WIP no crop functionality

This commit is contained in:
Erik Tiekstra
2017-05-12 11:01:36 +02:00
parent 4544b96093
commit 7d41f6b2e2
6 changed files with 24 additions and 13 deletions
+1 -1
View File
@@ -58,7 +58,7 @@ var DragHandle = function (handler) {
}; };
this.init = function () { this.init = function () {
var viewportData = this.getCanvas().getViewport().getCropData(); var viewportData = this.getCanvas().getViewport().getData();
var tracks = handler.getTracks(); var tracks = handler.getTracks();
if (this.__handles) { if (this.__handles) {
+2 -2
View File
@@ -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.getCropData().height], { return new fabric.Line([0, 0, 0, viewport.getData().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.getCropData().ppmm * 450; var step = viewport.getData().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++) {
@@ -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.getCropData().ppmm * 10); var dim = (this[axis] - bounds[axis]) / (viewport.getData().ppmm * 10);
if (axis === 'top') { if (axis === 'top') {
dim = viewport.getCropData().dim.height - dim; dim = viewport.getData().dim.height - dim;
} }
this.setText(Math.round(dim * 100) / 100 + ' cm'); this.setText(Math.round(dim * 100) / 100 + ' cm');
+1 -1
View File
@@ -124,7 +124,7 @@ function Viewport(canvas) {
canvas.getButtonMenu().bringToFront(); canvas.getButtonMenu().bringToFront();
}; };
this.getCropData = function () { this.getData = function () {
return _data; return _data;
}; };
+7 -2
View File
@@ -17,9 +17,14 @@ function calcCrop(obj, width, height) {
var returnValue = { var returnValue = {
image: obj, image: obj,
axis: objRatio > cropRatio ? 'x' : 'y', axis: objRatio > cropRatio ? 'x' : 'y',
dim: { width: width, height: height }, dim: {
width: Number(width),
height: Number(height)
},
width: obj.width, width: obj.width,
height: obj.height height: obj.height,
objectRatio: objRatio,
cropRatio: cropRatio
}; };
if (objRatio > cropRatio) { if (objRatio > cropRatio) {
+11 -5
View File
@@ -24,24 +24,30 @@ $(function() {
var editor = new ImageEditor({'type': 'canvas'}) var editor = new ImageEditor({'type': 'canvas'})
.loadImage(imageUrl, function() { .loadImage(imageUrl, function() {
$input.w.trigger('keyup'); $input.w.trigger('input');
}); });
var Event = { var Event = {
DimensionChange: function() { DimensionChange: function() {
var noCropIsChecked = $input.noCrop.is(':checked');
var dimension = $(this).attr('name');
var data = editor.canvas.getViewport().getData();
editor.crop($input.w.val(), $input.h.val()); editor.crop($input.w.val(), $input.h.val());
}, },
Mirror: function() { Mirror: function() {
editor.canvas.getImage().transformation.set('mirror', this.checked); editor.canvas.getImage().transformation.set('mirror', this.checked);
}, },
NoCrop: function() { NoCrop: function() {
// editor.canvas var data = editor.canvas.getViewport().getData();
$input.h.val(parseInt(data.dim.height / data.objectRatio)).trigger('input');
}, },
}; };
$input.w.keyup(Event.DimensionChange); $input.w.on('input', Event.DimensionChange);
$input.h.keyup(Event.DimensionChange); $input.h.on('input', Event.DimensionChange);
$input.mirror.change(Event.Mirror); $input.mirror.change(Event.Mirror);
$input.noCrop.change(Event.NoCrop); $input.noCrop.change(Event.NoCrop);
}()); }());