about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2024-05-12 18:08:12 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2024-05-12 18:08:12 -0400
commit00658b38bd65e2cb81a502bd72e98ad9c411a7b4 (patch)
treebf5a72fb47a17cb45640cdf773b807bdcb359170 /src
parentea16cff14ff4faf5782da8ff684a6ec412b7b6ac (diff)
downloadlingo-ap-tracker-00658b38bd65e2cb81a502bd72e98ad9c411a7b4.tar.gz
lingo-ap-tracker-00658b38bd65e2cb81a502bd72e98ad9c411a7b4.tar.bz2
lingo-ap-tracker-00658b38bd65e2cb81a502bd72e98ad9c411a7b4.zip
Higher quality + owl pictures
Diffstat (limited to 'src')
-rw-r--r--src/subway_map.cpp98
-rw-r--r--src/subway_map.h4
2 files changed, 68 insertions, 34 deletions
diff --git a/src/subway_map.cpp b/src/subway_map.cpp index c58b2d1..0aa7df3 100644 --- a/src/subway_map.cpp +++ b/src/subway_map.cpp
@@ -6,6 +6,12 @@
6 6
7constexpr int AREA_ACTUAL_SIZE = 21; 7constexpr int AREA_ACTUAL_SIZE = 21;
8 8
9enum class ItemDrawType {
10 kNone,
11 kBox,
12 kOwl
13};
14
9SubwayMap::SubwayMap(wxWindow *parent) : wxPanel(parent, wxID_ANY) { 15SubwayMap::SubwayMap(wxWindow *parent) : wxPanel(parent, wxID_ANY) {
10 map_image_ = 16 map_image_ =
11 wxImage(GetAbsolutePath("assets/subway.png").c_str(), wxBITMAP_TYPE_PNG); 17 wxImage(GetAbsolutePath("assets/subway.png").c_str(), wxBITMAP_TYPE_PNG);
@@ -13,8 +19,13 @@ SubwayMap::SubwayMap(wxWindow *parent) : wxPanel(parent, wxID_ANY) {
13 return; 19 return;
14 } 20 }
15 21
22 owl_image_ =
23 wxImage(GetAbsolutePath("assets/owl.png").c_str(), wxBITMAP_TYPE_PNG);
24 if (!owl_image_.IsOk()) {
25 return;
26 }
27
16 Redraw(); 28 Redraw();
17 Resize();
18 29
19 Bind(wxEVT_PAINT, &SubwayMap::OnPaint, this); 30 Bind(wxEVT_PAINT, &SubwayMap::OnPaint, this);
20 Bind(wxEVT_MOTION, &SubwayMap::OnMouseMove, this); 31 Bind(wxEVT_MOTION, &SubwayMap::OnMouseMove, this);
@@ -22,16 +33,15 @@ SubwayMap::SubwayMap(wxWindow *parent) : wxPanel(parent, wxID_ANY) {
22 33
23void SubwayMap::UpdateIndicators() { 34void SubwayMap::UpdateIndicators() {
24 Redraw(); 35 Redraw();
25 Resize();
26} 36}
27 37
28void SubwayMap::OnPaint(wxPaintEvent &event) { 38void SubwayMap::OnPaint(wxPaintEvent &event) {
29 if (GetSize() != resized_.GetSize()) { 39 if (GetSize() != rendered_.GetSize()) {
30 Resize(); 40 Redraw();
31 } 41 }
32 42
33 wxPaintDC dc(this); 43 wxPaintDC dc(this);
34 dc.DrawBitmap(resized_, 0, 0); 44 dc.DrawBitmap(rendered_, 0, 0);
35 45
36 event.Skip(); 46 event.Skip();
37} 47}
@@ -41,31 +51,8 @@ void SubwayMap::OnMouseMove(wxMouseEvent &event) {
41} 51}
42 52
43void SubwayMap::Redraw() { 53void SubwayMap::Redraw() {
44 rendered_ = wxBitmap(map_image_);
45
46 wxMemoryDC dc;
47 dc.SelectObject(rendered_);
48
49 for (const SubwayItem &subway_item : GD_GetSubwayItems()) {
50 const wxBrush *brush_color = wxGREY_BRUSH;
51 if (subway_item.door) {
52 if (IsDoorOpen(*subway_item.door)) {
53 brush_color = wxGREEN_BRUSH;
54 } else {
55 brush_color = wxRED_BRUSH;
56 }
57 }
58
59 dc.SetPen(*wxThePenList->FindOrCreatePen(*wxBLACK, 1));
60 dc.SetBrush(*brush_color);
61 dc.DrawRectangle({subway_item.x, subway_item.y},
62 {AREA_ACTUAL_SIZE, AREA_ACTUAL_SIZE});
63 }
64}
65
66void SubwayMap::Resize() {
67 wxSize panel_size = GetSize(); 54 wxSize panel_size = GetSize();
68 wxSize image_size = rendered_.GetSize(); 55 wxSize image_size = map_image_.GetSize();
69 56
70 render_x_ = 0; 57 render_x_ = 0;
71 render_y_ = 0; 58 render_y_ = 0;
@@ -75,15 +62,62 @@ void SubwayMap::Resize() {
75 if (image_size.GetWidth() * panel_size.GetHeight() > 62 if (image_size.GetWidth() * panel_size.GetHeight() >
76 panel_size.GetWidth() * image_size.GetHeight()) { 63 panel_size.GetWidth() * image_size.GetHeight()) {
77 render_height_ = (panel_size.GetWidth() * image_size.GetHeight()) / 64 render_height_ = (panel_size.GetWidth() * image_size.GetHeight()) /
78 image_size.GetWidth(); 65 image_size.GetWidth();
79 render_y_ = (panel_size.GetHeight() - render_height_) / 2; 66 render_y_ = (panel_size.GetHeight() - render_height_) / 2;
80 } else { 67 } else {
81 render_width_ = (image_size.GetWidth() * panel_size.GetHeight()) / 68 render_width_ = (image_size.GetWidth() * panel_size.GetHeight()) /
82 image_size.GetHeight(); 69 image_size.GetHeight();
83 render_x_ = (panel_size.GetWidth() - render_width_) / 2; 70 render_x_ = (panel_size.GetWidth() - render_width_) / 2;
84 } 71 }
85 72
86 resized_ = wxBitmap(rendered_.ConvertToImage() 73 rendered_ = wxBitmap(
74 map_image_
87 .Scale(render_width_, render_height_, wxIMAGE_QUALITY_BILINEAR) 75 .Scale(render_width_, render_height_, wxIMAGE_QUALITY_BILINEAR)
88 .Size(panel_size, {render_x_, render_y_}, 0, 0, 0)); 76 .Size(panel_size, {render_x_, render_y_}, 0, 0, 0));
77
78 wxMemoryDC dc;
79 dc.SelectObject(rendered_);
80
81 int real_area_size =
82 render_width_ * AREA_ACTUAL_SIZE / image_size.GetWidth();
83 if (real_area_size == 0) {
84 real_area_size = 1;
85 }
86 wxBitmap owl_bitmap = wxBitmap(owl_image_.Scale(
87 real_area_size * 1.25, real_area_size * 1.25, wxIMAGE_QUALITY_BILINEAR));
88
89 for (const SubwayItem &subway_item : GD_GetSubwayItems()) {
90 ItemDrawType draw_type = ItemDrawType::kNone;
91 const wxBrush *brush_color = wxGREY_BRUSH;
92
93 if (subway_item.door) {
94 draw_type = ItemDrawType::kBox;
95
96 if (IsDoorOpen(*subway_item.door)) {
97 if (!subway_item.paintings.empty()) {
98 draw_type = ItemDrawType::kOwl;
99 } else {
100 brush_color = wxGREEN_BRUSH;
101 }
102 } else {
103 brush_color = wxRED_BRUSH;
104 }
105 } else if (!subway_item.paintings.empty()) {
106 draw_type = ItemDrawType::kOwl;
107 }
108
109 int real_area_x =
110 render_x_ + subway_item.x * render_width_ / image_size.GetWidth();
111 int real_area_y =
112 render_y_ + subway_item.y * render_width_ / image_size.GetWidth();
113
114 if (draw_type == ItemDrawType::kBox) {
115 dc.SetPen(*wxThePenList->FindOrCreatePen(*wxBLACK, 1));
116 dc.SetBrush(*brush_color);
117 dc.DrawRectangle({real_area_x, real_area_y},
118 {real_area_size, real_area_size});
119 } else if (draw_type == ItemDrawType::kOwl) {
120 dc.DrawBitmap(owl_bitmap, {real_area_x, real_area_y});
121 }
122 }
89} 123}
diff --git a/src/subway_map.h b/src/subway_map.h index dc67867..e375750 100644 --- a/src/subway_map.h +++ b/src/subway_map.h
@@ -20,11 +20,11 @@ class SubwayMap : public wxPanel {
20 void OnMouseMove(wxMouseEvent &event); 20 void OnMouseMove(wxMouseEvent &event);
21 21
22 void Redraw(); 22 void Redraw();
23 void Resize();
24 23
25 wxImage map_image_; 24 wxImage map_image_;
25 wxImage owl_image_;
26
26 wxBitmap rendered_; 27 wxBitmap rendered_;
27 wxBitmap resized_;
28 int render_x_ = 0; 28 int render_x_ = 0;
29 int render_y_ = 0; 29 int render_y_ = 0;
30 int render_width_ = 0; 30 int render_width_ = 0;