adjusting how routes are shown -- thick when zoomed out, thin and dashed

when zoomed in
This commit is contained in:
Dustin Carlino 2019-11-08 09:32:03 -08:00
parent 6a5b312a07
commit c6ed4a687b
2 changed files with 60 additions and 25 deletions

View File

@ -124,7 +124,7 @@ impl AgentTools {
}
pub fn draw(&self, g: &mut GfxCtx, ui: &UI) {
self.route_viewer.draw(g, ui);
self.route_viewer.draw(g);
if g.canvas.cam_zoom < MIN_ZOOM_FOR_DETAIL {
let mut maybe_legend = self.agent_cs_legend.borrow_mut();

View File

@ -1,18 +1,19 @@
use crate::helpers::ID;
use crate::render::{dashed_lines, MIN_ZOOM_FOR_DETAIL};
use crate::ui::UI;
use ezgui::{hotkey, Color, EventCtx, GfxCtx, Key, ModalMenu};
use geom::{Duration, PolyLine};
use map_model::LANE_THICKNESS;
use ezgui::{hotkey, Color, Drawable, EventCtx, GeomBatch, GfxCtx, Key, ModalMenu};
use geom::{Distance, Duration};
use sim::{AgentID, TripID, TripResult};
pub enum RouteViewer {
Inactive,
Hovering(Duration, AgentID, PolyLine),
Active(Duration, TripID, Option<PolyLine>),
Hovering(Duration, AgentID, Drawable),
// (zoomed, unzoomed)
Active(Duration, TripID, Option<(Drawable, Drawable)>),
}
impl RouteViewer {
fn recalc(ui: &UI) -> RouteViewer {
fn recalc(ctx: &EventCtx, ui: &UI) -> RouteViewer {
if let Some(agent) = ui
.primary
.current_selection
@ -20,7 +21,21 @@ impl RouteViewer {
.and_then(|id| id.agent_id())
{
if let Some(trace) = ui.primary.sim.trace_route(agent, &ui.primary.map, None) {
return RouteViewer::Hovering(ui.primary.sim.time(), agent, trace);
let mut batch = GeomBatch::new();
batch.extend(
ui.cs.get_def("route", Color::ORANGE.alpha(0.5)),
dashed_lines(
&trace,
Distance::meters(0.75),
Distance::meters(1.0),
Distance::meters(0.4),
),
);
return RouteViewer::Hovering(
ui.primary.sim.time(),
agent,
ctx.prerender.upload(batch),
);
}
}
RouteViewer::Inactive
@ -29,13 +44,13 @@ impl RouteViewer {
pub fn event(&mut self, ctx: &mut EventCtx, ui: &UI, menu: &mut ModalMenu) {
match self {
RouteViewer::Inactive => {
*self = RouteViewer::recalc(ui);
*self = RouteViewer::recalc(ctx, ui);
}
RouteViewer::Hovering(time, agent, _) => {
if *time != ui.primary.sim.time()
|| ui.primary.current_selection != Some(ID::from_agent(*agent))
{
*self = RouteViewer::recalc(ui);
*self = RouteViewer::recalc(ctx, ui);
}
if let RouteViewer::Hovering(_, agent, _) = self {
@ -45,7 +60,7 @@ impl RouteViewer {
.input
.contextual_action(Key::R, format!("show {}'s route", agent))
{
*self = show_route(trip, ui);
*self = show_route(trip, ui, ctx);
menu.push_action(hotkey(Key::R), "stop showing agent's route", ctx);
}
}
@ -54,38 +69,58 @@ impl RouteViewer {
if menu.consume_action("stop showing agent's route", ctx) {
*self = RouteViewer::Inactive;
} else if *time != ui.primary.sim.time() {
*self = show_route(*trip, ui);
*self = show_route(*trip, ui, ctx);
}
}
}
}
pub fn draw(&self, g: &mut GfxCtx, ui: &UI) {
pub fn draw(&self, g: &mut GfxCtx) {
match self {
RouteViewer::Hovering(_, _, ref trace) => {
g.draw_polygon(
ui.cs.get("route").alpha(0.5),
&trace.make_polygons(LANE_THICKNESS),
);
RouteViewer::Hovering(_, _, ref route) => {
g.redraw(route);
}
RouteViewer::Active(_, _, Some(ref trace)) => {
g.draw_polygon(
ui.cs.get_def("route", Color::RED.alpha(0.8)),
&trace.make_polygons(LANE_THICKNESS),
);
RouteViewer::Active(_, _, Some((ref zoomed, ref unzoomed))) => {
if g.canvas.cam_zoom < MIN_ZOOM_FOR_DETAIL {
g.redraw(unzoomed);
} else {
g.redraw(zoomed);
}
}
_ => {}
}
}
}
fn show_route(trip: TripID, ui: &UI) -> RouteViewer {
fn show_route(trip: TripID, ui: &UI, ctx: &EventCtx) -> RouteViewer {
let time = ui.primary.sim.time();
match ui.primary.sim.trip_to_agent(trip) {
TripResult::Ok(agent) => RouteViewer::Active(
time,
trip,
ui.primary.sim.trace_route(agent, &ui.primary.map, None),
ui.primary
.sim
.trace_route(agent, &ui.primary.map, None)
.map(|trace| {
let mut zoomed = GeomBatch::new();
zoomed.extend(
ui.cs.get("route").alpha(0.8),
dashed_lines(
&trace,
Distance::meters(0.75),
Distance::meters(1.0),
Distance::meters(0.4),
),
);
let mut unzoomed = GeomBatch::new();
unzoomed.push(
ui.cs.get_def("unzoomed route", Color::CYAN),
trace.make_polygons(Distance::meters(10.0)),
);
(ctx.prerender.upload(zoomed), ctx.prerender.upload(unzoomed))
}),
),
TripResult::ModeChange => {
println!("{} is doing a mode change", trip);