GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/input/touch/multitouchmanager.cpp Lines: 5 7 71.4 %
Date: 2021-03-17 Branches: 0 0 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2013-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/multitouchmanager.h"
23
24
#ifdef USE_SDL2
25
#include "render/graphics.h"
26
27
#include "gui/sdlinput.h"
28
#endif  // USE_SDL2
29
#include "debug.h"
30
31
1
MultiTouchManager multiTouchManager;
32
33
MultiTouchManager::MultiTouchManager() :
34
2
    mEvents()
35
{
36
}
37
38
2
MultiTouchManager::~MultiTouchManager()
39
{
40
1
}
41
42
void MultiTouchManager::init()
43
{
44
2
}
45
46
#ifdef USE_SDL2
47
void MultiTouchManager::updateFinger(const SDL_Event &event, const bool active)
48
{
49
    const SDL_TouchFingerEvent &touch = event.tfinger;
50
    MultiTouchEventsMap &device = mEvents[touch.touchId];
51
    MultiTouchEvent &finger = device[touch.fingerId];
52
    finger.active = active;
53
    finger.x = touch.x;
54
    finger.y = touch.y;
55
}
56
57
void MultiTouchManager::handleFingerDown(const SDL_Event &event)
58
{
59
    updateFinger(event, true);
60
    const SDL_TouchFingerEvent &touch = event.tfinger;
61
    checkDevice(touch.touchId, touch.fingerId);
62
}
63
64
void MultiTouchManager::handleFingerUp(const SDL_Event &event)
65
{
66
    updateFinger(event, false);
67
}
68
69
void MultiTouchManager::checkDevice(const long touchId,
70
                                    const long fingerId)
71
{
72
    if (fingerId != 1 || !guiInput)
73
        return;
74
75
    MultiTouchEventsMap &device = mEvents[touchId];
76
    MultiTouchEvent &finger0 = device[0];
77
    if (finger0.active)
78
    {
79
        MultiTouchEvent &finger1 = device[1];
80
        if (finger1.active)
81
        {
82
            const int w = mainGraphics->mWidth;
83
            const int h = mainGraphics->mHeight;
84
            guiInput->simulateMouseClick(finger0.x * w, finger0.y * h,
85
                MouseButton::RIGHT);
86
        }
87
    }
88
}
89
#endif  // USE_SDL2