ScummVM API documentation
mouse_input.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef QDENGINE_SYSTEM_INPUT_MOUSE_INPUT_H
23#define QDENGINE_SYSTEM_INPUT_MOUSE_INPUT_H
24
25
26namespace QDEngine {
27
30public:
33
35
38 typedef bool (*event_handler_t)(int x, int y, int flags);
39
56 };
57
60 ID_BUTTON_LEFT,
61 ID_BUTTON_MIDDLE,
62 ID_BUTTON_RIGHT
63 };
64
67 event_handler_t old_h = _event_handlers[ev];
68 _event_handlers[ev] = h;
69 return old_h;
70 }
71
73 bool handle_event(mouseEvent ev, int x, int y, int flags);
74
76 bool check_event(mouseEvent ev) const {
77 if (_events & (1 << ev)) return true;
78 else return false;
79 }
81 bool is_event_active(mouseEvent ev) const {
82 if (_active_events & (1 << ev)) return true;
83 else return false;
84 }
86 bool clear_events() {
87 _events = _active_events = 0;
88 return true;
89 }
92 _events &= ~(1 << ev);
93 return true;
94 }
97 _active_events &= ~(1 << ev);
98 return true;
99 }
102 _events |= (1 << ev);
103 _active_events |= (1 << ev);
104 }
105
107 int mouse_x() const {
108 return _mouse_x;
109 }
111 int mouse_y() const {
112 return _mouse_y;
113 }
114
117 return (_button_status & (1 << bt_id));
118 }
119
122
125 return EV_LEFT_DOWN;
126 }
129 return EV_MOUSE_MOVE;
130 }
131
132private:
134 int _events;
136 int _active_events;
137
139 int _button_status;
140
142 int _mouse_x;
144 int _mouse_y;
145
147 event_handler_t _event_handlers[EV_MOUSE_MOVE + 1];
148};
149
150} // namespace QDEngine
151
152#endif // QDENGINE_SYSTEM_INPUT_MOUSE_INPUT_H
Обработчик мыши.
Definition: mouse_input.h:29
bool handle_event(mouseEvent ev, int x, int y, int flags)
Обработка события.
bool is_event_active(mouseEvent ev) const
Возвращает true, если событие происходило с момента вызова clear_events().
Definition: mouse_input.h:81
event_handler_t set_event_handler(mouseEvent ev, event_handler_t h)
Установка обработчика события.
Definition: mouse_input.h:66
static mouseEvent last_event_ID()
Возвращает идентификатор последнего события.
Definition: mouse_input.h:128
mouseButtonID
Идентификаторы кнопок.
Definition: mouse_input.h:59
int mouse_y() const
Возвращает вертикальную координату мышиного курсора.
Definition: mouse_input.h:111
void toggle_event(mouseEvent ev)
Помечает событие как произошедшее.
Definition: mouse_input.h:101
int mouse_x() const
Возвращает горизонтальную координату мышиного курсора.
Definition: mouse_input.h:107
bool clear_event(mouseEvent ev)
Очищает информацию о событии ev.
Definition: mouse_input.h:91
bool is_pressed(mouseButtonID bt_id)
Возвращает true, если кнопка bt_id нажата.
Definition: mouse_input.h:116
mouseEvent
События.
Definition: mouse_input.h:41
@ EV_RIGHT_UP
Отжатие правой кнопки.
Definition: mouse_input.h:53
@ EV_RIGHT_DBLCLICK
Двойное нажатие правой кнопки.
Definition: mouse_input.h:49
@ EV_LEFT_DBLCLICK
Двойное нажатие левой кнопки.
Definition: mouse_input.h:47
@ EV_LEFT_DOWN
Нажатие левой кнопки.
Definition: mouse_input.h:43
@ EV_LEFT_UP
Отжатие левой кнопки.
Definition: mouse_input.h:51
@ EV_RIGHT_DOWN
Нажатие правой кнопки.
Definition: mouse_input.h:45
@ EV_MOUSE_MOVE
Перемещение мыши.
Definition: mouse_input.h:55
static mouseDispatcher * instance()
Возвращает обработчик по-умолчанию.
static mouseEvent first_event_ID()
Возвращает идентификатор первого события.
Definition: mouse_input.h:124
bool(* event_handler_t)(int x, int y, int flags)
Обработчик событий.
Definition: mouse_input.h:38
bool deactivate_event(mouseEvent ev)
Помечает событие, как непроисходившее.
Definition: mouse_input.h:96
bool clear_events()
Очищает информацию о событиях.
Definition: mouse_input.h:86
bool check_event(mouseEvent ev) const
Возвращает true, если событие происходило и пока не обработано.
Definition: mouse_input.h:76
Базовый класс для игровых ресурсов.
Definition: console.h:28