OPENPANDORA: Start to cleanup the backend and move controls into remapkey.

* Work in progress.
This commit is contained in:
David-John Willis 2011-05-08 22:31:17 +01:00
parent 7878c1ec49
commit 4fcd65d885
7 changed files with 157 additions and 117 deletions

View file

@ -24,7 +24,6 @@
/*
* OpenPandora: Device Specific Event Handling.
*
*/
#if defined(OPENPANDORA)
@ -35,6 +34,8 @@
#include "backends/platform/openpandora/op-options.h"
#include "common/translation.h"
#include "common/util.h"
#include "common/events.h"
/* Quick default button states for modifiers. */
int BUTTON_STATE_L = false;
@ -50,6 +51,68 @@ OPEventSource::OPEventSource()
: _buttonStateL(false){
}
/* Custom handleMouseButtonDown/handleMouseButtonUp to deal with 'Tap Mode' for the touchscreen */
bool OPEventSource::handleMouseButtonDown(SDL_Event &ev, Common::Event &event) {
if (ev.button.button == SDL_BUTTON_LEFT){
if (BUTTON_STATE_L == true) /* BUTTON_STATE_L = Left Trigger Held, force Right Click */
event.type = Common::EVENT_RBUTTONDOWN;
else if (OP::tapmodeLevel == TAPMODE_LEFT) /* TAPMODE_LEFT = Left Click Tap Mode */
event.type = Common::EVENT_LBUTTONDOWN;
else if (OP::tapmodeLevel == TAPMODE_RIGHT) /* TAPMODE_RIGHT = Right Click Tap Mode */
event.type = Common::EVENT_RBUTTONDOWN;
else if (OP::tapmodeLevel == TAPMODE_HOVER) /* TAPMODE_HOVER = Hover (No Click) Tap Mode */
event.type = Common::EVENT_MOUSEMOVE;
else
event.type = Common::EVENT_LBUTTONDOWN; /* For normal mice etc. */
}
else if (ev.button.button == SDL_BUTTON_RIGHT)
event.type = Common::EVENT_RBUTTONDOWN;
#if defined(SDL_BUTTON_WHEELUP) && defined(SDL_BUTTON_WHEELDOWN)
else if (ev.button.button == SDL_BUTTON_WHEELUP)
event.type = Common::EVENT_WHEELUP;
else if (ev.button.button == SDL_BUTTON_WHEELDOWN)
event.type = Common::EVENT_WHEELDOWN;
#endif
#if defined(SDL_BUTTON_MIDDLE)
else if (ev.button.button == SDL_BUTTON_MIDDLE)
event.type = Common::EVENT_MBUTTONDOWN;
#endif
else
return false;
fillMouseEvent(event, ev.button.x, ev.button.y);
return true;
}
bool OPEventSource::handleMouseButtonUp(SDL_Event &ev, Common::Event &event) {
if (ev.button.button == SDL_BUTTON_LEFT){
if (BUTTON_STATE_L == true) /* BUTTON_STATE_L = Left Trigger Held, force Right Click */
event.type = Common::EVENT_RBUTTONUP;
else if (OP::tapmodeLevel == TAPMODE_LEFT) /* TAPMODE_LEFT = Left Click Tap Mode */
event.type = Common::EVENT_LBUTTONUP;
else if (OP::tapmodeLevel == TAPMODE_RIGHT) /* TAPMODE_RIGHT = Right Click Tap Mode */
event.type = Common::EVENT_RBUTTONUP;
else if (OP::tapmodeLevel == TAPMODE_HOVER) /* TAPMODE_HOVER = Hover (No Click) Tap Mode */
event.type = Common::EVENT_MOUSEMOVE;
else
event.type = Common::EVENT_LBUTTONUP; /* For normal mice etc. */
}
else if (ev.button.button == SDL_BUTTON_RIGHT)
event.type = Common::EVENT_RBUTTONUP;
#if defined(SDL_BUTTON_MIDDLE)
else if (ev.button.button == SDL_BUTTON_MIDDLE)
event.type = Common::EVENT_MBUTTONUP;
#endif
else
return false;
fillMouseEvent(event, ev.button.x, ev.button.y);
return true;
}
/* On the OpenPandora by default the ABXY and L/R Trigger buttons are returned by SDL as
(A): SDLK_HOME (B): SDLK_END (X): SDLK_PAGEDOWN (Y): SDLK_PAGEUP (L): SDLK_RSHIFT (R): SDLK_RCTRL
*/
@ -124,65 +187,4 @@ bool OPEventSource::remapKey(SDL_Event &ev, Common::Event &event) {
return false;
}
/* Custom handleMouseButtonDown/handleMouseButtonUp to deal with 'Tap Mode' for the touchscreen */
bool OPEventSource::handleMouseButtonDown(SDL_Event &ev, Common::Event &event) {
if (ev.button.button == SDL_BUTTON_LEFT){
if (BUTTON_STATE_L == true) /* BUTTON_STATE_L = Left Trigger Held, force Right Click */
event.type = Common::EVENT_RBUTTONDOWN;
else if (OP::tapmodeLevel == TAPMODE_LEFT) /* TAPMODE_LEFT = Left Click Tap Mode */
event.type = Common::EVENT_LBUTTONDOWN;
else if (OP::tapmodeLevel == TAPMODE_RIGHT) /* TAPMODE_RIGHT = Right Click Tap Mode */
event.type = Common::EVENT_RBUTTONDOWN;
else if (OP::tapmodeLevel == TAPMODE_HOVER) /* TAPMODE_HOVER = Hover (No Click) Tap Mode */
event.type = Common::EVENT_MOUSEMOVE;
else
event.type = Common::EVENT_LBUTTONDOWN; /* For normal mice etc. */
}
else if (ev.button.button == SDL_BUTTON_RIGHT)
event.type = Common::EVENT_RBUTTONDOWN;
#if defined(SDL_BUTTON_WHEELUP) && defined(SDL_BUTTON_WHEELDOWN)
else if (ev.button.button == SDL_BUTTON_WHEELUP)
event.type = Common::EVENT_WHEELUP;
else if (ev.button.button == SDL_BUTTON_WHEELDOWN)
event.type = Common::EVENT_WHEELDOWN;
#endif
#if defined(SDL_BUTTON_MIDDLE)
else if (ev.button.button == SDL_BUTTON_MIDDLE)
event.type = Common::EVENT_MBUTTONDOWN;
#endif
else
return false;
fillMouseEvent(event, ev.button.x, ev.button.y);
return true;
}
bool OPEventSource::handleMouseButtonUp(SDL_Event &ev, Common::Event &event) {
if (ev.button.button == SDL_BUTTON_LEFT){
if (BUTTON_STATE_L == true) /* BUTTON_STATE_L = Left Trigger Held, force Right Click */
event.type = Common::EVENT_RBUTTONUP;
else if (OP::tapmodeLevel == TAPMODE_LEFT) /* TAPMODE_LEFT = Left Click Tap Mode */
event.type = Common::EVENT_LBUTTONUP;
else if (OP::tapmodeLevel == TAPMODE_RIGHT) /* TAPMODE_RIGHT = Right Click Tap Mode */
event.type = Common::EVENT_RBUTTONUP;
else if (OP::tapmodeLevel == TAPMODE_HOVER) /* TAPMODE_HOVER = Hover (No Click) Tap Mode */
event.type = Common::EVENT_MOUSEMOVE;
else
event.type = Common::EVENT_LBUTTONUP; /* For normal mice etc. */
}
else if (ev.button.button == SDL_BUTTON_RIGHT)
event.type = Common::EVENT_RBUTTONUP;
#if defined(SDL_BUTTON_MIDDLE)
else if (ev.button.button == SDL_BUTTON_MIDDLE)
event.type = Common::EVENT_MBUTTONUP;
#endif
else
return false;
fillMouseEvent(event, ev.button.x, ev.button.y);
return true;
}
#endif

