From 09d67fbad9df92caf2251d36b4abd7979fd27126 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Tue, 2 May 2023 17:26:46 -0400 Subject: Map + popups reflect checked locations --- eye_indicator.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 eye_indicator.cpp (limited to 'eye_indicator.cpp') diff --git a/eye_indicator.cpp b/eye_indicator.cpp new file mode 100644 index 0000000..c490589 --- /dev/null +++ b/eye_indicator.cpp @@ -0,0 +1,47 @@ +#include "eye_indicator.h" + +EyeIndicator::EyeIndicator(wxWindow* parent) : wxWindow(parent, wxID_ANY) { + SetMinSize({32, 32}); + + Redraw(); + + Bind(wxEVT_PAINT, &EyeIndicator::OnPaint, this); +} + +void EyeIndicator::SetChecked(bool checked) { + if (intended_checked_ != checked) { + intended_checked_ = checked; + + Redraw(); + } +} + +const wxImage& EyeIndicator::GetUncheckedImage() { + static wxImage* unchecked_image = + new wxImage("assets/unchecked.png", wxBITMAP_TYPE_PNG); + return *unchecked_image; +} + +const wxImage& EyeIndicator::GetCheckedImage() { + static wxImage* checked_image = + new wxImage("assets/checked.png", wxBITMAP_TYPE_PNG); + return *checked_image; +} + +void EyeIndicator::OnPaint(wxPaintEvent& event) { + if (GetSize() != rendered_.GetSize() || + intended_checked_ != rendered_checked_) { + Redraw(); + } + + wxPaintDC dc(this); + dc.DrawBitmap(rendered_, 0, 0); +} + +void EyeIndicator::Redraw() { + rendered_ = + wxBitmap((intended_checked_ ? GetCheckedImage() : GetUncheckedImage()) + .Scale(GetSize().GetWidth(), GetSize().GetHeight(), + wxIMAGE_QUALITY_NORMAL)); + rendered_checked_ = intended_checked_; +} -- cgit 1.4.1