ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

resvm-sdl-events.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "common/scummsys.h"
00024 
00025 #if defined(SDL_BACKEND)
00026 
00027 #include "resvm-sdl-events.h"
00028 #include "backends/graphics/sdl/resvm-sdl-graphics.h"
00029 #include "engines/engine.h"
00030 #include "gui/gui-manager.h"
00031 
00032 bool ResVmSdlEventSource::handleJoyButtonDown(SDL_Event &ev, Common::Event &event) {
00033     if (shouldGenerateMouseEvents()) {
00034         return SdlEventSource::handleJoyButtonDown(ev, event);
00035     } else {
00036         event.type = Common::EVENT_JOYBUTTON_DOWN;
00037         event.joystick.button = ev.jbutton.button;
00038         return true;
00039     }
00040 }
00041 
00042 bool ResVmSdlEventSource::handleJoyButtonUp(SDL_Event &ev, Common::Event &event) {
00043     if (shouldGenerateMouseEvents()) {
00044         return SdlEventSource::handleJoyButtonUp(ev, event);
00045     } else {
00046         event.type = Common::EVENT_JOYBUTTON_UP;
00047         event.joystick.button = ev.jbutton.button;
00048         return true;
00049     }
00050 }
00051 
00052 bool ResVmSdlEventSource::handleJoyAxisMotion(SDL_Event &ev, Common::Event &event) {
00053     if (shouldGenerateMouseEvents()) {
00054         return SdlEventSource::handleJoyAxisMotion(ev, event);
00055     } else {
00056         event.type = Common::EVENT_JOYAXIS_MOTION;
00057         event.joystick.axis = ev.jaxis.axis;
00058         event.joystick.position = ev.jaxis.value;
00059         return true;
00060     }
00061 }
00062 
00063 #if SDL_VERSION_ATLEAST(2, 0, 0)
00064 bool ResVmSdlEventSource::handleControllerButton(const SDL_Event &ev, Common::Event &event, bool buttonUp) {
00065     if (shouldGenerateMouseEvents()) {
00066         return SdlEventSource::handleControllerButton(ev, event, buttonUp);
00067     } else {
00068         event.type = buttonUp ? Common::EVENT_JOYBUTTON_UP : Common::EVENT_JOYBUTTON_DOWN;
00069         event.joystick.button = ev.cbutton.button;
00070         return true;
00071     }
00072 }
00073 
00074 bool ResVmSdlEventSource::handleControllerAxisMotion(const SDL_Event &ev, Common::Event &event) {
00075     if (shouldGenerateMouseEvents()) {
00076         return SdlEventSource::handleControllerAxisMotion(ev, event);
00077     } else {
00078         event.type = Common::EVENT_JOYAXIS_MOTION;
00079         event.joystick.axis = ev.caxis.axis;
00080         event.joystick.position = ev.caxis.value;
00081         return true;
00082     }
00083 }
00084 #endif
00085 
00086 bool ResVmSdlEventSource::shouldGenerateMouseEvents() {
00087     // Engine doesn't support joystick -> emulate mouse events
00088     if (g_engine && !g_engine->hasFeature(Engine::kSupportsJoystick)) {
00089         return true;
00090     }
00091 
00092     if (g_gui.isActive()) {
00093         return true;
00094     }
00095 
00096     return false;
00097 }
00098 
00099 bool ResVmSdlEventSource::handleKbdMouse(Common::Event &event) {
00100     // The ResidualVM version of this method handles relative mouse
00101     // movement, as required by Myst III.
00102 
00103     int16 oldKmX = _km.x;
00104     int16 oldKmY = _km.y;
00105 
00106     updateKbdMouse();
00107 
00108     if (_km.x != oldKmX || _km.y != oldKmY) {
00109         ResVmSdlGraphicsManager *graphicsManager = dynamic_cast<ResVmSdlGraphicsManager *>(_graphicsManager);
00110 
00111         int16 relX = _km.x - oldKmX;
00112         int16 relY = _km.y - oldKmY;
00113 
00114         if (graphicsManager && graphicsManager->isMouseLocked()) {
00115             _km.x = oldKmX;
00116             _km.y = oldKmY;
00117         }
00118 
00119         if (graphicsManager) {
00120             graphicsManager->getWindow()->warpMouseInWindow((Uint16)(_km.x / MULTIPLIER), (Uint16)(_km.y / MULTIPLIER));
00121         }
00122 
00123         event.type = Common::EVENT_MOUSEMOVE;
00124         return processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER, relX / MULTIPLIER, relY / MULTIPLIER);
00125     }
00126 
00127     return false;
00128 }
00129 
00130 #endif


Generated on Sat Feb 16 2019 05:01:02 for ResidualVM by doxygen 1.7.1
curved edge   curved edge