ebiten/ui/cocoa/ebiten_opengl_view.c

116 lines
3.4 KiB
C
Raw Normal View History

2013-10-12 20:17:51 +02:00
// -*- objc -*-
#include "ebiten_opengl_view.h"
2013-10-13 16:33:22 +02:00
#include "input.h"
2013-10-12 20:17:51 +02:00
2013-10-13 16:06:05 +02:00
void ebiten_EbitenOpenGLView_Initialized(void);
void ebiten_EbitenOpenGLView_Updating(void);
2013-10-13 16:39:10 +02:00
void ebiten_EbitenOpenGLView_InputUpdated(InputType inputType, int x, int y);
2013-10-13 16:06:05 +02:00
2013-10-12 20:17:51 +02:00
// Reference:
// http://developer.apple.com/library/mac/#qa/qa1385/_index.html
// http://www.alecjacobson.com/weblog/?p=2185
// TODO: Use NSViewController?
2013-11-22 18:56:18 +01:00
/*static CVReturn
2013-10-12 20:17:51 +02:00
EbitenDisplayLinkCallback(CVDisplayLinkRef displayLink,
CVTimeStamp const* now,
CVTimeStamp const* outputTime,
CVOptionFlags flagsIn,
CVOptionFlags* flagsOut,
void* displayLinkContext) {
(void)displayLink;
(void)now;
(void)flagsIn;
(void)flagsOut;
@autoreleasepool {
EbitenOpenGLView* view = (__bridge EbitenOpenGLView*)displayLinkContext;
return [view getFrameForTime:outputTime];
}
2013-11-22 18:56:18 +01:00
}*/
2013-10-12 20:17:51 +02:00
@implementation EbitenOpenGLView {
2013-11-22 18:56:18 +01:00
/*@private
CVDisplayLinkRef displayLink_;*/
2013-10-12 20:17:51 +02:00
}
2013-11-22 18:56:18 +01:00
/*- (void)dealloc {
2013-10-12 20:17:51 +02:00
CVDisplayLinkRelease(self->displayLink_);
2013-11-22 18:56:18 +01:00
#if !__has_feature(objc_arc)
[super dealloc];
#endif
}*/
2013-10-12 20:17:51 +02:00
2013-11-22 18:56:18 +01:00
/*- (void)prepareOpenGL {
[super prepareOpenGL];
ebiten_EbitenOpenGLView_Initialized();
}*/
/*- (void)prepareOpenGL {
2013-10-12 20:17:51 +02:00
[super prepareOpenGL];
NSOpenGLContext* openGLContext = [self openGLContext];
assert(openGLContext != nil);
2013-10-13 16:06:05 +02:00
GLint swapInterval = 1;
2013-10-12 20:17:51 +02:00
[openGLContext setValues:&swapInterval
forParameter:NSOpenGLCPSwapInterval];
CVDisplayLinkCreateWithActiveCGDisplays(&self->displayLink_);
CVDisplayLinkSetOutputCallback(self->displayLink_,
&EbitenDisplayLinkCallback,
(__bridge void*)self);
CGLContextObj cglContext = (CGLContextObj)[openGLContext CGLContextObj];
CGLPixelFormatObj cglPixelFormat =
(CGLPixelFormatObj)[[self pixelFormat] CGLPixelFormatObj];
CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(self->displayLink_,
cglContext,
cglPixelFormat);
CVDisplayLinkStart(self->displayLink_);
2013-10-13 16:06:05 +02:00
ebiten_EbitenOpenGLView_Initialized();
2013-11-22 18:56:18 +01:00
}*/
2013-10-12 20:17:51 +02:00
2013-11-22 18:56:18 +01:00
/*- (CVReturn)getFrameForTime:(CVTimeStamp const*)outputTime {
2013-10-12 20:17:51 +02:00
(void)outputTime;
NSOpenGLContext* context = [self openGLContext];
assert(context != nil);
[context makeCurrentContext];
{
CGLLockContext((CGLContextObj)[context CGLContextObj]);
2013-10-13 16:06:05 +02:00
ebiten_EbitenOpenGLView_Updating();
2013-10-12 20:17:51 +02:00
[context flushBuffer];
CGLUnlockContext((CGLContextObj)[context CGLContextObj]);
}
return kCVReturnSuccess;
2013-11-22 18:56:18 +01:00
}*/
2013-10-12 20:17:51 +02:00
- (BOOL)isFlipped {
return YES;
}
- (void)mouseDown:(NSEvent*)theEvent {
NSPoint location = [self convertPoint:[theEvent locationInWindow]
fromView:nil];
2013-10-13 16:33:22 +02:00
int x = location.x;
int y = location.y;
ebiten_EbitenOpenGLView_InputUpdated(InputTypeMouseDown, x, y);
2013-10-12 20:17:51 +02:00
}
- (void)mouseUp:(NSEvent*)theEvent {
(void)theEvent;
2013-10-13 16:33:22 +02:00
NSPoint location = [self convertPoint:[theEvent locationInWindow]
fromView:nil];
int x = location.x;
int y = location.y;
ebiten_EbitenOpenGLView_InputUpdated(InputTypeMouseUp, x, y);
2013-10-12 20:17:51 +02:00
}
- (void)mouseDragged:(NSEvent*)theEvent {
NSPoint location = [self convertPoint:[theEvent locationInWindow]
fromView:nil];
2013-10-13 16:33:22 +02:00
int x = location.x;
int y = location.y;
ebiten_EbitenOpenGLView_InputUpdated(InputTypeMouseDragged, x, y);
2013-10-12 20:17:51 +02:00
}
@end