From 1d71df180ddd1dec52e5e7178f6ded71f454037d Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Mon, 14 Nov 2022 23:15:21 -0500 Subject: [PATCH] Changed how buttons are stored in press and release events --- backends/x/event.go | 12 ++++++++---- event.go | 4 ++-- examples/draw/main.go | 8 ++++---- examples/type/main.go | 2 +- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/backends/x/event.go b/backends/x/event.go index 04154e5..a3a8b8e 100644 --- a/backends/x/event.go +++ b/backends/x/event.go @@ -42,7 +42,9 @@ func (backend *Backend) handleButtonPress ( event xevent.ButtonPressEvent, ) { buttonEvent := *event.ButtonPressEvent - backend.channel <- stone.EventPress(buttonEvent.Detail) + backend.channel <- stone.EventPress { + Button: stone.Button(buttonEvent.Detail), + } } func (backend *Backend) handleButtonRelease ( @@ -50,7 +52,9 @@ func (backend *Backend) handleButtonRelease ( event xevent.ButtonReleaseEvent, ) { buttonEvent := *event.ButtonReleaseEvent - backend.channel <- stone.EventRelease(buttonEvent.Detail) + backend.channel <- stone.EventRelease { + Button: stone.Button(buttonEvent.Detail), + } } func (backend *Backend) handleKeyPress ( @@ -59,7 +63,7 @@ func (backend *Backend) handleKeyPress ( ) { keyEvent := *event.KeyPressEvent button := backend.keycodeToButton(keyEvent.Detail, keyEvent.State) - backend.channel <- stone.EventPress(button) + backend.channel <- stone.EventPress { Button: button } } func (backend *Backend) handleKeyRelease ( @@ -68,7 +72,7 @@ func (backend *Backend) handleKeyRelease ( ) { keyEvent := *event.KeyReleaseEvent button := backend.keycodeToButton(keyEvent.Detail, keyEvent.State) - backend.channel <- stone.EventRelease(button) + backend.channel <- stone.EventRelease { Button: button } } func (backend *Backend) handleMotionNotify ( diff --git a/event.go b/event.go index f60cff2..8fbefb7 100644 --- a/event.go +++ b/event.go @@ -3,8 +3,8 @@ package stone type Event interface { } type EventQuit struct { } -type EventPress Button -type EventRelease Button +type EventPress struct { Button } +type EventRelease struct { Button } type EventResize struct { } type EventMouseMove struct { X int diff --git a/examples/draw/main.go b/examples/draw/main.go index 52d54ba..7d78da8 100644 --- a/examples/draw/main.go +++ b/examples/draw/main.go @@ -38,16 +38,16 @@ func main () { os.Exit(0) case stone.EventPress: - event := event.(stone.EventPress) - if stone.Button(event) == stone.MouseButtonLeft { + button := event.(stone.EventPress).Button + if button == stone.MouseButtonLeft { mousePressed = true application.SetRune(0, 0, '+') application.Draw() } case stone.EventRelease: - event := event.(stone.EventRelease) - if stone.Button(event) == stone.MouseButtonLeft { + button := event.(stone.EventRelease).Button + if button == stone.MouseButtonLeft { mousePressed = false application.SetRune(0, 0, 0) application.Draw() diff --git a/examples/type/main.go b/examples/type/main.go index cfac4dc..1cda63e 100644 --- a/examples/type/main.go +++ b/examples/type/main.go @@ -38,7 +38,7 @@ func main () { os.Exit(0) case stone.EventPress: - button := stone.Button(event.(stone.EventPress)) + button := event.(stone.EventPress).Button if button.Printable() { application.SetRune(caret, 0, rune(button)) caret ++