mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 09:24:26 +03:00
drawing turns at a stop sign
This commit is contained in:
parent
545b96a74a
commit
6295d6b2e7
@ -1,8 +1,9 @@
|
||||
use ezgui::Color;
|
||||
use ezgui::{Color, GfxCtx};
|
||||
use map_model::{ControlStopSign, IntersectionID, TurnPriority};
|
||||
use objects::{Ctx, ID};
|
||||
use piston::input::Key;
|
||||
use plugins::{Plugin, PluginCtx};
|
||||
use render::draw_stop_sign;
|
||||
|
||||
#[derive(PartialEq)]
|
||||
pub enum StopSignEditor {
|
||||
@ -83,6 +84,15 @@ impl Plugin for StopSignEditor {
|
||||
}
|
||||
}
|
||||
|
||||
fn draw(&self, g: &mut GfxCtx, ctx: Ctx) {
|
||||
match self {
|
||||
StopSignEditor::Inactive => {}
|
||||
StopSignEditor::Active(id) => {
|
||||
draw_stop_sign(ctx.map.get_stop_sign(*id), g, ctx.cs, ctx.map);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn color_for(&self, obj: ID, ctx: Ctx) -> Option<Color> {
|
||||
match (self, obj) {
|
||||
(StopSignEditor::Active(i), ID::Turn(t)) => {
|
||||
@ -93,10 +103,7 @@ impl Plugin for StopSignEditor {
|
||||
TurnPriority::Priority => {
|
||||
Some(ctx.cs.get("priority stop sign turn", Color::GREEN))
|
||||
}
|
||||
TurnPriority::Yield => Some(
|
||||
ctx.cs
|
||||
.get("yield stop sign turn", Color::rgb(255, 105, 180)),
|
||||
),
|
||||
TurnPriority::Yield => Some(ctx.cs.get("yield stop sign turn", Color::YELLOW)),
|
||||
TurnPriority::Stop => Some(ctx.cs.get("stop turn", Color::RED)),
|
||||
TurnPriority::Banned => Some(ctx.cs.get("banned turn", Color::BLACK)),
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ use map_model::{IntersectionID, LaneID, TurnType};
|
||||
use objects::{Ctx, ID};
|
||||
use piston::input::Key;
|
||||
use plugins::{Plugin, PluginCtx};
|
||||
use render::{draw_signal_cycle, DrawTurn};
|
||||
use render::{draw_signal_cycle, draw_stop_sign, DrawTurn};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum TurnCyclerState {
|
||||
@ -138,6 +138,8 @@ impl Plugin for TurnCyclerState {
|
||||
);
|
||||
g.unfork(old_ctx);
|
||||
}
|
||||
} else if let Some(sign) = ctx.map.maybe_get_stop_sign(*id) {
|
||||
draw_stop_sign(sign, g, ctx.cs, ctx.map);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,12 @@
|
||||
use colors::ColorScheme;
|
||||
use dimensioned::si;
|
||||
use ezgui::{Color, GfxCtx};
|
||||
use geom::{Angle, Bounds, Circle, Line, Polygon, Pt2D};
|
||||
use geom::{Angle, Bounds, Circle, Polygon, Pt2D};
|
||||
use map_model::{
|
||||
Cycle, Intersection, IntersectionID, IntersectionType, Map, TurnID, TurnType, LANE_THICKNESS,
|
||||
ControlStopSign, Cycle, Intersection, IntersectionID, IntersectionType, Map, TurnID,
|
||||
TurnPriority, TurnType, LANE_THICKNESS,
|
||||
};
|
||||
use objects::{Ctx, ID};
|
||||
use render::{
|
||||
DrawCrosswalk, DrawMap, DrawTurn, RenderOptions, Renderable, BIG_ARROW_THICKNESS,
|
||||
BIG_ARROW_TIP_LENGTH,
|
||||
};
|
||||
use render::{DrawCrosswalk, DrawMap, DrawTurn, RenderOptions, Renderable};
|
||||
use std::collections::HashSet;
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -195,29 +192,43 @@ pub fn draw_signal_cycle(
|
||||
for t in &cycle.yield_turns {
|
||||
let turn = map.get_t(*t);
|
||||
if !turn.between_sidewalks() {
|
||||
let dash_len = 1.0 * si::M;
|
||||
for poly in turn
|
||||
.geom
|
||||
.dashed_polygons(BIG_ARROW_THICKNESS, dash_len, 0.5 * si::M)
|
||||
.into_iter()
|
||||
{
|
||||
g.draw_polygon(yield_color, &poly);
|
||||
}
|
||||
// And a cap on the arrow. In case the last line is long, trim it to be the dash
|
||||
// length.
|
||||
let last_line = turn.geom.last_line();
|
||||
let last_len = last_line.length();
|
||||
let arrow_line = if last_len <= dash_len {
|
||||
last_line
|
||||
} else {
|
||||
Line::new(last_line.dist_along(last_len - dash_len), last_line.pt2())
|
||||
};
|
||||
g.draw_rounded_arrow(
|
||||
yield_color,
|
||||
BIG_ARROW_THICKNESS / 2.0,
|
||||
BIG_ARROW_TIP_LENGTH,
|
||||
&arrow_line,
|
||||
);
|
||||
DrawTurn::draw_dashed(turn, g, yield_color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn draw_stop_sign(sign: &ControlStopSign, g: &mut GfxCtx, cs: &mut ColorScheme, map: &Map) {
|
||||
let priority_color = cs.get("stop sign priority turns", Color::GREEN);
|
||||
// TODO pink yield color from traffic signals is nice, but it's too close to red for stop...
|
||||
let yield_color = cs.get("stop sign yield turns", Color::YELLOW.alpha(0.8));
|
||||
let stop_color = cs.get("stop sign stop turns", Color::RED.alpha(0.8));
|
||||
|
||||
// TODO first crosswalks... actually, give rendering hints to override the color. dont do that
|
||||
// here.
|
||||
|
||||
// First draw solid-line priority turns.
|
||||
for (t, priority) in &sign.turns {
|
||||
let turn = map.get_t(*t);
|
||||
if turn.between_sidewalks() || *priority != TurnPriority::Priority {
|
||||
continue;
|
||||
}
|
||||
DrawTurn::draw_full(turn, g, priority_color);
|
||||
}
|
||||
|
||||
// Then dashed lines.
|
||||
for (t, priority) in &sign.turns {
|
||||
let turn = map.get_t(*t);
|
||||
if turn.between_sidewalks() {
|
||||
continue;
|
||||
}
|
||||
match *priority {
|
||||
TurnPriority::Yield => {
|
||||
DrawTurn::draw_dashed(turn, g, yield_color);
|
||||
}
|
||||
TurnPriority::Stop => {
|
||||
DrawTurn::draw_dashed(turn, g, stop_color);
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ pub use render::area::DrawArea;
|
||||
use render::bike::DrawBike;
|
||||
use render::car::DrawCar;
|
||||
pub use render::extra_shape::ExtraShapeID;
|
||||
pub use render::intersection::draw_signal_cycle;
|
||||
pub use render::intersection::{draw_signal_cycle, draw_stop_sign};
|
||||
pub use render::lane::DrawLane;
|
||||
pub use render::map::DrawMap;
|
||||
pub use render::pedestrian::DrawPedestrian;
|
||||
|
@ -53,6 +53,32 @@ impl DrawTurn {
|
||||
&t.geom.last_line(),
|
||||
);
|
||||
}
|
||||
|
||||
pub fn draw_dashed(turn: &Turn, g: &mut GfxCtx, color: Color) {
|
||||
let dash_len = 1.0 * si::M;
|
||||
for poly in turn
|
||||
.geom
|
||||
.dashed_polygons(BIG_ARROW_THICKNESS, dash_len, 0.5 * si::M)
|
||||
.into_iter()
|
||||
{
|
||||
g.draw_polygon(color, &poly);
|
||||
}
|
||||
// And a cap on the arrow. In case the last line is long, trim it to be the dash
|
||||
// length.
|
||||
let last_line = turn.geom.last_line();
|
||||
let last_len = last_line.length();
|
||||
let arrow_line = if last_len <= dash_len {
|
||||
last_line
|
||||
} else {
|
||||
Line::new(last_line.dist_along(last_len - dash_len), last_line.pt2())
|
||||
};
|
||||
g.draw_rounded_arrow(
|
||||
color,
|
||||
BIG_ARROW_THICKNESS / 2.0,
|
||||
BIG_ARROW_TIP_LENGTH,
|
||||
&arrow_line,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Little weird, but this is focused on the turn icon, not the full visualization
|
||||
|
@ -10,7 +10,7 @@ pub struct ControlStopSign {
|
||||
serialize_with = "serialize_btreemap",
|
||||
deserialize_with = "deserialize_btreemap"
|
||||
)]
|
||||
turns: BTreeMap<TurnID, TurnPriority>,
|
||||
pub turns: BTreeMap<TurnID, TurnPriority>,
|
||||
pub(crate) changed: bool,
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user