annotate pytouhou/ui/sdl/gamerenderer.py @ 615:d1f0bb0b7a17

Don’t inherit explicitely from object, we are not on Python 2.7 anymore. :)
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 28 Mar 2015 21:40:51 +0100
parents e15672733c93
children 0ea591b0b29e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
512
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 # -*- encoding: utf-8 -*-
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2 ##
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
3 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com>
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
4 ##
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
5 ## This program is free software; you can redistribute it and/or modify
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
6 ## it under the terms of the GNU General Public License as published
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
7 ## by the Free Software Foundation; version 3 only.
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
8 ##
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9 ## This program is distributed in the hope that it will be useful,
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
12 ## GNU General Public License for more details.
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
13 ##
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
14
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
15 from itertools import chain
544
b895ed2de71f Implement text rendering for the SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 533
diff changeset
16 from os.path import join
512
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
17
544
b895ed2de71f Implement text rendering for the SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 533
diff changeset
18 from pytouhou.lib.sdl import Rect, SDLError
512
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
19
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
20 from pytouhou.utils.helpers import get_logger
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
21 logger = get_logger(__name__)
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
22
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
23
615
d1f0bb0b7a17 Don’t inherit explicitely from object, we are not on Python 2.7 anymore. :)
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 590
diff changeset
24 class GameRenderer:
512
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
25 def __init__(self, resource_loader, window):
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
26 self.window = window
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
27 self.texture_manager = TextureManager(resource_loader, self.window.win)
544
b895ed2de71f Implement text rendering for the SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 533
diff changeset
28 font_name = join(resource_loader.game_dir, 'font.ttf')
b895ed2de71f Implement text rendering for the SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 533
diff changeset
29 try:
b895ed2de71f Implement text rendering for the SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 533
diff changeset
30 self.font_manager = FontManager(font_name, 16, self.window.win)
b895ed2de71f Implement text rendering for the SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 533
diff changeset
31 except SDLError:
b895ed2de71f Implement text rendering for the SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 533
diff changeset
32 self.font_manager = None
b895ed2de71f Implement text rendering for the SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 533
diff changeset
33 logger.error('Font file “%s” not found, disabling text rendering altogether.', font_name)
512
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
34
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
35
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
36 def load_textures(self, anms):
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
37 self.texture_manager.load(anms)
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
38
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
39
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
40 def load_background(self, background):
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
41 if background is not None:
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
42 logger.error('Background rendering unavailable in the SDL backend.')
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
43
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
44
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
45 def start(self, common):
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
46 pass
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
47
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
48
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
49 def render(self, game):
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
50 self.render_game(game)
516
577c3a88fb67 Merge the lists Game.texts and Game.native_texts into the Game.texts dict.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 512
diff changeset
51 self.render_text(game.texts)
512
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
52 self.render_interface(game.interface, game.boss)
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
53
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
54
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
55 def render_game(self, game):
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
56 x, y = game.interface.game_pos
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
57 self.window.win.render_set_viewport(Rect(x, y, game.width, game.height))
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
58 self.window.win.render_set_clip_rect(Rect(x, -y, game.width, game.height))
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
59
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
60 if game is not None:
551
0d7a16e0f834 Don’t display spellcard backgrounds either with the SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 549
diff changeset
61 self.window.win.render_clear()
512
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
62
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
63 self.render_elements([enemy for enemy in game.enemies if enemy.visible])
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
64 self.render_elements(game.effects)
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
65 self.render_elements(chain(game.players_bullets,
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
66 game.lasers_sprites(),
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
67 game.players,
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
68 game.msg_sprites()))
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
69 self.render_elements(chain(game.bullets, game.lasers,
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
70 game.cancelled_bullets, game.items,
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
71 game.labels))
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
72
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
73
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
74 def render_interface(self, interface, boss):
549
56bca8ce4b68 Add a very simple sample interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 544
diff changeset
75 interface_labels = interface.labels
56bca8ce4b68 Add a very simple sample interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 544
diff changeset
76 if 'framerate' in interface_labels:
56bca8ce4b68 Add a very simple sample interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 544
diff changeset
77 interface_labels['framerate'].set_text('%.2ffps' % self.window.get_fps())
512
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
78
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
79 self.window.win.render_set_viewport(Rect(0, 0, interface.width, interface.height))
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
80 self.window.win.render_set_clip_rect(Rect(0, 0, interface.width, interface.height))
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
81
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
82 items = [item for item in interface.items if item.anmrunner and item.anmrunner.running]
549
56bca8ce4b68 Add a very simple sample interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 544
diff changeset
83 labels = interface_labels.values()
512
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
84
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
85 if items:
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
86 # Redraw all the interface
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
87 self.render_elements(items)
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
88 else:
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
89 # Redraw only changed labels
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
90 labels = [label for label in labels if label.changed]
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
91
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
92 self.render_elements(interface.level_start)
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
93
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
94 if boss:
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
95 self.render_elements(interface.boss_items)
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
96
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
97 self.render_elements(labels)
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
98 for label in labels:
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
99 label.changed = False
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
100
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
101
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
102 def render_elements(self, elements):
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
103 nb_vertices = 0
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
104
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
105 objects = chain(*[element.objects for element in elements])
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
106 for element in objects:
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
107 if nb_vertices >= MAX_ELEMENTS - 4:
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
108 break
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
109
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
110 sprite = element.sprite
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
111 if sprite and sprite.visible:
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
112 ox, oy = element.x, element.y
532
dacdcca59b66 Don’t put back the rendering data into a tuple, use a specialised struct inside Sprite to pass it to the renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 516
diff changeset
113 data = get_sprite_rendering_data(sprite)
512
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
114
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
115 #XXX
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
116 texture_width = 256
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
117 texture_height = 256
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
118
532
dacdcca59b66 Don’t put back the rendering data into a tuple, use a specialised struct inside Sprite to pass it to the renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 516
diff changeset
119 source = Rect(data.left * texture_width,
dacdcca59b66 Don’t put back the rendering data into a tuple, use a specialised struct inside Sprite to pass it to the renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 516
diff changeset
120 data.bottom * texture_height,
dacdcca59b66 Don’t put back the rendering data into a tuple, use a specialised struct inside Sprite to pass it to the renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 516
diff changeset
121 (data.right - data.left) * texture_width,
dacdcca59b66 Don’t put back the rendering data into a tuple, use a specialised struct inside Sprite to pass it to the renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 516
diff changeset
122 (data.top - data.bottom) * texture_height)
dacdcca59b66 Don’t put back the rendering data into a tuple, use a specialised struct inside Sprite to pass it to the renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 516
diff changeset
123
dacdcca59b66 Don’t put back the rendering data into a tuple, use a specialised struct inside Sprite to pass it to the renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 516
diff changeset
124 dest = Rect(ox + data.x, oy + data.y, data.width, data.height)
512
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
125
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
126 texture = sprite.anm.texture
532
dacdcca59b66 Don’t put back the rendering data into a tuple, use a specialised struct inside Sprite to pass it to the renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 516
diff changeset
127 texture.set_color_mod(data.r, data.g, data.b)
dacdcca59b66 Don’t put back the rendering data into a tuple, use a specialised struct inside Sprite to pass it to the renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 516
diff changeset
128 texture.set_alpha_mod(data.a)
dacdcca59b66 Don’t put back the rendering data into a tuple, use a specialised struct inside Sprite to pass it to the renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 516
diff changeset
129 texture.set_blend_mode(2 if data.blendfunc else 1)
512
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
130
532
dacdcca59b66 Don’t put back the rendering data into a tuple, use a specialised struct inside Sprite to pass it to the renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 516
diff changeset
131 if data.rotation or data.flip:
dacdcca59b66 Don’t put back the rendering data into a tuple, use a specialised struct inside Sprite to pass it to the renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 516
diff changeset
132 self.window.win.render_copy_ex(texture, source, dest, data.rotation, data.flip)
512
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
133 else:
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
134 self.window.win.render_copy(texture, source, dest)
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
135
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
136 nb_vertices += 4
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
137
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
138
b39ad30c6620 Add a pure SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
139 def render_text(self, texts):
544
b895ed2de71f Implement text rendering for the SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 533
diff changeset
140 if self.font_manager is None:
b895ed2de71f Implement text rendering for the SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 533
diff changeset
141 return
b895ed2de71f Implement text rendering for the SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 533
diff changeset
142
b895ed2de71f Implement text rendering for the SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 533
diff changeset
143 self.font_manager.load(texts)
b895ed2de71f Implement text rendering for the SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 533
diff changeset
144
590
e15672733c93 Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 551
diff changeset
145 for label in texts.values():
544
b895ed2de71f Implement text rendering for the SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 533
diff changeset
146 texture = label.texture
b895ed2de71f Implement text rendering for the SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 533
diff changeset
147
b895ed2de71f Implement text rendering for the SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 533
diff changeset
148 source = Rect(0, 0, label.width, label.height)
b895ed2de71f Implement text rendering for the SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 533
diff changeset
149 rect = Rect(label.x, label.y, label.width, label.height)
b895ed2de71f Implement text rendering for the SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 533
diff changeset
150
b895ed2de71f Implement text rendering for the SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 533
diff changeset
151 texture.set_alpha_mod(label.alpha)
b895ed2de71f Implement text rendering for the SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 533
diff changeset
152
b895ed2de71f Implement text rendering for the SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 533
diff changeset
153 if label.shadow:
b895ed2de71f Implement text rendering for the SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 533
diff changeset
154 shadow_rect = Rect(label.x + 1, label.y + 1, label.width, label.height)
b895ed2de71f Implement text rendering for the SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 533
diff changeset
155 texture.set_color_mod(0, 0, 0)
b895ed2de71f Implement text rendering for the SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 533
diff changeset
156 self.window.win.render_copy(label.texture, source, shadow_rect)
b895ed2de71f Implement text rendering for the SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 533
diff changeset
157 texture.set_color_mod(192, 192, 255)
b895ed2de71f Implement text rendering for the SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 533
diff changeset
158 self.window.win.render_copy(label.texture, source, rect)
b895ed2de71f Implement text rendering for the SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 533
diff changeset
159 else:
b895ed2de71f Implement text rendering for the SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 533
diff changeset
160 texture.set_color_mod(192, 192, 255)
b895ed2de71f Implement text rendering for the SDL backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 533
diff changeset
161 self.window.win.render_copy(label.texture, source, rect)