Mercurial > touhou
comparison pytouhou/lib/sdl.pyx @ 590:e15672733c93
Switch to Python 3.x instead of 2.7.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Tue, 30 Sep 2014 17:14:24 +0200 |
parents | 0768122da817 |
children | 2dfa4aa135d2 |
comparison
equal
deleted
inserted
replaced
589:0768122da817 | 590:e15672733c93 |
---|---|
88 IMG_Quit() | 88 IMG_Quit() |
89 SDL_Quit() | 89 SDL_Quit() |
90 | 90 |
91 | 91 |
92 cdef class Window: | 92 cdef class Window: |
93 def __init__(self, const char *title, int x, int y, int w, int h, Uint32 flags): | 93 def __init__(self, str title, int x, int y, int w, int h, Uint32 flags): |
94 self.window = SDL_CreateWindow(title, x, y, w, h, flags) | 94 self.window = SDL_CreateWindow(title.encode(), x, y, w, h, flags) |
95 if self.window == NULL: | 95 if self.window == NULL: |
96 raise SDLError(SDL_GetError()) | 96 raise SDLError(SDL_GetError()) |
97 | 97 |
98 def __dealloc__(self): | 98 def __dealloc__(self): |
99 if self.context != NULL: | 99 if self.context != NULL: |
203 cdef void set_alpha(self, Surface alpha_surface) nogil: | 203 cdef void set_alpha(self, Surface alpha_surface) nogil: |
204 nb_pixels = self.surface.w * self.surface.h | 204 nb_pixels = self.surface.w * self.surface.h |
205 image = self.surface.pixels | 205 image = self.surface.pixels |
206 alpha = alpha_surface.surface.pixels | 206 alpha = alpha_surface.surface.pixels |
207 | 207 |
208 for i in xrange(nb_pixels): | 208 for i in range(nb_pixels): |
209 # Only use the red value, assume the others are equal. | 209 # Only use the red value, assume the others are equal. |
210 image[3+4*i] = alpha[3*i] | 210 image[3+4*i] = alpha[3*i] |
211 | 211 |
212 | 212 |
213 cdef class Music: | 213 cdef class Music: |
234 cdef void set_volume(self, float volume) nogil: | 234 cdef void set_volume(self, float volume) nogil: |
235 Mix_VolumeChunk(self.chunk, int(volume * 128)) | 235 Mix_VolumeChunk(self.chunk, int(volume * 128)) |
236 | 236 |
237 | 237 |
238 cdef class Font: | 238 cdef class Font: |
239 def __init__(self, const char *filename, int ptsize): | 239 def __init__(self, str filename, int ptsize): |
240 self.font = TTF_OpenFont(filename, ptsize) | 240 self.font = TTF_OpenFont(filename.encode(), ptsize) |
241 if self.font == NULL: | 241 if self.font == NULL: |
242 raise SDLError(SDL_GetError()) | 242 raise SDLError(SDL_GetError()) |
243 | 243 |
244 def __dealloc__(self): | 244 def __dealloc__(self): |
245 if self.font != NULL: | 245 if self.font != NULL: |
333 | 333 |
334 cdef int mix_volume_music(float volume) nogil: | 334 cdef int mix_volume_music(float volume) nogil: |
335 return Mix_VolumeMusic(int(volume * 128)) | 335 return Mix_VolumeMusic(int(volume * 128)) |
336 | 336 |
337 | 337 |
338 cdef Music load_music(const char *filename): | 338 cdef Music load_music(str filename): |
339 music = Music() | 339 music = Music() |
340 music.music = Mix_LoadMUS(filename) | 340 music.music = Mix_LoadMUS(filename.encode()) |
341 if music.music == NULL: | 341 if music.music == NULL: |
342 raise SDLError(SDL_GetError()) | 342 raise SDLError(SDL_GetError()) |
343 return music | 343 return music |
344 | 344 |
345 | 345 |