diff options
author | David-John Willis | 2011-03-08 20:38:56 +0000 |
---|---|---|
committer | David-John Willis | 2011-03-24 21:24:05 +0000 |
commit | b95013dfe25d75d39c7deb69ee1a63f93a4a495f (patch) | |
tree | aca9302c32044c3b4f9a416f5f840b18c6e474b9 /backends/events | |
parent | 0fb15847c6c195945b186aad9cc29dead154078a (diff) | |
download | scummvm-rg350-b95013dfe25d75d39c7deb69ee1a63f93a4a495f.tar.gz scummvm-rg350-b95013dfe25d75d39c7deb69ee1a63f93a4a495f.tar.bz2 scummvm-rg350-b95013dfe25d75d39c7deb69ee1a63f93a4a495f.zip |
OPENPANDORA: Refactor OpenPandora backend and move events and graphics into modular backend style.
Diffstat (limited to 'backends/events')
-rw-r--r-- | backends/events/openpandora/op-events.cpp | 186 | ||||
-rw-r--r-- | backends/events/openpandora/op-events.h | 46 |
2 files changed, 232 insertions, 0 deletions
diff --git a/backends/events/openpandora/op-events.cpp b/backends/events/openpandora/op-events.cpp new file mode 100644 index 0000000000..381cbf89e9 --- /dev/null +++ b/backends/events/openpandora/op-events.cpp @@ -0,0 +1,186 @@ +/* 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. + * + */ + +#include "common/scummsys.h" + +/* + * OpenPandora: Device Specific Event Handling. + * + */ + +#if defined(OPENPANDORA) + +#include "backends/events/openpandora/op-events.h" +#include "backends/graphics/openpandora/op-graphics.h" +#include "backends/platform/openpandora/op-sdl.h" +#include "backends/platform/openpandora/op-options.h" + +/* Quick default button states for modifiers. */ +int BUTTON_STATE_L = false; + +enum { + /* Touchscreen TapMode */ + TAPMODE_LEFT = 0, + TAPMODE_RIGHT = 1, + TAPMODE_HOVER = 2 +}; + +OPEventSource::OPEventSource() + : _buttonStateL(false){ +} + +/* On the OpenPandora by default the ABXY and L/R Trigger buttons are returned by SDL as + (A): SDLK_HOME (B): SDLK_END (X): SDLK_PAGEDOWN (Y): SDLK_PAGEUP (L): SDLK_RSHIFT (R): SDLK_RCTRL +*/ + +bool OPEventSource::remapKey(SDL_Event &ev, Common::Event &event) { + + if (ev.type == SDL_KEYDOWN) { + switch (ev.key.keysym.sym) { + case SDLK_HOME: + event.type = Common::EVENT_LBUTTONDOWN; + fillMouseEvent(event, _km.x, _km.y); + return true; + break; + case SDLK_END: + event.type = Common::EVENT_RBUTTONDOWN; + fillMouseEvent(event, _km.x, _km.y); + return true; + break; + case SDLK_PAGEDOWN: + event.type = Common::EVENT_MAINMENU; + return true; + break; + case SDLK_PAGEUP: + OP::ToggleTapMode(); + if (OP::tapmodeLevel == TAPMODE_LEFT) { + g_system->displayMessageOnOSD("Touchscreen 'Tap Mode' - Left Click"); + } else if (OP::tapmodeLevel == TAPMODE_RIGHT) { + g_system->displayMessageOnOSD("Touchscreen 'Tap Mode' - Right Click"); + } else if (OP::tapmodeLevel == TAPMODE_HOVER) { + g_system->displayMessageOnOSD("Touchscreen 'Tap Mode' - Hover (No Click)"); + } + break; + case SDLK_RSHIFT: + BUTTON_STATE_L = true; + break; + case SDLK_RCTRL: + break; + default: + return false; + break; + } + return false; + } else { + switch (ev.key.keysym.sym) { + case SDLK_HOME: + event.type = Common::EVENT_LBUTTONUP; + fillMouseEvent(event, _km.x, _km.y); + return true; + break; + case SDLK_END: + event.type = Common::EVENT_RBUTTONUP; + fillMouseEvent(event, _km.x, _km.y); + return true; + break; + case SDLK_PAGEDOWN: + event.type = Common::EVENT_MAINMENU; + return true; + break; + case SDLK_PAGEUP: + break; + case SDLK_RSHIFT: + BUTTON_STATE_L = false; + break; + case SDLK_RCTRL: + break; + default: + return false; + break; + } + return false; + } + return false; +} + +/* Custom handleMouseButtonDown/handleMouseButtonUp to deal with 'Tap Mode' for the touchscreen */ + +bool OPEventSource::handleMouseButtonDown(SDL_Event &ev, Common::Event &event) { + if (ev.button.button == SDL_BUTTON_LEFT){ + if (BUTTON_STATE_L == true) /* BUTTON_STATE_L = Left Trigger Held, force Right Click */ + event.type = Common::EVENT_RBUTTONDOWN; + else if (OP::tapmodeLevel == TAPMODE_LEFT) /* TAPMODE_LEFT = Left Click Tap Mode */ + event.type = Common::EVENT_LBUTTONDOWN; + else if (OP::tapmodeLevel == TAPMODE_RIGHT) /* TAPMODE_RIGHT = Right Click Tap Mode */ + event.type = Common::EVENT_RBUTTONDOWN; + else if (OP::tapmodeLevel == TAPMODE_HOVER) /* TAPMODE_HOVER = Hover (No Click) Tap Mode */ + event.type = Common::EVENT_MOUSEMOVE; + else + event.type = Common::EVENT_LBUTTONDOWN; /* For normal mice etc. */ + } + else if (ev.button.button == SDL_BUTTON_RIGHT) + event.type = Common::EVENT_RBUTTONDOWN; +#if defined(SDL_BUTTON_WHEELUP) && defined(SDL_BUTTON_WHEELDOWN) + else if (ev.button.button == SDL_BUTTON_WHEELUP) + event.type = Common::EVENT_WHEELUP; + else if (ev.button.button == SDL_BUTTON_WHEELDOWN) + event.type = Common::EVENT_WHEELDOWN; +#endif +#if defined(SDL_BUTTON_MIDDLE) + else if (ev.button.button == SDL_BUTTON_MIDDLE) + event.type = Common::EVENT_MBUTTONDOWN; +#endif + else + return false; + + fillMouseEvent(event, ev.button.x, ev.button.y); + + return true; +} + +bool OPEventSource::handleMouseButtonUp(SDL_Event &ev, Common::Event &event) { + if (ev.button.button == SDL_BUTTON_LEFT){ + if (BUTTON_STATE_L == true) /* BUTTON_STATE_L = Left Trigger Held, force Right Click */ + event.type = Common::EVENT_RBUTTONUP; + else if (OP::tapmodeLevel == TAPMODE_LEFT) /* TAPMODE_LEFT = Left Click Tap Mode */ + event.type = Common::EVENT_LBUTTONUP; + else if (OP::tapmodeLevel == TAPMODE_RIGHT) /* TAPMODE_RIGHT = Right Click Tap Mode */ + event.type = Common::EVENT_RBUTTONUP; + else if (OP::tapmodeLevel == TAPMODE_HOVER) /* TAPMODE_HOVER = Hover (No Click) Tap Mode */ + event.type = Common::EVENT_MOUSEMOVE; + else + event.type = Common::EVENT_LBUTTONUP; /* For normal mice etc. */ + } + else if (ev.button.button == SDL_BUTTON_RIGHT) + event.type = Common::EVENT_RBUTTONUP; +#if defined(SDL_BUTTON_MIDDLE) + else if (ev.button.button == SDL_BUTTON_MIDDLE) + event.type = Common::EVENT_MBUTTONUP; +#endif + else + return false; + + fillMouseEvent(event, ev.button.x, ev.button.y); + + return true; +} +#endif diff --git a/backends/events/openpandora/op-events.h b/backends/events/openpandora/op-events.h new file mode 100644 index 0000000000..4b13ef2105 --- /dev/null +++ b/backends/events/openpandora/op-events.h @@ -0,0 +1,46 @@ +/* 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. + * + */ + +#if !defined(BACKEND_EVENTS_OP_H) && !defined(DISABLE_DEFAULT_EVENTMANAGER) +#define BACKEND_EVENTS_OP_H + +#include "backends/events/sdl/sdl-events.h" + +/** + * Events manager for the OpenPandora. + */ +class OPEventSource : public SdlEventSource { +public: + OPEventSource(); + +protected: + /** Button state for L button modifier */ + 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); +}; + +#endif /* BACKEND_EVENTS_OP_H */ |