annotate pytouhou/ui/anmrenderer.pyx @ 772:7492d384d122 default tip

Rust: Add a Glide renderer (2D only for now) This is an experiment for a Rust renderer, iterating over the Python data using pyo3. It requires --feature=glide to be passed to cargo build, doesn’t support NPOT textures, text rendering, the background, or even msg faces, some of that may come in a future changeset.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Mon, 05 Sep 2022 17:53:36 +0200
parents 80687f258001
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
237
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 # -*- encoding: utf-8 -*-
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2 ##
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
3 ## Copyright (C) 2011 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
4 ##
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
5 ## This program is free software; you can redistribute it and/or modify
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
6 ## it under the terms of the GNU General Public License as published
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
7 ## by the Free Software Foundation; version 3 only.
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
8 ##
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9 ## This program is distributed in the hope that it will be useful,
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
12 ## GNU General Public License for more details.
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
13 ##
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
14
425
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
15 from pytouhou.lib.opengl cimport \
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
16 (glClearColor, glClear, GL_COLOR_BUFFER_BIT)
237
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
17
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
18 from pytouhou.game.sprite import Sprite
547
e35bef07290d Always import runners from pytouhou.vm, to allow their replacement.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 455
diff changeset
19 from pytouhou.vm import ANMRunner
237
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
20
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
21 from pytouhou.utils.helpers import get_logger
425
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
22 from pytouhou.utils.maths cimport perspective, setup_camera
237
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
23
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
24 from .renderer import Renderer
405
402e96a0baeb Make the anmviewer use the programmable pipeline too.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 384
diff changeset
25 from .shaders.eosd import GameShader
402e96a0baeb Make the anmviewer use the programmable pipeline too.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 384
diff changeset
26
635
80687f258001 Make sdl.Window inherit from gui.Window, so we can swap implementations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 547
diff changeset
27 cimport pytouhou.lib.sdl as sdl
237
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
28
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
29
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
30 logger = get_logger(__name__)
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
31
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
32
425
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
33 class ANMRenderer(Renderer):
430
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 426
diff changeset
34 def __init__(self, window, resource_loader, anm, index=0, sprites=False):
425
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
35 self.use_fixed_pipeline = window.use_fixed_pipeline #XXX
237
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
36
425
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
37 Renderer.__init__(self, resource_loader)
237
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
38
425
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
39 self.window = window
426
5d7bb2fd74f7 Never keep texture on the host when it has been uploaded, and prevent them from being decoded again.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 425
diff changeset
40 self.texture_manager.load(resource_loader.instanced_anms.values())
405
402e96a0baeb Make the anmviewer use the programmable pipeline too.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 384
diff changeset
41
430
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 426
diff changeset
42 self._anm = anm
237
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
43 self.sprites = sprites
239
901489c21d19 Fix a few crashes in the anmrunner, disable fullscreen switch, change alt+Fx to shift+Fx
Thibaut Girka <thib@sitedethib.com>
parents: 238
diff changeset
44 self.clear_color = (0., 0., 0., 1.)
241
dd2bd7283bec Add support for multiple-file anms to anmviewer, add feature to force acceptance of translations
Thibaut Girka <thib@sitedethib.com>
parents: 239
diff changeset
45 self.force_allow_dest_offset = False
dd2bd7283bec Add support for multiple-file anms to anmviewer, add feature to force acceptance of translations
Thibaut Girka <thib@sitedethib.com>
parents: 239
diff changeset
46 self.index_items()
237
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
47 self.load(index)
384
690b5faaa0e6 Make rendering of multiple-sprites elements work like single-sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 382
diff changeset
48 self.objects = [self]
237
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
49
425
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
50 self.width = 384
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
51 self.height = 448
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
52
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
53 self.x = self.width / 2
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
54 self.y = self.height / 2
237
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
55
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
56
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
57 def start(self, width=384, height=448):
425
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
58 self.window.set_size(width, height)
237
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
59
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
60 # Switch to game projection
425
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
61 proj = perspective(30, float(width) / float(height),
412
5fe6cd6ceb48 Refactor the maths functions out of Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 405
diff changeset
62 101010101./2010101., 101010101./10101.)
5fe6cd6ceb48 Refactor the maths functions out of Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 405
diff changeset
63 view = setup_camera(0, 0, 1)
405
402e96a0baeb Make the anmviewer use the programmable pipeline too.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 384
diff changeset
64
425
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
65 shader = GameShader()
237
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
66
425
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
67 mvp = view * proj
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
68 shader.bind()
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
69 shader.uniform_matrix('mvp', mvp)
237
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
70
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
71
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
72 def load(self, index=None):
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
73 if index is None:
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
74 index = self.num
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 288
diff changeset
75 self.sprite = Sprite()
237
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
76 if self.sprites:
430
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 426
diff changeset
77 self.sprite.anm = self._anm
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 426
diff changeset
78 self.sprite.texcoords = self._anm.sprites[index]
239
901489c21d19 Fix a few crashes in the anmrunner, disable fullscreen switch, change alt+Fx to shift+Fx
Thibaut Girka <thib@sitedethib.com>
parents: 238
diff changeset
79 print('Loaded sprite %d' % index)
237
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
80 else:
430
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 426
diff changeset
81 self.anmrunner = ANMRunner(self._anm, index, self.sprite)
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 288
diff changeset
82 print('Loading anim %d, handled events: %r' % (index, self.anmrunner.script.interrupts.keys()))
237
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
83 self.num = index
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
84
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
85
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
86 def change(self, diff):
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
87 keys = self.items.keys()
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
88 keys.sort()
239
901489c21d19 Fix a few crashes in the anmrunner, disable fullscreen switch, change alt+Fx to shift+Fx
Thibaut Girka <thib@sitedethib.com>
parents: 238
diff changeset
89 index = (keys.index(self.num) + diff) % len(keys)
237
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
90 item = keys[index]
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
91 self.load(item)
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
92
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
93
241
dd2bd7283bec Add support for multiple-file anms to anmviewer, add feature to force acceptance of translations
Thibaut Girka <thib@sitedethib.com>
parents: 239
diff changeset
94 def index_items(self):
dd2bd7283bec Add support for multiple-file anms to anmviewer, add feature to force acceptance of translations
Thibaut Girka <thib@sitedethib.com>
parents: 239
diff changeset
95 self.items = {}
dd2bd7283bec Add support for multiple-file anms to anmviewer, add feature to force acceptance of translations
Thibaut Girka <thib@sitedethib.com>
parents: 239
diff changeset
96 if self.sprites:
430
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 426
diff changeset
97 self.items = self._anm.sprites
241
dd2bd7283bec Add support for multiple-file anms to anmviewer, add feature to force acceptance of translations
Thibaut Girka <thib@sitedethib.com>
parents: 239
diff changeset
98 else:
430
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 426
diff changeset
99 self.items = self._anm.scripts
241
dd2bd7283bec Add support for multiple-file anms to anmviewer, add feature to force acceptance of translations
Thibaut Girka <thib@sitedethib.com>
parents: 239
diff changeset
100
dd2bd7283bec Add support for multiple-file anms to anmviewer, add feature to force acceptance of translations
Thibaut Girka <thib@sitedethib.com>
parents: 239
diff changeset
101
237
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
102 def toggle_sprites(self):
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
103 self.sprites = not(self.sprites)
241
dd2bd7283bec Add support for multiple-file anms to anmviewer, add feature to force acceptance of translations
Thibaut Girka <thib@sitedethib.com>
parents: 239
diff changeset
104 self.index_items()
239
901489c21d19 Fix a few crashes in the anmrunner, disable fullscreen switch, change alt+Fx to shift+Fx
Thibaut Girka <thib@sitedethib.com>
parents: 238
diff changeset
105 self.load(0)
901489c21d19 Fix a few crashes in the anmrunner, disable fullscreen switch, change alt+Fx to shift+Fx
Thibaut Girka <thib@sitedethib.com>
parents: 238
diff changeset
106
901489c21d19 Fix a few crashes in the anmrunner, disable fullscreen switch, change alt+Fx to shift+Fx
Thibaut Girka <thib@sitedethib.com>
parents: 238
diff changeset
107
901489c21d19 Fix a few crashes in the anmrunner, disable fullscreen switch, change alt+Fx to shift+Fx
Thibaut Girka <thib@sitedethib.com>
parents: 238
diff changeset
108 def toggle_clear_color(self):
901489c21d19 Fix a few crashes in the anmrunner, disable fullscreen switch, change alt+Fx to shift+Fx
Thibaut Girka <thib@sitedethib.com>
parents: 238
diff changeset
109 if self.clear_color[0] == 0.:
901489c21d19 Fix a few crashes in the anmrunner, disable fullscreen switch, change alt+Fx to shift+Fx
Thibaut Girka <thib@sitedethib.com>
parents: 238
diff changeset
110 self.clear_color = (1., 1., 1., 1.)
901489c21d19 Fix a few crashes in the anmrunner, disable fullscreen switch, change alt+Fx to shift+Fx
Thibaut Girka <thib@sitedethib.com>
parents: 238
diff changeset
111 else:
901489c21d19 Fix a few crashes in the anmrunner, disable fullscreen switch, change alt+Fx to shift+Fx
Thibaut Girka <thib@sitedethib.com>
parents: 238
diff changeset
112 self.clear_color = (0., 0., 0., 1.)
237
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
113
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
114
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
115 def update(self):
425
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
116 sdl.SCANCODE_C = 6
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
117 sdl.SCANCODE_TAB = 43
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
118 sdl.SCANCODE_SPACE = 44
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
119 sdl.SCANCODE_F1 = 58
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
120 sdl.SCANCODE_F12 = 69
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
121 for event in sdl.poll_events():
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
122 type_ = event[0]
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
123 if type_ == sdl.KEYDOWN:
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
124 scancode = event[1]
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
125 if scancode == sdl.SCANCODE_Z:
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
126 self.load()
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
127 elif scancode == sdl.SCANCODE_X:
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
128 self.x, self.y = {(192, 224): (0, 0),
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
129 (0, 0): (-224, 0),
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
130 (-224, 0): (192, 224)}[(self.x, self.y)]
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
131 elif scancode == sdl.SCANCODE_C:
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
132 self.force_allow_dest_offset = not self.force_allow_dest_offset
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
133 self.load()
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
134 elif scancode == sdl.SCANCODE_LEFT:
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
135 self.change(-1)
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
136 elif scancode == sdl.SCANCODE_RIGHT:
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
137 self.change(+1)
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
138 elif scancode == sdl.SCANCODE_TAB:
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
139 self.toggle_sprites()
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
140 elif scancode == sdl.SCANCODE_SPACE:
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
141 self.toggle_clear_color()
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
142 elif sdl.SCANCODE_F1 <= scancode <= sdl.SCANCODE_F12:
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
143 interrupt = scancode - sdl.SCANCODE_F1 + 1
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
144 keys = sdl.get_keyboard_state()
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
145 if keys[sdl.SCANCODE_LSHIFT]:
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
146 interrupt += 12
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
147 if not self.sprites:
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
148 self.anmrunner.interrupt(interrupt)
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
149 elif scancode == sdl.SCANCODE_ESCAPE:
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
150 return False
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
151 elif type_ == sdl.QUIT:
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
152 return False
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
153 elif type_ == sdl.WINDOWEVENT:
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
154 event_ = event[1]
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
155 if event_ == sdl.WINDOWEVENT_RESIZED:
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
156 self.window.set_size(event[2], event[3])
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
157
237
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
158 if not self.sprites:
425
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
159 self.anmrunner.run_frame()
237
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
160
241
dd2bd7283bec Add support for multiple-file anms to anmviewer, add feature to force acceptance of translations
Thibaut Girka <thib@sitedethib.com>
parents: 239
diff changeset
161 if self.force_allow_dest_offset:
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 288
diff changeset
162 self.sprite.allow_dest_offset = True
241
dd2bd7283bec Add support for multiple-file anms to anmviewer, add feature to force acceptance of translations
Thibaut Girka <thib@sitedethib.com>
parents: 239
diff changeset
163
425
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
164 glClearColor(self.clear_color[0], self.clear_color[1], self.clear_color[2], self.clear_color[3])
237
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
165 glClear(GL_COLOR_BUFFER_BIT)
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 288
diff changeset
166 if not self.sprite.removed:
239
901489c21d19 Fix a few crashes in the anmrunner, disable fullscreen switch, change alt+Fx to shift+Fx
Thibaut Girka <thib@sitedethib.com>
parents: 238
diff changeset
167 self.render_elements([self])
425
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
168 return True
237
cbe9dbd80dfb Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
169
425
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
170
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
171 def finish(self):
1104dc2553ee Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 414
diff changeset
172 pass