Formatting.

This commit is contained in:
Camilla Berglund 2012-08-14 21:58:22 +02:00
parent 6399fb19fd
commit ac653761b9

View File

@ -86,7 +86,7 @@ typedef struct
static _glfwJoystick _glfwJoysticks[GLFW_JOYSTICK_LAST + 1]; static _glfwJoystick _glfwJoysticks[GLFW_JOYSTICK_LAST + 1];
void GetElementsCFArrayHandler(const void* value, void* parameter); void getElementsCFArrayHandler(const void* value, void* parameter);
//======================================================================== //========================================================================
@ -112,7 +112,7 @@ static void addJoystickElement(_glfwJoystick* joystick, CFTypeRef refElement)
(elementType == kIOHIDElementTypeInput_Button) || (elementType == kIOHIDElementTypeInput_Button) ||
(elementType == kIOHIDElementTypeInput_Misc)) (elementType == kIOHIDElementTypeInput_Misc))
{ {
switch (usagePage) /* only interested in kHIDPage_GenericDesktop and kHIDPage_Button */ switch (usagePage)
{ {
case kHIDPage_GenericDesktop: case kHIDPage_GenericDesktop:
{ {
@ -175,10 +175,10 @@ static void addJoystickElement(_glfwJoystick* joystick, CFTypeRef refElement)
if (refElementTop) if (refElementTop)
{ {
CFTypeID type = CFGetTypeID (refElementTop); CFTypeID type = CFGetTypeID (refElementTop);
if (type == CFArrayGetTypeID()) /* if element is an array */ if (type == CFArrayGetTypeID())
{ {
CFRange range = {0, CFArrayGetCount (refElementTop)}; CFRange range = {0, CFArrayGetCount (refElementTop)};
CFArrayApplyFunction(refElementTop, range, GetElementsCFArrayHandler, joystick); CFArrayApplyFunction(refElementTop, range, getElementsCFArrayHandler, joystick);
} }
} }
} }
@ -189,7 +189,7 @@ static void addJoystickElement(_glfwJoystick* joystick, CFTypeRef refElement)
// Adds an element to the specified joystick // Adds an element to the specified joystick
//======================================================================== //========================================================================
void GetElementsCFArrayHandler(const void* value, void* parameter) static void getElementsCFArrayHandler(const void* value, void* parameter)
{ {
if (CFGetTypeID(value) == CFDictionaryGetTypeID()) if (CFGetTypeID(value) == CFDictionaryGetTypeID())
addJoystickElement((_glfwJoystick*) parameter, (CFTypeRef) value); addJoystickElement((_glfwJoystick*) parameter, (CFTypeRef) value);
@ -346,7 +346,7 @@ void _glfwInitJoysticks(void)
{ {
if (hidMatchDictionary) if (hidMatchDictionary)
CFRelease(hidMatchDictionary); CFRelease(hidMatchDictionary);
return; return;
} }
@ -356,8 +356,11 @@ void _glfwInitJoysticks(void)
if (result != kIOReturnSuccess) if (result != kIOReturnSuccess)
return; return;
if (!objectIterator) /* there are no joysticks */ if (!objectIterator)
{
// There are no joysticks
return; return;
}
while ((ioHIDDeviceObject = IOIteratorNext(objectIterator))) while ((ioHIDDeviceObject = IOIteratorNext(objectIterator)))
{ {
@ -395,7 +398,7 @@ void _glfwInitJoysticks(void)
if (refCF) if (refCF)
{ {
CFNumberGetValue(refCF, kCFNumberLongType, &usage); CFNumberGetValue(refCF, kCFNumberLongType, &usage);
if ((usage != kHIDUsage_GD_Joystick && if ((usage != kHIDUsage_GD_Joystick &&
usage != kHIDUsage_GD_GamePad && usage != kHIDUsage_GD_GamePad &&
usage != kHIDUsage_GD_MultiAxisController)) usage != kHIDUsage_GD_MultiAxisController))
@ -459,7 +462,7 @@ void _glfwInitJoysticks(void)
CFRange range = { 0, CFArrayGetCount(refTopElement) }; CFRange range = { 0, CFArrayGetCount(refTopElement) };
CFArrayApplyFunction(refTopElement, CFArrayApplyFunction(refTopElement,
range, range,
GetElementsCFArrayHandler, getElementsCFArrayHandler,
(void*) joystick); (void*) joystick);
} }
@ -509,7 +512,8 @@ int _glfwPlatformGetJoystickParam(int joy, int param)
return (int) CFArrayGetCount(_glfwJoysticks[joy].axes); return (int) CFArrayGetCount(_glfwJoysticks[joy].axes);
case GLFW_BUTTONS: case GLFW_BUTTONS:
return (int) CFArrayGetCount(_glfwJoysticks[joy].buttons) + ((int) CFArrayGetCount(_glfwJoysticks[joy].hats)) * 4; return (int) CFArrayGetCount(_glfwJoysticks[joy].buttons) +
(int) CFArrayGetCount(_glfwJoysticks[joy].hats) * 4;
default: default:
break; break;
@ -597,19 +601,28 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons,
// Virtual buttons - Inject data from hats // Virtual buttons - Inject data from hats
// Each hat is exposed as 4 buttons which exposes 8 directions with concurrent button presses // Each hat is exposed as 4 buttons which exposes 8 directions with concurrent button presses
const int directions[9] = { 1, 3, 2, 6, 4, 12, 8, 9, 0 }; // Bit fields of button presses for each direction, including nil // Bit fields of button presses for each direction, including nil
const int directions[9] = { 1, 3, 2, 6, 4, 12, 8, 9, 0 };
for (i = 0; i < joystick.numHats; i++) for (i = 0; i < joystick.numHats; i++)
{ {
_glfwJoystickElement* hat = (_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick.hats, i); _glfwJoystickElement* hat = (_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick.hats, i);
int value = hat->value;
if (value < 0 || value > 8) value = 8;
for (j = 0; j < 4 && button < numbuttons; j++) const int value = hat->value;
if (value < 0 || value > 8)
value = 8;
for (j = 0; j < 4 && button < numbuttons; j++)
{ {
buttons[button++] = directions[value] & (1 << j) ? GLFW_PRESS : GLFW_RELEASE; if (directions[value] & (1 << j))
buttons[button = GLFW_PRESS;
else
buttons[button = GLFW_RELEASE;
button++;
} }
} }
return button; return button;
} }