aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom/sub-path.js
diff options
context:
space:
mode:
authorArmen Kesablyan2012-06-19 00:45:26 -0700
committerArmen Kesablyan2012-06-19 00:45:26 -0700
commitc59eb371559a3061ce53223e249ca97daace5968 (patch)
treef9540e26c0f273d35f92010605da65dd85bbe70c /js/lib/geom/sub-path.js
parent0f040acabfb7a4bf3138debec5aff869487ceb11 (diff)
parent918a4f5870e972b6e4e301c3237e065a1ffd26f5 (diff)
downloadninja-c59eb371559a3061ce53223e249ca97daace5968.tar.gz
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal
Diffstat (limited to 'js/lib/geom/sub-path.js')
-rwxr-xr-xjs/lib/geom/sub-path.js35
1 files changed, 21 insertions, 14 deletions
diff --git a/js/lib/geom/sub-path.js b/js/lib/geom/sub-path.js
index f765b715..9b72f6b7 100755
--- a/js/lib/geom/sub-path.js
+++ b/js/lib/geom/sub-path.js
@@ -54,7 +54,7 @@ var GLSubpath = function GLSubpath() {
54 //drawing context 54 //drawing context
55 this._world = null; 55 this._world = null;
56 this._canvas = null; //todo this might be unnecessary (but faster) since we can get it from the world 56 this._canvas = null; //todo this might be unnecessary (but faster) since we can get it from the world
57 57
58 //tool that owns this subpath 58 //tool that owns this subpath
59 this._drawingTool = null; 59 this._drawingTool = null;
60 60
@@ -87,6 +87,7 @@ GLSubpath.prototype.buildColor = function(ctx, //the 2D rendering conte
87 if (ipColor.gradientMode){ 87 if (ipColor.gradientMode){
88 var position, gradient, cs, inset; //vars used in gradient calculations 88 var position, gradient, cs, inset; //vars used in gradient calculations
89 inset = Math.ceil( lw ) - 0.5; 89 inset = Math.ceil( lw ) - 0.5;
90 inset=0;
90 91
91 if(ipColor.gradientMode === "radial") { 92 if(ipColor.gradientMode === "radial") {
92 var ww = w - 2*lw, hh = h - 2*lw; 93 var ww = w - 2*lw, hh = h - 2*lw;
@@ -207,24 +208,25 @@ GLSubpath.prototype.geomType = function () {
207GLSubpath.prototype.setWidth = function (newW) { 208GLSubpath.prototype.setWidth = function (newW) {
208 var strokeWidth = this._strokeWidth; 209 var strokeWidth = this._strokeWidth;
209 var halfStrokeWidth = strokeWidth*0.5; 210 var halfStrokeWidth = strokeWidth*0.5;
210 if (newW<1) { 211 var minWidth = 1+strokeWidth;
211 newW=1; //clamp minimum width to 1 212 if (newW<minWidth) {
213 newW=minWidth;
212 } 214 }
213 215
214 //scale the contents of this subpath to lie within this width 216 //scale the contents of this subpath to lie within this width
215 //determine the scale factor by comparing with the old width 217 //determine the scale factor by comparing with the old width
216 var oldWidth = this._BBoxMax[0]-this._BBoxMin[0]; 218 var oldCanvasWidth = this._BBoxMax[0]-this._BBoxMin[0];
217 if (oldWidth<1) { 219 if (oldCanvasWidth<minWidth) {
218 oldWidth=1; 220 oldCanvasWidth=minWidth;
219 } 221 }
220 222
221 var scaleX = newW/oldWidth; 223 var scaleX = (newW-strokeWidth)/(oldCanvasWidth-strokeWidth);
222 if (scaleX===1) { 224 if (scaleX===1) {
223 return; //no need to do anything 225 return; //no need to do anything
224 } 226 }
225 227
226 //scale the anchor point positions such that the width of the bbox is the newW 228 //scale the anchor point positions such that the width of the bbox is the newW
227 var origX = this._BBoxMin[0]; //this should always be zero since we only deal with local coordinates 229 var origX = halfStrokeWidth;//this is the left edge //this._BBoxMin[0]; //this should always be zero since we only deal with local coordinates
228 var numAnchors = this._Anchors.length; 230 var numAnchors = this._Anchors.length;
229 for (var i=0;i<numAnchors;i++){ 231 for (var i=0;i<numAnchors;i++){
230 //compute the distance from the bboxMin 232 //compute the distance from the bboxMin
@@ -241,23 +243,27 @@ GLSubpath.prototype.setWidth = function (newW) {
241}; 243};
242 244
243GLSubpath.prototype.setHeight = function (newH) { 245GLSubpath.prototype.setHeight = function (newH) {
244 if (newH<1) { 246 var strokeWidth = this._strokeWidth;
245 newH=1; //clamp minimum width to 1 247 var halfStrokeWidth = strokeWidth*0.5;
248 var minHeight = 1+strokeWidth;
249
250 if (newH<minHeight) {
251 newH=minHeight; //clamp minimum width to 1
246 } 252 }
247 //scale the contents of this subpath to lie within this height 253 //scale the contents of this subpath to lie within this height
248 //determine the scale factor by comparing with the old height 254 //determine the scale factor by comparing with the old height
249 var oldHeight = this._BBoxMax[1]-this._BBoxMin[1]; 255 var oldHeight = this._BBoxMax[1]-this._BBoxMin[1];
250 if (oldHeight<1){ 256 if (oldHeight<minHeight){
251 oldHeight=1; 257 oldHeight=minHeight;
252 } 258 }
253 259
254 var scaleY = newH/oldHeight; 260 var scaleY = (newH-strokeWidth)/(oldHeight-strokeWidth);
255 if (scaleY===1){ 261 if (scaleY===1){
256 return; //no need to do anything 262 return; //no need to do anything
257 } 263 }
258 264
259 //scale the anchor point positions such that the height of the bbox is the newH 265 //scale the anchor point positions such that the height of the bbox is the newH
260 var origY = this._BBoxMin[1]; 266 var origY = halfStrokeWidth;// this._BBoxMin[1];//this is the top edge
261 var numAnchors = this._Anchors.length; 267 var numAnchors = this._Anchors.length;
262 for (var i=0;i<numAnchors;i++){ 268 for (var i=0;i<numAnchors;i++){
263 //compute the distance from the bboxMin 269 //compute the distance from the bboxMin
@@ -270,6 +276,7 @@ GLSubpath.prototype.setHeight = function (newH) {
270 this._Anchors[i].setNextPos(this._Anchors[i].getNextX(), origY + nextW*scaleY,this._Anchors[i].getNextZ()); 276 this._Anchors[i].setNextPos(this._Anchors[i].getNextX(), origY + nextW*scaleY,this._Anchors[i].getNextZ());
271 } 277 }
272 this.makeDirty(); 278 this.makeDirty();
279 this.computeBoundingBox(true, false);
273}; 280};
274 281
275GLSubpath.prototype.setWorld = function (world) { 282GLSubpath.prototype.setWorld = function (world) {