FFFF Enable Builds and Alternative Resolutions by jmahmood · Pull Request #31 · jmahmood/CardBrick · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,15 @@ deploy/knulli/scripts/.deckbuild-venv/
# the package (see deploy/knulli/decks/README.md) — not app content.
deploy/knulli/decks/*
!deploy/knulli/decks/README.md

# MinUI packaging outputs (deploy/minui) — build-runtime.sh writes the
# squashfs artifact straight into runtime-build/, alongside the tracked
# hook files (see deploy/minui/runtime-build/docker-compose.yml).
deploy/minui/runtime-build/*.squashfs
deploy/minui/dist/
deploy/minui/scripts/.deckbuild-venv/

# Personal deck files dropped in deploy/minui/decks/ for baking into
# the package (see deploy/minui/decks/README.md) — not app content.
deploy/minui/decks/*
!deploy/minui/decks/README.md
2 changes: 1 addition & 1 deletion cardbrick-py/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Review service (cardbrick/service.py — daily limits, category
Session runner (cardbrick/session.py — one sitting: queue, counters,
↓ summary)
Pygame app (cardbrick/app.py — state-driven child/parent UI on a
native 640x480 or 720x480 handheld canvas,
native 640x480, 720x480 or 720x720 handheld canvas,
controller-first)
```

Expand Down
53 changes: 43 additions & 10 deletions cardbrick-py/cardbrick/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@
button indices are never trusted (see input_map.py). Face buttons are
labelled with the fixed layout used by this app (A = right, B = bottom,
X = top, Y = left).
- Everything renders on a native handheld logical canvas (640x480 or
720x480 when detected) which is scaled — integer scaling when it
fits — to the real display.
- Everything renders on a native handheld logical canvas (640x480,
720x480 or 720x720 when detected) which is scaled — integer scaling
when it fits, or an exact aspect-matched scale (e.g. 1.6x on the
TrimUI Brick's 1024x768 panel) when the display is a clean multiple
of the canvas's proportions — to the real display.
- The app has its own exit path (SELECT quits/finishes) and never
relies on RetroArch hotkeys.
- A bundled Unicode font covers Spanish/Japanese glyphs when present;
Expand Down Expand Up @@ -84,6 +86,7 @@
NATIVE_FULLSCREEN_SIZES = {
(640, 480), # RG35XX Plus and similar 4:3 panels
(720, 480), # RG34XX SP widescreen panel
(720, 720), # RGB30 square panel
}

# "Paper & Ink" palette: the whole UI is warm paper printed with ink,
Expand Down Expand Up @@ -156,7 +159,8 @@ def _resolve_logical_size(configured_size, display_size=None, fullscreen=False):

The saved/default logical size remains the portable 640x480 layout.
In fullscreen on known handheld panels, use the physical panel size
as the logical canvas so 720x480 devices do not get pillarboxed.
as the logical canvas so non-4:3 devices (e.g. 720x480, 720x720)
do not get pillarboxed.
"""
if (
fullscreen
Expand All @@ -167,6 +171,33 @@ def _resolve_logical_size(configured_size, display_size=None, fullscreen=False):
return configured_size


def _compute_scaled_canvas_size(display_size, logical_size, integer_scaling):
"""Target size and mode for blitting the logical canvas onto the display.

Integer scaling keeps pixel art crisp, but flooring to a whole
factor can leave a lot of an otherwise well-proportioned panel
unused (e.g. a 640x480 canvas on a 1024x768 4:3 display floors to
1x instead of the exact 1.6x that would fill it). When the
display's aspect ratio exactly matches the logical canvas, scale
up to fill it exactly — there's no cropping or distortion risk,
so the "keep it a whole number" reason for integer scaling doesn't
apply.

Returns ((tw, th), mode) where mode is "integer", "exact-fill" or
"aspect-fit".
"""
dw, dh = display_size
w, h = logical_size
if integer_scaling:
factor = max(min(dw // w, dh // h), 1)
tw, th = w * factor, h * factor
if dw * h == dh * w and (dw > tw or dh > th):
return (dw, dh), "exact-fill"
return (tw, th), "integer"
ratio = min(dw / w, dh / h)
return (int(w * ratio), int(h * ratio)), "aspect-fit"


def resolve_font_path():
"""First existing font candidate, or None for the builtin fallback."""
for path in FONT_CANDIDATES:
Expand Down Expand Up @@ -346,13 +377,15 @@ def _init_display(self):
self._scaled = None # fast path: blit 1:1
log.info("scaling: none (display matches logical size)")
else:
if self.settings.get("integer_scaling", True):
factor = max(min(dw // self.w, dh // self.h), 1)
tw, th = self.w * factor, self.h * factor
log.info("scaling: integer x%d -> %dx%d", factor, tw, th)
integer_scaling = self.settings.get("integer_scaling", True)
(tw, th), mode = _compute_scaled_canvas_size(
(dw, dh), (self.w, self.h), integer_scaling
)
if mode == "integer":
log.info("scaling: integer x%d -> %dx%d", tw // self.w, tw, th)
elif mode == "exact-fill":
log.info("scaling: exact aspect fill -> %dx%d", tw, th)
else:
ratio = min(dw / self.w, dh / self.h)
tw, th = int(self.w * ratio), int(self.h * ratio)
log.info("scaling: aspect-fit -> %dx%d", tw, th)
self._scaled = pygame.Surface((tw, th))
self._scale_offset = ((dw - tw) // 2, (dh - th) // 2)
Expand Down
45 changes: 44 additions & 1 deletion cardbrick-py/tests/test_display_resolution.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Handheld display resolution selection."""

from cardbrick.app import _resolve_logical_size
from cardbrick.app import _compute_scaled_canvas_size, _resolve_logical_size


def test_fullscreen_720x480_uses_native_logical_size():
Expand All @@ -15,6 +15,20 @@ def test_fullscreen_640x480_keeps_native_logical_size():
) == (640, 480)


def test_fullscreen_720x720_uses_native_logical_size():
assert _resolve_logical_size(
(640, 480), display_size=(720, 720), fullscreen=True
) == (720, 720)


def test_fullscreen_1024x768_keeps_640x480_logical_size():
# The TrimUI Brick isn't a "native size" panel — its 640x480 canvas
# is scaled up to fill it instead (see the scaling tests below).
assert _resolve_logical_size(
(640, 480), display_size=(1024, 768), fullscreen=True
) == (640, 480)


def test_windowed_mode_keeps_configured_size():
assert _resolve_logical_size(
(640, 480), display_size=(720, 480), fullscreen=False
Expand All @@ -25,3 +39,32 @@ def test_custom_logical_size_is_n 8BD0 ot_overridden():
assert _resolve_logical_size(
(800, 480), display_size=(720, 480), fullscreen=True
) == (800, 480)


def test_integer_scaling_1024x768_display_fills_exactly():
# 1024x768 is an exact 1.6x of the 640x480 canvas and shares its
# 4:3 aspect ratio, so it should fill the panel rather than floor
# to a 1x integer factor and leave it tiny with huge borders.
assert _compute_scaled_canvas_size(
(1024, 768), (640, 480), integer_scaling=True
) == ((1024, 768), "exact-fill")


def test_integer_scaling_exact_multiple_stays_integer_mode():
assert _compute_scaled_canvas_size(
(1280, 960), (640, 480), integer_scaling=True
) == ((1280, 960), "integer")


def test_integer_scaling_mismatched_aspect_falls_back_to_floor():
# 1920x1080 is 16:9, not a clean multiple of the 4:3 canvas, so it
# should still floor to an integer factor and letterbox.
assert _compute_scaled_canvas_size(
(1920, 1080), (640, 480), integer_scaling=True
) == ((1280, 960), "integer")


def test_non_integer_scaling_uses_aspect_fit():
assert _compute_scaled_canvas_size(
(1024, 768), (640, 480), integer_scaling=False
) == ((1024, 768), "aspect-fit")
Loading
Loading
0