Properly encapsulate the scale in Display
Other parts of the code shouldn't have to care about this. Let Display convert between canvas coordinates and framebuffer coordinates.
This commit is contained in:
parent
8cbf1dd9d2
commit
280676c7e9
|
@ -1227,7 +1227,6 @@ var UI;
|
|||
var display = UI.rfb.get_display();
|
||||
var resizeMode = UI.getSetting('resize');
|
||||
display.set_scale(1);
|
||||
UI.rfb.get_mouse().set_scale(1);
|
||||
|
||||
if (resizeMode === 'remote') {
|
||||
|
||||
|
@ -1247,12 +1246,7 @@ var UI;
|
|||
|
||||
} else if (resizeMode === 'scale' || resizeMode === 'downscale') {
|
||||
var downscaleOnly = resizeMode === 'downscale';
|
||||
var scaleRatio = display.autoscale(screen.w, screen.h, downscaleOnly);
|
||||
|
||||
if (!UI.rfb.get_view_only()) {
|
||||
UI.rfb.get_mouse().set_scale(scaleRatio);
|
||||
Util.Debug('Scaling by ' + UI.rfb.get_mouse().get_scale());
|
||||
}
|
||||
display.autoscale(screen.w, screen.h, downscaleOnly);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -193,11 +193,11 @@
|
|||
},
|
||||
|
||||
absX: function (x) {
|
||||
return x + this._viewportLoc.x;
|
||||
return x / this._scale + this._viewportLoc.x;
|
||||
},
|
||||
|
||||
absY: function (y) {
|
||||
return y + this._viewportLoc.y;
|
||||
return y / this._scale + this._viewportLoc.y;
|
||||
},
|
||||
|
||||
resize: function (width, height) {
|
||||
|
@ -589,8 +589,6 @@
|
|||
}
|
||||
|
||||
this._rescale(scaleRatio);
|
||||
|
||||
return scaleRatio; // so that the mouse, etc scale can be set
|
||||
},
|
||||
|
||||
// Private Methods
|
||||
|
|
|
@ -161,7 +161,6 @@
|
|||
Util.set_defaults(this, defaults, {
|
||||
'target': document,
|
||||
'focused': true,
|
||||
'scale': 1.0,
|
||||
'touchButton': 1
|
||||
});
|
||||
|
||||
|
@ -343,8 +342,6 @@
|
|||
} else {
|
||||
y = e.clientY - bounds.top;
|
||||
}
|
||||
x = x / this._scale;
|
||||
y = y / this._scale;
|
||||
return {x:x, y:y};
|
||||
},
|
||||
|
||||
|
@ -398,7 +395,6 @@
|
|||
['target', 'ro', 'dom'], // DOM element that captures mouse input
|
||||
['notify', 'ro', 'func'], // Function to call to notify whenever a mouse event is received
|
||||
['focused', 'rw', 'bool'], // Capture and send mouse clicks/movement
|
||||
['scale', 'rw', 'float'], // Viewport scale factor 0.0 - 1.0
|
||||
|
||||
['onMouseButton', 'rw', 'func'], // Handler for mouse button click/release
|
||||
['onMouseMove', 'rw', 'func'], // Handler for mouse movement
|
||||
|
|
|
@ -274,13 +274,17 @@ describe('Display/Canvas Helper', function () {
|
|||
});
|
||||
|
||||
it('should use width to determine scale when the current aspect ratio is wider than the target', function () {
|
||||
expect(display.autoscale(9, 16)).to.equal(9 / 4);
|
||||
display.autoscale(9, 16);
|
||||
expect(display.absX(9)).to.equal(4);
|
||||
expect(display.absY(18)).to.equal(8);
|
||||
expect(canvas.clientWidth).to.equal(9);
|
||||
expect(canvas.clientHeight).to.equal(7); // round 9 / (4 / 3)
|
||||
});
|
||||
|
||||
it('should use height to determine scale when the current aspect ratio is taller than the target', function () {
|
||||
expect(display.autoscale(16, 9)).to.equal(3); // 9 / 3
|
||||
display.autoscale(16, 9);
|
||||
expect(display.absX(9)).to.equal(3);
|
||||
expect(display.absY(18)).to.equal(6);
|
||||
expect(canvas.clientWidth).to.equal(12); // 16 * (4 / 3)
|
||||
expect(canvas.clientHeight).to.equal(9);
|
||||
|
||||
|
@ -293,11 +297,15 @@ describe('Display/Canvas Helper', function () {
|
|||
});
|
||||
|
||||
it('should not upscale when downscaleOnly is true', function () {
|
||||
expect(display.autoscale(2, 2, true)).to.equal(0.5);
|
||||
display.autoscale(2, 2, true);
|
||||
expect(display.absX(9)).to.equal(18);
|
||||
expect(display.absY(18)).to.equal(36);
|
||||
expect(canvas.clientWidth).to.equal(2);
|
||||
expect(canvas.clientHeight).to.equal(2);
|
||||
|
||||
expect(display.autoscale(16, 9, true)).to.equal(1.0);
|
||||
display.autoscale(16, 9, true);
|
||||
expect(display.absX(9)).to.equal(9);
|
||||
expect(display.absY(18)).to.equal(18);
|
||||
expect(canvas.clientWidth).to.equal(4);
|
||||
expect(canvas.clientHeight).to.equal(3);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue