From 712313d825db7ce7c9d4457f7564b27d3dd4ce64 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 8 Feb 2025 15:11:23 -0500 Subject: Added a scrollbar to subway reports --- src/report_popup.cpp | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 src/report_popup.cpp (limited to 'src/report_popup.cpp') diff --git a/src/report_popup.cpp b/src/report_popup.cpp new file mode 100644 index 0000000..d772b32 --- /dev/null +++ b/src/report_popup.cpp @@ -0,0 +1,98 @@ +#include "report_popup.h" + +#include + +#include +#include + +#include "global.h" +#include "tracker_state.h" + +ReportPopup::ReportPopup(wxWindow* parent) + : wxScrolledCanvas(parent, wxID_ANY) { + SetBackgroundStyle(wxBG_STYLE_PAINT); + + unchecked_eye_ = + wxBitmap(wxImage(GetAbsolutePath("assets/unchecked.png").c_str(), + wxBITMAP_TYPE_PNG) + .Scale(32, 32)); + checked_eye_ = wxBitmap( + wxImage(GetAbsolutePath("assets/checked.png").c_str(), wxBITMAP_TYPE_PNG) + .Scale(32, 32)); + + SetScrollRate(5, 5); + + SetBackgroundColour(*wxBLACK); + Hide(); + + Bind(wxEVT_PAINT, &ReportPopup::OnPaint, this); +} + +void ReportPopup::SetDoorId(int door_id) { + door_id_ = door_id; + + UpdateIndicators(); +} + +void ReportPopup::Reset() { + door_id_ = -1; +} + +void ReportPopup::UpdateIndicators() { + wxMemoryDC mem_dc; + + const std::map& report = GetDoorRequirements(door_id_); + + int acc_height = 10; + int col_width = 0; + + for (const auto& [text, obtained] : report) { + wxSize item_extent = mem_dc.GetTextExtent(text); + int item_height = std::max(32, item_extent.GetHeight()) + 10; + acc_height += item_height; + + if (item_extent.GetWidth() > col_width) { + col_width = item_extent.GetWidth(); + } + } + + int item_width = col_width + 10 + 32; + int full_width = item_width + 20; + + Fit(); + SetVirtualSize(full_width, acc_height); + + rendered_ = wxBitmap(full_width, acc_height); + 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.SetFont(GetFont()); + + int cur_height = 10; + + for (const auto& [text, obtained] : report) { + wxBitmap* eye_ptr = obtained ? &checked_eye_ : &unchecked_eye_; + + mem_dc.DrawBitmap(*eye_ptr, wxPoint{10, cur_height}); + + mem_dc.SetTextForeground(obtained ? *wxWHITE : *wxRED); + wxSize item_extent = mem_dc.GetTextExtent(text); + mem_dc.DrawText( + text, wxPoint{10 + 32 + 10, + cur_height + (32 - mem_dc.GetFontMetrics().height) / 2}); + + cur_height += 10 + 32; + } +} + +void ReportPopup::OnPaint(wxPaintEvent& event) { + if (door_id_ != -1) { + wxBufferedPaintDC dc(this); + PrepareDC(dc); + dc.DrawBitmap(rendered_, 0, 0); + } + + event.Skip(); +} -- cgit 1.4.1