mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-01 02:33:54 +03:00
force showing full detail when screencapping at low zoom
This commit is contained in:
parent
dbfc1ec0d2
commit
299f05e0a2
@ -4,7 +4,7 @@ use ezgui::ToggleableLayer;
|
|||||||
|
|
||||||
// TODO ideally these would be tuned kind of dynamically based on rendering speed
|
// TODO ideally these would be tuned kind of dynamically based on rendering speed
|
||||||
const MIN_ZOOM_FOR_LANES: f64 = 0.15;
|
const MIN_ZOOM_FOR_LANES: f64 = 0.15;
|
||||||
const MIN_ZOOM_FOR_PARCE: f64 = 1.0;
|
const MIN_ZOOM_FOR_PARCELS: f64 = 1.0;
|
||||||
|
|
||||||
pub struct ToggleableLayers {
|
pub struct ToggleableLayers {
|
||||||
pub show_lanes: ToggleableLayer,
|
pub show_lanes: ToggleableLayer,
|
||||||
@ -23,7 +23,7 @@ impl ToggleableLayers {
|
|||||||
show_lanes: ToggleableLayer::new("lanes", Some(MIN_ZOOM_FOR_LANES)),
|
show_lanes: ToggleableLayer::new("lanes", Some(MIN_ZOOM_FOR_LANES)),
|
||||||
show_buildings: ToggleableLayer::new("buildings", Some(0.0)),
|
show_buildings: ToggleableLayer::new("buildings", Some(0.0)),
|
||||||
show_intersections: ToggleableLayer::new("intersections", Some(MIN_ZOOM_FOR_LANES)),
|
show_intersections: ToggleableLayer::new("intersections", Some(MIN_ZOOM_FOR_LANES)),
|
||||||
show_parcels: ToggleableLayer::new("parcels", Some(MIN_ZOOM_FOR_PARCE)),
|
show_parcels: ToggleableLayer::new("parcels", Some(MIN_ZOOM_FOR_PARCELS)),
|
||||||
show_extra_shapes: ToggleableLayer::new("extra shapes", Some(MIN_ZOOM_FOR_LANES)),
|
show_extra_shapes: ToggleableLayer::new("extra shapes", Some(MIN_ZOOM_FOR_LANES)),
|
||||||
show_all_turn_icons: ToggleableLayer::new("all turn icons", None),
|
show_all_turn_icons: ToggleableLayer::new("all turn icons", None),
|
||||||
show_areas: ToggleableLayer::new("areas", None),
|
show_areas: ToggleableLayer::new("areas", None),
|
||||||
|
@ -70,7 +70,7 @@ impl Renderable for DrawIntersection {
|
|||||||
ctx.canvas
|
ctx.canvas
|
||||||
.draw_text_at(g, Text::from_line(format!("{}", idx + 1)), *pt);
|
.draw_text_at(g, Text::from_line(format!("{}", idx + 1)), *pt);
|
||||||
}
|
}
|
||||||
} else if ctx.canvas.cam_zoom >= MIN_ZOOM_FOR_MARKINGS {
|
} else if ctx.canvas.cam_zoom >= MIN_ZOOM_FOR_MARKINGS || opts.show_all_detail {
|
||||||
for corner in &self.sidewalk_corners {
|
for corner in &self.sidewalk_corners {
|
||||||
g.draw_polygon(opts.color.unwrap_or_else(|| ctx.cs.get("sidewalk")), corner);
|
g.draw_polygon(opts.color.unwrap_or_else(|| ctx.cs.get("sidewalk")), corner);
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ impl Renderable for DrawLane {
|
|||||||
});
|
});
|
||||||
g.draw_polygon(color, &self.polygon);
|
g.draw_polygon(color, &self.polygon);
|
||||||
|
|
||||||
if ctx.canvas.cam_zoom >= MIN_ZOOM_FOR_MARKINGS {
|
if ctx.canvas.cam_zoom >= MIN_ZOOM_FOR_MARKINGS || opts.show_all_detail {
|
||||||
for m in &self.markings {
|
for m in &self.markings {
|
||||||
m(g, ctx.cs);
|
m(g, ctx.cs);
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,7 @@ pub struct RenderOptions {
|
|||||||
// TODO This should be accessible through ctx...
|
// TODO This should be accessible through ctx...
|
||||||
pub debug_mode: bool,
|
pub debug_mode: bool,
|
||||||
pub is_selected: bool,
|
pub is_selected: bool,
|
||||||
|
pub show_all_detail: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_vehicle(input: DrawCarInput, map: &Map) -> Box<Renderable> {
|
pub fn draw_vehicle(input: DrawCarInput, map: &Map) -> Box<Renderable> {
|
||||||
|
@ -238,8 +238,7 @@ impl<S: UIState> GUI<RenderingHints> for UI<S> {
|
|||||||
assert_eq!(bounds.min_x, 0.0);
|
assert_eq!(bounds.min_x, 0.0);
|
||||||
assert_eq!(bounds.min_y, 0.0);
|
assert_eq!(bounds.min_y, 0.0);
|
||||||
hints.mode = EventLoopMode::ScreenCaptureEverything {
|
hints.mode = EventLoopMode::ScreenCaptureEverything {
|
||||||
// TODO 6.0... or low zoom, but force detail
|
zoom: 4.0,
|
||||||
zoom: 2.0,
|
|
||||||
max_x: bounds.max_x,
|
max_x: bounds.max_x,
|
||||||
max_y: bounds.max_y,
|
max_y: bounds.max_y,
|
||||||
};
|
};
|
||||||
@ -252,26 +251,9 @@ impl<S: UIState> GUI<RenderingHints> for UI<S> {
|
|||||||
&mut self.canvas
|
&mut self.canvas
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw(&self, g: &mut GfxCtx, hints: &RenderingHints) {
|
fn draw(&self, _: &mut GfxCtx, _: &RenderingHints) {}
|
||||||
self.draw_screengrab(g, hints);
|
|
||||||
|
|
||||||
let ctx = Ctx {
|
fn new_draw(&self, g: &mut GfxCtx, hints: &RenderingHints, screencap: bool) {
|
||||||
cs: &self.cs,
|
|
||||||
map: &self.state.get_state().primary.map,
|
|
||||||
draw_map: &self.state.get_state().primary.draw_map,
|
|
||||||
canvas: &self.canvas,
|
|
||||||
sim: &self.state.get_state().primary.sim,
|
|
||||||
hints: &hints,
|
|
||||||
};
|
|
||||||
self.state.draw(g, &ctx);
|
|
||||||
|
|
||||||
// Not happy about cloning, but probably will make the OSD a first-class ezgui concept
|
|
||||||
// soon, so meh
|
|
||||||
self.canvas
|
|
||||||
.draw_blocking_text(g, hints.osd.clone(), BOTTOM_LEFT);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw_screengrab(&self, g: &mut GfxCtx, hints: &RenderingHints) {
|
|
||||||
g.clear(self.cs.get_def("map background", Color::rgb(242, 239, 233)));
|
g.clear(self.cs.get_def("map background", Color::rgb(242, 239, 233)));
|
||||||
|
|
||||||
let ctx = Ctx {
|
let ctx = Ctx {
|
||||||
@ -292,9 +274,20 @@ impl<S: UIState> GUI<RenderingHints> for UI<S> {
|
|||||||
color: self.state.get_state().color_obj(obj.get_id(), &ctx),
|
color: self.state.get_state().color_obj(obj.get_id(), &ctx),
|
||||||
debug_mode: self.state.get_state().layers.debug_mode.is_enabled(),
|
debug_mode: self.state.get_state().layers.debug_mode.is_enabled(),
|
||||||
is_selected: self.state.get_state().primary.current_selection == Some(obj.get_id()),
|
is_selected: self.state.get_state().primary.current_selection == Some(obj.get_id()),
|
||||||
|
// TODO If a ToggleableLayer is currently off, this won't affect it!
|
||||||
|
show_all_detail: screencap,
|
||||||
};
|
};
|
||||||
obj.draw(g, opts, &ctx);
|
obj.draw(g, opts, &ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !screencap {
|
||||||
|
self.state.draw(g, &ctx);
|
||||||
|
|
||||||
|
// Not happy about cloning, but probably will make the OSD a first-class ezgui concept
|
||||||
|
// soon, so meh
|
||||||
|
self.canvas
|
||||||
|
.draw_blocking_text(g, hints.osd.clone(), BOTTOM_LEFT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dump_before_abort(&self) {
|
fn dump_before_abort(&self) {
|
||||||
|
@ -16,8 +16,9 @@ pub trait GUI<T> {
|
|||||||
}
|
}
|
||||||
fn event(&mut self, input: &mut UserInput) -> (EventLoopMode, T);
|
fn event(&mut self, input: &mut UserInput) -> (EventLoopMode, T);
|
||||||
fn get_mut_canvas(&mut self) -> &mut Canvas;
|
fn get_mut_canvas(&mut self) -> &mut Canvas;
|
||||||
|
// TODO Migrate all callers
|
||||||
fn draw(&self, g: &mut GfxCtx, data: &T);
|
fn draw(&self, g: &mut GfxCtx, data: &T);
|
||||||
fn draw_screengrab(&self, g: &mut GfxCtx, data: &T) {
|
fn new_draw(&self, g: &mut GfxCtx, data: &T, _screencap: bool) {
|
||||||
self.draw(g, data);
|
self.draw(g, data);
|
||||||
}
|
}
|
||||||
// Will be called if event or draw panics.
|
// Will be called if event or draw panics.
|
||||||
@ -72,11 +73,7 @@ pub fn run<T, G: GUI<T>>(mut gui: G, window_title: &str) {
|
|||||||
gui.get_mut_canvas().start_drawing(&mut g);
|
gui.get_mut_canvas().start_drawing(&mut g);
|
||||||
|
|
||||||
if let Err(err) = panic::catch_unwind(panic::AssertUnwindSafe(|| {
|
if let Err(err) = panic::catch_unwind(panic::AssertUnwindSafe(|| {
|
||||||
if screen_cap.is_some() {
|
gui.new_draw(&mut g, data, screen_cap.is_some());
|
||||||
gui.draw_screengrab(&mut g, data);
|
|
||||||
} else {
|
|
||||||
gui.draw(&mut g, data);
|
|
||||||
}
|
|
||||||
})) {
|
})) {
|
||||||
gui.dump_before_abort();
|
gui.dump_before_abort();
|
||||||
panic::resume_unwind(err);
|
panic::resume_unwind(err);
|
||||||
|
Loading…
Reference in New Issue
Block a user