passing ctx to both plugins and renderers, so we can debug lanes

This commit is contained in:
Dustin Carlino 2018-09-15 09:11:06 -07:00
parent 269642a984
commit 008c63cd1a
21 changed files with 106 additions and 84 deletions

View File

@ -995,7 +995,9 @@ Alright, replan yet again.
- deal with overlapping keys that still kinda happen (sim ctrl, escape game) - deal with overlapping keys that still kinda happen (sim ctrl, escape game)
- bug: do need to recalculate current_selection whenever anything potentially changes camera, like follow - bug: do need to recalculate current_selection whenever anything potentially changes camera, like follow
- then rethink colors, with simplified single plugin = then rethink colors, with simplified single plugin
- plugin trait, color(id) -> Option<Color>. parallel list of box plugins (or, a fxn that takes the idx) = plugin trait, color(id) -> Option<Color>. parallel list of box plugins (or, a fxn that takes the idx)
- refactor to one color_blah method
- handle the two color things... just buildings?
- and see how much boilerplate a new type would need, by adding bus stops and water/parks - and see how much boilerplate a new type would need, by adding bus stops and water/parks
- consider merging control map into map - consider merging control map into map

View File

@ -1,5 +1,8 @@
use colors::ColorScheme;
use control::ControlMap;
use ezgui::Canvas;
use kml::ExtraShapeID; use kml::ExtraShapeID;
use map_model::{BuildingID, IntersectionID, LaneID, ParcelID, TurnID}; use map_model::{BuildingID, IntersectionID, LaneID, Map, ParcelID, TurnID};
use sim::{CarID, PedestrianID}; use sim::{CarID, PedestrianID};
#[derive(Clone, Copy, Hash, PartialEq, Eq, Debug)] #[derive(Clone, Copy, Hash, PartialEq, Eq, Debug)]
@ -13,3 +16,11 @@ pub enum ID {
ExtraShape(ExtraShapeID), ExtraShape(ExtraShapeID),
Parcel(ParcelID), Parcel(ParcelID),
} }
// For plugins and rendering. Not sure what module this should live in, here seems fine.
pub struct Ctx<'a> {
pub cs: &'a ColorScheme,
pub map: &'a Map,
pub control_map: &'a ControlMap,
pub canvas: &'a Canvas,
}

View File

