From 3a69f43f5be070db34cc61f454acf4756418e48b Mon Sep 17 00:00:00 2001 From: Einar Forselv Date: Fri, 6 Sep 2024 20:03:48 +0200 Subject: [PATCH 1/6] Enable scaling on windows by default --- arcade/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arcade/__init__.py b/arcade/__init__.py index 05c4afd90e..fb20949f75 100644 --- a/arcade/__init__.py +++ b/arcade/__init__.py @@ -72,6 +72,10 @@ def configure_logging(level: int | None = None): if sys.platform == "darwin" or os.environ.get("ARCADE_HEADLESS") or utils.is_raspberry_pi(): pyglet.options.shadow_window = False # type: ignore # pending https://github.com/pyglet/pyglet/issues/1164 +# Enable HiDPI support on Windows +if sys.platform == "win32": + pyglet.options.scale_with_dpi = True # type: ignore # pending https://github.com/pyglet/pyglet/pull/1202 + # Use the old gdi fonts on windows until directwrite is fast/stable # pyglet.options.win32_gdi_font = True From 6cfef7774346fc65cb78ba6599dc467b5e7c7eee Mon Sep 17 00:00:00 2001 From: Einar Forselv Date: Sat, 14 Sep 2024 15:09:19 +0200 Subject: [PATCH 2/6] Add scaling mode --- arcade/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/arcade/__init__.py b/arcade/__init__.py index fb20949f75..59a0386fc4 100644 --- a/arcade/__init__.py +++ b/arcade/__init__.py @@ -75,6 +75,7 @@ def configure_logging(level: int | None = None): # Enable HiDPI support on Windows if sys.platform == "win32": pyglet.options.scale_with_dpi = True # type: ignore # pending https://github.com/pyglet/pyglet/pull/1202 + pyglet.options.dpi_scaling = "window_and_content" # Use the old gdi fonts on windows until directwrite is fast/stable # pyglet.options.win32_gdi_font = True From cbfdbe3f6d7a379a60bb81d3c27b00802a1e75fe Mon Sep 17 00:00:00 2001 From: Einar Forselv Date: Sat, 14 Sep 2024 16:01:49 +0200 Subject: [PATCH 3/6] Draw offscreen texture using window projection --- arcade/start_finish_data.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arcade/start_finish_data.py b/arcade/start_finish_data.py index 52ccff1d11..31e7384457 100644 --- a/arcade/start_finish_data.py +++ b/arcade/start_finish_data.py @@ -52,7 +52,10 @@ def begin(self): Should only be called once followed by a call to :py:meth:`end`. """ - self.generator_func = self.atlas.render_into(self.texture) + self.generator_func = self.atlas.render_into( + self.texture, + projection=(0, self.window.width, 0, self.window.height), + ) fbo = self.generator_func.__enter__() fbo.clear(color=self.window.background_color) From 806b49a88dee16213193269a38430ce24035dc91 Mon Sep 17 00:00:00 2001 From: Einar Forselv Date: Sun, 13 Oct 2024 12:17:28 +0200 Subject: [PATCH 4/6] HDPI options from pyglet2.1 dev7 --- arcade/__init__.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/arcade/__init__.py b/arcade/__init__.py index 59a0386fc4..8964ab196d 100644 --- a/arcade/__init__.py +++ b/arcade/__init__.py @@ -72,13 +72,8 @@ def configure_logging(level: int | None = None): if sys.platform == "darwin" or os.environ.get("ARCADE_HEADLESS") or utils.is_raspberry_pi(): pyglet.options.shadow_window = False # type: ignore # pending https://github.com/pyglet/pyglet/issues/1164 -# Enable HiDPI support on Windows -if sys.platform == "win32": - pyglet.options.scale_with_dpi = True # type: ignore # pending https://github.com/pyglet/pyglet/pull/1202 - pyglet.options.dpi_scaling = "window_and_content" - -# Use the old gdi fonts on windows until directwrite is fast/stable -# pyglet.options.win32_gdi_font = True +# Enable HiDPI support +pyglet.options.dpi_scaling = "scaled" # Imports from modules that don't do anything circular From 5ad5d534d297bbbf9c23360f1175cb4c94bcf871 Mon Sep 17 00:00:00 2001 From: Einar Forselv Date: Sun, 13 Oct 2024 18:22:23 +0200 Subject: [PATCH 5/6] Adjust to pyglet 2.0dev7 --- arcade/__init__.py | 5 ++--- arcade/application.py | 12 +++++------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/arcade/__init__.py b/arcade/__init__.py index 8964ab196d..ffb4efdbeb 100644 --- a/arcade/__init__.py +++ b/arcade/__init__.py @@ -59,6 +59,8 @@ def configure_logging(level: int | None = None): import pyglet +# Enable HiDPI support +pyglet.options.dpi_scaling = "stretch" # Env variable shortcut for headless mode headless: Final[bool] = bool(os.environ.get("ARCADE_HEADLESS")) @@ -72,9 +74,6 @@ def configure_logging(level: int | None = None): if sys.platform == "darwin" or os.environ.get("ARCADE_HEADLESS") or utils.is_raspberry_pi(): pyglet.options.shadow_window = False # type: ignore # pending https://github.com/pyglet/pyglet/issues/1164 -# Enable HiDPI support -pyglet.options.dpi_scaling = "scaled" - # Imports from modules that don't do anything circular # Complex imports with potential circularity diff --git a/arcade/application.py b/arcade/application.py index c683212ef7..bad37616db 100644 --- a/arcade/application.py +++ b/arcade/application.py @@ -195,7 +195,7 @@ def __init__( alpha_size=8, ) display = pyglet.display.get_display() - screen = display.get_default_screen() # type: ignore # pending: resolve upstream type tricks + screen = screen or display.get_default_screen() if screen: config = screen.get_best_config(config) except pyglet.window.NoSuchConfigException: @@ -260,11 +260,9 @@ def __init__( self.set_vsync(vsync) - super().set_fullscreen(fullscreen, screen) - # This used to be necessary on Linux, but no longer appears to be. - # With Pyglet 2.0+, setting this to false will not allow the screen to - # update. It does, however, cause flickering if creating a window that - # isn't derived from the Window class. + if fullscreen is True: + super().set_fullscreen(True, screen) + set_window(self) self.push_handlers(on_resize=self._on_resize) @@ -472,7 +470,7 @@ def center_window(self) -> None: # Get the display screen using pyglet screen_width, screen_height = get_display_size() - window_width, window_height = self.get_size() + window_width, window_height = self.get_framebuffer_size() # Center the window self.set_location((screen_width - window_width) // 2, (screen_height - window_height) // 2) From 9091019081782c5d508c85500038dee1e4dab7af Mon Sep 17 00:00:00 2001 From: Einar Forselv Date: Sun, 13 Oct 2024 19:20:21 +0200 Subject: [PATCH 6/6] Disable scaling during unit tests --- arcade/__init__.py | 5 ++++- tests/conftest.py | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/arcade/__init__.py b/arcade/__init__.py index ffb4efdbeb..a4c812d3ea 100644 --- a/arcade/__init__.py +++ b/arcade/__init__.py @@ -60,7 +60,10 @@ def configure_logging(level: int | None = None): import pyglet # Enable HiDPI support -pyglet.options.dpi_scaling = "stretch" +if os.environ.get("ARCADE_TEST"): + pyglet.options.dpi_scaling = "real" +else: + pyglet.options.dpi_scaling = "stretch" # Env variable shortcut for headless mode headless: Final[bool] = bool(os.environ.get("ARCADE_HEADLESS")) diff --git a/tests/conftest.py b/tests/conftest.py index 2abf2d8e7f..422288e635 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,6 +3,9 @@ import os from pathlib import Path +os.environ["ARCADE_TEST"] = "True" + + if os.environ.get("ARCADE_PYTEST_USE_RUST"): import arcade_accelerate # pyright: ignore [reportMissingImports]