ebiten/ui/cocoa/ui.go

58 lines
1.0 KiB
Go
Raw Normal View History

2013-10-12 20:17:51 +02:00
package cocoa
2013-11-22 18:56:18 +01:00
// #cgo CFLAGS: -x objective-c
2013-11-23 10:10:15 +01:00
// #cgo LDFLAGS: -framework Cocoa -framework OpenGL
//
2013-11-23 17:17:22 +01:00
// void StartApplication(void);
2014-01-11 10:11:13 +01:00
// void DoEvents(void);
2014-01-13 07:26:20 +01:00
// void TerminateApplication(void);
2013-10-12 20:17:51 +02:00
//
import "C"
import (
2014-12-05 14:16:58 +01:00
"github.com/hajimehoshi/ebiten/graphics"
"github.com/hajimehoshi/ebiten/ui"
2013-10-12 20:17:51 +02:00
)
2013-12-11 14:31:13 +01:00
type cocoaUI struct {
2014-01-11 02:34:38 +01:00
sharedContext *sharedContext
2013-10-13 16:06:05 +02:00
}
2013-12-11 14:31:13 +01:00
var currentUI *cocoaUI
2013-10-13 16:06:05 +02:00
2013-12-11 14:31:13 +01:00
func getCurrentUI() *cocoaUI {
2013-10-14 17:49:30 +02:00
if currentUI != nil {
2013-12-11 14:31:13 +01:00
return currentUI
2013-10-14 17:49:30 +02:00
}
2013-12-11 14:31:13 +01:00
currentUI = &cocoaUI{}
2014-01-11 02:34:38 +01:00
currentUI.sharedContext = newSharedContext()
2013-10-14 17:49:30 +02:00
2013-12-11 14:31:13 +01:00
return currentUI
}
func UI() ui.UI {
return getCurrentUI()
}
2013-11-29 19:21:10 +01:00
2013-12-11 14:31:13 +01:00
func TextureFactory() graphics.TextureFactory {
2014-01-11 02:34:38 +01:00
return getCurrentUI().sharedContext
2013-10-14 17:49:30 +02:00
}
2014-05-11 14:24:37 +02:00
func (u *cocoaUI) CreateCanvas(width, height, scale int, title string) ui.Canvas {
2014-01-11 02:34:38 +01:00
return u.sharedContext.createGameWindow(width, height, scale, title)
2013-12-09 15:52:14 +01:00
}
2014-01-11 10:11:13 +01:00
func (u *cocoaUI) DoEvents() {
C.DoEvents()
2013-10-14 17:49:30 +02:00
}
2014-01-13 07:26:20 +01:00
func (u *cocoaUI) Start() {
C.StartApplication()
2014-01-11 02:34:38 +01:00
currentUI.sharedContext.run()
2013-12-06 18:20:48 +01:00
}
2014-01-11 02:34:38 +01:00
2014-01-13 07:26:20 +01:00
func (u *cocoaUI) Terminate() {
// TODO: Close existing windows
C.TerminateApplication()
2014-01-11 02:34:38 +01:00
}