diff options
-rw-r--r-- | backends/events/linuxmotosdl/linuxmotosdl-events.cpp (renamed from backends/platform/linuxmoto/linuxmoto-events.cpp) | 66 | ||||
-rw-r--r-- | backends/events/linuxmotosdl/linuxmotosdl-events.h | 41 | ||||
-rw-r--r-- | backends/events/sdl/sdl-events.h | 5 | ||||
-rw-r--r-- | backends/graphics/linuxmotosdl/linuxmotosdl-graphics.cpp (renamed from backends/platform/linuxmoto/linuxmoto-graphics.cpp) | 66 | ||||
-rw-r--r-- | backends/graphics/linuxmotosdl/linuxmotosdl-graphics.h | 51 | ||||
-rw-r--r-- | backends/mixer/sdl/sdl-mixer.cpp | 19 | ||||
-rw-r--r-- | backends/mixer/sdl/sdl-mixer.h | 5 | ||||
-rw-r--r-- | backends/platform/linuxmoto/linuxmoto-main.cpp | 11 | ||||
-rw-r--r-- | backends/platform/linuxmoto/linuxmoto-sdl.cpp | 47 | ||||
-rw-r--r-- | backends/platform/linuxmoto/linuxmoto-sdl.h | 38 | ||||
-rw-r--r-- | backends/platform/linuxmoto/module.mk | 2 | ||||
-rw-r--r-- | backends/platform/sdl/sdl.cpp | 5 | ||||
-rw-r--r-- | backends/platform/sdl/sdl.h | 3 |
13 files changed, 238 insertions, 121 deletions
diff --git a/backends/platform/linuxmoto/linuxmoto-events.cpp b/backends/events/linuxmotosdl/linuxmotosdl-events.cpp index 379e34b7ac..f27042ea5d 100644 --- a/backends/platform/linuxmoto/linuxmoto-events.cpp +++ b/backends/events/linuxmotosdl/linuxmotosdl-events.cpp @@ -23,8 +23,46 @@ * */ +#if defined(LINUXMOTO) + +#include "backends/events/linuxmotosdl/linuxmotosdl-events.h" #include "backends/platform/linuxmoto/linuxmoto-sdl.h" -#include "graphics/scaler/aspect.h" // for aspect2Real + +enum { + GFX_HALF = 12 +}; + +LinuxmotoSdlEventManager::LinuxmotoSdlEventManager(Common::EventSource *boss) + : + SdlEventManager(boss) { + +} + +LinuxmotoSdlEventManager::~LinuxmotoSdlEventManager() { + +} + +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; + } + } + } + } +} static int mapKey(SDLKey key, SDLMod mod, Uint16 unicode) { if (key >= SDLK_F1 && key <= SDLK_F9) { @@ -43,29 +81,9 @@ static int mapKey(SDLKey key, SDLMod mod, Uint16 unicode) { return key; } -void OSystem_LINUXMOTO::fillMouseEvent(Common::Event &event, int x, int y) { - if (_videoMode.mode == GFX_HALF && !_overlayVisible) { - event.mouse.x = x*2; - event.mouse.y = y*2; - } else { - event.mouse.x = x; - event.mouse.y = y; - } - - // Update the "keyboard mouse" coords - _km.x = x; - _km.y = y; +bool LinuxmotoSdlEventManager::remapKey(SDL_Event &ev, Common::Event &event) { + if (false) {} - // Adjust for the screen scaling - if (!_overlayVisible) { - event.mouse.x /= _videoMode.scaleFactor; - event.mouse.y /= _videoMode.scaleFactor; - if (_videoMode.aspectRatioCorrection) - event.mouse.y = aspect2Real(event.mouse.y); - } -} - -bool OSystem_LINUXMOTO::remapKey(SDL_Event &ev, Common::Event &event) { // Motorol A1200/E6/A1600 remapkey by Lubomyr #ifdef MOTOEZX // Quit on MOD+Camera Key on A1200 @@ -226,3 +244,5 @@ bool OSystem_LINUXMOTO::remapKey(SDL_Event &ev, Common::Event &event) { 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..d7ad715adb --- /dev/null +++ b/backends/events/linuxmotosdl/linuxmotosdl-events.h @@ -0,0 +1,41 @@ +/* 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" + +class LinuxmotoSdlEventManager : public SdlEventManager { +public: + LinuxmotoSdlEventManager(Common::EventSource *boss); + virtual ~LinuxmotoSdlEventManager(); + +protected: + virtual void preprocessEvents(SDL_Event *event); + virtual bool remapKey(SDL_Event &ev, Common::Event &event); +}; + +#endif diff --git a/backends/events/sdl/sdl-events.h b/backends/events/sdl/sdl-events.h index 7a399cc186..0f6cb998a8 100644 --- a/backends/events/sdl/sdl-events.h +++ b/backends/events/sdl/sdl-events.h @@ -43,6 +43,8 @@ public: virtual void resetKeyboadEmulation(int16 x_max, int16 y_max); + virtual void toggleMouseGrab(); + protected: virtual void preprocessEvents(SDL_Event *event) {} @@ -77,8 +79,7 @@ protected: virtual bool handleJoyButtonUp(SDL_Event &ev, Common::Event &event); virtual bool handleJoyAxisMotion(SDL_Event &ev, Common::Event &event); - virtual void fillMouseEvent(Common::Event &event, int x, int y); // overloaded by CE backend - virtual void toggleMouseGrab(); + virtual void fillMouseEvent(Common::Event &event, int x, int y); virtual void handleKbdMouse(); virtual bool remapKey(SDL_Event &ev, Common::Event &event); diff --git a/backends/platform/linuxmoto/linuxmoto-graphics.cpp b/backends/graphics/linuxmotosdl/linuxmotosdl-graphics.cpp index a39416ebc4..373bdc2346 100644 --- a/backends/platform/linuxmoto/linuxmoto-graphics.cpp +++ b/backends/graphics/linuxmotosdl/linuxmotosdl-graphics.cpp @@ -23,8 +23,10 @@ * */ -#include "backends/platform/linuxmoto/linuxmoto-sdl.h" +#ifdef LINUXMOTO +#include "backends/graphics/linuxmotosdl/linuxmotosdl-graphics.h" +#include "backends/events/linuxmotosdl/linuxmotosdl-events.h" #include "common/mutex.h" #include "graphics/font.h" #include "graphics/fontman.h" @@ -33,22 +35,33 @@ #include "graphics/scaler/downscaler.h" #include "graphics/surface.h" +enum { + GFX_HALF = 12 +}; + static const OSystem::GraphicsMode s_supportedGraphicsModes[] = { {"1x", "Fullscreen", GFX_NORMAL}, {"½x", "Downscale", GFX_HALF}, {0, 0, 0} }; +LinuxmotoSdlGraphicsManager::LinuxmotoSdlGraphicsManager() { + +} + +LinuxmotoSdlGraphicsManager::~LinuxmotoSdlGraphicsManager() { + +} -const OSystem::GraphicsMode *OSystem_LINUXMOTO::getSupportedGraphicsModes() const { +const OSystem::GraphicsMode *LinuxmotoSdlGraphicsManager::getSupportedGraphicsModes() const { return s_supportedGraphicsModes; } -int OSystem_LINUXMOTO::getDefaultGraphicsMode() const { +int LinuxmotoSdlGraphicsManager::getDefaultGraphicsMode() const { return GFX_NORMAL; } -bool OSystem_LINUXMOTO::setGraphicsMode(int mode) { +bool LinuxmotoSdlGraphicsManager::setGraphicsMode(int mode) { Common::StackLock lock(_graphicsMutex); assert(_transactionMode == kTransactionActive); @@ -82,7 +95,7 @@ bool OSystem_LINUXMOTO::setGraphicsMode(int mode) { return true; } -void OSystem_LINUXMOTO::setGraphicsModeIntern() { +void LinuxmotoSdlGraphicsManager::setGraphicsModeIntern() { Common::StackLock lock(_graphicsMutex); ScalerProc *newScalerProc = 0; @@ -112,7 +125,7 @@ void OSystem_LINUXMOTO::setGraphicsModeIntern() { } -void OSystem_LINUXMOTO::initSize(uint w, uint h) { +void LinuxmotoSdlGraphicsManager::initSize(uint w, uint h) { assert(_transactionMode == kTransactionActive); // Avoid redundant res changes @@ -125,13 +138,13 @@ void OSystem_LINUXMOTO::initSize(uint w, uint h) { if (w > 320 || h > 240) { setGraphicsMode(GFX_HALF); setGraphicsModeIntern(); - toggleMouseGrab(); + ((LinuxmotoSdlEventManager *)g_system->getEventManager())->toggleMouseGrab(); } _transactionDetails.sizeChanged = true; } -bool OSystem_LINUXMOTO::loadGFXMode() { +bool LinuxmotoSdlGraphicsManager::loadGFXMode() { printf("Game ScreenMode = %d*%d\n",_videoMode.screenWidth, _videoMode.screenHeight); if (_videoMode.screenWidth > 320 || _videoMode.screenHeight > 240) { _videoMode.aspectRatioCorrection = false; @@ -157,10 +170,10 @@ bool OSystem_LINUXMOTO::loadGFXMode() { _videoMode.hardwareHeight = effectiveScreenHeight(); } - return OSystem_SDL::loadGFXMode(); + return SdlGraphicsManager::loadGFXMode(); } -void OSystem_LINUXMOTO::drawMouse() { +void LinuxmotoSdlGraphicsManager::drawMouse() { if (!_mouseVisible || !_mouseSurface) { _mouseBackup.x = _mouseBackup.y = _mouseBackup.w = _mouseBackup.h = 0; return; @@ -226,7 +239,7 @@ void OSystem_LINUXMOTO::drawMouse() { addDirtyRect(dst.x, dst.y, dst.w, dst.h, true); } -void OSystem_LINUXMOTO::undrawMouse() { +void LinuxmotoSdlGraphicsManager::undrawMouse() { const int x = _mouseBackup.x; const int y = _mouseBackup.y; @@ -244,13 +257,13 @@ void OSystem_LINUXMOTO::undrawMouse() { } } -void OSystem_LINUXMOTO::internUpdateScreen() { +void LinuxmotoSdlGraphicsManager::internUpdateScreen() { SDL_Surface *srcSurf, *origSurf; int height, width; ScalerProc *scalerProc; int scale1; -#if defined (DEBUG) && ! defined(_WIN32_WCE) // definitions not available for non-DEBUG here. (needed this to compile in SYMBIAN32 & linux?) +#if defined (DEBUG) // definitions not available for non-DEBUG here. (needed this to compile in SYMBIAN32 & linux?) assert(_hwscreen != NULL); assert(_hwscreen->map->sw_data != NULL); #endif @@ -443,28 +456,43 @@ void OSystem_LINUXMOTO::internUpdateScreen() { _mouseNeedsRedraw = false; } -void OSystem_LINUXMOTO::showOverlay() { +void LinuxmotoSdlGraphicsManager::showOverlay() { if (_videoMode.mode == GFX_HALF) { _mouseCurState.x = _mouseCurState.x / 2; _mouseCurState.y = _mouseCurState.y / 2; } - OSystem_SDL::showOverlay(); + SdlGraphicsManager::showOverlay(); } -void OSystem_LINUXMOTO::hideOverlay() { +void LinuxmotoSdlGraphicsManager::hideOverlay() { if (_videoMode.mode == GFX_HALF) { _mouseCurState.x = _mouseCurState.x * 2; _mouseCurState.y = _mouseCurState.y * 2; } - OSystem_SDL::hideOverlay(); + SdlGraphicsManager::hideOverlay(); } -void OSystem_LINUXMOTO::warpMouse(int x, int y) { +void LinuxmotoSdlGraphicsManager::warpMouse(int x, int y) { if (_mouseCurState.x != x || _mouseCurState.y != y) { if (_videoMode.mode == GFX_HALF && !_overlayVisible) { x = x / 2; y = y / 2; } } - OSystem_SDL::warpMouse(x, y); + SdlGraphicsManager::warpMouse(x, y); } + +void LinuxmotoSdlGraphicsManager::adjustMouseEvent(Common::Event &event) { + if (!_overlayVisible) { + if (_videoMode.mode == GFX_HALF) { + event.mouse.x *= 2; + event.mouse.y *= 2; + } + event.mouse.x /= _videoMode.scaleFactor; + event.mouse.y /= _videoMode.scaleFactor; + if (_videoMode.aspectRatioCorrection) + event.mouse.y = aspect2Real(event.mouse.y); + } +} + +#endif diff --git a/backends/graphics/linuxmotosdl/linuxmotosdl-graphics.h b/backends/graphics/linuxmotosdl/linuxmotosdl-graphics.h new file mode 100644 index 0000000000..186e2a083b --- /dev/null +++ b/backends/graphics/linuxmotosdl/linuxmotosdl-graphics.h @@ -0,0 +1,51 @@ +/* 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$ + * + */ + +#ifndef BACKENDS_GRAPHICS_SDL_LINUXMOTO_H +#define BACKENDS_GRAPHICS_SDL_LINUXMOTO_H + +#include "backends/graphics/sdl/sdl-graphics.h" + +class LinuxmotoSdlGraphicsManager : public SdlGraphicsManager { +public: + LinuxmotoSdlGraphicsManager(); + virtual ~LinuxmotoSdlGraphicsManager(); + + virtual void initSize(uint w, uint h); + virtual void setGraphicsModeIntern(); + virtual bool setGraphicsMode(int mode); + virtual void internUpdateScreen(); + virtual const OSystem::GraphicsMode *getSupportedGraphicsModes() const; + virtual int getDefaultGraphicsMode() const; + virtual bool loadGFXMode(); + virtual void drawMouse(); + virtual void undrawMouse(); + virtual void showOverlay(); + virtual void hideOverlay(); + virtual void warpMouse(int x, int y); + virtual void adjustMouseEvent(Common::Event &event); +}; + +#endif diff --git a/backends/mixer/sdl/sdl-mixer.cpp b/backends/mixer/sdl/sdl-mixer.cpp index aa87fcb345..2317a03335 100644 --- a/backends/mixer/sdl/sdl-mixer.cpp +++ b/backends/mixer/sdl/sdl-mixer.cpp @@ -35,7 +35,8 @@ SdlMixerManager::SdlMixerManager() : - _mixer(0) { + _mixer(0), + _audioSuspended(false) { } @@ -120,4 +121,20 @@ void SdlMixerManager::sdlCallback(void *this_, byte *samples, int len) { manager->callbackHandler(samples, len); } +void SdlMixerManager::suspendAudio() { + SDL_CloseAudio(); + _audioSuspended = true; +} + +int SdlMixerManager::resumeAudio() { + if (!_audioSuspended) + return -2; + if (SDL_OpenAudio(&_obtainedRate, NULL) < 0){ + return -1; + } + SDL_PauseAudio(0); + _audioSuspended = false; + return 0; +} + #endif diff --git a/backends/mixer/sdl/sdl-mixer.h b/backends/mixer/sdl/sdl-mixer.h index e4e8263f38..f58260fef2 100644 --- a/backends/mixer/sdl/sdl-mixer.h +++ b/backends/mixer/sdl/sdl-mixer.h @@ -43,9 +43,14 @@ public: Audio::Mixer *getMixer() { return (Audio::Mixer *)_mixer; } + // Used by LinuxMoto Port + virtual void suspendAudio(); + virtual int resumeAudio(); + protected: Audio::MixerImpl *_mixer; SDL_AudioSpec _obtainedRate; + bool _audioSuspended; virtual SDL_AudioSpec getAudioSpec(); virtual void startAudio(); diff --git a/backends/platform/linuxmoto/linuxmoto-main.cpp b/backends/platform/linuxmoto/linuxmoto-main.cpp index b971a65f7e..dfd1428d8b 100644 --- a/backends/platform/linuxmoto/linuxmoto-main.cpp +++ b/backends/platform/linuxmoto/linuxmoto-main.cpp @@ -26,19 +26,20 @@ #include "common/scummsys.h" #include "common/system.h" -#include <SDL/SDL.h> -#include <SDL/SDL_syswm.h> - #include "backends/platform/linuxmoto/linuxmoto-sdl.h" #include "base/main.h" -#include "base/internal_version.h" int main(int argc, char *argv[]) { + + // Create our OSystem instance g_system = new OSystem_LINUXMOTO(); assert(g_system); + // Invoke the actual ScummVM main entry point: int res = scummvm_main(argc, argv); - g_system->quit(); // TODO: Consider removing / replacing this! + + // Free OSystem + delete (OSystem_LINUXMOTO *)g_system; return res; } diff --git a/backends/platform/linuxmoto/linuxmoto-sdl.cpp b/backends/platform/linuxmoto/linuxmoto-sdl.cpp index ad1af455c3..696c339638 100644 --- a/backends/platform/linuxmoto/linuxmoto-sdl.cpp +++ b/backends/platform/linuxmoto/linuxmoto-sdl.cpp @@ -25,44 +25,17 @@ #include "backends/platform/linuxmoto/linuxmoto-sdl.h" -void OSystem_LINUXMOTO::preprocessEvents(SDL_Event *event) { - if (event->type == SDL_ACTIVEEVENT) { - if (event->active.state == SDL_APPINPUTFOCUS && !event->active.gain) { - 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) { - resumeAudio(); - return; - } - } - } - } -} +#include "backends/graphics/linuxmotosdl/linuxmotosdl-graphics.h" +#include "backends/events/linuxmotosdl/linuxmotosdl-events.h" -void OSystem_LINUXMOTO::suspendAudio() { - SDL_CloseAudio(); - _audioSuspended = true; -} +void OSystem_LINUXMOTO::initBackend() { + // Create the backend custom managers + if (_eventsManager == 0) + _eventsManager = new LinuxmotoSdlEventManager(); -int OSystem_LINUXMOTO::resumeAudio() { - if (!_audioSuspended) - return -2; - if (SDL_OpenAudio(&_obtainedRate, NULL) < 0){ - return -1; - } - SDL_PauseAudio(0); - _audioSuspended = false; - return 0; -} + if (_graphicsManager == 0) + _graphicsManager = new LinuxmotoSdlGraphicsManager(); -void OSystem_LINUXMOTO::setupMixer() { - OSystem_SDL::setupMixer(); + // Call parent implementation of this method + OSystem_POSIX::initBackend(); } diff --git a/backends/platform/linuxmoto/linuxmoto-sdl.h b/backends/platform/linuxmoto/linuxmoto-sdl.h index c01d375603..78b9f81fd2 100644 --- a/backends/platform/linuxmoto/linuxmoto-sdl.h +++ b/backends/platform/linuxmoto/linuxmoto-sdl.h @@ -23,43 +23,17 @@ * */ -#ifndef LINUXMOTO_SDL -#define LINUXMOTO_SDL +#ifndef PLATFORM_SDL_LINUXMOTO_H +#define PLATFORM_SDL_LINUXMOTO_H -#include "backends/platform/sdl/sdl.h" +#include "backends/platform/sdl/posix/posix.h" -// FIXME: For now keep hacks in this header to save polluting the SDL backend. -enum { - GFX_HALF = 12 -}; - -class OSystem_LINUXMOTO : public OSystem_SDL { -private: - bool _audioSuspended; +class OSystem_LINUXMOTO : public OSystem_POSIX { public: - /* Graphics */ - void initSize(uint w, uint h); - void setGraphicsModeIntern(); - bool setGraphicsMode(int mode); - void internUpdateScreen(); - const OSystem::GraphicsMode *getSupportedGraphicsModes() const; - bool setGraphicsMode(const char *name); - int getDefaultGraphicsMode() const; - bool loadGFXMode(); - void drawMouse(); - void undrawMouse(); - void showOverlay(); - void hideOverlay(); + virtual void initBackend(); - /* Event Stuff */ - virtual bool remapKey(SDL_Event &ev, Common::Event &event); - virtual void preprocessEvents(SDL_Event *event); - virtual void setupMixer(); + // FIXME: This just calls parent methods, is it needed? virtual Common::HardwareKeySet *getHardwareKeySet(); - void fillMouseEvent(Common::Event&, int, int); - void suspendAudio(); - int resumeAudio(); - void warpMouse(int, int); }; #endif diff --git a/backends/platform/linuxmoto/module.mk b/backends/platform/linuxmoto/module.mk index 8123d6e2ac..23f578b841 100644 --- a/backends/platform/linuxmoto/module.mk +++ b/backends/platform/linuxmoto/module.mk @@ -1,8 +1,6 @@ MODULE := backends/platform/linuxmoto MODULE_OBJS := \ - linuxmoto-events.o \ - linuxmoto-graphics.o \ linuxmoto-main.o \ linuxmoto-sdl.o \ hardwarekeys.o diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 574eeb5a9a..742f40511a 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -269,3 +269,8 @@ Audio::Mixer *OSystem_SDL::getMixer() { assert(_mixerManager); return _mixerManager->getMixer(); } + +SdlMixerManager *OSystem_SDL::getMixerManager() { + assert(_mixerManager); + return _mixerManager; +} diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index c61b8c810f..c238422906 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -71,6 +71,9 @@ public: // Get the Graphics Manager instance, used by other managers virtual SdlGraphicsManager *getGraphicsManager(); + // Get the Sdl Mixer Manager instance (not the Audio::Mixer) + virtual SdlMixerManager *getMixerManager(); + protected: bool _inited; bool _initedSDL; |