The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Term::Graille::Interact

Allows user interaction in Graille Applications (or perhaps on any pterminal application). Depends on Term::ReadKey and Time::HiRes; When integrated with Term::Graille::Menu allows a modal drop down menu that can be navigated using key presses.

SYNOPSIS

     my $io=Term::Graille::Interact->new();
     $io->addAction(                             # add action for key press
                    "Am",                        # Am is returned for up arrow
                   {note=>"up arrow:cursor up ", # For drawing a menu
                    proc=>sub{my $self,@args)=@_ ...}  # the action
                    } );        
                   
     $io->run($io,@args);                        # start trapping keypresses
     ...
     $io->stop();                                # stop
                    

FUNCTIONS

my $io=Term::Graille::Interact->new(%params)

Creates a new IO object for user interaction. "Main", is default interaction profile, each active widget declkares its own interaction profile (responses to key presses)

my $io->addObject($menu,%params)

Adds a user interaction object. params are:-

objectId:Id of the object if not set this is automatically generated

object: the reference to object REQUIRED

actions: The key-press actions for this object when it is active

trigger:

$io->addAction($objectId,$key,$actionData)

Determines what happens when a key is pressed for a specific object. Functions in the users scripts have to be "fully qualified" e.g. &main::function()

    $io->addAction("menu","s",{note=>"s key saves sprite",proc=>sub{
           my ($self,$canvas,$sprite,$cursor)=@_; # these are the objects passed as parameters
           &main::saveSprite($sprite);  
           &main::flashCursor($sprite,$cursor);
           &main::restoreIO();},}  );   
 

my $io->updateAction($menu,$action)

Adds a routine that is executed every interaction cycle e.g for animations

$io->addActionSet(<ObjectID,$actionSet)>

allows multiple $key actions to be set/changed as a set. For example tyhe arrow keys may have one purpose navigating a menu and another set of actions in the game. Toggling between the game and menu would need the keys to be mapped to different actions, and this alows the actions to be swapped byu bundling the actions into sets.

   my $actionSet=[["s",{note=>"s key saves sprite",proc=>sub{
                                           my ($self,$canvas,$sprite,$cursor)=@_;
                                           &main::saveSprite($sprite);  
                                           &main::flashCursor($sprite,$cursor);
                                           &main::restoreIO();},} ],
                                #  [$key2, $actionData2], etc
                                 ]

$io->run()

Initiating the capture of the key presses that may trigger actions.

$io->start($objectId,$params)

Starts an object that consumes keypresses. $params is a hash ref that is passed to the object to allow customusation

$io->close()

closes currently active actually by calling Term::Graile::Interacts close(), this has been set during s Term::Graile::Interacts start($objectId)