diff --git a/application.go b/application.go index db956eb..a1dca70 100644 --- a/application.go +++ b/application.go @@ -13,7 +13,6 @@ type Application struct { func (application *Application) SetSize (width, height int) { application.DamageBuffer.SetSize(width, height) - // application.updateWindowSize() } func (application *Application) SetTitle (title string) { @@ -69,6 +68,31 @@ func (application *Application) Config () (config *Config) { return } +func (application *Application) JustPressed (button Button) (pressed bool) { + pressed = application.backend.JustPressed(button) + return +} + +func (application *Application) JustReleased (button Button) (released bool) { + released = application.backend.JustReleased(button) + return +} + +func (application *Application) Pressed (button Button) (pressed bool) { + pressed = application.backend.Pressed(button) + return +} + +func (application *Application) Repeated (button Button) (repeated bool) { + repeated = application.backend.Repeated(button) + return +} + +func (application *Application) Typed () (text string) { + text = application.backend.Typed() + return +} + func (application *Application) Resized () (resized bool) { resized = application.backend.Resized() return diff --git a/buffer.go b/buffer.go index 3e6b7e2..9bf6dec 100644 --- a/buffer.go +++ b/buffer.go @@ -85,9 +85,9 @@ func (buffer *Buffer) Write (bytes []byte) (bytesWritten int, err error) { for _, character := range text { buffer.SetRune(buffer.Dot.X, buffer.Dot.Y, character) buffer.Dot.X ++ - if buffer.Dot.X > buffer.width { + if buffer.Dot.X > buffer.width || character == '\n' { buffer.Dot.X = 0 - buffer.Dot.Y -- + buffer.Dot.Y ++ } } @@ -131,9 +131,9 @@ func (buffer *DamageBuffer) Write (bytes []byte) (bytesWritten int, err error) { for _, character := range text { buffer.SetRune(buffer.Dot.X, buffer.Dot.Y, character) buffer.Dot.X ++ - if buffer.Dot.X > buffer.width { + if buffer.Dot.X > buffer.width || character == '\n' { buffer.Dot.X = 0 - buffer.Dot.Y -- + buffer.Dot.Y ++ } } diff --git a/examples/hello/main.go b/examples/hello/main.go index e48f2dd..93d8463 100644 --- a/examples/hello/main.go +++ b/examples/hello/main.go @@ -14,9 +14,18 @@ func main () { func run (application *stone.Application) { currentTime := time.Time { } frameDelay := time.Second / 2 + textBuffer := "" for { - if application.Resized() || time.Since(currentTime) > frameDelay { + typed := application.Typed() + textBuffer += typed + + shouldRender := + application.Resized() || + time.Since(currentTime) > frameDelay || + len(typed) > 0 + + if shouldRender { currentTime = time.Now() application.ResetDot() @@ -34,7 +43,10 @@ func run (application *stone.Application) { application.SetRune(5, 1, ':') application.SetRune(6, 1, rune(second / 10 + 48)) application.SetRune(7, 1, rune(second % 10 + 48)) - + + application.Dot.X = 0 + application.Dot.Y = 2 + fmt.Fprintln(application, textBuffer) } if !application.Await(frameDelay) { break }