-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathReticle.cpp
49 lines (40 loc) · 1.06 KB
/
Reticle.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
//
// Reticle.cpp
//
// Engine includes.
#include "DisplayManager.h"
#include "EventMouse.h"
#include "WorldManager.h"
// Game includes.
#include "Reticle.h"
Reticle::Reticle() {
setType("Reticle");
setSolidness(df::SPECTRAL);
setAltitude(df::MAX_ALTITUDE); // Make Reticle in the foreground.
// Reticle moves with mouse, so register.
#ifdef DF_REGISTER_INTEREST
registerInterest(df::MSE_EVENT);
#endif
// Start reticle in center of window.
df::Vector p(40, 12);
setPosition(p);
}
// Handle event.
// Return 0 if ignored, else 1.
int Reticle::eventHandler(const df::Event *p_e) {
if (p_e->getType() == df::MSE_EVENT) {
const df::EventMouse *p_mouse_event = dynamic_cast <const df::EventMouse *> (p_e);
if (p_mouse_event->getMouseAction() == df::MOVED) {
// Change location to new mouse position.
setPosition(p_mouse_event->getMousePosition());
return 1;
}
}
// If get here, have ignored this event.
return 0;
}
// Draw reticle on window.
int Reticle::draw() {
DM.drawCh(getPosition(), RETICLE_CHAR, df::RED);
return 0;
}