summaryrefslogtreecommitdiff
path: root/Cursor.cpp
blob: 79d712acd816c89f4d12a39a3e0073525bc32dd8 (plain)
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
#include "Cursor.hpp"
#include "lzr.h"
#include <stdlib.h>
#include <math.h>

Cursor::Cursor() : _angle(0.0), _xscale(1.0), _yscale(1.0),
                   x(0), y(0), down(false), erase(false)
{
}

void Cursor::update()
{
	LZR_MousePosition(&x, &y);
	down = LZR_BUTTON(MOUSE_L);
	erase = LZR_BUTTON(MOUSE_R);
	if (erase) {
		_angle -= 1.0 / 16;
		_xscale = sin(LZR_GetTick());
		_yscale = cos(LZR_GetTick());
		while (_angle < -2.0)
			_angle += 1.0;
	} else if (down) {
		_angle += 1.0 / 16;
		_xscale = sin(LZR_GetTick());
		_yscale = cos(LZR_GetTick());
		while (_angle > 2.0)
			_angle -= 1.0;
	} else {
		double target_angle = 0.0;
		_angle += target_angle - _angle * 0.1;
		_xscale = 1.0 - _xscale * 0.1;
		_yscale = 1.0 - _yscale * 0.1;
	}
}

void Cursor::draw()
{
	LZR_ImageDrawSettings stg = {
		0, 0, -1, -1, 1.0, 1.0, 0.0, true, false, false
	};
	stg.angle = _angle;
	stg.scale_x = _xscale;
	stg.scale_y = _yscale;
	set_color();
	LZR_DrawImageEx(down || erase ? LZR_IMAGE("res/cursor_down.bmp")
			              : LZR_IMAGE("res/cursor_up.bmp"),
			x, y, stg);
}

void Cursor::set_color() const
{
	if (erase)
		LZR_DrawSetColor(rand() & 1, 0, rand() & 1, 1);
	else if (down)
		LZR_DrawSetColor(rand() & 1, rand() & 1, rand() & 1, 1);
	else
		LZR_DrawSetColor(1, 1, 1, (rand() & 3) != 0);
}