diff options
Diffstat (limited to 'src/area_popup.cpp')
| -rw-r--r-- | src/area_popup.cpp | 68 |
1 files changed, 43 insertions, 25 deletions
| diff --git a/src/area_popup.cpp b/src/area_popup.cpp index 467a2bc..aabf20b 100644 --- a/src/area_popup.cpp +++ b/src/area_popup.cpp | |||
| @@ -15,20 +15,16 @@ AreaPopup::AreaPopup(wxWindow* parent, int area_id) | |||
| 15 | : wxScrolledCanvas(parent, wxID_ANY), area_id_(area_id) { | 15 | : wxScrolledCanvas(parent, wxID_ANY), area_id_(area_id) { |
| 16 | SetBackgroundStyle(wxBG_STYLE_PAINT); | 16 | SetBackgroundStyle(wxBG_STYLE_PAINT); |
| 17 | 17 | ||
| 18 | unchecked_eye_ = | 18 | LoadIcons(); |
| 19 | wxBitmap(wxImage(GetAbsolutePath("assets/unchecked.png").c_str(), | ||
| 20 | wxBITMAP_TYPE_PNG) | ||
| 21 | .Scale(32, 32)); | ||
| 22 | checked_eye_ = wxBitmap( | ||
| 23 | wxImage(GetAbsolutePath("assets/checked.png").c_str(), wxBITMAP_TYPE_PNG) | ||
| 24 | .Scale(32, 32)); | ||
| 25 | 19 | ||
| 20 | // TODO: This is slow on high-DPI screens. | ||
| 26 | SetScrollRate(5, 5); | 21 | SetScrollRate(5, 5); |
| 27 | 22 | ||
| 28 | SetBackgroundColour(*wxBLACK); | 23 | SetBackgroundColour(*wxBLACK); |
| 29 | Hide(); | 24 | Hide(); |
| 30 | 25 | ||
| 31 | Bind(wxEVT_PAINT, &AreaPopup::OnPaint, this); | 26 | Bind(wxEVT_PAINT, &AreaPopup::OnPaint, this); |
| 27 | Bind(wxEVT_DPI_CHANGED, &AreaPopup::OnDPIChanged, this); | ||
| 32 | 28 | ||
| 33 | UpdateIndicators(); | 29 | UpdateIndicators(); |
| 34 | } | 30 | } |
| @@ -36,15 +32,17 @@ AreaPopup::AreaPopup(wxWindow* parent, int area_id) | |||
| 36 | void AreaPopup::UpdateIndicators() { | 32 | void AreaPopup::UpdateIndicators() { |
| 37 | const MapArea& map_area = GD_GetMapArea(area_id_); | 33 | const MapArea& map_area = GD_GetMapArea(area_id_); |
| 38 | 34 | ||
| 35 | wxFont the_font = GetFont().Scale(GetDPIScaleFactor()); | ||
| 36 | |||
| 39 | // Start calculating extents. | 37 | // Start calculating extents. |
| 40 | wxMemoryDC mem_dc; | 38 | wxMemoryDC mem_dc; |
| 41 | mem_dc.SetFont(GetFont().Bold()); | 39 | mem_dc.SetFont(the_font.Bold()); |
| 42 | wxSize header_extent = mem_dc.GetTextExtent(map_area.name); | 40 | wxSize header_extent = mem_dc.GetTextExtent(map_area.name); |
| 43 | 41 | ||
| 44 | int acc_height = header_extent.GetHeight() + 20; | 42 | int acc_height = header_extent.GetHeight() + FromDIP(20); |
| 45 | int col_width = 0; | 43 | int col_width = 0; |
| 46 | 44 | ||
| 47 | mem_dc.SetFont(GetFont()); | 45 | mem_dc.SetFont(the_font); |
| 48 | 46 | ||
| 49 | TrackerPanel* tracker_panel = dynamic_cast<TrackerPanel*>(GetParent()); | 47 | TrackerPanel* tracker_panel = dynamic_cast<TrackerPanel*>(GetParent()); |
| 50 | 48 | ||
| @@ -68,7 +66,8 @@ void AreaPopup::UpdateIndicators() { | |||
| 68 | real_locations.push_back(section_id); | 66 | real_locations.push_back(section_id); |
| 69 | 67 | ||
| 70 | wxSize item_extent = mem_dc.GetTextExtent(location.name); | 68 | wxSize item_extent = mem_dc.GetTextExtent(location.name); |
| 71 | int item_height = std::max(32, item_extent.GetHeight()) + 10; | 69 | int item_height = |
| 70 | std::max(FromDIP(32), item_extent.GetHeight()) + FromDIP(10); | ||
| 72 | acc_height += item_height; | 71 | acc_height += item_height; |
| 73 | 72 | ||
| 74 | if (item_extent.GetWidth() > col_width) { | 73 | if (item_extent.GetWidth() > col_width) { |
| @@ -80,7 +79,8 @@ void AreaPopup::UpdateIndicators() { | |||
| 80 | for (int painting_id : map_area.paintings) { | 79 | for (int painting_id : map_area.paintings) { |
| 81 | const PaintingExit& painting = GD_GetPaintingExit(painting_id); | 80 | const PaintingExit& painting = GD_GetPaintingExit(painting_id); |
| 82 | wxSize item_extent = mem_dc.GetTextExtent(painting.display_name); | 81 | wxSize item_extent = mem_dc.GetTextExtent(painting.display_name); |
| 83 | int item_height = std::max(32, item_extent.GetHeight()) + 10; | 82 | int item_height = |
| 83 | std::max(FromDIP(32), item_extent.GetHeight()) + FromDIP(10); | ||
| 84 | acc_height += item_height; | 84 | acc_height += item_height; |
| 85 | 85 | ||
| 86 | if (item_extent.GetWidth() > col_width) { | 86 | if (item_extent.GetWidth() > col_width) { |
| @@ -89,8 +89,8 @@ void AreaPopup::UpdateIndicators() { | |||
| 89 | } | 89 | } |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | int item_width = col_width + 10 + 32; | 92 | int item_width = col_width + FromDIP(10 + 32); |
| 93 | int full_width = std::max(header_extent.GetWidth(), item_width) + 20; | 93 | int full_width = std::max(header_extent.GetWidth(), item_width) + FromDIP(20); |
| 94 | 94 | ||
| 95 | Fit(); | 95 | Fit(); |
| 96 | SetVirtualSize(full_width, acc_height); | 96 | SetVirtualSize(full_width, acc_height); |
| @@ -101,14 +101,14 @@ void AreaPopup::UpdateIndicators() { | |||
| 101 | mem_dc.SetBrush(*wxBLACK_BRUSH); | 101 | mem_dc.SetBrush(*wxBLACK_BRUSH); |
| 102 | mem_dc.DrawRectangle({0, 0}, {full_width, acc_height}); | 102 | mem_dc.DrawRectangle({0, 0}, {full_width, acc_height}); |
| 103 | 103 | ||
| 104 | mem_dc.SetFont(GetFont().Bold()); | 104 | mem_dc.SetFont(the_font.Bold()); |
| 105 | mem_dc.SetTextForeground(*wxWHITE); | 105 | mem_dc.SetTextForeground(*wxWHITE); |
| 106 | mem_dc.DrawText(map_area.name, | 106 | mem_dc.DrawText(map_area.name, |
| 107 | {(full_width - header_extent.GetWidth()) / 2, 10}); | 107 | {(full_width - header_extent.GetWidth()) / 2, FromDIP(10)}); |
| 108 | 108 | ||
| 109 | int cur_height = header_extent.GetHeight() + 20; | 109 | int cur_height = header_extent.GetHeight() + FromDIP(20); |
| 110 | 110 | ||
| 111 | mem_dc.SetFont(GetFont()); | 111 | mem_dc.SetFont(the_font); |
| 112 | 112 | ||
| 113 | for (int section_id : real_locations) { | 113 | for (int section_id : real_locations) { |
| 114 | const Location& location = map_area.locations.at(section_id); | 114 | const Location& location = map_area.locations.at(section_id); |
| @@ -131,7 +131,7 @@ void AreaPopup::UpdateIndicators() { | |||
| 131 | 131 | ||
| 132 | wxBitmap* eye_ptr = checked ? &checked_eye_ : &unchecked_eye_; | 132 | wxBitmap* eye_ptr = checked ? &checked_eye_ : &unchecked_eye_; |
| 133 | 133 | ||
| 134 | mem_dc.DrawBitmap(*eye_ptr, {10, cur_height}); | 134 | mem_dc.DrawBitmap(*eye_ptr, {FromDIP(10), cur_height}); |
| 135 | 135 | ||
| 136 | bool reachable = IsLocationReachable(location.ap_location_id); | 136 | bool reachable = IsLocationReachable(location.ap_location_id); |
| 137 | const wxColour* text_color = reachable ? wxWHITE : wxRED; | 137 | const wxColour* text_color = reachable ? wxWHITE : wxRED; |
| @@ -140,9 +140,10 @@ void AreaPopup::UpdateIndicators() { | |||
| 140 | wxSize item_extent = mem_dc.GetTextExtent(location.name); | 140 | wxSize item_extent = mem_dc.GetTextExtent(location.name); |
| 141 | mem_dc.DrawText( | 141 | mem_dc.DrawText( |
| 142 | location.name, | 142 | location.name, |
| 143 | {10 + 32 + 10, cur_height + (32 - mem_dc.GetFontMetrics().height) / 2}); | 143 | {FromDIP(10 + 32 + 10), |
| 144 | cur_height + (FromDIP(32) - mem_dc.GetFontMetrics().height) / 2}); | ||
| 144 | 145 | ||
| 145 | cur_height += 10 + 32; | 146 | cur_height += FromDIP(10 + 32); |
| 146 | } | 147 | } |
| 147 | 148 | ||
| 148 | if (AP_IsPaintingShuffle() && !tracker_panel->IsPanelsMode()) { | 149 | if (AP_IsPaintingShuffle() && !tracker_panel->IsPanelsMode()) { |
| @@ -155,14 +156,14 @@ void AreaPopup::UpdateIndicators() { | |||
| 155 | 156 | ||
| 156 | bool checked = reachable && AP_IsPaintingChecked(painting.internal_id); | 157 | bool checked = reachable && AP_IsPaintingChecked(painting.internal_id); |
| 157 | wxBitmap* eye_ptr = checked ? &checked_eye_ : &unchecked_eye_; | 158 | wxBitmap* eye_ptr = checked ? &checked_eye_ : &unchecked_eye_; |
| 158 | mem_dc.DrawBitmap(*eye_ptr, {10, cur_height}); | 159 | mem_dc.DrawBitmap(*eye_ptr, {FromDIP(10), cur_height}); |
| 159 | 160 | ||
| 160 | wxSize item_extent = mem_dc.GetTextExtent(painting.display_name); | 161 | wxSize item_extent = mem_dc.GetTextExtent(painting.display_name); |
| 161 | mem_dc.DrawText(painting.display_name, | 162 | mem_dc.DrawText(painting.display_name, |
| 162 | {10 + 32 + 10, | 163 | {FromDIP(10 + 32 + 10), |
| 163 | cur_height + (32 - mem_dc.GetFontMetrics().height) / 2}); | 164 | cur_height + (FromDIP(32) - mem_dc.GetFontMetrics().height) / 2}); |
| 164 | 165 | ||
| 165 | cur_height += 10 + 32; | 166 | cur_height += FromDIP(10 + 32); |
| 166 | } | 167 | } |
| 167 | } | 168 | } |
| 168 | } | 169 | } |
| @@ -174,3 +175,20 @@ void AreaPopup::OnPaint(wxPaintEvent& event) { | |||
| 174 | 175 | ||
| 175 | event.Skip(); | 176 | event.Skip(); |
| 176 | } | 177 | } |
| 178 | |||
| 179 | void AreaPopup::OnDPIChanged(wxDPIChangedEvent& event) { | ||
| 180 | LoadIcons(); | ||
| 181 | UpdateIndicators(); | ||
| 182 | } | ||
| 183 | |||
| 184 | void AreaPopup::LoadIcons() { | ||
| 185 | // TODO: We do not have to read these in and scale them for every single | ||
| 186 | // popup. | ||
| 187 | unchecked_eye_ = | ||
| 188 | wxBitmap(wxImage(GetAbsolutePath("assets/unchecked.png").c_str(), | ||
| 189 | wxBITMAP_TYPE_PNG) | ||
| 190 | .Scale(FromDIP(32), FromDIP(32))); | ||
| 191 | checked_eye_ = wxBitmap( | ||
| 192 | wxImage(GetAbsolutePath("assets/checked.png").c_str(), wxBITMAP_TYPE_PNG) | ||
| 193 | .Scale(FromDIP(32), FromDIP(32))); | ||
| 194 | } | ||
