1 |
|
|
/* |
2 |
|
|
* The ManaPlus Client |
3 |
|
|
* Copyright (C) 2012-2019 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 |
|
|
#include "input/touch/touchmanager.h" |
22 |
|
|
|
23 |
|
|
#include "configuration.h" |
24 |
|
|
|
25 |
|
|
#include "gui/gui.h" |
26 |
|
|
#include "gui/skin.h" |
27 |
|
|
#include "gui/theme.h" |
28 |
|
|
|
29 |
|
|
#include "gui/fonts/font.h" |
30 |
|
|
|
31 |
|
|
#include "input/inputmanager.h" |
32 |
|
|
#include "input/mouseinput.h" |
33 |
|
|
|
34 |
|
|
#include "input/touch/touchactions.h" |
35 |
|
|
|
36 |
|
|
#include "utils/delete2.h" |
37 |
|
|
#include "utils/foreach.h" |
38 |
|
|
|
39 |
|
|
#include "render/graphics.h" |
40 |
|
|
|
41 |
|
|
#include "render/vertexes/imagecollection.h" |
42 |
|
|
|
43 |
|
|
#include "resources/imagerect.h" |
44 |
|
|
|
45 |
|
|
#include "resources/image/image.h" |
46 |
|
|
|
47 |
|
|
#include "debug.h" |
48 |
|
|
|
49 |
|
1 |
TouchManager touchManager; |
50 |
|
|
|
51 |
|
|
extern RenderType openGLMode; |
52 |
|
|
|
53 |
|
1 |
TouchManager::TouchManager() : |
54 |
|
|
mKeyboard(nullptr), |
55 |
|
|
mPad(nullptr), |
56 |
|
|
mObjects(), |
57 |
|
|
mVertexes(nullptr), |
58 |
|
|
mRedraw(true), |
59 |
|
|
mShowJoystick(false), |
60 |
|
|
mShowButtons(false), |
61 |
|
|
mShowKeyboard(false), |
62 |
|
|
mButtonsSize(1), |
63 |
|
|
mJoystickSize(1), |
64 |
|
|
mButtonsFormat(0), |
65 |
|
|
mWidth(0), |
66 |
|
|
mHeight(0), |
67 |
|
|
mShow(false), |
68 |
|
|
mInGame(false), |
69 |
|
3 |
mTempHideButtons(false) |
70 |
|
|
{ |
71 |
✓✓ |
670 |
for (int f = 0; f < actionsSize; f ++) |
72 |
|
669 |
mActions[f] = false; |
73 |
✓✓ |
25 |
for (int f = 0; f < buttonsCount; f ++) |
74 |
|
12 |
mButtons[f] = nullptr; |
75 |
|
1 |
} |
76 |
|
|
|
77 |
|
3 |
TouchManager::~TouchManager() |
78 |
|
|
{ |
79 |
|
1 |
clear(); |
80 |
|
|
CHECKLISTENERS |
81 |
|
1 |
} |
82 |
|
|
|
83 |
|
215 |
void TouchManager::shutdown() restrict2 |
84 |
|
|
{ |
85 |
|
215 |
config.removeListeners(this); |
86 |
|
215 |
} |
87 |
|
|
|
88 |
|
77 |
void TouchManager::init() restrict2 |
89 |
|
|
{ |
90 |
✗✓ |
77 |
delete mVertexes; |
91 |
✓✗ |
77 |
mVertexes = new ImageCollection; |
92 |
|
|
|
93 |
✓✗ |
308 |
config.addListener("showScreenJoystick", this); |
94 |
✓✗ |
308 |
config.addListener("showScreenButtons", this); |
95 |
✓✗ |
308 |
config.addListener("showScreenKeyboard", this); |
96 |
✓✗ |
308 |
config.addListener("screenButtonsSize", this); |
97 |
✓✗ |
308 |
config.addListener("screenJoystickSize", this); |
98 |
✓✗ |
308 |
config.addListener("screenButtonsFormat", this); |
99 |
|
|
|
100 |
✓✗ |
308 |
mShowJoystick = config.getBoolValue("showScreenJoystick"); |
101 |
✓✗ |
308 |
mShowButtons = config.getBoolValue("showScreenButtons"); |
102 |
✓✗ |
308 |
mShowKeyboard = config.getBoolValue("showScreenKeyboard"); |
103 |
✓✗ |
308 |
mButtonsSize = config.getIntValue("screenButtonsSize"); |
104 |
✓✗ |
308 |
mJoystickSize = config.getIntValue("screenJoystickSize"); |
105 |
✓✗ |
308 |
mButtonsFormat = config.getIntValue("screenButtonsFormat"); |
106 |
|
|
|
107 |
|
154 |
setHalfJoyPad(getPadSize() / 2); |
108 |
|
|
|
109 |
✗✓ |
77 |
if (mShowKeyboard) |
110 |
|
|
loadKeyboard(); |
111 |
✗✓ |
77 |
if (mShowJoystick) |
112 |
|
|
loadPad(); |
113 |
✗✓ |
77 |
if (mShowButtons) |
114 |
|
|
loadButtons(); |
115 |
|
77 |
mWidth = mainGraphics->mWidth; |
116 |
|
77 |
mHeight = mainGraphics->mHeight; |
117 |
|
77 |
} |
118 |
|
|
|
119 |
|
|
void TouchManager::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, |
129 |
|
|
const TouchFuncPtr fPressed, |
130 |
|
|
const TouchFuncPtr fReleased, |
131 |
|
|
const TouchFuncPtr fOut) restrict2 |
132 |
|
|
{ |
133 |
|
|
*item = nullptr; |
134 |
|
|
if (theme == nullptr) |
135 |
|
|
return; |
136 |
|
|
ImageRect *images = new ImageRect; |
137 |
|
|
for (int f = 0; f < 9; f ++) |
138 |
|
|
images->grid[f] = nullptr; |
139 |
|
|
|
140 |
|
|
Image *icon; |
141 |
|
|
if (imageName.empty()) |
142 |
|
|
icon = nullptr; |
143 |
|
|
else |
144 |
|
|
icon = Theme::getImageFromThemeXml(imageName, ""); |
145 |
|
|
|
146 |
|
|
Skin *const skin = theme->loadSkinRect(*images, |
147 |
|
|
name, |
148 |
|
|
"", |
149 |
|
|
0, |
150 |
|
|
8); |
151 |
|
|
if (skin != nullptr) |
152 |
|
|
{ |
153 |
|
|
Image *const image = images->grid[0]; |
154 |
|
|
if (image != nullptr) |
155 |
|
|
{ |
156 |
|
|
if (x == -1) |
157 |
|
|
x = skin->getOption("x", 10); |
158 |
|
|
if (y == -1) |
159 |
|
|
y = skin->getOption("y", 10); |
160 |
|
|
const int pad = skin->getPadding(); |
161 |
|
|
const int pad2 = 2 * pad; |
162 |
|
|
const int border = skin->getOption("clickborder"); |
163 |
|
|
const int border2 = border * 2; |
164 |
|
|
const int diff = pad - border; |
165 |
|
|
switch (type) |
166 |
|
|
{ |
167 |
|
|
case LEFT: |
168 |
|
|
y += (mainGraphics->mHeight - height) / 2; |
169 |
|
|
break; |
170 |
|
|
case RIGHT: |
171 |
|
|
x = mainGraphics->mWidth - width - pad2 - x; |
172 |
|
|
y = mainGraphics->mHeight - height - pad2 - y; |
173 |
|
|
break; |
174 |
|
|
case NORMAL: |
175 |
|
|
default: |
176 |
|
|
break; |
177 |
|
|
} |
178 |
|
|
*item = new TouchItem(text, Rect(x + diff, y + diff, |
179 |
|
|
width + border2, height + border2), type, |
180 |
|
|
eventPressed, eventReleased, images, icon, |
181 |
|
|
x + pad, y + pad, width, height, |
182 |
|
|
fAll, fPressed, fReleased, fOut); |
183 |
|
|
mObjects.push_back(*item); |
184 |
|
|
} |
185 |
|
|
else |
186 |
|
|
{ |
187 |
|
|
delete images; |
188 |
|
|
} |
189 |
|
|
theme->unload(skin); |
190 |
|
|
} |
191 |
|
|
else |
192 |
|
|
{ |
193 |
|
|
delete images; |
194 |
|
|
} |
195 |
|
|
mRedraw = true; |
196 |
|
|
} |
197 |
|
|
|
198 |
|
216 |
void TouchManager::clear() restrict2 |
199 |
|
|
{ |
200 |
✗✓ |
1296 |
FOR_EACH (TouchItemVectorCIter, it, mObjects) |
201 |
|
|
unload(*it); |
202 |
|
432 |
mObjects.clear(); |
203 |
✓✓ |
216 |
delete2(mVertexes) |
204 |
|
216 |
mRedraw = true; |
205 |
|
216 |
} |
206 |
|
|
|
207 |
|
67 |
void TouchManager::draw() restrict2 |
208 |
|
|
{ |
209 |
✓✗ |
67 |
if (mRedraw) |
210 |
|
|
{ |
211 |
|
67 |
mRedraw = false; |
212 |
|
67 |
mVertexes->clear(); |
213 |
✗✓ |
402 |
FOR_EACH (TouchItemVectorCIter, it, mObjects) |
214 |
|
|
{ |
215 |
|
|
const TouchItem *const item = *it; |
216 |
|
|
if ((item != nullptr) && (item->images != nullptr) && (mShow || |
217 |
|
|
(item == mKeyboard && mShowKeyboard))) |
218 |
|
|
{ |
219 |
|
|
mainGraphics->calcWindow(mVertexes, item->x, item->y, |
220 |
|
|
item->width, item->height, *item->images); |
221 |
|
|
const Image *const icon = item->icon; |
222 |
|
|
if (icon != nullptr) |
223 |
|
|
{ |
224 |
|
|
mainGraphics->calcTileCollection(mVertexes, icon, |
225 |
|
|
item->x + (item->width - icon->mBounds.w) / 2, |
226 |
|
|
item->y + (item->height - icon->mBounds.h) / 2); |
227 |
|
|
} |
228 |
|
|
} |
229 |
|
|
} |
230 |
|
67 |
mainGraphics->finalize(mVertexes); |
231 |
|
|
} |
232 |
|
67 |
mainGraphics->drawTileCollection(mVertexes); |
233 |
|
67 |
drawText(); |
234 |
|
67 |
} |
235 |
|
|
|
236 |
|
|
void TouchManager::safeDraw() restrict2 |
237 |
|
|
{ |
238 |
|
|
FOR_EACH (TouchItemVectorCIter, it, mObjects) |
239 |
|
|
{ |
240 |
|
|
const TouchItem *const item = *it; |
241 |
|
|
if ((item != nullptr) && (item->images != nullptr) && (mShow || |
242 |
|
|
(item == mKeyboard && mShowKeyboard))) |
243 |
|
|
{ |
244 |
|
|
mainGraphics->drawImageRect(item->x, item->y, |
245 |
|
|
item->width, item->height, *item->images); |
246 |
|
|
const Image *const icon = item->icon; |
247 |
|
|
if (icon != nullptr) |
248 |
|
|
{ |
249 |
|
|
mainGraphics->drawImage(icon, |
250 |
|
|
item->x + (item->width - icon->mBounds.w) / 2, |
251 |
|
|
item->y + (item->height - icon->mBounds.h) / 2); |
252 |
|
|
} |
253 |
|
|
} |
254 |
|
|
} |
255 |
|
|
drawText(); |
256 |
|
|
} |
257 |
|
|
|
258 |
|
67 |
void TouchManager::drawText() restrict2 |
259 |
|
|
{ |
260 |
✓✗ |
67 |
if (gui == nullptr) |
261 |
|
|
return; |
262 |
|
|
|
263 |
|
67 |
Font *const font = boldFont; |
264 |
|
67 |
const Color &color1 = theme->getColor(ThemeColorId::TEXT, 255); |
265 |
|
67 |
const Color &color2 = theme->getColor(ThemeColorId::TEXT_OUTLINE, 255); |
266 |
|
|
|
267 |
✗✓ |
402 |
FOR_EACH (TouchItemVectorCIter, it, mObjects) |
268 |
|
|
{ |
269 |
|
|
const TouchItem *const item = *it; |
270 |
|
|
if ((item != nullptr) && mShow && !item->text.empty()) |
271 |
|
|
{ |
272 |
|
|
const std::string str = item->text; |
273 |
|
|
const int textX = (item->rect.width - font->getWidth(str)) |
274 |
|
|
/ 2 + item->x; |
275 |
|
|
const int textY = (item->rect.height - font->getHeight()) |
276 |
|
|
/ 2 + item->y; |
277 |
|
|
font->drawString(mainGraphics, |
278 |
|
|
color1, |
279 |
|
|
color2, |
280 |
|
|
str, textX, textY); |
281 |
|
|
} |
282 |
|
|
} |
283 |
|
|
} |
284 |
|
|
|
285 |
|
|
bool TouchManager::processEvent(const MouseInput &mouseInput) restrict2 |
286 |
|
|
{ |
287 |
|
|
const int x = mouseInput.getTouchX(); |
288 |
|
|
const int y = mouseInput.getTouchY(); |
289 |
|
|
|
290 |
|
|
FOR_EACH (TouchItemVectorCIter, it, mObjects) |
291 |
|
|
{ |
292 |
|
|
const TouchItem *const item = *it; |
293 |
|
|
if (item == nullptr || |
294 |
|
|
(!mShow && (item != mKeyboard || !mShowKeyboard))) |
295 |
|
|
{ |
296 |
|
|
continue; |
297 |
|
|
} |
298 |
|
|
const Rect &rect = item->rect; |
299 |
|
|
if (rect.isPointInRect(x, y)) |
300 |
|
|
{ |
301 |
|
|
MouseInput event = mouseInput; |
302 |
|
|
event.setX(event.getTouchX() - item->x); |
303 |
|
|
event.setY(event.getTouchY() - item->y); |
304 |
|
|
if (item->funcAll != nullptr) |
305 |
|
|
item->funcAll(event); |
306 |
|
|
|
307 |
|
|
switch (mouseInput.getType()) |
308 |
|
|
{ |
309 |
|
|
case MouseEventType::PRESSED: |
310 |
|
|
if (!item->eventPressed.empty()) |
311 |
|
|
executeAction(item->eventPressed); |
312 |
|
|
else if (item->funcPressed != nullptr) |
313 |
|
|
item->funcPressed(event); |
314 |
|
|
break; |
315 |
|
|
case MouseEventType::RELEASED: |
316 |
|
|
if (!item->eventReleased.empty()) |
317 |
|
|
executeAction(item->eventReleased); |
318 |
|
|
else if (item->funcReleased != nullptr) |
319 |
|
|
item->funcReleased(event); |
320 |
|
|
break; |
321 |
|
|
default: |
322 |
|
|
case MouseEventType::MOVED: |
323 |
|
|
case MouseEventType::WHEEL_MOVED_DOWN: |
324 |
|
|
case MouseEventType::WHEEL_MOVED_UP: |
325 |
|
|
case MouseEventType::CLICKED: |
326 |
|
|
case MouseEventType::ENTERED: |
327 |
|
|
case MouseEventType::EXITED: |
328 |
|
|
case MouseEventType::DRAGGED: |
329 |
|
|
case MouseEventType::RELEASED2: |
330 |
|
|
break; |
331 |
|
|
} |
332 |
|
|
return true; |
333 |
|
|
} |
334 |
|
|
else if (item->funcOut != nullptr) |
335 |
|
|
{ |
336 |
|
|
item->funcOut(mouseInput); |
337 |
|
|
} |
338 |
|
|
} |
339 |
|
|
return false; |
340 |
|
|
} |
341 |
|
|
|
342 |
|
2 |
bool TouchManager::isActionActive(const InputActionT index) restrict2 const |
343 |
|
|
{ |
344 |
✓✗ |
2 |
if (CAST_S32(index) < 0 || |
345 |
|
|
CAST_S32(index) >= actionsSize) |
346 |
|
|
{ |
347 |
|
|
return false; |
348 |
|
|
} |
349 |
|
2 |
return mActions[CAST_SIZE(index)]; |
350 |
|
|
} |
351 |
|
|
|
352 |
|
|
void TouchManager::resize(const int width, const int height) restrict2 |
353 |
|
|
{ |
354 |
|
|
mRedraw = true; |
355 |
|
|
const int maxHeight = mHeight; |
356 |
|
|
const int diffW = width - mWidth; |
357 |
|
|
const int diffH = height - maxHeight; |
358 |
|
|
FOR_EACH (TouchItemVectorCIter, it, mObjects) |
359 |
|
|
{ |
360 |
|
|
TouchItem *const item = *it; |
361 |
|
|
if (item == nullptr) |
362 |
|
|
continue; |
363 |
|
|
|
364 |
|
|
switch (item->type) |
365 |
|
|
{ |
366 |
|
|
case LEFT: |
367 |
|
|
if (height != maxHeight) |
368 |
|
|
{ |
369 |
|
|
item->y = (height - item->height) / 2; |
370 |
|
|
item->rect.y = (height - item->rect.y) / 2; |
371 |
|
|
} |
372 |
|
|
break; |
373 |
|
|
case RIGHT: |
374 |
|
|
{ |
375 |
|
|
item->x += diffW; |
376 |
|
|
item->rect.x += diffW; |
377 |
|
|
item->y += diffH; |
378 |
|
|
item->rect.y += diffH; |
379 |
|
|
break; |
380 |
|
|
} |
381 |
|
|
case NORMAL: |
382 |
|
|
default: |
383 |
|
|
break; |
384 |
|
|
} |
385 |
|
|
} |
386 |
|
|
mWidth = mainGraphics->mWidth; |
387 |
|
|
mHeight = mainGraphics->mHeight; |
388 |
|
|
} |
389 |
|
|
|
390 |
|
|
void TouchManager::unload(TouchItem *restrict const item) |
391 |
|
|
{ |
392 |
|
|
if (item != nullptr) |
393 |
|
|
{ |
394 |
|
|
if (item->images != nullptr) |
395 |
|
|
{ |
396 |
|
|
Theme::unloadRect(*item->images, 0, 8); |
397 |
|
|
delete2(item->images) |
398 |
|
|
if (item->icon != nullptr) |
399 |
|
|
{ |
400 |
|
|
item->icon->decRef(); |
401 |
|
|
item->icon = nullptr; |
402 |
|
|
} |
403 |
|
|
} |
404 |
|
|
delete item; |
405 |
|
|
} |
406 |
|
|
} |
407 |
|
|
|
408 |
|
|
void TouchManager::unloadTouchItem(TouchItem *restrict *unloadItem) restrict2 |
409 |
|
|
{ |
410 |
|
|
FOR_EACH (TouchItemVectorIter, it, mObjects) |
411 |
|
|
{ |
412 |
|
|
TouchItem *item = *it; |
413 |
|
|
if ((item != nullptr) && *unloadItem == item) |
414 |
|
|
{ |
415 |
|
|
mObjects.erase(it); |
416 |
|
|
unload(item); |
417 |
|
|
return; |
418 |
|
|
} |
419 |
|
|
} |
420 |
|
|
} |
421 |
|
|
|
422 |
|
|
void TouchManager::loadPad() restrict2 |
423 |
|
|
{ |
424 |
|
|
const int sz = (mJoystickSize + 2) * 50; |
425 |
|
|
loadTouchItem(&mPad, "dpad.xml", "dpad_image.xml", "", -1, -1, sz, sz, |
426 |
|
|
LEFT, "", "", &padEvents, &padClick, &padUp, &padOut); |
427 |
|
|
} |
428 |
|
|
|
429 |
|
|
void TouchManager::loadButtons() restrict2 |
430 |
|
|
{ |
431 |
|
|
const int sz = (mButtonsSize + 1) * 50; |
432 |
|
|
if (theme == nullptr) |
433 |
|
|
return; |
434 |
|
|
Skin *const skin = theme->load("dbutton.xml", |
435 |
|
|
"", |
436 |
|
|
true, |
437 |
|
|
Theme::getThemePath()); |
438 |
|
|
|
439 |
|
|
if (skin != nullptr) |
440 |
|
|
{ |
441 |
|
|
const int x = skin->getOption("x", 10); |
442 |
|
|
const int y = skin->getOption("y", 10); |
443 |
|
|
const int pad = skin->getPadding(); |
444 |
|
|
const int pad2 = 2 * pad + sz; |
445 |
|
|
const int skipWidth = pad2 + x; |
446 |
|
|
const int skipHeight = pad2 + y; |
447 |
|
|
|
448 |
|
|
switch (mButtonsFormat) |
449 |
|
|
{ |
450 |
|
|
// 2x1 |
451 |
|
|
case 0: |
452 |
|
|
default: |
453 |
|
|
{ |
454 |
|
|
loadTouchItem(&mButtons[1], "dbutton.xml", "dbutton_image.xml", |
455 |
|
|
"2", x, y, sz, sz, RIGHT, "screenActionButton1", "", |
456 |
|
|
nullptr, nullptr, nullptr, nullptr); |
457 |
|
|
loadTouchItem(&mButtons[0], "dbutton.xml", "dbutton_image.xml", |
458 |
|
|
"1", skipWidth, y, sz, sz, RIGHT, |
459 |
|
|
"screenActionButton0", "", |
460 |
|
|
nullptr, nullptr, nullptr, nullptr); |
461 |
|
|
break; |
462 |
|
|
} |
463 |
|
|
// 2x2 |
464 |
|
|
case 1: |
465 |
|
|
{ |
466 |
|
|
loadTouchItem(&mButtons[3], "dbutton.xml", "dbutton_image.xml", |
467 |
|
|
"4", x, y, sz, sz, RIGHT, "screenActionButton3", "", |
468 |
|
|
nullptr, nullptr, nullptr, nullptr); |
469 |
|
|
loadTouchItem(&mButtons[2], "dbutton.xml", "dbutton_image.xml", |
470 |
|
|
"3", skipWidth, y, sz, sz, RIGHT, |
471 |
|
|
"screenActionButton2", "", |
472 |
|
|
nullptr, nullptr, nullptr, nullptr); |
473 |
|
|
loadTouchItem(&mButtons[1], "dbutton.xml", "dbutton_image.xml", |
474 |
|
|
"2", x, skipHeight, sz, sz, RIGHT, |
475 |
|
|
"screenActionButton1", "", |
476 |
|
|
nullptr, nullptr, nullptr, nullptr); |
477 |
|
|
loadTouchItem(&mButtons[0], "dbutton.xml", "dbutton_image.xml", |
478 |
|
|
"1", skipWidth, skipHeight, sz, sz, RIGHT, |
479 |
|
|
"screenActionButton0", "", |
480 |
|
|
nullptr, nullptr, nullptr, nullptr); |
481 |
|
|
break; |
482 |
|
|
} |
483 |
|
|
// 3x3 |
484 |
|
|
case 2: |
485 |
|
|
{ |
486 |
|
|
const int pad4 = pad2 * 2; |
487 |
|
|
const int skipWidth2 = pad4 + x; |
488 |
|
|
const int skipHeight2 = pad4 + y; |
489 |
|
|
loadTouchItem(&mButtons[8], "dbutton.xml", "dbutton_image.xml", |
490 |
|
|
"9", x, y, sz, sz, RIGHT, "screenActionButton8", "", |
491 |
|
|
nullptr, nullptr, nullptr, nullptr); |
492 |
|
|
loadTouchItem(&mButtons[7], "dbutton.xml", "dbutton_image.xml", |
493 |
|
|
"8", skipWidth, y, sz, sz, RIGHT, |
494 |
|
|
"screenActionButton7", "", |
495 |
|
|
nullptr, nullptr, nullptr, nullptr); |
496 |
|
|
loadTouchItem(&mButtons[6], "dbutton.xml", "dbutton_image.xml", |
497 |
|
|
"7", skipWidth2, y, sz, sz, RIGHT, |
498 |
|
|
"screenActionButton6", "", |
499 |
|
|
nullptr, nullptr, nullptr, nullptr); |
500 |
|
|
loadTouchItem(&mButtons[5], "dbutton.xml", "dbutton_image.xml", |
501 |
|
|
"6", x, skipHeight, sz, sz, RIGHT, |
502 |
|
|
"screenActionButton5", "", |
503 |
|
|
nullptr, nullptr, nullptr, nullptr); |
504 |
|
|
loadTouchItem(&mButtons[4], "dbutton.xml", "dbutton_image.xml", |
505 |
|
|
"5", skipWidth, skipHeight, sz, sz, RIGHT, |
506 |
|
|
"screenActionButton4", "", |
507 |
|
|
nullptr, nullptr, nullptr, nullptr); |
508 |
|
|
loadTouchItem(&mButtons[3], "dbutton.xml", "dbutton_image.xml", |
509 |
|
|
"4", skipWidth2, skipHeight, sz, sz, RIGHT, |
510 |
|
|
"screenActionButton3", "", |
511 |
|
|
nullptr, nullptr, nullptr, nullptr); |
512 |
|
|
loadTouchItem(&mButtons[2], "dbutton.xml", "dbutton_image.xml", |
513 |
|
|
"3", x, skipHeight2, sz, sz, RIGHT, |
514 |
|
|
"screenActionButton2", "", |
515 |
|
|
nullptr, nullptr, nullptr, nullptr); |
516 |
|
|
loadTouchItem(&mButtons[1], "dbutton.xml", "dbutton_image.xml", |
517 |
|
|
"2", skipWidth, skipHeight2, sz, sz, RIGHT, |
518 |
|
|
"screenActionButton1", "", |
519 |
|
|
nullptr, nullptr, nullptr, nullptr); |
520 |
|
|
loadTouchItem(&mButtons[0], "dbutton.xml", "dbutton_image.xml", |
521 |
|
|
"1", skipWidth2, skipHeight2, sz, sz, RIGHT, |
522 |
|
|
"screenActionButton0", "", |
523 |
|
|
nullptr, nullptr, nullptr, nullptr); |
524 |
|
|
break; |
525 |
|
|
} |
526 |
|
|
// 4x2 |
527 |
|
|
case 3: |
528 |
|
|
{ |
529 |
|
|
const int skipWidth2 = pad2 * 2 + x; |
530 |
|
|
const int skipWidth3 = pad2 * 3 + x; |
531 |
|
|
loadTouchItem(&mButtons[7], "dbutton.xml", "dbutton_image.xml", |
532 |
|
|
"8", x, y, sz, sz, RIGHT, "screenActionButton7", "", |
533 |
|
|
nullptr, nullptr, nullptr, nullptr); |
534 |
|
|
loadTouchItem(&mButtons[6], "dbutton.xml", "dbutton_image.xml", |
535 |
|
|
"7", skipWidth, y, sz, sz, RIGHT, |
536 |
|
|
"screenActionButton6", "", |
537 |
|
|
nullptr, nullptr, nullptr, nullptr); |
538 |
|
|
loadTouchItem(&mButtons[5], "dbutton.xml", "dbutton_image.xml", |
539 |
|
|
"6", skipWidth2, y, sz, sz, RIGHT, |
540 |
|
|
"screenActionButton5", "", |
541 |
|
|
nullptr, nullptr, nullptr, nullptr); |
542 |
|
|
loadTouchItem(&mButtons[4], "dbutton.xml", "dbutton_image.xml", |
543 |
|
|
"5", skipWidth3, y, sz, sz, RIGHT, |
544 |
|
|
"screenActionButton4", "", |
545 |
|
|
nullptr, nullptr, nullptr, nullptr); |
546 |
|
|
loadTouchItem(&mButtons[3], "dbutton.xml", "dbutton_image.xml", |
547 |
|
|
"4", x, skipHeight, sz, sz, RIGHT, |
548 |
|
|
"screenActionButton3", "", |
549 |
|
|
nullptr, nullptr, nullptr, nullptr); |
550 |
|
|
loadTouchItem(&mButtons[2], "dbutton.xml", "dbutton_image.xml", |
551 |
|
|
"3", skipWidth, skipHeight, sz, sz, RIGHT, |
552 |
|
|
"screenActionButton2", "", |
553 |
|
|
nullptr, nullptr, nullptr, nullptr); |
554 |
|
|
loadTouchItem(&mButtons[1], "dbutton.xml", "dbutton_image.xml", |
555 |
|
|
"2", skipWidth2, skipHeight, sz, sz, RIGHT, |
556 |
|
|
"screenActionButton1", "", |
557 |
|
|
nullptr, nullptr, nullptr, nullptr); |
558 |
|
|
loadTouchItem(&mButtons[0], "dbutton.xml", "dbutton_image.xml", |
559 |
|
|
"1", skipWidth3, skipHeight, sz, sz, RIGHT, |
560 |
|
|
"screenActionButton0", "", |
561 |
|
|
nullptr, nullptr, nullptr, nullptr); |
562 |
|
|
break; |
563 |
|
|
} |
564 |
|
|
// 4x3 |
565 |
|
|
case 4: |
566 |
|
|
{ |
567 |
|
|
const int skipWidth2 = pad2 * 2 + x; |
568 |
|
|
const int skipWidth3 = pad2 * 3 + x; |
569 |
|
|
const int skipHeight2 = pad2 * 2 + y; |
570 |
|
|
loadTouchItem(&mButtons[11], "dbutton.xml", |
571 |
|
|
"dbutton_image.xml", "12", x, y, sz, sz, RIGHT, |
572 |
|
|
"screenActionButton11", "", |
573 |
|
|
nullptr, nullptr, nullptr, nullptr); |
574 |
|
|
loadTouchItem(&mButtons[10], "dbutton.xml", |
575 |
|
|
"dbutton_image.xml", "11", skipWidth, y, sz, sz, RIGHT, |
576 |
|
|
"screenActionButton10", "", |
577 |
|
|
nullptr, nullptr, nullptr, nullptr); |
578 |
|
|
loadTouchItem(&mButtons[9], "dbutton.xml", "dbutton_image.xml", |
579 |
|
|
"10", skipWidth2, y, sz, sz, RIGHT, |
580 |
|
|
"screenActionButton9", "", |
581 |
|
|
nullptr, nullptr, nullptr, nullptr); |
582 |
|
|
loadTouchItem(&mButtons[8], "dbutton.xml", "dbutton_image.xml", |
583 |
|
|
"9", skipWidth3, y, sz, sz, RIGHT, |
584 |
|
|
"screenActionButton8", "", |
585 |
|
|
nullptr, nullptr, nullptr, nullptr); |
586 |
|
|
loadTouchItem(&mButtons[7], "dbutton.xml", "dbutton_image.xml", |
587 |
|
|
"8", x, skipHeight, sz, sz, RIGHT, |
588 |
|
|
"screenActionButton7", "", |
589 |
|
|
nullptr, nullptr, nullptr, nullptr); |
590 |
|
|
loadTouchItem(&mButtons[6], "dbutton.xml", "dbutton_image.xml", |
591 |
|
|
"7", skipWidth, skipHeight, sz, sz, RIGHT, |
592 |
|
|
"screenActionButton6", "", |
593 |
|
|
nullptr, nullptr, nullptr, nullptr); |
594 |
|
|
loadTouchItem(&mButtons[5], "dbutton.xml", "dbutton_image.xml", |
595 |
|
|
"6", skipWidth2, skipHeight, sz, sz, RIGHT, |
596 |
|
|
"screenActionButton5", "", |
597 |
|
|
nullptr, nullptr, nullptr, nullptr); |
598 |
|
|
loadTouchItem(&mButtons[4], "dbutton.xml", "dbutton_image.xml", |
599 |
|
|
"5", skipWidth3, skipHeight, sz, sz, RIGHT, |
600 |
|
|
"screenActionButton4", "", |
601 |
|
|
nullptr, nullptr, nullptr, nullptr); |
602 |
|
|
loadTouchItem(&mButtons[3], "dbutton.xml", "dbutton_image.xml", |
603 |
|
|
"4", x, skipHeight2, sz, sz, RIGHT, |
604 |
|
|
"screenActionButton3", "", |
605 |
|
|
nullptr, nullptr, nullptr, nullptr); |
606 |
|
|
loadTouchItem(&mButtons[2], "dbutton.xml", "dbutton_image.xml", |
607 |
|
|
"3", skipWidth, skipHeight2, sz, sz, RIGHT, |
608 |
|
|
"screenActionButton2", "", |
609 |
|
|
nullptr, nullptr, nullptr, nullptr); |
610 |
|
|
loadTouchItem(&mButtons[1], "dbutton.xml", "dbutton_image.xml", |
611 |
|
|
"2", skipWidth2, skipHeight2, sz, sz, RIGHT, |
612 |
|
|
"screenActionButton1", "", |
613 |
|
|
nullptr, nullptr, nullptr, nullptr); |
614 |
|
|
loadTouchItem(&mButtons[0], "dbutton.xml", "dbutton_image.xml", |
615 |
|
|
"1", skipWidth3, skipHeight2, sz, sz, RIGHT, |
616 |
|
|
"screenActionButton0", "", |
617 |
|
|
nullptr, nullptr, nullptr, nullptr); |
618 |
|
|
break; |
619 |
|
|
} |
620 |
|
|
// 3x2 |
621 |
|
|
case 5: |
622 |
|
|
{ |
623 |
|
|
const int pad4 = pad2 * 2; |
624 |
|
|
const int skipWidth2 = pad4 + x; |
625 |
|
|
loadTouchItem(&mButtons[5], "dbutton.xml", "dbutton_image.xml", |
626 |
|
|
"6", x, y, sz, sz, RIGHT, "screenActionButton5", "", |
627 |
|
|
nullptr, nullptr, nullptr, nullptr); |
628 |
|
|
loadTouchItem(&mButtons[4], "dbutton.xml", "dbutton_image.xml", |
629 |
|
|
"5", skipWidth, y, sz, sz, RIGHT, |
630 |
|
|
"screenActionButton4", "", |
631 |
|
|
nullptr, nullptr, nullptr, nullptr); |
632 |
|
|
loadTouchItem(&mButtons[3], "dbutton.xml", "dbutton_image.xml", |
633 |
|
|
"4", skipWidth2, y, sz, sz, RIGHT, |
634 |
|
|
"screenActionButton3", "", |
635 |
|
|
nullptr, nullptr, nullptr, nullptr); |
636 |
|
|
loadTouchItem(&mButtons[2], "dbutton.xml", "dbutton_image.xml", |
637 |
|
|
"3", x, skipHeight, sz, sz, RIGHT, |
638 |
|
|
"screenActionButton2", "", |
639 |
|
|
nullptr, nullptr, nullptr, nullptr); |
640 |
|
|
loadTouchItem(&mButtons[1], "dbutton.xml", "dbutton_image.xml", |
641 |
|
|
"2", skipWidth, skipHeight, sz, sz, RIGHT, |
642 |
|
|
"screenActionButton1", "", |
643 |
|
|
nullptr, nullptr, nullptr, nullptr); |
644 |
|
|
loadTouchItem(&mButtons[0], "dbutton.xml", "dbutton_image.xml", |
645 |
|
|
"1", skipWidth2, skipHeight, sz, sz, RIGHT, |
646 |
|
|
"screenActionButton0", "", |
647 |
|
|
nullptr, nullptr, nullptr, nullptr); |
648 |
|
|
break; |
649 |
|
|
} |
650 |
|
|
} |
651 |
|
|
theme->unload(skin); |
652 |
|
|
} |
653 |
|
|
} |
654 |
|
|
|
655 |
|
|
void TouchManager::loadKeyboard() restrict2 |
656 |
|
|
{ |
657 |
|
|
loadTouchItem(&mKeyboard, "keyboard_icon.xml", "", "", -1, -1, 28, 28, |
658 |
|
|
NORMAL, "", "screenActionKeyboard", |
659 |
|
|
nullptr, nullptr, nullptr, nullptr); |
660 |
|
|
} |
661 |
|
|
|
662 |
|
|
void TouchManager::optionChanged(const std::string &value) restrict2 |
663 |
|
|
{ |
664 |
|
|
if (value == "showScreenJoystick") |
665 |
|
|
{ |
666 |
|
|
if (mShowJoystick == config.getBoolValue("showScreenJoystick")) |
667 |
|
|
return; |
668 |
|
|
mShowJoystick = config.getBoolValue("showScreenJoystick"); |
669 |
|
|
if (mShowJoystick) |
670 |
|
|
loadPad(); |
671 |
|
|
else |
672 |
|
|
unloadTouchItem(&mPad); |
673 |
|
|
mRedraw = true; |
674 |
|
|
} |
675 |
|
|
else if (value == "showScreenButtons") |
676 |
|
|
{ |
677 |
|
|
if (mShowButtons == config.getBoolValue("showScreenButtons")) |
678 |
|
|
return; |
679 |
|
|
mShowButtons = config.getBoolValue("showScreenButtons"); |
680 |
|
|
if (mShowButtons) |
681 |
|
|
{ |
682 |
|
|
loadButtons(); |
683 |
|
|
} |
684 |
|
|
else |
685 |
|
|
{ |
686 |
|
|
for (int f = 0; f < buttonsCount; f ++) |
687 |
|
|
unloadTouchItem(&mButtons[f]); |
688 |
|
|
} |
689 |
|
|
mRedraw = true; |
690 |
|
|
} |
691 |
|
|
else if (value == "showScreenKeyboard") |
692 |
|
|
{ |
693 |
|
|
if (mShowKeyboard == config.getBoolValue("showScreenKeyboard")) |
694 |
|
|
return; |
695 |
|
|
mShowKeyboard = config.getBoolValue("showScreenKeyboard"); |
696 |
|
|
if (mShowKeyboard) |
697 |
|
|
loadKeyboard(); |
698 |
|
|
else |
699 |
|
|
unloadTouchItem(&mKeyboard); |
700 |
|
|
mRedraw = true; |
701 |
|
|
} |
702 |
|
|
else if (value == "screenButtonsSize") |
703 |
|
|
{ |
704 |
|
|
if (mButtonsSize == config.getIntValue("screenButtonsSize")) |
705 |
|
|
return; |
706 |
|
|
mButtonsSize = config.getIntValue("screenButtonsSize"); |
707 |
|
|
if (mShowButtons) |
708 |
|
|
{ |
709 |
|
|
for (int f = 0; f < buttonsCount; f ++) |
710 |
|
|
unloadTouchItem(&mButtons[f]); |
711 |
|
|
loadButtons(); |
712 |
|
|
} |
713 |
|
|
} |
714 |
|
|
else if (value == "screenJoystickSize") |
715 |
|
|
{ |
716 |
|
|
if (mJoystickSize == config.getIntValue("screenJoystickSize")) |
717 |
|
|
return; |
718 |
|
|
mJoystickSize = config.getIntValue("screenJoystickSize"); |
719 |
|
|
setHalfJoyPad(getPadSize() / 2); |
720 |
|
|
if (mShowJoystick) |
721 |
|
|
{ |
722 |
|
|
unloadTouchItem(&mPad); |
723 |
|
|
loadPad(); |
724 |
|
|
} |
725 |
|
|
} |
726 |
|
|
else if (value == "screenButtonsFormat") |
727 |
|
|
{ |
728 |
|
|
if (mButtonsFormat == config.getIntValue("screenButtonsFormat")) |
729 |
|
|
return; |
730 |
|
|
mButtonsFormat = config.getIntValue("screenButtonsFormat"); |
731 |
|
|
if (mShowButtons) |
732 |
|
|
{ |
733 |
|
|
for (int f = 0; f < buttonsCount; f ++) |
734 |
|
|
unloadTouchItem(&mButtons[f]); |
735 |
|
|
loadButtons(); |
736 |
|
|
} |
737 |
|
|
} |
738 |
|
|
} |
739 |
|
|
|
740 |
|
|
void TouchManager::setInGame(const bool b) restrict2 |
741 |
|
|
{ |
742 |
|
|
mInGame = b; |
743 |
|
|
mShow = mInGame && !mTempHideButtons; |
744 |
|
|
mRedraw = true; |
745 |
|
|
} |
746 |
|
|
|
747 |
|
|
void TouchManager::setTempHide(const bool b) restrict2 |
748 |
|
|
{ |
749 |
|
|
mTempHideButtons = b; |
750 |
|
|
mShow = mInGame && !mTempHideButtons; |
751 |
|
|
mRedraw = true; |
752 |
|
|
} |
753 |
|
|
|
754 |
|
|
void TouchManager::executeAction(const std::string &restrict event) |
755 |
|
|
{ |
756 |
|
|
inputManager.executeAction(static_cast<InputActionT>( |
757 |
|
|
config.getIntValue(event))); |
758 |
|
2 |
} |