mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
gg: add draw_ellipse_filled() + draw_ellipse_empty() APIs (#12869)
This commit is contained in:
parent
08766da7e8
commit
75830f1fe3
@ -70,6 +70,7 @@ const (
|
|||||||
]
|
]
|
||||||
skip_on_musl = [
|
skip_on_musl = [
|
||||||
'vlib/v/tests/profile/profile_test.v',
|
'vlib/v/tests/profile/profile_test.v',
|
||||||
|
'vlib/gg/draw_fns_api_test.v',
|
||||||
]
|
]
|
||||||
skip_on_ubuntu_musl = [
|
skip_on_ubuntu_musl = [
|
||||||
//'vlib/v/gen/js/jsgen_test.v',
|
//'vlib/v/gen/js/jsgen_test.v',
|
||||||
|
24
vlib/gg/draw_fns_api_test.v
Normal file
24
vlib/gg/draw_fns_api_test.v
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
fn test_all_samples_can_be_compiled() {
|
||||||
|
vexe := @VEXE
|
||||||
|
vroot := os.dir(vexe)
|
||||||
|
samples := os.walk_ext('$vroot/vlib/gg/testdata', '.vv')
|
||||||
|
mut fails := []string{}
|
||||||
|
for program_source in samples {
|
||||||
|
compile_cmd := '"$vexe" "$program_source"'
|
||||||
|
res := os.execute(compile_cmd)
|
||||||
|
if res.exit_code != 0 {
|
||||||
|
eprintln('>>> FAIL $compile_cmd')
|
||||||
|
fails << compile_cmd
|
||||||
|
}
|
||||||
|
println('OK $compile_cmd')
|
||||||
|
}
|
||||||
|
if fails.len > 0 {
|
||||||
|
eprintln('> Failed summary:')
|
||||||
|
for f in fails {
|
||||||
|
eprintln(' failed cmd: $f')
|
||||||
|
}
|
||||||
|
assert false
|
||||||
|
}
|
||||||
|
}
|
@ -1029,3 +1029,38 @@ pub fn dpi_scale() f32 {
|
|||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// draw_ellipse_filled draws an opaque elipse, with a center at x,y , filled with the color `c`
|
||||||
|
pub fn (ctx &Context) draw_ellipse_filled(x f32, y f32, r_horizontal f32, r_vertical 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_triangle_strip()
|
||||||
|
for i := 0; i < 360; i += 10 {
|
||||||
|
sgl.v2f(x, y)
|
||||||
|
sgl.v2f(x + math.sinf(f32(math.radians(i))) * r_horizontal, y +
|
||||||
|
math.cosf(f32(math.radians(i))) * r_vertical)
|
||||||
|
sgl.v2f(x + math.sinf(f32(math.radians(i + 10))) * r_horizontal, y +
|
||||||
|
math.cosf(f32(math.radians(i + 10))) * r_vertical)
|
||||||
|
}
|
||||||
|
sgl.end()
|
||||||
|
}
|
||||||
|
|
||||||
|
// draw_ellipse_empty draws the outline of an ellipse, with a center at x,y
|
||||||
|
pub fn (ctx &Context) draw_ellipse_empty(x f32, y f32, r_horizontal f32, r_vertical 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()
|
||||||
|
for i := 0; i < 360; i += 10 {
|
||||||
|
sgl.v2f(x + math.sinf(f32(math.radians(i))) * r_horizontal, y +
|
||||||
|
math.cosf(f32(math.radians(i))) * r_vertical)
|
||||||
|
sgl.v2f(x + math.sinf(f32(math.radians(i + 10))) * r_horizontal, y +
|
||||||
|
math.cosf(f32(math.radians(i + 10))) * r_vertical)
|
||||||
|
}
|
||||||
|
sgl.end()
|
||||||
|
}
|
||||||
|
21
vlib/gg/testdata/draw_elipses.vv
vendored
Normal file
21
vlib/gg/testdata/draw_elipses.vv
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
module main
|
||||||
|
|
||||||
|
import gg
|
||||||
|
import gx
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
mut context := gg.new_context(
|
||||||
|
width: 200
|
||||||
|
height: 200
|
||||||
|
window_title: 'Elipses'
|
||||||
|
frame_fn: frame
|
||||||
|
)
|
||||||
|
context.run()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn frame(mut ctx gg.Context) {
|
||||||
|
ctx.begin()
|
||||||
|
ctx.draw_ellipse_filled(100, 100, 100, 50, gx.red)
|
||||||
|
ctx.draw_ellipse_empty(100, 100, 50, 25, gx.black)
|
||||||
|
ctx.end()
|
||||||
|
}
|
24
vlib/gg/testdata/draw_polygons.vv
vendored
Normal file
24
vlib/gg/testdata/draw_polygons.vv
vendored
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
module main
|
||||||
|
|
||||||
|
import gg
|
||||||
|
import gx
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
mut context := gg.new_context(
|
||||||
|
bg_color: gx.rgb(174, 198, 255)
|
||||||
|
width: 600
|
||||||
|
height: 400
|
||||||
|
window_title: 'Polygons'
|
||||||
|
frame_fn: frame
|
||||||
|
)
|
||||||
|
context.run()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn frame(mut ctx gg.Context) {
|
||||||
|
ctx.begin()
|
||||||
|
ctx.draw_convex_poly([f32(100.0), 100.0, 200.0, 100.0, 300.0, 200.0, 200.0, 300.0, 100.0, 300.0],
|
||||||
|
gx.blue)
|
||||||
|
ctx.draw_empty_poly([f32(50.0), 50.0, 70.0, 60.0, 90.0, 80.0, 70.0, 110.0], gx.black)
|
||||||
|
ctx.draw_triangle(450, 142, 530, 280, 370, 280, gx.red)
|
||||||
|
ctx.end()
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user