Skip to content
This repository has been archived by the owner on Feb 19, 2018. It is now read-only.

Input Handler

Andrés edited this page Mar 20, 2015 · 6 revisions

###Overview Input Handler class simplifies the standard mouse & keyboard input of allegro

Name Version Header Implementation
Input Handler 0.7.6 input_handler.h input_handler.cpp

###Definitions

  • enum mouse_button{primary,secondary,wheel} enumeration intended to represent the standard 3 buttons of a mouse (currently unused)

###Variables Private

  • function<void(int,unsigned int,unsigned int)> click_mouse callback function to handle mouse clicks events, the arguments are button number ,mouse position x, and mouse position y

  • function<void(int)> key_pressed callback function to handle key events, argument is id of pressed key

Note that these are c++11 callback functions, from the library functional

  • bool active if the input handler is active or not, if this value is false, all the events updates will not be called (other methods like is_pressed and get_mouse_position will still work)

###Contructors

  • input_handler() default constructor

  • input_handler(ALLEGRO_EVENT_QUEUE *event_queue,function<void(int,unsigned int,unsigned int)> click_mouse,function<void(int)> key_pressed) full constructor, with event_queue to use for mouse & keyboard events and the 2 callback functions, this constructor will install keyboard and mouse to be used with allegro

###Destructor

  • ~input_handler() uninstall mouse and keyboard, so it will be impossible to use them until al_instal_X is called again or a new input_handler is defined

###Methods

  • void set_active(bool active) will set the active value

  • bool is_active() const will return true if the handler is active

  • pair<unsigned int,unsigned int> get_mouse_position() const returns current mouse position (updating mouse information)

  • bool is_pressed(int keycode) const return true if the key with given keycode (Allegro keycode) is being pressed

  • void update(const ALLEGRO_EVENT &event) const will check if given event is a mouse or a keyboard event, calling the function with the necessary events

  • void set_functions(function<void(int,unsigned int,unsigned int)> click_mouse,function<void(int)> key_pressed) will change the click_mouse and key_pressed callback functions if are callable

  • bool check() const will check class is working properly, checking if all callback functions are callable (returns false if there is any problem)

DCmC Wiki 0.7.6

Clone this wiki locally