about summary refs log tree commit diff stats
path: root/src/subway_map.cpp
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2024-05-19 11:48:34 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2024-05-19 11:48:34 -0400
commiteaa21c53b96b945d8809dc5f4a9353ecaaacc266 (patch)
treef36d399002934d608945c6a0ab38d40c8bf0662c /src/subway_map.cpp
parente50107d0339000c48a955caab8b56d0d4fc56e84 (diff)
downloadlingo-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.cpp31
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
59void SubwayMap::OnConnect() { 62void 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
400void 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
403void SubwayMap::Redraw() { 408void 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
538void 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
533quadtree::Box<float> SubwayMap::GetItemBox::operator()(const int &id) const { 550quadtree::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),