In light of the recent event bubbling discussions, here an email to the whole list, as I'm curious to hear your thoughts.
The mouse events are a bit in state of mess right now. To explain why things behave the way they do:
Early on we have introduced the Tool objects that are provided to simplify the creation of drawing tools, since that's an area of focus for the library. In order to simplify their creation and teaching, we decided to support global event handlers in PaperScript that will automatically get associated with a tool object that's created behind the scenes for you.
After implementing hit-testing, I realized that it is rather easy to use that to offer some basic level support for item based events. Many people are reaching the limits of that right now because the events don't bubble up.
The limits you are reaching are different: The fact that item level events cannot stop the execution of tool events. I actually think this is a feature, not a bug, since the two are on different levels altogether.
But here the solution for hopefully all these problems that I am currently looking into providing:
- I will add support for bubbling directly to the hit-testing code, through a callback method. This way I can support event bubbling on paper.js items.
- The View object will get support for mouse handlers as well. These will get executed if no item is hit, or if the hit item does not prevent propagation.
- Regardless of what will happen with propagation here, Tool events will always receive their callbacks, separately from the event bubbling infrastructure.
I think this is a pretty solid plan, with only one downside:
Since the global onResize / onFrame handlers in PaperScript are actually links to view.onResize / view.onFrame, I think it's weird that the global mouse handlers will not also be links to view.onMouseDown etc, but link to tool.onMouseDown instead (and the tool object is created on the fly)...
I'm considering changing this, and switching to tool objects for the more complex drawing tools. As soon as you use minDistance / maxDistance, you're handling the tool object anyhow. This change will obviously break backward compatibility of more complex drawing scripts, but I think it's important to keep the API consistent if we still can. That's also a reason why we haven't hit v1.0 yet, I'm still contemplating some API changes.
Thoughts?
J