diff options
Diffstat (limited to 'src/report_popup.cpp')
| -rw-r--r-- | src/report_popup.cpp | 98 |
1 files changed, 98 insertions, 0 deletions
| 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 @@ | |||
| 1 | #include "report_popup.h" | ||
| 2 | |||
| 3 | #include <wx/dcbuffer.h> | ||
| 4 | |||
| 5 | #include <map> | ||
| 6 | #include <string> | ||
| 7 | |||
| 8 | #include "global.h" | ||
| 9 | #include "tracker_state.h" | ||
| 10 | |||
| 11 | ReportPopup::ReportPopup(wxWindow* parent) | ||
| 12 | : wxScrolledCanvas(parent, wxID_ANY) { | ||
| 13 | SetBackgroundStyle(wxBG_STYLE_PAINT); | ||
| 14 | |||
| 15 | unchecked_eye_ = | ||
| 16 | wxBitmap(wxImage(GetAbsolutePath("assets/unchecked.png").c_str(), | ||
| 17 | wxBITMAP_TYPE_PNG) | ||
| 18 | .Scale(32, 32)); | ||
| 19 | checked_eye_ = wxBitmap( | ||
| 20 | wxImage(GetAbsolutePath("assets/checked.png").c_str(), wxBITMAP_TYPE_PNG) | ||
| 21 | .Scale(32, 32)); | ||
| 22 | |||
| 23 | SetScrollRate(5, 5); | ||
| 24 | |||
| 25 | SetBackgroundColour(*wxBLACK); | ||
| 26 | Hide(); | ||
| 27 | |||
| 28 | Bind(wxEVT_PAINT, &ReportPopup::OnPaint, this); | ||
| 29 | } | ||
| 30 | |||
| 31 | void ReportPopup::SetDoorId(int door_id) { | ||
| 32 | door_id_ = door_id; | ||
| 33 | |||
| 34 | UpdateIndicators(); | ||
| 35 | } | ||
| 36 | |||
| 37 | void ReportPopup::Reset() { | ||
| 38 | door_id_ = -1; | ||
| 39 | } | ||
| 40 | |||
| 41 | void ReportPopup::UpdateIndicators() { | ||
| 42 | wxMemoryDC mem_dc; | ||
| 43 | |||
| 44 | const std::map<std::string, bool>& report = GetDoorRequirements(door_id_); | ||
| 45 | |||
| 46 | int acc_height = 10; | ||
| 47 | int col_width = 0; | ||
| 48 | |||
| 49 | for (const auto& [text, obtained] : report) { | ||
| 50 | wxSize item_extent = mem_dc.GetTextExtent(text); | ||
| 51 | int item_height = std::max(32, item_extent.GetHeight()) + 10; | ||
| 52 | acc_height += item_height; | ||
| 53 | |||
| 54 | if (item_extent.GetWidth() > col_width) { | ||
| 55 | col_width = item_extent.GetWidth(); | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | int item_width = col_width + 10 + 32; | ||
| 60 | int full_width = item_width + 20; | ||
| 61 | |||
| 62 | Fit(); | ||
| 63 | SetVirtualSize(full_width, acc_height); | ||
| 64 | |||
| 65 | rendered_ = wxBitmap(full_width, acc_height); | ||
| 66 | mem_dc.SelectObject(rendered_); | ||
| 67 | mem_dc.SetPen(*wxTRANSPARENT_PEN); | ||
| 68 | mem_dc.SetBrush(*wxBLACK_BRUSH); | ||
| 69 | mem_dc.DrawRectangle({0, 0}, {full_width, acc_height}); | ||
| 70 | |||
| 71 | mem_dc.SetFont(GetFont()); | ||
| 72 | |||
| 73 | int cur_height = 10; | ||
| 74 | |||
| 75 | for (const auto& [text, obtained] : report) { | ||
| 76 | wxBitmap* eye_ptr = obtained ? &checked_eye_ : &unchecked_eye_; | ||
| 77 | |||
| 78 | mem_dc.DrawBitmap(*eye_ptr, wxPoint{10, cur_height}); | ||
| 79 | |||
| 80 | mem_dc.SetTextForeground(obtained ? *wxWHITE : *wxRED); | ||
| 81 | wxSize item_extent = mem_dc.GetTextExtent(text); | ||
| 82 | mem_dc.DrawText( | ||
| 83 | text, wxPoint{10 + 32 + 10, | ||
| 84 | cur_height + (32 - mem_dc.GetFontMetrics().height) / 2}); | ||
| 85 | |||
| 86 | cur_height += 10 + 32; | ||
| 87 | } | ||
| 88 | } | ||
| 89 | |||
| 90 | void ReportPopup::OnPaint(wxPaintEvent& event) { | ||
| 91 | if (door_id_ != -1) { | ||
| 92 | wxBufferedPaintDC dc(this); | ||
| 93 | PrepareDC(dc); | ||
| 94 | dc.DrawBitmap(rendered_, 0, 0); | ||
| 95 | } | ||
| 96 | |||
| 97 | event.Skip(); | ||
| 98 | } | ||
