Debian Codegraph @

glfw/__init__.py

raw symbols SCIP
1 """
2 Python bindings for GLFW.
3 """
4
5 from __future__ import print_function
6 from __future__ import division
7 from __future__ import unicode_literals
8
9 __author__ = 'Florian Rhiem ([email protected])'
10 __copyright__ = 'Copyright (c) 2013-2024 Florian Rhiem'
11 __license__ = 'MIT'
12 __version__ = '2.10.0'
13
14 # By default, GLFW errors will be handled by a pre-defined error callback.
15 # Depending on the value of ERROR_REPORTING, this callback will:
16 # - Raise a GLFWError exception, if ERROR_REPORTING is 'raise', 'exception'
17 # or True.
18 # - Issue a GLFWError warning, if ERROR_REPORTING is 'warn' or 'warning'.
19 # - Log on debug level using the 'glfw' logger, if ERROR_REPORTING is 'log'.
20 # - Ignore the GLFWError, if ERROR_REPORTING is 'ignore' or False.
21 # If ERROR_REPORTING is a dict containing the specific error code or None as a
22 # key, the corresponding value will be used.
23 # Alternatively, you can set a custom error callback using set_error_callback.
24 ERROR_REPORTING = 'warn'
25
26 # By default (NORMALIZE_GAMMA_RAMPS = True), gamma ramps are expected to
27 # contain values between 0 and 1, and the conversion to unsigned shorts will
28 # be performed internally. Set NORMALIZE_GAMMA_RAMPS to False if you want
29 # to disable this behavior and use integral values between 0 and 65535.
30 NORMALIZE_GAMMA_RAMPS = True
31
32 import collections
33 import ctypes
34 import logging
35 import os
36 import functools
37 import sys
38 import warnings
39
40 from .library import glfw as _glfw
41
42 if _glfw is None:
43 raise ImportError("Failed to load GLFW3 shared library.")
44
45 # By default, pyGLFW will only provide functionality from released GLFW
46 # versions, as using the development version may lead to changing behavior or
47 # missing functions. If the environment variable PYGLFW_PREVIEW is set or the
48 # glfw_preview package can be imported, macros and functions from the current
49 # developtment version of GLFW will be provided. Note that there will still be
50 # a delay between them getting added to GLFW and being wrapped by pyGLFW, and
51 # further delay until they are included in a pyGLFW release.
52 _PREVIEW = os.environ.get('PYGLFW_PREVIEW')
53 if _PREVIEW is None:
54 try:
55 import glfw_preview
56 _PREVIEW = True
57 except:
58 _PREVIEW = False
59 else:
60 _PREVIEW = bool(_PREVIEW)
61
62 # Python 3 compatibility:
63 try:
64 _getcwd = os.getcwdu
65 except AttributeError:
66 _getcwd = os.getcwd
67 if sys.version_info.major > 2:
68 _to_char_p = lambda s: s.encode('utf-8')
69 def _reraise(exception, traceback):
70 raise exception.with_traceback(traceback)
71 else:
72 _to_char_p = lambda s: s
73 def _reraise(exception, traceback):
74 # wrapped in exec, as python 3 does not support this variant of raise
75 exec("raise exception, None, traceback")
76
77 # support for CFFI pointers for Vulkan objects
78 try:
79 from cffi import FFI
80 except ImportError:
81 _cffi_to_ctypes_void_p = lambda ptr: ptr
82 else:
83 ffi = FFI()
84 def _cffi_to_ctypes_void_p(ptr):
85 if isinstance(ptr, ffi.CData):
86 return ctypes.cast(int(ffi.cast('uintptr_t', ptr)), ctypes.c_void_p)
87 return ptr
88
89
90 class GLFWError(UserWarning):
91 """
92 Exception class used for reporting GLFW errors.
93 """
94 def __init__(self, message, error_code=None):
95 super(GLFWError, self).__init__(message)
96 self.error_code = error_code
97
98
99 _callback_repositories = []
100
101
102 class _GLFWwindow(ctypes.Structure):
103 """
104 Wrapper for:
105 typedef struct GLFWwindow GLFWwindow;
106 """
107 _fields_ = [("dummy", ctypes.c_int)]
108
109
110 class _GLFWmonitor(ctypes.Structure):
111 """
112 Wrapper for:
113 typedef struct GLFWmonitor GLFWmonitor;
114 """
115 _fields_ = [("dummy", ctypes.c_int)]
116
117
118 class _GLFWvidmode(ctypes.Structure):
119 """
120 Wrapper for:
121 typedef struct GLFWvidmode GLFWvidmode;
122 """
123 _fields_ = [("width", ctypes.c_int),
124 ("height", ctypes.c_int),
125 ("red_bits", ctypes.c_int),
126 ("green_bits", ctypes.c_int),
127 ("blue_bits", ctypes.c_int),
128 ("refresh_rate", ctypes.c_uint)]
129
130 GLFWvidmode = collections.namedtuple('GLFWvidmode', [
131 'size', 'bits', 'refresh_rate'
132 ])
133 Size = collections.namedtuple('Size', [
134 'width', 'height'
135 ])
136 Bits = collections.namedtuple('Bits', [
137 'red', 'green', 'blue'
138 ])
139
140 def __init__(self):
141 ctypes.Structure.__init__(self)
142 self.width = 0
143 self.height = 0
144 self.red_bits = 0
145 self.green_bits = 0
146 self.blue_bits = 0
147 self.refresh_rate = 0
148
149 def wrap(self, video_mode):
150 """
151 Wraps a nested python sequence.
152 """
153 size, bits, self.refresh_rate = video_mode
154 self.width, self.height = size
155 self.red_bits, self.green_bits, self.blue_bits = bits
156
157 def unwrap(self):
158 """
159 Returns a GLFWvidmode object.
160 """
161 size = self.Size(self.width, self.height)
162 bits = self.Bits(self.red_bits, self.green_bits, self.blue_bits)
163 return self.GLFWvidmode(size, bits, self.refresh_rate)
164
165
166 class _GLFWgammaramp(ctypes.Structure):
167 """
168 Wrapper for:
169 typedef struct GLFWgammaramp GLFWgammaramp;
170 """
171 _fields_ = [("red", ctypes.POINTER(ctypes.c_ushort)),
172 ("green", ctypes.POINTER(ctypes.c_ushort)),
173 ("blue", ctypes.POINTER(ctypes.c_ushort)),
174 ("size", ctypes.c_uint)]
175
176 GLFWgammaramp = collections.namedtuple('GLFWgammaramp', [
177 'red', 'green', 'blue'
178 ])
179
180 def __init__(self):
181 ctypes.Structure.__init__(self)
182 self.red = None
183 self.red_array = None
184 self.green = None
185 self.green_array = None
186 self.blue = None
187 self.blue_array = None
188 self.size = 0
189
190 def wrap(self, gammaramp):
191 """
192 Wraps a nested python sequence.
193 """
194 red, green, blue = gammaramp
195 size = min(len(red), len(green), len(blue))
196 array_type = ctypes.c_ushort*size
197 self.size = ctypes.c_uint(size)
198 self.red_array = array_type()
199 self.green_array = array_type()
200 self.blue_array = array_type()
201 if NORMALIZE_GAMMA_RAMPS:
202 red = [value * 65535 for value in red]
203 green = [value * 65535 for value in green]
204 blue = [value * 65535 for value in blue]
205 for i in range(self.size):
206 self.red_array[i] = int(red[i])
207 self.green_array[i] = int(green[i])
208 self.blue_array[i] = int(blue[i])
209 pointer_type = ctypes.POINTER(ctypes.c_ushort)
210 self.red = ctypes.cast(self.red_array, pointer_type)
211 self.green = ctypes.cast(self.green_array, pointer_type)
212 self.blue = ctypes.cast(self.blue_array, pointer_type)
213
214 def unwrap(self):
215 """
216 Returns a GLFWgammaramp object.
217 """
218 red = [self.red[i] for i in range(self.size)]
219 green = [self.green[i] for i in range(self.size)]
220 blue = [self.blue[i] for i in range(self.size)]
221 if NORMALIZE_GAMMA_RAMPS:
222 red = [value / 65535.0 for value in red]
223 green = [value / 65535.0 for value in green]
224 blue = [value / 65535.0 for value in blue]
225 return self.GLFWgammaramp(red, green, blue)
226
227
228 class _GLFWcursor(ctypes.Structure):
229 """
230 Wrapper for:
231 typedef struct GLFWcursor GLFWcursor;
232 """
233 _fields_ = [("dummy", ctypes.c_int)]
234
235
236 class _GLFWimage(ctypes.Structure):
237 """
238 Wrapper for:
239 typedef struct GLFWimage GLFWimage;
240 """
241 _fields_ = [("width", ctypes.c_int),
242 ("height", ctypes.c_int),
243 ("pixels", ctypes.POINTER(ctypes.c_ubyte))]
244
245 GLFWimage = collections.namedtuple('GLFWimage', [
246 'width', 'height', 'pixels'
247 ])
248
249 def __init__(self):
250 ctypes.Structure.__init__(self)
251 self.width = 0
252 self.height = 0
253 self.pixels = None
254 self.pixels_array = None
255
256 def wrap(self, image):
257 """
258 Wraps a nested python sequence or PIL/pillow Image.
259 """
260 if hasattr(image, 'size') and hasattr(image, 'convert'):
261 # Treat image as PIL/pillow Image object
262 self.width, self.height = image.size
263 array_type = ctypes.c_ubyte * 4 * (self.width * self.height)
264 self.pixels_array = array_type()
265 pixels = image.convert('RGBA').getdata()
266 for i, pixel in enumerate(pixels):
267 self.pixels_array[i] = pixel
268 else:
269 self.width, self.height, pixels = image
270 array_type = ctypes.c_ubyte * 4 * self.width * self.height
271 self.pixels_array = array_type()
272 for i in range(self.height):
273 for j in range(self.width):
274 for k in range(4):
275 self.pixels_array[i][j][k] = pixels[i][j][k]
276 pointer_type = ctypes.POINTER(ctypes.c_ubyte)
277 self.pixels = ctypes.cast(self.pixels_array, pointer_type)
278
279 def unwrap(self):
280 """
281 Returns a GLFWimage object.
282 """
283 pixels = [[[int(c) for c in p] for p in l] for l in self.pixels_array]
284 return self.GLFWimage(self.width, self.height, pixels)
285
286
287 class _GLFWgamepadstate(ctypes.Structure):
288 """
289 Wrapper for:
290 typedef struct GLFWgamepadstate GLFWgamepadstate;
291 """
292 _fields_ = [("buttons", (ctypes.c_ubyte * 15)),
293 ("axes", (ctypes.c_float * 6))]
294
295 GLFWgamepadstate = collections.namedtuple('GLFWgamepadstate', [
296 'buttons', 'axes'
297 ])
298
299 def __init__(self):
300 ctypes.Structure.__init__(self)
301 self.buttons = (ctypes.c_ubyte * 15)(* [0] * 15)
302 self.axes = (ctypes.c_float * 6)(* [0] * 6)
303
304 def wrap(self, gamepad_state):
305 """
306 Wraps a nested python sequence.
307 """
308 buttons, axes = gamepad_state
309 for i in range(15):
310 self.buttons[i] = buttons[i]
311 for i in range(6):
312 self.axes[i] = axes[i]
313
314 def unwrap(self):
315 """
316 Returns a GLFWvidmode object.
317 """
318 buttons = [int(button) for button in self.buttons]
319 axes = [float(axis) for axis in self.axes]
320 return self.GLFWgamepadstate(buttons, axes)
321
322
323 VERSION_MAJOR = 3
324 VERSION_MINOR = 4
325 VERSION_REVISION = 0
326 TRUE = 1
327 FALSE = 0
328 RELEASE = 0
329 PRESS = 1
330 REPEAT = 2
331 HAT_CENTERED = 0
332 HAT_UP = 1
333 HAT_RIGHT = 2
334 HAT_DOWN = 4
335 HAT_LEFT = 8
336 HAT_RIGHT_UP = HAT_RIGHT | HAT_UP
337 HAT_RIGHT_DOWN = HAT_RIGHT | HAT_DOWN
338 HAT_LEFT_UP = HAT_LEFT | HAT_UP
339 HAT_LEFT_DOWN = HAT_LEFT | HAT_DOWN
340 KEY_UNKNOWN = -1
341 KEY_SPACE = 32
342 KEY_APOSTROPHE = 39
343 KEY_COMMA = 44
344 KEY_MINUS = 45
345 KEY_PERIOD = 46
346 KEY_SLASH = 47
347 KEY_0 = 48
348 KEY_1 = 49
349 KEY_2 = 50
350 KEY_3 = 51
351 KEY_4 = 52
352 KEY_5 = 53
353 KEY_6 = 54
354 KEY_7 = 55
355 KEY_8 = 56
356 KEY_9 = 57
357 KEY_SEMICOLON = 59
358 KEY_EQUAL = 61
359 KEY_A = 65
360 KEY_B = 66
361 KEY_C = 67
362 KEY_D = 68
363 KEY_E = 69
364 KEY_F = 70
365 KEY_G = 71
366 KEY_H = 72
367 KEY_I = 73
368 KEY_J = 74
369 KEY_K = 75
370 KEY_L = 76
371 KEY_M = 77
372 KEY_N = 78
373 KEY_O = 79
374 KEY_P = 80
375 KEY_Q = 81
376 KEY_R = 82
377 KEY_S = 83
378 KEY_T = 84
379 KEY_U = 85
380 KEY_V = 86
381 KEY_W = 87
382 KEY_X = 88
383 KEY_Y = 89
384 KEY_Z = 90
385 KEY_LEFT_BRACKET = 91
386 KEY_BACKSLASH = 92
387 KEY_RIGHT_BRACKET = 93
388 KEY_GRAVE_ACCENT = 96
389 KEY_WORLD_1 = 161
390 KEY_WORLD_2 = 162
391 KEY_ESCAPE = 256
392 KEY_ENTER = 257
393 KEY_TAB = 258
394 KEY_BACKSPACE = 259
395 KEY_INSERT = 260
396 KEY_DELETE = 261
397 KEY_RIGHT = 262
398 KEY_LEFT = 263
399 KEY_DOWN = 264
400 KEY_UP = 265
401 KEY_PAGE_UP = 266
402 KEY_PAGE_DOWN = 267
403 KEY_HOME = 268
404 KEY_END = 269
405 KEY_CAPS_LOCK = 280
406 KEY_SCROLL_LOCK = 281
407 KEY_NUM_LOCK = 282
408 KEY_PRINT_SCREEN = 283
409 KEY_PAUSE = 284
410 KEY_F1 = 290
411 KEY_F2 = 291
412 KEY_F3 = 292
413 KEY_F4 = 293
414 KEY_F5 = 294
415 KEY_F6 = 295
416 KEY_F7 = 296
417 KEY_F8 = 297
418 KEY_F9 = 298
419 KEY_F10 = 299
420 KEY_F11 = 300
421 KEY_F12 = 301
422 KEY_F13 = 302
423 KEY_F14 = 303
424 KEY_F15 = 304
425 KEY_F16 = 305
426 KEY_F17 = 306
427 KEY_F18 = 307
428 KEY_F19 = 308
429 KEY_F20 = 309
430 KEY_F21 = 310
431 KEY_F22 = 311
432 KEY_F23 = 312
433 KEY_F24 = 313
434 KEY_F25 = 314
435 KEY_KP_0 = 320
436 KEY_KP_1 = 321
437 KEY_KP_2 = 322
438 KEY_KP_3 = 323
439 KEY_KP_4 = 324
440 KEY_KP_5 = 325
441 KEY_KP_6 = 326
442 KEY_KP_7 = 327
443 KEY_KP_8 = 328
444 KEY_KP_9 = 329
445 KEY_KP_DECIMAL = 330
446 KEY_KP_DIVIDE = 331
447 KEY_KP_MULTIPLY = 332
448 KEY_KP_SUBTRACT = 333
449 KEY_KP_ADD = 334
450 KEY_KP_ENTER = 335
451 KEY_KP_EQUAL = 336
452 KEY_LEFT_SHIFT = 340
453 KEY_LEFT_CONTROL = 341
454 KEY_LEFT_ALT = 342
455 KEY_LEFT_SUPER = 343
456 KEY_RIGHT_SHIFT = 344
457 KEY_RIGHT_CONTROL = 345
458 KEY_RIGHT_ALT = 346
459 KEY_RIGHT_SUPER = 347
460 KEY_MENU = 348
461 KEY_LAST = KEY_MENU
462 MOD_SHIFT = 0x0001
463 MOD_CONTROL = 0x0002
464 MOD_ALT = 0x0004
465 MOD_SUPER = 0x0008
466 MOD_CAPS_LOCK = 0x0010
467 MOD_NUM_LOCK = 0x0020
468 MOUSE_BUTTON_1 = 0
469 MOUSE_BUTTON_2 = 1
470 MOUSE_BUTTON_3 = 2
471 MOUSE_BUTTON_4 = 3
472 MOUSE_BUTTON_5 = 4
473 MOUSE_BUTTON_6 = 5
474 MOUSE_BUTTON_7 = 6
475 MOUSE_BUTTON_8 = 7
476 MOUSE_BUTTON_LAST = MOUSE_BUTTON_8
477 MOUSE_BUTTON_LEFT = MOUSE_BUTTON_1
478 MOUSE_BUTTON_RIGHT = MOUSE_BUTTON_2
479 MOUSE_BUTTON_MIDDLE = MOUSE_BUTTON_3
480 JOYSTICK_1 = 0
481 JOYSTICK_2 = 1
482 JOYSTICK_3 = 2
483 JOYSTICK_4 = 3
484 JOYSTICK_5 = 4
485 JOYSTICK_6 = 5
486 JOYSTICK_7 = 6
487 JOYSTICK_8 = 7
488 JOYSTICK_9 = 8
489 JOYSTICK_10 = 9
490 JOYSTICK_11 = 10
491 JOYSTICK_12 = 11
492 JOYSTICK_13 = 12
493 JOYSTICK_14 = 13
494 JOYSTICK_15 = 14
495 JOYSTICK_16 = 15
496 JOYSTICK_LAST = JOYSTICK_16
497 GAMEPAD_BUTTON_A = 0
498 GAMEPAD_BUTTON_B = 1
499 GAMEPAD_BUTTON_X = 2
500 GAMEPAD_BUTTON_Y = 3
501 GAMEPAD_BUTTON_LEFT_BUMPER = 4
502 GAMEPAD_BUTTON_RIGHT_BUMPER = 5
503 GAMEPAD_BUTTON_BACK = 6
504 GAMEPAD_BUTTON_START = 7
505 GAMEPAD_BUTTON_GUIDE = 8
506 GAMEPAD_BUTTON_LEFT_THUMB = 9
507 GAMEPAD_BUTTON_RIGHT_THUMB = 10
508 GAMEPAD_BUTTON_DPAD_UP = 11
509 GAMEPAD_BUTTON_DPAD_RIGHT = 12
510 GAMEPAD_BUTTON_DPAD_DOWN = 13
511 GAMEPAD_BUTTON_DPAD_LEFT = 14
512 GAMEPAD_BUTTON_LAST = GAMEPAD_BUTTON_DPAD_LEFT
513 GAMEPAD_BUTTON_CROSS = GAMEPAD_BUTTON_A
514 GAMEPAD_BUTTON_CIRCLE = GAMEPAD_BUTTON_B
515 GAMEPAD_BUTTON_SQUARE = GAMEPAD_BUTTON_X
516 GAMEPAD_BUTTON_TRIANGLE = GAMEPAD_BUTTON_Y
517 GAMEPAD_AXIS_LEFT_X = 0
518 GAMEPAD_AXIS_LEFT_Y = 1
519 GAMEPAD_AXIS_RIGHT_X = 2
520 GAMEPAD_AXIS_RIGHT_Y = 3
521 GAMEPAD_AXIS_LEFT_TRIGGER = 4
522 GAMEPAD_AXIS_RIGHT_TRIGGER = 5
523 GAMEPAD_AXIS_LAST = GAMEPAD_AXIS_RIGHT_TRIGGER
524 NO_ERROR = 0
525 NOT_INITIALIZED = 0x00010001
526 NO_CURRENT_CONTEXT = 0x00010002
527 INVALID_ENUM = 0x00010003
528 INVALID_VALUE = 0x00010004
529 OUT_OF_MEMORY = 0x00010005
530 API_UNAVAILABLE = 0x00010006
531 VERSION_UNAVAILABLE = 0x00010007
532 PLATFORM_ERROR = 0x00010008
533 FORMAT_UNAVAILABLE = 0x00010009
534 NO_WINDOW_CONTEXT = 0x0001000A
535 CURSOR_UNAVAILABLE = 0x0001000B
536 FEATURE_UNAVAILABLE = 0x0001000C
537 FEATURE_UNIMPLEMENTED = 0x0001000D
538 PLATFORM_UNAVAILABLE = 0x0001000E
539 FOCUSED = 0x00020001
540 ICONIFIED = 0x00020002
541 RESIZABLE = 0x00020003
542 VISIBLE = 0x00020004
543 DECORATED = 0x00020005
544 AUTO_ICONIFY = 0x00020006
545 FLOATING = 0x00020007
546 MAXIMIZED = 0x00020008
547 CENTER_CURSOR = 0x00020009
548 TRANSPARENT_FRAMEBUFFER = 0x0002000A
549 HOVERED = 0x0002000B
550 FOCUS_ON_SHOW = 0x0002000C
551 MOUSE_PASSTHROUGH = 0x0002000D
552 POSITION_X = 0x0002000E
553 POSITION_Y = 0x0002000F
554 RED_BITS = 0x00021001
555 GREEN_BITS = 0x00021002
556 BLUE_BITS = 0x00021003
557 ALPHA_BITS = 0x00021004
558 DEPTH_BITS = 0x00021005
559 STENCIL_BITS = 0x00021006
560 ACCUM_RED_BITS = 0x00021007
561 ACCUM_GREEN_BITS = 0x00021008
562 ACCUM_BLUE_BITS = 0x00021009
563 ACCUM_ALPHA_BITS = 0x0002100A
564 AUX_BUFFERS = 0x0002100B
565 STEREO = 0x0002100C
566 SAMPLES = 0x0002100D
567 SRGB_CAPABLE = 0x0002100E
568 REFRESH_RATE = 0x0002100F
569 DOUBLEBUFFER = 0x00021010
570 CLIENT_API = 0x00022001
571 CONTEXT_VERSION_MAJOR = 0x00022002
572 CONTEXT_VERSION_MINOR = 0x00022003
573 CONTEXT_REVISION = 0x00022004
574 CONTEXT_ROBUSTNESS = 0x00022005
575 OPENGL_FORWARD_COMPAT = 0x00022006
576 OPENGL_DEBUG_CONTEXT = 0x00022007
577 CONTEXT_DEBUG = 0x00022007
578 OPENGL_PROFILE = 0x00022008
579 CONTEXT_RELEASE_BEHAVIOR = 0x00022009
580 CONTEXT_NO_ERROR = 0x0002200A
581 CONTEXT_CREATION_API = 0x0002200B
582 SCALE_TO_MONITOR = 0x0002200C
583 SCALE_FRAMEBUFFER = 0x0002200D
584 COCOA_RETINA_FRAMEBUFFER = 0x00023001
585 COCOA_FRAME_NAME = 0x00023002
586 COCOA_GRAPHICS_SWITCHING = 0x00023003
587 X11_CLASS_NAME = 0x00024001
588 X11_INSTANCE_NAME = 0x00024002
589 WIN32_KEYBOARD_MENU = 0x00025001
590 WIN32_SHOWDEFAULT = 0x00025002
591 WAYLAND_APP_ID = 0x00026001
592 NO_API = 0
593 OPENGL_API = 0x00030001
594 OPENGL_ES_API = 0x00030002
595 NO_ROBUSTNESS = 0
596 NO_RESET_NOTIFICATION = 0x00031001
597 LOSE_CONTEXT_ON_RESET = 0x00031002
598 OPENGL_ANY_PROFILE = 0
599 OPENGL_CORE_PROFILE = 0x00032001
600 OPENGL_COMPAT_PROFILE = 0x00032002
601 CURSOR = 0x00033001
602 STICKY_KEYS = 0x00033002
603 STICKY_MOUSE_BUTTONS = 0x00033003
604 LOCK_KEY_MODS = 0x00033004
605 RAW_MOUSE_MOTION = 0x00033005
606 CURSOR_NORMAL = 0x00034001
607 CURSOR_HIDDEN = 0x00034002
608 CURSOR_DISABLED = 0x00034003
609 CURSOR_CAPTURED = 0x00034004
610 ANY_RELEASE_BEHAVIOR = 0
611 RELEASE_BEHAVIOR_FLUSH = 0x00035001
612 RELEASE_BEHAVIOR_NONE = 0x00035002
613 NATIVE_CONTEXT_API = 0x00036001
614 EGL_CONTEXT_API = 0x00036002
615 OSMESA_CONTEXT_API = 0x00036003
616 ARROW_CURSOR = 0x00036001
617 IBEAM_CURSOR = 0x00036002
618 CROSSHAIR_CURSOR = 0x00036003
619 HAND_CURSOR = 0x00036004
620 POINTING_HAND_CURSOR = 0x00036004
621 HRESIZE_CURSOR = 0x00036005
622 RESIZE_EW_CURSOR = 0x00036005
623 VRESIZE_CURSOR = 0x00036006
624 RESIZE_NS_CURSOR = 0x00036006
625 RESIZE_NWSE_CURSOR = 0x00036007
626 RESIZE_NESW_CURSOR = 0x00036008
627 RESIZE_ALL_CURSOR = 0x00036009
628 NOT_ALLOWED_CURSOR = 0x0003600A
629 ANGLE_PLATFORM_TYPE_NONE = 0x00037001
630 ANGLE_PLATFORM_TYPE_OPENGL = 0x00037002
631 ANGLE_PLATFORM_TYPE_OPENGLES = 0x00037003
632 ANGLE_PLATFORM_TYPE_D3D9 = 0x00037004
633 ANGLE_PLATFORM_TYPE_D3D11 = 0x00037005
634 ANGLE_PLATFORM_TYPE_VULKAN = 0x00037007
635 ANGLE_PLATFORM_TYPE_METAL = 0x00037008
636 WAYLAND_PREFER_LIBDECOR = 0x00038001
637 WAYLAND_DISABLE_LIBDECOR = 0x00038002
638 CONNECTED = 0x00040001
639 DISCONNECTED = 0x00040002
640 JOYSTICK_HAT_BUTTONS = 0x00050001
641 ANGLE_PLATFORM_TYPE = 0x00050002
642 PLATFORM = 0x00050003
643 COCOA_CHDIR_RESOURCES = 0x00051001
644 COCOA_MENUBAR = 0x00051002
645 X11_XCB_VULKAN_SURFACE = 0x00052001
646 WAYLAND_LIBDECOR = 0x00053001
647 ANY_PLATFORM = 0x00060000
648 PLATFORM_WIN32 = 0x00060001
649 PLATFORM_COCOA = 0x00060002
650 PLATFORM_WAYLAND = 0x00060003
651 PLATFORM_X11 = 0x00060004
652 PLATFORM_NULL = 0x00060005
653 ANY_POSITION = 0x80000000
654 DONT_CARE = -1
655
656 if _PREVIEW:
657 UNLIMITED_MOUSE_BUTTONS = 0x00033006
658
659
660 _exc_info_from_callback = None
661 def _callback_exception_decorator(func):
662 @functools.wraps(func)
663 def callback_wrapper(*args, **kwargs):
664 global _exc_info_from_callback
665 if _exc_info_from_callback is not None:
666 # We are on the way back to Python after an exception was raised.
667 # Do not call further callbacks and wait for the errcheck function
668 # to handle the exception first.
669 return
670 try:
671 return func(*args, **kwargs)
672 except (KeyboardInterrupt, SystemExit):
673 raise
674 except:
675 _exc_info_from_callback = sys.exc_info()
676 return callback_wrapper
677
678
679 def _prepare_errcheck():
680 """
681 This function sets the errcheck attribute of all ctypes wrapped functions
682 to evaluate the _exc_info_from_callback global variable and re-raise any
683 exceptions that might have been raised in callbacks.
684 It also modifies all callback types to automatically wrap the function
685 using the _callback_exception_decorator.
686 """
687 def errcheck(result, *args):
688 global _exc_info_from_callback
689 if _exc_info_from_callback is not None:
690 exc = _exc_info_from_callback
691 _exc_info_from_callback = None
692 _reraise(exc[1], exc[2])
693 return result
694
695 for symbol in dir(_glfw):
696 if symbol.startswith('glfw'):
697 getattr(_glfw, symbol).errcheck = errcheck
698
699 _globals = globals()
700 for symbol in _globals:
701 if symbol.startswith('_GLFW') and symbol.endswith('fun'):
702 def wrapper_cfunctype(func, cfunctype=_globals[symbol]):
703 return cfunctype(_callback_exception_decorator(func))
704 _globals[symbol] = wrapper_cfunctype
705
706
707 _GLFWerrorfun = ctypes.CFUNCTYPE(None,
708 ctypes.c_int,
709 ctypes.c_char_p)
710 _GLFWwindowposfun = ctypes.CFUNCTYPE(None,
711 ctypes.POINTER(_GLFWwindow),
712 ctypes.c_int,
713 ctypes.c_int)
714 _GLFWwindowsizefun = ctypes.CFUNCTYPE(None,
715 ctypes.POINTER(_GLFWwindow),
716 ctypes.c_int,
717 ctypes.c_int)
718 _GLFWwindowclosefun = ctypes.CFUNCTYPE(None,
719 ctypes.POINTER(_GLFWwindow))
720 _GLFWwindowrefreshfun = ctypes.CFUNCTYPE(None,
721 ctypes.POINTER(_GLFWwindow))
722 _GLFWwindowfocusfun = ctypes.CFUNCTYPE(None,
723 ctypes.POINTER(_GLFWwindow),
724 ctypes.c_int)
725 _GLFWwindowiconifyfun = ctypes.CFUNCTYPE(None,
726 ctypes.POINTER(_GLFWwindow),
727 ctypes.c_int)
728 _GLFWwindowmaximizefun = ctypes.CFUNCTYPE(None,
729 ctypes.POINTER(_GLFWwindow),
730 ctypes.c_int)
731 _GLFWframebuffersizefun = ctypes.CFUNCTYPE(None,
732 ctypes.POINTER(_GLFWwindow),
733 ctypes.c_int,
734 ctypes.c_int)
735 _GLFWwindowcontentscalefun = ctypes.CFUNCTYPE(None,
736 ctypes.POINTER(_GLFWwindow),
737 ctypes.c_float,
738 ctypes.c_float)
739 _GLFWmousebuttonfun = ctypes.CFUNCTYPE(None,
740 ctypes.POINTER(_GLFWwindow),
741 ctypes.c_int,
742 ctypes.c_int,
743 ctypes.c_int)
744 _GLFWcursorposfun = ctypes.CFUNCTYPE(None,
745 ctypes.POINTER(_GLFWwindow),
746 ctypes.c_double,
747 ctypes.c_double)
748 _GLFWcursorenterfun = ctypes.CFUNCTYPE(None,
749 ctypes.POINTER(_GLFWwindow),
750 ctypes.c_int)
751 _GLFWscrollfun = ctypes.CFUNCTYPE(None,
752 ctypes.POINTER(_GLFWwindow),
753 ctypes.c_double,
754 ctypes.c_double)
755 _GLFWkeyfun = ctypes.CFUNCTYPE(None,
756 ctypes.POINTER(_GLFWwindow),
757 ctypes.c_int,
758 ctypes.c_int,
759 ctypes.c_int,
760 ctypes.c_int)
761 _GLFWcharfun = ctypes.CFUNCTYPE(None,
762 ctypes.POINTER(_GLFWwindow),
763 ctypes.c_int)
764 _GLFWmonitorfun = ctypes.CFUNCTYPE(None,
765 ctypes.POINTER(_GLFWmonitor),
766 ctypes.c_int)
767 _GLFWdropfun = ctypes.CFUNCTYPE(None,
768 ctypes.POINTER(_GLFWwindow),
769 ctypes.c_int,
770 ctypes.POINTER(ctypes.c_char_p))
771 _GLFWcharmodsfun = ctypes.CFUNCTYPE(None,
772 ctypes.POINTER(_GLFWwindow),
773 ctypes.c_uint,
774 ctypes.c_int)
775 _GLFWjoystickfun = ctypes.CFUNCTYPE(None,
776 ctypes.c_int,
777 ctypes.c_int)
778
779 _GLFWallocatefun = ctypes.CFUNCTYPE(ctypes.c_void_p,
780 ctypes.c_size_t,
781 ctypes.c_void_p)
782 _GLFWreallocatefun = ctypes.CFUNCTYPE(ctypes.c_void_p,
783 ctypes.c_void_p,
784 ctypes.c_size_t,
785 ctypes.c_void_p)
786 _GLFWdeallocatefun = ctypes.CFUNCTYPE(None,
787 ctypes.c_void_p,
788 ctypes.c_void_p)
789
790
791 class _GLFWallocator(ctypes.Structure):
792 """
793 Wrapper for:
794 typedef struct GLFWallocator GLFWallocator;
795 """
796 _fields_ = [
797 ("allocate", _GLFWallocatefun),
798 ("reallocate", _GLFWreallocatefun),
799 ("deallocate", _GLFWdeallocatefun),
800 ]
801
802
803 _glfw.glfwInit.restype = ctypes.c_int
804 _glfw.glfwInit.argtypes = []
805 def init():
806 """
807 Initializes the GLFW library.
808
809 Wrapper for:
810 int glfwInit(void);
811 """
812 cwd = _getcwd()
813 res = _glfw.glfwInit()
814 os.chdir(cwd)
815 return res
816
817 _glfw.glfwTerminate.restype = None
818 _glfw.glfwTerminate.argtypes = []
819 def terminate():
820 """
821 Terminates the GLFW library.
822
823 Wrapper for:
824 void glfwTerminate(void);
825 """
826
827 for callback_repository in _callback_repositories:
828 for window_addr in list(callback_repository.keys()):
829 del callback_repository[window_addr]
830 for window_addr in list(_window_user_data_repository.keys()):
831 del _window_user_data_repository[window_addr]
832 _glfw.glfwTerminate()
833
834
835 if hasattr(_glfw, 'glfwInitHint'):
836 _glfw.glfwInitHint.restype = None
837 _glfw.glfwInitHint.argtypes = [ctypes.c_int,
838 ctypes.c_int]
839 def init_hint(hint, value):
840 """
841 Sets the specified init hint to the desired value.
842
843 Wrapper for:
844 void glfwInitHint(int hint, int value);
845 """
846 _glfw.glfwInitHint(hint, value)
847
848
849 _glfw.glfwGetVersion.restype = None
850 _glfw.glfwGetVersion.argtypes = [ctypes.POINTER(ctypes.c_int),
851 ctypes.POINTER(ctypes.c_int),
852 ctypes.POINTER(ctypes.c_int)]
853 def get_version():
854 """
855 Retrieves the version of the GLFW library.
856
857 Wrapper for:
858 void glfwGetVersion(int* major, int* minor, int* rev);
859 """
860 major_value = ctypes.c_int(0)
861 major = ctypes.pointer(major_value)
862 minor_value = ctypes.c_int(0)
863 minor = ctypes.pointer(minor_value)
864 rev_value = ctypes.c_int(0)
865 rev = ctypes.pointer(rev_value)
866 _glfw.glfwGetVersion(major, minor, rev)
867 return major_value.value, minor_value.value, rev_value.value
868
869 _glfw.glfwGetVersionString.restype = ctypes.c_char_p
870 _glfw.glfwGetVersionString.argtypes = []
871 def get_version_string():
872 """
873 Returns a string describing the compile-time configuration.
874
875 Wrapper for:
876 const char* glfwGetVersionString(void);
877 """
878 return _glfw.glfwGetVersionString()
879
880
881 if hasattr(_glfw, 'glfwGetError'):
882 _glfw.glfwGetError.restype = ctypes.c_int
883 _glfw.glfwGetError.argtypes = [ctypes.POINTER(ctypes.c_char_p)]
884 def get_error():
885 """
886 Returns and clears the last error for the calling thread.
887
888 Wrapper for:
889 int glfwGetError(const char** description);
890 """
891 error_description = (ctypes.c_char_p * 1)()
892 error_code = _glfw.glfwGetError(error_description)
893 return error_code, error_description[0]
894
895
896 @_callback_exception_decorator
897 def _handle_glfw_errors(error_code, description):
898 """
899 Default error callback that raises GLFWError exceptions, issues GLFWError
900 warnings or logs to the 'glfw' logger.
901 Set an alternative error callback or set glfw.ERROR_REPORTING to False or
902 'ignore' to disable this behavior.
903 """
904 global ERROR_REPORTING
905 message = "(%d) %s" % (error_code, description)
906 error_reporting = ERROR_REPORTING
907 if isinstance(error_reporting, dict):
908 if error_code in error_reporting:
909 error_reporting = error_reporting[error_code]
910 elif None in error_reporting:
911 error_reporting = error_reporting[None]
912 else:
913 error_reporting = None
914 if error_reporting in ('raise', 'exception', True):
915 raise GLFWError(message, error_code=error_code)
916 elif error_reporting in ('warn', 'warning'):
917 warnings.warn(message, GLFWError)
918 elif error_reporting in ('log',):
919 logging.getLogger('glfw').debug(message)
920 elif error_reporting in ('ignore', False):
921 pass
922 else:
923 raise ValueError('Invalid value of ERROR_REPORTING while handling GLFW error:\n' + message)
924
925 _default_error_callback = _GLFWerrorfun(_handle_glfw_errors)
926 _error_callback = (_handle_glfw_errors, _default_error_callback)
927 _glfw.glfwSetErrorCallback.restype = _GLFWerrorfun
928 _glfw.glfwSetErrorCallback.argtypes = [_GLFWerrorfun]
929 _glfw.glfwSetErrorCallback(_default_error_callback)
930 def set_error_callback(cbfun):
931 """
932 Sets the error callback.
933
934 Wrapper for:
935 GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun cbfun);
936 """
937 global _error_callback
938 previous_callback = _error_callback
939 if cbfun is None:
940 cbfun = _handle_glfw_errors
941 c_cbfun = _default_error_callback
942 else:
943 c_cbfun = _GLFWerrorfun(cbfun)
944 _error_callback = (cbfun, c_cbfun)
945 cbfun = c_cbfun
946 _glfw.glfwSetErrorCallback(cbfun)
947 if previous_callback is not None and previous_callback[0] != _handle_glfw_errors:
948 return previous_callback[0]
949
950 _glfw.glfwGetMonitors.restype = ctypes.POINTER(ctypes.POINTER(_GLFWmonitor))
951 _glfw.glfwGetMonitors.argtypes = [ctypes.POINTER(ctypes.c_int)]
952 def get_monitors():
953 """
954 Returns the currently connected monitors.
955
956 Wrapper for:
957 GLFWmonitor** glfwGetMonitors(int* count);
958 """
959 count_value = ctypes.c_int(0)
960 count = ctypes.pointer(count_value)
961 result = _glfw.glfwGetMonitors(count)
962 monitors = [result[i] for i in range(count_value.value)]
963 return monitors
964
965 _glfw.glfwGetPrimaryMonitor.restype = ctypes.POINTER(_GLFWmonitor)
966 _glfw.glfwGetPrimaryMonitor.argtypes = []
967 def get_primary_monitor():
968 """
969 Returns the primary monitor.
970
971 Wrapper for:
972 GLFWmonitor* glfwGetPrimaryMonitor(void);
973 """
974 return _glfw.glfwGetPrimaryMonitor()
975
976 _glfw.glfwGetMonitorPos.restype = None
977 _glfw.glfwGetMonitorPos.argtypes = [ctypes.POINTER(_GLFWmonitor),
978 ctypes.POINTER(ctypes.c_int),
979 ctypes.POINTER(ctypes.c_int)]
980 def get_monitor_pos(monitor):
981 """
982 Returns the position of the monitor's viewport on the virtual screen.
983
984 Wrapper for:
985 void glfwGetMonitorPos(GLFWmonitor* monitor, int* xpos, int* ypos);
986 """
987 xpos_value = ctypes.c_int(0)
988 xpos = ctypes.pointer(xpos_value)
989 ypos_value = ctypes.c_int(0)
990 ypos = ctypes.pointer(ypos_value)
991 _glfw.glfwGetMonitorPos(monitor, xpos, ypos)
992 return xpos_value.value, ypos_value.value
993
994
995 if hasattr(_glfw, 'glfwGetMonitorWorkarea'):
996 _glfw.glfwGetMonitorWorkarea.restype = None
997 _glfw.glfwGetMonitorWorkarea.argtypes = [ctypes.POINTER(_GLFWmonitor),
998 ctypes.POINTER(ctypes.c_int),
999 ctypes.POINTER(ctypes.c_int),
1000 ctypes.POINTER(ctypes.c_int),
1001 ctypes.POINTER(ctypes.c_int)]
1002
1003
1004 def get_monitor_workarea(monitor):
1005 """
1006 Retrives the work area of the monitor.
1007
1008 Wrapper for:
1009 void glfwGetMonitorWorkarea(GLFWmonitor* monitor, int* xpos, int* ypos, int* width, int* height);
1010 """
1011 xpos_value = ctypes.c_int(0)
1012 xpos = ctypes.pointer(xpos_value)
1013 ypos_value = ctypes.c_int(0)
1014 ypos = ctypes.pointer(ypos_value)
1015 width_value = ctypes.c_int(0)
1016 width = ctypes.pointer(width_value)
1017 height_value = ctypes.c_int(0)
1018 height = ctypes.pointer(height_value)
1019 _glfw.glfwGetMonitorWorkarea(monitor, xpos, ypos, width, height)
1020 return (
1021 xpos_value.value,
1022 ypos_value.value,
1023 width_value.value,
1024 height_value.value
1025 )
1026
1027 _glfw.glfwGetMonitorPhysicalSize.restype = None
1028 _glfw.glfwGetMonitorPhysicalSize.argtypes = [ctypes.POINTER(_GLFWmonitor),
1029 ctypes.POINTER(ctypes.c_int),
1030 ctypes.POINTER(ctypes.c_int)]
1031 def get_monitor_physical_size(monitor):
1032 """
1033 Returns the physical size of the monitor.
1034
1035 Wrapper for:
1036 void glfwGetMonitorPhysicalSize(GLFWmonitor* monitor, int* width, int* height);
1037 """
1038 width_value = ctypes.c_int(0)
1039 width = ctypes.pointer(width_value)
1040 height_value = ctypes.c_int(0)
1041 height = ctypes.pointer(height_value)
1042 _glfw.glfwGetMonitorPhysicalSize(monitor, width, height)
1043 return width_value.value, height_value.value
1044
1045
1046 if hasattr(_glfw, 'glfwGetMonitorContentScale'):
1047 _glfw.glfwGetMonitorContentScale.restype = None
1048 _glfw.glfwGetMonitorContentScale.argtypes = [ctypes.POINTER(_GLFWmonitor),
1049 ctypes.POINTER(ctypes.c_float),
1050 ctypes.POINTER(ctypes.c_float)]
1051 def get_monitor_content_scale(monitor):
1052 """
1053 Retrieves the content scale for the specified monitor.
1054
1055 Wrapper for:
1056 void glfwGetMonitorContentScale(GLFWmonitor* monitor, float* xscale, float* yscale);
1057 """
1058 xscale_value = ctypes.c_float(0)
1059 xscale = ctypes.pointer(xscale_value)
1060 yscale_value = ctypes.c_float(0)
1061 yscale = ctypes.pointer(yscale_value)
1062 _glfw.glfwGetMonitorContentScale(monitor, xscale, yscale)
1063 return xscale_value.value, yscale_value.value
1064
1065
1066 _glfw.glfwGetMonitorName.restype = ctypes.c_char_p
1067 _glfw.glfwGetMonitorName.argtypes = [ctypes.POINTER(_GLFWmonitor)]
1068 def get_monitor_name(monitor):
1069 """
1070 Returns the name of the specified monitor.
1071
1072 Wrapper for:
1073 const char* glfwGetMonitorName(GLFWmonitor* monitor);
1074 """
1075 return _glfw.glfwGetMonitorName(monitor)
1076
1077
1078 if hasattr(_glfw, 'glfwSetMonitorUserPointer') and hasattr(_glfw, 'glfwGetMonitorUserPointer'):
1079 _monitor_user_data_repository = {}
1080 _glfw.glfwSetMonitorUserPointer.restype = None
1081 _glfw.glfwSetMonitorUserPointer.argtypes = [ctypes.POINTER(_GLFWmonitor),
1082 ctypes.c_void_p]
1083
1084
1085 def set_monitor_user_pointer(monitor, pointer):
1086 """
1087 Sets the user pointer of the specified monitor. You may pass a normal
1088 python object into this function and it will be wrapped automatically.
1089 The object will be kept in existence until the pointer is set to
1090 something else.
1091
1092 Wrapper for:
1093 void glfwSetMonitorUserPointer(int jid, void* pointer);
1094 """
1095
1096 data = (False, pointer)
1097 if not isinstance(pointer, ctypes.c_void_p):
1098 data = (True, pointer)
1099 # Create a void pointer for the python object
1100 pointer = ctypes.cast(ctypes.pointer(ctypes.py_object(pointer)),
1101 ctypes.c_void_p)
1102
1103 monitor_addr = ctypes.cast(ctypes.pointer(monitor),
1104 ctypes.POINTER(ctypes.c_long)).contents.value
1105 _monitor_user_data_repository[monitor_addr] = data
1106 _glfw.glfwSetMonitorUserPointer(monitor, pointer)
1107
1108
1109 _glfw.glfwGetMonitorUserPointer.restype = ctypes.c_void_p
1110 _glfw.glfwGetMonitorUserPointer.argtypes = [ctypes.POINTER(_GLFWmonitor)]
1111
1112
1113 def get_monitor_user_pointer(monitor):
1114 """
1115 Returns the user pointer of the specified monitor.
1116
1117 Wrapper for:
1118 void* glfwGetMonitorUserPointer(int jid);
1119 """
1120 monitor_addr = ctypes.cast(ctypes.pointer(monitor),
1121 ctypes.POINTER(ctypes.c_long)).contents.value
1122
1123 if monitor_addr in _monitor_user_data_repository:
1124 data = _monitor_user_data_repository[monitor_addr]
1125 is_wrapped_py_object = data[0]
1126 if is_wrapped_py_object:
1127 return data[1]
1128 return _glfw.glfwGetMonitorUserPointer(monitor)
1129
1130
1131 _monitor_callback = None
1132 _glfw.glfwSetMonitorCallback.restype = _GLFWmonitorfun
1133 _glfw.glfwSetMonitorCallback.argtypes = [_GLFWmonitorfun]
1134 def set_monitor_callback(cbfun):
1135 """
1136 Sets the monitor configuration callback.
1137
1138 Wrapper for:
1139 GLFWmonitorfun glfwSetMonitorCallback(GLFWmonitorfun cbfun);
1140 """
1141 global _monitor_callback
1142 previous_callback = _monitor_callback
1143 if cbfun is None:
1144 cbfun = 0
1145 c_cbfun = _GLFWmonitorfun(cbfun)
1146 _monitor_callback = (cbfun, c_cbfun)
1147 cbfun = c_cbfun
1148 _glfw.glfwSetMonitorCallback(cbfun)
1149 if previous_callback is not None and previous_callback[0] != 0:
1150 return previous_callback[0]
1151
1152 _glfw.glfwGetVideoModes.restype = ctypes.POINTER(_GLFWvidmode)
1153 _glfw.glfwGetVideoModes.argtypes = [ctypes.POINTER(_GLFWmonitor),
1154 ctypes.POINTER(ctypes.c_int)]
1155 def get_video_modes(monitor):
1156 """
1157 Returns the available video modes for the specified monitor.
1158
1159 Wrapper for:
1160 const GLFWvidmode* glfwGetVideoModes(GLFWmonitor* monitor, int* count);
1161 """
1162 count_value = ctypes.c_int(0)
1163 count = ctypes.pointer(count_value)
1164 result = _glfw.glfwGetVideoModes(monitor, count)
1165 videomodes = [result[i].unwrap() for i in range(count_value.value)]
1166 return videomodes
1167
1168 _glfw.glfwGetVideoMode.restype = ctypes.POINTER(_GLFWvidmode)
1169 _glfw.glfwGetVideoMode.argtypes = [ctypes.POINTER(_GLFWmonitor)]
1170 def get_video_mode(monitor):
1171 """
1172 Returns the current mode of the specified monitor.
1173
1174 Wrapper for:
1175 const GLFWvidmode* glfwGetVideoMode(GLFWmonitor* monitor);
1176 """
1177 videomode = _glfw.glfwGetVideoMode(monitor).contents
1178 return videomode.unwrap()
1179
1180 _glfw.glfwSetGamma.restype = None
1181 _glfw.glfwSetGamma.argtypes = [ctypes.POINTER(_GLFWmonitor),
1182 ctypes.c_float]
1183 def set_gamma(monitor, gamma):
1184 """
1185 Generates a gamma ramp and sets it for the specified monitor.
1186
1187 Wrapper for:
1188 void glfwSetGamma(GLFWmonitor* monitor, float gamma);
1189 """
1190 _glfw.glfwSetGamma(monitor, gamma)
1191
1192 _glfw.glfwGetGammaRamp.restype = ctypes.POINTER(_GLFWgammaramp)
1193 _glfw.glfwGetGammaRamp.argtypes = [ctypes.POINTER(_GLFWmonitor)]
1194 def get_gamma_ramp(monitor):
1195 """
1196 Retrieves the current gamma ramp for the specified monitor.
1197
1198 Wrapper for:
1199 const GLFWgammaramp* glfwGetGammaRamp(GLFWmonitor* monitor);
1200 """
1201 gammaramp = _glfw.glfwGetGammaRamp(monitor).contents
1202 return gammaramp.unwrap()
1203
1204 _glfw.glfwSetGammaRamp.restype = None
1205 _glfw.glfwSetGammaRamp.argtypes = [ctypes.POINTER(_GLFWmonitor),
1206 ctypes.POINTER(_GLFWgammaramp)]
1207 def set_gamma_ramp(monitor, ramp):
1208 """
1209 Sets the current gamma ramp for the specified monitor.
1210
1211 Wrapper for:
1212 void glfwSetGammaRamp(GLFWmonitor* monitor, const GLFWgammaramp* ramp);
1213 """
1214 gammaramp = _GLFWgammaramp()
1215 gammaramp.wrap(ramp)
1216 _glfw.glfwSetGammaRamp(monitor, ctypes.pointer(gammaramp))
1217
1218 _glfw.glfwDefaultWindowHints.restype = None
1219 _glfw.glfwDefaultWindowHints.argtypes = []
1220 def default_window_hints():
1221 """
1222 Resets all window hints to their default values.
1223
1224 Wrapper for:
1225 void glfwDefaultWindowHints(void);
1226 """
1227 _glfw.glfwDefaultWindowHints()
1228
1229 _glfw.glfwWindowHint.restype = None
1230 _glfw.glfwWindowHint.argtypes = [ctypes.c_int,
1231 ctypes.c_int]
1232 def window_hint(hint, value):
1233 """
1234 Sets the specified window hint to the desired value.
1235
1236 Wrapper for:
1237 void glfwWindowHint(int hint, int value);
1238 """
1239 _glfw.glfwWindowHint(hint, value)
1240
1241
1242 if hasattr(_glfw, 'glfwWindowHintString'):
1243 _glfw.glfwWindowHintString.restype = None
1244 _glfw.glfwWindowHintString.argtypes = [ctypes.c_int,
1245 ctypes.c_char_p]
1246 def window_hint_string(hint, value):
1247 """
1248 Sets the specified window hint to the desired value.
1249
1250 Wrapper for:
1251 void glfwWindowHintString(int hint, const char* value);
1252 """
1253 _glfw.glfwWindowHintString(hint, _to_char_p(value))
1254
1255
1256 _glfw.glfwCreateWindow.restype = ctypes.POINTER(_GLFWwindow)
1257 _glfw.glfwCreateWindow.argtypes = [ctypes.c_int,
1258 ctypes.c_int,
1259 ctypes.c_char_p,
1260 ctypes.POINTER(_GLFWmonitor),
1261 ctypes.POINTER(_GLFWwindow)]
1262 def create_window(width, height, title, monitor, share):
1263 """
1264 Creates a window and its associated context.
1265
1266 Wrapper for:
1267 GLFWwindow* glfwCreateWindow(int width, int height, const char* title, GLFWmonitor* monitor, GLFWwindow* share);
1268 """
1269 return _glfw.glfwCreateWindow(width, height, _to_char_p(title),
1270 monitor, share)
1271
1272 _glfw.glfwDestroyWindow.restype = None
1273 _glfw.glfwDestroyWindow.argtypes = [ctypes.POINTER(_GLFWwindow)]
1274 def destroy_window(window):
1275 """
1276 Destroys the specified window and its context.
1277
1278 Wrapper for:
1279 void glfwDestroyWindow(GLFWwindow* window);
1280 """
1281 _glfw.glfwDestroyWindow(window)
1282 window_addr = ctypes.cast(ctypes.pointer(window),
1283 ctypes.POINTER(ctypes.c_ulong)).contents.value
1284 for callback_repository in _callback_repositories:
1285 if window_addr in callback_repository:
1286 del callback_repository[window_addr]
1287 if window_addr in _window_user_data_repository:
1288 del _window_user_data_repository[window_addr]
1289
1290 _glfw.glfwWindowShouldClose.restype = ctypes.c_int
1291 _glfw.glfwWindowShouldClose.argtypes = [ctypes.POINTER(_GLFWwindow)]
1292 def window_should_close(window):
1293 """
1294 Checks the close flag of the specified window.
1295
1296 Wrapper for:
1297 int glfwWindowShouldClose(GLFWwindow* window);
1298 """
1299 return _glfw.glfwWindowShouldClose(window)
1300
1301 _glfw.glfwSetWindowShouldClose.restype = None
1302 _glfw.glfwSetWindowShouldClose.argtypes = [ctypes.POINTER(_GLFWwindow),
1303 ctypes.c_int]
1304 def set_window_should_close(window, value):
1305 """
1306 Sets the close flag of the specified window.
1307
1308 Wrapper for:
1309 void glfwSetWindowShouldClose(GLFWwindow* window, int value);
1310 """
1311 _glfw.glfwSetWindowShouldClose(window, value)
1312
1313 _glfw.glfwSetWindowTitle.restype = None
1314 _glfw.glfwSetWindowTitle.argtypes = [ctypes.POINTER(_GLFWwindow),
1315 ctypes.c_char_p]
1316 def set_window_title(window, title):
1317 """
1318 Sets the title of the specified window.
1319
1320 Wrapper for:
1321 void glfwSetWindowTitle(GLFWwindow* window, const char* title);
1322 """
1323 _glfw.glfwSetWindowTitle(window, _to_char_p(title))
1324
1325 _glfw.glfwGetWindowPos.restype = None
1326 _glfw.glfwGetWindowPos.argtypes = [ctypes.POINTER(_GLFWwindow),
1327 ctypes.POINTER(ctypes.c_int),
1328 ctypes.POINTER(ctypes.c_int)]
1329 def get_window_pos(window):
1330 """
1331 Retrieves the position of the client area of the specified window.
1332
1333 Wrapper for:
1334 void glfwGetWindowPos(GLFWwindow* window, int* xpos, int* ypos);
1335 """
1336 xpos_value = ctypes.c_int(0)
1337 xpos = ctypes.pointer(xpos_value)
1338 ypos_value = ctypes.c_int(0)
1339 ypos = ctypes.pointer(ypos_value)
1340 _glfw.glfwGetWindowPos(window, xpos, ypos)
1341 return xpos_value.value, ypos_value.value
1342
1343 _glfw.glfwSetWindowPos.restype = None
1344 _glfw.glfwSetWindowPos.argtypes = [ctypes.POINTER(_GLFWwindow),
1345 ctypes.c_int,
1346 ctypes.c_int]
1347 def set_window_pos(window, xpos, ypos):
1348 """
1349 Sets the position of the client area of the specified window.
1350
1351 Wrapper for:
1352 void glfwSetWindowPos(GLFWwindow* window, int xpos, int ypos);
1353 """
1354 _glfw.glfwSetWindowPos(window, xpos, ypos)
1355
1356 _glfw.glfwGetWindowSize.restype = None
1357 _glfw.glfwGetWindowSize.argtypes = [ctypes.POINTER(_GLFWwindow),
1358 ctypes.POINTER(ctypes.c_int),
1359 ctypes.POINTER(ctypes.c_int)]
1360 def get_window_size(window):
1361 """
1362 Retrieves the size of the client area of the specified window.
1363
1364 Wrapper for:
1365 void glfwGetWindowSize(GLFWwindow* window, int* width, int* height);
1366 """
1367 width_value = ctypes.c_int(0)
1368 width = ctypes.pointer(width_value)
1369 height_value = ctypes.c_int(0)
1370 height = ctypes.pointer(height_value)
1371 _glfw.glfwGetWindowSize(window, width, height)
1372 return width_value.value, height_value.value
1373
1374 _glfw.glfwSetWindowSize.restype = None
1375 _glfw.glfwSetWindowSize.argtypes = [ctypes.POINTER(_GLFWwindow),
1376 ctypes.c_int,
1377 ctypes.c_int]
1378 def set_window_size(window, width, height):
1379 """
1380 Sets the size of the client area of the specified window.
1381
1382 Wrapper for:
1383 void glfwSetWindowSize(GLFWwindow* window, int width, int height);
1384 """
1385 _glfw.glfwSetWindowSize(window, width, height)
1386
1387 _glfw.glfwGetFramebufferSize.restype = None
1388 _glfw.glfwGetFramebufferSize.argtypes = [ctypes.POINTER(_GLFWwindow),
1389 ctypes.POINTER(ctypes.c_int),
1390 ctypes.POINTER(ctypes.c_int)]
1391 def get_framebuffer_size(window):
1392 """
1393 Retrieves the size of the framebuffer of the specified window.
1394
1395 Wrapper for:
1396 void glfwGetFramebufferSize(GLFWwindow* window, int* width, int* height);
1397 """
1398 width_value = ctypes.c_int(0)
1399 width = ctypes.pointer(width_value)
1400 height_value = ctypes.c_int(0)
1401 height = ctypes.pointer(height_value)
1402 _glfw.glfwGetFramebufferSize(window, width, height)
1403 return width_value.value, height_value.value
1404
1405
1406 if hasattr(_glfw, 'glfwGetWindowContentScale'):
1407 _glfw.glfwGetWindowContentScale.restype = None
1408 _glfw.glfwGetWindowContentScale.argtypes = [ctypes.POINTER(_GLFWwindow),
1409 ctypes.POINTER(ctypes.c_float),
1410 ctypes.POINTER(ctypes.c_float)]
1411 def get_window_content_scale(window):
1412 """
1413 Retrieves the content scale for the specified window.
1414
1415 Wrapper for:
1416 void glfwGetWindowContentScale(GLFWwindow* window, float* xscale, float* yscale);
1417 """
1418 xscale_value = ctypes.c_float(0)
1419 xscale = ctypes.pointer(xscale_value)
1420 yscale_value = ctypes.c_float(0)
1421 yscale = ctypes.pointer(yscale_value)
1422 _glfw.glfwGetWindowContentScale(window, xscale, yscale)
1423 return xscale_value.value, yscale_value.value
1424
1425
1426 if hasattr(_glfw, 'glfwGetWindowOpacity'):
1427 _glfw.glfwGetWindowOpacity.restype = ctypes.c_float
1428 _glfw.glfwGetWindowOpacity.argtypes = [ctypes.POINTER(_GLFWwindow)]
1429 def get_window_opacity(window):
1430 """
1431 Returns the opacity of the whole window.
1432
1433 Wrapper for:
1434 float glfwGetWindowOpacity(GLFWwindow* window);
1435 """
1436 return _glfw.glfwGetWindowOpacity(window)
1437
1438
1439 if hasattr(_glfw, 'glfwSetWindowOpacity'):
1440 _glfw.glfwSetWindowOpacity.restype = None
1441 _glfw.glfwSetWindowOpacity.argtypes = [ctypes.POINTER(_GLFWwindow),
1442 ctypes.c_float]
1443 def set_window_opacity(window, opacity):
1444 """
1445 Sets the opacity of the whole window.
1446
1447 Wrapper for:
1448 void glfwSetWindowOpacity(GLFWwindow* window, float opacity);
1449 """
1450 opacity = ctypes.c_float(opacity)
1451 _glfw.glfwSetWindowOpacity(window, opacity)
1452
1453
1454 _glfw.glfwIconifyWindow.restype = None
1455 _glfw.glfwIconifyWindow.argtypes = [ctypes.POINTER(_GLFWwindow)]
1456 def iconify_window(window):
1457 """
1458 Iconifies the specified window.
1459
1460 Wrapper for:
1461 void glfwIconifyWindow(GLFWwindow* window);
1462 """
1463 _glfw.glfwIconifyWindow(window)
1464
1465 _glfw.glfwRestoreWindow.restype = None
1466 _glfw.glfwRestoreWindow.argtypes = [ctypes.POINTER(_GLFWwindow)]
1467 def restore_window(window):
1468 """
1469 Restores the specified window.
1470
1471 Wrapper for:
1472 void glfwRestoreWindow(GLFWwindow* window);
1473 """
1474 _glfw.glfwRestoreWindow(window)
1475
1476 _glfw.glfwShowWindow.restype = None
1477 _glfw.glfwShowWindow.argtypes = [ctypes.POINTER(_GLFWwindow)]
1478 def show_window(window):
1479 """
1480 Makes the specified window visible.
1481
1482 Wrapper for:
1483 void glfwShowWindow(GLFWwindow* window);
1484 """
1485 _glfw.glfwShowWindow(window)
1486
1487 _glfw.glfwHideWindow.restype = None
1488 _glfw.glfwHideWindow.argtypes = [ctypes.POINTER(_GLFWwindow)]
1489 def hide_window(window):
1490 """
1491 Hides the specified window.
1492
1493 Wrapper for:
1494 void glfwHideWindow(GLFWwindow* window);
1495 """
1496 _glfw.glfwHideWindow(window)
1497
1498
1499 if hasattr(_glfw, 'glfwRequestWindowAttention'):
1500 _glfw.glfwRequestWindowAttention.restype = None
1501 _glfw.glfwRequestWindowAttention.argtypes = [ctypes.POINTER(_GLFWwindow)]
1502 def request_window_attention(window):
1503 """
1504 Requests user attention to the specified window.
1505
1506 Wrapper for:
1507 void glfwRequestWindowAttention(GLFWwindow* window);
1508 """
1509 _glfw.glfwRequestWindowAttention(window)
1510
1511
1512 _glfw.glfwGetWindowMonitor.restype = ctypes.POINTER(_GLFWmonitor)
1513 _glfw.glfwGetWindowMonitor.argtypes = [ctypes.POINTER(_GLFWwindow)]
1514 def get_window_monitor(window):
1515 """
1516 Returns the monitor that the window uses for full screen mode.
1517
1518 Wrapper for:
1519 GLFWmonitor* glfwGetWindowMonitor(GLFWwindow* window);
1520 """
1521 return _glfw.glfwGetWindowMonitor(window)
1522
1523 _glfw.glfwGetWindowAttrib.restype = ctypes.c_int
1524 _glfw.glfwGetWindowAttrib.argtypes = [ctypes.POINTER(_GLFWwindow),
1525 ctypes.c_int]
1526 def get_window_attrib(window, attrib):
1527 """
1528 Returns an attribute of the specified window.
1529
1530 Wrapper for:
1531 int glfwGetWindowAttrib(GLFWwindow* window, int attrib);
1532 """
1533 return _glfw.glfwGetWindowAttrib(window, attrib)
1534
1535
1536 if hasattr(_glfw, 'glfwSetWindowAttrib'):
1537 _glfw.glfwSetWindowAttrib.restype = None
1538 _glfw.glfwSetWindowAttrib.argtypes = [ctypes.POINTER(_GLFWwindow),
1539 ctypes.c_int,
1540 ctypes.c_int]
1541 def set_window_attrib(window, attrib, value):
1542 """
1543 Returns an attribute of the specified window.
1544
1545 Wrapper for:
1546 void glfwSetWindowAttrib(GLFWwindow* window, int attrib, int value);
1547 """
1548 _glfw.glfwSetWindowAttrib(window, attrib, value)
1549
1550
1551 _window_user_data_repository = {}
1552 _glfw.glfwSetWindowUserPointer.restype = None
1553 _glfw.glfwSetWindowUserPointer.argtypes = [ctypes.POINTER(_GLFWwindow),
1554 ctypes.c_void_p]
1555 def set_window_user_pointer(window, pointer):
1556 """
1557 Sets the user pointer of the specified window. You may pass a normal python object into this function and it will
1558 be wrapped automatically. The object will be kept in existence until the pointer is set to something else or
1559 until the window is destroyed.
1560
1561 Wrapper for:
1562 void glfwSetWindowUserPointer(GLFWwindow* window, void* pointer);
1563 """
1564
1565 data = (False, pointer)
1566 if not isinstance(pointer, ctypes.c_void_p):
1567 data = (True, pointer)
1568 # Create a void pointer for the python object
1569 pointer = ctypes.cast(ctypes.pointer(ctypes.py_object(pointer)), ctypes.c_void_p)
1570
1571 window_addr = ctypes.cast(ctypes.pointer(window),
1572 ctypes.POINTER(ctypes.c_long)).contents.value
1573 _window_user_data_repository[window_addr] = data
1574 _glfw.glfwSetWindowUserPointer(window, pointer)
1575
1576 _glfw.glfwGetWindowUserPointer.restype = ctypes.c_void_p
1577 _glfw.glfwGetWindowUserPointer.argtypes = [ctypes.POINTER(_GLFWwindow)]
1578 def get_window_user_pointer(window):
1579 """
1580 Returns the user pointer of the specified window.
1581
1582 Wrapper for:
1583 void* glfwGetWindowUserPointer(GLFWwindow* window);
1584 """
1585
1586 window_addr = ctypes.cast(ctypes.pointer(window),
1587 ctypes.POINTER(ctypes.c_long)).contents.value
1588
1589 if window_addr in _window_user_data_repository:
1590 data = _window_user_data_repository[window_addr]
1591 is_wrapped_py_object = data[0]
1592 if is_wrapped_py_object:
1593 return data[1]
1594 return _glfw.glfwGetWindowUserPointer(window)
1595
1596 _window_pos_callback_repository = {}
1597 _callback_repositories.append(_window_pos_callback_repository)
1598 _glfw.glfwSetWindowPosCallback.restype = _GLFWwindowposfun
1599 _glfw.glfwSetWindowPosCallback.argtypes = [ctypes.POINTER(_GLFWwindow),
1600 _GLFWwindowposfun]
1601 def set_window_pos_callback(window, cbfun):
1602 """
1603 Sets the position callback for the specified window.
1604
1605 Wrapper for:
1606 GLFWwindowposfun glfwSetWindowPosCallback(GLFWwindow* window, GLFWwindowposfun cbfun);
1607 """
1608 window_addr = ctypes.cast(ctypes.pointer(window),
1609 ctypes.POINTER(ctypes.c_long)).contents.value
1610 if window_addr in _window_pos_callback_repository:
1611 previous_callback = _window_pos_callback_repository[window_addr]
1612 else:
1613 previous_callback = None
1614 if cbfun is None:
1615 cbfun = 0
1616 c_cbfun = _GLFWwindowposfun(cbfun)
1617 _window_pos_callback_repository[window_addr] = (cbfun, c_cbfun)
1618 cbfun = c_cbfun
1619 _glfw.glfwSetWindowPosCallback(window, cbfun)
1620 if previous_callback is not None and previous_callback[0] != 0:
1621 return previous_callback[0]
1622
1623 _window_size_callback_repository = {}
1624 _callback_repositories.append(_window_size_callback_repository)
1625 _glfw.glfwSetWindowSizeCallback.restype = _GLFWwindowsizefun
1626 _glfw.glfwSetWindowSizeCallback.argtypes = [ctypes.POINTER(_GLFWwindow),
1627 _GLFWwindowsizefun]
1628 def set_window_size_callback(window, cbfun):
1629 """
1630 Sets the size callback for the specified window.
1631
1632 Wrapper for:
1633 GLFWwindowsizefun glfwSetWindowSizeCallback(GLFWwindow* window, GLFWwindowsizefun cbfun);
1634 """
1635 window_addr = ctypes.cast(ctypes.pointer(window),
1636 ctypes.POINTER(ctypes.c_long)).contents.value
1637 if window_addr in _window_size_callback_repository:
1638 previous_callback = _window_size_callback_repository[window_addr]
1639 else:
1640 previous_callback = None
1641 if cbfun is None:
1642 cbfun = 0
1643 c_cbfun = _GLFWwindowsizefun(cbfun)
1644 _window_size_callback_repository[window_addr] = (cbfun, c_cbfun)
1645 cbfun = c_cbfun
1646 _glfw.glfwSetWindowSizeCallback(window, cbfun)
1647 if previous_callback is not None and previous_callback[0] != 0:
1648 return previous_callback[0]
1649
1650 _window_close_callback_repository = {}
1651 _callback_repositories.append(_window_close_callback_repository)
1652 _glfw.glfwSetWindowCloseCallback.restype = _GLFWwindowclosefun
1653 _glfw.glfwSetWindowCloseCallback.argtypes = [ctypes.POINTER(_GLFWwindow),
1654 _GLFWwindowclosefun]
1655 def set_window_close_callback(window, cbfun):
1656 """
1657 Sets the close callback for the specified window.
1658
1659 Wrapper for:
1660 GLFWwindowclosefun glfwSetWindowCloseCallback(GLFWwindow* window, GLFWwindowclosefun cbfun);
1661 """
1662 window_addr = ctypes.cast(ctypes.pointer(window),
1663 ctypes.POINTER(ctypes.c_long)).contents.value
1664 if window_addr in _window_close_callback_repository:
1665 previous_callback = _window_close_callback_repository[window_addr]
1666 else:
1667 previous_callback = None
1668 if cbfun is None:
1669 cbfun = 0
1670 c_cbfun = _GLFWwindowclosefun(cbfun)
1671 _window_close_callback_repository[window_addr] = (cbfun, c_cbfun)
1672 cbfun = c_cbfun
1673 _glfw.glfwSetWindowCloseCallback(window, cbfun)
1674 if previous_callback is not None and previous_callback[0] != 0:
1675 return previous_callback[0]
1676
1677 _window_refresh_callback_repository = {}
1678 _callback_repositories.append(_window_refresh_callback_repository)
1679 _glfw.glfwSetWindowRefreshCallback.restype = _GLFWwindowrefreshfun
1680 _glfw.glfwSetWindowRefreshCallback.argtypes = [ctypes.POINTER(_GLFWwindow),
1681 _GLFWwindowrefreshfun]
1682 def set_window_refresh_callback(window, cbfun):
1683 """
1684 Sets the refresh callback for the specified window.
1685
1686 Wrapper for:
1687 GLFWwindowrefreshfun glfwSetWindowRefreshCallback(GLFWwindow* window, GLFWwindowrefreshfun cbfun);
1688 """
1689 window_addr = ctypes.cast(ctypes.pointer(window),
1690 ctypes.POINTER(ctypes.c_long)).contents.value
1691 if window_addr in _window_refresh_callback_repository:
1692 previous_callback = _window_refresh_callback_repository[window_addr]
1693 else:
1694 previous_callback = None
1695 if cbfun is None:
1696 cbfun = 0
1697 c_cbfun = _GLFWwindowrefreshfun(cbfun)
1698 _window_refresh_callback_repository[window_addr] = (cbfun, c_cbfun)
1699 cbfun = c_cbfun
1700 _glfw.glfwSetWindowRefreshCallback(window, cbfun)
1701 if previous_callback is not None and previous_callback[0] != 0:
1702 return previous_callback[0]
1703
1704 _window_focus_callback_repository = {}
1705 _callback_repositories.append(_window_focus_callback_repository)
1706 _glfw.glfwSetWindowFocusCallback.restype = _GLFWwindowfocusfun
1707 _glfw.glfwSetWindowFocusCallback.argtypes = [ctypes.POINTER(_GLFWwindow),
1708 _GLFWwindowfocusfun]
1709 def set_window_focus_callback(window, cbfun):
1710 """
1711 Sets the focus callback for the specified window.
1712
1713 Wrapper for:
1714 GLFWwindowfocusfun glfwSetWindowFocusCallback(GLFWwindow* window, GLFWwindowfocusfun cbfun);
1715 """
1716 window_addr = ctypes.cast(ctypes.pointer(window),
1717 ctypes.POINTER(ctypes.c_long)).contents.value
1718 if window_addr in _window_focus_callback_repository:
1719 previous_callback = _window_focus_callback_repository[window_addr]
1720 else:
1721 previous_callback = None
1722 if cbfun is None:
1723 cbfun = 0
1724 c_cbfun = _GLFWwindowfocusfun(cbfun)
1725 _window_focus_callback_repository[window_addr] = (cbfun, c_cbfun)
1726 cbfun = c_cbfun
1727 _glfw.glfwSetWindowFocusCallback(window, cbfun)
1728 if previous_callback is not None and previous_callback[0] != 0:
1729 return previous_callback[0]
1730
1731 _window_iconify_callback_repository = {}
1732 _callback_repositories.append(_window_iconify_callback_repository)
1733 _glfw.glfwSetWindowIconifyCallback.restype = _GLFWwindowiconifyfun
1734 _glfw.glfwSetWindowIconifyCallback.argtypes = [ctypes.POINTER(_GLFWwindow),
1735 _GLFWwindowiconifyfun]
1736 def set_window_iconify_callback(window, cbfun):
1737 """
1738 Sets the iconify callback for the specified window.
1739
1740 Wrapper for:
1741 GLFWwindowiconifyfun glfwSetWindowIconifyCallback(GLFWwindow* window, GLFWwindowiconifyfun cbfun);
1742 """
1743 window_addr = ctypes.cast(ctypes.pointer(window),
1744 ctypes.POINTER(ctypes.c_long)).contents.value
1745 if window_addr in _window_iconify_callback_repository:
1746 previous_callback = _window_iconify_callback_repository[window_addr]
1747 else:
1748 previous_callback = None
1749 if cbfun is None:
1750 cbfun = 0
1751 c_cbfun = _GLFWwindowiconifyfun(cbfun)
1752 _window_iconify_callback_repository[window_addr] = (cbfun, c_cbfun)
1753 cbfun = c_cbfun
1754 _glfw.glfwSetWindowIconifyCallback(window, cbfun)
1755 if previous_callback is not None and previous_callback[0] != 0:
1756 return previous_callback[0]
1757
1758
1759 if hasattr(_glfw, 'glfwSetWindowMaximizeCallback'):
1760 _window_maximize_callback_repository = {}
1761 _callback_repositories.append(_window_maximize_callback_repository)
1762 _glfw.glfwSetWindowMaximizeCallback.restype = _GLFWwindowmaximizefun
1763 _glfw.glfwSetWindowMaximizeCallback.argtypes = [
1764 ctypes.POINTER(_GLFWwindow),
1765 _GLFWwindowmaximizefun
1766 ]
1767 def set_window_maximize_callback(window, cbfun):
1768 """
1769 Sets the maximize callback for the specified window.
1770
1771 Wrapper for:
1772 GLFWwindowmaximizefun glfwSetWindowMaximizeCallback(GLFWwindow* window, GLFWwindowmaximizefun cbfun);
1773 """
1774 window_addr = ctypes.cast(ctypes.pointer(window),
1775 ctypes.POINTER(ctypes.c_long)).contents.value
1776 if window_addr in _window_maximize_callback_repository:
1777 previous_callback = _window_maximize_callback_repository[
1778 window_addr]
1779 else:
1780 previous_callback = None
1781 if cbfun is None:
1782 cbfun = 0
1783 c_cbfun = _GLFWwindowmaximizefun(cbfun)
1784 _window_maximize_callback_repository[window_addr] = (cbfun, c_cbfun)
1785 cbfun = c_cbfun
1786 _glfw.glfwSetWindowMaximizeCallback(window, cbfun)
1787 if previous_callback is not None and previous_callback[0] != 0:
1788 return previous_callback[0]
1789
1790
1791 _framebuffer_size_callback_repository = {}
1792 _callback_repositories.append(_framebuffer_size_callback_repository)
1793 _glfw.glfwSetFramebufferSizeCallback.restype = _GLFWframebuffersizefun
1794 _glfw.glfwSetFramebufferSizeCallback.argtypes = [ctypes.POINTER(_GLFWwindow),
1795 _GLFWframebuffersizefun]
1796 def set_framebuffer_size_callback(window, cbfun):
1797 """
1798 Sets the framebuffer resize callback for the specified window.
1799
1800 Wrapper for:
1801 GLFWframebuffersizefun glfwSetFramebufferSizeCallback(GLFWwindow* window, GLFWframebuffersizefun cbfun);
1802 """
1803 window_addr = ctypes.cast(ctypes.pointer(window),
1804 ctypes.POINTER(ctypes.c_long)).contents.value
1805 if window_addr in _framebuffer_size_callback_repository:
1806 previous_callback = _framebuffer_size_callback_repository[window_addr]
1807 else:
1808 previous_callback = None
1809 if cbfun is None:
1810 cbfun = 0
1811 c_cbfun = _GLFWframebuffersizefun(cbfun)
1812 _framebuffer_size_callback_repository[window_addr] = (cbfun, c_cbfun)
1813 cbfun = c_cbfun
1814 _glfw.glfwSetFramebufferSizeCallback(window, cbfun)
1815 if previous_callback is not None and previous_callback[0] != 0:
1816 return previous_callback[0]
1817
1818
1819 if hasattr(_glfw, 'glfwSetWindowContentScaleCallback'):
1820 _window_content_scale_callback_repository = {}
1821 _callback_repositories.append(_window_content_scale_callback_repository)
1822 _glfw.glfwSetWindowContentScaleCallback.restype = _GLFWwindowcontentscalefun
1823 _glfw.glfwSetWindowContentScaleCallback.argtypes = [
1824 ctypes.POINTER(_GLFWwindow),
1825 _GLFWwindowcontentscalefun]
1826
1827
1828 def set_window_content_scale_callback(window, cbfun):
1829 """
1830 Sets the window content scale callback for the specified window.
1831
1832 Wrapper for:
1833 GLFWwindowcontentscalefun glfwSetWindowContentScaleCallback(GLFWwindow* window, GLFWwindowcontentscalefun cbfun);
1834 """
1835 window_addr = ctypes.cast(ctypes.pointer(window),
1836 ctypes.POINTER(ctypes.c_long)).contents.value
1837 if window_addr in _window_content_scale_callback_repository:
1838 previous_callback = _window_content_scale_callback_repository[
1839 window_addr]
1840 else:
1841 previous_callback = None
1842 if cbfun is None:
1843 cbfun = 0
1844 c_cbfun = _GLFWwindowcontentscalefun(cbfun)
1845 _window_content_scale_callback_repository[window_addr] = (cbfun, c_cbfun)
1846 cbfun = c_cbfun
1847 _glfw.glfwSetWindowContentScaleCallback(window, cbfun)
1848 if previous_callback is not None and previous_callback[0] != 0:
1849 return previous_callback[0]
1850
1851
1852 _glfw.glfwPollEvents.restype = None
1853 _glfw.glfwPollEvents.argtypes = []
1854 def poll_events():
1855 """
1856 Processes all pending events.
1857
1858 Wrapper for:
1859 void glfwPollEvents(void);
1860 """
1861 _glfw.glfwPollEvents()
1862
1863 _glfw.glfwWaitEvents.restype = None
1864 _glfw.glfwWaitEvents.argtypes = []
1865 def wait_events():
1866 """
1867 Waits until events are pending and processes them.
1868
1869 Wrapper for:
1870 void glfwWaitEvents(void);
1871 """
1872 _glfw.glfwWaitEvents()
1873
1874 _glfw.glfwGetInputMode.restype = ctypes.c_int
1875 _glfw.glfwGetInputMode.argtypes = [ctypes.POINTER(_GLFWwindow),
1876 ctypes.c_int]
1877 def get_input_mode(window, mode):
1878 """
1879 Returns the value of an input option for the specified window.
1880
1881 Wrapper for:
1882 int glfwGetInputMode(GLFWwindow* window, int mode);
1883 """
1884 return _glfw.glfwGetInputMode(window, mode)
1885
1886 _glfw.glfwSetInputMode.restype = None
1887 _glfw.glfwSetInputMode.argtypes = [ctypes.POINTER(_GLFWwindow),
1888 ctypes.c_int,
1889 ctypes.c_int]
1890 def set_input_mode(window, mode, value):
1891 """
1892 Sets an input option for the specified window.
1893 @param[in] window The window whose input mode to set.
1894 @param[in] mode One of `GLFW_CURSOR`, `GLFW_STICKY_KEYS` or
1895 `GLFW_STICKY_MOUSE_BUTTONS`.
1896 @param[in] value The new value of the specified input mode.
1897
1898 Wrapper for:
1899 void glfwSetInputMode(GLFWwindow* window, int mode, int value);
1900 """
1901 _glfw.glfwSetInputMode(window, mode, value)
1902
1903
1904 if hasattr(_glfw, 'glfwRawMouseMotionSupported'):
1905 _glfw.glfwRawMouseMotionSupported.restype = ctypes.c_int
1906 _glfw.glfwRawMouseMotionSupported.argtypes = []
1907 def raw_mouse_motion_supported():
1908 """
1909 Returns whether raw mouse motion is supported.
1910
1911 Wrapper for:
1912 int glfwRawMouseMotionSupported(void);
1913 """
1914 return _glfw.glfwRawMouseMotionSupported() != 0
1915
1916
1917 _glfw.glfwGetKey.restype = ctypes.c_int
1918 _glfw.glfwGetKey.argtypes = [ctypes.POINTER(_GLFWwindow),
1919 ctypes.c_int]
1920 def get_key(window, key):
1921 """
1922 Returns the last reported state of a keyboard key for the specified
1923 window.
1924
1925 Wrapper for:
1926 int glfwGetKey(GLFWwindow* window, int key);
1927 """
1928 return _glfw.glfwGetKey(window, key)
1929
1930 _glfw.glfwGetMouseButton.restype = ctypes.c_int
1931 _glfw.glfwGetMouseButton.argtypes = [ctypes.POINTER(_GLFWwindow),
1932 ctypes.c_int]
1933 def get_mouse_button(window, button):
1934 """
1935 Returns the last reported state of a mouse button for the specified
1936 window.
1937
1938 Wrapper for:
1939 int glfwGetMouseButton(GLFWwindow* window, int button);
1940 """
1941 return _glfw.glfwGetMouseButton(window, button)
1942
1943 _glfw.glfwGetCursorPos.restype = None
1944 _glfw.glfwGetCursorPos.argtypes = [ctypes.POINTER(_GLFWwindow),
1945 ctypes.POINTER(ctypes.c_double),
1946 ctypes.POINTER(ctypes.c_double)]
1947 def get_cursor_pos(window):
1948 """
1949 Retrieves the last reported cursor position, relative to the client
1950 area of the window.
1951
1952 Wrapper for:
1953 void glfwGetCursorPos(GLFWwindow* window, double* xpos, double* ypos);
1954 """
1955 xpos_value = ctypes.c_double(0.0)
1956 xpos = ctypes.pointer(xpos_value)
1957 ypos_value = ctypes.c_double(0.0)
1958 ypos = ctypes.pointer(ypos_value)
1959 _glfw.glfwGetCursorPos(window, xpos, ypos)
1960 return xpos_value.value, ypos_value.value
1961
1962 _glfw.glfwSetCursorPos.restype = None
1963 _glfw.glfwSetCursorPos.argtypes = [ctypes.POINTER(_GLFWwindow),
1964 ctypes.c_double,
1965 ctypes.c_double]
1966 def set_cursor_pos(window, xpos, ypos):
1967 """
1968 Sets the position of the cursor, relative to the client area of the window.
1969
1970 Wrapper for:
1971 void glfwSetCursorPos(GLFWwindow* window, double xpos, double ypos);
1972 """
1973 _glfw.glfwSetCursorPos(window, xpos, ypos)
1974
1975 _key_callback_repository = {}
1976 _callback_repositories.append(_key_callback_repository)
1977 _glfw.glfwSetKeyCallback.restype = _GLFWkeyfun
1978 _glfw.glfwSetKeyCallback.argtypes = [ctypes.POINTER(_GLFWwindow),
1979 _GLFWkeyfun]
1980 def set_key_callback(window, cbfun):
1981 """
1982 Sets the key callback.
1983
1984 Wrapper for:
1985 GLFWkeyfun glfwSetKeyCallback(GLFWwindow* window, GLFWkeyfun cbfun);
1986 """
1987 window_addr = ctypes.cast(ctypes.pointer(window),
1988 ctypes.POINTER(ctypes.c_long)).contents.value
1989 if window_addr in _key_callback_repository:
1990 previous_callback = _key_callback_repository[window_addr]
1991 else:
1992 previous_callback = None
1993 if cbfun is None:
1994 cbfun = 0
1995 c_cbfun = _GLFWkeyfun(cbfun)
1996 _key_callback_repository[window_addr] = (cbfun, c_cbfun)
1997 cbfun = c_cbfun
1998 _glfw.glfwSetKeyCallback(window, cbfun)
1999 if previous_callback is not None and previous_callback[0] != 0:
2000 return previous_callback[0]
2001
2002 _char_callback_repository = {}
2003 _callback_repositories.append(_char_callback_repository)
2004 _glfw.glfwSetCharCallback.restype = _GLFWcharfun
2005 _glfw.glfwSetCharCallback.argtypes = [ctypes.POINTER(_GLFWwindow),
2006 _GLFWcharfun]
2007 def set_char_callback(window, cbfun):
2008 """
2009 Sets the Unicode character callback.
2010
2011 Wrapper for:
2012 GLFWcharfun glfwSetCharCallback(GLFWwindow* window, GLFWcharfun cbfun);
2013 """
2014 window_addr = ctypes.cast(ctypes.pointer(window),
2015 ctypes.POINTER(ctypes.c_long)).contents.value
2016 if window_addr in _char_callback_repository:
2017 previous_callback = _char_callback_repository[window_addr]
2018 else:
2019 previous_callback = None
2020 if cbfun is None:
2021 cbfun = 0
2022 c_cbfun = _GLFWcharfun(cbfun)
2023 _char_callback_repository[window_addr] = (cbfun, c_cbfun)
2024 cbfun = c_cbfun
2025 _glfw.glfwSetCharCallback(window, cbfun)
2026 if previous_callback is not None and previous_callback[0] != 0:
2027 return previous_callback[0]
2028
2029 _mouse_button_callback_repository = {}
2030 _callback_repositories.append(_mouse_button_callback_repository)
2031 _glfw.glfwSetMouseButtonCallback.restype = _GLFWmousebuttonfun
2032 _glfw.glfwSetMouseButtonCallback.argtypes = [ctypes.POINTER(_GLFWwindow),
2033 _GLFWmousebuttonfun]
2034 def set_mouse_button_callback(window, cbfun):
2035 """
2036 Sets the mouse button callback.
2037
2038 Wrapper for:
2039 GLFWmousebuttonfun glfwSetMouseButtonCallback(GLFWwindow* window, GLFWmousebuttonfun cbfun);
2040 """
2041 window_addr = ctypes.cast(ctypes.pointer(window),
2042 ctypes.POINTER(ctypes.c_long)).contents.value
2043 if window_addr in _mouse_button_callback_repository:
2044 previous_callback = _mouse_button_callback_repository[window_addr]
2045 else:
2046 previous_callback = None
2047 if cbfun is None:
2048 cbfun = 0
2049 c_cbfun = _GLFWmousebuttonfun(cbfun)
2050 _mouse_button_callback_repository[window_addr] = (cbfun, c_cbfun)
2051 cbfun = c_cbfun
2052 _glfw.glfwSetMouseButtonCallback(window, cbfun)
2053 if previous_callback is not None and previous_callback[0] != 0:
2054 return previous_callback[0]
2055
2056 _cursor_pos_callback_repository = {}
2057 _callback_repositories.append(_cursor_pos_callback_repository)
2058 _glfw.glfwSetCursorPosCallback.restype = _GLFWcursorposfun
2059 _glfw.glfwSetCursorPosCallback.argtypes = [ctypes.POINTER(_GLFWwindow),
2060 _GLFWcursorposfun]
2061 def set_cursor_pos_callback(window, cbfun):
2062 """
2063 Sets the cursor position callback.
2064
2065 Wrapper for:
2066 GLFWcursorposfun glfwSetCursorPosCallback(GLFWwindow* window, GLFWcursorposfun cbfun);
2067 """
2068 window_addr = ctypes.cast(ctypes.pointer(window),
2069 ctypes.POINTER(ctypes.c_long)).contents.value
2070 if window_addr in _cursor_pos_callback_repository:
2071 previous_callback = _cursor_pos_callback_repository[window_addr]
2072 else:
2073 previous_callback = None
2074 if cbfun is None:
2075 cbfun = 0
2076 c_cbfun = _GLFWcursorposfun(cbfun)
2077 _cursor_pos_callback_repository[window_addr] = (cbfun, c_cbfun)
2078 cbfun = c_cbfun
2079 _glfw.glfwSetCursorPosCallback(window, cbfun)
2080 if previous_callback is not None and previous_callback[0] != 0:
2081 return previous_callback[0]
2082
2083 _cursor_enter_callback_repository = {}
2084 _callback_repositories.append(_cursor_enter_callback_repository)
2085 _glfw.glfwSetCursorEnterCallback.restype = _GLFWcursorenterfun
2086 _glfw.glfwSetCursorEnterCallback.argtypes = [ctypes.POINTER(_GLFWwindow),
2087 _GLFWcursorenterfun]
2088 def set_cursor_enter_callback(window, cbfun):
2089 """
2090 Sets the cursor enter/exit callback.
2091
2092 Wrapper for:
2093 GLFWcursorenterfun glfwSetCursorEnterCallback(GLFWwindow* window, GLFWcursorenterfun cbfun);
2094 """
2095 window_addr = ctypes.cast(ctypes.pointer(window),
2096 ctypes.POINTER(ctypes.c_long)).contents.value
2097 if window_addr in _cursor_enter_callback_repository:
2098 previous_callback = _cursor_enter_callback_repository[window_addr]
2099 else:
2100 previous_callback = None
2101 if cbfun is None:
2102 cbfun = 0
2103 c_cbfun = _GLFWcursorenterfun(cbfun)
2104 _cursor_enter_callback_repository[window_addr] = (cbfun, c_cbfun)
2105 cbfun = c_cbfun
2106 _glfw.glfwSetCursorEnterCallback(window, cbfun)
2107 if previous_callback is not None and previous_callback[0] != 0:
2108 return previous_callback[0]
2109
2110 _scroll_callback_repository = {}
2111 _callback_repositories.append(_scroll_callback_repository)
2112 _glfw.glfwSetScrollCallback.restype = _GLFWscrollfun
2113 _glfw.glfwSetScrollCallback.argtypes = [ctypes.POINTER(_GLFWwindow),
2114 _GLFWscrollfun]
2115 def set_scroll_callback(window, cbfun):
2116 """
2117 Sets the scroll callback.
2118
2119 Wrapper for:
2120 GLFWscrollfun glfwSetScrollCallback(GLFWwindow* window, GLFWscrollfun cbfun);
2121 """
2122 window_addr = ctypes.cast(ctypes.pointer(window),
2123 ctypes.POINTER(ctypes.c_long)).contents.value
2124 if window_addr in _scroll_callback_repository:
2125 previous_callback = _scroll_callback_repository[window_addr]
2126 else:
2127 previous_callback = None
2128 if cbfun is None:
2129 cbfun = 0
2130 c_cbfun = _GLFWscrollfun(cbfun)
2131 _scroll_callback_repository[window_addr] = (cbfun, c_cbfun)
2132 cbfun = c_cbfun
2133 _glfw.glfwSetScrollCallback(window, cbfun)
2134 if previous_callback is not None and previous_callback[0] != 0:
2135 return previous_callback[0]
2136
2137 _glfw.glfwJoystickPresent.restype = ctypes.c_int
2138 _glfw.glfwJoystickPresent.argtypes = [ctypes.c_int]
2139 def joystick_present(joy):
2140 """
2141 Returns whether the specified joystick is present.
2142
2143 Wrapper for:
2144 int glfwJoystickPresent(int joy);
2145 """
2146 return _glfw.glfwJoystickPresent(joy)
2147
2148 _glfw.glfwGetJoystickAxes.restype = ctypes.POINTER(ctypes.c_float)
2149 _glfw.glfwGetJoystickAxes.argtypes = [ctypes.c_int,
2150 ctypes.POINTER(ctypes.c_int)]
2151 def get_joystick_axes(joy):
2152 """
2153 Returns the values of all axes of the specified joystick.
2154
2155 Wrapper for:
2156 const float* glfwGetJoystickAxes(int joy, int* count);
2157 """
2158 count_value = ctypes.c_int(0)
2159 count = ctypes.pointer(count_value)
2160 result = _glfw.glfwGetJoystickAxes(joy, count)
2161 return result, count_value.value
2162
2163 _glfw.glfwGetJoystickButtons.restype = ctypes.POINTER(ctypes.c_ubyte)
2164 _glfw.glfwGetJoystickButtons.argtypes = [ctypes.c_int,
2165 ctypes.POINTER(ctypes.c_int)]
2166 def get_joystick_buttons(joy):
2167 """
2168 Returns the state of all buttons of the specified joystick.
2169
2170 Wrapper for:
2171 const unsigned char* glfwGetJoystickButtons(int joy, int* count);
2172 """
2173 count_value = ctypes.c_int(0)
2174 count = ctypes.pointer(count_value)
2175 result = _glfw.glfwGetJoystickButtons(joy, count)
2176 return result, count_value.value
2177
2178
2179 if hasattr(_glfw, 'glfwGetJoystickHats'):
2180 _glfw.glfwGetJoystickHats.restype = ctypes.POINTER(ctypes.c_ubyte)
2181 _glfw.glfwGetJoystickHats.argtypes = [ctypes.c_int,
2182 ctypes.POINTER(ctypes.c_int)]
2183 def get_joystick_hats(joystick_id):
2184 """
2185 Returns the state of all hats of the specified joystick.
2186
2187 Wrapper for:
2188 const unsigned char* glfwGetJoystickButtons(int joy, int* count);
2189 """
2190 count_value = ctypes.c_int(0)
2191 count = ctypes.pointer(count_value)
2192 result = _glfw.glfwGetJoystickHats(joystick_id, count)
2193 return result, count_value.value
2194
2195
2196 _glfw.glfwGetJoystickName.restype = ctypes.c_char_p
2197 _glfw.glfwGetJoystickName.argtypes = [ctypes.c_int]
2198 def get_joystick_name(joy):
2199 """
2200 Returns the name of the specified joystick.
2201
2202 Wrapper for:
2203 const char* glfwGetJoystickName(int joy);
2204 """
2205 return _glfw.glfwGetJoystickName(joy)
2206
2207
2208 if hasattr(_glfw, 'glfwGetJoystickGUID'):
2209 _glfw.glfwGetJoystickGUID.restype = ctypes.c_char_p
2210 _glfw.glfwGetJoystickGUID.argtypes = [ctypes.c_int]
2211 def get_joystick_guid(joystick_id):
2212 """
2213 Returns the SDL compatible GUID of the specified joystick.
2214
2215 Wrapper for:
2216 const char* glfwGetJoystickGUID(int jid);
2217 """
2218 return _glfw.glfwGetJoystickGUID(joystick_id)
2219
2220 if hasattr(_glfw, 'glfwSetJoystickUserPointer') and hasattr(_glfw, 'glfwGetJoystickUserPointer'):
2221 _joystick_user_data_repository = {}
2222 _glfw.glfwSetJoystickUserPointer.restype = None
2223 _glfw.glfwSetJoystickUserPointer.argtypes = [ctypes.c_int,
2224 ctypes.c_void_p]
2225
2226
2227 def set_joystick_user_pointer(joystick_id, pointer):
2228 """
2229 Sets the user pointer of the specified joystick. You may pass a normal
2230 python object into this function and it will be wrapped automatically.
2231 The object will be kept in existence until the pointer is set to
2232 something else.
2233
2234 Wrapper for:
2235 void glfwSetJoystickUserPointer(int jid, void* pointer);
2236 """
2237
2238 data = (False, pointer)
2239 if not isinstance(pointer, ctypes.c_void_p):
2240 data = (True, pointer)
2241 # Create a void pointer for the python object
2242 pointer = ctypes.cast(ctypes.pointer(ctypes.py_object(pointer)),
2243 ctypes.c_void_p)
2244
2245 _joystick_user_data_repository[joystick_id] = data
2246 _glfw.glfwSetWindowUserPointer(joystick_id, pointer)
2247
2248
2249 _glfw.glfwGetJoystickUserPointer.restype = ctypes.c_void_p
2250 _glfw.glfwGetJoystickUserPointer.argtypes = [ctypes.c_int]
2251
2252
2253 def get_joystick_user_pointer(joystick_id):
2254 """
2255 Returns the user pointer of the specified joystick.
2256
2257 Wrapper for:
2258 void* glfwGetJoystickUserPointer(int jid);
2259 """
2260
2261 if joystick_id in _joystick_user_data_repository:
2262 data = _joystick_user_data_repository[joystick_id]
2263 is_wrapped_py_object = data[0]
2264 if is_wrapped_py_object:
2265 return data[1]
2266 return _glfw.glfwGetJoystickUserPointer(joystick_id)
2267
2268
2269 if hasattr(_glfw, 'glfwJoystickIsGamepad'):
2270 _glfw.glfwJoystickIsGamepad.restype = ctypes.c_int
2271 _glfw.glfwJoystickIsGamepad.argtypes = [ctypes.c_int]
2272 def joystick_is_gamepad(joystick_id):
2273 """
2274 Returns whether the specified joystick has a gamepad mapping.
2275
2276 Wrapper for:
2277 int glfwJoystickIsGamepad(int jid);
2278 """
2279 return _glfw.glfwJoystickIsGamepad(joystick_id) != 0
2280
2281
2282 if hasattr(_glfw, 'glfwGetGamepadState'):
2283 _glfw.glfwGetGamepadState.restype = ctypes.c_int
2284 _glfw.glfwGetGamepadState.argtypes = [ctypes.c_int,
2285 ctypes.POINTER(_GLFWgamepadstate)]
2286 def get_gamepad_state(joystick_id):
2287 """
2288 Retrieves the state of the specified joystick remapped as a gamepad.
2289
2290 Wrapper for:
2291 int glfwGetGamepadState(int jid, GLFWgamepadstate* state);
2292 """
2293 gamepad_state = _GLFWgamepadstate()
2294 if _glfw.glfwGetGamepadState(joystick_id, ctypes.byref(gamepad_state)) == FALSE:
2295 return None
2296 return gamepad_state.unwrap()
2297
2298
2299 _glfw.glfwSetClipboardString.restype = None
2300 _glfw.glfwSetClipboardString.argtypes = [ctypes.POINTER(_GLFWwindow),
2301 ctypes.c_char_p]
2302 def set_clipboard_string(window, string):
2303 """
2304 Sets the clipboard to the specified string.
2305
2306 Wrapper for:
2307 void glfwSetClipboardString(GLFWwindow* window, const char* string);
2308 """
2309 if window is not None:
2310 warnings.warn("The window parameter to glfwSetClipboardString is deprecated", DeprecationWarning, stacklevel=2)
2311 _glfw.glfwSetClipboardString(window, _to_char_p(string))
2312
2313 _glfw.glfwGetClipboardString.restype = ctypes.c_char_p
2314 _glfw.glfwGetClipboardString.argtypes = [ctypes.POINTER(_GLFWwindow)]
2315 def get_clipboard_string(window):
2316 """
2317 Retrieves the contents of the clipboard as a string.
2318
2319 Wrapper for:
2320 const char* glfwGetClipboardString(GLFWwindow* window);
2321 """
2322 if window is not None:
2323 warnings.warn("The window parameter to glfwSetClipboardString is deprecated", DeprecationWarning, stacklevel=2)
2324 return _glfw.glfwGetClipboardString(window)
2325
2326 _glfw.glfwGetTime.restype = ctypes.c_double
2327 _glfw.glfwGetTime.argtypes = []
2328 def get_time():
2329 """
2330 Returns the value of the GLFW timer.
2331
2332 Wrapper for:
2333 double glfwGetTime(void);
2334 """
2335 return _glfw.glfwGetTime()
2336
2337 _glfw.glfwSetTime.restype = None
2338 _glfw.glfwSetTime.argtypes = [ctypes.c_double]
2339 def set_time(time):
2340 """
2341 Sets the GLFW timer.
2342
2343 Wrapper for:
2344 void glfwSetTime(double time);
2345 """
2346 _glfw.glfwSetTime(time)
2347
2348 _glfw.glfwMakeContextCurrent.restype = None
2349 _glfw.glfwMakeContextCurrent.argtypes = [ctypes.POINTER(_GLFWwindow)]
2350 def make_context_current(window):
2351 """
2352 Makes the context of the specified window current for the calling
2353 thread.
2354
2355 Wrapper for:
2356 void glfwMakeContextCurrent(GLFWwindow* window);
2357 """
2358 _glfw.glfwMakeContextCurrent(window)
2359
2360 _glfw.glfwGetCurrentContext.restype = ctypes.POINTER(_GLFWwindow)
2361 _glfw.glfwGetCurrentContext.argtypes = []
2362 def get_current_context():
2363 """
2364 Returns the window whose context is current on the calling thread.
2365
2366 Wrapper for:
2367 GLFWwindow* glfwGetCurrentContext(void);
2368 """
2369 return _glfw.glfwGetCurrentContext()
2370
2371 _glfw.glfwSwapBuffers.restype = None
2372 _glfw.glfwSwapBuffers.argtypes = [ctypes.POINTER(_GLFWwindow)]
2373 def swap_buffers(window):
2374 """
2375 Swaps the front and back buffers of the specified window.
2376
2377 Wrapper for:
2378 void glfwSwapBuffers(GLFWwindow* window);
2379 """
2380 _glfw.glfwSwapBuffers(window)
2381
2382 _glfw.glfwSwapInterval.restype = None
2383 _glfw.glfwSwapInterval.argtypes = [ctypes.c_int]
2384 def swap_interval(interval):
2385 """
2386 Sets the swap interval for the current context.
2387
2388 Wrapper for:
2389 void glfwSwapInterval(int interval);
2390 """
2391 _glfw.glfwSwapInterval(interval)
2392
2393 _glfw.glfwExtensionSupported.restype = ctypes.c_int
2394 _glfw.glfwExtensionSupported.argtypes = [ctypes.c_char_p]
2395 def extension_supported(extension):
2396 """
2397 Returns whether the specified extension is available.
2398
2399 Wrapper for:
2400 int glfwExtensionSupported(const char* extension);
2401 """
2402 return _glfw.glfwExtensionSupported(_to_char_p(extension))
2403
2404 _glfw.glfwGetProcAddress.restype = ctypes.c_void_p
2405 _glfw.glfwGetProcAddress.argtypes = [ctypes.c_char_p]
2406 def get_proc_address(procname):
2407 """
2408 Returns the address of the specified function for the current
2409 context.
2410
2411 Wrapper for:
2412 GLFWglproc glfwGetProcAddress(const char* procname);
2413 """
2414 return _glfw.glfwGetProcAddress(_to_char_p(procname))
2415
2416 if hasattr(_glfw, 'glfwSetDropCallback'):
2417 _window_drop_callback_repository = {}
2418 _callback_repositories.append(_window_drop_callback_repository)
2419 _glfw.glfwSetDropCallback.restype = _GLFWdropfun
2420 _glfw.glfwSetDropCallback.argtypes = [ctypes.POINTER(_GLFWwindow),
2421 _GLFWdropfun]
2422 def set_drop_callback(window, cbfun):
2423 """
2424 Sets the file drop callback.
2425
2426 Wrapper for:
2427 GLFWdropfun glfwSetDropCallback(GLFWwindow* window, GLFWdropfun cbfun);
2428 """
2429 window_addr = ctypes.cast(ctypes.pointer(window),
2430 ctypes.POINTER(ctypes.c_long)).contents.value
2431 if window_addr in _window_drop_callback_repository:
2432 previous_callback = _window_drop_callback_repository[window_addr]
2433 else:
2434 previous_callback = None
2435 if cbfun is None:
2436 cbfun = 0
2437 else:
2438 def cb_wrapper(window, count, c_paths, cbfun=cbfun):
2439 paths = [c_paths[i].decode('utf-8') for i in range(count)]
2440 cbfun(window, paths)
2441 cbfun = cb_wrapper
2442 c_cbfun = _GLFWdropfun(cbfun)
2443 _window_drop_callback_repository[window_addr] = (cbfun, c_cbfun)
2444 cbfun = c_cbfun
2445 _glfw.glfwSetDropCallback(window, cbfun)
2446 if previous_callback is not None and previous_callback[0] != 0:
2447 return previous_callback[0]
2448
2449 if hasattr(_glfw, 'glfwSetCharModsCallback'):
2450 _window_char_mods_callback_repository = {}
2451 _callback_repositories.append(_window_char_mods_callback_repository)
2452 _glfw.glfwSetCharModsCallback.restype = _GLFWcharmodsfun
2453 _glfw.glfwSetCharModsCallback.argtypes = [ctypes.POINTER(_GLFWwindow),
2454 _GLFWcharmodsfun]
2455 def set_char_mods_callback(window, cbfun):
2456 """
2457 Sets the Unicode character with modifiers callback.
2458
2459 Wrapper for:
2460 GLFWcharmodsfun glfwSetCharModsCallback(GLFWwindow* window, GLFWcharmodsfun cbfun);
2461 """
2462 warnings.warn("glfwSetCharModsCallback is scheduled for removal in GLFW 4.0", DeprecationWarning, stacklevel=2)
2463 window_addr = ctypes.cast(ctypes.pointer(window),
2464 ctypes.POINTER(ctypes.c_long)).contents.value
2465 if window_addr in _window_char_mods_callback_repository:
2466 previous_callback = _window_char_mods_callback_repository[window_addr]
2467 else:
2468 previous_callback = None
2469 if cbfun is None:
2470 cbfun = 0
2471 c_cbfun = _GLFWcharmodsfun(cbfun)
2472 _window_char_mods_callback_repository[window_addr] = (cbfun, c_cbfun)
2473 cbfun = c_cbfun
2474 _glfw.glfwSetCharModsCallback(window, cbfun)
2475 if previous_callback is not None and previous_callback[0] != 0:
2476 return previous_callback[0]
2477
2478 if hasattr(_glfw, 'glfwVulkanSupported'):
2479 _glfw.glfwVulkanSupported.restype = ctypes.c_int
2480 _glfw.glfwVulkanSupported.argtypes = []
2481 def vulkan_supported():
2482 """
2483 Returns whether the Vulkan loader has been found.
2484
2485 Wrapper for:
2486 int glfwVulkanSupported(void);
2487 """
2488 return _glfw.glfwVulkanSupported() != 0
2489
2490 if hasattr(_glfw, 'glfwGetRequiredInstanceExtensions'):
2491 _glfw.glfwGetRequiredInstanceExtensions.restype = ctypes.POINTER(ctypes.c_char_p)
2492 _glfw.glfwGetRequiredInstanceExtensions.argtypes = [ctypes.POINTER(ctypes.c_uint32)]
2493 def get_required_instance_extensions():
2494 """
2495 Returns the Vulkan instance extensions required by GLFW.
2496
2497 Wrapper for:
2498 const char** glfwGetRequiredInstanceExtensions(uint32_t* count);
2499 """
2500 count_value = ctypes.c_uint32(0)
2501 count = ctypes.pointer(count_value)
2502 c_extensions = _glfw.glfwGetRequiredInstanceExtensions(count)
2503 count = count_value.value
2504 extensions = [c_extensions[i].decode('utf-8') for i in range(count)]
2505 return extensions
2506
2507 if hasattr(_glfw, 'glfwGetTimerValue'):
2508 _glfw.glfwGetTimerValue.restype = ctypes.c_uint64
2509 _glfw.glfwGetTimerValue.argtypes = []
2510 def get_timer_value():
2511 """
2512 Returns the current value of the raw timer.
2513
2514 Wrapper for:
2515 uint64_t glfwGetTimerValue(void);
2516 """
2517 return int(_glfw.glfwGetTimerValue())
2518
2519 if hasattr(_glfw, 'glfwGetTimerFrequency'):
2520 _glfw.glfwGetTimerFrequency.restype = ctypes.c_uint64
2521 _glfw.glfwGetTimerFrequency.argtypes = []
2522 def get_timer_frequency():
2523 """
2524 Returns the frequency, in Hz, of the raw timer.
2525
2526 Wrapper for:
2527 uint64_t glfwGetTimerFrequency(void);
2528 """
2529 return int(_glfw.glfwGetTimerFrequency())
2530
2531
2532 if hasattr(_glfw, 'glfwSetJoystickCallback'):
2533 _joystick_callback = None
2534 _glfw.glfwSetJoystickCallback.restype = _GLFWjoystickfun
2535 _glfw.glfwSetJoystickCallback.argtypes = [_GLFWjoystickfun]
2536 def set_joystick_callback(cbfun):
2537 """
2538 Sets the error callback.
2539
2540 Wrapper for:
2541 GLFWjoystickfun glfwSetJoystickCallback(GLFWjoystickfun cbfun);
2542 """
2543 global _joystick_callback
2544 previous_callback = _error_callback
2545 if cbfun is None:
2546 cbfun = 0
2547 c_cbfun = _GLFWjoystickfun(cbfun)
2548 _joystick_callback = (cbfun, c_cbfun)
2549 cbfun = c_cbfun
2550 _glfw.glfwSetJoystickCallback(cbfun)
2551 if previous_callback is not None and previous_callback[0] != 0:
2552 return previous_callback[0]
2553
2554
2555 if hasattr(_glfw, 'glfwUpdateGamepadMappings'):
2556 _glfw.glfwUpdateGamepadMappings.restype = ctypes.c_int
2557 _glfw.glfwUpdateGamepadMappings.argtypes = [ctypes.c_char_p]
2558 def update_gamepad_mappings(string):
2559 """
2560 Adds the specified SDL_GameControllerDB gamepad mappings.
2561
2562 Wrapper for:
2563 int glfwUpdateGamepadMappings(const char* string);
2564 """
2565 return _glfw.glfwUpdateGamepadMappings(_to_char_p(string))
2566
2567
2568 if hasattr(_glfw, 'glfwGetGamepadName'):
2569 _glfw.glfwGetGamepadName.restype = ctypes.c_char_p
2570 _glfw.glfwGetGamepadName.argtypes = [ctypes.c_int]
2571 def get_gamepad_name(joystick_id):
2572 """
2573 Returns the human-readable gamepad name for the specified joystick.
2574
2575 Wrapper for:
2576 const char* glfwGetGamepadName(int jid);
2577 """
2578 gamepad_name = _glfw.glfwGetGamepadName(joystick_id)
2579 if gamepad_name:
2580 return gamepad_name.decode('utf-8')
2581 return None
2582
2583
2584 if hasattr(_glfw, 'glfwGetKeyName'):
2585 _glfw.glfwGetKeyName.restype = ctypes.c_char_p
2586 _glfw.glfwGetKeyName.argtypes = [ctypes.c_int, ctypes.c_int]
2587 def get_key_name(key, scancode):
2588 """
2589 Returns the localized name of the specified printable key.
2590
2591 Wrapper for:
2592 const char* glfwGetKeyName(int key, int scancode);
2593 """
2594 key_name = _glfw.glfwGetKeyName(key, scancode)
2595 if key_name:
2596 return key_name.decode('utf-8')
2597 return None
2598
2599
2600 if hasattr(_glfw, 'glfwGetKeyScancode'):
2601 _glfw.glfwGetKeyScancode.restype = ctypes.c_int
2602 _glfw.glfwGetKeyScancode.argtypes = [ctypes.c_int]
2603 def get_key_scancode(key):
2604 """
2605 Returns the platform-specific scancode of the specified key.
2606
2607 Wrapper for:
2608 int glfwGetKeyScancode(int key);
2609 """
2610 return _glfw.glfwGetKeyScancode(key)
2611
2612
2613 if hasattr(_glfw, 'glfwCreateCursor'):
2614 _glfw.glfwCreateCursor.restype = ctypes.POINTER(_GLFWcursor)
2615 _glfw.glfwCreateCursor.argtypes = [ctypes.POINTER(_GLFWimage),
2616 ctypes.c_int,
2617 ctypes.c_int]
2618 def create_cursor(image, xhot, yhot):
2619 """
2620 Creates a custom cursor.
2621
2622 Wrapper for:
2623 GLFWcursor* glfwCreateCursor(const GLFWimage* image, int xhot, int yhot);
2624 """
2625 c_image = _GLFWimage()
2626 c_image.wrap(image)
2627 return _glfw.glfwCreateCursor(ctypes.pointer(c_image), xhot, yhot)
2628
2629 if hasattr(_glfw, 'glfwCreateStandardCursor'):
2630 _glfw.glfwCreateStandardCursor.restype = ctypes.POINTER(_GLFWcursor)
2631 _glfw.glfwCreateStandardCursor.argtypes = [ctypes.c_int]
2632 def create_standard_cursor(shape):
2633 """
2634 Creates a cursor with a standard shape.
2635
2636 Wrapper for:
2637 GLFWcursor* glfwCreateStandardCursor(int shape);
2638 """
2639 return _glfw.glfwCreateStandardCursor(shape)
2640
2641 if hasattr(_glfw, 'glfwDestroyCursor'):
2642 _glfw.glfwDestroyCursor.restype = None
2643 _glfw.glfwDestroyCursor.argtypes = [ctypes.POINTER(_GLFWcursor)]
2644 def destroy_cursor(cursor):
2645 """
2646 Destroys a cursor.
2647
2648 Wrapper for:
2649 void glfwDestroyCursor(GLFWcursor* cursor);
2650 """
2651 _glfw.glfwDestroyCursor(cursor)
2652
2653 if hasattr(_glfw, 'glfwSetCursor'):
2654 _glfw.glfwSetCursor.restype = None
2655 _glfw.glfwSetCursor.argtypes = [ctypes.POINTER(_GLFWwindow),
2656 ctypes.POINTER(_GLFWcursor)]
2657 def set_cursor(window, cursor):
2658 """
2659 Sets the cursor for the window.
2660
2661 Wrapper for:
2662 void glfwSetCursor(GLFWwindow* window, GLFWcursor* cursor);
2663 """
2664 _glfw.glfwSetCursor(window, cursor)
2665
2666 if hasattr(_glfw, 'glfwCreateWindowSurface'):
2667 _glfw.glfwCreateWindowSurface.restype = ctypes.c_int
2668 _glfw.glfwCreateWindowSurface.argtypes = [ctypes.c_void_p,
2669 ctypes.POINTER(_GLFWwindow),
2670 ctypes.c_void_p,
2671 ctypes.c_void_p]
2672 def create_window_surface(instance, window, allocator, surface):
2673 """
2674 Creates a Vulkan surface for the specified window.
2675
2676 Wrapper for:
2677 VkResult glfwCreateWindowSurface(VkInstance instance, GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface);
2678 """
2679 instance = _cffi_to_ctypes_void_p(instance)
2680 surface = _cffi_to_ctypes_void_p(surface)
2681 allocator = _cffi_to_ctypes_void_p(allocator)
2682 return _glfw.glfwCreateWindowSurface(instance, window, allocator, surface)
2683
2684 if hasattr(_glfw, 'glfwGetPhysicalDevicePresentationSupport'):
2685 _glfw.glfwGetPhysicalDevicePresentationSupport.restype = ctypes.c_int
2686 _glfw.glfwGetPhysicalDevicePresentationSupport.argtypes = [ctypes.c_void_p,
2687 ctypes.c_void_p,
2688 ctypes.c_uint32]
2689 def get_physical_device_presentation_support(instance, device, queuefamily):
2690 """
2691 Creates a Vulkan surface for the specified window.
2692
2693 Wrapper for:
2694 int glfwGetPhysicalDevicePresentationSupport(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily);
2695 """
2696 instance = _cffi_to_ctypes_void_p(instance)
2697 device = _cffi_to_ctypes_void_p(device)
2698 return _glfw.glfwGetPhysicalDevicePresentationSupport(instance, device, queuefamily)
2699
2700 if hasattr(_glfw, 'glfwGetInstanceProcAddress'):
2701 _glfw.glfwGetInstanceProcAddress.restype = ctypes.c_void_p
2702 _glfw.glfwGetInstanceProcAddress.argtypes = [ctypes.c_void_p,
2703 ctypes.c_char_p]
2704 def get_instance_proc_address(instance, procname):
2705 """
2706 Returns the address of the specified Vulkan instance function.
2707
2708 Wrapper for:
2709 GLFWvkproc glfwGetInstanceProcAddress(VkInstance instance, const char* procname);
2710 """
2711 instance = _cffi_to_ctypes_void_p(instance)
2712 return _glfw.glfwGetInstanceProcAddress(instance, procname)
2713
2714 if hasattr(_glfw, 'glfwSetWindowIcon'):
2715 _glfw.glfwSetWindowIcon.restype = None
2716 _glfw.glfwSetWindowIcon.argtypes = [ctypes.POINTER(_GLFWwindow),
2717 ctypes.c_int,
2718 ctypes.POINTER(_GLFWimage)]
2719
2720 def set_window_icon(window, count, images):
2721 """
2722 Sets the icon for the specified window.
2723
2724 Wrapper for:
2725 void glfwSetWindowIcon(GLFWwindow* window, int count, const GLFWimage* images);
2726 """
2727 if count == 1 and (not hasattr(images, '__len__') or len(images) == 3):
2728 # Stay compatible to calls passing a single icon
2729 images = [images]
2730 array_type = _GLFWimage * count
2731 _images = array_type()
2732 for i, image in enumerate(images):
2733 _images[i].wrap(image)
2734 _glfw.glfwSetWindowIcon(window, count, _images)
2735
2736 if hasattr(_glfw, 'glfwSetWindowSizeLimits'):
2737 _glfw.glfwSetWindowSizeLimits.restype = None
2738 _glfw.glfwSetWindowSizeLimits.argtypes = [ctypes.POINTER(_GLFWwindow),
2739 ctypes.c_int, ctypes.c_int,
2740 ctypes.c_int, ctypes.c_int]
2741
2742 def set_window_size_limits(window,
2743 minwidth, minheight,
2744 maxwidth, maxheight):
2745 """
2746 Sets the size limits of the specified window.
2747
2748 Wrapper for:
2749 void glfwSetWindowSizeLimits(GLFWwindow* window, int minwidth, int minheight, int maxwidth, int maxheight);
2750 """
2751 _glfw.glfwSetWindowSizeLimits(window,
2752 minwidth, minheight,
2753 maxwidth, maxheight)
2754
2755 if hasattr(_glfw, 'glfwSetWindowAspectRatio'):
2756 _glfw.glfwSetWindowAspectRatio.restype = None
2757 _glfw.glfwSetWindowAspectRatio.argtypes = [ctypes.POINTER(_GLFWwindow),
2758 ctypes.c_int, ctypes.c_int]
2759 def set_window_aspect_ratio(window, numer, denom):
2760 """
2761 Sets the aspect ratio of the specified window.
2762
2763 Wrapper for:
2764 void glfwSetWindowAspectRatio(GLFWwindow* window, int numer, int denom);
2765 """
2766 _glfw.glfwSetWindowAspectRatio(window, numer, denom)
2767
2768 if hasattr(_glfw, 'glfwGetWindowFrameSize'):
2769 _glfw.glfwGetWindowFrameSize.restype = None
2770 _glfw.glfwGetWindowFrameSize.argtypes = [ctypes.POINTER(_GLFWwindow),
2771 ctypes.POINTER(ctypes.c_int),
2772 ctypes.POINTER(ctypes.c_int),
2773 ctypes.POINTER(ctypes.c_int),
2774 ctypes.POINTER(ctypes.c_int)]
2775 def get_window_frame_size(window):
2776 """
2777 Retrieves the size of the frame of the window.
2778
2779 Wrapper for:
2780 void glfwGetWindowFrameSize(GLFWwindow* window, int* left, int* top, int* right, int* bottom);
2781 """
2782 left = ctypes.c_int(0)
2783 top = ctypes.c_int(0)
2784 right = ctypes.c_int(0)
2785 bottom = ctypes.c_int(0)
2786 _glfw.glfwGetWindowFrameSize(window,
2787 ctypes.pointer(left),
2788 ctypes.pointer(top),
2789 ctypes.pointer(right),
2790 ctypes.pointer(bottom))
2791 return left.value, top.value, right.value, bottom.value
2792
2793 if hasattr(_glfw, 'glfwMaximizeWindow'):
2794 _glfw.glfwMaximizeWindow.restype = None
2795 _glfw.glfwMaximizeWindow.argtypes = [ctypes.POINTER(_GLFWwindow)]
2796 def maximize_window(window):
2797 """
2798 Maximizes the specified window.
2799
2800 Wrapper for:
2801 void glfwMaximizeWindow(GLFWwindow* window);
2802 """
2803 _glfw.glfwMaximizeWindow(window)
2804
2805 if hasattr(_glfw, 'glfwFocusWindow'):
2806 _glfw.glfwFocusWindow.restype = None
2807 _glfw.glfwFocusWindow.argtypes = [ctypes.POINTER(_GLFWwindow)]
2808 def focus_window(window):
2809 """
2810 Brings the specified window to front and sets input focus.
2811
2812 Wrapper for:
2813 void glfwFocusWindow(GLFWwindow* window);
2814 """
2815 _glfw.glfwFocusWindow(window)
2816
2817 if hasattr(_glfw, 'glfwSetWindowMonitor'):
2818 _glfw.glfwSetWindowMonitor.restype = None
2819 _glfw.glfwSetWindowMonitor.argtypes = [ctypes.POINTER(_GLFWwindow),
2820 ctypes.POINTER(_GLFWmonitor),
2821 ctypes.c_int,
2822 ctypes.c_int,
2823 ctypes.c_int,
2824 ctypes.c_int,
2825 ctypes.c_int]
2826 def set_window_monitor(window, monitor, xpos, ypos, width, height,
2827 refresh_rate):
2828 """
2829 Sets the mode, monitor, video mode and placement of a window.
2830
2831 Wrapper for:
2832 void glfwSetWindowMonitor(GLFWwindow* window, GLFWmonitor* monitor, int xpos, int ypos, int width, int height, int refreshRate);
2833 """
2834 _glfw.glfwSetWindowMonitor(window, monitor,
2835 xpos, ypos, width, height, refresh_rate)
2836
2837 if hasattr(_glfw, 'glfwWaitEventsTimeout'):
2838 _glfw.glfwWaitEventsTimeout.restype = None
2839 _glfw.glfwWaitEventsTimeout.argtypes = [ctypes.c_double]
2840 def wait_events_timeout(timeout):
2841 """
2842 Waits with timeout until events are queued and processes them.
2843
2844 Wrapper for:
2845 void glfwWaitEventsTimeout(double timeout);
2846 """
2847 _glfw.glfwWaitEventsTimeout(timeout)
2848
2849 if hasattr(_glfw, 'glfwPostEmptyEvent'):
2850 _glfw.glfwPostEmptyEvent.restype = None
2851 _glfw.glfwPostEmptyEvent.argtypes = []
2852 def post_empty_event():
2853 """
2854 Posts an empty event to the event queue.
2855
2856 Wrapper for:
2857 void glfwPostEmptyEvent();
2858 """
2859 _glfw.glfwPostEmptyEvent()
2860
2861
2862 if hasattr(_glfw, 'glfwGetWin32Adapter'):
2863 _glfw.glfwGetWin32Adapter.restype = ctypes.c_char_p
2864 _glfw.glfwGetWin32Adapter.argtypes = [ctypes.POINTER(_GLFWmonitor)]
2865 def get_win32_adapter(monitor):
2866 """
2867 Returns the adapter device name of the specified monitor.
2868
2869 Wrapper for:
2870 const char* glfwGetWin32Adapter(GLFWmonitor* monitor);
2871 """
2872 adapter_name = _glfw.glfwGetWin32Adapter(monitor)
2873 if adapter_name:
2874 return adapter_name.decode('utf-8')
2875 return None
2876
2877
2878 if hasattr(_glfw, 'glfwGetWin32Monitor'):
2879 _glfw.glfwGetWin32Monitor.restype = ctypes.c_char_p
2880 _glfw.glfwGetWin32Monitor.argtypes = [ctypes.POINTER(_GLFWmonitor)]
2881 def get_win32_monitor(monitor):
2882 """
2883 Returns the display device name of the specified monitor.
2884
2885 Wrapper for:
2886 const char* glfwGetWin32Monitor(GLFWmonitor* monitor);
2887 """
2888 monitor_name = _glfw.glfwGetWin32Monitor(monitor)
2889 if monitor_name:
2890 return monitor_name.decode('utf-8')
2891 return None
2892
2893
2894 if hasattr(_glfw, 'glfwGetWin32Window'):
2895 _glfw.glfwGetWin32Window.restype = ctypes.c_void_p
2896 _glfw.glfwGetWin32Window.argtypes = [ctypes.POINTER(_GLFWwindow)]
2897 def get_win32_window(window):
2898 """
2899 Returns the HWND of the specified window.
2900
2901 Wrapper for:
2902 HWND glfwGetWin32Window(GLFWwindow* window);
2903 """
2904 return _glfw.glfwGetWin32Window(window)
2905
2906
2907 if hasattr(_glfw, 'glfwGetWGLContext'):
2908 _glfw.glfwGetWGLContext.restype = ctypes.c_void_p
2909 _glfw.glfwGetWGLContext.argtypes = [ctypes.POINTER(_GLFWwindow)]
2910 def get_wgl_context(window):
2911 """
2912 Returns the HGLRC of the specified window.
2913
2914 Wrapper for:
2915 HGLRC glfwGetWGLContext(GLFWwindow* window);
2916 """
2917 return _glfw.glfwGetWGLContext(window)
2918
2919
2920 if hasattr(_glfw, 'glfwGetCocoaMonitor'):
2921 _glfw.glfwGetCocoaMonitor.restype = ctypes.c_uint32
2922 _glfw.glfwGetCocoaMonitor.argtypes = [ctypes.POINTER(_GLFWmonitor)]
2923 def get_cocoa_monitor(monitor):
2924 """
2925 Returns the CGDirectDisplayID of the specified monitor.
2926
2927 Wrapper for:
2928 CGDirectDisplayID glfwGetCocoaMonitor(GLFWmonitor* monitor);
2929 """
2930 return _glfw.glfwGetCocoaMonitor(monitor)
2931
2932
2933 if hasattr(_glfw, 'glfwGetCocoaWindow'):
2934 _glfw.glfwGetCocoaWindow.restype = ctypes.c_void_p
2935 _glfw.glfwGetCocoaWindow.argtypes = [ctypes.POINTER(_GLFWwindow)]
2936 def get_cocoa_window(window):
2937 """
2938 Returns the NSWindow of the specified window.
2939
2940 Wrapper for:
2941 id glfwGetCocoaWindow(GLFWwindow* window);
2942 """
2943 return _glfw.glfwGetCocoaWindow(window)
2944
2945
2946 if hasattr(_glfw, 'glfwGetNSGLContext'):
2947 _glfw.glfwGetNSGLContext.restype = ctypes.c_void_p
2948 _glfw.glfwGetNSGLContext.argtypes = [ctypes.POINTER(_GLFWwindow)]
2949 def get_nsgl_context(window):
2950 """
2951 Returns the NSOpenGLContext of the specified window.
2952
2953 Wrapper for:
2954 id glfwGetNSGLContext(GLFWwindow* window);
2955 """
2956 return _glfw.glfwGetNSGLContext(window)
2957
2958
2959 if hasattr(_glfw, 'glfwGetX11Display'):
2960 _glfw.glfwGetX11Display.restype = ctypes.c_void_p
2961 _glfw.glfwGetX11Display.argtypes = []
2962 def get_x11_display():
2963 """
2964 Returns the Display used by GLFW.
2965
2966 Wrapper for:
2967 Display* glfwGetX11Display(void);
2968 """
2969 return _glfw.glfwGetX11Display()
2970
2971
2972 if hasattr(_glfw, 'glfwGetX11Adapter'):
2973 _glfw.glfwGetX11Adapter.restype = ctypes.c_uint32
2974 _glfw.glfwGetX11Adapter.argtypes = [ctypes.POINTER(_GLFWmonitor)]
2975 def get_x11_adapter(monitor):
2976 """
2977 Returns the RRCrtc of the specified monitor.
2978
2979 Wrapper for:
2980 RRCrtc glfwGetX11Adapter(GLFWmonitor* monitor);
2981 """
2982 return _glfw.glfwGetX11Adapter(monitor)
2983
2984
2985 if hasattr(_glfw, 'glfwGetX11Monitor'):
2986 _glfw.glfwGetX11Monitor.restype = ctypes.c_uint32
2987 _glfw.glfwGetX11Monitor.argtypes = [ctypes.POINTER(_GLFWmonitor)]
2988 def get_x11_monitor(monitor):
2989 """
2990 Returns the RROutput of the specified monitor.
2991
2992 Wrapper for:
2993 RROutput glfwGetX11Monitor(GLFWmonitor* monitor);
2994 """
2995 return _glfw.glfwGetX11Monitor(monitor)
2996
2997
2998 if hasattr(_glfw, 'glfwGetX11Window'):
2999 _glfw.glfwGetX11Window.restype = ctypes.c_uint32
3000 _glfw.glfwGetX11Window.argtypes = [ctypes.POINTER(_GLFWwindow)]
3001 def get_x11_window(window):
3002 """
3003 Returns the Window of the specified window.
3004
3005 Wrapper for:
3006 Window glfwGetX11Window(GLFWwindow* window);
3007 """
3008 return _glfw.glfwGetX11Window(window)
3009
3010
3011 if hasattr(_glfw, 'glfwSetX11SelectionString'):
3012 _glfw.glfwSetX11SelectionString.restype = None
3013 _glfw.glfwSetX11SelectionString.argtypes = [ctypes.c_char_p]
3014 def set_x11_selection_string(string):
3015 """
3016 Sets the current primary selection to the specified string.
3017
3018 Wrapper for:
3019 void glfwSetX11SelectionString(const char* string);
3020 """
3021 binary_string = string.encode('utf-8')
3022 _glfw.glfwSetX11SelectionString(binary_string)
3023
3024
3025 if hasattr(_glfw, 'glfwGetX11SelectionString'):
3026 _glfw.glfwGetX11SelectionString.restype = ctypes.c_char_p
3027 _glfw.glfwGetX11SelectionString.argtypes = []
3028 def get_x11_selection_string():
3029 """
3030 Returns the contents of the current primary selection as a string.
3031
3032 Wrapper for:
3033 const char* glfwGetX11SelectionString(void);
3034 """
3035 selection_string = _glfw.glfwGetX11SelectionString()
3036 if selection_string:
3037 return selection_string.decode('utf-8')
3038 return None
3039
3040
3041 if hasattr(_glfw, 'glfwGetGLXContext'):
3042 _glfw.glfwGetGLXContext.restype = ctypes.c_void_p
3043 _glfw.glfwGetGLXContext.argtypes = [ctypes.POINTER(_GLFWwindow)]
3044 def get_glx_context(window):
3045 """
3046 Returns the GLXContext of the specified window.
3047
3048 Wrapper for:
3049 GLXContext glfwGetGLXContext(GLFWwindow* window);
3050 """
3051 return _glfw.glfwGetGLXContext(window)
3052
3053
3054 if hasattr(_glfw, 'glfwGetGLXWindow'):
3055 _glfw.glfwGetGLXWindow.restype = ctypes.c_uint32
3056 _glfw.glfwGetGLXWindow.argtypes = [ctypes.POINTER(_GLFWwindow)]
3057 def get_glx_window(window):
3058 """
3059 Returns the GLXWindow of the specified window.
3060
3061 Wrapper for:
3062 GLXWindow glfwGetGLXWindow(GLFWwindow* window);
3063 """
3064 return _glfw.glfwGetGLXWindow(window)
3065
3066
3067 if hasattr(_glfw, 'glfwGetWaylandDisplay'):
3068 _glfw.glfwGetWaylandDisplay.restype = ctypes.c_void_p
3069 _glfw.glfwGetWaylandDisplay.argtypes = []
3070 def get_wayland_display():
3071 """
3072 Returns the struct wl_display* used by GLFW.
3073
3074 Wrapper for:
3075 struct wl_display* glfwGetWaylandDisplay(void);
3076 """
3077 return _glfw.glfwGetWaylandDisplay()
3078
3079
3080 if hasattr(_glfw, 'glfwGetWaylandMonitor'):
3081 _glfw.glfwGetWaylandMonitor.restype = ctypes.c_void_p
3082 _glfw.glfwGetWaylandMonitor.argtypes = [ctypes.POINTER(_GLFWmonitor)]
3083 def get_wayland_monitor(monitor):
3084 """
3085 Returns the struct wl_output* of the specified monitor.
3086
3087 Wrapper for:
3088 struct wl_output* glfwGetWaylandMonitor(GLFWmonitor* monitor);
3089 """
3090 return _glfw.glfwGetWaylandMonitor(monitor)
3091
3092
3093 if hasattr(_glfw, 'glfwGetWaylandWindow'):
3094 _glfw.glfwGetWaylandWindow.restype = ctypes.c_void_p
3095 _glfw.glfwGetWaylandWindow.argtypes = [ctypes.POINTER(_GLFWwindow)]
3096 def get_wayland_window(window):
3097 """
3098 Returns the main struct wl_surface* of the specified window.
3099
3100 Wrapper for:
3101 struct wl_surface* glfwGetWaylandWindow(GLFWwindow* window);
3102 """
3103 return _glfw.glfwGetWaylandWindow(window)
3104
3105
3106 if hasattr(_glfw, 'glfwGetEGLDisplay'):
3107 _glfw.glfwGetEGLDisplay.restype = ctypes.c_void_p
3108 _glfw.glfwGetEGLDisplay.argtypes = []
3109 def get_egl_display():
3110 """
3111 Returns the EGLDisplay used by GLFW.
3112
3113 Wrapper for:
3114 EGLDisplay glfwGetEGLDisplay(void);
3115 """
3116 return _glfw.glfwGetEGLDisplay()
3117
3118
3119 if hasattr(_glfw, 'glfwGetEGLContext'):
3120 _glfw.glfwGetEGLContext.restype = ctypes.c_void_p
3121 _glfw.glfwGetEGLContext.argtypes = [ctypes.POINTER(_GLFWwindow)]
3122 def get_egl_context(window):
3123 """
3124 Returns the EGLContext of the specified window.
3125
3126 Wrapper for:
3127 EGLContext glfwGetEGLContext(GLFWwindow* window);
3128 """
3129 return _glfw.glfwGetEGLContext(window)
3130
3131
3132 if hasattr(_glfw, 'glfwGetEGLSurface'):
3133 _glfw.glfwGetEGLSurface.restype = ctypes.c_void_p
3134 _glfw.glfwGetEGLSurface.argtypes = [ctypes.POINTER(_GLFWwindow)]
3135 def get_egl_surface(window):
3136 """
3137 Returns the EGLSurface of the specified window.
3138
3139 Wrapper for:
3140 EGLSurface glfwGetEGLSurface(GLFWwindow* window);
3141 """
3142 return _glfw.glfwGetEGLSurface(window)
3143
3144
3145 if hasattr(_glfw, 'glfwGetOSMesaColorBuffer'):
3146 _glfw.glfwGetOSMesaColorBuffer.restype = ctypes.c_int
3147 _glfw.glfwGetOSMesaColorBuffer.argtypes = [ctypes.POINTER(_GLFWwindow), ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_void_p)]
3148 def get_os_mesa_color_buffer(window):
3149 """
3150 Retrieves the color buffer associated with the specified window.
3151
3152 Wrapper for:
3153 int glfwGetOSMesaColorBuffer(GLFWwindow* window, int* width, int* height, int* format, void** buffer);
3154 """
3155 width_value = ctypes.c_int(0)
3156 width = ctypes.pointer(width_value)
3157 height_value = ctypes.c_int(0)
3158 height = ctypes.pointer(height_value)
3159 format_value = ctypes.c_int(0)
3160 format = ctypes.pointer(format_value)
3161 buffer_value = ctypes.c_void_p(0)
3162 buffer = ctypes.pointer(buffer_value)
3163 success = _glfw.glfwGetOSMesaColorBuffer(window, width, height, format, buffer)
3164 if not success:
3165 return None
3166 return width.value, height.value, format.value, buffer.value
3167
3168
3169 if hasattr(_glfw, 'glfwGetOSMesaDepthBuffer'):
3170 _glfw.glfwGetOSMesaDepthBuffer.restype = ctypes.c_int
3171 _glfw.glfwGetOSMesaDepthBuffer.argtypes = [ctypes.POINTER(_GLFWwindow), ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_void_p)]
3172 def get_os_mesa_depth_buffer(window):
3173 """
3174 Retrieves the depth buffer associated with the specified window.
3175
3176 Wrapper for:
3177 int glfwGetOSMesaDepthBuffer(GLFWwindow* window, int* width, int* height, int* bytesPerValue, void** buffer);
3178 """
3179 width_value = ctypes.c_int(0)
3180 width = ctypes.pointer(width_value)
3181 height_value = ctypes.c_int(0)
3182 height = ctypes.pointer(height_value)
3183 bytes_per_value_value = ctypes.c_int(0)
3184 bytes_per_value = ctypes.pointer(bytes_per_value_value)
3185 buffer_value = ctypes.c_void_p(0)
3186 buffer = ctypes.pointer(buffer_value)
3187 success = _glfw.glfwGetOSMesaDepthBuffer(window, width, height, bytes_per_value, buffer)
3188 if not success:
3189 return None
3190 return width.value, height.value, bytes_per_value.value, buffer.value
3191
3192
3193 if hasattr(_glfw, 'glfwGetOSMesaContext'):
3194 _glfw.glfwGetOSMesaContext.restype = ctypes.c_void_p
3195 _glfw.glfwGetOSMesaContext.argtypes = [ctypes.POINTER(_GLFWwindow)]
3196 def get_os_mesa_context(window):
3197 """
3198 Returns the OSMesaContext of the specified window.
3199
3200 Wrapper for:
3201 OSMesaContext glfwGetOSMesaContext(GLFWwindow* window);
3202 """
3203 return _glfw.glfwGetOSMesaContext(window)
3204
3205 if hasattr(_glfw, 'glfwInitAllocator'):
3206 _allocate_callback = None
3207 _reallocate_callback = None
3208 _deallocate_callback = None
3209 _glfw.glfwInitAllocator.restype = None
3210 _glfw.glfwInitAllocator.argtypes = [ctypes.POINTER(_GLFWallocator)]
3211 def init_allocator(allocate, reallocate, deallocate):
3212 """
3213 Sets the init allocator to the desired value.
3214
3215 Wrapper for:
3216 void glfwInitAllocator(const GLFWallocator* allocator);
3217 """
3218 global _allocate_callback
3219 global _reallocate_callback
3220 global _deallocate_callback
3221 if allocate is None and reallocate is None and deallocate is None:
3222 allocator_ptr = ctypes.POINTER(_GLFWallocator)(0)
3223 else:
3224 if allocate is None:
3225 allocate = 0
3226 c_allocate = _GLFWallocatefun(allocate)
3227 _allocate_callback = (allocate, c_allocate)
3228 if reallocate is None:
3229 reallocate = 0
3230 c_reallocate = _GLFWreallocatefun(reallocate)
3231 _reallocate_callback = (reallocate, c_reallocate)
3232 if deallocate is None:
3233 deallocate = 0
3234 c_deallocate = _GLFWdeallocatefun(deallocate)
3235 _deallocate_callback = (deallocate, c_deallocate)
3236 allocator = _GLFWallocator()
3237 allocator.allocate = c_allocate
3238 allocator.reallocate = c_reallocate
3239 allocator.deallocate = c_deallocate
3240 allocator_ptr = ctypes.byref(allocator)
3241 _glfw.glfwInitAllocator(allocator_ptr)
3242
3243 if hasattr(_glfw, 'glfwInitVulkanLoader'):
3244 _loader_callback = None
3245 _loader_callback_type = ctypes.CFUNCTYPE(ctypes.c_void_p, ctypes.c_void_p, ctypes.c_char_p)
3246 _glfw.glfwInitVulkanLoader.restype = None
3247 _glfw.glfwInitVulkanLoader.argtypes = [_loader_callback_type]
3248 def init_vulkan_loader(loader):
3249 """
3250 Sets the desired Vulkan `vkGetInstanceProcAddr` function.
3251
3252 Wrapper for:
3253 void glfwInitVulkanLoader(PFN_vkGetInstanceProcAddr loader);
3254 """
3255 global _loader_callback
3256 if loader is None:
3257 loader = 0
3258 c_loader = _loader_callback_type(loader)
3259 _loader_callback = (loader, c_loader)
3260 _glfw.glfwInitVulkanLoader(c_loader)
3261
3262 if hasattr(_glfw, 'glfwGetPlatform'):
3263 _glfw.glfwGetPlatform.restype = ctypes.c_int
3264 _glfw.glfwGetPlatform.argtypes = []
3265 def get_platform():
3266 """
3267 Returns the currently selected platform.
3268
3269 Wrapper for:
3270 int glfwGetPlatform(void);
3271 """
3272 return _glfw.glfwGetPlatform()
3273
3274 if hasattr(_glfw, 'glfwPlatformSupported'):
3275 _glfw.glfwPlatformSupported.restype = ctypes.c_int
3276 _glfw.glfwPlatformSupported.argtypes = [ctypes.c_int]
3277 def platform_supported(platform):
3278 """
3279 Returns whether the library includes support for the specified platform.
3280
3281 Wrapper for:
3282 int glfwPlatformSupported(int platform);
3283 """
3284 return _glfw.glfwPlatformSupported(platform)
3285
3286 if hasattr(_glfw, 'glfwGetWindowTitle'):
3287 _glfw.glfwGetWindowTitle.restype = ctypes.c_char_p
3288 _glfw.glfwGetWindowTitle.argtypes = [ctypes.POINTER(_GLFWwindow)]
3289 def get_window_title(window):
3290 """
3291 Returns the title of the specified window.
3292
3293 Wrapper for:
3294 const char* glfwGetWindowTitle(GLFWwindow* window);
3295 """
3296 window_title = _glfw.glfwGetWindowTitle(window)
3297 if window_title:
3298 return window_title.decode('utf-8')
3299 return None
3300
3301
3302 _prepare_errcheck()