From fa50874d9ca03540dc5741fb51261ef2b56f89ea Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Fri, 25 May 2012 15:34:44 -0700 Subject: IKNinja-1491 - Adding slice value to border gradients. Note that using "circle cover" comes close to matching our canvas 2d/WebGL shape's stroke gradients, but still a little off. Signed-off-by: Nivesh Rajbhandari --- js/controllers/elements/element-controller.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/js/controllers/elements/element-controller.js b/js/controllers/elements/element-controller.js index 20225c61..7bb07976 100755 --- a/js/controllers/elements/element-controller.js +++ b/js/controllers/elements/element-controller.js @@ -159,8 +159,6 @@ exports.ElementController = Montage.create(Component, { el.elementModel.stroke = null; return; case 'gradient': - this.setProperty(el, "border-image", color.color.css); - this.setProperty(el, "border-color", "none"); if(color.borderInfo) { if(color.borderInfo.borderWidth) { this.setProperty(el, "border-width", color.borderInfo.borderWidth + color.borderInfo.borderUnits); @@ -169,9 +167,11 @@ exports.ElementController = Montage.create(Component, { this.setProperty(el, "border-style", color.borderInfo.borderStyle); } } + this.setGradientBorder(el, color.color.gradientMode, color.color.css); break; default: this.setProperty(el, "border-image", "none"); + this.setProperty(el, "border-image-slice", ""); this.setProperty(el, "border-color", color.color.css); if(color.borderInfo) { if(color.borderInfo.borderWidth) { @@ -188,6 +188,25 @@ exports.ElementController = Montage.create(Component, { } }, + setGradientBorder: { + value: function(el, gradientMode, css) { + if(gradientMode === "radial") { + this.setProperty(el, "border-image", css.replace("ellipse", "circle")); + } else { + this.setProperty(el, "border-image", css); + } + this.setProperty(el, "border-color", "none"); + // gradient slice = borderWidth/totalWidth + var b = parseInt(this.getProperty(el, "border-left-width", true)), + w = parseInt(this.getProperty(el, "width", true)), + h = parseInt(this.getProperty(el, "height", true)); + if(h > w) { + w = h; + } + this.setProperty(el, "border-image-slice", Math.floor(b/(w+b+b) * 100) + "%"); + } + }, + getStroke: { value: function(el) { // TODO - Need to figure out which border side user wants -- cgit v1.2.3