Added mouse movement and click support
This commit is contained in:
parent
5c90d15869
commit
52acb4044c
3 changed files with 101 additions and 3 deletions
|
@ -8,8 +8,10 @@
|
|||
#include <map>
|
||||
#include <GL/glut.h>
|
||||
|
||||
#include "types.h"
|
||||
|
||||
/// Handles the key events from glut and keep the status of keys up to date.
|
||||
|
||||
/// Handles the key and mouse events from glut and keep their status up to date.
|
||||
/// "Static class"
|
||||
class KeyStateManager {
|
||||
public:
|
||||
|
@ -21,16 +23,34 @@ public:
|
|||
static bool is_key_pressed(unsigned char key);
|
||||
static bool is_special_key_pressed(int key);
|
||||
|
||||
static bool is_mouse_button_pressed(int mouse_button);
|
||||
|
||||
/// Updates and returns the movement of the mouse.
|
||||
/// \param update If true, updates the mouse delta that will be returned
|
||||
/// \return Updated displacement on each axis between the two last updates.
|
||||
static const Vec2i& get_mouse_delta(bool update = false);
|
||||
|
||||
// Glut callbacks for input events
|
||||
static void key_press(unsigned char event_key, int mouse_x, int mouse_y);
|
||||
static void key_up(unsigned char event_key, int mouse_x, int mouse_y);
|
||||
static void special_key_press(int event_key, int mouse_x, int mouse_y);
|
||||
static void special_key_up(int event_key, int mouse_x, int mouse_y);
|
||||
|
||||
static void mouse_click(int mouse_button, int button_state, int mouse_x, int mouse_y);
|
||||
/// Accumulates the movements of the mouse
|
||||
static void mouse_movement(int mouse_x, int mouse_y);
|
||||
|
||||
private:
|
||||
// The maps are used to keep track of the keys which were pressed or released during runtime.
|
||||
static std::map<unsigned char,bool> ascii_keys_status;
|
||||
static std::map<int,bool> special_keys_status;
|
||||
static std::map<int,bool> mouse_button_status;
|
||||
|
||||
// Updated by callback
|
||||
static Vec2i current_mouse_delta;
|
||||
// Updated on user request
|
||||
static Vec2i last_mouse_delta;
|
||||
static Vec2i last_mouse_position;
|
||||
|
||||
// These functions are called by *_press and *_up to update their values
|
||||
static void update_key(unsigned char event_key, bool new_status);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue