PaintContext architecture & enforced clipping refactor#145
Closed
sastraxi wants to merge 11 commits into
Closed
Conversation
sastraxi
commented
May 19, 2026
|
|
||
| def toggle(self, is_bypassed): | ||
| self.is_bypassed = is_bypassed | ||
| self._draw_halo() |
Contributor
Author
There was a problem hiding this comment.
If you look at pistomp/lcd320x240.py, the update_footswitch method already handles this correctly:
def update_footswitch(self, footswitch):
for wfs in self.w_footswitches:
if wfs.object == footswitch:
wfs.toggle(footswitch.enabled == False) # 1. Update state
# ... update label ...
break
self.footswitch_panel.refresh() # 2. Trigger redrawBecause the caller immediately triggers footswitch_panel.refresh(), the framework will:
- Walk down the tree.
- Call _do_draw on each footswitch.
- Pass in a fresh, valid PaintContext.
- The footswitch will see its new self.is_bypassed state and draw the correct halo color.
Contributor
Author
|
I'm going a different route with this one. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The current drawing API conflates where the widget is and what part of it is dirty, providing only one parameter: real_box. For full refreshes, these rectangles are identical and there's no information loss. But for partial updates, it makes it impossible to properly perform coordinate changes.
The bug
The current code uses real_box (the dirty clip) as the drawing origin for children. So during a partial refresh, text is drawn a few pixels from where it should be. The final paste only covered the clip region, leaving fringe pixels from the wrong-position drawn outside it. Those leaked pixels then sat under the correctly-positioned text on the next full refresh, effectively overdrawing text in some cases and reproducing whole parts of the image where they shouldn't be.
New paint architecture
_do_draw now takes:
All drawing is now wrapped in a context manager
PaintContext.painting(frame), which enforces clip boundaries. If possible, it draws directly on the backing image. When the frame is not fully contained in the clip, it falls back to a "slow path": a temporary buffer is allocated from a buffer pool which is blanked out withRGBA(0, 0, 0, 0)then only the clip region is composited over the target.This buffer pool returns the "best fitting" buffer for the visible = clip ∩ frame region.
New in this PR
Author checklist