input::manager Class Reference

Handles inputs (keyboard and mouse). More...

#include <input.hpp>

List of all members.

Public Member Functions

 manager (const handler &mHandler)
 Initializes this manager with the proper input source.
 manager (const manager &mMgr)
 This class is non copiable.
manageroperator= (const manager &mMgr)
 This class is non copiable.
void update (float fDelta)
 Updates input (keyboard and mouse).
void allow_input (const std::string &sGroupName)
 Allows a particular input group to receive input events.
void block_input (const std::string &sGroupName)
 Prevents a particular input group from receiving input events.
bool can_receive_input (const std::string &sGroupName) const
 Checks if a particular input group can receive input events.
void force_input_allowed (const std::string &sGroupName, bool bForce)
 Makes sure a particular input group receives input events.
bool get_key (bool bForce=false) const
 Checks if a key has been pressed.
bool key_is_down (key::code mKey, bool bForce=false) const
 Checks if a key is being pressed.
bool key_is_down_long (key::code mKey, bool bForce=false) const
 Checks if a key is being pressed for a long time.
double get_key_press_duration (key::code mKey) const
 Returns elapsed time since the key has been pressed.
bool key_is_pressed (key::code mKey, bool bForce=false) const
 Checks if a key has been pressed.
bool key_is_released (key::code mKey, bool bForce=false) const
 Checks if a key has been released.
std::vector< char32_t > get_chars () const
 Returns the UTF8 (multibyte) character that has been entered.
std::string get_key_name (key::code mKey) const
 Returns the name of the provided key, as it appears on your keyboard.
std::string get_key_name (key::code mKey, key::code mModifier) const
 Returns the name of the provided key combination.
std::string get_key_name (key::code mKey, key::code mModifier1, key::code mModifier2) const
 Returns the name of the provided key combination.
const std::deque< key::code > & get_key_release_stack () const
 Returns the list of keys that have been released during this frame.
const std::deque< key::code > & get_key_press_stack () const
 Returns the list of keys that have been pressed during this frame.
bool alt_is_pressed () const
 Checks if Alt is beeing pressed.
bool shift_is_pressed () const
 Checks if Shift is beeing pressed.
bool ctrl_is_pressed () const
 Checks if Control (Ctrl) is beeing pressed.
bool mouse_is_down (mouse::button mID) const
 Checks if a mouse button is being pressed.
bool mouse_is_down_long (mouse::button mID) const
 Checks if a mouse button is being pressed for a long time.
double get_mouse_press_duration (mouse::button mKey) const
 Returns elapsed time since the mouse button has been pressed.
bool mouse_is_pressed (mouse::button mID) const
 Checks if a mouse button has been pressed.
bool mouse_is_released (mouse::button mID) const
 Checks if a mouse button has been released.
bool mouse_is_doubleclicked (mouse::button mID) const
 Checks if a mouse button has been double clicked.
bool wheel_is_rolled () const
 Checks if the mouse wheel has been rolled.
bool mouse_last_dragged () const
 Checks if the mouse has just started beeing dragged.
mouse::state get_mouse_state (mouse::button mID) const
 Returns a mouse button's state.
float get_mouse_x () const
 Returns the horizontal position of the mouse.
float get_mouse_y () const
 Returns the vertical position of the mouse.
float get_mouse_rel_x () const
 Returns the horizontal position of the mouse in window units.
float get_mouse_rel_y () const
 Returns the vertical position of the mouse in window units.
float get_mouse_raw_dx () const
 Returns the horizontal position variation of the mouse.
float get_mouse_raw_dy () const
 Returns the vertical position variation of the mouse.
float get_mouse_dx () const
 Returns the horizontal position variation of the mouse.
float get_mouse_dy () const
 Returns the vertical position variation of the mouse.
float get_mouse_rel_dx () const
 Returns the horizontal position variation of the mouse in window units.
float get_mouse_rel_dy () const
 Returns the vertical position variation of the mouse in window units.
float get_mouse_smooth_dx () const
 Returns the horizontal position variation of the mouse.
float get_mouse_smooth_dy () const
 Returns the vertical position variation of the mouse.
float get_mouse_wheel () const
 Returns the rolling ammount of the mouse wheel.
std::string get_mouse_button_string (mouse::button mID) const
 Returns the string associated to a mouse button.
