mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-27 00:12:55 +03:00
implementing GfxCtx forking... aka, reset uniforms
This commit is contained in:
parent
d9d89e93dd
commit
9b14206be0
@ -48,6 +48,7 @@ impl Plugin for Legend {
|
|||||||
g.fork(
|
g.fork(
|
||||||
Pt2D::new(-self.top_left.x / zoom, -self.top_left.y / zoom),
|
Pt2D::new(-self.top_left.x / zoom, -self.top_left.y / zoom),
|
||||||
zoom,
|
zoom,
|
||||||
|
&ctx.canvas,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create a fake turn.
|
// Create a fake turn.
|
||||||
@ -92,6 +93,6 @@ impl Plugin for Legend {
|
|||||||
ScreenPt::new(self.top_left.x + 20.0, self.top_left.y + 110.0),
|
ScreenPt::new(self.top_left.x + 20.0, self.top_left.y + 110.0),
|
||||||
);
|
);
|
||||||
|
|
||||||
g.unfork();
|
g.unfork(&ctx.canvas);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -328,7 +328,7 @@ pub fn draw_signal_diagram(
|
|||||||
let total_screen_width = (intersection_width * zoom) + label_length + 10.0;
|
let total_screen_width = (intersection_width * zoom) + label_length + 10.0;
|
||||||
let x1_screen = ctx.canvas.window_width - total_screen_width;
|
let x1_screen = ctx.canvas.window_width - total_screen_width;
|
||||||
|
|
||||||
g.fork_screenspace();
|
g.fork_screenspace(&ctx.canvas);
|
||||||
g.draw_polygon(
|
g.draw_polygon(
|
||||||
ctx.cs
|
ctx.cs
|
||||||
.get_def("signal editor panel", Color::BLACK.alpha(0.95)),
|
.get_def("signal editor panel", Color::BLACK.alpha(0.95)),
|
||||||
@ -364,6 +364,7 @@ pub fn draw_signal_diagram(
|
|||||||
- padding * ((idx as f64) + 1.0),
|
- padding * ((idx as f64) + 1.0),
|
||||||
),
|
),
|
||||||
zoom,
|
zoom,
|
||||||
|
&ctx.canvas,
|
||||||
);
|
);
|
||||||
draw_signal_cycle(&cycle, g, ctx);
|
draw_signal_cycle(&cycle, g, ctx);
|
||||||
|
|
||||||
@ -377,7 +378,7 @@ pub fn draw_signal_diagram(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
g.unfork();
|
g.unfork(&ctx.canvas);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_pts_between(pts: &Vec<Pt2D>, start: Pt2D, end: Pt2D) -> Option<Vec<Pt2D>> {
|
fn find_pts_between(pts: &Vec<Pt2D>, start: Pt2D, end: Pt2D) -> Option<Vec<Pt2D>> {
|
||||||
|
@ -99,7 +99,13 @@ impl Canvas {
|
|||||||
let x1 = self.cursor_x - (width / 2.0);
|
let x1 = self.cursor_x - (width / 2.0);
|
||||||
let y1 = self.cursor_y - (height / 2.0);
|
let y1 = self.cursor_y - (height / 2.0);
|
||||||
// No need to cover the tooltip; this tooltip follows the mouse anyway.
|
// No need to cover the tooltip; this tooltip follows the mouse anyway.
|
||||||
text::draw_text_bubble(g, glyphs.as_mut().unwrap(), ScreenPt::new(x1, y1), txt);
|
text::draw_text_bubble(
|
||||||
|
g,
|
||||||
|
glyphs.as_mut().unwrap(),
|
||||||
|
ScreenPt::new(x1, y1),
|
||||||
|
txt,
|
||||||
|
self,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Rename these draw_nonblocking_text_*
|
// TODO Rename these draw_nonblocking_text_*
|
||||||
@ -112,6 +118,7 @@ impl Canvas {
|
|||||||
glyphs.as_mut().unwrap(),
|
glyphs.as_mut().unwrap(),
|
||||||
ScreenPt::new(pt.x - (width / 2.0), pt.y - (height / 2.0)),
|
ScreenPt::new(pt.x - (width / 2.0), pt.y - (height / 2.0)),
|
||||||
txt,
|
txt,
|
||||||
|
self,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,11 +128,12 @@ impl Canvas {
|
|||||||
self.glyphs.borrow_mut().as_mut().unwrap(),
|
self.glyphs.borrow_mut().as_mut().unwrap(),
|
||||||
self.map_to_screen(pt),
|
self.map_to_screen(pt),
|
||||||
txt,
|
txt,
|
||||||
|
self,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_text_at_screenspace_topleft(&self, g: &mut GfxCtx, txt: Text, pt: ScreenPt) {
|
pub fn draw_text_at_screenspace_topleft(&self, g: &mut GfxCtx, txt: Text, pt: ScreenPt) {
|
||||||
text::draw_text_bubble(g, self.glyphs.borrow_mut().as_mut().unwrap(), pt, txt);
|
text::draw_text_bubble(g, self.glyphs.borrow_mut().as_mut().unwrap(), pt, txt, self);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The text box covers up what's beneath and eats the cursor (for get_cursor_in_map_space).
|
// The text box covers up what's beneath and eats the cursor (for get_cursor_in_map_space).
|
||||||
@ -156,6 +164,7 @@ impl Canvas {
|
|||||||
glyphs.as_mut().unwrap(),
|
glyphs.as_mut().unwrap(),
|
||||||
ScreenPt::new(x1, y1),
|
ScreenPt::new(x1, y1),
|
||||||
txt,
|
txt,
|
||||||
|
self,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,16 +134,22 @@ impl<'a> GfxCtx<'a> {
|
|||||||
// Up to the caller to call unfork()!
|
// Up to the caller to call unfork()!
|
||||||
// TODO Canvas doesn't understand this change, so things like text drawing that use
|
// TODO Canvas doesn't understand this change, so things like text drawing that use
|
||||||
// map_to_screen will just be confusing.
|
// map_to_screen will just be confusing.
|
||||||
pub fn fork(&mut self, top_left: Pt2D, zoom: f64) {
|
pub fn fork(&mut self, top_left: Pt2D, zoom: f64, canvas: &Canvas) {
|
||||||
// TODO set uniforms based on values above
|
self.uniforms = uniform! {
|
||||||
|
transform: [top_left.x() as f32, top_left.y() as f32, zoom as f32],
|
||||||
|
window: [canvas.window_width as f32, canvas.window_height as f32],
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fork_screenspace(&mut self) {
|
pub fn fork_screenspace(&mut self, canvas: &Canvas) {
|
||||||
self.fork(Pt2D::new(0.0, 0.0), 1.0)
|
self.fork(Pt2D::new(0.0, 0.0), 1.0, canvas)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unfork(&mut self) {
|
pub fn unfork(&mut self, canvas: &Canvas) {
|
||||||
// TODO Reset to canvas?
|
self.uniforms = uniform! {
|
||||||
|
transform: [canvas.cam_x as f32, canvas.cam_y as f32, canvas.cam_zoom as f32],
|
||||||
|
window: [canvas.window_width as f32, canvas.window_height as f32],
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear(&mut self, color: Color) {
|
pub fn clear(&mut self, color: Color) {
|
||||||
|
@ -133,15 +133,19 @@ impl Text {
|
|||||||
so_far.push_str(&span.text);
|
so_far.push_str(&span.text);
|
||||||
so_far
|
so_far
|
||||||
});
|
});
|
||||||
let rect = glyphs
|
if let Some(rect) = glyphs.pixel_bounds(Section {
|
||||||
.pixel_bounds(Section {
|
text: &full_line,
|
||||||
text: &full_line,
|
scale: Scale::uniform(FONT_SIZE),
|
||||||
scale: Scale::uniform(FONT_SIZE),
|
..Section::default()
|
||||||
..Section::default()
|
}) {
|
||||||
})
|
widths.push(rect.width());
|
||||||
.unwrap();
|
heights.push(rect.height());
|
||||||
widths.push(rect.width());
|
} else {
|
||||||
heights.push(rect.height());
|
// TODO Sometimes we want to space something like " ", but no drawn glyphs
|
||||||
|
// means pixel_bounds fails. Hack?
|
||||||
|
widths.push((MAX_CHAR_WIDTH * (full_line.len() as f64)) as i32);
|
||||||
|
heights.push(LINE_HEIGHT as i32);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(
|
(
|
||||||
@ -156,9 +160,10 @@ pub fn draw_text_bubble(
|
|||||||
glyphs: &mut GlyphBrush<'static, 'static>,
|
glyphs: &mut GlyphBrush<'static, 'static>,
|
||||||
top_left: ScreenPt,
|
top_left: ScreenPt,
|
||||||
txt: Text,
|
txt: Text,
|
||||||
|
canvas: &Canvas,
|
||||||
) -> ScreenRectangle {
|
) -> ScreenRectangle {
|
||||||
// TODO Is it expensive to constantly change uniforms and the shader program?
|
// TODO Is it expensive to constantly change uniforms and the shader program?
|
||||||
g.fork_screenspace();
|
g.fork_screenspace(canvas);
|
||||||
|
|
||||||
let (total_width, total_height) = txt.dims(glyphs);
|
let (total_width, total_height) = txt.dims(glyphs);
|
||||||
if let Some(c) = txt.bg_color {
|
if let Some(c) = txt.bg_color {
|
||||||
@ -212,7 +217,7 @@ pub fn draw_text_bubble(
|
|||||||
y += LINE_HEIGHT;
|
y += LINE_HEIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
g.unfork();
|
g.unfork(canvas);
|
||||||
|
|
||||||
ScreenRectangle {
|
ScreenRectangle {
|
||||||
x1: top_left.x,
|
x1: top_left.x,
|
||||||
|
@ -135,7 +135,7 @@ impl TopMenu {
|
|||||||
y2: TOP_MENU_HEIGHT,
|
y2: TOP_MENU_HEIGHT,
|
||||||
});
|
});
|
||||||
|
|
||||||
g.fork_screenspace();
|
g.fork_screenspace(canvas);
|
||||||
g.draw_polygon(
|
g.draw_polygon(
|
||||||
text::BG_COLOR,
|
text::BG_COLOR,
|
||||||
&Polygon::rectangle_topleft(Pt2D::new(0.0, 0.0), canvas.window_width, TOP_MENU_HEIGHT),
|
&Polygon::rectangle_topleft(Pt2D::new(0.0, 0.0), canvas.window_width, TOP_MENU_HEIGHT),
|
||||||
@ -148,7 +148,7 @@ impl TopMenu {
|
|||||||
&Polygon::rectangle_topleft(Pt2D::new(r.x1, r.y1), r.x2 - r.x1, r.y2 - r.y1),
|
&Polygon::rectangle_topleft(Pt2D::new(r.x1, r.y1), r.x2 - r.x1, r.y2 - r.y1),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
g.unfork();
|
g.unfork(canvas);
|
||||||
|
|
||||||
canvas.draw_text_at_screenspace_topleft(g, self.txt.clone(), ScreenPt::new(0.0, 0.0));
|
canvas.draw_text_at_screenspace_topleft(g, self.txt.clone(), ScreenPt::new(0.0, 0.0));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user