Squashed 'deps/nostalgia/' changes from dd5d1bfb..976550ef

976550ef [nostalgia/sample_project] Add missing type descriptors
1fb0a866 [nostalgia/core] Fix CompactPalette TypeName and TypeVersion
eb46aeeb [nfde] Fix compiler warnings on Gtk build
9244b735 [nostalgia] Fix non-Linux non-Apple systems not to build GLFW for Wayland
3fba36b4 [nfde] Make only option BUILD_SHARED_LIBS if not already set
6ddb6b42 Merge commit '5461f6700dac79e9e71e3966f8a1270706c385ba'
5461f670 Squashed 'deps/nfde/' changes from 28ade5a5c..5786fabce
1ecc7aa7 Merge commit '26c8cc348eacea01237cd64e1a68d0df8141e848'
26c8cc34 Squashed 'deps/glfw/' changes from 7d5a16ce7..7b6aead9f
fc25c12d Merge commit 'ae51a422787bc3b720ff1748c0219c8f33363427'
ae51a422 Squashed 'deps/imgui/' changes from f33737806..2db79d086
6c71e1e2 [nostalgia/core/studio,studio] Give TileSheetEditor Ctrl-A and Ctrl-G for selection
2ede01e7 [nostalgia/core/studio] Fix build
deacd4ab [nostalgia/core/studio] Fix PaletteEditor add/remove color commands

git-subtree-dir: deps/nostalgia
git-subtree-split: 976550ef6fa269cf1e367e880f148b0ad7b1b163
This commit is contained in:
2024-05-31 20:54:46 -05:00
parent e3cd379bb4
commit 60789230be
374 changed files with 61191 additions and 26808 deletions

452
deps/glfw/src/input.c vendored
View File

