mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-01 10:44:56 +03:00
eradicate DrawBoth
This commit is contained in:
parent
d3aa02cee4
commit
b7b607a6b6
@ -584,34 +584,3 @@ impl<'a> Prerender<'a> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// I'm tempted to fold this into GeomBatch and Drawable, but since this represents a screen-space
|
||||
// thing, it'd be weird to do that.
|
||||
pub struct DrawBoth {
|
||||
geom: Drawable,
|
||||
// Covers both geometry and text
|
||||
dims: ScreenDims,
|
||||
}
|
||||
|
||||
impl DrawBoth {
|
||||
pub fn new(ctx: &EventCtx, mut batch: GeomBatch, texts: Vec<(Text, ScreenPt)>) -> DrawBoth {
|
||||
for (txt, pt) in texts {
|
||||
batch.add_translated(txt.render(&ctx.prerender.assets), pt.x, pt.y);
|
||||
}
|
||||
DrawBoth {
|
||||
dims: batch.get_dims(),
|
||||
geom: batch.upload(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// DON'T fork before calling this.
|
||||
pub fn redraw(&self, top_left: ScreenPt, g: &mut GfxCtx) {
|
||||
g.fork(Pt2D::new(0.0, 0.0), top_left, 1.0);
|
||||
g.redraw(&self.geom);
|
||||
g.unfork();
|
||||
}
|
||||
|
||||
pub fn get_dims(&self) -> ScreenDims {
|
||||
self.dims
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ mod widgets;
|
||||
|
||||
pub use crate::canvas::{Canvas, HorizontalAlignment, VerticalAlignment};
|
||||
pub use crate::color::Color;
|
||||
pub use crate::drawing::{DrawBoth, Drawable, GeomBatch, GfxCtx, Prerender, RewriteColor};
|
||||
pub use crate::drawing::{Drawable, GeomBatch, GfxCtx, Prerender, RewriteColor};
|
||||
pub use crate::event::{hotkey, lctrl, Event, Key, MultiKey};
|
||||
pub use crate::event_ctx::{EventCtx, TextureType};
|
||||
pub use crate::input::UserInput;
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::layout::Widget;
|
||||
use crate::widgets::PopupMenu;
|
||||
use crate::{
|
||||
Button, Color, DrawBoth, EventCtx, Filler, GeomBatch, GfxCtx, Histogram, HorizontalAlignment,
|
||||
Button, Color, Drawable, EventCtx, Filler, GeomBatch, GfxCtx, Histogram, HorizontalAlignment,
|
||||
JustDraw, Plot, RewriteColor, ScreenDims, ScreenPt, ScreenRectangle, Slider, Text,
|
||||
VerticalAlignment,
|
||||
};
|
||||
@ -21,7 +21,7 @@ pub struct ManagedWidget {
|
||||
widget: WidgetType,
|
||||
style: LayoutStyle,
|
||||
rect: ScreenRectangle,
|
||||
bg: Option<DrawBoth>,
|
||||
bg: Option<Drawable>,
|
||||
}
|
||||
|
||||
enum WidgetType {
|
||||
@ -323,7 +323,7 @@ impl ManagedWidget {
|
||||
menus: &HashMap<String, Menu>,
|
||||
) {
|
||||
if let Some(ref bg) = self.bg {
|
||||
bg.redraw(ScreenPt::new(self.rect.x1, self.rect.y1), g);
|
||||
g.redraw_at(ScreenPt::new(self.rect.x1, self.rect.y1), bg);
|
||||
}
|
||||
|
||||
match self.widget {
|
||||
@ -453,7 +453,7 @@ impl ManagedWidget {
|
||||
.to_outline(Distance::meters(thickness)),
|
||||
);
|
||||
}
|
||||
self.bg = Some(DrawBoth::new(ctx, batch, Vec::new()));
|
||||
self.bg = Some(ctx.upload(batch));
|
||||
}
|
||||
|
||||
match self.widget {
|
||||
|
@ -1,15 +1,15 @@
|
||||
use crate::layout::Widget;
|
||||
use crate::{
|
||||
Color, DrawBoth, EventCtx, GeomBatch, GfxCtx, Line, ManagedWidget, ScreenDims, ScreenPt, Text,
|
||||
Color, Drawable, EventCtx, GeomBatch, GfxCtx, Line, ManagedWidget, ScreenDims, ScreenPt, Text,
|
||||
};
|
||||
use abstutil::prettyprint_usize;
|
||||
use geom::{Distance, Duration, Polygon, Pt2D};
|
||||
|
||||
// The X axis is Durations, with positive meaning "faster" (considered good) and negative "slower"
|
||||
pub struct Histogram {
|
||||
draw: DrawBoth,
|
||||
draw: Drawable,
|
||||
|
||||
// TODO Bit sad to pretty much duplicate the geometry from DrawBoth...
|
||||
// TODO Bit sad to pretty much duplicate the geometry?
|
||||
rect_labels: Vec<(Polygon, Text)>,
|
||||
|
||||
top_left: ScreenPt,
|
||||
@ -68,7 +68,7 @@ impl Histogram {
|
||||
batch.extend(Color::BLACK, outlines);
|
||||
|
||||
let histogram = Histogram {
|
||||
draw: DrawBoth::new(ctx, batch, Vec::new()),
|
||||
draw: ctx.upload(batch),
|
||||
rect_labels,
|
||||
|
||||
top_left: ScreenPt::new(0.0, 0.0),
|
||||
@ -113,7 +113,7 @@ impl Histogram {
|
||||
}
|
||||
|
||||
pub(crate) fn draw(&self, g: &mut GfxCtx) {
|
||||
self.draw.redraw(self.top_left, g);
|
||||
g.redraw_at(self.top_left, &self.draw);
|
||||
|
||||
if let Some(cursor) = g.canvas.get_cursor_in_screen_space() {
|
||||
let pt = Pt2D::new(cursor.x - self.top_left.x, cursor.y - self.top_left.y);
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::layout::Widget;
|
||||
use crate::{
|
||||
Color, DrawBoth, EventCtx, GeomBatch, GfxCtx, Line, ManagedWidget, ScreenDims, ScreenPt,
|
||||
Color, Drawable, EventCtx, GeomBatch, GfxCtx, Line, ManagedWidget, ScreenDims, ScreenPt,
|
||||
ScreenRectangle, Text,
|
||||
};
|
||||
use abstutil::prettyprint_usize;
|
||||
@ -8,7 +8,7 @@ use geom::{Bounds, Circle, Distance, Duration, FindClosest, PolyLine, Pt2D, Time
|
||||
|
||||
// The X is always time
|
||||
pub struct Plot<T> {
|
||||
draw: DrawBoth,
|
||||
draw: Drawable,
|
||||
|
||||
// The geometry here is in screen-space.
|
||||
max_x: Time,
|
||||
@ -148,7 +148,7 @@ impl<T: 'static + Ord + PartialEq + Copy + core::fmt::Debug + Yvalue<T>> Plot<T>
|
||||
}
|
||||
|
||||
let plot = Plot {
|
||||
draw: DrawBoth::new(ctx, batch, Vec::new()),
|
||||
draw: ctx.upload(batch),
|
||||
closest,
|
||||
max_x,
|
||||
max_y: Box::new(max_y),
|
||||
@ -185,7 +185,7 @@ impl<T: 'static + Ord + PartialEq + Copy + core::fmt::Debug + Yvalue<T>> Plot<T>
|
||||
}
|
||||
|
||||
pub(crate) fn draw(&self, g: &mut GfxCtx) {
|
||||
self.draw.redraw(self.top_left, g);
|
||||
g.redraw_at(self.top_left, &self.draw);
|
||||
|
||||
if let Some(cursor) = g.canvas.get_cursor_in_screen_space() {
|
||||
if ScreenRectangle::top_left(self.top_left, self.dims).contains(cursor) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::layout::{stack_vertically, ContainerOrientation, Widget};
|
||||
use crate::widgets::text_box::TextBox;
|
||||
use crate::{
|
||||
hotkey, Color, DrawBoth, EventCtx, EventLoopMode, GeomBatch, GfxCtx, InputResult, Key, Line,
|
||||
hotkey, Color, Drawable, EventCtx, EventLoopMode, GeomBatch, GfxCtx, InputResult, Key, Line,
|
||||
ModalMenu, MultiKey, ScreenDims, ScreenPt, ScreenRectangle, Text, Warper,
|
||||
};
|
||||
use geom::{Polygon, Pt2D, Time};
|
||||
@ -15,7 +15,7 @@ pub struct Slider {
|
||||
main_bg_len: f64,
|
||||
dragger_len: f64,
|
||||
|
||||
draw: DrawBoth,
|
||||
draw: Drawable,
|
||||
|
||||
top_left: ScreenPt,
|
||||
dims: ScreenDims,
|
||||
@ -34,12 +34,7 @@ impl Slider {
|
||||
main_bg_len: width,
|
||||
dragger_len,
|
||||
|
||||
// Dummy value; empty GeomBatches can't be measured.
|
||||
draw: DrawBoth::new(
|
||||
ctx,
|
||||
GeomBatch::from(vec![(Color::BLACK, Polygon::rectangle(1.0, 1.0))]),
|
||||
Vec::new(),
|
||||
),
|
||||
draw: ctx.upload(GeomBatch::new()),
|
||||
|
||||
top_left: ScreenPt::new(0.0, 0.0),
|
||||
dims: ScreenDims::new(0.0, 0.0),
|
||||
@ -58,12 +53,7 @@ impl Slider {
|
||||
main_bg_len: height,
|
||||
dragger_len,
|
||||
|
||||
// Dummy value; empty GeomBatches can't be measured.
|
||||
draw: DrawBoth::new(
|
||||
ctx,
|
||||
GeomBatch::from(vec![(Color::BLACK, Polygon::rectangle(1.0, 1.0))]),
|
||||
Vec::new(),
|
||||
),
|
||||
draw: ctx.upload(GeomBatch::new()),
|
||||
|
||||
top_left: ScreenPt::new(0.0, 0.0),
|
||||
dims: ScreenDims::new(0.0, 0.0),
|
||||
@ -98,7 +88,7 @@ impl Slider {
|
||||
self.slider_geom(),
|
||||
);
|
||||
|
||||
self.draw = DrawBoth::new(ctx, batch, Vec::new());
|
||||
self.draw = ctx.upload(batch);
|
||||
}
|
||||
|
||||
// Doesn't touch self.top_left
|
||||
@ -216,7 +206,7 @@ impl Slider {
|
||||
}
|
||||
|
||||
pub fn draw(&self, g: &mut GfxCtx) {
|
||||
self.draw.redraw(self.top_left, g);
|
||||
g.redraw_at(self.top_left, &self.draw);
|
||||
// TODO Since the sliders in Composites are scrollbars outside of the clipping rectangle,
|
||||
// this stays for now.
|
||||
g.canvas
|
||||
|
Loading…
Reference in New Issue
Block a user