73 lines
1.7 KiB
C++
73 lines
1.7 KiB
C++
#include "GUIMouse.h"
|
|
|
|
#include "application.h"
|
|
|
|
namespace GUIMouse
|
|
{
|
|
Vector2 position {0, 0};
|
|
Vector2 delta {0, 0};
|
|
Vector2 slowDelta {0, 0};
|
|
Vector2 wheel {0, 0};
|
|
ButtonState buttons[3] {ButtonState::Released, ButtonState::Released, ButtonState::Released};
|
|
Gesture gesture {};
|
|
|
|
Vector2 slowAccum {0, 0};
|
|
|
|
void ReceiveMouseUpEvent(const Button button)
|
|
{
|
|
buttons[button] = ButtonState::Up;
|
|
Application::NeedsUpdate();
|
|
}
|
|
|
|
void ReceiveMouseDownEvent(const Button button)
|
|
{
|
|
buttons[button] = ButtonState::Down;
|
|
Application::NeedsUpdate();
|
|
}
|
|
|
|
void ReceiveMouseMoveEvent(const float x, const float y)
|
|
{
|
|
delta = {x-position.x, y-position.y};
|
|
slowAccum += delta * 0.2f;
|
|
if (slowAccum.x >= 1 or slowAccum.x <= -1) {
|
|
slowDelta.x = int(slowAccum.x);
|
|
slowAccum.x = slowAccum.x - int(slowAccum.x);
|
|
}
|
|
if (slowAccum.y >= 1 or slowAccum.y <= -1) {
|
|
slowDelta.y = int(slowAccum.y);
|
|
slowAccum.y = slowAccum.y - int(slowAccum.y);
|
|
}
|
|
position = Vector2(x, y);
|
|
Application::NeedsUpdate();
|
|
}
|
|
|
|
void ReceiveMouseWheelEvent(const float x, const float y)
|
|
{
|
|
wheel = Vector2(x, y);
|
|
Application::NeedsUpdate();
|
|
}
|
|
|
|
void ReceiveMultigestureEvent(const float theta, const float dist, const int numFingers)
|
|
{
|
|
gesture.theta = theta;
|
|
gesture.dist = dist;
|
|
gesture.numFingers = numFingers;
|
|
Application::NeedsUpdate();
|
|
}
|
|
|
|
void Reset()
|
|
{
|
|
for (int i = 0; i < 3; i++) {
|
|
if (buttons[i] == ButtonState::Down) {
|
|
buttons[i] = ButtonState::Pressed;
|
|
} else if (buttons[i] == ButtonState::Up) {
|
|
buttons[i] = ButtonState::Released;
|
|
}
|
|
}
|
|
wheel = {0,0};
|
|
delta = {0,0};
|
|
slowDelta = {0,0};
|
|
gesture.theta = gesture.dist = gesture.numFingers = 0;
|
|
}
|
|
}
|