From 9ef05a0e137d3d38e9a6b5d94851227440ac0fbc Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Fri, 24 Feb 2012 16:48:14 -0800 Subject: Moved all color updating routines to a single function. Signed-off-by: Nivesh Rajbhandari --- js/tools/EyedropperTool.js | 110 ++++++++++++++++++++++++++------------------- 1 file changed, 64 insertions(+), 46 deletions(-) diff --git a/js/tools/EyedropperTool.js b/js/tools/EyedropperTool.js index 710c96ef..11c15158 100755 --- a/js/tools/EyedropperTool.js +++ b/js/tools/EyedropperTool.js @@ -71,7 +71,7 @@ exports.EyedropperTool = Montage.create(toolBase, { this._escape = false; } - this._updateColor(this._color); + this._updateColor(this._color, true); this._color = null; @@ -86,18 +86,7 @@ exports.EyedropperTool = Montage.create(toolBase, { if(this._color && this._color.value) { var color = this.application.ninja.colorController.getColorObjFromCss(this._previousColor); - - if (color && color.value) { - color.value.wasSetByCode = true; - color.value.type = 'change'; - if (color.value.a) { - this.application.ninja.colorController.colorModel.alpha = {value: color.value.a, - wasSetByCode: true, - type: 'change'}; - } - this.application.ninja.colorController.colorModel[color.mode] = color.value; - this._color = null; - } + this._updateColor(color, true); } this._escape = true; } @@ -151,21 +140,11 @@ exports.EyedropperTool = Montage.create(toolBase, { } else { - color = c; + color = this.application.ninja.colorController.getColorObjFromCss(c.color.css); } } - if (color && color.value) { - color.value.wasSetByCode = true; - color.value.type = 'changing'; - if (color.value.a) { - this.application.ninja.colorController.colorModel.alpha = {value: color.value.a, - wasSetByCode: true, - type: 'changing'}; - } - this.application.ninja.colorController.colorModel[color.mode] = color.value; - this._color = color; - } + this._updateColor(color, false); } else { @@ -177,32 +156,75 @@ exports.EyedropperTool = Montage.create(toolBase, { }, _updateColor: { - value: function(color) { - if (color && color.value) { - var input = this.application.ninja.colorController.colorModel.input; + value: function(color, updateColorToolBar) { + var eventType = "changing"; + if(updateColorToolBar) + { + eventType = "change"; + if (color && color.value) + { + var input = this.application.ninja.colorController.colorModel.input; + + if(input === "fill") + { + this.application.ninja.colorController.colorToolbar.fill_btn.color(color.mode, color.value); + } + else + { + this.application.ninja.colorController.colorToolbar.stroke_btn.color(color.mode, color.value); + } + + // Updating color chips will set the input type to "chip", so set it back here. + this.application.ninja.colorController.colorModel.input = input; + } + } + + if(color) + { + if(color.color) + { + color.color.wasSetByCode = true; + color.color.type = eventType; + } - if(input === "fill") + if(color.mode === "gradient") { - this.application.ninja.colorController.colorToolbar.fill_btn.color(color.mode, color.value); + this.application.ninja.colorController.colorModel["gradient"] = + {value: color.color, wasSetByCode: true, type: eventType}; } else { - this.application.ninja.colorController.colorToolbar.stroke_btn.color(color.mode, color.value); + if (color.color.a !== undefined) + { + this.application.ninja.colorController.colorModel.alpha = + {value: color.color.a, wasSetByCode: true, type: eventType}; + } + if(color.color.mode) + { + this.application.ninja.colorController.colorModel[color.color.mode] = color.color; + } + else + { + this.application.ninja.colorController.colorModel["rgb"] = color.color; + } } - // Updating color chips will set the input type to "chip", so set it back here. - this.application.ninja.colorController.colorModel.input = input; - - color.value.wasSetByCode = true; - color.value.type = 'change'; - if (color.value.a) { - this.application.ninja.colorController.colorModel.alpha = {value: color.value.a, - wasSetByCode: true, - type: 'change'}; + if(updateColorToolBar) + { + this._previousColor = color.color.css; } - this.application.ninja.colorController.colorModel[color.mode] = color.value; - this._previousColor = color.value.css; } + else + { + this.application.ninja.colorController.colorModel.alpha = {value: 1, wasSetByCode: true, type: eventType}; + this.application.ninja.colorController.colorModel.applyNoColor(); + if(updateColorToolBar) + { + this._previousColor = "none"; + } + } + + this._color = color; } }, @@ -288,8 +310,6 @@ exports.EyedropperTool = Montage.create(toolBase, { this._imageDataCanvas.width = w; this._imageDataCanvas.height = h; -// this.application.ninja.currentDocument.documentRoot.appendChild(this._imageDataCanvas); - this._imageDataContext = this._imageDataCanvas.getContext("2d"); this._imageDataContext.drawImage(elt, 0, 0); } @@ -306,7 +326,6 @@ exports.EyedropperTool = Montage.create(toolBase, { _getColorFromCanvas: { value: function(ctx, pt) { -// var imageData = ctx.getImageData(pt.x, pt.y, 1, 1).data; var imageData = ctx.getImageData(pt[0], pt[1], 1, 1).data; if(imageData) { @@ -324,7 +343,6 @@ exports.EyedropperTool = Montage.create(toolBase, { { if(this._imageDataCanvas) { -// this.application.ninja.currentDocument.documentRoot.removeChild(this._imageDataCanvas); this._imageDataCanvas = null; this._imageDataContext = null; } -- cgit v1.2.3