diff options
| -rw-r--r-- | CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/area_popup.cpp | 18 | ||||
| -rw-r--r-- | src/area_popup.h | 5 | ||||
| -rw-r--r-- | src/icons.cpp | 22 | ||||
| -rw-r--r-- | src/icons.h | 25 | ||||
| -rw-r--r-- | src/report_popup.cpp | 16 | ||||
| -rw-r--r-- | src/report_popup.h | 5 | ||||
| -rw-r--r-- | src/tracker_frame.cpp | 2 | ||||
| -rw-r--r-- | src/tracker_frame.h | 3 |
9 files changed, 72 insertions, 25 deletions
| diff --git a/CMakeLists.txt b/CMakeLists.txt index 50425dd..0929cd7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
| @@ -54,6 +54,7 @@ set(SOURCE_FILES | |||
| 54 | "src/ipc_dialog.cpp" | 54 | "src/ipc_dialog.cpp" |
| 55 | "src/report_popup.cpp" | 55 | "src/report_popup.cpp" |
| 56 | "src/updater.cpp" | 56 | "src/updater.cpp" |
| 57 | "src/icons.cpp" | ||
| 57 | "vendor/whereami/whereami.c" | 58 | "vendor/whereami/whereami.c" |
| 58 | ) | 59 | ) |
| 59 | 60 | ||
| diff --git a/src/area_popup.cpp b/src/area_popup.cpp index aabf20b..9cc1208 100644 --- a/src/area_popup.cpp +++ b/src/area_popup.cpp | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include "ap_state.h" | 7 | #include "ap_state.h" |
| 8 | #include "game_data.h" | 8 | #include "game_data.h" |
| 9 | #include "global.h" | 9 | #include "global.h" |
| 10 | #include "icons.h" | ||
| 10 | #include "tracker_config.h" | 11 | #include "tracker_config.h" |
| 11 | #include "tracker_panel.h" | 12 | #include "tracker_panel.h" |
| 12 | #include "tracker_state.h" | 13 | #include "tracker_state.h" |
| @@ -129,7 +130,7 @@ void AreaPopup::UpdateIndicators() { | |||
| 129 | (location.hunt && AP_HasCheckedHuntPanel(location.ap_location_id)); | 130 | (location.hunt && AP_HasCheckedHuntPanel(location.ap_location_id)); |
| 130 | } | 131 | } |
| 131 | 132 | ||
| 132 | wxBitmap* eye_ptr = checked ? &checked_eye_ : &unchecked_eye_; | 133 | const wxBitmap* eye_ptr = checked ? checked_eye_ : unchecked_eye_; |
| 133 | 134 | ||
| 134 | mem_dc.DrawBitmap(*eye_ptr, {FromDIP(10), cur_height}); | 135 | mem_dc.DrawBitmap(*eye_ptr, {FromDIP(10), cur_height}); |
| 135 | 136 | ||
| @@ -155,7 +156,7 @@ void AreaPopup::UpdateIndicators() { | |||
| 155 | mem_dc.SetTextForeground(*text_color); | 156 | mem_dc.SetTextForeground(*text_color); |
| 156 | 157 | ||
| 157 | bool checked = reachable && AP_IsPaintingChecked(painting.internal_id); | 158 | bool checked = reachable && AP_IsPaintingChecked(painting.internal_id); |
| 158 | wxBitmap* eye_ptr = checked ? &checked_eye_ : &unchecked_eye_; | 159 | const wxBitmap* eye_ptr = checked ? checked_eye_ : unchecked_eye_; |
| 159 | mem_dc.DrawBitmap(*eye_ptr, {FromDIP(10), cur_height}); | 160 | mem_dc.DrawBitmap(*eye_ptr, {FromDIP(10), cur_height}); |
| 160 | 161 | ||
| 161 | wxSize item_extent = mem_dc.GetTextExtent(painting.display_name); | 162 | wxSize item_extent = mem_dc.GetTextExtent(painting.display_name); |
| @@ -182,13 +183,8 @@ void AreaPopup::OnDPIChanged(wxDPIChangedEvent& event) { | |||
| 182 | } | 183 | } |
| 183 | 184 | ||
| 184 | void AreaPopup::LoadIcons() { | 185 | void AreaPopup::LoadIcons() { |
| 185 | // TODO: We do not have to read these in and scale them for every single | 186 | unchecked_eye_ = GetTheIconCache().GetIcon("assets/unchecked.png", |
| 186 | // popup. | 187 | FromDIP(wxSize{32, 32})); |
| 187 | unchecked_eye_ = | 188 | checked_eye_ = |
| 188 | wxBitmap(wxImage(GetAbsolutePath("assets/unchecked.png").c_str(), | 189 | GetTheIconCache().GetIcon("assets/checked.png", FromDIP(wxSize{32, 32})); |
| 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 | } | 190 | } |
| diff --git a/src/area_popup.h b/src/area_popup.h index 3326406..d2d50b9 100644 --- a/src/area_popup.h +++ b/src/area_popup.h | |||
| @@ -21,8 +21,9 @@ class AreaPopup : public wxScrolledCanvas { | |||
| 21 | 21 | ||
| 22 | int area_id_; | 22 | int area_id_; |
| 23 | 23 | ||
| 24 | wxBitmap unchecked_eye_; | 24 | const wxBitmap* unchecked_eye_; |
| 25 | wxBitmap checked_eye_; | 25 | const wxBitmap* checked_eye_; |
| 26 | |||
| 26 | wxBitmap rendered_; | 27 | wxBitmap rendered_; |
| 27 | }; | 28 | }; |
| 28 | 29 | ||
| diff --git a/src/icons.cpp b/src/icons.cpp new file mode 100644 index 0000000..87ba037 --- /dev/null +++ b/src/icons.cpp | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | #include "icons.h" | ||
| 2 | |||
| 3 | #include "global.h" | ||
| 4 | |||
| 5 | const wxBitmap* IconCache::GetIcon(const std::string& filename, wxSize size) { | ||
| 6 | std::tuple<std::string, int, int> key = {filename, size.x, size.y}; | ||
| 7 | |||
| 8 | if (!icons_.count(key)) { | ||
| 9 | icons_[key] = | ||
| 10 | wxBitmap(wxImage(GetAbsolutePath(filename).c_str(), | ||
| 11 | wxBITMAP_TYPE_PNG) | ||
| 12 | .Scale(size.x, size.y)); | ||
| 13 | } | ||
| 14 | |||
| 15 | return &icons_.at(key); | ||
| 16 | } | ||
| 17 | |||
| 18 | static IconCache* ICON_CACHE_INSTANCE = nullptr; | ||
| 19 | |||
| 20 | void SetTheIconCache(IconCache* instance) { ICON_CACHE_INSTANCE = instance; } | ||
| 21 | |||
| 22 | IconCache& GetTheIconCache() { return *ICON_CACHE_INSTANCE; } | ||
| diff --git a/src/icons.h b/src/icons.h new file mode 100644 index 0000000..23dca2a --- /dev/null +++ b/src/icons.h | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | #ifndef ICONS_H_B95159A6 | ||
| 2 | #define ICONS_H_B95159A6 | ||
| 3 | |||
| 4 | #include <wx/wxprec.h> | ||
| 5 | |||
| 6 | #ifndef WX_PRECOMP | ||
| 7 | #include <wx/wx.h> | ||
| 8 | #endif | ||
| 9 | |||
| 10 | #include <map> | ||
| 11 | #include <string> | ||
| 12 | #include <tuple> | ||
| 13 | |||
| 14 | class IconCache { | ||
| 15 | public: | ||
| 16 | const wxBitmap* GetIcon(const std::string& filename, wxSize size); | ||
| 17 | |||
| 18 | private: | ||
| 19 | std::map<std::tuple<std::string, int, int>, wxBitmap> icons_; | ||
| 20 | }; | ||
| 21 | |||
| 22 | void SetTheIconCache(IconCache* instance); | ||
| 23 | IconCache& GetTheIconCache(); | ||
| 24 | |||
| 25 | #endif /* end of include guard: ICONS_H_B95159A6 */ | ||
| diff --git a/src/report_popup.cpp b/src/report_popup.cpp index 74216c3..cf5b086 100644 --- a/src/report_popup.cpp +++ b/src/report_popup.cpp | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | #include <string> | 6 | #include <string> |
| 7 | 7 | ||
| 8 | #include "global.h" | 8 | #include "global.h" |
| 9 | #include "icons.h" | ||
| 9 | #include "tracker_state.h" | 10 | #include "tracker_state.h" |
| 10 | 11 | ||
| 11 | ReportPopup::ReportPopup(wxWindow* parent) | 12 | ReportPopup::ReportPopup(wxWindow* parent) |
| @@ -73,7 +74,7 @@ void ReportPopup::UpdateIndicators() { | |||
| 73 | int cur_height = FromDIP(10); | 74 | int cur_height = FromDIP(10); |
| 74 | 75 | ||
| 75 | for (const auto& [text, obtained] : report) { | 76 | for (const auto& [text, obtained] : report) { |
| 76 | wxBitmap* eye_ptr = obtained ? &checked_eye_ : &unchecked_eye_; | 77 | const wxBitmap* eye_ptr = obtained ? checked_eye_ : unchecked_eye_; |
| 77 | 78 | ||
| 78 | mem_dc.DrawBitmap(*eye_ptr, wxPoint{FromDIP(10), cur_height}); | 79 | mem_dc.DrawBitmap(*eye_ptr, wxPoint{FromDIP(10), cur_height}); |
| 79 | 80 | ||
| @@ -104,13 +105,8 @@ void ReportPopup::OnDPIChanged(wxDPIChangedEvent& event) { | |||
| 104 | } | 105 | } |
| 105 | 106 | ||
| 106 | void ReportPopup::LoadIcons() { | 107 | void ReportPopup::LoadIcons() { |
| 107 | // TODO: We do not have to read these in and scale them for every single | 108 | unchecked_eye_ = GetTheIconCache().GetIcon("assets/unchecked.png", |
| 108 | // popup. | 109 | FromDIP(wxSize{32, 32})); |
| 109 | unchecked_eye_ = | 110 | checked_eye_ = |
| 110 | wxBitmap(wxImage(GetAbsolutePath("assets/unchecked.png").c_str(), | 111 | GetTheIconCache().GetIcon("assets/checked.png", FromDIP(wxSize{32, 32})); |
| 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 | } | 112 | } |
| diff --git a/src/report_popup.h b/src/report_popup.h index 4ccc913..2da9b73 100644 --- a/src/report_popup.h +++ b/src/report_popup.h | |||
| @@ -25,8 +25,9 @@ class ReportPopup : public wxScrolledCanvas { | |||
| 25 | 25 | ||
| 26 | int door_id_ = -1; | 26 | int door_id_ = -1; |
| 27 | 27 | ||
| 28 | wxBitmap unchecked_eye_; | 28 | const wxBitmap* unchecked_eye_; |
| 29 | wxBitmap checked_eye_; | 29 | const wxBitmap* checked_eye_; |
| 30 | |||
| 30 | wxBitmap rendered_; | 31 | wxBitmap rendered_; |
| 31 | }; | 32 | }; |
| 32 | 33 | ||
| diff --git a/src/tracker_frame.cpp b/src/tracker_frame.cpp index abc413d..a1bd23e 100644 --- a/src/tracker_frame.cpp +++ b/src/tracker_frame.cpp | |||
| @@ -63,6 +63,8 @@ TrackerFrame::TrackerFrame() | |||
| 63 | AP_SetTrackerFrame(this); | 63 | AP_SetTrackerFrame(this); |
| 64 | IPC_SetTrackerFrame(this); | 64 | IPC_SetTrackerFrame(this); |
| 65 | 65 | ||
| 66 | SetTheIconCache(&icons_); | ||
| 67 | |||
| 66 | updater_ = std::make_unique<Updater>(this); | 68 | updater_ = std::make_unique<Updater>(this); |
| 67 | updater_->Cleanup(); | 69 | updater_->Cleanup(); |
| 68 | 70 | ||
| diff --git a/src/tracker_frame.h b/src/tracker_frame.h index 76c071f..9aff0a5 100644 --- a/src/tracker_frame.h +++ b/src/tracker_frame.h | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | 9 | ||
| 10 | #include <memory> | 10 | #include <memory> |
| 11 | 11 | ||
| 12 | #include "icons.h" | ||
| 12 | #include "updater.h" | 13 | #include "updater.h" |
| 13 | 14 | ||
| 14 | class AchievementsPane; | 15 | class AchievementsPane; |
| @@ -94,6 +95,8 @@ class TrackerFrame : public wxFrame { | |||
| 94 | 95 | ||
| 95 | wxMenuItem *zoom_in_menu_item_; | 96 | wxMenuItem *zoom_in_menu_item_; |
| 96 | wxMenuItem *zoom_out_menu_item_; | 97 | wxMenuItem *zoom_out_menu_item_; |
| 98 | |||
| 99 | IconCache icons_; | ||
| 97 | }; | 100 | }; |
| 98 | 101 | ||
| 99 | #endif /* end of include guard: TRACKER_FRAME_H_86BD8DFB */ | 102 | #endif /* end of include guard: TRACKER_FRAME_H_86BD8DFB */ |
