Wise&mystical  1.0
Project about Europe
Loading...
Searching...
No Matches
input.c
Go to the documentation of this file.
1//========================================================================
2// GLFW 3.4 - www.glfw.org
3//------------------------------------------------------------------------
4// Copyright (c) 2002-2006 Marcus Geelnard
5// Copyright (c) 2006-2019 Camilla Löwy <elmindreda@glfw.org>
6//
7// This software is provided 'as-is', without any express or implied
8// warranty. In no event will the authors be held liable for any damages
9// arising from the use of this software.
10//
11// Permission is granted to anyone to use this software for any purpose,
12// including commercial applications, and to alter it and redistribute it
13// freely, subject to the following restrictions:
14//
15// 1. The origin of this software must not be misrepresented; you must not
16// claim that you wrote the original software. If you use this software
17// in a product, an acknowledgment in the product documentation would
18// be appreciated but is not required.
19//
20// 2. Altered source versions must be plainly marked as such, and must not
21// be misrepresented as being the original software.
22//
23// 3. This notice may not be removed or altered from any source
24// distribution.
25//
26//========================================================================
27// Please use C89 style variable declarations in this file because VS 2010
28//========================================================================
29
30#include "internal.h"
31
32#include <assert.h>
33#include <float.h>
34#include <math.h>
35#include <stdlib.h>
36#include <string.h>
37
38// Internal key state used for sticky keys
39#define _GLFW_STICK 3
40
41// Internal constants for gamepad mapping source types
42#define _GLFW_JOYSTICK_AXIS 1
43#define _GLFW_JOYSTICK_BUTTON 2
44#define _GLFW_JOYSTICK_HATBIT 3
45
46// Initializes the platform joystick API if it has not been already
47//
48static GLFWbool initJoysticks(void)
49{
51 {
53 {
55 return GLFW_FALSE;
56 }
57 }
58
60}
61
62// Finds a mapping based on joystick GUID
63//
64static _GLFWmapping* findMapping(const char* guid)
65{
66 int i;
67
68 for (i = 0; i < _glfw.mappingCount; i++)
69 {
70 if (strcmp(_glfw.mappings[i].guid, guid) == 0)
71 return _glfw.mappings + i;
72 }
73
74 return NULL;
75}
76
77// Checks whether a gamepad mapping element is present in the hardware
78//
79static GLFWbool isValidElementForJoystick(const _GLFWmapelement* e,
80 const _GLFWjoystick* js)
81{
82 if (e->type == _GLFW_JOYSTICK_HATBIT && (e->index >> 4) >= js->hatCount)
83 return GLFW_FALSE;
84 else if (e->type == _GLFW_JOYSTICK_BUTTON && e->index >= js->buttonCount)
85 return GLFW_FALSE;
86 else if (e->type == _GLFW_JOYSTICK_AXIS && e->index >= js->axisCount)
87 return GLFW_FALSE;
88
89 return GLFW_TRUE;
90}
91
92// Finds a mapping based on joystick GUID and verifies element indices
93//
94static _GLFWmapping* findValidMapping(const _GLFWjoystick* js)
95{
96 _GLFWmapping* mapping = findMapping(js->guid);
97 if (mapping)
98 {
99 int i;
100
101 for (i = 0; i <= GLFW_GAMEPAD_BUTTON_LAST; i++)
102 {
103 if (!isValidElementForJoystick(mapping->buttons + i, js))
104 {
106 "Invalid button in gamepad mapping %s (%s)",
107 mapping->guid,
108 mapping->name);
109 return NULL;
110 }
111 }
112
113 for (i = 0; i <= GLFW_GAMEPAD_AXIS_LAST; i++)
114 {
115 if (!isValidElementForJoystick(mapping->axes + i, js))
116 {
118 "Invalid axis in gamepad mapping %s (%s)",
119 mapping->guid,
120 mapping->name);
121 return NULL;
122 }
123 }
124 }
125
126 return mapping;
127}
128
129// Parses an SDL_GameControllerDB line and adds it to the mapping list
130//
131static GLFWbool parseMapping(_GLFWmapping* mapping, const char* string)
132{
133 const char* c = string;
134 size_t i, length;
135 struct
136 {
137 const char* name;
138 _GLFWmapelement* element;
139 } fields[] =
140 {
141 { "platform", NULL },
142 { "a", mapping->buttons + GLFW_GAMEPAD_BUTTON_A },
143 { "b", mapping->buttons + GLFW_GAMEPAD_BUTTON_B },
144 { "x", mapping->buttons + GLFW_GAMEPAD_BUTTON_X },
145 { "y", mapping->buttons + GLFW_GAMEPAD_BUTTON_Y },
146 { "back", mapping->buttons + GLFW_GAMEPAD_BUTTON_BACK },
147 { "start", mapping->buttons + GLFW_GAMEPAD_BUTTON_START },
148 { "guide", mapping->buttons + GLFW_GAMEPAD_BUTTON_GUIDE },
149 { "leftshoulder", mapping->buttons + GLFW_GAMEPAD_BUTTON_LEFT_BUMPER },
150 { "rightshoulder", mapping->buttons + GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER },
151 { "leftstick", mapping->buttons + GLFW_GAMEPAD_BUTTON_LEFT_THUMB },
152 { "rightstick", mapping->buttons + GLFW_GAMEPAD_BUTTON_RIGHT_THUMB },
153 { "dpup", mapping->buttons + GLFW_GAMEPAD_BUTTON_DPAD_UP },
154 { "dpright", mapping->buttons + GLFW_GAMEPAD_BUTTON_DPAD_RIGHT },
155 { "dpdown", mapping->buttons + GLFW_GAMEPAD_BUTTON_DPAD_DOWN },
156 { "dpleft", mapping->buttons + GLFW_GAMEPAD_BUTTON_DPAD_LEFT },
157 { "lefttrigger", mapping->axes + GLFW_GAMEPAD_AXIS_LEFT_TRIGGER },
158 { "righttrigger", mapping->axes + GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER },
159 { "leftx", mapping->axes + GLFW_GAMEPAD_AXIS_LEFT_X },
160 { "lefty", mapping->axes + GLFW_GAMEPAD_AXIS_LEFT_Y },
161 { "rightx", mapping->axes + GLFW_GAMEPAD_AXIS_RIGHT_X },
162 { "righty", mapping->axes + GLFW_GAMEPAD_AXIS_RIGHT_Y }
163 };
164
165 length = strcspn(c, ",");
166 if (length != 32 || c[length] != ',')
167 {
169 return GLFW_FALSE;
170 }
171
172 memcpy(mapping->guid, c, length);
173 c += length + 1;
174
175 length = strcspn(c, ",");
176 if (length >= sizeof(mapping->name) || c[length] != ',')
177 {
179 return GLFW_FALSE;
180 }
181
182 memcpy(mapping->name, c, length);
183 c += length + 1;
184
185 while (*c)
186 {
187 // TODO: Implement output modifiers
188 if (*c == '+' || *c == '-')
189 return GLFW_FALSE;
190
191 for (i = 0; i < sizeof(fields) / sizeof(fields[0]); i++)
192 {
193 length = strlen(fields[i].name);
194 if (strncmp(c, fields[i].name, length) != 0 || c[length] != ':')
195 continue;
196
197 c += length + 1;
198
199 if (fields[i].element)
200 {
201 _GLFWmapelement* e = fields[i].element;
202 int8_t minimum = -1;
203 int8_t maximum = 1;
204
205 if (*c == '+')
206 {
207 minimum = 0;
208 c += 1;
209 }
210 else if (*c == '-')
211 {
212 maximum = 0;
213 c += 1;
214 }
215
216 if (*c == 'a')
218 else if (*c == 'b')
220 else if (*c == 'h')
222 else
223 break;
224
225 if (e->type == _GLFW_JOYSTICK_HATBIT)
226 {
227 const unsigned long hat = strtoul(c + 1, (char**) &c, 10);
228 const unsigned long bit = strtoul(c + 1, (char**) &c, 10);
229 e->index = (uint8_t) ((hat << 4) | bit);
230 }
231 else
232 e->index = (uint8_t) strtoul(c + 1, (char**) &c, 10);
233
234 if (e->type == _GLFW_JOYSTICK_AXIS)
235 {
236 e->axisScale = 2 / (maximum - minimum);
237 e->axisOffset = -(maximum + minimum);
238
239 if (*c == '~')
240 {
241 e->axisScale = -e->axisScale;
242 e->axisOffset = -e->axisOffset;
243 }
244 }
245 }
246 else
247 {
248 length = strlen(_GLFW_PLATFORM_MAPPING_NAME);
249 if (strncmp(c, _GLFW_PLATFORM_MAPPING_NAME, length) != 0)
250 return GLFW_FALSE;
251 }
252
253 break;
254 }
255
256 c += strcspn(c, ",");
257 c += strspn(c, ",");
258 }
259
260 for (i = 0; i < 32; i++)
261 {
262 if (mapping->guid[i] >= 'A' && mapping->guid[i] <= 'F')
263 mapping->guid[i] += 'a' - 'A';
264 }
265
267 return GLFW_TRUE;
268}
269
270
274
275// Notifies shared code of a physical key event
276//
277void _glfwInputKey(_GLFWwindow* window, int key, int scancode, int action, int mods)
278{
279 if (key >= 0 && key <= GLFW_KEY_LAST)
280 {
281 GLFWbool repeated = GLFW_FALSE;
282
283 if (action == GLFW_RELEASE && window->keys[key] == GLFW_RELEASE)
284 return;
285
286 if (action == GLFW_PRESS && window->keys[key] == GLFW_PRESS)
287 repeated = GLFW_TRUE;
288
289 if (action == GLFW_RELEASE && window->stickyKeys)
290 window->keys[key] = _GLFW_STICK;
291 else
292 window->keys[key] = (char) action;
293
294 if (repeated)
295 action = GLFW_REPEAT;
296 }
297
298 if (!window->lockKeyMods)
300
301 if (window->callbacks.key)
302 window->callbacks.key((GLFWwindow*) window, key, scancode, action, mods);
303}
304
305// Notifies shared code of a Unicode codepoint input event
306// The 'plain' parameter determines whether to emit a regular character event
307//
308void _glfwInputChar(_GLFWwindow* window, unsigned int codepoint, int mods, GLFWbool plain)
309{
310 if (codepoint < 32 || (codepoint > 126 && codepoint < 160))
311 return;
312
313 if (!window->lockKeyMods)
315
316 if (window->callbacks.charmods)
317 window->callbacks.charmods((GLFWwindow*) window, codepoint, mods);
318
319 if (plain)
320 {
321 if (window->callbacks.character)
322 window->callbacks.character((GLFWwindow*) window, codepoint);
323 }
324}
325
326// Notifies shared code of a scroll event
327//
328void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset)
329{
330 if (window->callbacks.scroll)
331 window->callbacks.scroll((GLFWwindow*) window, xoffset, yoffset);
332}
333
334// Notifies shared code of a mouse button click event
335//
336void _glfwInputMouseClick(_GLFWwindow* window, int button, int action, int mods)
337{
338 if (button < 0 || button > GLFW_MOUSE_BUTTON_LAST)
339 return;
340
341 if (!window->lockKeyMods)
343
344 if (action == GLFW_RELEASE && window->stickyMouseButtons)
345 window->mouseButtons[button] = _GLFW_STICK;
346 else
347 window->mouseButtons[button] = (char) action;
348
349 if (window->callbacks.mouseButton)
350 window->callbacks.mouseButton((GLFWwindow*) window, button, action, mods);
351}
352
353// Notifies shared code of a cursor motion event
354// The position is specified in content area relative screen coordinates
355//
356void _glfwInputCursorPos(_GLFWwindow* window, double xpos, double ypos)
357{
358 if (window->virtualCursorPosX == xpos && window->virtualCursorPosY == ypos)
359 return;
360
361 window->virtualCursorPosX = xpos;
362 window->virtualCursorPosY = ypos;
363
364 if (window->callbacks.cursorPos)
365 window->callbacks.cursorPos((GLFWwindow*) window, xpos, ypos);
366}
367
368// Notifies shared code of a cursor enter/leave event
369//
371{
372 if (window->callbacks.cursorEnter)
373 window->callbacks.cursorEnter((GLFWwindow*) window, entered);
374}
375
376// Notifies shared code of files or directories dropped on a window
377//
378void _glfwInputDrop(_GLFWwindow* window, int count, const char** paths)
379{
380 if (window->callbacks.drop)
381 window->callbacks.drop((GLFWwindow*) window, count, paths);
382}
383
384// Notifies shared code of a joystick connection or disconnection
385//
387{
388 const int jid = (int) (js - _glfw.joysticks);
389
391 _glfw.callbacks.joystick(jid, event);
392}
393
394// Notifies shared code of the new value of a joystick axis
395//
396void _glfwInputJoystickAxis(_GLFWjoystick* js, int axis, float value)
397{
398 js->axes[axis] = value;
399}
400
401// Notifies shared code of the new value of a joystick button
402//
403void _glfwInputJoystickButton(_GLFWjoystick* js, int button, char value)
404{
405 js->buttons[button] = value;
406}
407
408// Notifies shared code of the new value of a joystick hat
409//
410void _glfwInputJoystickHat(_GLFWjoystick* js, int hat, char value)
411{
412 const int base = js->buttonCount + hat * 4;
413
414 js->buttons[base + 0] = (value & 0x01) ? GLFW_PRESS : GLFW_RELEASE;
415 js->buttons[base + 1] = (value & 0x02) ? GLFW_PRESS : GLFW_RELEASE;
416 js->buttons[base + 2] = (value & 0x04) ? GLFW_PRESS : GLFW_RELEASE;
417 js->buttons[base + 3] = (value & 0x08) ? GLFW_PRESS : GLFW_RELEASE;
418
419 js->hats[hat] = value;
420}
421
422
426
427// Returns an available joystick object with arrays and name allocated
428//
430 const char* guid,
431 int axisCount,
432 int buttonCount,
433 int hatCount)
434{
435 int jid;
436 _GLFWjoystick* js;
437
438 for (jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++)
439 {
440 if (!_glfw.joysticks[jid].present)
441 break;
442 }
443
444 if (jid > GLFW_JOYSTICK_LAST)
445 return NULL;
446
447 js = _glfw.joysticks + jid;
448 js->present = GLFW_TRUE;
449 js->axes = calloc(axisCount, sizeof(float));
450 js->buttons = calloc(buttonCount + (size_t) hatCount * 4, 1);
451 js->hats = calloc(hatCount, 1);
452 js->axisCount = axisCount;
453 js->buttonCount = buttonCount;
454 js->hatCount = hatCount;
455
456 strncpy(js->name, name, sizeof(js->name) - 1);
457 strncpy(js->guid, guid, sizeof(js->guid) - 1);
458 js->mapping = findValidMapping(js);
459
460 return js;
461}
462
463// Frees arrays and name and flags the joystick object as unused
464//
466{
467 free(js->axes);
468 free(js->buttons);
469 free(js->hats);
470 memset(js, 0, sizeof(_GLFWjoystick));
471}
472
473// Center the cursor in the content area of the specified window
474//
476{
477 int width, height;
478
479 _glfwPlatformGetWindowSize(window, &width, &height);
480 _glfwPlatformSetCursorPos(window, width / 2.0, height / 2.0);
481}
482
483
487
488GLFWAPI int glfwGetInputMode(GLFWwindow* handle, int mode)
489{
490 _GLFWwindow* window = (_GLFWwindow*) handle;
491 assert(window != NULL);
492
494
495 switch (mode)
496 {
497 case GLFW_CURSOR:
498 return window->cursorMode;
499 case GLFW_STICKY_KEYS:
500 return window->stickyKeys;
502 return window->stickyMouseButtons;
504 return window->lockKeyMods;
506 return window->rawMouseMotion;
507 }
508
509 _glfwInputError(GLFW_INVALID_ENUM, "Invalid input mode 0x%08X", mode);
510 return 0;
511}
512
513GLFWAPI void glfwSetInputMode(GLFWwindow* handle, int mode, int value)
514{
515 _GLFWwindow* window = (_GLFWwindow*) handle;
516 assert(window != NULL);
517
519
520 if (mode == GLFW_CURSOR)
521 {
522 if (value != GLFW_CURSOR_NORMAL &&
523 value != GLFW_CURSOR_HIDDEN &&
524 value != GLFW_CURSOR_DISABLED)
525 {
527 "Invalid cursor mode 0x%08X",
528 value);
529 return;
530 }
531
532 if (window->cursorMode == value)
533 return;
534
535 window->cursorMode = value;
536
538 &window->virtualCursorPosX,
539 &window->virtualCursorPosY);
540 _glfwPlatformSetCursorMode(window, value);
541 }
542 else if (mode == GLFW_STICKY_KEYS)
543 {
544 value = value ? GLFW_TRUE : GLFW_FALSE;
545 if (window->stickyKeys == value)
546 return;
547
548 if (!value)
549 {
550 int i;
551
552 // Release all sticky keys
553 for (i = 0; i <= GLFW_KEY_LAST; i++)
554 {
555 if (window->keys[i] == _GLFW_STICK)
556 window->keys[i] = GLFW_RELEASE;
557 }
558 }
559
560 window->stickyKeys = value;
561 }
562 else if (mode == GLFW_STICKY_MOUSE_BUTTONS)
563 {
564 value = value ? GLFW_TRUE : GLFW_FALSE;
565 if (window->stickyMouseButtons == value)
566 return;
567
568 if (!value)
569 {
570 int i;
571
572 // Release all sticky mouse buttons
573 for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++)
574 {
575 if (window->mouseButtons[i] == _GLFW_STICK)
576 window->mouseButtons[i] = GLFW_RELEASE;
577 }
578 }
579
580 window->stickyMouseButtons = value;
581 }
582 else if (mode == GLFW_LOCK_KEY_MODS)
583 {
584 window->lockKeyMods = value ? GLFW_TRUE : GLFW_FALSE;
585 }
586 else if (mode == GLFW_RAW_MOUSE_MOTION)
587 {
589 {
591 "Raw mouse motion is not supported on this system");
592 return;
593 }
594
595 value = value ? GLFW_TRUE : GLFW_FALSE;
596 if (window->rawMouseMotion == value)
597 return;
598
599 window->rawMouseMotion = value;
600 _glfwPlatformSetRawMouseMotion(window, value);
601 }
602 else
603 _glfwInputError(GLFW_INVALID_ENUM, "Invalid input mode 0x%08X", mode);
604}
605
607{
610}
611
612GLFWAPI const char* glfwGetKeyName(int key, int scancode)
613{
615
616 if (key != GLFW_KEY_UNKNOWN)
617 {
618 if (key != GLFW_KEY_KP_EQUAL &&
619 (key < GLFW_KEY_KP_0 || key > GLFW_KEY_KP_ADD) &&
620 (key < GLFW_KEY_APOSTROPHE || key > GLFW_KEY_WORLD_2))
621 {
622 return NULL;
623 }
624
625 scancode = _glfwPlatformGetKeyScancode(key);
626 }
627
628 return _glfwPlatformGetScancodeName(scancode);
629}
630
632{
634
635 if (key < GLFW_KEY_SPACE || key > GLFW_KEY_LAST)
636 {
637 _glfwInputError(GLFW_INVALID_ENUM, "Invalid key %i", key);
638 return GLFW_RELEASE;
639 }
640
641 return _glfwPlatformGetKeyScancode(key);
642}
643
644GLFWAPI int glfwGetKey(GLFWwindow* handle, int key)
645{
646 _GLFWwindow* window = (_GLFWwindow*) handle;
647 assert(window != NULL);
648
650
651 if (key < GLFW_KEY_SPACE || key > GLFW_KEY_LAST)
652 {
653 _glfwInputError(GLFW_INVALID_ENUM, "Invalid key %i", key);
654 return GLFW_RELEASE;
655 }
656
657 if (window->keys[key] == _GLFW_STICK)
658 {
659 // Sticky mode: release key now
660 window->keys[key] = GLFW_RELEASE;
661 return GLFW_PRESS;
662 }
663
664 return (int) window->keys[key];
665}
666
667GLFWAPI int glfwGetMouseButton(GLFWwindow* handle, int button)
668{
669 _GLFWwindow* window = (_GLFWwindow*) handle;
670 assert(window != NULL);
671
673
674 if (button < GLFW_MOUSE_BUTTON_1 || button > GLFW_MOUSE_BUTTON_LAST)
675 {
676 _glfwInputError(GLFW_INVALID_ENUM, "Invalid mouse button %i", button);
677 return GLFW_RELEASE;
678 }
679
680 if (window->mouseButtons[button] == _GLFW_STICK)
681 {
682 // Sticky mode: release mouse button now
683 window->mouseButtons[button] = GLFW_RELEASE;
684 return GLFW_PRESS;
685 }
686
687 return (int) window->mouseButtons[button];
688}
689
690GLFWAPI void glfwGetCursorPos(GLFWwindow* handle, double* xpos, double* ypos)
691{
692 _GLFWwindow* window = (_GLFWwindow*) handle;
693 assert(window != NULL);
694
695 if (xpos)
696 *xpos = 0;
697 if (ypos)
698 *ypos = 0;
699
701
702 if (window->cursorMode == GLFW_CURSOR_DISABLED)
703 {
704 if (xpos)
705 *xpos = window->virtualCursorPosX;
706 if (ypos)
707 *ypos = window->virtualCursorPosY;
708 }
709 else
710 _glfwPlatformGetCursorPos(window, xpos, ypos);
711}
712
713GLFWAPI void glfwSetCursorPos(GLFWwindow* handle, double xpos, double ypos)
714{
715 _GLFWwindow* window = (_GLFWwindow*) handle;
716 assert(window != NULL);
717
719
720 if (xpos != xpos || xpos < -DBL_MAX || xpos > DBL_MAX ||
721 ypos != ypos || ypos < -DBL_MAX || ypos > DBL_MAX)
722 {
724 "Invalid cursor position %f %f",
725 xpos, ypos);
726 return;
727 }
728
729 if (!_glfwPlatformWindowFocused(window))
730 return;
731
732 if (window->cursorMode == GLFW_CURSOR_DISABLED)
733 {
734 // Only update the accumulated position if the cursor is disabled
735 window->virtualCursorPosX = xpos;
736 window->virtualCursorPosY = ypos;
737 }
738 else
739 {
740 // Update system cursor position
741 _glfwPlatformSetCursorPos(window, xpos, ypos);
742 }
743}
744
745GLFWAPI GLFWcursor* glfwCreateCursor(const GLFWimage* image, int xhot, int yhot)
746{
747 _GLFWcursor* cursor;
748
749 assert(image != NULL);
750
752
753 cursor = calloc(1, sizeof(_GLFWcursor));
754 cursor->next = _glfw.cursorListHead;
755 _glfw.cursorListHead = cursor;
756
757 if (!_glfwPlatformCreateCursor(cursor, image, xhot, yhot))
758 {
759 glfwDestroyCursor((GLFWcursor*) cursor);
760 return NULL;
761 }
762
763 return (GLFWcursor*) cursor;
764}
765
767{
768 _GLFWcursor* cursor;
769
771
772 if (shape != GLFW_ARROW_CURSOR &&
773 shape != GLFW_IBEAM_CURSOR &&
774 shape != GLFW_CROSSHAIR_CURSOR &&
775 shape != GLFW_POINTING_HAND_CURSOR &&
776 shape != GLFW_RESIZE_EW_CURSOR &&
777 shape != GLFW_RESIZE_NS_CURSOR &&
778 shape != GLFW_RESIZE_NWSE_CURSOR &&
779 shape != GLFW_RESIZE_NESW_CURSOR &&
780 shape != GLFW_RESIZE_ALL_CURSOR &&
782 {
783 _glfwInputError(GLFW_INVALID_ENUM, "Invalid standard cursor 0x%08X", shape);
784 return NULL;
785 }
786
787 cursor = calloc(1, sizeof(_GLFWcursor));
788 cursor->next = _glfw.cursorListHead;
789 _glfw.cursorListHead = cursor;
790
791 if (!_glfwPlatformCreateStandardCursor(cursor, shape))
792 {
793 glfwDestroyCursor((GLFWcursor*) cursor);
794 return NULL;
795 }
796
797 return (GLFWcursor*) cursor;
798}
799
801{
802 _GLFWcursor* cursor = (_GLFWcursor*) handle;
803
805
806 if (cursor == NULL)
807 return;
808
809 // Make sure the cursor is not being used by any window
810 {
811 _GLFWwindow* window;
812
813 for (window = _glfw.windowListHead; window; window = window->next)
814 {
815 if (window->cursor == cursor)
816 glfwSetCursor((GLFWwindow*) window, NULL);
817 }
818 }
819
821
822 // Unlink cursor from global linked list
823 {
825
826 while (*prev != cursor)
827 prev = &((*prev)->next);
828
829 *prev = cursor->next;
830 }
831
832 free(cursor);
833}
834
835GLFWAPI void glfwSetCursor(GLFWwindow* windowHandle, GLFWcursor* cursorHandle)
836{
837 _GLFWwindow* window = (_GLFWwindow*) windowHandle;
838 _GLFWcursor* cursor = (_GLFWcursor*) cursorHandle;
839 assert(window != NULL);
840
842
843 window->cursor = cursor;
844
845 _glfwPlatformSetCursor(window, cursor);
846}
847
849{
850 _GLFWwindow* window = (_GLFWwindow*) handle;
851 assert(window != NULL);
852
854 _GLFW_SWAP_POINTERS(window->callbacks.key, cbfun);
855 return cbfun;
856}
857
859{
860 _GLFWwindow* window = (_GLFWwindow*) handle;
861 assert(window != NULL);
862
865 return cbfun;
866}
867
869{
870 _GLFWwindow* window = (_GLFWwindow*) handle;
871 assert(window != NULL);
872
874 _GLFW_SWAP_POINTERS(window->callbacks.charmods, cbfun);
875 return cbfun;
876}
877
879 GLFWmousebuttonfun cbfun)
880{
881 _GLFWwindow* window = (_GLFWwindow*) handle;
882 assert(window != NULL);
883
886 return cbfun;
887}
888
890 GLFWcursorposfun cbfun)
891{
892 _GLFWwindow* window = (_GLFWwindow*) handle;
893 assert(window != NULL);
894
897 return cbfun;
898}
899
901 GLFWcursorenterfun cbfun)
902{
903 _GLFWwindow* window = (_GLFWwindow*) handle;
904 assert(window != NULL);
905
908 return cbfun;
909}
910
912 GLFWscrollfun cbfun)
913{
914 _GLFWwindow* window = (_GLFWwindow*) handle;
915 assert(window != NULL);
916
918 _GLFW_SWAP_POINTERS(window->callbacks.scroll, cbfun);
919 return cbfun;
920}
921
923{
924 _GLFWwindow* window = (_GLFWwindow*) handle;
925 assert(window != NULL);
926
928 _GLFW_SWAP_POINTERS(window->callbacks.drop, cbfun);
929 return cbfun;
930}
931
933{
934 _GLFWjoystick* js;
935
936 assert(jid >= GLFW_JOYSTICK_1);
937 assert(jid <= GLFW_JOYSTICK_LAST);
938
940
941 if (jid < 0 || jid > GLFW_JOYSTICK_LAST)
942 {
943 _glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick ID %i", jid);
944 return GLFW_FALSE;
945 }
946
947 if (!initJoysticks())
948 return GLFW_FALSE;
949
950 js = _glfw.joysticks + jid;
951 if (!js->present)
952 return GLFW_FALSE;
953
955}
956
957GLFWAPI const float* glfwGetJoystickAxes(int jid, int* count)
958{
959 _GLFWjoystick* js;
960
961 assert(jid >= GLFW_JOYSTICK_1);
962 assert(jid <= GLFW_JOYSTICK_LAST);
963 assert(count != NULL);
964
965 *count = 0;
966
968
969 if (jid < 0 || jid > GLFW_JOYSTICK_LAST)
970 {
971 _glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick ID %i", jid);
972 return NULL;
973 }
974
975 if (!initJoysticks())
976 return NULL;
977
978 js = _glfw.joysticks + jid;
979 if (!js->present)
980 return NULL;
981
983 return NULL;
984
985 *count = js->axisCount;
986 return js->axes;
987}
988
989GLFWAPI const unsigned char* glfwGetJoystickButtons(int jid, int* count)
990{
991 _GLFWjoystick* js;
992
993 assert(jid >= GLFW_JOYSTICK_1);
994 assert(jid <= GLFW_JOYSTICK_LAST);
995 assert(count != NULL);
996
997 *count = 0;
998
1000
1001 if (jid < 0 || jid > GLFW_JOYSTICK_LAST)
1002 {
1003 _glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick ID %i", jid);
1004 return NULL;
1005 }
1006
1007 if (!initJoysticks())
1008 return NULL;
1009
1010 js = _glfw.joysticks + jid;
1011 if (!js->present)
1012 return NULL;
1013
1015 return NULL;
1016
1018 *count = js->buttonCount + js->hatCount * 4;
1019 else
1020 *count = js->buttonCount;
1021
1022 return js->buttons;
1023}
1024
1025GLFWAPI const unsigned char* glfwGetJoystickHats(int jid, int* count)
1026{
1027 _GLFWjoystick* js;
1028
1029 assert(jid >= GLFW_JOYSTICK_1);
1030 assert(jid <= GLFW_JOYSTICK_LAST);
1031 assert(count != NULL);
1032
1033 *count = 0;
1034
1036
1037 if (jid < 0 || jid > GLFW_JOYSTICK_LAST)
1038 {
1039 _glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick ID %i", jid);
1040 return NULL;
1041 }
1042
1043 if (!initJoysticks())
1044 return NULL;
1045
1046 js = _glfw.joysticks + jid;
1047 if (!js->present)
1048 return NULL;
1049
1051 return NULL;
1052
1053 *count = js->hatCount;
1054 return js->hats;
1055}
1056
1057GLFWAPI const char* glfwGetJoystickName(int jid)
1058{
1059 _GLFWjoystick* js;
1060
1061 assert(jid >= GLFW_JOYSTICK_1);
1062 assert(jid <= GLFW_JOYSTICK_LAST);
1063
1065
1066 if (jid < 0 || jid > GLFW_JOYSTICK_LAST)
1067 {
1068 _glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick ID %i", jid);
1069 return NULL;
1070 }
1071
1072 if (!initJoysticks())
1073 return NULL;
1074
1075 js = _glfw.joysticks + jid;
1076 if (!js->present)
1077 return NULL;
1078
1080 return NULL;
1081
1082 return js->name;
1083}
1084
1085GLFWAPI const char* glfwGetJoystickGUID(int jid)
1086{
1087 _GLFWjoystick* js;
1088
1089 assert(jid >= GLFW_JOYSTICK_1);
1090 assert(jid <= GLFW_JOYSTICK_LAST);
1091
1093
1094 if (jid < 0 || jid > GLFW_JOYSTICK_LAST)
1095 {
1096 _glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick ID %i", jid);
1097 return NULL;
1098 }
1099
1100 if (!initJoysticks())
1101 return NULL;
1102
1103 js = _glfw.joysticks + jid;
1104 if (!js->present)
1105 return NULL;
1106
1108 return NULL;
1109
1110 return js->guid;
1111}
1112
1113GLFWAPI void glfwSetJoystickUserPointer(int jid, void* pointer)
1114{
1115 _GLFWjoystick* js;
1116
1117 assert(jid >= GLFW_JOYSTICK_1);
1118 assert(jid <= GLFW_JOYSTICK_LAST);
1119
1121
1122 js = _glfw.joysticks + jid;
1123 if (!js->present)
1124 return;
1125
1126 js->userPointer = pointer;
1127}
1128
1130{
1131 _GLFWjoystick* js;
1132
1133 assert(jid >= GLFW_JOYSTICK_1);
1134 assert(jid <= GLFW_JOYSTICK_LAST);
1135
1137
1138 js = _glfw.joysticks + jid;
1139 if (!js->present)
1140 return NULL;
1141
1142 return js->userPointer;
1143}
1144
1146{
1148
1149 if (!initJoysticks())
1150 return NULL;
1151
1153 return cbfun;
1154}
1155
1156GLFWAPI int glfwUpdateGamepadMappings(const char* string)
1157{
1158 int jid;
1159 const char* c = string;
1160
1161 assert(string != NULL);
1162
1164
1165 while (*c)
1166 {
1167 if ((*c >= '0' && *c <= '9') ||
1168 (*c >= 'a' && *c <= 'f') ||
1169 (*c >= 'A' && *c <= 'F'))
1170 {
1171 char line[1024];
1172
1173 const size_t length = strcspn(c, "\r\n");
1174 if (length < sizeof(line))
1175 {
1176 _GLFWmapping mapping = {{0}};
1177
1178 memcpy(line, c, length);
1179 line[length] = '\0';
1180
1181 if (parseMapping(&mapping, line))
1182 {
1183 _GLFWmapping* previous = findMapping(mapping.guid);
1184 if (previous)
1185 *previous = mapping;
1186 else
1187 {
1189 _glfw.mappings =
1190 realloc(_glfw.mappings,
1191 sizeof(_GLFWmapping) * _glfw.mappingCount);
1192 _glfw.mappings[_glfw.mappingCount - 1] = mapping;
1193 }
1194 }
1195 }
1196
1197 c += length;
1198 }
1199 else
1200 {
1201 c += strcspn(c, "\r\n");
1202 c += strspn(c, "\r\n");
1203 }
1204 }
1205
1206 for (jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++)
1207 {
1208 _GLFWjoystick* js = _glfw.joysticks + jid;
1209 if (js->present)
1210 js->mapping = findValidMapping(js);
1211 }
1212
1213 return GLFW_TRUE;
1214}
1215
1217{
1218 _GLFWjoystick* js;
1219
1220 assert(jid >= GLFW_JOYSTICK_1);
1221 assert(jid <= GLFW_JOYSTICK_LAST);
1222
1224
1225 if (jid < 0 || jid > GLFW_JOYSTICK_LAST)
1226 {
1227 _glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick ID %i", jid);
1228 return GLFW_FALSE;
1229 }
1230
1231 if (!initJoysticks())
1232 return GLFW_FALSE;
1233
1234 js = _glfw.joysticks + jid;
1235 if (!js->present)
1236 return GLFW_FALSE;
1237
1239 return GLFW_FALSE;
1240
1241 return js->mapping != NULL;
1242}
1243
1244GLFWAPI const char* glfwGetGamepadName(int jid)
1245{
1246 _GLFWjoystick* js;
1247
1248 assert(jid >= GLFW_JOYSTICK_1);
1249 assert(jid <= GLFW_JOYSTICK_LAST);
1250
1252
1253 if (jid < 0 || jid > GLFW_JOYSTICK_LAST)
1254 {
1255 _glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick ID %i", jid);
1256 return NULL;
1257 }
1258
1259 if (!initJoysticks())
1260 return NULL;
1261
1262 js = _glfw.joysticks + jid;
1263 if (!js->present)
1264 return NULL;
1265
1267 return NULL;
1268
1269 if (!js->mapping)
1270 return NULL;
1271
1272 return js->mapping->name;
1273}
1274
1276{
1277 int i;
1278 _GLFWjoystick* js;
1279
1280 assert(jid >= GLFW_JOYSTICK_1);
1281 assert(jid <= GLFW_JOYSTICK_LAST);
1282 assert(state != NULL);
1283
1284 memset(state, 0, sizeof(GLFWgamepadstate));
1285
1287
1288 if (jid < 0 || jid > GLFW_JOYSTICK_LAST)
1289 {
1290 _glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick ID %i", jid);
1291 return GLFW_FALSE;
1292 }
1293
1294 if (!initJoysticks())
1295 return GLFW_FALSE;
1296
1297 js = _glfw.joysticks + jid;
1298 if (!js->present)
1299 return GLFW_FALSE;
1300
1302 return GLFW_FALSE;
1303
1304 if (!js->mapping)
1305 return GLFW_FALSE;
1306
1307 for (i = 0; i <= GLFW_GAMEPAD_BUTTON_LAST; i++)
1308 {
1309 const _GLFWmapelement* e = js->mapping->buttons + i;
1310 if (e->type == _GLFW_JOYSTICK_AXIS)
1311 {
1312 const float value = js->axes[e->index] * e->axisScale + e->axisOffset;
1313 // HACK: This should be baked into the value transform
1314 // TODO: Bake into transform when implementing output modifiers
1315 if (e->axisOffset < 0 || (e->axisOffset == 0 && e->axisScale > 0))
1316 {
1317 if (value >= 0.f)
1318 state->buttons[i] = GLFW_PRESS;
1319 }
1320 else
1321 {
1322 if (value <= 0.f)
1323 state->buttons[i] = GLFW_PRESS;
1324 }
1325 }
1326 else if (e->type == _GLFW_JOYSTICK_HATBIT)
1327 {
1328 const unsigned int hat = e->index >> 4;
1329 const unsigned int bit = e->index & 0xf;
1330 if (js->hats[hat] & bit)
1331 state->buttons[i] = GLFW_PRESS;
1332 }
1333 else if (e->type == _GLFW_JOYSTICK_BUTTON)
1334 state->buttons[i] = js->buttons[e->index];
1335 }
1336
1337 for (i = 0; i <= GLFW_GAMEPAD_AXIS_LAST; i++)
1338 {
1339 const _GLFWmapelement* e = js->mapping->axes + i;
1340 if (e->type == _GLFW_JOYSTICK_AXIS)
1341 {
1342 const float value = js->axes[e->index] * e->axisScale + e->axisOffset;
1343 state->axes[i] = _glfw_fminf(_glfw_fmaxf(value, -1.f), 1.f);
1344 }
1345 else if (e->type == _GLFW_JOYSTICK_HATBIT)
1346 {
1347 const unsigned int hat = e->index >> 4;
1348 const unsigned int bit = e->index & 0xf;
1349 if (js->hats[hat] & bit)
1350 state->axes[i] = 1.f;
1351 else
1352 state->axes[i] = -1.f;
1353 }
1354 else if (e->type == _GLFW_JOYSTICK_BUTTON)
1355 state->axes[i] = js->buttons[e->index] * 2.f - 1.f;
1356 }
1357
1358 return GLFW_TRUE;
1359}
1360
1361GLFWAPI void glfwSetClipboardString(GLFWwindow* handle, const char* string)
1362{
1363 assert(string != NULL);
1364
1367}
1368
1370{
1373}
1374
1376{
1378 return (double) (_glfwPlatformGetTimerValue() - _glfw.timer.offset) /
1380}
1381
1382GLFWAPI void glfwSetTime(double time)
1383{
1385
1386 if (time != time || time < 0.0 || time > 18446744073.0)
1387 {
1388 _glfwInputError(GLFW_INVALID_VALUE, "Invalid time %f", time);
1389 return;
1390 }
1391
1394}
1395
1397{
1400}
1401
1403{
1406}
#define _GLFW_PLATFORM_MAPPING_NAME
void _glfwPlatformTerminateJoysticks(void)
int _glfwPlatformPollJoystick(_GLFWjoystick *js, int mode)
GLFWbool _glfwPlatformInitJoysticks(void)
void _glfwPlatformUpdateGamepadGUID(char *guid)
uint64_t _glfwPlatformGetTimerValue(void)
Definition: cocoa_time.c:53
uint64_t _glfwPlatformGetTimerFrequency(void)
Definition: cocoa_time.c:58
void _glfwPlatformSetCursorPos(_GLFWwindow *window, double x, double y)
int _glfwPlatformCreateCursor(_GLFWcursor *cursor, const GLFWimage *image, int xhot, int yhot)
void _glfwPlatformSetCursor(_GLFWwindow *window, _GLFWcursor *cursor)
void _glfwPlatformGetWindowSize(_GLFWwindow *window, int *width, int *height)
const char * _glfwPlatformGetScancodeName(int scancode)
void _glfwPlatformDestroyCursor(_GLFWcursor *cursor)
GLFWbool _glfwPlatformRawMouseMotionSupported(void)
void _glfwPlatformSetCursorMode(_GLFWwindow *window, int mode)
void _glfwPlatformSetClipboardString(const char *string)
void _glfwPlatformSetRawMouseMotion(_GLFWwindow *window, GLFWbool enabled)
int _glfwPlatformWindowFocused(_GLFWwindow *window)
int _glfwPlatformGetKeyScancode(int key)
int _glfwPlatformCreateStandardCursor(_GLFWcursor *cursor, int shape)
const char * _glfwPlatformGetClipboardString(void)
void _glfwPlatformGetCursorPos(_GLFWwindow *window, double *xpos, double *ypos)
#define GLFW_LOCK_KEY_MODS
Definition: glfw3.h:1101
#define GLFW_CURSOR_DISABLED
Definition: glfw3.h:1106
#define GLFW_STICKY_MOUSE_BUTTONS
Definition: glfw3.h:1100
#define GLFWAPI
Definition: glfw3.h:269
#define GLFW_CURSOR
Definition: glfw3.h:1098
#define GLFW_CURSOR_HIDDEN
Definition: glfw3.h:1105
#define GLFW_CURSOR_NORMAL
Definition: glfw3.h:1104
#define GLFW_STICKY_KEYS
Definition: glfw3.h:1099
#define GLFW_RAW_MOUSE_MOTION
Definition: glfw3.h:1102
#define GLFW_MOUSE_BUTTON_LAST
Definition: glfw3.h:577
#define GLFW_INVALID_ENUM
One of the arguments to the function was an invalid enum value.
Definition: glfw3.h:695
#define GLFW_INVALID_VALUE
One of the arguments to the function was an invalid value.
Definition: glfw3.h:706
#define GLFW_PLATFORM_ERROR
A platform-specific error occurred that does not match any of the more specific categories.
Definition: glfw3.h:758
#define GLFW_GAMEPAD_AXIS_LAST
Definition: glfw3.h:652
#define GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER
Definition: glfw3.h:651
#define GLFW_GAMEPAD_AXIS_RIGHT_Y
Definition: glfw3.h:649
#define GLFW_GAMEPAD_AXIS_LEFT_X
Definition: glfw3.h:646
#define GLFW_GAMEPAD_AXIS_LEFT_Y
Definition: glfw3.h:647
#define GLFW_GAMEPAD_AXIS_LEFT_TRIGGER
Definition: glfw3.h:650
#define GLFW_GAMEPAD_AXIS_RIGHT_X
Definition: glfw3.h:648
#define GLFW_GAMEPAD_BUTTON_START
Definition: glfw3.h:623
#define GLFW_GAMEPAD_BUTTON_LEFT_BUMPER
Definition: glfw3.h:620
#define GLFW_GAMEPAD_BUTTON_RIGHT_THUMB
Definition: glfw3.h:626
#define GLFW_GAMEPAD_BUTTON_B
Definition: glfw3.h:617
#define GLFW_GAMEPAD_BUTTON_LEFT_THUMB
Definition: glfw3.h:625
#define GLFW_GAMEPAD_BUTTON_DPAD_UP
Definition: glfw3.h:627
#define GLFW_GAMEPAD_BUTTON_X
Definition: glfw3.h:618
#define GLFW_GAMEPAD_BUTTON_LAST
Definition: glfw3.h:631
#define GLFW_GAMEPAD_BUTTON_GUIDE
Definition: glfw3.h:624
#define GLFW_GAMEPAD_BUTTON_DPAD_DOWN
Definition: glfw3.h:629
#define GLFW_GAMEPAD_BUTTON_BACK
Definition: glfw3.h:622
#define GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER
Definition: glfw3.h:621
#define GLFW_GAMEPAD_BUTTON_A
Definition: glfw3.h:616
#define GLFW_GAMEPAD_BUTTON_DPAD_RIGHT
Definition: glfw3.h:628
#define GLFW_GAMEPAD_BUTTON_DPAD_LEFT
Definition: glfw3.h:630
#define GLFW_GAMEPAD_BUTTON_Y
Definition: glfw3.h:619
#define GLFW_TRUE
One.
Definition: glfw3.h:310
#define GLFW_FALSE
Zero.
Definition: glfw3.h:319
GLFWAPI double glfwGetTime(void)
Returns the GLFW time.
Definition: input.c:1375
void(* GLFWscrollfun)(GLFWwindow *, double, double)
The function pointer type for scroll callbacks.
Definition: glfw3.h:1636
void(* GLFWcursorposfun)(GLFWwindow *, double, double)
The function pointer type for cursor position callbacks.
Definition: glfw3.h:1594
GLFWAPI int glfwGetInputMode(GLFWwindow *handle, int mode)
Returns the value of an input option for the specified window.
Definition: input.c:488
GLFWAPI GLFWcursor * glfwCreateCursor(const GLFWimage *image, int xhot, int yhot)
Creates a custom cursor.
Definition: input.c:745
#define GLFW_PRESS
The key or mouse button was pressed.
Definition: glfw3.h:336
GLFWAPI void glfwDestroyCursor(GLFWcursor *handle)
Destroys a cursor.
Definition: input.c:800
GLFWAPI int glfwUpdateGamepadMappings(const char *string)
Adds the specified SDL_GameControllerDB gamepad mappings.
Definition: input.c:1156
void(* GLFWcharfun)(GLFWwindow *, unsigned int)
The function pointer type for Unicode character callbacks.
Definition: glfw3.h:1683
GLFWAPI const char * glfwGetJoystickGUID(int jid)
Returns the SDL compatible GUID of the specified joystick.
Definition: input.c:1085
GLFWAPI const char * glfwGetClipboardString(GLFWwindow *handle)
Returns the contents of the clipboard as a string.
Definition: input.c:1369
GLFWAPI GLFWcharmodsfun glfwSetCharModsCallback(GLFWwindow *handle, GLFWcharmodsfun cbfun)
Sets the Unicode character with modifiers callback.
Definition: input.c:868
GLFWAPI void glfwSetJoystickUserPointer(int jid, void *pointer)
Sets the user pointer of the specified joystick.
Definition: input.c:1113
GLFWAPI int glfwGetKeyScancode(int key)
Returns the platform-specific scancode of the specified key.
Definition: input.c:631
GLFWAPI const char * glfwGetJoystickName(int jid)
Returns the name of the specified joystick.
Definition: input.c:1057
GLFWAPI int glfwGetMouseButton(GLFWwindow *handle, int button)
Returns the last reported state of a mouse button for the specified window.
Definition: input.c:667
GLFWAPI int glfwGetGamepadState(int jid, GLFWgamepadstate *state)
Retrieves the state of the specified joystick remapped as a gamepad.
Definition: input.c:1275
GLFWAPI GLFWcursorposfun glfwSetCursorPosCallback(GLFWwindow *handle, GLFWcursorposfun cbfun)
Sets the cursor position callback.
Definition: input.c:889
void(* GLFWdropfun)(GLFWwindow *, int, const char *[])
The function pointer type for path drop callbacks.
Definition: glfw3.h:1734
void(* GLFWcharmodsfun)(GLFWwindow *, unsigned int, int)
The function pointer type for Unicode character with modifiers callbacks.
Definition: glfw3.h:1710
GLFWAPI void glfwSetClipboardString(GLFWwindow *handle, const char *string)
Sets the clipboard to the specified string.
Definition: input.c:1361
GLFWAPI int glfwGetKey(GLFWwindow *handle, int key)
Returns the last reported state of a keyboard key for the specified window.
Definition: input.c:644
struct GLFWcursor GLFWcursor
Opaque cursor object.
Definition: glfw3.h:1331
GLFWAPI GLFWdropfun glfwSetDropCallback(GLFWwindow *handle, GLFWdropfun cbfun)
Sets the path drop callback.
Definition: input.c:922
GLFWAPI const unsigned char * glfwGetJoystickButtons(int jid, int *count)
Returns the state of all buttons of the specified joystick.
Definition: input.c:989
GLFWAPI void glfwSetTime(double time)
Sets the GLFW time.
Definition: input.c:1382
void(* GLFWcursorenterfun)(GLFWwindow *, int)
The function pointer type for cursor enter/leave callbacks.
Definition: glfw3.h:1615
GLFWAPI void * glfwGetJoystickUserPointer(int jid)
Returns the user pointer of the specified joystick.
Definition: input.c:1129
GLFWAPI const char * glfwGetKeyName(int key, int scancode)
Returns the layout-specific name of the specified printable key.
Definition: input.c:612
GLFWAPI int glfwRawMouseMotionSupported(void)
Returns whether raw mouse motion is supported.
Definition: input.c:606
void(* GLFWkeyfun)(GLFWwindow *, int, int, int, int)
The function pointer type for keyboard key callbacks.
Definition: glfw3.h:1662
GLFWAPI uint64_t glfwGetTimerValue(void)
Returns the current value of the raw timer.
Definition: input.c:1396
GLFWAPI GLFWkeyfun glfwSetKeyCallback(GLFWwindow *handle, GLFWkeyfun cbfun)
Sets the key callback.
Definition: input.c:848
GLFWAPI GLFWscrollfun glfwSetScrollCallback(GLFWwindow *handle, GLFWscrollfun cbfun)
Sets the scroll callback.
Definition: input.c:911
GLFWAPI uint64_t glfwGetTimerFrequency(void)
Returns the frequency, in Hz, of the raw timer.
Definition: input.c:1402
GLFWAPI void glfwSetCursorPos(GLFWwindow *handle, double xpos, double ypos)
Sets the position of the cursor, relative to the content area of the window.
Definition: input.c:713
GLFWAPI const char * glfwGetGamepadName(int jid)
Returns the human-readable gamepad name for the specified joystick.
Definition: input.c:1244
GLFWAPI GLFWcursor * glfwCreateStandardCursor(int shape)
Creates a cursor with a standard shape.
Definition: input.c:766
GLFWAPI GLFWmousebuttonfun glfwSetMouseButtonCallback(GLFWwindow *handle, GLFWmousebuttonfun cbfun)
Sets the mouse button callback.
Definition: input.c:878
void(* GLFWmousebuttonfun)(GLFWwindow *, int, int, int)
The function pointer type for mouse button callbacks.
Definition: glfw3.h:1571
#define GLFW_REPEAT
The key was held down until it repeated.
Definition: glfw3.h:343
GLFWAPI int glfwJoystickIsGamepad(int jid)
Returns whether the specified joystick has a gamepad mapping.
Definition: input.c:1216
GLFWAPI int glfwJoystickPresent(int jid)
Returns whether the specified joystick is present.
Definition: input.c:932
GLFWAPI const float * glfwGetJoystickAxes(int jid, int *count)
Returns the values of all axes of the specified joystick.
Definition: input.c:957
GLFWAPI GLFWcursorenterfun glfwSetCursorEnterCallback(GLFWwindow *handle, GLFWcursorenterfun cbfun)
Sets the cursor enter/leave callback.
Definition: input.c:900
GLFWAPI void glfwGetCursorPos(GLFWwindow *handle, double *xpos, double *ypos)
Retrieves the position of the cursor relative to the content area of the window.
Definition: input.c:690
GLFWAPI GLFWcharfun glfwSetCharCallback(GLFWwindow *handle, GLFWcharfun cbfun)
Sets the Unicode character callback.
Definition: input.c:858
GLFWAPI GLFWjoystickfun glfwSetJoystickCallback(GLFWjoystickfun cbfun)
Sets the joystick configuration callback.
Definition: input.c:1145
#define GLFW_RELEASE
The key or mouse button was released.
Definition: glfw3.h:329
GLFWAPI void glfwSetInputMode(GLFWwindow *handle, int mode, int value)
Sets an input option for the specified window.
Definition: input.c:513
GLFWAPI const unsigned char * glfwGetJoystickHats(int jid, int *count)
Returns the state of all hats of the specified joystick.
Definition: input.c:1025
GLFWAPI void glfwSetCursor(GLFWwindow *windowHandle, GLFWcursor *cursorHandle)
Sets the cursor for the window.
Definition: input.c:835
void(* GLFWjoystickfun)(int, int)
The function pointer type for joystick configuration callbacks.
Definition: glfw3.h:1776
#define GLFW_JOYSTICK_1
Definition: glfw3.h:590
#define GLFW_JOYSTICK_LAST
Definition: glfw3.h:606
#define GLFW_KEY_WORLD_2
Definition: glfw3.h:441
#define GLFW_KEY_LAST
Definition: glfw3.h:515
#define GLFW_KEY_UNKNOWN
Definition: glfw3.h:389
#define GLFW_KEY_KP_ADD
Definition: glfw3.h:502
#define GLFW_KEY_KP_EQUAL
Definition: glfw3.h:504
#define GLFW_MOD_NUM_LOCK
If this bit is set the Num Lock key is enabled.
Definition: glfw3.h:558
#define GLFW_MOD_CAPS_LOCK
If this bit is set the Caps Lock key is enabled.
Definition: glfw3.h:552
#define GLFW_RESIZE_EW_CURSOR
The horizontal resize/move arrow shape.
Definition: glfw3.h:1158
#define GLFW_NOT_ALLOWED_CURSOR
The operation-not-allowed shape.
Definition: glfw3.h:1212
#define GLFW_IBEAM_CURSOR
The text input I-beam cursor shape.
Definition: glfw3.h:1142
#define GLFW_RESIZE_ALL_CURSOR
The omni-directional resize/move cursor shape.
Definition: glfw3.h:1200
#define GLFW_ARROW_CURSOR
The regular arrow cursor shape.
Definition: glfw3.h:1137
#define GLFW_CROSSHAIR_CURSOR
The crosshair cursor shape.
Definition: glfw3.h:1147
#define GLFW_RESIZE_NS_CURSOR
The vertical resize/move arrow shape.
Definition: glfw3.h:1164
#define GLFW_POINTING_HAND_CURSOR
The pointing hand cursor shape.
Definition: glfw3.h:1152
#define GLFW_RESIZE_NESW_CURSOR
The top-right to bottom-left diagonal resize/move arrow shape.
Definition: glfw3.h:1194
#define GLFW_RESIZE_NWSE_CURSOR
The top-left to bottom-right diagonal resize/move arrow shape.
Definition: glfw3.h:1179
struct GLFWwindow GLFWwindow
Opaque window object.
Definition: glfw3.h:1319
float _glfw_fmaxf(float a, float b)
Definition: init.c:141
_GLFWlibrary _glfw
Definition: init.c:46
void _glfwInputError(int code, const char *format,...)
Definition: init.c:160
float _glfw_fminf(float a, float b)
Definition: init.c:129
_GLFWjoystick * _glfwAllocJoystick(const char *name, const char *guid, int axisCount, int buttonCount, int hatCount)
Definition: input.c:429
void _glfwInputDrop(_GLFWwindow *window, int count, const char **paths)
Definition: input.c:378
void _glfwInputJoystick(_GLFWjoystick *js, int event)
Definition: input.c:386
void _glfwInputCursorEnter(_GLFWwindow *window, GLFWbool entered)
Definition: input.c:370
#define _GLFW_JOYSTICK_BUTTON
Definition: input.c:43
#define _GLFW_JOYSTICK_AXIS
Definition: input.c:42
void _glfwInputScroll(_GLFWwindow *window, double xoffset, double yoffset)
Definition: input.c:328
void _glfwInputChar(_GLFWwindow *window, unsigned int codepoint, int mods, GLFWbool plain)
Definition: input.c:308
void _glfwInputCursorPos(_GLFWwindow *window, double xpos, double ypos)
Definition: input.c:356
#define _GLFW_JOYSTICK_HATBIT
Definition: input.c:44
void _glfwInputJoystickAxis(_GLFWjoystick *js, int axis, float value)
Definition: input.c:396
void _glfwInputKey(_GLFWwindow *window, int key, int scancode, int action, int mods)
Definition: input.c:277
void _glfwInputJoystickHat(_GLFWjoystick *js, int hat, char value)
Definition: input.c:410
void _glfwCenterCursorInContentArea(_GLFWwindow *window)
Definition: input.c:475
void _glfwInputMouseClick(_GLFWwindow *window, int button, int action, int mods)
Definition: input.c:336
void _glfwFreeJoystick(_GLFWjoystick *js)
Definition: input.c:465
#define _GLFW_STICK
Definition: input.c:39
void _glfwInputJoystickButton(_GLFWjoystick *js, int button, char value)
Definition: input.c:403
#define _GLFW_POLL_AXES
Definition: internal.h:55
#define _GLFW_POLL_ALL
Definition: internal.h:57
#define _GLFW_REQUIRE_INIT_OR_RETURN(x)
Definition: internal.h:214
#define _GLFW_SWAP_POINTERS(x, y)
Definition: internal.h:222
#define _GLFW_POLL_BUTTONS
Definition: internal.h:56
int GLFWbool
Definition: internal.h:61
#define _GLFW_REQUIRE_INIT()
Definition: internal.h:208
#define _GLFW_POLL_PRESENCE
Definition: internal.h:54
#define NULL
Definition: miniaudio.h:3718
unsigned char uint8_t
Definition: stdint.h:78
unsigned __int64 uint64_t
Definition: stdint.h:90
signed char int8_t
Definition: stdint.h:75
_GLFWcursor * next
Definition: internal.h:463
GLFWbool hatButtons
Definition: internal.h:245
char guid[33]
Definition: internal.h:502
_GLFWmapping * mapping
Definition: internal.h:503
int buttonCount
Definition: internal.h:497
char name[128]
Definition: internal.h:500
void * userPointer
Definition: internal.h:501
unsigned char * hats
Definition: internal.h:498
GLFWbool present
Definition: internal.h:493
float * axes
Definition: internal.h:494
unsigned char * buttons
Definition: internal.h:496
struct _GLFWlibrary::@26 callbacks
_GLFWmapping * mappings
Definition: internal.h:548
uint64_t offset
Definition: internal.h:556
struct _GLFWlibrary::@24 timer
GLFWjoystickfun joystick
Definition: internal.h:585
_GLFWwindow * windowListHead
Definition: internal.h:541
_GLFWjoystick joysticks[GLFW_JOYSTICK_LAST+1]
Definition: internal.h:547
_GLFWinitconfig init
Definition: internal.h:532
_GLFWcursor * cursorListHead
Definition: internal.h:540
int mappingCount
Definition: internal.h:549
GLFWbool joysticksInitialized
Definition: internal.h:546
struct _GLFWlibrary::@23 hints
uint8_t type
Definition: internal.h:473
int8_t axisScale
Definition: internal.h:475
int8_t axisOffset
Definition: internal.h:476
uint8_t index
Definition: internal.h:474
_GLFWmapelement buttons[15]
Definition: internal.h:485
_GLFWmapelement axes[6]
Definition: internal.h:486
char name[128]
Definition: internal.h:483
char guid[33]
Definition: internal.h:484
GLFWcursorposfun cursorPos
Definition: internal.h:422
struct _GLFWwindow::@22 callbacks
int cursorMode
Definition: internal.h:402
char mouseButtons[GLFW_MOUSE_BUTTON_LAST+1]
Definition: internal.h:403
double virtualCursorPosY
Definition: internal.h:406
double virtualCursorPosX
Definition: internal.h:406
struct _GLFWwindow * next
Definition: internal.h:379
GLFWcharmodsfun charmods
Definition: internal.h:427
GLFWbool stickyMouseButtons
Definition: internal.h:400
GLFWcharfun character
Definition: internal.h:426
GLFWdropfun drop
Definition: internal.h:428
GLFWbool lockKeyMods
Definition: internal.h:401
GLFWscrollfun scroll
Definition: internal.h:424
GLFWbool rawMouseMotion
Definition: internal.h:407
GLFWbool stickyKeys
Definition: internal.h:399
GLFWkeyfun key
Definition: internal.h:425
char keys[GLFW_KEY_LAST+1]
Definition: internal.h:404
GLFWmousebuttonfun mouseButton
Definition: internal.h:421
_GLFWcursor * cursor
Definition: internal.h:393
GLFWcursorenterfun cursorEnter
Definition: internal.h:423
Gamepad input state.
Definition: glfw3.h:1879
unsigned char buttons[15]
Definition: glfw3.h:1883
float axes[6]
Definition: glfw3.h:1887
Image data.
Definition: glfw3.h:1855