mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 20:29:04 +03:00
cut down the places populating covered_areas. mainly Composite should do it, being aware of clipping. some temporary exceptions remain.
This commit is contained in:
parent
14596d00ea
commit
1c3b7fe52b
@ -30,7 +30,6 @@ pub struct Canvas {
|
||||
|
||||
// TODO Bit weird and hacky to mutate inside of draw() calls.
|
||||
pub(crate) covered_areas: RefCell<Vec<ScreenRectangle>>,
|
||||
pub(crate) covered_polygons: RefCell<Vec<Polygon>>,
|
||||
|
||||
// Kind of just ezgui state awkwardly stuck here...
|
||||
pub(crate) lctrl_held: bool,
|
||||
@ -63,7 +62,6 @@ impl Canvas {
|
||||
map_dims: (0.0, 0.0),
|
||||
|
||||
covered_areas: RefCell::new(Vec::new()),
|
||||
covered_polygons: RefCell::new(Vec::new()),
|
||||
|
||||
lctrl_held: false,
|
||||
button_tooltip: None,
|
||||
@ -127,10 +125,9 @@ impl Canvas {
|
||||
|
||||
pub(crate) fn start_drawing(&self) {
|
||||
self.covered_areas.borrow_mut().clear();
|
||||
self.covered_polygons.borrow_mut().clear();
|
||||
}
|
||||
|
||||
pub fn mark_covered_area(&self, rect: ScreenRectangle) {
|
||||
pub(crate) fn mark_covered_area(&self, rect: ScreenRectangle) {
|
||||
self.covered_areas.borrow_mut().push(rect);
|
||||
}
|
||||
|
||||
@ -147,11 +144,6 @@ impl Canvas {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
for c in self.covered_polygons.borrow().iter() {
|
||||
if c.contains_pt(pt.to_pt()) {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
Some(self.screen_to_map(pt))
|
||||
} else {
|
||||
|
@ -242,6 +242,12 @@ impl<'a> GfxCtx<'a> {
|
||||
.mark_covered_area(text::draw_text_bubble(self, top_left, txt, dims, true));
|
||||
}
|
||||
|
||||
pub(crate) fn draw_blocking_text_at_screenspace_topleft(&mut self, txt: &Text, pt: ScreenPt) {
|
||||
let dims = self.text_dims(&txt);
|
||||
self.canvas
|
||||
.mark_covered_area(text::draw_text_bubble(self, pt, txt, dims, true));
|
||||
}
|
||||
|
||||
pub fn get_screen_bounds(&self) -> Bounds {
|
||||
self.canvas.get_screen_bounds()
|
||||
}
|
||||
@ -272,12 +278,6 @@ impl<'a> GfxCtx<'a> {
|
||||
);
|
||||
}
|
||||
|
||||
pub fn draw_text_at_screenspace_topleft(&mut self, txt: &Text, pt: ScreenPt) {
|
||||
let dims = self.text_dims(&txt);
|
||||
self.canvas
|
||||
.mark_covered_area(text::draw_text_bubble(self, pt, txt, dims, true));
|
||||
}
|
||||
|
||||
pub fn draw_mouse_tooltip(&mut self, txt: &Text) {
|
||||
let dims = self.text_dims(&txt);
|
||||
// TODO Maybe also consider the cursor as a valid center
|
||||
@ -590,9 +590,13 @@ impl DrawBoth {
|
||||
g.redraw(&self.geom);
|
||||
g.unfork();
|
||||
for (txt, pt) in &self.txt {
|
||||
g.draw_text_at_screenspace_topleft(
|
||||
txt,
|
||||
let dims = g.text_dims(&txt);
|
||||
text::draw_text_bubble(
|
||||
g,
|
||||
ScreenPt::new(top_left.x + pt.x, top_left.y + pt.y),
|
||||
txt,
|
||||
dims,
|
||||
true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -707,9 +707,11 @@ impl Composite {
|
||||
}
|
||||
|
||||
pub fn draw(&self, g: &mut GfxCtx) {
|
||||
g.canvas.mark_covered_area(self.top_level.rect.clone());
|
||||
if self.scrollable_x || self.scrollable_y {
|
||||
g.enable_clipping(self.clip_rect.clone().unwrap());
|
||||
if let Some(ref rect) = self.clip_rect {
|
||||
g.enable_clipping(rect.clone());
|
||||
g.canvas.mark_covered_area(rect.clone());
|
||||
} else {
|
||||
g.canvas.mark_covered_area(self.top_level.rect.clone());
|
||||
}
|
||||
self.top_level.draw(g, &self.sliders, &self.menus);
|
||||
if self.scrollable_x || self.scrollable_y {
|
||||
|
@ -105,11 +105,6 @@ impl Button {
|
||||
} else {
|
||||
self.draw_normal.redraw(self.top_left, g);
|
||||
}
|
||||
|
||||
g.canvas
|
||||
.covered_polygons
|
||||
.borrow_mut()
|
||||
.push(self.get_hitbox());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -196,7 +196,7 @@ impl ModalMenu {
|
||||
}
|
||||
|
||||
pub fn draw(&self, g: &mut GfxCtx) {
|
||||
g.draw_text_at_screenspace_topleft(&self.calculate_txt(), self.top_left);
|
||||
g.draw_blocking_text_at_screenspace_topleft(&self.calculate_txt(), self.top_left);
|
||||
}
|
||||
|
||||
fn recalculate_dims(&mut self, ctx: &EventCtx) {
|
||||
|
@ -114,7 +114,7 @@ impl<T: Clone> PopupMenu<T> {
|
||||
}
|
||||
|
||||
pub fn draw(&self, g: &mut GfxCtx) {
|
||||
g.draw_text_at_screenspace_topleft(&self.calculate_txt(), self.top_left);
|
||||
g.draw_blocking_text_at_screenspace_topleft(&self.calculate_txt(), self.top_left);
|
||||
}
|
||||
|
||||
pub fn current_choice(&self) -> &T {
|
||||
|
@ -215,6 +215,8 @@ impl Slider {
|
||||
|
||||
pub fn draw(&self, g: &mut GfxCtx) {
|
||||
self.draw.redraw(self.top_left, g);
|
||||
// TODO Since the sliders in Composites are scrollbars outside of the clipping rectangle,
|
||||
// this stays for now.
|
||||
g.canvas
|
||||
.mark_covered_area(ScreenRectangle::top_left(self.top_left, self.dims));
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ impl TextBox {
|
||||
}
|
||||
|
||||
pub fn draw(&self, g: &mut GfxCtx) {
|
||||
g.draw_text_at_screenspace_topleft(&self.get_text(), self.top_left);
|
||||
g.draw_blocking_text_at_screenspace_topleft(&self.get_text(), self.top_left);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user