GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/input/touch/touchmanager.h Lines: 1 6 16.7 %
Date: 2017-11-29 Branches: 0 0 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2011-2017  The ManaPlus Developers
4
 *
5
 *  This file is part of The ManaPlus Client.
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  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, see <http://www.gnu.org/licenses/>.
19
 */
20
21
#ifndef INPUT_TOUCH_TOUCHMANAGER_H
22
#define INPUT_TOUCH_TOUCHMANAGER_H
23
24
#include "listeners/configlistener.h"
25
26
#include "enums/input/inputaction.h"
27
28
#include "gui/rect.h"
29
30
#include "utils/cast.h"
31
#include "utils/vector.h"
32
33
#include "localconsts.h"
34
35
class Image;
36
class ImageCollection;
37
class ImageRect;
38
class MouseInput;
39
40
typedef void (*TouchFuncPtr) (const MouseInput &restrict mouseInput);
41
42
const int actionsSize = CAST_S32(InputAction::TOTAL);
43
const int buttonsCount = 12;
44
45
struct TouchItem final
46
{
47
    TouchItem(const std::string &text0,
48
              const Rect &rect0,
49
              const int type0,
50
              const std::string &restrict eventPressed0,
51
              const std::string &restrict eventReleased0,
52
              ImageRect *restrict const images0,
53
              Image *restrict const icon0,
54
              const int x0, const int y0,
55
              const int width0, const int height0,
56
              const TouchFuncPtr ptrAll,
57
              const TouchFuncPtr ptrPressed,
58
              const TouchFuncPtr ptrReleased,
59
              const TouchFuncPtr ptrOut) :
60
        text(text0),
61
        rect(rect0),
62
        type(type0),
63
        eventPressed(eventPressed0),
64
        eventReleased(eventReleased0),
65
        images(images0),
66
        icon(icon0),
67
        x(x0),
68
        y(y0),
69
        width(width0),
70
        height(height0),
71
        funcAll(ptrAll),
72
        funcPressed(ptrPressed),
73
        funcReleased(ptrReleased),
74
        funcOut(ptrOut)
75
    {
76
    }
77
78
    A_DELETE_COPY(TouchItem)
79
80
    std::string text;
81
    Rect rect;
82
    int type;
83
    std::string eventPressed;
84
    std::string eventReleased;
85
    ImageRect *images;
86
    Image *icon;
87
    int x;
88
    int y;
89
    int width;
90
    int height;
91
    TouchFuncPtr funcAll;
92
    TouchFuncPtr funcPressed;
93
    TouchFuncPtr funcReleased;
94
    TouchFuncPtr funcOut;
95
};
96
97
typedef STD_VECTOR<TouchItem*> TouchItemVector;
98
typedef TouchItemVector::const_iterator TouchItemVectorCIter;
99
typedef TouchItemVector::iterator TouchItemVectorIter;
100
101
class TouchManager final : public ConfigListener
102
{
103
    public:
104
        TouchManager();
105
106
        ~TouchManager();
107
108
        A_DELETE_COPY(TouchManager)
109
110
        enum Types
111
        {
112
            NORMAL = 0,
113
            LEFT = 1,
114
            RIGHT = 2
115
        };
116
117
        void init() restrict2;
118
119
        void loadTouchItem(TouchItem **restrict item,
120
                           const std::string &restrict name,
121
                           const std::string &restrict imageName,
122
                           const std::string &restrict text,
123
                           int x, int y,
124
                           const int width, const int height,
125
                           const int type,
126
                           const std::string &restrict eventPressed,
127
                           const std::string &restrict eventReleased,
128
                           const TouchFuncPtr fAll = nullptr,
129
                           const TouchFuncPtr fPressed = nullptr,
130
                           const TouchFuncPtr fReleased = nullptr,
131
                           const TouchFuncPtr fOut = nullptr)
132
                           restrict2 A_NONNULL(2);
133
134
        void clear() restrict2;
135
136
        void draw() restrict2;
137
138
        void safeDraw() restrict2;
139
140
        void drawText() restrict2;
141
142
        bool processEvent(const MouseInput &mouseInput) restrict2;
143
144
        bool isActionActive(const InputActionT index) restrict2 const;
145
146
        void setActionActive(const InputActionT index,
147
                             const bool value) restrict2
148
        {
149
            if (CAST_S32(index) >= 0 &&
150
                CAST_S32(index) < actionsSize)
151
            {
152
                mActions[CAST_SIZE(index)] = value;
153
            }
154
        }
155
156
        void resize(const int width, const int height) restrict2;
157
158
        static void unload(TouchItem *restrict const item);
159
160
        void unloadTouchItem(TouchItem *restrict *unloadItem) restrict2;
161
162
        void optionChanged(const std::string &value) restrict2 override final;
163
164
        void loadPad() restrict2;
165
166
        void loadButtons() restrict2;
167
168
        void loadKeyboard() restrict2;
169
170
        int getPadSize() restrict2 const
171
152
        { return (mJoystickSize + 2) * 50; }
172
173
        void setInGame(const bool b) restrict2;
174
175
        void setTempHide(const bool b) restrict2;
176
177
        void shutdown() restrict2;
178
179
        static void executeAction(const std::string &restrict event);
180
181
    private:
182
        TouchItem *mKeyboard;
183
        TouchItem *mPad;
184
        TouchItem *mButtons[buttonsCount] A_NONNULLPOINTER;
185
        TouchItemVector mObjects;
186
        ImageCollection *mVertexes A_NONNULLPOINTER;
187
        bool mActions[actionsSize];
188
        bool mRedraw;
189
        bool mShowJoystick;
190
        bool mShowButtons;
191
        bool mShowKeyboard;
192
        int mButtonsSize;
193
        int mJoystickSize;
194
        int mButtonsFormat;
195
        int mWidth;
196
        int mHeight;
197
        bool mShow;
198
        bool mInGame;
199
        bool mTempHideButtons;
200
};
201
202
extern TouchManager touchManager;
203
204
#endif  // INPUT_TOUCH_TOUCHMANAGER_H