mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-25 07:25:47 +03:00
Similar refactor for ColorDiscrete. Anywhere separately managed a zoomed
and unzoomed batch should just migrate to this.
This commit is contained in:
parent
5dfb8f26f0
commit
cabffc7f47
@ -328,8 +328,7 @@ fn route_body(ctx: &mut EventCtx, app: &App, details: &mut Details, id: TransitR
|
||||
}
|
||||
}
|
||||
}
|
||||
details.draw_extra.unzoomed.append(colorer.draw.unzoomed);
|
||||
details.draw_extra.zoomed.append(colorer.draw.zoomed);
|
||||
details.draw_extra.append(colorer.draw);
|
||||
|
||||
for pt in bus_locations {
|
||||
details.draw_extra.unzoomed.push(
|
||||
|
@ -117,7 +117,7 @@ impl SteepStreets {
|
||||
);
|
||||
}
|
||||
}
|
||||
colorer.unzoomed.append(arrows);
|
||||
colorer.draw.unzoomed.append(arrows);
|
||||
|
||||
(colorer, steepest, uphill_legend)
|
||||
}
|
||||
|
@ -166,8 +166,8 @@ impl Layers {
|
||||
// The Colorer fades the map as the very first thing in the batch, but we
|
||||
// don't want to do that twice.
|
||||
// TODO Can't use no_fading without complicating make_colorer...
|
||||
colorer.unzoomed.shift();
|
||||
self.steep_streets = Some(colorer.unzoomed.upload(ctx));
|
||||
colorer.draw.unzoomed.shift();
|
||||
self.steep_streets = Some(colorer.draw.unzoomed.upload(ctx));
|
||||
} else {
|
||||
self.steep_streets = None;
|
||||
}
|
||||
|
@ -11,8 +11,7 @@ use crate::AppLike;
|
||||
pub struct ColorDiscrete<'a> {
|
||||
map: &'a Map,
|
||||
// pub so callers can add stuff in before building
|
||||
pub unzoomed: GeomBatch,
|
||||
pub zoomed: GeomBatch,
|
||||
pub draw: ToggleZoomedBuilder,
|
||||
// Store both, so we can build the legend in the original order later
|
||||
pub categories: Vec<(String, Color)>,
|
||||
colors: HashMap<String, Color>,
|
||||
@ -23,8 +22,8 @@ impl<'a> ColorDiscrete<'a> {
|
||||
app: &'a dyn AppLike,
|
||||
categories: Vec<(I, Color)>,
|
||||
) -> ColorDiscrete<'a> {
|
||||
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(),
|
||||
);
|
||||
@ -32,8 +31,7 @@ impl<'a> ColorDiscrete<'a> {
|
||||
categories.into_iter().map(|(k, v)| (k.into(), v)).collect();
|
||||
ColorDiscrete {
|
||||
map: app.map(),
|
||||
unzoomed,
|
||||
zoomed: GeomBatch::new(),
|
||||
draw,
|
||||
colors: categories.iter().cloned().collect(),
|
||||
categories,
|
||||
}
|
||||
@ -44,48 +42,60 @@ impl<'a> ColorDiscrete<'a> {
|
||||
categories: Vec<(I, Color)>,
|
||||
) -> ColorDiscrete<'a> {
|
||||
let mut c = ColorDiscrete::new(app, categories);
|
||||
c.unzoomed = GeomBatch::new();
|
||||
c.draw.unzoomed = GeomBatch::new();
|
||||
c
|
||||
}
|
||||
|
||||
pub fn add_l<I: AsRef<str>>(&mut self, l: LaneID, category: I) {
|
||||
let color = self.colors[category.as_ref()];
|
||||
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<I: AsRef<str>>(&mut self, r: RoadID, category: I) {
|
||||
let color = self.colors[category.as_ref()];
|
||||
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<I: AsRef<str>>(&mut self, i: IntersectionID, category: I) {
|
||||
let color = self.colors[category.as_ref()];
|
||||
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<I: AsRef<str>>(&mut self, b: BuildingID, category: I) {
|
||||
let color = self.colors[category.as_ref()];
|
||||
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_ts<I: AsRef<str>>(&mut self, ts: TransitStopID, category: I) {
|
||||
let color = self.colors[category.as_ref()];
|
||||
let pt = self.map.get_ts(ts).sidewalk_pos.pt(self.map);
|
||||
self.zoomed.push(
|
||||
self.draw.zoomed.push(
|
||||
color.alpha(0.4),
|
||||
Circle::new(pt, Distance::meters(5.0)).to_polygon(),
|
||||
);
|
||||
self.unzoomed
|
||||
self.draw
|
||||
.unzoomed
|
||||
.push(color, Circle::new(pt, Distance::meters(15.0)).to_polygon());
|
||||
}
|
||||
|
||||
@ -95,10 +105,7 @@ impl<'a> ColorDiscrete<'a> {
|
||||
.into_iter()
|
||||
.map(|(name, color)| ColorLegend::row(ctx, color, name))
|
||||
.collect();
|
||||
(
|
||||
ToggleZoomed::new(ctx, self.unzoomed, self.zoomed),
|
||||
Widget::col(legend),
|
||||
)
|
||||
(self.draw.build(ctx), Widget::col(legend))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user