Is it possible to turn off all input events (mouse, keyboard, touch etc)? I don't need it for anything, so the entire canvas might as well not have them?
You can turn off all mouse events with pointer-events:none;.
And touch-action: none; might turn off all touch events.
Sure, that won't however remove the event listeners on the document and canvas elements that paperjs sets up - those are the ones I really wanna get rid of :-)
Sorry for late response.
I guess that there are no supported way to get rid of all events.
I guess you can remove these events, by comment out DomEvent.add in src/view/View.js and src/event/Key.js.
Of course, this is not supported way and I have not tested, but it would work :)
No worries at all :-) Thanks for pointing me to the right spots.
Would be great if a future release could have this option baked in :-)
The API could be:
// with a given PaperScope instance
var paper = new PaperScope();
// we would have a listenEvents setting
// that would be true by default
console.log(paper.settings.listenEvents); // => true
// we could disable it this way
paper.settings.listenEvents = false;
// and set it back this way
paper.settings.listenEvents = true;
Internally, paper.settings.listenEvents set would call DomEvent.addAll() / DomEvent.removeAll().
Inside of DomEvent we would store a list of all listeners and switch them on / off when needed.
@lehni & @sapics what do you think ?
What would happen if I have events installed, and would temporarily do this?
paper.settings.listenEvents = false;
paper.settings.listenEvents = true;
Would the old events still work, or would they all be discharged?
Also, not sure about the naming yet, because it sounds like wrong english (listen to events?). Some other options, with slightly different meaning (and potentially different behaviour, e.g. not installing events VS ignoring them from their callbacks without preventing default, probably the easier way to implement it?)
paper.settings.listenToEvents = true
paper.settings.installEvents = true
paper.settings.disableEvents = true
paper.settings.enableEvents = false
paper.settings.suppressEvents = true
paper.settings.ignoreEvents = true
In my idea, if we did this
paper.settings.listenEvents = false;
paper.settings.listenEvents = true;
Everything would work as if nothing happened.
Event listeners would simply be added / removed from DOM elements on demand.
About the naming, I'm not surprised my proposal "sounds like wrong english", because I'm french 馃槃 !
Another flavor could be:
paper.settings.eventsActive = true
paper.settings.eventsEnabled = true
@sasensi that sounds like a whole lot of overhead to remove / install events. I'd think that you would only ever do something like this:
paper.settings.discardMouseEvents = true (or whatever we end up calling it), then any call to the methods that add events end up doing nothing. The thing is though: We don't want all events discarded, only the mouse and keyboard events. Resize and animation frame events should never get ignored I guess?
We can do something like this:
const config = {
disableMouseListeners: true,
disableKeyboardListeners: true,
disableResizeListeners: false,
disableRAFListeners: false,
}
const paper = new PaperScope(config);
@lehni, ok, we can do that "no way back style" which will be simpler to implement.
We only have to document it well.
So the API would be:
paper.settings.discardMouseEvents = true
paper.settings.discardKeyboardEvents = true
Mouse including touch of course.
And it would only affect future events registration.
@kumarharsh and @supermoos, as the ones who actually asked for this feature, what do you think about the API only allowing discard of mouse and keyboard events ?
I think it should not just discard events, it should not even have event listeners setup if this api should make sense. But maybe that's what you're intending, in that case discard is perhaps not the best name for it.
It would be preferable to be able to also not have a rAF running, but instead be able to tie an external rAF into a paper.js update/render method. It's been a while since I had this issue, so excuse me if if this is already possible.
I agree with @supermoos: what i want is the the event listeners shouldn't even be attached to the dom. It's unnecessary for some use cases.
Has this been implemented yet or what is the current status?
If it was implemented, you would see the change here.