void set_doubleclick_time (double dDoubleClickTime)
 Sets the double click maximum time.
double get_doubleclick_time () const
 Returns the double click maximum time.
void set_mouse_buffer_duration (double dMouseHistoryMaxLength)
 Sets the ammount of mouse movement to be buffered.
double get_mouse_buffer_duration () const
 Returns the ammount of mouse movement to be buffered.
void set_mouse_sensibility (float fMouseSensibility)
 Sets the mouse movement factor.
float get_mouse_sensibility () const
 Returns the mouse movement factor.
void set_long_press_delay (double dLongPressDelay)
 Sets the duration after which a key is considered as pressed for a long time.
double get_long_press_delay () const
 Returns the duration after which a key is considered as pressed for a long time.
void set_focus (bool bFocus, gui::event_receiver *pReceiver=nullptr)
 Sets whether input should be stopped.
bool is_focused () const
 Checks whether input is focused somewhere, to prevent multiple inputs.
void register_event_manager (utils::wptr< gui::event_manager > pManager)
 Registers a new event manager that will listen to input events.
void unregister_event_manager (utils::wptr< gui::event_manager > pManager)
 Unregisters an event manager.
const handlerget_handler () const
 Returns this manager's handler.
handlerget_handler ()
 Returns this manager's handler.

Detailed Description

Handles inputs (keyboard and mouse).

Definition at line 142 of file input.hpp.


Constructor & Destructor Documentation

input::manager::manager ( const handler mHandler  )  [explicit]

Initializes this manager with the proper input source.

Parameters:
mHandler The input source (from another library)

Definition at line 74 of file input.cpp.

input::manager::manager ( const manager mMgr  ) 

This class is non copiable.


Member Function Documentation

void input::manager::allow_input ( const std::string &  sGroupName  ) 

Allows a particular input group to receive input events.

Parameters:
sGroupName The name of the group to enable

Definition at line 96 of file input.cpp.

bool input::manager::alt_is_pressed (  )  const

Checks if Alt is beeing pressed.

Returns:
'true' if Alt is beeing pressed

Definition at line 635 of file input.cpp.

void input::manager::block_input ( const std::string &  sGroupName  ) 

Prevents a particular input group from receiving input events.

Parameters:
sGroupName The name of the group to disable

Definition at line 101 of file input.cpp.

bool input::manager::can_receive_input ( const std::string &  sGroupName  )  const

Checks if a particular input group can receive input events.

Parameters:
sGroupName The name of the group to check
Returns:
'true' if the group can receive input events

Definition at line 106 of file input.cpp.

bool input::manager::ctrl_is_pressed (  )  const

Checks if Control (Ctrl) is beeing pressed.

Returns:
'true' if Control (Ctrl) is beeing pressed

Definition at line 645 of file input.cpp.

void input::manager::force_input_allowed ( const std::string &  sGroupName,
bool  bForce 
)

Makes sure a particular input group receives input events.

Parameters:
sGroupName The name of the group to force
bForce 'true' to force input
Note:
Even if you call block_input() with the same group name, can_receive_input() will return true.

Definition at line 119 of file input.cpp.

std::vector< char32_t > input::manager::get_chars (  )  const

Returns the UTF8 (multibyte) character that has been entered.

Returns:
The multibyte UTF8 character just entered with the keyboard

Definition at line 262 of file input.cpp.

double input::manager::get_doubleclick_time (  )  const

Returns the double click maximum time.

Returns:
The double click maximum time

Definition at line 603 of file input.cpp.

handler & input::manager::get_handler (  ) 

Returns this manager's handler.

Returns:
This manager's handler

Definition at line 761 of file input.cpp.

const handler & input::manager::get_handler (  )  const

Returns this manager's handler.

Returns:
This manager's handler

Definition at line 756 of file input.cpp.

bool input::manager::get_key ( bool  bForce = false  )  const

Checks if a key has been pressed.

Parameters:
bForce 'true' to bypass focus (see set_focus())
Returns:
'true' if a key has been pressed

Definition at line 124 of file input.cpp.

std::string input::manager::get_key_name ( key::code  mKey,
key::code  mModifier1,
key::code  mModifier2 
) const

Returns the name of the provided key combination.

