-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmouse.cpp
More file actions
31 lines (27 loc) · 858 Bytes
/
Copy pathmouse.cpp
File metadata and controls
31 lines (27 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "mouse.h"
uint8_t Mouse::update() {
uint8_t ret = 0;
lastButtons = buttons;
buttons = SDL_GetMouseState(&x, &y);
left = buttons & SDL_BUTTON_LMASK;
right = buttons & SDL_BUTTON_RMASK;
if (buttons != lastButtons) ret |= M_ButtonMask;
if (lastX != x || lastY != y) ret |= M_MovementMask;
if (!(lastButtons & SDL_BUTTON_LMASK) && left) ret |= M_LClickMask;
if (!(lastButtons & SDL_BUTTON_RMASK) && right) ret |= M_RClickMask;
if (!(lastButtons & SDL_BUTTON_MMASK) && middle) ret |= M_MClickMask;
lastX = x;
lastY = y;
last_event = ret;
return ret;
}
Point Mouse::cameraToWorldPos(Camera* c) {
Point p;
p.x = (double)x / c->scale + c->x;
#ifdef LEGACY_COORDINATE_SYSTEM
p.y = (double)(c->h - y) / c->scale + c->y;
#else
p.y = (double)y / c->scale + c->y;
#endif
return p;
}