Refactor ColorNetwork to use ToggleZoomed

This commit is contained in:
Dustin Carlino 2022-01-26 11:31:33 +00:00
parent ec0fd1b94d
commit 5dfb8f26f0
6 changed files with 37 additions and 31 deletions

View File

@ -49,9 +49,11 @@ impl PathCounter {
let mut colorer = ColorNetwork::new(app);
// Highlight the intersection
colorer
.draw
.unzoomed
.push(Color::CYAN, map.get_i(i).polygon.clone());
colorer
.draw
.zoomed
.push(Color::CYAN.alpha(0.5), map.get_i(i).polygon.clone());

View File

@ -328,8 +328,8 @@ fn route_body(ctx: &mut EventCtx, app: &App, details: &mut Details, id: TransitR
}
}
}
details.draw_extra.unzoomed.append(colorer.unzoomed);
details.draw_extra.zoomed.append(colorer.zoomed);
details.draw_extra.unzoomed.append(colorer.draw.unzoomed);
details.draw_extra.zoomed.append(colorer.draw.zoomed);
for pt in bus_locations {
details.draw_extra.unzoomed.push(

View File

@ -253,7 +253,7 @@ impl Occupancy {
.to_polygon();
for a in app.primary.sim.get_unzoomed_agents(&app.primary.map) {
if a.parking {
colorer.unzoomed.push(
colorer.draw.unzoomed.push(
app.cs.parking_trip.alpha(0.8),
car_circle.translate(a.pos.x(), a.pos.y()),
);

View File

@ -103,8 +103,7 @@ impl Results {
self.before_intersection_counts.clone(),
&app.cs.good_to_bad_red,
);
self.before_world
.draw_master_batch_built(colorer.build(ctx));
self.before_world.draw_master_batch(ctx, colorer.draw);
}
// After the filters
@ -130,7 +129,7 @@ impl Results {
self.after_intersection_counts.clone(),
&app.cs.good_to_bad_red,
);
self.after_world.draw_master_batch_built(colorer.build(ctx));
self.after_world.draw_master_batch(ctx, colorer.draw);
}
self.recalculate_relative_diff(ctx, app);

View File

@ -3,7 +3,7 @@ use std::collections::HashMap;
use abstutil::Counter;
use geom::{Circle, Distance, Line, Polygon, Pt2D};
use map_model::{BuildingID, IntersectionID, LaneID, Map, ParkingLotID, RoadID, TransitStopID};
use widgetry::mapspace::ToggleZoomed;
use widgetry::mapspace::{ToggleZoomed, ToggleZoomedBuilder};
use widgetry::{Color, EventCtx, Fill, GeomBatch, Line, LinearGradient, Text, Widget};
use crate::AppLike;
@ -258,62 +258,72 @@ impl DivergingScale {
// TODO Bad name
pub struct ColorNetwork<'a> {
map: &'a Map,
pub unzoomed: GeomBatch,
pub zoomed: GeomBatch,
pub draw: ToggleZoomedBuilder,
}
impl<'a> ColorNetwork<'a> {
pub fn new(app: &'a dyn AppLike) -> ColorNetwork {
let mut unzoomed = GeomBatch::new();
unzoomed.push(
let mut draw = ToggleZoomed::builder();
draw.unzoomed.push(
app.cs().fade_map_dark,
app.map().get_boundary_polygon().clone(),
);
ColorNetwork {
map: app.map(),
unzoomed,
zoomed: GeomBatch::new(),
draw,
}
}
pub fn no_fading(app: &'a dyn AppLike) -> ColorNetwork {
ColorNetwork {
map: app.map(),
unzoomed: GeomBatch::new(),
zoomed: GeomBatch::new(),
draw: ToggleZoomed::builder(),
}
}
pub fn add_l(&mut self, l: LaneID, color: Color) {
self.unzoomed
self.draw
.unzoomed
.push(color, self.map.get_parent(l).get_thick_polygon());
let lane = self.map.get_l(l);
self.zoomed.push(color.alpha(0.4), lane.get_thick_polygon());
self.draw
.zoomed
.push(color.alpha(0.4), lane.get_thick_polygon());
}
pub fn add_r(&mut self, r: RoadID, color: Color) {
self.unzoomed
self.draw
.unzoomed
.push(color, self.map.get_r(r).get_thick_polygon());
self.zoomed
self.draw
.zoomed
.push(color.alpha(0.4), self.map.get_r(r).get_thick_polygon());
}
pub fn add_i(&mut self, i: IntersectionID, color: Color) {
self.unzoomed.push(color, self.map.get_i(i).polygon.clone());
self.zoomed
self.draw
.unzoomed
.push(color, self.map.get_i(i).polygon.clone());
self.draw
.zoomed
.push(color.alpha(0.4), self.map.get_i(i).polygon.clone());
}
pub fn add_b(&mut self, b: BuildingID, color: Color) {
self.unzoomed.push(color, self.map.get_b(b).polygon.clone());
self.zoomed
self.draw
.unzoomed
.push(color, self.map.get_b(b).polygon.clone());
self.draw
.zoomed
.push(color.alpha(0.4), self.map.get_b(b).polygon.clone());
}
pub fn add_pl(&mut self, pl: ParkingLotID, color: Color) {
self.unzoomed
self.draw
.unzoomed
.push(color, self.map.get_pl(pl).polygon.clone());
self.zoomed
self.draw
.zoomed
.push(color.alpha(0.4), self.map.get_pl(pl).polygon.clone());
}
@ -355,7 +365,7 @@ impl<'a> ColorNetwork<'a> {
}
pub fn build(self, ctx: &mut EventCtx) -> ToggleZoomed {
ToggleZoomed::new(ctx, self.unzoomed, self.zoomed)
self.draw.build(ctx)
}
}

View File

@ -390,11 +390,6 @@ impl<ID: ObjectID> World<ID> {
self.draw_master_batches.push(draw.into().build(ctx));
}
// TODO Refactor ColorNetwork, then delete this variation
pub fn draw_master_batch_built(&mut self, draw: ToggleZoomed) {
self.draw_master_batches.push(draw);
}
/// Let objects in the world respond to something happening.
pub fn event(&mut self, ctx: &mut EventCtx) -> WorldOutcome<ID> {
if let Some((drag_from, moved)) = self.dragging_from {