Ticket #8711: backends-lib.v3.patch

File backends-lib.v3.patch, 24.6 KB (added by SF/sbatyuk, 17 years ago)

key to key mapping patch v3

  • D:/programming/projects/gsoc/scummvm/backends/events/default/default-events.cpp

     
    4949        uint32 time = _boss->getMillis();
    5050        bool result;
    5151       
    52         result = _boss->pollEvent(event);
     52        result = _boss->pollMappedEvent(event);
    5353       
    5454        if (result) {
    5555                event.synthetic = false;
     
    128128        return result;
    129129}
    130130
     131void DefaultEventManager::registerActionMappings(const Common::MappingList mappings) {
     132        _boss->getKeyMapper()->registerActionMappings(mappings);
     133}
     134void DefaultEventManager::unregisterActionMappings() {
     135        _boss->getKeyMapper()->unregisterActionMappings();
     136}
     137
     138
    131139#endif // !defined(DISABLE_DEFAULT_EVENTMANAGER)
  • D:/programming/projects/gsoc/scummvm/backends/events/default/default-events.h

     
    6767
    6868        virtual bool pollEvent(Common::Event &event);
    6969
     70        virtual void registerActionMappings(const Common::MappingList);
     71        virtual void unregisterActionMappings();
     72
    7073        virtual Common::Point getMousePos() const { return _mousePos; }
    7174        virtual int getButtonState() const { return _buttonState; }
    7275        virtual int getModifierState() const { return _modifierState; }
  • D:/programming/projects/gsoc/scummvm/backends/platform/sdl/sdl.cpp

     
    257257        memset(&_mouseCurState, 0, sizeof(_mouseCurState));
    258258
    259259        _inited = false;
     260
     261        // init keys available for the device
     262        _availableKeys.push_front(Common::KEYCODE_F5);
     263        _availableKeys.push_front(Common::KEYCODE_p);
     264        _availableKeys.push_front(Common::KEYCODE_ESCAPE);
    260265}
    261266
    262267OSystem_SDL::~OSystem_SDL() {
  • D:/programming/projects/gsoc/scummvm/backends/platform/sdl/events.cpp

     
    445445        return false;
    446446}
    447447
     448Common::KeyCodeList OSystem_SDL::getAvailableKeys() const {
     449        return _availableKeys;
     450}
     451
    448452bool OSystem_SDL::remapKey(SDL_Event &ev, Common::Event &event) {
    449453#ifdef LINUPY
    450454        // On Yopy map the End button to quit
  • D:/programming/projects/gsoc/scummvm/backends/platform/sdl/sdl-common.h

     
    3434#include "graphics/scaler.h"
    3535#include "backends/intern.h"
    3636
     37#include "backends/platform/common/common-system.h"
    3738
     39
    3840namespace Audio {
    3941        class Mixer;
    4042}
     
    6668};
    6769
    6870
    69 class OSystem_SDL : public OSystem {
     71class OSystem_SDL : public OSystem_Common {
    7072public:
    7173        OSystem_SDL();
    7274        virtual ~OSystem_SDL();
     
    131133        // Returns true if an event was retrieved.
    132134        virtual bool pollEvent(Common::Event &event); // overloaded by CE backend
    133135
     136        virtual std::list<Common::KeyCode> getAvailableKeys() const;
     137
    134138        // Set function that generates samples
    135139        typedef void (*SoundProc)(void *param, byte *buf, int len);
    136140        virtual bool setSoundCallback(SoundProc proc, void *param); // overloaded by CE backend
     
    411415        virtual bool remapKey(SDL_Event &ev, Common::Event &event);
    412416
    413417        void handleScalerHotkeys(const SDL_KeyboardEvent &key);
     418
     419private:
     420        Common::KeyCodeList _availableKeys;
    414421};
    415422
    416423#endif
  • D:/programming/projects/gsoc/scummvm/backends/platform/common/common-system.h

     
     1/* ScummVM - Graphic Adventure Engine
     2 *
     3 * ScummVM is the legal property of its developers, whose names
     4 * are too numerous to list here. Please refer to the COPYRIGHT
     5 * file distributed with this source distribution.
     6 *
     7 * This program is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU General Public License
     9 * as published by the Free Software Foundation; either version 2
     10 * of the License, or (at your option) any later version.
     11
     12 * This program is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16
     17 * You should have received a copy of the GNU General Public License
     18 * along with this program; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 *
     21 */
     22
     23#ifndef PLATFORM_COMMON_SYSTEM_H
     24#define PLATFORM_COMMON_SYSTEM_H
     25
     26#include "common/stdafx.h"
     27#include "common/scummsys.h"
     28#include "common/system.h"
     29#include "common/keyboard.h"
     30#include "common/events.h"
     31
     32#include "backends/platform/common/virtual-keyboard.h"
     33#include "backends/platform/common/key-mapper.h"
     34
     35class OSystem_Common : public OSystem {
     36
     37public:
     38        OSystem_Common();
     39        ~OSystem_Common();
     40
     41        virtual bool pollMappedEvent(Common::Event &);
     42        virtual KeyMapper *getKeyMapper();
     43
     44protected:
     45
     46        virtual Common::KeyCodeList getAvailableKeys() const = 0;
     47
     48private:
     49
     50        KeyMapper *_keyMapper;
     51        VirtualKeyboard *_virtualKeyboard;
     52
     53};
     54
     55#endif
  • D:/programming/projects/gsoc/scummvm/backends/platform/common/key-mapper.h

     
     1/* ScummVM - Graphic Adventure Engine
     2 *
     3 * ScummVM is the legal property of its developers, whose names
     4 * are too numerous to list here. Please refer to the COPYRIGHT
     5 * file distributed with this source distribution.
     6 *
     7 * This program is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU General Public License
     9 * as published by the Free Software Foundation; either version 2
     10 * of the License, or (at your option) any later version.
     11 *
     12 * This program is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with this program; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 *
     21 */
     22
     23#ifndef COMMON_KEY_MAPPER_H
     24#define COMMON_KEY_MAPPER_H
     25
     26#include "common/stdafx.h"
     27#include "common/scummsys.h"
     28#include "common/keyboard.h"
     29#include "common/events.h"
     30
     31#include <list>
     32#include <map>
     33
     34typedef std::map<Common::KeyState, Common::ActionMapping> KeyActionMap;
     35
     36class KeyMapper {
     37
     38public:
     39
     40        KeyMapper(Common::KeyCodeList);
     41
     42        virtual void registerActionMappings(const Common::MappingList);
     43        virtual void unregisterActionMappings();
     44
     45        void resolve(Common::Event &);
     46
     47private:
     48        bool _registered;
     49        Common::KeyCodeList _availableKeys; // keys available on the device
     50        Common::MappingList _needsMapping; // mappings which default keys are not in the available keys
     51        KeyActionMap _mappings; // available keys and action mappings
     52};
     53
     54#endif
     55 No newline at end of file
  • D:/programming/projects/gsoc/scummvm/backends/platform/common/virtual-keyboard.cpp

     
     1/* ScummVM - Graphic Adventure Engine
     2 *
     3 * ScummVM is the legal property of its developers, whose names
     4 * are too numerous to list here. Please refer to the COPYRIGHT
     5 * file distributed with this source distribution.
     6 *
     7 * This program is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU General Public License
     9 * as published by the Free Software Foundation; either version 2
     10 * of the License, or (at your option) any later version.
     11 *
     12 * This program is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with this program; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 *
     21 */
     22
     23#include "backends/platform/common/virtual-keyboard.h"
     24
     25VirtualKeyboard::VirtualKeyboard() {
     26}
     27
     28void VirtualKeyboard::resolve(Common::Event &event) {
     29}
  • D:/programming/projects/gsoc/scummvm/backends/platform/common/virtual-keyboard.h

     
     1/* ScummVM - Graphic Adventure Engine
     2 *
     3 * ScummVM is the legal property of its developers, whose names
     4 * are too numerous to list here. Please refer to the COPYRIGHT
     5 * file distributed with this source distribution.
     6 *
     7 * This program is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU General Public License
     9 * as published by the Free Software Foundation; either version 2
     10 * of the License, or (at your option) any later version.
     11 *
     12 * This program is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with this program; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 *
     21 */
     22
     23#ifndef COMMON_VIRTUAL_KEYBOARD_H
     24#define COMMON_VIRTUAL_KEYBOARD_H
     25
     26#include "common/stdafx.h"
     27#include "common/scummsys.h"
     28#include "common/events.h"
     29
     30class VirtualKeyboard {
     31
     32public:
     33        VirtualKeyboard();
     34        void resolve(Common::Event &);
     35};
     36
     37#endif
     38 No newline at end of file
  • D:/programming/projects/gsoc/scummvm/backends/platform/common/key-mapper.cpp

     
     1/* ScummVM - Graphic Adventure Engine
     2 *
     3 * ScummVM is the legal property of its developers, whose names
     4 * are too numerous to list here. Please refer to the COPYRIGHT
     5 * file distributed with this source distribution.
     6 *
     7 * This program is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU General Public License
     9 * as published by the Free Software Foundation; either version 2
     10 * of the License, or (at your option) any later version.
     11 *
     12 * This program is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with this program; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 *
     21 */
     22
     23#include "backends/platform/common/key-mapper.h"
     24
     25KeyMapper::KeyMapper(Common::KeyCodeList availableKeys) :
     26        _availableKeys(availableKeys),
     27        _registered(false) {
     28}
     29
     30void KeyMapper::registerActionMappings(const Common::MappingList supportedActions) {
     31        this->unregisterActionMappings();
     32        // check if the backend supports any of the default keys
     33        Common::MappingList tmpList = supportedActions;
     34        for (Common::MappingList::iterator mIt = tmpList.begin(); mIt != tmpList.end(); mIt++) {
     35                bool found = false;
     36                for (Common::KeyCodeList::iterator kcIt = _availableKeys.begin(); !found && kcIt != _availableKeys.end(); kcIt++) {
     37                        // TODO add support for flags
     38                        if (mIt->defaultKey.keycode == *kcIt) {
     39                                // TODO check the behaviour of map. Maybe heap objects should be used
     40                                _mappings[mIt->defaultKey] = *mIt;
     41                                found = true;
     42                        }
     43                }
     44                if (!found) {
     45                        _needsMapping.push_back(*mIt);
     46                }
     47        }
     48        // open the keys dialog or look up mappings in the tables for the rest of actions
     49        // ...
     50        _registered = true;
     51}
     52
     53void KeyMapper::unregisterActionMappings() {
     54        _needsMapping.clear();
     55        _mappings.clear();
     56        _registered = false;
     57}
     58
     59void KeyMapper::resolve(Common::Event &event) {
     60        if (!_registered || _mappings.empty()) {
     61                return;
     62        }
     63        KeyActionMap::iterator it =  _mappings.find(event.kbd);
     64        if (it != _mappings.end()) {
     65                event.kbd = it->second.defaultKey;
     66                event.type = it->second.type;
     67        }
     68}
  • D:/programming/projects/gsoc/scummvm/backends/platform/common/module.mk

     
     1MODULE := backends/platform/common
     2
     3MODULE_OBJS := \
     4        common-system.o
     5
     6MODULE_DIRS += \
     7        backends/platform/common/
     8
     9# We don't use the rules.mk here on purpose
     10OBJS := $(addprefix $(MODULE)/, $(MODULE_OBJS)) $(OBJS)
  • D:/programming/projects/gsoc/scummvm/backends/platform/common/common-system.cpp

     
     1/* ScummVM - Graphic Adventure Engine
     2 *
     3 * ScummVM is the legal property of its developers, whose names
     4 * are too numerous to list here. Please refer to the COPYRIGHT
     5 * file distributed with this source distribution.
     6 *
     7 * This program is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU General Public License
     9 * as published by the Free Software Foundation; either version 2
     10 * of the License, or (at your option) any later version.
     11
     12 * This program is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16
     17 * You should have received a copy of the GNU General Public License
     18 * along with this program; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 *
     21 */
     22#include "backends/platform/common/common-system.h"
     23
     24OSystem_Common::OSystem_Common() {
     25        _keyMapper = NULL;
     26        _virtualKeyboard = new VirtualKeyboard();
     27}
     28
     29OSystem_Common::~OSystem_Common() {
     30        if (_keyMapper) {
     31                delete _keyMapper;
     32        }
     33        delete _virtualKeyboard;
     34}
     35bool OSystem_Common::pollMappedEvent(Common::Event &event) {
     36
     37        bool result = true;
     38        if (pollEvent(event)) { // calling virtual superclass function
     39                bool lbutton = event.type == Common::EVENT_LBUTTONDOWN || event.type == Common::EVENT_LBUTTONUP;
     40                if (getFeatureState(kFeatureVirtualKeyboard) && lbutton) { // possible a virtual keyboard event
     41                        _virtualKeyboard->resolve(event); // try to resolve a virtual keyboard event
     42                }
     43                getKeyMapper()->resolve(event);
     44        } else {
     45                result = false;
     46        }
     47        return result;
     48}
     49
     50KeyMapper *OSystem_Common::getKeyMapper() {
     51        if (!_keyMapper) {
     52                _keyMapper = new KeyMapper(getAvailableKeys());
     53        }
     54        return _keyMapper;
     55}
  • D:/programming/projects/gsoc/scummvm/common/keyboard.h

     
    2828
    2929#include "common/scummsys.h"
    3030
     31#include <list>
     32
    3133namespace Common {
    3234
    3335enum KeyCode {
     
    181183        KEYCODE_UNDO        = 322       // Atari keyboard has Undo
    182184};
    183185
     186typedef std::list<Common::KeyCode> KeyCodeList;
     187
    184188/**
    185189 * List of certan special and some fake 'ascii' values used in keyboard events.
    186190 * The values for the function keys listed here are based on what certain SCUMM
     
    259263                keycode = KEYCODE_INVALID;
    260264                ascii = flags = 0;
    261265        }
     266
     267        bool operator <(const KeyState keyState) const {
     268                return keycode < keyState.keycode;
     269        }
     270
     271        bool operator ==(const KeyState keyState) const {
     272                return (keycode == keyState.keycode) && (flags == keyState.flags);
     273        }
     274
    262275};
    263276
    264277} // End of namespace Common
  • D:/programming/projects/gsoc/scummvm/common/system.h

     
    3131#include "common/noncopyable.h"
    3232#include "common/rect.h"
    3333
     34#include "backends/platform/common/key-mapper.h"
     35
    3436namespace Audio {
    3537        class Mixer;
    3638}
     
    724726         */
    725727        virtual bool pollEvent(Common::Event &event) = 0;
    726728
     729        /**
     730         * Get the next event with resolved key mapping from the event queue.
     731         * @param event point to an Common::Event struct, which will be filled with the event data.
     732         * @return true if an event was retrieved.
     733         */
     734        virtual bool pollMappedEvent(Common::Event &event) = 0;
     735
     736        virtual KeyMapper *getKeyMapper() = 0;
     737
    727738public:
     739
    728740        /** Get the number of milliseconds since the program was started. */
    729741        virtual uint32 getMillis() = 0;
    730742
     
    743755         */
    744756        virtual Common::EventManager *getEventManager();
    745757
     758
    746759        //@}
    747760
    748761
     
    894907         * refer to the SaveFileManager documentation.
    895908         */
    896909        virtual Common::SaveFileManager *getSavefileManager() = 0;
    897 
    898910        //@}
    899911};
    900912
  • D:/programming/projects/gsoc/scummvm/common/events.h

     
    2828
    2929#include "common/keyboard.h"
    3030#include "common/rect.h"
    31 #include "common/system.h"
    3231#include "common/noncopyable.h"
    3332
     33#include <list>
     34
    3435namespace Common {
    3536
    3637/**
     
    107108          * Keyboard data; only valid for keyboard events (EVENT_KEYDOWN and
    108109          * EVENT_KEYUP). For all other event types, content is undefined.
    109110          */
    110         KeyState kbd;
     111        Common::KeyState kbd;
    111112        /**
    112113         * The mouse coordinates, in virtual screen coordinates. Only valid
    113114         * for mouse events.
     
    117118        Common::Point mouse;
    118119};
    119120
     121enum Priority {
     122        PRIORITY_HIGHEST,
     123        PRIORITY_HIGH,
     124        PRIORITY_LOW,
     125        PRIORITY_LOWEST
     126};
    120127
     128struct ActionMapping {
     129        Common::KeyState defaultKey;  // default key combo used for mapping; includes modifier state
     130        Common::EventType type;  // event type like key up/down, quit, save/load
     131        String description; // human readable description, for a GUI keymapping config dialog
     132        Common::Priority priority; // mapping priority
     133
     134        ActionMapping(Common::KeyState ks = Common::KeyState(Common::KEYCODE_ESCAPE),
     135                Common::EventType et = Common::EVENT_KEYDOWN, String d = "Action name",
     136                Common::Priority p = Common::PRIORITY_HIGHEST) {
     137               
     138                defaultKey = ks;
     139                type = et;
     140                description = d;
     141                priority = p;
     142        }
     143};
     144
     145typedef std::list<Common::ActionMapping> MappingList;
     146
    121147/**
    122148 * The EventManager provides user input events to the client code.
    123149 * In addition, it keeps track of the state of various input devices,
     
    166192        // TODO: Keyboard repeat support?
    167193       
    168194        // TODO: Consider removing OSystem::getScreenChangeID and
    169         // replacing it by a generic getScreenChangeID method here
     195        // replacing it by a generic getScreenChaneID method here
     196
     197        virtual void registerActionMappings(const MappingList) = 0;
     198
     199        virtual void unregisterActionMappings() = 0;
    170200};
    171201
    172202} // End of namespace Common
  • D:/programming/projects/gsoc/scummvm/engines/cruise/cruise_main.cpp

     
    3030#include "cruise/cruise_main.h"
    3131#include "cruise/cell.h"
    3232
     33#include "common/system.h"
     34
    3335namespace Cruise {
    3436
    3537unsigned int timer = 0;
  • D:/programming/projects/gsoc/scummvm/engines/sky/sky.cpp

     
    3030#include "common/config-manager.h"
    3131#include "common/file.h"
    3232#include "common/fs.h"
     33#include "common/keyboard.h"
    3334#include "common/events.h"
    3435#include "common/system.h"
    3536#include "common/timer.h"
     
    183184
    184185SkyEngine::SkyEngine(OSystem *syst)
    185186        : Engine(syst), _fastMode(0), _debugger(0) {
     187        Common::MappingList mappings;
     188
     189        Common::KeyState key = Common::KeyState(Common::KEYCODE_F5);
     190        Common::ActionMapping mapping = Common::ActionMapping(key, Common::EVENT_KEYDOWN, "Menu", Common::PRIORITY_HIGHEST);
     191        mappings.push_back(mapping);
     192
     193       
     194        key = Common::KeyState(Common::KEYCODE_ESCAPE);
     195        mapping = Common::ActionMapping(key, Common::EVENT_KEYDOWN, "Esc", Common::PRIORITY_HIGHEST);
     196        mappings.push_back(mapping);
     197
     198        key = Common::KeyState(Common::KEYCODE_p);
     199        mapping = Common::ActionMapping(key, Common::EVENT_KEYDOWN, "Pause", Common::PRIORITY_HIGHEST);
     200        mappings.push_back(mapping);
     201
     202        _eventMan->registerActionMappings(mappings);
    186203}
    187204
    188205SkyEngine::~SkyEngine() {
  • D:/programming/projects/gsoc/scummvm/engines/gob/mult_v2.cpp

     
    11531153
    11541154                if (_multData->imdIndices[i] != -1) {
    11551155                        int fileN;
    1156                         char *imdFile;
     1156                        char *imdFile = NULL;
    11571157                        int dir;
    11581158                        int startFrame;
    11591159
  • D:/programming/projects/gsoc/scummvm/engines/parallaction/dialogue.cpp

     
    2828#include "common/events.h"
    2929#include "parallaction/parallaction.h"
    3030
     31#include "common/system.h"
    3132
    3233
     34
    3335namespace Parallaction {
    3436
    3537#define SKIPPED_ANSWER             1000
  • D:/programming/projects/gsoc/scummvm/engines/parallaction/parallaction.cpp

     
    3030#include "common/file.h"
    3131#include "common/util.h"
    3232
     33#include "common/system.h"
     34
    3335#include "sound/mididrv.h"
    3436#include "sound/mixer.h"
    3537