diff options
author | Max Horn | 2009-11-09 23:33:05 +0000 |
---|---|---|
committer | Max Horn | 2009-11-09 23:33:05 +0000 |
commit | be0e94f4cd06694665e0a622310eb29a34e6ad2b (patch) | |
tree | 73a5f4d9347173381ad2f87ccfaeba18c83c131e | |
parent | fc1758f33b31a9cbc5630643cf7c4017923fac7f (diff) | |
download | scummvm-rg350-be0e94f4cd06694665e0a622310eb29a34e6ad2b.tar.gz scummvm-rg350-be0e94f4cd06694665e0a622310eb29a34e6ad2b.tar.bz2 scummvm-rg350-be0e94f4cd06694665e0a622310eb29a34e6ad2b.zip |
Indention
svn-id: r45793
-rw-r--r-- | backends/platform/sdl/events.cpp | 451 |
1 files changed, 225 insertions, 226 deletions
diff --git a/backends/platform/sdl/events.cpp b/backends/platform/sdl/events.cpp index 3dc9649c9a..a20e0b4387 100644 --- a/backends/platform/sdl/events.cpp +++ b/backends/platform/sdl/events.cpp @@ -192,304 +192,303 @@ bool OSystem_SDL::pollEvent(Common::Event &event) { } bool OSystem_SDL::dispatchSDLEvent(const 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: - _forceFull = true; - break; - - case SDL_QUIT: - event.type = Common::EVENT_QUIT; - return true; + 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: + _forceFull = true; + break; + + case SDL_QUIT: + event.type = Common::EVENT_QUIT; + return true; - } - - return false; + } + + return false; } bool OSystem_SDL::handleKeyDown(const SDL_Event &ev, Common::Event &event) { byte b = 0; - b = event.kbd.flags = SDLModToOSystemKeyFlags(SDL_GetModState()); - - // Alt-Return and Alt-Enter toggle full screen mode - if (b == Common::KBD_ALT && (ev.key.keysym.sym == SDLK_RETURN - || ev.key.keysym.sym == SDLK_KP_ENTER)) { - beginGFXTransaction(); - setFullscreenMode(!_videoMode.fullscreen); - endGFXTransaction(); + b = event.kbd.flags = SDLModToOSystemKeyFlags(SDL_GetModState()); + + // Alt-Return and Alt-Enter toggle full screen mode + if (b == Common::KBD_ALT && (ev.key.keysym.sym == SDLK_RETURN + || ev.key.keysym.sym == SDLK_KP_ENTER)) { + beginGFXTransaction(); + setFullscreenMode(!_videoMode.fullscreen); + endGFXTransaction(); #ifdef USE_OSD - if (_videoMode.fullscreen) - displayMessageOnOSD("Fullscreen mode"); - else - displayMessageOnOSD("Windowed mode"); + if (_videoMode.fullscreen) + displayMessageOnOSD("Fullscreen mode"); + else + displayMessageOnOSD("Windowed mode"); #endif - return false; - } + return false; + } - // Alt-S: Create a screenshot - if (b == Common::KBD_ALT && ev.key.keysym.sym == 's') { - char filename[20]; + // Alt-S: Create a screenshot + if (b == Common::KBD_ALT && ev.key.keysym.sym == 's') { + char filename[20]; - for (int n = 0;; n++) { - SDL_RWops *file; + for (int n = 0;; n++) { + SDL_RWops *file; - sprintf(filename, "scummvm%05d.bmp", n); - file = SDL_RWFromFile(filename, "r"); - if (!file) - return false; - SDL_RWclose(file); - } - if (saveScreenshot(filename)) - printf("Saved '%s'\n", filename); - else - printf("Could not save screenshot!\n"); + sprintf(filename, "scummvm%05d.bmp", n); + file = SDL_RWFromFile(filename, "r"); + if (!file) return false; - } + SDL_RWclose(file); + } + if (saveScreenshot(filename)) + printf("Saved '%s'\n", filename); + else + printf("Could not save screenshot!\n"); + return false; + } - // Ctrl-m toggles mouse capture - if (b == Common::KBD_CTRL && ev.key.keysym.sym == 'm') { - toggleMouseGrab(); - return false; - } + // Ctrl-m toggles mouse capture + if (b == 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; - } + // 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; - } + // 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 ((b == Common::KBD_CTRL && ev.key.keysym.sym == 'z') || (b == Common::KBD_ALT && ev.key.keysym.sym == 'x')) { - event.type = Common::EVENT_QUIT; - return true; - } + // Ctrl-z and Alt-X quit + if ((b == Common::KBD_CTRL && ev.key.keysym.sym == 'z') || (b == 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 ((ev.key.keysym.mod & KMOD_CTRL) && ev.key.keysym.sym == 'u') { + event.type = Common::EVENT_MUTE; + return true; + } - // Ctrl-Alt-<key> will change the GFX mode - if ((b & (Common::KBD_CTRL|Common::KBD_ALT)) == (Common::KBD_CTRL|Common::KBD_ALT)) { + // Ctrl-Alt-<key> will change the GFX mode + if ((b & (Common::KBD_CTRL|Common::KBD_ALT)) == (Common::KBD_CTRL|Common::KBD_ALT)) { - handleScalerHotkeys(ev.key); - return false; - } - const bool event_complete = remapKey(ev, event); + handleScalerHotkeys(ev.key); + return false; + } + const bool event_complete = remapKey(ev, event); - if (event_complete) - return true; + if (event_complete) + 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); + 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; + return true; } bool OSystem_SDL::handleKeyUp(const SDL_Event &ev, Common::Event &event) { byte b = 0; - const bool event_complete = remapKey(ev,event); + const bool event_complete = remapKey(ev,event); - if (event_complete) - return true; + if (event_complete) + 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); - b = event.kbd.flags = SDLModToOSystemKeyFlags(SDL_GetModState()); + 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); + b = event.kbd.flags = SDLModToOSystemKeyFlags(SDL_GetModState()); - // Ctrl-Alt-<key> will change the GFX mode - if ((b & (Common::KBD_CTRL|Common::KBD_ALT)) == (Common::KBD_CTRL|Common::KBD_ALT)) { - // Swallow these key up events - return false; - } + // Ctrl-Alt-<key> will change the GFX mode + if ((b & (Common::KBD_CTRL|Common::KBD_ALT)) == (Common::KBD_CTRL|Common::KBD_ALT)) { + // Swallow these key up events + return false; + } - return true; + return true; } bool OSystem_SDL::handleMouseMotion(const SDL_Event &ev, Common::Event &event) { - event.type = Common::EVENT_MOUSEMOVE; - fillMouseEvent(event, ev.motion.x, ev.motion.y); + event.type = Common::EVENT_MOUSEMOVE; + fillMouseEvent(event, ev.motion.x, ev.motion.y); - setMousePos(event.mouse.x, event.mouse.y); - return true; + setMousePos(event.mouse.x, event.mouse.y); + return true; } bool OSystem_SDL::handleMouseButtonDown(const 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 (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; + 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; + else if (ev.button.button == SDL_BUTTON_MIDDLE) + event.type = Common::EVENT_MBUTTONDOWN; #endif - else - return false; + else + return false; - fillMouseEvent(event, ev.button.x, ev.button.y); + fillMouseEvent(event, ev.button.x, ev.button.y); - return true; + return true; } bool OSystem_SDL::handleMouseButtonUp(const 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 (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; + 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); + else + return false; + fillMouseEvent(event, ev.button.x, ev.button.y); - return true; + return true; } bool OSystem_SDL::handleJoyButtonDown(const 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; + 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 OSystem_SDL::handleJoyButtonUp(const 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; + 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 OSystem_SDL::handleJoyAxisMotion(const SDL_Event &ev, Common::Event &event) { - int axis; - 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) { + 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; + _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; - } + 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) { + } else if (ev.jaxis.axis == JOY_YAXIS) { #ifndef JOY_INVERT_Y - axis = -axis; + axis = -axis; #endif #ifdef JOY_ANALOG - _km.y_vel = -axis / 2000; - _km.y_down_count = 0; + _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; - } + 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); + fillMouseEvent(event, _km.x, _km.y); - return true; + return true; } bool OSystem_SDL::remapKey(const SDL_Event &ev, Common::Event &event) { |