From 9e6b627cbb9d60ef1f7d0a04d609b546686fb0ec Mon Sep 17 00:00:00 2001 From: DragonMoffon Date: Wed, 3 Jul 2024 18:26:44 +1200 Subject: [PATCH 1/2] Adding a sub-event for on_resize so users don't need to call `super().on_resize()` --- arcade/application.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/arcade/application.py b/arcade/application.py index 7be8fbed30..d56a2ebd2f 100644 --- a/arcade/application.py +++ b/arcade/application.py @@ -214,6 +214,8 @@ def __init__( # self.invalid = False set_window(self) + self.push_handlers(on_resize=self._on_resize) + self._ctx: ArcadeContext = ArcadeContext(self, gc_mode=gc_mode, gl_api=gl_api) self._background_color: Color = TRANSPARENT_BLACK @@ -601,18 +603,10 @@ def on_draw(self) -> Optional[bool]: """ return False - def on_resize(self, width: int, height: int) -> Optional[bool]: + def _on_resize(self, width: int, height: int): """ - Override this function to add custom code to be called any time the window - is resized. The main responsibility of this method is updating - the projection and the viewport. - - If you are not changing the default behavior when overriding, make sure - you call the parent's ``on_resize`` first:: - - def on_resize(self, width: int, height: int): - super().on_resize(width, height) - # Add extra resize logic here + Update the screen's viewport. If you need custom behaviour on resize there is another + method that can be overridden. :param width: New width :param height: New height @@ -626,6 +620,16 @@ def on_resize(self, width: int, height: int): return False + def on_resize(self, width: int, height: int) -> Optional[bool]: + """ + Override this function to add custom code to be called any time the window + is resized. + + :param width: New width + :param height: New height + """ + pass + def set_min_size(self, width: int, height: int) -> None: """Wrap the Pyglet window call to set minimum size From ea8d0d4aa9c2a39d9a4dd5181e59d0ba4397bfd3 Mon Sep 17 00:00:00 2001 From: DragonMoffon Date: Wed, 3 Jul 2024 19:24:39 +1200 Subject: [PATCH 2/2] remove unnecessary ctx check --- arcade/application.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/arcade/application.py b/arcade/application.py index d56a2ebd2f..de000a0972 100644 --- a/arcade/application.py +++ b/arcade/application.py @@ -611,12 +611,9 @@ def _on_resize(self, width: int, height: int): :param width: New width :param height: New height """ - # NOTE: When a second window is opened pyglet will - # dispatch on_resize during the window constructor. - # The arcade context is not created at that time - if hasattr(self, "_ctx"): - # Retain projection scrolling if applied - self.viewport = (0, 0, width, height) + + # Retain viewport + self.viewport = (0, 0, width, height) return False