ENGINE::InputDeviceSingleton Class Reference

#include <InputDevice.h>

List of all members.


Detailed Description

Interface to the input devices; keyboard, mouse, and joystick.

Author:
Richard Marks <ccpsceo@gmail.com>

Definition at line 238 of file InputDevice.h.


Public Member Functions

 ~InputDeviceSingleton ()
void Initialize (unsigned int initMask=INIT_ALLDEVICES)
void Update (unsigned int updateMask=UPDATE_ALLDEVICES)
bool KeyPressed (KEY::VirtualKey keyCode)
bool KeyDown (KEY::VirtualKey keyCode)
bool KeyUp (KEY::VirtualKey keyCode)
bool KeyPressed (KEY::Modifier modifier, KEY::VirtualKey keyCode)
bool KeyDown (KEY::Modifier modifier, KEY::VirtualKey keyCode)
bool KeyUp (KEY::Modifier modifier, KEY::VirtualKey keyCode)
bool MouseButtonDown (int button)
bool MouseButtonUp (int button)
int MouseX ()
int MouseY ()
int MouseZ ()
int MouseMoveRelative (AXIS::Axis axis)
void MouseSetPosition (int x, int y, int z=0)
void MouseSetRegion (int left, int top, int right, int bottom)
void MouseSetSpeed (int speedX=2, int speedY=2)
void MouseSetCursorImage (ImageResource *image=0, int hotSpotX=0, int hotSpotY=0)
void MouseDisplayOnScreen (bool enabled=true)
void MouseDisplayOnSurface (ImageResource *target=0)
void MouseEnableCursorDisplay (bool enabled=true)
void BeginJoystickCalibration ()
bool JoyButtonDown (int button, int joystick=0)
bool JoyButtonUp (int button, int joystick=0)
bool JoyUp (int joystick=0, int stick=0)
bool JoyDown (int joystick=0, int stick=0)
bool JoyLeft (int joystick=0, int stick=0)
bool JoyRight (int joystick=0, int stick=0)
int Joy (AXIS::Axis axis, int stick=0, int joystick=0)

Static Public Member Functions

static InputDeviceSingletonGetInstance ()
static bool JoyExists (int joystick=0)
static bool JoyButtonExists (int joystick, int button)
static bool JoyStickExists (int joystick, int stick)

Private Member Functions

void InitializeKeyboard ()
void InitializeMouse ()
void InitializeJoystick ()
void UpdateKeyboard ()
void UpdateMouse ()
void UpdateJoystick ()
 InputDeviceSingleton ()
 InputDeviceSingleton (const InputDeviceSingleton &rhs)
InputDeviceSingletonoperator= (const InputDeviceSingleton &rhs)

Private Attributes

bool key_ [KEY::Key_Max]
 an array of booleans to track if the key is currently up or down
bool keys_ [KEY::Key_Max]
 an array of booleans to track if a key was pressed (used in non-repeating key handling)
bool joystickAvailable_
 this variable is true when we successfully load the joystick calibration data file

Constructor & Destructor Documentation

ENGINE::InputDeviceSingleton::~InputDeviceSingleton (  ) 

default destructor - De-allocates any allocated memory

Definition at line 36 of file InputDevice.cpp.

ENGINE::InputDeviceSingleton::InputDeviceSingleton (  )  [private]

The class constructor is hidden because this is a singleton.

Definition at line 29 of file InputDevice.cpp.

ENGINE::InputDeviceSingleton::InputDeviceSingleton ( const InputDeviceSingleton rhs  )  [private]

The copy constructor is hidden because the class cannot be copied.


Member Function Documentation

InputDeviceSingleton * ENGINE::InputDeviceSingleton::GetInstance (  )  [static]

Returns:
a pointer to the input device singleton

Definition at line 20 of file InputDevice.cpp.

Referenced by JoyButtonUp().

Here is the caller graph for this function:

void ENGINE::InputDeviceSingleton::Initialize ( unsigned int  initMask = INIT_ALLDEVICES  ) 

Installs the input device drivers on the first call. You need to call this at least once before you can use the other methods.

Parameters:
initMask is a bitmask to say what devices to initialize. possible values are INIT_KEYBOARD, INIT_MOUSE, INIT_JOYSTICK, INIT_ALLDEVICES

