v / examples / gg
Raw file | 53 loc (46 sloc) | 981 bytes | Latest commit hash 68501677e
1module main
2
3import gg
4import gx
5import os
6
7const (
8 win_width = 600
9 win_height = 300
10)
11
12struct App {
13mut:
14 gg &gg.Context = unsafe { nil }
15 image int // gg.Image
16}
17
18fn main() {
19 mut app := &App{
20 gg: 0
21 }
22 app.gg = gg.new_context(
23 bg_color: gx.white
24 width: win_width
25 height: win_height
26 create_window: true
27 window_title: 'Rectangles'
28 frame_fn: frame
29 user_data: app
30 init_fn: init_images
31 )
32 mut logo_path := os.resource_abs_path(os.join_path('..', 'assets', 'logo.png'))
33 app.image = app.gg.create_image(logo_path)!.id
34 app.gg.run()
35}
36
37fn init_images(mut app App) {
38 // app.image = gg.create_image('logo.png')
39}
40
41fn frame(app &App) {
42 app.gg.begin()
43 app.draw()
44 app.gg.end()
45}
46
47fn (app &App) draw() {
48 // app.gg.draw_text_def(200,20, 'hello world!')
49 // app.gg.draw_text_def(300,300, 'привет')
50 app.gg.draw_rect_filled(10, 10, 100, 30, gx.blue)
51 app.gg.draw_rect_empty(110, 150, 80, 40, gx.black)
52 app.gg.draw_image_by_id(230, 30, 200, 200, app.image)
53}