diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2024-06-06 11:09:15 -0400 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2024-06-06 11:09:15 -0400 |
commit | f9d209b21596e5aac09a7743385065803749f6a0 (patch) | |
tree | b5465072c5aadeebc4e6b8b0b189e04eea83b9a1 /src/subway_map.cpp | |
parent | 13d2a129f6972e6e752da9c9cb686a63d5550517 (diff) | |
download | lingo-ap-tracker-f9d209b21596e5aac09a7743385065803749f6a0.tar.gz lingo-ap-tracker-f9d209b21596e5aac09a7743385065803749f6a0.tar.bz2 lingo-ap-tracker-f9d209b21596e5aac09a7743385065803749f6a0.zip |
Subway: Click to activate scroll / sticky popup
Diffstat (limited to 'src/subway_map.cpp')
-rw-r--r-- | src/subway_map.cpp | 97 |
1 files changed, 68 insertions, 29 deletions
diff --git a/src/subway_map.cpp b/src/subway_map.cpp index 9175514..77f6ae6 100644 --- a/src/subway_map.cpp +++ b/src/subway_map.cpp | |||
@@ -53,6 +53,7 @@ SubwayMap::SubwayMap(wxWindow *parent) : wxPanel(parent, wxID_ANY) { | |||
53 | Bind(wxEVT_MOTION, &SubwayMap::OnMouseMove, this); | 53 | Bind(wxEVT_MOTION, &SubwayMap::OnMouseMove, this); |
54 | Bind(wxEVT_MOUSEWHEEL, &SubwayMap::OnMouseScroll, this); | 54 | Bind(wxEVT_MOUSEWHEEL, &SubwayMap::OnMouseScroll, this); |
55 | Bind(wxEVT_LEAVE_WINDOW, &SubwayMap::OnMouseLeave, this); | 55 | Bind(wxEVT_LEAVE_WINDOW, &SubwayMap::OnMouseLeave, this); |
56 | Bind(wxEVT_LEFT_DOWN, &SubwayMap::OnMouseClick, this); | ||
56 | Bind(wxEVT_TIMER, &SubwayMap::OnTimer, this); | 57 | Bind(wxEVT_TIMER, &SubwayMap::OnTimer, this); |
57 | 58 | ||
58 | zoom_slider_ = new wxSlider(this, wxID_ANY, 0, 0, 8, {15, 15}); | 59 | zoom_slider_ = new wxSlider(this, wxID_ANY, 0, 0, 8, {15, 15}); |
@@ -216,6 +217,8 @@ void SubwayMap::OnPaint(wxPaintEvent &event) { | |||
216 | } | 217 | } |
217 | 218 | ||
218 | if (hovered_item_) { | 219 | if (hovered_item_) { |
220 | // Note that these requirements are duplicated on OnMouseClick so that it | ||
221 | // knows when an item has a hover effect. | ||
219 | const SubwayItem &subway_item = GD_GetSubwayItem(*hovered_item_); | 222 | const SubwayItem &subway_item = GD_GetSubwayItem(*hovered_item_); |
220 | if (subway_item.door && !GetDoorRequirements(*subway_item.door).empty()) { | 223 | if (subway_item.door && !GetDoorRequirements(*subway_item.door).empty()) { |
221 | const std::map<std::string, bool> &report = | 224 | const std::map<std::string, bool> &report = |
@@ -354,44 +357,22 @@ void SubwayMap::OnMouseMove(wxMouseEvent &event) { | |||
354 | 357 | ||
355 | std::vector<int> hovered = tree_->query( | 358 | std::vector<int> hovered = tree_->query( |
356 | {static_cast<float>(mouse_pos.x), static_cast<float>(mouse_pos.y), 2, 2}); | 359 | {static_cast<float>(mouse_pos.x), static_cast<float>(mouse_pos.y), 2, 2}); |
357 | std::optional<int> new_hovered_item; | ||
358 | if (!hovered.empty()) { | 360 | if (!hovered.empty()) { |
359 | new_hovered_item = hovered[0]; | 361 | actual_hover_= hovered[0]; |
362 | } else { | ||
363 | actual_hover_ = std::nullopt; | ||
360 | } | 364 | } |
361 | 365 | ||
362 | if (new_hovered_item != hovered_item_) { | 366 | if (!sticky_hover_ && actual_hover_ != hovered_item_) { |
363 | hovered_item_ = new_hovered_item; | 367 | hovered_item_ = actual_hover_; |
364 | 368 | ||
365 | Refresh(); | 369 | Refresh(); |
366 | } | 370 | } |
367 | 371 | ||
368 | int scroll_x; | 372 | if (scroll_mode_) { |
369 | int scroll_y; | 373 | EvaluateScroll(event.GetPosition()); |
370 | if (event.GetPosition().x < GetSize().GetWidth() / 9) { | ||
371 | scroll_x = 20; | ||
372 | } else if (event.GetPosition().x < GetSize().GetWidth() / 6) { | ||
373 | scroll_x = 5; | ||
374 | } else if (event.GetPosition().x > 8 * GetSize().GetWidth() / 9) { | ||
375 | scroll_x = -20; | ||
376 | } else if (event.GetPosition().x > 5 * GetSize().GetWidth() / 6) { | ||
377 | scroll_x = -5; | ||
378 | } else { | ||
379 | scroll_x = 0; | ||
380 | } | ||
381 | if (event.GetPosition().y < GetSize().GetHeight() / 9) { | ||
382 | scroll_y = 20; | ||
383 | } else if (event.GetPosition().y < GetSize().GetHeight() / 6) { | ||
384 | scroll_y = 5; | ||
385 | } else if (event.GetPosition().y > 8 * GetSize().GetHeight() / 9) { | ||
386 | scroll_y = -20; | ||
387 | } else if (event.GetPosition().y > 5 * GetSize().GetHeight() / 6) { | ||
388 | scroll_y = -5; | ||
389 | } else { | ||
390 | scroll_y = 0; | ||
391 | } | 374 | } |
392 | 375 | ||
393 | SetScrollSpeed(scroll_x, scroll_y); | ||
394 | |||
395 | mouse_position_ = event.GetPosition(); | 376 | mouse_position_ = event.GetPosition(); |
396 | 377 | ||
397 | event.Skip(); | 378 | event.Skip(); |
@@ -417,6 +398,35 @@ void SubwayMap::OnMouseLeave(wxMouseEvent &event) { | |||
417 | mouse_position_ = std::nullopt; | 398 | mouse_position_ = std::nullopt; |
418 | } | 399 | } |
419 | 400 | ||
401 | void SubwayMap::OnMouseClick(wxMouseEvent &event) { | ||
402 | if (sticky_hover_) { | ||
403 | sticky_hover_ = false; | ||
404 | |||
405 | if (actual_hover_ != hovered_item_) { | ||
406 | hovered_item_ = actual_hover_; | ||
407 | |||
408 | Refresh(); | ||
409 | } | ||
410 | } else if (hovered_item_) { | ||
411 | const SubwayItem &subway_item = GD_GetSubwayItem(*hovered_item_); | ||
412 | if ((subway_item.door && !GetDoorRequirements(*subway_item.door).empty()) || | ||
413 | networks_.IsItemInNetwork(*hovered_item_)) { | ||
414 | sticky_hover_ = true; | ||
415 | } | ||
416 | } else if (scroll_mode_) { | ||
417 | scroll_mode_ = false; | ||
418 | |||
419 | SetScrollSpeed(0, 0); | ||
420 | } else if (event.GetPosition().x < GetSize().GetWidth() / 6 || | ||
421 | event.GetPosition().x > 5 * GetSize().GetWidth() / 6 || | ||
422 | event.GetPosition().y < GetSize().GetHeight() / 6 || | ||
423 | event.GetPosition().y > 5 * GetSize().GetHeight() / 6) { | ||
424 | scroll_mode_ = true; | ||
425 | |||
426 | EvaluateScroll(event.GetPosition()); | ||
427 | } | ||
428 | } | ||
429 | |||
420 | void SubwayMap::OnTimer(wxTimerEvent &event) { | 430 | void SubwayMap::OnTimer(wxTimerEvent &event) { |
421 | SetZoomPos({zoom_x_ + scroll_x_, zoom_y_ + scroll_y_}); | 431 | SetZoomPos({zoom_x_ + scroll_x_, zoom_y_ + scroll_y_}); |
422 | Refresh(); | 432 | Refresh(); |
@@ -504,6 +514,35 @@ void SubwayMap::Redraw() { | |||
504 | } | 514 | } |
505 | } | 515 | } |
506 | 516 | ||
517 | void SubwayMap::EvaluateScroll(wxPoint pos) { | ||
518 | int scroll_x; | ||
519 | int scroll_y; | ||
520 | if (pos.x < GetSize().GetWidth() / 9) { | ||
521 | scroll_x = 20; | ||
522 | } else if (pos.x < GetSize().GetWidth() / 6) { | ||
523 | scroll_x = 5; | ||
524 | } else if (pos.x > 8 * GetSize().GetWidth() / 9) { | ||
525 | scroll_x = -20; | ||
526 | } else if (pos.x > 5 * GetSize().GetWidth() / 6) { | ||
527 | scroll_x = -5; | ||
528 | } else { | ||
529 | scroll_x = 0; | ||
530 | } | ||
531 | if (pos.y < GetSize().GetHeight() / 9) { | ||
532 | scroll_y = 20; | ||
533 | } else if (pos.y < GetSize().GetHeight() / 6) { | ||
534 | scroll_y = 5; | ||
535 | } else if (pos.y > 8 * GetSize().GetHeight() / 9) { | ||
536 | scroll_y = -20; | ||
537 | } else if (pos.y > 5 * GetSize().GetHeight() / 6) { | ||
538 | scroll_y = -5; | ||
539 | } else { | ||
540 | scroll_y = 0; | ||
541 | } | ||
542 | |||
543 | SetScrollSpeed(scroll_x, scroll_y); | ||
544 | } | ||
545 | |||
507 | wxPoint SubwayMap::MapPosToRenderPos(wxPoint pos) const { | 546 | wxPoint SubwayMap::MapPosToRenderPos(wxPoint pos) const { |
508 | return {static_cast<int>(pos.x * render_width_ * zoom_ / | 547 | return {static_cast<int>(pos.x * render_width_ * zoom_ / |
509 | map_image_.GetSize().GetWidth() + | 548 | map_image_.GetSize().GetWidth() + |