Mercurial > touhou
annotate pytouhou/ui/anmrenderer.pyx @ 429:40d5f3083ebc
Implement PCB’s ANM2 format and vm.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sat, 03 Aug 2013 15:48:57 +0200 |
parents | 5d7bb2fd74f7 |
children | c9433188ffdb |
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 |
cbe9dbd80dfb
Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
19 from pytouhou.vm.anmrunner import ANMRunner |
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 |
425
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
27 from pytouhou.lib import 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): |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
34 def __init__(self, window, resource_loader, anm_wrapper, index=0, sprites=False): |
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 |
237
cbe9dbd80dfb
Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
42 self._anm_wrapper = anm_wrapper |
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: |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
288
diff
changeset
|
77 self.sprite.anm, self.sprite.texcoords = self._anm_wrapper.get_sprite(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
|
78 print('Loaded sprite %d' % index) |
237
cbe9dbd80dfb
Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
79 else: |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
288
diff
changeset
|
80 self.anmrunner = ANMRunner(self._anm_wrapper, index, self.sprite) |
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
288
diff
changeset
|
81 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
|
82 self.num = index |
cbe9dbd80dfb
Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
83 |
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 def change(self, diff): |
cbe9dbd80dfb
Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
86 keys = self.items.keys() |
cbe9dbd80dfb
Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
87 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
|
88 index = (keys.index(self.num) + diff) % len(keys) |
237
cbe9dbd80dfb
Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
89 item = keys[index] |
cbe9dbd80dfb
Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
90 self.load(item) |
cbe9dbd80dfb
Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
91 |
cbe9dbd80dfb
Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
92 |
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
|
93 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
|
94 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
|
95 if self.sprites: |
288
d95beee0087a
Make anmviewer work with newest anmwrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
241
diff
changeset
|
96 self.items = self._anm_wrapper.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
|
97 else: |
288
d95beee0087a
Make anmviewer work with newest anmwrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
241
diff
changeset
|
98 self.items = self._anm_wrapper.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
|
99 |
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 |
237
cbe9dbd80dfb
Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
101 def toggle_sprites(self): |
cbe9dbd80dfb
Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
102 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
|
103 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
|
104 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
|
105 |
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 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
|
108 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
|
109 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
|
110 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
|
111 self.clear_color = (0., 0., 0., 1.) |
237
cbe9dbd80dfb
Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
112 |
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 def update(self): |
425
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
115 sdl.SCANCODE_C = 6 |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
116 sdl.SCANCODE_TAB = 43 |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
117 sdl.SCANCODE_SPACE = 44 |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
118 sdl.SCANCODE_F1 = 58 |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
119 sdl.SCANCODE_F12 = 69 |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
120 for event in sdl.poll_events(): |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
121 type_ = event[0] |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
122 if type_ == sdl.KEYDOWN: |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
123 scancode = event[1] |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
124 if scancode == sdl.SCANCODE_Z: |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
125 self.load() |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
126 elif scancode == sdl.SCANCODE_X: |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
127 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
|
128 (0, 0): (-224, 0), |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
129 (-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
|
130 elif scancode == sdl.SCANCODE_C: |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
131 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
|
132 self.load() |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
133 elif scancode == sdl.SCANCODE_LEFT: |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
134 self.change(-1) |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
135 elif scancode == sdl.SCANCODE_RIGHT: |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
136 self.change(+1) |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
137 elif scancode == sdl.SCANCODE_TAB: |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
138 self.toggle_sprites() |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
139 elif scancode == sdl.SCANCODE_SPACE: |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
140 self.toggle_clear_color() |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
141 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
|
142 interrupt = scancode - sdl.SCANCODE_F1 + 1 |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
143 keys = sdl.get_keyboard_state() |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
144 if keys[sdl.SCANCODE_LSHIFT]: |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
145 interrupt += 12 |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
146 if not self.sprites: |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
147 self.anmrunner.interrupt(interrupt) |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
148 elif scancode == sdl.SCANCODE_ESCAPE: |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
149 return False |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
150 elif type_ == sdl.QUIT: |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
151 return False |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
152 elif type_ == sdl.WINDOWEVENT: |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
153 event_ = event[1] |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
154 if event_ == sdl.WINDOWEVENT_RESIZED: |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
155 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
|
156 |
237
cbe9dbd80dfb
Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
157 if not self.sprites: |
425
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
158 self.anmrunner.run_frame() |
237
cbe9dbd80dfb
Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
159 |
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
|
160 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
|
161 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
|
162 |
425
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
163 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
|
164 glClear(GL_COLOR_BUFFER_BIT) |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
288
diff
changeset
|
165 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
|
166 self.render_elements([self]) |
425
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
167 return True |
237
cbe9dbd80dfb
Add an anmviewer script.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
168 |
425
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
169 |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
170 def finish(self): |
1104dc2553ee
Make the anmviewer use the new architecture.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
414
diff
changeset
|
171 pass |