@ -3,9 +3,9 @@
use colors::Colors; use colors::Colors;
use ezgui::UserInput; use ezgui::UserInput;
use graphics::types::Color; use graphics::types::Color;
use objects::ID; use objects::{Ctx, ID};
use piston::input::Key; use piston::input::Key;
use plugins::{Colorizer, Ctx}; use plugins::Colorizer;
// TODO have some UI for editing these rules and saving them // TODO have some UI for editing these rules and saving them
pub struct OsmClassifier { pub struct OsmClassifier {

View File

@ -4,9 +4,9 @@ use colors::Colors;
use ezgui::UserInput; use ezgui::UserInput;
use graphics::types::Color; use graphics::types::Color;
use map_model::{LaneID, Map}; use map_model::{LaneID, Map};
use objects::ID; use objects::{Ctx, ID};
use piston::input::Key; use piston::input::Key;
use plugins::{Colorizer, Ctx}; use plugins::Colorizer;
use std::collections::{HashSet, VecDeque}; use std::collections::{HashSet, VecDeque};
// Keeps track of state so this can be interactively visualized // Keeps track of state so this can be interactively visualized

View File

@ -16,20 +16,11 @@ pub mod turn_colors;
pub mod turn_cycler; pub mod turn_cycler;
pub mod warp; pub mod warp;
use colors::ColorScheme;
use control::ControlMap;
use graphics::types::Color; use graphics::types::Color;
use map_model::Map; use objects::{Ctx, ID};
use objects::ID;
pub trait Colorizer { pub trait Colorizer {
fn color_for(&self, _obj: ID, _ctx: Ctx) -> Option<Color> { fn color_for(&self, _obj: ID, _ctx: Ctx) -> Option<Color> {
None None
} }
} }
pub struct Ctx<'a> {
pub cs: &'a ColorScheme,
pub map: &'a Map,
pub control_map: &'a ControlMap,
}

View File

@ -3,9 +3,9 @@
use colors::{ColorScheme, Colors}; use colors::{ColorScheme, Colors};
use ezgui::{TextBox, UserInput}; use ezgui::{TextBox, UserInput};
use graphics::types::Color; use graphics::types::Color;
use objects::ID; use objects::{Ctx, ID};
use piston::input::Key; use piston::input::Key;
use plugins::{Colorizer, Ctx}; use plugins::Colorizer;
use std::collections::BTreeMap; use std::collections::BTreeMap;
pub enum SearchState { pub enum SearchState {

View File

@ -2,9 +2,9 @@ use colors::Colors;
use ezgui::UserInput; use ezgui::UserInput;
use graphics::types::Color; use graphics::types::Color;
use map_model::LaneID; use map_model::LaneID;
use objects::ID; use objects::{Ctx, ID};
use piston::input::Key; use piston::input::Key;
use plugins::{Colorizer, Ctx}; use plugins::Colorizer;
use sim::{AgentID, Sim}; use sim::{AgentID, Sim};
use std::collections::HashSet; use std::collections::HashSet;

View File

@ -5,9 +5,9 @@
use ezgui::UserInput; use ezgui::UserInput;
use graphics::types::Color; use graphics::types::Color;
use map_model::{Lane, Map}; use map_model::{Lane, Map};
use objects::ID; use objects::{Ctx, ID};
use piston::input::Key; use piston::input::Key;
use plugins::{Colorizer, Ctx}; use plugins::Colorizer;
use std::f64; use std::f64;
pub struct SteepnessVisualizer { pub struct SteepnessVisualizer {

View File

@ -7,9 +7,9 @@ use ezgui::UserInput;
use graphics::types::Color; use graphics::types::Color;
use map_model::IntersectionID; use map_model::IntersectionID;
use map_model::Map; use map_model::Map;
use objects::ID; use objects::{Ctx, ID};
use piston::input::Key; use piston::input::Key;
use plugins::{Colorizer, Ctx}; use plugins::Colorizer;
#[derive(PartialEq)] #[derive(PartialEq)]
pub enum StopSignEditor { pub enum StopSignEditor {

View File

@ -7,9 +7,9 @@ use control::ControlMap;
use ezgui::UserInput; use ezgui::UserInput;
use graphics::types::Color; use graphics::types::Color;
use map_model::{IntersectionID, Map}; use map_model::{IntersectionID, Map};
use objects::ID; use objects::{Ctx, ID};
use piston::input::Key; use piston::input::Key;
use plugins::{Colorizer, Ctx}; use plugins::Colorizer;
#[derive(PartialEq)] #[derive(PartialEq)]
pub enum TrafficSignalEditor { pub enum TrafficSignalEditor {

View File

@ -5,9 +5,9 @@ use control::ControlMap;
use ezgui::{GfxCtx, UserInput}; use ezgui::{GfxCtx, UserInput};
use graphics::types::Color; use graphics::types::Color;
use map_model::{IntersectionID, LaneID, Map}; use map_model::{IntersectionID, LaneID, Map};
use objects::ID; use objects::{Ctx, ID};
use piston::input::Key; use piston::input::Key;
use plugins::{Colorizer, Ctx}; use plugins::Colorizer;
use render::DrawMap; use render::DrawMap;
use sim::Sim; use sim::Sim;

View File

@ -1,12 +1,12 @@
// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0 // Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0
use aabb_quadtree::geom::Rect; use aabb_quadtree::geom::Rect;
use colors::{ColorScheme, Colors}; use colors::Colors;
use ezgui::GfxCtx; use ezgui::GfxCtx;
use geom::{PolyLine, Polygon, Pt2D}; use geom::{PolyLine, Polygon, Pt2D};
use graphics; use graphics;
use map_model::{Building, BuildingID, Map}; use map_model::{Building, BuildingID, Map};
use objects::ID; use objects::{Ctx, ID};
use render::{get_bbox, RenderOptions, Renderable, BUILDING_BOUNDARY_THICKNESS}; use render::{get_bbox, RenderOptions, Renderable, BUILDING_BOUNDARY_THICKNESS};
use std::f64; use std::f64;
@ -40,13 +40,13 @@ impl Renderable for DrawBuilding {
} }
// TODO need two colors here // TODO need two colors here
fn draw(&self, g: &mut GfxCtx, opts: RenderOptions, cs: &ColorScheme) { fn draw(&self, g: &mut GfxCtx, opts: RenderOptions, ctx: Ctx) {
//g.draw_polygon(boundary_color, &self.boundary_polygon); //g.draw_polygon(boundary_color, &self.boundary_polygon);
g.draw_polygon(opts.color, &self.fill_polygon); g.draw_polygon(opts.color, &self.fill_polygon);
// TODO tune width // TODO tune width
g.draw_line( g.draw_line(
&graphics::Line::new_round(cs.get(Colors::BuildingPath), 1.0), &graphics::Line::new_round(ctx.cs.get(Colors::BuildingPath), 1.0),
self.front_path, self.front_path,
); );
} }

View File

@ -1,11 +1,10 @@
use aabb_quadtree::geom::Rect; use aabb_quadtree::geom::Rect;
use colors::ColorScheme;
use dimensioned::si; use dimensioned::si;
use ezgui::GfxCtx; use ezgui::GfxCtx;
use geom::{Polygon, Pt2D}; use geom::{Polygon, Pt2D};
use graphics; use graphics;
use map_model::{geometry, Map}; use map_model::{geometry, Map};
use objects::ID; use objects::{Ctx, ID};
use render::{get_bbox, RenderOptions, Renderable}; use render::{get_bbox, RenderOptions, Renderable};
use sim::{CarID, DrawCarInput}; use sim::{CarID, DrawCarInput};
@ -99,7 +98,7 @@ impl Renderable for DrawCar {
ID::Car(self.id) ID::Car(self.id)
} }
fn draw(&self, g: &mut GfxCtx, opts: RenderOptions, _cs: &ColorScheme) { fn draw(&self, g: &mut GfxCtx, opts: RenderOptions, _ctx: Ctx) {
g.draw_polygon(opts.color, &self.body_polygon); g.draw_polygon(opts.color, &self.body_polygon);
for p in &self.window_polygons { for p in &self.window_polygons {
g.draw_polygon([0.0, 0.0, 0.0, 1.0], p); g.draw_polygon([0.0, 0.0, 0.0, 1.0], p);

View File

@ -1,10 +1,9 @@
use aabb_quadtree::geom::Rect; use aabb_quadtree::geom::Rect;
use colors::ColorScheme;
use ezgui::GfxCtx; use ezgui::GfxCtx;
use geom::{Polygon, Pt2D}; use geom::{Polygon, Pt2D};
use kml::{ExtraShape, ExtraShapeGeom, ExtraShapeID}; use kml::{ExtraShape, ExtraShapeGeom, ExtraShapeID};
use map_model::{geometry, Map}; use map_model::{geometry, Map};
use objects::ID; use objects::{Ctx, ID};
use render::{ use render::{
get_bbox, RenderOptions, Renderable, EXTRA_SHAPE_POINT_RADIUS, EXTRA_SHAPE_THICKNESS, get_bbox, RenderOptions, Renderable, EXTRA_SHAPE_POINT_RADIUS, EXTRA_SHAPE_THICKNESS,
}; };
@ -45,7 +44,7 @@ impl Renderable for DrawExtraShape {
ID::ExtraShape(self.id) ID::ExtraShape(self.id)
} }
fn draw(&self, g: &mut GfxCtx, opts: RenderOptions, _cs: &ColorScheme) { fn draw(&self, g: &mut GfxCtx, opts: RenderOptions, _ctx: Ctx) {
match self.shape { match self.shape {
Shape::Polygon(ref p) => g.draw_polygon(opts.color, &p), Shape::Polygon(ref p) => g.draw_polygon(opts.color, &p),
Shape::Circle(c) => g.draw_ellipse(opts.color, c), Shape::Circle(c) => g.draw_ellipse(opts.color, c),

View File

@ -1,14 +1,14 @@
// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0 // Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0
use aabb_quadtree::geom::Rect; use aabb_quadtree::geom::Rect;
use colors::{ColorScheme, Colors}; use colors::Colors;
use dimensioned::si; use dimensioned::si;
use ezgui::GfxCtx; use ezgui::GfxCtx;
use geom::{Line, Polygon, Pt2D}; use geom::{Line, Polygon, Pt2D};
use graphics; use graphics;
use graphics::math::Vec2d; use graphics::math::Vec2d;
use map_model::{geometry, Intersection, IntersectionID, LaneType, Map}; use map_model::{geometry, Intersection, IntersectionID, LaneType, Map};
use objects::ID; use objects::{Ctx, ID};
use render::{get_bbox, DrawLane, RenderOptions, Renderable}; use render::{get_bbox, DrawLane, RenderOptions, Renderable};
use std::f64; use std::f64;
@ -50,20 +50,20 @@ impl DrawIntersection {
} }
} }
fn draw_stop_sign(&self, g: &mut GfxCtx, cs: &ColorScheme) { fn draw_stop_sign(&self, g: &mut GfxCtx, ctx: Ctx) {
// TODO rotate it // TODO rotate it
g.draw_polygon( g.draw_polygon(
cs.get(Colors::StopSignBackground), ctx.cs.get(Colors::StopSignBackground),
&geometry::regular_polygon(self.center, 8, 1.5), &geometry::regular_polygon(self.center, 8, 1.5),
); );
// TODO draw "STOP" // TODO draw "STOP"
} }
fn draw_traffic_signal(&self, g: &mut GfxCtx, cs: &ColorScheme) { fn draw_traffic_signal(&self, g: &mut GfxCtx, ctx: Ctx) {
let radius = 0.5; let radius = 0.5;
g.draw_rectangle( g.draw_rectangle(
cs.get(Colors::TrafficSignalBox), ctx.cs.get(Colors::TrafficSignalBox),
[ [
self.center.x() - (2.0 * radius), self.center.x() - (2.0 * radius),
self.center.y() - (4.0 * radius), self.center.y() - (4.0 * radius),
@ -73,17 +73,17 @@ impl DrawIntersection {
); );
g.draw_ellipse( g.draw_ellipse(
cs.get(Colors::TrafficSignalYellow), ctx.cs.get(Colors::TrafficSignalYellow),
geometry::make_circle(self.center, radius), geometry::make_circle(self.center, radius),
); );
g.draw_ellipse( g.draw_ellipse(
cs.get(Colors::TrafficSignalGreen), ctx.cs.get(Colors::TrafficSignalGreen),
geometry::make_circle(self.center.offset(0.0, radius * 2.0), radius), geometry::make_circle(self.center.offset(0.0, radius * 2.0), radius),
); );
g.draw_ellipse( g.draw_ellipse(
cs.get(Colors::TrafficSignalRed), ctx.cs.get(Colors::TrafficSignalRed),
geometry::make_circle(self.center.offset(0.0, radius * -2.0), radius), geometry::make_circle(self.center.offset(0.0, radius * -2.0), radius),
); );
} }
@ -94,11 +94,11 @@ impl Renderable for DrawIntersection {
ID::Intersection(self.id) ID::Intersection(self.id)
} }
fn draw(&self, g: &mut GfxCtx, opts: RenderOptions, cs: &ColorScheme) { fn draw(&self, g: &mut GfxCtx, opts: RenderOptions, ctx: Ctx) {
g.draw_polygon(opts.color, &self.polygon); g.draw_polygon(opts.color, &self.polygon);
let crosswalk_marking = graphics::Line::new( let crosswalk_marking = graphics::Line::new(
cs.get(Colors::Crosswalk), ctx.cs.get(Colors::Crosswalk),
// TODO move this somewhere // TODO move this somewhere
0.25, 0.25,
); );
@ -112,9 +112,9 @@ impl Renderable for DrawIntersection {
} }
if self.has_traffic_signal { if self.has_traffic_signal {
self.draw_traffic_signal(g, cs); self.draw_traffic_signal(g, ctx);
} else { } else {
self.draw_stop_sign(g, cs); self.draw_stop_sign(g, ctx);
} }
} }

View File

@ -1,15 +1,15 @@
// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0 // Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0
use aabb_quadtree::geom::Rect; use aabb_quadtree::geom::Rect;
use colors::{ColorScheme, Colors}; use colors::Colors;
use control::ControlMap; use control::ControlMap;
use dimensioned::si; use dimensioned::si;
use ezgui::{Canvas, GfxCtx}; use ezgui::GfxCtx;
use geom::{Line, Polygon, Pt2D}; use geom::{Line, Polygon, Pt2D};
use graphics; use graphics;
use map_model; use map_model;
use map_model::{geometry, LaneID}; use map_model::{geometry, LaneID};
use objects::ID; use objects::{Ctx, ID};
use render::{get_bbox, RenderOptions, Renderable, PARCEL_BOUNDARY_THICKNESS}; use render::{get_bbox, RenderOptions, Renderable, PARCEL_BOUNDARY_THICKNESS};
const MIN_ZOOM_FOR_LANE_MARKERS: f64 = 5.0; const MIN_ZOOM_FOR_LANE_MARKERS: f64 = 5.0;
@ -88,14 +88,12 @@ impl DrawLane {
} }
} }
// TODO can't easily call this with generic quadtree fn draw_debug(&self, g: &mut GfxCtx, ctx: Ctx) {
#[allow(dead_code)]
fn draw_debug(&self, g: &mut GfxCtx, canvas: &Canvas, cs: &ColorScheme, l: &map_model::Lane) {
let line = let line =
graphics::Line::new_round(cs.get(Colors::Debug), PARCEL_BOUNDARY_THICKNESS / 2.0); graphics::Line::new_round(ctx.cs.get(Colors::Debug), PARCEL_BOUNDARY_THICKNESS / 2.0);
let circle_color = cs.get(Colors::BrightDebug); let circle_color = ctx.cs.get(Colors::BrightDebug);
for pair in l.lane_center_pts.points().windows(2) { for pair in ctx.map.get_l(self.id).lane_center_pts.points().windows(2) {
let (pt1, pt2) = (pair[0], pair[1]); let (pt1, pt2) = (pair[0], pair[1]);
g.draw_line(&line, [pt1.x(), pt1.y(), pt2.x(), pt2.y()]); g.draw_line(&line, [pt1.x(), pt1.y(), pt2.x(), pt2.y()]);
g.draw_ellipse(circle_color, geometry::make_circle(pt1, 0.4)); g.draw_ellipse(circle_color, geometry::make_circle(pt1, 0.4));
@ -103,7 +101,8 @@ impl DrawLane {
} }
for pt in &self.draw_id_at { for pt in &self.draw_id_at {
canvas.draw_text_at(g, &vec![format!("{}", self.id.0)], pt.x(), pt.y()); ctx.canvas
.draw_text_at(g, &vec![format!("{}", self.id.0)], pt.x(), pt.y());
} }
} }
@ -122,15 +121,15 @@ impl Renderable for DrawLane {
ID::Lane(self.id) ID::Lane(self.id)
} }
fn draw(&self, g: &mut GfxCtx, opts: RenderOptions, cs: &ColorScheme) { fn draw(&self, g: &mut GfxCtx, opts: RenderOptions, ctx: Ctx) {
g.draw_polygon(opts.color, &self.polygon); g.draw_polygon(opts.color, &self.polygon);
if opts.cam_zoom >= MIN_ZOOM_FOR_LANE_MARKERS { if opts.cam_zoom >= MIN_ZOOM_FOR_LANE_MARKERS {
for m in &self.markings { for m in &self.markings {
let line = if m.round { let line = if m.round {
graphics::Line::new_round(cs.get(m.color), m.thickness) graphics::Line::new_round(ctx.cs.get(m.color), m.thickness)
} else { } else {
graphics::Line::new(cs.get(m.color), m.thickness) graphics::Line::new(ctx.cs.get(m.color), m.thickness)
}; };
for pts in &m.lines { for pts in &m.lines {
g.draw_line(&line, *pts); g.draw_line(&line, *pts);
@ -139,8 +138,7 @@ impl Renderable for DrawLane {
} }
if opts.debug_mode { if opts.debug_mode {
// TODO Don't have canvas and map available in draw()... self.draw_debug(g, ctx);
//self.draw_debug(g, canvas, cs, map.get_l(self.id));
} }
} }

View File

@ -11,12 +11,11 @@ mod pedestrian;
mod turn; mod turn;
use aabb_quadtree::geom::{Point, Rect}; use aabb_quadtree::geom::{Point, Rect};
use colors::ColorScheme;
use ezgui::GfxCtx; use ezgui::GfxCtx;
use geom::{Bounds, Pt2D}; use geom::{Bounds, Pt2D};
use graphics::types::Color; use graphics::types::Color;
use map_model::{geometry, Map}; use map_model::{geometry, Map};
use objects::ID; use objects::{Ctx, ID};
pub use render::car::DrawCar; pub use render::car::DrawCar;
pub use render::lane::DrawLane; pub use render::lane::DrawLane;
pub use render::map::DrawMap; pub use render::map::DrawMap;
@ -50,7 +49,7 @@ pub fn get_bbox(b: &Bounds) -> Rect {
pub trait Renderable { pub trait Renderable {
fn get_id(&self) -> ID; fn get_id(&self) -> ID;
fn draw(&self, g: &mut GfxCtx, opts: RenderOptions, cs: &ColorScheme); fn draw(&self, g: &mut GfxCtx, opts: RenderOptions, ctx: Ctx);
// TODO Maybe return Bounds // TODO Maybe return Bounds
fn get_bbox(&self) -> Rect; fn get_bbox(&self) -> Rect;
fn contains_pt(&self, pt: Pt2D) -> bool; fn contains_pt(&self, pt: Pt2D) -> bool;

View File

@ -1,11 +1,10 @@
// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0 // Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0
use aabb_quadtree::geom::Rect; use aabb_quadtree::geom::Rect;
use colors::ColorScheme;
use ezgui::GfxCtx; use ezgui::GfxCtx;
use geom::{PolyLine, Polygon, Pt2D}; use geom::{PolyLine, Polygon, Pt2D};
use map_model::{Map, Parcel, ParcelID}; use map_model::{Map, Parcel, ParcelID};
use objects::ID; use objects::{Ctx, ID};
use render::{get_bbox, RenderOptions, Renderable, PARCEL_BOUNDARY_THICKNESS}; use render::{get_bbox, RenderOptions, Renderable, PARCEL_BOUNDARY_THICKNESS};
#[derive(Debug)] #[derive(Debug)]
@ -32,7 +31,7 @@ impl Renderable for DrawParcel {
ID::Parcel(self.id) ID::Parcel(self.id)
} }
fn draw(&self, g: &mut GfxCtx, opts: RenderOptions, _cs: &ColorScheme) { fn draw(&self, g: &mut GfxCtx, opts: RenderOptions, _ctx: Ctx) {
g.draw_polygon(opts.color, &self.fill_polygon); g.draw_polygon(opts.color, &self.fill_polygon);
} }

View File

@ -1,10 +1,9 @@
use aabb_quadtree::geom::Rect; use aabb_quadtree::geom::Rect;
use colors::ColorScheme;
use ezgui::GfxCtx; use ezgui::GfxCtx;
use geom::Pt2D; use geom::Pt2D;
use graphics; use graphics;
use map_model::{geometry, Map}; use map_model::{geometry, Map};
use objects::ID; use objects::{Ctx, ID};
use render::{RenderOptions, Renderable}; use render::{RenderOptions, Renderable};
use sim::{DrawPedestrianInput, PedestrianID}; use sim::{DrawPedestrianInput, PedestrianID};
@ -41,7 +40,7 @@ impl Renderable for DrawPedestrian {
ID::Pedestrian(self.id) ID::Pedestrian(self.id)
} }
fn draw(&self, g: &mut GfxCtx, opts: RenderOptions, _cs: &ColorScheme) { fn draw(&self, g: &mut GfxCtx, opts: RenderOptions, _ctx: Ctx) {
g.draw_ellipse(opts.color, self.circle); g.draw_ellipse(opts.color, self.circle);
// TODO tune color, sizes // TODO tune color, sizes

View File

@ -1,7 +1,7 @@
// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0 // Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0
use aabb_quadtree::geom::Rect; use aabb_quadtree::geom::Rect;
use colors::{ColorScheme, Colors}; use colors::Colors;
use dimensioned::si; use dimensioned::si;
use ezgui::GfxCtx; use ezgui::GfxCtx;
use geom::Pt2D; use geom::Pt2D;
@ -9,7 +9,7 @@ use graphics;
use graphics::math::Vec2d; use graphics::math::Vec2d;
use graphics::types::Color; use graphics::types::Color;
use map_model::{geometry, Map, Turn, TurnID}; use map_model::{geometry, Map, Turn, TurnID};
use objects::ID; use objects::{Ctx, ID};
use render::{ use render::{
RenderOptions, Renderable, BIG_ARROW_TIP_LENGTH, TURN_ICON_ARROW_LENGTH, RenderOptions, Renderable, BIG_ARROW_TIP_LENGTH, TURN_ICON_ARROW_LENGTH,
TURN_ICON_ARROW_THICKNESS, TURN_ICON_ARROW_TIP_LENGTH, TURN_ICON_ARROW_THICKNESS, TURN_ICON_ARROW_TIP_LENGTH,
@ -78,8 +78,8 @@ impl Renderable for DrawTurn {
ID::Turn(self.id) ID::Turn(self.id)
} }
fn draw(&self, g: &mut GfxCtx, opts: RenderOptions, cs: &ColorScheme) { fn draw(&self, g: &mut GfxCtx, opts: RenderOptions, ctx: Ctx) {
g.draw_ellipse(cs.get(Colors::TurnIconCircle), self.icon_circle); g.draw_ellipse(ctx.cs.get(Colors::TurnIconCircle), self.icon_circle);
g.draw_arrow( g.draw_arrow(
&graphics::Line::new_round(opts.color, TURN_ICON_ARROW_THICKNESS), &graphics::Line::new_round(opts.color, TURN_ICON_ARROW_THICKNESS),

View File

@ -13,7 +13,7 @@ use graphics::types::Color;
use kml; use kml;
use map_model; use map_model;
use map_model::IntersectionID; use map_model::IntersectionID;
use objects::ID; use objects::{Ctx, ID};
use piston::input::{Key, MouseCursorEvent}; use piston::input::{Key, MouseCursorEvent};
use piston::window::Size; use piston::window::Size;
use plugins::classification::OsmClassifier; use plugins::classification::OsmClassifier;
@ -33,7 +33,7 @@ use plugins::traffic_signal_editor::TrafficSignalEditor;
use plugins::turn_colors::TurnColors; use plugins::turn_colors::TurnColors;
use plugins::turn_cycler::TurnCyclerState; use plugins::turn_cycler::TurnCyclerState;
use plugins::warp::WarpState; use plugins::warp::WarpState;
use plugins::{Colorizer, Ctx}; use plugins::Colorizer;
use render::{DrawMap, RenderOptions}; use render::{DrawMap, RenderOptions};
use sim; use sim;
use sim::{CarID, CarState, PedestrianID, Sim}; use sim::{CarID, CarState, PedestrianID, Sim};
@ -332,6 +332,7 @@ impl UI {
cs: &self.cs, cs: &self.cs,
map: &self.map, map: &self.map,
control_map: &self.control_map, control_map: &self.control_map,
canvas: &self.canvas,
}, },
) { ) {
return c; return c;
@ -363,6 +364,7 @@ impl UI {
cs: &self.cs, cs: &self.cs,
map: &self.map, map: &self.map,
control_map: &self.control_map, control_map: &self.control_map,
canvas: &self.canvas,
}, },
) { ) {
return c; return c;
@ -395,6 +397,7 @@ impl UI {
cs: &self.cs, cs: &self.cs,
map: &self.map, map: &self.map,
control_map: &self.control_map, control_map: &self.control_map,
canvas: &self.canvas,
}, },
) { ) {
return c; return c;
@ -417,6 +420,7 @@ impl UI {
cs: &self.cs, cs: &self.cs,
map: &self.map, map: &self.map,
control_map: &self.control_map, control_map: &self.control_map,
canvas: &self.canvas,
}, },
) { ) {
return c; return c;
@ -437,6 +441,7 @@ impl UI {
cs: &self.cs, cs: &self.cs,
map: &self.map, map: &self.map,
control_map: &self.control_map, control_map: &self.control_map,
canvas: &self.canvas,
}, },
) { ) {
return c; return c;
@ -476,6 +481,7 @@ impl UI {
cs: &self.cs, cs: &self.cs,
map: &self.map, map: &self.map,
control_map: &self.control_map, control_map: &self.control_map,
canvas: &self.canvas,
}, },
) { ) {
return c; return c;
@ -502,6 +508,7 @@ impl UI {
cs: &self.cs, cs: &self.cs,
map: &self.map, map: &self.map,
control_map: &self.control_map, control_map: &self.control_map,
canvas: &self.canvas,
}, },
) { ) {
return c; return c;
@ -620,7 +627,16 @@ impl UI {
cam_zoom: self.canvas.cam_zoom, cam_zoom: self.canvas.cam_zoom,
debug_mode: self.layers.debug_mode.is_enabled(), debug_mode: self.layers.debug_mode.is_enabled(),
}; };
obj.draw(g, opts, &self.cs); obj.draw(
g,
opts,
Ctx {
cs: &self.cs,
map: &self.map,
control_map: &self.control_map,
canvas: &self.canvas,
},
);
} }
for obj in dynamics.into_iter() { for obj in dynamics.into_iter() {
let color = match obj.get_id() { let color = match obj.get_id() {
@ -633,7 +649,16 @@ impl UI {
cam_zoom: self.canvas.cam_zoom, cam_zoom: self.canvas.cam_zoom,
debug_mode: self.layers.debug_mode.is_enabled(), debug_mode: self.layers.debug_mode.is_enabled(),
}; };
obj.draw(g, opts, &self.cs); obj.draw(
g,
opts,
Ctx {
cs: &self.cs,
map: &self.map,
control_map: &self.control_map,
canvas: &self.canvas,
},
);
} }
self.turn_cycler.draw( self.turn_cycler.draw(