ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
sys_events.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 AGS_ENGINE_AC_SYS_EVENTS_H
23 #define AGS_ENGINE_AC_SYS_EVENTS_H
24 
25 #include "common/events.h"
26 #include "ags/shared/ac/keycode.h"
27 
28 namespace AGS3 {
29 
30 // Keyboard input handling
31 //
32 // avoid including SDL.h here, at least for now, because that leads to conflicts with allegro
33 union SDL_Event;
34 
35 // Tells if key event refers to one of the mod-keys
36 inline bool is_mod_key(const Common::KeyState &ks) {
37  return ks.keycode == Common::KEYCODE_LCTRL || ks.keycode == Common::KEYCODE_RCTRL ||
38  ks.keycode == Common::KEYCODE_LALT || ks.keycode == Common::KEYCODE_RALT ||
39  ks.keycode == Common::KEYCODE_LSHIFT || ks.keycode == Common::KEYCODE_RSHIFT ||
40  ks.keycode == Common::KEYCODE_MODE;
41 }
42 
43 // Converts mod key into merged mod (left & right) for easier handling
44 inline int make_merged_mod(int mod) {
45  int m_mod = 0;
46  if ((mod & Common::KBD_CTRL) != 0) m_mod |= Common::KBD_CTRL;
47  if ((mod & Common::KBD_SHIFT) != 0) m_mod |= Common::KBD_SHIFT;
48  if ((mod & Common::KBD_ALT) != 0) m_mod |= Common::KBD_ALT;
49  // what about Common::KBD_GUI, and there's also some Common::KEYCODE_MODE?
50  return m_mod;
51 }
52 
53 // Converts ScummVM key event to eAGSKeyCode if it is in proper range,
54 // see comments to eAGSKeyCode for details.
55 // Optionally works in bacward compatible mode (old_keyhandle)
56 extern KeyInput ags_keycode_from_scummvm(const Common::Event &event, bool old_keyhandle);
57 
58 // Tells if there are any buffered key events
59 extern bool ags_keyevent_ready();
60 // Queries for the next key event in buffer; returns uninitialized data if none was queued
61 extern Common::Event ags_get_next_keyevent();
62 // Tells if the key is currently down, provided AGS key.
63 // NOTE: for particular script codes this function returns positive if either of two keys are down.
64 extern int ags_iskeydown(eAGSKeyCode ags_key);
65 // Simulates key press with the given AGS key
66 extern void ags_simulate_keypress(eAGSKeyCode ags_key, bool old_keyhandle);
67 
68 
69 // Mouse input handling
70 //
71 // Tells if the mouse button is currently down
72 extern bool ags_misbuttondown(eAGSMouseButton but);
73 // Returns last "clicked" mouse button
74 extern eAGSMouseButton ags_mgetbutton();
75 // Returns recent relative mouse movement; resets accumulated values
76 extern void ags_mouse_acquire_relxy(int &x, int &y);
77 // Updates mouse cursor position in game
78 extern void ags_domouse();
79 // Returns -1 for wheel down and +1 for wheel up
80 // TODO: introduce constants for this
81 extern int ags_check_mouse_wheel();
82 
83 // Other input utilities
84 //
85 // Clears buffered keypresses and mouse clicks;
86 // resets current key/mb states
87 void ags_clear_input_state();
88 // Clears buffered keypresses and mouse clicks, if any;
89 // does NOT reset current key/mb states
90 void ags_clear_input_buffer();
91 // Clears buffered mouse movement
92 void ags_clear_mouse_movement();
93 // Halts execution until any user input
94 // TODO: seriously not a good design, replace with event listening
95 extern void ags_wait_until_keypress();
96 
97 
98 // Events.
99 //
100 
101 // Set engine callback for when quit event is received by the backend.
102 extern void sys_evt_set_quit_callback(void(*proc)(void));
103 // Set engine callback for when input focus is received or lost by the window.
104 extern void sys_evt_set_focus_callbacks(void(*switch_in)(void), void(*switch_out)(void));
105 
106 // Process all events in the backend's queue.
107 extern void sys_evt_process_pending(void);
108 // Flushes system events following window initialization.
109 void sys_flush_events(void);
110 
111 } // namespace AGS3
112 
113 #endif
KeyCode keycode
Definition: keyboard.h:299
Definition: events.h:199
Definition: keyboard.h:294
Definition: ags.h:40