Skip to content

Commit 8745ab1

Browse files
authored
gg: cleanup some testdata and add a new sample draw_rounded_rect_filled.vv (#26389)
1 parent f61de59 commit 8745ab1

File tree

6 files changed

+99
-91
lines changed

6 files changed

+99
-91
lines changed

vlib/gg/testdata/draw_arcs.vv

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,14 @@ module main
33
import math
44
import gg
55

6-
fn main() {
7-
mut context := gg.new_context(
8-
width: 200
9-
height: 200
10-
window_title: 'Arcs'
11-
frame_fn: frame
12-
)
13-
context.run()
14-
}
15-
16-
fn frame(mut ctx gg.Context) {
17-
ctx.begin()
18-
ctx.draw_arc_filled(100, 100, 35, 45, 0, f32(math.radians(290)), 30, gg.red)
19-
ctx.draw_arc_empty(100, 100, 30, 50, 0, f32(math.radians(290)), 30, gg.white)
20-
ctx.end()
21-
}
6+
gg.start(
7+
window_title: 'Arcs'
8+
width: 200
9+
height: 200
10+
frame_fn: fn (mut ctx gg.Context) {
11+
ctx.begin()
12+
ctx.draw_arc_filled(100, 100, 35, 45, 0, f32(math.radians(290)), 30, gg.red)
13+
ctx.draw_arc_empty(100, 100, 30, 50, 0, f32(math.radians(290)), 30, gg.white)
14+
ctx.end()
15+
}
16+
)

vlib/gg/testdata/draw_circles.vv

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,17 @@ module main
22

33
import gg
44

5-
fn main() {
6-
mut context := gg.new_context(
7-
width: 300
8-
height: 300
9-
window_title: 'Circles'
10-
frame_fn: frame
11-
)
12-
context.run()
13-
}
14-
15-
fn frame(mut ctx gg.Context) {
16-
ctx.begin()
17-
ctx.draw_circle_empty(150, 150, 80, gg.blue)
18-
ctx.draw_circle_filled(150, 150, 40, gg.yellow)
19-
ctx.draw_circle_line(150, 150, 80, 6, gg.red)
20-
ctx.draw_circle_line(150, 150, 120, 6, gg.green)
21-
ctx.draw_circle_line(150, 150, 150, 8, gg.white)
22-
ctx.end()
23-
}
5+
gg.start(
6+
width: 300
7+
height: 300
8+
window_title: 'Circles'
9+
frame_fn: fn (mut ctx gg.Context) {
10+
ctx.begin()
11+
ctx.draw_circle_empty(150, 150, 80, gg.blue)
12+
ctx.draw_circle_filled(150, 150, 40, gg.yellow)
13+
ctx.draw_circle_line(150, 150, 80, 6, gg.red)
14+
ctx.draw_circle_line(150, 150, 120, 6, gg.green)
15+
ctx.draw_circle_line(150, 150, 150, 8, gg.white)
16+
ctx.end()
17+
}
18+
)

vlib/gg/testdata/draw_polygons.vv

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,17 @@ module main
22

33
import gg
44

5-
fn main() {
6-
mut context := gg.new_context(
7-
bg_color: gg.rgb(174, 198, 255)
8-
width: 600
9-
height: 400
10-
window_title: 'Polygons'
11-
frame_fn: frame
12-
)
13-
context.run()
14-
}
15-
16-
fn frame(mut ctx gg.Context) {
17-
ctx.begin()
18-
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],
19-
gg.blue)
20-
ctx.draw_poly_empty([f32(50.0), 50.0, 70.0, 60.0, 90.0, 80.0, 70.0, 110.0], gg.black)
21-
ctx.draw_triangle_filled(450, 142, 530, 280, 370, 280, gg.red)
22-
ctx.end()
23-
}
5+
gg.start(
6+
bg_color: gg.rgb(174, 198, 255)
7+
width: 600
8+
height: 400
9+
window_title: 'Polygons'
10+
frame_fn: fn (mut ctx gg.Context) {
11+
ctx.begin()
12+
ctx.draw_convex_poly([f32(100.0), 100.0, 200.0, 100.0, 300.0, 200.0, 200.0, 300.0, 100.0,
13+
300.0], gg.blue)
14+
ctx.draw_poly_empty([f32(50.0), 50.0, 70.0, 60.0, 90.0, 80.0, 70.0, 110.0], gg.black)
15+
ctx.draw_triangle_filled(450, 142, 530, 280, 370, 280, gg.red)
16+
ctx.end()
17+
}
18+
)

vlib/gg/testdata/draw_rounded_rect_empty.vv

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,27 @@ module main
22

33
import gg
44

