MAEMO: Use custom event Click Mode keymap action

This commit is contained in:
Tarek Soliman 2012-02-09 01:26:42 -06:00
parent d90d4d10a0
commit c2640ed33a
5 changed files with 52 additions and 5 deletions

View file

@ -164,6 +164,22 @@ bool MaemoSdlEventSource::toggleClickMode() {
return _clickEnabled;
}
MaemoSdlEventObserver::MaemoSdlEventObserver(MaemoSdlEventSource *eventSource) {
assert(_eventSource);
_eventSource = eventSource;
}
bool MaemoSdlEventObserver::notifyEvent(const Common::Event &event) {
if (event.type != Common::EVENT_CUSTOM_BACKEND)
return false;
if (event.customType == kEventClickMode) {
assert(_eventSource);
_eventSource->toggleClickMode();
return true;
}
return false;
}
} // namespace Maemo
#endif // if defined(MAEMO)

View file

@ -47,6 +47,15 @@ protected:
bool _clickEnabled;
};
class MaemoSdlEventObserver : public Common::EventObserver {
public:
MaemoSdlEventObserver(MaemoSdlEventSource *eventSource);
virtual bool notifyEvent(const Common::Event &event);
private:
MaemoSdlEventSource *_eventSource;
};
} // namespace Maemo
#endif // include guard

View file

@ -51,6 +51,11 @@ static const Model models[] = {
{0, kModelTypeInvalid, 0, true}
};
enum CustomEventType {
kEventClickMode = 1,
kEventInvalid = 0
};
} // namespace Maemo
#endif // ifndef PLATFORM_SDL_MAEMO_COMMON_H

View file

@ -46,6 +46,10 @@ OSystem_SDL_Maemo::OSystem_SDL_Maemo()
OSystem_POSIX() {
}
OSystem_SDL_Maemo::~OSystem_SDL_Maemo() {
delete _eventObserver;
}
void OSystem_SDL_Maemo::initBackend() {
// Create the events manager
if (_eventSource == 0)
@ -54,12 +58,16 @@ void OSystem_SDL_Maemo::initBackend() {
if (_graphicsManager == 0)
_graphicsManager = new MaemoSdlGraphicsManager(_eventSource);
if (_eventObserver == 0)
_eventObserver = new MaemoSdlEventObserver((MaemoSdlEventSource *)_eventSource);
ConfMan.set("vkeybdpath", DATA_PATH);
_model = Model(detectModel());
// Call parent implementation of this method
OSystem_POSIX::initBackend();
initObserver();
}
void OSystem_SDL_Maemo::quit() {
@ -136,8 +144,11 @@ Common::Keymap *OSystem_SDL_Maemo::getGlobalKeymap() {
Action *act;
// act = new Action(globalMap, "CLKM", _("Click Mode"), kKeyRemapActionType);
// act->addCustomEvent(CLICK_MODE);
act = new Action(globalMap, "CLKM", _("Click Mode"), kKeyRemapActionType);
Event evt = Event();
evt.type = EVENT_CUSTOM_BACKEND;
evt.customType = Maemo::kEventClickMode;
act->addEvent(evt);
act = new Action(globalMap, "LCLK", _("Left Click"), kKeyRemapActionType);
act->addLeftClickEvent();
@ -154,8 +165,11 @@ Common::Keymap *OSystem_SDL_Maemo::getGlobalKeymap() {
#endif
}
void OSystem_SDL_Maemo::initObserver() {
assert(_eventManager);
_eventManager->getEventDispatcher()->registerObserver(_eventObserver, 10, false);
}
} //namespace Maemo
#endif

View file

@ -29,10 +29,12 @@
#include "backends/platform/maemo/maemo-common.h"
namespace Maemo {
class MaemoSdlEventObserver;
class OSystem_SDL_Maemo : public OSystem_POSIX {
public:
OSystem_SDL_Maemo();
~OSystem_SDL_Maemo();
virtual void initBackend();
virtual void quit();
@ -46,10 +48,11 @@ public:
private:
virtual void setXWindowName(const char *caption);
void initObserver();
const Model detectModel();
Model _model;
MaemoSdlEventObserver *_eventObserver;
};
} // namespace Maemo