From f7530492119f94a83bdb85bb3887b50ddb5a6ffd Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Mon, 1 May 2023 19:12:45 -0400 Subject: Map image now has aspect ratio maintained --- tracker_panel.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'tracker_panel.cpp') diff --git a/tracker_panel.cpp b/tracker_panel.cpp index 74bf605..38d7c86 100644 --- a/tracker_panel.cpp +++ b/tracker_panel.cpp @@ -21,7 +21,26 @@ void TrackerPanel::OnPaint(wxPaintEvent &event) { } void TrackerPanel::Redraw() { - wxSize sz = GetSize(); + wxSize panel_size = GetSize(); + wxSize image_size = map_image_.GetSize(); + + int final_x = 0; + int final_y = 0; + int final_width = panel_size.GetWidth(); + int final_height = panel_size.GetHeight(); + + if (image_size.GetWidth() * panel_size.GetHeight() > + panel_size.GetWidth() * image_size.GetHeight()) { + final_height = (panel_size.GetWidth() * image_size.GetHeight()) / + image_size.GetWidth(); + final_y = (panel_size.GetHeight() - final_height) / 2; + } else { + final_width = (image_size.GetWidth() * panel_size.GetHeight()) / + image_size.GetHeight(); + final_x = (panel_size.GetWidth() - final_width) / 2; + } + rendered_ = wxBitmap( - map_image_.Scale(sz.GetWidth(), sz.GetHeight(), wxIMAGE_QUALITY_NORMAL)); + map_image_.Scale(final_width, final_height, wxIMAGE_QUALITY_NORMAL) + .Size(panel_size, {final_x, final_y}, 0, 0, 0)); } -- cgit 1.4.1