GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/input/touch/touchmanager.cpp Lines: 61 364 16.8 %
Date: 2021-03-17 Branches: 29 703 4.1 %

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