1 /* Python 2.x/3.x and SDL compatibility tools
4 #if !defined(PGCOMPAT_H)
9 /* Cobjects vanish in Python 3.2; so we will code as though we use capsules */
10 #if defined(Py_CAPSULE_H)
11 #define PG_HAVE_CAPSULE 1
13 #define PG_HAVE_CAPSULE 0
15 #if defined(Py_COBJECT_H)
16 #define PG_HAVE_COBJECT 1
18 #define PG_HAVE_COBJECT 0
21 #define PyCapsule_New(ptr, n, dfn) PyCObject_FromVoidPtr(ptr, dfn)
22 #define PyCapsule_GetPointer(obj, n) PyCObject_AsVoidPtr(obj)
23 #define PyCapsule_CheckExact(obj) PyCObject_Check(obj)
26 /* Pygame uses Py_buffer (PEP 3118) to exchange array information internally;
27 * define here as needed.
29 #if !defined(PyBUF_SIMPLE)
30 typedef struct bufferinfo {
40 Py_ssize_t *suboffsets;
44 /* Flags for getting buffers */
45 #define PyBUF_SIMPLE 0
46 #define PyBUF_WRITABLE 0x0001
47 /* we used to include an E, backwards compatible alias */
48 #define PyBUF_WRITEABLE PyBUF_WRITABLE
49 #define PyBUF_FORMAT 0x0004
50 #define PyBUF_ND 0x0008
51 #define PyBUF_STRIDES (0x0010 | PyBUF_ND)
52 #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
53 #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
54 #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
55 #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)
57 #define PyBUF_CONTIG (PyBUF_ND | PyBUF_WRITABLE)
58 #define PyBUF_CONTIG_RO (PyBUF_ND)
60 #define PyBUF_STRIDED (PyBUF_STRIDES | PyBUF_WRITABLE)
61 #define PyBUF_STRIDED_RO (PyBUF_STRIDES)
63 #define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_WRITABLE | PyBUF_FORMAT)
64 #define PyBUF_RECORDS_RO (PyBUF_STRIDES | PyBUF_FORMAT)
66 #define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_WRITABLE | PyBUF_FORMAT)
67 #define PyBUF_FULL_RO (PyBUF_INDIRECT | PyBUF_FORMAT)
69 #define PyBUF_READ 0x100
70 #define PyBUF_WRITE 0x200
71 #define PyBUF_SHADOW 0x400
73 typedef int(*getbufferproc)(PyObject *, Py_buffer *, int);
74 typedef void(*releasebufferproc)(Py_buffer *);
75 #endif /* ~defined(PyBUF_SIMPLE) */
77 /* define common types where SDL is not included */
78 #ifndef SDL_VERSION_ATLEAST
80 typedef unsigned __int8 uint8_t;
81 typedef unsigned __int32 uint32_t;
85 typedef uint32_t Uint32;
86 typedef uint8_t Uint8;
90 #if defined(SDL_VERSION_ATLEAST)
92 #ifndef SDL_WINDOW_VULKAN
93 #define SDL_WINDOW_VULKAN 0
96 #ifndef SDL_WINDOW_ALWAYS_ON_TOP
97 #define SDL_WINDOW_ALWAYS_ON_TOP 0
100 #ifndef SDL_WINDOW_SKIP_TASKBAR
101 #define SDL_WINDOW_SKIP_TASKBAR 0
104 #ifndef SDL_WINDOW_UTILITY
105 #define SDL_WINDOW_UTILITY 0
108 #ifndef SDL_WINDOW_TOOLTIP
109 #define SDL_WINDOW_TOOLTIP 0
112 #ifndef SDL_WINDOW_POPUP_MENU
113 #define SDL_WINDOW_POPUP_MENU 0
117 #ifndef SDL_WINDOW_INPUT_GRABBED
118 #define SDL_WINDOW_INPUT_GRABBED 0
121 #ifndef SDL_WINDOW_INPUT_FOCUS
122 #define SDL_WINDOW_INPUT_FOCUS 0
125 #ifndef SDL_WINDOW_MOUSE_FOCUS
126 #define SDL_WINDOW_MOUSE_FOCUS 0
129 #ifndef SDL_WINDOW_FOREIGN
130 #define SDL_WINDOW_FOREIGN 0
133 #ifndef SDL_WINDOW_ALLOW_HIGHDPI
134 #define SDL_WINDOW_ALLOW_HIGHDPI 0
137 #ifndef SDL_WINDOW_MOUSE_CAPTURE
138 #define SDL_WINDOW_MOUSE_CAPTURE 0
141 #ifndef SDL_WINDOW_ALWAYS_ON_TOP
142 #define SDL_WINDOW_ALWAYS_ON_TOP 0
145 #ifndef SDL_WINDOW_SKIP_TASKBAR
146 #define SDL_WINDOW_SKIP_TASKBAR 0
149 #ifndef SDL_WINDOW_UTILITY
150 #define SDL_WINDOW_UTILITY 0
153 #ifndef SDL_WINDOW_TOOLTIP
154 #define SDL_WINDOW_TOOLTIP 0
157 #ifndef SDL_WINDOW_POPUP_MENU
158 #define SDL_WINDOW_POPUP_MENU 0
161 #if SDL_VERSION_ATLEAST(2, 0, 4)
162 /* To control the use of:
163 * SDL_AUDIODEVICEADDED
164 * SDL_AUDIODEVICEREMOVED
166 * Ref: https://wiki.libsdl.org/SDL_EventType
167 * Ref: https://wiki.libsdl.org/SDL_AudioDeviceEvent
169 #define SDL2_AUDIODEVICE_SUPPORTED
172 #ifndef SDL_MOUSEWHEEL_FLIPPED
173 #define NO_SDL_MOUSEWHEEL_FLIPPED
177 #endif /* defined(SDL_VERSION_ATLEAST) */
180 #endif /* ~defined(PGCOMPAT_H) */