.gitignore added
[dotfiles/.git] / .local / include / python3.9 / pygame / _pygame.h
1 /*
2     pygame - Python Game Library
3     Copyright (C) 2000-2001  Pete Shinners
4
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Library General Public
7     License as published by the Free Software Foundation; either
8     version 2 of the License, or (at your option) any later version.
9
10     This library is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13     Library General Public License for more details.
14
15     You should have received a copy of the GNU Library General Public
16     License along with this library; if not, write to the Free
17     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
19     Pete Shinners
20     pete@shinners.org
21 */
22
23 /* This will use PYGAMEAPI_EXTERN_SLOTS instead
24  * of PYGAMEAPI_DEFINE_SLOTS for base modules.
25  */
26 #ifndef _PYGAME_INTERNAL_H
27 #define _PYGAME_INTERNAL_H
28
29 #include "pgplatform.h"
30 /*
31     If PY_SSIZE_T_CLEAN is defined before including Python.h, length is a
32     Py_ssize_t rather than an int for all # variants of formats (s#, y#, etc.)
33 */
34 #define PY_SSIZE_T_CLEAN
35 #include <Python.h>
36 #include <SDL.h>
37
38 /* IS_SDLv1 is 1 if SDL 1.x.x, 0 otherwise */
39 /* IS_SDLv2 is 1 if at least SDL 2.0.0, 0 otherwise */
40 #if (SDL_VERSION_ATLEAST(2, 0, 0))
41 #define IS_SDLv2 1
42 #define IS_SDLv1 0
43 #else
44 #define IS_SDLv2 0
45 #define IS_SDLv1 1
46 #endif
47
48 /*#if IS_SDLv1 && PG_MAJOR_VERSION >= 2
49 #error pygame 2 requires SDL 2
50 #endif*/
51
52 #if IS_SDLv2
53 /* SDL 1.2 constants removed from SDL 2 */
54 typedef enum {
55     SDL_HWSURFACE = 0,
56     SDL_RESIZABLE = SDL_WINDOW_RESIZABLE,
57     SDL_ASYNCBLIT = 0,
58     SDL_OPENGL = SDL_WINDOW_OPENGL,
59     SDL_OPENGLBLIT = 0,
60     SDL_ANYFORMAT = 0,
61     SDL_HWPALETTE = 0,
62     SDL_DOUBLEBUF = 0,
63     SDL_FULLSCREEN = SDL_WINDOW_FULLSCREEN,
64     SDL_HWACCEL = 0,
65     SDL_SRCCOLORKEY = 0,
66     SDL_RLEACCELOK = 0,
67     SDL_SRCALPHA = 0,
68     SDL_NOFRAME = SDL_WINDOW_BORDERLESS,
69     SDL_GL_SWAP_CONTROL = 0,
70     TIMER_RESOLUTION = 0
71 } PygameVideoFlags;
72
73 /* the wheel button constants were removed from SDL 2 */
74 typedef enum {
75     PGM_BUTTON_LEFT = SDL_BUTTON_LEFT,
76     PGM_BUTTON_RIGHT = SDL_BUTTON_RIGHT,
77     PGM_BUTTON_MIDDLE = SDL_BUTTON_MIDDLE,
78     PGM_BUTTON_WHEELUP = 4,
79     PGM_BUTTON_WHEELDOWN = 5,
80     PGM_BUTTON_X1 = SDL_BUTTON_X1 + 2,
81     PGM_BUTTON_X2 = SDL_BUTTON_X2 + 2,
82     PGM_BUTTON_KEEP = 0x80
83 } PygameMouseFlags;
84
85 typedef enum {
86     /* Any SDL_* events here are for backward compatibility. */
87     SDL_NOEVENT = 0,
88
89     SDL_ACTIVEEVENT = SDL_USEREVENT,
90     SDL_VIDEORESIZE,
91     SDL_VIDEOEXPOSE,
92
93     PGE_MIDIIN,
94     PGE_MIDIOUT,
95     PGE_KEYREPEAT, /* Special internal pygame event, for managing key-presses */
96
97     /* DO NOT CHANGE THE ORDER OF EVENTS HERE */
98     PGE_WINDOWSHOWN,
99     PGE_WINDOWHIDDEN,
100     PGE_WINDOWEXPOSED,
101     PGE_WINDOWMOVED,
102     PGE_WINDOWRESIZED,
103     PGE_WINDOWSIZECHANGED,
104     PGE_WINDOWMINIMIZED,
105     PGE_WINDOWMAXIMIZED,
106     PGE_WINDOWRESTORED,
107     PGE_WINDOWENTER,
108     PGE_WINDOWLEAVE,
109     PGE_WINDOWFOCUSGAINED,
110     PGE_WINDOWFOCUSLOST,
111     PGE_WINDOWCLOSE,
112     PGE_WINDOWTAKEFOCUS,
113     PGE_WINDOWHITTEST,
114
115     /* Here we define PGPOST_* events, events that act as a one-to-one
116      * proxy for SDL events (and some extra events too!), the proxy is used
117      * internally when pygame users use event.post()
118      *
119      * Thankfully, SDL2 provides over 8000 userevents, so theres no need
120      * to worry about wasting userevent space.
121      *
122      * IMPORTANT NOTE: Do not post events directly with these proxy types,
123      * use the appropriate functions in event.c, that handle these proxy
124      * events for you.
125      * Proxy events are for internal use only */
126     PGPOST_EVENTBEGIN, /* mark start of proxy-events */
127     PGPOST_ACTIVEEVENT = PGPOST_EVENTBEGIN,
128     PGPOST_AUDIODEVICEADDED,
129     PGPOST_AUDIODEVICEREMOVED,
130     PGPOST_CONTROLLERAXISMOTION,
131     PGPOST_CONTROLLERBUTTONDOWN,
132     PGPOST_CONTROLLERBUTTONUP,
133     PGPOST_CONTROLLERDEVICEADDED,
134     PGPOST_CONTROLLERDEVICEREMOVED,
135     PGPOST_CONTROLLERDEVICEREMAPPED,
136     PGPOST_DOLLARGESTURE,
137     PGPOST_DOLLARRECORD,
138     PGPOST_DROPFILE,
139     PGPOST_DROPTEXT,
140     PGPOST_DROPBEGIN,
141     PGPOST_DROPCOMPLETE,
142     PGPOST_FINGERMOTION,
143     PGPOST_FINGERDOWN,
144     PGPOST_FINGERUP,
145     PGPOST_KEYDOWN,
146     PGPOST_KEYUP,
147     PGPOST_JOYAXISMOTION,
148     PGPOST_JOYBALLMOTION,
149     PGPOST_JOYHATMOTION,
150     PGPOST_JOYBUTTONDOWN,
151     PGPOST_JOYBUTTONUP,
152     PGPOST_JOYDEVICEADDED,
153     PGPOST_JOYDEVICEREMOVED,
154     PGPOST_MIDIIN,
155     PGPOST_MIDIOUT,
156     PGPOST_MOUSEMOTION,
157     PGPOST_MOUSEBUTTONDOWN,
158     PGPOST_MOUSEBUTTONUP,
159     PGPOST_MOUSEWHEEL,
160     PGPOST_MULTIGESTURE,
161     PGPOST_NOEVENT,
162     PGPOST_QUIT,
163     PGPOST_SYSWMEVENT,
164     PGPOST_TEXTEDITING,
165     PGPOST_TEXTINPUT,
166     PGPOST_VIDEORESIZE,
167     PGPOST_VIDEOEXPOSE,
168     PGPOST_WINDOWSHOWN,
169     PGPOST_WINDOWHIDDEN,
170     PGPOST_WINDOWEXPOSED,
171     PGPOST_WINDOWMOVED,
172     PGPOST_WINDOWRESIZED,
173     PGPOST_WINDOWSIZECHANGED,
174     PGPOST_WINDOWMINIMIZED,
175     PGPOST_WINDOWMAXIMIZED,
176     PGPOST_WINDOWRESTORED,
177     PGPOST_WINDOWENTER,
178     PGPOST_WINDOWLEAVE,
179     PGPOST_WINDOWFOCUSGAINED,
180     PGPOST_WINDOWFOCUSLOST,
181     PGPOST_WINDOWCLOSE,
182     PGPOST_WINDOWTAKEFOCUS,
183     PGPOST_WINDOWHITTEST,
184
185     PGE_USEREVENT, /* this event must stay in this position only */
186
187     PG_NUMEVENTS = SDL_LASTEVENT /* Not an event. Indicates end of user events. */
188 } PygameEventCode;
189
190 typedef enum {
191     SDL_APPFOCUSMOUSE,
192     SDL_APPINPUTFOCUS,
193     SDL_APPACTIVE
194 } PygameAppCode;
195
196 /* Surface flags: based on SDL 1.2 flags */
197 typedef enum {
198     PGS_SWSURFACE = 0x00000000,
199     PGS_HWSURFACE = 0x00000001,
200     PGS_ASYNCBLIT = 0x00000004,
201
202     PGS_ANYFORMAT = 0x10000000,
203     PGS_HWPALETTE = 0x20000000,
204     PGS_DOUBLEBUF = 0x40000000,
205     PGS_FULLSCREEN = 0x80000000,
206     PGS_SCALED = 0x00000200,
207
208     PGS_OPENGL = 0x00000002,
209     PGS_OPENGLBLIT = 0x0000000A,
210     PGS_RESIZABLE = 0x00000010,
211     PGS_NOFRAME = 0x00000020,
212     PGS_SHOWN = 0x00000040,  /* Added from SDL 2 */
213     PGS_HIDDEN = 0x00000080, /* Added from SDL 2 */
214
215     PGS_HWACCEL = 0x00000100,
216     PGS_SRCCOLORKEY = 0x00001000,
217     PGS_RLEACCELOK = 0x00002000,
218     PGS_RLEACCEL = 0x00004000,
219     PGS_SRCALPHA = 0x00010000,
220     PGS_PREALLOC = 0x01000000
221 } PygameSurfaceFlags;
222
223 #else /* IS_SDLv2 */
224
225 /* To maintain SDL 1.2 build support. */
226 #define PGE_USEREVENT SDL_USEREVENT
227 #define PG_NUMEVENTS SDL_NUMEVENTS
228 #define PGPOST_EVENTBEGIN 0
229 /* These midi events were originally defined in midi.py.
230  * Note: They are outside the SDL_USEREVENT/SDL_NUMEVENTS event range for
231  * SDL 1.2. */
232 #define PGE_MIDIIN PGE_USEREVENT + 10
233 #define PGE_MIDIOUT PGE_USEREVENT + 11
234 #endif /* IS_SDLv1 */
235
236 //TODO Implement check below in a way that does not break CI
237 /* New buffer protocol (PEP 3118) implemented on all supported Py versions.
238 #if !defined(Py_TPFLAGS_HAVE_NEWBUFFER)
239 #error No support for PEP 3118/Py_TPFLAGS_HAVE_NEWBUFFER. Please use a supported Python version.
240 #endif */
241
242 #define RAISE(x, y) (PyErr_SetString((x), (y)), (PyObject *)NULL)
243 #define DEL_ATTR_NOT_SUPPORTED_CHECK(name, value)           \
244     do {                                                    \
245        if (!value) {                                        \
246            if (name) {                                      \
247                PyErr_Format(PyExc_AttributeError,           \
248                             "Cannot delete attribute %s",   \
249                             name);                          \
250            } else {                                         \
251                PyErr_SetString(PyExc_AttributeError,        \
252                                "Cannot delete attribute");  \
253            }                                                \
254            return -1;                                       \
255        }                                                    \
256     } while (0)
257
258 /*
259  * Initialization checks
260  */
261
262 #define VIDEO_INIT_CHECK()            \
263     if (!SDL_WasInit(SDL_INIT_VIDEO)) \
264     return RAISE(pgExc_SDLError, "video system not initialized")
265
266 #define CDROM_INIT_CHECK()            \
267     if (!SDL_WasInit(SDL_INIT_CDROM)) \
268     return RAISE(pgExc_SDLError, "cdrom system not initialized")
269
270 #define JOYSTICK_INIT_CHECK()            \
271     if (!SDL_WasInit(SDL_INIT_JOYSTICK)) \
272     return RAISE(pgExc_SDLError, "joystick system not initialized")
273
274 /* thread check */
275 #ifdef WITH_THREAD
276 #define PG_CHECK_THREADS() (1)
277 #else /* ~WITH_THREAD */
278 #define PG_CHECK_THREADS()                        \
279     (RAISE(PyExc_NotImplementedError,             \
280           "Python built without thread support"))
281 #endif /* ~WITH_THREAD */
282
283 #define PyType_Init(x) (((x).ob_type) = &PyType_Type)
284
285 /*
286  * event module internals
287  */
288 struct pgEventObject {
289     PyObject_HEAD int type;
290     PyObject *dict;
291 };
292
293 /*
294  * surflock module internals
295  */
296 typedef struct {
297     PyObject_HEAD PyObject *surface;
298     PyObject *lockobj;
299     PyObject *weakrefs;
300 } pgLifetimeLockObject;
301
302 /*
303  * surface module internals
304  */
305 struct pgSubSurface_Data {
306     PyObject *owner;
307     int pixeloffset;
308     int offsetx, offsety;
309 };
310
311 /*
312  * color module internals
313  */
314 struct pgColorObject {
315     PyObject_HEAD
316     Uint8 data[4];
317     Uint8 len;
318 };
319
320 /*
321  * include public API
322  */
323 #include "include/_pygame.h"
324
325 #include "pgimport.h"
326
327 /* Slot counts.
328  * Remember to keep these constants up to date.
329  */
330
331 #define PYGAMEAPI_RECT_NUMSLOTS 5
332 #define PYGAMEAPI_JOYSTICK_NUMSLOTS 2
333 #define PYGAMEAPI_DISPLAY_NUMSLOTS 2
334 #define PYGAMEAPI_SURFACE_NUMSLOTS 4
335 #define PYGAMEAPI_SURFLOCK_NUMSLOTS 8
336 #define PYGAMEAPI_RWOBJECT_NUMSLOTS 6
337 #define PYGAMEAPI_PIXELARRAY_NUMSLOTS 2
338 #define PYGAMEAPI_COLOR_NUMSLOTS 5
339 #define PYGAMEAPI_MATH_NUMSLOTS 2
340 #define PYGAMEAPI_CDROM_NUMSLOTS 2
341
342 #if PG_API_VERSION == 1
343 #define PYGAMEAPI_BASE_NUMSLOTS 19
344 #define PYGAMEAPI_EVENT_NUMSLOTS 4
345 #else /* PG_API_VERSION == 2 */
346 #define PYGAMEAPI_BASE_NUMSLOTS 24
347 #define PYGAMEAPI_EVENT_NUMSLOTS 6
348 #endif /* PG_API_VERSION == 2 */
349
350 #endif /* _PYGAME_INTERNAL_H */