mirror of
https://github.com/bloeys/nmage.git
synced 2025-12-29 13:28:20 +00:00
Allow app to receive window event callbacks
This commit is contained in:
@ -11,6 +11,7 @@ import (
|
|||||||
type Window struct {
|
type Window struct {
|
||||||
SDLWin *sdl.Window
|
SDLWin *sdl.Window
|
||||||
GlCtx sdl.GLContext
|
GlCtx sdl.GLContext
|
||||||
|
EventCallbacks []func(sdl.Event)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) handleInputs() {
|
func (w *Window) handleInputs() {
|
||||||
@ -20,6 +21,12 @@ func (w *Window) handleInputs() {
|
|||||||
|
|
||||||
for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
|
for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
|
||||||
|
|
||||||
|
//Fire callbacks
|
||||||
|
for i := 0; i < len(w.EventCallbacks); i++ {
|
||||||
|
w.EventCallbacks[i](event)
|
||||||
|
}
|
||||||
|
|
||||||
|
//Internal processing
|
||||||
switch e := event.(type) {
|
switch e := event.(type) {
|
||||||
|
|
||||||
case *sdl.MouseWheelEvent:
|
case *sdl.MouseWheelEvent:
|
||||||
@ -136,7 +143,7 @@ func createWindow(title string, x, y, width, height int32, flags WindowFlags) (*
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
win := &Window{SDLWin: sdlWin}
|
win := &Window{SDLWin: sdlWin, EventCallbacks: make([]func(sdl.Event), 0)}
|
||||||
|
|
||||||
win.GlCtx, err = sdlWin.GLCreateContext()
|
win.GlCtx, err = sdlWin.GLCreateContext()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user