View file

@ -28,17 +28,22 @@
/**
* Events manager for the OpenPandora.
*/
class OPEventSource : public SdlEventSource {
public:
OPEventSource();
protected:
/** Button state for L button modifier */
/**
* Button state for L button modifier
*/
bool _buttonStateL;
bool remapKey(SDL_Event &ev, Common::Event &event);
bool handleMouseButtonDown(SDL_Event &ev, Common::Event &event);
bool handleMouseButtonUp(SDL_Event &ev, Common::Event &event);
bool remapKey(SDL_Event &ev, Common::Event &event);
};
#endif /* BACKEND_EVENTS_OP_H */

View file

@ -26,15 +26,13 @@
#include "backends/graphics/openpandora/op-graphics.h"
#include "backends/events/openpandora/op-events.h"
#include "backends/platform/openpandora/op-sdl.h"
#include "common/mutex.h"
#include "common/util.h"
//#include "backends/platform/openpandora/op-sdl.h"
#include "graphics/scaler/aspect.h"
#include "graphics/surface.h"
#include "common/mutex.h"
#include "common/textconsole.h"
OPGraphicsManager::OPGraphicsManager(SdlEventSource *boss)
: SdlGraphicsManager(boss) {
OPGraphicsManager::OPGraphicsManager(SdlEventSource *sdlEventSource)
: SdlGraphicsManager(sdlEventSource) {
}
bool OPGraphicsManager::loadGFXMode() {

View file

@ -33,30 +33,30 @@ enum {
class OPGraphicsManager : public SdlGraphicsManager {
public:
OPGraphicsManager(SdlEventSource *boss);
OPGraphicsManager(SdlEventSource *sdlEventSource);
bool hasFeature(OSystem::Feature f);
void setFeatureState(OSystem::Feature f, bool enable);
bool getFeatureState(OSystem::Feature f);
int getDefaultGraphicsMode() const;
// bool hasFeature(OSystem::Feature f);
// void setFeatureState(OSystem::Feature f, bool enable);
// bool getFeatureState(OSystem::Feature f);
// int getDefaultGraphicsMode() const;
void initSize(uint w, uint h);
const OSystem::GraphicsMode *getSupportedGraphicsModes() const;
bool setGraphicsMode(const char *name);
bool setGraphicsMode(int mode);
void setGraphicsModeIntern();
void internUpdateScreen();
void showOverlay();
void hideOverlay();
// void initSize(uint w, uint h, const Graphics::PixelFormat *format = NULL);
// const OSystem::GraphicsMode *getSupportedGraphicsModes() const;
// bool setGraphicsMode(const char *name);
// bool setGraphicsMode(int mode);
// void setGraphicsModeIntern();
// void internUpdateScreen();
// void showOverlay();
// void hideOverlay();
bool loadGFXMode();
void drawMouse();
void undrawMouse();
virtual void warpMouse(int x, int y);
// void drawMouse();
// void undrawMouse();
// virtual void warpMouse(int x, int y);
SdlGraphicsManager::MousePos *getMouseCurState();
SdlGraphicsManager::VideoState *getVideoMode();
// SdlGraphicsManager::MousePos *getMouseCurState();
// SdlGraphicsManager::VideoState *getVideoMode();
virtual void adjustMouseEvent(const Common::Event &event);
// virtual void adjustMouseEvent(const Common::Event &event);
};
#endif /* BACKENDS_GRAPHICS_OP_H */

View file

@ -20,13 +20,16 @@
*
*/
#if defined(OPENPANDORA)
// Disable symbol overrides so that we can use system headers.
#define FORBIDDEN_SYMBOL_ALLOW_ALL
#include "backends/platform/openpandora/op-sdl.h"
#include "base/main.h"
#include "backends/platform/sdl/sdl-sys.h"
#include "backends/mixer/doublebuffersdl/doublebuffersdl-mixer.h"
#include "backends/platform/openpandora/op-sdl.h"
#include "backends/plugins/posix/posix-provider.h"
#include "backends/saves/default/default-saves.h"
#include "backends/timer/default/default-timer.h"
@ -35,6 +38,7 @@
#include "common/debug.h"
#include "common/events.h"
#include "common/file.h"
#include "common/textconsole.h"
#include "common/util.h"
#include "audio/mixer_intern.h"
@ -52,15 +56,29 @@
static SDL_Cursor *hiddenCursor;
static Uint32 timer_handler(Uint32 interval, void *param) {
((DefaultTimerManager *)param)->handler();
return interval;
OSystem_OP::OSystem_OP()
:
OSystem_POSIX() {
}
//static Uint32 timer_handler(Uint32 interval, void *param) {
// ((DefaultTimerManager *)param)->handler();
// return interval;
//}
void OSystem_OP::initBackend() {
assert(!_inited);
// Create the events manager
if (_eventSource == 0)
_eventSource = new OPEventSource();
// Create the graphics manager
if (_graphicsManager == 0) {
_graphicsManager = new OPGraphicsManager(_eventSource);
}
// int joystick_num = ConfMan.getInt("joystick_num");
// uint32 sdlFlags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER;
//
@ -76,12 +94,12 @@ void OSystem_OP::initBackend() {
//
// Create the mixer manager
if (_mixer == 0) {
_mixerManager = new DoubleBufferSDLMixerManager();
// if (_mixer == 0) {
// _mixerManager = new DoubleBufferSDLMixerManager();
// Setup and start mixer
_mixerManager->init();
}
// _mixerManager->init();
// }
/* Setup default save path to be workingdir/saves */
@ -103,7 +121,7 @@ void OSystem_OP::initBackend() {
if (mkdir(savePath, 0755) != 0)
warning("mkdir for '%s' failed!", savePath);
// _savefileManager = new DefaultSaveFileManager(savePath);
_savefileManager = new DefaultSaveFileManager(savePath);
#ifdef DUMP_STDOUT
// The OpenPandora has a serial console on the EXT connection but most users do not use this so we
@ -161,22 +179,32 @@ void OSystem_OP::initBackend() {
/* Make sure SDL knows that we have a joystick we want to use. */
ConfMan.setInt("joystick_num", 0);
// Create the events manager
if (_eventSource == 0)
_eventSource = new OPEventSource();
// Create the graphics manager
if (_graphicsManager == 0)
_graphicsManager = new OPGraphicsManager(_eventSource);
// _graphicsMutex = createMutex();
// Invoke parent implementation of this method
/* Pass to POSIX method to do the heavy lifting */
OSystem_POSIX::initBackend();
_inited = true;
}
// enable joystick
// if (joystick_num > -1 && SDL_NumJoysticks() > 0) {
// printf("Using joystick: %s\n", SDL_JoystickName(0));
// _joystick = SDL_JoystickOpen(joystick_num);
// }
//
// setupMixer();
// Note: We could implement a custom SDLTimerManager by using
// SDL_AddTimer. That might yield better timer resolution, but it would
// also change the semantics of a timer: Right now, ScummVM timers
// *never* run in parallel, due to the way they are implemented. If we
// switched to SDL_AddTimer, each timer might run in a separate thread.
// However, not all our code is prepared for that, so we can't just
// switch. Still, it's a potential future change to keep in mind.
// _timer = new DefaultTimerManager();
// _timerID = SDL_AddTimer(10, &timer_handler, _timer);
void OSystem_OP::initSDL() {
// Check if SDL has not been initialized
if (!_initedSDL) {
@ -219,13 +247,14 @@ void OSystem_OP::initSDL() {
// _videoMode.fullscreen = true;
_initedSDL = true;
// OSystem_POSIX::initSDL();
}
}
void OSystem_OP::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) {
/* Setup default extra data paths for engine data files and plugins */
char workDirName[PATH_MAX+1];
if (getcwd(workDirName, PATH_MAX) == NULL) {
@ -256,3 +285,5 @@ void OSystem_OP::quit() {
OSystem_POSIX::quit();
}
#endif

View file

@ -20,8 +20,6 @@
*
*/
#include "backends/platform/sdl/sdl-sys.h"
#include "backends/platform/openpandora/op-sdl.h"
#include "backends/plugins/posix/posix-provider.h"
#include "base/main.h"
@ -35,7 +33,7 @@ int main(int argc, char *argv[]) {
assert(g_system);
// Pre initialize the backend
//((OSystem_OP *)g_system)->init();
((OSystem_OP *)g_system)->init();
#ifdef DYNAMIC_MODULES
PluginManager::instance().addPluginProvider(new POSIXPluginProvider());

View file

@ -26,12 +26,12 @@
#if defined(OPENPANDORA)
#include "backends/base-backend.h"
#include "backends/platform/sdl/sdl.h"
#include "backends/platform/sdl/sdl-sys.h"
#include "backends/platform/sdl/posix/posix.h"
#include "backends/events/openpandora/op-events.h"
#include "backends/graphics/openpandora/op-graphics.h"
#define __OPENPANDORA__
//#define MIXER_DOUBLE_BUFFERING 1
#ifndef PATH_MAX
#define PATH_MAX 255
@ -39,16 +39,22 @@
class OSystem_OP : public OSystem_POSIX {
public:
OSystem_OP() {}
OSystem_OP();
/* Platform Setup Stuff */
void addSysArchivesToSearchSet(Common::SearchSet &s, int priority);
void initBackend();
void initSDL();
void quit();
protected:
bool _inited;
bool _initedSDL;
/**
* Initialse the SDL library
* with an OpenPandora workaround.
*/
virtual void initSDL();
};
#endif
#endif //OP_SDL_H