ManaPlus
touchmanager.h
Go to the documentation of this file.
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 
26 
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 
44 const int buttonsCount = 12;
45 
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 
80 
81  std::string text;
83  int type;
84  std::string eventPressed;
85  std::string eventReleased;
88  int x;
89  int y;
90  int width;
91  int height;
96 };
97 
99 typedef TouchItemVector::const_iterator TouchItemVectorCIter;
101 
103 {
104  public:
105  TouchManager();
106 
107  ~TouchManager() override final;
108 
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  { 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;
186  TouchItemVector mObjects;
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 
204 
205 #endif // INPUT_TOUCH_TOUCHMANAGER_H
#define CAST_S32
Definition: cast.h:30
#define CAST_SIZE
Definition: cast.h:34
Definition: rect.h:74
InputAction ::T InputActionT
Definition: inputaction.h:717
#define restrict
Definition: localconsts.h:165
#define restrict2
Definition: localconsts.h:166
#define A_NONNULL(...)
Definition: localconsts.h:168
#define A_NONNULLPOINTER
Definition: localconsts.h:266
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
void unload()
Definition: net.cpp:180
void init()
Definition: playerinfo.cpp:434
void clear()
Definition: playerinfo.cpp:452
std::string eventPressed
Definition: touchmanager.h:84
TouchFuncPtr funcOut
Definition: touchmanager.h:95
Image * icon
Definition: touchmanager.h:87
TouchFuncPtr funcReleased
Definition: touchmanager.h:94
std::string eventReleased
Definition: touchmanager.h:85
std::string text
Definition: touchmanager.h:81
TouchFuncPtr funcAll
Definition: touchmanager.h:92
ImageRect * images
Definition: touchmanager.h:86
TouchItem(const std::string &text0, const Rect &rect0, const int type0, const std::string &eventPressed0, const std::string &eventReleased0, ImageRect *const images0, Image *const icon0, const int x0, const int y0, const int width0, const int height0, const TouchFuncPtr ptrAll, const TouchFuncPtr ptrPressed, const TouchFuncPtr ptrReleased, const TouchFuncPtr ptrOut)
Definition: touchmanager.h:48
TouchFuncPtr funcPressed
Definition: touchmanager.h:93
TouchItemVector::iterator TouchItemVectorIter
Definition: touchmanager.h:100
const int buttonsCount
Definition: touchmanager.h:44
TouchItemVector::const_iterator TouchItemVectorCIter
Definition: touchmanager.h:99
const int actionsSize
Definition: touchmanager.h:43
void(* TouchFuncPtr)(const MouseInput &mouseInput)
Definition: touchmanager.h:41
std::vector< TouchItem * > TouchItemVector
Definition: touchmanager.h:98
TouchManager touchManager
#define STD_VECTOR
Definition: vector.h:30