mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-29 17:34:58 +03:00
add a bit of padding to the minimap, pick an initial zoom to fit the entire width, and clip using scissor test
This commit is contained in:
parent
082ae0cea1
commit
c0cfbde4ec
@ -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).
|
||||
|
@ -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));
|
||||
(
|
||||
|
Loading…
Reference in New Issue
Block a user