comparison pytouhou/lib/sdl.pyx @ 456:cae1ae9de430

Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 16 Jul 2013 21:11:40 +0200
parents 6864a38b2413
children ec327e58b477
comparison
equal deleted inserted replaced
455:6864a38b2413 456:cae1ae9de430
114 114
115 cdef void set_volume(self, float volume) nogil: 115 cdef void set_volume(self, float volume) nogil:
116 Mix_VolumeChunk(self.chunk, int(volume * 128)) 116 Mix_VolumeChunk(self.chunk, int(volume * 128))
117 117
118 118
119 cdef class Font:
120 def __init__(self, const char *filename, int ptsize):
121 self.font = TTF_OpenFont(filename, ptsize)
122 if self.font == NULL:
123 raise SDLError(SDL_GetError())
124
125 def __dealloc__(self):
126 if self.font != NULL:
127 TTF_CloseFont(self.font)
128
129 cdef Surface render(self, unicode text):
130 cdef SDL_Color white
131 white = SDL_Color(255, 255, 255, 255)
132 surface = Surface()
133 string = text.encode('utf-8')
134 surface.surface = TTF_RenderUTF8_Blended(self.font, string, white)
135 if surface.surface == NULL:
136 raise SDLError(SDL_GetError())
137 return surface
138
139
119 cdef void init(Uint32 flags) except *: 140 cdef void init(Uint32 flags) except *:
120 if SDL_Init(flags) < 0: 141 if SDL_Init(flags) < 0:
121 raise SDLError(SDL_GetError()) 142 raise SDLError(SDL_GetError())
122 143
123 144
126 raise SDLError(SDL_GetError()) 147 raise SDLError(SDL_GetError())
127 148
128 149
129 cdef void mix_init(int flags) except *: 150 cdef void mix_init(int flags) except *:
130 if Mix_Init(flags) != flags: 151 if Mix_Init(flags) != flags:
152 raise SDLError(SDL_GetError())
153
154
155 cdef void ttf_init() except *:
156 if TTF_Init() < 0:
131 raise SDLError(SDL_GetError()) 157 raise SDLError(SDL_GetError())
132 158
133 159
134 IF UNAME_SYSNAME == "Windows": 160 IF UNAME_SYSNAME == "Windows":
135 cdef void set_main_ready(): 161 cdef void set_main_ready():
144 IMG_Quit() 170 IMG_Quit()
145 171
146 172
147 cdef void mix_quit() nogil: 173 cdef void mix_quit() nogil:
148 Mix_Quit() 174 Mix_Quit()
175
176
177 cdef void ttf_quit() nogil:
178 TTF_Quit()
149 179
150 180
151 cdef void gl_set_attribute(SDL_GLattr attr, int value) except *: 181 cdef void gl_set_attribute(SDL_GLattr attr, int value) except *:
152 if SDL_GL_SetAttribute(attr, value) < 0: 182 if SDL_GL_SetAttribute(attr, value) < 0:
153 raise SDLError(SDL_GetError()) 183 raise SDLError(SDL_GetError())