update an ezgui API from another branch, so the git diff isnt crazy

This commit is contained in:
Dustin Carlino 2020-04-07 17:02:06 -07:00
parent 6b7d7891df
commit ac3e4ee233
11 changed files with 74 additions and 33 deletions

View File

@ -113,24 +113,7 @@ impl GeomBatch {
pub fn rewrite_color(&mut self, transformation: RewriteColor) {
for (fancy, _) in self.list.iter_mut() {
if let FancyColor::RGBA(ref mut c) = fancy {
match transformation {
RewriteColor::NoOp => {}
RewriteColor::Change(from, to) => {
if *c == from {
*c = to;
}
}
RewriteColor::ChangeMore(ref list) => {
for (from, to) in list {
if c == from {
*c = *to;
}
}
}
RewriteColor::ChangeAll(to) => {
*c = to;
}
}
*c = transformation.apply(*c);
}
}
}
@ -144,23 +127,37 @@ impl GeomBatch {
center: Pt2D,
scale: f64,
rotate: Angle,
rewrite: RewriteColor,
) {
self.add_transformed(svg::load_svg(prerender, filename).0, center, scale, rotate);
self.add_transformed(
svg::load_svg(prerender, filename).0,
center,
scale,
rotate,
rewrite,
);
}
/// Adds geometry from another batch to the current batch, first centering it on the given
/// point.
pub fn add_centered(&mut self, other: GeomBatch, center: Pt2D) {
self.add_transformed(other, center, 1.0, Angle::ZERO);
self.add_transformed(other, center, 1.0, Angle::ZERO, RewriteColor::NoOp);
}
/// Adds geometry from another batch to the current batch, first transforming it. The
/// translation centers on the given point.
pub fn add_transformed(&mut self, other: GeomBatch, center: Pt2D, scale: f64, rotate: Angle) {
pub fn add_transformed(
&mut self,
other: GeomBatch,
center: Pt2D,
scale: f64,
rotate: Angle,
rewrite: RewriteColor,
) {
let dims = other.get_dims();
let dx = center.x() - dims.width * scale / 2.0;
let dy = center.y() - dims.height * scale / 2.0;
for (color, mut poly) in other.consume() {
for (mut fancy_color, mut poly) in other.consume() {
// Avoid unnecessary transformations for slight perf boost
if scale != 1.0 {
poly = poly.scale(scale);
@ -169,7 +166,10 @@ impl GeomBatch {
if rotate != Angle::ZERO {
poly = poly.rotate(rotate);
}
self.fancy_push(color, poly);
if let FancyColor::RGBA(ref mut c) = fancy_color {
*c = rewrite.apply(*c);
}
self.fancy_push(fancy_color, poly);
}
}
@ -188,3 +188,27 @@ pub enum RewriteColor {
ChangeMore(Vec<(Color, Color)>),
ChangeAll(Color),
}
impl RewriteColor {
fn apply(&self, c: Color) -> Color {
match self {
RewriteColor::NoOp => c,
RewriteColor::Change(from, to) => {
if c == *from {
*to
} else {
c
}
}
RewriteColor::ChangeMore(ref list) => {
for (from, to) in list {
if c == *from {
return *to;
}
}
c
}
RewriteColor::ChangeAll(to) => *to,
}
}
}

View File

@ -404,7 +404,7 @@ pub fn apply_map_edits(ctx: &mut EventCtx, app: &mut App, edits: MapEdits) {
&app.cs,
&mut timer,
)
.finish(ctx.prerender, lane);
.finish(ctx.prerender, &app.cs, lane);
}
}

View File

@ -146,6 +146,7 @@ fn make_timeline(
center,
1.0,
Angle::ZERO,
RewriteColor::NoOp,
);
details.zoomed.add_svg(
ctx.prerender,
@ -153,6 +154,7 @@ fn make_timeline(
center,
0.5,
Angle::ZERO,
RewriteColor::NoOp,
);
let mut txt = Text::from(Line(name));
txt.add(Line(start_time.ampm_tostring()));
@ -175,6 +177,7 @@ fn make_timeline(
center,
1.0,
Angle::ZERO,
RewriteColor::NoOp,
);
details.zoomed.add_svg(
ctx.prerender,
@ -182,6 +185,7 @@ fn make_timeline(
center,
0.5,
Angle::ZERO,
RewriteColor::NoOp,
);
let mut txt = Text::from(Line(name));
if let Some(t) = end_time {
@ -249,6 +253,7 @@ fn make_timeline(
Pt2D::new(p * phase_width, 7.5),
1.0,
Angle::ZERO,
RewriteColor::NoOp,
);
}
}
@ -271,6 +276,7 @@ fn make_timeline(
Pt2D::new(0.5 * phase_width, -20.0),
1.0,
Angle::ZERO,
RewriteColor::NoOp,
);
let mut hovered = GeomBatch::from(vec![(color.alpha(1.0), rect.clone())]);

View File

@ -2,7 +2,7 @@ use crate::app::App;
use crate::colors::ColorScheme;
use crate::helpers::ID;
use crate::render::{DrawOptions, Renderable, OUTLINE_THICKNESS};
use ezgui::{Color, Drawable, GeomBatch, GfxCtx, Line, Prerender, Text};
use ezgui::{Color, Drawable, GeomBatch, GfxCtx, Line, Prerender, RewriteColor, Text};
use geom::{Angle, Distance, Line, Polygon, Pt2D};
use map_model::{Building, BuildingID, Map, NORMAL_LANE_THICKNESS, SIDEWALK_THICKNESS};
@ -51,6 +51,7 @@ impl DrawBuilding {
bldg.label_center,
0.1,
Angle::ZERO,
RewriteColor::NoOp,
);
}
@ -63,6 +64,7 @@ impl DrawBuilding {
bldg.label_center,
0.1,
Angle::ZERO,
RewriteColor::NoOp,
);
prerender.upload(lbl)
})

View File

@ -2,7 +2,7 @@ use crate::app::App;
use crate::colors::ColorScheme;
use crate::helpers::ID;
use crate::render::{DrawOptions, Renderable, OUTLINE_THICKNESS};
use ezgui::{Color, Drawable, GeomBatch, GfxCtx, Line, Prerender, Text};
use ezgui::{Color, Drawable, GeomBatch, GfxCtx, Line, Prerender, RewriteColor, Text};
use geom::{Angle, Distance, PolyLine, Polygon, Pt2D};
use map_model::{Map, TurnType};
use sim::{CarID, CarStatus, DrawCarInput, VehicleType};
@ -48,6 +48,7 @@ impl DrawCar {
body_polygon.center(),
0.01,
Angle::ZERO,
RewriteColor::NoOp,
);
}
@ -119,6 +120,7 @@ impl DrawCar {
input.body.dist_along(Distance::meters(9.0)).0,
0.07,
Angle::ZERO,
RewriteColor::NoOp,
);
}