Parameters:
mKey The main key
mModifier1 The first modifier key (shift, ctrl, ...)
mModifier2 The second modifier key (shift, ctrl, ...)
Returns:
The name of key combination, example : "Ctrl + Shift + A"

Definition at line 165 of file input.cpp.

std::string input::manager::get_key_name ( key::code  mKey,
key::code  mModifier 
) const

Returns the name of the provided key combination.

Parameters:
mKey The main key
mModifier The modifier key (shift, ctrl, ...)
Returns:
The name of key combination, example : "Ctrl + A"

Definition at line 137 of file input.cpp.

std::string input::manager::get_key_name ( key::code  mKey  )  const

Returns the name of the provided key, as it appears on your keyboard.

Parameters:
mKey The key
Returns:
The name of the provided key, as it appears on your keyboard

Definition at line 132 of file input.cpp.

double input::manager::get_key_press_duration ( key::code  mKey  )  const

Returns elapsed time since the key has been pressed.

Parameters:
mKey The ID code of the key you're interested in
Returns:
Elapsed time since the key has been pressed

Definition at line 241 of file input.cpp.

const std::deque< key::code > & input::manager::get_key_press_stack (  )  const

Returns the list of keys that have been pressed during this frame.

Returns:
The list of keys that have been pressed during this frame.

Definition at line 215 of file input.cpp.

const std::deque< key::code > & input::manager::get_key_release_stack (  )  const

Returns the list of keys that have been released during this frame.

Returns:
The list of keys that have been released during this frame.

Definition at line 220 of file input.cpp.

double input::manager::get_long_press_delay (  )  const

Returns the duration after which a key is considered as pressed for a long time.

Returns:
The duration after which a key is considered as pressed for a long time

Definition at line 740 of file input.cpp.

double input::manager::get_mouse_buffer_duration (  )  const

Returns the ammount of mouse movement to be buffered.

Returns:
The ammount of mouse movement to be buffered

Definition at line 613 of file input.cpp.

std::string input::manager::get_mouse_button_string ( mouse::button  mID  )  const

Returns the string associated to a mouse button.

Parameters:
mID The ID code of the mouse button you're interested in
Returns:
The string associated with the mouse button

Definition at line 745 of file input.cpp.

float input::manager::get_mouse_dx (  )  const

Returns the horizontal position variation of the mouse.

Returns:
The horizontal position variation of the mouse
Note:
This function returns the same thing as get_mouse_raw_dx(), but this time, the game's sensibility factor is applied.

Definition at line 690 of file input.cpp.

float input::manager::get_mouse_dy (  )  const

Returns the vertical position variation of the mouse.

Returns:
The vertical position variation of the mouse
Note:
This function returns the same thing as get_mouse_raw_dy(), but this time, the game's sensibility factor is applied.

Definition at line 695 of file input.cpp.

double input::manager::get_mouse_press_duration ( mouse::button  mKey  )  const

Returns elapsed time since the mouse button has been pressed.

Parameters:
mKey The ID code of the mouse button you're interested in
Returns:
Elapsed time since the mouse button has been pressed

Definition at line 277 of file input.cpp.

float input::manager::get_mouse_raw_dx (  )  const

Returns the horizontal position variation of the mouse.

Returns:
The horizontal position variation of the mouse
Note:
This function returns values just as they are given by the mouse.

Definition at line 680 of file input.cpp.

float input::manager::get_mouse_raw_dy (  )  const

Returns the vertical position variation of the mouse.

Returns:
The vertical position variation of the mouse
Note:
This function returns values just as they are given by the mouse.

Definition at line 685 of file input.cpp.

float input::manager::get_mouse_rel_dx (  )  const

Returns the horizontal position variation of the mouse in window units.

Returns:
The horizontal position variation of the mouse in window units
Note:
This function returns the same thing as get_mouse_dx(), but divided by the window's width

Definition at line 700 of file input.cpp.

float input::manager::get_mouse_rel_dy (  )  const

Returns the vertical position variation of the mouse in window units.

Returns:
The vertical position variation of the mouse in window units
Note:
This function returns the same thing as get_mouse_dy(), but divided by the window's height

Definition at line 705 of file input.cpp.

float input::manager::get_mouse_rel_x (  )  const

Returns the horizontal position of the mouse in window units.

Returns:
The horizontal position of the mouse in window units
Note:
This function returns the same thing as get_mouse_x(), but divided by the window's width

