aboutsummaryrefslogtreecommitdiff
path: root/js/lib
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib')
-rwxr-xr-xjs/lib/geom/sub-path.js57
1 files changed, 49 insertions, 8 deletions
diff --git a/js/lib/geom/sub-path.js b/js/lib/geom/sub-path.js
index 35070915..bca4e1c5 100755
--- a/js/lib/geom/sub-path.js
+++ b/js/lib/geom/sub-path.js
@@ -310,6 +310,9 @@ GLSubpath.prototype = new GeomObj();
310GLSubpath.prototype.setCanvas = function (c) { 310GLSubpath.prototype.setCanvas = function (c) {
311 this._canvas = c; 311 this._canvas = c;
312}; 312};
313GLSubpath.prototype.getCanvas = function() {
314 return this._canvas;
315};
313 316
314GLSubpath.prototype.setWorld = function (world) { 317GLSubpath.prototype.setWorld = function (world) {
315 this._world = world; 318 this._world = world;
@@ -875,6 +878,22 @@ GLSubpath.prototype.translateSubpathPerCanvas = function(elemMediator){
875 this._dirty=true; 878 this._dirty=true;
876}; 879};
877 880
881GLSubpath.prototype.computeLeftTopWidthHeight = function() {
882 //build the width and height of this canvas by looking at local coordinates
883 var bboxMin = this.getLocalBBoxMin();
884 var bboxMax = this.getLocalBBoxMax();
885 var bboxWidth = bboxMax[0] - bboxMin[0];
886 var bboxHeight = bboxMax[1] - bboxMin[1];
887
888 //build the 3D position of the plane center of this canvas by looking at midpoint of the bounding box in stage world coords
889 bboxMin = this.getBBoxMin();
890 bboxMax = this.getBBoxMax();
891 var bboxMid = [0.5 * (bboxMax[0] + bboxMin[0]), 0.5 * (bboxMax[1] + bboxMin[1]), 0.5 * (bboxMax[2] + bboxMin[2])];
892 var left = Math.round(bboxMid[0] - 0.5 * bboxWidth);
893 var top = Math.round(bboxMid[1] - 0.5 * bboxHeight);
894 return [left, top, bboxWidth, bboxHeight];
895};
896
878GLSubpath.prototype.setStrokeWidth = function (w) { 897GLSubpath.prototype.setStrokeWidth = function (w) {
879 var diffStrokeWidth = w-Math.floor(this._strokeWidth);//if positive, then stroke width grew, else shrunk 898 var diffStrokeWidth = w-Math.floor(this._strokeWidth);//if positive, then stroke width grew, else shrunk
880 if (diffStrokeWidth === 0) 899 if (diffStrokeWidth === 0)
@@ -891,7 +910,7 @@ GLSubpath.prototype.setStrokeWidth = function (w) {
891 // **** adjust the left, top, width, and height to adjust for the change in stroke width **** 910 // **** adjust the left, top, width, and height to adjust for the change in stroke width ****
892 this.createSamples(); //dirty bit is checked here 911 this.createSamples(); //dirty bit is checked here
893 this.buildLocalCoord(); //local dirty bit is checked here 912 this.buildLocalCoord(); //local dirty bit is checked here
894 913/*
895 //build the width and height of this canvas by looking at local coordinates 914 //build the width and height of this canvas by looking at local coordinates
896 var bboxMin = this.getLocalBBoxMin(); 915 var bboxMin = this.getLocalBBoxMin();
897 var bboxMax = this.getLocalBBoxMax(); 916 var bboxMax = this.getLocalBBoxMax();
@@ -904,14 +923,15 @@ GLSubpath.prototype.setStrokeWidth = function (w) {
904 var bboxMid = [0.5 * (bboxMax[0] + bboxMin[0]), 0.5 * (bboxMax[1] + bboxMin[1]), 0.5 * (bboxMax[2] + bboxMin[2])]; 923 var bboxMid = [0.5 * (bboxMax[0] + bboxMin[0]), 0.5 * (bboxMax[1] + bboxMin[1]), 0.5 * (bboxMax[2] + bboxMin[2])];
905 var left = Math.round(bboxMid[0] - 0.5 * bboxWidth); 924 var left = Math.round(bboxMid[0] - 0.5 * bboxWidth);
906 var top = Math.round(bboxMid[1] - 0.5 * bboxHeight); 925 var top = Math.round(bboxMid[1] - 0.5 * bboxHeight);
907 926*/
927 var ltwh = this.computeLeftTopWidthHeight();
908 var canvasArray=[this._canvas]; 928 var canvasArray=[this._canvas];
909 ElementMediator.setProperty(canvasArray, "width", [bboxWidth+"px"], "Changing", "penTool");//canvas.width = w; 929 ElementMediator.setProperty(canvasArray, "width", [ltwh[2]+"px"], "Changing", "penTool");//canvas.width = w;
910 ElementMediator.setProperty(canvasArray, "height", [bboxHeight+"px"], "Changing", "penTool");//canvas.height = h; 930 ElementMediator.setProperty(canvasArray, "height", [ltwh[3]+"px"], "Changing", "penTool");//canvas.height = h;
911 ElementMediator.setProperty(canvasArray, "left", [left+"px"],"Changing", "penTool");//DocumentControllerModule.DocumentController.SetElementStyle(canvas, "left", parseInt(left) + "px"); 931 ElementMediator.setProperty(canvasArray, "left", [ltwh[0]+"px"],"Changing", "penTool");//DocumentControllerModule.DocumentController.SetElementStyle(canvas, "left", parseInt(left) + "px");
912 ElementMediator.setProperty(canvasArray, "top", [top + "px"],"Changing", "penTool");//DocumentControllerModule.DocumentController.SetElementStyle(canvas, "top", parseInt(top) + "px"); 932 ElementMediator.setProperty(canvasArray, "top", [ltwh[1]+ "px"],"Changing", "penTool");//DocumentControllerModule.DocumentController.SetElementStyle(canvas, "top", parseInt(top) + "px");
913 this.setCanvasLeft(left); 933 this.setCanvasLeft(ltwh[0]);
914 this.setCanvasTop(top); 934 this.setCanvasTop(ltwh[1]);
915}; 935};
916 936
917GLSubpath.prototype.getStrokeMaterial = function () { 937GLSubpath.prototype.getStrokeMaterial = function () {
@@ -1098,6 +1118,25 @@ GLSubpath.prototype._unprojectPt = function(pt, pespectiveDist) {
1098 return retPt; 1118 return retPt;
1099}; 1119};
1100 1120
1121//return the local coord. of the anchor at the specified index, null if the anchor does not have a local coord yet
1122GLSubpath.prototype.getAnchorLocalCoord = function(index){
1123 if (this._isDirty){
1124 this.createSamples();
1125 }
1126 if (this._isLocalDirty){
1127 this.buildLocalCoord();
1128 }
1129 if (index<0 || index>= this._Anchors.length || index>=this._anchorSampleIndex.length){
1130 return null;
1131 }
1132 var anchorSampleIndex = this._anchorSampleIndex[index];
1133 if (anchorSampleIndex>=this._LocalPoints.length){
1134 return null;
1135 }
1136 var localCoord = this._LocalPoints[anchorSampleIndex].slice(0);
1137 return localCoord;
1138};
1139
1101//buildLocalCoord 1140//buildLocalCoord
1102GLSubpath.prototype.buildLocalCoord = function () { 1141GLSubpath.prototype.buildLocalCoord = function () {
1103 if (!this._isLocalDirty) { 1142 if (!this._isLocalDirty) {
@@ -1435,6 +1474,8 @@ GLSubpath.prototype.makeFillMaterial = function() {
1435}; 1474};
1436 1475
1437GLSubpath.prototype.getNearVertex = function( eyePt, dir ){ 1476GLSubpath.prototype.getNearVertex = function( eyePt, dir ){
1477 //todo BUILD A BBOX USING LOCAL COORD. (NO z NEEDED)
1478
1438 //get the parameters used for computing perspective transformation 1479 //get the parameters used for computing perspective transformation
1439 var bboxDim = []; 1480 var bboxDim = [];
1440 var bboxMid = []; 1481 var bboxMid = [];