1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-26 20:28:49 -05:00

Added stubs, implemented on Linux and Cocoa.

This commit is contained in:
Camilla Berglund 2012-09-07 01:01:34 +02:00
parent 8cf093a19d
commit 93a1d1c226
8 changed files with 76 additions and 7 deletions

View File

@ -566,6 +566,7 @@ GLFWAPI void glfwSetScrollCallback(GLFWscrollfun cbfun);
GLFWAPI int glfwGetJoystickParam(int joy, int param);
GLFWAPI int glfwGetJoystickAxes(int joy, float* axes, int numaxes);
GLFWAPI int glfwGetJoystickButtons(int joy, unsigned char* buttons, int numbuttons);
GLFWAPI const char* glfwGetJoystickName(int joy);
/* Clipboard */
GLFWAPI void glfwSetClipboardString(GLFWwindow window, const char* string);

View File

@ -443,9 +443,9 @@ void _glfwInitJoysticks(void)
if (refCF)
{
CFStringGetCString(refCF,
(char*) &(joystick->product),
256,
CFStringGetSystemEncoding());
joystick->product,
sizeof(joystick->product),
kCFStringEncodingUTF8);
}
joystick->numAxes = 0;
@ -625,3 +625,13 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons,
return button;
}
//========================================================================
// Get joystick name
//========================================================================
const char* _glfwPlatformGetJoystickName(int joy)
{
return _glfwJoysticks[joy].product;
}

View File

@ -274,6 +274,7 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window);
int _glfwPlatformGetJoystickParam(int joy, int param);
int _glfwPlatformGetJoystickAxes(int joy, float* axes, int numaxes);
int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons, int numbuttons);
const char* _glfwPlatformGetJoystickName(int joy);
// Time input
double _glfwPlatformGetTime(void);

View File

@ -126,3 +126,25 @@ GLFWAPI int glfwGetJoystickButtons(int joy,
return _glfwPlatformGetJoystickButtons(joy, buttons, numbuttons);
}
//========================================================================
// Get joystick name
//========================================================================
GLFWAPI const char* glfwGetJoystickName(int joy)
{
if (!_glfwInitialized)
{
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return 0;
}
if (joy < 0 || joy > GLFW_JOYSTICK_LAST)
{
_glfwSetError(GLFW_INVALID_ENUM, NULL);
return 0;
}
return _glfwPlatformGetJoystickName(joy);
}

View File

@ -211,3 +211,14 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons,
return button;
}
//========================================================================
// Get joystick name
//========================================================================
const char* _glfwPlatformGetJoystickName(int joy)
{
return "";
}

View File

@ -40,6 +40,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#endif // _GLFW_USE_LINUX_JOYSTICKS
@ -51,6 +52,7 @@ static int openJoystickDevice(int joy, const char* path)
{
#ifdef _GLFW_USE_LINUX_JOYSTICKS
char numAxes, numButtons;
char name[256];
int fd, version;
fd = open(path, O_RDONLY | O_NONBLOCK);
@ -68,6 +70,11 @@ static int openJoystickDevice(int joy, const char* path)
return GL_FALSE;
}
if (ioctl(fd, JSIOCGNAME(sizeof(name)), name) < 0)
strncpy(name, "Unknown", sizeof(name));
_glfwLibrary.X11.joystick[joy].name = strdup(name);
ioctl(fd, JSIOCGAXES, &numAxes);
_glfwLibrary.X11.joystick[joy].numAxes = (int) numAxes;
@ -214,6 +221,7 @@ void _glfwTerminateJoysticks(void)
close(_glfwLibrary.X11.joystick[i].fd);
free(_glfwLibrary.X11.joystick[i].axis);
free(_glfwLibrary.X11.joystick[i].button);
free(_glfwLibrary.X11.joystick[i].name);
_glfwLibrary.X11.joystick[i].present = GL_FALSE;
}
@ -302,3 +310,13 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons,
return numButtons;
}
//========================================================================
// Get joystick name
//========================================================================
const char* _glfwPlatformGetJoystickName(int joy)
{
return _glfwLibrary.X11.joystick[joy].name;
}

View File

@ -240,6 +240,7 @@ typedef struct _GLFWlibraryX11
int numButtons;
float* axis;
unsigned char* button;
char* name;
} joystick[GLFW_JOYSTICK_LAST + 1];
} _GLFWlibraryX11;

View File

@ -37,6 +37,7 @@
typedef struct Joystick
{
GLboolean present;
char* name;
float* axes;
unsigned char* buttons;
int axis_count;
@ -130,6 +131,9 @@ static void refresh_joysticks(void)
{
int axis_count, button_count;
free(j->name);
j->name = strdup(glfwGetJoystickName(GLFW_JOYSTICK_1 + i));
axis_count = glfwGetJoystickParam(GLFW_JOYSTICK_1 + i, GLFW_AXES);
if (axis_count != j->axis_count)
{
@ -150,8 +154,8 @@ static void refresh_joysticks(void)
if (!j->present)
{
printf("Found joystick %i with %i axes, %i buttons\n",
i + 1, j->axis_count, j->button_count);
printf("Found joystick %i named \'%s\' with %i axes, %i buttons\n",
i + 1, j->name, j->axis_count, j->button_count);
joystick_count++;
}
@ -162,12 +166,13 @@ static void refresh_joysticks(void)
{
if (j->present)
{
printf("Lost joystick %i named \'%s\'\n", i + 1, j->name);
free(j->name);
free(j->axes);
free(j->buttons);
memset(j, 0, sizeof(Joystick));
printf("Lost joystick %i\n", i + 1);
joystick_count--;
}
}