From 4b4e6f17a0e029d3e0a451716742319339a25f09 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Thu, 2 May 2019 12:21:11 -0500 Subject: [PATCH] start a really basic OSD --- editor/src/common/mod.rs | 32 +++++++++++++++++++++++++++++++- ezgui/src/canvas.rs | 1 + ezgui/src/drawing.rs | 6 +++++- map_model/src/building.rs | 14 ++++++++++++++ 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/editor/src/common/mod.rs b/editor/src/common/mod.rs index b59d29010c..559173e028 100644 --- a/editor/src/common/mod.rs +++ b/editor/src/common/mod.rs @@ -7,7 +7,9 @@ use crate::helpers::ID; use crate::render::DrawOptions; use crate::ui::UI; use abstutil::elapsed_seconds; -use ezgui::{EventCtx, EventLoopMode, GfxCtx, Key}; +use ezgui::{ + Color, EventCtx, EventLoopMode, GfxCtx, HorizontalAlignment, Key, Text, VerticalAlignment, +}; use geom::{Line, Pt2D}; use std::time::Instant; @@ -71,6 +73,34 @@ impl CommonState { navigate.draw(g); } self.turn_cycler.draw(g, ui); + + let id_color = ui.cs.get_def("OSD ID color", Color::RED); + let name_color = ui.cs.get_def("OSD name color", Color::CYAN); + let mut osd = Text::new(); + match ui.primary.current_selection { + None => { + osd.append("...".to_string(), None); + } + Some(ID::Lane(l)) => { + osd.append(format!("{}", l), Some(id_color)); + osd.append(" is ".to_string(), None); + osd.append(ui.primary.map.get_parent(l).get_name(), Some(name_color)); + } + Some(ID::Building(b)) => { + osd.append(format!("{}", b), Some(id_color)); + osd.append(" is ".to_string(), None); + osd.append(ui.primary.map.get_b(b).get_name(), Some(name_color)); + } + // TODO Intersections, cars, pedestrians... + Some(id) => { + osd.append(format!("{:?}", id), Some(id_color)); + } + } + // TODO Grab hotkeys from the context menu + g.draw_blocking_text( + &osd, + (HorizontalAlignment::FillScreen, VerticalAlignment::Bottom), + ); } pub fn draw_options(&self, ui: &UI) -> DrawOptions { diff --git a/ezgui/src/canvas.rs b/ezgui/src/canvas.rs index 6ac788ec47..bd2de9f051 100644 --- a/ezgui/src/canvas.rs +++ b/ezgui/src/canvas.rs @@ -188,6 +188,7 @@ pub enum HorizontalAlignment { Left, Center, Right, + FillScreen, } pub enum VerticalAlignment { diff --git a/ezgui/src/drawing.rs b/ezgui/src/drawing.rs index 3fe7dd8bed..5fc8371ab9 100644 --- a/ezgui/src/drawing.rs +++ b/ezgui/src/drawing.rs @@ -153,11 +153,15 @@ impl<'a> GfxCtx<'a> { if txt.is_empty() { return; } - let (width, height) = self.text_dims(&txt); + let (mut width, height) = self.text_dims(&txt); let x1 = match horiz { HorizontalAlignment::Left => 0.0, HorizontalAlignment::Center => (self.canvas.window_width - width) / 2.0, HorizontalAlignment::Right => self.canvas.window_width - width, + HorizontalAlignment::FillScreen => { + width = self.canvas.window_width; + 0.0 + } }; let y1 = match vert { VerticalAlignment::Top => 0.0, diff --git a/map_model/src/building.rs b/map_model/src/building.rs index f799240e4d..38e5158b9a 100644 --- a/map_model/src/building.rs +++ b/map_model/src/building.rs @@ -50,4 +50,18 @@ impl Building { pub fn sidewalk(&self) -> LaneID { self.front_path.sidewalk.lane() } + + pub fn get_name(&self) -> String { + self.osm_tags + .get("name") + .map(|s| s.to_string()) + .or_else(|| { + self.osm_tags.get("addr:housenumber").and_then(|num| { + self.osm_tags + .get("addr:street") + .map(|street| format!("{} {}", num, street)) + }) + }) + .unwrap_or("???".to_string()) + } }