rendering buildings statically

This commit is contained in:
Dustin Carlino 2018-10-06 13:48:08 -07:00
parent b14df8a090
commit 282a4a6712
2 changed files with 50 additions and 18 deletions

View File

@ -55,8 +55,6 @@ impl GUI for UI {
}
fn draw(&self, g: &mut GfxCtx, _osd: Text) {
g.clear([1.0; 4]);
self.draw_map.draw(g);
}
}

View File

@ -1,9 +1,44 @@
use ezgui::GfxCtx;
use geom::Polygon;
use map_model::{Map, Road, RoadID, LANE_THICKNESS};
use geom::{Line, Polygon};
use map_model::{Building, Map, Road, LANE_THICKNESS};
const WHITE: [f32; 4] = [1.0, 1.0, 1.0, 1.0];
const BLACK: [f32; 4] = [0.0, 0.0, 0.0, 1.0];
const RED: [f32; 4] = [1.0, 0.0, 0.0, 1.0];
const BLUE: [f32; 4] = [0.0, 0.0, 1.0, 1.0];
const LINE_WIDTH: f64 = 1.0;
pub struct DrawMap {
roads: Vec<DrawRoad>,
buildings: Vec<DrawBuilding>,
}
impl DrawMap {
pub fn new(map: Map) -> DrawMap {
DrawMap {
roads: map.all_roads().iter().map(|r| DrawRoad::new(r)).collect(),
buildings: map
.all_buildings()
.iter()
.map(|b| DrawBuilding::new(b))
.collect(),
}
}
pub fn draw(&self, g: &mut GfxCtx) {
g.clear(WHITE);
// TODO no pruning yet
for r in &self.roads {
r.draw(g);
}
for b in &self.buildings {
b.draw(g);
}
}
}
struct DrawRoad {
id: RoadID,
polygon: Polygon,
}
@ -12,7 +47,6 @@ impl DrawRoad {
// TODO Should shift if the number of children is uneven
let num_lanes = r.children_forwards.len() + r.children_backwards.len();
DrawRoad {
id: r.id,
polygon: r
.center_pts
.make_polygons_blindly(LANE_THICKNESS * (num_lanes as f64)),
@ -20,25 +54,25 @@ impl DrawRoad {
}
fn draw(&self, g: &mut GfxCtx) {
g.draw_polygon([0.0, 0.0, 0.0, 1.0], &self.polygon);
g.draw_polygon(BLACK, &self.polygon);
}
}
pub struct DrawMap {
roads: Vec<DrawRoad>,
struct DrawBuilding {
polygon: Polygon,
line: Line,
}
impl DrawMap {
pub fn new(map: Map) -> DrawMap {
DrawMap {
roads: map.all_roads().iter().map(|r| DrawRoad::new(r)).collect(),
impl DrawBuilding {
fn new(b: &Building) -> DrawBuilding {
DrawBuilding {
polygon: Polygon::new(&b.points),
line: b.front_path.line.clone(),
}
}
pub fn draw(&self, g: &mut GfxCtx) {
// TODO no pruning yet
for r in &self.roads {
r.draw(g);
}
fn draw(&self, g: &mut GfxCtx) {
g.draw_polygon(RED, &self.polygon);
g.draw_rounded_line(BLUE, LINE_WIDTH, &self.line);
}
}