2 pygame - Python Game Library
3 Copyright (C) 2000-2001 Pete Shinners
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.
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.
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
23 /* This will use PYGAMEAPI_EXTERN_SLOTS instead
24 * of PYGAMEAPI_DEFINE_SLOTS for base modules.
26 #ifndef _PYGAME_INTERNAL_H
27 #define _PYGAME_INTERNAL_H
29 #include "pgplatform.h"
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.)
34 #define PY_SSIZE_T_CLEAN
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))
48 /*#if IS_SDLv1 && PG_MAJOR_VERSION >= 2
49 #error pygame 2 requires SDL 2
53 /* SDL 1.2 constants removed from SDL 2 */
56 SDL_RESIZABLE = SDL_WINDOW_RESIZABLE,
58 SDL_OPENGL = SDL_WINDOW_OPENGL,
63 SDL_FULLSCREEN = SDL_WINDOW_FULLSCREEN,
68 SDL_NOFRAME = SDL_WINDOW_BORDERLESS,
69 SDL_GL_SWAP_CONTROL = 0,
73 /* the wheel button constants were removed from SDL 2 */
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
86 /* Any SDL_* events here are for backward compatibility. */
89 SDL_ACTIVEEVENT = SDL_USEREVENT,
95 PGE_KEYREPEAT, /* Special internal pygame event, for managing key-presses */
97 /* DO NOT CHANGE THE ORDER OF EVENTS HERE */
103 PGE_WINDOWSIZECHANGED,
109 PGE_WINDOWFOCUSGAINED,
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()
119 * Thankfully, SDL2 provides over 8000 userevents, so theres no need
120 * to worry about wasting userevent space.
122 * IMPORTANT NOTE: Do not post events directly with these proxy types,
123 * use the appropriate functions in event.c, that handle these proxy
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,
147 PGPOST_JOYAXISMOTION,
148 PGPOST_JOYBALLMOTION,
150 PGPOST_JOYBUTTONDOWN,
152 PGPOST_JOYDEVICEADDED,
153 PGPOST_JOYDEVICEREMOVED,
157 PGPOST_MOUSEBUTTONDOWN,
158 PGPOST_MOUSEBUTTONUP,
170 PGPOST_WINDOWEXPOSED,
172 PGPOST_WINDOWRESIZED,
173 PGPOST_WINDOWSIZECHANGED,
174 PGPOST_WINDOWMINIMIZED,
175 PGPOST_WINDOWMAXIMIZED,
176 PGPOST_WINDOWRESTORED,
179 PGPOST_WINDOWFOCUSGAINED,
180 PGPOST_WINDOWFOCUSLOST,
182 PGPOST_WINDOWTAKEFOCUS,
183 PGPOST_WINDOWHITTEST,
185 PGE_USEREVENT, /* this event must stay in this position only */
187 PG_NUMEVENTS = SDL_LASTEVENT /* Not an event. Indicates end of user events. */
196 /* Surface flags: based on SDL 1.2 flags */
198 PGS_SWSURFACE = 0x00000000,
199 PGS_HWSURFACE = 0x00000001,
200 PGS_ASYNCBLIT = 0x00000004,
202 PGS_ANYFORMAT = 0x10000000,
203 PGS_HWPALETTE = 0x20000000,
204 PGS_DOUBLEBUF = 0x40000000,
205 PGS_FULLSCREEN = 0x80000000,
206 PGS_SCALED = 0x00000200,
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 */
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;
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
232 #define PGE_MIDIIN PGE_USEREVENT + 10
233 #define PGE_MIDIOUT PGE_USEREVENT + 11
234 #endif /* IS_SDLv1 */
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.
242 #define RAISE(x, y) (PyErr_SetString((x), (y)), (PyObject *)NULL)
243 #define DEL_ATTR_NOT_SUPPORTED_CHECK(name, value) \
247 PyErr_Format(PyExc_AttributeError, \
248 "Cannot delete attribute %s", \
251 PyErr_SetString(PyExc_AttributeError, \
252 "Cannot delete attribute"); \
259 * Initialization checks
262 #define VIDEO_INIT_CHECK() \
263 if (!SDL_WasInit(SDL_INIT_VIDEO)) \
264 return RAISE(pgExc_SDLError, "video system not initialized")
266 #define CDROM_INIT_CHECK() \
267 if (!SDL_WasInit(SDL_INIT_CDROM)) \
268 return RAISE(pgExc_SDLError, "cdrom system not initialized")
270 #define JOYSTICK_INIT_CHECK() \
271 if (!SDL_WasInit(SDL_INIT_JOYSTICK)) \
272 return RAISE(pgExc_SDLError, "joystick system not initialized")
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 */
283 #define PyType_Init(x) (((x).ob_type) = &PyType_Type)
286 * event module internals
288 struct pgEventObject {
289 PyObject_HEAD int type;
294 * surflock module internals
297 PyObject_HEAD PyObject *surface;
300 } pgLifetimeLockObject;
303 * surface module internals
305 struct pgSubSurface_Data {
308 int offsetx, offsety;
312 * color module internals
314 struct pgColorObject {
323 #include "include/_pygame.h"
325 #include "pgimport.h"
328 * Remember to keep these constants up to date.
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
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 */
350 #endif /* _PYGAME_INTERNAL_H */