Definition at line 42 of file InputDevice.cpp.

References ENGINE::INIT_JOYSTICK, ENGINE::INIT_KEYBOARD, ENGINE::INIT_MOUSE, InitializeJoystick(), InitializeKeyboard(), and InitializeMouse().

Here is the call graph for this function:

void ENGINE::InputDeviceSingleton::Update ( unsigned int  updateMask = UPDATE_ALLDEVICES  ) 

Updates all input devices so that the device data is current If you do not pass a parameter, then all devices will be updated.

Parameters:
updateMask is a bitmask to say what devices to update. possible values are UPDATE_KEYBOARD, UPDATE_MOUSE, UPDATE_JOYSTICK, UPDATE_ALLDEVICES

Definition at line 64 of file InputDevice.cpp.

References ENGINE::UPDATE_JOYSTICK, ENGINE::UPDATE_KEYBOARD, ENGINE::UPDATE_MOUSE, UpdateJoystick(), UpdateKeyboard(), and UpdateMouse().

Here is the call graph for this function:

bool ENGINE::InputDeviceSingleton::KeyPressed ( KEY::VirtualKey  keyCode  ) 

Checks for a key being pressed in a non-repeating manner.

Parameters:
keyCode is the virtual-key code constant such as KEY::Key_Escape to check /return true if the key was presssed, false if not

Definition at line 74 of file InputDevice_Keyboard.cpp.

References keys_.

Referenced by KeyPressed().

Here is the caller graph for this function:

bool ENGINE::InputDeviceSingleton::KeyDown ( KEY::VirtualKey  keyCode  ) 

Checks that a key is currently being pressed down in a repeating manner.

Parameters:
keyCode is the virtual-key code constant such as KEY::Key_Left to check
Returns:
true if the key is currently down, and false if not

Definition at line 101 of file InputDevice_Keyboard.cpp.

References key_.

Referenced by KeyDown().

Here is the caller graph for this function:

bool ENGINE::InputDeviceSingleton::KeyUp ( KEY::VirtualKey  keyCode  ) 

Checks that a key is currently not being pressed down in a repeating manner.

Parameters:
keyCode is the virtual-key code constant such as KEY::Key_Left to check
Returns:
true if the key is currently up, and false if it is down

Definition at line 109 of file InputDevice_Keyboard.cpp.

References key_.

Referenced by KeyUp().

Here is the caller graph for this function:

bool ENGINE::InputDeviceSingleton::KeyPressed ( KEY::Modifier  modifier,
KEY::VirtualKey  keyCode 
)

Checks for a key being pressed in a non-repeating manner. Also checks for a modifier such as KEY::Mod_Ctrl

Parameters:
modifier is a key modifier bit mask such as KEY::Mod_Ctrl
keyCode is the virtual-key code constant such as KEY::Key_Escape to check /return true if the key was presssed, false if not

Definition at line 117 of file InputDevice_Keyboard.cpp.

References KeyPressed().

Here is the call graph for this function:

bool ENGINE::InputDeviceSingleton::KeyDown ( KEY::Modifier  modifier,
KEY::VirtualKey  keyCode 
)

Checks that a key is currently being pressed down in a repeating manner.

Parameters:
modifier is a key modifier bit mask such as KEY::Mod_Ctrl
keyCode is the virtual-key code constant such as KEY::Key_Left to check
Returns:
true if the key is currently down, and false if not

Definition at line 127 of file InputDevice_Keyboard.cpp.

References KeyDown().

Here is the call graph for this function:

bool ENGINE::InputDeviceSingleton::KeyUp ( KEY::Modifier  modifier,
KEY::VirtualKey  keyCode 
)

Checks that a key is currently not being pressed down in a repeating manner.

Parameters:
modifier is a key modifier bit mask such as KEY::Mod_Ctrl
keyCode is the virtual-key code constant such as KEY::Key_Left to check
Returns:
true if the key is currently up, and false if it is down

Definition at line 137 of file InputDevice_Keyboard.cpp.

References KeyUp().

Here is the call graph for this function:

bool ENGINE::InputDeviceSingleton::MouseButtonDown ( int  button  ) 

Checks to see if the button is currently down

Returns:
true if the button is down, false if not

