28
28
#include "Systems/Base/MouseCursor.hpp"
30
#include "Systems/Base/EventSystem.hpp"
31
#include "Systems/Base/GraphicsSystem.hpp"
30
32
#include "Systems/Base/Surface.hpp"
33
#include "Systems/Base/System.hpp"
32
35
const int CURSOR_SIZE_INT = 32;
33
36
const Size CURSOR_SIZE = Size(CURSOR_SIZE_INT, CURSOR_SIZE_INT);
34
const Rect CURSOR_RECT = Rect(8, 8, CURSOR_SIZE);
36
38
const int HOTSPOTMASK_X_OFFSET = 8;
37
39
const int HOTSPOTMASK_Y_OFFSET = 48;
41
43
// -----------------------------------------------------------------------
42
44
// MouseCursor (public)
43
45
// -----------------------------------------------------------------------
44
MouseCursor::MouseCursor(const boost::shared_ptr<Surface>& cursor_surface)
45
: cursor_surface_(cursor_surface) {
46
MouseCursor::MouseCursor(
48
const boost::shared_ptr<const Surface>& cursor_surface,
52
cursor_surface_(cursor_surface),
54
frame_speed_(speed / count_),
56
last_time_frame_incremented_(system.event().getTicks()) {
57
// TODO(erg): Technically, each frame might have a hotspot. In practice, the
58
// hotspot is in the same place every frame.
48
61
int alphaR, alphaG, alphaB;
49
62
cursor_surface->getDCPixel(Point(0, 0), alphaR, alphaG, alphaB);
52
cursor_surface->clipAsColorMask(CURSOR_RECT, alphaR, alphaG, alphaB);
64
cursor_surface_ = cursor_surface->clipAsColorMask(
65
Rect(8, 8, Size(CURSOR_SIZE_INT * count_, CURSOR_SIZE_INT)),
66
alphaR, alphaG, alphaB);
55
69
MouseCursor::~MouseCursor() {}
71
void MouseCursor::execute(System& system) {
72
unsigned int cur_time = system.event().getTicks();
74
if (last_time_frame_incremented_ + frame_speed_ < cur_time) {
75
last_time_frame_incremented_ = cur_time;
77
system.graphics().markScreenAsDirty(GUT_MOUSE_MOTION);
80
if (current_frame_ >= count_)
57
85
void MouseCursor::renderHotspotAt(const Point& mouse_location) {
58
86
Point render_point = getTopLeftForHotspotAt(mouse_location);
59
87
cursor_surface_->renderToScreen(
60
Rect(0, 0, CURSOR_SIZE),
88
Rect(current_frame_ * CURSOR_SIZE_INT, 0, CURSOR_SIZE),
61
89
Rect(render_point, CURSOR_SIZE));
92
// -----------------------------------------------------------------------
93
// MouseCursor (private)
94
// -----------------------------------------------------------------------
64
96
Point MouseCursor::getTopLeftForHotspotAt(const Point& mouse_location) {
65
97
return mouse_location - hotspot_offset_;
68
// -----------------------------------------------------------------------
69
// MouseCursor (private)
70
// -----------------------------------------------------------------------
72
100
void MouseCursor::findHotspot() {