aboutsummaryrefslogtreecommitdiff
path: root/ViewController.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-10-23 14:36:41 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-10-23 14:36:41 +0200
commit64028952ceb17f97ded08f1ab7ec0b06c41e2b87 (patch)
treef792377f93ff30a41a0c559c67aa874a022d4763 /ViewController.cpp
parente522f2a36ee00a3e0890adb2c34bfc8431711265 (diff)
add pathfinding start/end selection
Diffstat (limited to 'ViewController.cpp')
-rw-r--r--ViewController.cpp31
1 files changed, 29 insertions, 2 deletions
diff --git a/ViewController.cpp b/ViewController.cpp
index 989f11a..ec0315d 100644
--- a/ViewController.cpp
+++ b/ViewController.cpp
@@ -66,7 +66,28 @@ void ViewController::update_artists() {
}
}
+void ViewController::draw_pathfinding_dot(unsigned int x, unsigned int y, const Color & c) {
+ this->view.fill_rect(center({
+ .x = static_cast<float>(x * scale),
+ .y = static_cast<float>(y * scale),
+ .width = static_cast<float>(pathfinding_size),
+ .height = static_cast<float>(pathfinding_size),
+ }), c);
+}
+
void ViewController::update_pathfinding() {
+
+ PathfindingContext & ctx = this->museum.pathfinding;
+ this->draw_pathfinding_dot(ctx.get_end().first, ctx.get_end().second, {
+ .red = 0x00,
+ .green = 0x00,
+ .blue = 0xdd,
+ });
+ this->draw_pathfinding_dot(ctx.get_start().first, ctx.get_start().second, {
+ .red = 0xff,
+ .green = 0xff,
+ .blue = 0xff,
+ });
}
void ViewController::update_quadtree_recursive(QuadTreeCollisionChecker * tree) {
@@ -140,11 +161,11 @@ void ViewController::ev_mousedown(MouseCode button) {
try {
switch (button) {
case MOUSE_LEFT: {
- // TODO: pathfinding start point
+ this->museum.pathfinding.set_start(this->mouse_pos);
break;
}
case MOUSE_RIGHT: {
- // TODO: pathfinding end point
+ this->museum.pathfinding.set_end(this->mouse_pos);
break;
}
default: break;
@@ -161,3 +182,9 @@ void ViewController::ev_mousemove(unsigned x, unsigned y) {
};
}
+Rectangle ViewController::center(Rectangle rect) {
+ rect.x += (scale - rect.width) / 2;
+ rect.y += (scale - rect.height) / 2;
+ return rect;
+}
+