Ticket #8711: backends-lib.v3.3.patch

File backends-lib.v3.3.patch, 19.0 KB (added by SF/sbatyuk, 13 years ago)

v3.2 update: STL replaced with Common:: - debug.cpp in sky engine does not compile

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

     
    3535
    3636DefaultEventManager::DefaultEventManager(OSystem *boss) :
    3737        _boss(boss),
     38        _keyMapper(boss->getKeyMapper()),
     39        _virtualKeyboard(boss->getVirtualKeyboard()),
    3840        _buttonState(0),
    3941        _modifierState(0),
    4042        _shouldQuit(false) {
     
    5254        result = _boss->pollEvent(event);
    5355       
    5456        if (result) {
     57                // check if we have to resolve virtual keyboard event
     58                bool lbutton = event.type == Common::EVENT_LBUTTONDOWN || event.type == Common::EVENT_LBUTTONUP;
     59                if (_boss->getFeatureState(OSystem::kFeatureVirtualKeyboard) && _virtualKeyboard && lbutton) { // possibly a virtual keyboard event
     60                        _virtualKeyboard->resolve(event); // try to resolve a virtual keyboard event
     61                }
     62
     63                // check if we have to resolve key mapping
     64                if (_keyMapper) {
     65                        _keyMapper->resolve(event);
     66                }
     67
    5568                event.synthetic = false;
    5669                switch (event.type) {
    5770                case Common::EVENT_KEYDOWN:
     
    128141        return result;
    129142}
    130143
     144void DefaultEventManager::registerActions(const Common::ActionList actions) {
     145        _keyMapper->registerActions(actions);
     146}
     147void DefaultEventManager::unregisterActions() {
     148        _keyMapper->unregisterActions();
     149}
     150
     151
    131152#endif // !defined(DISABLE_DEFAULT_EVENTMANAGER)
  • D:/programming/projects/gsoc/scummvm/backends/events/default/default-events.h

     
    4343
    4444class DefaultEventManager : public Common::EventManager {
    4545        OSystem *_boss;
     46        KeyMapper *_keyMapper;
     47        VirtualKeyboard *_virtualKeyboard;
    4648
    4749        Common::Point _mousePos;
    4850        int _buttonState;
     
    6769
    6870        virtual bool pollEvent(Common::Event &event);
    6971
     72        virtual void registerActions(const Common::ActionList);
     73        virtual void unregisterActions();
     74
    7075        virtual Common::Point getMousePos() const { return _mousePos; }
    7176        virtual int getButtonState() const { return _buttonState; }
    7277        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        _keyMapper = new KeyMapper();
     262        _virtualKeyboard = new VirtualKeyboard();
    260263}
    261264
    262265OSystem_SDL::~OSystem_SDL() {
     
    271274        delete _savefile;
    272275        delete _mixer;
    273276        delete _timer;
     277
     278        delete _keyMapper;
     279        delete _virtualKeyboard;
    274280}
    275281
    276282uint32 OSystem_SDL::getMillis() {
  • D:/programming/projects/gsoc/scummvm/backends/platform/sdl/events.cpp

     
    444444        }
    445445        return false;
    446446}
     447KeyMapper *OSystem_SDL::getKeyMapper() {
     448        return _keyMapper;
     449}
    447450
     451VirtualKeyboard *OSystem_SDL::getVirtualKeyboard() {
     452        return _virtualKeyboard;
     453}
     454
    448455bool OSystem_SDL::remapKey(SDL_Event &ev, Common::Event &event) {
    449456#ifdef LINUPY
    450457        // On Yopy map the End button to quit
  • D:/programming/projects/gsoc/scummvm/backends/platform/sdl/sdl-common.h

     
    131131        // Returns true if an event was retrieved.
    132132        virtual bool pollEvent(Common::Event &event); // overloaded by CE backend
    133133
     134        virtual KeyMapper *getKeyMapper();
     135
     136        virtual VirtualKeyboard *getVirtualKeyboard();
     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        KeyMapper *_keyMapper;
     421        VirtualKeyboard *_virtualKeyboard;
     422
    414423};
    415424
    416425#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 "common/hashmap.h"
     32
     33typedef Common::HashMap<Common::KeyState, Common::UserAction, Common::KeyState_Hash> KeyActionMap;
     34
     35class KeyMapper {
     36
     37public:
     38
     39        KeyMapper();
     40
     41        virtual void registerActions(const Common::ActionList);
     42        virtual void unregisterActions();
     43
     44        virtual void mapActions();
     45
     46        void resolve(Common::Event &);
     47
     48private:
     49        bool _registered;
     50        Common::ActionList _supportedActions;
     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/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/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() :
     26        _registered(false) {
     27}
     28
     29void KeyMapper::registerActions(const Common::ActionList supportedActions) {
     30        this->unregisterActions();
     31        _supportedActions = supportedActions;
     32        for (Common::ActionList::iterator mIt = _supportedActions.begin(); mIt != _supportedActions.end(); mIt++) {
     33                // actions are mapped to default keys to substitute later the type of event
     34                _mappings[mIt->defaultKey] = *mIt;
     35        }
     36        // open the keys dialog or look up mappings in the tables for the rest of actions
     37        // ...
     38        _registered = true;
     39}
     40
     41void KeyMapper::unregisterActions() {
     42        _supportedActions.clear();
     43        _mappings.clear();
     44        _registered = false;
     45}
     46
     47void KeyMapper::mapActions() {
     48}
     49
     50void KeyMapper::resolve(Common::Event &event) {
     51        if (!_registered || _mappings.empty()) {
     52                return;
     53        }
     54       
     55        if (_mappings.contains(event.kbd)) {
     56                event.kbd = _mappings[event.kbd].defaultKey;
     57                if (_mappings[event.kbd].type != Common::EVENT_INVALID) {
     58                        event.type = _mappings[event.kbd].type;
     59                }
     60        }
     61}
  • D:/programming/projects/gsoc/scummvm/common/keyboard.h

     
    2828
    2929#include "common/scummsys.h"
    3030
     31#include <list>
     32
    3133namespace Common {
    3234
    3335enum KeyCode {
     
    259261                keycode = KEYCODE_INVALID;
    260262                ascii = flags = 0;
    261263        }
     264
     265        bool operator <(const KeyState keyState) const {
     266                bool result;
     267                if (keycode != keyState.keycode) {
     268                        result = keycode < keyState.keycode;
     269                } else {
     270                        result = flags < keyState.flags;
     271                }
     272
     273                return result;
     274        }
     275
     276        bool operator ==(const KeyState keyState) const {
     277                return (keycode == keyState.keycode) && (flags == keyState.flags);
     278        }
     279
     280        uint hash() const {
     281                return 0;
     282        }
     283
    262284};
    263285
     286struct KeyState_Hash {
     287        uint operator()(const KeyState& ks) const { return ks.hash(); }
     288};
     289
     290
    264291} // End of namespace Common
    265292
    266293#endif
  • 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#include "backends/platform/common/virtual-keyboard.h"
     36
    3437namespace Audio {
    3538        class Mixer;
    3639}
     
    724727         */
    725728        virtual bool pollEvent(Common::Event &event) = 0;
    726729
     730        virtual KeyMapper *getKeyMapper() { return NULL; }
     731
     732        virtual VirtualKeyboard *getVirtualKeyboard() { return NULL; }
     733
    727734public:
     735
    728736        /** Get the number of milliseconds since the program was started. */
    729737        virtual uint32 getMillis() = 0;
    730738
     
    743751         */
    744752        virtual Common::EventManager *getEventManager();
    745753
     754
    746755        //@}
    747756
    748757
     
    894903         * refer to the SaveFileManager documentation.
    895904         */
    896905        virtual Common::SaveFileManager *getSavefileManager() = 0;
    897 
    898906        //@}
    899907};
    900908
  • 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 "common/list.h"
     34
    3435namespace Common {
    3536
    3637/**
     
    4344 *       indicates which button was pressed.
    4445 */
    4546enum EventType {
     47
     48        EVENT_INVALID = 0,
    4649        /** A key was pressed, details in Event::kbd. */
    4750        EVENT_KEYDOWN = 1,
    4851        /** A key was released, details in Event::kbd. */
     
    107110          * Keyboard data; only valid for keyboard events (EVENT_KEYDOWN and
    108111          * EVENT_KEYUP). For all other event types, content is undefined.
    109112          */
    110         KeyState kbd;
     113        Common::KeyState kbd;
    111114        /**
    112115         * The mouse coordinates, in virtual screen coordinates. Only valid
    113116         * for mouse events.
     
    115118         * screen area as defined by the most recent call to initSize().
    116119         */
    117120        Common::Point mouse;
     121
     122        Event(Common::EventType et = Common::EVENT_INVALID, bool s = false,
     123                Common::KeyState ks = Common::KeyState(), Common::Point p = Common::Point()) {
     124               
     125                type = et;
     126                synthetic = s;
     127                kbd = ks;
     128                mouse = p;
     129        }
     130
     131        void reset() {
     132                type = Common::EVENT_INVALID;
     133                synthetic = false;
     134                kbd = Common::KeyState();
     135                mouse = Common::Point();
     136        }
    118137};
    119138
     139enum Priority {
     140        PRIORITY_HIGHEST,
     141        PRIORITY_HIGH,
     142        PRIORITY_NORMAL,
     143        PRIORITY_LOW,
     144        PRIORITY_LOWEST
     145};
    120146
     147struct UserAction {
     148        Common::KeyState defaultKey;  // default key combo used for mapping; includes modifier state
     149        Common::EventType type;  // event type like key up/down, quit, save/load
     150        String description; // human readable description, for a GUI keymapping config dialog
     151        Common::Priority priority; // mapping priority
     152
     153        UserAction(Common::KeyState ks = Common::KeyState(Common::KEYCODE_ESCAPE),
     154                Common::EventType et = Common::EVENT_KEYDOWN, String d = "Action name",
     155                Common::Priority p = Common::PRIORITY_NORMAL) {
     156               
     157                defaultKey = ks;
     158                type = et;
     159                description = d;
     160                priority = p;
     161        }
     162
     163        UserAction(Common::KeyState ks, String d, Common::Priority p = Common::PRIORITY_NORMAL) {
     164                defaultKey = ks;
     165                type = Common::EVENT_INVALID;
     166                description = d;
     167                priority = p;
     168        }
     169
     170};
     171
     172typedef Common::List<Common::UserAction> ActionList;
     173
    121174/**
    122175 * The EventManager provides user input events to the client code.
    123176 * In addition, it keeps track of the state of various input devices,
     
    166219        // TODO: Keyboard repeat support?
    167220       
    168221        // TODO: Consider removing OSystem::getScreenChangeID and
    169         // replacing it by a generic getScreenChangeID method here
     222        // replacing it by a generic getScreenChaneID method here
     223
     224        virtual void registerActions(const ActionList) = 0;
     225
     226        virtual void unregisterActions() = 0;
    170227};
    171228
    172229} // End of namespace Common
  • D:/programming/projects/gsoc/scummvm/engines/sky/sky.h

     
    2727#define SKY_H
    2828
    2929#include "common/stdafx.h"
     30#include "common/keyboard.h"
    3031#include "common/events.h"
     32#include "common/system.h"
    3133#include "engines/engine.h"
    3234
    3335namespace Sky {
  • 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/events.h"
    34 #include "common/system.h"
    3533#include "common/timer.h"
    3634
    3735#include "sky/control.h"