mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-26 07:52:05 +03:00
draw text in map-space, except drawing zoomed-in text is extremely slow!
This commit is contained in:
parent
320c91faf7
commit
e627930757
@ -254,5 +254,6 @@ Forget top menu, modal menu, OSD, right-click menus, all the current GUI things.
|
||||
- this makes sense as a separate thing, to visualize the edits and make sure to save them
|
||||
- and to make it clear that there's no mixing with a running sim
|
||||
- but how fluidly should this be enterable from the sandbox mode?
|
||||
- replace with OSD with a little summary thing.. "sidewalk of 5th Ave"
|
||||
- debug mode
|
||||
- stuff like tooltips, warp, search only belong here... until i make more generally usable navigation tools
|
||||
|
@ -78,7 +78,7 @@ impl AmbientPlugin for NeighborhoodSummary {
|
||||
|
||||
g.redraw(&self.draw_all_regions);
|
||||
for r in &self.regions {
|
||||
g.draw_text_at(&r.summary, r.center);
|
||||
g.draw_text_at_mapspace(&r.summary, r.center);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -118,7 +118,8 @@ impl Region {
|
||||
|
||||
fn update_summary(&mut self, primary: &Sim, maybe_secondary: Option<&Sim>) {
|
||||
let mut txt = Text::new();
|
||||
txt.add_line(format!("{} has {} lanes", self.name, self.lanes.len()));
|
||||
txt.add_styled_line(self.name.clone(), None, Some(Color::GREEN), Some(50));
|
||||
txt.add_line(format!("contains {} lanes", self.lanes.len()));
|
||||
|
||||
if let Some(secondary) = maybe_secondary {
|
||||
// TODO colors
|
||||
|
@ -186,6 +186,16 @@ impl<'a> GfxCtx<'a> {
|
||||
);
|
||||
}
|
||||
|
||||
pub fn draw_text_at_mapspace(&mut self, txt: &Text, map_pt: Pt2D) {
|
||||
let (width, height) = self.text_dims(&txt);
|
||||
text::draw_text_bubble_mapspace(
|
||||
self,
|
||||
Pt2D::new(map_pt.x() - (width / 2.0), map_pt.y() - (height / 2.0)),
|
||||
txt,
|
||||
(width, height),
|
||||
);
|
||||
}
|
||||
|
||||
pub fn text_dims(&self, txt: &Text) -> (f64, f64) {
|
||||
self.canvas.text_dims(txt)
|
||||
}
|
||||
|
@ -210,3 +210,59 @@ pub fn draw_text_bubble(
|
||||
y2: top_left.y + total_height,
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Painfully slow at high zooms. Maybe need to use draw_queued_with_transform, expose a
|
||||
// flush_text_screenspace and flush_text_mapspace.
|
||||
pub fn draw_text_bubble_mapspace(
|
||||
g: &mut GfxCtx,
|
||||
top_left: Pt2D,
|
||||
txt: &Text,
|
||||
// Callers almost always calculate this anyway
|
||||
(total_width, total_height): (f64, f64),
|
||||
) {
|
||||
if let Some(c) = txt.bg_color {
|
||||
g.draw_polygon(
|
||||
c,
|
||||
&Polygon::rectangle_topleft(top_left, total_width, total_height),
|
||||
);
|
||||
}
|
||||
|
||||
let start_at = g
|
||||
.canvas
|
||||
.map_to_screen(Pt2D::new(top_left.x(), top_left.y()));
|
||||
let mut y = 0.0;
|
||||
for (line_color, line) in &txt.lines {
|
||||
let mut max_size = 0;
|
||||
let section = VariedSection {
|
||||
screen_position: (start_at.x as f32, (start_at.y + y) as f32),
|
||||
text: line
|
||||
.into_iter()
|
||||
.map(|span| {
|
||||
max_size = max_size.max(span.size);
|
||||
SectionText {
|
||||
text: &span.text,
|
||||
color: span.fg_color.0,
|
||||
scale: Scale::uniform(((span.size as f64) * g.canvas.cam_zoom) as f32),
|
||||
..SectionText::default()
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
..VariedSection::default()
|
||||
};
|
||||
let height = g.canvas.line_height(max_size);
|
||||
|
||||
if let Some(c) = line_color {
|
||||
g.draw_polygon(
|
||||
*c,
|
||||
&Polygon::rectangle_topleft(
|
||||
Pt2D::new(top_left.x(), top_left.y() + y),
|
||||
total_width,
|
||||
height,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
y += height * g.canvas.cam_zoom;
|
||||
g.canvas.glyphs.borrow_mut().queue(section);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user