From 57c373259fb22a6c20248ef338dc2766a364ac59 Mon Sep 17 00:00:00 2001 From: Pushkar Joshi Date: Fri, 27 Apr 2012 15:38:17 -0700 Subject: scale the brush stroke according to the input width and height Fixes: 1444 Brush: Unable to scale brushstroke using the Transform handles --- js/lib/geom/brush-stroke.js | 62 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 4 deletions(-) (limited to 'js/lib') diff --git a/js/lib/geom/brush-stroke.js b/js/lib/geom/brush-stroke.js index 1fae0c1d..d5d9a893 100755 --- a/js/lib/geom/brush-stroke.js +++ b/js/lib/geom/brush-stroke.js @@ -264,13 +264,67 @@ var BrushStroke = function GLBrushStroke() { this._strokeStyle = s; }; - this.setWidth = function () { + this.setWidth = function (newW) { + if (newW<1) { + newW=1; //clamp minimum width to 1 + } + + //scale the contents of this subpath to lie within this width + //determine the scale factor by comparing with the old width + var oldWidth = this._BBoxMax[0]-this._BBoxMin[0]; + if (oldWidth<1) { + oldWidth=1; + } + + var scaleX = newW/oldWidth; + if (scaleX===1) { + return; //no need to do anything + } + + //scale the local point positions such that the width of the bbox is the newW + var origX = this._BBoxMin[0]; + var numPoints = this._LocalPoints.length; + for (var i=0;i0) { - alphaVal = 1.0 - distFromOpaqueRegion/maxTransparentRegionHalfWidth; - alphaVal *= 1.0/ctx.lineWidth; //factor that accounts for lineWidth !== 1 + var transparencyFactor = distFromOpaqueRegion/maxTransparentRegionHalfWidth; + alphaVal = 1.0 - transparencyFactor;//(transparencyFactor*transparencyFactor);//the square term produces nonlinearly varying alpha values } ctx.save(); - if (t === (numTraces-1)){ + if (t === (numTraces-1) || t === 0){ ctx.lineWidth = 1; } else { //todo figure out the correct formula for the line width ctx.lineWidth=2; + alphaVal *= 0.5; //factor that accounts for lineWidth == 2 } ctx.strokeStyle="rgba("+parseInt(255*this._strokeColor[0])+","+parseInt(255*this._strokeColor[1])+","+parseInt(255*this._strokeColor[2])+","+alphaVal+")"; //linearly interpolate between the two stroke colors -- cgit v1.2.3 From b9262c831952e77135b79c2de7c455d5e7ff0589 Mon Sep 17 00:00:00 2001 From: Pushkar Joshi Date: Tue, 1 May 2012 17:00:40 -0700 Subject: undo some previous change that was halving the alpha value of the stroke --- js/lib/geom/brush-stroke.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/lib') diff --git a/js/lib/geom/brush-stroke.js b/js/lib/geom/brush-stroke.js index a1746d95..519e0433 100755 --- a/js/lib/geom/brush-stroke.js +++ b/js/lib/geom/brush-stroke.js @@ -665,6 +665,7 @@ var BrushStroke = function GLBrushStroke() { if (distFromOpaqueRegion>0) { var transparencyFactor = distFromOpaqueRegion/maxTransparentRegionHalfWidth; alphaVal = 1.0 - transparencyFactor;//(transparencyFactor*transparencyFactor);//the square term produces nonlinearly varying alpha values + alphaVal *= 0.5; //factor that accounts for lineWidth == 2 } ctx.save(); if (t === (numTraces-1) || t === 0){ @@ -672,7 +673,6 @@ var BrushStroke = function GLBrushStroke() { } else { //todo figure out the correct formula for the line width ctx.lineWidth=2; - alphaVal *= 0.5; //factor that accounts for lineWidth == 2 } ctx.strokeStyle="rgba("+parseInt(255*this._strokeColor[0])+","+parseInt(255*this._strokeColor[1])+","+parseInt(255*this._strokeColor[2])+","+alphaVal+")"; //linearly interpolate between the two stroke colors -- cgit v1.2.3 From de9f718b739ef2b31a161d9dac6e81d614fab853 Mon Sep 17 00:00:00 2001 From: Pushkar Joshi Date: Fri, 11 May 2012 08:55:07 -0700 Subject: code cleanup and starting the subtool functionality --- js/lib/geom/sub-path.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'js/lib') diff --git a/js/lib/geom/sub-path.js b/js/lib/geom/sub-path.js index 56c94df3..24acb2b0 100755 --- a/js/lib/geom/sub-path.js +++ b/js/lib/geom/sub-path.js @@ -166,6 +166,8 @@ var GLSubpath = function GLSubpath() { }; this.setWidth = function (newW) { + var strokeWidth = this._strokeWidth; + var halfStrokeWidth = strokeWidth*0.5; if (newW<1) { newW=1; //clamp minimum width to 1 } @@ -183,7 +185,7 @@ var GLSubpath = function GLSubpath() { } //scale the anchor point positions such that the width of the bbox is the newW - var origX = this._BBoxMin[0]; + var origX = this._BBoxMin[0]; //this should always be zero since we only deal with local coordinates var numAnchors = this._Anchors.length; for (var i=0;i --- js/lib/NJUtils.js | 120 ------------------------------------------------------ 1 file changed, 120 deletions(-) (limited to 'js/lib') diff --git a/js/lib/NJUtils.js b/js/lib/NJUtils.js index 7dd4c9e8..0dec6345 100755 --- a/js/lib/NJUtils.js +++ b/js/lib/NJUtils.js @@ -90,30 +90,6 @@ exports.NJUtils = Montage.create(Component, { } }, - createModel: { - value: function(el) { - el.elementModel = Montage.create(ElementModel).initialize(el); - } - }, - - createModelWithShape: { - value: function(el, selection) { - el.elementModel = Montage.create(ElementModel).initialize(el, true, selection); - } - }, - - createModelWithSelection: { - value: function(el, selection) { - el.elementModel = Montage.create(ElementModel).initialize(el, false, selection); - } - }, - - createModelForComponent: { - value: function(el, selection) { - el.elementModel = Montage.create(ElementModel).initialize(el, false, selection, true); - } - }, - // TODO: Find a better place for this method stylesFromDraw: { value: function(element, width, height, drawData, pos) { @@ -166,102 +142,6 @@ exports.NJUtils = Montage.create(Component, { } }, - ///// Element Model creation for existing elements - ///// TODO: find a different place for this function - makeElementModel: { - value: function(el, selection, controller, isShape) { - var p3d = Montage.create(Properties3D); - - var shapeProps = null; - var pi = controller + "Pi"; - - if(isShape) { - shapeProps = Montage.create(ShapeModel); - } - - if(el.controller) { - - var componentInfo = Montage.getInfoForObject(el.controller); - var componentName = componentInfo.objectName.toLowerCase(); - - controller = "component"; - isShape = false; - - switch(componentName) { - case "feedreader": - selection = "Feed Reader"; - pi = "FeedReaderPi"; - break; - case "map": - selection = "Map"; - pi = "MapPi"; - break; - case "youtubechannel": - selection = "Youtube Channel"; - pi = "YoutubeChannelPi"; - break; - case "picasacarousel": - selection = "Picasa Carousel"; - pi = "PicasaCarouselPi"; - break; - } - } - - el.elementModel = Montage.create(ElementModel, { - type: { value: el.nodeName}, - selection: { value: selection}, - controller: { value: ControllerFactory.getController(controller)}, - pi: { value: pi}, - props3D: { value: p3d}, - shapeModel: { value: shapeProps}, - isShape: { value: isShape} - }); - - - } - }, - - ///// Element Model creation for existing elements based on element type. - ///// TODO: Selection and model should be based on the element type - makeModelFromElement: { - value: function(el) { - var selection = "div", - controller = "block", - isShape = false; - switch(el.nodeName.toLowerCase()) - { - case "div": - break; - case "img": - selection = "image"; - controller = "image"; - break; - case "video": - selection = "video"; - controller = "video"; - break; - case "canvas": - isShape = el.getAttribute("data-RDGE-id"); - if(isShape) { - // TODO - Need more info about the shape - selection = "canvas"; - controller = "shape"; - isShape = true; - } else { - selection = "canvas"; - controller = "canvas"; - } - break; - case "shape": - break; - } - this.makeElementModel(el, selection, controller, isShape); - if(el.elementModel && el.elementModel.props3D) { - el.elementModel.props3D.init(el, (selection === "Stage")); - } - } - }, - ///// Removes all child nodes and returns node ///// Accepts a single node, or an array of dom nodes empty : { -- cgit v1.2.3