[SOLUTION]
This fix was commissioned by fidless. He deserves credit for bringing it to my attention. Thanks to
Quxios too. This came to me as a request to fix the mouse issue when using QTouch. It's actually a problem with older versions of nwjs not respecting cursors. I've put together a few example bits of code and an explanation for the QTouch version at the bottom.
es6 version (MV 1.6 and above only!). This example is put on window object. Best practice would be to contain it somewhere, this is just an example.
Code:
window.onMouseLeave = () => {
document.body.style.cursor = 'none';
};
window.onMouseEnter = () => {
document.body.style.cursor = 'url("img/system/mycursor.png"), default';
};
document.addEventListener('mouseleave', onMouseLeave);
document.addEventListener('mouseenter', onMouseEnter);
es5 version (should work with all versions of MV). This example is uniform to MV's code base.
Code:
TouchInput.onMouseLeave = function() {
document.body.style.cursor = 'none';
};
TouchInput.onMouseEnter = function() {
document.body.style.cursor = 'url("img/system/cursor.png"), default';
};
var someAlias = TouchInput._setupEventHandlers;
TouchInput._setupEventHandlers = function() {
someAlias.call(this);
document.addEventListener('mouseleave', this.onMouseLeave.bind(this));
document.addEventListener('mouseenter', this.onMouseEnter.bind(this));
};
QTouch version (required for QTouch). This example is uniform to QTouch's code
Code:
TouchInput.onMouseEnter = function() {
setTimeout(function() {
this.hideCursor();
}.bind(this), 0);
};
var someAlias = TouchInput._setupEventHandlers;
TouchInput._setupEventHandlers = function() {
someAlias.call(this);
document.addEventListener('mouseenter', this.onMouseEnter.bind(this));
};
About this QTouch version.
QTouch cursor is checked every frame and set to the correct icon usually. It won't update the cursor if it's the same as the last frame though. That seems ok and my brain tells me the previous examples should work but they don't. I'm honestly not sure why and would love to know if someone finds a way to improve my code. I think it's an issue involving:
- update cursor only if last frame was different
- QTouch cursor update linked to SceneManager.update
- event.eventListener not linked to SceneManager.update
About this QTouch version BUG.
The mouse icon will still be stuck on 'resize' if you cross the window border very slowly. It may be possible to completely eliminate the bug but I'm not interested in tearing apart QTouch to figure it out at the moment. It may take several edits to the code to adjust the timing of cursor update. I'm not sure. I've already spent a lot of time figuring out what NWjs is doing when you enter the window.
I have a solution to mitigate it at a cost however...
Code:
TouchInput.onMouseEnter = function() {
setTimeout(function() {
this.hideCursor();
setTimeout(function() {
this.hideCursor();
setTimeout(function() {
this.hideCursor();
setTimeout(function() {
this.hideCursor();
setTimeout(function() {
this.hideCursor();
}.bind(this), 250);
}.bind(this), 250);
}.bind(this), 250);
}.bind(this), 250);
}.bind(this), 0);
};
setTimeout can be nested. This example will allow the mouse approximately one second to cross the border. It runs hideCursor() every quarter of a second to check if it's passed yet. The hack will still fail if it hasn't passed in the allotted one second. The cost is that all remaining checks will cause the mouse to flicker if it is moving. I personally think it's better to avoid this particular hack. I think the flicker is more likely to annoy the player than it is for the mouse to enter slow enough to need it. It's quite simply fixed by reentering the window or hovering over a pointer element.
Have fun with your unbroken custom mouse in nwjs v0.29.0
🙂
feel free to hit me up in a private msg