added a key char event handler

This commit is contained in:
Thomas Friedel 2018-05-09 19:45:21 +02:00
parent e2e03846b8
commit fc1a194e69

View file

@ -7,6 +7,7 @@ import (
_ "image/png" _ "image/png"
"runtime" "runtime"
"time" "time"
"unicode/utf8"
"github.com/go-gl/gl/v3.2-core/gl" "github.com/go-gl/gl/v3.2-core/gl"
"github.com/tfriedel6/canvas" "github.com/tfriedel6/canvas"
@ -29,8 +30,9 @@ type Window struct {
MouseDown func(button, x, y int) MouseDown func(button, x, y int)
MouseMove func(x, y int) MouseMove func(x, y int)
MouseUp func(button, x, y int) MouseUp func(button, x, y int)
KeyDown func(scancode int, rune rune, name string) KeyDown func(scancode int, rn rune, name string)
KeyUp func(scancode int, rune rune, name string) KeyUp func(scancode int, rn rune, name string)
KeyChar func(rn rune)
} }
// CreateWindow creates a window using SDL and initializes the OpenGL context // CreateWindow creates a window using SDL and initializes the OpenGL context
@ -155,6 +157,12 @@ func (wnd *Window) StartFrame() error {
handled = true handled = true
} }
} }
case *sdl.TextInputEvent:
if wnd.KeyChar != nil {
rn, _ := utf8.DecodeRune(e.Text[:])
wnd.KeyChar(rn)
handled = true
}
} }
if !handled && wnd.Event != nil { if !handled && wnd.Event != nil {