cutting over more internal callers to new thing

This commit is contained in:
Dustin Carlino 2020-02-06 17:13:42 -08:00
parent ab1652aa77
commit 7f0539bcac
3 changed files with 38 additions and 22 deletions

View File

@ -235,17 +235,21 @@ impl<'a> GfxCtx<'a> {
) {
let mut dims = self.text_dims(&txt);
let top_left = self.canvas.align_window(dims, horiz, vert);
// TODO This doesn't take effect anymore
if let HorizontalAlignment::FillScreen = horiz {
dims.width = self.canvas.window_width;
}
self.canvas
.mark_covered_area(text::draw_text_bubble(self, top_left, txt, dims, true));
self.draw_blocking_text_at_screenspace_topleft(txt, top_left);
}
pub(crate) fn draw_blocking_text_at_screenspace_topleft(&mut self, txt: &Text, pt: ScreenPt) {
let dims = self.text_dims(&txt);
let mut batch = GeomBatch::new();
self.canvas
.mark_covered_area(text::draw_text_bubble(self, pt, txt, dims, true));
.mark_covered_area(txt.clone().render(&mut batch, pt));
self.fork_screenspace();
batch.draw(self);
self.unfork();
}
pub fn get_screen_bounds(&self) -> Bounds {
@ -256,13 +260,14 @@ impl<'a> GfxCtx<'a> {
pub fn draw_text_at(&mut self, txt: &Text, map_pt: Pt2D) {
let dims = self.text_dims(&txt);
let pt = self.canvas.map_to_screen(map_pt);
text::draw_text_bubble(
self,
let mut batch = GeomBatch::new();
txt.clone().render(
&mut batch,
ScreenPt::new(pt.x - (dims.width / 2.0), pt.y - (dims.height / 2.0)),
txt,
dims,
true,
);
self.fork_screenspace();
batch.draw(self);
self.unfork();
}
pub fn draw_text_at_mapspace(&mut self, txt: &Text, map_pt: Pt2D) {
@ -285,8 +290,11 @@ impl<'a> GfxCtx<'a> {
ScreenPt::new(self.canvas.cursor_x, self.canvas.cursor_y),
&self.canvas,
);
// No need to cover the tooltip; this tooltip follows the mouse anyway.
text::draw_text_bubble(self, pt, txt, dims, true);
let mut batch = GeomBatch::new();
txt.clone().render(&mut batch, pt);
self.fork_screenspace();
batch.draw(self);
self.unfork();
}
pub fn screen_to_map(&self, pt: ScreenPt) -> Pt2D {

View File

@ -202,7 +202,8 @@ impl<'a> LoadingScreen<'a> {
// Timer throttles updates reasonably, so don't bother throttling redraws.
fn redraw(&mut self) {
if elapsed_seconds(self.last_drawn) < 0.2 {
// TODO Gotta speed things up before this is reasonable again
if elapsed_seconds(self.last_drawn) < 1.0 {
return;
}
self.last_drawn = Instant::now();

View File

@ -333,18 +333,12 @@ pub fn draw_text_bubble_mapspace(
// TODO Rearrange
impl Text {
pub fn render(self, master_batch: &mut GeomBatch, top_left: ScreenPt) -> ScreenRectangle {
/*if let Some(c) = txt.bg_color {
g.draw_polygon(
c,
&Polygon::rectangle(total_dims.width, total_dims.height)
.translate(top_left.x, top_left.y),
);
}*/
pub fn render(self, output_batch: &mut GeomBatch, top_left: ScreenPt) -> ScreenRectangle {
// TODO Bad guess
let empty_line_height = 30.0;
let mut master_batch = GeomBatch::new();
let mut y = top_left.y;
let mut max_width = 0.0_f64;
for (line_color, line) in self.lines {
@ -385,6 +379,16 @@ impl Text {
max_width = max_width.max(x - top_left.x);
}
if let Some(c) = self.bg_color {
output_batch.push(
c,
Polygon::rectangle(max_width, y - top_left.y).translate(top_left.x, top_left.y),
);
}
for (color, poly) in master_batch.consume() {
output_batch.push(color, poly);
}
ScreenRectangle::top_left(top_left, ScreenDims::new(max_width, y - top_left.y))
}
}
@ -419,7 +423,10 @@ fn render_text(txt: TextSpan) -> GeomBatch {
// TODO Bundle better
opts.font_directories
.push("/home/dabreegster/abstreet/ezgui/src/assets".to_string());
let svg_tree = usvg::Tree::from_str(&svg, &opts).unwrap();
let svg_tree = match usvg::Tree::from_str(&svg, &opts) {
Ok(t) => t,
Err(err) => panic!("render_text({}): {}", svg, err),
};
let mut batch = GeomBatch::new();
match crate::svg::add_svg_inner(&mut batch, svg_tree) {
Ok(_) => batch,