Event propagation in a Morphic GUI
I have an image for a Squeak Morphic GUI that contains some transparent parts and thus should not accept any mouseevents etc. but just be visible, but it needs to be visible in front of other morphs.
That's why i thought it would be useful to propagate the appearing mouseevents to the underlying morphs. Does anyone know a solution for my problem or another suggestion to solve it. 开发者_开发知识库
V <- mouseDownEvent
_____________________________ <- transparent image (BorderedMorph)
_____ _____ _____
_| |___| |___| |__ <- buttons waiting for click and drop events
_____________________________ <- basic morph
i hope that illustrates my problem.
The best thing I can think of is something along the following lines (in increasing order of smoothness, and decreasing order of likelihood to work)
- Record the event, tab the transparent image away, and replay the event. This seems like an inefficient and poor way of doing it.
- Somehow keep track of what has focus behind your transparent image, and pass the event to it. I'm not familiar with the libraries in question, so I don't know if it's possible to do it like that. If you have control over the other layers, this is most likely the way to go. (You can directly call their 'a mouse event happened' functions with that mouseDownEvent, though you do still have to identify which one would receive it).
- Simply declare it as something that doesn't get mouse events passed to it at whatever level is available. OSD windows tend to do this, I'm not sure how. If you can do it this way, I would advise it... but given that you're asking this question, you probably can't.
By default, Morphic mouse events are handled in the top-most morph. However, a parent morph is able to intercept #mouseDown
to children using #mouseDownPriority
.
Your transparent image gets all clicks because it is top-most. Take a look at #rejectsEvent:
. It justs combines #isLocked
and #visible
to reject events. You may want to override this in order to reject events even if visible.
For example:
MyMorph>>rejectsEvent: anEvent
^ true "Ignores all events."
精彩评论