From 866354ef6207fbe21054b1950e8158160f85420a Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Fri, 12 Apr 2019 23:38:42 +0100 Subject: [PATCH] Javascript frontend: make Shift- and Ctrl-click work. In other front ends, Shift-click is an alternative to the middle button, and Ctrl-click the right button. Apparently I completely forgot to implement this in the JS front end. Better late than never. --- emccpre.js | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/emccpre.js b/emccpre.js index 5082555..56f6972 100644 --- a/emccpre.js +++ b/emccpre.js @@ -212,28 +212,51 @@ function initPuzzle() { // button down (our puzzles don't want those events). mousedown = Module.cwrap('mousedown', 'void', ['number', 'number', 'number']); - buttons_down = 0; + + button_phys2log = [null, null, null]; + buttons_down = function() { + var i, toret = 0; + for (i = 0; i < 3; i++) + if (button_phys2log[i] !== null) + toret |= 1 << button_phys2log[i]; + return toret; + }; + onscreen_canvas.onmousedown = function(event) { + if (event.button >= 3) + return; + var xy = relative_mouse_coords(event, onscreen_canvas); - mousedown(xy.x, xy.y, event.button); - buttons_down |= 1 << event.button; + var logbutton = event.button; + if (event.shiftKey) + logbutton = 1; // Shift-click overrides to middle button + else if (event.ctrlKey) + logbutton = 2; // Ctrl-click overrides to right button + + mousedown(xy.x, xy.y, logbutton); + button_phys2log[event.button] = logbutton; + onscreen_canvas.setCapture(true); }; mousemove = Module.cwrap('mousemove', 'void', ['number', 'number', 'number']); onscreen_canvas.onmousemove = function(event) { - if (buttons_down) { + var down = buttons_down(); + if (down) { var xy = relative_mouse_coords(event, onscreen_canvas); - mousemove(xy.x, xy.y, buttons_down); + mousemove(xy.x, xy.y, down); } }; mouseup = Module.cwrap('mouseup', 'void', ['number', 'number', 'number']); onscreen_canvas.onmouseup = function(event) { - if (buttons_down & (1 << event.button)) { - buttons_down ^= 1 << event.button; + if (event.button >= 3) + return; + + if (button_phys2log[event.button] !== null) { var xy = relative_mouse_coords(event, onscreen_canvas); - mouseup(xy.x, xy.y, event.button); + mouseup(xy.x, xy.y, button_phys2log[event.button]); + button_phys2log[event.button] = null; } };