-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow.go
81 lines (63 loc) · 1.39 KB
/
window.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* Gyro - A modern UI toolkit for Golang
* Copyright (C) 2018 Roland Singer <[email protected]>
*/
package nano
import (
"github.com/gyrolab/gyro"
"github.com/gyrolab/nanovgo"
"github.com/desertbit/closer"
"github.com/goxjs/gl"
"github.com/goxjs/glfw"
)
type Window struct {
*closer.Closer
*widgets
//ctx *Context
win *glfw.Window
nc *nanovgo.Context
title string
bgColor gyro.Color
bgColorR float32
bgColorG float32
bgColorB float32
bgColorA float32
}
func (b *Backend) NewWindow(
title string,
width, height int,
) (gyro.Window, error) {
// MSAA: multisample antialiasing.
glfw.WindowHint(glfw.Samples, 4)
//glfw.WindowHint(glfw.Visible, 0) // TODO
glfw.WindowHint(glfw.Resizable, 1)
win, err := glfw.CreateWindow(width, height, title, nil, nil)
if err != nil {
return nil, err
}
win.MakeContextCurrent()
width, height = win.GetSize()
gl.Viewport(0, 0, width, height)
nc, err := nanovgo.NewContext(nanovgo.AntiAlias | nanovgo.StencilStrokes)
if err != nil {
return nil, err
}
w := &Window{
win: win,
nc: nc,
title: title,
}
w.widgets = newWidgets(nil) // TODO: must pass the window
w.Closer = closer.New(w.onClose)
// Register the window to the app.
b.app.window = w
return w, nil
}
func (w *Window) onClose() error {
w.nc.Delete()
w.win.Destroy()
return nil
}
func (w *Window) CloseChan() <-chan struct{} {
return w.Closer.CloseChan
}