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
|
|
|
|
//
|
2014-01-06 16:10:46 +01:00
|
|
|
// 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"
|
2013-12-02 16:15:01 +01:00
|
|
|
"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 {
|
2014-01-06 16:10:46 +01:00
|
|
|
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{}
|
2014-01-06 18:14:53 +01:00
|
|
|
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 {
|
2014-01-06 16:10:46 +01:00
|
|
|
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 {
|
2014-01-06 16:10:46 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-01-06 18:14:53 +01:00
|
|
|
func (u *cocoaUI) RunMainLoop() {
|
|
|
|
C.StartApplication()
|
|
|
|
currentUI.textureFactory.run()
|
|
|
|
|
|
|
|
// TODO: Enable the loop
|
|
|
|
//C.Run()
|
2013-12-06 18:20:48 +01:00
|
|
|
}
|