diff options
author | Stephen Kennedy | 2008-08-14 23:45:02 +0000 |
---|---|---|
committer | Stephen Kennedy | 2008-08-14 23:45:02 +0000 |
commit | c61294e70f6a6acc67efdad1529038f06ea1a5e6 (patch) | |
tree | 169cc3d52008549d8ee1faa54457d7a84a71fb51 /backends | |
parent | 6d0ed23b4469de23c9d93ab15329f10a8441fd29 (diff) | |
download | scummvm-rg350-c61294e70f6a6acc67efdad1529038f06ea1a5e6.tar.gz scummvm-rg350-c61294e70f6a6acc67efdad1529038f06ea1a5e6.tar.bz2 scummvm-rg350-c61294e70f6a6acc67efdad1529038f06ea1a5e6.zip |
Changed Action constructor to take a pointer to the Keymap it belongs too, meaning Keymap::addAction is automatically called
svn-id: r33885
Diffstat (limited to 'backends')
-rw-r--r-- | backends/keymapper/action.cpp | 27 | ||||
-rw-r--r-- | backends/keymapper/action.h | 14 | ||||
-rw-r--r-- | backends/keymapper/keymap.cpp | 1 | ||||
-rw-r--r-- | backends/keymapper/keymap.h | 15 | ||||
-rw-r--r-- | backends/platform/sdl/events.cpp | 21 |
5 files changed, 29 insertions, 49 deletions
diff --git a/backends/keymapper/action.cpp b/backends/keymapper/action.cpp index 413ebdecee..de1c5b7b43 100644 --- a/backends/keymapper/action.cpp +++ b/backends/keymapper/action.cpp @@ -28,29 +28,18 @@ namespace Common { -Action::Action(int32 i, String des, - ActionCategory cat, ActionType typ, - int pri, int grp, int flg) { - id = i; - description = des; - category = cat; - type = typ; - priority = pri; - group = grp; - flags = flg; - _hwKey = 0; - _parent = 0; -} - -void Action::setParent(Keymap *parent) { - _parent = parent; +Action::Action(Keymap *boss, int32 i, String des, ActionCategory cat, + ActionType typ, int pri, int grp, int flg) + : _boss(boss), id(i), description(des), category(cat), type(typ), + priority(pri), group(grp), flags(flg), _hwKey(0) { + assert(_boss); + _boss->addAction(this); } void Action::mapKey(const HardwareKey *key) { - assert(_parent); - if (_hwKey) _parent->unregisterMapping(this); + if (_hwKey) _boss->unregisterMapping(this); _hwKey = key; - if (_hwKey) _parent->registerMapping(this, _hwKey); + if (_hwKey) _boss->registerMapping(this, _hwKey); } const HardwareKey *Action::getMappedKey() const { diff --git a/backends/keymapper/action.h b/backends/keymapper/action.h index 7f75446b87..cc1b4c7262 100644 --- a/backends/keymapper/action.h +++ b/backends/keymapper/action.h @@ -85,18 +85,16 @@ struct Action { private: /** Hardware key that is mapped to this Action */ const HardwareKey *_hwKey; - Keymap *_parent; + Keymap *_boss; public: - Action( int32 id, - String des = "", - ActionCategory cat = kGenericActionCategory, - ActionType typ = kGenericActionType, - int pri = 0, int grp = 0, int flg = 0 ); + Action(Keymap *boss, int32 id, String des = "", + ActionCategory cat = kGenericActionCategory, + ActionType typ = kGenericActionType, + int pri = 0, int grp = 0, int flg = 0 ); void addEvent(const Event &evt) { events.push_back(evt); } - void setParent(Keymap *parent); - Keymap *getParent() { return _parent; } + Keymap *getBoss() { return _boss; } void mapKey(const HardwareKey *key); const HardwareKey *getMappedKey() const; diff --git a/backends/keymapper/keymap.cpp b/backends/keymapper/keymap.cpp index 42454efc87..5b6addd8a6 100644 --- a/backends/keymapper/keymap.cpp +++ b/backends/keymapper/keymap.cpp @@ -47,7 +47,6 @@ Keymap::~Keymap() { void Keymap::addAction(Action *action) { if (findAction(action->id)) error("Action with id %d already in KeyMap!", action->id); - action->setParent(this); _actions.push_back(action); } diff --git a/backends/keymapper/keymap.h b/backends/keymapper/keymap.h index f921b5bd87..bb4aff960d 100644 --- a/backends/keymapper/keymap.h +++ b/backends/keymapper/keymap.h @@ -57,13 +57,6 @@ public: public: /** - * Adds a new Action to this Map, - * adding it at the back of the internal array - * @param action the Action to add - */ - void addAction(Action *action); - - /** * Retrieves the Action with the given id * @param id id of Action to retrieve * @return Pointer to the Action or 0 if not found @@ -108,6 +101,14 @@ public: private: friend struct Action; + + /** + * Adds a new Action to this Map, + * adding it at the back of the internal array + * @param action the Action to add + */ + void addAction(Action *action); + /** * Registers a HardwareKey to the given Action * @param action Action in this Keymap diff --git a/backends/platform/sdl/events.cpp b/backends/platform/sdl/events.cpp index bc8f3c8f8c..93d05822df 100644 --- a/backends/platform/sdl/events.cpp +++ b/backends/platform/sdl/events.cpp @@ -542,33 +542,26 @@ void OSystem_SDL::setupKeymapper() { evt.kbd = KeyState(kc, asc, flags); \ act->events.push_back(evt); - act = new Action('MENU', "Menu", kGenericActionCategory, kMenuAction); + act = new Action(global, 'MENU', "Menu", kGenericActionCategory, kMenuAction); ADD_KEYDOWN_EVENT(KEYCODE_F5, ASCII_F5, 0) - global->addAction(act); - act = new Action('SKCT', "Skip"); + act = new Action(global, 'SKCT', "Skip"); ADD_KEYDOWN_EVENT(KEYCODE_ESCAPE, ASCII_ESCAPE, 0); - global->addAction(act); - act = new Action('PAUS', "Pause"); + act = new Action(global, 'PAUS', "Pause"); ADD_KEYDOWN_EVENT(KEYCODE_SPACE, ' ', 0) - global->addAction(act); - act = new Action('SKLI', "Skip line"); + act = new Action(global, 'SKLI', "Skip line"); ADD_KEYDOWN_EVENT(Common::KEYCODE_PERIOD, '.', 0); - global->addAction(act); - act = new Action('JUMP', "Jump"); + act = new Action(specific, 'JUMP', "Jump"); ADD_KEYDOWN_EVENT(KEYCODE_j, 'j', 0); - specific->addAction(act); - act = new Action('DUCK', "Duck"); + act = new Action(specific, 'DUCK', "Duck"); ADD_KEYDOWN_EVENT(KEYCODE_d, 'd', 0); - specific->addAction(act); - act = new Action('RUN_', "Run"); + act = new Action(specific, 'RUN_', "Run"); ADD_KEYDOWN_EVENT(KEYCODE_r, 'r', 0); - specific->addAction(act); #undef ADD_KEYDOWN_EVENT |