about summary refs log tree commit diff stats
path: root/src/subway_map.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/subway_map.cpp')
-rw-r--r--src/subway_map.cpp89
1 files changed, 89 insertions, 0 deletions
diff --git a/src/subway_map.cpp b/src/subway_map.cpp new file mode 100644 index 0000000..c58b2d1 --- /dev/null +++ b/src/subway_map.cpp
@@ -0,0 +1,89 @@
1#include "subway_map.h"
2
3#include "game_data.h"
4#include "global.h"
5#include "tracker_state.h"
6
7constexpr int AREA_ACTUAL_SIZE = 21;
8
9SubwayMap::SubwayMap(wxWindow *parent) : wxPanel(parent, wxID_ANY) {
10 map_image_ =
11 wxImage(GetAbsolutePath("assets/subway.png").c_str(), wxBITMAP_TYPE_PNG);
12 if (!map_image_.IsOk()) {
13 return;
14 }
15
16 Redraw();
17 Resize();
18
19 Bind(wxEVT_PAINT, &SubwayMap::OnPaint, this);
20 Bind(wxEVT_MOTION, &SubwayMap::OnMouseMove, this);
21}
22
23void SubwayMap::UpdateIndicators() {
24 Redraw();
25 Resize();
26}
27
28void SubwayMap::OnPaint(wxPaintEvent &event) {
29 if (GetSize() != resized_.GetSize()) {
30 Resize();
31 }
32
33 wxPaintDC dc(this);
34 dc.DrawBitmap(resized_, 0, 0);
35
36 event.Skip();
37}
38
39void SubwayMap::OnMouseMove(wxMouseEvent &event) {
40 event.Skip();
41}
42
43void 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();
68 wxSize image_size = rendered_.GetSize();
69
70 render_x_ = 0;
71 render_y_ = 0;
72 render_width_ = panel_size.GetWidth();
73 render_height_ = panel_size.GetHeight();
74
75 if (image_size.GetWidth() * panel_size.GetHeight() >
76 panel_size.GetWidth() * image_size.GetHeight()) {
77 render_height_ = (panel_size.GetWidth() * image_size.GetHeight()) /
78 image_size.GetWidth();
79 render_y_ = (panel_size.GetHeight() - render_height_) / 2;
80 } else {
81 render_width_ = (image_size.GetWidth() * panel_size.GetHeight()) /
82 image_size.GetHeight();
83 render_x_ = (panel_size.GetWidth() - render_width_) / 2;
84 }
85
86 resized_ = wxBitmap(rendered_.ConvertToImage()
87 .Scale(render_width_, render_height_, wxIMAGE_QUALITY_BILINEAR)
88 .Size(panel_size, {render_x_, render_y_}, 0, 0, 0));
89}