mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-25 11:44:25 +03:00
batch turn icon drawing in editors
This commit is contained in:
parent
ec015624c0
commit
808d4b2718
@ -4,7 +4,7 @@ use crate::game::GameState;
|
||||
use crate::helpers::ID;
|
||||
use crate::render::{DrawOptions, DrawTurn};
|
||||
use crate::ui::{ShowEverything, UI};
|
||||
use ezgui::{Color, EventCtx, GfxCtx, Key, ModalMenu, Text};
|
||||
use ezgui::{Color, EventCtx, GeomBatch, GfxCtx, Key, ModalMenu, Text};
|
||||
use geom::{Angle, Distance, Polygon, Pt2D};
|
||||
use map_model::{IntersectionID, RoadID, TurnID, TurnPriority};
|
||||
use std::collections::HashMap;
|
||||
@ -139,9 +139,13 @@ impl StopSignEditor {
|
||||
let map = &state.ui.primary.map;
|
||||
let sign = map.get_stop_sign(self.id);
|
||||
|
||||
let mut batch = GeomBatch::new();
|
||||
|
||||
for (r, octagon) in &self.octagons {
|
||||
g.draw_polygon(
|
||||
if sign.roads[r].enabled {
|
||||
batch.push(
|
||||
if Some(*r) == self.selected_sign {
|
||||
state.ui.cs.get("selected")
|
||||
} else if sign.roads[r].enabled {
|
||||
state.ui.cs.get_def("enabled stop sign octagon", Color::RED)
|
||||
} else {
|
||||
state
|
||||
@ -149,15 +153,8 @@ impl StopSignEditor {
|
||||
.cs
|
||||
.get_def("disabled stop sign octagon", Color::RED.alpha(0.2))
|
||||
},
|
||||
octagon,
|
||||
octagon.clone(),
|
||||
);
|
||||
if Some(*r) == self.selected_sign {
|
||||
g.draw_polygon(
|
||||
state.ui.cs.get("selected"),
|
||||
// TODO Just the boundary?
|
||||
&self.octagons[r],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for t in &state.ui.primary.draw_map.get_turns(self.id, map) {
|
||||
@ -169,20 +166,21 @@ impl StopSignEditor {
|
||||
TurnPriority::Stop => state.ui.cs.get_def("stop turn", Color::RED),
|
||||
TurnPriority::Banned => state.ui.cs.get_def("banned turn", Color::BLACK),
|
||||
};
|
||||
t.draw(g, &state.ui.cs, color);
|
||||
t.draw_icon(&mut batch, &state.ui.cs, color);
|
||||
}
|
||||
if let Some(id) = self.selected_turn {
|
||||
g.draw_polygon(
|
||||
batch.push(
|
||||
state.ui.cs.get("selected"),
|
||||
// TODO thin ring
|
||||
&state.ui.primary.draw_map.get_t(id).icon_circle.to_polygon(),
|
||||
state.ui.primary.draw_map.get_t(id).icon_circle.to_polygon(),
|
||||
);
|
||||
DrawTurn::draw_dashed(
|
||||
map.get_t(id),
|
||||
g,
|
||||
&mut batch,
|
||||
state.ui.cs.get_def("selected turn", Color::RED),
|
||||
);
|
||||
}
|
||||
batch.draw(g);
|
||||
|
||||
self.menu.draw(g);
|
||||
if let Some(r) = self.selected_sign {
|
||||
|
@ -5,7 +5,7 @@ use crate::helpers::ID;
|
||||
use crate::render::{draw_signal_cycle, draw_signal_diagram, DrawCtx, DrawOptions, DrawTurn};
|
||||
use crate::ui::{ShowEverything, UI};
|
||||
use abstutil::Timer;
|
||||
use ezgui::{Color, EventCtx, GfxCtx, Key, ModalMenu, ScreenPt, Wizard, WrappedWizard};
|
||||
use ezgui::{Color, EventCtx, GeomBatch, GfxCtx, Key, ModalMenu, ScreenPt, Wizard, WrappedWizard};
|
||||
use geom::Duration;
|
||||
use map_model::{ControlTrafficSignal, Cycle, IntersectionID, Map, TurnID, TurnPriority, TurnType};
|
||||
|
||||
@ -233,6 +233,7 @@ impl TrafficSignalEditor {
|
||||
.draw(g, opts, &state.ui.primary.sim, &ShowEverything::new());
|
||||
}
|
||||
|
||||
let mut batch = GeomBatch::new();
|
||||
let ctx = DrawCtx {
|
||||
cs: &state.ui.cs,
|
||||
map: &state.ui.primary.map,
|
||||
@ -257,17 +258,18 @@ impl TrafficSignalEditor {
|
||||
.get_def("turn not in current cycle", Color::BLACK),
|
||||
TurnPriority::Stop => panic!("Can't have TurnPriority::Stop in a traffic signal"),
|
||||
};
|
||||
t.draw(g, &ctx.cs, color);
|
||||
t.draw_icon(&mut batch, &ctx.cs, color);
|
||||
}
|
||||
draw_signal_cycle(cycle, None, g, &ctx);
|
||||
if let Some(id) = self.icon_selected {
|
||||
g.draw_polygon(
|
||||
batch.push(
|
||||
state.ui.cs.get("selected"),
|
||||
// TODO thin ring
|
||||
&state.ui.primary.draw_map.get_t(id).icon_circle.to_polygon(),
|
||||
state.ui.primary.draw_map.get_t(id).icon_circle.to_polygon(),
|
||||
);
|
||||
DrawTurn::draw_dashed(map.get_t(id), g, state.ui.cs.get("selected turn"));
|
||||
DrawTurn::draw_dashed(map.get_t(id), &mut batch, state.ui.cs.get("selected turn"));
|
||||
}
|
||||
batch.draw(g);
|
||||
|
||||
draw_signal_diagram(
|
||||
self.i,
|
||||
|
@ -52,12 +52,13 @@ impl DrawTurn {
|
||||
}*/
|
||||
}
|
||||
|
||||
pub fn draw_dashed(turn: &Turn, g: &mut GfxCtx, color: Color) {
|
||||
pub fn draw_dashed(turn: &Turn, batch: &mut GeomBatch, color: Color) {
|
||||
let dash_len = Distance::meters(1.0);
|
||||
let dashed =
|
||||
batch.extend(
|
||||
color,
|
||||
turn.geom
|
||||
.dashed_polygons(BIG_ARROW_THICKNESS, dash_len, Distance::meters(0.5));
|
||||
g.draw_polygons(color, &dashed);
|
||||
.dashed_polygons(BIG_ARROW_THICKNESS, dash_len, Distance::meters(0.5)),
|
||||
);
|
||||
// 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();
|
||||
@ -67,7 +68,13 @@ impl DrawTurn {
|
||||
} else {
|
||||
Line::new(last_line.dist_along(last_len - dash_len), last_line.pt2())
|
||||
};
|
||||
g.draw_arrow(color, BIG_ARROW_THICKNESS, &arrow_line);
|
||||
batch.extend(
|
||||
color,
|
||||
arrow_line
|
||||
.to_polyline()
|
||||
.make_arrow(BIG_ARROW_THICKNESS)
|
||||
.unwrap(),
|
||||
);
|
||||
}
|
||||
|
||||
pub fn outline_geom(turn: &Turn, batch: &mut GeomBatch, color: Color) {
|
||||
@ -79,13 +86,18 @@ impl DrawTurn {
|
||||
);
|
||||
}
|
||||
|
||||
pub fn draw(&self, g: &mut GfxCtx, cs: &ColorScheme, arrow_color: Color) {
|
||||
g.draw_circle(
|
||||
pub fn draw_icon(&self, batch: &mut GeomBatch, cs: &ColorScheme, arrow_color: Color) {
|
||||
batch.push(
|
||||
cs.get_def("turn icon circle", Color::grey(0.6)),
|
||||
&self.icon_circle,
|
||||
self.icon_circle.to_polygon(),
|
||||
);
|
||||
batch.extend(
|
||||
arrow_color,
|
||||
self.icon_arrow
|
||||
.to_polyline()
|
||||
.make_arrow(TURN_ICON_ARROW_THICKNESS)
|
||||
.unwrap(),
|
||||
);
|
||||
|
||||
g.draw_arrow(arrow_color, TURN_ICON_ARROW_THICKNESS, &self.icon_arrow);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user