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

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