GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/input/touch/multitouchmanager.cpp Lines: 6 7 85.7 %
Date: 2017-11-29 Branches: 0 0 0.0 %

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