Definition at line 65 of file InputDevice_Mouse.cpp.

bool ENGINE::InputDeviceSingleton::MouseButtonUp ( int  button  ) 

Checks to see if the button is currently up

Returns:
true if the button is up, false if not

Definition at line 72 of file InputDevice_Mouse.cpp.

int ENGINE::InputDeviceSingleton::MouseX (  ) 

Returns:
the X pixel coordinate of the mouse pointer

Definition at line 79 of file InputDevice_Mouse.cpp.

int ENGINE::InputDeviceSingleton::MouseY (  ) 

Returns:
the Y pixel coordinate of the mouse pointer

Definition at line 86 of file InputDevice_Mouse.cpp.

int ENGINE::InputDeviceSingleton::MouseZ (  ) 

Returns:
the mouse wheel position

Definition at line 93 of file InputDevice_Mouse.cpp.

int ENGINE::InputDeviceSingleton::MouseMoveRelative ( AXIS::Axis  axis  ) 

Measures how far the mouse has moved on a given axis since the last call to this function. The returned values will become negative if the mouse is moved left or up. The mouse will continue to generate movement mickeys even when it reaches the edge of the screen, so this form of input can be useful for games that require an infinite range of mouse movement.

Parameters:
axis is which axis to check. AXIS::Axis_X checks the horizontal motion, AXIS::Axis_Y checks the vertical motion.
Returns:
the amount of pixels the mouse has moved on a given axis, relative to the last time the function was called

Definition at line 100 of file InputDevice_Mouse.cpp.

References ENGINE::AXIS::Axis_X, and ENGINE::AXIS::Axis_Y.

void ENGINE::InputDeviceSingleton::MouseSetPosition ( int  x,
int  y,
int  z = 0 
)

Sets the position of the mouse and optionally the mouse wheel.

Parameters:
x is the new horizontal mouse position in pixels.
y is the new vertical mouse position in pixels.
z is the new mouse wheel position.

Definition at line 117 of file InputDevice_Mouse.cpp.

void ENGINE::InputDeviceSingleton::MouseSetRegion ( int  left,
int  top,
int  right,
int  bottom 
)

Sets the area of the screen within which the mouse can move. Pass the top left corner and the bottom right corner (inclusive)

Parameters:
left is the X coordinate of the upper-left corner in pixels.
top is the Y coordinate of the upper-left corner in pixels.
right is the X coordinate of the lower-right corner in pixels.
bottom is the Y coordinate of the lower-right corner in pixels.

Definition at line 125 of file InputDevice_Mouse.cpp.

void ENGINE::InputDeviceSingleton::MouseSetSpeed ( int  speedX = 2,
int  speedY = 2 
)

Sets the speed of the mouse cursor. Larger values of speedX and speedY represent slower mouse movement. The default for both is 2.

Parameters:
speedX is the horizontal speed of the mouse.
speedY is the vertical speed of the mouse.

Definition at line 132 of file InputDevice_Mouse.cpp.

void ENGINE::InputDeviceSingleton::MouseSetCursorImage ( ImageResource image = 0,
int  hotSpotX = 0,
int  hotSpotY = 0 
)

Changes the image of the mouse cursor. You can optionally change the hot-spot of the mouse cursor.
This "clicky" point is the location on the mouse cursor that determines the position of the mouse cursor.
By default, this is the upper-left corner of the cursor at 0, 0.

Parameters:
image is an ImageResource containing the image to use for the mouse cursor.
hotSpotX is the X coordinate of the actual "clicky" point of the mouse cursor in pixels.
hotSpotY is the Y coordinate of the actual "clicky" point of the mouse cursor in pixels.

Definition at line 139 of file InputDevice_Mouse.cpp.

References ENGINE::ImageResource::GetBitmap().

Here is the call graph for this function:

void ENGINE::InputDeviceSingleton::MouseDisplayOnScreen ( bool  enabled = true  ) 

Toggle the mouse cursor being drawn on the screen or not

Parameters:
enabled is a boolean value - set to true to show the mouse cursor on the primary screen

void ENGINE::InputDeviceSingleton::MouseDisplayOnSurface ( ImageResource target = 0  ) 

Lets you display the mouse cursor on any image resource call without any parameters to turn off the mouse cursor completely (same as calling MouseDisplayOnScreen(false))

