diff --git a/internal/ui/input.go b/internal/ui/input.go index 7edc372d5..ac6a8f7d8 100644 --- a/internal/ui/input.go +++ b/internal/ui/input.go @@ -39,22 +39,22 @@ const ( MouseButtonMax ) -type input struct { +type Input struct { keyPressed [KeyMax]bool mouseButtonPressed [MouseButtonMax]bool cursorX int cursorY int } -func (i *input) IsKeyPressed(key Key) bool { +func (i *Input) IsKeyPressed(key Key) bool { return i.keyPressed[key] } -func (i *input) IsMouseButtonPressed(button MouseButton) bool { +func (i *Input) IsMouseButtonPressed(button MouseButton) bool { return i.mouseButtonPressed[button] } -func (i *input) CursorPosition() (x, y int) { +func (i *Input) CursorPosition() (x, y int) { return i.cursorX, i.cursorY } @@ -66,7 +66,7 @@ var glfwKeyCodeToKey = map[glfw.Key]Key{ glfw.KeyDown: KeyDown, } -func (i *input) update(window *glfw.Window, scale int) { +func (i *Input) update(window *glfw.Window, scale int) { for g, u := range glfwKeyCodeToKey { i.keyPressed[u] = window.GetKey(g) == glfw.Press } diff --git a/internal/ui/ui.go b/internal/ui/ui.go index ae3245ab5..a497a2a8d 100644 --- a/internal/ui/ui.go +++ b/internal/ui/ui.go @@ -21,10 +21,10 @@ import ( "runtime" ) -var currentUI *UI +var current *UI func Current() *UI { - return currentUI + return current } func init() { @@ -57,7 +57,7 @@ func init() { f() } }() - currentUI = u + current = u } type UI struct { @@ -65,7 +65,7 @@ type UI struct { scale int actualScale int glContext *opengl.Context - input input + input Input funcs chan func() } @@ -82,7 +82,7 @@ func New(width, height, scale int, title string) (*UI, error) { y := (videoMode.Height - height*scale) / 3 ch := make(chan struct{}) - ui := currentUI + ui := current window := ui.window window.SetFramebufferSizeCallback(func(w *glfw.Window, width, height int) { close(ch) @@ -135,7 +135,7 @@ func (u *UI) SwapBuffers() { u.window.SwapBuffers() } -func (u *UI) Input() *input { +func (u *UI) Input() *Input { return &u.input }