-
Notifications
You must be signed in to change notification settings - Fork 27
/
global.go
79 lines (69 loc) · 1.4 KB
/
global.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
package nanogui
import (
"github.com/goxjs/gl"
"github.com/shibukawa/glfw"
"sync"
"time"
)
var mainloopActive bool = false
var startTime time.Time
var debugFlag bool
func Init() {
err := glfw.Init(gl.ContextWatcher)
if err != nil {
panic(err)
}
startTime = time.Now()
}
func GetTime() float32 {
return float32(time.Now().Sub(startTime)/time.Millisecond) * 0.001
}
func MainLoop() {
mainloopActive = true
var wg sync.WaitGroup
/* If there are no mouse/keyboard events, try to refresh the
view roughly every 50 ms; this is to support animations
such as progress bars while keeping the system load
reasonably low */
wg.Add(1)
go func() {
for mainloopActive {
time.Sleep(50 * time.Millisecond)
glfw.PostEmptyEvent()
}
wg.Done()
}()
for mainloopActive {
haveActiveScreen := false
for _, screen := range nanoguiScreens {
if !screen.Visible() {
continue
} else if screen.GLFWWindow().ShouldClose() {
screen.SetVisible(false)
continue
}
//screen.DebugPrint()
screen.DrawAll()
haveActiveScreen = true
}
if !haveActiveScreen {
mainloopActive = false
break
}
glfw.WaitEvents()
}
wg.Wait()
}
func SetDebug(d bool) {
debugFlag = d
}
func InitWidget(child, parent Widget) {
//w.cursor = Arrow
if parent != nil {
parent.AddChild(parent, child)
child.SetTheme(parent.Theme())
}
child.SetVisible(true)
child.SetEnabled(true)
child.SetFontSize(-1)
}