5-
fn main() {
6-
mut context := gg.new_context(
7-
width: 325
8-
height: 275
9-
window_title: 'Rounded Rectangles'
10-
frame_fn: frame
11-
)
12-
context.run()
13-
}
14-
15-
fn frame(mut ctx gg.Context) {
16-
ctx.begin()
17-
// these should be rounded rectangles
18-
ctx.draw_rounded_rect_empty(10, 10, 50, 100, 5, gg.blue)
19-
ctx.draw_rounded_rect_empty(25, 25, 50, 100, 15, gg.yellow)
20-
ctx.draw_rounded_rect_empty(50, 50, 50, 100, 50, gg.red)
21-
ctx.draw_rounded_rect_empty(75, 75, 50, 100, 100, gg.green)
22-
ctx.draw_rounded_rect_empty(100, 100, 50, 100, 1000, gg.white)
23-
ctx.draw_rounded_rect_empty(110, 10, 100, 50, 5, gg.blue)
24-
ctx.draw_rounded_rect_empty(125, 25, 100, 50, 15, gg.yellow)
25-
ctx.draw_rounded_rect_empty(150, 50, 100, 50, 50, gg.red)
26-
ctx.draw_rounded_rect_empty(175, 75, 100, 50, 100, gg.green)
27-
ctx.draw_rounded_rect_empty(200, 100, 100, 50, 1000, gg.white)
28-
// this should be a perfect circle
29-
ctx.draw_rounded_rect_empty(10, 200, 50, 50, 1000, gg.magenta)
30-
// this should be a perfect square
31-
ctx.draw_rounded_rect_empty(250, 200, 50, 50, 0, gg.cyan)
32-
ctx.end()
33-
}
5+
gg.start(
6+
width: 325
7+
height: 275
8+
window_title: 'Rounded Rectangles'
9+
frame_fn: fn (mut ctx gg.Context) {
10+
ctx.begin()
11+
// these should be rounded rectangles
12+
ctx.draw_rounded_rect_empty(10, 10, 50, 100, 5, gg.blue)
13+
ctx.draw_rounded_rect_empty(25, 25, 50, 100, 15, gg.yellow)
14+
ctx.draw_rounded_rect_empty(50, 50, 50, 100, 50, gg.red)
15+
ctx.draw_rounded_rect_empty(75, 75, 50, 100, 100, gg.green)
16+
ctx.draw_rounded_rect_empty(100, 100, 50, 100, 1000, gg.white)
17+
ctx.draw_rounded_rect_empty(110, 10, 100, 50, 5, gg.blue)
18+
ctx.draw_rounded_rect_empty(125, 25, 100, 50, 15, gg.yellow)
19+
ctx.draw_rounded_rect_empty(150, 50, 100, 50, 50, gg.red)
20+
ctx.draw_rounded_rect_empty(175, 75, 100, 50, 100, gg.green)
21+
ctx.draw_rounded_rect_empty(200, 100, 100, 50, 1000, gg.white)
22+
// this should be a perfect circle
23+
ctx.draw_rounded_rect_empty(10, 200, 50, 50, 1000, gg.magenta)
24+
// this should be a perfect square
25+
ctx.draw_rounded_rect_empty(250, 200, 50, 50, 0, gg.cyan)
26+
ctx.end()
27+
}
28+
)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module main
2+
3+
import gg
4+
5+
gg.start(
6+
width: 325
7+
height: 275
8+
window_title: 'Rounded Rectangles'
9+
frame_fn: fn (mut ctx gg.Context) {
10+
ctx.begin()
11+
// these should be rounded rectangles
12+
ctx.draw_rounded_rect_filled(10, 10, 50, 100, 5, gg.blue)
13+
ctx.draw_rounded_rect_filled(25, 25, 50, 100, 15, gg.yellow)
14+
ctx.draw_rounded_rect_filled(50, 50, 50, 100, 50, gg.red)
15+
ctx.draw_rounded_rect_filled(75, 75, 50, 100, 100, gg.green)
16+
ctx.draw_rounded_rect_filled(100, 100, 50, 100, 1000, gg.white)
17+
ctx.draw_rounded_rect_filled(110, 10, 100, 50, 5, gg.blue)
18+
ctx.draw_rounded_rect_filled(125, 25, 100, 50, 15, gg.yellow)
19+
ctx.draw_rounded_rect_filled(150, 50, 100, 50, 50, gg.red)
20+
ctx.draw_rounded_rect_filled(175, 75, 100, 50, 100, gg.green)
21+
ctx.draw_rounded_rect_filled(200, 100, 100, 50, 1000, gg.white)
22+
// this should be a perfect circle
23+
ctx.draw_rounded_rect_filled(10, 200, 50, 50, 1000, gg.magenta)
24+
// this should be a perfect square
25+
ctx.draw_rounded_rect_filled(250, 200, 50, 50, 0, gg.cyan)
26+
ctx.end()
27+
}
28+
)

vlib/gg/testdata/draw_simple_polygons.vv

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import gg
55
struct App {
66
mut:
77
gg &gg.Context = unsafe { nil }
8-
rotation f32 = f32(0)
9-
edge int = 3
8+
rotation f32 = f32(0)
9+
edge int = 3
1010
}
1111

1212
fn main() {
@@ -17,12 +17,12 @@ fn main() {
1717

1818
app.gg = gg.new_context(
1919
window_title: 'Simple Polygons'
20-
width: 500
21-
height: 500
22-
bg_color: gg.black
23-
event_fn: event
24-
frame_fn: render
25-
user_data: app
20+
width: 500
21+
height: 500
22+
bg_color: gg.black
23+
event_fn: event
24+
frame_fn: render
25+
user_data: app
2626
)
2727

2828
app.gg.run()

0 commit comments

Comments
 (0)