ebiten/ui/cocoa/ui.go

56 lines
1018 B
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
//
// void Run(void);
2013-11-23 17:17:22 +01:00
// void StartApplication(void);
2013-11-23 10:10:15 +01:00
// void PollEvents(void);
2013-10-12 20:17:51 +02:00
//
import "C"
import (
2013-11-22 18:56:18 +01:00
"github.com/hajimehoshi/go-ebiten/graphics"
"github.com/hajimehoshi/go-ebiten/ui"
2013-10-12 20:17:51 +02:00
)
2013-12-11 14:31:13 +01:00
type cocoaUI struct {
textureFactory *textureFactory
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{}
currentUI.textureFactory = newTextureFactory()
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 {
return getCurrentUI().textureFactory
2013-10-14 17:49:30 +02:00
}
2013-12-30 19:17:39 +01:00
func (u *cocoaUI) CreateGameWindow(width, height, scale int, title string) ui.GameWindow {
return u.textureFactory.createGameWindow(width, height, scale, title)
2013-12-09 15:52:14 +01:00
}
2013-12-11 14:31:13 +01:00
func (u *cocoaUI) PollEvents() {
2013-11-23 10:10:15 +01:00
C.PollEvents()
2013-10-14 17:49:30 +02:00
}
func (u *cocoaUI) RunMainLoop() {
C.StartApplication()
currentUI.textureFactory.run()
// TODO: Enable the loop
//C.Run()
2013-12-06 18:20:48 +01:00
}