Add event package

Updates #926
This commit is contained in:
Hajime Hoshi 2020-03-21 03:34:22 +09:00
parent 60c6626235
commit 18364268de
5 changed files with 528 additions and 0 deletions

78
event/chan.go Normal file
View File

@ -0,0 +1,78 @@
// Copyright 2013 The Ebiten Authors
//
// 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.
// Code generated by genevents.go using 'go generate'. DO NOT EDIT.
package event
import (
"fmt"
"github.com/hajimehoshi/ebiten/internal/driver"
)
func convertCh(driverCh chan driver.Event) chan Event {
ch := make(chan Event)
go func() {
defer close(ch)
for v := range driverCh {
switch v := v.(type) {
case driver.KeyboardKeyCharacter:
ch <- KeyboardKeyCharacter(v)
case driver.KeyboardKeyDown:
ch <- KeyboardKeyDown(v)
case driver.KeyboardKeyUp:
ch <- KeyboardKeyUp(v)
case driver.GamepadAxis:
ch <- GamepadAxis(v)
case driver.GamepadButtonDown:
ch <- GamepadButtonDown(v)
case driver.GamepadButtonUp:
ch <- GamepadButtonUp(v)
case driver.GamepadAttach:
ch <- GamepadAttach(v)
case driver.GamepadDetach:
ch <- GamepadDetach(v)
case driver.MouseMove:
ch <- MouseMove(v)
case driver.MouseWheel:
ch <- MouseWheel(v)
case driver.MouseButtonDown:
ch <- MouseButtonDown(v)
case driver.MouseButtonUp:
ch <- MouseButtonUp(v)
case driver.MouseEnter:
ch <- MouseEnter(v)
case driver.MouseLeave:
ch <- MouseLeave(v)
case driver.TouchBegin:
ch <- TouchBegin(v)
case driver.TouchMove:
ch <- TouchMove(v)
case driver.TouchEnd:
ch <- TouchEnd(v)
case driver.TouchCancel:
ch <- TouchCancel(v)
case driver.ViewUpdate:
ch <- ViewUpdate(v)
case driver.ViewSize:
ch <- ViewSize(v)
default:
panic(fmt.Sprintf("event: unknown event: %v", v))
}
}
}()
return ch
}

19
event/doc.go Normal file
View File

@ -0,0 +1,19 @@
// Copyright 2020 The Ebiten Authors
//
// 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.
// Package event implements low-layer events and their handlings.
//
// This is still work in progress and is not used anywhere yet.
// The tracking issue is #926.
package event

272
event/event.go Normal file
View File

