about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/area_popup.cpp118
-rw-r--r--src/area_popup.h11
-rw-r--r--src/eye_indicator.cpp51
-rw-r--r--src/eye_indicator.h30
-rw-r--r--src/tracker_panel.cpp10
5 files changed, 91 insertions, 129 deletions
diff --git a/src/area_popup.cpp b/src/area_popup.cpp index 6bbc0cf..8f694bb 100644 --- a/src/area_popup.cpp +++ b/src/area_popup.cpp
@@ -2,73 +2,113 @@
2 2
3#include "ap_state.h" 3#include "ap_state.h"
4#include "game_data.h" 4#include "game_data.h"
5#include "global.h"
5#include "tracker_config.h" 6#include "tracker_config.h"
6#include "tracker_state.h" 7#include "tracker_state.h"
7 8
8AreaPopup::AreaPopup(wxWindow* parent, int area_id) 9AreaPopup::AreaPopup(wxWindow* parent, int area_id)
9 : wxScrolledWindow(parent, wxID_ANY), area_id_(area_id) { 10 : wxScrolledCanvas(parent, wxID_ANY), area_id_(area_id) {
10 const MapArea& map_area = GD_GetMapArea(area_id); 11 unchecked_eye_ =
11 12 wxBitmap(wxImage(GetAbsolutePath("assets/unchecked.png").c_str(),
12 wxFlexGridSizer* section_sizer = new wxFlexGridSizer(2, 10, 10); 13 wxBITMAP_TYPE_PNG)
13 14 .Scale(32, 32));
14 for (const Location& location : map_area.locations) { 15 checked_eye_ = wxBitmap(
15 EyeIndicator* eye_indicator = new EyeIndicator(this); 16 wxImage(GetAbsolutePath("assets/checked.png").c_str(), wxBITMAP_TYPE_PNG)
16 section_sizer->Add(eye_indicator, wxSizerFlags().Expand()); 17 .Scale(32, 32));
17 eye_indicators_.push_back(eye_indicator);
18
19 wxStaticText* section_label = new wxStaticText(this, -1, location.name);
20 section_label->SetForegroundColour(*wxWHITE);
21 section_sizer->Add(
22 section_label,
23 wxSizerFlags().Align(wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL));
24 section_labels_.push_back(section_label);
25 }
26
27 wxBoxSizer* top_sizer = new wxBoxSizer(wxVERTICAL);
28
29 wxStaticText* top_label = new wxStaticText(this, -1, map_area.name);
30 top_label->SetForegroundColour(*wxWHITE);
31 top_label->SetFont(top_label->GetFont().Bold());
32 top_sizer->Add(top_label,
33 wxSizerFlags().Center().DoubleBorder(wxUP | wxLEFT | wxRIGHT));
34
35 top_sizer->Add(section_sizer, wxSizerFlags().DoubleBorder(wxALL).Expand());
36 18
37 SetSizerAndFit(top_sizer);
38 SetScrollRate(5, 5); 19 SetScrollRate(5, 5);
39 20
40 SetBackgroundColour(*wxBLACK); 21 SetBackgroundColour(*wxBLACK);
41 Hide(); 22 Hide();
23
24 Bind(wxEVT_PAINT, &AreaPopup::OnPaint, this);
25
26 UpdateIndicators();
42} 27}
43 28
44void AreaPopup::UpdateIndicators() { 29void AreaPopup::UpdateIndicators() {
45 const MapArea& map_area = GD_GetMapArea(area_id_); 30 const MapArea& map_area = GD_GetMapArea(area_id_);
31
32 // Start calculating extents.
33 wxMemoryDC mem_dc;
34 mem_dc.SetFont(GetFont().Bold());
35 wxSize header_extent = mem_dc.GetTextExtent(map_area.name);
36
37 int acc_height = header_extent.GetHeight() + 20;
38 int col_width = 0;
39
40 mem_dc.SetFont(GetFont());
41
42 std::vector<int> real_locations;
43
46 for (int section_id = 0; section_id < map_area.locations.size(); 44 for (int section_id = 0; section_id < map_area.locations.size();
47 section_id++) { 45 section_id++) {
48 const Location& location = map_area.locations.at(section_id); 46 const Location& location = map_area.locations.at(section_id);
49 wxSizer* container_sizer =
50 section_labels_[section_id]->GetContainingSizer();
51 47
52 if (!AP_IsLocationVisible(location.classification) && 48 if (!AP_IsLocationVisible(location.classification) &&
53 !(location.hunt && GetTrackerConfig().show_hunt_panels)) { 49 !(location.hunt && GetTrackerConfig().show_hunt_panels)) {
54 container_sizer->Hide(section_labels_[section_id]);
55 container_sizer->Hide(eye_indicators_[section_id]);
56 continue; 50 continue;
57 } else {
58 container_sizer->Show(section_labels_[section_id]);
59 container_sizer->Show(eye_indicators_[section_id]);
60 } 51 }
61 52
53 real_locations.push_back(section_id);
54
55 wxSize item_extent = mem_dc.GetTextExtent(location.name);
56 int item_height = std::max(32, item_extent.GetHeight()) + 10;
57 acc_height += item_height;
58
59 if (item_extent.GetWidth() > col_width) {
60 col_width = item_extent.GetWidth();
61 }
62 }
63
64 int item_width = col_width + 10 + 32;
65 int full_width = std::max(header_extent.GetWidth(), item_width) + 20;
66
67 SetVirtualSize(full_width, acc_height);
68
69 rendered_ = wxBitmap(full_width, acc_height);
70 mem_dc.SelectObject(rendered_);
71 mem_dc.SetPen(*wxTRANSPARENT_PEN);
72 mem_dc.SetBrush(*wxBLACK_BRUSH);
73 mem_dc.DrawRectangle({0, 0}, {full_width, acc_height});
74
75 mem_dc.SetFont(GetFont().Bold());
76 mem_dc.SetTextForeground(*wxWHITE);
77 mem_dc.DrawText(map_area.name,
78 {(full_width - header_extent.GetWidth()) / 2, 10});
79
80 int cur_height = header_extent.GetHeight() + 20;
81
82 mem_dc.SetFont(GetFont());
83
84 for (int section_id : real_locations) {
85 const Location& location = map_area.locations.at(section_id);
86
62 bool checked = 87 bool checked =
63 AP_HasCheckedGameLocation(location.ap_location_id) || 88 AP_HasCheckedGameLocation(location.ap_location_id) ||
64 (location.hunt && AP_HasCheckedHuntPanel(location.ap_location_id)); 89 (location.hunt && AP_HasCheckedHuntPanel(location.ap_location_id));
90
91 wxBitmap* eye_ptr = checked ? &checked_eye_ : &unchecked_eye_;
92
93 mem_dc.DrawBitmap(*eye_ptr, {10, cur_height});
94
65 bool reachable = IsLocationReachable(location.ap_location_id); 95 bool reachable = IsLocationReachable(location.ap_location_id);
66 const wxColour* text_color = reachable ? wxWHITE : wxRED; 96 const wxColour* text_color = reachable ? wxWHITE : wxRED;
97 mem_dc.SetTextForeground(*text_color);
67 98
68 section_labels_[section_id]->SetForegroundColour(*text_color); 99 wxSize item_extent = mem_dc.GetTextExtent(location.name);
69 eye_indicators_[section_id]->SetChecked(checked); 100 mem_dc.DrawText(
101 location.name,
102 {10 + 32 + 10, cur_height + (32 - mem_dc.GetFontMetrics().height) / 2});
103
104 cur_height += 10 + 32;
70 } 105 }
106}
107
108void AreaPopup::OnPaint(wxPaintEvent& event) {
109 wxPaintDC dc(this);
110 PrepareDC(dc);
111 dc.DrawBitmap(rendered_, 0, 0);
71 112
72 section_labels_[0]->GetContainingSizer()->Layout(); 113 event.Skip();
73 GetSizer()->Fit(this);
74} 114}
diff --git a/src/area_popup.h b/src/area_popup.h index d5f6a50..00c644d 100644 --- a/src/area_popup.h +++ b/src/area_popup.h
@@ -7,19 +7,20 @@
7#include <wx/wx.h> 7#include <wx/wx.h>
8#endif 8#endif
9 9
10#include "eye_indicator.h" 10class AreaPopup : public wxScrolledCanvas {
11
12class AreaPopup : public wxScrolledWindow {
13 public: 11 public:
14 AreaPopup(wxWindow* parent, int area_id); 12 AreaPopup(wxWindow* parent, int area_id);
15 13
16 void UpdateIndicators(); 14 void UpdateIndicators();
17 15
18 private: 16 private:
17 void OnPaint(wxPaintEvent& event);
18
19 int area_id_; 19 int area_id_;
20 20
21 std::vector<wxStaticText*> section_labels_; 21 wxBitmap unchecked_eye_;
22 std::vector<EyeIndicator*> eye_indicators_; 22 wxBitmap checked_eye_;
23 wxBitmap rendered_;
23}; 24};
24 25
25#endif /* end of include guard: AREA_POPUP_H_03FAC988 */ 26#endif /* end of include guard: AREA_POPUP_H_03FAC988 */
diff --git a/src/eye_indicator.cpp b/src/eye_indicator.cpp deleted file mode 100644 index 61ad780..0000000 --- a/src/eye_indicator.cpp +++ /dev/null
@@ -1,51 +0,0 @@
1#include "eye_indicator.h"
2
3#include "global.h"
4
5EyeIndicator::EyeIndicator(wxWindow* parent) : wxWindow(parent, wxID_ANY) {
6 SetMinSize({32, 32});
7
8 Redraw();
9
10 Bind(wxEVT_PAINT, &EyeIndicator::OnPaint, this);
11}
12
13void EyeIndicator::SetChecked(bool checked) {
14 if (intended_checked_ != checked) {
15 intended_checked_ = checked;
16
17 Redraw();
18 }
19}
20
21const wxImage& EyeIndicator::GetUncheckedImage() {
22 static wxImage* unchecked_image = new wxImage(
23 GetAbsolutePath("assets/unchecked.png").c_str(), wxBITMAP_TYPE_PNG);
24 return *unchecked_image;
25}
26
27const wxImage& EyeIndicator::GetCheckedImage() {
28 static wxImage* checked_image = new wxImage(
29 GetAbsolutePath("assets/checked.png").c_str(), wxBITMAP_TYPE_PNG);
30 return *checked_image;
31}
32
33void EyeIndicator::OnPaint(wxPaintEvent& event) {
34 if (GetSize() != rendered_.GetSize() ||
35 intended_checked_ != rendered_checked_) {
36 Redraw();
37 }
38
39 wxPaintDC dc(this);
40 dc.DrawBitmap(rendered_, 0, 0);
41
42 event.Skip();
43}
44
45void EyeIndicator::Redraw() {
46 rendered_ =
47 wxBitmap((intended_checked_ ? GetCheckedImage() : GetUncheckedImage())
48 .Scale(GetSize().GetWidth(), GetSize().GetHeight(),
49 wxIMAGE_QUALITY_NORMAL));
50 rendered_checked_ = intended_checked_;
51}
diff --git a/src/eye_indicator.h b/src/eye_indicator.h deleted file mode 100644 index e8fd890..0000000 --- a/src/eye_indicator.h +++ /dev/null
@@ -1,30 +0,0 @@
1#ifndef EYE_INDICATOR_H_778150F2
2#define EYE_INDICATOR_H_778150F2
3
4#include <wx/wxprec.h>
5
6#ifndef WX_PRECOMP
7#include <wx/wx.h>
8#endif
9
10class EyeIndicator : public wxWindow {
11 public:
12 EyeIndicator(wxWindow* parent);
13
14 void SetChecked(bool checked);
15
16 private:
17 static const wxImage& GetUncheckedImage();
18 static const wxImage& GetCheckedImage();
19
20 void OnPaint(wxPaintEvent& event);
21
22 void Redraw();
23
24 bool intended_checked_ = false;
25
26 wxBitmap rendered_;
27 bool rendered_checked_ = false;
28};
29
30#endif /* end of include guard: EYE_INDICATOR_H_778150F2 */
diff --git a/src/tracker_panel.cpp b/src/tracker_panel.cpp index 81cb595..3102110 100644 --- a/src/tracker_panel.cpp +++ b/src/tracker_panel.cpp
@@ -35,11 +35,11 @@ TrackerPanel::TrackerPanel(wxWindow *parent) : wxPanel(parent, wxID_ANY) {
35} 35}
36 36
37void TrackerPanel::UpdateIndicators() { 37void TrackerPanel::UpdateIndicators() {
38 Redraw();
39
40 for (AreaIndicator &area : areas_) { 38 for (AreaIndicator &area : areas_) {
41 area.popup->UpdateIndicators(); 39 area.popup->UpdateIndicators();
42 } 40 }
41
42 Redraw();
43} 43}
44 44
45void TrackerPanel::OnPaint(wxPaintEvent &event) { 45void TrackerPanel::OnPaint(wxPaintEvent &event) {
@@ -178,8 +178,10 @@ void TrackerPanel::Redraw() {
178 int popup_y = 178 int popup_y =
179 final_y + map_area.map_y * final_width / image_size.GetWidth(); 179 final_y + map_area.map_y * final_width / image_size.GetWidth();
180 180
181 area.popup->SetMaxSize(panel_size); 181 area.popup->SetClientSize(
182 area.popup->GetSizer()->Fit(area.popup); 182 area.popup->GetVirtualSize().GetWidth(),
183 std::min(panel_size.GetHeight(),
184 area.popup->GetVirtualSize().GetHeight()));
183 185
184 if (popup_x + area.popup->GetSize().GetWidth() > panel_size.GetWidth()) { 186 if (popup_x + area.popup->GetSize().GetWidth() > panel_size.GetWidth()) {
185 popup_x = panel_size.GetWidth() - area.popup->GetSize().GetWidth(); 187 popup_x = panel_size.GetWidth() - area.popup->GetSize().GetWidth();