start a really basic OSD

This commit is contained in:
Dustin Carlino 2019-05-02 12:21:11 -05:00
parent 08e1d3f353
commit 4b4e6f17a0
4 changed files with 51 additions and 2 deletions

View File

@ -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 {

View File

@ -188,6 +188,7 @@ pub enum HorizontalAlignment {
Left,
Center,
Right,
FillScreen,
}
pub enum VerticalAlignment {

View File

@ -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,

View File

@ -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())
}
}