2013-12-10 14:12:39 +01:00
|
|
|
package cocoa
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hajimehoshi/go-ebiten/ui"
|
|
|
|
)
|
|
|
|
|
|
|
|
type windowEvents struct {
|
|
|
|
screenSizeUpdated chan ui.ScreenSizeUpdatedEvent // initialized lazily
|
2013-12-15 15:41:33 +01:00
|
|
|
mouseStateUpdated chan ui.MouseStateUpdatedEvent // initialized lazily
|
2013-12-12 16:31:00 +01:00
|
|
|
windowClosed chan ui.WindowClosedEvent // initialized lazily
|
2013-12-10 14:12:39 +01:00
|
|
|
}
|
|
|
|
|
2013-12-15 18:42:54 +01:00
|
|
|
func (w *windowEvents) notify(e interface{}) {
|
|
|
|
go func() {
|
|
|
|
w.doNotify(e)
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *windowEvents) doNotify(e interface{}) {
|
|
|
|
switch e := e.(type) {
|
|
|
|
case ui.ScreenSizeUpdatedEvent:
|
|
|
|
if w.screenSizeUpdated != nil {
|
|
|
|
w.screenSizeUpdated <- e
|
|
|
|
}
|
|
|
|
case ui.MouseStateUpdatedEvent:
|
|
|
|
if w.mouseStateUpdated != nil {
|
|
|
|
w.mouseStateUpdated <- e
|
|
|
|
}
|
|
|
|
case ui.WindowClosedEvent:
|
|
|
|
if w.windowClosed != nil {
|
|
|
|
w.windowClosed <- e
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-10 14:12:39 +01:00
|
|
|
func (w *windowEvents) ScreenSizeUpdated() <-chan ui.ScreenSizeUpdatedEvent {
|
|
|
|
if w.screenSizeUpdated != nil {
|
|
|
|
return w.screenSizeUpdated
|
|
|
|
}
|
|
|
|
w.screenSizeUpdated = make(chan ui.ScreenSizeUpdatedEvent)
|
|
|
|
return w.screenSizeUpdated
|
|
|
|
}
|
|
|
|
|
2013-12-15 15:41:33 +01:00
|
|
|
func (w *windowEvents) MouseStateUpdated() <-chan ui.MouseStateUpdatedEvent {
|
|
|
|
if w.mouseStateUpdated != nil {
|
|
|
|
return w.mouseStateUpdated
|
2013-12-10 14:12:39 +01:00
|
|
|
}
|
2013-12-15 15:41:33 +01:00
|
|
|
w.mouseStateUpdated = make(chan ui.MouseStateUpdatedEvent)
|
|
|
|
return w.mouseStateUpdated
|
2013-12-10 14:12:39 +01:00
|
|
|
}
|
|
|
|
|
2013-12-10 16:49:30 +01:00
|
|
|
func (w *windowEvents) WindowClosed() <-chan ui.WindowClosedEvent {
|
|
|
|
if w.windowClosed != nil {
|
|
|
|
return w.windowClosed
|
|
|
|
}
|
|
|
|
w.windowClosed = make(chan ui.WindowClosedEvent)
|
|
|
|
return w.windowClosed
|
|
|
|
}
|