Definition at line 670 of file input.cpp.

float input::manager::get_mouse_rel_y (  )  const

Returns the vertical position of the mouse in window units.

Returns:
The vertical position of the mouse in window units
Note:
This function returns the same thing as get_mouse_y(), but divided by the window's height

Definition at line 675 of file input.cpp.

float input::manager::get_mouse_sensibility (  )  const

Returns the mouse movement factor.

Returns:
The mouse movement factor

Definition at line 730 of file input.cpp.

float input::manager::get_mouse_smooth_dx (  )  const

Returns the horizontal position variation of the mouse.

Returns:
The horizontal position variation of the mouse
Note:
A common mouse's update rate is 125Hz (it will report its movement every 8ms). In the cases where the game updates faster, the mouse will just report zero movement for some frames, which can be disturbing if you need a continuous movement.
If that's an issue for you, then use this function instead of get_mouse_dx().
Sensibility factor is applied on the result.

Definition at line 710 of file input.cpp.

float input::manager::get_mouse_smooth_dy (  )  const

Returns the vertical position variation of the mouse.

Returns:
The vertical position variation of the mouse
Note:
A common mouse's update rate is 125Hz (it will report its movement every 8ms). In the cases where the game updates faster, the mouse will just report zero movement for some frames, which can be disturbing if you need a continuous movement.
If that's an issue for you, then use this function instead of get_mouse_dy().
Sensibility factor is applied on the result.

Definition at line 715 of file input.cpp.

mouse::state input::manager::get_mouse_state ( mouse::button  mID  )  const

Returns a mouse button's state.

Parameters:
mID The ID code of the mouse button you're interested in
Returns:
The mouse button's state

Definition at line 655 of file input.cpp.

float input::manager::get_mouse_wheel (  )  const

Returns the rolling ammount of the mouse wheel.

Returns:
The rolling ammount of the mouse wheel

Definition at line 720 of file input.cpp.

float input::manager::get_mouse_x (  )  const

Returns the horizontal position of the mouse.

Returns:
The horizontal position of the mouse

Definition at line 660 of file input.cpp.

float input::manager::get_mouse_y (  )  const

Returns the vertical position of the mouse.

Returns:
The vertical position of the mouse

Definition at line 665 of file input.cpp.

bool input::manager::is_focused (  )  const

Checks whether input is focused somewhere, to prevent multiple inputs.

Returns:
'true' if input is focused
Note:
See set_focus() for more information. If you use another input source than this manager, you should check the result of this function before actually using it.

Definition at line 630 of file input.cpp.

bool input::manager::key_is_down ( key::code  mKey,
bool  bForce = false 
) const

Checks if a key is being pressed.

Parameters:
mKey The ID code of the key you're interested in
bForce 'true' to bypass focus (see set_focus())
Returns:
'true' if the key is being pressed

Definition at line 225 of file input.cpp.

bool input::manager::key_is_down_long ( key::code  mKey,
bool  bForce = false 
) const

Checks if a key is being pressed for a long time.

Parameters:
mKey The ID code of the key you're interested in
bForce 'true' to bypass focus (see set_focus())
Returns:
'true' if the key is being pressed for a long time

Definition at line 233 of file input.cpp.

bool input::manager::key_is_pressed ( key::code  mKey,
bool  bForce = false 
) const

Checks if a key has been pressed.

Parameters:
mKey The ID code of the key you're interested in
bForce 'true' to bypass focus (see set_focus())
Returns:
'true' if the key has been pressed
Note:
Happens just when the key is pressed.

Definition at line 246 of file input.cpp.

bool input::manager::key_is_released ( key::code  mKey,
bool  bForce = false 
) const

Checks if a key has been released.

Parameters:
mKey The ID code of the key you're interested in
bForce 'true' to bypass focus (see set_focus())
Returns:
'true' if the key has been released
Note:
Happens just when the key is released.

Definition at line 254 of file input.cpp.

bool input::manager::mouse_is_doubleclicked ( mouse::button  mID  )  const

Checks if a mouse button has been double clicked.

Parameters:
mID The ID code of the mouse button you're interested in
Returns:
'true' if the mouse button has been double clicked

Definition at line 292 of file input.cpp.

bool input::manager::mouse_is_down ( mouse::button  mID  )  const

Checks if a mouse button is being pressed.

