diff options
Diffstat (limited to 'backends/events')
-rw-r--r-- | backends/events/gp2xsdl/gp2xsdl-events.cpp | 373 | ||||
-rw-r--r-- | backends/events/gp2xsdl/gp2xsdl-events.h | 57 | ||||
-rw-r--r-- | backends/events/linuxmotosdl/linuxmotosdl-events.cpp | 227 | ||||
-rw-r--r-- | backends/events/linuxmotosdl/linuxmotosdl-events.h | 43 | ||||
-rw-r--r-- | backends/events/samsungtvsdl/samsungtvsdl-events.cpp | 78 | ||||
-rw-r--r-- | backends/events/samsungtvsdl/samsungtvsdl-events.h | 42 | ||||
-rw-r--r-- | backends/events/sdl/sdl-events.cpp | 571 | ||||
-rw-r--r-- | backends/events/sdl/sdl-events.h | 138 | ||||
-rw-r--r-- | backends/events/symbiansdl/symbiansdl-events.cpp | 201 | ||||
-rw-r--r-- | backends/events/symbiansdl/symbiansdl-events.h | 59 |
10 files changed, 1789 insertions, 0 deletions
diff --git a/backends/events/gp2xsdl/gp2xsdl-events.cpp b/backends/events/gp2xsdl/gp2xsdl-events.cpp new file mode 100644 index 0000000000..2be3f2b2e7 --- /dev/null +++ b/backends/events/gp2xsdl/gp2xsdl-events.cpp @@ -0,0 +1,373 @@ +/* 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(GP2X) || defined(GP2XWIZ) + +#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" + +// FIXME move joystick defines out and replace with confile file options +// we should really allow users to map any key to a joystick button using the keymapper. +#define JOY_DEADZONE 2200 + +#define JOY_XAXIS 0 +#define JOY_YAXIS 1 + +/* GP2X: Main Joystick Mappings */ +enum { + GP2X_BUTTON_UP = 0, + GP2X_BUTTON_UPLEFT = 1, + GP2X_BUTTON_LEFT = 2, + GP2X_BUTTON_DOWNLEFT = 3, + GP2X_BUTTON_DOWN = 4, + GP2X_BUTTON_DOWNRIGHT = 5, + GP2X_BUTTON_RIGHT = 6, + GP2X_BUTTON_UPRIGHT = 7, + GP2X_BUTTON_MENU = 8, + GP2X_BUTTON_SELECT = 9, + GP2X_BUTTON_L = 10, + GP2X_BUTTON_R = 11, + GP2X_BUTTON_A = 12, + GP2X_BUTTON_B = 13, + GP2X_BUTTON_X = 14, + GP2X_BUTTON_Y = 15, + GP2X_BUTTON_VOLUP = 16, + GP2X_BUTTON_VOLDOWN = 17, + GP2X_BUTTON_CLICK = 18 +}; + +GP2XSdlEventManager::GP2XSdlEventManager(Common::EventSource *boss) + : + _buttonStateL(false), + SdlEventManager(boss) { + +} + +void GP2XSdlEventManager::SDLModToOSystemKeyFlags(SDLMod mod, Common::Event &event) { + event.kbd.flags = 0; + + if (mod & KMOD_SHIFT) + event.kbd.flags |= Common::KBD_SHIFT; + if (mod & KMOD_ALT) + event.kbd.flags |= Common::KBD_ALT; + if (mod & KMOD_CTRL) + event.kbd.flags |= Common::KBD_CTRL; +} + +void GP2XSdlEventManager::moveStick() { + bool stickBtn[32]; + + memcpy(stickBtn, _stickBtn, sizeof(stickBtn)); + + if ((stickBtn[0])||(stickBtn[2])||(stickBtn[4])||(stickBtn[6])) + stickBtn[1] = stickBtn[3] = stickBtn[5] = stickBtn[7] = 0; + + if ((stickBtn[1])||(stickBtn[2])||(stickBtn[3])) { + if (_km.x_down_count!=2) { + _km.x_vel = -1; + _km.x_down_count = 1; + } else + _km.x_vel = -4; + } else if ((stickBtn[5])||(stickBtn[6])||(stickBtn[7])) { + if (_km.x_down_count!=2) { + _km.x_vel = 1; + _km.x_down_count = 1; + } else + _km.x_vel = 4; + } else { + _km.x_vel = 0; + _km.x_down_count = 0; + } + + if ((stickBtn[0])||(stickBtn[1])||(stickBtn[7])) { + if (_km.y_down_count!=2) { + _km.y_vel = -1; + _km.y_down_count = 1; + } else + _km.y_vel = -4; + } else if ((stickBtn[3])||(stickBtn[4])||(stickBtn[5])) { + if (_km.y_down_count!=2) { + _km.y_vel = 1; + _km.y_down_count = 1; + } else + _km.y_vel = 4; + } else { + _km.y_vel = 0; + _km.y_down_count = 0; + } +} + +/* GP2X Input mappings. +Single Button + +Movement: + +GP2X_BUTTON_UP Cursor Up +GP2X_BUTTON_DOWN Cursor Down +GP2X_BUTTON_LEFT Cursor Left +GP2X_BUTTON_RIGHT Cursor Right + +GP2X_BUTTON_UPLEFT Cursor Up Left +GP2X_BUTTON_UPRIGHT Cursor Up Right +GP2X_BUTTON_DOWNLEFT Cursor Down Left +GP2X_BUTTON_DOWNRIGHT Cursor Down Right + +Button Emulation: + +GP2X_BUTTON_CLICK Left Mouse Click (GP2X only) +GP2X_BUTTON_A . (Period) +GP2X_BUTTON_B Left Mouse Click +GP2X_BUTTON_Y Space Bar +GP2X_BUTTON_X Right Mouse Click +GP2X_BUTTON_L Combo Modifier (Left Trigger) +GP2X_BUTTON_R Return (Right Trigger) +GP2X_BUTTON_MENU F5 (Game Menu) +GP2X_BUTTON_SELECT Escape +GP2X_BUTTON_VOLUP /dev/mixer Global Volume Up +GP2X_BUTTON_VOLDOWN /dev/mixer Global Volume Down + +Combos: + +GP2X_BUTTON_VOLUP & GP2X_BUTTON_VOLDOWN 0 (For Monkey 2 CP) or Virtual Keyboard if enabled +GP2X_BUTTON_L & GP2X_BUTTON_SELECT Common::EVENT_QUIT (Calls Sync() to make sure SD is flushed) +GP2X_BUTTON_L & GP2X_BUTTON_MENU Common::EVENT_MAINMENU (ScummVM Global Main Menu) +GP2X_BUTTON_L & GP2X_BUTTON_A Common::EVENT_PREDICTIVE_DIALOG for predictive text entry box (AGI games) +GP2X_BUTTON_L & GP2X_BUTTON_Y Toggles setZoomOnMouse() for larger then 320*240 games to scale to the point + raduis. (GP2X only) +*/ + +bool GP2XSdlEventManager::handleKeyDown(SDL_Event &ev, Common::Event &event) { + SDLModToOSystemKeyFlags(SDL_GetModState(), event); + + if (remapKey(ev, event)) + return true; + + event.type = Common::EVENT_KEYDOWN; + event.kbd.keycode = (Common::KeyCode)ev.key.keysym.sym; + event.kbd.ascii = mapKey(ev.key.keysym.sym, ev.key.keysym.mod, ev.key.keysym.unicode); + + return true; +} + +bool GP2XSdlEventManager::handleKeyUp(SDL_Event &ev, Common::Event &event) { + if (remapKey(ev, event)) + return true; + + event.type = Common::EVENT_KEYUP; + event.kbd.keycode = (Common::KeyCode)ev.key.keysym.sym; + event.kbd.ascii = mapKey(ev.key.keysym.sym, ev.key.keysym.mod, ev.key.keysym.unicode); + SDLModToOSystemKeyFlags(SDL_GetModState(), event); + + // Ctrl-Alt-<key> will change the GFX mode + if ((event.kbd.flags & (Common::KBD_CTRL | Common::KBD_ALT)) == (Common::KBD_CTRL | Common::KBD_ALT)) { + // Swallow these key up events + return false; + } + + return true; +} + +bool GP2XSdlEventManager::handleJoyButtonDown(SDL_Event &ev, Common::Event &event) { + _stickBtn[ev.jbutton.button] = 1; + if (ev.jbutton.button == GP2X_BUTTON_B) { + event.type = Common::EVENT_LBUTTONDOWN; + fillMouseEvent(event, _km.x, _km.y); +#ifdef GP2X + } else if (ev.jbutton.button == GP2X_BUTTON_CLICK) { + event.type = Common::EVENT_LBUTTONDOWN; + fillMouseEvent(event, _km.x, _km.y); +#endif + } else if (ev.jbutton.button == GP2X_BUTTON_X) { + event.type = Common::EVENT_RBUTTONDOWN; + fillMouseEvent(event, _km.x, _km.y); + } else if (_stickBtn[GP2X_BUTTON_L] && (ev.jbutton.button == GP2X_BUTTON_SELECT)) { + event.type = Common::EVENT_QUIT; + } else if (ev.jbutton.button < 8) { + moveStick(); + event.type = Common::EVENT_MOUSEMOVE; + fillMouseEvent(event, _km.x, _km.y); + } else { + event.type = Common::EVENT_KEYDOWN; + event.kbd.flags = 0; + switch (ev.jbutton.button) { + case GP2X_BUTTON_L: + _buttonStateL = true; + break; + case GP2X_BUTTON_R: + if (_buttonStateL) { +#ifdef ENABLE_VKEYBD + event.kbd.keycode = Common::KEYCODE_F7; + event.kbd.ascii = mapKey(SDLK_F7, ev.key.keysym.mod, 0); +#else + event.kbd.keycode = Common::KEYCODE_0; + event.kbd.ascii = mapKey(SDLK_0, ev.key.keysym.mod, 0); +#endif + } else { + event.kbd.keycode = Common::KEYCODE_RETURN; + event.kbd.ascii = mapKey(SDLK_RETURN, ev.key.keysym.mod, 0); + } + break; + case GP2X_BUTTON_SELECT: + if (_buttonStateL) { + event.type = Common::EVENT_QUIT; + } else { + event.kbd.keycode = Common::KEYCODE_ESCAPE; + event.kbd.ascii = mapKey(SDLK_ESCAPE, ev.key.keysym.mod, 0); + } + break; + case GP2X_BUTTON_A: + if (_buttonStateL) { + event.type = Common::EVENT_PREDICTIVE_DIALOG; + } else { + event.kbd.keycode = Common::KEYCODE_PERIOD; + event.kbd.ascii = mapKey(SDLK_PERIOD, ev.key.keysym.mod, 0); + } + break; + case GP2X_BUTTON_Y: +#ifdef GP2X + if (_buttonStateL) { + ((GP2XSdlGraphicsManager *)((OSystem_SDL *)g_system)->getGraphicsManager())->toggleZoomOnMouse(); + } else { +#endif + event.kbd.keycode = Common::KEYCODE_SPACE; + event.kbd.ascii = mapKey(SDLK_SPACE, ev.key.keysym.mod, 0); +#ifdef GP2X + } +#endif + break; + case GP2X_BUTTON_MENU: + if (_buttonStateL) { + event.type = Common::EVENT_MAINMENU; + } else { + event.kbd.keycode = Common::KEYCODE_F5; + event.kbd.ascii = mapKey(SDLK_F5, ev.key.keysym.mod, 0); + } + break; + case GP2X_BUTTON_VOLUP: +#ifdef GP2X + GP2X_HW::mixerMoveVolume(2); + if (GP2X_HW::volumeLevel == 100) { +#else + WIZ_HW::mixerMoveVolume(2); + if (WIZ_HW::volumeLevel == 100) { +#endif + g_system->displayMessageOnOSD("Maximum Volume"); + } else { + g_system->displayMessageOnOSD("Increasing Volume"); + } + break; + + case GP2X_BUTTON_VOLDOWN: +#ifdef GP2X + GP2X_HW::mixerMoveVolume(1); + if (GP2X_HW::volumeLevel == 0) { +#else + WIZ_HW::mixerMoveVolume(1); + if (WIZ_HW::volumeLevel == 0) { +#endif + g_system->displayMessageOnOSD("Minimal Volume"); + } else { + g_system->displayMessageOnOSD("Decreasing Volume"); + } + break; + } + } + return true; +} + +bool GP2XSdlEventManager::handleJoyButtonUp(SDL_Event &ev, Common::Event &event) { + _stickBtn[ev.jbutton.button] = 0; + if (ev.jbutton.button == GP2X_BUTTON_B) { + event.type = Common::EVENT_LBUTTONUP; + fillMouseEvent(event, _km.x, _km.y); +#ifdef GP2X + } else if (ev.jbutton.button == GP2X_BUTTON_CLICK) { + event.type = Common::EVENT_LBUTTONUP; + fillMouseEvent(event, _km.x, _km.y); +#endif + } else if (ev.jbutton.button == GP2X_BUTTON_X) { + event.type = Common::EVENT_RBUTTONUP; + fillMouseEvent(event, _km.x, _km.y); + } else if (ev.jbutton.button < 8) { + moveStick(); + event.type = Common::EVENT_MOUSEMOVE; + fillMouseEvent(event, _km.x, _km.y); + } else { + event.type = Common::EVENT_KEYUP; + event.kbd.flags = 0; + switch (ev.jbutton.button) { + case GP2X_BUTTON_SELECT: + event.kbd.keycode = Common::KEYCODE_ESCAPE; + event.kbd.ascii = mapKey(SDLK_ESCAPE, ev.key.keysym.mod, 0); + break; + case GP2X_BUTTON_A: + event.kbd.keycode = Common::KEYCODE_PERIOD; + event.kbd.ascii = mapKey(SDLK_PERIOD, ev.key.keysym.mod, 0); + break; + case GP2X_BUTTON_Y: + event.kbd.keycode = Common::KEYCODE_SPACE; + event.kbd.ascii = mapKey(SDLK_SPACE, ev.key.keysym.mod, 0); + break; + case GP2X_BUTTON_MENU: + if (_buttonStateL == true) { + event.type = Common::EVENT_MAINMENU; + } else { + event.kbd.keycode = Common::KEYCODE_F5; + event.kbd.ascii = mapKey(SDLK_F5, ev.key.keysym.mod, 0); + } + break; + case GP2X_BUTTON_L: + _buttonStateL = false; + break; + case GP2X_BUTTON_R: + if (_buttonStateL == true) { +#ifdef ENABLE_VKEYBD + event.kbd.keycode = Common::KEYCODE_F7; + event.kbd.ascii = mapKey(SDLK_F7, ev.key.keysym.mod, 0); +#else + event.kbd.keycode = Common::KEYCODE_0; + event.kbd.ascii = mapKey(SDLK_0, ev.key.keysym.mod, 0); +#endif + } else { + event.kbd.keycode = Common::KEYCODE_RETURN; + event.kbd.ascii = mapKey(SDLK_RETURN, ev.key.keysym.mod, 0); + } + break; + case GP2X_BUTTON_VOLUP: + break; + case GP2X_BUTTON_VOLDOWN: + break; + } + } + return true; +} + +#endif diff --git a/backends/events/gp2xsdl/gp2xsdl-events.h b/backends/events/gp2xsdl/gp2xsdl-events.h new file mode 100644 index 0000000000..559aa53388 --- /dev/null +++ b/backends/events/gp2xsdl/gp2xsdl-events.h @@ -0,0 +1,57 @@ +/* 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_GP2X_H) && !defined(DISABLE_DEFAULT_EVENTMANAGER) +#define BACKEND_EVENTS_SDL_GP2X_H + +#include "backends/events/sdl/sdl-events.h" + +/** + * SDL events manager for GP2X and GP2XWIZ + */ +class GP2XSdlEventManager : public SdlEventManager { +public: + GP2XSdlEventManager(Common::EventSource *boss); + +protected: + bool _stickBtn[32]; + + /** Button state for L button modifier */ + bool _buttonStateL; + + /** + * Handles the stick movement + */ + void moveStick(); + + virtual bool handleKeyDown(SDL_Event &ev, Common::Event &event); + virtual bool handleKeyUp(SDL_Event &ev, Common::Event &event); + virtual bool handleJoyButtonDown(SDL_Event &ev, Common::Event &event); + virtual bool handleJoyButtonUp(SDL_Event &ev, Common::Event &event); + + virtual void SDLModToOSystemKeyFlags(SDLMod mod, Common::Event &event); +}; + +#endif diff --git a/backends/events/linuxmotosdl/linuxmotosdl-events.cpp b/backends/events/linuxmotosdl/linuxmotosdl-events.cpp new file mode 100644 index 0000000000..1313007158 --- /dev/null +++ b/backends/events/linuxmotosdl/linuxmotosdl-events.cpp @@ -0,0 +1,227 @@ +/* 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(LINUXMOTO) + +#include "backends/events/linuxmotosdl/linuxmotosdl-events.h" +#include "backends/platform/linuxmoto/linuxmoto-sdl.h" + +enum { + GFX_HALF = 12 +}; + +LinuxmotoSdlEventManager::LinuxmotoSdlEventManager(Common::EventSource *boss) + : + SdlEventManager(boss) { + +} + +void LinuxmotoSdlEventManager::preprocessEvents(SDL_Event *event) { + if (event->type == SDL_ACTIVEEVENT) { + if (event->active.state == SDL_APPINPUTFOCUS && !event->active.gain) { + ((OSystem_SDL* )g_system)->getMixerManager()->suspendAudio(); + for (;;) { + if (!SDL_WaitEvent(event)) { + SDL_Delay(10); + continue; + } + if (event->type == SDL_QUIT) + return; + if (event->type != SDL_ACTIVEEVENT) + continue; + if (event->active.state == SDL_APPINPUTFOCUS && event->active.gain) { + ((OSystem_SDL* )g_system)->getMixerManager()->resumeAudio(); + return; + } + } + } + } +} + +bool LinuxmotoSdlEventManager::remapKey(SDL_Event &ev, Common::Event &event) { + if (false) {} + + // Motorol A1200/E6/A1600 remapkey by Lubomyr +#ifdef MOTOEZX + // Quit on MOD+Camera Key on A1200 + if (ev.key.keysym.sym == SDLK_e) { + event.type = Common::EVENT_QUIT; + return true; + } + // '1' Bypass security protection - MOD+Call key + if (ev.key.keysym.sym == SDLK_f) { + ev.key.keysym.sym = SDLK_1; + } + // F5 Game Menu - Call key + else if (ev.key.keysym.sym == SDLK_SPACE) { + ev.key.keysym.sym = SDLK_F5; + } + // VirtualKeyboard - Camera key + else if (ev.key.keysym.sym == SDLK_PAUSE) { + ev.key.keysym.sym = SDLK_F7; + } + // Enter - mod+fire key + else if (ev.key.keysym.sym == SDLK_b) { + ev.key.keysym.sym = SDLK_RETURN; + } + // '3' - mod+up key + else if (ev.key.keysym.sym == SDLK_j) { + ev.key.keysym.sym = SDLK_3; + } + // '6' - mod+up key + else if (ev.key.keysym.sym == SDLK_i) { + ev.key.keysym.sym = SDLK_6; + } + // 'y' - mod+right key + else if (ev.key.keysym.sym == SDLK_g) { + ev.key.keysym.sym = SDLK_y; + } + // 'n' - mod+right key + else if (ev.key.keysym.sym == SDLK_h) { + ev.key.keysym.sym = SDLK_n; + } + // mod+vol'+' -> volume'+' + else if (ev.key.keysym.sym == SDLK_c) { + ev.key.keysym.sym = SDLK_RIGHTBRACKET; + } + // mod+vol'-' -> volume'-' + else if (ev.key.keysym.sym == SDLK_d) { + ev.key.keysym.sym = SDLK_LEFTBRACKET; + } +#endif + +#ifdef MOTOMAGX + // Quit on Clr + if (ev.key.keysym.sym == SDLK_BACKSPACE) { + event.type = Common::EVENT_QUIT; + return true; + } + // Game Menu - Left Soft key + else if (ev.key.keysym.sym == SDLK_F9) { + ev.key.keysym.sym = SDLK_F5; + } + // VirtualKeyboard - Right Soft key + else if (ev.key.keysym.sym == SDLK_F11) { + ev.key.keysym.sym = SDLK_F7; + } +#endif + +// Joystick to Mouse + else if (ev.key.keysym.sym == SDLK_LEFT) { + if (ev.type == SDL_KEYDOWN) { + _km.x_vel = -1; + _km.x_down_count = 1; + } else { + _km.x_vel = 0; + _km.x_down_count = 0; + } + + event.type = Common::EVENT_MOUSEMOVE; + fillMouseEvent(event, _km.x, _km.y); + return true; + } else if (ev.key.keysym.sym == SDLK_RIGHT) { + if (ev.type == SDL_KEYDOWN) { + _km.x_vel = 1; + _km.x_down_count = 1; + } else { + _km.x_vel = 0; + _km.x_down_count = 0; + } + + event.type = Common::EVENT_MOUSEMOVE; + fillMouseEvent(event, _km.x, _km.y); + + return true; + } else if (ev.key.keysym.sym == SDLK_DOWN) { + if (ev.type == SDL_KEYDOWN) { + _km.y_vel = 1; + _km.y_down_count = 1; + } else { + _km.y_vel = 0; + _km.y_down_count = 0; + } + + event.type = Common::EVENT_MOUSEMOVE; + fillMouseEvent(event, _km.x, _km.y); + + return true; + } else if (ev.key.keysym.sym == SDLK_UP) { + if (ev.type == SDL_KEYDOWN) { + _km.y_vel = -1; + _km.y_down_count = 1; + } else { + _km.y_vel = 0; + _km.y_down_count = 0; + } + + event.type = Common::EVENT_MOUSEMOVE; + fillMouseEvent(event, _km.x, _km.y); + + return true; + } else if (ev.key.keysym.sym == SDLK_RETURN) { + // Joystick center to pressing Left Mouse + if (ev.key.type == SDL_KEYDOWN) { + event.type = Common::EVENT_LBUTTONDOWN; + } else { + event.type = Common::EVENT_LBUTTONUP; + } + + fillMouseEvent(event, _km.x, _km.y); + + return true; + } else if (ev.key.keysym.sym == SDLK_PLUS) { + // Volume Up to pressing Right Mouse + if (ev.key.type == SDL_KEYDOWN ) { + event.type = Common::EVENT_RBUTTONDOWN; + } else { + event.type = Common::EVENT_RBUTTONUP; + } + fillMouseEvent(event, _km.x, _km.y); + + return true; + } else if (ev.key.keysym.sym == SDLK_MINUS) { + // Volume Down to pressing Left Mouse + if (ev.key.type == SDL_KEYDOWN) { + event.type = Common::EVENT_LBUTTONDOWN; + } else { + event.type = Common::EVENT_LBUTTONUP; + } + + fillMouseEvent(event, _km.x, _km.y); + + return true; + } else { + // Let the events fall through if we didn't change them, this may not be the best way to + // set it up, but i'm not sure how sdl would like it if we let if fall through then redid it though. + // and yes i have an huge terminal size so i dont wrap soon enough. + event.type = Common::EVENT_KEYDOWN; + event.kbd.keycode = (Common::KeyCode)ev.key.keysym.sym; + event.kbd.ascii = mapKey(ev.key.keysym.sym, ev.key.keysym.mod, ev.key.keysym.unicode); + } + + return false; +} + +#endif diff --git a/backends/events/linuxmotosdl/linuxmotosdl-events.h b/backends/events/linuxmotosdl/linuxmotosdl-events.h new file mode 100644 index 0000000000..414db080ed --- /dev/null +++ b/backends/events/linuxmotosdl/linuxmotosdl-events.h @@ -0,0 +1,43 @@ +/* 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_LINUXMOTO_H) && !defined(DISABLE_DEFAULT_EVENTMANAGER) +#define BACKEND_EVENTS_SDL_LINUXMOTO_H + +#include "backends/events/sdl/sdl-events.h" + +/** + * SDL events manager for LINUXMOTO + */ +class LinuxmotoSdlEventManager : public SdlEventManager { +public: + LinuxmotoSdlEventManager(Common::EventSource *boss); + +protected: + virtual void preprocessEvents(SDL_Event *event); + virtual bool remapKey(SDL_Event &ev, Common::Event &event); +}; + +#endif diff --git a/backends/events/samsungtvsdl/samsungtvsdl-events.cpp b/backends/events/samsungtvsdl/samsungtvsdl-events.cpp new file mode 100644 index 0000000000..d1c35d3a5a --- /dev/null +++ b/backends/events/samsungtvsdl/samsungtvsdl-events.cpp @@ -0,0 +1,78 @@ +/* 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 SAMSUNGTV + +#include "backends/events/samsungtvsdl/samsungtvsdl-events.h" + +SamsungTVSdlEventManager::SamsungTVSdlEventManager(Common::EventSource *boss) + : + SdlEventManager(boss) { + +} + +bool SamsungTVSdlEventManager::remapKey(SDL_Event &ev, Common::Event &event) { + switch (ev.type) { + case SDL_KEYDOWN:{ + if (ev.key.keysym.sym == SDLK_POWER) { + event.type = Common::EVENT_QUIT; + return true; + } else if (ev.key.keysym.sym == SDLK_F1 && ev.key.keysym.scancode == 20) { + event.type = Common::EVENT_KEYDOWN; + event.kbd.keycode = Common::KEYCODE_F5; + event.kbd.ascii = Common::ASCII_F5; + return true; + } else if (ev.key.keysym.sym == SDLK_F2 && ev.key.keysym.scancode == 21) { + event.type = Common::EVENT_KEYDOWN; + event.kbd.keycode = Common::KEYCODE_F7; + event.kbd.ascii = Common::ASCII_F7; + return true; + } + break; + } + case SDL_KEYUP: { + if (ev.key.keysym.sym == SDLK_POWER) { + event.type = Common::EVENT_QUIT; + return true; + } else if (ev.key.keysym.sym == SDLK_F1 && ev.key.keysym.scancode == 20) { + event.type = Common::EVENT_KEYUP; + event.kbd.keycode = Common::KEYCODE_F5; + event.kbd.ascii = Common::ASCII_F5; + return true; + } else if (ev.key.keysym.sym == SDLK_F2 && ev.key.keysym.scancode == 21) { + event.type = Common::EVENT_KEYUP; + event.kbd.keycode = Common::KEYCODE_F7; + event.kbd.ascii = Common::ASCII_F7; + return true; + } + break; + } + } + + // Invoke parent implementation of this method + return SdlEventManager::remapKey(ev, event); +} + +#endif diff --git a/backends/events/samsungtvsdl/samsungtvsdl-events.h b/backends/events/samsungtvsdl/samsungtvsdl-events.h new file mode 100644 index 0000000000..10e1eb84bb --- /dev/null +++ b/backends/events/samsungtvsdl/samsungtvsdl-events.h @@ -0,0 +1,42 @@ +/* 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_SAMSUNGTV_H) && !defined(DISABLE_DEFAULT_EVENTMANAGER) +#define BACKEND_EVENTS_SDL_SAMSUNGTV_H + +#include "backends/events/sdl/sdl-events.h" + +/** + * SDL events manager for Samsung TV + */ +class SamsungTVSdlEventManager : public SdlEventManager { +public: + SamsungTVSdlEventManager(Common::EventSource *boss); + +protected: + virtual bool remapKey(SDL_Event &ev, Common::Event &event); +}; + +#endif diff --git a/backends/events/sdl/sdl-events.cpp b/backends/events/sdl/sdl-events.cpp new file mode 100644 index 0000000000..66685e1886 --- /dev/null +++ b/backends/events/sdl/sdl-events.cpp @@ -0,0 +1,571 @@ +/* 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(WIN32) || defined(UNIX) || defined(MACOSX) + +#include "backends/events/sdl/sdl-events.h" +#include "backends/platform/sdl/sdl.h" +#include "common/config-manager.h" + +// FIXME move joystick defines out and replace with confile file options +// we should really allow users to map any key to a joystick button +#define JOY_DEADZONE 3200 + +#ifndef __SYMBIAN32__ // Symbian wants dialog joystick i.e cursor for movement/selection + #define JOY_ANALOG +#endif + +// #define JOY_INVERT_Y +#define JOY_XAXIS 0 +#define JOY_YAXIS 1 +// buttons +#define JOY_BUT_LMOUSE 0 +#define JOY_BUT_RMOUSE 2 +#define JOY_BUT_ESCAPE 3 +#define JOY_BUT_PERIOD 1 +#define JOY_BUT_SPACE 4 +#define JOY_BUT_F5 5 + +SdlEventManager::SdlEventManager(Common::EventSource *boss) + : + _scrollLock(false), + _joystick(0), + _lastScreenID(0), + DefaultEventManager(boss) { + + // Reset mouse state + memset(&_km, 0, sizeof(_km)); + + int joystick_num = ConfMan.getInt("joystick_num"); + if (joystick_num > -1) { + // Initialize SDL joystick subsystem + if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1) { + error("Could not initialize SDL: %s", SDL_GetError()); + } + + // Enable joystick + if (SDL_NumJoysticks() > 0) { + printf("Using joystick: %s\n", SDL_JoystickName(0)); + _joystick = SDL_JoystickOpen(joystick_num); + } + } +} + +SdlEventManager::~SdlEventManager() { + if (_joystick) + SDL_JoystickClose(_joystick); +} + +int SdlEventManager::mapKey(SDLKey key, SDLMod mod, Uint16 unicode) { + if (key >= SDLK_F1 && key <= SDLK_F9) { + return key - SDLK_F1 + Common::ASCII_F1; + } else if (key >= SDLK_KP0 && key <= SDLK_KP9) { + return key - SDLK_KP0 + '0'; + } else if (key >= SDLK_UP && key <= SDLK_PAGEDOWN) { + return key; + } else if (unicode) { + return unicode; + } else if (key >= 'a' && key <= 'z' && (mod & KMOD_SHIFT)) { + return key & ~0x20; + } else if (key >= SDLK_NUMLOCK && key <= SDLK_EURO) { + return 0; + } + return key; +} + +void SdlEventManager::fillMouseEvent(Common::Event &event, int x, int y) { + event.mouse.x = x; + event.mouse.y = y; + + // Update the "keyboard mouse" coords + _km.x = x; + _km.y = y; +} + +void SdlEventManager::handleKbdMouse() { + uint32 curTime = g_system->getMillis(); + if (curTime >= _km.last_time + _km.delay_time) { + _km.last_time = curTime; + if (_km.x_down_count == 1) { + _km.x_down_time = curTime; + _km.x_down_count = 2; + } + if (_km.y_down_count == 1) { + _km.y_down_time = curTime; + _km.y_down_count = 2; + } + + if (_km.x_vel || _km.y_vel) { + if (_km.x_down_count) { + if (curTime > _km.x_down_time + _km.delay_time * 12) { + if (_km.x_vel > 0) + _km.x_vel++; + else + _km.x_vel--; + } else if (curTime > _km.x_down_time + _km.delay_time * 8) { + if (_km.x_vel > 0) + _km.x_vel = 5; + else + _km.x_vel = -5; + } + } + if (_km.y_down_count) { + if (curTime > _km.y_down_time + _km.delay_time * 12) { + if (_km.y_vel > 0) + _km.y_vel++; + else + _km.y_vel--; + } else if (curTime > _km.y_down_time + _km.delay_time * 8) { + if (_km.y_vel > 0) + _km.y_vel = 5; + else + _km.y_vel = -5; + } + } + + _km.x += _km.x_vel; + _km.y += _km.y_vel; + + if (_km.x < 0) { + _km.x = 0; + _km.x_vel = -1; + _km.x_down_count = 1; + } else if (_km.x > _km.x_max) { + _km.x = _km.x_max; + _km.x_vel = 1; + _km.x_down_count = 1; + } + + if (_km.y < 0) { + _km.y = 0; + _km.y_vel = -1; + _km.y_down_count = 1; + } else if (_km.y > _km.y_max) { + _km.y = _km.y_max; + _km.y_vel = 1; + _km.y_down_count = 1; + } + + SDL_WarpMouse((Uint16)_km.x, (Uint16)_km.y); + } + } +} + +void SdlEventManager::SDLModToOSystemKeyFlags(SDLMod mod, Common::Event &event) { + + event.kbd.flags = 0; + +#ifdef LINUPY + // Yopy has no ALT key, steal the SHIFT key + // (which isn't used much anyway) + if (mod & KMOD_SHIFT) + event.kbd.flags |= Common::KBD_ALT; +#else + if (mod & KMOD_SHIFT) + event.kbd.flags |= Common::KBD_SHIFT; + if (mod & KMOD_ALT) + event.kbd.flags |= Common::KBD_ALT; +#endif + if (mod & KMOD_CTRL) + event.kbd.flags |= Common::KBD_CTRL; + + // Sticky flags + if (mod & KMOD_NUM) + event.kbd.flags |= Common::KBD_NUM; + if (mod & KMOD_CAPS) + event.kbd.flags |= Common::KBD_CAPS; +} + +bool SdlEventManager::pollSdlEvent(Common::Event &event) { + handleKbdMouse(); + + // If the screen changed, send an Common::EVENT_SCREEN_CHANGED + int screenID = ((OSystem_SDL *)g_system)->getGraphicsManager()->getScreenChangeID(); + if (screenID != _lastScreenID) { + _lastScreenID = screenID; + event.type = Common::EVENT_SCREEN_CHANGED; + return true; + } + + SDL_Event ev; + ev.type = SDL_NOEVENT; + while (SDL_PollEvent(&ev)) { + preprocessEvents(&ev); + if (dispatchSDLEvent(ev, event)) + return true; + } + return false; +} + +bool SdlEventManager::dispatchSDLEvent(SDL_Event &ev, Common::Event &event) { + switch (ev.type) { + case SDL_KEYDOWN: + return handleKeyDown(ev, event); + case SDL_KEYUP: + return handleKeyUp(ev, event); + case SDL_MOUSEMOTION: + return handleMouseMotion(ev, event); + case SDL_MOUSEBUTTONDOWN: + return handleMouseButtonDown(ev, event); + case SDL_MOUSEBUTTONUP: + return handleMouseButtonUp(ev, event); + case SDL_JOYBUTTONDOWN: + return handleJoyButtonDown(ev, event); + case SDL_JOYBUTTONUP: + return handleJoyButtonUp(ev, event); + case SDL_JOYAXISMOTION: + return handleJoyAxisMotion(ev, event); + + case SDL_VIDEOEXPOSE: + // HACK: Send a fake event, handled by SdlGraphicsManager + event.type = (Common::EventType)OSystem_SDL::kSdlEventExpose; + return true; + + case SDL_VIDEORESIZE: + // HACK: Send a fake event, handled by OpenGLSdlGraphicsManager + event.type = (Common::EventType)OSystem_SDL::kSdlEventResize; + event.mouse.x = ev.resize.w; + event.mouse.y = ev.resize.h; + return true; + + case SDL_QUIT: + event.type = Common::EVENT_QUIT; + return true; + + } + + return false; +} + + +bool SdlEventManager::handleKeyDown(SDL_Event &ev, Common::Event &event) { + + SDLModToOSystemKeyFlags(SDL_GetModState(), event); + + // Handle scroll lock as a key modifier + if (ev.key.keysym.sym == SDLK_SCROLLOCK) + _scrollLock = !_scrollLock; + + if (_scrollLock) + event.kbd.flags |= Common::KBD_SCRL; + + // Ctrl-m toggles mouse capture + if (event.kbd.hasFlags(Common::KBD_CTRL) && ev.key.keysym.sym == 'm') { + toggleMouseGrab(); + return false; + } + +#if defined(MACOSX) + // On Macintosh', Cmd-Q quits + if ((ev.key.keysym.mod & KMOD_META) && ev.key.keysym.sym == 'q') { + event.type = Common::EVENT_QUIT; + return true; + } +#elif defined(UNIX) + // On other unices, Control-Q quits + if ((ev.key.keysym.mod & KMOD_CTRL) && ev.key.keysym.sym == 'q') { + event.type = Common::EVENT_QUIT; + return true; + } +#else + // Ctrl-z and Alt-X quit + if ((event.kbd.hasFlags(Common::KBD_CTRL) && ev.key.keysym.sym == 'z') || (event.kbd.hasFlags(Common::KBD_ALT) && ev.key.keysym.sym == 'x')) { + event.type = Common::EVENT_QUIT; + return true; + } +#endif + + if ((ev.key.keysym.mod & KMOD_CTRL) && ev.key.keysym.sym == 'u') { + event.type = Common::EVENT_MUTE; + return true; + } + + if (remapKey(ev, event)) + return true; + + event.type = Common::EVENT_KEYDOWN; + event.kbd.keycode = (Common::KeyCode)ev.key.keysym.sym; + event.kbd.ascii = mapKey(ev.key.keysym.sym, ev.key.keysym.mod, ev.key.keysym.unicode); + + return true; +} + +bool SdlEventManager::handleKeyUp(SDL_Event &ev, Common::Event &event) { + if (remapKey(ev, event)) + return true; + + event.type = Common::EVENT_KEYUP; + event.kbd.keycode = (Common::KeyCode)ev.key.keysym.sym; + event.kbd.ascii = mapKey(ev.key.keysym.sym, ev.key.keysym.mod, ev.key.keysym.unicode); + + // Ctrl-Alt-<key> will change the GFX mode + SDLModToOSystemKeyFlags(SDL_GetModState(), event); + + // Set the scroll lock sticky flag + if (_scrollLock) + event.kbd.flags |= Common::KBD_SCRL; + + return true; +} + +bool SdlEventManager::handleMouseMotion(SDL_Event &ev, Common::Event &event) { + event.type = Common::EVENT_MOUSEMOVE; + fillMouseEvent(event, ev.motion.x, ev.motion.y); + + return true; +} + +bool SdlEventManager::handleMouseButtonDown(SDL_Event &ev, Common::Event &event) { + if (ev.button.button == SDL_BUTTON_LEFT) + event.type = Common::EVENT_LBUTTONDOWN; + 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 SdlEventManager::handleMouseButtonUp(SDL_Event &ev, Common::Event &event) { + if (ev.button.button == SDL_BUTTON_LEFT) + event.type = Common::EVENT_LBUTTONUP; + 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; +} + +bool SdlEventManager::handleJoyButtonDown(SDL_Event &ev, Common::Event &event) { + if (ev.jbutton.button == JOY_BUT_LMOUSE) { + event.type = Common::EVENT_LBUTTONDOWN; + fillMouseEvent(event, _km.x, _km.y); + } else if (ev.jbutton.button == JOY_BUT_RMOUSE) { + event.type = Common::EVENT_RBUTTONDOWN; + fillMouseEvent(event, _km.x, _km.y); + } else { + event.type = Common::EVENT_KEYDOWN; + switch (ev.jbutton.button) { + case JOY_BUT_ESCAPE: + event.kbd.keycode = Common::KEYCODE_ESCAPE; + event.kbd.ascii = mapKey(SDLK_ESCAPE, ev.key.keysym.mod, 0); + break; + case JOY_BUT_PERIOD: + event.kbd.keycode = Common::KEYCODE_PERIOD; + event.kbd.ascii = mapKey(SDLK_PERIOD, ev.key.keysym.mod, 0); + break; + case JOY_BUT_SPACE: + event.kbd.keycode = Common::KEYCODE_SPACE; + event.kbd.ascii = mapKey(SDLK_SPACE, ev.key.keysym.mod, 0); + break; + case JOY_BUT_F5: + event.kbd.keycode = Common::KEYCODE_F5; + event.kbd.ascii = mapKey(SDLK_F5, ev.key.keysym.mod, 0); + break; + } + } + return true; +} + +bool SdlEventManager::handleJoyButtonUp(SDL_Event &ev, Common::Event &event) { + if (ev.jbutton.button == JOY_BUT_LMOUSE) { + event.type = Common::EVENT_LBUTTONUP; + fillMouseEvent(event, _km.x, _km.y); + } else if (ev.jbutton.button == JOY_BUT_RMOUSE) { + event.type = Common::EVENT_RBUTTONUP; + fillMouseEvent(event, _km.x, _km.y); + } else { + event.type = Common::EVENT_KEYUP; + switch (ev.jbutton.button) { + case JOY_BUT_ESCAPE: + event.kbd.keycode = Common::KEYCODE_ESCAPE; + event.kbd.ascii = mapKey(SDLK_ESCAPE, ev.key.keysym.mod, 0); + break; + case JOY_BUT_PERIOD: + event.kbd.keycode = Common::KEYCODE_PERIOD; + event.kbd.ascii = mapKey(SDLK_PERIOD, ev.key.keysym.mod, 0); + break; + case JOY_BUT_SPACE: + event.kbd.keycode = Common::KEYCODE_SPACE; + event.kbd.ascii = mapKey(SDLK_SPACE, ev.key.keysym.mod, 0); + break; + case JOY_BUT_F5: + event.kbd.keycode = Common::KEYCODE_F5; + event.kbd.ascii = mapKey(SDLK_F5, ev.key.keysym.mod, 0); + break; + } + } + return true; +} + +bool SdlEventManager::handleJoyAxisMotion(SDL_Event &ev, Common::Event &event) { + int axis = ev.jaxis.value; + if ( axis > JOY_DEADZONE) { + axis -= JOY_DEADZONE; + event.type = Common::EVENT_MOUSEMOVE; + } else if ( axis < -JOY_DEADZONE ) { + axis += JOY_DEADZONE; + event.type = Common::EVENT_MOUSEMOVE; + } else + axis = 0; + + if ( ev.jaxis.axis == JOY_XAXIS) { +#ifdef JOY_ANALOG + _km.x_vel = axis / 2000; + _km.x_down_count = 0; +#else + if (axis != 0) { + _km.x_vel = (axis > 0) ? 1:-1; + _km.x_down_count = 1; + } else { + _km.x_vel = 0; + _km.x_down_count = 0; + } +#endif + + } else if (ev.jaxis.axis == JOY_YAXIS) { +#ifndef JOY_INVERT_Y + axis = -axis; +#endif +#ifdef JOY_ANALOG + _km.y_vel = -axis / 2000; + _km.y_down_count = 0; +#else + if (axis != 0) { + _km.y_vel = (-axis > 0) ? 1: -1; + _km.y_down_count = 1; + } else { + _km.y_vel = 0; + _km.y_down_count = 0; + } +#endif + } + + fillMouseEvent(event, _km.x, _km.y); + + return true; +} + +bool SdlEventManager::remapKey(SDL_Event &ev, Common::Event &event) { +#ifdef LINUPY + // On Yopy map the End button to quit + if ((ev.key.keysym.sym == 293)) { + event.type = Common::EVENT_QUIT; + return true; + } + // Map menu key to f5 (scumm menu) + if (ev.key.keysym.sym == 306) { + event.type = Common::EVENT_KEYDOWN; + event.kbd.keycode = Common::KEYCODE_F5; + event.kbd.ascii = mapKey(SDLK_F5, ev.key.keysym.mod, 0); + return true; + } + // Map action key to action + if (ev.key.keysym.sym == 291) { + event.type = Common::EVENT_KEYDOWN; + event.kbd.keycode = Common::KEYCODE_TAB; + event.kbd.ascii = mapKey(SDLK_TAB, ev.key.keysym.mod, 0); + return true; + } + // Map OK key to skip cinematic + if (ev.key.keysym.sym == 292) { + event.type = Common::EVENT_KEYDOWN; + event.kbd.keycode = Common::KEYCODE_ESCAPE; + event.kbd.ascii = mapKey(SDLK_ESCAPE, ev.key.keysym.mod, 0); + return true; + } +#endif + +#ifdef QTOPIA + // Quit on fn+backspace on zaurus + if (ev.key.keysym.sym == 127) { + event.type = Common::EVENT_QUIT; + return true; + } + + // Map menu key (f11) to f5 (scumm menu) + if (ev.key.keysym.sym == SDLK_F11) { + event.type = Common::EVENT_KEYDOWN; + event.kbd.keycode = Common::KEYCODE_F5; + event.kbd.ascii = mapKey(SDLK_F5, ev.key.keysym.mod, 0); + } + // Nap center (space) to tab (default action ) + // I wanted to map the calendar button but the calendar comes up + // + else if (ev.key.keysym.sym == SDLK_SPACE) { + event.type = Common::EVENT_KEYDOWN; + event.kbd.keycode = Common::KEYCODE_TAB; + event.kbd.ascii = mapKey(SDLK_TAB, ev.key.keysym.mod, 0); + } + // Since we stole space (pause) above we'll rebind it to the tab key on the keyboard + else if (ev.key.keysym.sym == SDLK_TAB) { + event.type = Common::EVENT_KEYDOWN; + event.kbd.keycode = Common::KEYCODE_SPACE; + event.kbd.ascii = mapKey(SDLK_SPACE, ev.key.keysym.mod, 0); + } else { + // Let the events fall through if we didn't change them, this may not be the best way to + // set it up, but i'm not sure how sdl would like it if we let if fall through then redid it though. + // and yes i have an huge terminal size so i dont wrap soon enough. + event.type = Common::EVENT_KEYDOWN; + event.kbd.keycode = ev.key.keysym.sym; + event.kbd.ascii = mapKey(ev.key.keysym.sym, ev.key.keysym.mod, ev.key.keysym.unicode); + } +#endif + return false; +} + +void SdlEventManager::toggleMouseGrab() { + if (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_OFF) + SDL_WM_GrabInput(SDL_GRAB_ON); + else + SDL_WM_GrabInput(SDL_GRAB_OFF); +} + +void SdlEventManager::resetKeyboadEmulation(int16 x_max, int16 y_max) { + _km.x_max = x_max; + _km.y_max = y_max; + _km.delay_time = 25; + _km.last_time = 0; +} + +#endif diff --git a/backends/events/sdl/sdl-events.h b/backends/events/sdl/sdl-events.h new file mode 100644 index 0000000000..4bc2277fcd --- /dev/null +++ b/backends/events/sdl/sdl-events.h @@ -0,0 +1,138 @@ +/* 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_H) && !defined(DISABLE_DEFAULT_EVENTMANAGER) +#define BACKEND_EVENTS_SDL_H + +#include "backends/events/default/default-events.h" + +#if defined(__SYMBIAN32__) +#include <esdl\SDL.h> +#else +#include <SDL.h> +#endif + +/** + * The SDL event manager class. + */ +class SdlEventManager : public DefaultEventManager { +public: + SdlEventManager(Common::EventSource *boss); + virtual ~SdlEventManager(); + + /** + * Gets and proccess SDL events + */ + virtual bool pollSdlEvent(Common::Event &event); + + /** + * Resets keyboard emulation after a video screen change + */ + virtual void resetKeyboadEmulation(int16 x_max, int16 y_max); + + /** + * Toggles mouse input grab + */ + virtual void toggleMouseGrab(); + +protected: + /** @name Keyboard mouse emulation + * Disabled by fingolfin 2004-12-18. + * I am keeping the rest of the code in for now, since the joystick + * code (or rather, "hack") uses it, too. + */ + //@{ + + struct KbdMouse { + int16 x, y, x_vel, y_vel, x_max, y_max, x_down_count, y_down_count; + uint32 last_time, delay_time, x_down_time, y_down_time; + }; + KbdMouse _km; + + //@} + + /** Scroll lock state - since SDL doesn't track it */ + bool _scrollLock; + + /** Joystick */ + SDL_Joystick *_joystick; + + /** Last screen id for checking if it was modified */ + int _lastScreenID; + + /** + * Pre process an event before it is dispatched. + */ + virtual void preprocessEvents(SDL_Event *event) {} + + /** + * Dispatchs SDL events for each handler. + */ + virtual bool dispatchSDLEvent(SDL_Event &ev, Common::Event &event); + + + /** @name Event Handlers + * Handlers for specific SDL events, called by SdlEventManager::dispatchSDLEvent(). + * This way, if a managers inherits fromt this SDL events manager, it can + * change the behavior of only a single event, without having to override all + * of SdlEventManager::dispatchSDLEvent(). + */ + //@{ + + virtual bool handleKeyDown(SDL_Event &ev, Common::Event &event); + virtual bool handleKeyUp(SDL_Event &ev, Common::Event &event); + virtual bool handleMouseMotion(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 handleJoyButtonDown(SDL_Event &ev, Common::Event &event); + virtual bool handleJoyButtonUp(SDL_Event &ev, Common::Event &event); + virtual bool handleJoyAxisMotion(SDL_Event &ev, Common::Event &event); + virtual void handleKbdMouse(); + + //@} + + /** + * Assigns the mouse coords to the mouse event + */ + virtual void fillMouseEvent(Common::Event &event, int x, int y); + + /** + * Remaps key events. This allows platforms to configure + * their custom keys. + */ + virtual bool remapKey(SDL_Event &ev, Common::Event &event); + + /** + * Maps the ASCII value of key + */ + virtual int mapKey(SDLKey key, SDLMod mod, Uint16 unicode); + + /** + * Configures the key modifiers flags status + */ + virtual void SDLModToOSystemKeyFlags(SDLMod mod, Common::Event &event); +}; + +#endif diff --git a/backends/events/symbiansdl/symbiansdl-events.cpp b/backends/events/symbiansdl/symbiansdl-events.cpp new file mode 100644 index 0000000000..2d144f9ad9 --- /dev/null +++ b/backends/events/symbiansdl/symbiansdl-events.cpp @@ -0,0 +1,201 @@ +/* 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 __SYMBIAN32__ + +#include "backends/events/symbiansdl/symbiansdl-events.h" +#include "backends/platform/symbian/src/SymbianActions.h" +#include "gui/message.h" +#include "common/translation.h" + +#include <bautils.h> + +SymbianSdlEventManager::zoneDesc SymbianSdlEventManager::_zones[TOTAL_ZONES] = { + { 0, 0, 320, 145 }, + { 0, 145, 150, 55 }, + { 150, 145, 170, 55 } +}; + +SymbianSdlEventManager::SymbianSdlEventManager(Common::EventSource *boss) + : + _currentZone(0), + SdlEventManager(boss) { + for (int i = 0; i < TOTAL_ZONES; i++) { + _mouseXZone[i] = (_zones[i].x + (_zones[i].width / 2)); + _mouseYZone[i] = (_zones[i].y + (_zones[i].height / 2)); + } +} + +bool SymbianSdlEventManager::remapKey(SDL_Event &ev, Common::Event &event) { + if (GUI::Actions::Instance()->mappingActive() || ev.key.keysym.sym <= SDLK_UNKNOWN) + return false; + + for (TInt loop = 0; loop < GUI::ACTION_LAST; loop++) { + if (GUI::Actions::Instance()->getMapping(loop) == (uint)ev.key.keysym.sym && + GUI::Actions::Instance()->isEnabled(loop)) { + // Create proper event instead + switch (loop) { + case GUI::ACTION_UP: + if (ev.type == SDL_KEYDOWN) { + _km.y_vel = -1; + _km.y_down_count = 1; + } else { + _km.y_vel = 0; + _km.y_down_count = 0; + } + event.type = Common::EVENT_MOUSEMOVE; + fillMouseEvent(event, _km.x, _km.y); + + return true; + + case GUI::ACTION_DOWN: + if (ev.type == SDL_KEYDOWN) { + _km.y_vel = 1; + _km.y_down_count = 1; + } else { + _km.y_vel = 0; + _km.y_down_count = 0; + } + event.type = Common::EVENT_MOUSEMOVE; + fillMouseEvent(event, _km.x, _km.y); + + return true; + + case GUI::ACTION_LEFT: + if (ev.type == SDL_KEYDOWN) { + _km.x_vel = -1; + _km.x_down_count = 1; + } else { + _km.x_vel = 0; + _km.x_down_count = 0; + } + event.type = Common::EVENT_MOUSEMOVE; + fillMouseEvent(event, _km.x, _km.y); + + return true; + + case GUI::ACTION_RIGHT: + if (ev.type == SDL_KEYDOWN) { + _km.x_vel = 1; + _km.x_down_count = 1; + } else { + _km.x_vel = 0; + _km.x_down_count = 0; + } + event.type = Common::EVENT_MOUSEMOVE; + fillMouseEvent(event, _km.x, _km.y); + + return true; + + case GUI::ACTION_LEFTCLICK: + event.type = (ev.type == SDL_KEYDOWN ? Common::EVENT_LBUTTONDOWN : Common::EVENT_LBUTTONUP); + fillMouseEvent(event, _km.x, _km.y); + + return true; + + case GUI::ACTION_RIGHTCLICK: + event.type = (ev.type == SDL_KEYDOWN ? Common::EVENT_RBUTTONDOWN : Common::EVENT_RBUTTONUP); + fillMouseEvent(event, _km.x, _km.y); + + return true; + + case GUI::ACTION_ZONE: + if (ev.type == SDL_KEYDOWN) { + for (int i = 0; i < TOTAL_ZONES; i++) + if (_km.x >= _zones[i].x && _km.y >= _zones[i].y && + _km.x <= _zones[i].x + _zones[i].width && _km.y <= _zones[i].y + _zones[i].height + ) { + _mouseXZone[i] = _km.x; + _mouseYZone[i] = _km.y; + break; + } + _currentZone++; + if (_currentZone >= TOTAL_ZONES) + _currentZone = 0; + event.type = Common::EVENT_MOUSEMOVE; + fillMouseEvent(event, _mouseXZone[_currentZone], _mouseYZone[_currentZone]); + SDL_WarpMouse(event.mouse.x, event.mouse.y); + } + + return true; + case GUI::ACTION_MULTI: { + GUI::Key &key = GUI::Actions::Instance()->getKeyAction(loop); + // if key code is pause, then change event to interactive or just fall through + if (key.keycode() == SDLK_PAUSE) { + event.type = Common::EVENT_PREDICTIVE_DIALOG; + return true; + } + } + case GUI::ACTION_SAVE: + case GUI::ACTION_SKIP: + case GUI::ACTION_SKIP_TEXT: + case GUI::ACTION_PAUSE: + case GUI::ACTION_SWAPCHAR: + case GUI::ACTION_FASTMODE: + case GUI::ACTION_DEBUGGER: + case GUI::ACTION_MAINMENU: + case GUI::ACTION_VKB: + case GUI::ACTION_KEYMAPPER:{ + GUI::Key &key = GUI::Actions::Instance()->getKeyAction(loop); + ev.key.keysym.sym = (SDLKey) key.keycode(); + ev.key.keysym.scancode = 0; + ev.key.keysym.mod = (SDLMod) key.flags(); + + // Translate from SDL keymod event to Scummvm Key Mod Common::Event. + // This codes is also present in GP32 backend and in SDL backend as a static function + // Perhaps it should be shared. + if (key.flags() != 0) { + event.kbd.flags = 0; + + if (ev.key.keysym.mod & KMOD_SHIFT) + event.kbd.flags |= Common::KBD_SHIFT; + + if (ev.key.keysym.mod & KMOD_ALT) + event.kbd.flags |= Common::KBD_ALT; + + if (ev.key.keysym.mod & KMOD_CTRL) + event.kbd.flags |= Common::KBD_CTRL; + } + + return false; + } + + case GUI::ACTION_QUIT: + { + GUI::MessageDialog alert(_("Do you want to quit ?"), _("Yes"), _("No")); + if (alert.runModal() == GUI::kMessageOK) + g_system->quit(); + + return true; + } + } + } + } + + return false; +} + +#endif + diff --git a/backends/events/symbiansdl/symbiansdl-events.h b/backends/events/symbiansdl/symbiansdl-events.h new file mode 100644 index 0000000000..fa1c066cae --- /dev/null +++ b/backends/events/symbiansdl/symbiansdl-events.h @@ -0,0 +1,59 @@ +/* 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_SYMBIAN_SDL_H) && !defined(DISABLE_DEFAULT_EVENTMANAGER) +#define BACKEND_EVENTS_SYMBIAN_SDL_H + +#include "backends/events/sdl/sdl-events.h" + +#define TOTAL_ZONES 3 + +/** + * SDL events manager for Symbian + */ +class SymbianSdlEventManager : public SdlEventManager { +public: + SymbianSdlEventManager(Common::EventSource *boss); + +protected: + // Used to handle joystick navi zones + int _mouseXZone[TOTAL_ZONES]; + int _mouseYZone[TOTAL_ZONES]; + int _currentZone; + + struct zoneDesc { + int x; + int y; + int width; + int height; + }; + + static zoneDesc _zones[TOTAL_ZONES]; + + virtual bool remapKey(SDL_Event &ev, Common::Event &event); +}; + +#endif + |