MCPcopy Create free account
hub / github.com/diasurgical/DevilutionX / UpdatePosition

Method UpdatePosition

Source/controls/touch/gamepad.cpp:209–238  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

207}
208
209void VirtualDirectionPad::UpdatePosition(Point touchCoordinates)
210{
211 position = touchCoordinates;
212
213 Displacement diff = position - area.position;
214 if (diff == Displacement { 0, 0 }) {
215 isUpPressed = false;
216 isDownPressed = false;
217 isLeftPressed = false;
218 isRightPressed = false;
219 return;
220 }
221
222 if (!area.contains(position)) {
223 int x = diff.deltaX;
224 int y = diff.deltaY;
225 double dist = sqrt(x * x + y * y);
226 x = round(x * area.radius / dist);
227 y = round(y * area.radius / dist);
228 position.x = area.position.x + x;
229 position.y = area.position.y + y;
230 }
231
232 double angle = atan2(-diff.deltaY, diff.deltaX);
233
234 isUpPressed = PointsUp(angle);
235 isDownPressed = PointsDown(angle);
236 isLeftPressed = PointsLeft(angle);
237 isRightPressed = PointsRight(angle);
238}
239
240void VirtualDirectionPad::Deactivate()
241{

Callers 3

HandleFingerDownMethod · 0.80
HandleFingerUpMethod · 0.80
HandleFingerMotionMethod · 0.80

Calls 5

PointsUpFunction · 0.85
PointsDownFunction · 0.85
PointsLeftFunction · 0.85
PointsRightFunction · 0.85
containsMethod · 0.45

Tested by

no test coverage detected