Refactor properties into methods for viewport
This commit is contained in:
@@ -58,7 +58,7 @@ var DragHandle = function (handler) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.init = function () {
|
this.init = function () {
|
||||||
var viewportData = this.getCanvas().getViewport().data;
|
var viewportData = this.getCanvas().getViewport().getCropData();
|
||||||
var tracks = handler.getTracks();
|
var tracks = handler.getTracks();
|
||||||
|
|
||||||
if (this.__handles) {
|
if (this.__handles) {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ function GoreHandler(viewport) {
|
|||||||
* @return {fabric.Line}
|
* @return {fabric.Line}
|
||||||
*/
|
*/
|
||||||
function getLine(left) {
|
function getLine(left) {
|
||||||
return new fabric.Line([0, 0, 0, viewport.data.height], {
|
return new fabric.Line([0, 0, 0, viewport.getCropData().height], {
|
||||||
evented: false,
|
evented: false,
|
||||||
strokeDashArray: [5, 5],
|
strokeDashArray: [5, 5],
|
||||||
stroke: '#000',
|
stroke: '#000',
|
||||||
@@ -43,7 +43,7 @@ function GoreHandler(viewport) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var bounds = viewport.getBounds();
|
var bounds = viewport.getBounds();
|
||||||
var step = viewport.data.ppmm * 450;
|
var step = viewport.getCropData().ppmm * 450;
|
||||||
var count = Math.ceil(bounds.width / step);
|
var count = Math.ceil(bounds.width / step);
|
||||||
|
|
||||||
for (var i = 1; i < count; i++) {
|
for (var i = 1; i < count; i++) {
|
||||||
|
|||||||
@@ -15,10 +15,10 @@ function ImageEditor(args) {
|
|||||||
|
|
||||||
_canvas.getButtonMenu()
|
_canvas.getButtonMenu()
|
||||||
.addItem(['Show Murals Panel', 'Hide Murals Panel'], function () {
|
.addItem(['Show Murals Panel', 'Hide Murals Panel'], function () {
|
||||||
_canvas.getViewport().gores.enable(this.isActive());
|
_canvas.getViewport().getGores().enable(this.isActive());
|
||||||
})
|
})
|
||||||
.addItem(['Show Ruler', 'Hide Ruler'], function () {
|
.addItem(['Show Ruler', 'Hide Ruler'], function () {
|
||||||
_canvas.getViewport().rulers.enable(this.isActive());
|
_canvas.getViewport().getRulers().enable(this.isActive());
|
||||||
})
|
})
|
||||||
.addItem(['Fullscreen', 'Exit Fullscreen'], function () {
|
.addItem(['Fullscreen', 'Exit Fullscreen'], function () {
|
||||||
util.toggleFullscreen(_canvas.getSelectionElement().parentNode);
|
util.toggleFullscreen(_canvas.getSelectionElement().parentNode);
|
||||||
|
|||||||
@@ -16,10 +16,10 @@ function RulerHandler(viewport) {
|
|||||||
var bounds = viewport.getBounds();
|
var bounds = viewport.getBounds();
|
||||||
var pos = util.assertBetween(this[axis], bounds.min[axis], bounds.max[axis]);
|
var pos = util.assertBetween(this[axis], bounds.min[axis], bounds.max[axis]);
|
||||||
this.marker[axis] = this[axis] = pos;
|
this.marker[axis] = this[axis] = pos;
|
||||||
var dim = (this[axis] - bounds[axis]) / (viewport.data.ppmm * 10);
|
var dim = (this[axis] - bounds[axis]) / (viewport.getCropData().ppmm * 10);
|
||||||
|
|
||||||
if (axis === 'top') {
|
if (axis === 'top') {
|
||||||
dim = viewport.data.dim.height - dim;
|
dim = viewport.getCropData().dim.height - dim;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setText(Math.round(dim * 100) / 100 + ' cm');
|
this.setText(Math.round(dim * 100) / 100 + ' cm');
|
||||||
|
|||||||
@@ -117,32 +117,25 @@ function Viewport(canvas) {
|
|||||||
this.set = function (width, height) {
|
this.set = function (width, height) {
|
||||||
_data = util.calcCrop(canvas.getImage(), width, height);
|
_data = util.calcCrop(canvas.getImage(), width, height);
|
||||||
apply();
|
apply();
|
||||||
this.gores.reset();
|
this.getGores().reset();
|
||||||
this.rulers.reset();
|
this.getRulers().reset();
|
||||||
canvas.getApertures().setTransparent(true);
|
canvas.getApertures().setTransparent(true);
|
||||||
canvas.getImage().__moved = false;
|
canvas.getImage().__moved = false;
|
||||||
canvas.getButtonMenu().bringToFront();
|
canvas.getButtonMenu().bringToFront();
|
||||||
};
|
};
|
||||||
|
|
||||||
util.setProperties(this, {
|
this.getCropData = function () {
|
||||||
data: {
|
|
||||||
get: function () {
|
|
||||||
return _data;
|
return _data;
|
||||||
}
|
};
|
||||||
},
|
|
||||||
gores: {
|
this.getGores = function () {
|
||||||
get: function () {
|
return this.__goreHandler || (this.__goreHandler = new GoreHandler(this));
|
||||||
return this.__goreHandler ||
|
};
|
||||||
(this.__goreHandler = new GoreHandler(this));
|
|
||||||
}
|
this.getRulers = function () {
|
||||||
},
|
return this.__rulerHandler || (this.__rulerHandler = new RulerHandler(this));
|
||||||
rulers: {
|
};
|
||||||
get: function () {
|
|
||||||
return this.__rulerHandler ||
|
|
||||||
(this.__rulerHandler = new RulerHandler(this));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Viewport;
|
module.exports = Viewport;
|
||||||
|
|||||||
+4
-2
@@ -16,7 +16,8 @@ $(function () {
|
|||||||
w: $('#form-control input[name="w"]'),
|
w: $('#form-control input[name="w"]'),
|
||||||
h: $('#form-control input[name="h"]'),
|
h: $('#form-control input[name="h"]'),
|
||||||
image_id: $('#form-control input[name="image_id"]'),
|
image_id: $('#form-control input[name="image_id"]'),
|
||||||
mirror: $('#form-control input[name="mirror"]')
|
mirror: $('#form-control input[name="mirror"]'),
|
||||||
|
noCrop: $('#form-control input[name="no-crop"]')
|
||||||
};
|
};
|
||||||
|
|
||||||
var imageUrl = '//images.photowall.com/products/' + $input.image_id.val() + '.jpg?h=450';
|
var imageUrl = '//images.photowall.com/products/' + $input.image_id.val() + '.jpg?h=450';
|
||||||
@@ -34,6 +35,7 @@ $(function () {
|
|||||||
editor.canvas.getImage().transformation.set('mirror', this.checked);
|
editor.canvas.getImage().transformation.set('mirror', this.checked);
|
||||||
},
|
},
|
||||||
NoCrop: function() {
|
NoCrop: function() {
|
||||||
|
// editor.canvas
|
||||||
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -41,5 +43,5 @@ $(function () {
|
|||||||
$input.w.keyup(Event.DimensionChange);
|
$input.w.keyup(Event.DimensionChange);
|
||||||
$input.h.keyup(Event.DimensionChange);
|
$input.h.keyup(Event.DimensionChange);
|
||||||
$input.mirror.change(Event.Mirror);
|
$input.mirror.change(Event.Mirror);
|
||||||
$input.mirror.change(Event.NoCrop);
|
$input.noCrop.change(Event.NoCrop);
|
||||||
}());
|
}());
|
||||||
|
|||||||
Reference in New Issue
Block a user