fix rounded rect gradient

This commit is contained in:
griffi-gh 2024-03-02 01:19:47 +01:00
parent 6549a6a410
commit d1588932e5

View file

@ -159,29 +159,43 @@ impl UiDrawCall {
let x = angle.sin(); let x = angle.sin();
let y = angle.cos(); let y = angle.cos();
//Top-right corner //Top-right corner
let mut corner_impl = |rp: Vec2, color: &Corners<Vec4>, uv: Vec2| {
//TODO: also calculate proper uv
let rrp = rp / *size;
let color_at_point =
color.bottom_right * rrp.x * rrp.y +
color.top_right * rrp.x * (1. - rrp.y) +
color.bottom_left * (1. - rrp.x) * rrp.y +
color.top_left * (1. - rrp.x) * (1. - rrp.y);
draw_call.vertices.push(UiVertex { draw_call.vertices.push(UiVertex {
position: *position + vec2(x, 1. - y) * corner.radius.top_right + vec2(size.x - corner.radius.top_right, 0.), position: *position + rp,
color: color.top_right, color: color_at_point,
uv: uvs.top_right, uv,
}); });
};
corner_impl(
vec2(x, 1. - y) * corner.radius.top_right + vec2(size.x - corner.radius.top_right, 0.),
color,
uvs.top_right,
);
//Bottom-right corner //Bottom-right corner
draw_call.vertices.push(UiVertex { corner_impl(
position: *position + vec2(x - 1., y) * corner.radius.bottom_right + vec2(size.x, size.y - corner.radius.bottom_right), vec2(x - 1., y) * corner.radius.bottom_right + vec2(size.x, size.y - corner.radius.bottom_right),
color: color.bottom_right, color,
uv: uvs.bottom_right, uvs.bottom_right,
}); );
//Bottom-left corner //Bottom-left corner
draw_call.vertices.push(UiVertex { corner_impl(
position: *position + vec2(1. - x, y) * corner.radius.bottom_left + vec2(0., size.y - corner.radius.bottom_left), vec2(1. - x, y) * corner.radius.bottom_left + vec2(0., size.y - corner.radius.bottom_left),
color: color.bottom_left, color,
uv: uvs.bottom_left, uvs.bottom_left,
}); );
//Top-left corner //Top-left corner
draw_call.vertices.push(UiVertex { corner_impl(
position: *position + vec2(1. - x, 1. - y) * corner.radius.top_left, vec2(1. - x, 1. - y) * corner.radius.top_left,
color: color.top_left, color,
uv: uvs.top_left, uvs.top_left,
}); );
// mental illness: // mental illness:
if i > 0 { if i > 0 {
draw_call.indices.extend([ draw_call.indices.extend([