Skip to content

Fix item hitbox ignoring transparency - #25

Merged
emosaru merged 2 commits into
avaloniafrom
fix/issue-8-hitbox-transparency
Apr 11, 2026
Merged

Fix item hitbox ignoring transparency#25
emosaru merged 2 commits into
avaloniafrom
fix/issue-8-hitbox-transparency

Conversation

@emosaru

@emosaru emosaru commented Apr 11, 2026

Copy link
Copy Markdown
Contributor

Summary

InputMaskingImage was using pointer-event filtering (OnPointerPressed etc.) to suppress clicks on transparent pixels, but this approach doesn't work for items stacked in z-order. Avalonia's hit-test walk picks the front-most element that passes HitTestCore (which defaulted to the full bounding box), routes the event there, and stops — so the transparent area of one item would consume clicks intended for the item below it.

Fix: Replace the event-filter approach with a proper HitTestCore override. When HitTestCore returns false, Avalonia continues its hit-test walk to the next element in z-order, so transparent pixels cleanly pass through to whatever is beneath them.

Test plan

  • Open CodeTracker Items/Key Tracker variant
  • Click on the Prize Shuffle icon's transparent corners — verify clicks pass through to items underneath
  • Verify opaque parts of items still respond to clicks normally

Closes #8

🤖 Generated with Claude Code

Replace the pointer-event filter approach with a proper HitTestCore
override so transparent pixels fail Avalonia's visual hit-test walk.
When HitTestCore returns false, Avalonia continues searching elements
below in z-order, allowing clicks on transparent areas to fall through
to the item underneath.

The previous OnPointerPressed/Moved/Released filtering still consumed
the event even on transparent pixels, preventing sibling elements at
lower z-order from receiving it.

Fixes #8

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@emosaru
emosaru requested a review from a team April 11, 2026 19:14
PointHitTestParameters does not exist in Avalonia — it is a WPF type.
The correct Avalonia 11 API for per-pixel hit testing is implementing the
ICustomHitTest interface (Avalonia.Rendering), whose HitTest(Point) method
is called by the compositor instead of the default bounding-box check.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@emosaru
emosaru merged commit 536dcd9 into avalonia Apr 11, 2026
3 checks passed
@emosaru
emosaru deleted the fix/issue-8-hitbox-transparency branch April 11, 2026 21:10
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.

1 participant