comparison pytouhou/ui/texture.pyx @ 473:1c891c71cf22

Cythonize pytouhou.game.text.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Mon, 16 Sep 2013 18:42:12 +0200
parents cae1ae9de430
children 69c73023f7a0
comparison
equal deleted inserted replaced
472:8038f1957b71 473:1c891c71cf22
19 glGenTextures, glBindTexture, glTexImage2D, GL_TEXTURE_2D, GLuint, 19 glGenTextures, glBindTexture, glTexImage2D, GL_TEXTURE_2D, GLuint,
20 glDeleteTextures) 20 glDeleteTextures)
21 21
22 from pytouhou.lib.sdl cimport load_png, create_rgb_surface, Font 22 from pytouhou.lib.sdl cimport load_png, create_rgb_surface, Font
23 from pytouhou.formats.thtx import Texture #TODO: perhaps define that elsewhere? 23 from pytouhou.formats.thtx import Texture #TODO: perhaps define that elsewhere?
24 from pytouhou.game.text cimport NativeText
24 25
25 import os 26 import os
26 27
27 28
28 class TextureId(int): 29 class TextureId(int):
58 self.font = Font(fontname, fontsize) 59 self.font = Font(fontname, fontsize)
59 self.renderer = renderer 60 self.renderer = renderer
60 61
61 62
62 def load(self, label_list): 63 def load(self, label_list):
64 cdef NativeText label
65
63 for label in label_list: 66 for label in label_list:
64 if not hasattr(label, 'texture'): 67 if label.texture is None:
65 surface = self.font.render(label.text) 68 surface = self.font.render(label.text)
66 label.width, label.height = surface.surface.w, surface.surface.h 69 label.width, label.height = surface.surface.w, surface.surface.h
67 70
68 if label.align == 'center': 71 if label.align == 'center':
69 label.x -= label.width // 2 72 label.x -= label.width // 2