diff options
Diffstat (limited to 'src/report_popup.cpp')
-rw-r--r-- | src/report_popup.cpp | 52 |
1 files changed, 35 insertions, 17 deletions
diff --git a/src/report_popup.cpp b/src/report_popup.cpp index d772b32..74216c3 100644 --- a/src/report_popup.cpp +++ b/src/report_popup.cpp | |||
@@ -12,20 +12,16 @@ ReportPopup::ReportPopup(wxWindow* parent) | |||
12 | : wxScrolledCanvas(parent, wxID_ANY) { | 12 | : wxScrolledCanvas(parent, wxID_ANY) { |
13 | SetBackgroundStyle(wxBG_STYLE_PAINT); | 13 | SetBackgroundStyle(wxBG_STYLE_PAINT); |
14 | 14 | ||
15 | unchecked_eye_ = | 15 | LoadIcons(); |
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 | 16 | ||
17 | // TODO: This is slow on high-DPI screens. | ||
23 | SetScrollRate(5, 5); | 18 | SetScrollRate(5, 5); |
24 | 19 | ||
25 | SetBackgroundColour(*wxBLACK); | 20 | SetBackgroundColour(*wxBLACK); |
26 | Hide(); | 21 | Hide(); |
27 | 22 | ||
28 | Bind(wxEVT_PAINT, &ReportPopup::OnPaint, this); | 23 | Bind(wxEVT_PAINT, &ReportPopup::OnPaint, this); |
24 | Bind(wxEVT_DPI_CHANGED, &ReportPopup::OnDPIChanged, this); | ||
29 | } | 25 | } |
30 | 26 | ||
31 | void ReportPopup::SetDoorId(int door_id) { | 27 | void ReportPopup::SetDoorId(int door_id) { |
@@ -41,14 +37,18 @@ void ReportPopup::Reset() { | |||
41 | void ReportPopup::UpdateIndicators() { | 37 | void ReportPopup::UpdateIndicators() { |
42 | wxMemoryDC mem_dc; | 38 | wxMemoryDC mem_dc; |
43 | 39 | ||
40 | wxFont the_font = GetFont().Scale(GetDPIScaleFactor()); | ||
41 | mem_dc.SetFont(the_font); | ||
42 | |||
44 | const std::map<std::string, bool>& report = GetDoorRequirements(door_id_); | 43 | const std::map<std::string, bool>& report = GetDoorRequirements(door_id_); |
45 | 44 | ||
46 | int acc_height = 10; | 45 | int acc_height = FromDIP(10); |
47 | int col_width = 0; | 46 | int col_width = 0; |
48 | 47 | ||
49 | for (const auto& [text, obtained] : report) { | 48 | for (const auto& [text, obtained] : report) { |
50 | wxSize item_extent = mem_dc.GetTextExtent(text); | 49 | wxSize item_extent = mem_dc.GetTextExtent(text); |
51 | int item_height = std::max(32, item_extent.GetHeight()) + 10; | 50 | int item_height = |
51 | std::max(FromDIP(32), item_extent.GetHeight()) + FromDIP(10); | ||
52 | acc_height += item_height; | 52 | acc_height += item_height; |
53 | 53 | ||
54 | if (item_extent.GetWidth() > col_width) { | 54 | if (item_extent.GetWidth() > col_width) { |
@@ -56,8 +56,8 @@ void ReportPopup::UpdateIndicators() { | |||
56 | } | 56 | } |
57 | } | 57 | } |
58 | 58 | ||
59 | int item_width = col_width + 10 + 32; | 59 | int item_width = col_width + FromDIP(10 + 32); |
60 | int full_width = item_width + 20; | 60 | int full_width = item_width + FromDIP(20); |
61 | 61 | ||
62 | Fit(); | 62 | Fit(); |
63 | SetVirtualSize(full_width, acc_height); | 63 | SetVirtualSize(full_width, acc_height); |
@@ -68,22 +68,23 @@ void ReportPopup::UpdateIndicators() { | |||
68 | mem_dc.SetBrush(*wxBLACK_BRUSH); | 68 | mem_dc.SetBrush(*wxBLACK_BRUSH); |
69 | mem_dc.DrawRectangle({0, 0}, {full_width, acc_height}); | 69 | mem_dc.DrawRectangle({0, 0}, {full_width, acc_height}); |
70 | 70 | ||
71 | mem_dc.SetFont(GetFont()); | 71 | mem_dc.SetFont(the_font); |
72 | 72 | ||
73 | int cur_height = 10; | 73 | int cur_height = FromDIP(10); |
74 | 74 | ||
75 | for (const auto& [text, obtained] : report) { | 75 | for (const auto& [text, obtained] : report) { |
76 | wxBitmap* eye_ptr = obtained ? &checked_eye_ : &unchecked_eye_; | 76 | wxBitmap* eye_ptr = obtained ? &checked_eye_ : &unchecked_eye_; |
77 | 77 | ||
78 | mem_dc.DrawBitmap(*eye_ptr, wxPoint{10, cur_height}); | 78 | mem_dc.DrawBitmap(*eye_ptr, wxPoint{FromDIP(10), cur_height}); |
79 | 79 | ||
80 | mem_dc.SetTextForeground(obtained ? *wxWHITE : *wxRED); | 80 | mem_dc.SetTextForeground(obtained ? *wxWHITE : *wxRED); |
81 | wxSize item_extent = mem_dc.GetTextExtent(text); | 81 | wxSize item_extent = mem_dc.GetTextExtent(text); |
82 | mem_dc.DrawText( | 82 | mem_dc.DrawText( |
83 | text, wxPoint{10 + 32 + 10, | 83 | text, wxPoint{FromDIP(10 + 32 + 10), |
84 | cur_height + (32 - mem_dc.GetFontMetrics().height) / 2}); | 84 | cur_height + |
85 | (FromDIP(32) - mem_dc.GetFontMetrics().height) / 2}); | ||
85 | 86 | ||
86 | cur_height += 10 + 32; | 87 | cur_height += FromDIP(10 + 32); |
87 | } | 88 | } |
88 | } | 89 | } |
89 | 90 | ||
@@ -96,3 +97,20 @@ void ReportPopup::OnPaint(wxPaintEvent& event) { | |||
96 | 97 | ||
97 | event.Skip(); | 98 | event.Skip(); |
98 | } | 99 | } |
100 | |||
101 | void ReportPopup::OnDPIChanged(wxDPIChangedEvent& event) { | ||
102 | LoadIcons(); | ||
103 | UpdateIndicators(); | ||
104 | } | ||
105 | |||
106 | void ReportPopup::LoadIcons() { | ||
107 | // TODO: We do not have to read these in and scale them for every single | ||
108 | // popup. | ||
109 | unchecked_eye_ = | ||
110 | wxBitmap(wxImage(GetAbsolutePath("assets/unchecked.png").c_str(), | ||
111 | wxBITMAP_TYPE_PNG) | ||
112 | .Scale(FromDIP(32), FromDIP(32))); | ||
113 | checked_eye_ = wxBitmap( | ||
114 | wxImage(GetAbsolutePath("assets/checked.png").c_str(), wxBITMAP_TYPE_PNG) | ||
115 | .Scale(FromDIP(32), FromDIP(32))); | ||
116 | } | ||