Parameters:
target is an ImageResource that the mouse cursor will be displayed on

void ENGINE::InputDeviceSingleton::MouseEnableCursorDisplay ( bool  enabled = true  ) 

Toggle the mouse cursor display to aid in drawing without artifacts

Parameters:
enabled is a boolean value - set to true to show the mouse cursor, false to hide it

void ENGINE::InputDeviceSingleton::BeginJoystickCalibration (  ) 

A mini-program in its own right, this function calibrates the joysticks attached to the computer, and saves the calibration data to a file. The program will exit to the OS after the calibration is complete.

Definition at line 175 of file InputDevice_Joystick.cpp.

References LogFatal, and LogMessage.

Referenced by InitializeJoystick().

Here is the caller graph for this function:

bool ENGINE::InputDeviceSingleton::JoyExists ( int  joystick = 0  )  [static]

Validate a joystick by ID

Parameters:
joystick is an integer to specify the ID # of the joystick. 0 is the default
Returns:
true if the passed joystickID is valid.

Definition at line 95 of file InputDevice_Joystick.cpp.

Referenced by JoyButtonExists(), and JoyStickExists().

Here is the caller graph for this function:

bool ENGINE::InputDeviceSingleton::JoyButtonExists ( int  joystick,
int  button 
) [static]

Validate a joystick button by ID

Parameters:
joystick is an integer to specify the ID # of the joystick.
button is an integer to specify the ID # of the joystick button.
Returns:
true if the passed buttonID is valid.

Definition at line 102 of file InputDevice_Joystick.cpp.

References JoyExists().

Referenced by JoyButtonDown().

Here is the call graph for this function:

Here is the caller graph for this function:

bool ENGINE::InputDeviceSingleton::JoyStickExists ( int  joystick,
int  stick 
) [static]

Validate a joystick stick (the actual thing you hold on to) by ID

Parameters:
joystick is an integer to specify the ID # of the joystick.
stick is an integer to specify the ID # of the joystick stick.
Returns:
true if the passed stickID is valid.

Definition at line 109 of file InputDevice_Joystick.cpp.

References JoyExists().

Referenced by Joy(), JoyDown(), JoyLeft(), JoyRight(), and JoyUp().

Here is the call graph for this function:

Here is the caller graph for this function:

bool ENGINE::InputDeviceSingleton::JoyButtonDown ( int  button,
int  joystick = 0 
)

Checks if a button on the joystick is currently down.

Parameters:
button is an integer to specify the ID # of the joystick button.
joystick is an integer to specify the ID # of the joystick.
Returns:
true if the button is down.

Definition at line 116 of file InputDevice_Joystick.cpp.

References JoyButtonExists().

Referenced by JoyButtonUp().

Here is the call graph for this function:

Here is the caller graph for this function:

bool ENGINE::InputDeviceSingleton::JoyButtonUp ( int  button,
int  joystick = 0 
)

Checks if a button on the joystick is currently up.

Parameters:
button is an integer to specify the ID # of the joystick button.
joystick is an integer to specify the ID # of the joystick.
Returns:
true if the button is up.

Definition at line 123 of file InputDevice_Joystick.cpp.

References GetInstance(), and JoyButtonDown().

Here is the call graph for this function:

bool ENGINE::InputDeviceSingleton::JoyUp ( int  joystick = 0,
int  stick = 0 
)

Check if joystick is pushed up (on a game pad) or forward (on a flight stick)

Parameters:
joystick is an integer to specify the ID # of the joystick.
stick is an integer to specify the ID # of the joystick stick.
Returns:
true if the joystick stick is pushed up (on a game pad) or forward (on a flight stick)

Definition at line 130 of file InputDevice_Joystick.cpp.

References JoyStickExists().

Here is the call graph for this function:

bool ENGINE::InputDeviceSingleton::JoyDown ( int  joystick = 0,
int  stick = 0 
)

Check if joystick is pushed down (on a game pad) or back (on a flight stick)

Parameters:
joystick is an integer to specify the ID # of the joystick.
stick is an integer to specify the ID # of the joystick stick.
Returns:
true if the joystick stick is pushed down (on a game pad) or back (on a flight stick)

Definition at line 137 of file InputDevice_Joystick.cpp.

