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 | |
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')
-rw-r--r-- | src/subway_map.cpp | 31 | ||||
-rw-r--r-- | src/subway_map.h | 4 |
2 files changed, 28 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), |
diff --git a/src/subway_map.h b/src/subway_map.h index 9b0b43f..e891058 100644 --- a/src/subway_map.h +++ b/src/subway_map.h | |||
@@ -32,6 +32,7 @@ class SubwayMap : public wxPanel { | |||
32 | void OnMouseScroll(wxMouseEvent &event); | 32 | void OnMouseScroll(wxMouseEvent &event); |
33 | void OnMouseLeave(wxMouseEvent &event); | 33 | void OnMouseLeave(wxMouseEvent &event); |
34 | void OnTimer(wxTimerEvent &event); | 34 | void OnTimer(wxTimerEvent &event); |
35 | void OnZoomSlide(wxCommandEvent &event); | ||
35 | 36 | ||
36 | void Redraw(); | 37 | void Redraw(); |
37 | 38 | ||
@@ -41,6 +42,7 @@ class SubwayMap : public wxPanel { | |||
41 | 42 | ||
42 | void SetZoomPos(wxPoint pos); | 43 | void SetZoomPos(wxPoint pos); |
43 | void SetScrollSpeed(int scroll_x, int scroll_y); | 44 | void SetScrollSpeed(int scroll_x, int scroll_y); |
45 | void SetZoom(double zoom, wxPoint static_point); | ||
44 | 46 | ||
45 | wxImage map_image_; | 47 | wxImage map_image_; |
46 | wxImage owl_image_; | 48 | wxImage owl_image_; |
@@ -61,6 +63,8 @@ class SubwayMap : public wxPanel { | |||
61 | int scroll_x_ = 0; | 63 | int scroll_x_ = 0; |
62 | int scroll_y_ = 0; | 64 | int scroll_y_ = 0; |
63 | 65 | ||
66 | wxSlider *zoom_slider_; | ||
67 | |||
64 | struct GetItemBox { | 68 | struct GetItemBox { |
65 | quadtree::Box<float> operator()(const int &id) const; | 69 | quadtree::Box<float> operator()(const int &id) const; |
66 | }; | 70 | }; |