Commit 26eb8e74 authored by Camilla Berglund's avatar Camilla Berglund
Browse files

Converted Cocoa port to new API.

parent 855b386e
......@@ -3,10 +3,9 @@ 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
${GLFW_INCLUDE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/src
${GLFW_INCLUDE_DIR})
set(cocoa_SOURCES
cocoa_enable.m
......
......@@ -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é
......
......@@ -33,7 +33,7 @@
// Check whether the display mode should be included in enumeration
//========================================================================
static BOOL modeIsGood( NSDictionary *mode )
static BOOL modeIsGood(NSDictionary* mode)
{
// This is a bit controversial, if you've got something other than an
// LCD computer monitor as an output device you might not want these
......@@ -50,7 +50,7 @@ static BOOL modeIsGood( NSDictionary *mode )
// Convert Core Graphics display mode to GLFW video mode
//========================================================================
static GLFWvidmode vidmodeFromCGDisplayMode( NSDictionary *mode )
static GLFWvidmode vidmodeFromCGDisplayMode(NSDictionary* mode)
{
unsigned int width = [[mode objectForKey:(id)kCGDisplayWidth] unsignedIntValue];
unsigned int height = [[mode objectForKey:(id)kCGDisplayHeight] unsignedIntValue];
......@@ -74,18 +74,16 @@ static GLFWvidmode vidmodeFromCGDisplayMode( NSDictionary *mode )
// Get a list of available video modes
//========================================================================
int _glfwPlatformGetVideoModes( GLFWvidmode *list, int maxcount )
int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
{
NSArray *modes = (NSArray *)CGDisplayAvailableModes( CGMainDisplayID() );
NSArray* modes = (NSArray*) CGDisplayAvailableModes(CGMainDisplayID());
unsigned int i, j = 0, n = [modes count];
for( i = 0; i < n && i < (unsigned)maxcount; i++ )
for (i = 0; i < n && i < (unsigned)maxcount; i++)
{
NSDictionary *mode = [modes objectAtIndex:i];
if( modeIsGood( mode ) )
{
list[j++] = vidmodeFromCGDisplayMode( mode );
}
if (modeIsGood(mode))
list[j++] = vidmodeFromCGDisplayMode(mode);
}
return j;
......@@ -95,8 +93,8 @@ int _glfwPlatformGetVideoModes( GLFWvidmode *list, int maxcount )
// Get the desktop video mode
//========================================================================
void _glfwPlatformGetDesktopMode( GLFWvidmode *mode )
void _glfwPlatformGetDesktopMode(GLFWvidmode *mode)
{
*mode = vidmodeFromCGDisplayMode( _glfwLibrary.DesktopMode );
*mode = vidmodeFromCGDisplayMode(_glfwLibrary.NS.desktopMode);
}
......@@ -37,7 +37,7 @@
// Check if an OpenGL extension is available at runtime
//========================================================================
int _glfwPlatformExtensionSupported( const char *extension )
int _glfwPlatformExtensionSupported(const char* extension)
{
// There are no AGL, CGL or NSGL extensions.
return GL_FALSE;
......@@ -47,16 +47,16 @@ int _glfwPlatformExtensionSupported( const char *extension )
// Get the function pointer to an OpenGL function
//========================================================================
void * _glfwPlatformGetProcAddress( const char *procname )
void* _glfwPlatformGetProcAddress(const char* procname)
{
CFStringRef symbolName = CFStringCreateWithCString( kCFAllocatorDefault,
procname,
kCFStringEncodingASCII );
CFStringRef symbolName = CFStringCreateWithCString(kCFAllocatorDefault,
procname,
kCFStringEncodingASCII);
void *symbol = CFBundleGetFunctionPointerForName( _glfwLibrary.OpenGLFramework,
symbolName );
void* symbol = CFBundleGetFunctionPointerForName(_glfwLibrary.NS.OpenGLFramework,
symbolName);
CFRelease( symbolName );
CFRelease(symbolName);
return symbol;
}
......
......@@ -42,14 +42,10 @@
// down the command key don't get sent to the key window.
- (void)sendEvent:(NSEvent *)event
{
if( [event type] == NSKeyUp && ( [event modifierFlags] & NSCommandKeyMask ) )
{
if ([event type] == NSKeyUp && ([event modifierFlags] & NSCommandKeyMask))
[[self keyWindow] sendEvent:event];
}
else
{
[super sendEvent:event];
}
}
@end
......@@ -58,11 +54,11 @@
// to get the application menu working properly. Need to be careful in
// case it goes away in a future OS update.
@interface NSApplication (NSAppleMenu)
- (void)setAppleMenu:(NSMenu *)m;
- (void)setAppleMenu:(NSMenu*)m;
@end
// Keys to search for as potential application names
NSString *GLFWNameKeys[] =
NSString* GLFWNameKeys[] =
{
@"CFBundleDisplayName",
@"CFBundleName",
......@@ -72,12 +68,12 @@ NSString *GLFWNameKeys[] =
//========================================================================
// Try to figure out what the calling application is called
//========================================================================
static NSString *findAppName( void )
static NSString* findAppName(void)
{
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
unsigned int i;
for( i = 0; i < sizeof(GLFWNameKeys) / sizeof(GLFWNameKeys[0]); i++ )
NSDictionary* infoDictionary = [[NSBundle mainBundle] infoDictionary];
for (i = 0; i < sizeof(GLFWNameKeys) / sizeof(GLFWNameKeys[0]); i++)
{
id name = [infoDictionary objectForKey:GLFWNameKeys[i]];
if (name &&
......@@ -89,22 +85,22 @@ 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...
ProcessSerialNumber psn = { 0, kCurrentProcess };
TransformProcessType( &psn, kProcessTransformToForegroundApplication );
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
// Having the app in front of the terminal window is also generally
// handy. There is an NSApplication API to do this, but...
SetFrontProcess( &psn );
SetFrontProcess(&psn);
_glfwLibrary.Unbundled = GL_TRUE;
_glfwLibrary.NS.unbundled = GL_TRUE;
}
char **progname = _NSGetProgname();
if( progname && *progname )
char** progname = _NSGetProgname();
if (progname && *progname)
{
// TODO: UTF8?
return [NSString stringWithUTF8String:*progname];
......@@ -178,17 +174,15 @@ static void setUpMenuBar( void )
// At least guard the call to private API to avoid an exception if it
// goes away. Hopefully that means the worst we'll break in future is to
// look ugly...
if( [NSApp respondsToSelector:@selector(setAppleMenu:)] )
{
if ([NSApp respondsToSelector:@selector(setAppleMenu:)])
[NSApp setAppleMenu:appMenu];
}
}
//========================================================================
// Terminate GLFW when exiting application
//========================================================================
static void glfw_atexit( void )
static void glfw_atexit(void)
{
glfwTerminate();
}
......@@ -202,19 +196,17 @@ static void glfw_atexit( void )
// Initialize the GLFW library
//========================================================================
int _glfwPlatformInit( void )
int _glfwPlatformInit(void)
{
_glfwLibrary.AutoreleasePool = [[NSAutoreleasePool alloc] init];
_glfwLibrary.NS.autoreleasePool = [[NSAutoreleasePool alloc] init];
// Implicitly create shared NSApplication instance
[GLFWApplication sharedApplication];
NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
if( access( [resourcePath cStringUsingEncoding:NSUTF8StringEncoding], R_OK ) == 0 )
{
chdir( [resourcePath cStringUsingEncoding:NSUTF8StringEncoding] );
}
if (access([resourcePath cStringUsingEncoding:NSUTF8StringEncoding], R_OK) == 0)
chdir([resourcePath cStringUsingEncoding:NSUTF8StringEncoding]);
// Setting up menu bar must go exactly here else weirdness ensues
setUpMenuBar();
......@@ -222,12 +214,12 @@ int _glfwPlatformInit( void )
[NSApp finishLaunching];
// Install atexit routine
atexit( glfw_atexit );
atexit(glfw_atexit);
_glfwPlatformSetTime( 0.0 );
_glfwPlatformSetTime(0.0);
_glfwLibrary.DesktopMode =
(NSDictionary *)CGDisplayCurrentMode( CGMainDisplayID() );
_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;
}
......@@ -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;
}
This diff is collapsed.
......@@ -31,25 +31,33 @@
#define _platform_h_
#include <stdint.h>
// This is the Mac OS X version of GLFW
#define _GLFW_MAC_OS_X
#if defined(__OBJC__)
#import <Cocoa/Cocoa.h>
#else
typedef void *id;
typedef void* id;
#endif
#include "../../include/GL/glfw.h"
#include "../../include/GL/glfw3.h"
#ifndef GL_VERSION_3_0
typedef const GLubyte * (APIENTRY *PFNGLGETSTRINGIPROC) (GLenum, GLuint);
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;
id pixelFormat;
id context;
id delegate;
unsigned int modifierFlags;
};
GLFWGLOBAL _GLFWwin _glfwWin;
typedef struct _GLFWcontextNSGL
{
id pixelFormat;
id context;
} _GLFWcontextNSGL;
//------------------------------------------------------------------------
// Library global data
// Platform-specific window structure
//------------------------------------------------------------------------
GLFWGLOBAL struct {
// ========= PLATFORM INDEPENDENT MANDATORY PART =========================
// Window opening hints
_GLFWhints hints;
typedef struct _GLFWwindowNS
{
id window;
id delegate;
unsigned int modifierFlags;
double wheelPosFloating;
} _GLFWwindowNS;
// ========= PLATFORM SPECIFIC PART ======================================
//------------------------------------------------------------------------
// Platform-specific library global data
//------------------------------------------------------------------------
typedef struct _GLFWlibraryNS
{
// Timer data
struct {
double t0;
} Timer;
} timer;
// dlopen handle for dynamically-loading extension function pointers
void *OpenGLFramework;
int Unbundled;
id DesktopMode;
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;
void* OpenGLFramework;
int unbundled;
// ========= PLATFORM SPECIFIC PART ======================================
id desktopMode;
double WheelPosFloating;
id autoreleasePool;
} _glfwInput;
} _GLFWlibraryNS;
#endif // _platform_h_
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment