mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-25 11:44:25 +03:00
rendering for areas
This commit is contained in:
parent
966d7bb03d
commit
361755400d
@ -299,6 +299,18 @@
|
||||
0.0,
|
||||
0.0,
|
||||
1.0
|
||||
],
|
||||
"ParkArea": [
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
1.0
|
||||
],
|
||||
"WaterArea": [
|
||||
0.0,
|
||||
0.0,
|
||||
1.0,
|
||||
1.0
|
||||
]
|
||||
}
|
||||
}
|
@ -81,6 +81,9 @@ pub enum Colors {
|
||||
TrafficSignalRed,
|
||||
|
||||
StopSignBackground,
|
||||
|
||||
ParkArea,
|
||||
WaterArea,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
|
@ -2,7 +2,7 @@ use colors::ColorScheme;
|
||||
use control::ControlMap;
|
||||
use ezgui::Canvas;
|
||||
use kml::ExtraShapeID;
|
||||
use map_model::{BuildingID, BusStopID, IntersectionID, LaneID, Map, ParcelID, TurnID};
|
||||
use map_model::{AreaID, BuildingID, BusStopID, IntersectionID, LaneID, Map, ParcelID, TurnID};
|
||||
use render::{DrawMap, Renderable};
|
||||
use sim::{CarID, PedestrianID, Sim};
|
||||
|
||||
@ -17,6 +17,7 @@ pub enum ID {
|
||||
ExtraShape(ExtraShapeID),
|
||||
Parcel(ParcelID),
|
||||
BusStop(BusStopID),
|
||||
Area(AreaID),
|
||||
}
|
||||
|
||||
impl ID {
|
||||
@ -46,6 +47,9 @@ impl ID {
|
||||
ID::BusStop(id) => {
|
||||
map.get_bs(id).dump_debug();
|
||||
}
|
||||
ID::Area(id) => {
|
||||
map.get_a(id).dump_debug();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,6 +65,7 @@ impl ID {
|
||||
ID::ExtraShape(id) => draw_map.get_es(id).tooltip_lines(map),
|
||||
ID::BusStop(id) => draw_map.get_bs(id).tooltip_lines(map),
|
||||
ID::Parcel(id) => vec![format!("{}", id)],
|
||||
ID::Area(id) => vec![format!("{}", id)],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
use ezgui::{Canvas, TextBox, UserInput};
|
||||
use map_model::{geometry, BuildingID, IntersectionID, LaneID, Map, ParcelID, RoadID};
|
||||
use map_model::{geometry, AreaID, BuildingID, IntersectionID, LaneID, Map, ParcelID, RoadID};
|
||||
use objects::ID;
|
||||
use piston::input::Key;
|
||||
use plugins::Colorizer;
|
||||
@ -109,6 +109,17 @@ fn warp(line: String, map: &Map, sim: &Sim, canvas: &mut Canvas, selected: &mut
|
||||
return;
|
||||
}
|
||||
}
|
||||
'a' => {
|
||||
let id = AreaID(idx);
|
||||
if let Some(a) = map.maybe_get_a(id) {
|
||||
println!("Warping to {}", id);
|
||||
*selected = Some(ID::Area(id));
|
||||
geometry::center(&a.points)
|
||||
} else {
|
||||
println!("{} doesn't exist", id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// TODO ideally "pa" prefix?
|
||||
'e' => {
|
||||
let id = ParcelID(idx);
|
||||
|
57
editor/src/render/area.rs
Normal file
57
editor/src/render/area.rs
Normal file
@ -0,0 +1,57 @@
|
||||
use aabb_quadtree::geom::Rect;
|
||||
use colors::Colors;
|
||||
use ezgui::GfxCtx;
|
||||
use geom::{Polygon, Pt2D};
|
||||
use map_model::{Area, AreaID, AreaType, Map};
|
||||
use objects::{Ctx, ID};
|
||||
use render::{get_bbox, RenderOptions, Renderable};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DrawArea {
|
||||
pub id: AreaID,
|
||||
fill_polygon: Polygon,
|
||||
color: Colors,
|
||||
}
|
||||
|
||||
impl DrawArea {
|
||||
pub fn new(area: &Area) -> DrawArea {
|
||||
DrawArea {
|
||||
id: area.id,
|
||||
fill_polygon: Polygon::new(&area.points),
|
||||
color: match area.area_type {
|
||||
AreaType::Park => Colors::ParkArea,
|
||||
AreaType::Water => Colors::WaterArea,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Renderable for DrawArea {
|
||||
fn get_id(&self) -> ID {
|
||||
ID::Area(self.id)
|
||||
}
|
||||
|
||||
fn draw(&self, g: &mut GfxCtx, opts: RenderOptions, ctx: Ctx) {
|
||||
g.draw_polygon(
|
||||
opts.color.unwrap_or(ctx.cs.get(Colors::Building)),
|
||||
&self.fill_polygon,
|
||||
);
|
||||
}
|
||||
|
||||
fn get_bbox(&self) -> Rect {
|
||||
get_bbox(&self.fill_polygon.get_bounds())
|
||||
}
|
||||
|
||||
fn contains_pt(&self, pt: Pt2D) -> bool {
|
||||
self.fill_polygon.contains_pt(pt)
|
||||
}
|
||||
|
||||
fn tooltip_lines(&self, map: &Map) -> Vec<String> {
|
||||
let a = map.get_a(self.id);
|
||||
let mut lines = vec![format!("{} (from OSM way {})", self.id, a.osm_way_id)];
|
||||
for (k, v) in &a.osm_tags {
|
||||
lines.push(format!("{} = {}", k, v));
|
||||
}
|
||||
lines
|
||||
}
|
||||
}
|
@ -5,9 +5,12 @@ use aabb_quadtree::QuadTree;
|
||||
use control::ControlMap;
|
||||
use geom::{LonLat, Pt2D};
|
||||
use kml::{ExtraShape, ExtraShapeID};
|
||||
use map_model::{BuildingID, BusStopID, IntersectionID, Lane, LaneID, Map, ParcelID, Turn, TurnID};
|
||||
use map_model::{
|
||||
AreaID, BuildingID, BusStopID, IntersectionID, Lane, LaneID, Map, ParcelID, Turn, TurnID,
|
||||
};
|
||||
use objects::ID;
|
||||
use plugins::hider::Hider;
|
||||
use render::area::DrawArea;
|
||||
use render::building::DrawBuilding;
|
||||
use render::bus_stop::DrawBusStop;
|
||||
use render::car::DrawCar;
|
||||
@ -30,6 +33,7 @@ pub struct DrawMap {
|
||||
pub parcels: Vec<DrawParcel>,
|
||||
pub extra_shapes: Vec<DrawExtraShape>,
|
||||
pub bus_stops: HashMap<BusStopID, DrawBusStop>,
|
||||
pub areas: Vec<DrawArea>,
|
||||
|
||||
quadtree: QuadTree<ID>,
|
||||
}
|
||||
@ -79,6 +83,7 @@ impl DrawMap {
|
||||
for s in map.all_bus_stops().values() {
|
||||
bus_stops.insert(s.id, DrawBusStop::new(s, map));
|
||||
}
|
||||
let areas: Vec<DrawArea> = map.all_areas().iter().map(|a| DrawArea::new(a)).collect();
|
||||
|
||||
// min_y here due to the wacky y inversion
|
||||
let bounds = map.get_gps_bounds();
|
||||
@ -111,6 +116,9 @@ impl DrawMap {
|
||||
for obj in bus_stops.values() {
|
||||
quadtree.insert_with_box(obj.get_id(), obj.get_bbox());
|
||||
}
|
||||
for obj in &areas {
|
||||
quadtree.insert_with_box(obj.get_id(), obj.get_bbox());
|
||||
}
|
||||
|
||||
(
|
||||
DrawMap {
|
||||
@ -121,6 +129,7 @@ impl DrawMap {
|
||||
parcels,
|
||||
extra_shapes,
|
||||
bus_stops,
|
||||
areas,
|
||||
|
||||
quadtree,
|
||||
},
|
||||
@ -195,6 +204,10 @@ impl DrawMap {
|
||||
&self.bus_stops[&id]
|
||||
}
|
||||
|
||||
pub fn get_a(&self, id: AreaID) -> &DrawArea {
|
||||
&self.areas[id.0]
|
||||
}
|
||||
|
||||
// Returns in back-to-front order
|
||||
// The second pair is ephemeral objects (cars, pedestrians) that we can't borrow --
|
||||
// conveniently they're the front-most layer, so the caller doesn't have to do anything strange
|
||||
@ -213,6 +226,7 @@ impl DrawMap {
|
||||
show_turn_icons: &T,
|
||||
) -> (Vec<Box<&Renderable>>, Vec<Box<Renderable>>) {
|
||||
// From background to foreground Z-order
|
||||
let mut areas: Vec<Box<&Renderable>> = Vec::new();
|
||||
let mut parcels: Vec<Box<&Renderable>> = Vec::new();
|
||||
let mut lanes: Vec<Box<&Renderable>> = Vec::new();
|
||||
let mut intersections: Vec<Box<&Renderable>> = Vec::new();
|
||||
@ -227,6 +241,7 @@ impl DrawMap {
|
||||
for &(id, _, _) in &self.quadtree.query(screen_bbox) {
|
||||
if hider.show(*id) && layers.show(*id) {
|
||||
match id {
|
||||
ID::Area(id) => areas.push(Box::new(self.get_a(*id))),
|
||||
ID::Parcel(id) => parcels.push(Box::new(self.get_p(*id))),
|
||||
ID::Lane(id) => {
|
||||
lanes.push(Box::new(self.get_l(*id)));
|
||||
@ -266,6 +281,7 @@ impl DrawMap {
|
||||
}
|
||||
|
||||
let mut borrows: Vec<Box<&Renderable>> = Vec::new();
|
||||
borrows.extend(areas);
|
||||
borrows.extend(parcels);
|
||||
borrows.extend(lanes);
|
||||
borrows.extend(intersections);
|
||||
|
@ -1,5 +1,6 @@
|
||||
// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
mod area;
|
||||
mod building;
|
||||
mod bus_stop;
|
||||
mod car;
|
||||
@ -17,6 +18,7 @@ use geom::{Bounds, Pt2D};
|
||||
use graphics::types::Color;
|
||||
use map_model::{geometry, Map};
|
||||
use objects::{Ctx, ID};
|
||||
pub use render::area::DrawArea;
|
||||
pub use render::car::DrawCar;
|
||||
pub use render::lane::DrawLane;
|
||||
pub use render::map::DrawMap;
|
||||
|
@ -198,6 +198,7 @@ impl Map {
|
||||
}
|
||||
|
||||
for (idx, a) in data.areas.iter().enumerate() {
|
||||
assert_eq!(a.points[0], *a.points.last().unwrap());
|
||||
m.areas.push(Area {
|
||||
id: AreaID(idx),
|
||||
area_type: a.area_type,
|
||||
@ -287,6 +288,10 @@ impl Map {
|
||||
self.parcels.get(id.0)
|
||||
}
|
||||
|
||||
pub fn maybe_get_a(&self, id: AreaID) -> Option<&Area> {
|
||||
self.areas.get(id.0)
|
||||
}
|
||||
|
||||
pub fn get_r(&self, id: RoadID) -> &Road {
|
||||
&self.roads[id.0]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user