ManaPlus
multitouchmanager.cpp
Go to the documentation of this file.
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 
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 
32 
34  mEvents()
35 {
36 }
37 
39 {
40 }
41 
43 {
44 }
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,
86  }
87  }
88 }
89 #endif // USE_SDL2
int mWidth
Definition: graphics.h:484
int mHeight
Definition: graphics.h:485
MultiTouchDevicesMap mEvents
void simulateMouseClick(const int x, const int y, const MouseButtonT button)
Definition: sdlinput.cpp:360
Graphics * mainGraphics
Definition: graphics.cpp:109
MultiTouchManager multiTouchManager
std::map< int, MultiTouchEvent > MultiTouchEventsMap
SDLInput * guiInput
Definition: sdlinput.cpp:101