diff options
| author | Simon Tatham <anakin@pobox.com> | 2019-04-12 23:38:42 +0100 |
|---|---|---|
| committer | Simon Tatham <anakin@pobox.com> | 2019-04-12 23:38:42 +0100 |
| commit | 866354ef6207fbe21054b1950e8158160f85420a (patch) | |
| tree | 868dc2e792f57681f8801e14714c2aee7b46cf64 | |
| parent | 7ac48f9fe3ff827460b885b50d1e25f1ed2f7862 (diff) | |
| download | puzzles-866354ef6207fbe21054b1950e8158160f85420a.zip puzzles-866354ef6207fbe21054b1950e8158160f85420a.tar.gz puzzles-866354ef6207fbe21054b1950e8158160f85420a.tar.bz2 puzzles-866354ef6207fbe21054b1950e8158160f85420a.tar.xz | |
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.
| -rw-r--r-- | emccpre.js | 39 |
1 files changed, 31 insertions, 8 deletions
@@ -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; } }; |