mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
ui: Rename functions from Safari to Edge
This commit is contained in:
parent
0c0cd7e9d6
commit
37ca48dc38
18
genkeys.go
18
genkeys.go
@ -32,8 +32,8 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
nameToCodes map[string][]string
|
||||
keyCodeToNameSafari map[int]string
|
||||
nameToCodes map[string][]string
|
||||
keyCodeToNameEdge map[int]string
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -84,7 +84,7 @@ func init() {
|
||||
}
|
||||
|
||||
func init() {
|
||||
keyCodeToNameSafari = map[int]string{
|
||||
keyCodeToNameEdge = map[int]string{
|
||||
0xbc: "Comma",
|
||||
0xbe: "Period",
|
||||
0x12: "Alt",
|
||||
@ -118,15 +118,15 @@ func init() {
|
||||
}
|
||||
// ASCII: 0 - 9
|
||||
for c := '0'; c <= '9'; c++ {
|
||||
keyCodeToNameSafari[int(c)] = string(c)
|
||||
keyCodeToNameEdge[int(c)] = string(c)
|
||||
}
|
||||
// ASCII: A - Z
|
||||
for c := 'A'; c <= 'Z'; c++ {
|
||||
keyCodeToNameSafari[int(c)] = string(c)
|
||||
keyCodeToNameEdge[int(c)] = string(c)
|
||||
}
|
||||
// Function keys
|
||||
for i := 1; i <= 12; i++ {
|
||||
keyCodeToNameSafari[0x70+i-1] = "F" + strconv.Itoa(i)
|
||||
keyCodeToNameEdge[0x70+i-1] = "F" + strconv.Itoa(i)
|
||||
}
|
||||
}
|
||||
|
||||
@ -205,8 +205,8 @@ var keyToCodes = map[Key][]string{
|
||||
{{end}}
|
||||
}
|
||||
|
||||
var keyCodeToKeySafari = map[int]Key{
|
||||
{{range $code, $name := .KeyCodeToNameSafari}}{{$code}}: Key{{$name}},
|
||||
var keyCodeToKeyEdge = map[int]Key{
|
||||
{{range $code, $name := .KeyCodeToNameEdge}}{{$code}}: Key{{$name}},
|
||||
{{end}}
|
||||
}
|
||||
`
|
||||
@ -353,7 +353,7 @@ func main() {
|
||||
"Notice": notice,
|
||||
"BuildTag": buildTag,
|
||||
"NameToCodes": nameToCodes,
|
||||
"KeyCodeToNameSafari": keyCodeToNameSafari,
|
||||
"KeyCodeToNameEdge": keyCodeToNameEdge,
|
||||
"Codes": codes,
|
||||
"KeyNames": names,
|
||||
"LastKeyName": names[len(names)-1],
|
||||
|
@ -29,7 +29,7 @@ func (m mockRWLock) RUnlock() {}
|
||||
|
||||
type Input struct {
|
||||
keyPressed map[string]bool
|
||||
keyPressedSafari map[int]bool
|
||||
keyPressedEdge map[int]bool
|
||||
mouseButtonPressed map[int]bool
|
||||
cursorX int
|
||||
cursorY int
|
||||
@ -51,12 +51,12 @@ func (i *Input) IsKeyPressed(key Key) bool {
|
||||
}
|
||||
}
|
||||
}
|
||||
if i.keyPressedSafari != nil {
|
||||
for c, k := range keyCodeToKeySafari {
|
||||
if i.keyPressedEdge != nil {
|
||||
for c, k := range keyCodeToKeyEdge {
|
||||
if k != key {
|
||||
continue
|
||||
}
|
||||
if i.keyPressedSafari[c] {
|
||||
if i.keyPressedEdge[c] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@ -99,18 +99,18 @@ func (i *Input) keyUp(code string) {
|
||||
i.keyPressed[code] = false
|
||||
}
|
||||
|
||||
func (i *Input) keyDownSafari(code int) {
|
||||
if i.keyPressedSafari == nil {
|
||||
i.keyPressedSafari = map[int]bool{}
|
||||
func (i *Input) keyDownEdge(code int) {
|
||||
if i.keyPressedEdge == nil {
|
||||
i.keyPressedEdge = map[int]bool{}
|
||||
}
|
||||
i.keyPressedSafari[code] = true
|
||||
i.keyPressedEdge[code] = true
|
||||
}
|
||||
|
||||
func (i *Input) keyUpSafari(code int) {
|
||||
if i.keyPressedSafari == nil {
|
||||
i.keyPressedSafari = map[int]bool{}
|
||||
func (i *Input) keyUpEdge(code int) {
|
||||
if i.keyPressedEdge == nil {
|
||||
i.keyPressedEdge = map[int]bool{}
|
||||
}
|
||||
i.keyPressedSafari[code] = false
|
||||
i.keyPressedEdge[code] = false
|
||||
}
|
||||
|
||||
func (i *Input) mouseDown(code int) {
|
||||
|
@ -255,7 +255,7 @@ var keyToCodes = map[Key][]string{
|
||||
},
|
||||
}
|
||||
|
||||
var keyCodeToKeySafari = map[int]Key{
|
||||
var keyCodeToKeyEdge = map[int]Key{
|
||||
8: KeyBackspace,
|
||||
9: KeyTab,
|
||||
13: KeyEnter,
|
||||
|
@ -246,13 +246,12 @@ func initialize() error {
|
||||
canvas.Call("addEventListener", "keydown", func(e *js.Object) {
|
||||
c := e.Get("code")
|
||||
if c == js.Undefined {
|
||||
// TODO: Now this is used for Edge, not Safari. Rename functions.
|
||||
code := e.Get("keyCode").Int()
|
||||
if keyCodeToKeySafari[code] == KeyUp ||
|
||||
keyCodeToKeySafari[code] == KeyDown ||
|
||||
keyCodeToKeySafari[code] == KeyLeft ||
|
||||
keyCodeToKeySafari[code] == KeyRight {
|
||||
currentInput.keyDownSafari(code)
|
||||
if keyCodeToKeyEdge[code] == KeyUp ||
|
||||
keyCodeToKeyEdge[code] == KeyDown ||
|
||||
keyCodeToKeyEdge[code] == KeyLeft ||
|
||||
keyCodeToKeyEdge[code] == KeyRight {
|
||||
currentInput.keyDownEdge(code)
|
||||
}
|
||||
return
|
||||
}
|
||||
@ -274,9 +273,9 @@ func initialize() error {
|
||||
canvas.Call("addEventListener", "keyup", func(e *js.Object) {
|
||||
e.Call("preventDefault")
|
||||
if e.Get("code") == js.Undefined {
|
||||
// Assume that UA is Safari.
|
||||
// Assume that UA is Edge.
|
||||
code := e.Get("keyCode").Int()
|
||||
currentInput.keyUpSafari(code)
|
||||
currentInput.keyUpEdge(code)
|
||||
}
|
||||
code := e.Get("code").String()
|
||||
currentInput.keyUp(code)
|
||||
|
Loading…
Reference in New Issue
Block a user