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 #include "backends/platform/sdl/sdl-sys.h"
24 
25 #include "EventsBuffer.h"
26 
27 namespace CEKEYS {
28 
simulateKey(GUI::Key * key,bool pushed)29 bool EventsBuffer::simulateKey(GUI::Key *key, bool pushed) {
30 	SDL_Event ev = {0};
31 
32 	if (!key->keycode())
33 		key->setKey(key->ascii(), key->ascii());
34 	else if (!key->ascii())
35 		key->setKey(key->keycode());
36 
37 	ev.type = (pushed ? SDL_KEYDOWN : SDL_KEYUP);
38 	ev.key.keysym.unicode = (SDLMod)key->flags();   // HACK: put the flags into the unused unicode field
39 	ev.key.keysym.sym = (SDLKey)key->keycode();
40 	ev.key.keysym.mod = KMOD_RESERVED;
41 	return (SDL_PushEvent(&ev) == 0);
42 }
43 
simulateMouseMove(int x,int y)44 bool EventsBuffer::simulateMouseMove(int x, int y) {
45 	SDL_Event ev = {0};
46 
47 	ev.type = SDL_MOUSEMOTION;
48 	ev.motion.x = x;
49 	ev.motion.y = y;
50 	return (SDL_PushEvent(&ev) == 0);
51 }
52 
simulateMouseLeftClick(int x,int y,bool pushed)53 bool EventsBuffer::simulateMouseLeftClick(int x, int y, bool pushed) {
54 	SDL_Event ev = {0};
55 	static bool state = false;
56 
57 	if (pushed == state) return 0;
58 	state = pushed;
59 	ev.type = (pushed ? SDL_MOUSEBUTTONDOWN : SDL_MOUSEBUTTONUP);
60 	ev.button.button = SDL_BUTTON_LEFT;
61 	ev.button.x = x;
62 	ev.button.y = y;
63 	return (SDL_PushEvent(&ev) == 0);
64 }
65 
simulateMouseRightClick(int x,int y,bool pushed)66 bool EventsBuffer::simulateMouseRightClick(int x, int y, bool pushed) {
67 	SDL_Event ev = {0};
68 	static bool state = false;
69 
70 	if (pushed == state) return 0;
71 	state = pushed;
72 	ev.type = (pushed ? SDL_MOUSEBUTTONDOWN : SDL_MOUSEBUTTONUP);
73 	ev.button.button = SDL_BUTTON_RIGHT;
74 	ev.button.x = x;
75 	ev.button.y = y;
76 	return (SDL_PushEvent(&ev) == 0);
77 }
78 }
79