-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathdefault.go
104 lines (86 loc) · 2.59 KB
/
default.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package oak
import (
"image"
"sync"
"time"
"github.com/oakmound/oak/v4/alg/intgeom"
"github.com/oakmound/oak/v4/event"
"github.com/oakmound/oak/v4/key"
"github.com/oakmound/oak/v4/render"
"github.com/oakmound/oak/v4/scene"
)
var defaultWindow *Window
var initDefaultWindowOnce sync.Once
func initDefaultWindow() {
initDefaultWindowOnce.Do(func() {
defaultWindow = NewWindow()
})
}
// Init calls Init on the default window. The default window
// will be set to use render.GlobalDrawStack and event.DefaultBus.
func Init(scene string, configOptions ...ConfigOption) error {
initDefaultWindow()
defaultWindow.DrawStack = render.GlobalDrawStack
defaultWindow.eventHandler = event.DefaultBus
return defaultWindow.Init(scene, configOptions...)
}
// AddScene calls AddScene on the default window.
func AddScene(name string, sc scene.Scene) error {
initDefaultWindow()
return defaultWindow.AddScene(name, sc)
}
// IsDown calls IsDown on the default window.
func IsDown(k key.Code) bool {
initDefaultWindow()
return defaultWindow.IsDown(k)
}
// IsHeld calls IsHeld on the default window.
func IsHeld(k key.Code) (bool, time.Duration) {
initDefaultWindow()
return defaultWindow.IsHeld(k)
}
// SetViewportBounds calls SetViewportBounds on the default window.
func SetViewportBounds(rect intgeom.Rect2) {
initDefaultWindow()
defaultWindow.SetViewportBounds(rect)
}
// ShiftViewport calls ShiftViewport on the default window.
func ShiftViewport(pt intgeom.Point2) {
initDefaultWindow()
defaultWindow.ShiftViewport(pt)
}
// SetViewport calls SetViewport on the default window.
func SetViewport(pt intgeom.Point2) {
initDefaultWindow()
defaultWindow.SetViewport(pt)
}
// UpdateViewSize calls UpdateViewSize on the default window.
func UpdateViewSize(w, h int) error {
initDefaultWindow()
return defaultWindow.UpdateViewSize(w, h)
}
// ScreenShot calls ScreenShot on the default window.
func ScreenShot() *image.RGBA {
initDefaultWindow()
return defaultWindow.ScreenShot()
}
// SetLoadingRenderable calls SetLoadingRenderable on the default window.
func SetLoadingRenderable(r render.Renderable) {
initDefaultWindow()
defaultWindow.SetLoadingRenderable(r)
}
// SetBackground calls SetBackground on the default window.
func SetBackground(b Background) {
initDefaultWindow()
defaultWindow.SetBackground(b)
}
// SetColorBackground calls SetColorBackground on the default window.
func SetColorBackground(img image.Image) {
initDefaultWindow()
defaultWindow.SetColorBackground(img)
}
// Bounds returns the default window's boundary.
func Bounds() intgeom.Point2 {
initDefaultWindow()
return defaultWindow.Bounds()
}