Mercurial > touhou
comparison pytouhou/ui/sdl/sprite.pyx @ 512:b39ad30c6620
Add a pure SDL backend.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Thu, 05 Dec 2013 01:55:39 +0100 |
parents | |
children | 3d4410de78e1 |
comparison
equal
deleted
inserted
replaced
511:2e8ceaa85d5c | 512:b39ad30c6620 |
---|---|
1 # -*- encoding: utf-8 -*- | |
2 ## | |
3 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com> | |
4 ## | |
5 ## This program is free software; you can redistribute it and/or modify | |
6 ## it under the terms of the GNU General Public License as published | |
7 ## by the Free Software Foundation; version 3 only. | |
8 ## | |
9 ## This program is distributed in the hope that it will be useful, | |
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 ## GNU General Public License for more details. | |
13 ## | |
14 | |
15 | |
16 from libc.math cimport M_PI as pi | |
17 | |
18 | |
19 cpdef object get_sprite_rendering_data(Sprite sprite): | |
20 cdef double x, y, tx, ty, tw, th, sx, sy, rz, tox, toy | |
21 | |
22 if not sprite.changed: | |
23 return sprite._rendering_data | |
24 | |
25 x = 0 | |
26 y = 0 | |
27 | |
28 tx, ty, tw, th = sprite.texcoords | |
29 sx, sy = sprite.rescale | |
30 width = sprite.width_override or (tw * sx) | |
31 height = sprite.height_override or (th * sy) | |
32 | |
33 rz = sprite.rotations_3d[2] | |
34 if sprite.automatic_orientation: | |
35 rz += pi/2. - sprite.angle | |
36 elif sprite.force_rotation: | |
37 rz += sprite.angle | |
38 | |
39 if sprite.allow_dest_offset: | |
40 x += sprite.dest_offset[0] | |
41 y += sprite.dest_offset[1] | |
42 if not sprite.corner_relative_placement: # Reposition | |
43 x -= width / 2 | |
44 y -= height / 2 | |
45 | |
46 size = sprite.anm.size | |
47 x_1 = 1 / <double>size[0] | |
48 y_1 = 1 / <double>size[1] | |
49 tox, toy = sprite.texoffsets | |
50 uvs = (tx * x_1 + tox, | |
51 (tx + tw) * x_1 + tox, | |
52 ty * y_1 + toy, | |
53 (ty + th) * y_1 + toy) | |
54 | |
55 key = sprite.blendfunc | |
56 r, g, b = sprite.color | |
57 values = (x, y, width, height), uvs, (r, g, b, sprite.alpha), -rz * 180 / pi, sprite.mirrored | |
58 sprite._rendering_data = key, values | |
59 sprite.changed = False | |
60 | |
61 return sprite._rendering_data |