Repository navigation
Expand file tree
/
Copy pathCursor.cpp
More file actions
103 lines (95 loc) · 2.3 KB
/
Copy pathCursor.cpp
File metadata and controls
103 lines (95 loc) · 2.3 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
* Copyright 2010 Daniel Albano
*
* This file is part of OpenXcom.
*
* OpenXcom is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenXcom is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Cursor.h"
#include "SDL.h"
#include "SDL_gfxPrimitives.h"
#include "../Engine/Palette.h"
/**
* Sets up a cursor with the specified size and position
* and hides the system cursor.
* @note The size and position don't really matter since
* it's a 9x13 shape, they're just there for inhertiance.
* @param width Width in pixels.
* @param height Height in pixels.
* @param x X position in pixels.
* @param y Y position in pixels.
*/
Cursor::Cursor(int width, int height, int x, int y) : Surface(width, height, x, y), _color(0)
{
SDL_ShowCursor(SDL_DISABLE);
}
/**
*
*/
Cursor::~Cursor()
{
}
/**
* Automatically updates the cursor position
* when the mouse moves.
* @param ev Pointer to the SDL_Event.
* @param scale Scale of the screen.
*/
void Cursor::handle(SDL_Event *ev, int scale)
{
if (ev->type == SDL_MOUSEMOTION)
{
setX(ev->motion.x / scale);
setY(ev->motion.y / scale);
draw();
}
}
/**
* Changes the cursor's base color.
* @param color Color value.
*/
void Cursor::setColor(Uint8 color)
{
_color = color;
draw();
}
/**
* Returns the cursor's base color.
* @return Color value.
*/
Uint8 Cursor::getColor()
{
return _color;
}
/**
* Draws a pointer-shaped cursor graphic.
*/
void Cursor::draw()
{
Uint8 color = _color;
int x1 = 0, y1 = 0, x2 = _width-1, y2 = _height-1;
lock();
for (int i = 0; i < 4; i++)
{
lineColor(getSurface(), x1, y1, x1, y2, Palette::getRGBA(this->getPalette(), color));
lineColor(getSurface(), x1, y1, x2, _width-1, Palette::getRGBA(this->getPalette(), color));
x1++;
y1 += 2;
y2--;
x2--;
color++;
}
this->setPixel(4, 8, --color);
unlock();
}