@ -0,0 +1,272 @@
// Copyright 2013 The Ebiten Authors
//
// 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.
// Code generated by genevents.go using 'go generate'. DO NOT EDIT.
package event
type Event interface{}
// KeyboardKeyCharacter is an event that occurs when a character is actually typed on the keyboard. This may be provided by an input method.
type KeyboardKeyCharacter struct {
// Key is the key code of the key typed.
Key Key
// Modifier is the logical-or value of the modifiers pressed together with the key.
Modifier Modifier
// Character is the character that was typed.
Character rune
}
// KeyboardKeyDown is an event that occurs when a key is pressed on the keyboard.
type KeyboardKeyDown struct {
// Key is the key code of the key pressed or released.
Key Key
// Modifier is the logical-or value of the modifiers pressed together with the key.
Modifier Modifier
}
// KeyboardKeyUp is an event that occurs when a key is released on the keyboard.
type KeyboardKeyUp struct {
// Key is the key code of the key pressed or released.
Key Key
// Modifier is the logical-or value of the modifiers pressed together with the key.
Modifier Modifier
}
// GamepadAxis is for event where an axis on a gamepad changes.
type GamepadAxis struct {
// ID represents which gamepad caused the event.
ID int
// Axis is the axis of the game pad that changed position.
Axis int
// Position is the position of the axis after the change. It varies between -1.0 and 1.0.
Position float32
}
// GamepadButtonDown is a gamepad button press event.
type GamepadButtonDown struct {
// ID represents which gamepad caused the event.
ID int
// Button is the button that was pressed on the game pad.
Button int
// Pressure is the pressure that is applied to the gamepad button. It varies between 0.0 for not pressed, and 1.0 for completely pressed.
Pressure float32
}
// GamepadButtonUp is a gamepad button release event.
type GamepadButtonUp struct {
// ID represents which gamepad caused the event.
ID int
// Button is the button that was pressed on the game pad.
Button int
// Pressure is the pressure that is applied to the gamepad button. It varies between 0.0 for not pressed, and 1.0 for completely pressed.
Pressure float32
}
// GamepadAttach happens when a new gamepad is attached.
type GamepadAttach struct {
// ID represents which gamepad caused the event.
ID int
// Axes represents the amount of axes the gamepad has.
Axes int
// Buttons represents the amount of buttons the gamepad has.
Buttons int
}
// GamepadDetach happens when a gamepad is detached.
type GamepadDetach struct {
// ID represents which gamepad caused the event.
ID int
}
// MouseMove is a mouse movement event.
type MouseMove struct {
// X is the X position of the mouse pointer. This value is expressed in device independent pixels.
X float32
// Y is the Y position of the mouse pointer. This value is expressed in device independent pixels.
Y float32
// DeltaX is the change in X since the last MouseMove event. This value is expressed in device independent pixels.
DeltaX float32
// DeltaY is the change in Y since the last MouseMove event. This value is expressed in device independent pixels.
DeltaY float32
}
// MouseWheel is a mouse wheel event.
type MouseWheel struct {
// X is the X position of the mouse wheel. This value is expressed in arbitrary units. It increases when the mouse wheel is scrolled downwards, and decreases when the mouse is scrolled upwards.
X float32
// Y is the Y position of the mouse wheel. This value is expressed in arbitrary units. It increases when the mouse wheel is scrolled to the right, and decreases when the mouse is scrolled to the left.
Y float32
// DeltaX is the change in X since the last MouseWheel event. This value is expressed in arbitrary units. It is positive when the mouse wheel is scrolled downwards, and negative when the mouse is scrolled upwards.
DeltaX float32
// DeltaY is the change in Y since the last MouseWheel event. This value is expressed in arbitrary units. It is positive when the mouse wheel is scrolled to the right, and negative when the mouse is scrolled to the left.
DeltaY float32
}
// MouseButtonDown is a mouse button press event.
type MouseButtonDown struct {
// X is the X position of the mouse pointer. This value is expressed in device independent pixels.
X float32
// Y is the Y position of the mouse pointer. This value is expressed in device independent pixels.
Y float32
// Button is the button on the mouse that was pressed. TODO: this should change later from an int to an enumeration type.
Button int
// Pressure is the pressure applied on the mouse button. It varies between 0.0 for not pressed, and 1.0 for completely pressed.
Pressure float32
}
// MouseButtonUp is a mouse button release event.
type MouseButtonUp struct {
// X is the X position of the mouse pointer. This value is expressed in device independent pixels.
X float32
// Y is the Y position of the mouse pointer. This value is expressed in device independent pixels.
Y float32
// Button is the button on the mouse that was pressed. TODO: this should change later from an int to an enumeration type.
Button int
// Pressure is the pressure applied on the mouse button. It varies between 0.0 for not pressed, and 1.0 for completely pressed.
Pressure float32
}
// MouseEnter occurs when the mouse enters the view window.
type MouseEnter struct {
// X is the X position of the mouse pointer. This value is expressed in device independent pixels.
X float32
// Y is the Y position of the mouse pointer. This value is expressed in device independent pixels.
Y float32
}
// MouseLeave occurs when the mouse leaves the view window.
type MouseLeave struct {
// X is the X position of the mouse pointer. This value is expressed in device independent pixels.
X float32
// Y is the Y position of the mouse pointer. This value is expressed in device independent pixels.
Y float32
}
// TouchBegin occurs when a touch begins.
type TouchBegin struct {
// ID identifies the touch that caused the touch event.
ID int
// X is the X position of the touch. This value is expressed in device independent pixels.
X float32
// Y is the Y position of the touch. This value is expressed in device independent pixels.
Y float32
// DeltaX is the change in X since last touch event. This value is expressed in device independent pixels.
DeltaX float32
// Deltay is the change in Y since last touch event. This value is expressed in device independent pixels.
Deltay float32
// Pressure of applied touch. It varies between 0.0 for not pressed, and 1.0 for completely pressed.
Pressure float32
// Primary represents whether the touch event is the primary touch or not. If it is true, then it is a primary touch. If it is false then it is not.
Primary bool
}
// TouchMove occurs when a touch moved, or in other words, is dragged.
type TouchMove struct {
// ID identifies the touch that caused the touch event.
ID int
// X is the X position of the touch. This value is expressed in device independent pixels.
X float32
// Y is the Y position of the touch. This value is expressed in device independent pixels.
Y float32
// DeltaX is the change in X since last touch event. This value is expressed in device independent pixels.
DeltaX float32
// Deltay is the change in Y since last touch event. This value is expressed in device independent pixels.
Deltay float32
// Pressure of applied touch. It varies between 0.0 for not pressed, and 1.0 for completely pressed.
Pressure float32
// Primary represents whether the touch event is the primary touch or not. If it is true, then it is a primary touch. If it is false then it is not.
Primary bool
}
// TouchEnd occurs when a touch ends.
type TouchEnd struct {
// ID identifies the touch that caused the touch event.
ID int
// X is the X position of the touch. This value is expressed in device independent pixels.
X float32
// Y is the Y position of the touch. This value is expressed in device independent pixels.
Y float32
// DeltaX is the change in X since last touch event. This value is expressed in device independent pixels.
DeltaX float32
// Deltay is the change in Y since last touch event. This value is expressed in device independent pixels.
Deltay float32
// Pressure of applied touch. It varies between 0.0 for not pressed, and 1.0 for completely pressed.
Pressure float32
// Primary represents whether the touch event is the primary touch or not. If it is true, then it is a primary touch. If it is false then it is not.
Primary bool
}
// TouchCancel occurs when a touch is canceled. This can happen in various situations, depending on the underlying platform, for example when the application loses focus.
type TouchCancel struct {
// ID identifies the touch that caused the touch event.
ID int
}
// ViewUpdate occurs when the application is ready to update the next frame on the view port.
type ViewUpdate struct {
}
// ViewSize occurs when the size of the application's view port changes.
type ViewSize struct {
// Width is the width of the view. This value is expressed in device independent pixels.
Width int
// Height is the height of the view. This value is expressed in device independent pixels.
Height int
}

