mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-29 17:34:58 +03:00
hack in a mask to change the color of image buttons without backgrounds
This commit is contained in:
parent
c87c043286
commit
202cfcf0d6
@ -24,40 +24,47 @@ uniform sampler2DArray tex14;
|
||||
in vec4 pass_style;
|
||||
out vec4 f_color;
|
||||
|
||||
void handle_texture(in sampler2DArray tex, in vec4 style, out vec4 color) {
|
||||
color = texture(tex, vec3(pass_style[0], pass_style[1], pass_style[3] - 100.0));
|
||||
if (pass_style[3] >= 200.0 && color[3] > 0.0) {
|
||||
color = vec4(1.0, 0.55, 0.0, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
// See actually_upload in drawing.rs to understand the different things encoded.
|
||||
if (pass_style[3] < 100.0) {
|
||||
f_color = pass_style;
|
||||
} else if (pass_style[2] == 0.0) {
|
||||
f_color = texture(tex0, vec3(pass_style[0], pass_style[1], pass_style[3] - 100.0));
|
||||
handle_texture(tex0, pass_style, f_color);
|
||||
} else if (pass_style[2] == 1.0) {
|
||||
f_color = texture(tex1, vec3(pass_style[0], pass_style[1], pass_style[3] - 100.0));
|
||||
handle_texture(tex1, pass_style, f_color);
|
||||
} else if (pass_style[2] == 2.0) {
|
||||
f_color = texture(tex2, vec3(pass_style[0], pass_style[1], pass_style[3] - 100.0));
|
||||
handle_texture(tex2, pass_style, f_color);
|
||||
} else if (pass_style[2] == 3.0) {
|
||||
f_color = texture(tex3, vec3(pass_style[0], pass_style[1], pass_style[3] - 100.0));
|
||||
handle_texture(tex3, pass_style, f_color);
|
||||
} else if (pass_style[2] == 4.0) {
|
||||
f_color = texture(tex4, vec3(pass_style[0], pass_style[1], pass_style[3] - 100.0));
|
||||
handle_texture(tex4, pass_style, f_color);
|
||||
} else if (pass_style[2] == 5.0) {
|
||||
f_color = texture(tex5, vec3(pass_style[0], pass_style[1], pass_style[3] - 100.0));
|
||||
handle_texture(tex5, pass_style, f_color);
|
||||
} else if (pass_style[2] == 6.0) {
|
||||
f_color = texture(tex6, vec3(pass_style[0], pass_style[1], pass_style[3] - 100.0));
|
||||
handle_texture(tex6, pass_style, f_color);
|
||||
} else if (pass_style[2] == 7.0) {
|
||||
f_color = texture(tex7, vec3(pass_style[0], pass_style[1], pass_style[3] - 100.0));
|
||||
handle_texture(tex7, pass_style, f_color);
|
||||
} else if (pass_style[2] == 8.0) {
|
||||
f_color = texture(tex8, vec3(pass_style[0], pass_style[1], pass_style[3] - 100.0));
|
||||
handle_texture(tex8, pass_style, f_color);
|
||||
} else if (pass_style[2] == 9.0) {
|
||||
f_color = texture(tex9, vec3(pass_style[0], pass_style[1], pass_style[3] - 100.0));
|
||||
handle_texture(tex9, pass_style, f_color);
|
||||
} else if (pass_style[2] == 10.0) {
|
||||
f_color = texture(tex10, vec3(pass_style[0], pass_style[1], pass_style[3] - 100.0));
|
||||
handle_texture(tex10, pass_style, f_color);
|
||||
} else if (pass_style[2] == 11.0) {
|
||||
f_color = texture(tex11, vec3(pass_style[0], pass_style[1], pass_style[3] - 100.0));
|
||||
handle_texture(tex11, pass_style, f_color);
|
||||
} else if (pass_style[2] == 12.0) {
|
||||
f_color = texture(tex12, vec3(pass_style[0], pass_style[1], pass_style[3] - 100.0));
|
||||
handle_texture(tex12, pass_style, f_color);
|
||||
} else if (pass_style[2] == 13.0) {
|
||||
f_color = texture(tex13, vec3(pass_style[0], pass_style[1], pass_style[3] - 100.0));
|
||||
handle_texture(tex13, pass_style, f_color);
|
||||
} else if (pass_style[2] == 14.0) {
|
||||
f_color = texture(tex14, vec3(pass_style[0], pass_style[1], pass_style[3] - 100.0));
|
||||
handle_texture(tex14, pass_style, f_color);
|
||||
} else if (pass_style[0] == 100.0) {
|
||||
// The hatching should be done in map-space, so panning/zooming doesn't move the stripes.
|
||||
// This is screen_to_map, also accounting for the y-inversion done by the vertex shader.
|
||||
|
@ -21,6 +21,8 @@ pub enum Color {
|
||||
// TODO Figure out how to pack more data into this.
|
||||
HatchingStyle1,
|
||||
HatchingStyle2,
|
||||
// Complete hack. Turns the non-transparent pixels in the texture orange in the shader.
|
||||
MaskedTexture(TextureID),
|
||||
}
|
||||
|
||||
impl fmt::Display for Color {
|
||||
@ -40,6 +42,7 @@ impl fmt::Display for Color {
|
||||
Color::CustomUVTexture(id) => write!(f, "Color::CustomUVTexture({}:{})", id.0, id.1),
|
||||
Color::HatchingStyle1 => write!(f, "Color::HatchingStyle1"),
|
||||
Color::HatchingStyle2 => write!(f, "Color::HatchingStyle2"),
|
||||
Color::MaskedTexture(id) => write!(f, "Color::MaskedTexture({}:{})", id.0, id.1),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -107,6 +110,13 @@ impl Color {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_masking(&self) -> Color {
|
||||
match self {
|
||||
Color::StretchTexture(id, _, _) => Color::MaskedTexture(*id),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn texture_dims(&self) -> ScreenDims {
|
||||
match self {
|
||||
Color::TileTexture(_, dims) => *dims,
|
||||
|
@ -460,6 +460,12 @@ impl<'a> Prerender<'a> {
|
||||
let ty = (rot_pt.y() - b.min_y) / (b.max_y - b.min_y);
|
||||
[tx as f32, ty as f32, id.0, 100.0 + id.1]
|
||||
}
|
||||
Color::MaskedTexture(id) => {
|
||||
let b = poly.get_bounds();
|
||||
let tx = (pt.x() - b.min_x) / (b.max_x - b.min_x);
|
||||
let ty = (pt.y() - b.min_y) / (b.max_y - b.min_y);
|
||||
[tx as f32, ty as f32, id.0, 200.0 + id.1]
|
||||
}
|
||||
Color::CustomUVTexture(id) => {
|
||||
let (tx, ty) =
|
||||
maybe_uv.expect("CustomUVTexture with polygon lacking UV")[idx];
|
||||
|
@ -5,7 +5,6 @@ use crate::{
|
||||
};
|
||||
use geom::{Circle, Distance, Polygon, Pt2D};
|
||||
|
||||
// Assumed circular.
|
||||
pub struct Button {
|
||||
draw_normal: Drawable,
|
||||
draw_hovered: Drawable,
|
||||
@ -167,8 +166,7 @@ impl Button {
|
||||
);
|
||||
|
||||
let normal = GeomBatch::from(vec![(color, rect.clone())]);
|
||||
// TODO Different color...
|
||||
let hovered = GeomBatch::from(vec![(color, rect.clone())]);
|
||||
let hovered = GeomBatch::from(vec![(color.with_masking(), rect.clone())]);
|
||||
Button::new(normal, hovered, key, "", rect, ctx)
|
||||
}
|
||||
|
||||
@ -233,6 +231,8 @@ impl Button {
|
||||
const HORIZ_PADDING: f64 = 30.0;
|
||||
const VERT_PADDING: f64 = 10.0;
|
||||
|
||||
// TODO Unify with Button. Maybe Drawable should subsume MultiText (and understand screens-space
|
||||
// offsets)
|
||||
pub struct TextButton {
|
||||
bg_unselected: Drawable,
|
||||
bg_selected: Drawable,
|
||||
|
Loading…
Reference in New Issue
Block a user