ManaPlus
touchactions.cpp
Go to the documentation of this file.
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 
23 
24 #include "input/inputmanager.h"
25 #include "input/mouseinput.h"
26 
28 
29 #include "debug.h"
30 
31 bool padClicked(false);
32 int halfJoyPad = 50;
33 
34 #define impHandler(name) void name(const MouseInput &mouseInput)
35 #define impHandler0(name) void name(const MouseInput &mouseInput A_UNUSED)
36 
37 void setHalfJoyPad(const int s)
38 {
39  halfJoyPad = s;
40 }
41 
42 static void moveChar(int x, int y)
43 {
44  static const int lim1 = 10;
45  static const int diff = 20;
46 
47  // set center at (0,0)
48  x -= halfJoyPad;
49  y -= halfJoyPad;
50 
51  // some magic for checking at what sector was click
52  if (abs(x) < lim1)
53  x = 0;
54 
55  if (abs(y) < lim1)
56  y = 0;
57 
58  const int x2 = abs(x);
59  const int y2 = abs(y);
60  if (x2 > y2)
61  {
62  if ((y2 != 0) && x2 * 10 / y2 > diff)
63  y = 0;
64  }
65  else
66  {
67  if ((x2 != 0) && y2 * 10 / x2 > diff)
68  x = 0;
69  }
70 
71  // detecting direction
72  if (x > 0)
73  {
76  }
77  else if (x < 0)
78  {
81  }
82  else
83  {
86  }
87  if (y > 0)
88  {
91  }
92  else if (y < 0)
93  {
96  }
97  else
98  {
101  }
103 }
104 
106 {
107  moveChar(mouseInput.getX(), mouseInput.getY());
108  padClicked = true;
109 }
110 
112 {
113  if (mouseInput.getType() == MouseEventType::MOVED)
114  {
115  if (padClicked)
116  moveChar(mouseInput.getX(), mouseInput.getY());
117  }
118 }
119 
121 {
122  padClicked = false;
124 }
125 
127 {
128  padClicked = false;
130 }
void updateConditionMask(const bool pressed)
void setActionActive(const InputActionT index, const bool value)
Definition: touchmanager.h:147
InputManager inputManager
void padClick(const MouseInput &mouseInput)
static void moveChar(int x, int y)
void setHalfJoyPad(const int s)
#define impHandler0(name)
void padOut(const MouseInput &mouseInput)
void padEvents(const MouseInput &mouseInput)
bool padClicked(false)
int halfJoyPad
void padUp(const MouseInput &mouseInput)
#define impHandler(name)
TouchManager touchManager