From 983f01cb8a2eaecd162e5734de88c461ef197b34 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sun, 19 May 2024 12:24:00 -0400 Subject: Zoom in/out menu items with keyboard shortcuts --- src/subway_map.cpp | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'src/subway_map.cpp') diff --git a/src/subway_map.cpp b/src/subway_map.cpp index 98d544c..69bf51b 100644 --- a/src/subway_map.cpp +++ b/src/subway_map.cpp @@ -119,6 +119,26 @@ void SubwayMap::UpdateSunwarp(SubwaySunwarp from_sunwarp, GD_GetSubwayItemForSunwarp(to_sunwarp)); } +void SubwayMap::Zoom(bool in) { + wxPoint focus_point; + + if (mouse_position_) { + focus_point = *mouse_position_; + } else { + focus_point = {GetSize().GetWidth() / 2, GetSize().GetHeight() / 2}; + } + + if (in) { + if (zoom_ < 3.0) { + SetZoom(zoom_ + 0.25, focus_point); + } + } else { + if (zoom_ > 1.0) { + SetZoom(zoom_ - 0.25, focus_point); + } + } +} + void SubwayMap::OnPaint(wxPaintEvent &event) { if (GetSize() != rendered_.GetSize()) { wxSize panel_size = GetSize(); @@ -372,6 +392,8 @@ void SubwayMap::OnMouseMove(wxMouseEvent &event) { SetScrollSpeed(scroll_x, scroll_y); + mouse_position_ = event.GetPosition(); + event.Skip(); } @@ -390,7 +412,10 @@ void SubwayMap::OnMouseScroll(wxMouseEvent &event) { event.Skip(); } -void SubwayMap::OnMouseLeave(wxMouseEvent &event) { SetScrollSpeed(0, 0); } +void SubwayMap::OnMouseLeave(wxMouseEvent &event) { + SetScrollSpeed(0, 0); + mouse_position_ = std::nullopt; +} void SubwayMap::OnTimer(wxTimerEvent &event) { SetZoomPos({zoom_x_ + scroll_x_, zoom_y_ + scroll_y_}); @@ -464,7 +489,8 @@ void SubwayMap::Redraw() { wxPoint real_area_pos = {subway_item.x, subway_item.y}; - int real_area_size = (draw_type == ItemDrawType::kOwl ? OWL_ACTUAL_SIZE : AREA_ACTUAL_SIZE); + int real_area_size = + (draw_type == ItemDrawType::kOwl ? OWL_ACTUAL_SIZE : AREA_ACTUAL_SIZE); if (draw_type == ItemDrawType::kBox) { dc.SetPen(*wxThePenList->FindOrCreatePen(*wxBLACK, 1)); -- cgit 1.4.1