ManaPlus
Macros | Functions | Variables
touchactions.cpp File Reference

(986a3bf)

#include "input/touch/touchactions.h"
#include "input/inputmanager.h"
#include "input/mouseinput.h"
#include "input/touch/touchmanager.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define impHandler(name)   void name(const MouseInput &mouseInput)
 
#define impHandler0(name)   void name(const MouseInput &mouseInput A_UNUSED)
 

Functions

bool padClicked (false)
 
void setHalfJoyPad (const int s)
 
static void moveChar (int x, int y)
 
void padClick (const MouseInput &mouseInput)
 
void padEvents (const MouseInput &mouseInput)
 
void padOut (const MouseInput &mouseInput)
 
void padUp (const MouseInput &mouseInput)
 

Variables

int halfJoyPad = 50
 

Macro Definition Documentation

◆ impHandler

#define impHandler (   name)    void name(const MouseInput &mouseInput)

Definition at line 34 of file touchactions.cpp.

◆ impHandler0

#define impHandler0 (   name)    void name(const MouseInput &mouseInput A_UNUSED)

Definition at line 35 of file touchactions.cpp.

Function Documentation

◆ moveChar()

static void moveChar ( int  x,
int  y 
)
static

Definition at line 42 of file touchactions.cpp.

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 }
void updateConditionMask(const bool pressed)
void setActionActive(const InputActionT index, const bool value)
Definition: touchmanager.h:147
InputManager inputManager
int halfJoyPad
TouchManager touchManager

References halfJoyPad, inputManager, InputAction::MOVE_DOWN, InputAction::MOVE_LEFT, InputAction::MOVE_RIGHT, InputAction::MOVE_UP, TouchManager::setActionActive(), touchManager, InputManager::updateConditionMask(), x, and y.

Referenced by padClick(), padEvents(), padOut(), and padUp().

◆ padClick()

void padClick ( const MouseInput mouseInput)

Definition at line 105 of file touchactions.cpp.

106 {
107  moveChar(mouseInput.getX(), mouseInput.getY());
108  padClicked = true;
109 }
int getX() const
Definition: mouseinput.h:149
int getY() const
Definition: mouseinput.h:159
static void moveChar(int x, int y)
bool padClicked(false)

References moveChar(), and padClicked().

Referenced by TouchManager::loadPad().

◆ padClicked()

bool padClicked ( false  )

Referenced by padClick(), padEvents(), padOut(), and padUp().

◆ padEvents()

void padEvents ( const MouseInput mouseInput)

Definition at line 111 of file touchactions.cpp.

112 {
113  if (mouseInput.getType() == MouseEventType::MOVED)
114  {
115  if (padClicked)
116  moveChar(mouseInput.getX(), mouseInput.getY());
117  }
118 }
MouseEventTypeT getType() const
Definition: mouseinput.h:119

References moveChar(), MouseEventType::MOVED, and padClicked().

Referenced by TouchManager::loadPad().

◆ padOut()

void padOut ( const MouseInput mouseInput)

Definition at line 120 of file touchactions.cpp.

121 {
122  padClicked = false;
124 }

References halfJoyPad, moveChar(), and padClicked().

Referenced by TouchManager::loadPad().

◆ padUp()

void padUp ( const MouseInput mouseInput)

Definition at line 126 of file touchactions.cpp.

127 {
128  padClicked = false;
130 }

References halfJoyPad, moveChar(), and padClicked().

Referenced by TouchManager::loadPad().

◆ setHalfJoyPad()

void setHalfJoyPad ( const int  s)

Definition at line 37 of file touchactions.cpp.

38 {
39  halfJoyPad = s;
40 }

References halfJoyPad.

Referenced by TouchManager::init(), and TouchManager::optionChanged().

Variable Documentation

◆ halfJoyPad

int halfJoyPad = 50

Definition at line 32 of file touchactions.cpp.

Referenced by moveChar(), padOut(), padUp(), and setHalfJoyPad().