ソースを参照

Input updated to allow a specific element to watch for mouse events in a more direct way than previously. CTRLPainter updated for the change to Input.

dev
Bryan Miller 6年前
コミット
2e9302f101
2個のファイルの変更32行の追加26行の削除
  1. +2
    -2
      app/js/ctrls/CTRLPainter.js
  2. +30
    -24
      app/js/ui/Input.js

+ 2
- 2
app/js/ctrls/CTRLPainter.js ファイルの表示

// Setting-up Input controls. // Setting-up Input controls.
var input = new Input(); var input = new Input();
input.enableKeyboardInput(true); input.enableKeyboardInput(true);
input.enableMouseInput(true);
input.preventDefaults = true; input.preventDefaults = true;




throw new Error("Failed to obtain canvas context."); throw new Error("Failed to obtain canvas context.");
context.imageSmoothingEnabled = false; context.imageSmoothingEnabled = false;
ResizeCanvasImg(canvas.clientWidth, canvas.clientHeight); // A forced "resize". ResizeCanvasImg(canvas.clientWidth, canvas.clientHeight); // A forced "resize".
input.mouseTargetElement = canvas;
input.enableMouseInput(true, canvas);
//input.mouseTargetElement = canvas;


this.scale_to_fit(); this.scale_to_fit();
this.center_surface(); this.center_surface();

+ 30
- 24
app/js/ui/Input.js ファイルの表示

return false; return false;
}).bind(this); }).bind(this);


return (function(enable){
return (function(enable, target){
enable = (enable !== false); enable = (enable !== false);
target = (Utils.isElement(target)) ? target : window;
if (enable === true && this.__mouseEnabled === true && this.__mouseTarget !== target){
this.enableMouseInput(false);
}
// NOTE: There shouldn't be any harm if the user repeatedly enables or disables mouse. // NOTE: There shouldn't be any harm if the user repeatedly enables or disables mouse.
if (enable){ if (enable){
this.__mouseEnabled = true; this.__mouseEnabled = true;
window.addEventListener("mousemove", handle_mousemove);
window.addEventListener("mousedown", handle_mousedown);
window.addEventListener("mouseup", handle_mouseup);
window.addEventListener("mousewheel", handle_mousewheel); // For older browsers?
window.addEventListener("wheel", handle_mousewheel);
window.addEventListener("click", handle_mouseprevdef);
window.addEventListener("dblclick", handle_mouseprevdef);
window.addEventListener("contextmenu", handle_mouseprevdef);
this.__mouseTarget = target;
this.__mouseTarget.addEventListener("mousemove", handle_mousemove);
this.__mouseTarget.addEventListener("mousedown", handle_mousedown);
this.__mouseTarget.addEventListener("mouseup", handle_mouseup);
this.__mouseTarget.addEventListener("mousewheel", handle_mousewheel); // For older browsers?
this.__mouseTarget.addEventListener("wheel", handle_mousewheel);
this.__mouseTarget.addEventListener("click", handle_mouseprevdef);
this.__mouseTarget.addEventListener("dblclick", handle_mouseprevdef);
this.__mouseTarget.addEventListener("contextmenu", handle_mouseprevdef);
} else { } else {
this.__mouseEnabled = false; this.__mouseEnabled = false;
window.removeEventListener("mousemove", handle_mousemove);
window.removeEventListener("mousedown", handle_mousedown);
window.removeEventListener("mouseup", handle_mouseup);
window.removeEventListener("mousewheel", handle_mousewheel); // For older browsers?
window.removeEventListener("wheel", handle_mousewheel);
window.removeEventListener("click", handle_mouseprevdef);
window.removeEventListener("dblclick", handle_mouseprevdef);
window.removeEventListener("contextmenu", handle_mouseprevdef);
this.__mouseTarget.removeEventListener("mousemove", handle_mousemove);
this.__mouseTarget.removeEventListener("mousedown", handle_mousedown);
this.__mouseTarget.removeEventListener("mouseup", handle_mouseup);
this.__mouseTarget.removeEventListener("mousewheel", handle_mousewheel); // For older browsers?
this.__mouseTarget.removeEventListener("wheel", handle_mousewheel);
this.__mouseTarget.removeEventListener("click", handle_mouseprevdef);
this.__mouseTarget.removeEventListener("dblclick", handle_mouseprevdef);
this.__mouseTarget.removeEventListener("contextmenu", handle_mouseprevdef);
this.__mouseTarget = null;
} }
}).bind(this); }).bind(this);
}).apply(this); }).apply(this);
set ieMouseMode(m){this.__ieMouseMode = (m === true);} set ieMouseMode(m){this.__ieMouseMode = (m === true);}


get mouseTargetElement(){return this.__mouseTarget;} get mouseTargetElement(){return this.__mouseTarget;}
set mouseTargetElement(el){
if (el === null || Utils.isElement(el)){
this.__mouseTarget = el;
} else {
throw new TypeError("Expected Mouse Target Element to be null or an HTMLElement object.");
}
}
//set mouseTargetElement(el){
// if (el === null || Utils.isElement(el)){
// this.__mouseTarget = el;
// } else {
// throw new TypeError("Expected Mouse Target Element to be null or an HTMLElement object.");
// }
//}


isKeyDown(key){ isKeyDown(key){
if (typeof(key) === 'string'){ if (typeof(key) === 'string'){

読み込み中…
キャンセル
保存