Mercurial > touhou
comparison pytouhou/ui/window.pyx @ 464:36bc577b2392
Make the window resizable, and scale its content correctly.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Wed, 11 Sep 2013 15:55:19 +0200 |
parents | 11708a1d0a1a |
children | 58b47e788c59 |
comparison
equal
deleted
inserted
replaced
463:11708a1d0a1a | 464:36bc577b2392 |
---|---|
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 ## GNU General Public License for more details. | 12 ## GNU General Public License for more details. |
13 ## | 13 ## |
14 | 14 |
15 cimport cython | |
15 | 16 |
16 from pytouhou.lib.opengl cimport \ | 17 from pytouhou.lib.opengl cimport \ |
17 (glEnable, glHint, glEnableClientState, GL_TEXTURE_2D, GL_BLEND, | 18 (glEnable, glHint, glEnableClientState, GL_TEXTURE_2D, GL_BLEND, |
18 GL_PERSPECTIVE_CORRECTION_HINT, GL_FOG_HINT, GL_NICEST, | 19 GL_PERSPECTIVE_CORRECTION_HINT, GL_FOG_HINT, GL_NICEST, |
19 GL_COLOR_ARRAY, GL_VERTEX_ARRAY, GL_TEXTURE_COORD_ARRAY) | 20 GL_COLOR_ARRAY, GL_VERTEX_ARRAY, GL_TEXTURE_COORD_ARRAY) |
98 sdl.gl_set_attribute(sdl.GL_DOUBLEBUFFER, int(double_buffer)) | 99 sdl.gl_set_attribute(sdl.GL_DOUBLEBUFFER, int(double_buffer)) |
99 sdl.gl_set_attribute(sdl.GL_DEPTH_SIZE, 24) | 100 sdl.gl_set_attribute(sdl.GL_DEPTH_SIZE, 24) |
100 | 101 |
101 self.width, self.height = size if size is not None else (640, 480) | 102 self.width, self.height = size if size is not None else (640, 480) |
102 | 103 |
104 flags = sdl.WINDOW_OPENGL | sdl.WINDOW_SHOWN | |
105 if not self.use_fixed_pipeline: | |
106 flags |= sdl.WINDOW_RESIZABLE | |
107 | |
103 self.win = sdl.Window('PyTouhou', | 108 self.win = sdl.Window('PyTouhou', |
104 sdl.WINDOWPOS_CENTERED, sdl.WINDOWPOS_CENTERED, | 109 sdl.WINDOWPOS_CENTERED, sdl.WINDOWPOS_CENTERED, |
105 self.width, self.height, | 110 self.width, self.height, |
106 sdl.WINDOW_OPENGL | sdl.WINDOW_SHOWN) | 111 flags) |
107 self.win.gl_create_context() | 112 self.win.gl_create_context() |
108 | 113 |
109 IF USE_GLEW: | 114 IF USE_GLEW: |
110 if glewInit() != 0: | 115 if glewInit() != 0: |
111 raise Exception('GLEW init fail!') | 116 raise Exception('GLEW init fail!') |
121 glEnableClientState(GL_TEXTURE_COORD_ARRAY) | 126 glEnableClientState(GL_TEXTURE_COORD_ARRAY) |
122 | 127 |
123 self.clock = Clock(self.fps_limit) | 128 self.clock = Clock(self.fps_limit) |
124 | 129 |
125 | 130 |
131 @cython.cdivision(True) | |
126 cdef void set_size(self, int width, int height) nogil: | 132 cdef void set_size(self, int width, int height) nogil: |
127 self.win.set_window_size(width, height) | 133 self.win.set_window_size(width, height) |
134 | |
135 runner_width = float(self.runner.width) | |
136 runner_height = float(self.runner.height) | |
137 | |
138 scale = min(width / runner_width, | |
139 height / runner_height) | |
140 | |
141 self.width = int(runner_width * scale) | |
142 self.height = int(runner_height * scale) | |
143 | |
144 self.x = (width - self.width) // 2 | |
145 self.y = (height - self.height) // 2 | |
128 | 146 |
129 | 147 |
130 cpdef set_runner(self, Runner runner=None): | 148 cpdef set_runner(self, Runner runner=None): |
131 self.runner = runner | 149 self.runner = runner |
132 if runner is not None: | 150 if runner is not None: |