diff --git a/ezgui/src/drawing.rs b/ezgui/src/drawing.rs index b4e8ad1613..37b78d46a3 100644 --- a/ezgui/src/drawing.rs +++ b/ezgui/src/drawing.rs @@ -1,7 +1,7 @@ use crate::widgets::ContextMenu; use crate::{ - text, Canvas, Color, EventCtx, HorizontalAlignment, Key, ScreenDims, ScreenPt, Text, - VerticalAlignment, + text, Canvas, Color, EventCtx, HorizontalAlignment, Key, ScreenDims, ScreenPt, ScreenRectangle, + Text, VerticalAlignment, }; use geom::{Bounds, Circle, Distance, Line, Polygon, Pt2D}; use glium::uniforms::{SamplerBehavior, SamplerWrapFunction, UniformValue}; @@ -203,6 +203,27 @@ impl<'a> GfxCtx<'a> { // println!("{:?}", backtrace::Backtrace::new()); } + pub fn redraw_clipped(&mut self, obj: &Drawable, rect: &ScreenRectangle) { + let mut params = self.params.clone(); + params.scissor = Some(glium::Rect { + left: rect.x1 as u32, + // Y-inversion + bottom: (self.canvas.window_height - rect.y2) as u32, + width: (rect.x2 - rect.x1) as u32, + height: (rect.y2 - rect.y1) as u32, + }); + self.target + .draw( + &obj.vertex_buffer, + &obj.index_buffer, + &self.program, + &self.uniforms, + ¶ms, + ) + .unwrap(); + self.num_draw_calls += 1; + } + // Canvas stuff. // The text box covers up what's beneath and eats the cursor (for get_cursor_in_map_space). diff --git a/game/src/common/minimap.rs b/game/src/common/minimap.rs index 1378820907..5b4c41f49d 100644 --- a/game/src/common/minimap.rs +++ b/game/src/common/minimap.rs @@ -40,14 +40,32 @@ impl Minimap { g.unfork(); // The map - g.fork(Pt2D::new(0.0, 0.0), top_left, 0.1); - g.redraw(&ui.primary.draw_map.draw_all_areas); - g.redraw(&ui.primary.draw_map.draw_all_thick_roads); - g.redraw(&ui.primary.draw_map.draw_all_unzoomed_intersections); - g.redraw(&ui.primary.draw_map.draw_all_buildings); + let padding = 10.0; + let inner_rect = ScreenRectangle { + x1: top_left.x + padding, + x2: top_left.x + square_len - padding, + y1: top_left.y + padding, + y2: top_left.y + square_len - padding, + }; + let bounds = ui.primary.map.get_bounds(); + // Fit the entire width of the map in the box, to start + let zoom = (square_len - (padding * 2.0)) / (bounds.max_x - bounds.min_x); + + g.fork( + Pt2D::new(0.0, 0.0), + ScreenPt::new(inner_rect.x1, inner_rect.y1), + zoom, + ); + g.redraw_clipped(&ui.primary.draw_map.boundary_polygon, &inner_rect); + g.redraw_clipped(&ui.primary.draw_map.draw_all_areas, &inner_rect); + g.redraw_clipped(&ui.primary.draw_map.draw_all_thick_roads, &inner_rect); + g.redraw_clipped( + &ui.primary.draw_map.draw_all_unzoomed_intersections, + &inner_rect, + ); + g.redraw_clipped(&ui.primary.draw_map.draw_all_buildings, &inner_rect); // The cursor - let bounds = ui.primary.map.get_bounds(); let (x1, y1) = { let pt = g.canvas.screen_to_map(ScreenPt::new(0.0, 0.0)); (