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 BACKEND_EVENTS_SDL_LEGACY_H
24 #define BACKEND_EVENTS_SDL_LEGACY_H
25 
26 #include "backends/events/sdl/sdl-events.h"
27 
28 // multiplier used to increase resolution for keyboard/joystick mouse
29 #define MULTIPLIER 16
30 
31 class LegacySdlEventSource : public SdlEventSource {
32 public:
33 	LegacySdlEventSource();
34 
35 	bool pollEvent(Common::Event &event) override;
36 
37 	void checkScreenChange();
38 
39 protected:
40 	/** @name Keyboard mouse emulation
41 	 * Disabled by fingolfin 2004-12-18.
42 	 * I am keeping the rest of the code in for now, since the joystick
43 	 * code (or rather, "hack") uses it, too.
44 	 */
45 	//@{
46 
47 	struct KbdMouse {
48 		int32 x, y;
49 		int16 x_vel, y_vel, x_max, y_max, x_down_count, y_down_count, joy_x, joy_y;
50 		uint32 last_time, delay_time, x_down_time, y_down_time;
51 		bool modifier;
52 	};
53 	KbdMouse _km;
54 
55 	virtual void updateKbdMouse();
56 	virtual bool handleKbdMouse(Common::Event &event);
57 
58 	//@}
59 
60 	bool handleMouseMotion(SDL_Event &ev, Common::Event &event) override;
61 	bool handleMouseButtonDown(SDL_Event &ev, Common::Event &event) override;
62 	bool handleMouseButtonUp(SDL_Event &ev, Common::Event &event) override;
63 	bool handleJoyAxisMotion(SDL_Event &ev, Common::Event &event) override;
64 
65 #if SDL_VERSION_ATLEAST(2, 0, 0)
66 	bool handleControllerButton(const SDL_Event &ev, Common::Event &event, bool buttonUp) override;
67 	bool handleControllerAxisMotion(const SDL_Event &ev, Common::Event &event) override;
68 #endif
69 
70 	/**
71 	 * Update the virtual mouse according to a joystick or game controller axis position change
72 	 */
73 	virtual bool handleAxisToMouseMotion(int16 xAxis, int16 yAxis);
74 
75 	/**
76 	 * Compute the virtual mouse movement speed factor according to the 'kbdmouse_speed' setting.
77 	 * The speed factor is scaled with the display size.
78 	 */
79 	int16 computeJoystickMouseSpeedFactor() const;
80 
81 	/**
82 	 * Resets keyboard emulation after a video screen change
83 	 */
84 	void resetKeyboardEmulation(int16 x_max, int16 y_max);
85 
86 };
87 
88 #endif
89