|
5 | 5 | from OpenGL import GL
|
6 | 6 | from time import time
|
7 | 7 |
|
| 8 | +import copy |
8 | 9 | from ..events import handler_names
|
9 | 10 | from .handlers import *
|
10 | 11 | from .util import *
|
@@ -205,19 +206,33 @@ def frame_buffer_resize_callback_handler(self, window, width, height):
|
205 | 206 | Values of width and height may not be equal to the actual window's width and height
|
206 | 207 | in Retina Display
|
207 | 208 | """
|
208 |
| - |
209 | 209 | # Callback handler for frame buffer resize events
|
| 210 | + |
| 211 | + self.resized = False |
210 | 212 | builtins.pixel_x_density = width / self.size[0]
|
211 | 213 | builtins.pixel_y_density = height / self.size[1]
|
212 | 214 | self.pixel_density = width * height // (self.size[0] * self.size[1])
|
213 | 215 |
|
| 216 | + # Creates an Image of current surface and a copy of current style configurations |
| 217 | + # For the purpose of handling setup_method() re-call |
| 218 | + # Ref: Issue #419 |
| 219 | + old_image = self.surface.makeImageSnapshot() |
| 220 | + old_image = old_image.resize(old_image.width(), old_image.height()) |
| 221 | + old_style = copy.deepcopy(p5.renderer.style) |
| 222 | + |
214 | 223 | GL.glViewport(0, 0, width, height)
|
215 | 224 | self.create_surface(size=(width, height))
|
216 |
| - # with self.surface as self.canvas: |
217 |
| - # # redraw on the canvas/ ( new frame buffer ) after resizing |
218 |
| - # # and do not rewind/clear the path |
| 225 | + self.setup_method() |
| 226 | + |
| 227 | + # Redraws Image on the canvas/ new frame buffer |
| 228 | + # Previously stored style configurations are restored for |
| 229 | + # discarding setup_method() style changes |
| 230 | + p5.renderer.style = old_style |
| 231 | + with self.surface as self.canvas: |
| 232 | + self.canvas.drawImage(old_image, 0, 0) |
219 | 233 |
|
220 | 234 | # Tell the program, we have resized the frame buffer
|
| 235 | + # and do not rewind/clear the path |
221 | 236 | # Restart the rendering again
|
222 | 237 | self.resized = True
|
223 | 238 |
|
|
0 commit comments