comparison pytouhou/lib/sdl.pxd @ 455:6864a38b2413

Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Mon, 02 Sep 2013 22:16:38 +0200
parents 2a352118c55a
children cae1ae9de430
comparison
equal deleted inserted replaced
454:a502887557ac 455:6864a38b2413
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of 10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ## GNU General Public License for more details. 12 ## GNU General Public License for more details.
13 ## 13 ##
14 14
15 cdef extern from "SDL.h": 15 from _sdl cimport *
16 ctypedef unsigned int Uint32
17 ctypedef unsigned short Uint16
18 ctypedef unsigned char Uint8
19
20 int SDL_INIT_VIDEO
21
22 int SDL_Init(Uint32 flags)
23 void SDL_Quit()
24 16
25 17
26 IF UNAME_SYSNAME == "Windows": 18 cdef Uint32 INIT_VIDEO
27 cdef extern from "SDL_main.h": 19 cdef Uint32 INIT_PNG
28 void SDL_SetMainReady() 20
21 cdef SDL_GLattr GL_CONTEXT_MAJOR_VERSION
22 cdef SDL_GLattr GL_CONTEXT_MINOR_VERSION
23 cdef SDL_GLattr GL_DOUBLEBUFFER
24 cdef SDL_GLattr GL_DEPTH_SIZE
25
26 cdef SDL_WindowFlags WINDOWPOS_CENTERED
27 cdef SDL_WindowFlags WINDOW_OPENGL
28 cdef SDL_WindowFlags WINDOW_SHOWN
29
30 #TODO: should be SDL_Scancode, but Cython doesn’t allow enum for array indexing.
31 cdef long SCANCODE_Z
32 cdef long SCANCODE_X
33 cdef long SCANCODE_LSHIFT
34 cdef long SCANCODE_UP
35 cdef long SCANCODE_DOWN
36 cdef long SCANCODE_LEFT
37 cdef long SCANCODE_RIGHT
38 cdef long SCANCODE_LCTRL
39 cdef long SCANCODE_ESCAPE
40
41 cdef SDL_EventType KEYDOWN
42 cdef SDL_EventType QUIT
43
44 cdef Uint16 DEFAULT_FORMAT
29 45
30 46
31 cdef extern from "SDL_error.h": 47 cdef class Window:
32 const char *SDL_GetError() 48 cdef SDL_Window *window
49 cdef SDL_GLContext context
50
51 cdef void gl_create_context(self) except *
52 cdef void gl_swap_window(self) nogil
53 cdef void set_window_size(self, int width, int height) nogil
33 54
34 55
35 cdef extern from "SDL_video.h": 56 cdef class Surface:
36 ctypedef enum SDL_GLattr: 57 cdef SDL_Surface *surface
37 SDL_GL_CONTEXT_MAJOR_VERSION
38 SDL_GL_CONTEXT_MINOR_VERSION
39 SDL_GL_DOUBLEBUFFER
40 SDL_GL_DEPTH_SIZE
41 58
42 ctypedef enum SDL_WindowFlags: 59 cdef void blit(self, Surface other) except *
43 SDL_WINDOWPOS_CENTERED 60 cdef void set_alpha(self, Surface alpha_surface) nogil
44 SDL_WINDOW_OPENGL
45 SDL_WINDOW_SHOWN
46
47 ctypedef struct SDL_Window:
48 pass
49
50 ctypedef void *SDL_GLContext
51
52 int SDL_GL_SetAttribute(SDL_GLattr attr, int value)
53 SDL_Window *SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
54 SDL_GLContext SDL_GL_CreateContext(SDL_Window *window)
55 void SDL_GL_SwapWindow(SDL_Window *window)
56 void SDL_GL_DeleteContext(SDL_GLContext context)
57 void SDL_DestroyWindow(SDL_Window *window)
58
59 void SDL_SetWindowSize(SDL_Window *window, int w, int h)
60 61
61 62
62 cdef extern from "SDL_scancode.h": 63 cdef class Music:
63 ctypedef enum SDL_Scancode: 64 cdef Mix_Music *music
64 SDL_SCANCODE_Z 65
65 SDL_SCANCODE_X 66 cdef void play(self, int loops) nogil
66 SDL_SCANCODE_LSHIFT 67 cdef void set_loop_points(self, double start, double end) nogil
67 SDL_SCANCODE_UP
68 SDL_SCANCODE_DOWN
69 SDL_SCANCODE_LEFT
70 SDL_SCANCODE_RIGHT
71 SDL_SCANCODE_LCTRL
72 SDL_SCANCODE_ESCAPE
73 68
74 69
75 cdef extern from "SDL_events.h": 70 cdef class Chunk:
76 ctypedef enum SDL_EventType: 71 cdef Mix_Chunk *chunk
77 SDL_KEYDOWN
78 SDL_QUIT
79 72
80 ctypedef struct SDL_Keysym: 73 cdef void play(self, int channel, int loops) nogil
81 SDL_Scancode scancode 74 cdef void set_volume(self, float volume) nogil
82
83 ctypedef struct SDL_KeyboardEvent:
84 Uint32 type
85 SDL_Keysym keysym
86
87 ctypedef union SDL_Event:
88 Uint32 type
89 SDL_KeyboardEvent key
90
91 int SDL_PollEvent(SDL_Event *event)
92 75
93 76
94 cdef extern from "SDL_keyboard.h": 77 cdef void init(Uint32 flags) except *
95 const Uint8 *SDL_GetKeyboardState(int *numkeys) 78 cdef void img_init(Uint32 flags) except *
79 cdef void mix_init(int flags) except *
96 80
81 IF UNAME_SYSNAME == "Windows":
82 cdef void set_main_ready()
97 83
98 cdef extern from "SDL_timer.h": 84 cdef void quit() nogil
99 Uint32 SDL_GetTicks() 85 cdef void img_quit() nogil
100 void SDL_Delay(Uint32 ms) 86 cdef void mix_quit() nogil
101 87 cdef void gl_set_attribute(SDL_GLattr attr, int value) except *
102 88 cdef list poll_events()
103 cdef extern from "SDL_rect.h": 89 cdef const Uint8* get_keyboard_state() nogil
104 ctypedef struct SDL_Rect: 90 cdef Surface load_png(file_)
105 int x, y 91 cdef Surface create_rgb_surface(int width, int height, int depth, Uint32 rmask=*, Uint32 gmask=*, Uint32 bmask=*, Uint32 amask=*)
106 int w, h 92 cdef void mix_open_audio(int frequency, Uint16 format_, int channels, int chunksize) except *
107 93 cdef void mix_close_audio() nogil
108 94 cdef void mix_allocate_channels(int numchans) except *
109 cdef extern from "SDL_surface.h": 95 cdef int mix_volume(int channel, float volume) nogil
110 ctypedef struct SDL_Surface: 96 cdef int mix_volume_music(float volume) nogil
111 int w, h 97 cdef Music load_music(const char *filename)
112 unsigned char *pixels 98 cdef Chunk load_chunk(file_)
113 99 cdef Uint32 get_ticks() nogil
114 void SDL_FreeSurface(SDL_Surface *surface) 100 cdef void delay(Uint32 ms) nogil
115 int SDL_BlitSurface(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)
116 SDL_Surface *SDL_CreateRGBSurface(Uint32 flags, int width, int height, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
117
118
119 cdef extern from "SDL_rwops.h":
120 ctypedef struct SDL_RWops:
121 pass
122
123 SDL_RWops *SDL_RWFromConstMem(const void *mem, int size)
124 int SDL_RWclose(SDL_RWops *context)
125
126
127 cdef extern from "SDL_image.h":
128 int IMG_INIT_PNG
129
130 int IMG_Init(int flags)
131 void IMG_Quit()
132 SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src)
133
134
135 cdef extern from "SDL_mixer.h":
136 ctypedef enum:
137 MIX_DEFAULT_FORMAT
138
139 ctypedef struct Mix_Music:
140 pass
141
142 ctypedef struct Mix_Chunk:
143 pass
144
145 int Mix_Init(int flags)
146 void Mix_Quit()
147
148 int Mix_OpenAudio(int frequency, Uint16 format_, int channels, int chunksize)
149 void Mix_CloseAudio()
150
151 int Mix_AllocateChannels(int numchans)
152
153 Mix_Music *Mix_LoadMUS(const char *filename)
154 Mix_Chunk *Mix_LoadWAV_RW(SDL_RWops *src, int freesrc)
155
156 void Mix_FreeMusic(Mix_Music *music)
157 void Mix_FreeChunk(Mix_Chunk *chunk)
158
159 int Mix_PlayMusic(Mix_Music *music, int loops)
160 #int Mix_SetLoopPoints(Mix_Music *music, double start, double end)
161
162 int Mix_Volume(int channel, int volume)
163 int Mix_VolumeChunk(Mix_Chunk *chunk, int volume)
164 int Mix_VolumeMusic(int volume)
165
166 int Mix_PlayChannel(int channel, Mix_Chunk *chunk, int loops)