From 00658b38bd65e2cb81a502bd72e98ad9c411a7b4 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sun, 12 May 2024 18:08:12 -0400 Subject: Higher quality + owl pictures --- src/subway_map.cpp | 98 ++++++++++++++++++++++++++++++++++++------------------ src/subway_map.h | 4 +-- 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 @@ constexpr int AREA_ACTUAL_SIZE = 21; +enum class ItemDrawType { + kNone, + kBox, + kOwl +}; + SubwayMap::SubwayMap(wxWindow *parent) : wxPanel(parent, wxID_ANY) { map_image_ = wxImage(GetAbsolutePath("assets/subway.png").c_str(), wxBITMAP_TYPE_PNG); @@ -13,8 +19,13 @@ SubwayMap::SubwayMap(wxWindow *parent) : wxPanel(parent, wxID_ANY) { return; } + owl_image_ = + wxImage(GetAbsolutePath("assets/owl.png").c_str(), wxBITMAP_TYPE_PNG); + if (!owl_image_.IsOk()) { + return; + } + Redraw(); - Resize(); Bind(wxEVT_PAINT, &SubwayMap::OnPaint, this); Bind(wxEVT_MOTION, &SubwayMap::OnMouseMove, this); @@ -22,16 +33,15 @@ SubwayMap::SubwayMap(wxWindow *parent) : wxPanel(parent, wxID_ANY) { void SubwayMap::UpdateIndicators() { Redraw(); - Resize(); } void SubwayMap::OnPaint(wxPaintEvent &event) { - if (GetSize() != resized_.GetSize()) { - Resize(); + if (GetSize() != rendered_.GetSize()) { + Redraw(); } wxPaintDC dc(this); - dc.DrawBitmap(resized_, 0, 0); + dc.DrawBitmap(rendered_, 0, 0); event.Skip(); } @@ -41,31 +51,8 @@ void SubwayMap::OnMouseMove(wxMouseEvent &event) { } void SubwayMap::Redraw() { - rendered_ = wxBitmap(map_image_); - - wxMemoryDC dc; - dc.SelectObject(rendered_); - - for (const SubwayItem &subway_item : GD_GetSubwayItems()) { - const wxBrush *brush_color = wxGREY_BRUSH; - if (subway_item.door) { - if (IsDoorOpen(*subway_item.door)) { - brush_color = wxGREEN_BRUSH; - } else { - brush_color = wxRED_BRUSH; - } - } - - dc.SetPen(*wxThePenList->FindOrCreatePen(*wxBLACK, 1)); - dc.SetBrush(*brush_color); - dc.DrawRectangle({subway_item.x, subway_item.y}, - {AREA_ACTUAL_SIZE, AREA_ACTUAL_SIZE}); - } -} - -void SubwayMap::Resize() { wxSize panel_size = GetSize(); - wxSize image_size = rendered_.GetSize(); + wxSize image_size = map_image_.GetSize(); render_x_ = 0; render_y_ = 0; @@ -75,15 +62,62 @@ void SubwayMap::Resize() { if (image_size.GetWidth() * panel_size.GetHeight() > panel_size.GetWidth() * image_size.GetHeight()) { render_height_ = (panel_size.GetWidth() * image_size.GetHeight()) / - image_size.GetWidth(); + image_size.GetWidth(); render_y_ = (panel_size.GetHeight() - render_height_) / 2; } else { render_width_ = (image_size.GetWidth() * panel_size.GetHeight()) / - image_size.GetHeight(); + image_size.GetHeight(); render_x_ = (panel_size.GetWidth() - render_width_) / 2; } - resized_ = wxBitmap(rendered_.ConvertToImage() + rendered_ = wxBitmap( + map_image_ .Scale(render_width_, render_height_, wxIMAGE_QUALITY_BILINEAR) .Size(panel_size, {render_x_, render_y_}, 0, 0, 0)); + + wxMemoryDC dc; + dc.SelectObject(rendered_); + + int real_area_size = + render_width_ * AREA_ACTUAL_SIZE / image_size.GetWidth(); + if (real_area_size == 0) { + real_area_size = 1; + } + wxBitmap owl_bitmap = wxBitmap(owl_image_.Scale( + real_area_size * 1.25, real_area_size * 1.25, wxIMAGE_QUALITY_BILINEAR)); + + for (const SubwayItem &subway_item : GD_GetSubwayItems()) { + ItemDrawType draw_type = ItemDrawType::kNone; + const wxBrush *brush_color = wxGREY_BRUSH; + + if (subway_item.door) { + draw_type = ItemDrawType::kBox; + + if (IsDoorOpen(*subway_item.door)) { + if (!subway_item.paintings.empty()) { + draw_type = ItemDrawType::kOwl; + } else { + brush_color = wxGREEN_BRUSH; + } + } else { + brush_color = wxRED_BRUSH; + } + } else if (!subway_item.paintings.empty()) { + draw_type = ItemDrawType::kOwl; + } + + int real_area_x = + render_x_ + subway_item.x * render_width_ / image_size.GetWidth(); + int real_area_y = + render_y_ + subway_item.y * render_width_ / image_size.GetWidth(); + + if (draw_type == ItemDrawType::kBox) { + dc.SetPen(*wxThePenList->FindOrCreatePen(*wxBLACK, 1)); + dc.SetBrush(*brush_color); + dc.DrawRectangle({real_area_x, real_area_y}, + {real_area_size, real_area_size}); + } else if (draw_type == ItemDrawType::kOwl) { + dc.DrawBitmap(owl_bitmap, {real_area_x, real_area_y}); + } + } } 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 { void OnMouseMove(wxMouseEvent &event); void Redraw(); - void Resize(); wxImage map_image_; + wxImage owl_image_; + wxBitmap rendered_; - wxBitmap resized_; int render_x_ = 0; int render_y_ = 0; int render_width_ = 0; -- cgit 1.4.1