Merge branch 'master' of git://94.254.65.99

This commit is contained in:
Camilla Berglund 2010-09-16 01:30:20 +02:00
commit 8308c4b89b
8 changed files with 367 additions and 442 deletions

View File

@ -3,9 +3,8 @@ configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/libglfw.pc.cmake
${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc @ONLY)
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/lib
include_directories(${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/src
${GLFW_INCLUDE_DIR})
set(cocoa_SOURCES

View File

@ -37,12 +37,12 @@
// Enable and disable system keys
//========================================================================
void _glfwPlatformEnableSystemKeys( void )
void _glfwPlatformEnableSystemKeys(_GLFWwindow* window)
{
// This is checked in macosx_window.m; we take no action here
}
void _glfwPlatformDisableSystemKeys( void )
void _glfwPlatformDisableSystemKeys(_GLFWwindow* window)
{
// This is checked in macosx_window.m; we take no action here
// I don't think it's really possible to disable stuff like Exposé

View File

@ -77,16 +77,14 @@ static GLFWvidmode vidmodeFromCGDisplayMode( NSDictionary *mode )
int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
{
NSArray* modes = (NSArray*) CGDisplayAvailableModes(CGMainDisplayID());
unsigned int i, j = 0, n = [modes count];
for (i = 0; i < n && i < (unsigned)maxcount; i++)
{
NSDictionary *mode = [modes objectAtIndex:i];
if (modeIsGood(mode))
{
list[j++] = vidmodeFromCGDisplayMode(mode);
}
}
return j;
}
@ -97,6 +95,6 @@ int _glfwPlatformGetVideoModes( GLFWvidmode *list, int maxcount )
void _glfwPlatformGetDesktopMode(GLFWvidmode *mode)
{
*mode = vidmodeFromCGDisplayMode( _glfwLibrary.DesktopMode );
*mode = vidmodeFromCGDisplayMode(_glfwLibrary.NS.desktopMode);
}

View File

@ -53,7 +53,7 @@ void * _glfwPlatformGetProcAddress( const char *procname )
procname,
kCFStringEncodingASCII);
void *symbol = CFBundleGetFunctionPointerForName( _glfwLibrary.OpenGLFramework,
void* symbol = CFBundleGetFunctionPointerForName(_glfwLibrary.NS.OpenGLFramework,
symbolName);
CFRelease(symbolName);

View File

@ -43,14 +43,10 @@
- (void)sendEvent:(NSEvent *)event
{
if ([event type] == NSKeyUp && ([event modifierFlags] & NSCommandKeyMask))
{
[[self keyWindow] sendEvent:event];
}
else
{
[super sendEvent:event];
}
}
@end
@ -74,9 +70,9 @@ NSString *GLFWNameKeys[] =
//========================================================================
static NSString* findAppName(void)
{
unsigned int i;
NSDictionary* infoDictionary = [[NSBundle mainBundle] infoDictionary];
unsigned int i;
for (i = 0; i < sizeof(GLFWNameKeys) / sizeof(GLFWNameKeys[0]); i++)
{
id name = [infoDictionary objectForKey:GLFWNameKeys[i]];
@ -89,7 +85,7 @@ static NSString *findAppName( void )
}
// If we get here, we're unbundled
if( !_glfwLibrary.Unbundled )
if (!_glfwLibrary.NS.unbundled)
{
// Could do this only if we discover we're unbundled, but it should
// do no harm...
@ -100,7 +96,7 @@ static NSString *findAppName( void )
// handy. There is an NSApplication API to do this, but...
SetFrontProcess(&psn);
_glfwLibrary.Unbundled = GL_TRUE;
_glfwLibrary.NS.unbundled = GL_TRUE;
}
char** progname = _NSGetProgname();
@ -179,10 +175,8 @@ static void setUpMenuBar( void )
// goes away. Hopefully that means the worst we'll break in future is to
// look ugly...
if ([NSApp respondsToSelector:@selector(setAppleMenu:)])
{
[NSApp setAppleMenu:appMenu];
}
}
//========================================================================
// Terminate GLFW when exiting application
@ -204,7 +198,7 @@ static void glfw_atexit( void )
int _glfwPlatformInit(void)
{
_glfwLibrary.AutoreleasePool = [[NSAutoreleasePool alloc] init];
_glfwLibrary.NS.autoreleasePool = [[NSAutoreleasePool alloc] init];
// Implicitly create shared NSApplication instance
[GLFWApplication sharedApplication];
@ -212,9 +206,7 @@ int _glfwPlatformInit( void )
NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
if (access([resourcePath cStringUsingEncoding:NSUTF8StringEncoding], R_OK) == 0)
{
chdir([resourcePath cStringUsingEncoding:NSUTF8StringEncoding]);
}
// Setting up menu bar must go exactly here else weirdness ensues
setUpMenuBar();
@ -226,7 +218,7 @@ int _glfwPlatformInit( void )
_glfwPlatformSetTime(0.0);
_glfwLibrary.DesktopMode =
_glfwLibrary.NS.desktopMode =
(NSDictionary*) CGDisplayCurrentMode(CGMainDisplayID());
return GL_TRUE;
@ -238,13 +230,24 @@ int _glfwPlatformInit( void )
int _glfwPlatformTerminate( void )
{
glfwCloseWindow();
// TODO: Probably other cleanup
[_glfwLibrary.AutoreleasePool release];
_glfwLibrary.AutoreleasePool = nil;
[_glfwLibrary.NS.autoreleasePool release];
_glfwLibrary.NS.autoreleasePool = nil;
return GL_TRUE;
}
//========================================================================
// Get the GLFW version string
//========================================================================
const char* _glfwPlatformGetVersionString(void)
{
// TODO: Bring in CMake version
const char* version = "GLFW" " Cocoa";
return version;
}

View File

@ -39,7 +39,8 @@
double _glfwPlatformGetTime( void )
{
return [NSDate timeIntervalSinceReferenceDate] - _glfwLibrary.Timer.t0;
return [NSDate timeIntervalSinceReferenceDate] -
_glfwLibrary.NS.timer.t0;
}
//========================================================================
@ -48,6 +49,7 @@ double _glfwPlatformGetTime( void )
void _glfwPlatformSetTime( double time )
{
_glfwLibrary.Timer.t0 = [NSDate timeIntervalSinceReferenceDate] - time;
_glfwLibrary.NS.timer.t0 =
[NSDate timeIntervalSinceReferenceDate] - time;
}

View File

@ -35,52 +35,59 @@
//========================================================================
@interface GLFWWindowDelegate : NSObject
{
_GLFWwindow* window;
}
- (id)initWithRats:(_GLFWwindow*)initWndow;
@end
@implementation GLFWWindowDelegate
- (BOOL)windowShouldClose:(id)window
- (id)initWithRats:(_GLFWwindow*)initWindow
{
if( _glfwWin.windowCloseCallback )
{
if( !_glfwWin.windowCloseCallback() )
{
return NO;
}
self = [super init];
if (self != nil)
window = initWindow;
return self;
}
// This is horribly ugly, but it works
glfwCloseWindow();
- (BOOL)windowShouldClose:(id)sender
{
if (window->windowCloseCallback)
{
if (!window->windowCloseCallback(window))
return NO;
}
window->closed = GL_TRUE;
return NO;
}
- (void)windowDidResize:(NSNotification *)notification
{
[_glfwWin.context update];
[window->NSGL.context update];
NSRect contentRect =
[_glfwWin.window contentRectForFrameRect:[_glfwWin.window frame]];
_glfwWin.width = contentRect.size.width;
_glfwWin.height = contentRect.size.height;
[window->NS.window contentRectForFrameRect:[window->NS.window frame]];
window->width = contentRect.size.width;
window->height = contentRect.size.height;
if( _glfwWin.windowSizeCallback )
{
_glfwWin.windowSizeCallback( _glfwWin.width, _glfwWin.height );
}
if (window->windowSizeCallback)
window->windowSizeCallback(window, window->width, window->height);
}
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
{
if( _glfwWin.windowCloseCallback )
{
if( !_glfwWin.windowCloseCallback() )
if (window->windowCloseCallback)
{
if (!window->windowCloseCallback(window))
return NSTerminateCancel;
}
}
// This is horribly ugly, but it works
glfwCloseWindow();
window->closed = GL_TRUE;
return NSTerminateCancel;
}
@ -226,9 +233,7 @@ static const unsigned int MAC_TO_GLFW_KEYCODE_MAPPING[128] =
static int convertMacKeyCode(unsigned int macKeyCode)
{
if (macKeyCode >= 128)
{
return -1;
}
// This treats keycodes as *positional*; that is, we'll return 'a'
// for the key left of 's', even on an AZERTY keyboard. The charInput
@ -241,10 +246,25 @@ static int convertMacKeyCode( unsigned int macKeyCode )
//========================================================================
@interface GLFWContentView : NSView
{
_GLFWwindow* window;
}
- (id)initWithRats:(_GLFWwindow*)initWindow;
@end
@implementation GLFWContentView
- (id)initWithRats:(_GLFWwindow*)initWindow
{
self = [super init];
if (self != nil)
window = initWindow;
return self;
}
- (BOOL)isOpaque
{
return YES;
@ -262,7 +282,7 @@ static int convertMacKeyCode( unsigned int macKeyCode )
- (void)mouseDown:(NSEvent *)event
{
_glfwInputMouseClick( GLFW_MOUSE_BUTTON_LEFT, GLFW_PRESS );
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_LEFT, GLFW_PRESS);
}
- (void)mouseDragged:(NSEvent *)event
@ -272,34 +292,32 @@ static int convertMacKeyCode( unsigned int macKeyCode )
- (void)mouseUp:(NSEvent *)event
{
_glfwInputMouseClick( GLFW_MOUSE_BUTTON_LEFT, GLFW_RELEASE );
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_LEFT, GLFW_RELEASE);
}
- (void)mouseMoved:(NSEvent *)event
{
if( _glfwWin.mouseLock )
if (window == _glfwLibrary.cursorLockWindow)
{
_glfwInput.MousePosX += [event deltaX];
_glfwInput.MousePosY += [event deltaY];
window->mousePosX += [event deltaX];
window->mousePosY += [event deltaY];
}
else
{
NSPoint p = [event locationInWindow];
// Cocoa coordinate system has origin at lower left
_glfwInput.MousePosX = p.x;
_glfwInput.MousePosY = [[_glfwWin.window contentView] bounds].size.height - p.y;
window->mousePosX = p.x;
window->mousePosY = [[window->NS.window contentView] bounds].size.height - p.y;
}
if( _glfwWin.mousePosCallback )
{
_glfwWin.mousePosCallback( _glfwInput.MousePosX, _glfwInput.MousePosY );
}
if (window->mousePosCallback)
window->mousePosCallback(window, window->mousePosX, window->mousePosY);
}
- (void)rightMouseDown:(NSEvent *)event
{
_glfwInputMouseClick( GLFW_MOUSE_BUTTON_RIGHT, GLFW_PRESS );
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_RIGHT, GLFW_PRESS);
}
- (void)rightMouseDragged:(NSEvent *)event
@ -309,12 +327,12 @@ static int convertMacKeyCode( unsigned int macKeyCode )
- (void)rightMouseUp:(NSEvent *)event
{
_glfwInputMouseClick( GLFW_MOUSE_BUTTON_RIGHT, GLFW_RELEASE );
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_RIGHT, GLFW_RELEASE);
}
- (void)otherMouseDown:(NSEvent *)event
{
_glfwInputMouseClick( [event buttonNumber], GLFW_PRESS );
_glfwInputMouseClick(window, [event buttonNumber], GLFW_PRESS);
}
- (void)otherMouseDragged:(NSEvent *)event
@ -324,86 +342,64 @@ static int convertMacKeyCode( unsigned int macKeyCode )
- (void)otherMouseUp:(NSEvent *)event
{
_glfwInputMouseClick( [event buttonNumber], GLFW_RELEASE );
_glfwInputMouseClick(window, [event buttonNumber], GLFW_RELEASE);
}
- (void)keyDown:(NSEvent *)event
{
NSUInteger length;
NSUInteger i, length;
NSString* characters;
int i, code = convertMacKeyCode( [event keyCode] );
int code = convertMacKeyCode([event keyCode]);
if (code != -1)
{
_glfwInputKey( code, GLFW_PRESS );
_glfwInputKey(window, code, GLFW_PRESS);
if ([event modifierFlags] & NSCommandKeyMask)
{
if( !_glfwWin.sysKeysDisabled )
{
if (!window->sysKeysDisabled)
[super keyDown:event];
}
}
else
{
characters = [event characters];
length = [characters length];
for (i = 0; i < length; i++)
{
_glfwInputChar( [characters characterAtIndex:i], GLFW_PRESS );
}
_glfwInputChar(window, [characters characterAtIndex:i]);
}
}
}
- (void)flagsChanged:(NSEvent *)event
{
unsigned int newModifierFlags = [event modifierFlags] | NSDeviceIndependentModifierFlagsMask;
int mode;
unsigned int newModifierFlags =
[event modifierFlags] | NSDeviceIndependentModifierFlagsMask;
if( newModifierFlags > _glfwWin.modifierFlags )
{
if (newModifierFlags > window->NS.modifierFlags)
mode = GLFW_PRESS;
}
else
{
mode = GLFW_RELEASE;
}
_glfwWin.modifierFlags = newModifierFlags;
_glfwInputKey( MAC_TO_GLFW_KEYCODE_MAPPING[[event keyCode]], mode );
window->NS.modifierFlags = newModifierFlags;
_glfwInputKey(window, MAC_TO_GLFW_KEYCODE_MAPPING[[event keyCode]], mode);
}
- (void)keyUp:(NSEvent *)event
{
NSUInteger length;
NSString* characters;
int i, code = convertMacKeyCode( [event keyCode] );
int code = convertMacKeyCode([event keyCode]);
if (code != -1)
{
_glfwInputKey( code, GLFW_RELEASE );
characters = [event characters];
length = [characters length];
for( i = 0; i < length; i++ )
{
_glfwInputChar( [characters characterAtIndex:i], GLFW_RELEASE );
}
}
_glfwInputKey(window, code, GLFW_RELEASE);
}
- (void)scrollWheel:(NSEvent *)event
{
_glfwInput.WheelPosFloating += [event deltaY];
_glfwInput.WheelPos = lrint(_glfwInput.WheelPosFloating);
window->NS.wheelPosFloating += [event deltaY];
window->wheelPos = lrint(window->NS.wheelPosFloating);
if( _glfwWin.mouseWheelCallback )
{
_glfwWin.mouseWheelCallback( _glfwInput.WheelPos );
}
if (window->mouseWheelCallback)
window->mouseWheelCallback(window, window->wheelPos);
}
@end
@ -417,43 +413,37 @@ static int convertMacKeyCode( unsigned int macKeyCode )
// created
//========================================================================
int _glfwPlatformOpenWindow( int width, int height,
int _glfwPlatformOpenWindow(_GLFWwindow* window,
const _GLFWwndconfig *wndconfig,
const _GLFWfbconfig *fbconfig)
{
int colorBits;
_glfwWin.pixelFormat = nil;
_glfwWin.window = nil;
_glfwWin.context = nil;
_glfwWin.delegate = nil;
window->NS.window = nil;
window->NS.delegate = nil;
window->NSGL.pixelFormat = nil;
window->NSGL.context = nil;
// Fail if OpenGL 3.0 or above was requested
if (wndconfig->glMajor > 2)
{
_glfwPlatformCloseWindow();
_glfwSetError(GLFW_UNAVAILABLE_VERSION);
return GL_FALSE;
}
_glfwWin.delegate = [[GLFWWindowDelegate alloc] init];
if( _glfwWin.delegate == nil )
window->NS.delegate = [[GLFWWindowDelegate alloc] initWithRats:window];
if (window->NS.delegate == nil)
{
_glfwPlatformCloseWindow();
_glfwSetError(GLFW_INTERNAL_ERROR);
return GL_FALSE;
}
[NSApp setDelegate:_glfwWin.delegate];
[NSApp setDelegate:window->NS.delegate];
// Mac OS X needs non-zero color size, so set resonable values
colorBits = fbconfig->redBits + fbconfig->greenBits + fbconfig->blueBits;
int colorBits = fbconfig->redBits + fbconfig->greenBits + fbconfig->blueBits;
if (colorBits == 0)
{
colorBits = 24;
}
else if (colorBits < 15)
{
colorBits = 15;
}
// Ignored hints:
// OpenGLMajor, OpenGLMinor, OpenGLForward:
@ -467,48 +457,48 @@ int _glfwPlatformOpenWindow( int width, int height,
CFDictionaryRef fullscreenMode = NULL;
if (wndconfig->mode == GLFW_FULLSCREEN)
{
fullscreenMode =
// I think it's safe to pass 0 to the refresh rate for this function
// rather than conditionalizing the code to call the version which
// doesn't specify refresh...
fullscreenMode =
CGDisplayBestModeForParametersAndRefreshRateWithProperty(
CGMainDisplayID(),
colorBits + fbconfig->alphaBits,
width,
height,
window->width, window->height,
wndconfig->refreshRate,
// Controversial, see macosx_fullscreen.m for discussion
kCGDisplayModeIsSafeForHardware,
NULL);
width = [[(id)fullscreenMode objectForKey:(id)kCGDisplayWidth] intValue];
height = [[(id)fullscreenMode objectForKey:(id)kCGDisplayHeight] intValue];
window->width = [[(id)fullscreenMode objectForKey:(id)kCGDisplayWidth] intValue];
window->height = [[(id)fullscreenMode objectForKey:(id)kCGDisplayHeight] intValue];
}
unsigned int styleMask = 0;
if( wndconfig->mode == GLFW_WINDOW )
if (wndconfig->mode == GLFW_WINDOWED)
{
styleMask = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask;
if (!wndconfig->windowNoResize)
{
styleMask |= NSResizableWindowMask;
}
}
else
{
styleMask = NSBorderlessWindowMask;
}
_glfwWin.window = [[NSWindow alloc]
initWithContentRect:NSMakeRect(0, 0, width, height)
window->NS.window = [[NSWindow alloc]
initWithContentRect:NSMakeRect(0, 0, window->width, window->height)
styleMask:styleMask
backing:NSBackingStoreBuffered
defer:NO];
[_glfwWin.window setContentView:[[GLFWContentView alloc] init]];
[_glfwWin.window setDelegate:_glfwWin.delegate];
[_glfwWin.window setAcceptsMouseMovedEvents:YES];
[_glfwWin.window center];
[window->NS.window setTitle:[NSString stringWithCString:wndconfig->title
encoding:NSISOLatin1StringEncoding]];
[window->NS.window setContentView:[[GLFWContentView alloc] initWithRats:window]];
[window->NS.window setDelegate:window->NS.delegate];
[window->NS.window setAcceptsMouseMovedEvents:YES];
[window->NS.window center];
if (wndconfig->mode == GLFW_FULLSCREEN)
{
@ -535,37 +525,25 @@ int _glfwPlatformOpenWindow( int width, int height,
ADD_ATTR2(NSOpenGLPFAColorSize, colorBits);
if (fbconfig->alphaBits > 0)
{
ADD_ATTR2(NSOpenGLPFAAlphaSize, fbconfig->alphaBits);
}
if (fbconfig->depthBits > 0)
{
ADD_ATTR2(NSOpenGLPFADepthSize, fbconfig->depthBits);
}
if (fbconfig->stencilBits > 0)
{
ADD_ATTR2(NSOpenGLPFAStencilSize, fbconfig->stencilBits);
}
int accumBits = fbconfig->accumRedBits + fbconfig->accumGreenBits +
fbconfig->accumBlueBits + fbconfig->accumAlphaBits;
if (accumBits > 0)
{
ADD_ATTR2(NSOpenGLPFAAccumSize, accumBits);
}
if (fbconfig->auxBuffers > 0)
{
ADD_ATTR2(NSOpenGLPFAAuxBuffers, fbconfig->auxBuffers);
}
if (fbconfig->stereo)
{
ADD_ATTR(NSOpenGLPFAStereo );
}
if (fbconfig->samples > 0)
{
@ -575,70 +553,84 @@ int _glfwPlatformOpenWindow( int width, int height,
ADD_ATTR(0);
_glfwWin.pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
if( _glfwWin.pixelFormat == nil )
window->NSGL.pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
if (window->NSGL.pixelFormat == nil)
{
_glfwPlatformCloseWindow();
_glfwSetError(GLFW_NO_PIXEL_FORMAT);
return GL_FALSE;
}
_glfwWin.context = [[NSOpenGLContext alloc] initWithFormat:_glfwWin.pixelFormat
window->NSGL.context = [[NSOpenGLContext alloc] initWithFormat:window->NSGL.pixelFormat
shareContext:nil];
if( _glfwWin.context == nil )
if (window->NSGL.context == nil)
{
_glfwPlatformCloseWindow();
_glfwSetError(GLFW_INTERNAL_ERROR);
return GL_FALSE;
}
[_glfwWin.window makeKeyAndOrderFront:nil];
[_glfwWin.context setView:[_glfwWin.window contentView]];
[window->NS.window makeKeyAndOrderFront:nil];
[window->NSGL.context setView:[window->NS.window contentView]];
if (wndconfig->mode == GLFW_FULLSCREEN)
{
// TODO: Make this work on pre-Leopard systems
[[_glfwWin.window contentView] enterFullScreenMode:[NSScreen mainScreen]
[[window->NS.window contentView] enterFullScreenMode:[NSScreen mainScreen]
withOptions:nil];
}
[_glfwWin.context makeCurrentContext];
glfwMakeWindowCurrent(window);
NSPoint point = [[NSCursor currentCursor] hotSpot];
_glfwInput.MousePosX = point.x;
_glfwInput.MousePosY = point.y;
window->mousePosX = point.x;
window->mousePosY = point.y;
return GL_TRUE;
}
//========================================================================
// Make the OpenGL context associated with the specified window current
//========================================================================
void _glfwPlatformMakeWindowCurrent(_GLFWwindow* window)
{
if (window)
[window->NSGL.context makeCurrentContext];
else
[NSOpenGLContext clearCurrentContext];
}
//========================================================================
// Properly kill the window / video display
//========================================================================
void _glfwPlatformCloseWindow( void )
void _glfwPlatformCloseWindow(_GLFWwindow* window)
{
[_glfwWin.window orderOut:nil];
[window->NS.window orderOut:nil];
if( _glfwWin.fullscreen )
if (window->mode == GLFW_FULLSCREEN)
{
[[_glfwWin.window contentView] exitFullScreenModeWithOptions:nil];
[[window->NS.window contentView] exitFullScreenModeWithOptions:nil];
CGDisplaySwitchToMode(CGMainDisplayID(),
(CFDictionaryRef)_glfwLibrary.DesktopMode );
(CFDictionaryRef) _glfwLibrary.NS.desktopMode);
CGReleaseAllDisplays();
}
[_glfwWin.pixelFormat release];
_glfwWin.pixelFormat = nil;
[window->NSGL.pixelFormat release];
window->NSGL.pixelFormat = nil;
[NSOpenGLContext clearCurrentContext];
[_glfwWin.context release];
_glfwWin.context = nil;
[window->NSGL.context release];
window->NSGL.context = nil;
[_glfwWin.window setDelegate:nil];
[window->NS.window setDelegate:nil];
[NSApp setDelegate:nil];
[_glfwWin.delegate release];
_glfwWin.delegate = nil;
[window->NS.delegate release];
window->NS.delegate = nil;
[_glfwWin.window close];
_glfwWin.window = nil;
[window->NS.window close];
window->NS.window = nil;
// TODO: Probably more cleanup
}
@ -647,9 +639,9 @@ void _glfwPlatformCloseWindow( void )
// Set the window title
//========================================================================
void _glfwPlatformSetWindowTitle( const char *title )
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char *title)
{
[_glfwWin.window setTitle:[NSString stringWithCString:title
[window->NS.window setTitle:[NSString stringWithCString:title
encoding:NSISOLatin1StringEncoding]];
}
@ -657,27 +649,27 @@ void _glfwPlatformSetWindowTitle( const char *title )
// Set the window size
//========================================================================
void _glfwPlatformSetWindowSize( int width, int height )
void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
{
[_glfwWin.window setContentSize:NSMakeSize(width, height)];
[window->NS.window setContentSize:NSMakeSize(width, height)];
}
//========================================================================
// Set the window position
//========================================================================
void _glfwPlatformSetWindowPos( int x, int y )
void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y)
{
NSRect contentRect = [_glfwWin.window contentRectForFrameRect:[_glfwWin.window frame]];
NSRect contentRect = [window->NS.window contentRectForFrameRect:[window->NS.window frame]];
// We assume here that the client code wants to position the window within the
// screen the window currently occupies
NSRect screenRect = [[_glfwWin.window screen] visibleFrame];
NSRect screenRect = [[window->NS.window screen] visibleFrame];
contentRect.origin = NSMakePoint(screenRect.origin.x + x,
screenRect.origin.y + screenRect.size.height -
y - contentRect.size.height);
[_glfwWin.window setFrame:[_glfwWin.window frameRectForContentRect:contentRect]
[window->NS.window setFrame:[window->NS.window frameRectForContentRect:contentRect]
display:YES];
}
@ -685,18 +677,18 @@ void _glfwPlatformSetWindowPos( int x, int y )
// Iconify the window
//========================================================================
void _glfwPlatformIconifyWindow( void )
void _glfwPlatformIconifyWindow(_GLFWwindow* window)
{
[_glfwWin.window miniaturize:nil];
[window->NS.window miniaturize:nil];
}
//========================================================================
// Restore (un-iconify) the window
//========================================================================
void _glfwPlatformRestoreWindow( void )
void _glfwPlatformRestoreWindow(_GLFWwindow* window)
{
[_glfwWin.window deminiaturize:nil];
[window->NS.window deminiaturize:nil];
}
//========================================================================
@ -705,8 +697,10 @@ void _glfwPlatformRestoreWindow( void )
void _glfwPlatformSwapBuffers(void)
{
_GLFWwindow* window = _glfwLibrary.currentWindow;
// ARP appears to be unnecessary, but this is future-proof
[_glfwWin.context flushBuffer];
[window->NSGL.context flushBuffer];
}
//========================================================================
@ -715,8 +709,10 @@ void _glfwPlatformSwapBuffers( void )
void _glfwPlatformSwapInterval(int interval)
{
_GLFWwindow* window = _glfwLibrary.currentWindow;
GLint sync = interval;
[_glfwWin.context setValues:&sync forParameter:NSOpenGLCPSwapInterval];
[window->NSGL.context setValues:&sync forParameter:NSOpenGLCPSwapInterval];
}
//========================================================================
@ -726,67 +722,68 @@ void _glfwPlatformSwapInterval( int interval )
void _glfwPlatformRefreshWindowParams(void)
{
GLint value;
_GLFWwindow* window = _glfwLibrary.currentWindow;
// Since GLFW 2.x doesn't understand screens, we use virtual screen zero
// Since GLFW doesn't understand screens, we use virtual screen zero
[_glfwWin.pixelFormat getValues:&value
[window->NSGL.pixelFormat getValues:&value
forAttribute:NSOpenGLPFAAccelerated
forVirtualScreen:0];
_glfwWin.accelerated = value;
window->accelerated = value;
[_glfwWin.pixelFormat getValues:&value
[window->NSGL.pixelFormat getValues:&value
forAttribute:NSOpenGLPFAAlphaSize
forVirtualScreen:0];
_glfwWin.alphaBits = value;
window->alphaBits = value;
// It seems that the color size includes the size of the alpha channel
[_glfwWin.pixelFormat getValues:&value
[window->NSGL.pixelFormat getValues:&value
forAttribute:NSOpenGLPFAColorSize
forVirtualScreen:0];
value -= _glfwWin.alphaBits;
_glfwWin.redBits = value / 3;
_glfwWin.greenBits = value / 3;
_glfwWin.blueBits = value / 3;
value -= window->alphaBits;
window->redBits = value / 3;
window->greenBits = value / 3;
window->blueBits = value / 3;
[_glfwWin.pixelFormat getValues:&value
[window->NSGL.pixelFormat getValues:&value
forAttribute:NSOpenGLPFADepthSize
forVirtualScreen:0];
_glfwWin.depthBits = value;
window->depthBits = value;
[_glfwWin.pixelFormat getValues:&value
[window->NSGL.pixelFormat getValues:&value
forAttribute:NSOpenGLPFAStencilSize
forVirtualScreen:0];
_glfwWin.stencilBits = value;
window->stencilBits = value;
[_glfwWin.pixelFormat getValues:&value
[window->NSGL.pixelFormat getValues:&value
forAttribute:NSOpenGLPFAAccumSize
forVirtualScreen:0];
_glfwWin.accumRedBits = value / 3;
_glfwWin.accumGreenBits = value / 3;
_glfwWin.accumBlueBits = value / 3;
window->accumRedBits = value / 3;
window->accumGreenBits = value / 3;
window->accumBlueBits = value / 3;
// TODO: Figure out what to set this value to
_glfwWin.accumAlphaBits = 0;
window->accumAlphaBits = 0;
[_glfwWin.pixelFormat getValues:&value
[window->NSGL.pixelFormat getValues:&value
forAttribute:NSOpenGLPFAAuxBuffers
forVirtualScreen:0];
_glfwWin.auxBuffers = value;
window->auxBuffers = value;
[_glfwWin.pixelFormat getValues:&value
[window->NSGL.pixelFormat getValues:&value
forAttribute:NSOpenGLPFAStereo
forVirtualScreen:0];
_glfwWin.stereo = value;
window->stereo = value;
[_glfwWin.pixelFormat getValues:&value
[window->NSGL.pixelFormat getValues:&value
forAttribute:NSOpenGLPFASamples
forVirtualScreen:0];
_glfwWin.samples = value;
window->samples = value;
// These are forced to false as long as Mac OS X lacks support for OpenGL 3.0+
_glfwWin.glForward = GL_FALSE;
_glfwWin.glDebug = GL_FALSE;
_glfwWin.glProfile = 0;
window->glForward = GL_FALSE;
window->glDebug = GL_FALSE;
window->glProfile = 0;
}
//========================================================================
@ -805,14 +802,12 @@ void _glfwPlatformPollEvents( void )
dequeue:YES];
if (event)
{
[NSApp sendEvent:event];
}
}
while (event);
[_glfwLibrary.AutoreleasePool drain];
_glfwLibrary.AutoreleasePool = [[NSAutoreleasePool alloc] init];
[_glfwLibrary.NS.autoreleasePool drain];
_glfwLibrary.NS.autoreleasePool = [[NSAutoreleasePool alloc] init];
}
//========================================================================
@ -837,7 +832,7 @@ void _glfwPlatformWaitEvents( void )
// Hide mouse cursor (lock it)
//========================================================================
void _glfwPlatformHideMouseCursor( void )
void _glfwPlatformHideMouseCursor(_GLFWwindow* window)
{
[NSCursor hide];
CGAssociateMouseAndMouseCursorPosition(false);
@ -847,7 +842,7 @@ void _glfwPlatformHideMouseCursor( void )
// Show mouse cursor (unlock it)
//========================================================================
void _glfwPlatformShowMouseCursor( void )
void _glfwPlatformShowMouseCursor(_GLFWwindow* window)
{
[NSCursor unhide];
CGAssociateMouseAndMouseCursorPosition(true);
@ -857,7 +852,7 @@ void _glfwPlatformShowMouseCursor( void )
// Set physical mouse cursor position
//========================================================================
void _glfwPlatformSetMouseCursorPos( int x, int y )
void _glfwPlatformSetMouseCursorPos(_GLFWwindow* window, int x, int y)
{
// The library seems to assume that after calling this the mouse won't move,
// but obviously it will, and escape the app's window, and activate other apps,
@ -876,7 +871,7 @@ void _glfwPlatformSetMouseCursorPos( int x, int y )
CGSetLocalEventsSuppressionInterval( 0.0 );
NSPoint localPoint = NSMakePoint( x, y );
NSPoint globalPoint = [_glfwWin.window convertBaseToScreen:localPoint];
NSPoint globalPoint = [window->NS.window convertBaseToScreen:localPoint];
CGPoint mainScreenOrigin = CGDisplayBounds( CGMainDisplayID() ).origin;
double mainScreenHeight = CGDisplayBounds( CGMainDisplayID() ).size.height;
CGPoint targetPoint = CGPointMake( globalPoint.x - mainScreenOrigin.x,

View File

@ -31,6 +31,9 @@
#define _platform_h_
#include <stdint.h>
// This is the Mac OS X version of GLFW
#define _GLFW_MAC_OS_X
@ -40,7 +43,7 @@
typedef void* id;
#endif
#include "../../include/GL/glfw.h"
#include "../../include/GL/glfw3.h"
#ifndef GL_VERSION_3_0
@ -50,6 +53,11 @@ typedef const GLubyte * (APIENTRY *PFNGLGETSTRINGIPROC) (GLenum, GLuint);
#endif /*GL_VERSION_3_0*/
#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowNS NS
#define _GLFW_PLATFORM_LIBRARY_STATE _GLFWlibraryNS NS
#define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextNSGL NSGL
//========================================================================
// GLFW platform specific types
//========================================================================
@ -60,127 +68,47 @@ typedef const GLubyte * (APIENTRY *PFNGLGETSTRINGIPROC) (GLenum, GLuint);
typedef intptr_t GLFWintptr;
//------------------------------------------------------------------------
// Window structure
// Platform-specific OpenGL context structure
//------------------------------------------------------------------------
typedef struct _GLFWwin_struct _GLFWwin;
struct _GLFWwin_struct {
// ========= PLATFORM INDEPENDENT MANDATORY PART =========================
// User callback functions
GLFWwindowsizefun windowSizeCallback;
GLFWwindowclosefun windowCloseCallback;
GLFWwindowrefreshfun windowRefreshCallback;
GLFWmousebuttonfun mouseButtonCallback;
GLFWmouseposfun mousePosCallback;
GLFWmousewheelfun mouseWheelCallback;
GLFWkeyfun keyCallback;
GLFWcharfun charCallback;
// User selected window settings
int fullscreen; // Fullscreen flag
int mouseLock; // Mouse-lock flag
int sysKeysDisabled; // System keys disabled flag
int windowNoResize; // Resize- and maximize gadgets disabled flag
int refreshRate; // Vertical monitor refresh rate
// Window status & parameters
int opened; // Flag telling if window is opened or not
int active; // Application active flag
int iconified; // Window iconified flag
int width, height; // Window width and heigth
int accelerated; // GL_TRUE if window is HW accelerated
// Framebuffer attributes
int redBits;
int greenBits;
int blueBits;
int alphaBits;
int depthBits;
int stencilBits;
int accumRedBits;
int accumGreenBits;
int accumBlueBits;
int accumAlphaBits;
int auxBuffers;
int stereo;
int samples;
// OpenGL extensions and context attributes
int glMajor, glMinor, glRevision;
int glForward, glDebug, glProfile;
PFNGLGETSTRINGIPROC GetStringi;
// ========= PLATFORM SPECIFIC PART ======================================
id window;
typedef struct _GLFWcontextNSGL
{
id pixelFormat;
id context;
} _GLFWcontextNSGL;
//------------------------------------------------------------------------
// Platform-specific window structure
//------------------------------------------------------------------------
typedef struct _GLFWwindowNS
{
id window;
id delegate;
unsigned int modifierFlags;
};
GLFWGLOBAL _GLFWwin _glfwWin;
double wheelPosFloating;
} _GLFWwindowNS;
//------------------------------------------------------------------------
// Library global data
// Platform-specific library global data
//------------------------------------------------------------------------
GLFWGLOBAL struct {
// ========= PLATFORM INDEPENDENT MANDATORY PART =========================
// Window opening hints
_GLFWhints hints;
// ========= PLATFORM SPECIFIC PART ======================================
typedef struct _GLFWlibraryNS
{
// Timer data
struct {
double t0;
} Timer;
} timer;
// dlopen handle for dynamically-loading extension function pointers
void* OpenGLFramework;
int Unbundled;
int unbundled;
id DesktopMode;
id desktopMode;
id AutoreleasePool;
id autoreleasePool;
} _glfwLibrary;
//------------------------------------------------------------------------
// User input status (some of this should go in _GLFWwin)
//------------------------------------------------------------------------
GLFWGLOBAL struct {
// ========= PLATFORM INDEPENDENT MANDATORY PART =========================
// Mouse status
int MousePosX, MousePosY;
int WheelPos;
char MouseButton[ GLFW_MOUSE_BUTTON_LAST+1 ];
// Keyboard status
char Key[ GLFW_KEY_LAST+1 ];
int LastChar;
// User selected settings
int StickyKeys;
int StickyMouseButtons;
int KeyRepeat;
// ========= PLATFORM SPECIFIC PART ======================================
double WheelPosFloating;
} _glfwInput;
} _GLFWlibraryNS;
#endif // _platform_h_