Mercurial > touhou
comparison pytouhou/ui/sdl/gamerenderer.py @ 532:dacdcca59b66
Don’t put back the rendering data into a tuple, use a specialised struct inside Sprite to pass it to the renderer.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Thu, 19 Dec 2013 21:55:26 +0100 |
parents | 577c3a88fb67 |
children | de778a80820a |
comparison
equal
deleted
inserted
replaced
531:a7dc55ad9380 | 532:dacdcca59b66 |
---|---|
13 ## | 13 ## |
14 | 14 |
15 from itertools import chain | 15 from itertools import chain |
16 | 16 |
17 from pytouhou.lib.sdl import Rect | 17 from pytouhou.lib.sdl import Rect |
18 from .sprite import get_sprite_rendering_data | |
19 | 18 |
20 from pytouhou.utils.helpers import get_logger | 19 from pytouhou.utils.helpers import get_logger |
21 logger = get_logger(__name__) | 20 logger = get_logger(__name__) |
22 | 21 |
23 | 22 |
103 break | 102 break |
104 | 103 |
105 sprite = element.sprite | 104 sprite = element.sprite |
106 if sprite and sprite.visible: | 105 if sprite and sprite.visible: |
107 ox, oy = element.x, element.y | 106 ox, oy = element.x, element.y |
108 blendfunc, (vertices, uvs, colors, rotation, flip) = get_sprite_rendering_data(sprite) | 107 data = get_sprite_rendering_data(sprite) |
109 | |
110 # Pack data in buffer | |
111 x, y, width, height = vertices | |
112 left, right, bottom, top = uvs | |
113 r, g, b, a = colors #TODO: use it. | |
114 | 108 |
115 #XXX | 109 #XXX |
116 texture_width = 256 | 110 texture_width = 256 |
117 texture_height = 256 | 111 texture_height = 256 |
118 | 112 |
119 source = Rect(left * texture_width, bottom * texture_height, (right - left) * texture_width, (top - bottom) * texture_height) | 113 source = Rect(data.left * texture_width, |
120 dest = Rect(ox + x, oy + y, width, height) | 114 data.bottom * texture_height, |
115 (data.right - data.left) * texture_width, | |
116 (data.top - data.bottom) * texture_height) | |
117 | |
118 dest = Rect(ox + data.x, oy + data.y, data.width, data.height) | |
121 | 119 |
122 texture = sprite.anm.texture | 120 texture = sprite.anm.texture |
123 texture.set_color_mod(r, g, b) | 121 texture.set_color_mod(data.r, data.g, data.b) |
124 texture.set_alpha_mod(a) | 122 texture.set_alpha_mod(data.a) |
125 texture.set_blend_mode(2 if blendfunc else 1) | 123 texture.set_blend_mode(2 if data.blendfunc else 1) |
126 | 124 |
127 if rotation or flip: | 125 if data.rotation or data.flip: |
128 self.window.win.render_copy_ex(texture, source, dest, rotation, flip) | 126 self.window.win.render_copy_ex(texture, source, dest, data.rotation, data.flip) |
129 else: | 127 else: |
130 self.window.win.render_copy(texture, source, dest) | 128 self.window.win.render_copy(texture, source, dest) |
131 | 129 |
132 nb_vertices += 4 | 130 nb_vertices += 4 |
133 | 131 |