-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathevents.hpp
91 lines (68 loc) · 2.42 KB
/
events.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
This file is part of Heroes of Wesnoth.
Copyright (C) 2007, 2008, 2009 Jon Ander Peñalba <[email protected]>
Heroes of Wesnoth is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3 as
published by the Free Software Foundation.
Heroes of Wesnoth is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Heroes of Wesnoth. If not, see <http://www.gnu.org/licenses/>
*/
/// @file
/// The Events class and global events variables.
/// @author Jonan
#ifndef EVENTS_HPP
#define EVENTS_HPP
#include <SDL/SDL_keysym.h>
#include <SDL/SDL_mouse.h>
#include "util.hpp"
struct SDL_Rect;
struct SDL_Surface;
union SDL_Event;
/// All functions related to events.
namespace events_engine {
/// Mouse info
enum {MOUSE_X, MOUSE_Y, MOUSE_BUTTON};
/// Types of cursors
enum {NO_CURSOR,
NORMAL_CURSOR,
ATTACK_CURSOR,
MOVE_CURSOR,
ILLEGAL_CURSOR,
WAIT_CURSOR,
NUM_CURSORS};
/// Event control.
/// Tells you when has an event has occurred. This event can be a system event (resize,
/// close, redraw, etc.) or user event (keyboard or mouse). Once the event has occurred,
/// gives you complete information about it.
class Events {
public:
static Events* getInstance(void); // Singleton pattern constructor
~Events(void); // Destructor
/// Sets the cursor's type.
/// @param[in] type Type of cursor.
void setCursorType(const int type) {cursor_type = type;}
/// Reads the input from mouse, keyboard and system.
/// Gets the input and stores the information obtained
/// (must be called before any other events function).
void readInput(void);
/// Draws the mouse on the screen.
/// It's called every time the screen is updated,
/// so it should only be called from graphics.
void drawMouse(void);
private:
Events(void); // Constructor
SDL_Event *event;
SDL_Rect *mouse_position;
SDL_Surface *cursor_image[NUM_CURSORS];
int cursor_type;
DISALLOW_COPY_AND_ASSIGN(Events);
};
extern Events *input;
extern bool *keys; // Stores the state of each keyboard key
extern int *mouse; // Stores all the mouse info
} // namespace events_engine
#endif // EVENTS_HPP