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.cpp103
1 files changed, 69 insertions, 34 deletions
diff --git a/src/subway_map.cpp b/src/subway_map.cpp index b02c616..51f17c5 100644 --- a/src/subway_map.cpp +++ b/src/subway_map.cpp
@@ -117,13 +117,77 @@ void SubwayMap::UpdateSunwarp(SubwaySunwarp from_sunwarp,
117 117
118void SubwayMap::OnPaint(wxPaintEvent &event) { 118void SubwayMap::OnPaint(wxPaintEvent &event) {
119 if (GetSize() != rendered_.GetSize()) { 119 if (GetSize() != rendered_.GetSize()) {
120 Redraw(); 120 wxSize panel_size = GetSize();
121 wxSize image_size = map_image_.GetSize();
122
123 render_x_ = 0;
124 render_y_ = 0;
125 render_width_ = panel_size.GetWidth();
126 render_height_ = panel_size.GetHeight();
127
128 if (image_size.GetWidth() * panel_size.GetHeight() >
129 panel_size.GetWidth() * image_size.GetHeight()) {
130 render_height_ = (panel_size.GetWidth() * image_size.GetHeight()) /
131 image_size.GetWidth();
132 render_y_ = (panel_size.GetHeight() - render_height_) / 2;
133 } else {
134 render_width_ = (image_size.GetWidth() * panel_size.GetHeight()) /
135 image_size.GetHeight();
136 render_x_ = (panel_size.GetWidth() - render_width_) / 2;
137 }
138
139 SetZoomPos({zoom_x_, zoom_y_});
121 } 140 }
122 141
123 wxBufferedPaintDC dc(this); 142 wxBufferedPaintDC dc(this);
124 dc.SetBackground(*wxWHITE_BRUSH); 143 dc.SetBackground(*wxWHITE_BRUSH);
125 dc.Clear(); 144 dc.Clear();
126 dc.DrawBitmap(rendered_, zoom_x_, zoom_y_); 145
146 {
147 wxMemoryDC rendered_dc;
148 rendered_dc.SelectObject(rendered_);
149
150 int dst_x;
151 int dst_y;
152 int dst_w;
153 int dst_h;
154 int src_x;
155 int src_y;
156 int src_w;
157 int src_h;
158
159 int zoomed_width = render_width_ * zoom_;
160 int zoomed_height = render_height_ * zoom_;
161
162 if (zoomed_width <= GetSize().GetWidth()) {
163 dst_x = (GetSize().GetWidth() - zoomed_width) / 2;
164 dst_w = zoomed_width;
165 src_x = 0;
166 src_w = map_image_.GetWidth();
167 } else {
168 dst_x = 0;
169 dst_w = GetSize().GetWidth();
170 src_x = -zoom_x_ * map_image_.GetWidth() / render_width_ / zoom_;
171 src_w =
172 GetSize().GetWidth() * map_image_.GetWidth() / render_width_ / zoom_;
173 }
174
175 if (zoomed_height <= GetSize().GetHeight()) {
176 dst_y = (GetSize().GetHeight() - zoomed_height) / 2;
177 dst_h = zoomed_height;
178 src_y = 0;
179 src_h = map_image_.GetHeight();
180 } else {
181 dst_y = 0;
182 dst_h = GetSize().GetHeight();
183 src_y = -zoom_y_ * map_image_.GetWidth() / render_width_ / zoom_;
184 src_h =
185 GetSize().GetHeight() * map_image_.GetWidth() / render_width_ / zoom_;
186 }
187
188 dc.StretchBlit(dst_x, dst_y, dst_w, dst_h, &rendered_dc, src_x, src_y,
189 src_w, src_h);
190 }
127 191
128 if (hovered_item_) { 192 if (hovered_item_) {
129 const SubwayItem &subway_item = GD_GetSubwayItem(*hovered_item_); 193 const SubwayItem &subway_item = GD_GetSubwayItem(*hovered_item_);
@@ -320,7 +384,6 @@ void SubwayMap::OnMouseScroll(wxMouseEvent &event) {
320 wxPoint virtual_pos = MapPosToVirtualPos(map_pos); 384 wxPoint virtual_pos = MapPosToVirtualPos(map_pos);
321 SetZoomPos(-(virtual_pos - event.GetPosition())); 385 SetZoomPos(-(virtual_pos - event.GetPosition()));
322 386
323 Redraw();
324 Refresh(); 387 Refresh();
325 } 388 }
326 389
@@ -335,29 +398,7 @@ void SubwayMap::OnTimer(wxTimerEvent &event) {
335} 398}
336 399
337void SubwayMap::Redraw() { 400void SubwayMap::Redraw() {
338 wxSize panel_size = GetSize(); 401 rendered_ = wxBitmap(map_image_);
339 wxSize image_size = map_image_.GetSize();
340
341 render_x_ = 0;
342 render_y_ = 0;
343 render_width_ = panel_size.GetWidth();
344 render_height_ = panel_size.GetHeight();
345
346 if (image_size.GetWidth() * panel_size.GetHeight() >
347 panel_size.GetWidth() * image_size.GetHeight()) {
348 render_height_ = (panel_size.GetWidth() * image_size.GetHeight()) /
349 image_size.GetWidth();
350 render_y_ = (panel_size.GetHeight() - render_height_) / 2;
351 } else {
352 render_width_ = (image_size.GetWidth() * panel_size.GetHeight()) /
353 image_size.GetHeight();
354 render_x_ = (panel_size.GetWidth() - render_width_) / 2;
355 }
356
357 rendered_ = wxBitmap(map_image_.Scale(
358 render_width_ * zoom_, render_height_ * zoom_, wxIMAGE_QUALITY_BILINEAR));
359
360 SetZoomPos({zoom_x_, zoom_y_});
361 402
362 wxMemoryDC dc; 403 wxMemoryDC dc;
363 dc.SelectObject(rendered_); 404 dc.SelectObject(rendered_);
@@ -413,15 +454,9 @@ void SubwayMap::Redraw() {
413 } 454 }
414 } 455 }
415 456
416 wxPoint real_area_pos = MapPosToVirtualPos({subway_item.x, subway_item.y}); 457 wxPoint real_area_pos = {subway_item.x, subway_item.y};
417 458
418 int real_area_size = 459 int real_area_size = (draw_type == ItemDrawType::kOwl ? OWL_ACTUAL_SIZE : AREA_ACTUAL_SIZE);
419 render_width_ * zoom_ *
420 (draw_type == ItemDrawType::kOwl ? OWL_ACTUAL_SIZE : AREA_ACTUAL_SIZE) /
421 image_size.GetWidth();
422 if (real_area_size == 0) {
423 real_area_size = 1;
424 }
425 460
426 if (draw_type == ItemDrawType::kBox) { 461 if (draw_type == ItemDrawType::kBox) {
427 dc.SetPen(*wxThePenList->FindOrCreatePen(*wxBLACK, 1)); 462 dc.SetPen(*wxThePenList->FindOrCreatePen(*wxBLACK, 1));