Parameters:
mID The ID code of the mouse button you're interested in
Returns:
'true' if the mouse button is being pressed

Definition at line 267 of file input.cpp.

bool input::manager::mouse_is_down_long ( mouse::button  mID  )  const

Checks if a mouse button is being pressed for a long time.

Parameters:
mID The ID code of the mouse button you're interested in
Returns:
'true' if the mouse button is being pressed for a long time

Definition at line 272 of file input.cpp.

bool input::manager::mouse_is_pressed ( mouse::button  mID  )  const

Checks if a mouse button has been pressed.

Parameters:
mID The ID code of the mouse button you're interested in
Returns:
'true' if the mouse button has been pressed
Note:
Happens just when the mouse button is pressed.

Definition at line 282 of file input.cpp.

bool input::manager::mouse_is_released ( mouse::button  mID  )  const

Checks if a mouse button has been released.

Parameters:
mID The ID code of the mouse button you're interested in
Returns:
'true' if the mouse button has been released
Note:
Happens just when the mouse button is released.

Definition at line 287 of file input.cpp.

bool input::manager::mouse_last_dragged (  )  const

Checks if the mouse has just started beeing dragged.

Returns:
'true' if the mouse has just started beeing dragged

Definition at line 650 of file input.cpp.

manager& input::manager::operator= ( const manager mMgr  ) 

This class is non copiable.

void input::manager::register_event_manager ( utils::wptr< gui::event_manager pManager  ) 

Registers a new event manager that will listen to input events.

Parameters:
pManager The new event manager
Note:
There can be as many event managers connected to this input manager. If you need to remove one from the list, see remove_event_manager().

Definition at line 766 of file input.cpp.

void input::manager::set_doubleclick_time ( double  dDoubleClickTime  ) 

Sets the double click maximum time.

Parameters:
dDoubleClickTime 

Definition at line 598 of file input.cpp.

void input::manager::set_focus ( bool  bFocus,
gui::event_receiver pReceiver = nullptr 
)

Sets whether input should be stopped.

Parameters:
bFocus 'true' to stop inputs
pReceiver The event receiver that requires focus (if any)
Note:
This function is usefull if you need to implement an edit box : the user can type letters binded to actions in the game, and you should prevent them from happening. So, you just have to call this function and use the second argument of all input functions to force focus in your edit box.
Calling set_focus(false) doesn't immediately remove focus. You have to wait for the next update() call.

Definition at line 618 of file input.cpp.

void input::manager::set_long_press_delay ( double  dLongPressDelay  ) 

Sets the duration after which a key is considered as pressed for a long time.

Parameters:
dLongPressDelay The "long pressed" duration
Note:
This is used for key repeating for example.

Definition at line 735 of file input.cpp.

void input::manager::set_mouse_buffer_duration ( double  dMouseHistoryMaxLength  ) 

Sets the ammount of mouse movement to be buffered.

Parameters:
dMouseHistoryMaxLength The maximum buffer length (in seconds)
Note:
If you experience jerky mouse movement, you can try to increase this value (default : 0.1s).
On the contrary, if you feel your mouse is not responsive enough, try to decrease it.

Definition at line 608 of file input.cpp.

void input::manager::set_mouse_sensibility ( float  fMouseSensibility  ) 

Sets the mouse movement factor.

Parameters:
fMouseSensibility The new movement factor
Note:
Increase this parameter to make mouse controlled movement faster.

Definition at line 725 of file input.cpp.

bool input::manager::shift_is_pressed (  )  const

Checks if Shift is beeing pressed.

Returns:
'true' if Shift is beeing pressed

Definition at line 640 of file input.cpp.

void input::manager::unregister_event_manager ( utils::wptr< gui::event_manager pManager  ) 

Unregisters an event manager.

Parameters:
pManager The manager to unregister
Note:
For more details, see register_event_manager().

Definition at line 772 of file input.cpp.

void input::manager::update ( float  fDelta  ) 

Updates input (keyboard and mouse).

Definition at line 302 of file input.cpp.

bool input::manager::wheel_is_rolled (  )  const

Checks if the mouse wheel has been rolled.

Returns:
'true' if the mouse wheel has been rolled

Definition at line 297 of file input.cpp.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on Tue Jan 1 21:58:13 2013 for gui by  doxygen 1.6.1