@ -1,5 +1,5 @@
//========================================================================
// GLFW 3.3 - www.glfw.org
// GLFW 3.4 - www.glfw.org
//------------------------------------------------------------------------
// Copyright (c) 2002-2006 Marcus Geelnard
// Copyright (c) 2006-2019 Camilla Löwy <elmindreda@glfw.org>
@ -24,8 +24,6 @@
// distribution.
//
//========================================================================
// Please use C89 style variable declarations in this file because VS 2010
//========================================================================
#include "internal.h"
#include "mappings.h"
@ -44,6 +42,29 @@
#define _GLFW_JOYSTICK_BUTTON 2
#define _GLFW_JOYSTICK_HATBIT 3
#define GLFW_MOD_MASK (GLFW_MOD_SHIFT | \
GLFW_MOD_CONTROL | \
GLFW_MOD_ALT | \
GLFW_MOD_SUPER | \
GLFW_MOD_CAPS_LOCK | \
GLFW_MOD_NUM_LOCK)
// Initializes the platform joystick API if it has not been already
//
static GLFWbool initJoysticks(void)
{
if (!_glfw.joysticksInitialized)
{
if (!_glfw.platform.initJoysticks())
{
_glfw.platform.terminateJoysticks();
return GLFW_FALSE;
}
}
return _glfw.joysticksInitialized = GLFW_TRUE;
}
// Finds a mapping based on joystick GUID
//
static _GLFWmapping* findMapping(const char* guid)
@ -218,8 +239,9 @@ static GLFWbool parseMapping(_GLFWmapping* mapping, const char* string)
}
else
{
length = strlen(_GLFW_PLATFORM_MAPPING_NAME);
if (strncmp(c, _GLFW_PLATFORM_MAPPING_NAME, length) != 0)
const char* name = _glfw.platform.getMappingName();
length = strlen(name);
if (strncmp(c, name, length) != 0)
return GLFW_FALSE;
}
@ -236,7 +258,7 @@ static GLFWbool parseMapping(_GLFWmapping* mapping, const char* string)
mapping->guid[i] += 'a' - 'A';
}
_glfwPlatformUpdateGamepadGUID(mapping->guid);
_glfw.platform.updateGamepadGUID(mapping->guid);
return GLFW_TRUE;
}
@ -249,6 +271,12 @@ static GLFWbool parseMapping(_GLFWmapping* mapping, const char* string)
//
void _glfwInputKey(_GLFWwindow* window, int key, int scancode, int action, int mods)
{
assert(window != NULL);
assert(key >= 0 || key == GLFW_KEY_UNKNOWN);
assert(key <= GLFW_KEY_LAST);
assert(action == GLFW_PRESS || action == GLFW_RELEASE);
assert(mods == (mods & GLFW_MOD_MASK));
if (key >= 0 && key <= GLFW_KEY_LAST)
{
GLFWbool repeated = GLFW_FALSE;
@ -278,8 +306,12 @@ void _glfwInputKey(_GLFWwindow* window, int key, int scancode, int action, int m
// Notifies shared code of a Unicode codepoint input event
// The 'plain' parameter determines whether to emit a regular character event
//
void _glfwInputChar(_GLFWwindow* window, unsigned int codepoint, int mods, GLFWbool plain)
void _glfwInputChar(_GLFWwindow* window, uint32_t codepoint, int mods, GLFWbool plain)
{
assert(window != NULL);
assert(mods == (mods & GLFW_MOD_MASK));
assert(plain == GLFW_TRUE || plain == GLFW_FALSE);
if (codepoint < 32 || (codepoint > 126 && codepoint < 160))
return;
@ -300,6 +332,12 @@ void _glfwInputChar(_GLFWwindow* window, unsigned int codepoint, int mods, GLFWb
//
void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset)
{
assert(window != NULL);
assert(xoffset > -FLT_MAX);
assert(xoffset < FLT_MAX);
assert(yoffset > -FLT_MAX);
assert(yoffset < FLT_MAX);
if (window->callbacks.scroll)
window->callbacks.scroll((GLFWwindow*) window, xoffset, yoffset);
}
@ -308,6 +346,12 @@ void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset)
//
void _glfwInputMouseClick(_GLFWwindow* window, int button, int action, int mods)
{
assert(window != NULL);
assert(button >= 0);
assert(button <= GLFW_MOUSE_BUTTON_LAST);
assert(action == GLFW_PRESS || action == GLFW_RELEASE);
assert(mods == (mods & GLFW_MOD_MASK));
if (button < 0 || button > GLFW_MOUSE_BUTTON_LAST)
return;
@ -328,6 +372,12 @@ void _glfwInputMouseClick(_GLFWwindow* window, int button, int action, int mods)
//
void _glfwInputCursorPos(_GLFWwindow* window, double xpos, double ypos)
{
assert(window != NULL);
assert(xpos > -FLT_MAX);
assert(xpos < FLT_MAX);
assert(ypos > -FLT_MAX);
assert(ypos < FLT_MAX);
if (window->virtualCursorPosX == xpos && window->virtualCursorPosY == ypos)
return;
@ -342,6 +392,9 @@ void _glfwInputCursorPos(_GLFWwindow* window, double xpos, double ypos)
//
void _glfwInputCursorEnter(_GLFWwindow* window, GLFWbool entered)
{
assert(window != NULL);
assert(entered == GLFW_TRUE || entered == GLFW_FALSE);
if (window->callbacks.cursorEnter)
window->callbacks.cursorEnter((GLFWwindow*) window, entered);
}
@ -350,6 +403,10 @@ void _glfwInputCursorEnter(_GLFWwindow* window, GLFWbool entered)
//
void _glfwInputDrop(_GLFWwindow* window, int count, const char** paths)
{
assert(window != NULL);
assert(count > 0);
assert(paths != NULL);
if (window->callbacks.drop)
window->callbacks.drop((GLFWwindow*) window, count, paths);
}
@ -358,16 +415,26 @@ void _glfwInputDrop(_GLFWwindow* window, int count, const char** paths)
//
void _glfwInputJoystick(_GLFWjoystick* js, int event)
{
const int jid = (int) (js - _glfw.joysticks);
assert(js != NULL);
assert(event == GLFW_CONNECTED || event == GLFW_DISCONNECTED);
if (event == GLFW_CONNECTED)
js->connected = GLFW_TRUE;
else if (event == GLFW_DISCONNECTED)
js->connected = GLFW_FALSE;
if (_glfw.callbacks.joystick)
_glfw.callbacks.joystick(jid, event);
_glfw.callbacks.joystick((int) (js - _glfw.joysticks), event);
}
// Notifies shared code of the new value of a joystick axis
//
void _glfwInputJoystickAxis(_GLFWjoystick* js, int axis, float value)
{
assert(js != NULL);
assert(axis >= 0);
assert(axis < js->axisCount);
js->axes[axis] = value;
}
@ -375,6 +442,11 @@ void _glfwInputJoystickAxis(_GLFWjoystick* js, int axis, float value)
//
void _glfwInputJoystickButton(_GLFWjoystick* js, int button, char value)
{
assert(js != NULL);
assert(button >= 0);
assert(button < js->buttonCount);
assert(value == GLFW_PRESS || value == GLFW_RELEASE);
js->buttons[button] = value;
}
@ -382,7 +454,19 @@ void _glfwInputJoystickButton(_GLFWjoystick* js, int button, char value)
//
void _glfwInputJoystickHat(_GLFWjoystick* js, int hat, char value)
{
const int base = js->buttonCount + hat * 4;
int base;
assert(js != NULL);
assert(hat >= 0);
assert(hat < js->hatCount);
// Valid hat values only use the least significant nibble
assert((value & 0xf0) == 0);
// Valid hat values do not have both bits of an axis set
assert((value & GLFW_HAT_LEFT) == 0 || (value & GLFW_HAT_RIGHT) == 0);
assert((value & GLFW_HAT_UP) == 0 || (value & GLFW_HAT_DOWN) == 0);
base = js->buttonCount + hat * 4;
js->buttons[base + 0] = (value & 0x01) ? GLFW_PRESS : GLFW_RELEASE;
js->buttons[base + 1] = (value & 0x02) ? GLFW_PRESS : GLFW_RELEASE;
@ -401,23 +485,15 @@ void _glfwInputJoystickHat(_GLFWjoystick* js, int hat, char value)
//
void _glfwInitGamepadMappings(void)
{
int jid;
size_t i;
const size_t count = sizeof(_glfwDefaultMappings) / sizeof(char*);
_glfw.mappings = calloc(count, sizeof(_GLFWmapping));
_glfw.mappings = _glfw_calloc(count, sizeof(_GLFWmapping));
for (i = 0; i < count; i++)
{
if (parseMapping(&_glfw.mappings[_glfw.mappingCount], _glfwDefaultMappings[i]))
_glfw.mappingCount++;
}
for (jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++)
{
_GLFWjoystick* js = _glfw.joysticks + jid;
if (js->present)
js->mapping = findValidMapping(js);
}
}
// Returns an available joystick object with arrays and name allocated
@ -433,7 +509,7 @@ _GLFWjoystick* _glfwAllocJoystick(const char* name,
for (jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++)
{
if (!_glfw.joysticks[jid].present)
if (!_glfw.joysticks[jid].allocated)
break;
}
@ -441,10 +517,10 @@ _GLFWjoystick* _glfwAllocJoystick(const char* name,
return NULL;
js = _glfw.joysticks + jid;
js->present = GLFW_TRUE;
js->axes = calloc(axisCount, sizeof(float));
js->buttons = calloc(buttonCount + (size_t) hatCount * 4, 1);
js->hats = calloc(hatCount, 1);
js->allocated = GLFW_TRUE;
js->axes = _glfw_calloc(axisCount, sizeof(float));
js->buttons = _glfw_calloc(buttonCount + (size_t) hatCount * 4, 1);
js->hats = _glfw_calloc(hatCount, 1);
js->axisCount = axisCount;
js->buttonCount = buttonCount;
js->hatCount = hatCount;
@ -460,9 +536,9 @@ _GLFWjoystick* _glfwAllocJoystick(const char* name,
//
void _glfwFreeJoystick(_GLFWjoystick* js)
{
free(js->axes);
free(js->buttons);
free(js->hats);
_glfw_free(js->axes);
_glfw_free(js->buttons);
_glfw_free(js->hats);
memset(js, 0, sizeof(_GLFWjoystick));
}
@ -472,8 +548,8 @@ void _glfwCenterCursorInContentArea(_GLFWwindow* window)
{
int width, height;
_glfwPlatformGetWindowSize(window, &width, &height);
_glfwPlatformSetCursorPos(window, width / 2.0, height / 2.0);
_glfw.platform.getWindowSize(window, &width, &height);
_glfw.platform.setCursorPos(window, width / 2.0, height / 2.0);
}
@ -513,96 +589,109 @@ GLFWAPI void glfwSetInputMode(GLFWwindow* handle, int mode, int value)
_GLFW_REQUIRE_INIT();
if (mode == GLFW_CURSOR)
switch (mode)
{
if (value != GLFW_CURSOR_NORMAL &&
value != GLFW_CURSOR_HIDDEN &&
value != GLFW_CURSOR_DISABLED)
case GLFW_CURSOR:
{
_glfwInputError(GLFW_INVALID_ENUM,
"Invalid cursor mode 0x%08X",
value);
return;
}
if (window->cursorMode == value)
return;
window->cursorMode = value;
_glfwPlatformGetCursorPos(window,
&window->virtualCursorPosX,
&window->virtualCursorPosY);
_glfwPlatformSetCursorMode(window, value);
}
else if (mode == GLFW_STICKY_KEYS)
{
value = value ? GLFW_TRUE : GLFW_FALSE;
if (window->stickyKeys == value)
return;
if (!value)
{
int i;
// Release all sticky keys
for (i = 0; i <= GLFW_KEY_LAST; i++)
if (value != GLFW_CURSOR_NORMAL &&
value != GLFW_CURSOR_HIDDEN &&
value != GLFW_CURSOR_DISABLED &&
value != GLFW_CURSOR_CAPTURED)
{
if (window->keys[i] == _GLFW_STICK)
window->keys[i] = GLFW_RELEASE;
_glfwInputError(GLFW_INVALID_ENUM,
"Invalid cursor mode 0x%08X",
value);
return;
}
if (window->cursorMode == value)
return;
window->cursorMode = value;
_glfw.platform.getCursorPos(window,
&window->virtualCursorPosX,
&window->virtualCursorPosY);
_glfw.platform.setCursorMode(window, value);
return;
}
window->stickyKeys = value;
}
else if (mode == GLFW_STICKY_MOUSE_BUTTONS)
{
value = value ? GLFW_TRUE : GLFW_FALSE;
if (window->stickyMouseButtons == value)
return;
if (!value)
case GLFW_STICKY_KEYS:
{
int i;
value = value ? GLFW_TRUE : GLFW_FALSE;
if (window->stickyKeys == value)
return;
// Release all sticky mouse buttons
for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++)
if (!value)
{
if (window->mouseButtons[i] == _GLFW_STICK)
window->mouseButtons[i] = GLFW_RELEASE;
int i;
// Release all sticky keys
for (i = 0; i <= GLFW_KEY_LAST; i++)
{
if (window->keys[i] == _GLFW_STICK)
window->keys[i] = GLFW_RELEASE;
}
}
window->stickyKeys = value;
return;
}
window->stickyMouseButtons = value;
}
else if (mode == GLFW_LOCK_KEY_MODS)
{
window->lockKeyMods = value ? GLFW_TRUE : GLFW_FALSE;
}
else if (mode == GLFW_RAW_MOUSE_MOTION)
{
if (!_glfwPlatformRawMouseMotionSupported())
case GLFW_STICKY_MOUSE_BUTTONS:
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Raw mouse motion is not supported on this system");
value = value ? GLFW_TRUE : GLFW_FALSE;
if (window->stickyMouseButtons == value)
return;
if (!value)
{
int i;
// Release all sticky mouse buttons
for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++)
{
if (window->mouseButtons[i] == _GLFW_STICK)
window->mouseButtons[i] = GLFW_RELEASE;
}
}
window->stickyMouseButtons = value;
return;
}
value = value ? GLFW_TRUE : GLFW_FALSE;
if (window->rawMouseMotion == value)
case GLFW_LOCK_KEY_MODS:
{
window->lockKeyMods = value ? GLFW_TRUE : GLFW_FALSE;
return;
}
window->rawMouseMotion = value;
_glfwPlatformSetRawMouseMotion(window, value);
case GLFW_RAW_MOUSE_MOTION:
{
if (!_glfw.platform.rawMouseMotionSupported())
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Raw mouse motion is not supported on this system");
return;
}
value = value ? GLFW_TRUE : GLFW_FALSE;
if (window->rawMouseMotion == value)
return;
window->rawMouseMotion = value;
_glfw.platform.setRawMouseMotion(window, value);
return;
}
}
else
_glfwInputError(GLFW_INVALID_ENUM, "Invalid input mode 0x%08X", mode);
_glfwInputError(GLFW_INVALID_ENUM, "Invalid input mode 0x%08X", mode);
}
GLFWAPI int glfwRawMouseMotionSupported(void)
{
_GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE);
return _glfwPlatformRawMouseMotionSupported();
return _glfw.platform.rawMouseMotionSupported();
}
GLFWAPI const char* glfwGetKeyName(int key, int scancode)
@ -611,6 +700,12 @@ GLFWAPI const char* glfwGetKeyName(int key, int scancode)
if (key != GLFW_KEY_UNKNOWN)
{
if (key < GLFW_KEY_SPACE || key > GLFW_KEY_LAST)
{
_glfwInputError(GLFW_INVALID_ENUM, "Invalid key %i", key);
return NULL;
}
if (key != GLFW_KEY_KP_EQUAL &&
(key < GLFW_KEY_KP_0 || key > GLFW_KEY_KP_ADD) &&
(key < GLFW_KEY_APOSTROPHE || key > GLFW_KEY_WORLD_2))
@ -618,23 +713,23 @@ GLFWAPI const char* glfwGetKeyName(int key, int scancode)
return NULL;
}
scancode = _glfwPlatformGetKeyScancode(key);
scancode = _glfw.platform.getKeyScancode(key);
}
return _glfwPlatformGetScancodeName(scancode);
return _glfw.platform.getScancodeName(scancode);
}
GLFWAPI int glfwGetKeyScancode(int key)
{
_GLFW_REQUIRE_INIT_OR_RETURN(-1);
_GLFW_REQUIRE_INIT_OR_RETURN(0);
if (key < GLFW_KEY_SPACE || key > GLFW_KEY_LAST)
{
_glfwInputError(GLFW_INVALID_ENUM, "Invalid key %i", key);
return GLFW_RELEASE;
return -1;
}
return _glfwPlatformGetKeyScancode(key);
return _glfw.platform.getKeyScancode(key);
}
GLFWAPI int glfwGetKey(GLFWwindow* handle, int key)
@ -703,7 +798,7 @@ GLFWAPI void glfwGetCursorPos(GLFWwindow* handle, double* xpos, double* ypos)
*ypos = window->virtualCursorPosY;
}
else
_glfwPlatformGetCursorPos(window, xpos, ypos);
_glfw.platform.getCursorPos(window, xpos, ypos);
}
GLFWAPI void glfwSetCursorPos(GLFWwindow* handle, double xpos, double ypos)
@ -722,7 +817,7 @@ GLFWAPI void glfwSetCursorPos(GLFWwindow* handle, double xpos, double ypos)
return;
}
if (!_glfwPlatformWindowFocused(window))
if (!_glfw.platform.windowFocused(window))
return;
if (window->cursorMode == GLFW_CURSOR_DISABLED)
@ -734,7 +829,7 @@ GLFWAPI void glfwSetCursorPos(GLFWwindow* handle, double xpos, double ypos)
else
{
// Update system cursor position
_glfwPlatformSetCursorPos(window, xpos, ypos);
_glfw.platform.setCursorPos(window, xpos, ypos);
}
}
@ -743,14 +838,21 @@ GLFWAPI GLFWcursor* glfwCreateCursor(const GLFWimage* image, int xhot, int yhot)
_GLFWcursor* cursor;
assert(image != NULL);
assert(image->pixels != NULL);
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
cursor = calloc(1, sizeof(_GLFWcursor));
if (image->width <= 0 || image->height <= 0)
{
_glfwInputError(GLFW_INVALID_VALUE, "Invalid image dimensions for cursor");
return NULL;
}
cursor = _glfw_calloc(1, sizeof(_GLFWcursor));
cursor->next = _glfw.cursorListHead;
_glfw.cursorListHead = cursor;
if (!_glfwPlatformCreateCursor(cursor, image, xhot, yhot))
if (!_glfw.platform.createCursor(cursor, image, xhot, yhot))
{
glfwDestroyCursor((GLFWcursor*) cursor);
return NULL;
@ -768,19 +870,23 @@ GLFWAPI GLFWcursor* glfwCreateStandardCursor(int shape)
if (shape != GLFW_ARROW_CURSOR &&
shape != GLFW_IBEAM_CURSOR &&
shape != GLFW_CROSSHAIR_CURSOR &&
shape != GLFW_HAND_CURSOR &&
shape != GLFW_HRESIZE_CURSOR &&
shape != GLFW_VRESIZE_CURSOR)
shape != GLFW_POINTING_HAND_CURSOR &&
shape != GLFW_RESIZE_EW_CURSOR &&
shape != GLFW_RESIZE_NS_CURSOR &&
shape != GLFW_RESIZE_NWSE_CURSOR &&
shape != GLFW_RESIZE_NESW_CURSOR &&
shape != GLFW_RESIZE_ALL_CURSOR &&
shape != GLFW_NOT_ALLOWED_CURSOR)
{
_glfwInputError(GLFW_INVALID_ENUM, "Invalid standard cursor 0x%08X", shape);
return NULL;
}
cursor = calloc(1, sizeof(_GLFWcursor));
cursor = _glfw_calloc(1, sizeof(_GLFWcursor));
cursor->next = _glfw.cursorListHead;
_glfw.cursorListHead = cursor;
if (!_glfwPlatformCreateStandardCursor(cursor, shape))
if (!_glfw.platform.createStandardCursor(cursor, shape))
{
glfwDestroyCursor((GLFWcursor*) cursor);
return NULL;
@ -809,7 +915,7 @@ GLFWAPI void glfwDestroyCursor(GLFWcursor* handle)
}
}
_glfwPlatformDestroyCursor(cursor);
_glfw.platform.destroyCursor(cursor);
// Unlink cursor from global linked list
{
@ -821,7 +927,7 @@ GLFWAPI void glfwDestroyCursor(GLFWcursor* handle)
*prev = cursor->next;
}
free(cursor);
_glfw_free(cursor);
}
GLFWAPI void glfwSetCursor(GLFWwindow* windowHandle, GLFWcursor* cursorHandle)
@ -834,7 +940,7 @@ GLFWAPI void glfwSetCursor(GLFWwindow* windowHandle, GLFWcursor* cursorHandle)
window->cursor = cursor;
_glfwPlatformSetCursor(window, cursor);
_glfw.platform.setCursor(window, cursor);
}
GLFWAPI GLFWkeyfun glfwSetKeyCallback(GLFWwindow* handle, GLFWkeyfun cbfun)
@ -843,7 +949,7 @@ GLFWAPI GLFWkeyfun glfwSetKeyCallback(GLFWwindow* handle, GLFWkeyfun cbfun)
assert(window != NULL);
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
_GLFW_SWAP_POINTERS(window->callbacks.key, cbfun);
_GLFW_SWAP(GLFWkeyfun, window->callbacks.key, cbfun);
return cbfun;
}
@ -853,7 +959,7 @@ GLFWAPI GLFWcharfun glfwSetCharCallback(GLFWwindow* handle, GLFWcharfun cbfun)
assert(window != NULL);
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
_GLFW_SWAP_POINTERS(window->callbacks.character, cbfun);
_GLFW_SWAP(GLFWcharfun, window->callbacks.character, cbfun);
return cbfun;
}
@ -863,7 +969,7 @@ GLFWAPI GLFWcharmodsfun glfwSetCharModsCallback(GLFWwindow* handle, GLFWcharmods
assert(window != NULL);
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
_GLFW_SWAP_POINTERS(window->callbacks.charmods, cbfun);
_GLFW_SWAP(GLFWcharmodsfun, window->callbacks.charmods, cbfun);
return cbfun;
}
@ -874,7 +980,7 @@ GLFWAPI GLFWmousebuttonfun glfwSetMouseButtonCallback(GLFWwindow* handle,
assert(window != NULL);
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
_GLFW_SWAP_POINTERS(window->callbacks.mouseButton, cbfun);
_GLFW_SWAP(GLFWmousebuttonfun, window->callbacks.mouseButton, cbfun);
return cbfun;
}
@ -885,7 +991,7 @@ GLFWAPI GLFWcursorposfun glfwSetCursorPosCallback(GLFWwindow* handle,
assert(window != NULL);
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
_GLFW_SWAP_POINTERS(window->callbacks.cursorPos, cbfun);
_GLFW_SWAP(GLFWcursorposfun, window->callbacks.cursorPos, cbfun);
return cbfun;
}
@ -896,7 +1002,7 @@ GLFWAPI GLFWcursorenterfun glfwSetCursorEnterCallback(GLFWwindow* handle,
assert(window != NULL);
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
_GLFW_SWAP_POINTERS(window->callbacks.cursorEnter, cbfun);
_GLFW_SWAP(GLFWcursorenterfun, window->callbacks.cursorEnter, cbfun);
return cbfun;
}
@ -907,7 +1013,7 @@ GLFWAPI GLFWscrollfun glfwSetScrollCallback(GLFWwindow* handle,
assert(window != NULL);
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
_GLFW_SWAP_POINTERS(window->callbacks.scroll, cbfun);
_GLFW_SWAP(GLFWscrollfun, window->callbacks.scroll, cbfun);
return cbfun;
}
@ -917,7 +1023,7 @@ GLFWAPI GLFWdropfun glfwSetDropCallback(GLFWwindow* handle, GLFWdropfun cbfun)
assert(window != NULL);
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
_GLFW_SWAP_POINTERS(window->callbacks.drop, cbfun);
_GLFW_SWAP(GLFWdropfun, window->callbacks.drop, cbfun);
return cbfun;
}
@ -936,11 +1042,14 @@ GLFWAPI int glfwJoystickPresent(int jid)
return GLFW_FALSE;
}
js = _glfw.joysticks + jid;
if (!js->present)
if (!initJoysticks())
return GLFW_FALSE;
return _glfwPlatformPollJoystick(js, _GLFW_POLL_PRESENCE);
js = _glfw.joysticks + jid;
if (!js->connected)
return GLFW_FALSE;
return _glfw.platform.pollJoystick(js, _GLFW_POLL_PRESENCE);
}
GLFWAPI const float* glfwGetJoystickAxes(int jid, int* count)
@ -961,11 +1070,14 @@ GLFWAPI const float* glfwGetJoystickAxes(int jid, int* count)
return NULL;
}
js = _glfw.joysticks + jid;
if (!js->present)
if (!initJoysticks())
return NULL;
if (!_glfwPlatformPollJoystick(js, _GLFW_POLL_AXES))
js = _glfw.joysticks + jid;
if (!js->connected)
return NULL;
if (!_glfw.platform.pollJoystick(js, _GLFW_POLL_AXES))
return NULL;
*count = js->axisCount;
@ -990,11 +1102,14 @@ GLFWAPI const unsigned char* glfwGetJoystickButtons(int jid, int* count)
return NULL;
}
js = _glfw.joysticks + jid;
if (!js->present)
if (!initJoysticks())
return NULL;
if (!_glfwPlatformPollJoystick(js, _GLFW_POLL_BUTTONS))
js = _glfw.joysticks + jid;
if (!js->connected)
return NULL;
if (!_glfw.platform.pollJoystick(js, _GLFW_POLL_BUTTONS))
return NULL;
if (_glfw.hints.init.hatButtons)
@ -1023,11 +1138,14 @@ GLFWAPI const unsigned char* glfwGetJoystickHats(int jid, int* count)
return NULL;
}
js = _glfw.joysticks + jid;
if (!js->present)
if (!initJoysticks())
return NULL;
if (!_glfwPlatformPollJoystick(js, _GLFW_POLL_BUTTONS))
js = _glfw.joysticks + jid;
if (!js->connected)
return NULL;
if (!_glfw.platform.pollJoystick(js, _GLFW_POLL_BUTTONS))
return NULL;
*count = js->hatCount;
@ -1049,11 +1167,14 @@ GLFWAPI const char* glfwGetJoystickName(int jid)
return NULL;
}
js = _glfw.joysticks + jid;
if (!js->present)
if (!initJoysticks())
return NULL;
if (!_glfwPlatformPollJoystick(js, _GLFW_POLL_PRESENCE))
js = _glfw.joysticks + jid;
if (!js->connected)
return NULL;
if (!_glfw.platform.pollJoystick(js, _GLFW_POLL_PRESENCE))
return NULL;
return js->name;
@ -1074,11 +1195,14 @@ GLFWAPI const char* glfwGetJoystickGUID(int jid)
return NULL;
}
js = _glfw.joysticks + jid;
if (!js->present)
if (!initJoysticks())
return NULL;
if (!_glfwPlatformPollJoystick(js, _GLFW_POLL_PRESENCE))
js = _glfw.joysticks + jid;
if (!js->connected)
return NULL;
if (!_glfw.platform.pollJoystick(js, _GLFW_POLL_PRESENCE))
return NULL;
return js->guid;
@ -1094,7 +1218,7 @@ GLFWAPI void glfwSetJoystickUserPointer(int jid, void* pointer)
_GLFW_REQUIRE_INIT();
js = _glfw.joysticks + jid;
if (!js->present)
if (!js->allocated)
return;
js->userPointer = pointer;
@ -1110,7 +1234,7 @@ GLFWAPI void* glfwGetJoystickUserPointer(int jid)
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
js = _glfw.joysticks + jid;
if (!js->present)
if (!js->allocated)
return NULL;
return js->userPointer;
@ -1119,7 +1243,11 @@ GLFWAPI void* glfwGetJoystickUserPointer(int jid)
GLFWAPI GLFWjoystickfun glfwSetJoystickCallback(GLFWjoystickfun cbfun)
{
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
_GLFW_SWAP_POINTERS(_glfw.callbacks.joystick, cbfun);
if (!initJoysticks())
return NULL;
_GLFW_SWAP(GLFWjoystickfun, _glfw.callbacks.joystick, cbfun);
return cbfun;
}
@ -1157,8 +1285,8 @@ GLFWAPI int glfwUpdateGamepadMappings(const char* string)
{
_glfw.mappingCount++;
_glfw.mappings =
realloc(_glfw.mappings,
sizeof(_GLFWmapping) * _glfw.mappingCount);
_glfw_realloc(_glfw.mappings,
sizeof(_GLFWmapping) * _glfw.mappingCount);
_glfw.mappings[_glfw.mappingCount - 1] = mapping;
}
}
@ -1176,7 +1304,7 @@ GLFWAPI int glfwUpdateGamepadMappings(const char* string)
for (jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++)
{
_GLFWjoystick* js = _glfw.joysticks + jid;
if (js->present)
if (js->connected)
js->mapping = findValidMapping(js);
}
@ -1198,11 +1326,14 @@ GLFWAPI int glfwJoystickIsGamepad(int jid)
return GLFW_FALSE;
}
js = _glfw.joysticks + jid;
if (!js->present)
if (!initJoysticks())
return GLFW_FALSE;
if (!_glfwPlatformPollJoystick(js, _GLFW_POLL_PRESENCE))
js = _glfw.joysticks + jid;
if (!js->connected)
return GLFW_FALSE;
if (!_glfw.platform.pollJoystick(js, _GLFW_POLL_PRESENCE))
return GLFW_FALSE;
return js->mapping != NULL;
@ -1223,11 +1354,14 @@ GLFWAPI const char* glfwGetGamepadName(int jid)
return NULL;
}
js = _glfw.joysticks + jid;
if (!js->present)
if (!initJoysticks())
return NULL;
if (!_glfwPlatformPollJoystick(js, _GLFW_POLL_PRESENCE))
js = _glfw.joysticks + jid;
if (!js->connected)
return NULL;
if (!_glfw.platform.pollJoystick(js, _GLFW_POLL_PRESENCE))
return NULL;
if (!js->mapping)
@ -1255,11 +1389,14 @@ GLFWAPI int glfwGetGamepadState(int jid, GLFWgamepadstate* state)
return GLFW_FALSE;
}
js = _glfw.joysticks + jid;
if (!js->present)
if (!initJoysticks())
return GLFW_FALSE;
if (!_glfwPlatformPollJoystick(js, _GLFW_POLL_ALL))
js = _glfw.joysticks + jid;
if (!js->connected)
return GLFW_FALSE;
if (!_glfw.platform.pollJoystick(js, _GLFW_POLL_ALL))
return GLFW_FALSE;
if (!js->mapping)
@ -1301,7 +1438,7 @@ GLFWAPI int glfwGetGamepadState(int jid, GLFWgamepadstate* state)
if (e->type == _GLFW_JOYSTICK_AXIS)
{
const float value = js->axes[e->index] * e->axisScale + e->axisOffset;
state->axes[i] = _glfw_fminf(_glfw_fmaxf(value, -1.f), 1.f);
state->axes[i] = fminf(fmaxf(value, -1.f), 1.f);
}
else if (e->type == _GLFW_JOYSTICK_HATBIT)
{
@ -1324,13 +1461,13 @@ GLFWAPI void glfwSetClipboardString(GLFWwindow* handle, const char* string)
assert(string != NULL);
_GLFW_REQUIRE_INIT();
_glfwPlatformSetClipboardString(string);
_glfw.platform.setClipboardString(string);
}
GLFWAPI const char* glfwGetClipboardString(GLFWwindow* handle)
{
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
return _glfwPlatformGetClipboardString();
return _glfw.platform.getClipboardString();
}
GLFWAPI double glfwGetTime(void)
@ -1365,3 +1502,4 @@ GLFWAPI uint64_t glfwGetTimerFrequency(void)
_GLFW_REQUIRE_INIT_OR_RETURN(0);
return _glfwPlatformGetTimerFrequency();
}