mirror of
https://github.com/glfw/glfw.git
synced 2026-09-18 22:55:46 +00:00
Merge branch 'master' of github.com:raedwulf/glfw into clipboard
Conflicts: src/CMakeLists.txt tests/CMakeLists.txt
This commit is contained in:
+8
-29
@@ -1,16 +1,4 @@
|
||||
|
||||
if(CYGWIN)
|
||||
|
||||
# These lines are intended to remove the --export-all-symbols
|
||||
# flag added in the Modules/Platform/CYGWIN.cmake file of the
|
||||
# CMake distribution.
|
||||
# This is a HACK. If you have trouble _linking_ the GLFW
|
||||
# _shared_ library on Cygwin, try disabling this.
|
||||
set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared")
|
||||
set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS})
|
||||
|
||||
endif(CYGWIN)
|
||||
|
||||
if(UNIX)
|
||||
if(_GLFW_HAS_XRANDR)
|
||||
set(GLFW_PKGLIBS "${GLFW_PKGLIBS} xrandr")
|
||||
@@ -27,27 +15,25 @@ include_directories(${GLFW_SOURCE_DIR}/src
|
||||
${GLFW_BINARY_DIR}/src
|
||||
${GLFW_INCLUDE_DIR})
|
||||
|
||||
set(common_SOURCES clipboard.c enable.c error.c fullscreen.c gamma.c init.c input.c
|
||||
set(common_SOURCES clipboard.c error.c fullscreen.c gamma.c init.c input.c
|
||||
joystick.c opengl.c time.c window.c)
|
||||
|
||||
if(_GLFW_COCOA_NSGL)
|
||||
set(libglfw_SOURCES ${common_SOURCES} cocoa_clipboard.c
|
||||
cocoa_enable.m cocoa_fullscreen.m
|
||||
cocoa_gamma.m cocoa_init.m cocoa_joystick.m
|
||||
set(libglfw_SOURCES ${common_SOURCES} cocoa_clipboard.m
|
||||
cocoa_fullscreen.m cocoa_gamma.m
|
||||
cocoa_init.m cocoa_input.m cocoa_joystick.m
|
||||
cocoa_opengl.m cocoa_time.m cocoa_window.m)
|
||||
|
||||
# For some reason, CMake doesn't know about .m
|
||||
set_source_files_properties(${libglfw_SOURCES} PROPERTIES LANGUAGE C)
|
||||
elseif(_GLFW_WIN32_WGL)
|
||||
set(libglfw_SOURCES ${common_SOURCES} win32_clipboard.c
|
||||
win32_enable.c win32_fullscreen.c
|
||||
win32_gamma.c win32_init.c win32_joystick.c
|
||||
set(libglfw_SOURCES ${common_SOURCES} win32_clipboard.c win32_fullscreen.c
|
||||
win32_gamma.c win32_init.c win32_input.c win32_joystick.c
|
||||
win32_opengl.c win32_time.c win32_window.c
|
||||
win32_dllmain.c)
|
||||
elseif(_GLFW_X11_GLX)
|
||||
set(libglfw_SOURCES ${common_SOURCES} x11_clipboard.c
|
||||
x11_enable.c x11_fullscreen.c
|
||||
x11_gamma.c x11_init.c x11_joystick.c
|
||||
set(libglfw_SOURCES ${common_SOURCES} x11_clipboard.c x11_fullscreen.c
|
||||
x11_gamma.c x11_init.c x11_input.c x11_joystick.c
|
||||
x11_keysym2unicode.c x11_opengl.c x11_time.c
|
||||
x11_window.c)
|
||||
else()
|
||||
@@ -70,13 +56,6 @@ if(WIN32)
|
||||
IMPORT_SUFFIX "dll.lib")
|
||||
endif(WIN32)
|
||||
|
||||
if(CYGWIN)
|
||||
# Build for the regular Win32 environment (not Cygwin)
|
||||
set_target_properties(libglfwStatic libglfwShared PROPERTIES
|
||||
COMPILE_FLAGS "-mwin32 -mno-cygwin"
|
||||
LINK_FLAGS "-mwin32 -mno-cygwin")
|
||||
endif(CYGWIN)
|
||||
|
||||
if(APPLE)
|
||||
# Append -fno-common to the compile flags to work around a bug in the Apple GCC
|
||||
get_target_property(CFLAGS libglfwShared COMPILE_FLAGS)
|
||||
|
||||
+5
-8
@@ -48,13 +48,11 @@ void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp)
|
||||
CGGammaValue red[GLFW_GAMMA_RAMP_SIZE];
|
||||
CGGammaValue green[GLFW_GAMMA_RAMP_SIZE];
|
||||
CGGammaValue blue[GLFW_GAMMA_RAMP_SIZE];
|
||||
|
||||
|
||||
// For now, don't support anything that is not GLFW_GAMMA_RAMP_SIZE
|
||||
// i.e. 256. I don't think anyone would want to change the gamma on
|
||||
// Mac anyway...
|
||||
if (_glfwLibrary.originalRampSize != GLFW_GAMMA_RAMP_SIZE)
|
||||
return;
|
||||
|
||||
|
||||
CGGetDisplayTransferByTable(CGMainDisplayID(), GLFW_GAMMA_RAMP_SIZE, red, green, blue,
|
||||
&sampleCount);
|
||||
|
||||
@@ -78,13 +76,11 @@ void _glfwPlatformSetGammaRamp(const GLFWgammaramp* ramp)
|
||||
CGGammaValue red[GLFW_GAMMA_RAMP_SIZE];
|
||||
CGGammaValue green[GLFW_GAMMA_RAMP_SIZE];
|
||||
CGGammaValue blue[GLFW_GAMMA_RAMP_SIZE];
|
||||
|
||||
|
||||
// For now, don't support anything that is not GLFW_GAMMA_RAMP_SIZE
|
||||
// i.e. 256. I don't think anyone would want to change the gamma on
|
||||
// Mac anyway...
|
||||
if (_glfwLibrary.originalRampSize != GLFW_GAMMA_RAMP_SIZE)
|
||||
return;
|
||||
|
||||
|
||||
// Convert to float & take the difference of the original gamma and
|
||||
// the linear function.
|
||||
for (i = 0; i < size; i++)
|
||||
@@ -93,6 +89,7 @@ void _glfwPlatformSetGammaRamp(const GLFWgammaramp* ramp)
|
||||
green[i] = ramp->green[i] / 65535.f;
|
||||
blue[i] = ramp->blue[i] / 65535.f;
|
||||
}
|
||||
|
||||
CGSetDisplayTransferByTable(CGMainDisplayID(), GLFW_GAMMA_RAMP_SIZE, red, green, blue);
|
||||
}
|
||||
|
||||
|
||||
+36
-24
@@ -72,6 +72,18 @@ NSString* GLFWNameKeys[] =
|
||||
};
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Change to our application bundle's resources directory, if present
|
||||
//========================================================================
|
||||
static void changeToResourcesDirectory(void)
|
||||
{
|
||||
char* resourcePath = [[[NSBundle mainBundle] resourcePath] UTF8String];
|
||||
|
||||
if (access(resourcePath, R_OK) == 0)
|
||||
chdir(resourcePath);
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Try to figure out what the calling application is called
|
||||
//========================================================================
|
||||
@@ -87,29 +99,23 @@ static NSString* findAppName(void)
|
||||
[name isKindOfClass:[NSString class]] &&
|
||||
![@"" isEqualToString:name])
|
||||
{
|
||||
_glfwLibrary.NS.bundled = GL_TRUE;
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
// If we get here, we're 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);
|
||||
ProcessSerialNumber psn = { 0, kCurrentProcess };
|
||||
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);
|
||||
|
||||
_glfwLibrary.NS.unbundled = GL_TRUE;
|
||||
}
|
||||
// Having the app in front of the terminal window is also generally
|
||||
// handy. There is an NSApplication API to do this, but...
|
||||
SetFrontProcess(&psn);
|
||||
|
||||
char** progname = _NSGetProgname();
|
||||
if (progname && *progname)
|
||||
{
|
||||
// TODO: UTF8?
|
||||
// TODO: UTF-8?
|
||||
return [NSString stringWithUTF8String:*progname];
|
||||
}
|
||||
|
||||
@@ -202,7 +208,7 @@ int _glfwPlatformInit(void)
|
||||
[GLFWApplication sharedApplication];
|
||||
|
||||
_glfwLibrary.NS.OpenGLFramework =
|
||||
CFBundleGetBundleWithIdentifier( CFSTR( "com.apple.opengl" ) );
|
||||
CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl"));
|
||||
if (_glfwLibrary.NS.OpenGLFramework == NULL)
|
||||
{
|
||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||
@@ -210,16 +216,16 @@ int _glfwPlatformInit(void)
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
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
|
||||
// Setting up the menu bar must go between sharedApplication
|
||||
// above and finishLaunching below, in order to properly emulate the
|
||||
// behavior of NSApplicationMain
|
||||
setUpMenuBar();
|
||||
|
||||
[NSApp finishLaunching];
|
||||
|
||||
if (_glfwLibrary.NS.bundled)
|
||||
changeToResourcesDirectory();
|
||||
|
||||
_glfwPlatformSetTime(0.0);
|
||||
|
||||
_glfwLibrary.NS.desktopMode =
|
||||
@@ -229,7 +235,11 @@ int _glfwPlatformInit(void)
|
||||
_glfwLibrary.originalRampSize = CGDisplayGammaTableCapacity(CGMainDisplayID());
|
||||
_glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp);
|
||||
_glfwLibrary.currentRamp = _glfwLibrary.originalRamp;
|
||||
|
||||
|
||||
_glfwInitTimer();
|
||||
|
||||
_glfwInitJoysticks();
|
||||
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
@@ -240,10 +250,10 @@ int _glfwPlatformInit(void)
|
||||
int _glfwPlatformTerminate(void)
|
||||
{
|
||||
// TODO: Probably other cleanup
|
||||
|
||||
|
||||
// Restore the original gamma ramp
|
||||
_glfwPlatformSetGammaRamp(&_glfwLibrary.originalRamp);
|
||||
|
||||
|
||||
[NSApp setDelegate:nil];
|
||||
[_glfwLibrary.NS.delegate release];
|
||||
_glfwLibrary.NS.delegate = nil;
|
||||
@@ -251,6 +261,8 @@ int _glfwPlatformTerminate(void)
|
||||
[_glfwLibrary.NS.autoreleasePool release];
|
||||
_glfwLibrary.NS.autoreleasePool = nil;
|
||||
|
||||
_glfwTerminateJoysticks();
|
||||
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
@@ -261,7 +273,7 @@ int _glfwPlatformTerminate(void)
|
||||
|
||||
const char* _glfwPlatformGetVersionString(void)
|
||||
{
|
||||
const char* version = "GLFW " _GLFW_VERSION_FULL " Cocoa";
|
||||
const char* version = _GLFW_VERSION_FULL " Cocoa";
|
||||
|
||||
return version;
|
||||
}
|
||||
|
||||
+525
-9
@@ -29,6 +29,440 @@
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <mach/mach.h>
|
||||
#include <mach/mach_error.h>
|
||||
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include <IOKit/IOKitLib.h>
|
||||
#include <IOKit/IOCFPlugIn.h>
|
||||
#include <IOKit/hid/IOHIDLib.h>
|
||||
#include <IOKit/hid/IOHIDKeys.h>
|
||||
#include <Kernel/IOKit/hidsystem/IOHIDUsageTables.h>
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Joystick element information
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
typedef struct
|
||||
{
|
||||
IOHIDElementCookie cookie;
|
||||
|
||||
long value;
|
||||
|
||||
long min;
|
||||
long max;
|
||||
|
||||
long minReport;
|
||||
long maxReport;
|
||||
|
||||
} _glfwJoystickElement;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Joystick information & state
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int present;
|
||||
char product[256];
|
||||
|
||||
IOHIDDeviceInterface** interface;
|
||||
|
||||
int numAxes;
|
||||
int numButtons;
|
||||
int numHats;
|
||||
|
||||
CFMutableArrayRef axes;
|
||||
CFMutableArrayRef buttons;
|
||||
CFMutableArrayRef hats;
|
||||
|
||||
} _glfwJoystick;
|
||||
|
||||
static _glfwJoystick _glfwJoysticks[GLFW_JOYSTICK_LAST + 1];
|
||||
|
||||
|
||||
void GetElementsCFArrayHandler(const void* value, void* parameter);
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Adds an element to the specified joystick
|
||||
//========================================================================
|
||||
|
||||
static void addJoystickElement(_glfwJoystick* joystick, CFTypeRef refElement)
|
||||
{
|
||||
long elementType, usagePage, usage;
|
||||
CFTypeRef refElementType, refUsagePage, refUsage;
|
||||
|
||||
refElementType = CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementTypeKey));
|
||||
refUsagePage = CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementUsagePageKey));
|
||||
refUsage = CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementUsageKey));
|
||||
|
||||
CFMutableArrayRef elementsArray = NULL;
|
||||
|
||||
CFNumberGetValue(refElementType, kCFNumberLongType, &elementType);
|
||||
CFNumberGetValue(refUsagePage, kCFNumberLongType, &usagePage);
|
||||
CFNumberGetValue(refUsage, kCFNumberLongType, &usage);
|
||||
|
||||
if ((elementType == kIOHIDElementTypeInput_Axis) ||
|
||||
(elementType == kIOHIDElementTypeInput_Button) ||
|
||||
(elementType == kIOHIDElementTypeInput_Misc))
|
||||
{
|
||||
switch (usagePage) /* only interested in kHIDPage_GenericDesktop and kHIDPage_Button */
|
||||
{
|
||||
case kHIDPage_GenericDesktop:
|
||||
{
|
||||
switch (usage)
|
||||
{
|
||||
case kHIDUsage_GD_X:
|
||||
case kHIDUsage_GD_Y:
|
||||
case kHIDUsage_GD_Z:
|
||||
case kHIDUsage_GD_Rx:
|
||||
case kHIDUsage_GD_Ry:
|
||||
case kHIDUsage_GD_Rz:
|
||||
case kHIDUsage_GD_Slider:
|
||||
case kHIDUsage_GD_Dial:
|
||||
case kHIDUsage_GD_Wheel:
|
||||
joystick->numAxes++;
|
||||
elementsArray = joystick->axes;
|
||||
break;
|
||||
case kHIDUsage_GD_Hatswitch:
|
||||
joystick->numHats++;
|
||||
elementsArray = joystick->hats;
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case kHIDPage_Button:
|
||||
joystick->numButtons++;
|
||||
elementsArray = joystick->buttons;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (elementsArray)
|
||||
{
|
||||
long number;
|
||||
CFTypeRef refType;
|
||||
|
||||
_glfwJoystickElement* element = (_glfwJoystickElement*) malloc(sizeof(_glfwJoystickElement));
|
||||
|
||||
CFArrayAppendValue(elementsArray, element);
|
||||
|
||||
refType = CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementCookieKey));
|
||||
if (refType && CFNumberGetValue(refType, kCFNumberLongType, &number))
|
||||
element->cookie = (IOHIDElementCookie) number;
|
||||
|
||||
refType = CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementMinKey));
|
||||
if (refType && CFNumberGetValue(refType, kCFNumberLongType, &number))
|
||||
element->minReport = element->min = number;
|
||||
|
||||
refType = CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementMaxKey));
|
||||
if (refType && CFNumberGetValue(refType, kCFNumberLongType, &number))
|
||||
element->maxReport = element->max = number;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CFTypeRef refElementTop = CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementKey));
|
||||
if (refElementTop)
|
||||
{
|
||||
CFTypeID type = CFGetTypeID (refElementTop);
|
||||
if (type == CFArrayGetTypeID()) /* if element is an array */
|
||||
{
|
||||
CFRange range = {0, CFArrayGetCount (refElementTop)};
|
||||
CFArrayApplyFunction(refElementTop, range, GetElementsCFArrayHandler, joystick);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Adds an element to the specified joystick
|
||||
//========================================================================
|
||||
|
||||
void GetElementsCFArrayHandler(const void* value, void* parameter)
|
||||
{
|
||||
if (CFGetTypeID(value) == CFDictionaryGetTypeID())
|
||||
addJoystickElement((_glfwJoystick*) parameter, (CFTypeRef) value);
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Returns the value of the specified element of the specified joystick
|
||||
//========================================================================
|
||||
|
||||
static long getElementValue(_glfwJoystick* joystick, _glfwJoystickElement* element)
|
||||
{
|
||||
IOReturn result = kIOReturnSuccess;
|
||||
IOHIDEventStruct hidEvent;
|
||||
hidEvent.value = 0;
|
||||
|
||||
if (joystick && element && joystick->interface)
|
||||
{
|
||||
result = (*(joystick->interface))->getElementValue(joystick->interface,
|
||||
element->cookie,
|
||||
&hidEvent);
|
||||
if (kIOReturnSuccess == result)
|
||||
{
|
||||
/* record min and max for auto calibration */
|
||||
if (hidEvent.value < element->minReport)
|
||||
element->minReport = hidEvent.value;
|
||||
if (hidEvent.value > element->maxReport)
|
||||
element->maxReport = hidEvent.value;
|
||||
}
|
||||
}
|
||||
|
||||
/* auto user scale */
|
||||
return (long) hidEvent.value;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Removes the specified joystick
|
||||
//========================================================================
|
||||
|
||||
static void removeJoystick(_glfwJoystick* joystick)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (joystick->present)
|
||||
{
|
||||
joystick->present = GL_FALSE;
|
||||
|
||||
for (i = 0; i < joystick->numAxes; i++)
|
||||
{
|
||||
_glfwJoystickElement* axes =
|
||||
(_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->axes, i);
|
||||
free(axes);
|
||||
}
|
||||
CFArrayRemoveAllValues(joystick->axes);
|
||||
joystick->numAxes = 0;
|
||||
|
||||
for (i = 0; i < joystick->numButtons; i++)
|
||||
{
|
||||
_glfwJoystickElement* button =
|
||||
(_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->buttons, i);
|
||||
free(button);
|
||||
}
|
||||
CFArrayRemoveAllValues(joystick->buttons);
|
||||
joystick->numButtons = 0;
|
||||
|
||||
for (i = 0; i < joystick->numHats; i++)
|
||||
{
|
||||
_glfwJoystickElement* hat =
|
||||
(_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->hats, i);
|
||||
free(hat);
|
||||
}
|
||||
CFArrayRemoveAllValues(joystick->hats);
|
||||
joystick->hats = 0;
|
||||
|
||||
(*(joystick->interface))->close(joystick->interface);
|
||||
(*(joystick->interface))->Release(joystick->interface);
|
||||
|
||||
joystick->interface = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Callback for user-initiated joystick removal
|
||||
//========================================================================
|
||||
|
||||
static void removalCallback(void* target, IOReturn result, void* refcon, void* sender)
|
||||
{
|
||||
removeJoystick((_glfwJoystick*) refcon);
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Polls for joystick events and updates GFLW state
|
||||
//========================================================================
|
||||
|
||||
static void pollJoystickEvents(void)
|
||||
{
|
||||
int i;
|
||||
CFIndex j;
|
||||
|
||||
for (i = 0; i < GLFW_JOYSTICK_LAST + 1; i++)
|
||||
{
|
||||
_glfwJoystick* joystick = &_glfwJoysticks[i];
|
||||
|
||||
if (joystick->present)
|
||||
{
|
||||
for (j = 0; j < joystick->numButtons; j++)
|
||||
{
|
||||
_glfwJoystickElement* button =
|
||||
(_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->buttons, j);
|
||||
button->value = getElementValue(joystick, button);
|
||||
}
|
||||
|
||||
for (j = 0; j < joystick->numAxes; j++)
|
||||
{
|
||||
_glfwJoystickElement* axes =
|
||||
(_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->axes, j);
|
||||
axes->value = getElementValue(joystick, axes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW internal API //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//========================================================================
|
||||
// Initialize joystick interface
|
||||
//========================================================================
|
||||
|
||||
void _glfwInitJoysticks(void)
|
||||
{
|
||||
int deviceCounter = 0;
|
||||
IOReturn result = kIOReturnSuccess;
|
||||
mach_port_t masterPort = 0;
|
||||
io_iterator_t objectIterator = 0;
|
||||
CFMutableDictionaryRef hidMatchDictionary = NULL;
|
||||
io_object_t ioHIDDeviceObject = 0;
|
||||
|
||||
result = IOMasterPort(bootstrap_port, &masterPort);
|
||||
hidMatchDictionary = IOServiceMatching(kIOHIDDeviceKey);
|
||||
if (kIOReturnSuccess != result || !hidMatchDictionary)
|
||||
return;
|
||||
|
||||
result = IOServiceGetMatchingServices(masterPort,
|
||||
hidMatchDictionary,
|
||||
&objectIterator);
|
||||
if (result != kIOReturnSuccess)
|
||||
return;
|
||||
|
||||
if (!objectIterator) /* there are no joysticks */
|
||||
return;
|
||||
|
||||
while ((ioHIDDeviceObject = IOIteratorNext(objectIterator)))
|
||||
{
|
||||
CFMutableDictionaryRef hidProperties = 0;
|
||||
kern_return_t result;
|
||||
CFTypeRef refCF = 0;
|
||||
|
||||
IOCFPlugInInterface** ppPlugInInterface = NULL;
|
||||
HRESULT plugInResult = S_OK;
|
||||
SInt32 score = 0;
|
||||
|
||||
long usagePage, usage;
|
||||
|
||||
result = IORegistryEntryCreateCFProperties(ioHIDDeviceObject,
|
||||
&hidProperties,
|
||||
kCFAllocatorDefault,
|
||||
kNilOptions);
|
||||
|
||||
if (result != kIOReturnSuccess)
|
||||
continue;
|
||||
|
||||
/* Check device type */
|
||||
refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDPrimaryUsagePageKey));
|
||||
if (refCF)
|
||||
CFNumberGetValue(refCF, kCFNumberLongType, &usagePage);
|
||||
|
||||
refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDPrimaryUsageKey));
|
||||
if (refCF)
|
||||
CFNumberGetValue(refCF, kCFNumberLongType, &usage);
|
||||
|
||||
if ((usagePage != kHIDPage_GenericDesktop) ||
|
||||
(usage != kHIDUsage_GD_Joystick &&
|
||||
usage != kHIDUsage_GD_GamePad &&
|
||||
usage != kHIDUsage_GD_MultiAxisController))
|
||||
{
|
||||
/* We don't interested in this device */
|
||||
continue;
|
||||
}
|
||||
|
||||
_glfwJoystick* joystick = &_glfwJoysticks[deviceCounter];
|
||||
|
||||
joystick->present = GL_TRUE;
|
||||
|
||||
result = IOCreatePlugInInterfaceForService(ioHIDDeviceObject,
|
||||
kIOHIDDeviceUserClientTypeID,
|
||||
kIOCFPlugInInterfaceID,
|
||||
&ppPlugInInterface,
|
||||
&score);
|
||||
|
||||
if (kIOReturnSuccess != result)
|
||||
return;
|
||||
|
||||
plugInResult = (*ppPlugInInterface)->QueryInterface(
|
||||
ppPlugInInterface,
|
||||
CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID),
|
||||
(void *) &(joystick->interface));
|
||||
|
||||
if (plugInResult != S_OK)
|
||||
return;
|
||||
|
||||
(*ppPlugInInterface)->Release(ppPlugInInterface);
|
||||
|
||||
(*(joystick->interface))->open(joystick->interface, 0);
|
||||
(*(joystick->interface))->setRemovalCallback(joystick->interface,
|
||||
removalCallback,
|
||||
joystick,
|
||||
joystick);
|
||||
|
||||
/* Get product string */
|
||||
refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDProductKey));
|
||||
if (refCF)
|
||||
{
|
||||
CFStringGetCString(refCF,
|
||||
(char*) &(joystick->product),
|
||||
256,
|
||||
CFStringGetSystemEncoding());
|
||||
}
|
||||
|
||||
joystick->numAxes = 0;
|
||||
joystick->numButtons = 0;
|
||||
joystick->numHats = 0;
|
||||
joystick->axes = CFArrayCreateMutable(NULL, 0, NULL);
|
||||
joystick->buttons = CFArrayCreateMutable(NULL, 0, NULL);
|
||||
joystick->hats = CFArrayCreateMutable(NULL, 0, NULL);
|
||||
|
||||
CFTypeRef refTopElement = CFDictionaryGetValue(hidProperties,
|
||||
CFSTR(kIOHIDElementKey));
|
||||
CFTypeID type = CFGetTypeID(refTopElement);
|
||||
if (type == CFArrayGetTypeID())
|
||||
{
|
||||
CFRange range = { 0, CFArrayGetCount(refTopElement) };
|
||||
CFArrayApplyFunction(refTopElement,
|
||||
range,
|
||||
GetElementsCFArrayHandler,
|
||||
(void*) joystick);
|
||||
}
|
||||
|
||||
deviceCounter++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Close all opened joystick handles
|
||||
//========================================================================
|
||||
|
||||
void _glfwTerminateJoysticks(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < GLFW_JOYSTICK_LAST + 1; i++)
|
||||
{
|
||||
_glfwJoystick* joystick = &_glfwJoysticks[i];
|
||||
removeJoystick(joystick);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW platform API //////
|
||||
@@ -38,29 +472,111 @@
|
||||
// Determine joystick capabilities
|
||||
//========================================================================
|
||||
|
||||
int _glfwPlatformGetJoystickParam( int joy, int param )
|
||||
int _glfwPlatformGetJoystickParam(int joy, int param)
|
||||
{
|
||||
// TODO: Implement this.
|
||||
return 0;
|
||||
if (!_glfwJoysticks[joy].present)
|
||||
{
|
||||
// TODO: Figure out if this is an error
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
switch (param)
|
||||
{
|
||||
case GLFW_PRESENT:
|
||||
return GL_TRUE;
|
||||
|
||||
case GLFW_AXES:
|
||||
return (int) CFArrayGetCount(_glfwJoysticks[joy].axes);
|
||||
|
||||
case GLFW_BUTTONS:
|
||||
return (int) CFArrayGetCount(_glfwJoysticks[joy].buttons);
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Get joystick axis positions
|
||||
//========================================================================
|
||||
|
||||
int _glfwPlatformGetJoystickPos( int joy, float *pos, int numaxes )
|
||||
int _glfwPlatformGetJoystickPos(int joy, float* pos, int numaxes)
|
||||
{
|
||||
// TODO: Implement this.
|
||||
return 0;
|
||||
int i;
|
||||
|
||||
if (joy < GLFW_JOYSTICK_1 || joy > GLFW_JOYSTICK_LAST)
|
||||
return 0;
|
||||
|
||||
_glfwJoystick joystick = _glfwJoysticks[joy];
|
||||
|
||||
if (!joystick.present)
|
||||
{
|
||||
// TODO: Figure out if this is an error
|
||||
return 0;
|
||||
}
|
||||
|
||||
numaxes = numaxes < joystick.numAxes ? numaxes : joystick.numAxes;
|
||||
|
||||
// Update joystick state
|
||||
pollJoystickEvents();
|
||||
|
||||
for (i = 0; i < numaxes; i++)
|
||||
{
|
||||
_glfwJoystickElement* axes =
|
||||
(_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick.axes, i);
|
||||
|
||||
long readScale = axes->maxReport - axes->minReport;
|
||||
|
||||
if (readScale == 0)
|
||||
pos[i] = axes->value;
|
||||
else
|
||||
pos[i] = (2.0f * (axes->value - axes->minReport) / readScale) - 1.0f;
|
||||
|
||||
//printf("%ld, %ld, %ld\n", axes->value, axes->minReport, axes->maxReport);
|
||||
|
||||
if (i & 1)
|
||||
pos[i] = -pos[i];
|
||||
}
|
||||
|
||||
return numaxes;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Get joystick button states
|
||||
//========================================================================
|
||||
|
||||
int _glfwPlatformGetJoystickButtons( int joy, unsigned char *buttons, int numbuttons )
|
||||
int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons,
|
||||
int numbuttons)
|
||||
{
|
||||
// TODO: Implement this.
|
||||
return 0;
|
||||
int i;
|
||||
|
||||
if (joy < GLFW_JOYSTICK_1 || joy > GLFW_JOYSTICK_LAST)
|
||||
return 0;
|
||||
|
||||
_glfwJoystick joystick = _glfwJoysticks[joy];
|
||||
|
||||
if (!joystick.present)
|
||||
{
|
||||
// TODO: Figure out if this is an error
|
||||
return 0;
|
||||
}
|
||||
|
||||
numbuttons = numbuttons < joystick.numButtons ? numbuttons : joystick.numButtons;
|
||||
|
||||
// Update joystick state
|
||||
pollJoystickEvents();
|
||||
|
||||
for (i = 0; i < numbuttons; i++)
|
||||
{
|
||||
_glfwJoystickElement* button = (_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick.buttons, i);
|
||||
buttons[i] = button->value ? GLFW_PRESS : GLFW_RELEASE;
|
||||
}
|
||||
|
||||
return numbuttons;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+15
-2
@@ -85,16 +85,29 @@ typedef struct _GLFWwindowNS
|
||||
typedef struct _GLFWlibraryNS
|
||||
{
|
||||
struct {
|
||||
double t0;
|
||||
double base;
|
||||
double resolution;
|
||||
} timer;
|
||||
|
||||
// dlopen handle for dynamically loading OpenGL extension entry points
|
||||
void* OpenGLFramework;
|
||||
GLboolean unbundled;
|
||||
GLboolean bundled;
|
||||
id desktopMode;
|
||||
id delegate;
|
||||
id autoreleasePool;
|
||||
} _GLFWlibraryNS;
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Prototypes for platform specific internal functions
|
||||
//========================================================================
|
||||
|
||||
// Time
|
||||
void _glfwInitTimer(void);
|
||||
|
||||
// Joystick input
|
||||
void _glfwInitJoysticks(void);
|
||||
void _glfwTerminateJoysticks(void);
|
||||
|
||||
|
||||
#endif // _platform_h_
|
||||
|
||||
+34
-4
@@ -29,6 +29,36 @@
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
#include <mach/mach_time.h>
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Return raw time
|
||||
//========================================================================
|
||||
|
||||
static uint64_t getRawTime(void)
|
||||
{
|
||||
return mach_absolute_time();
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW internal API //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//========================================================================
|
||||
// Initialise timer
|
||||
//========================================================================
|
||||
|
||||
void _glfwInitTimer(void)
|
||||
{
|
||||
mach_timebase_info_data_t info;
|
||||
mach_timebase_info(&info);
|
||||
|
||||
_glfwLibrary.NS.timer.resolution = (double) info.numer / (info.denom * 1.0e9);
|
||||
_glfwLibrary.NS.timer.base = getRawTime();
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW platform API //////
|
||||
@@ -40,8 +70,8 @@
|
||||
|
||||
double _glfwPlatformGetTime(void)
|
||||
{
|
||||
return [NSDate timeIntervalSinceReferenceDate] -
|
||||
_glfwLibrary.NS.timer.t0;
|
||||
return (double) (getRawTime() - _glfwLibrary.NS.timer.base) *
|
||||
_glfwLibrary.NS.timer.resolution;
|
||||
}
|
||||
|
||||
//========================================================================
|
||||
@@ -50,7 +80,7 @@ double _glfwPlatformGetTime(void)
|
||||
|
||||
void _glfwPlatformSetTime(double time)
|
||||
{
|
||||
_glfwLibrary.NS.timer.t0 =
|
||||
[NSDate timeIntervalSinceReferenceDate] - time;
|
||||
_glfwLibrary.NS.timer.base = getRawTime() -
|
||||
(uint64_t) (time / _glfwLibrary.NS.timer.resolution);
|
||||
}
|
||||
|
||||
|
||||
+146
-117
@@ -147,7 +147,7 @@ static const unsigned int MAC_TO_GLFW_KEYCODE_MAPPING[128] =
|
||||
/* 07 */ GLFW_KEY_X,
|
||||
/* 08 */ GLFW_KEY_C,
|
||||
/* 09 */ GLFW_KEY_V,
|
||||
/* 0a */ -1,
|
||||
/* 0a */ GLFW_KEY_GRAVE_ACCENT,
|
||||
/* 0b */ GLFW_KEY_B,
|
||||
/* 0c */ GLFW_KEY_Q,
|
||||
/* 0d */ GLFW_KEY_W,
|
||||
@@ -187,7 +187,7 @@ static const unsigned int MAC_TO_GLFW_KEYCODE_MAPPING[128] =
|
||||
/* 2f */ GLFW_KEY_PERIOD,
|
||||
/* 30 */ GLFW_KEY_TAB,
|
||||
/* 31 */ GLFW_KEY_SPACE,
|
||||
/* 32 */ GLFW_KEY_GRAVE_ACCENT,
|
||||
/* 32 */ GLFW_KEY_WORLD_1,
|
||||
/* 33 */ GLFW_KEY_BACKSPACE,
|
||||
/* 34 */ -1,
|
||||
/* 35 */ GLFW_KEY_ESCAPE,
|
||||
@@ -393,7 +393,7 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
|
||||
if ([event modifierFlags] & NSCommandKeyMask)
|
||||
{
|
||||
if (!window->sysKeysDisabled)
|
||||
if (window->systemKeys)
|
||||
[super keyDown:event];
|
||||
}
|
||||
else
|
||||
@@ -443,20 +443,66 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
|
||||
@end
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW platform API //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//========================================================================
|
||||
// Here is where the window is created, and the OpenGL rendering context is
|
||||
// created
|
||||
// Create the Cocoa window
|
||||
//========================================================================
|
||||
|
||||
int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
||||
const _GLFWwndconfig *wndconfig,
|
||||
const _GLFWfbconfig *fbconfig)
|
||||
static GLboolean createWindow(_GLFWwindow* window,
|
||||
const _GLFWwndconfig* wndconfig)
|
||||
{
|
||||
unsigned int styleMask = 0;
|
||||
|
||||
if (wndconfig->mode == GLFW_WINDOWED)
|
||||
{
|
||||
styleMask = NSTitledWindowMask | NSClosableWindowMask |
|
||||
NSMiniaturizableWindowMask;
|
||||
|
||||
if (wndconfig->resizable)
|
||||
styleMask |= NSResizableWindowMask;
|
||||
}
|
||||
else
|
||||
styleMask = NSBorderlessWindowMask;
|
||||
|
||||
window->NS.window = [[NSWindow alloc]
|
||||
initWithContentRect:NSMakeRect(0, 0, window->width, window->height)
|
||||
styleMask:styleMask
|
||||
backing:NSBackingStoreBuffered
|
||||
defer:NO];
|
||||
|
||||
if (window->NS.window == nil)
|
||||
{
|
||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||
"Cocoa/NSOpenGL: Failed to create window");
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
[window->NS.window setTitle:[NSString stringWithUTF8String:wndconfig->title]];
|
||||
[window->NS.window setContentView:[[GLFWContentView alloc]
|
||||
initWithGlfwWindow:window]];
|
||||
[window->NS.window setDelegate:window->NS.delegate];
|
||||
[window->NS.window setAcceptsMouseMovedEvents:YES];
|
||||
[window->NS.window center];
|
||||
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
//========================================================================
|
||||
// Create the OpenGL context
|
||||
//========================================================================
|
||||
|
||||
static GLboolean createContext(_GLFWwindow* window,
|
||||
const _GLFWwndconfig* wndconfig,
|
||||
const _GLFWfbconfig* fbconfig)
|
||||
{
|
||||
unsigned int attributeCount = 0;
|
||||
|
||||
// Mac OS X needs non-zero color size, so set resonable values
|
||||
int colorBits = fbconfig->redBits + fbconfig->greenBits + fbconfig->blueBits;
|
||||
if (colorBits == 0)
|
||||
colorBits = 24;
|
||||
else if (colorBits < 15)
|
||||
colorBits = 15;
|
||||
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
|
||||
// Fail if any OpenGL version above 2.1 other than 3.2 was requested
|
||||
if (wndconfig->glMajor > 3 ||
|
||||
@@ -499,104 +545,7 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
// We can only have one application delegate, but we only allocate it the
|
||||
// first time we create a window to keep all window code in this file
|
||||
if (_glfwLibrary.NS.delegate == nil)
|
||||
{
|
||||
_glfwLibrary.NS.delegate = [[GLFWApplicationDelegate alloc] init];
|
||||
if (_glfwLibrary.NS.delegate == nil)
|
||||
{
|
||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||
"Cocoa/NSOpenGL: Failed to create application "
|
||||
"delegate");
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
[NSApp setDelegate:_glfwLibrary.NS.delegate];
|
||||
}
|
||||
|
||||
window->NS.delegate = [[GLFWWindowDelegate alloc] initWithGlfwWindow:window];
|
||||
if (window->NS.delegate == nil)
|
||||
{
|
||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||
"Cocoa/NSOpenGL: Failed to create window delegate");
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
// Mac OS X needs non-zero color size, so set resonable values
|
||||
int colorBits = fbconfig->redBits + fbconfig->greenBits + fbconfig->blueBits;
|
||||
if (colorBits == 0)
|
||||
colorBits = 24;
|
||||
else if (colorBits < 15)
|
||||
colorBits = 15;
|
||||
|
||||
// Ignored hints:
|
||||
// OpenGLMajor, OpenGLMinor, OpenGLForward:
|
||||
// pending Mac OS X support for OpenGL 3.x
|
||||
// OpenGLDebug
|
||||
// pending it meaning anything on Mac OS X
|
||||
|
||||
// Don't use accumulation buffer support; it's not accelerated
|
||||
// Aux buffers probably aren't accelerated either
|
||||
|
||||
CFDictionaryRef fullscreenMode = NULL;
|
||||
if (wndconfig->mode == GLFW_FULLSCREEN)
|
||||
{
|
||||
// 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,
|
||||
window->width, window->height,
|
||||
wndconfig->refreshRate,
|
||||
// Controversial, see macosx_fullscreen.m for discussion
|
||||
kCGDisplayModeIsSafeForHardware,
|
||||
NULL);
|
||||
|
||||
window->width =
|
||||
[[(id)fullscreenMode objectForKey:(id)kCGDisplayWidth] intValue];
|
||||
window->height =
|
||||
[[(id)fullscreenMode objectForKey:(id)kCGDisplayHeight] intValue];
|
||||
}
|
||||
|
||||
unsigned int styleMask = 0;
|
||||
|
||||
if (wndconfig->mode == GLFW_WINDOWED)
|
||||
{
|
||||
styleMask = NSTitledWindowMask | NSClosableWindowMask |
|
||||
NSMiniaturizableWindowMask;
|
||||
|
||||
if (!wndconfig->windowNoResize)
|
||||
styleMask |= NSResizableWindowMask;
|
||||
}
|
||||
else
|
||||
styleMask = NSBorderlessWindowMask;
|
||||
|
||||
window->NS.window = [[NSWindow alloc]
|
||||
initWithContentRect:NSMakeRect(0, 0, window->width, window->height)
|
||||
styleMask:styleMask
|
||||
backing:NSBackingStoreBuffered
|
||||
defer:NO];
|
||||
|
||||
[window->NS.window setTitle:[NSString stringWithCString:wndconfig->title
|
||||
encoding:NSISOLatin1StringEncoding]];
|
||||
|
||||
[window->NS.window setContentView:[[GLFWContentView alloc] initWithGlfwWindow:window]];
|
||||
[window->NS.window setDelegate:window->NS.delegate];
|
||||
[window->NS.window setAcceptsMouseMovedEvents:YES];
|
||||
[window->NS.window center];
|
||||
|
||||
if (wndconfig->mode == GLFW_FULLSCREEN)
|
||||
{
|
||||
CGCaptureAllDisplays();
|
||||
CGDisplaySwitchToMode(CGMainDisplayID(), fullscreenMode);
|
||||
}
|
||||
|
||||
unsigned int attribute_count = 0;
|
||||
|
||||
#define ADD_ATTR(x) { attributes[attribute_count++] = x; }
|
||||
#define ADD_ATTR(x) { attributes[attributeCount++] = x; }
|
||||
#define ADD_ATTR2(x, y) { ADD_ATTR(x); ADD_ATTR(y); }
|
||||
|
||||
// Arbitrary array size here
|
||||
@@ -638,7 +587,7 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
||||
ADD_ATTR2(NSOpenGLPFAAuxBuffers, fbconfig->auxBuffers);
|
||||
|
||||
if (fbconfig->stereo)
|
||||
ADD_ATTR(NSOpenGLPFAStereo );
|
||||
ADD_ATTR(NSOpenGLPFAStereo);
|
||||
|
||||
if (fbconfig->samples > 0)
|
||||
{
|
||||
@@ -656,7 +605,7 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
||||
if (window->NSGL.pixelFormat == nil)
|
||||
{
|
||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||
"Cocoa/NSOpenGL: Failed to create pixel format");
|
||||
"Cocoa/NSOpenGL: Failed to create OpenGL pixel format");
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
@@ -675,12 +624,93 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW platform API //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//========================================================================
|
||||
// Here is where the window is created, and the OpenGL rendering context is
|
||||
// created
|
||||
//========================================================================
|
||||
|
||||
int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
||||
const _GLFWwndconfig* wndconfig,
|
||||
const _GLFWfbconfig* fbconfig)
|
||||
{
|
||||
// We can only have one application delegate, but we only allocate it the
|
||||
// first time we create a window to keep all window code in this file
|
||||
if (_glfwLibrary.NS.delegate == nil)
|
||||
{
|
||||
_glfwLibrary.NS.delegate = [[GLFWApplicationDelegate alloc] init];
|
||||
if (_glfwLibrary.NS.delegate == nil)
|
||||
{
|
||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||
"Cocoa/NSOpenGL: Failed to create application "
|
||||
"delegate");
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
[NSApp setDelegate:_glfwLibrary.NS.delegate];
|
||||
}
|
||||
|
||||
window->NS.delegate = [[GLFWWindowDelegate alloc] initWithGlfwWindow:window];
|
||||
if (window->NS.delegate == nil)
|
||||
{
|
||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||
"Cocoa/NSOpenGL: Failed to create window delegate");
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
// Mac OS X needs non-zero color size, so set resonable values
|
||||
int colorBits = fbconfig->redBits + fbconfig->greenBits + fbconfig->blueBits;
|
||||
if (colorBits == 0)
|
||||
colorBits = 24;
|
||||
else if (colorBits < 15)
|
||||
colorBits = 15;
|
||||
|
||||
// Don't use accumulation buffer support; it's not accelerated
|
||||
// Aux buffers probably aren't accelerated either
|
||||
|
||||
CFDictionaryRef fullscreenMode = NULL;
|
||||
if (wndconfig->mode == GLFW_FULLSCREEN)
|
||||
{
|
||||
// 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,
|
||||
window->width, window->height,
|
||||
wndconfig->refreshRate,
|
||||
// Controversial, see macosx_fullscreen.m for discussion
|
||||
kCGDisplayModeIsSafeForHardware,
|
||||
NULL);
|
||||
|
||||
window->width =
|
||||
[[(id)fullscreenMode objectForKey:(id)kCGDisplayWidth] intValue];
|
||||
window->height =
|
||||
[[(id)fullscreenMode objectForKey:(id)kCGDisplayHeight] intValue];
|
||||
}
|
||||
|
||||
if (!createWindow(window, wndconfig))
|
||||
return GL_FALSE;
|
||||
|
||||
if (!createContext(window, wndconfig, fbconfig))
|
||||
return GL_FALSE;
|
||||
|
||||
[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
|
||||
CGCaptureAllDisplays();
|
||||
CGDisplaySwitchToMode(CGMainDisplayID(), fullscreenMode);
|
||||
|
||||
[[window->NS.window contentView] enterFullScreenMode:[NSScreen mainScreen]
|
||||
withOptions:nil];
|
||||
}
|
||||
@@ -691,7 +721,7 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
||||
window->cursorPosX = point.x;
|
||||
window->cursorPosY = point.y;
|
||||
|
||||
window->windowNoResize = wndconfig->windowNoResize;
|
||||
window->resizable = wndconfig->resizable;
|
||||
|
||||
return GL_TRUE;
|
||||
}
|
||||
@@ -737,8 +767,7 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window)
|
||||
|
||||
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char *title)
|
||||
{
|
||||
[window->NS.window setTitle:[NSString stringWithCString:title
|
||||
encoding:NSISOLatin1StringEncoding]];
|
||||
[window->NS.window setTitle:[NSString stringWithUTF8String:title]];
|
||||
}
|
||||
|
||||
//========================================================================
|
||||
|
||||
-192
@@ -1,192 +0,0 @@
|
||||
//========================================================================
|
||||
// GLFW - An OpenGL library
|
||||
// Platform: Any
|
||||
// API version: 3.0
|
||||
// WWW: http://www.glfw.org/
|
||||
//------------------------------------------------------------------------
|
||||
// Copyright (c) 2002-2006 Marcus Geelnard
|
||||
// Copyright (c) 2006-2010 Camilla Berglund <elmindreda@elmindreda.org>
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would
|
||||
// be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such, and must not
|
||||
// be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source
|
||||
// distribution.
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Enable and disable sticky keys mode
|
||||
//========================================================================
|
||||
|
||||
static void enableStickyKeys(_GLFWwindow* window)
|
||||
{
|
||||
window->stickyKeys = GL_TRUE;
|
||||
}
|
||||
|
||||
static void disableStickyKeys(_GLFWwindow* window)
|
||||
{
|
||||
int i;
|
||||
|
||||
window->stickyKeys = GL_FALSE;
|
||||
|
||||
// Release all sticky keys
|
||||
for (i = 0; i <= GLFW_KEY_LAST; i++)
|
||||
{
|
||||
if (window->key[i] == GLFW_STICK)
|
||||
window->key[i] = GLFW_RELEASE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Enable and disable sticky mouse buttons mode
|
||||
//========================================================================
|
||||
|
||||
static void enableStickyMouseButtons(_GLFWwindow* window)
|
||||
{
|
||||
window->stickyMouseButtons = GL_TRUE;
|
||||
}
|
||||
|
||||
static void disableStickyMouseButtons(_GLFWwindow* window)
|
||||
{
|
||||
int i;
|
||||
|
||||
window->stickyMouseButtons = GL_FALSE;
|
||||
|
||||
// Release all sticky mouse buttons
|
||||
for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++)
|
||||
{
|
||||
if (window->mouseButton[i] == GLFW_STICK)
|
||||
window->mouseButton[i] = GLFW_RELEASE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Enable and disable system keys
|
||||
//========================================================================
|
||||
|
||||
static void enableSystemKeys(_GLFWwindow* window)
|
||||
{
|
||||
if (!window->sysKeysDisabled)
|
||||
return;
|
||||
|
||||
_glfwPlatformEnableSystemKeys(window);
|
||||
|
||||
// Indicate that system keys are no longer disabled
|
||||
window->sysKeysDisabled = GL_FALSE;
|
||||
}
|
||||
|
||||
static void disableSystemKeys(_GLFWwindow* window)
|
||||
{
|
||||
if (window->sysKeysDisabled)
|
||||
return;
|
||||
|
||||
_glfwPlatformDisableSystemKeys(window);
|
||||
|
||||
// Indicate that system keys are now disabled
|
||||
window->sysKeysDisabled = GL_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Enable and disable key repeat
|
||||
//========================================================================
|
||||
|
||||
static void enableKeyRepeat(_GLFWwindow* window)
|
||||
{
|
||||
window->keyRepeat = GL_TRUE;
|
||||
}
|
||||
|
||||
static void disableKeyRepeat(_GLFWwindow* window)
|
||||
{
|
||||
window->keyRepeat = GL_FALSE;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW public API //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//========================================================================
|
||||
// Enable certain GLFW/window/system functions
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwEnable(GLFWwindow window, int token)
|
||||
{
|
||||
if (!_glfwInitialized)
|
||||
{
|
||||
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (token)
|
||||
{
|
||||
case GLFW_STICKY_KEYS:
|
||||
enableStickyKeys(window);
|
||||
break;
|
||||
case GLFW_STICKY_MOUSE_BUTTONS:
|
||||
enableStickyMouseButtons(window);
|
||||
break;
|
||||
case GLFW_SYSTEM_KEYS:
|
||||
enableSystemKeys(window);
|
||||
break;
|
||||
case GLFW_KEY_REPEAT:
|
||||
enableKeyRepeat(window);
|
||||
break;
|
||||
default:
|
||||
_glfwSetError(GLFW_INVALID_ENUM, NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Disable certain GLFW/window/system functions
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwDisable(GLFWwindow window, int token)
|
||||
{
|
||||
if (!_glfwInitialized)
|
||||
{
|
||||
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (token)
|
||||
{
|
||||
case GLFW_STICKY_KEYS:
|
||||
disableStickyKeys(window);
|
||||
break;
|
||||
case GLFW_STICKY_MOUSE_BUTTONS:
|
||||
disableStickyMouseButtons(window);
|
||||
break;
|
||||
case GLFW_SYSTEM_KEYS:
|
||||
disableSystemKeys(window);
|
||||
break;
|
||||
case GLFW_KEY_REPEAT:
|
||||
disableKeyRepeat(window);
|
||||
break;
|
||||
default:
|
||||
_glfwSetError(GLFW_INVALID_ENUM, NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,6 +117,7 @@ GLFWAPI const char* glfwErrorString(int error)
|
||||
|
||||
//========================================================================
|
||||
// Sets the callback function for GLFW errors
|
||||
// This function may be called without GLFW having been initialized
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwSetErrorCallback(GLFWerrorfun cbfun)
|
||||
|
||||
-55
@@ -35,30 +35,6 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW internal API //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//========================================================================
|
||||
// Allocate memory using the allocator
|
||||
//========================================================================
|
||||
|
||||
void* _glfwMalloc(size_t size)
|
||||
{
|
||||
return _glfwLibrary.allocator.malloc(size);
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Free memory using the allocator
|
||||
//========================================================================
|
||||
|
||||
void _glfwFree(void* ptr)
|
||||
{
|
||||
_glfwLibrary.allocator.free(ptr);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW public API //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@@ -68,43 +44,12 @@ void _glfwFree(void* ptr)
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI int glfwInit(void)
|
||||
{
|
||||
return glfwInitWithModels(NULL, NULL);
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Initialize various GLFW state using custom model interfaces
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI int glfwInitWithModels(GLFWthreadmodel* threading, GLFWallocator* allocator)
|
||||
{
|
||||
if (_glfwInitialized)
|
||||
return GL_TRUE;
|
||||
|
||||
memset(&_glfwLibrary, 0, sizeof(_glfwLibrary));
|
||||
|
||||
if (threading)
|
||||
_glfwLibrary.threading = *threading;
|
||||
|
||||
if (allocator)
|
||||
{
|
||||
// Verify that the specified model is complete
|
||||
if (!allocator->malloc || !allocator->free)
|
||||
{
|
||||
_glfwSetError(GLFW_INVALID_VALUE, NULL);
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
_glfwLibrary.allocator = *allocator;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use the libc malloc and free
|
||||
_glfwLibrary.allocator.malloc = malloc;
|
||||
_glfwLibrary.allocator.free = free;
|
||||
}
|
||||
|
||||
// Not all window hints have zero as their default value, so this
|
||||
// needs to be here despite the memset above
|
||||
_glfwSetDefaultWindowHints();
|
||||
|
||||
+192
-54
@@ -31,6 +31,122 @@
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Sets the cursor mode for the specified window
|
||||
//========================================================================
|
||||
|
||||
static void setCursorMode(_GLFWwindow* window, int mode)
|
||||
{
|
||||
int centerPosX, centerPosY;
|
||||
|
||||
if (mode != GLFW_CURSOR_NORMAL &&
|
||||
mode != GLFW_CURSOR_HIDDEN &&
|
||||
mode != GLFW_CURSOR_CAPTURED)
|
||||
{
|
||||
_glfwSetError(GLFW_INVALID_ENUM, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
if (window->cursorMode == mode)
|
||||
return;
|
||||
|
||||
centerPosX = window->width / 2;
|
||||
centerPosY = window->height / 2;
|
||||
|
||||
if (mode == GLFW_CURSOR_CAPTURED)
|
||||
_glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
|
||||
else if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
||||
{
|
||||
_glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
|
||||
_glfwInputCursorMotion(window,
|
||||
centerPosX - window->cursorPosX,
|
||||
centerPosY - window->cursorPosY);
|
||||
}
|
||||
|
||||
_glfwPlatformSetCursorMode(window, mode);
|
||||
|
||||
window->cursorMode = mode;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Set sticky keys mode for the specified window
|
||||
//========================================================================
|
||||
|
||||
static void setStickyKeys(_GLFWwindow* window, int enabled)
|
||||
{
|
||||
if (window->stickyKeys == enabled)
|
||||
return;
|
||||
|
||||
if (!enabled)
|
||||
{
|
||||
int i;
|
||||
|
||||
// Release all sticky keys
|
||||
for (i = 0; i <= GLFW_KEY_LAST; i++)
|
||||
{
|
||||
if (window->key[i] == GLFW_STICK)
|
||||
window->key[i] = GLFW_RELEASE;
|
||||
}
|
||||
}
|
||||
|
||||
window->stickyKeys = enabled;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Set sticky mouse buttons mode for the specified window
|
||||
//========================================================================
|
||||
|
||||
static void setStickyMouseButtons(_GLFWwindow* window, int enabled)
|
||||
{
|
||||
if (window->stickyMouseButtons == enabled)
|
||||
return;
|
||||
|
||||
if (!enabled)
|
||||
{
|
||||
int i;
|
||||
|
||||
// Release all sticky mouse buttons
|
||||
for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++)
|
||||
{
|
||||
if (window->mouseButton[i] == GLFW_STICK)
|
||||
window->mouseButton[i] = GLFW_RELEASE;
|
||||
}
|
||||
}
|
||||
|
||||
window->stickyMouseButtons = enabled;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Set system keys for the specified window
|
||||
//========================================================================
|
||||
|
||||
static void setSystemKeys(_GLFWwindow* window, int enabled)
|
||||
{
|
||||
if (window->systemKeys == enabled)
|
||||
return;
|
||||
|
||||
if (enabled)
|
||||
_glfwPlatformEnableSystemKeys(window);
|
||||
else
|
||||
_glfwPlatformDisableSystemKeys(window);
|
||||
|
||||
window->systemKeys = enabled;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Set key repeat for the specified window
|
||||
//========================================================================
|
||||
|
||||
static void setKeyRepeat(_GLFWwindow* window, int enabled)
|
||||
{
|
||||
window->keyRepeat = enabled;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW internal API //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@@ -41,7 +157,7 @@
|
||||
|
||||
void _glfwInputKey(_GLFWwindow* window, int key, int action)
|
||||
{
|
||||
GLboolean keyrepeat = GL_FALSE;
|
||||
GLboolean repeated = GL_FALSE;
|
||||
|
||||
if (key < 0 || key > GLFW_KEY_LAST)
|
||||
return;
|
||||
@@ -55,12 +171,12 @@ void _glfwInputKey(_GLFWwindow* window, int key, int action)
|
||||
window->key[key] = GLFW_STICK;
|
||||
else
|
||||
{
|
||||
keyrepeat = (window->key[key] == GLFW_PRESS) && (action == GLFW_PRESS);
|
||||
repeated = (window->key[key] == GLFW_PRESS) && (action == GLFW_PRESS);
|
||||
window->key[key] = (char) action;
|
||||
}
|
||||
|
||||
// Call user callback function
|
||||
if (_glfwLibrary.keyCallback && (window->keyRepeat || !keyrepeat))
|
||||
if (_glfwLibrary.keyCallback && (window->keyRepeat || !repeated))
|
||||
_glfwLibrary.keyCallback(window, key, action);
|
||||
}
|
||||
|
||||
@@ -138,9 +254,11 @@ void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y)
|
||||
}
|
||||
|
||||
if (_glfwLibrary.mousePosCallback)
|
||||
{
|
||||
_glfwLibrary.mousePosCallback(window,
|
||||
window->cursorPosX,
|
||||
window->cursorPosY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -148,6 +266,77 @@ void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y)
|
||||
////// GLFW public API //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//========================================================================
|
||||
// Returns the specified input mode of the specified window
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI int glfwGetInputMode(GLFWwindow handle, int mode)
|
||||
{
|
||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||
|
||||
if (!_glfwInitialized)
|
||||
{
|
||||
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case GLFW_CURSOR_MODE:
|
||||
return window->cursorMode;
|
||||
case GLFW_STICKY_KEYS:
|
||||
return window->stickyKeys;
|
||||
case GLFW_STICKY_MOUSE_BUTTONS:
|
||||
return window->stickyMouseButtons;
|
||||
case GLFW_SYSTEM_KEYS:
|
||||
return window->systemKeys;
|
||||
case GLFW_KEY_REPEAT:
|
||||
return window->keyRepeat;
|
||||
default:
|
||||
_glfwSetError(GLFW_INVALID_ENUM, NULL);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Sets the specified input mode of the specified window
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwSetInputMode(GLFWwindow handle, int mode, int value)
|
||||
{
|
||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||
|
||||
if (!_glfwInitialized)
|
||||
{
|
||||
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case GLFW_CURSOR_MODE:
|
||||
setCursorMode(window, value);
|
||||
break;
|
||||
case GLFW_STICKY_KEYS:
|
||||
setStickyKeys(window, value ? GL_TRUE : GL_FALSE);
|
||||
break;
|
||||
case GLFW_STICKY_MOUSE_BUTTONS:
|
||||
setStickyMouseButtons(window, value ? GL_TRUE : GL_FALSE);
|
||||
break;
|
||||
case GLFW_SYSTEM_KEYS:
|
||||
setSystemKeys(window, value ? GL_TRUE : GL_FALSE);
|
||||
break;
|
||||
case GLFW_KEY_REPEAT:
|
||||
setKeyRepeat(window, value ? GL_TRUE : GL_FALSE);
|
||||
break;
|
||||
default:
|
||||
_glfwSetError(GLFW_INVALID_ENUM, NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Returns the state of the specified key for the specified window
|
||||
//========================================================================
|
||||
@@ -162,10 +351,8 @@ GLFWAPI int glfwGetKey(GLFWwindow handle, int key)
|
||||
return GLFW_RELEASE;
|
||||
}
|
||||
|
||||
// Is it a valid key?
|
||||
if (key < 0 || key > GLFW_KEY_LAST)
|
||||
{
|
||||
// TODO: Decide whether key is a value or enum
|
||||
_glfwSetError(GLFW_INVALID_ENUM,
|
||||
"glfwGetKey: The specified key is invalid");
|
||||
return GLFW_RELEASE;
|
||||
@@ -196,7 +383,6 @@ GLFWAPI int glfwGetMouseButton(GLFWwindow handle, int button)
|
||||
return GLFW_RELEASE;
|
||||
}
|
||||
|
||||
// Is it a valid mouse button?
|
||||
if (button < 0 || button > GLFW_MOUSE_BUTTON_LAST)
|
||||
{
|
||||
_glfwSetError(GLFW_INVALID_ENUM,
|
||||
@@ -229,7 +415,6 @@ GLFWAPI void glfwGetMousePos(GLFWwindow handle, int* xpos, int* ypos)
|
||||
return;
|
||||
}
|
||||
|
||||
// Return mouse position
|
||||
if (xpos != NULL)
|
||||
*xpos = window->cursorPosX;
|
||||
|
||||
@@ -298,51 +483,6 @@ GLFWAPI void glfwGetScrollOffset(GLFWwindow handle, int* xoffset, int* yoffset)
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Sets the cursor mode for the specified window
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwSetCursorMode(GLFWwindow handle, int mode)
|
||||
{
|
||||
int centerPosX, centerPosY;
|
||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||
|
||||
if (!_glfwInitialized)
|
||||
{
|
||||
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mode != GLFW_CURSOR_NORMAL &&
|
||||
mode != GLFW_CURSOR_HIDDEN &&
|
||||
mode != GLFW_CURSOR_CAPTURED)
|
||||
{
|
||||
_glfwSetError(GLFW_INVALID_ENUM, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
if (window->cursorMode == mode)
|
||||
return;
|
||||
|
||||
centerPosX = window->width / 2;
|
||||
centerPosY = window->height / 2;
|
||||
|
||||
if (mode == GLFW_CURSOR_CAPTURED)
|
||||
_glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
|
||||
else if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
||||
{
|
||||
_glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
|
||||
_glfwInputCursorMotion(window,
|
||||
centerPosX - window->cursorPosX,
|
||||
centerPosY - window->cursorPosY);
|
||||
}
|
||||
|
||||
_glfwPlatformSetCursorMode(window, mode);
|
||||
|
||||
window->cursorMode = mode;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Set callback function for keyboard input
|
||||
//========================================================================
|
||||
@@ -403,7 +543,6 @@ GLFWAPI void glfwSetMousePosCallback(GLFWmouseposfun cbfun)
|
||||
return;
|
||||
}
|
||||
|
||||
// Set callback function
|
||||
_glfwLibrary.mousePosCallback = cbfun;
|
||||
|
||||
// Call the callback function to let the application know the current
|
||||
@@ -430,7 +569,6 @@ GLFWAPI void glfwSetScrollCallback(GLFWscrollfun cbfun)
|
||||
return;
|
||||
}
|
||||
|
||||
// Set callback function
|
||||
_glfwLibrary.scrollCallback = cbfun;
|
||||
}
|
||||
|
||||
|
||||
+13
-20
@@ -37,9 +37,9 @@
|
||||
//========================================================================
|
||||
|
||||
#if defined(_init_c_)
|
||||
#define GLFWGLOBAL
|
||||
#define GLFWGLOBAL
|
||||
#else
|
||||
#define GLFWGLOBAL extern
|
||||
#define GLFWGLOBAL extern
|
||||
#endif
|
||||
|
||||
|
||||
@@ -66,13 +66,13 @@
|
||||
#include "../support/GL/glext.h"
|
||||
|
||||
#if defined(_GLFW_COCOA_NSGL)
|
||||
#include "cocoa_platform.h"
|
||||
#include "cocoa_platform.h"
|
||||
#elif defined(_GLFW_WIN32_WGL)
|
||||
#include "win32_platform.h"
|
||||
#include "win32_platform.h"
|
||||
#elif defined(_GLFW_X11_GLX)
|
||||
#include "x11_platform.h"
|
||||
#include "x11_platform.h"
|
||||
#else
|
||||
#error "No supported platform selected"
|
||||
#error "No supported platform selected"
|
||||
#endif
|
||||
|
||||
typedef struct _GLFWhints _GLFWhints;
|
||||
@@ -103,7 +103,7 @@ struct _GLFWhints
|
||||
int accumAlphaBits;
|
||||
int auxBuffers;
|
||||
GLboolean stereo;
|
||||
GLboolean windowNoResize;
|
||||
GLboolean resizable;
|
||||
int samples;
|
||||
int glMajor;
|
||||
int glMinor;
|
||||
@@ -125,7 +125,7 @@ struct _GLFWwndconfig
|
||||
int mode;
|
||||
const char* title;
|
||||
int refreshRate;
|
||||
GLboolean windowNoResize;
|
||||
GLboolean resizable;
|
||||
int glMajor;
|
||||
int glMinor;
|
||||
GLboolean glForward;
|
||||
@@ -175,7 +175,7 @@ struct _GLFWwindow
|
||||
int width, height;
|
||||
int positionX, positionY;
|
||||
int mode; // GLFW_WINDOW or GLFW_FULLSCREEN
|
||||
GLboolean windowNoResize; // resize- and maximize gadgets disabled flag
|
||||
GLboolean resizable; // GL_TRUE if user may resize this window
|
||||
int refreshRate; // monitor refresh rate
|
||||
void* userPointer;
|
||||
|
||||
@@ -183,7 +183,7 @@ struct _GLFWwindow
|
||||
GLboolean stickyKeys;
|
||||
GLboolean stickyMouseButtons;
|
||||
GLboolean keyRepeat;
|
||||
GLboolean sysKeysDisabled; // system keys disabled flag
|
||||
GLboolean systemKeys; // system keys enabled flag
|
||||
int cursorPosX, cursorPosY;
|
||||
int cursorMode;
|
||||
int scrollX, scrollY;
|
||||
@@ -241,9 +241,6 @@ struct _GLFWlibrary
|
||||
GLFWkeyfun keyCallback;
|
||||
GLFWcharfun charCallback;
|
||||
|
||||
GLFWthreadmodel threading;
|
||||
GLFWallocator allocator;
|
||||
|
||||
GLFWgammaramp currentRamp;
|
||||
GLFWgammaramp originalRamp;
|
||||
int originalRampSize;
|
||||
@@ -276,7 +273,7 @@ int _glfwPlatformInit(void);
|
||||
int _glfwPlatformTerminate(void);
|
||||
const char* _glfwPlatformGetVersionString(void);
|
||||
|
||||
// Enable/Disable
|
||||
// Input
|
||||
void _glfwPlatformEnableSystemKeys(_GLFWwindow* window);
|
||||
void _glfwPlatformDisableSystemKeys(_GLFWwindow* window);
|
||||
|
||||
@@ -330,10 +327,6 @@ void _glfwPlatformCopyContext(_GLFWwindow* src, _GLFWwindow* dst, unsigned long
|
||||
// Prototypes for platform independent internal functions
|
||||
//========================================================================
|
||||
|
||||
// Memory management (init.c)
|
||||
void* _glfwMalloc(size_t size);
|
||||
void _glfwFree(void* ptr);
|
||||
|
||||
// Fullscren management (fullscreen.c)
|
||||
void _glfwSplitBPP(int bpp, int* red, int* green, int* blue);
|
||||
|
||||
@@ -343,14 +336,14 @@ void _glfwSetError(int error, const char* description);
|
||||
// Window management (window.c)
|
||||
void _glfwSetDefaultWindowHints(void);
|
||||
|
||||
// WIndow event notification
|
||||
// Window event notification (window.c)
|
||||
void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean activated);
|
||||
void _glfwInputWindowPos(_GLFWwindow* window, int x, int y);
|
||||
void _glfwInputWindowSize(_GLFWwindow* window, int width, int height);
|
||||
void _glfwInputWindowIconify(_GLFWwindow* window, int iconified);
|
||||
void _glfwInputWindowDamage(_GLFWwindow* window);
|
||||
|
||||
// Input event notification
|
||||
// Input event notification (input.c)
|
||||
void _glfwInputKey(_GLFWwindow* window, int key, int action);
|
||||
void _glfwInputChar(_GLFWwindow* window, int character);
|
||||
void _glfwInputScroll(_GLFWwindow* window, int x, int y);
|
||||
|
||||
+60
-6
@@ -47,7 +47,7 @@ static GLboolean initLibraries(void)
|
||||
#ifndef _GLFW_NO_DLOAD_GDI32
|
||||
// gdi32.dll (OpenGL pixel format functions & SwapBuffers)
|
||||
|
||||
_glfwLibrary.Win32.gdi.instance = LoadLibrary("gdi32.dll");
|
||||
_glfwLibrary.Win32.gdi.instance = LoadLibrary(L"gdi32.dll");
|
||||
if (!_glfwLibrary.Win32.gdi.instance)
|
||||
return GL_FALSE;
|
||||
|
||||
@@ -81,12 +81,12 @@ static GLboolean initLibraries(void)
|
||||
#ifndef _GLFW_NO_DLOAD_WINMM
|
||||
// winmm.dll (for joystick and timer support)
|
||||
|
||||
_glfwLibrary.Win32.winmm.instance = LoadLibrary("winmm.dll");
|
||||
_glfwLibrary.Win32.winmm.instance = LoadLibrary(L"winmm.dll");
|
||||
if (!_glfwLibrary.Win32.winmm.instance)
|
||||
return GL_FALSE;
|
||||
|
||||
_glfwLibrary.Win32.winmm.joyGetDevCapsA = (JOYGETDEVCAPSA_T)
|
||||
GetProcAddress(_glfwLibrary.Win32.winmm.instance, "joyGetDevCapsA");
|
||||
_glfwLibrary.Win32.winmm.joyGetDevCaps = (JOYGETDEVCAPS_T)
|
||||
GetProcAddress(_glfwLibrary.Win32.winmm.instance, "joyGetDevCapsW");
|
||||
_glfwLibrary.Win32.winmm.joyGetPos = (JOYGETPOS_T)
|
||||
GetProcAddress(_glfwLibrary.Win32.winmm.instance, "joyGetPos");
|
||||
_glfwLibrary.Win32.winmm.joyGetPosEx = (JOYGETPOSEX_T)
|
||||
@@ -94,7 +94,7 @@ static GLboolean initLibraries(void)
|
||||
_glfwLibrary.Win32.winmm.timeGetTime = (TIMEGETTIME_T)
|
||||
GetProcAddress(_glfwLibrary.Win32.winmm.instance, "timeGetTime");
|
||||
|
||||
if (!_glfwLibrary.Win32.winmm.joyGetDevCapsA ||
|
||||
if (!_glfwLibrary.Win32.winmm.joyGetDevCaps ||
|
||||
!_glfwLibrary.Win32.winmm.joyGetPos ||
|
||||
!_glfwLibrary.Win32.winmm.joyGetPosEx ||
|
||||
!_glfwLibrary.Win32.winmm.timeGetTime)
|
||||
@@ -131,6 +131,60 @@ static void freeLibraries(void)
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW internal API //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//========================================================================
|
||||
// Returns a wide string version of the specified UTF-8 string
|
||||
//========================================================================
|
||||
|
||||
WCHAR* _glfwCreateWideStringFromUTF8(const char* source)
|
||||
{
|
||||
WCHAR* target;
|
||||
int length;
|
||||
|
||||
length = MultiByteToWideChar(CP_UTF8, 0, source, -1, NULL, 0);
|
||||
if (!length)
|
||||
return NULL;
|
||||
|
||||
target = (WCHAR*) malloc(sizeof(WCHAR) * (length + 1));
|
||||
|
||||
if (!MultiByteToWideChar(CP_UTF8, 0, source, -1, target, length + 1))
|
||||
{
|
||||
free(target);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Returns a UTF-8 string version of the specified wide string
|
||||
//========================================================================
|
||||
|
||||
char* _glfwCreateUTF8FromWideString(const WCHAR* source)
|
||||
{
|
||||
char* target;
|
||||
int length;
|
||||
|
||||
length = WideCharToMultiByte(CP_UTF8, 0, source, -1, NULL, 0, NULL, NULL);
|
||||
if (!length)
|
||||
return NULL;
|
||||
|
||||
target = (char*) malloc(length + 1);
|
||||
|
||||
if (!WideCharToMultiByte(CP_UTF8, 0, source, -1, target, length + 1, NULL, NULL))
|
||||
{
|
||||
free(target);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW platform API //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@@ -205,7 +259,7 @@ int _glfwPlatformTerminate(void)
|
||||
|
||||
const char* _glfwPlatformGetVersionString(void)
|
||||
{
|
||||
const char* version = "GLFW " _GLFW_VERSION_FULL
|
||||
const char* version = _GLFW_VERSION_FULL
|
||||
#if defined(__MINGW32__)
|
||||
" MinGW"
|
||||
#elif defined(__CYGWIN__)
|
||||
|
||||
+64
-47
@@ -40,6 +40,19 @@
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
|
||||
// This is a workaround for the fact that glfw3.h needs to export APIENTRY (to
|
||||
// correctly declare a GL_ARB_debug_output callback, for example) but windows.h
|
||||
// thinks it is the only one that gets to do so
|
||||
#undef APIENTRY
|
||||
|
||||
// GLFW on Windows is Unicode only and does not work in MBCS mode
|
||||
#ifndef UNICODE
|
||||
#define UNICODE
|
||||
#endif
|
||||
|
||||
// GLFW requires Windows XP
|
||||
#define WINVER 0x0501
|
||||
|
||||
#include <windows.h>
|
||||
#include <mmsystem.h>
|
||||
|
||||
@@ -56,10 +69,10 @@
|
||||
// Some old versions of w32api (used by MinGW and Cygwin) define
|
||||
// WH_KEYBOARD_LL without typedef:ing KBDLLHOOKSTRUCT (!)
|
||||
#if defined(__MINGW32__) || defined(__CYGWIN__)
|
||||
#include <w32api.h>
|
||||
#if defined(WH_KEYBOARD_LL) && (__W32API_MAJOR_VERSION == 1) && (__W32API_MINOR_VERSION <= 2)
|
||||
#undef WH_KEYBOARD_LL
|
||||
#endif
|
||||
#include <w32api.h>
|
||||
#if defined(WH_KEYBOARD_LL) && (__W32API_MAJOR_VERSION == 1) && (__W32API_MINOR_VERSION <= 2)
|
||||
#undef WH_KEYBOARD_LL
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
@@ -79,64 +92,64 @@ typedef struct tagKBDLLHOOKSTRUCT {
|
||||
#endif // WH_KEYBOARD_LL
|
||||
|
||||
#ifndef LLKHF_ALTDOWN
|
||||
#define LLKHF_ALTDOWN 0x00000020
|
||||
#define LLKHF_ALTDOWN 0x00000020
|
||||
#endif
|
||||
|
||||
#ifndef SPI_SETSCREENSAVERRUNNING
|
||||
#define SPI_SETSCREENSAVERRUNNING 97
|
||||
#define SPI_SETSCREENSAVERRUNNING 97
|
||||
#endif
|
||||
#ifndef SPI_GETANIMATION
|
||||
#define SPI_GETANIMATION 72
|
||||
#define SPI_GETANIMATION 72
|
||||
#endif
|
||||
#ifndef SPI_SETANIMATION
|
||||
#define SPI_SETANIMATION 73
|
||||
#define SPI_SETANIMATION 73
|
||||
#endif
|
||||
#ifndef SPI_GETFOREGROUNDLOCKTIMEOUT
|
||||
#define SPI_GETFOREGROUNDLOCKTIMEOUT 0x2000
|
||||
#define SPI_GETFOREGROUNDLOCKTIMEOUT 0x2000
|
||||
#endif
|
||||
#ifndef SPI_SETFOREGROUNDLOCKTIMEOUT
|
||||
#define SPI_SETFOREGROUNDLOCKTIMEOUT 0x2001
|
||||
#define SPI_SETFOREGROUNDLOCKTIMEOUT 0x2001
|
||||
#endif
|
||||
|
||||
#ifndef CDS_FULLSCREEN
|
||||
#define CDS_FULLSCREEN 4
|
||||
#define CDS_FULLSCREEN 4
|
||||
#endif
|
||||
|
||||
#ifndef PFD_GENERIC_ACCELERATED
|
||||
#define PFD_GENERIC_ACCELERATED 0x00001000
|
||||
#define PFD_GENERIC_ACCELERATED 0x00001000
|
||||
#endif
|
||||
#ifndef PFD_DEPTH_DONTCARE
|
||||
#define PFD_DEPTH_DONTCARE 0x20000000
|
||||
#define PFD_DEPTH_DONTCARE 0x20000000
|
||||
#endif
|
||||
|
||||
#ifndef ENUM_CURRENT_SETTINGS
|
||||
#define ENUM_CURRENT_SETTINGS -1
|
||||
#define ENUM_CURRENT_SETTINGS -1
|
||||
#endif
|
||||
#ifndef ENUM_REGISTRY_SETTINGS
|
||||
#define ENUM_REGISTRY_SETTINGS -2
|
||||
#define ENUM_REGISTRY_SETTINGS -2
|
||||
#endif
|
||||
|
||||
#ifndef WM_MOUSEWHEEL
|
||||
#define WM_MOUSEWHEEL 0x020A
|
||||
#define WM_MOUSEWHEEL 0x020A
|
||||
#endif
|
||||
#ifndef WHEEL_DELTA
|
||||
#define WHEEL_DELTA 120
|
||||
#define WHEEL_DELTA 120
|
||||
#endif
|
||||
#ifndef WM_MOUSEHWHEEL
|
||||
#define WM_MOUSEHWHEEL 0x020E
|
||||
#define WM_MOUSEHWHEEL 0x020E
|
||||
#endif
|
||||
|
||||
#ifndef WM_XBUTTONDOWN
|
||||
#define WM_XBUTTONDOWN 0x020B
|
||||
#define WM_XBUTTONDOWN 0x020B
|
||||
#endif
|
||||
#ifndef WM_XBUTTONUP
|
||||
#define WM_XBUTTONUP 0x020C
|
||||
#define WM_XBUTTONUP 0x020C
|
||||
#endif
|
||||
#ifndef XBUTTON1
|
||||
#define XBUTTON1 1
|
||||
#define XBUTTON1 1
|
||||
#endif
|
||||
#ifndef XBUTTON2
|
||||
#define XBUTTON2 2
|
||||
#define XBUTTON2 2
|
||||
#endif
|
||||
|
||||
|
||||
@@ -157,7 +170,7 @@ typedef BOOL (WINAPI * SETDEVICEGAMMARAMP_T) (HDC,PVOID);
|
||||
|
||||
// winmm.dll function pointer typedefs
|
||||
#ifndef _GLFW_NO_DLOAD_WINMM
|
||||
typedef MMRESULT (WINAPI * JOYGETDEVCAPSA_T) (UINT,LPJOYCAPSA,UINT);
|
||||
typedef MMRESULT (WINAPI * JOYGETDEVCAPS_T) (UINT,LPJOYCAPS,UINT);
|
||||
typedef MMRESULT (WINAPI * JOYGETPOS_T) (UINT,LPJOYINFO);
|
||||
typedef MMRESULT (WINAPI * JOYGETPOSEX_T) (UINT,LPJOYINFOEX);
|
||||
typedef DWORD (WINAPI * TIMEGETTIME_T) (void);
|
||||
@@ -166,40 +179,40 @@ typedef DWORD (WINAPI * TIMEGETTIME_T) (void);
|
||||
|
||||
// gdi32.dll shortcuts
|
||||
#ifndef _GLFW_NO_DLOAD_GDI32
|
||||
#define _glfw_ChoosePixelFormat _glfwLibrary.Win32.gdi.ChoosePixelFormat
|
||||
#define _glfw_DescribePixelFormat _glfwLibrary.Win32.gdi.DescribePixelFormat
|
||||
#define _glfw_GetPixelFormat _glfwLibrary.Win32.gdi.GetPixelFormat
|
||||
#define _glfw_SetPixelFormat _glfwLibrary.Win32.gdi.SetPixelFormat
|
||||
#define _glfw_SwapBuffers _glfwLibrary.Win32.gdi.SwapBuffers
|
||||
#define _glfw_GetDeviceGammaRamp _glfwLibrary.Win32.gdi.GetDeviceGammaRamp
|
||||
#define _glfw_SetDeviceGammaRamp _glfwLibrary.Win32.gdi.SetDeviceGammaRamp
|
||||
#define _glfw_ChoosePixelFormat _glfwLibrary.Win32.gdi.ChoosePixelFormat
|
||||
#define _glfw_DescribePixelFormat _glfwLibrary.Win32.gdi.DescribePixelFormat
|
||||
#define _glfw_GetPixelFormat _glfwLibrary.Win32.gdi.GetPixelFormat
|
||||
#define _glfw_SetPixelFormat _glfwLibrary.Win32.gdi.SetPixelFormat
|
||||
#define _glfw_SwapBuffers _glfwLibrary.Win32.gdi.SwapBuffers
|
||||
#define _glfw_GetDeviceGammaRamp _glfwLibrary.Win32.gdi.GetDeviceGammaRamp
|
||||
#define _glfw_SetDeviceGammaRamp _glfwLibrary.Win32.gdi.SetDeviceGammaRamp
|
||||
#else
|
||||
#define _glfw_ChoosePixelFormat ChoosePixelFormat
|
||||
#define _glfw_DescribePixelFormat DescribePixelFormat
|
||||
#define _glfw_GetPixelFormat GetPixelFormat
|
||||
#define _glfw_SetPixelFormat SetPixelFormat
|
||||
#define _glfw_SwapBuffers SwapBuffers
|
||||
#define _glfw_GetDeviceGammaRamp GetDeviceGammaRamp
|
||||
#define _glfw_SetDeviceGammaRamp SetDeviceGammaRamp
|
||||
#define _glfw_ChoosePixelFormat ChoosePixelFormat
|
||||
#define _glfw_DescribePixelFormat DescribePixelFormat
|
||||
#define _glfw_GetPixelFormat GetPixelFormat
|
||||
#define _glfw_SetPixelFormat SetPixelFormat
|
||||
#define _glfw_SwapBuffers SwapBuffers
|
||||
#define _glfw_GetDeviceGammaRamp GetDeviceGammaRamp
|
||||
#define _glfw_SetDeviceGammaRamp SetDeviceGammaRamp
|
||||
#endif // _GLFW_NO_DLOAD_GDI32
|
||||
|
||||
// winmm.dll shortcuts
|
||||
#ifndef _GLFW_NO_DLOAD_WINMM
|
||||
#define _glfw_joyGetDevCaps _glfwLibrary.Win32.winmm.joyGetDevCapsA
|
||||
#define _glfw_joyGetPos _glfwLibrary.Win32.winmm.joyGetPos
|
||||
#define _glfw_joyGetPosEx _glfwLibrary.Win32.winmm.joyGetPosEx
|
||||
#define _glfw_timeGetTime _glfwLibrary.Win32.winmm.timeGetTime
|
||||
#define _glfw_joyGetDevCaps _glfwLibrary.Win32.winmm.joyGetDevCaps
|
||||
#define _glfw_joyGetPos _glfwLibrary.Win32.winmm.joyGetPos
|
||||
#define _glfw_joyGetPosEx _glfwLibrary.Win32.winmm.joyGetPosEx
|
||||
#define _glfw_timeGetTime _glfwLibrary.Win32.winmm.timeGetTime
|
||||
#else
|
||||
#define _glfw_joyGetDevCaps joyGetDevCapsA
|
||||
#define _glfw_joyGetPos joyGetPos
|
||||
#define _glfw_joyGetPosEx joyGetPosEx
|
||||
#define _glfw_timeGetTime timeGetTime
|
||||
#define _glfw_joyGetDevCaps joyGetDevCaps
|
||||
#define _glfw_joyGetPos joyGetPos
|
||||
#define _glfw_joyGetPosEx joyGetPosEx
|
||||
#define _glfw_timeGetTime timeGetTime
|
||||
#endif // _GLFW_NO_DLOAD_WINMM
|
||||
|
||||
|
||||
// We use versioned window class names in order not to cause conflicts
|
||||
// between applications using different versions of GLFW
|
||||
#define _GLFW_WNDCLASSNAME "GLFW30"
|
||||
#define _GLFW_WNDCLASSNAME L"GLFW30"
|
||||
|
||||
|
||||
#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowWin32 Win32
|
||||
@@ -304,7 +317,7 @@ typedef struct _GLFWlibraryWin32
|
||||
// winmm.dll
|
||||
struct {
|
||||
HINSTANCE instance;
|
||||
JOYGETDEVCAPSA_T joyGetDevCapsA;
|
||||
JOYGETDEVCAPS_T joyGetDevCaps;
|
||||
JOYGETPOS_T joyGetPos;
|
||||
JOYGETPOSEX_T joyGetPosEx;
|
||||
TIMEGETTIME_T timeGetTime;
|
||||
@@ -318,6 +331,10 @@ typedef struct _GLFWlibraryWin32
|
||||
// Prototypes for platform specific internal functions
|
||||
//========================================================================
|
||||
|
||||
// Wide strings
|
||||
WCHAR* _glfwCreateWideStringFromUTF8(const char* source);
|
||||
char* _glfwCreateUTF8FromWideString(const WCHAR* source);
|
||||
|
||||
// Time
|
||||
void _glfwInitTimer(void);
|
||||
|
||||
|
||||
+30
-9
@@ -195,7 +195,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
result = (_GLFWfbconfig*) _glfwMalloc(sizeof(_GLFWfbconfig) * count);
|
||||
result = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * count);
|
||||
if (!result)
|
||||
{
|
||||
_glfwSetError(GLFW_OUT_OF_MEMORY,
|
||||
@@ -895,7 +895,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
||||
if (_glfwLibrary.charCallback)
|
||||
translateChar(window, (DWORD) wParam, (DWORD) lParam);
|
||||
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_KEYUP:
|
||||
@@ -910,7 +910,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
||||
else
|
||||
_glfwInputKey(window, translateKey(wParam, lParam), GLFW_RELEASE);
|
||||
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_LBUTTONDOWN:
|
||||
@@ -1220,7 +1220,7 @@ static ATOM registerWindowClass(void)
|
||||
wc.lpszClassName = _GLFW_WNDCLASSNAME; // Set class name
|
||||
|
||||
// Load user-provided icon if available
|
||||
wc.hIcon = LoadIcon(_glfwLibrary.Win32.instance, "GLFW_ICON");
|
||||
wc.hIcon = LoadIcon(_glfwLibrary.Win32.instance, L"GLFW_ICON");
|
||||
if (!wc.hIcon)
|
||||
{
|
||||
// Load default icon
|
||||
@@ -1257,13 +1257,13 @@ static int choosePixelFormat(_GLFWwindow* window, const _GLFWfbconfig* fbconfig)
|
||||
closest = _glfwChooseFBConfig(fbconfig, fbconfigs, fbcount);
|
||||
if (!closest)
|
||||
{
|
||||
_glfwFree(fbconfigs);
|
||||
free(fbconfigs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pixelFormat = (int) closest->platformID;
|
||||
|
||||
_glfwFree(fbconfigs);
|
||||
free(fbconfigs);
|
||||
fbconfigs = NULL;
|
||||
closest = NULL;
|
||||
|
||||
@@ -1283,6 +1283,7 @@ static int createWindow(_GLFWwindow* window,
|
||||
int pixelFormat, fullWidth, fullHeight;
|
||||
RECT wa;
|
||||
POINT pos;
|
||||
WCHAR* wideTitle;
|
||||
|
||||
// Set common window styles
|
||||
dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
|
||||
@@ -1309,7 +1310,7 @@ static int createWindow(_GLFWwindow* window,
|
||||
{
|
||||
dwStyle |= WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
|
||||
|
||||
if (!wndconfig->windowNoResize)
|
||||
if (wndconfig->resizable)
|
||||
{
|
||||
dwStyle |= (WS_MAXIMIZEBOX | WS_SIZEBOX);
|
||||
dwExStyle |= WS_EX_WINDOWEDGE;
|
||||
@@ -1331,9 +1332,17 @@ static int createWindow(_GLFWwindow* window,
|
||||
else
|
||||
SystemParametersInfo(SPI_GETWORKAREA, 0, &wa, 0);
|
||||
|
||||
wideTitle = _glfwCreateWideStringFromUTF8(wndconfig->title);
|
||||
if (!wideTitle)
|
||||
{
|
||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||
"glfwOpenWindow: Failed to convert title to wide string");
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
window->Win32.handle = CreateWindowEx(window->Win32.dwExStyle,
|
||||
_GLFW_WNDCLASSNAME,
|
||||
wndconfig->title,
|
||||
wideTitle,
|
||||
window->Win32.dwStyle,
|
||||
wa.left, wa.top, // Window position
|
||||
fullWidth, // Decorated window width
|
||||
@@ -1349,6 +1358,8 @@ static int createWindow(_GLFWwindow* window,
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
free(wideTitle);
|
||||
|
||||
window->WGL.DC = GetDC(window->Win32.handle);
|
||||
if (!window->WGL.DC)
|
||||
{
|
||||
@@ -1568,7 +1579,17 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window)
|
||||
|
||||
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
|
||||
{
|
||||
SetWindowText(window->Win32.handle, title);
|
||||
WCHAR* wideTitle = _glfwCreateWideStringFromUTF8(title);
|
||||
if (!wideTitle)
|
||||
{
|
||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||
"glfwSetWindowTitle: Failed to convert title to wide string");
|
||||
return;
|
||||
}
|
||||
|
||||
SetWindowText(window->Win32.handle, wideTitle);
|
||||
|
||||
free(wideTitle);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+12
-9
@@ -100,6 +100,9 @@ void _glfwSetDefaultWindowHints(void)
|
||||
// The default minimum OpenGL version is 1.0
|
||||
_glfwLibrary.hints.glMajor = 1;
|
||||
_glfwLibrary.hints.glMinor = 0;
|
||||
|
||||
// The default is to allow window resizing
|
||||
_glfwLibrary.hints.resizable = GL_TRUE;
|
||||
}
|
||||
|
||||
|
||||
@@ -247,7 +250,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
|
||||
wndconfig.mode = mode;
|
||||
wndconfig.title = title;
|
||||
wndconfig.refreshRate = Max(_glfwLibrary.hints.refreshRate, 0);
|
||||
wndconfig.windowNoResize = _glfwLibrary.hints.windowNoResize ? GL_TRUE : GL_FALSE;
|
||||
wndconfig.resizable = _glfwLibrary.hints.resizable ? GL_TRUE : GL_FALSE;
|
||||
wndconfig.glMajor = _glfwLibrary.hints.glMajor;
|
||||
wndconfig.glMinor = _glfwLibrary.hints.glMinor;
|
||||
wndconfig.glForward = _glfwLibrary.hints.glForward ? GL_TRUE : GL_FALSE;
|
||||
@@ -288,7 +291,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
|
||||
height = 480;
|
||||
}
|
||||
|
||||
window = (_GLFWwindow*) _glfwMalloc(sizeof(_GLFWwindow));
|
||||
window = (_GLFWwindow*) malloc(sizeof(_GLFWwindow));
|
||||
if (!window)
|
||||
{
|
||||
_glfwSetError(GLFW_OUT_OF_MEMORY,
|
||||
@@ -306,6 +309,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
|
||||
window->height = height;
|
||||
window->mode = mode;
|
||||
window->cursorMode = GLFW_CURSOR_NORMAL;
|
||||
window->systemKeys = GL_TRUE;
|
||||
|
||||
// Open the actual window and create its context
|
||||
if (!_glfwPlatformOpenWindow(window, &wndconfig, &fbconfig))
|
||||
@@ -327,7 +331,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
|
||||
// The GLFW specification states that fullscreen windows have the cursor
|
||||
// captured by default
|
||||
if (mode == GLFW_FULLSCREEN)
|
||||
glfwSetCursorMode(window, GLFW_CURSOR_CAPTURED);
|
||||
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_CAPTURED);
|
||||
|
||||
// Clearing the front buffer to black to avoid garbage pixels left over
|
||||
// from previous uses of our bit of VRAM
|
||||
@@ -419,8 +423,8 @@ GLFWAPI void glfwOpenWindowHint(int target, int hint)
|
||||
case GLFW_STEREO:
|
||||
_glfwLibrary.hints.stereo = hint;
|
||||
break;
|
||||
case GLFW_WINDOW_NO_RESIZE:
|
||||
_glfwLibrary.hints.windowNoResize = hint;
|
||||
case GLFW_WINDOW_RESIZABLE:
|
||||
_glfwLibrary.hints.resizable = hint;
|
||||
break;
|
||||
case GLFW_FSAA_SAMPLES:
|
||||
_glfwLibrary.hints.samples = hint;
|
||||
@@ -488,7 +492,7 @@ GLFWAPI void glfwCloseWindow(GLFWwindow handle)
|
||||
*prev = window->next;
|
||||
}
|
||||
|
||||
_glfwFree(window);
|
||||
free(window);
|
||||
}
|
||||
|
||||
|
||||
@@ -651,7 +655,6 @@ GLFWAPI void glfwRestoreWindow(GLFWwindow handle)
|
||||
if (!window->iconified)
|
||||
return;
|
||||
|
||||
// Restore iconified window
|
||||
_glfwPlatformRestoreWindow(window);
|
||||
|
||||
if (window->mode == GLFW_FULLSCREEN)
|
||||
@@ -707,8 +710,8 @@ GLFWAPI int glfwGetWindowParam(GLFWwindow handle, int param)
|
||||
return window->stereo;
|
||||
case GLFW_REFRESH_RATE:
|
||||
return window->refreshRate;
|
||||
case GLFW_WINDOW_NO_RESIZE:
|
||||
return window->windowNoResize;
|
||||
case GLFW_WINDOW_RESIZABLE:
|
||||
return window->resizable;
|
||||
case GLFW_FSAA_SAMPLES:
|
||||
return window->samples;
|
||||
case GLFW_OPENGL_VERSION_MAJOR:
|
||||
|
||||
@@ -339,7 +339,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
||||
return 0;
|
||||
}
|
||||
|
||||
rgbarray = (int*) _glfwMalloc(sizeof(int) * viscount);
|
||||
rgbarray = (int*) malloc(sizeof(int) * viscount);
|
||||
rgbcount = 0;
|
||||
|
||||
// Build RGB array
|
||||
@@ -387,7 +387,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
||||
sc = XRRGetScreenInfo(_glfwLibrary.X11.display, _glfwLibrary.X11.root);
|
||||
sizelist = XRRConfigSizes(sc, &sizecount);
|
||||
|
||||
resarray = (struct _glfwResolution*) _glfwMalloc(sizeof(struct _glfwResolution) * sizecount);
|
||||
resarray = (struct _glfwResolution*) malloc(sizeof(struct _glfwResolution) * sizecount);
|
||||
|
||||
for (k = 0; k < sizecount; k++)
|
||||
{
|
||||
@@ -407,7 +407,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
||||
|
||||
XF86VidModeGetAllModeLines(_glfwLibrary.X11.display, screen, &modecount, &modelist);
|
||||
|
||||
resarray = (struct _glfwResolution*) _glfwMalloc(sizeof(struct _glfwResolution) * modecount);
|
||||
resarray = (struct _glfwResolution*) malloc(sizeof(struct _glfwResolution) * modecount);
|
||||
|
||||
for (k = 0; k < modecount; k++)
|
||||
{
|
||||
@@ -436,7 +436,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
||||
if (!resarray)
|
||||
{
|
||||
rescount = 1;
|
||||
resarray = (struct _glfwResolution*) _glfwMalloc(sizeof(struct _glfwResolution) * rescount);
|
||||
resarray = (struct _glfwResolution*) malloc(sizeof(struct _glfwResolution) * rescount);
|
||||
|
||||
resarray[0].width = DisplayWidth(_glfwLibrary.X11.display, screen);
|
||||
resarray[0].height = DisplayHeight(_glfwLibrary.X11.display, screen);
|
||||
@@ -459,8 +459,8 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
||||
|
||||
XFree(vislist);
|
||||
|
||||
_glfwFree(resarray);
|
||||
_glfwFree(rgbarray);
|
||||
free(resarray);
|
||||
free(rgbarray);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
+5
-2
@@ -366,7 +366,7 @@ static void updateKeyCodeLUT(void)
|
||||
|
||||
static GLboolean initDisplay(void)
|
||||
{
|
||||
_glfwLibrary.X11.display = XOpenDisplay(0);
|
||||
_glfwLibrary.X11.display = XOpenDisplay(NULL);
|
||||
if (!_glfwLibrary.X11.display)
|
||||
{
|
||||
_glfwSetError(GLFW_OPENGL_UNAVAILABLE, "X11/GLX: Failed to open X display");
|
||||
@@ -639,7 +639,7 @@ int _glfwPlatformTerminate(void)
|
||||
|
||||
const char* _glfwPlatformGetVersionString(void)
|
||||
{
|
||||
const char* version = "GLFW " _GLFW_VERSION_FULL
|
||||
const char* version = _GLFW_VERSION_FULL
|
||||
#if defined(_GLFW_HAS_XRANDR)
|
||||
" XRandR"
|
||||
#endif
|
||||
@@ -649,6 +649,9 @@ const char* _glfwPlatformGetVersionString(void)
|
||||
#if !defined(_GLFW_HAS_XRANDR) && !defined(_GLFW_HAS_XF86VIDMODE)
|
||||
" no-mode-switching-support"
|
||||
#endif
|
||||
#if defined(_GLFW_HAS_XKB)
|
||||
" Xkb"
|
||||
#endif
|
||||
#if defined(_GLFW_HAS_GLXGETPROCADDRESS)
|
||||
" glXGetProcAddress"
|
||||
#elif defined(_GLFW_HAS_GLXGETPROCADDRESSARB)
|
||||
|
||||
+1
-2
@@ -31,8 +31,7 @@
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
void (*glXGetProcAddress(const GLubyte* procName))();
|
||||
void (*glXGetProcAddressARB(const GLubyte* procName))();
|
||||
// This is the only glXGetProcAddress variant not declared by glxext.h
|
||||
void (*glXGetProcAddressEXT(const GLubyte* procName))();
|
||||
|
||||
|
||||
|
||||
+2
-7
@@ -46,13 +46,6 @@
|
||||
// extensions and not all operating systems come with an up-to-date version
|
||||
#include "../support/GL/glxext.h"
|
||||
|
||||
|
||||
// We need declarations for GLX version 1.3 or above even if the server doesn't
|
||||
// support version 1.3
|
||||
#ifndef GLX_VERSION_1_3
|
||||
#error "GLX header version 1.3 or above is required"
|
||||
#endif
|
||||
|
||||
// With XFree86, we can use the XF86VidMode extension
|
||||
#if defined(_GLFW_HAS_XF86VIDMODE)
|
||||
#include <X11/extensions/xf86vmode.h>
|
||||
@@ -152,6 +145,8 @@ typedef struct _GLFWwindowX11
|
||||
Colormap colormap; // Window colormap
|
||||
Window handle; // Window handle
|
||||
Atom wmDeleteWindow; // WM_DELETE_WINDOW atom
|
||||
Atom wmName; // _NET_WM_NAME atom
|
||||
Atom wmIconName; // _NET_WM_ICON_NAME atom
|
||||
Atom wmPing; // _NET_WM_PING atom
|
||||
Atom wmState; // _NET_WM_STATE atom
|
||||
Atom wmStateFullscreen; // _NET_WM_STATE_FULLSCREEN atom
|
||||
|
||||
+52
-11
@@ -195,6 +195,12 @@ static GLboolean hasEWMH(_GLFWwindow* window)
|
||||
window->X11.wmStateFullscreen =
|
||||
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_STATE_FULLSCREEN");
|
||||
|
||||
window->X11.wmName =
|
||||
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_NAME");
|
||||
|
||||
window->X11.wmIconName =
|
||||
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_ICON_NAME");
|
||||
|
||||
window->X11.wmPing =
|
||||
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_PING");
|
||||
|
||||
@@ -310,7 +316,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
|
||||
}
|
||||
}
|
||||
|
||||
result = (_GLFWfbconfig*) _glfwMalloc(sizeof(_GLFWfbconfig) * count);
|
||||
result = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * count);
|
||||
if (!result)
|
||||
{
|
||||
_glfwSetError(GLFW_OUT_OF_MEMORY,
|
||||
@@ -794,7 +800,7 @@ static GLboolean createWindow(_GLFWwindow* window,
|
||||
|
||||
hints->flags = 0;
|
||||
|
||||
if (wndconfig->windowNoResize)
|
||||
if (!wndconfig->resizable)
|
||||
{
|
||||
hints->flags |= (PMinSize | PMaxSize);
|
||||
hints->min_width = hints->max_width = window->width;
|
||||
@@ -1426,8 +1432,8 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
||||
{
|
||||
_GLFWfbconfig closest;
|
||||
|
||||
window->refreshRate = wndconfig->refreshRate;
|
||||
window->windowNoResize = wndconfig->windowNoResize;
|
||||
window->refreshRate = wndconfig->refreshRate;
|
||||
window->resizable = wndconfig->resizable;
|
||||
|
||||
initGLXExtensions(window);
|
||||
|
||||
@@ -1444,12 +1450,12 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
||||
result = _glfwChooseFBConfig(fbconfig, fbconfigs, fbcount);
|
||||
if (!result)
|
||||
{
|
||||
_glfwFree(fbconfigs);
|
||||
free(fbconfigs);
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
closest = *result;
|
||||
_glfwFree(fbconfigs);
|
||||
free(fbconfigs);
|
||||
}
|
||||
|
||||
if (!createContext(window, wndconfig, (GLXFBConfigID) closest.platformID))
|
||||
@@ -1544,9 +1550,39 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window)
|
||||
|
||||
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
|
||||
{
|
||||
// Set window & icon title
|
||||
XStoreName(_glfwLibrary.X11.display, window->X11.handle, title);
|
||||
XSetIconName(_glfwLibrary.X11.display, window->X11.handle, title);
|
||||
Atom type = XInternAtom(_glfwLibrary.X11.display, "UTF8_STRING", False);
|
||||
|
||||
#if defined(X_HAVE_UTF8_STRING)
|
||||
Xutf8SetWMProperties(_glfwLibrary.X11.display,
|
||||
window->X11.handle,
|
||||
title, title,
|
||||
NULL, 0,
|
||||
NULL, NULL, NULL);
|
||||
#else
|
||||
// This may be a slightly better fallback than using XStoreName and
|
||||
// XSetIconName, which always store their arguments using STRING
|
||||
XmbSetWMProperties(_glfwLibrary.X11.display,
|
||||
window->X11.handle,
|
||||
title, title,
|
||||
NULL, 0,
|
||||
NULL, NULL, NULL);
|
||||
#endif
|
||||
|
||||
if (window->X11.wmName != None)
|
||||
{
|
||||
XChangeProperty(_glfwLibrary.X11.display, window->X11.handle,
|
||||
window->X11.wmName, type, 8,
|
||||
PropModeReplace,
|
||||
(unsigned char*) title, strlen(title));
|
||||
}
|
||||
|
||||
if (window->X11.wmIconName != None)
|
||||
{
|
||||
XChangeProperty(_glfwLibrary.X11.display, window->X11.handle,
|
||||
window->X11.wmIconName, type, 8,
|
||||
PropModeReplace,
|
||||
(unsigned char*) title, strlen(title));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1568,7 +1604,7 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
|
||||
&width, &height, &rate);
|
||||
}
|
||||
|
||||
if (window->windowNoResize)
|
||||
if (!window->resizable)
|
||||
{
|
||||
// Update window size restrictions to match new window size
|
||||
|
||||
@@ -1735,7 +1771,7 @@ void _glfwPlatformRefreshWindowParams(void)
|
||||
&dotclock, &modeline);
|
||||
pixels_per_second = 1000.0f * (float) dotclock;
|
||||
pixels_per_frame = (float) modeline.htotal * modeline.vtotal;
|
||||
window->refreshRate = (int)(pixels_per_second/pixels_per_frame+0.5);
|
||||
window->refreshRate = (int) (pixels_per_second / pixels_per_frame + 0.5);
|
||||
#endif /*_GLFW_HAS_XF86VIDMODE*/
|
||||
}
|
||||
else
|
||||
@@ -1771,6 +1807,11 @@ void _glfwPlatformPollEvents(void)
|
||||
window->width / 2,
|
||||
window->height / 2);
|
||||
window->X11.cursorCentered = GL_TRUE;
|
||||
|
||||
// NOTE: This is a temporary fix. It works as long as you use
|
||||
// offsets accumulated over the course of a frame, instead of
|
||||
// performing the necessary actions per callback call.
|
||||
XFlush( _glfwLibrary.X11.display );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user