Input Class Reference
[C++ Wrapper for SDLCommand Line Interface]

Hold keyboard and mouse state.

* For mouse absolute position and delta motion, this should be obvious. * For mouse button, use constants SDL_BUTTON_LEFT, ..., see SDL_MouseButtonEvent(5). * For keyboard, two informations are available. Keys currently pressed, and keys being pressed since the last updat.e occured. Access key using ascii character, eg: if (key_['b']) {...} * For keyboard modifier, use class convenience function. More...

#include <Input.hh>

List of all members.

Public Member Functions

void reset ()
 To call before a serie of update();.
void update (SDL_Event &event)
 Update Input structure. To use in the main loop only.
bool isModDown (int mod) const
 See if keyboard modifier mod is down.
bool isModPressed (int mod) const
 Same as isModDown, but since last update.
bool lockKeyboard (const std::string &lock_id)
 Locks the keyboard, so that key_ and key_pressed_ will always be empty, until it is unlocked with the same lock_id.
bool unlockKeyboard (const std::string &lock_id)
 Unlock the keyboard.
bool isKeyboardLocked () const
 Check if the keyboard is locked.
const std::string & getString () const
 Input (CmdLineInterface *i, Api *gc, bool use_readline)
bool process ()
 ! Main loop, check input, process commands.
void processCommand (const std::string &s)
 ! Process a command.
void wantExit ()
 ! Wants exit, next call to process() will return true.
void stopWaiting ()
 ! Tell to process input again.

Static Public Member Functions

static InputgetInst ()

Public Attributes

Point mouse_delta_
 Mouse motion since last update.
Point mouse_
 Mouse position.
bool button_ [10]
 Mouse button currently down.
bool button_pressed_ [10]
 Mouse button pressed since last update.
bool key_ [SDLK_LAST]
 Keys currently pressed.
bool key_pressed_ [SDLK_LAST]
 Keys pressed between last updat and now.

Static Public Attributes

static InputCommand main_cmd_ []
static InputSubCommand print_cmd_ []
static InputSubCommand move_cmd_ []
static InputSubCommand choose_cmd_ []
static InputSubCommand place_cmd_ []
static InputSubCommand block_cmd_ []
static InputSubCommand skill_cmd_ []
static InputSubCommand declare_cmd_ []

Classes

struct  InputCommand
struct  InputSubCommand


Detailed Description

Hold keyboard and mouse state.

* For mouse absolute position and delta motion, this should be obvious. * For mouse button, use constants SDL_BUTTON_LEFT, ..., see SDL_MouseButtonEvent(5). * For keyboard, two informations are available. Keys currently pressed, and keys being pressed since the last updat.e occured. Access key using ascii character, eg: if (key_['b']) {...} * For keyboard modifier, use class convenience function.

It also provides a easy way to gain exclusive access to the keyboard, by locking and unlocking it.


Member Function Documentation

bool Input::isModDown ( int  mod  )  const

See if keyboard modifier mod is down.

Use constants KMOD_CTRL, ... as specified in SDL_GetModState(5).

bool Input::lockKeyboard ( const std::string &  lock_id  ) 

Locks the keyboard, so that key_ and key_pressed_ will always be empty, until it is unlocked with the same lock_id.

Returns:
true if lock is successful, else false (already locked).

bool Input::process (  ) 

! Main loop, check input, process commands.

.. call it frequently.

Note:
Block at most 50ms.
Returns:
true if user wants to exit from app (EOF, quit, etc...).

void Input::processCommand ( const std::string &  s  ) 

! Process a command.

Parameters:
s The command line, without trailing '\n'.

bool Input::unlockKeyboard ( const std::string &  lock_id  ) 

Unlock the keyboard.

Returns:
true if unlock successful (same lock_id), else false.


Member Data Documentation

Input::InputSubCommand Input::block_cmd_ [static]

Initial value:

 {
  {"", &Input::cmdBlockBlock, "<att> <def>|Block <def> with player <att>."},
  {"dice", &Input::cmdBlockDice, "<n>|Choose a block dice."},
  {"follow", &Input::cmdBlockFollow, "Follow after a block."},
  {"stay", &Input::cmdBlockStay, "Stay after a block."},
  {"push", &Input::cmdBlockPush, "<n>|Choose a square to push the player in."},
  {NULL, NULL, NULL}
}

Input::InputSubCommand Input::choose_cmd_ [static]

Initial value:

 {
  {"kickoff", &Input::cmdChooseKickoff, "Choose to kick off the ball first."},
  {"receive", &Input::cmdChooseReceive, "Choose to receive the ball first."},
  {NULL, NULL, NULL}
}

Input::InputSubCommand Input::declare_cmd_ [static]

Initial value:

 {
  {"move", &Input::cmdDeclareMove, "<p>|Declare a move action for player <p>."},
  {"block", &Input::cmdDeclareBlock, "<p>|Declare a block action for player <p>."},
  {"blitz", &Input::cmdDeclareBlitz, "<p>|Declare a blitz action for player <p>."},
  {"pass", &Input::cmdDeclarePass, "<p>|Declare a pass action for player <p>."},
  {NULL, NULL, NULL}
}

Input::InputCommand Input::main_cmd_ [static]

Initial value:

 {
  {"quit", &Input::cmdQuit, "Exit the game, CU."},
  {"help", &Input::cmdHelp, "Print this help."},
  {"print", &Input::cmdPrint, "<subcmd>|Print some informations. ('help print')"},
  {"say", &Input::cmdSay, "<s>|Chat with others."},
  {"choose", &Input::cmdChoose, "<subcmd>|Choose to kick off or receive. ('help choose')"},
  {"place", &Input::cmdPlace, "<subcmd>|Set up team placement. ('help place')"},
  {"kickoff", &Input::cmdKickOff, "<r> <c>|Kick off the ball to [<r> <c>]."},
  {"giveBall", &Input::cmdGiveBall, "<p>|Give the ball to the player <p>."},
  {"illegal", &Input::cmdIllegal, "Ask for an illegal procedure, absolutely useless."},
  {"reroll", &Input::cmdReroll, "Reroll the dice(s) using a team reroll."},
  {"skill", &Input::cmdSkill, "<subcmd>|Skill usage. ('help skill')"},
  {"accept", &Input::cmdAccept, "Accept result of the dice(s)."},
  {"end", &Input::cmdEnd, "End turn."},
  {"declare", &Input::cmdDeclare, "<subcmd>|Declare an action. ('help declare')"},
  {"move", &Input::cmdMove, "<subcmd>|Move something. ('help move')"},
  {"standup", &Input::cmdStandUp, "<p>|Stand up the player <p>."},
  {"block", &Input::cmdBlock, "<subcmd>|Block action. ('help block')"},
  {"pass", &Input::cmdPass, "<p> <r> <c>|Pass the ball from player <p> to [<r> <c>]."},
  {"cheat", &Input::cmdCheat, "<n> <...>|Force next dice rolls to give these results (cheat)."},
  {"wait", &Input::cmdWait, "Do not process input until it's your turn."},
  {NULL, NULL, NULL}
}

Input::InputSubCommand Input::move_cmd_ [static]

Initial value:

 {
  {"turnmarker", &Input::cmdMoveTurnMarker, "Move the turn marker, absolutely useless."},
  {"", &Input::cmdMovePlayer, "<p> <r> <c>|Move player <p> to [<r> <c>]."},
  {NULL, NULL, NULL}
}

Input::InputSubCommand Input::place_cmd_ [static]

Initial value:

 {
  {"", &Input::cmdPlaceField, "<p> <r> <c>|Place the player <p> at [<r> <c>]."},
  {"reserve", &Input::cmdPlaceReserve, "<p>|Place the player <p> in the reserve."},
  {"end", &Input::cmdEndPlacement, "End team placement."},
  {NULL, NULL, NULL}
}

Input::InputSubCommand Input::print_cmd_ [static]

Initial value:

 {
  {"global", &Input::cmdPrintGlobal, "Print game globals."},
  {"field", &Input::cmdPrintField, "Print field in ascii art."},
  {"players", &Input::cmdPrintPlayers, "Print players list."},
  {"us", &Input::cmdPrintUs, "<p>|Print info for our team player <p>."},
  {"them", &Input::cmdPrintThem, "<p>|Print info for other team player <p>."},
  {"", &Input::cmdPrintString, "<s>|Simply display the string <s>."},
  {NULL, NULL, NULL}
}

Input::InputSubCommand Input::skill_cmd_ [static]

Initial value:

 {
  {"use", &Input::cmdUseSkill, "<s>|Use the skill <s>."},
  {"ignore", &Input::cmdIgnoreSkill, "<s>|Ignore the skill <s>."},
  {NULL, NULL, NULL}
}


The documentation for this class was generated from the following files:
Generated on Sat Jun 23 16:10:49 2007 for Stechec/TBT by  doxygen 1.4.7