Skip to content

Fix linear flip.left.x / flip.right.x rendering on desktop pygame/SDL#21

Open
foonerd wants to merge 3 commits into
project-owner:masterfrom
foonerd:fix/linear-indicator-flip-x
Open

Fix linear flip.left.x / flip.right.x rendering on desktop pygame/SDL#21
foonerd wants to merge 3 commits into
project-owner:masterfrom
foonerd:fix/linear-indicator-flip-x

Conversation

@foonerd

@foonerd foonerd commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Parse flip.left.x / flip.right.x as real booleans (aligned with left.needle.flip / right.needle.flip), so False is no longer treated as enabled.
  • When flipping a linear indicator, copy the surface first (channels often share one cached image), then convert_alpha() after transform.flip so the flipped indicator remains blit-safe on desktop pygame/SDL backends.
  • Initialize linear mask source rectangles in image-local coordinates so the first draw does not sample outside the indicator image.

Why

Horizontal flip for linear meters is applied in LinearAnimator. On some pygame/SDL desktop configurations the flipped surface fails to blit useful pixels (indicator looks missing or unflipped). Stereo meters also commonly reuse one cached indicator Surface for left and right; flipping without a detached copy is unsafe when both channels need independent content. Separately, reset_mask previously stored screen position in the blit source rect, which can yield an empty first paint.

Benefit

  • flip.left.x / flip.right.x work reliably for linear meters across embedded and desktop pygame/SDL hosts.
  • flip.*.x = False means off (previously the non-empty string "False" was truthy).
  • Stock meters that use flip (relax, steam-punk, fantasy, and custom themes) render as designed.

Impact

Area Impact
Storage / flash wear Negligible. No extra files on disk. At most one extra in-memory surface copy per flipped channel when a linear meter starts (not per frame).
Performance Negligible ongoing cost. Flip runs once in LinearAnimator.__init__ (meter start / theme change). Extra work is Surface.copy + transform.flip + optional convert_alpha per flipped channel. No change to the per-frame run() path.
Footprint (RAM) Small and temporary relative to meter assets: one additional full-size indicator surface per flipped channel for the life of that meter instance (same order as the indicator PNG already loaded). Unflipped meters unchanged.
Config compatibility Additive / corrective. Existing True keeps working. Explicit False now correctly disables flip. Missing key remains off.

Files

  • configfileparser.py - boolean parse helper for flip keys
  • linear.py - detached flip + convert_alpha
  • meter.py - default flip flags; image-local reset_mask

Parse flip flags as booleans, detach cached indicator surfaces before
horizontal flip, and use image-local mask source coordinates.
@foonerd

foonerd commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

@project-owner, @Gjuju - FYI

After image-local reset_mask, previous_rect must start at content_x/y
or the first volume union wipes from (0,0) and can flicker vinyl/cdart.
@project-owner

Copy link
Copy Markdown
Owner

@foonerd, thank you for the changes! Just one comment, let's use the current naming convention and avoid underscore as a function name prefix (e.g. _get_optional_boolean etc). Thanks!

Match PeppyMeter naming: get_optional_boolean, as_bool, flip_x.
@foonerd

foonerd commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

@project-owner Thanks for the review, and for catching the naming.

The leading underscores were only a Python “private helper” habit from my side (_get_optional_boolean, _as_bool, _flip_x), not meant as a PeppyMeter convention. I’ve dropped them to match the existing style: get_optional_boolean, as_bool, flip_x. Behavior is unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants