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
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef AGS_ENGINE_AC_SYS_EVENTS_H
24 #define AGS_ENGINE_AC_SYS_EVENTS_H
25 
26 #include "common/events.h"
27 #include "ags/shared/ac/keycode.h"
28 
29 namespace AGS3 {
30 
31 // AGS own mouse button codes
32 // TODO: these were internal button codes, but AGS script uses different ones,
33 // which start with Left=1, and make more sense (0 is easier to use as "no value").
34 // Must research if there are any dependencies to these internal values, and if not,
35 // then just replace these matching script ones!
36 // UPD: even plugin API seem to match script codes and require remap to internals.
37 // UPD: or use SDL constants in the engine, but make conversion more visible by using a function.
38 enum eAGSMouseButton {
39 	MouseNone = -1,
40 	MouseLeft = 0,
41 	MouseRight = 1,
42 	MouseMiddle = 2
43 };
44 
45 
46 // Keyboard input handling
47 //
48 // avoid including SDL.h here, at least for now, because that leads to conflicts with allegro
49 union SDL_Event;
50 
51 // Tells if key event refers to one of the mod-keys
is_mod_key(const Common::KeyState & ks)52 inline bool is_mod_key(const Common::KeyState &ks) {
53 	return ks.keycode == Common::KEYCODE_LCTRL || ks.keycode == Common::KEYCODE_RCTRL ||
54 	       ks.keycode == Common::KEYCODE_LALT || ks.keycode == Common::KEYCODE_RALT ||
55 	       ks.keycode == Common::KEYCODE_LSHIFT || ks.keycode == Common::KEYCODE_RSHIFT ||
56 	       ks.keycode == Common::KEYCODE_MODE;
57 }
58 
59 // Converts mod key into merged mod (left & right) for easier handling
make_merged_mod(int mod)60 inline int make_merged_mod(int mod) {
61 	int m_mod = 0;
62 	if ((mod & Common::KBD_CTRL) != 0) m_mod |= Common::KBD_CTRL;
63 	if ((mod & Common::KBD_SHIFT) != 0) m_mod |= Common::KBD_SHIFT;
64 	if ((mod & Common::KBD_ALT) != 0) m_mod |= Common::KBD_ALT;
65 	// what about Common::KBD_GUI, and there's also some Common::KEYCODE_MODE?
66 	return m_mod;
67 }
68 
69 extern KeyInput ags_keycode_from_scummvm(const Common::Event &event);
70 
71 // Tells if there are any buffered key events
72 extern bool ags_keyevent_ready();
73 // Queries for the next key event in buffer; returns uninitialized data if none was queued
74 extern Common::Event ags_get_next_keyevent();
75 // Tells if the key is currently down, provided AGS key;
76 // Returns positive value if it's down, 0 if it's not, negative value if the key code is not supported.
77 // NOTE: for particular script codes this function returns positive if either of two keys are down.
78 extern int ags_iskeydown(eAGSKeyCode ags_key);
79 // Simulates key press with the given AGS key
80 extern void ags_simulate_keypress(eAGSKeyCode ags_key);
81 
82 
83 // Mouse input handling
84 //
85 // Tells if the mouse button is currently down
86 extern bool ags_misbuttondown(int but);
87 // Returns mouse button code
88 extern int  ags_mgetbutton();
89 // Returns recent relative mouse movement
90 extern void ags_mouse_get_relxy(int &x, int &y);
91 // Updates mouse cursor position in game
92 extern void ags_domouse(int what);
93 // Returns -1 for wheel down and +1 for wheel up
94 // TODO: introduce constants for this
95 extern int  ags_check_mouse_wheel();
96 
97 // Other input utilities
98 //
99 // Clears buffered keypresses and mouse clicks;
100 // resets current key/mb states
101 void ags_clear_input_state();
102 // Clears buffered keypresses and mouse clicks, if any;
103 // does NOT reset current key/mb states
104 void ags_clear_input_buffer();
105 // Clears buffered mouse movement
106 void ags_clear_mouse_movement();
107 // Halts execution until any user input
108 // TODO: seriously not a good design, replace with event listening
109 extern void ags_wait_until_keypress();
110 
111 
112 // Events.
113 //
114 
115 // Set engine callback for when quit event is received by the backend.
116 extern void sys_evt_set_quit_callback(void(*proc)(void));
117 // Set engine callback for when input focus is received or lost by the window.
118 extern void sys_evt_set_focus_callbacks(void(*switch_in)(void), void(*switch_out)(void));
119 
120 // Process single event.
121 //extern void sys_evt_process_one(const Common::Event &event);
122 // Process all events in the backend's queue.
123 extern void sys_evt_process_pending(void);
124 
125 } // namespace AGS3
126 
127 #endif
128