Add keys_glfw.go and keys_js.go

This commit is contained in:
Hajime Hoshi 2015-01-07 00:05:46 +09:00
parent a1d3815008
commit a9f1b4f0e9
5 changed files with 54 additions and 20 deletions

View File

@ -33,14 +33,6 @@ func CursorPosition() (x, y int) {
return current.input.cursorPosition() return current.input.cursorPosition()
} }
var glfwKeyCodeToKey = map[glfw.Key]Key{
glfw.KeySpace: KeySpace,
glfw.KeyLeft: KeyLeft,
glfw.KeyRight: KeyRight,
glfw.KeyUp: KeyUp,
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 { for g, u := range glfwKeyCodeToKey {
i.keyPressed[u] = window.GetKey(g) == glfw.Press i.keyPressed[u] = window.GetKey(g) == glfw.Press

View File

@ -16,14 +16,6 @@
package ui package ui
var keyCodeToKey = map[int]Key{
32: KeySpace,
37: KeyLeft,
39: KeyRight,
38: KeyUp,
40: KeyDown,
}
var currentInput input var currentInput input
func IsKeyPressed(key Key) bool { func IsKeyPressed(key Key) bool {

29
internal/ui/keys_glfw.go Normal file
View File

@ -0,0 +1,29 @@
// Copyright 2015 Hajime Hoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// +build !js
package ui
import (
glfw "github.com/go-gl/glfw3"
)
var glfwKeyCodeToKey = map[glfw.Key]Key{
glfw.KeySpace: KeySpace,
glfw.KeyLeft: KeyLeft,
glfw.KeyRight: KeyRight,
glfw.KeyUp: KeyUp,
glfw.KeyDown: KeyDown,
}

25
internal/ui/keys_js.go Normal file
View File

@ -0,0 +1,25 @@
// Copyright 2015 Hajime Hoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// +build js
package ui
var keyCodeToKey = map[int]Key{
32: KeySpace,
37: KeyLeft,
39: KeyRight,
38: KeyUp,
40: KeyDown,
}

View File

@ -21,10 +21,6 @@ import (
// A Key represents a keyboard key. // A Key represents a keyboard key.
type Key int type Key int
// TODO: Add more keys.
// TODO: Generate this automatically.
// Keys // Keys
const ( const (
KeyUp = Key(ui.KeyUp) KeyUp = Key(ui.KeyUp)