Skip to content
Snippets Groups Projects
Commit 0fd9e525 authored by hertzhaft's avatar hertzhaft
Browse files

added Rect shape (rectangle drawn from a base line)

parent 97c7f28e
Branches
Tags
No related merge requests found
...@@ -175,9 +175,14 @@ ...@@ -175,9 +175,14 @@
top : this.y top : this.y
}; };
}; };
// return as string
that.toString = function() { that.toString = function() {
return (this.x + "," + this.y); return (this.x + "," + this.y);
}; };
// return as array
that.toArray = function() {
return [this.x, this.y];
};
return that; return that;
}; };
/* /*
......
...@@ -710,7 +710,7 @@ ...@@ -710,7 +710,7 @@
// color of selected objects // color of selected objects
selectColor : 'red', selectColor : 'red',
// implemented measuring shape types, for select widget // implemented measuring shape types, for select widget
implementedShapes : ['Line', 'LineString', 'Proportion', 'Rectangle', 'Polygon', 'Circle', 'Ellipse'], implementedShapes : ['Line', 'LineString', 'Proportion', 'Rect', 'Rectangle', 'Polygon', 'Circle', 'Ellipse'],
// all measuring shape types // all measuring shape types
shapeInfo : { shapeInfo : {
Line : { name : 'line', display : 'length', }, Line : { name : 'line', display : 'length', },
...@@ -969,15 +969,15 @@ ...@@ -969,15 +969,15 @@
var newShape = function(data) { var newShape = function(data) {
var shapeType = getActiveShapeType(data); var shapeType = getActiveShapeType(data);
return { return {
geometry : { 'geometry' : {
type : shapeType 'type' : shapeType
}, },
properties : { 'properties' : {
stroke : getSelectedStroke(data), 'editable' : true,
editable : true, 'selected' : false,
cssclass : shapeClass(shapeType), 'stroke' : getSelectedStroke(data),
center : data.settings.drawFromCenter, 'cssclass' : shapeClass(shapeType)
selected : false // 'center' : data.settings.drawFromCenter
} }
}; };
}; };
...@@ -1179,11 +1179,34 @@ ...@@ -1179,11 +1179,34 @@
console.error("No SVG factory found: jquery.digilib.vector not loaded?"); console.error("No SVG factory found: jquery.digilib.vector not loaded?");
return; return;
} }
var trafo = data.imgTrafo;
factory['Proportion'] = function (shape) { factory['Proportion'] = function (shape) {
var $s = factory['LineString'](shape); var $s = factory['LineString'](shape);
shape.properties.maxvtx = 3; shape.properties.maxvtx = 3;
return $s; return $s;
} };
factory['Rect'] = function (shape) {
var $s = factory['Polygon'](shape);
var props = shape.properties;
props.maxvtx = 3;
$s.place = function () {
var p = props.screenpos;
var vtx = props.vtx;
if (vtx > 1 || p.length > 2) {
var pv = p[2];
var pd = geom.position(p[1].x - p[0].x, p[1].y - p[0].y);
var pe = (Math.abs(pd.y) > Math.abs(pd.x))
? geom.position(pv.x - p[1].x, pd.x/pd.y * (pv.x - p[1].x))
: geom.position(pd.y/pd.x * (p[1].y - pv.y), p[1].y - pv.y);
p[2] = geom.position(p[1].x + pe.x, p[1].y - pe.y);
p[3] = geom.position(p[0].x + pe.x, p[0].y - pe.y);
shape.geometry.coordinates[2] = data.imgTrafo.invtransform(p[2]).toArray();
shape.geometry.coordinates[3] = data.imgTrafo.invtransform(p[3]).toArray();
}
this.attr({'points': p.join(" ")});
};
return $s;
};
}; };
// set up a div for accessing the measuring functionality // set up a div for accessing the measuring functionality
......
...@@ -479,8 +479,12 @@ ...@@ -479,8 +479,12 @@
$.each(coords, createHandle); $.each(coords, createHandle);
// vertexElems must be defined before calling getVertexDragHandler() // vertexElems must be defined before calling getVertexDragHandler()
shape.$vertexElems = handles; shape.$vertexElems = handles;
var done = function (data, shape, evt) {
unrenderShape(data, shape);
renderShape(data, shape, layer);
}
var attachEvent = function (i, item) { var attachEvent = function (i, item) {
item.one("mousedown.dlVertexDrag", getVertexDragHandler(data, shape, i)); item.one("mousedown.dlVertexDrag", getVertexDragHandler(data, shape, i, done));
}; };
$.each(handles, attachEvent); $.each(handles, attachEvent);
}; };
...@@ -592,15 +596,14 @@ ...@@ -592,15 +596,14 @@
pt.clipTo(imgRect); pt.clipTo(imgRect);
shape.properties.screenpos[vtx] = pt; shape.properties.screenpos[vtx] = pt;
$(data).trigger('positionShape', shape); $(data).trigger('positionShape', shape);
$handle.moveTo(pt);
if (isSupported(data, shapeType)) { if (isSupported(data, shapeType)) {
// update shape object and trigger drag event // update shape object and trigger drag event
var p = data.imgTrafo.invtransform(pt); shape.geometry.coordinates[vtx] = data.imgTrafo.invtransform(pt).toArray();
shape.geometry.coordinates[vtx] = [p.x, p.y];
// update shape SVG element // update shape SVG element
shape.$elem.place(); shape.$elem.place();
$(data).trigger('dragShape', shape); $(data).trigger('dragShape', shape);
} }
$handle.moveTo(pt);
return false; return false;
}; };
...@@ -666,12 +669,13 @@ ...@@ -666,12 +669,13 @@
var shapeStart = function (evt) { var shapeStart = function (evt) {
var pt = geom.position(evt); var pt = geom.position(evt);
// setup shape // setup shape
var p = data.imgTrafo.invtransform(pt); var p1 = data.imgTrafo.invtransform(pt).toArray();
var p2 = p1.slice(0);
var vtx = 1; var vtx = 1;
if (shapeType === 'Point') { if (shapeType === 'Point') {
shape.geometry.coordinates = [[p.x, p.y]]; shape.geometry.coordinates = [p1];
} else if (isSupported(data, shapeType)) { } else if (isSupported(data, shapeType)) {
shape.geometry.coordinates = [[p.x, p.y], [p.x, p.y]]; shape.geometry.coordinates = [p1, p2];
} else { } else {
console.error("defineShape: unsupported shape type: "+shapeType); console.error("defineShape: unsupported shape type: "+shapeType);
$overlayDiv.remove(); $overlayDiv.remove();
...@@ -683,6 +687,7 @@ ...@@ -683,6 +687,7 @@
} }
// save first mousedown position // save first mousedown position
shape.properties.screenpos = [pt]; shape.properties.screenpos = [pt];
shape.properties.vtx = vtx;
// draw shape // draw shape
renderShape(data, shape, layer); renderShape(data, shape, layer);
// vertex drag end handler // vertex drag end handler
...@@ -698,6 +703,7 @@ ...@@ -698,6 +703,7 @@
coords.push(coords[vtx].slice()); coords.push(coords[vtx].slice());
vtx += 1; vtx += 1;
// draw shape // draw shape
shape.properties.vtx = vtx;
renderShape(data, shape, layer); renderShape(data, shape, layer);
// execute vertex drag handler on next vertex // execute vertex drag handler on next vertex
getVertexDragHandler(data, shape, vtx, vertexDragDone)(evt); getVertexDragHandler(data, shape, vtx, vertexDragDone)(evt);
...@@ -714,6 +720,7 @@ ...@@ -714,6 +720,7 @@
} }
if (rerender) { if (rerender) {
unrenderShape(data, shape); unrenderShape(data, shape);
shape.properties.vtx = vtx;
renderShape(data, shape, layer); renderShape(data, shape, layer);
} }
} else { } else {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment