Pass keyboard events through application
This commit is contained in:
parent
f6b8d9903b
commit
ff7240d553
@ -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
|
||||
|
@ -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 ++
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
@ -35,6 +44,9 @@ func run (application *stone.Application) {
|
||||
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 }
|
||||
|
Loading…
Reference in New Issue
Block a user