1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

gg: support transparency for rect/triangle/etc primitives too

This commit is contained in:
Delyan Angelov
2020-09-20 12:05:30 +03:00
parent 4ae88c69ac
commit d4fbf422b3
3 changed files with 18 additions and 2 deletions

View File

@@ -226,6 +226,9 @@ pub fn (mut ctx Context) set_bg_color(c gx.Color) {
// TODO: Fix alpha
pub fn (ctx &Context) draw_rect(x, y, w, h f32, c gx.Color) {
if c.a != 255 {
sgl.load_pipeline(ctx.timage_pip)
}
sgl.c4b(c.r, c.g, c.b, c.a)
sgl.begin_quads()
sgl.v2f(x * ctx.scale, y * ctx.scale)
@@ -236,6 +239,9 @@ pub fn (ctx &Context) draw_rect(x, y, w, h f32, c gx.Color) {
}
pub fn (ctx &Context) draw_triangle(x, y, x2, y2, x3, y3 f32, c gx.Color) {
if c.a != 255 {
sgl.load_pipeline(ctx.timage_pip)
}
sgl.c4b(c.r, c.g, c.b, c.a)
sgl.begin_quads()
sgl.v2f(x * ctx.scale, y * ctx.scale)
@@ -245,6 +251,9 @@ pub fn (ctx &Context) draw_triangle(x, y, x2, y2, x3, y3 f32, c gx.Color) {
}
pub fn (ctx &Context) draw_empty_rect(x, y, w, h f32, c gx.Color) {
if c.a != 255 {
sgl.load_pipeline(ctx.timage_pip)
}
sgl.c4b(c.r, c.g, c.b, c.a)
sgl.begin_line_strip()
if ctx.scale == 1 {
@@ -295,6 +304,9 @@ fn abs(a f32) f32 {
pub fn (ctx &Context) draw_line(x, y, x2, y2 f32, c gx.Color) {
if c.a != 255 {
sgl.load_pipeline(ctx.timage_pip)
}
if ctx.scale > 1 {
// Make the line more clear on hi dpi screens: draw a rectangle
mut width := abs(x2 - x)