129
event/keys.go Normal file
View File

@ -0,0 +1,129 @@
// Copyright 2013 The Ebiten Authors
//
// 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.
// Code generated by genkeys.go using 'go generate'. DO NOT EDIT.
package event
import (
"github.com/hajimehoshi/ebiten/internal/driver"
)
type Key = driver.Key
const (
Key0 = driver.Key0
Key1 = driver.Key1
Key2 = driver.Key2
Key3 = driver.Key3
Key4 = driver.Key4
Key5 = driver.Key5
Key6 = driver.Key6
Key7 = driver.Key7
Key8 = driver.Key8
Key9 = driver.Key9
KeyA = driver.KeyA
KeyB = driver.KeyB
KeyC = driver.KeyC
KeyD = driver.KeyD
KeyE = driver.KeyE
KeyF = driver.KeyF
KeyG = driver.KeyG
KeyH = driver.KeyH
KeyI = driver.KeyI
KeyJ = driver.KeyJ
KeyK = driver.KeyK
KeyL = driver.KeyL
KeyM = driver.KeyM
KeyN = driver.KeyN
KeyO = driver.KeyO
KeyP = driver.KeyP
KeyQ = driver.KeyQ
KeyR = driver.KeyR
KeyS = driver.KeyS
KeyT = driver.KeyT
KeyU = driver.KeyU
KeyV = driver.KeyV
KeyW = driver.KeyW
KeyX = driver.KeyX
KeyY = driver.KeyY
KeyZ = driver.KeyZ
KeyApostrophe = driver.KeyApostrophe
KeyBackslash = driver.KeyBackslash
KeyBackspace = driver.KeyBackspace
KeyCapsLock = driver.KeyCapsLock
KeyComma = driver.KeyComma
KeyDelete = driver.KeyDelete
KeyDown = driver.KeyDown
KeyEnd = driver.KeyEnd
KeyEnter = driver.KeyEnter
KeyEqual = driver.KeyEqual
KeyEscape = driver.KeyEscape
KeyF1 = driver.KeyF1
KeyF2 = driver.KeyF2
KeyF3 = driver.KeyF3
KeyF4 = driver.KeyF4
KeyF5 = driver.KeyF5
KeyF6 = driver.KeyF6
KeyF7 = driver.KeyF7
KeyF8 = driver.KeyF8
KeyF9 = driver.KeyF9
KeyF10 = driver.KeyF10
KeyF11 = driver.KeyF11
KeyF12 = driver.KeyF12
KeyGraveAccent = driver.KeyGraveAccent
KeyHome = driver.KeyHome
KeyInsert = driver.KeyInsert
KeyKP0 = driver.KeyKP0
KeyKP1 = driver.KeyKP1
KeyKP2 = driver.KeyKP2
KeyKP3 = driver.KeyKP3
KeyKP4 = driver.KeyKP4
KeyKP5 = driver.KeyKP5
KeyKP6 = driver.KeyKP6
KeyKP7 = driver.KeyKP7
KeyKP8 = driver.KeyKP8
KeyKP9 = driver.KeyKP9
KeyKPAdd = driver.KeyKPAdd
KeyKPDecimal = driver.KeyKPDecimal
KeyKPDivide = driver.KeyKPDivide
KeyKPEnter = driver.KeyKPEnter
KeyKPEqual = driver.KeyKPEqual
KeyKPMultiply = driver.KeyKPMultiply
KeyKPSubtract = driver.KeyKPSubtract
KeyLeft = driver.KeyLeft
KeyLeftAlt = driver.KeyLeftAlt
KeyLeftBracket = driver.KeyLeftBracket
KeyLeftControl = driver.KeyLeftControl
KeyLeftShift = driver.KeyLeftShift
KeyMenu = driver.KeyMenu
KeyMinus = driver.KeyMinus
KeyNumLock = driver.KeyNumLock
KeyPageDown = driver.KeyPageDown
KeyPageUp = driver.KeyPageUp
KeyPause = driver.KeyPause
KeyPeriod = driver.KeyPeriod
KeyPrintScreen = driver.KeyPrintScreen
KeyRight = driver.KeyRight
KeyRightAlt = driver.KeyRightAlt
KeyRightBracket = driver.KeyRightBracket
KeyRightControl = driver.KeyRightControl
KeyRightShift = driver.KeyRightShift
KeyScrollLock = driver.KeyScrollLock
KeySemicolon = driver.KeySemicolon
KeySlash = driver.KeySlash
KeySpace = driver.KeySpace
KeyTab = driver.KeyTab
KeyUp = driver.KeyUp
)

30
event/modifier.go Normal file
View File

@ -0,0 +1,30 @@
// Copyright 2019 The Ebiten Authors
//
// 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.
package event
import (
"github.com/hajimehoshi/ebiten/internal/driver"
)
// Modifier is a bit set of modifier keys on a keyboard.
type Modifier = driver.Modifier
const (
ModifierShift = driver.ModifierShift
ModifierControl = driver.ModifierControl
ModifierAlt = driver.ModifierAlt
ModifierCapsLock = driver.ModifierCapsLock
ModifierNumLock = driver.ModifierNumLock
)