-
Notifications
You must be signed in to change notification settings - Fork 0
/
cursor.cpp
executable file
·80 lines (66 loc) · 1.26 KB
/
cursor.cpp
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "main.hpp"
Image cursorImage("cursor.png");
ScreenCursor::ScreenCursor()
: EventListener(100)
{
pos = ICoord(screenWidth/2, screenHeight/2);
scroll = ICoord(0,0);
}
void ScreenCursor::moveCursor(int x, int y, int relx, int rely)
{
#ifdef FULLSCREEN
if(x == screenWidth/2 && y == screenHeight/2)
return;
if(relx==0 && rely==0)
return;
pos.x += relx;
pos.y += rely;
SDL_WarpMouse(screenWidth/2, screenHeight/2);
if(pos.x < 0) {
scroll.x += pos.x;
pos.x = 0;
}
if(pos.y < 0) {
scroll.y += pos.y;
pos.y = 0;
}
if(pos.x >= screenWidth) {
scroll.x += (pos.x-screenWidth+1);
pos.x = screenWidth-1;
}
if(pos.y >= screenHeight) {
scroll.y += (pos.y-screenHeight+1);
pos.y = screenHeight-1;
}
#else
pos = ICoord(x, y);
#endif
}
void ScreenCursor::redraw()
{
// Draw cursor
glColor3f(1.0, 1.0, 1.0);
drawImage(pos.x, pos.y, 64, 64, cursorImage);
}
bool ScreenCursor::isOpaque()
{
return false;
}
ICoord ScreenCursor::getLocation()
{
return pos;
}
ICoord ScreenCursor::getScroll()
{
return scroll;
}
void ScreenCursor::clearScroll()
{
scroll = ICoord(0,0);
}
ScreenCursor *cursor = NULL;
void initCursor()
{
if(!cursor)
cursor = new ScreenCursor();
}