|
| 1 | +"""get_display_size() is in window units, so a window that size fills the screen (#2791).""" |
| 2 | + |
| 3 | +import pyglet |
| 4 | +import pytest |
| 5 | + |
| 6 | +import arcade |
| 7 | + |
| 8 | + |
| 9 | +class FakeScreen: |
| 10 | + def __init__(self, width, height, scale): |
| 11 | + self.width = width |
| 12 | + self.height = height |
| 13 | + self._scale = scale |
| 14 | + |
| 15 | + def get_scale(self): |
| 16 | + return self._scale |
| 17 | + |
| 18 | + |
| 19 | +@pytest.fixture |
| 20 | +def fake_screen(monkeypatch): |
| 21 | + def use(width, height, scale, dpi_scaling, platform): |
| 22 | + screen = FakeScreen(width, height, scale) |
| 23 | + |
| 24 | + class FakeDisplay: |
| 25 | + def get_screens(self): |
| 26 | + return [screen] |
| 27 | + |
| 28 | + monkeypatch.setattr(pyglet.display, "Display", FakeDisplay) |
| 29 | + monkeypatch.setattr(pyglet.options, "dpi_scaling", dpi_scaling) |
| 30 | + monkeypatch.setattr(pyglet, "compat_platform", platform) |
| 31 | + |
| 32 | + return use |
| 33 | + |
| 34 | + |
| 35 | +@pytest.mark.parametrize("platform", ["win32", "linux", "linux-compat"]) |
| 36 | +@pytest.mark.parametrize( |
| 37 | + ("width", "height", "scale", "expected"), |
| 38 | + [ |
| 39 | + (1920, 1080, 1.0, (1920, 1080)), |
| 40 | + (2560, 1440, 1.25, (2048, 1152)), |
| 41 | + (1920, 1080, 1.5, (1280, 720)), |
| 42 | + # Rounded down, so the scaled window isn't bigger than the screen |
| 43 | + (1366, 768, 1.75, (780, 438)), |
| 44 | + ], |
| 45 | +) |
| 46 | +def test_stretch_divides_by_scale(fake_screen, platform, width, height, scale, expected): |
| 47 | + fake_screen(width, height, scale, "stretch", platform) |
| 48 | + size = arcade.get_display_size() |
| 49 | + assert size == expected |
| 50 | + assert int(size[0] * scale) <= width |
| 51 | + assert int(size[1] * scale) <= height |
| 52 | + |
| 53 | + |
| 54 | +@pytest.mark.parametrize("platform", ["darwin", "emscripten"]) |
| 55 | +def test_stretch_on_platforms_that_dont_scale_windows(fake_screen, platform): |
| 56 | + fake_screen(1440, 900, 2.0, "stretch", platform) |
| 57 | + assert arcade.get_display_size() == (1440, 900) |
| 58 | + |
| 59 | + |
| 60 | +def test_platform_scaling_returns_the_screen_size(fake_screen): |
| 61 | + fake_screen(2560, 1440, 1.25, "platform", "win32") |
| 62 | + assert arcade.get_display_size() == (2560, 1440) |
0 commit comments