-
Notifications
You must be signed in to change notification settings - Fork 1
/
Cursor.cpp
56 lines (48 loc) · 1.47 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
#include "Cursor.hpp"
#include "Renderer.hpp"
#include "Spritesheet.hpp"
namespace TappyPlane {
using namespace SDLW::Video;
using namespace SDLW::Events;
constexpr Size normalCursorSize{146, 149};
constexpr Size pressedCursorSize{223, 222};
Cursor::Cursor()
: mNormalSourceBounds(Spritesheet::instance().sourceBounds("cursorNormal"))
, mPressedSourceBounds(
Spritesheet::instance().sourceBounds("cursorPressed"))
, mNormalSize(normalCursorSize)
, mPressedSize(pressedCursorSize)
{
Mouse::ActiveCursor::hide();
}
void Cursor::handleEvent(const Event& event)
{
switch (event.type()) {
case Event::Type::MouseButtonDown:
mIsPressed = true;
break;
case Event::Type::MouseButtonUp:
mIsPressed = false;
break;
case Event::Type::MouseMotion:
mPosition = {event.mouseMotionEvent().x(),
event.mouseMotionEvent().y()};
break;
default:
break;
}
}
void Cursor::draw() const
{
if (mIsPressed) {
auto position = mPosition;
position.setX(position.x() - mNormalSize.width() / 2);
position.setY(position.y() - mNormalSize.height() / 2);
Renderer::instance().copy(Spritesheet::instance().texture(),
mPressedSourceBounds, Rectangle{position, mPressedSize});
} else {
Renderer::instance().copy(Spritesheet::instance().texture(),
mNormalSourceBounds, Rectangle{mPosition, mNormalSize});
}
}
} // namespace TappyPlane