v2 / examples / gg / rectangles.v
43 lines · 37 sloc · 870 bytes · bbb61ab3687afe512a1fa12492c876d011626107
Raw
1module main
2
3import gg
4import os.asset
5
6const win_width = 600
7const win_height = 300
8
9struct App {
10mut:
11 gg &gg.Context = unsafe { nil }
12 image int // gg.Image
13}
14
15fn main() {
16 mut app := &App{}
17 app.gg = gg.new_context(
18 bg_color: gg.white
19 width: win_width
20 height: win_height
21 create_window: true
22 window_title: 'Rectangles'
23 frame_fn: frame
24 user_data: app
25 )
26 logo_path := asset.get_path('../assets', 'logo.png')
27 app.image = app.gg.create_image(logo_path)!.id
28 app.gg.run()
29}
30
31fn frame(app &App) {
32 app.gg.begin()
33 app.draw()
34 app.gg.end()
35}
36
37fn (app &App) draw() {
38 // app.gg.draw_text_def(200,20, 'hello world!')
39 // app.gg.draw_text_def(300,300, 'привет')
40 app.gg.draw_rect_filled(10, 10, 100, 30, gg.blue)
41 app.gg.draw_rect_empty(110, 150, 80, 40, gg.black)
42 app.gg.draw_image_by_id(230, 30, 200, 200, app.image)
43}
44