References JoyStickExists().

Here is the call graph for this function:

bool ENGINE::InputDeviceSingleton::JoyLeft ( int  joystick = 0,
int  stick = 0 
)

Check if joystick is pushed left (on a game pad or on a flight stick)

Parameters:
joystick is an integer to specify the ID # of the joystick.
stick is an integer to specify the ID # of the joystick stick.
Returns:
true if the joystick stick is pushed left (on a game pad or on a flight stick)

Definition at line 144 of file InputDevice_Joystick.cpp.

References JoyStickExists().

Here is the call graph for this function:

bool ENGINE::InputDeviceSingleton::JoyRight ( int  joystick = 0,
int  stick = 0 
)

Check if joystick is pushed right (on a game pad or on a flight stick)

Parameters:
joystick is an integer to specify the ID # of the joystick.
stick is an integer to specify the ID # of the joystick stick.
Returns:
true if the joystick stick is pushed right (on a game pad or on a flight stick)

Definition at line 151 of file InputDevice_Joystick.cpp.

References JoyStickExists().

Here is the call graph for this function:

int ENGINE::InputDeviceSingleton::Joy ( AXIS::Axis  axis,
int  stick = 0,
int  joystick = 0 
)

Get analogue joystick input (relative motion of the joystick on a given axis)

Parameters:
axis is the axis to check motion on. Possible values are AXIS::Axis_X, AXIS::Axis_Y, AXIS::Axis_Z.
stick is the stickID to check. Default is 0
joystick is the joystickID to check. Default is 0
Returns:
the relative position of the joystick motion on a given axis.

Definition at line 158 of file InputDevice_Joystick.cpp.

References JoyStickExists().

Here is the call graph for this function:

void ENGINE::InputDeviceSingleton::InitializeKeyboard (  )  [private]

The keyboard input device initialization function

Definition at line 31 of file InputDevice_Keyboard.cpp.

References key_, keys_, and LogFatal.

Referenced by Initialize().

Here is the caller graph for this function:

void ENGINE::InputDeviceSingleton::InitializeMouse (  )  [private]

The mouse input device initialization function

Definition at line 34 of file InputDevice_Mouse.cpp.

References LogFatal.

Referenced by Initialize().

Here is the caller graph for this function:

void ENGINE::InputDeviceSingleton::InitializeJoystick (  )  [private]

The joystick input device initialization function

Definition at line 34 of file InputDevice_Joystick.cpp.

References BeginJoystickCalibration(), joystickAvailable_, LogFatal, and LogWarning.

Referenced by Initialize().

Here is the call graph for this function:

Here is the caller graph for this function:

void ENGINE::InputDeviceSingleton::UpdateKeyboard (  )  [private]

The keyboard input device update function

Definition at line 59 of file InputDevice_Keyboard.cpp.

References key_, and ENGINE::KEY::Key_Max.

Referenced by Update().

Here is the caller graph for this function:

void ENGINE::InputDeviceSingleton::UpdateMouse (  )  [private]

The mouse input device update function

Definition at line 55 of file InputDevice_Mouse.cpp.

Referenced by Update().

Here is the caller graph for this function:

void ENGINE::InputDeviceSingleton::UpdateJoystick (  )  [private]

The joystick input device update function

Definition at line 88 of file InputDevice_Joystick.cpp.

Referenced by Update().

Here is the caller graph for this function:

InputDeviceSingleton& ENGINE::InputDeviceSingleton::operator= ( const InputDeviceSingleton rhs  )  [private]

The assignment operator is hidden because the class cannot be copied.


Member Data Documentation

an array of booleans to track if the key is currently up or down

Definition at line 575 of file InputDevice.h.

Referenced by InitializeKeyboard(), KeyDown(), KeyUp(), and UpdateKeyboard().

an array of booleans to track if a key was pressed (used in non-repeating key handling)

Definition at line 581 of file InputDevice.h.

Referenced by InitializeKeyboard(), and KeyPressed().

this variable is true when we successfully load the joystick calibration data file

Definition at line 587 of file InputDevice.h.

Referenced by InitializeJoystick().


The documentation for this class was generated from the following files:

Generated on Tue Mar 3 20:11:40 2009 for ged101minimal by  doxygen 1.5.5