Update ui/cocoa

This commit is contained in:
Hajime Hoshi 2013-10-13 17:36:18 +09:00
parent e8a4bdcef2
commit c396d5561d
6 changed files with 10 additions and 20 deletions

View File

@ -5,16 +5,20 @@ package cocoa
// //
// #include <stdlib.h> // #include <stdlib.h>
// //
// void Run(size_t width, size_t height, size_t scale); // void Run(size_t width, size_t height, size_t scale, const char* title);
// //
import "C" import "C"
import ( import (
"github.com/hajimehoshi/go.ebiten" "github.com/hajimehoshi/go.ebiten"
_ "github.com/hajimehoshi/go.ebiten/graphics" _ "github.com/hajimehoshi/go.ebiten/graphics"
_ "github.com/hajimehoshi/go.ebiten/graphics/opengl" _ "github.com/hajimehoshi/go.ebiten/graphics/opengl"
"unsafe"
) )
func Run(game ebiten.Game, screenWidth, screenHeight, screenScale int, func Run(game ebiten.Game, screenWidth, screenHeight, screenScale int,
title string) { title string) {
C.Run(C.size_t(screenWidth), C.size_t(screenHeight), C.size_t(screenScale)) cTitle := C.CString(title)
defer C.free(unsafe.Pointer(cTitle))
C.Run(C.size_t(screenWidth), C.size_t(screenHeight), C.size_t(screenScale), cTitle)
} }

View File

@ -8,8 +8,7 @@
} }
- (id)initWithWindow:(NSWindow*)window { - (id)initWithWindow:(NSWindow*)window {
self = [super init]; if (self = [super init]) {
if (self != nil) {
self->window_ = window; self->window_ = window;
} }
return self; return self;

View File

@ -30,7 +30,6 @@ EbitenDisplayLinkCallback(CVDisplayLinkRef displayLink,
CVDisplayLinkRef displayLink_; CVDisplayLinkRef displayLink_;
updating* updating_; updating* updating_;
//ebiten::input* input_; //ebiten::input* input_;
bool isTerminated_;
} }
- (id)init { - (id)init {
@ -47,7 +46,6 @@ EbitenDisplayLinkCallback(CVDisplayLinkRef displayLink,
- (void)prepareOpenGL { - (void)prepareOpenGL {
[super prepareOpenGL]; [super prepareOpenGL];
self->isTerminated_ = false;
NSOpenGLContext* openGLContext = [self openGLContext]; NSOpenGLContext* openGLContext = [self openGLContext];
assert(openGLContext != nil); assert(openGLContext != nil);
GLint const swapInterval = 1; GLint const swapInterval = 1;
@ -141,12 +139,4 @@ EbitenDisplayLinkCallback(CVDisplayLinkRef displayLink,
}*/ }*/
} }
- (void)terminate {
self->isTerminated_ = true;
}
- (bool)isTerminated {
return self->isTerminated_;
}
@end @end

View File

@ -12,8 +12,6 @@ typedef bool updating(void);
- (CVReturn)getFrameForTime:(CVTimeStamp const*)outputTime; - (CVReturn)getFrameForTime:(CVTimeStamp const*)outputTime;
- (void)setUpdatingFunc:(updating*)updatingFunc; - (void)setUpdatingFunc:(updating*)updatingFunc;
- (void)terminate;
- (bool)isTerminated;
@end @end

View File

@ -52,8 +52,7 @@
(void)alert; (void)alert;
(void)contextInfo; (void)contextInfo;
if (returnCode == NSAlertDefaultReturn) { if (returnCode == NSAlertDefaultReturn) {
EbitenOpenGLView* glView = [self contentView]; [NSApp terminate:nil];
[glView terminate];
} }
} }

View File

@ -30,7 +30,7 @@ static NSWindow* generateWindow(size_t width, size_t height) {
return window; return window;
} }
void Run(size_t width, size_t height, size_t scale) { void Run(size_t width, size_t height, size_t scale, const char* title) {
@autoreleasepool { @autoreleasepool {
NSWindow* window = generateWindow(width * scale, height * scale); NSWindow* window = generateWindow(width * scale, height * scale);
EbitenController* controller = [[EbitenController alloc] EbitenController* controller = [[EbitenController alloc]