I’m not so sure that will help me with my use-case. I’m trying to develop a Component that has a transparent frame and an interior rectangle that draws with setOpaque(true). We talked about this in the other thread. After much consideration, and taking your input into account, I have decided that this is the best way to do it:
- The main control Component will have setOpaque(false) and do its drawing in paint().
- This control Component can be a juce::Button, any other Juce Component object, or a custom object
- A helper Component will be created with setOpaque(true), that has a bounds inset from the main control
- This helper Component will not draw at all, it only exists to clip out everything underneath it from drawing
- The helper will sit underneath the main control in the z-order, follow the main control around.
- The helper is not a child of the main Component, or a parent, but is instead a sibling.
Rather than have a “frame” or “shadow” object that moves around, my needs are served best by having a simple opaque clipping Component sit underneath the main object. It is less obtrusive, easier to generalize, and it lets me do all the drawing in a single function. This is important to me because of the way I have “connected edges” in the controls. Plus, like you said before the object that receives the user input also performs the drawing.
In order for the helper Component to properly follow around the main Component I need to know when the main Component is attached or detached from its parent, when the main Component is moved or resized, and when the main Component changes its position in the z-order. ComponentListener supports all of that except the z-order.
The problem with having ComponentListener receive componentChildrenChanged() when a child moves in the z-order, is that I’m not listening to the parent of the helper, I’m listening to the helper. The helper has no children. I suppose a work around is to addComponentListener to both the main control Component and also the helper’s parent but this seems bulky.