event: Auto-generate event definitions (#935)

As event package needs to depend on driver package, and drvier
package needs to emit events, we need event definitions in both
side. This change add a generator for event definitions.

Updates #926
This commit is contained in:
Hajime Hoshi 2019-09-12 11:32:20 +09:00 committed by GitHub
parent e85c847376
commit 529ab5f191
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 778 additions and 107 deletions

View File

@ -1,4 +1,4 @@
// Copyright 2019 The Ebiten Authors
// 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.
@ -12,26 +12,18 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// Package event is a package that models events that occur during
// the execution of a program.
//
// This package is still experimental and there is no guarantee for
// backward compatibility so far.
// Code generated by genevents.go using 'go generate'. DO NOT EDIT.
package event
// Event is an interface that custom events should implement.
// It is empty for now because there are no general methods
// required of events yet.
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.
// 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
}
@ -40,22 +32,29 @@ type KeyboardKeyCharacter struct {
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.
// The data is the same as for a KeyboardKeyDown event.
type KeyboardKeyUp KeyboardKeyDown
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 psoition of the axis after the change.
// It varies between -1.0 and 1.0.
// Position is the position of the axis after the change. It varies between -1.0 and 1.0.
Position float32
}
@ -63,23 +62,34 @@ type GamepadAxis struct {
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 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
}
// GamepadButtonDown is a gamepad button release event.
// The data is identical to a GamePadButtonDown event.
type GamepadButtonUp GamepadButtonDown
// 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
}
@ -92,110 +102,103 @@ type GamepadDetach struct {
// 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 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.
// Y is the Y position of the mouse pointer. This value is expressed in device independent pixels.
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 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 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 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 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 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 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 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 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 is the pressure applied on the mouse button. It varies between 0.0 for not pressed, and 1.0 for completely pressed.
Pressure float32
}
// MouseButtonDown is a mouse button Release event.
// The data is identical to a MouseButtonDown event.
type MouseButtonUp MouseButtonDown
// 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 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 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.
// The data is identical to MouseEnter.
type MouseLeave MouseEnter
type MouseLeave struct {
// X is the X position of the mouse pointer. This value is expressed in device independent pixels.
X float32
// ViewUpdate occurs when the application is ready to update
// the next frame on the view port.
type ViewUpdate struct {
// No data neccesary, for now.
}
// 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
// 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 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 is the Y position of the touch. This value is expressed in device independent pixels.
Y float32
// Pressure is the pressure applied to the touch.
// It varies between 0.0 for not pressed, and 1.0 for completely pressed.
// 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.
// Otherwise it is false.
// 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
}
@ -203,35 +206,65 @@ type TouchBegin struct {
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 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 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 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.
// 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 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.
// The data is the same as for a TouchMove event.
type TouchEnd TouchMove
type TouchEnd struct {
// ID identifies the touch that caused the touch event.
ID int
// TouchCancel occurs when a touch is canceled.
// This can happen in various situations, depending on the underlying platform,
// for example when the aplication loses focus.
// 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 aplication 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
}

View File

@ -15,4 +15,5 @@
package ebiten
//go:generate go run genkeys.go
//go:generate go run genevents.go
//go:generate gofmt -s -w .

367
genevents.go Normal file
View File

@ -0,0 +1,367 @@
// 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.
// +build ignore
package main
import (
"log"
"os"
"path/filepath"
"strings"
"text/template"
)
type Event struct {
Comment string
Members []Member
}
func (e *Event) Name() string {
return strings.SplitN(e.Comment, " ", 2)[0]
}
type Member struct {
Comment string
Type string
}
func (m *Member) Name() string {
return strings.SplitN(m.Comment, " ", 2)[0]
}
var (
membersKeyboardKey = []Member{
{
Comment: "Key is the key code of the key pressed or released.",
Type: "Key",
},
{
Comment: "Modifier is the logical-or value of the modifiers pressed together with the key.",
Type: "Modifier",
},
}
membersGamepadButton = []Member{
{
Comment: "ID represents which gamepad caused the event.",
Type: "int",
},
{
Comment: "Button is the button that was pressed on the game pad.",
Type: "int",
},
{
Comment: "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.",
Type: "float32",
},
}
membersMouseButton = []Member{
{
Comment: "X is the X position of the mouse pointer. This value is expressed in device independent pixels.",
Type: "float32",
},
{
Comment: "Y is the Y position of the mouse pointer. This value is expressed in device independent pixels.",
Type: "float32",
},
{
Comment: "Button is the button on the mouse that was pressed. TODO: this should change later from an int to an enumeration type.",
Type: "int",
},
{
Comment: "Pressure is the pressure applied on the mouse button. It varies between 0.0 for not pressed, and 1.0 for completely pressed.",
Type: "float32",
},
}
membersMouseEnter = []Member{
{
Comment: "X is the X position of the mouse pointer. This value is expressed in device independent pixels.",
Type: "float32",
},
{
Comment: "Y is the Y position of the mouse pointer. This value is expressed in device independent pixels.",
Type: "float32",
},
}
membersTouch = []Member{
{
Comment: "ID identifies the touch that caused the touch event.",
Type: "int",
},
{
Comment: "X is the X position of the touch. This value is expressed in device independent pixels.",
Type: "float32",
},
{
Comment: "Y is the Y position of the touch. This value is expressed in device independent pixels.",
Type: "float32",
},
{
Comment: "DeltaX is the change in X since last touch event. This value is expressed in device independent pixels.",
Type: "float32",
},
{
Comment: "Deltay is the change in Y since last touch event. This value is expressed in device independent pixels.",
Type: "float32",
},
{
Comment: "Pressure of applied touch. It varies between 0.0 for not pressed, and 1.0 for completely pressed.",
Type: "float32",
},
{
Comment: "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.",
Type: "bool",
},
}
events = []Event{
{
Comment: "KeyboardKeyCharacter is an event that occurs when a character is actually typed on the keyboard. This may be provided by an input method.",
Members: []Member{
{
Comment: "Key is the key code of the key typed.",
Type: "Key",
},
{
Comment: "Modifier is the logical-or value of the modifiers pressed together with the key.",
Type: "Modifier",
},
{
Comment: "Character is the character that was typed.",
Type: "rune",
},
},
},
{
Comment: "KeyboardKeyDown is an event that occurs when a key is pressed on the keyboard.",
Members: membersKeyboardKey,
},
{
Comment: "KeyboardKeyUp is an event that occurs when a key is released on the keyboard.",
Members: membersKeyboardKey,
},
{
Comment: "GamepadAxis is for event where an axis on a gamepad changes.",
Members: []Member{
{
Comment: "ID represents which gamepad caused the event.",
Type: "int",
},
{
Comment: "Axis is the axis of the game pad that changed position.",
Type: "int",
},
{
Comment: "Position is the position of the axis after the change. It varies between -1.0 and 1.0.",
Type: "float32",
},
},
},
{
Comment: "GamepadButtonDown is a gamepad button press event.",
Members: membersGamepadButton,
},
{
Comment: "GamepadButtonUp is a gamepad button release event.",
Members: membersGamepadButton,
},
{
Comment: "GamepadAttach happens when a new gamepad is attached.",
Members: []Member{
{
Comment: "ID represents which gamepad caused the event.",
Type: "int",
},
{
Comment: "Axes represents the amount of axes the gamepad has.",
Type: "int",
},
{
Comment: "Buttons represents the amount of buttons the gamepad has.",
Type: "int",
},
},
},
{
Comment: "GamepadDetach happens when a gamepad is detached.",
Members: []Member{
{
Comment: "ID represents which gamepad caused the event.",
Type: "int",
},
},
},
{
Comment: "MouseMove is a mouse movement event.",
Members: []Member{
{
Comment: "X is the X position of the mouse pointer. This value is expressed in device independent pixels.",
Type: "float32",
},
{
Comment: " Y is the Y position of the mouse pointer. This value is expressed in device independent pixels.",
Type: "float32",
},
{
Comment: "DeltaX is the change in X since the last MouseMove event. This value is expressed in device independent pixels.",
Type: "float32",
},
{
Comment: "DeltaY is the change in Y since the last MouseMove event. This value is expressed in device independent pixels.",
Type: "float32",
},
},
},
{
Comment: "MouseWheel is a mouse wheel event.",
Members: []Member{
{
Comment: "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.",
Type: "float32",
},
{
Comment: "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.",
Type: "float32",
},
{
Comment: "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.",
Type: "float32",
},
{
Comment: "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.",
Type: "float32",
},
},
},
{
Comment: "MouseButtonDown is a mouse button press event.",
Members: membersMouseButton,
},
{
Comment: "MouseButtonUp is a mouse button release event.",
Members: membersMouseButton,
},
{
Comment: "MouseEnter occurs when the mouse enters the view window.",
Members: membersMouseEnter,
},
{
Comment: "MouseLeave occurs when the mouse leaves the view window.",
Members: membersMouseEnter,
},
{
Comment: "TouchBegin occurs when a touch begins.",
Members: membersTouch,
},
{
Comment: "TouchMove occurs when a touch moved, or in other words, is dragged.",
Members: membersTouch,
},
{
Comment: "TouchEnd occurs when a touch ends.",
Members: membersTouch,
},
{
Comment: "TouchCancel occurs when a touch is canceled. This can happen in various situations, depending on the underlying platform, for example when the aplication loses focus.",
Members: []Member{
{
Comment: "ID identifies the touch that caused the touch event.",
Type: "int",
},
},
},
{
Comment: "ViewUpdate occurs when the application is ready to update the next frame on the view port.",
},
{
Comment: "ViewSize occurs when the size of the application's view port changes.",
Members: []Member{
{
Comment: "Width is the width of the view. This value is expressed in device independent pixels.",
Type: "int",
},
{
Comment: "Height is the height of the view. This value is expressed in device independent pixels.",
Type: "int",
},
},
},
}
)
const (
license = `// 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.
`
doNotEdit = "// Code generated by genevents.go using 'go generate'. DO NOT EDIT."
)
var eventTmpl = template.Must(template.New("event.go").Parse(`{{.License}}
{{.DoNotEdit}}
package {{.Package}}
{{range .Events}}// {{.Comment}}
type {{.Name}} struct {
{{range .Members}} // {{.Comment}}
{{.Name}} {{.Type}}
{{end}}
}
{{end}}
`))
func main() {
for _, path := range []string{
filepath.Join("event", "event.go"),
filepath.Join("internal", "driver", "event.go"),
} {
f, err := os.Create(path)
if err != nil {
log.Fatal(err)
}
defer f.Close()
tokens := strings.Split(path, string(filepath.Separator))
pkg := tokens[len(tokens)-2]
if err := eventTmpl.Execute(f, struct {
License string
DoNotEdit string
Package string
Events []Event
}{
License: license,
DoNotEdit: doNotEdit,
Package: pkg,
Events: events,
}); err != nil {
log.Fatal(err)
}
}
}

270
internal/driver/event.go Normal file
View File

@ -0,0 +1,270 @@
// 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 driver
// 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.
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 aplication 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
}