-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame_display.py
More file actions
92 lines (73 loc) · 2.97 KB
/
Copy pathgame_display.py
File metadata and controls
92 lines (73 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
"""Display mode: windowed by default; set FKAC_FULLSCREEN=1 for fullscreen (legacy behavior)."""
import os
import sys
# Before pygame/SDL init: SCALED fullscreen uses GPU scale; "0" = nearest (sharp), not linear blur.
os.environ.setdefault("SDL_RENDER_SCALE_QUALITY", "0")
import pygame
# Window chrome (caption + taskbar icon). Icon must be set before set_mode() on many platforms.
GAME_WINDOW_TITLE = "For King and Country"
_ICON_CANDIDATES = (
os.path.join("images", "kin1", "kin1_fr1.gif"), # King walk frame (matches GameUI.King "kin1")
os.path.join("images", "placeholder.png"),
)
_ICON_SIZE = (32, 32)
def _load_window_icon():
"""Load a small surface for pygame.display.set_icon (King sprite preferred)."""
for path in _ICON_CANDIDATES:
if not os.path.isfile(path):
continue
try:
surf = pygame.image.load(path).convert_alpha()
if surf.get_size() != _ICON_SIZE:
surf = pygame.transform.smoothscale(surf, _ICON_SIZE)
return surf
except pygame.error:
continue
return None
def _apply_window_icon_before_set_mode():
"""Call after pygame.init(), immediately before pygame.display.set_mode()."""
icon = _load_window_icon()
if icon is not None:
pygame.display.set_icon(icon)
def _windows_dpi_aware() -> None:
"""Reduce odd scaling / compositor glitches next to the taskbar in fullscreen on Windows."""
if sys.platform != "win32":
return
try:
import ctypes
ctypes.windll.shcore.SetProcessDpiAwareness(2) # PROCESS_PER_MONITOR_DPI_AWARE
except Exception:
try:
import ctypes
ctypes.windll.user32.SetProcessDPIAware()
except Exception:
pass
_windows_dpi_aware()
def env_fullscreen() -> bool:
return os.environ.get("FKAC_FULLSCREEN", "").strip().lower() in ("1", "true", "yes")
def ui_font_antialias() -> bool:
"""Antialiased text looks soft when the window is GPU-upscaled; use crisp glyphs in fullscreen."""
try:
s = pygame.display.get_surface()
if s is None:
return True
return not bool(s.get_flags() & pygame.FULLSCREEN)
except Exception:
return True
def set_mode(size=(640, 480), fullscreen=None):
"""If fullscreen is None, use env FKAC_FULLSCREEN; otherwise use the explicit bool."""
if fullscreen is None:
fs = env_fullscreen()
else:
fs = bool(fullscreen)
if fs:
# SCALED: logical size (e.g. 640x480) is GPU-scaled to the monitor — avoids letterboxing
# that can leave the desktop / taskbar visible as a smeared strip on some setups.
flags = pygame.FULLSCREEN | pygame.SCALED
else:
flags = 0
# Avoid vsync= here: on some Windows/GPU/driver combos it can leave the window black with no error.
_apply_window_icon_before_set_mode()
screen = pygame.display.set_mode(size, flags)
pygame.display.set_caption(GAME_WINDOW_TITLE)
return screen