gg: fix ctx.scale for circles (#10210)
parent
ddcc22a778
commit
465860e418
66
vlib/gg/gg.v
66
vlib/gg/gg.v
|
@ -419,19 +419,11 @@ pub fn (ctx &Context) draw_empty_rect(x f32, y f32, w f32, h f32, c gx.Color) {
|
|||
}
|
||||
sgl.c4b(c.r, c.g, c.b, c.a)
|
||||
sgl.begin_line_strip()
|
||||
if ctx.scale == 1 {
|
||||
sgl.v2f(x, y)
|
||||
sgl.v2f(x + w, y)
|
||||
sgl.v2f(x + w, y + h)
|
||||
sgl.v2f(x, y + h)
|
||||
sgl.v2f(x, y)
|
||||
} else {
|
||||
sgl.v2f(x * ctx.scale, y * ctx.scale)
|
||||
sgl.v2f((x + w) * ctx.scale, y * ctx.scale)
|
||||
sgl.v2f((x + w) * ctx.scale, (y + h) * ctx.scale)
|
||||
sgl.v2f(x * ctx.scale, (y + h) * ctx.scale)
|
||||
sgl.v2f(x * ctx.scale, y * ctx.scale)
|
||||
}
|
||||
sgl.v2f(x * ctx.scale, y * ctx.scale)
|
||||
sgl.v2f((x + w) * ctx.scale, y * ctx.scale)
|
||||
sgl.v2f((x + w) * ctx.scale, (y + h) * ctx.scale)
|
||||
sgl.v2f(x * ctx.scale, (y + h) * ctx.scale)
|
||||
sgl.v2f(x * ctx.scale, y * ctx.scale)
|
||||
sgl.end()
|
||||
}
|
||||
|
||||
|
@ -465,12 +457,7 @@ pub fn (ctx &Context) draw_circle_line(x f32, y f32, r int, segments int, c gx.C
|
|||
}
|
||||
|
||||
pub fn (ctx &Context) draw_circle(x f32, y f32, r f32, c gx.Color) {
|
||||
if ctx.scale == 1 {
|
||||
ctx.draw_circle_with_segments(x, y, r, 10, c)
|
||||
} else {
|
||||
ctx.draw_circle_with_segments(x * f32(ctx.scale), y * f32(ctx.scale), r * ctx.scale,
|
||||
10, c)
|
||||
}
|
||||
ctx.draw_circle_with_segments(x, y, r, 10, c)
|
||||
}
|
||||
|
||||
pub fn (ctx &Context) draw_circle_with_segments(x f32, y f32, r f32, segments int, c gx.Color) {
|
||||
|
@ -478,16 +465,19 @@ pub fn (ctx &Context) draw_circle_with_segments(x f32, y f32, r f32, segments in
|
|||
sgl.load_pipeline(ctx.timage_pip)
|
||||
}
|
||||
sgl.c4b(c.r, c.g, c.b, c.a)
|
||||
nx := x * ctx.scale
|
||||
ny := y * ctx.scale
|
||||
nr := r * ctx.scale
|
||||
mut theta := f32(0)
|
||||
mut xx := f32(0)
|
||||
mut yy := f32(0)
|
||||
sgl.begin_triangle_strip()
|
||||
for i := 0; i < segments + 1; i++ {
|
||||
theta = 2.0 * f32(math.pi) * f32(i) / f32(segments)
|
||||
xx = r * math.cosf(theta)
|
||||
yy = r * math.sinf(theta)
|
||||
sgl.v2f(xx + x, yy + y)
|
||||
sgl.v2f(x, y)
|
||||
xx = nr * math.cosf(theta)
|
||||
yy = nr * math.sinf(theta)
|
||||
sgl.v2f(xx + nx, yy + ny)
|
||||
sgl.v2f(nx, ny)
|
||||
}
|
||||
sgl.end()
|
||||
}
|
||||
|
@ -500,11 +490,13 @@ pub fn (ctx &Context) draw_arc_line(x f32, y f32, r int, start_angle f32, arc_an
|
|||
theta := f32(arc_angle / f32(segments))
|
||||
tan_factor := math.tanf(theta)
|
||||
rad_factor := math.cosf(theta)
|
||||
nx := x * ctx.scale
|
||||
ny := y * ctx.scale
|
||||
mut xx := f32(r * math.cosf(start_angle))
|
||||
mut yy := f32(r * math.sinf(start_angle))
|
||||
sgl.begin_line_strip()
|
||||
for i := 0; i < segments + 1; i++ {
|
||||
sgl.v2f(xx + x, yy + y)
|
||||
sgl.v2f(xx + nx, yy + ny)
|
||||
tx := -yy
|
||||
ty := xx
|
||||
xx += tx * tan_factor
|
||||
|
@ -520,6 +512,8 @@ pub fn (ctx &Context) draw_arc(x f32, y f32, r int, start_angle f32, arc_angle f
|
|||
sgl.load_pipeline(ctx.timage_pip)
|
||||
}
|
||||
sgl.c4b(c.r, c.g, c.b, c.a)
|
||||
nx := x * ctx.scale
|
||||
ny := y * ctx.scale
|
||||
theta := f32(arc_angle / f32(segments))
|
||||
tan_factor := math.tanf(theta)
|
||||
rad_factor := math.cosf(theta)
|
||||
|
@ -527,8 +521,8 @@ pub fn (ctx &Context) draw_arc(x f32, y f32, r int, start_angle f32, arc_angle f
|
|||
mut yy := f32(r * math.sinf(start_angle))
|
||||
sgl.begin_triangle_strip()
|
||||
for i := 0; i < segments + 1; i++ {
|
||||
sgl.v2f(xx + x, yy + y)
|
||||
sgl.v2f(x, y)
|
||||
sgl.v2f(xx + nx, yy + ny)
|
||||
sgl.v2f(nx, ny)
|
||||
tx := -yy
|
||||
ty := xx
|
||||
xx += tx * tan_factor
|
||||
|
@ -597,11 +591,11 @@ pub fn (ctx &Context) draw_rounded_rect(x f32, y f32, w f32, h f32, radius f32,
|
|||
mut theta := f32(0)
|
||||
mut xx := f32(0)
|
||||
mut yy := f32(0)
|
||||
r := radius * f32(ctx.scale)
|
||||
nx := x * f32(ctx.scale)
|
||||
ny := y * f32(ctx.scale)
|
||||
width := w * f32(ctx.scale)
|
||||
height := h * f32(ctx.scale)
|
||||
r := radius * ctx.scale
|
||||
nx := x * ctx.scale
|
||||
ny := y * ctx.scale
|
||||
width := w * ctx.scale
|
||||
height := h * ctx.scale
|
||||
segments := 2 * math.pi * r
|
||||
segdiv := segments / 4
|
||||
rb := 0
|
||||
|
@ -663,11 +657,11 @@ pub fn (ctx &Context) draw_empty_rounded_rect(x f32, y f32, w f32, h f32, radius
|
|||
mut theta := f32(0)
|
||||
mut xx := f32(0)
|
||||
mut yy := f32(0)
|
||||
r := radius * f32(ctx.scale)
|
||||
nx := x * f32(ctx.scale)
|
||||
ny := y * f32(ctx.scale)
|
||||
width := w * f32(ctx.scale)
|
||||
height := h * f32(ctx.scale)
|
||||
r := radius * ctx.scale
|
||||
nx := x * ctx.scale
|
||||
ny := y * ctx.scale
|
||||
width := w * ctx.scale
|
||||
height := h * ctx.scale
|
||||
segments := 2 * math.pi * r
|
||||
segdiv := segments / 4
|
||||
rb := 0
|
||||
|
|
Loading…
Reference in New Issue