|
@@ -26,6 +26,12 @@ class Window {
|
|
|
var curH : Int;
|
|
|
|
|
|
var focused : Bool;
|
|
|
+
|
|
|
+ /**
|
|
|
+ When enabled, the browser zoom does not affect the canvas.
|
|
|
+ (default : true)
|
|
|
+ **/
|
|
|
+ public var useScreenPixels : Bool = true;
|
|
|
|
|
|
public function new( ?canvas : js.html.CanvasElement, ?globalEvents ) : Void {
|
|
|
var customCanvas = canvas != null;
|
|
@@ -158,20 +164,24 @@ class Window {
|
|
|
return inst;
|
|
|
}
|
|
|
|
|
|
+ function getPixelRatio() {
|
|
|
+ return useScreenPixels ? js.Browser.window.devicePixelRatio : 1;
|
|
|
+ }
|
|
|
+
|
|
|
function get_width() {
|
|
|
- return Math.round(canvasPos.width * js.Browser.window.devicePixelRatio);
|
|
|
+ return Math.round(canvasPos.width * getPixelRatio());
|
|
|
}
|
|
|
|
|
|
function get_height() {
|
|
|
- return Math.round(canvasPos.height * js.Browser.window.devicePixelRatio);
|
|
|
+ return Math.round(canvasPos.height * getPixelRatio());
|
|
|
}
|
|
|
|
|
|
function get_mouseX() {
|
|
|
- return Math.round((curMouseX - canvasPos.left) * js.Browser.window.devicePixelRatio);
|
|
|
+ return Math.round((curMouseX - canvasPos.left) * getPixelRatio());
|
|
|
}
|
|
|
|
|
|
function get_mouseY() {
|
|
|
- return Math.round((curMouseY - canvasPos.top) * js.Browser.window.devicePixelRatio);
|
|
|
+ return Math.round((curMouseY - canvasPos.top) * getPixelRatio());
|
|
|
}
|
|
|
|
|
|
function get_mouseLock() : Bool {
|
|
@@ -231,8 +241,8 @@ class Window {
|
|
|
e.preventDefault();
|
|
|
var x, y, ev;
|
|
|
for (touch in e.changedTouches) {
|
|
|
- x = Math.round((touch.clientX - canvasPos.left) * js.Browser.window.devicePixelRatio);
|
|
|
- y = Math.round((touch.clientY - canvasPos.top) * js.Browser.window.devicePixelRatio);
|
|
|
+ x = Math.round((touch.clientX - canvasPos.left) * getPixelRatio());
|
|
|
+ y = Math.round((touch.clientY - canvasPos.top) * getPixelRatio());
|
|
|
ev = new Event(EPush, x, y);
|
|
|
ev.touchId = touch.identifier;
|
|
|
event(ev);
|
|
@@ -243,8 +253,8 @@ class Window {
|
|
|
e.preventDefault();
|
|
|
var x, y, ev;
|
|
|
for (touch in e.changedTouches) {
|
|
|
- x = Math.round((touch.clientX - canvasPos.left) * js.Browser.window.devicePixelRatio);
|
|
|
- y = Math.round((touch.clientY - canvasPos.top) * js.Browser.window.devicePixelRatio);
|
|
|
+ x = Math.round((touch.clientX - canvasPos.left) * getPixelRatio());
|
|
|
+ y = Math.round((touch.clientY - canvasPos.top) * getPixelRatio());
|
|
|
ev = new Event(EMove, x, y);
|
|
|
ev.touchId = touch.identifier;
|
|
|
event(ev);
|
|
@@ -255,8 +265,8 @@ class Window {
|
|
|
e.preventDefault();
|
|
|
var x, y, ev;
|
|
|
for (touch in e.changedTouches) {
|
|
|
- x = Math.round((touch.clientX - canvasPos.left) * js.Browser.window.devicePixelRatio);
|
|
|
- y = Math.round((touch.clientY - canvasPos.top) * js.Browser.window.devicePixelRatio);
|
|
|
+ x = Math.round((touch.clientX - canvasPos.left) * getPixelRatio());
|
|
|
+ y = Math.round((touch.clientY - canvasPos.top) * getPixelRatio());
|
|
|
ev = new Event(ERelease, x, y);
|
|
|
ev.touchId = touch.identifier;
|
|
|
event(ev);
|