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

« back to all changes in this revision

Viewing changes to src/input/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 INPUT_KEYBOARDCONFIG_H
 
24
#define INPUT_KEYBOARDCONFIG_H
 
25
 
 
26
#include <SDL_keyboard.h>
 
27
 
 
28
#include "sdlshared.h"
 
29
 
 
30
#include "input/inputevent.h"
 
31
 
 
32
#include <string>
 
33
 
 
34
union SDL_Event;
 
35
 
 
36
class KeyboardConfig final
 
37
{
 
38
    public:
 
39
        KeyboardConfig();
 
40
 
 
41
        A_DELETE_COPY(KeyboardConfig)
 
42
 
 
43
        /**
 
44
         * Initializes the keyboard config explicitly.
 
45
         */
 
46
        void init();
 
47
 
 
48
        void deinit();
 
49
 
 
50
        /**
 
51
         * Get the enable flag, which will stop the user from doing actions.
 
52
         */
 
53
        bool isEnabled() const A_WARN_UNUSED
 
54
        { return mEnabled; }
 
55
 
 
56
        /**
 
57
         * Get the key function index by providing the keys value.
 
58
         */
 
59
        int getKeyIndex(const SDL_Event &event,
 
60
                        const int grp = 1) const A_WARN_UNUSED;
 
61
 
 
62
        /**
 
63
         * Set the enable flag, which will stop the user from doing actions.
 
64
         */
 
65
        void setEnabled(const bool flag)
 
66
        { mEnabled = flag; }
 
67
 
 
68
        /**
 
69
         * Takes a snapshot of all the active keys.
 
70
         */
 
71
        void refreshActiveKeys();
 
72
 
 
73
        static std::string getKeyShortString(const std::string &key)
 
74
                                             A_WARN_UNUSED;
 
75
 
 
76
        static SDLKey getKeyFromEvent(const SDL_Event &event) A_WARN_UNUSED;
 
77
 
 
78
        int getKeyValueFromEvent(const SDL_Event &event) const A_WARN_UNUSED;
 
79
 
 
80
        KeysVector *getActionVector(const SDL_Event &event) A_WARN_UNUSED;
 
81
 
 
82
        KeysVector *getActionVectorByKey(const int i) A_WARN_UNUSED;
 
83
 
 
84
        static std::string getKeyName(const int key)A_WARN_UNUSED;
 
85
 
 
86
        bool isActionActive(const int index) const A_WARN_UNUSED;
 
87
 
 
88
        void update();
 
89
 
 
90
        void handleActicateKey(const SDL_Event &event);
 
91
 
 
92
        void handleActicateKey(const int key);
 
93
 
 
94
        void handleDeActicateKey(const SDL_Event &event);
 
95
 
 
96
        void handleDeActicateKey(const int key);
 
97
 
 
98
        int getActionId(const SDL_Event &event) A_WARN_UNUSED;
 
99
 
 
100
        void handleRepeat(const int time);
 
101
 
 
102
        void resetRepeat(const int key);
 
103
 
 
104
    private:
 
105
        bool mEnabled;                   /**< Flag to respond to key input */
 
106
 
 
107
        const uint8_t *mActiveKeys;      /**< Stores a list of all the keys */
 
108
 
 
109
        uint8_t *mActiveKeys2;           /**< Stores a list of all the keys */
 
110
 
 
111
        unsigned int mRepeatTime;
 
112
 
 
113
        KeyToActionMap mKeyToAction;
 
114
 
 
115
        KeyToIdMap mKeyToId;
 
116
 
 
117
        KeyTimeMap mKeyTimeMap;
 
118
};
 
119
 
 
120
extern KeyboardConfig keyboard;
 
121
 
 
122
#endif  // INPUT_KEYBOARDCONFIG_H