We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm using the term view in roughly the same manner as Apple's NSView (I've had a bit of unsuccessful experience in iOS/macOS programming). A view is a thing which has a position and size and which can draw itself when instructed to do so, as well as hold a list of child views whose position is relative to the containing view.
I have views drawing themselves in the correct place with no problems, thanks to
translate(). The present challenge is to make sure that each view does not permit its own drawing commands and those of its child views to spill outside the view's rectangle.
The problem is that calls to
clip() do not stack. A view with width/height 100 will fail to clip a child view with width/height 200 because the child view will call
clip(0, 0, 200, 200) to make sure its own drawing commands don't fall outside its bounds.
The following diagram describes desired behavior. The grey areas are where a view's content should be drawn. White areas should not be drawn.
What is particularly notable is that the right-hand grandchild's view is constrained by both its parent and grandparent.
Can someone sketch for me a solution to this? I'm guessing I will need a given view to recurse upwards (or downwards?) through the transform matrix stack, but I don't know how transform matrices work.
Thanks in advance!