Rename Window -> GameWindow

This commit is contained in:
Hajime Hoshi 2014-01-04 01:47:05 +09:00
parent 1a7a8b340f
commit 0829299fea
4 changed files with 27 additions and 27 deletions

View File

@ -51,7 +51,7 @@ NSOpenGLContext* CreateGLContext(NSOpenGLContext* sharedGLContext) {
return glContext; return glContext;
} }
NSWindow* CreateWindow(size_t width, size_t height, const char* title, NSOpenGLContext* glContext) { EbitenGameWindow* CreateGameWindow(size_t width, size_t height, const char* title, NSOpenGLContext* glContext) {
NSSize size = NSMakeSize(width, height); NSSize size = NSMakeSize(width, height);
EbitenGameWindow* window = [[EbitenGameWindow alloc] EbitenGameWindow* window = [[EbitenGameWindow alloc]
initWithSize:size initWithSize:size
@ -100,6 +100,6 @@ void UnuseGLContext(void) {
CGLUnlockContext(cglContext); CGLUnlockContext(cglContext);
} }
NSOpenGLContext* GetGLContext(NSWindow* window) { NSOpenGLContext* GetGLContext(EbitenGameWindow* window) {
return [(EbitenGameWindow*)window glContext]; return [window glContext];
} }

View File

@ -50,6 +50,6 @@ func (t *textureFactory) useGLContext(f func()) {
<-t.funcsDone <-t.funcsDone
} }
func (t *textureFactory) createWindow(ui *cocoaUI, width, height, scale int, title string) *Window { func (t *textureFactory) createGameWindow(ui *cocoaUI, width, height, scale int, title string) *GameWindow {
return runWindow(ui, width, height, scale, title, t.sharedContext) return runGameWindow(ui, width, height, scale, title, t.sharedContext)
} }

View File

@ -48,7 +48,7 @@ func TextureFactory() graphics.TextureFactory {
} }
func (u *cocoaUI) CreateGameWindow(width, height, scale int, title string) ui.GameWindow { func (u *cocoaUI) CreateGameWindow(width, height, scale int, title string) ui.GameWindow {
return u.textureFactory.createWindow(u, width, height, scale, title) return u.textureFactory.createGameWindow(u, width, height, scale, title)
} }
func (u *cocoaUI) PollEvents() { func (u *cocoaUI) PollEvents() {

View File

@ -4,15 +4,15 @@ package cocoa
// //
// #include "input.h" // #include "input.h"
// //
// @class NSWindow; // @class EbitenGameWindow;
// @class NSOpenGLContext; // @class NSOpenGLContext;
// //
// typedef NSWindow* NSWindowPtr; // typedef EbitenGameWindow* EbitenGameWindowPtr;
// //
// NSWindow* CreateWindow(size_t width, size_t height, const char* title, NSOpenGLContext* glContext); // EbitenGameWindow* CreateGameWindow(size_t width, size_t height, const char* title, NSOpenGLContext* glContext);
// NSOpenGLContext* CreateGLContext(NSOpenGLContext* sharedGLContext); // NSOpenGLContext* CreateGLContext(NSOpenGLContext* sharedGLContext);
// //
// NSOpenGLContext* GetGLContext(NSWindow* window); // NSOpenGLContext* GetGLContext(EbitenGameWindow* window);
// void UseGLContext(NSOpenGLContext* glContext); // void UseGLContext(NSOpenGLContext* glContext);
// void UnuseGLContext(void); // void UnuseGLContext(void);
// //
@ -25,13 +25,13 @@ import (
"unsafe" "unsafe"
) )
type Window struct { type GameWindow struct {
ui *cocoaUI ui *cocoaUI
screenWidth int screenWidth int
screenHeight int screenHeight int
screenScale int screenScale int
closed bool closed bool
native *C.NSWindow native *C.EbitenGameWindow
pressedKeys map[ui.Key]struct{} pressedKeys map[ui.Key]struct{}
context *opengl.Context context *opengl.Context
funcs chan func() funcs chan func()
@ -39,10 +39,10 @@ type Window struct {
events chan interface{} events chan interface{}
} }
var windows = map[*C.NSWindow]*Window{} var windows = map[*C.EbitenGameWindow]*GameWindow{}
func runWindow(cocoaUI *cocoaUI, width, height, scale int, title string, sharedContext *C.NSOpenGLContext) *Window { func runGameWindow(cocoaUI *cocoaUI, width, height, scale int, title string, sharedContext *C.NSOpenGLContext) *GameWindow {
w := &Window{ w := &GameWindow{
ui: cocoaUI, ui: cocoaUI,
screenWidth: width, screenWidth: width,
screenHeight: height, screenHeight: height,
@ -60,7 +60,7 @@ func runWindow(cocoaUI *cocoaUI, width, height, scale int, title string, sharedC
go func() { go func() {
runtime.LockOSThread() runtime.LockOSThread()
glContext := C.CreateGLContext(sharedContext) glContext := C.CreateGLContext(sharedContext)
w.native = C.CreateWindow(C.size_t(width*scale), w.native = C.CreateGameWindow(C.size_t(width*scale),
C.size_t(height*scale), C.size_t(height*scale),
cTitle, cTitle,
glContext) glContext)
@ -75,7 +75,7 @@ func runWindow(cocoaUI *cocoaUI, width, height, scale int, title string, sharedC
return w return w
} }
func (w *Window) loop() { func (w *GameWindow) loop() {
for { for {
select { select {
case f := <-w.funcs: case f := <-w.funcs:
@ -88,7 +88,7 @@ func (w *Window) loop() {
} }
} }
func (w *Window) Draw(f func(graphics.Context)) { func (w *GameWindow) Draw(f func(graphics.Context)) {
if w.closed { if w.closed {
return return
} }
@ -97,12 +97,12 @@ func (w *Window) Draw(f func(graphics.Context)) {
}) })
} }
func (w *Window) useGLContext(f func()) { func (w *GameWindow) useGLContext(f func()) {
w.funcs <- f w.funcs <- f
<-w.funcsDone <-w.funcsDone
} }
func (w *Window) Events() <-chan interface{} { func (w *GameWindow) Events() <-chan interface{} {
if w.events != nil { if w.events != nil {
return w.events return w.events
} }
@ -110,7 +110,7 @@ func (w *Window) Events() <-chan interface{} {
return w.events return w.events
} }
func (w *Window) notify(e interface{}) { func (w *GameWindow) notify(e interface{}) {
if w.events == nil { if w.events == nil {
return return
} }
@ -121,13 +121,13 @@ func (w *Window) notify(e interface{}) {
// Now this function is not used anywhere. // Now this function is not used anywhere.
//export ebiten_WindowSizeUpdated //export ebiten_WindowSizeUpdated
func ebiten_WindowSizeUpdated(nativeWindow C.NSWindowPtr, width, height int) { func ebiten_WindowSizeUpdated(nativeWindow C.EbitenGameWindowPtr, width, height int) {
w := windows[nativeWindow] w := windows[nativeWindow]
e := ui.WindowSizeUpdatedEvent{width, height} e := ui.WindowSizeUpdatedEvent{width, height}
w.notify(e) w.notify(e)
} }
func (w *Window) keyStateUpdatedEvent() ui.KeyStateUpdatedEvent { func (w *GameWindow) keyStateUpdatedEvent() ui.KeyStateUpdatedEvent {
keys := []ui.Key{} keys := []ui.Key{}
for key, _ := range w.pressedKeys { for key, _ := range w.pressedKeys {
keys = append(keys, key) keys = append(keys, key)
@ -146,7 +146,7 @@ var cocoaKeyCodeToKey = map[int]ui.Key{
} }
//export ebiten_KeyDown //export ebiten_KeyDown
func ebiten_KeyDown(nativeWindow C.NSWindowPtr, keyCode int) { func ebiten_KeyDown(nativeWindow C.EbitenGameWindowPtr, keyCode int) {
key, ok := cocoaKeyCodeToKey[keyCode] key, ok := cocoaKeyCodeToKey[keyCode]
if !ok { if !ok {
return return
@ -157,7 +157,7 @@ func ebiten_KeyDown(nativeWindow C.NSWindowPtr, keyCode int) {
} }
//export ebiten_KeyUp //export ebiten_KeyUp
func ebiten_KeyUp(nativeWindow C.NSWindowPtr, keyCode int) { func ebiten_KeyUp(nativeWindow C.EbitenGameWindowPtr, keyCode int) {
key, ok := cocoaKeyCodeToKey[keyCode] key, ok := cocoaKeyCodeToKey[keyCode]
if !ok { if !ok {
return return
@ -168,7 +168,7 @@ func ebiten_KeyUp(nativeWindow C.NSWindowPtr, keyCode int) {
} }
//export ebiten_MouseStateUpdated //export ebiten_MouseStateUpdated
func ebiten_MouseStateUpdated(nativeWindow C.NSWindowPtr, inputType C.InputType, cx, cy C.int) { func ebiten_MouseStateUpdated(nativeWindow C.EbitenGameWindowPtr, inputType C.InputType, cx, cy C.int) {
w := windows[nativeWindow] w := windows[nativeWindow]
if inputType == C.InputTypeMouseUp { if inputType == C.InputTypeMouseUp {
@ -195,7 +195,7 @@ func ebiten_MouseStateUpdated(nativeWindow C.NSWindowPtr, inputType C.InputType,
} }
//export ebiten_WindowClosed //export ebiten_WindowClosed
func ebiten_WindowClosed(nativeWindow C.NSWindowPtr) { func ebiten_WindowClosed(nativeWindow C.EbitenGameWindowPtr) {
w := windows[nativeWindow] w := windows[nativeWindow]
w.closed = true w.closed = true
w.notify(ui.WindowClosedEvent{}) w.notify(ui.WindowClosedEvent{})