mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
gg: improve some loops in draw_rounded_rect* methods (#14195)
This commit is contained in:
parent
f53b9b4f12
commit
eb03fad934
@ -250,12 +250,10 @@ pub fn (ctx &Context) draw_rounded_rect_empty(x f32, y f32, w f32, h f32, radius
|
|||||||
mut dx := f32(0)
|
mut dx := f32(0)
|
||||||
mut dy := f32(0)
|
mut dy := f32(0)
|
||||||
|
|
||||||
|
if r != 0 {
|
||||||
// left top quarter
|
// left top quarter
|
||||||
sgl.begin_line_strip()
|
sgl.begin_line_strip()
|
||||||
for i in 0 .. 31 {
|
for i in 0 .. 31 {
|
||||||
if r == 0 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
rad = f32(math.radians(i * 3))
|
rad = f32(math.radians(i * 3))
|
||||||
dx = r * math.cosf(rad)
|
dx = r * math.cosf(rad)
|
||||||
dy = r * math.sinf(rad)
|
dy = r * math.sinf(rad)
|
||||||
@ -266,9 +264,6 @@ pub fn (ctx &Context) draw_rounded_rect_empty(x f32, y f32, w f32, h f32, radius
|
|||||||
// right top quarter
|
// right top quarter
|
||||||
sgl.begin_line_strip()
|
sgl.begin_line_strip()
|
||||||
for i in 0 .. 31 {
|
for i in 0 .. 31 {
|
||||||
if r == 0 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
rad = f32(math.radians(i * 3))
|
rad = f32(math.radians(i * 3))
|
||||||
dx = r * math.cosf(rad)
|
dx = r * math.cosf(rad)
|
||||||
dy = r * math.sinf(rad)
|
dy = r * math.sinf(rad)
|
||||||
@ -279,9 +274,6 @@ pub fn (ctx &Context) draw_rounded_rect_empty(x f32, y f32, w f32, h f32, radius
|
|||||||
// right bottom quarter
|
// right bottom quarter
|
||||||
sgl.begin_line_strip()
|
sgl.begin_line_strip()
|
||||||
for i in 0 .. 31 {
|
for i in 0 .. 31 {
|
||||||
if r == 0 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
rad = f32(math.radians(i * 3))
|
rad = f32(math.radians(i * 3))
|
||||||
dx = r * math.cosf(rad)
|
dx = r * math.cosf(rad)
|
||||||
dy = r * math.sinf(rad)
|
dy = r * math.sinf(rad)
|
||||||
@ -292,15 +284,13 @@ pub fn (ctx &Context) draw_rounded_rect_empty(x f32, y f32, w f32, h f32, radius
|
|||||||
// left bottom quarter
|
// left bottom quarter
|
||||||
sgl.begin_line_strip()
|
sgl.begin_line_strip()
|
||||||
for i in 0 .. 31 {
|
for i in 0 .. 31 {
|
||||||
if r == 0 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
rad = f32(math.radians(i * 3))
|
rad = f32(math.radians(i * 3))
|
||||||
dx = r * math.cosf(rad)
|
dx = r * math.cosf(rad)
|
||||||
dy = r * math.sinf(rad)
|
dy = r * math.sinf(rad)
|
||||||
sgl.v2f(lbx - dx, lby + dy)
|
sgl.v2f(lbx - dx, lby + dy)
|
||||||
}
|
}
|
||||||
sgl.end()
|
sgl.end()
|
||||||
|
}
|
||||||
|
|
||||||
// Currently don't use 'gg.draw_line()' directly, it will repeatedly execute '*ctx.scale'.
|
// Currently don't use 'gg.draw_line()' directly, it will repeatedly execute '*ctx.scale'.
|
||||||
sgl.begin_lines()
|
sgl.begin_lines()
|
||||||
@ -358,12 +348,10 @@ pub fn (ctx &Context) draw_rounded_rect_filled(x f32, y f32, w f32, h f32, radiu
|
|||||||
mut dx := f32(0)
|
mut dx := f32(0)
|
||||||
mut dy := f32(0)
|
mut dy := f32(0)
|
||||||
|
|
||||||
|
if r != 0 {
|
||||||
// left top quarter
|
// left top quarter
|
||||||
sgl.begin_triangle_strip()
|
sgl.begin_triangle_strip()
|
||||||
for i in 0 .. 31 {
|
for i in 0 .. 31 {
|
||||||
if r == 0 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
rad = f32(math.radians(i * 3))
|
rad = f32(math.radians(i * 3))
|
||||||
dx = r * math.cosf(rad)
|
dx = r * math.cosf(rad)
|
||||||
dy = r * math.sinf(rad)
|
dy = r * math.sinf(rad)
|
||||||
@ -375,9 +363,6 @@ pub fn (ctx &Context) draw_rounded_rect_filled(x f32, y f32, w f32, h f32, radiu
|
|||||||
// right top quarter
|
// right top quarter
|
||||||
sgl.begin_triangle_strip()
|
sgl.begin_triangle_strip()
|
||||||
for i in 0 .. 31 {
|
for i in 0 .. 31 {
|
||||||
if r == 0 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
rad = f32(math.radians(i * 3))
|
rad = f32(math.radians(i * 3))
|
||||||
dx = r * math.cosf(rad)
|
dx = r * math.cosf(rad)
|
||||||
dy = r * math.sinf(rad)
|
dy = r * math.sinf(rad)
|
||||||
@ -389,9 +374,6 @@ pub fn (ctx &Context) draw_rounded_rect_filled(x f32, y f32, w f32, h f32, radiu
|
|||||||
// right bottom quarter
|
// right bottom quarter
|
||||||
sgl.begin_triangle_strip()
|
sgl.begin_triangle_strip()
|
||||||
for i in 0 .. 31 {
|
for i in 0 .. 31 {
|
||||||
if r == 0 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
rad = f32(math.radians(i * 3))
|
rad = f32(math.radians(i * 3))
|
||||||
dx = r * math.cosf(rad)
|
dx = r * math.cosf(rad)
|
||||||
dy = r * math.sinf(rad)
|
dy = r * math.sinf(rad)
|
||||||
@ -403,9 +385,6 @@ pub fn (ctx &Context) draw_rounded_rect_filled(x f32, y f32, w f32, h f32, radiu
|
|||||||
// left bottom quarter
|
// left bottom quarter
|
||||||
sgl.begin_triangle_strip()
|
sgl.begin_triangle_strip()
|
||||||
for i in 0 .. 31 {
|
for i in 0 .. 31 {
|
||||||
if r == 0 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
rad = f32(math.radians(i * 3))
|
rad = f32(math.radians(i * 3))
|
||||||
dx = r * math.cosf(rad)
|
dx = r * math.cosf(rad)
|
||||||
dy = r * math.sinf(rad)
|
dy = r * math.sinf(rad)
|
||||||
@ -413,6 +392,7 @@ pub fn (ctx &Context) draw_rounded_rect_filled(x f32, y f32, w f32, h f32, radiu
|
|||||||
sgl.v2f(lbx, lby)
|
sgl.v2f(lbx, lby)
|
||||||
}
|
}
|
||||||
sgl.end()
|
sgl.end()
|
||||||
|
}
|
||||||
|
|
||||||
// Separate drawing is to prevent transparent color overlap
|
// Separate drawing is to prevent transparent color overlap
|
||||||
// top rectangle
|
// top rectangle
|
||||||
|
Loading…
x
Reference in New Issue
Block a user