diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2024-05-19 11:48:34 -0400 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2024-05-19 11:48:34 -0400 |
commit | eaa21c53b96b945d8809dc5f4a9353ecaaacc266 (patch) | |
tree | f36d399002934d608945c6a0ab38d40c8bf0662c /src/subway_map.cpp | |
parent | e50107d0339000c48a955caab8b56d0d4fc56e84 (diff) | |
download | lingo-ap-tracker-eaa21c53b96b945d8809dc5f4a9353ecaaacc266.tar.gz lingo-ap-tracker-eaa21c53b96b945d8809dc5f4a9353ecaaacc266.tar.bz2 lingo-ap-tracker-eaa21c53b96b945d8809dc5f4a9353ecaaacc266.zip |
Zoom slider
Diffstat (limited to 'src/subway_map.cpp')
-rw-r--r-- | src/subway_map.cpp | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/src/subway_map.cpp b/src/subway_map.cpp index 47ebfdf..98d544c 100644 --- a/src/subway_map.cpp +++ b/src/subway_map.cpp | |||
@@ -54,6 +54,9 @@ SubwayMap::SubwayMap(wxWindow *parent) : wxPanel(parent, wxID_ANY) { | |||
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_TIMER, &SubwayMap::OnTimer, this); | 56 | Bind(wxEVT_TIMER, &SubwayMap::OnTimer, this); |
57 | |||
58 | zoom_slider_ = new wxSlider(this, wxID_ANY, 0, 0, 8, {15, 15}); | ||
59 | zoom_slider_->Bind(wxEVT_SLIDER, &SubwayMap::OnZoomSlide, this); | ||
57 | } | 60 | } |
58 | 61 | ||
59 | void SubwayMap::OnConnect() { | 62 | void SubwayMap::OnConnect() { |
@@ -381,13 +384,7 @@ void SubwayMap::OnMouseScroll(wxMouseEvent &event) { | |||
381 | } | 384 | } |
382 | 385 | ||
383 | if (zoom_ != new_zoom) { | 386 | if (zoom_ != new_zoom) { |
384 | wxPoint map_pos = RenderPosToMapPos(event.GetPosition()); | 387 | SetZoom(new_zoom, event.GetPosition()); |
385 | zoom_ = new_zoom; | ||
386 | |||
387 | wxPoint virtual_pos = MapPosToVirtualPos(map_pos); | ||
388 | SetZoomPos(-(virtual_pos - event.GetPosition())); | ||
389 | |||
390 | Refresh(); | ||
391 | } | 388 | } |
392 | 389 | ||
393 | event.Skip(); | 390 | event.Skip(); |
@@ -400,6 +397,14 @@ void SubwayMap::OnTimer(wxTimerEvent &event) { | |||
400 | Refresh(); | 397 | Refresh(); |
401 | } | 398 | } |
402 | 399 | ||
400 | void SubwayMap::OnZoomSlide(wxCommandEvent &event) { | ||
401 | double new_zoom = 1.0 + 0.25 * zoom_slider_->GetValue(); | ||
402 | |||
403 | if (new_zoom != zoom_) { | ||
404 | SetZoom(new_zoom, {GetSize().GetWidth() / 2, GetSize().GetHeight() / 2}); | ||
405 | } | ||
406 | } | ||
407 | |||
403 | void SubwayMap::Redraw() { | 408 | void SubwayMap::Redraw() { |
404 | rendered_ = wxBitmap(map_image_); | 409 | rendered_ = wxBitmap(map_image_); |
405 | 410 | ||
@@ -530,6 +535,18 @@ void SubwayMap::SetScrollSpeed(int scroll_x, int scroll_y) { | |||
530 | scroll_y_ = scroll_y; | 535 | scroll_y_ = scroll_y; |
531 | } | 536 | } |
532 | 537 | ||
538 | void SubwayMap::SetZoom(double zoom, wxPoint static_point) { | ||
539 | wxPoint map_pos = RenderPosToMapPos(static_point); | ||
540 | zoom_ = zoom; | ||
541 | |||
542 | wxPoint virtual_pos = MapPosToVirtualPos(map_pos); | ||
543 | SetZoomPos(-(virtual_pos - static_point)); | ||
544 | |||
545 | Refresh(); | ||
546 | |||
547 | zoom_slider_->SetValue((zoom - 1.0) / 0.25); | ||
548 | } | ||
549 | |||
533 | quadtree::Box<float> SubwayMap::GetItemBox::operator()(const int &id) const { | 550 | quadtree::Box<float> SubwayMap::GetItemBox::operator()(const int &id) const { |
534 | const SubwayItem &subway_item = GD_GetSubwayItem(id); | 551 | const SubwayItem &subway_item = GD_GetSubwayItem(id); |
535 | return {static_cast<float>(subway_item.x), static_cast<float>(subway_item.y), | 552 | return {static_cast<float>(subway_item.x), static_cast<float>(subway_item.y), |