From 32e30440f700f101145434838945b1067f224f3b Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Wed, 2 Nov 2022 15:14:59 -0400 Subject: [PATCH] Add input state queries --- application.go | 16 ++++++++++------ backends/pixel/pixel.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/application.go b/application.go index 4af336b..ad27cab 100644 --- a/application.go +++ b/application.go @@ -36,16 +36,20 @@ func (application *Application) Run (callback func (application *Application)) { color.RGBA { R: 0xFF, G: 0xFF, B: 0xFF, A: 0xFF }, } + // TODO: instead, return the error + var err error + application.backend, err = instantiateBackend(application) + if err != nil { panic(err.Error()) } application.backend.Run(callback) } func (application *Application) Await (timeout time.Duration) (keepRunning bool) { - keepRunning = application.Await(timeout) + keepRunning = application.backend.Await(timeout) return } func (application *Application) Poll () (keepRunning bool) { - keepRunning = application.Poll() + keepRunning = application.backend.Poll() return } @@ -59,10 +63,10 @@ func (application *Application) Config () (config *Config) { return } -// func (application *Application) Resized () (resized bool) { - // resized = application.boundsDirty - // return -// } +func (application *Application) Resized () (resized bool) { + resized = application.backend.Resized() + return +} // // updateWindowSize updates the window size according to the buffer size. diff --git a/backends/pixel/pixel.go b/backends/pixel/pixel.go index 21bff3f..2b16c02 100644 --- a/backends/pixel/pixel.go +++ b/backends/pixel/pixel.go @@ -83,6 +83,36 @@ func (backend *Backend) SetTitle (title string) { } } +func (backend *Backend) JustPressed (button stone.Button) (pressed bool) { + pressed = backend.window.JustPressed(pixelgl.Button(button)) + return +} + +func (backend *Backend) JustReleased (button stone.Button) (released bool) { + released = backend.window.JustReleased(pixelgl.Button(button)) + return +} + +func (backend *Backend) Pressed (button stone.Button) (pressed bool) { + pressed = backend.window.Pressed(pixelgl.Button(button)) + return +} + +func (backend *Backend) Repeated (button stone.Button) (repeated bool) { + repeated = backend.window.Repeated(pixelgl.Button(button)) + return +} + +func (backend *Backend) Typed () (text string) { + text = backend.window.Typed() + return +} + +func (backend *Backend) Resized () (resized bool) { + resized = backend.boundsDirty + return +} + func (backend *Backend) draw () { didDrawing := false