From 30f9e78cb30178834c420106c9f515c8358c4dbf Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Mon, 10 Mar 2025 13:05:10 -0400 Subject: Optimize ReportPopup refresh slightly It no longer resizes the window or vanishes if it is open during a refresh, and instead just redraws the image. --- src/report_popup.cpp | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'src/report_popup.cpp') diff --git a/src/report_popup.cpp b/src/report_popup.cpp index 674eea0..7ceef0d 100644 --- a/src/report_popup.cpp +++ b/src/report_popup.cpp @@ -28,21 +28,20 @@ ReportPopup::ReportPopup(wxWindow* parent) void ReportPopup::SetDoorId(int door_id) { door_id_ = door_id; - UpdateIndicators(); + ResetIndicators(); } void ReportPopup::Reset() { door_id_ = -1; } -void ReportPopup::UpdateIndicators() { - wxMemoryDC mem_dc; - +void ReportPopup::ResetIndicators() { wxFont the_font = GetFont().Scale(GetDPIScaleFactor()); - mem_dc.SetFont(the_font); - const std::map& report = GetDoorRequirements(door_id_); + wxMemoryDC mem_dc; + mem_dc.SetFont(the_font); + int acc_height = FromDIP(10); int col_width = 0; @@ -58,16 +57,26 @@ void ReportPopup::UpdateIndicators() { } int item_width = col_width + FromDIP(10 + 32); - int full_width = item_width + FromDIP(20); + full_width_ = item_width + FromDIP(20); + full_height_ = acc_height; Fit(); - SetVirtualSize(full_width, acc_height); + SetVirtualSize(full_width_, full_height_); - rendered_ = wxBitmap(full_width, acc_height); + UpdateIndicators(); +} + +void ReportPopup::UpdateIndicators() { + wxFont the_font = GetFont().Scale(GetDPIScaleFactor()); + const std::map& report = GetDoorRequirements(door_id_); + + rendered_ = wxBitmap(full_width_, full_height_); + + wxMemoryDC mem_dc; mem_dc.SelectObject(rendered_); mem_dc.SetPen(*wxTRANSPARENT_PEN); mem_dc.SetBrush(*wxBLACK_BRUSH); - mem_dc.DrawRectangle({0, 0}, {full_width, acc_height}); + mem_dc.DrawRectangle({0, 0}, {full_width_, full_height_}); mem_dc.SetFont(the_font); @@ -101,7 +110,7 @@ void ReportPopup::OnPaint(wxPaintEvent& event) { void ReportPopup::OnDPIChanged(wxDPIChangedEvent& event) { LoadIcons(); - UpdateIndicators(); + ResetIndicators(); event.Skip(); } -- cgit 1.4.1