| 207 | } |
| 208 | |
| 209 | void 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 | |
| 240 | void VirtualDirectionPad::Deactivate() |
| 241 | { |
no test coverage detected