forked from g3n/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
window.go
142 lines (119 loc) · 3.37 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Copyright 2016 The G3N Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package window abstracts a platform-specific window.
// Depending on the build tags it can be a GLFW desktop window or a browser WebGlCanvas.
package window
import (
"fmt"
"github.com/Cyberselves/engine/core"
"github.com/Cyberselves/engine/gls"
"github.com/Cyberselves/engine/util/logger"
)
// Package logger
var log = logger.New("WIN", logger.Default)
// IWindow singleton
var win IWindow
// Get returns the IWindow singleton.
func Get() IWindow {
// Return singleton if already created
if win != nil {
return win
}
panic(fmt.Errorf("need to call window.Init() first"))
}
// IWindow is the interface for all windows
type IWindow interface {
core.IDispatcher
Gls() *gls.GLS
GetFramebufferSize() (width int, height int)
GetSize() (width int, height int)
GetScale() (x float64, y float64)
CreateCursor(imgFile string, xhot, yhot int) (Cursor, error)
SetCursor(cursor Cursor)
DisposeAllCustomCursors()
Destroy()
FullScreen() bool
SetFullScreen(full bool)
}
// Key corresponds to a keyboard key.
type Key int
// ModifierKey corresponds to a set of modifier keys (bitmask).
type ModifierKey int
// MouseButton corresponds to a mouse button.
type MouseButton int
// InputMode corresponds to an input mode.
type InputMode int
// InputMode corresponds to an input mode.
type CursorMode int
// Cursor corresponds to a g3n standard or user-created cursor icon.
type Cursor int
// Standard cursors for G3N.
const (
ArrowCursor = Cursor(iota)
IBeamCursor
CrosshairCursor
HandCursor
HResizeCursor
VResizeCursor
DiagResize1Cursor
DiagResize2Cursor
CursorLast = DiagResize2Cursor
)
// Window event names. See availability per platform below ("x" indicates available).
const ( // Desktop | Browser |
OnWindowFocus = "w.OnWindowFocus" // x | x |
OnWindowPos = "w.OnWindowPos" // x | |
OnWindowSize = "w.OnWindowSize" // x | |
OnKeyUp = "w.OnKeyUp" // x | x |
OnKeyDown = "w.OnKeyDown" // x | x |
OnKeyRepeat = "w.OnKeyRepeat" // x | |
OnChar = "w.OnChar" // x | x |
OnCursor = "w.OnCursor" // x | x |
OnMouseUp = "w.OnMouseUp" // x | x |
OnMouseDown = "w.OnMouseDown" // x | x |
OnScroll = "w.OnScroll" // x | x |
)
// PosEvent describes a windows position changed event
type PosEvent struct {
Xpos int
Ypos int
}
// SizeEvent describers a window size changed event
type SizeEvent struct {
Width int
Height int
}
// KeyEvent describes a window key event
type KeyEvent struct {
Key Key
Mods ModifierKey
}
// CharEvent describes a window char event
type CharEvent struct {
Char rune
Mods ModifierKey
}
// MouseEvent describes a mouse event over the window
type MouseEvent struct {
Xpos float32
Ypos float32
Button MouseButton
Mods ModifierKey
}
// CursorEvent describes a cursor position changed event
type CursorEvent struct {
Xpos float32
Ypos float32
Mods ModifierKey
}
// ScrollEvent describes a scroll event
type ScrollEvent struct {
Xoffset float32
Yoffset float32
Mods ModifierKey
}
// FocusEvent describes a focus event
type FocusEvent struct {
Focused bool
}