From 3126b06600016893f85e492b645a0773847aeb39 Mon Sep 17 00:00:00 2001 From: Doron Rosenberg Date: Mon, 1 Aug 2011 12:01:22 -0700 Subject: WebOS: touchpad work to show menu --- backends/events/webossdl/webossdl-events.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/backends/events/webossdl/webossdl-events.cpp b/backends/events/webossdl/webossdl-events.cpp index 102eb5802e..acc54e0bd2 100644 --- a/backends/events/webossdl/webossdl-events.cpp +++ b/backends/events/webossdl/webossdl-events.cpp @@ -32,6 +32,7 @@ #include "backends/events/webossdl/webossdl-events.h" #include "gui/message.h" +#include "engines/engine.h" // Inidicates if gesture area is pressed down or not. static bool gestureDown = false; @@ -176,6 +177,15 @@ bool WebOSSdlEventSource::handleMouseButtonUp(SDL_Event &ev, Common::Event &even if (motionPtrIndex == ev.button.which) { motionPtrIndex = -1; + int screenY = g_system->getHeight(); + // 60% of the screen height for menu dialog + if (ABS(dragDiffY) >= ABS(screenY*0.6)) { + if (g_engine && !g_engine->isPaused()) { + g_engine->openMainMenuDialog(); + return true; + } + } + // When drag mode was active then simply send a mouse up event if (dragging) { -- cgit v1.2.3 From 0ceb7b4ccd89150e46f92545bf4bdbb070cede12 Mon Sep 17 00:00:00 2001 From: Doron Rosenberg Date: Thu, 4 Aug 2011 10:44:06 -0700 Subject: WebOS: touchpad virtual keyboard --- backends/events/webossdl/webossdl-events.cpp | 28 ++++++++++++++++++++++++---- configure | 2 +- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/backends/events/webossdl/webossdl-events.cpp b/backends/events/webossdl/webossdl-events.cpp index acc54e0bd2..00cbf39d08 100644 --- a/backends/events/webossdl/webossdl-events.cpp +++ b/backends/events/webossdl/webossdl-events.cpp @@ -33,6 +33,7 @@ #include "backends/events/webossdl/webossdl-events.h" #include "gui/message.h" #include "engines/engine.h" +#include "PDL.h" // Inidicates if gesture area is pressed down or not. static bool gestureDown = false; @@ -138,6 +139,16 @@ bool WebOSSdlEventSource::handleKeyUp(SDL_Event &ev, Common::Event &event) { return true; } + // handle virtual keyboard dismiss key + if (ev.key.keysym.sym == 24) { + int gblPDKVersion = PDL_GetPDKVersion(); + // check for correct PDK Version + if (gblPDKVersion >= 300) { + PDL_SetKeyboardState(PDL_FALSE); + return true; + } + } + // Call original SDL key handler. return SdlEventSource::handleKeyUp(ev, event); } @@ -178,11 +189,20 @@ bool WebOSSdlEventSource::handleMouseButtonUp(SDL_Event &ev, Common::Event &even motionPtrIndex = -1; int screenY = g_system->getHeight(); - // 60% of the screen height for menu dialog + + // 60% of the screen height for menu dialog/keyboard if (ABS(dragDiffY) >= ABS(screenY*0.6)) { - if (g_engine && !g_engine->isPaused()) { - g_engine->openMainMenuDialog(); - return true; + if (dragDiffY >= 0) { + int gblPDKVersion = PDL_GetPDKVersion(); + // check for correct PDK Version + if (gblPDKVersion >= 300) { + PDL_SetKeyboardState(PDL_TRUE); + } + } else { + if (g_engine && !g_engine->isPaused()) { + g_engine->openMainMenuDialog(); + return true; + } } } diff --git a/configure b/configure index d5e2345acb..e330722c9d 100755 --- a/configure +++ b/configure @@ -2395,7 +2395,7 @@ case $_backend in ;; webos) # There is no sdl-config in the WebOS PDK so we don't use find_sdlconfig here. - LIBS="$LIBS -lSDL" + LIBS="$LIBS -lSDL -lpdl" DEFINES="$DEFINES -DWEBOS" DEFINES="$DEFINES -DSDL_BACKEND" add_line_to_config_mk "SDL_BACKEND = 1" -- cgit v1.2.3 From 82a3cc0ac06e598e069ad207ab741cd7397df329 Mon Sep 17 00:00:00 2001 From: Doron Rosenberg Date: Thu, 4 Aug 2011 10:50:19 -0700 Subject: WebOS: fix indentation, make sure to return true when opening the keyboard --- backends/events/webossdl/webossdl-events.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/backends/events/webossdl/webossdl-events.cpp b/backends/events/webossdl/webossdl-events.cpp index 00cbf39d08..cec990e775 100644 --- a/backends/events/webossdl/webossdl-events.cpp +++ b/backends/events/webossdl/webossdl-events.cpp @@ -141,10 +141,10 @@ bool WebOSSdlEventSource::handleKeyUp(SDL_Event &ev, Common::Event &event) { // handle virtual keyboard dismiss key if (ev.key.keysym.sym == 24) { - int gblPDKVersion = PDL_GetPDKVersion(); - // check for correct PDK Version - if (gblPDKVersion >= 300) { - PDL_SetKeyboardState(PDL_FALSE); + int gblPDKVersion = PDL_GetPDKVersion(); + // check for correct PDK Version + if (gblPDKVersion >= 300) { + PDL_SetKeyboardState(PDL_FALSE); return true; } } @@ -191,20 +191,21 @@ bool WebOSSdlEventSource::handleMouseButtonUp(SDL_Event &ev, Common::Event &even int screenY = g_system->getHeight(); // 60% of the screen height for menu dialog/keyboard - if (ABS(dragDiffY) >= ABS(screenY*0.6)) { + if (ABS(dragDiffY) >= ABS(screenY*0.6)) { if (dragDiffY >= 0) { int gblPDKVersion = PDL_GetPDKVersion(); // check for correct PDK Version if (gblPDKVersion >= 300) { PDL_SetKeyboardState(PDL_TRUE); + return true; } } else { - if (g_engine && !g_engine->isPaused()) { - g_engine->openMainMenuDialog(); - return true; + if (g_engine && !g_engine->isPaused()) { + g_engine->openMainMenuDialog(); + return true; } - } - } + } + } // When drag mode was active then simply send a mouse up event if (dragging) -- cgit v1.2.3 From 28201a1e9d1825ea2b590288f06003a8ae7a7e00 Mon Sep 17 00:00:00 2001 From: Doron Rosenberg Date: Wed, 10 Aug 2011 17:44:48 -0700 Subject: WebOS: not handling keyboard dismiss in keydown breaks things --- backends/events/webossdl/webossdl-events.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/backends/events/webossdl/webossdl-events.cpp b/backends/events/webossdl/webossdl-events.cpp index cec990e775..01b2c1ea7f 100644 --- a/backends/events/webossdl/webossdl-events.cpp +++ b/backends/events/webossdl/webossdl-events.cpp @@ -120,6 +120,16 @@ bool WebOSSdlEventSource::handleKeyDown(SDL_Event &ev, Common::Event &event) { gestureDown = false; } + // handle virtual keyboard dismiss key + if (ev.key.keysym.sym == 24) { + int gblPDKVersion = PDL_GetPDKVersion(); + // check for correct PDK Version + if (gblPDKVersion >= 300) { + PDL_SetKeyboardState(PDL_FALSE); + return true; + } + } + // Call original SDL key handler. return SdlEventSource::handleKeyDown(ev, event); } -- cgit v1.2.3 From 10264f575b585b404ba8c7ca7c495f54b7424986 Mon Sep 17 00:00:00 2001 From: TomFrost Date: Sat, 24 Sep 2011 08:58:18 -0400 Subject: Git: Adding Komodo project files to .gitignore. --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 99902064ea..69ae2e099c 100644 --- a/.gitignore +++ b/.gitignore @@ -164,3 +164,6 @@ ScummVM.config ScummVM.creator ScummVM.files ScummVM.includes + +#Ignore Komodo IDE/Edit project files +*.komodoproject -- cgit v1.2.3 From 5143a0c7085bff3b4613a62970d9ed19e6ac91cb Mon Sep 17 00:00:00 2001 From: TomFrost Date: Sat, 24 Sep 2011 15:11:46 -0400 Subject: WebOS: Adding portdist folder to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 69ae2e099c..80adcb7551 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,7 @@ lib*.a /build /staging +/portdist /backends/platform/dc/gui /backends/platform/dc/graphics -- cgit v1.2.3 From c619c241dec00e5693e8ec83e6278a9978dc1ac5 Mon Sep 17 00:00:00 2001 From: TomFrost Date: Sat, 24 Sep 2011 15:12:27 -0400 Subject: WebOS: Enable scalers and Darwin compatibility. On Mac OS X (Darwin), there are minor differences in the 'sed' and 'install' tools that require slightly different usage. This distinction has been made in webos.mk, made possible by an additional flag in ./configure. --- backends/platform/webos/webos.mk | 17 +++++++++++++---- configure | 4 +++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/backends/platform/webos/webos.mk b/backends/platform/webos/webos.mk index 37223ac56c..20d79c0555 100644 --- a/backends/platform/webos/webos.mk +++ b/backends/platform/webos/webos.mk @@ -60,10 +60,19 @@ APP_ID = $(shell basename $(prefix)) APP_VERSION = $(shell printf "%d.%d.%02d%02d" $(VER_MAJOR) $(VER_MINOR) $(VER_PATCH) $(VER_PACKAGE)) DESTDIR ?= staging PORTDISTDIR ?= portdist +ifeq ($(HOST_COMPILER),Darwin) + SED_DASH_I = "-i \"\"" +else + SED_DASH_I = "-i" +endif install: all $(QUIET)$(INSTALL) -d "$(DESTDIR)$(prefix)" +ifeq ($(HOST_COMPILER),Darwin) + $(QUIET)$(INSTALL) -m 0644 "$(PATH_MOJO)/"* "$(DESTDIR)$(prefix)/" +else $(QUIET)$(INSTALL) -m 0644 -t "$(DESTDIR)$(prefix)/" "$(PATH_MOJO)/"* +endif $(QUIET)$(INSTALL) -m 0755 "$(PATH_MOJO)/start" "$(DESTDIR)$(prefix)/" $(QUIET)$(INSTALL) -d "$(DESTDIR)$(bindir)" $(QUIET)$(INSTALL) -c -m 755 "./$(EXECUTABLE)" "$(DESTDIR)$(bindir)/$(EXECUTABLE)" @@ -77,12 +86,12 @@ ifdef DYNAMIC_MODULES $(QUIET)$(INSTALL) -c -m 644 $(PLUGINS) "$(DESTDIR)$(libdir)/" $(QUIET)$(STRIP) "$(DESTDIR)$(libdir)/"* endif - $(QUIET)sed -i s/'APP_VERSION'/'$(APP_VERSION)'/ "$(DESTDIR)$(prefix)/appinfo.json" - $(QUIET)sed -i s/'APP_ID'/'$(APP_ID)'/ "$(DESTDIR)$(prefix)/appinfo.json" + $(QUIET)sed $(SED_DASH_I) s/'APP_VERSION'/'$(APP_VERSION)'/ "$(DESTDIR)$(prefix)/appinfo.json" + $(QUIET)sed $(SED_DASH_I) s/'APP_ID'/'$(APP_ID)'/ "$(DESTDIR)$(prefix)/appinfo.json" ifneq (,$(findstring -beta,$(APP_ID))) - $(QUIET)sed -i s/'APP_TITLE'/'ScummVM Beta'/ "$(DESTDIR)$(prefix)/appinfo.json" + $(QUIET)sed $(SED_DASH_I) s/'APP_TITLE'/'ScummVM Beta'/ "$(DESTDIR)$(prefix)/appinfo.json" else - $(QUIET)sed -i s/'APP_TITLE'/'ScummVM'/ "$(DESTDIR)$(prefix)/appinfo.json" + $(QUIET)sed $(SED_DASH_I) s/'APP_TITLE'/'ScummVM'/ "$(DESTDIR)$(prefix)/appinfo.json" endif uninstall: diff --git a/configure b/configure index 9a824b97ed..914690512b 100755 --- a/configure +++ b/configure @@ -2355,12 +2355,14 @@ if test -n "$_host"; then webos) _backend="webos" _port_mk="backends/platform/webos/webos.mk" - _build_scalers=no + _build_scalers=yes + _build_hq_scalers=no _timidity=no _mt32emu=no _seq_midi=no _vkeybd=no _keymapper=yes + add_line_to_config_mk "HOST_COMPILER = `uname`" ;; wii) _backend="wii" -- cgit v1.2.3 From f88191ae1e68e1ae6c371e068ea7b9beeb3618cf Mon Sep 17 00:00:00 2001 From: TomFrost Date: Sat, 24 Sep 2011 17:21:24 -0400 Subject: WebOS: Correct code convention and graphic errors. This is a mass commit for the following items: - Conversion of mixed and unaligned spaces/tabs to tabs - Moved static globals in webos_events to class members - Corrected variable naming convention to use underscores - Added a constructor to WebOSSdlEventSource to initialize variables. - Changed SDL getWidth and getHeight calls to getOverlayWidth and getOverlayHeight to support larger form factors (such as the HP TouchPad). - Removed unnecessary static getMillis() declaration and changed existing code to use the built-in getMillis(). --- backends/events/webossdl/webossdl-events.cpp | 144 +++++++++++---------------- backends/events/webossdl/webossdl-events.h | 26 +++++ 2 files changed, 84 insertions(+), 86 deletions(-) diff --git a/backends/events/webossdl/webossdl-events.cpp b/backends/events/webossdl/webossdl-events.cpp index 820efe25c5..76c4fd7976 100644 --- a/backends/events/webossdl/webossdl-events.cpp +++ b/backends/events/webossdl/webossdl-events.cpp @@ -35,43 +35,18 @@ #include "engines/engine.h" #include "PDL.h" -// Inidicates if gesture area is pressed down or not. -static bool gestureDown = false; - -// 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. + * Construct a new WebOSSdlEventSource. */ -static time_t getMillis() -{ - struct timeval tv; - gettimeofday(&tv, NULL); - return (time(0) - programStartTime) * 1000 + tv.tv_usec / 1000; +WebOSSdlEventSource::WebOSSdlEventSource() : + _gestureDown(false), + _screenDownTime(0), + _dragStartTime(0), + _motionPtrIndex(-1), + _dragDiffX(0), _dragDiffY(0), + _dragging(false), + _curX(0), _curY(0) { + } /** @@ -93,7 +68,7 @@ void WebOSSdlEventSource::SDLModToOSystemKeyFlags(SDLMod mod, event.kbd.flags |= Common::KBD_CTRL; // Holding down the gesture area emulates the ALT key - if (gestureDown) + if (_gestureDown) event.kbd.flags |= Common::KBD_ALT; } @@ -101,14 +76,14 @@ void WebOSSdlEventSource::SDLModToOSystemKeyFlags(SDLMod mod, * Before calling the original SDL implementation this method checks if the * gesture area is pressed down. * - * @param ev The SDL event + * @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; + _gestureDown = true; return true; } @@ -117,18 +92,18 @@ bool WebOSSdlEventSource::handleKeyDown(SDL_Event &ev, Common::Event &event) { // gesture tap AFTER the backward gesture event and not BEFORE (Like // WebOS 2). if (ev.key.keysym.sym == 27 || ev.key.keysym.sym == 229) { - gestureDown = false; + _gestureDown = false; } - // handle virtual keyboard dismiss key - if (ev.key.keysym.sym == 24) { - int gblPDKVersion = PDL_GetPDKVersion(); - // check for correct PDK Version - if (gblPDKVersion >= 300) { - PDL_SetKeyboardState(PDL_FALSE); - return true; - } - } + // handle virtual keyboard dismiss key + if (ev.key.keysym.sym == 24) { + int gblPDKVersion = PDL_GetPDKVersion(); + // check for correct PDK Version + if (gblPDKVersion >= 300) { + PDL_SetKeyboardState(PDL_FALSE); + return true; + } + } // Call original SDL key handler. return SdlEventSource::handleKeyDown(ev, event); @@ -138,14 +113,14 @@ bool WebOSSdlEventSource::handleKeyDown(SDL_Event &ev, Common::Event &event) { * Before calling the original SDL implementation this method checks if the * gesture area has been released. * - * @param ev The SDL event + * @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; + _gestureDown = false; return true; } @@ -166,22 +141,22 @@ bool WebOSSdlEventSource::handleKeyUp(SDL_Event &ev, Common::Event &event) { /** * Handles mouse button press. * - * @param ev The SDL event + * @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(); + if (_motionPtrIndex == -1) { + _motionPtrIndex = ev.button.which; + _dragDiffX = 0; + _dragDiffY = 0; + _screenDownTime = g_system->getMillis(); // Start dragging when pressing the screen shortly after a tap. - if (getMillis() - dragStartTime < 250) { - dragging = true; + if (g_system->getMillis() - _dragStartTime < 250) { + _dragging = true; event.type = Common::EVENT_LBUTTONDOWN; - processMouseEvent(event, curX, curY); + processMouseEvent(event, _curX, _curY); } } return true; @@ -190,19 +165,19 @@ bool WebOSSdlEventSource::handleMouseButtonDown(SDL_Event &ev, Common::Event &ev /** * Handles mouse button release. * - * @param ev The SDL event + * @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; + if (_motionPtrIndex == ev.button.which) { + _motionPtrIndex = -1; - int screenY = g_system->getHeight(); + int screenY = g_system->getOverlayHeight(); // 60% of the screen height for menu dialog/keyboard - if (ABS(dragDiffY) >= ABS(screenY*0.6)) { - if (dragDiffY >= 0) { + if (ABS(_dragDiffY) >= ABS(screenY*0.6)) { + if (_dragDiffY >= 0) { int gblPDKVersion = PDL_GetPDKVersion(); // check for correct PDK Version if (gblPDKVersion >= 300) { @@ -218,35 +193,33 @@ bool WebOSSdlEventSource::handleMouseButtonUp(SDL_Event &ev, Common::Event &even } // When drag mode was active then simply send a mouse up event - if (dragging) - { + if (_dragging) { event.type = Common::EVENT_LBUTTONUP; - processMouseEvent(event, curX, curY); - dragging = false; + processMouseEvent(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; + if (ABS(_dragDiffX) < 6 && ABS(_dragDiffY) < 6) { + int duration = g_system->getMillis() - _screenDownTime; // When screen was pressed for less than 500ms then emulate a // left mouse click. if (duration < 500) { event.type = Common::EVENT_LBUTTONUP; - processMouseEvent(event, curX, curY); + processMouseEvent(event, _curX, _curY); g_system->getEventManager()->pushEvent(event); event.type = Common::EVENT_LBUTTONDOWN; - dragStartTime = getMillis(); + _dragStartTime = g_system->getMillis(); } // When screen was pressed for less than 1000ms then emulate a // right mouse click. else if (duration < 1000) { event.type = Common::EVENT_RBUTTONUP; - processMouseEvent(event, curX, curY); + processMouseEvent(event, _curX, _curY); g_system->getEventManager()->pushEvent(event); event.type = Common::EVENT_RBUTTONDOWN; } @@ -255,11 +228,10 @@ bool WebOSSdlEventSource::handleMouseButtonUp(SDL_Event &ev, Common::Event &even // middle mouse click. else { event.type = Common::EVENT_MBUTTONUP; - processMouseEvent(event, curX, curY); + processMouseEvent(event, _curX, _curY); g_system->getEventManager()->pushEvent(event); event.type = Common::EVENT_MBUTTONDOWN; } - } } return true; @@ -268,20 +240,20 @@ bool WebOSSdlEventSource::handleMouseButtonUp(SDL_Event &ev, Common::Event &even /** * Handles mouse motion. * - * @param ev The SDL event + * @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; + if (ev.motion.which == _motionPtrIndex) { + int screenX = g_system->getOverlayWidth(); + int screenY = g_system->getOverlayHeight(); + _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; - processMouseEvent(event, curX, curY); + processMouseEvent(event, _curX, _curY); } return true; } diff --git a/backends/events/webossdl/webossdl-events.h b/backends/events/webossdl/webossdl-events.h index c925132d92..ad69fa27e4 100644 --- a/backends/events/webossdl/webossdl-events.h +++ b/backends/events/webossdl/webossdl-events.h @@ -29,7 +29,33 @@ * SDL events manager for WebOS */ class WebOSSdlEventSource : public SdlEventSource { +public: + WebOSSdlEventSource(); protected: + // Inidicates if gesture area is pressed down or not. + bool _gestureDown; + + // The timestamp when screen was pressed down. + uint32 _screenDownTime; + + // The timestamp when a possible drag operation was triggered. + uint32 _dragStartTime; + + // The index of the motion pointer. + int _motionPtrIndex; + + // The maximum horizontal motion during dragging (For tap recognition). + int _dragDiffX; + + // The maximum vertical motion during dragging (For tap recognition). + int _dragDiffY; + + // Indicates if we are in drag mode. + bool _dragging; + + // The current mouse position on the screen. + int _curX, _curY; + 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); -- cgit v1.2.3 From d7abbb523cbad1e8283a820907c24981ad6b019d Mon Sep 17 00:00:00 2001 From: TomFrost Date: Sun, 25 Sep 2011 12:06:06 -0400 Subject: WebOS: Change to multitouch control scheme. This is a near-rewrite of the WebOS event system to take advantage of multitouch, with which all WebOS devices are outfitted. This commit also marks full compatibility with the HP TouchPad, or any future tablet device without a hardware keyboard. Controls: - Left click: Single-tap once - Right click: Put one finger on screen, single-tap another - Middle click: Put two fingers on screen, single-tap another - Menu: Swipe two fingers down - Show keyboard: Swipe two fingers up - Touchpad Mode: - Swipe two fingers to the right to toggle - When off (default) mouse will move to the location tapped - When on, mouse will move relative to its current position - Autodrag Mode: - Swipe three fingers to the right to toggle - When on (default), touching the screen and holding still for a half-second will initiate a left-mouse button hold. Useful for games like COMI and FT. - When off (or on) a double-tap will initiate a left-mouse button hold. - Escape key: Swipe two fingers left - Space bar (pause): Swipe three fingers down --- backends/events/webossdl/webossdl-events.cpp | 314 ++++++++++++++++++++------- backends/events/webossdl/webossdl-events.h | 67 ++++-- 2 files changed, 284 insertions(+), 97 deletions(-) diff --git a/backends/events/webossdl/webossdl-events.cpp b/backends/events/webossdl/webossdl-events.cpp index 76c4fd7976..778f41dd7e 100644 --- a/backends/events/webossdl/webossdl-events.cpp +++ b/backends/events/webossdl/webossdl-events.cpp @@ -22,33 +22,16 @@ #ifdef WEBOS -// Allow use of stuff in -#define FORBIDDEN_SYMBOL_EXCEPTION_time_h - #include "common/scummsys.h" #include "common/system.h" -#include "sys/time.h" -#include "time.h" +#include "common/str.h" +#include "common/translation.h" #include "backends/events/webossdl/webossdl-events.h" #include "gui/message.h" #include "engines/engine.h" #include "PDL.h" -/** - * Construct a new WebOSSdlEventSource. - */ -WebOSSdlEventSource::WebOSSdlEventSource() : - _gestureDown(false), - _screenDownTime(0), - _dragStartTime(0), - _motionPtrIndex(-1), - _dragDiffX(0), _dragDiffY(0), - _dragging(false), - _curX(0), _curY(0) { - -} - /** * 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 @@ -76,7 +59,7 @@ void WebOSSdlEventSource::SDLModToOSystemKeyFlags(SDLMod mod, * Before calling the original SDL implementation this method checks if the * gesture area is pressed down. * - * @param ev The SDL event + * @param ev The SDL event * @param event The ScummVM event. * @return True if event was processed, false if not. */ @@ -113,7 +96,7 @@ bool WebOSSdlEventSource::handleKeyDown(SDL_Event &ev, Common::Event &event) { * Before calling the original SDL implementation this method checks if the * gesture area has been released. * - * @param ev The SDL event + * @param ev The SDL event * @param event The ScummVM event. * @return True if event was processed, false if not. */ @@ -141,23 +124,52 @@ bool WebOSSdlEventSource::handleKeyUp(SDL_Event &ev, Common::Event &event) { /** * Handles mouse button press. * - * @param ev The SDL event + * @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 = g_system->getMillis(); +bool WebOSSdlEventSource::handleMouseButtonDown(SDL_Event &ev, + Common::Event &event) { + _dragDiffX[ev.button.which] = 0; + _dragDiffY[ev.button.which] = 0; + _fingerDown[ev.button.which] = true; + _screenDownTime[ev.button.which] = g_system->getMillis(); - // Start dragging when pressing the screen shortly after a tap. - if (g_system->getMillis() - _dragStartTime < 250) { + if (ev.button.which == 0) { + // Do a click when the finger lifts unless we leave the range + _doClick = true; + // Queue up dragging if auto-drag mode is on + if (_autoDragMode) + _queuedDragTime = g_system->getMillis() + QUEUED_DRAG_DELAY; + // Turn drag mode on instantly for a double-tap + else if (g_system->getMillis() - _dragStartTime < 400) { _dragging = true; event.type = Common::EVENT_LBUTTONDOWN; processMouseEvent(event, _curX, _curY); } + // If we're not in touchpad mode, move the cursor to the tap + if (!_touchpadMode) { + int screenX = g_system->getOverlayWidth(); + int screenY = g_system->getOverlayHeight(); + _curX = MIN(screenX, MAX(0, 0 + ev.motion.x)); + _curY = MIN(screenY, MAX(0, 0 + ev.motion.y)); + // If we're already clicking, hold it until after the move. + if (event.type == Common::EVENT_LBUTTONDOWN) { + processMouseEvent(event, _curX, _curY); + g_system->getEventManager()->pushEvent(event); + } + // Move the mouse + event.type = Common::EVENT_MOUSEMOVE; + processMouseEvent(event, _curX, _curY); + } + // Watch for a double-tap-triggered drag + _dragStartTime = g_system->getMillis(); + } + // Kill any queued drag event if a second finger goes down + else if (ev.button.which == 1) { + if (_queuedDragTime > 0) + _queuedDragTime = 0; + _doClick = false; } return true; } @@ -165,74 +177,58 @@ bool WebOSSdlEventSource::handleMouseButtonDown(SDL_Event &ev, Common::Event &ev /** * Handles mouse button release. * - * @param ev The SDL event + * @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; - - int screenY = g_system->getOverlayHeight(); - - // 60% of the screen height for menu dialog/keyboard - if (ABS(_dragDiffY) >= ABS(screenY*0.6)) { - if (_dragDiffY >= 0) { - int gblPDKVersion = PDL_GetPDKVersion(); - // check for correct PDK Version - if (gblPDKVersion >= 300) { - PDL_SetKeyboardState(PDL_TRUE); - return true; - } - } else { - if (g_engine && !g_engine->isPaused()) { - g_engine->openMainMenuDialog(); - return true; - } - } - } - - // When drag mode was active then simply send a mouse up event - if (_dragging) { +bool WebOSSdlEventSource::handleMouseButtonUp(SDL_Event &ev, + Common::Event &event) { + // Only react if the finger hasn't been virtually lifted already + if (_fingerDown[ev.button.which]) { + // No matter what, if it's the first finger that's lifted when + // we're dragging, just lift the mouse button. + if (ev.button.which == 0 && _dragging) { event.type = Common::EVENT_LBUTTONUP; processMouseEvent(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 = g_system->getMillis() - _screenDownTime; - - // When screen was pressed for less than 500ms then emulate a - // left mouse click. - if (duration < 500) { + else { + // If it was the first finger and the click hasn't been + // canceled, it's a click. + if (ev.button.which == 0 && _doClick && + !_fingerDown[1] && !_fingerDown[2]) { event.type = Common::EVENT_LBUTTONUP; processMouseEvent(event, _curX, _curY); g_system->getEventManager()->pushEvent(event); event.type = Common::EVENT_LBUTTONDOWN; - _dragStartTime = g_system->getMillis(); + if (_queuedDragTime > 0) + _queuedDragTime = 0; } - // When screen was pressed for less than 1000ms then emulate a + // If the first finger's down and the second taps, it's a // right mouse click. - else if (duration < 1000) { + else if (ev.button.which == 1 && + _fingerDown[0] && _fingerDown[1] && !_fingerDown[2]) { event.type = Common::EVENT_RBUTTONUP; processMouseEvent(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 { + // If two fingers are down and a third taps, it's a middle + // click -- but lift the second finger so it doesn't register + // as a right click. + else if (ev.button.which == 2 && + _fingerDown[0] && _fingerDown[1]) { event.type = Common::EVENT_MBUTTONUP; processMouseEvent(event, _curX, _curY); g_system->getEventManager()->pushEvent(event); event.type = Common::EVENT_MBUTTONDOWN; + _fingerDown[1] = false; } } + // Officially lift the finger that was raised. + _fingerDown[ev.button.which] = false; } return true; } @@ -240,22 +236,178 @@ bool WebOSSdlEventSource::handleMouseButtonUp(SDL_Event &ev, Common::Event &even /** * Handles mouse motion. * - * @param ev The SDL event + * @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) { +bool WebOSSdlEventSource::handleMouseMotion(SDL_Event &ev, + Common::Event &event) { + if (_fingerDown[ev.motion.which]) { + _dragDiffX[ev.motion.which] += ev.motion.xrel; + _dragDiffY[ev.motion.which] += ev.motion.yrel; int screenX = g_system->getOverlayWidth(); int screenY = g_system->getOverlayHeight(); - _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; - processMouseEvent(event, _curX, _curY); + + switch (ev.motion.which) { + case 0: + // If our dragDiff goes too many pixels in either direction, + // kill the future click and any queued drag event. + if (_doClick && (ABS(_dragDiffX[0]) > 5 || + ABS(_dragDiffY[0]) > 5)) { + _doClick = false; + if (_queuedDragTime > 0) + _queuedDragTime = 0; + } + // If only one finger is on the screen and moving, that's + // the mouse pointer. + if (!_fingerDown[1] && !_fingerDown[2]) { + if (_touchpadMode) { + _curX = MIN(screenX, MAX(0, _curX + ev.motion.xrel)); + _curY = MIN(screenY, MAX(0, _curY + ev.motion.yrel)); + } else { + _curX = MIN(screenX, MAX(0, 0 + ev.motion.x)); + _curY = MIN(screenY, MAX(0, 0 + ev.motion.y)); + } + event.type = Common::EVENT_MOUSEMOVE; + processMouseEvent(event, _curX, _curY); + } + break; + case 1: + // Check for a two-finger swipe + if (_fingerDown[0] && !_fingerDown[2]) { + // Check for a vertical 20% swipe + if (ABS(_dragDiffY[0]) > screenY * 0.2 && + ABS(_dragDiffY[1]) > screenY * 0.2) { + // Virtually lift fingers to prevent repeat triggers + _fingerDown[0] = _fingerDown[1] = false; + if (_dragDiffY[0] < 0 && _dragDiffY[1] < 0) { + // A swipe up triggers the keyboard, if it exists + int gblPDKVersion = PDL_GetPDKVersion(); + if (gblPDKVersion >= 300) + PDL_SetKeyboardState(PDL_TRUE); + } else if (_dragDiffY[0] > 0 && _dragDiffY[1] > 0){ + // A swipe down triggers the menu + if (g_engine && !g_engine->isPaused()) + g_engine->openMainMenuDialog(); + } + return true; + } + // Check for a horizontal 15% swipe + if (ABS(_dragDiffX[0]) > screenX * 0.15 && + ABS(_dragDiffX[1]) > screenX * 0.15) { + // Virtually lift fingers to prevent repeat triggers + _fingerDown[0] = _fingerDown[1] = false; + if (_dragDiffX[0] < 0 && _dragDiffX[1] < 0) { + // A swipe left presses escape + event.type = Common::EVENT_KEYDOWN; + event.kbd.flags = 0; + event.kbd.keycode = Common::KEYCODE_ESCAPE; + event.kbd.ascii = Common::ASCII_ESCAPE; + _queuedEscapeUpTime = g_system->getMillis() + + QUEUED_KEY_DELAY; + } else if (_dragDiffX[0] > 0 && _dragDiffX[1] > 0) { + // A swipe right toggles touchpad mode + _touchpadMode = !_touchpadMode; + g_system->showMouse(_touchpadMode); + Common::String dialogMsg(_("Touchpad mode is now ")); + dialogMsg += (_touchpadMode ? _("ON") : _("OFF")); + dialogMsg += ".\n"; + dialogMsg += + _("Swipe two fingers to the right to toggle."); + GUI::TimedMessageDialog dialog(dialogMsg, 1500); + dialog.runModal(); + } + return true; + } + } + break; + case 2: + // Check for a three-finger 15% swipe + if (_fingerDown[0] && _fingerDown[1]) { + // Swipe to the right toggles Auto-drag + if (_dragDiffX[0] > screenX * 0.15 && + _dragDiffX[1] > screenX * 0.15 && + _dragDiffX[2] > screenX * 0.15) { + // Virtually lift fingers to prevent repeat triggers + _fingerDown[0] = _fingerDown[1] = _fingerDown[2] = false; + // Toggle Auto-drag mode + _autoDragMode = !_autoDragMode; + Common::String dialogMsg(_("Auto-drag mode is now ")); + dialogMsg += (_autoDragMode ? _("ON") : _("OFF")); + dialogMsg += ".\n"; + dialogMsg += _( + "Swipe three fingers to the right to toggle."); + GUI::TimedMessageDialog dialog(dialogMsg, 1500); + dialog.runModal(); + return true; + } + // Swipe down to emulate spacebar (pause) + else if (_dragDiffY[0] > screenY * 0.15 && + _dragDiffY[1] > screenY * 0.15 && + _dragDiffY[2] > screenY * 0.15) { + // Virtually lift fingers to prevent repeat triggers + _fingerDown[0] = _fingerDown[1] = _fingerDown[2] = false; + // Press space + event.type = Common::EVENT_KEYDOWN; + event.kbd.flags = 0; + event.kbd.keycode = Common::KEYCODE_SPACE; + event.kbd.ascii = Common::ASCII_SPACE; + _queuedSpaceUpTime = g_system->getMillis() + + QUEUED_KEY_DELAY; + } + } + } } return true; } +/** + * Before calling the original SDL implementation, this method loads in + * queued events. + * + * @param event The ScummVM event + */ +bool WebOSSdlEventSource::pollEvent(Common::Event &event) { + uint32 curTime = g_system->getMillis(); + + // Run down the priority list for queued events. The built-in + // event queue runs events on the next poll, which causes many + // WebOS devices to ignore certain inputs. Allowing keys to + // stay "down" longer is enough to register the press. + if (_queuedEscapeUpTime != 0 && curTime >= _queuedEscapeUpTime) { + event.type = Common::EVENT_KEYUP; + event.kbd.flags = 0; + event.kbd.keycode = Common::KEYCODE_ESCAPE; + event.kbd.ascii = Common::ASCII_ESCAPE; + _queuedEscapeUpTime = 0; + return true; + } + else if (_queuedSpaceUpTime != 0 && curTime >= _queuedSpaceUpTime) { + event.type = Common::EVENT_KEYUP; + event.kbd.flags = 0; + event.kbd.keycode = Common::KEYCODE_SPACE; + event.kbd.ascii = Common::ASCII_SPACE; + _queuedSpaceUpTime = 0; + return true; + } + else if (_queuedDragTime != 0 && curTime >= _queuedDragTime) { + event.type = Common::EVENT_LBUTTONDOWN; + _dragging = true; + processMouseEvent(event, _curX, _curY); + _queuedDragTime = 0; + return true; + } + + // Having a mouse pointer on screen when not in Touchpad mode is poor + // interface design, because the user won't know whether to tap buttons + // or drag the pointer to them. On the first poll, set the appropriate + // pointer visibility. + if (_firstPoll) { + g_system->showMouse(_touchpadMode); + _firstPoll = false; + } + + return SdlEventSource::pollEvent(event); +} + #endif diff --git a/backends/events/webossdl/webossdl-events.h b/backends/events/webossdl/webossdl-events.h index ad69fa27e4..a623a133b8 100644 --- a/backends/events/webossdl/webossdl-events.h +++ b/backends/events/webossdl/webossdl-events.h @@ -30,38 +30,73 @@ */ class WebOSSdlEventSource : public SdlEventSource { public: - WebOSSdlEventSource(); + enum { + MAX_FINGERS = 3 + }; + WebOSSdlEventSource() : + _gestureDown(false), + _dragStartTime(0), + _dragging(false), + _curX(0), _curY(0), + _touchpadMode(false), + _autoDragMode(true), + _doClick(true), + _queuedDragTime(0), _queuedEscapeUpTime(0), _queuedSpaceUpTime(0), + _firstPoll(true), + QUEUED_KEY_DELAY(250), QUEUED_DRAG_DELAY(500) { + for (int i = 0; i < MAX_FINGERS; i++) { + _fingerDown[i] = false; + _screenDownTime[i] = _dragDiffX[i] = _dragDiffY[i] = 0; + } + }; protected: // Inidicates if gesture area is pressed down or not. bool _gestureDown; - - // The timestamp when screen was pressed down. - uint32 _screenDownTime; - + + // The timestamp when screen was pressed down for each finger. + uint32 _screenDownTime[MAX_FINGERS]; + // The timestamp when a possible drag operation was triggered. uint32 _dragStartTime; - - // The index of the motion pointer. - int _motionPtrIndex; - - // The maximum horizontal motion during dragging (For tap recognition). - int _dragDiffX; - - // The maximum vertical motion during dragging (For tap recognition). - int _dragDiffY; - + + // The distance each finger traveled from touch to release. + int _dragDiffX[MAX_FINGERS], _dragDiffY[MAX_FINGERS]; + // Indicates if we are in drag mode. bool _dragging; - + // The current mouse position on the screen. int _curX, _curY; + // Indicates if we're in touchpad mode or tap-to-move mode. + bool _touchpadMode; + + // Indicates if we're in automatic drag mode. + bool _autoDragMode; + + // Tracks which fingers are currently touching the screen. + bool _fingerDown[MAX_FINGERS]; + + // Indicates if a click should be executed when the first finger is lifted + bool _doClick; + + // Indicates whether the event poll has been run before + bool _firstPoll; + + // Event queues + uint32 _queuedDragTime, _queuedEscapeUpTime, _queuedSpaceUpTime; + + // Standard event queue delays in milliseconds + const int QUEUED_KEY_DELAY; + const int QUEUED_DRAG_DELAY; + 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); + virtual bool pollEvent(Common::Event &event); }; #endif -- cgit v1.2.3 From 9467e4d8d4270deaa24e2d040f504fee82fc96ec Mon Sep 17 00:00:00 2001 From: TomFrost Date: Sun, 25 Sep 2011 12:15:38 -0400 Subject: WebOS: Reset package version to 0. The package version must be incremented for each new WebOS release, due to the device needing a new version to install. Whenever the ScummVM version is raised, this can be reset to 0. Changing to 0 in anticipation of ScummVM 1.4.0. --- backends/platform/webos/webos.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backends/platform/webos/webos.mk b/backends/platform/webos/webos.mk index 20d79c0555..804b56de35 100644 --- a/backends/platform/webos/webos.mk +++ b/backends/platform/webos/webos.mk @@ -51,8 +51,8 @@ # Increment this number when the packaging of the app has been changed while # ScummVM itself has the same version as before. The number can be reset to -# 1 when the ScummVM version is increased. -VER_PACKAGE = 5 +# 0 when the ScummVM version is increased. +VER_PACKAGE = 0 PATH_DIST = $(srcdir)/dists/webos PATH_MOJO = $(PATH_DIST)/mojo -- cgit v1.2.3 From c958701c788217e93534deb6f5059e0a702531e8 Mon Sep 17 00:00:00 2001 From: TomFrost Date: Sun, 25 Sep 2011 14:13:47 -0400 Subject: WebOS: Make right-clicks last longer. While the right-click was working in most games, the weapon-switching in Full Throttle wasn't registering the click. Holding the button down for 50ms instead of immediately firing the mouseup fixes the issue. --- backends/events/webossdl/webossdl-events.cpp | 18 +++++++++++++----- backends/events/webossdl/webossdl-events.h | 14 ++++++++------ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/backends/events/webossdl/webossdl-events.cpp b/backends/events/webossdl/webossdl-events.cpp index 778f41dd7e..be96f20e12 100644 --- a/backends/events/webossdl/webossdl-events.cpp +++ b/backends/events/webossdl/webossdl-events.cpp @@ -209,10 +209,11 @@ bool WebOSSdlEventSource::handleMouseButtonUp(SDL_Event &ev, // right mouse click. else if (ev.button.which == 1 && _fingerDown[0] && _fingerDown[1] && !_fingerDown[2]) { - event.type = Common::EVENT_RBUTTONUP; - processMouseEvent(event, _curX, _curY); - g_system->getEventManager()->pushEvent(event); + //event.type = Common::EVENT_RBUTTONUP; + //g_system->getEventManager()->pushEvent(event); event.type = Common::EVENT_RBUTTONDOWN; + processMouseEvent(event, _curX, _curY); + _queuedRUpTime = g_system->getMillis() + QUEUED_RUP_DELAY; } // If two fingers are down and a third taps, it's a middle @@ -372,8 +373,9 @@ bool WebOSSdlEventSource::pollEvent(Common::Event &event) { // Run down the priority list for queued events. The built-in // event queue runs events on the next poll, which causes many - // WebOS devices to ignore certain inputs. Allowing keys to - // stay "down" longer is enough to register the press. + // WebOS devices (and a few game engines) to ignore certain inputs. + // Allowing keys and clicks to stay "down" longer is enough to register + // the press. if (_queuedEscapeUpTime != 0 && curTime >= _queuedEscapeUpTime) { event.type = Common::EVENT_KEYUP; event.kbd.flags = 0; @@ -390,6 +392,12 @@ bool WebOSSdlEventSource::pollEvent(Common::Event &event) { _queuedSpaceUpTime = 0; return true; } + else if (_queuedRUpTime != 0 && curTime >= _queuedRUpTime) { + event.type = Common::EVENT_RBUTTONUP; + processMouseEvent(event, _curX, _curY); + _queuedRUpTime = 0; + return true; + } else if (_queuedDragTime != 0 && curTime >= _queuedDragTime) { event.type = Common::EVENT_LBUTTONDOWN; _dragging = true; diff --git a/backends/events/webossdl/webossdl-events.h b/backends/events/webossdl/webossdl-events.h index a623a133b8..3c2679c4a1 100644 --- a/backends/events/webossdl/webossdl-events.h +++ b/backends/events/webossdl/webossdl-events.h @@ -35,15 +35,15 @@ public: }; WebOSSdlEventSource() : _gestureDown(false), - _dragStartTime(0), - _dragging(false), + _dragStartTime(0), _dragging(false), _curX(0), _curY(0), - _touchpadMode(false), - _autoDragMode(true), + _touchpadMode(false), _autoDragMode(true), _doClick(true), _queuedDragTime(0), _queuedEscapeUpTime(0), _queuedSpaceUpTime(0), + _queuedRUpTime(0), _firstPoll(true), - QUEUED_KEY_DELAY(250), QUEUED_DRAG_DELAY(500) { + QUEUED_KEY_DELAY(250), QUEUED_DRAG_DELAY(500), + QUEUED_RUP_DELAY(50) { for (int i = 0; i < MAX_FINGERS; i++) { _fingerDown[i] = false; _screenDownTime[i] = _dragDiffX[i] = _dragDiffY[i] = 0; @@ -84,11 +84,13 @@ protected: bool _firstPoll; // Event queues - uint32 _queuedDragTime, _queuedEscapeUpTime, _queuedSpaceUpTime; + uint32 _queuedDragTime, _queuedEscapeUpTime, _queuedSpaceUpTime, + _queuedRUpTime; // Standard event queue delays in milliseconds const int QUEUED_KEY_DELAY; const int QUEUED_DRAG_DELAY; + const int QUEUED_RUP_DELAY; virtual void SDLModToOSystemKeyFlags(SDLMod mod, Common::Event &event); virtual bool handleKeyDown(SDL_Event &ev, Common::Event &event); -- cgit v1.2.3 From dbd391bdfe9790aab8f6ae3dc7762ff2662cfbb4 Mon Sep 17 00:00:00 2001 From: TomFrost Date: Sat, 1 Oct 2011 23:03:15 -0400 Subject: WebOS: Add improvements suggested in pull req. 89. The improvements in this commit are mostly code formatting, variable abstraction, and in one case, a performance enhancement as calculations were made a one-time fire rather than being run with every mouse move event. --- backends/events/webossdl/webossdl-events.cpp | 149 +++++++++++++++------------ backends/events/webossdl/webossdl-events.h | 29 ++++-- configure | 1 + 3 files changed, 102 insertions(+), 77 deletions(-) diff --git a/backends/events/webossdl/webossdl-events.cpp b/backends/events/webossdl/webossdl-events.cpp index be96f20e12..d01e51fafe 100644 --- a/backends/events/webossdl/webossdl-events.cpp +++ b/backends/events/webossdl/webossdl-events.cpp @@ -30,7 +30,9 @@ #include "backends/events/webossdl/webossdl-events.h" #include "gui/message.h" #include "engines/engine.h" -#include "PDL.h" + +// PDL.h provided by the official Palm WebOS PDK. +#include /** * WebOS devices only have a Shift key and a CTRL key. There is also an Alt @@ -81,7 +83,8 @@ bool WebOSSdlEventSource::handleKeyDown(SDL_Event &ev, Common::Event &event) { // handle virtual keyboard dismiss key if (ev.key.keysym.sym == 24) { int gblPDKVersion = PDL_GetPDKVersion(); - // check for correct PDK Version + // check for correct PDK Version, as this determines whether an + // OS-supplied virtual keyboard is available on this device. if (gblPDKVersion >= 300) { PDL_SetKeyboardState(PDL_FALSE); return true; @@ -110,7 +113,8 @@ bool WebOSSdlEventSource::handleKeyUp(SDL_Event &ev, Common::Event &event) { // handle virtual keyboard dismiss key if (ev.key.keysym.sym == 24) { int gblPDKVersion = PDL_GetPDKVersion(); - // check for correct PDK Version + // check for correct PDK Version, as this determines whether an + // OS-supplied virtual keyboard is available on this device. if (gblPDKVersion >= 300) { PDL_SetKeyboardState(PDL_FALSE); return true; @@ -142,17 +146,15 @@ bool WebOSSdlEventSource::handleMouseButtonDown(SDL_Event &ev, if (_autoDragMode) _queuedDragTime = g_system->getMillis() + QUEUED_DRAG_DELAY; // Turn drag mode on instantly for a double-tap - else if (g_system->getMillis() - _dragStartTime < 400) { + else if (g_system->getMillis() - _dragStartTime < DOUBLETAP_LIMIT) { _dragging = true; event.type = Common::EVENT_LBUTTONDOWN; processMouseEvent(event, _curX, _curY); } // If we're not in touchpad mode, move the cursor to the tap if (!_touchpadMode) { - int screenX = g_system->getOverlayWidth(); - int screenY = g_system->getOverlayHeight(); - _curX = MIN(screenX, MAX(0, 0 + ev.motion.x)); - _curY = MIN(screenY, MAX(0, 0 + ev.motion.y)); + _curX = MIN(_screenX, MAX(0, 0 + ev.motion.x)); + _curY = MIN(_screenY, MAX(0, 0 + ev.motion.y)); // If we're already clicking, hold it until after the move. if (event.type == Common::EVENT_LBUTTONDOWN) { processMouseEvent(event, _curX, _curY); @@ -164,9 +166,8 @@ bool WebOSSdlEventSource::handleMouseButtonDown(SDL_Event &ev, } // Watch for a double-tap-triggered drag _dragStartTime = g_system->getMillis(); - } - // Kill any queued drag event if a second finger goes down - else if (ev.button.which == 1) { + } else if (ev.button.which == 1) { + // Kill any queued drag event if a second finger goes down if (_queuedDragTime > 0) _queuedDragTime = 0; _doClick = false; @@ -191,8 +192,7 @@ bool WebOSSdlEventSource::handleMouseButtonUp(SDL_Event &ev, event.type = Common::EVENT_LBUTTONUP; processMouseEvent(event, _curX, _curY); _dragging = false; - } - else { + } else { // If it was the first finger and the click hasn't been // canceled, it's a click. if (ev.button.which == 0 && _doClick && @@ -203,24 +203,18 @@ bool WebOSSdlEventSource::handleMouseButtonUp(SDL_Event &ev, event.type = Common::EVENT_LBUTTONDOWN; if (_queuedDragTime > 0) _queuedDragTime = 0; - } - - // If the first finger's down and the second taps, it's a - // right mouse click. - else if (ev.button.which == 1 && + } else if (ev.button.which == 1 && _fingerDown[0] && _fingerDown[1] && !_fingerDown[2]) { - //event.type = Common::EVENT_RBUTTONUP; - //g_system->getEventManager()->pushEvent(event); + // If the first finger's down and the second taps, it's a + // right mouse click. event.type = Common::EVENT_RBUTTONDOWN; processMouseEvent(event, _curX, _curY); _queuedRUpTime = g_system->getMillis() + QUEUED_RUP_DELAY; - } - - // If two fingers are down and a third taps, it's a middle - // click -- but lift the second finger so it doesn't register - // as a right click. - else if (ev.button.which == 2 && + } else if (ev.button.which == 2 && _fingerDown[0] && _fingerDown[1]) { + // If two fingers are down and a third taps, it's a middle + // click -- but lift the second finger so it doesn't register + // as a right click. event.type = Common::EVENT_MBUTTONUP; processMouseEvent(event, _curX, _curY); g_system->getEventManager()->pushEvent(event); @@ -246,15 +240,13 @@ bool WebOSSdlEventSource::handleMouseMotion(SDL_Event &ev, if (_fingerDown[ev.motion.which]) { _dragDiffX[ev.motion.which] += ev.motion.xrel; _dragDiffY[ev.motion.which] += ev.motion.yrel; - int screenX = g_system->getOverlayWidth(); - int screenY = g_system->getOverlayHeight(); switch (ev.motion.which) { case 0: // If our dragDiff goes too many pixels in either direction, // kill the future click and any queued drag event. - if (_doClick && (ABS(_dragDiffX[0]) > 5 || - ABS(_dragDiffY[0]) > 5)) { + if (_doClick && (ABS(_dragDiffX[0]) > MOUSE_DEADZONE_PIXELS || + ABS(_dragDiffY[0]) > MOUSE_DEADZONE_PIXELS)) { _doClick = false; if (_queuedDragTime > 0) _queuedDragTime = 0; @@ -263,11 +255,11 @@ bool WebOSSdlEventSource::handleMouseMotion(SDL_Event &ev, // the mouse pointer. if (!_fingerDown[1] && !_fingerDown[2]) { if (_touchpadMode) { - _curX = MIN(screenX, MAX(0, _curX + ev.motion.xrel)); - _curY = MIN(screenY, MAX(0, _curY + ev.motion.yrel)); + _curX = MIN(_screenX, MAX(0, _curX + ev.motion.xrel)); + _curY = MIN(_screenY, MAX(0, _curY + ev.motion.yrel)); } else { - _curX = MIN(screenX, MAX(0, 0 + ev.motion.x)); - _curY = MIN(screenY, MAX(0, 0 + ev.motion.y)); + _curX = MIN(_screenX, MAX(0, 0 + ev.motion.x)); + _curY = MIN(_screenY, MAX(0, 0 + ev.motion.y)); } event.type = Common::EVENT_MOUSEMOVE; processMouseEvent(event, _curX, _curY); @@ -276,26 +268,28 @@ bool WebOSSdlEventSource::handleMouseMotion(SDL_Event &ev, case 1: // Check for a two-finger swipe if (_fingerDown[0] && !_fingerDown[2]) { - // Check for a vertical 20% swipe - if (ABS(_dragDiffY[0]) > screenY * 0.2 && - ABS(_dragDiffY[1]) > screenY * 0.2) { + // Check for a vertical swipe + if (ABS(_dragDiffY[0]) > _swipeDistY && + ABS(_dragDiffY[1]) > _swipeDistY) { // Virtually lift fingers to prevent repeat triggers _fingerDown[0] = _fingerDown[1] = false; if (_dragDiffY[0] < 0 && _dragDiffY[1] < 0) { - // A swipe up triggers the keyboard, if it exists + // A swipe up triggers the keyboard, if it exists. We + // test for existance of a virtual OS keyboard by + // checking for the version of the linked PDK libs. int gblPDKVersion = PDL_GetPDKVersion(); if (gblPDKVersion >= 300) PDL_SetKeyboardState(PDL_TRUE); - } else if (_dragDiffY[0] > 0 && _dragDiffY[1] > 0){ + } else if (_dragDiffY[0] > 0 && _dragDiffY[1] > 0) { // A swipe down triggers the menu if (g_engine && !g_engine->isPaused()) g_engine->openMainMenuDialog(); } return true; } - // Check for a horizontal 15% swipe - if (ABS(_dragDiffX[0]) > screenX * 0.15 && - ABS(_dragDiffX[1]) > screenX * 0.15) { + // Check for a horizontal swipe + if (ABS(_dragDiffX[0]) > _swipeDistX && + ABS(_dragDiffX[1]) > _swipeDistX) { // Virtually lift fingers to prevent repeat triggers _fingerDown[0] = _fingerDown[1] = false; if (_dragDiffX[0] < 0 && _dragDiffX[1] < 0) { @@ -310,9 +304,13 @@ bool WebOSSdlEventSource::handleMouseMotion(SDL_Event &ev, // A swipe right toggles touchpad mode _touchpadMode = !_touchpadMode; g_system->showMouse(_touchpadMode); - Common::String dialogMsg(_("Touchpad mode is now ")); + // I18N: Touchpad mode toggle status. + Common::String dialogMsg(_("Touchpad mode is now")); + dialogMsg += " "; + // I18N: Touchpad mode on or off. dialogMsg += (_touchpadMode ? _("ON") : _("OFF")); dialogMsg += ".\n"; + // I18N: Instructions to toggle Touchpad mode. dialogMsg += _("Swipe two fingers to the right to toggle."); GUI::TimedMessageDialog dialog(dialogMsg, 1500); @@ -323,29 +321,32 @@ bool WebOSSdlEventSource::handleMouseMotion(SDL_Event &ev, } break; case 2: - // Check for a three-finger 15% swipe + // Check for a three-finger swipe if (_fingerDown[0] && _fingerDown[1]) { // Swipe to the right toggles Auto-drag - if (_dragDiffX[0] > screenX * 0.15 && - _dragDiffX[1] > screenX * 0.15 && - _dragDiffX[2] > screenX * 0.15) { + if (_dragDiffX[0] > _swipeDistX && + _dragDiffX[1] > _swipeDistX && + _dragDiffX[2] > _swipeDistX) { // Virtually lift fingers to prevent repeat triggers _fingerDown[0] = _fingerDown[1] = _fingerDown[2] = false; // Toggle Auto-drag mode _autoDragMode = !_autoDragMode; - Common::String dialogMsg(_("Auto-drag mode is now ")); + // I18N: Auto-drag toggle status. + Common::String dialogMsg(_("Auto-drag mode is now")); + dialogMsg += " "; + // I18N: Auto-drag on or off. dialogMsg += (_autoDragMode ? _("ON") : _("OFF")); dialogMsg += ".\n"; + // I18N: Instructions to toggle auto-drag. dialogMsg += _( "Swipe three fingers to the right to toggle."); GUI::TimedMessageDialog dialog(dialogMsg, 1500); dialog.runModal(); return true; - } - // Swipe down to emulate spacebar (pause) - else if (_dragDiffY[0] > screenY * 0.15 && - _dragDiffY[1] > screenY * 0.15 && - _dragDiffY[2] > screenY * 0.15) { + } else if (_dragDiffY[0] > _swipeDistY && + _dragDiffY[1] > _swipeDistY && + _dragDiffY[2] > _swipeDistY ) { + // Swipe down to emulate spacebar (pause) // Virtually lift fingers to prevent repeat triggers _fingerDown[0] = _fingerDown[1] = _fingerDown[2] = false; // Press space @@ -371,6 +372,19 @@ bool WebOSSdlEventSource::handleMouseMotion(SDL_Event &ev, bool WebOSSdlEventSource::pollEvent(Common::Event &event) { uint32 curTime = g_system->getMillis(); + // Event-dependent nitializations for when SDL runs its first poll. + if (_firstPoll) { + // Set the initial dimensions + calculateDimensions(); + + // Having a mouse pointer on screen when not in Touchpad mode is poor + // interface design, because the user won't know whether to tap buttons + // or drag the pointer to them. On the first poll, set the appropriate + // pointer visibility. + g_system->showMouse(_touchpadMode); + _firstPoll = false; + } + // Run down the priority list for queued events. The built-in // event queue runs events on the next poll, which causes many // WebOS devices (and a few game engines) to ignore certain inputs. @@ -383,22 +397,19 @@ bool WebOSSdlEventSource::pollEvent(Common::Event &event) { event.kbd.ascii = Common::ASCII_ESCAPE; _queuedEscapeUpTime = 0; return true; - } - else if (_queuedSpaceUpTime != 0 && curTime >= _queuedSpaceUpTime) { + } else if (_queuedSpaceUpTime != 0 && curTime >= _queuedSpaceUpTime) { event.type = Common::EVENT_KEYUP; event.kbd.flags = 0; event.kbd.keycode = Common::KEYCODE_SPACE; event.kbd.ascii = Common::ASCII_SPACE; _queuedSpaceUpTime = 0; return true; - } - else if (_queuedRUpTime != 0 && curTime >= _queuedRUpTime) { + } else if (_queuedRUpTime != 0 && curTime >= _queuedRUpTime) { event.type = Common::EVENT_RBUTTONUP; processMouseEvent(event, _curX, _curY); _queuedRUpTime = 0; return true; - } - else if (_queuedDragTime != 0 && curTime >= _queuedDragTime) { + } else if (_queuedDragTime != 0 && curTime >= _queuedDragTime) { event.type = Common::EVENT_LBUTTONDOWN; _dragging = true; processMouseEvent(event, _curX, _curY); @@ -406,16 +417,18 @@ bool WebOSSdlEventSource::pollEvent(Common::Event &event) { return true; } - // Having a mouse pointer on screen when not in Touchpad mode is poor - // interface design, because the user won't know whether to tap buttons - // or drag the pointer to them. On the first poll, set the appropriate - // pointer visibility. - if (_firstPoll) { - g_system->showMouse(_touchpadMode); - _firstPoll = false; - } - return SdlEventSource::pollEvent(event); } +/** + * Sets the _screenX and _screenY variables to the effective screen dimensions, + * and alters _swipeDistX and _swipeDistY to the correct relative values. + */ +void WebOSSdlEventSource::calculateDimensions() { + _screenX = g_system->getOverlayWidth(); + _screenY = g_system->getOverlayHeight(); + _swipeDistX = _screenX * SWIPE_PERCENT_HORIZ / 100; + _swipeDistY = _screenY * SWIPE_PERCENT_VERT / 100; +} + #endif diff --git a/backends/events/webossdl/webossdl-events.h b/backends/events/webossdl/webossdl-events.h index 3c2679c4a1..a36ee535a3 100644 --- a/backends/events/webossdl/webossdl-events.h +++ b/backends/events/webossdl/webossdl-events.h @@ -31,19 +31,25 @@ class WebOSSdlEventSource : public SdlEventSource { public: enum { - MAX_FINGERS = 3 + DOUBLETAP_LIMIT = 400, + MAX_FINGERS = 3, + MOUSE_DEADZONE_PIXELS = 5, + QUEUED_DRAG_DELAY = 500, + QUEUED_KEY_DELAY = 250, + QUEUED_RUP_DELAY = 50, + SWIPE_PERCENT_HORIZ = 15, + SWIPE_PERCENT_VERT = 20 }; WebOSSdlEventSource() : _gestureDown(false), _dragStartTime(0), _dragging(false), _curX(0), _curY(0), + _screenX(0), _screenY(0), _touchpadMode(false), _autoDragMode(true), _doClick(true), _queuedDragTime(0), _queuedEscapeUpTime(0), _queuedSpaceUpTime(0), _queuedRUpTime(0), - _firstPoll(true), - QUEUED_KEY_DELAY(250), QUEUED_DRAG_DELAY(500), - QUEUED_RUP_DELAY(50) { + _firstPoll(true) { for (int i = 0; i < MAX_FINGERS; i++) { _fingerDown[i] = false; _screenDownTime[i] = _dragDiffX[i] = _dragDiffY[i] = 0; @@ -67,6 +73,12 @@ protected: // The current mouse position on the screen. int _curX, _curY; + + // The current screen dimensions + int _screenX, _screenY; + + // The drag distance for linear gestures + int _swipeDistX, _swipeDistY; // Indicates if we're in touchpad mode or tap-to-move mode. bool _touchpadMode; @@ -87,11 +99,7 @@ protected: uint32 _queuedDragTime, _queuedEscapeUpTime, _queuedSpaceUpTime, _queuedRUpTime; - // Standard event queue delays in milliseconds - const int QUEUED_KEY_DELAY; - const int QUEUED_DRAG_DELAY; - const int QUEUED_RUP_DELAY; - + // SDL overrides 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); @@ -99,6 +107,9 @@ protected: virtual bool handleMouseButtonUp(SDL_Event &ev, Common::Event &event); virtual bool handleMouseMotion(SDL_Event &ev, Common::Event &event); virtual bool pollEvent(Common::Event &event); + + // Utility functions + void calculateDimensions(); }; #endif diff --git a/configure b/configure index 914690512b..9a757960d9 100755 --- a/configure +++ b/configure @@ -2506,6 +2506,7 @@ case $_backend in ;; webos) # There is no sdl-config in the WebOS PDK so we don't use find_sdlconfig here. + # The PDL library acts as the WebOS device toolchain, and is required to control the virtual keyboard among other OS-level events. LIBS="$LIBS -lSDL -lpdl" DEFINES="$DEFINES -DWEBOS" DEFINES="$DEFINES -DSDL_BACKEND" -- cgit v1.2.3