View File

@ -5,7 +5,7 @@ use crate::render::{
draw_signal_phase, DrawOptions, Renderable, CROSSWALK_LINE_THICKNESS, OUTLINE_THICKNESS,
};
use abstutil::Timer;
use ezgui::{Drawable, FancyColor, GeomBatch, GfxCtx, Line, Prerender, Text};
use ezgui::{Drawable, FancyColor, GeomBatch, GfxCtx, Line, Prerender, RewriteColor, Text};
use geom::{Angle, Distance, Line, PolyLine, Polygon, Pt2D, Time, EPSILON_DIST};
use map_model::raw::DrivingSide;
use map_model::{
@ -150,6 +150,7 @@ impl Renderable for DrawIntersection {
app.primary.map.get_i(self.id).polygon.center(),
0.1,
Angle::ZERO,
RewriteColor::NoOp,
);
*maybe_redraw = Some((app.primary.sim.time(), g.prerender.upload(batch)));
}

View File

@ -3,7 +3,7 @@ use crate::colors::ColorScheme;
use crate::helpers::ID;
use crate::render::{dashed_lines, DrawOptions, Renderable, OUTLINE_THICKNESS};
use abstutil::Timer;
use ezgui::{Drawable, FancyColor, GeomBatch, GfxCtx, Prerender};
use ezgui::{Drawable, FancyColor, GeomBatch, GfxCtx, Prerender, RewriteColor};
use geom::{Angle, Distance, Line, PolyLine, Polygon, Pt2D};
use map_model::{Lane, LaneID, LaneType, Map, Road, TurnType, PARKING_SPOT_LENGTH};
@ -17,7 +17,7 @@ pub struct AlmostDrawLane {
}
impl AlmostDrawLane {
pub fn finish(mut self, prerender: &Prerender, lane: &Lane) -> DrawLane {
pub fn finish(mut self, prerender: &Prerender, _: &ColorScheme, lane: &Lane) -> DrawLane {
// Need prerender to load the (cached) SVGs
if lane.is_bus() {
let buffer = Distance::meters(2.0);
@ -35,6 +35,7 @@ impl AlmostDrawLane {
angle
.shortest_rotation_towards(Angle::new_degs(-90.0))
.invert_y(),
RewriteColor::NoOp,
);
dist += btwn;
}
@ -54,6 +55,7 @@ impl AlmostDrawLane {
angle
.shortest_rotation_towards(Angle::new_degs(-90.0))
.invert_y(),
RewriteColor::NoOp,
);
dist += btwn;
}

View File

@ -95,7 +95,7 @@ impl DrawMap {
for almost in almost_lanes {
timer.next();
let lane = map.get_l(almost.id);
lanes.push(almost.finish(ctx.prerender, lane));
lanes.push(almost.finish(ctx.prerender, cs, lane));
}
let mut intersections: Vec<DrawIntersection> = Vec::new();

View File

@ -2,7 +2,7 @@ use crate::app::App;
use crate::colors::ColorScheme;
use crate::helpers::ID;
use crate::render::{DrawOptions, Renderable, OUTLINE_THICKNESS};
use ezgui::{Color, Drawable, GeomBatch, GfxCtx, Line, Prerender, Text};
use ezgui::{Color, Drawable, GeomBatch, GfxCtx, Line, Prerender, RewriteColor, Text};
use geom::{Angle, Circle, Distance, PolyLine, Polygon};
use map_model::{Map, SIDEWALK_THICKNESS};
use sim::{DrawPedCrowdInput, DrawPedestrianInput, PedCrowdLocation, PedestrianID};
@ -228,6 +228,7 @@ impl DrawPedCrowd {
blob.center(),
0.02,
Angle::ZERO,
RewriteColor::NoOp,
);
DrawPedCrowd {

View File

@ -2,7 +2,7 @@ use crate::app::App;
use crate::colors::ColorScheme;
use crate::helpers::ID;
use crate::render::{dashed_lines, DrawOptions, Renderable};
use ezgui::{Drawable, GeomBatch, GfxCtx, Line, Prerender, Text};
use ezgui::{Drawable, GeomBatch, GfxCtx, Line, Prerender, RewriteColor, Text};
use geom::{Angle, Distance, Polygon, Pt2D};
use map_model::{LaneType, Map, Road, RoadID};
@ -45,6 +45,7 @@ impl DrawRoad {
r.center_pts.middle(),
0.1,
Angle::ZERO,
RewriteColor::NoOp,
);
}

View File

@ -4,7 +4,7 @@ use crate::render::intersection::make_crosswalk;
use crate::render::{DrawTurnGroup, BIG_ARROW_THICKNESS};
use ezgui::{
hotkey, Btn, Color, Composite, EventCtx, GeomBatch, HorizontalAlignment, Key, Line, Prerender,
Text, TextExt, VerticalAlignment, Widget,
RewriteColor, Text, TextExt, VerticalAlignment, Widget,
};
use geom::{Angle, Circle, Distance, Duration, Line, PolyLine, Polygon, Pt2D};
use map_model::{IntersectionID, Phase, TurnPriority};
@ -68,6 +68,7 @@ pub fn draw_signal_phase(
center,
0.07,
angle,
RewriteColor::NoOp,
);
dont_walk.remove(g);
}
@ -80,6 +81,7 @@ pub fn draw_signal_phase(
center,
0.07,
angle,
RewriteColor::NoOp,
);
}
}