diff options
Diffstat (limited to 'backends/events')
-rw-r--r-- | backends/events/gp2xsdl/gp2xsdl-events.cpp | 11 | ||||
-rw-r--r-- | backends/events/gp2xsdl/gp2xsdl-events.h | 3 | ||||
-rw-r--r-- | backends/events/gph/gph-events.cpp | 42 | ||||
-rw-r--r-- | backends/events/openpandora/op-events.h | 2 | ||||
-rw-r--r-- | backends/events/webossdl/webossdl-events.cpp | 241 | ||||
-rw-r--r-- | backends/events/webossdl/webossdl-events.h | 44 |
6 files changed, 326 insertions, 17 deletions
diff --git a/backends/events/gp2xsdl/gp2xsdl-events.cpp b/backends/events/gp2xsdl/gp2xsdl-events.cpp index 91feb2b447..86d4de384f 100644 --- a/backends/events/gp2xsdl/gp2xsdl-events.cpp +++ b/backends/events/gp2xsdl/gp2xsdl-events.cpp @@ -18,22 +18,15 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * $URL$ - * $Id$ - * */ #include "common/scummsys.h" -#if defined(GP2X) +#if defined(GP2X_OLD) #include "backends/events/gp2xsdl/gp2xsdl-events.h" -#if defined(GP2X) #include "backends/platform/gp2x/gp2x-hw.h" #include "backends/graphics/gp2xsdl/gp2xsdl-graphics.h" -#else -#include "backends/platform/gp2xwiz/gp2xwiz-hw.h" -#endif #include "backends/platform/sdl/sdl.h" @@ -88,7 +81,6 @@ enum { GP2XSdlEventSource::GP2XSdlEventSource() : _buttonStateL(false){ - } void GP2XSdlEventSource::SDLModToOSystemKeyFlags(SDLMod mod, Common::Event &event) { @@ -468,5 +460,4 @@ bool GP2XSdlEventSource::remapKey(SDL_Event &ev, Common::Event &event) { return false; } - #endif diff --git a/backends/events/gp2xsdl/gp2xsdl-events.h b/backends/events/gp2xsdl/gp2xsdl-events.h index 5bf472d3d8..0d74c1bcac 100644 --- a/backends/events/gp2xsdl/gp2xsdl-events.h +++ b/backends/events/gp2xsdl/gp2xsdl-events.h @@ -18,9 +18,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * $URL$ - * $Id$ - * */ #if !defined(BACKEND_EVENTS_SDL_GP2X_H) && !defined(DISABLE_DEFAULT_EVENTMANAGER) diff --git a/backends/events/gph/gph-events.cpp b/backends/events/gph/gph-events.cpp index 05fd747605..d2b3483f84 100644 --- a/backends/events/gph/gph-events.cpp +++ b/backends/events/gph/gph-events.cpp @@ -26,7 +26,7 @@ * GPH: Device Specific Event Handling. */ -#if defined(GP2XWIZ) || defined(CAANOO) +#if defined(GPH_DEVICE) #include "backends/events/gph/gph-events.h" #include "backends/graphics/gph/gph-graphics.h" @@ -78,7 +78,9 @@ int BUTTON_STATE_L = false; BUTTON_SELECT = 62 }; -#else +#endif + +#if defined(GP2XWIZ) /* Wiz: Main Joystick Mappings */ enum { @@ -115,6 +117,42 @@ int BUTTON_STATE_L = false; #endif +#if defined(GP2X) + +enum { + /* DPAD/Stick */ + BUTTON_UP = 0, + BUTTON_UPLEFT = 1, + BUTTON_LEFT = 2, + BUTTON_DOWNLEFT = 3, + BUTTON_DOWN = 4, + BUTTON_DOWNRIGHT = 5, + BUTTON_RIGHT = 6, + BUTTON_UPRIGHT = 7, + /* Joystick Buttons */ + BUTTON_MENU = 8, // Start on F100 GP2X + BUTTON_SELECT = 9, + BUTTON_L = 10, + BUTTON_R = 11, + BUTTON_A = 12, + BUTTON_B = 13, + BUTTON_X = 14, + BUTTON_Y = 15, + BUTTON_VOLUP = 16, + BUTTON_VOLDOWN = 17, + BUTTON_CLICK = 18 +}; + +enum { + /* Unused Joystick Buttons on the GP2X */ + BUTTON_HOME = 51, + BUTTON_HOLD = 52, + BUTTON_HELP = 53, + BUTTON_HELP2 = 54 +}; + +#endif + enum { /* Touchscreen TapMode */ TAPMODE_LEFT = 0, diff --git a/backends/events/openpandora/op-events.h b/backends/events/openpandora/op-events.h index 4b13ef2105..9aa637992a 100644 --- a/backends/events/openpandora/op-events.h +++ b/backends/events/openpandora/op-events.h @@ -37,8 +37,6 @@ protected: bool _buttonStateL; bool remapKey(SDL_Event &ev, Common::Event &event); - -//private: bool handleMouseButtonDown(SDL_Event &ev, Common::Event &event); bool handleMouseButtonUp(SDL_Event &ev, Common::Event &event); }; diff --git a/backends/events/webossdl/webossdl-events.cpp b/backends/events/webossdl/webossdl-events.cpp new file mode 100644 index 0000000000..fd9628995d --- /dev/null +++ b/backends/events/webossdl/webossdl-events.cpp @@ -0,0 +1,241 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#ifdef WEBOS + +#include "common/scummsys.h" +#include "sys/time.h" +#include "time.h" + +#include "backends/events/webossdl/webossdl-events.h" +#include "gui/message.h" + +// Inidicates if gesture area is pressed down or not. +static bool gestureDown = false; + +// The timestamp when gesture area was pressed down. +static int gestureDownTime = 0; + +// The timestamp when screen was pressed down. +static int screenDownTime = 0; + +// The timestamp when a possible drag operation was triggered. +static int dragStartTime = 0; + +// The index of the motion pointer. +static int motionPtrIndex = -1; + +// The maximum horizontal motion during dragging (For tap recognition). +static int dragDiffX = 0; + +// The maximum vertical motion during dragging (For tap recognition). +static int dragDiffY = 0; + +// Indicates if we are in drag mode. +static bool dragging = false; + +// The current mouse position on the screen. +static int curX = 0, curY = 0; + +// The time (seconds after 1/1/1970) when program started. +static time_t programStartTime = time(0); + +/** + * Returns the number of passed milliseconds since program start. + * + * @return The number of passed milliseconds. + */ +static time_t getMillis() +{ + struct timeval tv; + gettimeofday(&tv, NULL); + return (time(0) - programStartTime) * 1000 + tv.tv_usec / 1000; +} + +/** + * WebOS devices only have a Shift key and a CTRL key. There is also an Alt + * key (the orange key) but this is already processed by WebOS to change the + * mode of the keys so ScummVM must not use this key as a modifier. Instead + * pressing down the gesture area is used as Alt key. + * + * @param mod The pressed key modifier as detected by SDL. + * @param event The ScummVM event to setup. + */ +void WebOSSdlEventSource::SDLModToOSystemKeyFlags(SDLMod mod, + Common::Event &event) { + event.kbd.flags = 0; + + if (mod & KMOD_SHIFT) + event.kbd.flags |= Common::KBD_SHIFT; + if (mod & KMOD_CTRL) + event.kbd.flags |= Common::KBD_CTRL; + if (gestureDown) + event.kbd.flags |= Common::KBD_ALT; +} + +/** + * Before calling the original SDL implementation this method checks if the + * gesture area is pressed down. + * + * @param ev The SDL event + * @param event The ScummVM event. + * @return True if event was processed, false if not. + */ +bool WebOSSdlEventSource::handleKeyDown(SDL_Event &ev, Common::Event &event) { + // Handle gesture area tap. + if (ev.key.keysym.sym == SDLK_WORLD_71) { + gestureDown = true; + gestureDownTime = getMillis(); + return true; + } + + // Call original SDL key handler. + return SdlEventSource::handleKeyDown(ev, event); +} + +/** + * Before calling the original SDL implementation this method checks if the + * gesture area has been released. + * + * @param ev The SDL event + * @param event The ScummVM event. + * @return True if event was processed, false if not. + */ +bool WebOSSdlEventSource::handleKeyUp(SDL_Event &ev, Common::Event &event) { + // Handle gesture area tap. + if (ev.key.keysym.sym == SDLK_WORLD_71) { + gestureDown = false; + return true; + } + + // Call original SDL key handler. + return SdlEventSource::handleKeyUp(ev, event); +} + +/** + * Handles mouse button press. + * + * @param ev The SDL event + * @param event The ScummVM event. + * @return True if event was processed, false if not. + */ +bool WebOSSdlEventSource::handleMouseButtonDown(SDL_Event &ev, Common::Event &event) { + if (motionPtrIndex == -1) { + motionPtrIndex = ev.button.which; + dragDiffX = 0; + dragDiffY = 0; + screenDownTime = getMillis(); + + // Start dragging when pressing the screen shortly after a tap. + if (getMillis() - dragStartTime < 250) { + dragging = true; + event.type = Common::EVENT_LBUTTONDOWN; + fillMouseEvent(event, curX, curY); + } + } + return true; +} + +/** + * Handles mouse button release. + * + * @param ev The SDL event + * @param event The ScummVM event. + * @return True if event was processed, false if not. + */ +bool WebOSSdlEventSource::handleMouseButtonUp(SDL_Event &ev, Common::Event &event) { + if (motionPtrIndex == ev.button.which) { + motionPtrIndex = -1; + + // When drag mode was active then simply send a mouse up event + if (dragging) + { + event.type = Common::EVENT_LBUTTONUP; + fillMouseEvent(event, curX, curY); + dragging = false; + return true; + } + + // When mouse was moved 5 pixels or less then emulate a mouse button + // click. + if (ABS(dragDiffX) < 6 && ABS(dragDiffY) < 6) + { + int duration = getMillis() - screenDownTime; + + // When screen was pressed for less than 500ms then emulate a + // left mouse click. + if (duration < 500) { + event.type = Common::EVENT_LBUTTONUP; + fillMouseEvent(event, curX, curY); + g_system->getEventManager()->pushEvent(event); + event.type = Common::EVENT_LBUTTONDOWN; + dragStartTime = getMillis(); + } + + // When screen was pressed for less than 1000ms then emulate a + // right mouse click. + else if (duration < 1000) { + event.type = Common::EVENT_RBUTTONUP; + fillMouseEvent(event, curX, curY); + g_system->getEventManager()->pushEvent(event); + event.type = Common::EVENT_RBUTTONDOWN; + } + + // When screen was pressed for more than 1000ms then emulate a + // middle mouse click. + else { + event.type = Common::EVENT_MBUTTONUP; + fillMouseEvent(event, curX, curY); + g_system->getEventManager()->pushEvent(event); + event.type = Common::EVENT_MBUTTONDOWN; + } + + } + } + return true; +} + +/** + * Handles mouse motion. + * + * @param ev The SDL event + * @param event The ScummVM event. + * @return True if event was processed, false if not. + */ +bool WebOSSdlEventSource::handleMouseMotion(SDL_Event &ev, Common::Event &event) { + if (ev.motion.which == motionPtrIndex) { + int screenX = g_system->getWidth(); + int screenY = g_system->getHeight(); + curX = MIN(screenX, MAX(0, curX + ev.motion.xrel)); + curY = MIN(screenY, MAX(0, curY + ev.motion.yrel)); + dragDiffX += ev.motion.xrel; + dragDiffY += ev.motion.yrel; + event.type = Common::EVENT_MOUSEMOVE; + fillMouseEvent(event, curX, curY); + } + return true; +} + +#endif diff --git a/backends/events/webossdl/webossdl-events.h b/backends/events/webossdl/webossdl-events.h new file mode 100644 index 0000000000..3a41111cf2 --- /dev/null +++ b/backends/events/webossdl/webossdl-events.h @@ -0,0 +1,44 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#if !defined(BACKEND_EVENTS_SDL_WEBOS_H) && !defined(DISABLE_DEFAULT_EVENTMANAGER) +#define BACKEND_EVENTS_SDL_WEBOS_H + +#include "backends/events/sdl/sdl-events.h" + +/** + * SDL events manager for WebOS + */ +class WebOSSdlEventSource : public SdlEventSource { +protected: + virtual void SDLModToOSystemKeyFlags(SDLMod mod, Common::Event &event); + virtual bool handleKeyDown(SDL_Event &ev, Common::Event &event); + virtual bool handleKeyUp(SDL_Event &ev, Common::Event &event); + virtual bool handleMouseButtonDown(SDL_Event &ev, Common::Event &event); + virtual bool handleMouseButtonUp(SDL_Event &ev, Common::Event &event); + virtual bool handleMouseMotion(SDL_Event &ev, Common::Event &event); +}; + +#endif |