~ubuntu-branches/ubuntu/trusty/manaplus/trusty-proposed

« back to all changes in this revision

Viewing changes to src/keyboardconfig.h

  • Committer: Package Import Robot
  • Author(s): Patrick Matthäi
  • Date: 2013-09-17 10:35:51 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20130917103551-az7p3nz9jgxwqjfn
Tags: 1.3.9.15-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  Custom keyboard shortcuts configuration
3
 
 *  Copyright (C) 2007  Joshua Langley <joshlangley@optusnet.com.au>
4
 
 *  Copyright (C) 2009-2010  The Mana Developers
5
 
 *  Copyright (C) 2011-2013  The ManaPlus Developers
6
 
 *
7
 
 *  This file is part of The ManaPlus Client.
8
 
 *
9
 
 *  This program is free software; you can redistribute it and/or modify
10
 
 *  it under the terms of the GNU General Public License as published by
11
 
 *  the Free Software Foundation; either version 2 of the License, or
12
 
 *  any later version.
13
 
 *
14
 
 *  This program is distributed in the hope that it will be useful,
15
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 
 *  GNU General Public License for more details.
18
 
 *
19
 
 *  You should have received a copy of the GNU General Public License
20
 
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 
 */
22
 
 
23
 
#ifndef KEYBOARDCONFIG_H
24
 
#define KEYBOARDCONFIG_H
25
 
 
26
 
#include <SDL_types.h>
27
 
#include <SDL_keyboard.h>
28
 
 
29
 
#include "inputevent.h"
30
 
#include "sdlshared.h"
31
 
 
32
 
#include <map>
33
 
#include <string>
34
 
#include <vector>
35
 
 
36
 
union SDL_Event;
37
 
 
38
 
class KeyboardConfig final
39
 
{
40
 
    public:
41
 
        KeyboardConfig();
42
 
 
43
 
        A_DELETE_COPY(KeyboardConfig)
44
 
 
45
 
        /**
46
 
         * Initializes the keyboard config explicitly.
47
 
         */
48
 
        void init();
49
 
 
50
 
        void deinit();
51
 
 
52
 
        /**
53
 
         * Get the enable flag, which will stop the user from doing actions.
54
 
         */
55
 
        bool isEnabled() const A_WARN_UNUSED
56
 
        { return mEnabled; }
57
 
 
58
 
        /**
59
 
         * Get the key function index by providing the keys value.
60
 
         */
61
 
        int getKeyIndex(const SDL_Event &event,
62
 
                        const int grp = 1) const A_WARN_UNUSED;
63
 
 
64
 
        /**
65
 
         * Set the enable flag, which will stop the user from doing actions.
66
 
         */
67
 
        void setEnabled(const bool flag)
68
 
        { mEnabled = flag; }
69
 
 
70
 
        /**
71
 
         * Takes a snapshot of all the active keys.
72
 
         */
73
 
        void refreshActiveKeys();
74
 
 
75
 
        static std::string getKeyShortString(const std::string &key)
76
 
                                             A_WARN_UNUSED;
77
 
 
78
 
        static SDLKey getKeyFromEvent(const SDL_Event &event) A_WARN_UNUSED;
79
 
 
80
 
        int getKeyValueFromEvent(const SDL_Event &event) const A_WARN_UNUSED;
81
 
 
82
 
        KeysVector *getActionVector(const SDL_Event &event) A_WARN_UNUSED;
83
 
 
84
 
        KeysVector *getActionVectorByKey(const int i) A_WARN_UNUSED;
85
 
 
86
 
        static std::string getKeyName(const int key)A_WARN_UNUSED;
87
 
 
88
 
        bool isActionActive(const int index) const A_WARN_UNUSED;
89
 
 
90
 
        void update();
91
 
 
92
 
        void handleActicateKey(const SDL_Event &event);
93
 
 
94
 
        void handleActicateKey(const int key);
95
 
 
96
 
        void handleDeActicateKey(const SDL_Event &event);
97
 
 
98
 
        void handleDeActicateKey(const int key);
99
 
 
100
 
        int getActionId(const SDL_Event &event) A_WARN_UNUSED;
101
 
 
102
 
        void handleRepeat(const int time);
103
 
 
104
 
        void resetRepeat(const int key);
105
 
 
106
 
    private:
107
 
        bool mEnabled;                   /**< Flag to respond to key input */
108
 
 
109
 
        const uint8_t *mActiveKeys;      /**< Stores a list of all the keys */
110
 
 
111
 
        uint8_t *mActiveKeys2;           /**< Stores a list of all the keys */
112
 
 
113
 
        unsigned int mRepeatTime;
114
 
 
115
 
        KeyToActionMap mKeyToAction;
116
 
 
117
 
        KeyToIdMap mKeyToId;
118
 
 
119
 
        KeyTimeMap mKeyTimeMap;
120
 
};
121
 
 
122
 
extern KeyboardConfig keyboard;
123
 
 
124
 
#endif  // KEYBOARDCONFIG_H