fix z values, especially for tooltips. also refactor Button::new

This commit is contained in:
Dustin Carlino 2020-02-07 11:20:11 -08:00
parent b7b607a6b6
commit da59362dfe
8 changed files with 45 additions and 60 deletions

View File

@ -2,7 +2,7 @@
// (x offset, y offset, zoom)
uniform vec3 transform;
// (window width, window height, 0.0=mapspace and 1.0=screenspace)
// (window width, window height, z value)
uniform vec3 window;
in vec2 position;
@ -19,12 +19,6 @@ void main() {
float x = (screen_x / window[0] * 2.0) - 1.0;
float y = (screen_y / window[1] * 2.0) - 1.0;
// Screen-space is at z=0.0
float z = 0.5;
if (window[2] == 1.0) {
z = 0.0;
}
// Note the y inversion
gl_Position = vec4(x, -y, z, 1.0);
gl_Position = vec4(x, -y, window[2], 1.0);
}

View File

@ -9,8 +9,10 @@ use glium::uniforms::{SamplerBehavior, SamplerWrapFunction, UniformValue};
use glium::Surface;
use std::cell::Cell;
const MAPSPACE: f32 = 0.0;
const SCREENSPACE: f32 = 1.0;
// Lower is more on top
const MAPSPACE_Z: f32 = 1.0;
const SCREENSPACE_Z: f32 = 0.5;
const TOOLTIP_Z: f32 = 0.0;
struct Uniforms<'a> {
// (cam_x, cam_y, cam_zoom)
@ -31,7 +33,7 @@ impl<'a> Uniforms<'a> {
window: [
canvas.window_width as f32,
canvas.window_height as f32,
MAPSPACE,
MAPSPACE_Z,
],
canvas,
}
@ -123,7 +125,7 @@ impl<'a> GfxCtx<'a> {
self.uniforms.window = [
self.canvas.window_width as f32,
self.canvas.window_height as f32,
SCREENSPACE,
SCREENSPACE_Z,
];
}
@ -132,7 +134,7 @@ impl<'a> GfxCtx<'a> {
self.uniforms.window = [
self.canvas.window_width as f32,
self.canvas.window_height as f32,
SCREENSPACE,
SCREENSPACE_Z,
];
}
@ -285,9 +287,19 @@ impl<'a> GfxCtx<'a> {
);
let mut batch = GeomBatch::new();
batch.add_translated(txt_batch, pt.x, pt.y);
self.fork_screenspace();
// fork_screenspace, but with an even more prominent Z
self.uniforms.transform = [0.0, 0.0, 1.0];
self.uniforms.window = [
self.canvas.window_width as f32,
self.canvas.window_height as f32,
TOOLTIP_Z,
];
// Temporarily disable clipping if needed.
let clip = self.params.scissor.take();
batch.draw(self);
self.unfork();
self.params.scissor = clip;
}
pub fn screen_to_map(&self, pt: ScreenPt) -> Pt2D {

View File

@ -27,10 +27,10 @@ pub struct Button {
}
impl Button {
// TODO Take ctx and upload here, probably
pub fn new(
draw_normal: Drawable,
draw_hovered: Drawable,
ctx: &EventCtx,
normal: GeomBatch,
hovered: GeomBatch,
hotkey: Option<MultiKey>,
tooltip: &str,
hitbox: Polygon,
@ -42,8 +42,8 @@ impl Button {
Button {
action: tooltip.to_string(),
draw_normal,
draw_hovered,
draw_normal: ctx.upload(normal),
draw_hovered: ctx.upload(hovered),
hotkey,
tooltip: if let Some(key) = hotkey {
let mut txt = Text::from(Line(key.describe()).fg(text::HOTKEY_COLOR)).with_bg();
@ -145,15 +145,15 @@ impl Button {
VERT_PADDING,
);
let normal = ctx.upload(GeomBatch::from(vec![
let normal = GeomBatch::from(vec![
(Color::WHITE, bg.clone()),
(img_color, img_rect.clone()),
]));
let hovered = ctx.upload(GeomBatch::from(vec![
]);
let hovered = GeomBatch::from(vec![
(Color::ORANGE, bg.clone()),
(img_color, img_rect.clone()),
]));
Button::new(normal, hovered, key, label, bg)
]);
Button::new(ctx, normal, hovered, key, label, bg)
}
pub fn rectangle_svg(
@ -169,13 +169,7 @@ impl Button {
let mut hovered = normal.clone();
hovered.rewrite_color(hover);
Button::new(
ctx.upload(normal),
ctx.upload(hovered),
key,
tooltip,
bounds.get_rectangle(),
)
Button::new(ctx, normal, hovered, key, tooltip, bounds.get_rectangle())
}
pub fn rectangle_svg_rewrite(
@ -193,13 +187,7 @@ impl Button {
let mut hovered = normal.clone();
hovered.rewrite_color(hover);
Button::new(
ctx.upload(normal),
ctx.upload(hovered),
key,
tooltip,
bounds.get_rectangle(),
)
Button::new(ctx, normal, hovered, key, tooltip, bounds.get_rectangle())
}
pub fn text_bg(
@ -227,13 +215,7 @@ impl Button {
let mut hovered = GeomBatch::from(vec![(selected_bg_color, geom.clone())]);
hovered.add_translated(txt_batch.clone(), HORIZ_PADDING, VERT_PADDING);
Button::new(
ctx.upload(normal),
ctx.upload(hovered),
hotkey,
tooltip,
geom,
)
Button::new(ctx, normal, hovered, hotkey, tooltip, geom)
}
pub fn text_no_bg(
@ -263,13 +245,7 @@ impl Button {
let mut hovered = GeomBatch::new();
hovered.add_translated(selected_batch, horiz_padding, vert_padding);
Button::new(
ctx.upload(normal),
ctx.upload(hovered),
hotkey,
tooltip,
geom,
)
Button::new(ctx, normal, hovered, hotkey, tooltip, geom)
}
// TODO Extreme wackiness.

View File

@ -61,7 +61,7 @@ impl Histogram {
max,
prettyprint_usize(cnt)
)))
.with_bg(),
.bg(Color::BLACK),
));
}
}

View File

@ -190,7 +190,7 @@ impl<T: 'static + Ord + PartialEq + Copy + core::fmt::Debug + Yvalue<T>> Plot<T>
if let Some(cursor) = g.canvas.get_cursor_in_screen_space() {
if ScreenRectangle::top_left(self.top_left, self.dims).contains(cursor) {
let radius = Distance::meters(5.0);
let mut txt = Text::new().bg(Color::grey(0.6));
let mut txt = Text::new().bg(Color::BLACK);
for (label, pt, _) in self.closest.all_close_pts(
Pt2D::new(cursor.x - self.top_left.x, cursor.y - self.top_left.y),
radius,

View File

@ -297,8 +297,9 @@ fn make_minimap_panel(ctx: &mut EventCtx, acs: &AgentColorScheme, zoom_lvl: usiz
};
let rect = Polygon::rectangle(20.0, 8.0);
zoom_col.push(ManagedWidget::btn(Button::new(
ctx.upload(GeomBatch::from(vec![(color, rect.clone())])),
ctx.upload(GeomBatch::from(vec![(colors::HOVERING, rect.clone())])),
ctx,
GeomBatch::from(vec![(color, rect.clone())]),
GeomBatch::from(vec![(colors::HOVERING, rect.clone())]),
None,
&format!("zoom to level {}", i + 1),
rect,

View File

@ -325,8 +325,9 @@ fn make_diagram(i: IntersectionID, selected: usize, ui: &UI, ctx: &mut EventCtx)
col.push(
ManagedWidget::btn(Button::new(
ctx.upload(normal),
ctx.upload(hovered),
ctx,
normal,
hovered,
None,
&format!("phase {}", idx + 1),
bbox.clone(),

View File

@ -556,8 +556,9 @@ fn make_diagram(i: IntersectionID, selected: usize, ui: &UI, ctx: &mut EventCtx)
col.push(
ManagedWidget::row(vec![
ManagedWidget::btn(Button::new(
ctx.upload(normal),
ctx.upload(hovered),
ctx,
normal,
hovered,
None,
&format!("phase {}", idx + 1),
bbox.clone(),