From 299f05e0a27489ac1a78748eaa70ba68f9859744 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Mon, 14 Jan 2019 11:16:55 -0800 Subject: [PATCH] force showing full detail when screencapping at low zoom --- editor/src/plugins/debug/layers.rs | 4 ++-- editor/src/render/intersection.rs | 2 +- editor/src/render/lane.rs | 2 +- editor/src/render/mod.rs | 1 + editor/src/ui.rs | 35 ++++++++++++------------------ ezgui/src/runner.rs | 9 +++----- 6 files changed, 22 insertions(+), 31 deletions(-) diff --git a/editor/src/plugins/debug/layers.rs b/editor/src/plugins/debug/layers.rs index 5cc4c85fe0..be8c7e3baf 100644 --- a/editor/src/plugins/debug/layers.rs +++ b/editor/src/plugins/debug/layers.rs @@ -4,7 +4,7 @@ use ezgui::ToggleableLayer; // 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_PARCE: f64 = 1.0; +const MIN_ZOOM_FOR_PARCELS: f64 = 1.0; pub struct ToggleableLayers { pub show_lanes: ToggleableLayer, @@ -23,7 +23,7 @@ impl ToggleableLayers { show_lanes: ToggleableLayer::new("lanes", Some(MIN_ZOOM_FOR_LANES)), show_buildings: ToggleableLayer::new("buildings", Some(0.0)), 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_all_turn_icons: ToggleableLayer::new("all turn icons", None), show_areas: ToggleableLayer::new("areas", None), diff --git a/editor/src/render/intersection.rs b/editor/src/render/intersection.rs index 8457566ba0..db42ee0eb5 100644 --- a/editor/src/render/intersection.rs +++ b/editor/src/render/intersection.rs @@ -70,7 +70,7 @@ impl Renderable for DrawIntersection { ctx.canvas .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 { g.draw_polygon(opts.color.unwrap_or_else(|| ctx.cs.get("sidewalk")), corner); } diff --git a/editor/src/render/lane.rs b/editor/src/render/lane.rs index 7a0380b9c8..5b5b29a0e4 100644 --- a/editor/src/render/lane.rs +++ b/editor/src/render/lane.rs @@ -117,7 +117,7 @@ impl Renderable for DrawLane { }); 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 { m(g, ctx.cs); } diff --git a/editor/src/render/mod.rs b/editor/src/render/mod.rs index dab5871c04..8f0c5e902b 100644 --- a/editor/src/render/mod.rs +++ b/editor/src/render/mod.rs @@ -55,6 +55,7 @@ pub struct RenderOptions { // TODO This should be accessible through ctx... pub debug_mode: bool, pub is_selected: bool, + pub show_all_detail: bool, } pub fn draw_vehicle(input: DrawCarInput, map: &Map) -> Box { diff --git a/editor/src/ui.rs b/editor/src/ui.rs index 0bfb5be6d7..5124e27d59 100644 --- a/editor/src/ui.rs +++ b/editor/src/ui.rs @@ -238,8 +238,7 @@ impl GUI for UI { assert_eq!(bounds.min_x, 0.0); assert_eq!(bounds.min_y, 0.0); hints.mode = EventLoopMode::ScreenCaptureEverything { - // TODO 6.0... or low zoom, but force detail - zoom: 2.0, + zoom: 4.0, max_x: bounds.max_x, max_y: bounds.max_y, }; @@ -252,26 +251,9 @@ impl GUI for UI { &mut self.canvas } - fn draw(&self, g: &mut GfxCtx, hints: &RenderingHints) { - self.draw_screengrab(g, hints); + fn draw(&self, _: &mut GfxCtx, _: &RenderingHints) {} - let ctx = Ctx { - 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) { + fn new_draw(&self, g: &mut GfxCtx, hints: &RenderingHints, screencap: bool) { g.clear(self.cs.get_def("map background", Color::rgb(242, 239, 233))); let ctx = Ctx { @@ -292,9 +274,20 @@ impl GUI for UI { color: self.state.get_state().color_obj(obj.get_id(), &ctx), debug_mode: self.state.get_state().layers.debug_mode.is_enabled(), 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); } + + 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) { diff --git a/ezgui/src/runner.rs b/ezgui/src/runner.rs index 34a446e50e..fcb5f9f4e1 100644 --- a/ezgui/src/runner.rs +++ b/ezgui/src/runner.rs @@ -16,8 +16,9 @@ pub trait GUI { } fn event(&mut self, input: &mut UserInput) -> (EventLoopMode, T); fn get_mut_canvas(&mut self) -> &mut Canvas; + // TODO Migrate all callers 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); } // Will be called if event or draw panics. @@ -72,11 +73,7 @@ pub fn run>(mut gui: G, window_title: &str) { gui.get_mut_canvas().start_drawing(&mut g); if let Err(err) = panic::catch_unwind(panic::AssertUnwindSafe(|| { - if screen_cap.is_some() { - gui.draw_screengrab(&mut g, data); - } else { - gui.draw(&mut g, data); - } + gui.new_draw(&mut g, data, screen_cap.is_some()); })) { gui.dump_before_abort(); panic::resume_unwind(err);