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); let mut colorer = ColorNetwork::new(app);
// Highlight the intersection // Highlight the intersection
colorer colorer
.draw
.unzoomed .unzoomed
.push(Color::CYAN, map.get_i(i).polygon.clone()); .push(Color::CYAN, map.get_i(i).polygon.clone());
colorer colorer
.draw
.zoomed .zoomed
.push(Color::CYAN.alpha(0.5), map.get_i(i).polygon.clone()); .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.unzoomed.append(colorer.draw.unzoomed);
details.draw_extra.zoomed.append(colorer.zoomed); details.draw_extra.zoomed.append(colorer.draw.zoomed);
for pt in bus_locations { for pt in bus_locations {
details.draw_extra.unzoomed.push( details.draw_extra.unzoomed.push(

View File

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

View File

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

View File

@ -3,7 +3,7 @@ use std::collections::HashMap;
use abstutil::Counter; use abstutil::Counter;
use geom::{Circle, Distance, Line, Polygon, Pt2D}; use geom::{Circle, Distance, Line, Polygon, Pt2D};
use map_model::{BuildingID, IntersectionID, LaneID, Map, ParkingLotID, RoadID, TransitStopID}; 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 widgetry::{Color, EventCtx, Fill, GeomBatch, Line, LinearGradient, Text, Widget};
use crate::AppLike; use crate::AppLike;
@ -258,62 +258,72 @@ impl DivergingScale {
// TODO Bad name // TODO Bad name
pub struct ColorNetwork<'a> { pub struct ColorNetwork<'a> {
map: &'a Map, map: &'a Map,
pub unzoomed: GeomBatch, pub draw: ToggleZoomedBuilder,
pub zoomed: GeomBatch,
} }
impl<'a> ColorNetwork<'a> { impl<'a> ColorNetwork<'a> {
pub fn new(app: &'a dyn AppLike) -> ColorNetwork { pub fn new(app: &'a dyn AppLike) -> ColorNetwork {
let mut unzoomed = GeomBatch::new(); let mut draw = ToggleZoomed::builder();
unzoomed.push( draw.unzoomed.push(
app.cs().fade_map_dark, app.cs().fade_map_dark,
app.map().get_boundary_polygon().clone(), app.map().get_boundary_polygon().clone(),
); );
ColorNetwork { ColorNetwork {
map: app.map(), map: app.map(),
unzoomed, draw,
zoomed: GeomBatch::new(),
} }
} }
pub fn no_fading(app: &'a dyn AppLike) -> ColorNetwork { pub fn no_fading(app: &'a dyn AppLike) -> ColorNetwork {
ColorNetwork { ColorNetwork {
map: app.map(), map: app.map(),
unzoomed: GeomBatch::new(), draw: ToggleZoomed::builder(),
zoomed: GeomBatch::new(),
} }
} }
pub fn add_l(&mut self, l: LaneID, color: Color) { 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()); .push(color, self.map.get_parent(l).get_thick_polygon());
let lane = self.map.get_l(l); 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) { 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()); .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()); .push(color.alpha(0.4), self.map.get_r(r).get_thick_polygon());
} }
pub fn add_i(&mut self, i: IntersectionID, color: Color) { pub fn add_i(&mut self, i: IntersectionID, color: Color) {
self.unzoomed.push(color, self.map.get_i(i).polygon.clone()); self.draw
self.zoomed .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()); .push(color.alpha(0.4), self.map.get_i(i).polygon.clone());
} }
pub fn add_b(&mut self, b: BuildingID, color: Color) { pub fn add_b(&mut self, b: BuildingID, color: Color) {
self.unzoomed.push(color, self.map.get_b(b).polygon.clone()); self.draw
self.zoomed .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()); .push(color.alpha(0.4), self.map.get_b(b).polygon.clone());
} }
pub fn add_pl(&mut self, pl: ParkingLotID, color: Color) { pub fn add_pl(&mut self, pl: ParkingLotID, color: Color) {
self.unzoomed self.draw
.unzoomed
.push(color, self.map.get_pl(pl).polygon.clone()); .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()); .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 { 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)); 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. /// Let objects in the world respond to something happening.
pub fn event(&mut self, ctx: &mut EventCtx) -> WorldOutcome<ID> { pub fn event(&mut self, ctx: &mut EventCtx) -> WorldOutcome<ID> {
if let Some((drag_from, moved)) = self.dragging_from { if let Some((drag_from, moved)) = self.dragging_from {