From 1a759361b82127f9d5c1428dc889fffdf2daaf86 Mon Sep 17 00:00:00 2001 From: John Mayhew Date: Thu, 3 May 2012 15:11:56 -0700 Subject: First round of moving color chips into the sub tools. Shape and Pen tool now have chips in the sub tool bar. Still need to complete adding chips to the Brush tool and finalizing the subtool bar layout to our spec for all of the subtools. --- .../brush-properties.reel/brush-properties.js | 1 + .../line-properties.reel/line-properties.js | 8 + .../oval-properties.reel/oval-properties.js | 8 + .../pen-properties.reel/pen-properties.css | 20 + .../pen-properties.reel/pen-properties.html | 16 +- .../pen-properties.reel/pen-properties.js | 83 +- .../rect-properties.reel/rect-properties.js | 10 +- .../shape-properties.reel/shape-properties.css | 22 +- .../shape-properties.reel/shape-properties.html | 14 +- .../shape-properties.reel/shape-properties.js | 125 +- .../text-properties.reel/text-properties.html | 4 +- .../text-properties.reel/text-properties.js | 1 - .../color/colorpanelbase.reel/colorpanelbase.js | 2835 ++++++++++---------- js/tools/BrushTool.js | 2 +- js/tools/LineTool.js | 6 +- js/tools/OvalTool.js | 4 +- js/tools/PenTool.js | 4 +- js/tools/RectTool.js | 4 +- 18 files changed, 1704 insertions(+), 1463 deletions(-) (limited to 'js') diff --git a/js/components/tools-properties/brush-properties.reel/brush-properties.js b/js/components/tools-properties/brush-properties.reel/brush-properties.js index fdcd50f8..677cd2d9 100755 --- a/js/components/tools-properties/brush-properties.reel/brush-properties.js +++ b/js/components/tools-properties/brush-properties.reel/brush-properties.js @@ -36,6 +36,7 @@ exports.BrushProperties = Montage.create(ToolProperties, { } } }, + strokeSize: { get: function() { return this._strokeSize; } }, diff --git a/js/components/tools-properties/line-properties.reel/line-properties.js b/js/components/tools-properties/line-properties.reel/line-properties.js index e1ecf790..ce8c0494 100755 --- a/js/components/tools-properties/line-properties.reel/line-properties.js +++ b/js/components/tools-properties/line-properties.reel/line-properties.js @@ -24,6 +24,14 @@ exports.LineProperties = Montage.create(ToolProperties, { }, // Public API + fill: { + get: function () { return this.base.fill; } + }, + + stroke: { + get: function () { return this.base.stroke; } + }, + use3D: { get: function() { return this.base._use3D; } }, diff --git a/js/components/tools-properties/oval-properties.reel/oval-properties.js b/js/components/tools-properties/oval-properties.reel/oval-properties.js index ddeb64ee..3edd9214 100755 --- a/js/components/tools-properties/oval-properties.reel/oval-properties.js +++ b/js/components/tools-properties/oval-properties.reel/oval-properties.js @@ -24,6 +24,14 @@ exports.OvalProperties = Montage.create(ToolProperties, { }, // Public API + fill: { + get: function () { return this.base.fill; } + }, + + stroke: { + get: function () { return this.base.stroke; } + }, + use3D: { get: function() { return this.base._use3D; } }, diff --git a/js/components/tools-properties/pen-properties.reel/pen-properties.css b/js/components/tools-properties/pen-properties.reel/pen-properties.css index 7f1b0f7f..01a0ca1f 100755 --- a/js/components/tools-properties/pen-properties.reel/pen-properties.css +++ b/js/components/tools-properties/pen-properties.reel/pen-properties.css @@ -4,3 +4,23 @@ (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. */ + + .optionsPenTool { + padding: 6px; +} + + .optionsPenTool > * { + float:left; +} + + .optionsPenTool .fillColorCtrl, .optionsPenTool .strokeColorCtrl { + width: 20px; + height: 18px; + margin: 2px 6px; +} + + .optionsPenTool .colorCtrlIcon { + width: 20px; + height: 20px; + background-color: rgb(54, 54, 54); +} \ No newline at end of file diff --git a/js/components/tools-properties/pen-properties.reel/pen-properties.html b/js/components/tools-properties/pen-properties.reel/pen-properties.html index e835f69d..176663df 100755 --- a/js/components/tools-properties/pen-properties.reel/pen-properties.html +++ b/js/components/tools-properties/pen-properties.reel/pen-properties.html @@ -28,20 +28,24 @@ "prototype": "js/components/tools-properties/pen-properties.reel", "properties": { "element": {"#": "penProperties"}, + "_fillColorCtrl": {"#": "fillColorCtrl"}, + "_strokeColorCtrl": {"#": "strokeColorCtrl"}, "_strokeSize": {"@": "strokeSizeHT"} } } } - + -
-
- -
-
+
+
+
+
+
+ +
diff --git a/js/components/tools-properties/pen-properties.reel/pen-properties.js b/js/components/tools-properties/pen-properties.reel/pen-properties.js index b57f9a6f..cd205e07 100755 --- a/js/components/tools-properties/pen-properties.reel/pen-properties.js +++ b/js/components/tools-properties/pen-properties.reel/pen-properties.js @@ -7,8 +7,87 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot var Montage = require("montage/core/core").Montage; var ToolProperties = require("js/components/tools-properties/tool-properties").ToolProperties; -exports.PenProperties = Montage.create(ToolProperties, { +var PenProperties = exports.PenProperties = Montage.create(ToolProperties, { + addedColorChips: { value: false }, + + _fill: { + enumerable: false, + value: { colorMode: 'rgb', color: { r: 255, g: 255, b: 255, a: 1, css: 'rgb(255,255,255)', mode: 'rgb', wasSetByCode: true, type: 'change' }, webGlColor: [1, 1, 1, 1] } + }, + + _stroke: { + enumerable: false, + value: { colorMode: 'rgb', color: { r: 0, g: 0, b: 0, a: 1, css: 'rgb(0,0,0)', mode: 'rgb', wasSetByCode: true, type: 'change' }, webGlColor: [0, 0, 0, 1] } + }, + + stroke: { + enumerable: true, + get: function () { + return this._stroke; + }, + set: function (value) { + if (value !== this._stroke) { + this._stroke = value; + } + } + }, + + fill: { + enumerable: true, + get: function () { + return this._fill; + }, + set: function (value) { + if (value !== this._fill) { + this._fill = value; + } + } + }, + strokeSize: { - get: function() { return this._strokeSize; } + get: function () { + return this._strokeSize; + } + }, + + draw: { + enumerable: false, + value: function () { + Object.getPrototypeOf(PenProperties).draw.call(this); + + if (this.addedColorChips === false && this.application.ninja.colorController.colorPanelDrawn) { + // setup fill color + this._fillColorCtrl.props = { side: 'top', align: 'center', wheel: true, palette: true, gradient: false, image: false, nocolor: true, offset: -80 }; + this.application.ninja.colorController.addButton("chip", this._fillColorCtrl); + + // setup stroke color + this._strokeColorCtrl.props = { side: 'top', align: 'center', wheel: true, palette: true, gradient: false, image: false, nocolor: true, offset: -80 }; + this.application.ninja.colorController.addButton("chip", this._strokeColorCtrl); + + this._fillColorCtrl.addEventListener("change", this.handleFillColorChange.bind(this), false); + this._strokeColorCtrl.addEventListener("change", this.handleStrokeColorChange.bind(this), false); + + this.addedColorChips = true; + } + + if (this.addedColorChips) { + this._fillColorCtrl.color(this._fill.colorMode, this._fill.color); + this._strokeColorCtrl.color(this._stroke.colorMode, this._stroke.color); + } + } + }, + + handleFillColorChange: { + value: function (e) { + this.fill = e._event; + this.fill.webGlColor = this.application.ninja.colorController.colorModel.colorToWebGl(e._event.color); + } + }, + + handleStrokeColorChange: { + value: function (e) { + this.stroke = e._event; + this.stroke.webGlColor = this.application.ninja.colorController.colorModel.colorToWebGl(e._event.color); + } } }); \ No newline at end of file diff --git a/js/components/tools-properties/rect-properties.reel/rect-properties.js b/js/components/tools-properties/rect-properties.reel/rect-properties.js index f023f4bb..c1cb3945 100755 --- a/js/components/tools-properties/rect-properties.reel/rect-properties.js +++ b/js/components/tools-properties/rect-properties.reel/rect-properties.js @@ -42,6 +42,14 @@ exports.RectProperties = Montage.create(ToolProperties, { }, // Public API + fill: { + get: function () { return this.base.fill; } + }, + + stroke: { + get: function () { return this.base.stroke; } + }, + use3D: { get: function() { return this.base._use3D; } }, @@ -125,6 +133,4 @@ exports.RectProperties = Montage.create(ToolProperties, { } } - - }); \ No newline at end of file diff --git a/js/components/tools-properties/shape-properties.reel/shape-properties.css b/js/components/tools-properties/shape-properties.reel/shape-properties.css index 0441c1cf..6efa615c 100755 --- a/js/components/tools-properties/shape-properties.reel/shape-properties.css +++ b/js/components/tools-properties/shape-properties.reel/shape-properties.css @@ -2,4 +2,24 @@ This file contains proprietary software owned by Motorola Mobility, Inc.
No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. - */ \ No newline at end of file + */ + + .optionsShapeTool { + padding: 6px; +} + + .optionsShapeTool > * { + float:left; +} + + .optionsShapeTool .fillColorCtrl, .optionsShapeTool .strokeColorCtrl { + width: 20px; + height: 18px; + margin: 2px 6px; +} + + .optionsShapeTool .colorCtrlIcon { + width: 20px; + height: 20px; + background-color: rgb(54, 54, 54); +} \ No newline at end of file diff --git a/js/components/tools-properties/shape-properties.reel/shape-properties.html b/js/components/tools-properties/shape-properties.reel/shape-properties.html index 117664a3..d3faab75 100755 --- a/js/components/tools-properties/shape-properties.reel/shape-properties.html +++ b/js/components/tools-properties/shape-properties.reel/shape-properties.html @@ -36,6 +36,7 @@ } }, + "_strokeSize1": { "prototype": "js/components/hottextunit.reel[HotTextUnit]", "properties": { @@ -108,6 +109,10 @@ "_materialLabel": {"#": "materialLabel"}, "_strokeIcon": {"#": "strokeIcon"}, + "_fillColorCtrlIcon": {"#": "fillColorCtrlIcon"}, + "_fillColorCtrl": {"#": "fillColorCtrl"}, + "_strokeColorCtrl": {"#": "strokeColorCtrl"}, + "_strokeSize": {"@": "_strokeSize1"}, "ovalProperties": {"@": "ovalProperties1"}, "rectProperties": {"@": "rectProperties1"}, @@ -121,20 +126,23 @@ } } - + -
+
+
+
+
+
-
diff --git a/js/components/tools-properties/shape-properties.reel/shape-properties.js b/js/components/tools-properties/shape-properties.reel/shape-properties.js index 79567453..74875544 100755 --- a/js/components/tools-properties/shape-properties.reel/shape-properties.js +++ b/js/components/tools-properties/shape-properties.reel/shape-properties.js @@ -8,12 +8,75 @@ var Montage = require("montage/core/core").Montage, ShapesController = require("js/controllers/elements/shapes-controller").ShapesController, ToolProperties = require("js/components/tools-properties/tool-properties").ToolProperties; -exports.ShapeProperties = Montage.create(ToolProperties, { +var ShapeProperties = exports.ShapeProperties = Montage.create(ToolProperties, { toolsData: { value: null }, - _use3D: { value: false }, + _use3D: { value: false }, + addedColorChips: { value: false }, + + _fill: { + enumerable: false, + value: { colorMode: 'rgb', color: { r: 255, g: 255, b: 255, a: 1, css: 'rgb(255,255,255)', mode: 'rgb', wasSetByCode: true, type: 'change' }, webGlColor: [1, 1, 1, 1] } + //this._fillColorCtrl.color('nocolor', null); + }, + + _stroke: { + enumerable: false, + value: { colorMode: 'rgb', color: { r: 0, g: 0, b: 0, a: 1, css: 'rgb(0,0,0)', mode: 'rgb', wasSetByCode: true, type: 'change' }, webGlColor: [0, 0, 0, 1] } + }, + + stroke: { + enumerable: true, + get: function () { + return this._stroke; + }, + set: function (value) { + if (value !== this._stroke) { + this._stroke = value; + } + } + }, + + fill: { + enumerable: true, + get: function () { + return this._fill; + }, + set: function (value) { + if (value !== this._fill) { + this._fill = value; + } + } + }, + + draw: { + enumerable: false, + value: function () { + Object.getPrototypeOf(ShapeProperties).draw.call(this); + + if (this.addedColorChips === false && this.application.ninja.colorController.colorPanelDrawn) { + // setup fill color + this._fillColorCtrl.props = { side: 'top', align: 'center', wheel: true, palette: true, gradient: false, image: false, nocolor: true, offset: -80 }; + this.application.ninja.colorController.addButton("chip", this._fillColorCtrl); + + // setup stroke color + this._strokeColorCtrl.props = { side: 'top', align: 'center', wheel: true, palette: true, gradient: false, image: false, nocolor: true, offset: -80 }; + this.application.ninja.colorController.addButton("chip", this._strokeColorCtrl); + + this._fillColorCtrl.addEventListener("change", this.handleFillColorChange.bind(this), false); + this._strokeColorCtrl.addEventListener("change", this.handleStrokeColorChange.bind(this), false); + + this.addedColorChips = true; + } + + if (this.addedColorChips) { + this._fillColorCtrl.color(this._fill.colorMode, this._fill.color); + this._strokeColorCtrl.color(this._stroke.colorMode, this._stroke.color); + } + } + }, _subPrepare: { - value: function() { + value: function () { this.rectProperties.visible = true; Object.defineBinding(this._strokeMaterial, "items", { @@ -33,21 +96,32 @@ exports.ShapeProperties = Montage.create(ToolProperties, { } }, - _selectedSubTool: { value: null, enumerable: false}, + _selectedSubTool: { value: null, enumerable: false }, - selectedSubTool : { - get: function() { return this._selectedSubTool;}, - set: function(value) { - if(value) { + selectedSubTool: { + get: function () { return this._selectedSubTool; }, + set: function (value) { + if (value) { - this._selectedSubTool? this[this._selectedSubTool.properties].visible = false : this.rectProperties.visible = false; + this._selectedSubTool ? this[this._selectedSubTool.properties].visible = false : this.rectProperties.visible = false; this._selectedSubTool = value; this[this._selectedSubTool.properties].visible = true; - if(this._useWebGL.checked) - { - if(this._selectedSubTool.id === "LineTool") { + if (this._selectedSubTool.id === "LineTool") { + this._fillColorCtrl.style["display"] = "none"; + this._fillColorCtrl.visible = false; + this._fillColorCtrlIcon.style["display"] = "none"; + this._fillColorCtrlIcon.visible = false; + } else { + this._fillColorCtrl.style["display"] = ""; + this._fillColorCtrl.visible = true; + this._fillColorCtrlIcon.style["display"] = ""; + this._fillColorCtrlIcon.visible = true; + } + + if (this._useWebGL.checked) { + if (this._selectedSubTool.id === "LineTool") { this._fillIcon.style["display"] = "none"; this._fillMaterial.visible = false; } else { @@ -55,27 +129,23 @@ exports.ShapeProperties = Montage.create(ToolProperties, { this._fillMaterial.visible = true; } } - } } }, handleChange: { - value: function(event) { - if(this._useWebGL.checked) - { + value: function (event) { + if (this._useWebGL.checked) { this._use3D = true; this._materialLabel.style["display"] = ""; this._strokeIcon.style["display"] = ""; this._strokeMaterial.visible = true; - if(this.selectedSubTool.id !== "LineTool") - { + if (this.selectedSubTool.id !== "LineTool") { this._fillIcon.style["display"] = ""; this._fillMaterial.visible = true; } } - else - { + else { this._use3D = false; this._materialLabel.style["display"] = "none"; this._strokeIcon.style["display"] = "none"; @@ -84,6 +154,19 @@ exports.ShapeProperties = Montage.create(ToolProperties, { this._fillMaterial.visible = false; } } - } + }, + handleFillColorChange: { + value: function (e) { + this.fill = e._event; + this.fill.webGlColor = this.application.ninja.colorController.colorModel.colorToWebGl(e._event.color); + } + }, + + handleStrokeColorChange: { + value: function (e) { + this.stroke = e._event; + this.stroke.webGlColor = this.application.ninja.colorController.colorModel.colorToWebGl(e._event.color); + } + } }); diff --git a/js/components/tools-properties/text-properties.reel/text-properties.html b/js/components/tools-properties/text-properties.reel/text-properties.html index 03786d76..23de2bca 100755 --- a/js/components/tools-properties/text-properties.reel/text-properties.html +++ b/js/components/tools-properties/text-properties.reel/text-properties.html @@ -21,7 +21,7 @@ "fontSelection": {"@": "fontSelection"}, "fontSettings": {"@": "fontSettings"}, "fontSize": {"@": "fontSize"}, - "fontColor": {"@": "fontColor"}, + "fontColor": {"#": "fontColorCtrl"}, "btnBold": {"@": "btnBold"}, "btnItalic": {"@": "btnItalic"}, "btnUnderline": {"@": "btnUnderline"}, @@ -306,7 +306,7 @@ -
+
diff --git a/js/components/tools-properties/text-properties.reel/text-properties.js b/js/components/tools-properties/text-properties.reel/text-properties.js index 88d38ffe..fa2ec066 100755 --- a/js/components/tools-properties/text-properties.reel/text-properties.js +++ b/js/components/tools-properties/text-properties.reel/text-properties.js @@ -202,7 +202,6 @@ exports.TextProperties = Montage.create(ToolProperties, { if (!this.initialized) { //Setup Font Selection tool - this.fontColor = this.element.getElementsByClassName("fontColor")[0]; this.fontColor.props = {side: 'top', align: 'center', wheel: true, palette: true, gradient: false, image: false, nocolor: true, offset: -80}; this.application.ninja.colorController.addButton("chip", this.fontColor); this.fontColor.color('rgb', {wasSetByCode: true, type: 'change', color: {r: 0, g: 0, b: 0}, css: 'rgb(0,0,0)'}); diff --git a/js/panels/color/colorpanelbase.reel/colorpanelbase.js b/js/panels/color/colorpanelbase.reel/colorpanelbase.js index af62dd07..64cdc360 100755 --- a/js/panels/color/colorpanelbase.reel/colorpanelbase.js +++ b/js/panels/color/colorpanelbase.reel/colorpanelbase.js @@ -15,35 +15,35 @@ var Montage = require("montage/core/core").Montage, //////////////////////////////////////////////////////////////////////// //Exporting as ColorPanelBase exports.ColorPanelBase = Montage.create(Component, { - //////////////////////////////////////////////////////////////////// - // - hasTemplate: { + //////////////////////////////////////////////////////////////////// + // + hasTemplate: { value: true }, //////////////////////////////////////////////////////////////////// //Storing ColorPanel sliders mode _panelMode: { - enumerable: false, - value: 'rgb' + enumerable: false, + value: 'rgb' }, //////////////////////////////////////////////////////////////////// //Storing ColorPanel sliders mode panelMode: { - enumerable: true, - get: function() { + enumerable: true, + get: function () { return this._panelMode; }, - set: function(value) { - if (value !== this._panelMode) { - this._panelMode = value; - } + set: function (value) { + if (value !== this._panelMode) { + this._panelMode = value; + } } }, //////////////////////////////////////////////////////////////////// // _colorBar: { - enumerable: false, - value: null + enumerable: false, + value: null }, //////////////////////////////////////////////////////////////////// //Storing color manager @@ -54,19 +54,19 @@ exports.ColorPanelBase = Montage.create(Component, { //////////////////////////////////////////////////////////////////// // colorManager: { - enumerable: true, - get: function() { + enumerable: true, + get: function () { return this._colorManager; }, - set: function(value) { - if (value !== this._colorManager) { - this._colorManager = value; - //Updating input buttons - this._colorManager.addEventListener('change', this._update.bind(this)); - this._colorManager.addEventListener('changing', this._update.bind(this)); - //Updating history buttons once color is set - this._colorManager.addEventListener('change', this._updateHistoryButtons.bind(this)); - } + set: function (value) { + if (value !== this._colorManager) { + this._colorManager = value; + //Updating input buttons + this._colorManager.addEventListener('change', this._update.bind(this)); + this._colorManager.addEventListener('changing', this._update.bind(this)); + //Updating history buttons once color is set + this._colorManager.addEventListener('change', this._updateHistoryButtons.bind(this)); + } } }, //////////////////////////////////////////////////////////////////// @@ -78,50 +78,50 @@ exports.ColorPanelBase = Montage.create(Component, { //////////////////////////////////////////////////////////////////// // _combo: { - enumerable: false, - value: [{slider: null, hottext: null}, {slider: null, hottext: null}, {slider: null, hottext: null}, {slider: null, hottext: null}] + enumerable: false, + value: [{ slider: null, hottext: null }, { slider: null, hottext: null }, { slider: null, hottext: null }, { slider: null, hottext: null}] }, //////////////////////////////////////////////////////////////////// // _buttons: { - enumerable: false, - value: {chip: [], fill: [], stroke: [], current: [], previous: [], rgbmode: [], hslmode: [], hexinput: [], nocolor: [], reset: [], swap: [], mlabel1: [], mlabel2: [], mlabel3: []} + enumerable: false, + value: { chip: [], fill: [], stroke: [], current: [], previous: [], rgbmode: [], hslmode: [], hexinput: [], nocolor: [], reset: [], swap: [], mlabel1: [], mlabel2: [], mlabel3: [] } }, //////////////////////////////////////////////////////////////////// // historyCache: { - enumerable: false, - value: {current: null, previous: null} + enumerable: false, + value: { current: null, previous: null } }, //////////////////////////////////////////////////////////////////// // colorChipProps: { - enumerable: true, - value: {side: 'top', align: 'center', wheel: true, palette: true, gradient: true, image: true, panel: false} + enumerable: true, + value: { side: 'top', align: 'center', wheel: true, palette: true, gradient: true, image: true, panel: false } }, //////////////////////////////////////////////////////////////////// // currentChip: { - enumerable: true, - value: null + enumerable: true, + value: null }, //////////////////////////////////////////////////////////////////// // previousInput: { - enumerable: true, - value: null + enumerable: true, + value: null }, //////////////////////////////////////////////////////////////////// //Setting up elements/components prepareForDraw: { - enumerable: false, - value: function() { - //TODO: Remove temporary hack, color history should be initilized + enumerable: false, + value: function () { + //TODO: Remove temporary hack, color history should be initilized this.addEventListener('firstDraw', this, false); this.application.ninja.colorController.colorView = this; - this.colorManager.colorHistory.fill = [{m: 'nocolor', c: {}, a: 1}]; - this.colorManager.colorHistory.stroke = [{m: 'nocolor', c: {}, a: 1}]; - } + this.colorManager.colorHistory.fill = [{ m: 'nocolor', c: {}, a: 1}]; + this.colorManager.colorHistory.stroke = [{ m: 'nocolor', c: {}, a: 1}]; + } }, handleFirstDraw: { @@ -131,1521 +131,1526 @@ exports.ColorPanelBase = Montage.create(Component, { this.application.ninja.colorController.createToolbar(); this.applyDefaultColors(); this.removeEventListener('firstDraw', this, false); + + // Workaround for delaying subtool colorchip creation until the color panel is initialized. + // This can be removed and the subtools must be updated once we create a new view for color buttons + // and they no longer rely on the view of the color panel. + this.application.ninja.colorController.colorPanelDrawn = true; } }, //////////////////////////////////////////////////////////////////// //Assigning values and binding willDraw: { - enumerable: false, - value: function() { - //////////////////////////////////////////////////////////// - //TODO: remove ID dependencies - createCombo(this._combo[0], "cp_slider1", "cp_hottext1", true, this.element); - createCombo(this._combo[1], "cp_slider2", "cp_hottext2", true, this.element); - createCombo(this._combo[2], "cp_slider3", "cp_hottext3", true, this.element); - createCombo(this._combo[3], "cp_slider4", "cp_hottext4", false, this.element); - //////////////////////////////////////////////////////////// - //Function to create slider/hottext combination - function createCombo (c, slid, htid, color, e) { - //Only creating, not drawing - c.slider = Slider.create(); - c.hottext = HotText.create(); - c.slider.element = e.getElementsByClassName(slid)[0]; - c.hottext.element = e.getElementsByClassName(htid)[0]; - c.slider.changesColor = c.hottext.changesColor = color; - c.slider.cInputType = 'slider'; - c.slider.cInputType = 'hottext'; - //Binding Hottext to Slider - Object.defineBinding(c.hottext, "value", { - boundObject: c.slider, - boundObjectPropertyPath: "_value", //TODO: Check if needed - oneway: false, - boundValueMutator: function(value) { - return Math.round(value); + enumerable: false, + value: function () { + //////////////////////////////////////////////////////////// + //TODO: remove ID dependencies + createCombo(this._combo[0], "cp_slider1", "cp_hottext1", true, this.element); + createCombo(this._combo[1], "cp_slider2", "cp_hottext2", true, this.element); + createCombo(this._combo[2], "cp_slider3", "cp_hottext3", true, this.element); + createCombo(this._combo[3], "cp_slider4", "cp_hottext4", false, this.element); + //////////////////////////////////////////////////////////// + //Function to create slider/hottext combination + function createCombo(c, slid, htid, color, e) { + //Only creating, not drawing + c.slider = Slider.create(); + c.hottext = HotText.create(); + c.slider.element = e.getElementsByClassName(slid)[0]; + c.hottext.element = e.getElementsByClassName(htid)[0]; + c.slider.changesColor = c.hottext.changesColor = color; + c.slider.cInputType = 'slider'; + c.slider.cInputType = 'hottext'; + //Binding Hottext to Slider + Object.defineBinding(c.hottext, "value", { + boundObject: c.slider, + boundObjectPropertyPath: "_value", //TODO: Check if needed + oneway: false, + boundValueMutator: function (value) { + return Math.round(value); } - }); - //Binding Slider to Hottext - Object.defineBinding(c.slider, "value", { - boundObject: c.hottext, - boundObjectPropertyPath: "value", - oneway: false, - boundValueMutator: function(value) { + }); + //Binding Slider to Hottext + Object.defineBinding(c.slider, "value", { + boundObject: c.hottext, + boundObjectPropertyPath: "value", + oneway: false, + boundValueMutator: function (value) { return Math.round(value); } - }); - } - //////////////////////////////////////////////////////////// - //Creating ColorBar and sending color manager - this._colorBar = ColorBar.create(); - this._colorBar.element = this.element.getElementsByClassName("cp_spectrum")[0]; - //////////////////////////////////////////////////////////// - //Adding/Initializing buttons - this.addButton('fill', this.element.getElementsByClassName('cpe_fill')[0]); - this.addButton('fillicon', this.element.getElementsByClassName('cpe_fill_icon')[0]); - this.addButton('stroke', this.element.getElementsByClassName('cpe_stroke')[0]); - this.addButton('strokeicon', this.element.getElementsByClassName('cpe_stroke_icon')[0]); - - this.addButton('current', this.element.getElementsByClassName('cp_color_current')[0]); - this.addButton('previous', this.element.getElementsByClassName('cp_color_previous')[0]); - - this.addButton('hexinput', this.element.getElementsByClassName('cp_hottext5')[0]); - this.addButton('reset', this.element.getElementsByClassName('cp_reset')[0]); - this.addButton('nocolor', this.element.getElementsByClassName('cp_nocolor')[0]); - this.addButton('swap', this.element.getElementsByClassName('cp_swap')[0]); - - //TODO: Add HSL mode when Chrome can pass proper mode in color, also add in CSS button states - //this.addButton('hslmode', this.element.getElementsByClassName('cp_hsl_mode')[0]); - this.addButton('rgbmode', this.element.getElementsByClassName('cp_rgb_mode')[0]); - - this.addButton('mlabel1', this.element.getElementsByClassName('sh_label1')[0]); - this.addButton('mlabel2', this.element.getElementsByClassName('sh_label2')[0]); - this.addButton('mlabel3', this.element.getElementsByClassName('sh_label3')[0]); - - - - //Initialing values of sliders according to current mode - if (this._panelMode === 'rgb') { - this._combo[0].slider.maxValue = this._combo[0].hottext.maxValue = 255; - this._combo[1].slider.maxValue = this._combo[1].hottext.maxValue = 255; - this._combo[2].slider.maxValue = this._combo[2].hottext.maxValue = 255; - } else if (this._panelMode === 'hsl') { - this._combo[0].slider.maxValue = this._combo[0].hottext.maxValue = 360; - this._combo[1].slider.maxValue = this._combo[1].hottext.maxValue = 100; - this._combo[2].slider.maxValue = this._combo[2].hottext.maxValue = 100; - } - //Alpha slider/hottext is indepenent of color panel mode - this._combo[3].slider.maxValue = this._combo[3].hottext.maxValue = 100; - } + }); + } + //////////////////////////////////////////////////////////// + //Creating ColorBar and sending color manager + this._colorBar = ColorBar.create(); + this._colorBar.element = this.element.getElementsByClassName("cp_spectrum")[0]; + //////////////////////////////////////////////////////////// + //Adding/Initializing buttons + this.addButton('fill', this.element.getElementsByClassName('cpe_fill')[0]); + this.addButton('fillicon', this.element.getElementsByClassName('cpe_fill_icon')[0]); + this.addButton('stroke', this.element.getElementsByClassName('cpe_stroke')[0]); + this.addButton('strokeicon', this.element.getElementsByClassName('cpe_stroke_icon')[0]); + + this.addButton('current', this.element.getElementsByClassName('cp_color_current')[0]); + this.addButton('previous', this.element.getElementsByClassName('cp_color_previous')[0]); + + this.addButton('hexinput', this.element.getElementsByClassName('cp_hottext5')[0]); + this.addButton('reset', this.element.getElementsByClassName('cp_reset')[0]); + this.addButton('nocolor', this.element.getElementsByClassName('cp_nocolor')[0]); + this.addButton('swap', this.element.getElementsByClassName('cp_swap')[0]); + + //TODO: Add HSL mode when Chrome can pass proper mode in color, also add in CSS button states + //this.addButton('hslmode', this.element.getElementsByClassName('cp_hsl_mode')[0]); + this.addButton('rgbmode', this.element.getElementsByClassName('cp_rgb_mode')[0]); + + this.addButton('mlabel1', this.element.getElementsByClassName('sh_label1')[0]); + this.addButton('mlabel2', this.element.getElementsByClassName('sh_label2')[0]); + this.addButton('mlabel3', this.element.getElementsByClassName('sh_label3')[0]); + + + + //Initialing values of sliders according to current mode + if (this._panelMode === 'rgb') { + this._combo[0].slider.maxValue = this._combo[0].hottext.maxValue = 255; + this._combo[1].slider.maxValue = this._combo[1].hottext.maxValue = 255; + this._combo[2].slider.maxValue = this._combo[2].hottext.maxValue = 255; + } else if (this._panelMode === 'hsl') { + this._combo[0].slider.maxValue = this._combo[0].hottext.maxValue = 360; + this._combo[1].slider.maxValue = this._combo[1].hottext.maxValue = 100; + this._combo[2].slider.maxValue = this._combo[2].hottext.maxValue = 100; + } + //Alpha slider/hottext is indepenent of color panel mode + this._combo[3].slider.maxValue = this._combo[3].hottext.maxValue = 100; + } }, //////////////////////////////////////////////////////////////////// //Drawing elements/components draw: { - enumerable: false, - value: function() { - //////////////////////////////////////////////////////////// - //Drawing slider/hottext combinations - for (var i=0; i 1) { - // - prev = this.colorManager.colorHistory[input][this.colorManager.colorHistory[input].length-2]; - alpha = prev.a; - // - cvs = this._buttons.previous[i].getElementsByTagName('canvas')[0]; - ctx = cvs.getContext('2d'); - ctx.clearRect(0, 0, cvs.width, cvs.height); - // - this._buttons.previous[i].style.background = 'none'; - this._buttons.previous[i].style.backgroundImage = 'none'; - this._buttons.previous[i].style.backgroundColor = 'none'; - // - switch (prev.m) { - case 'hsv': - hsv = prev.c; - color = this.colorManager.hsvToRgb(hsv.h/(Math.PI*2), hsv.s, hsv.v); - this._buttons.previous[i].style.backgroundColor = this.historyCache.previous = 'rgba('+color.r+', '+color.g+', '+color.b+', '+alpha+')'; - break; - case 'hsl': - color = prev.c; - this._buttons.previous[i].style.backgroundColor = this.historyCache.previous = 'hsla('+color.h+', '+color.s+'%, '+color.l+'%, '+alpha+')'; - break; - case 'rgb': - color = prev.c; - this._buttons.previous[i].style.backgroundColor = this.historyCache.previous = 'rgba('+color.r+', '+color.g+', '+color.b+', '+alpha+')'; - break; - case 'hex': - this._buttons.previous[i].style.backgroundColor = this.historyCache.previous = prev.c.hex; - break; - case 'gradient': - this._buttons.previous[i].style.backgroundImage = this.historyCache.previous = prev.c.value.css; - break; - case 'nocolor': - ctx.beginPath(); - ctx.moveTo(0, cvs.height); - ctx.lineTo(cvs.width, 0); - ctx.lineWidth = 16; - ctx.strokeStyle = "#FF0000"; - ctx.stroke(); - this._buttons.previous[i].style.backgroundColor = 'white'; - this.historyCache.previous = 'nocolor'; - break; - default: - this._buttons.previous[i].style.backgroundColor = this.historyCache.previous = 'transparent'; - this._buttons.previous[i].style.backgroundImage = this.historyCache.previous = 'transparent'; - break; - } - } else { - this._buttons.previous[i].style.backgroundColor = this.historyCache.previous = 'transparent'; - this._buttons.previous[i].style.backgroundImage = this.historyCache.previous = 'transparent'; - } - } - } + enumerable: false, + value: function (e) { + //Locals + var bg = 'none', img, i, input = this.colorManager.input.toLowerCase(), color, hsv, mode = e._event.mode, prev, alpha, ctx, cvs; + if (input === 'chip') { + return; + } + //Creating background color string according to panel mode (not input color mode) + if (mode === 'hsv' || mode === 'hsl' || mode === 'rgb' || mode === 'hex' || mode === 'alpha') { + if (this.panelMode === 'rgb' && e._event.rgba) { + color = e._event.rgba; + bg = 'rgba(' + color.r + ', ' + color.g + ', ' + color.b + ', ' + color.a + ')'; + } else if (this.panelMode === 'hsl' && e._event.hsla) { + color = e._event.hsla; + bg = 'hsla(' + color.h + ', ' + color.s + '%, ' + color.l + '%, ' + color.a + ')'; + } else { + bg = 'nocolor'; + } + color = null; + for (i = 0; this._buttons.current[i]; i++) { + cvs = this._buttons.current[i].getElementsByTagName('canvas')[0]; + ctx = cvs.getContext('2d'); + ctx.clearRect(0, 0, cvs.width, cvs.height); + this._buttons.current[i].style.backgroundColor = bg; + this._buttons.current[i].style.backgroundImage = 'none'; + } + } else if (mode === 'gradient') { + // + color = e._event.value; + bg = e._event.value.value.css; + for (i = 0; this._buttons.current[i]; i++) { + cvs = this._buttons.current[i].getElementsByTagName('canvas')[0]; + ctx = cvs.getContext('2d'); + ctx.clearRect(0, 0, cvs.width, cvs.height); + this._buttons.current[i].style.background = 'none'; + this._buttons.current[i].style.backgroundColor = 'none'; + this._buttons.current[i].style.backgroundImage = bg; + } + } else { + // + bg = 'nocolor'; + for (i = 0; this._buttons.current[i]; i++) { + //TODO: combine no color into one reusable funtion + cvs = this._buttons.current[i].getElementsByTagName('canvas')[0]; + ctx = cvs.getContext('2d'); + ctx.clearRect(0, 0, cvs.width, cvs.height); + ctx.beginPath(); + ctx.moveTo(0, cvs.height); + ctx.lineTo(cvs.width, 0); + ctx.lineWidth = 16; + ctx.strokeStyle = "#FF0000"; + ctx.stroke(); + this._buttons.current[i].style.backgroundColor = 'white'; + this._buttons.current[i].style.backgroundImage = 'none'; + } + } + this.historyCache.current = bg; + //Using history of input type to set colors of 'previous' buttons + for (i = 0; this._buttons.previous[i]; i++) { + // + if (this.colorManager.colorHistory[input].length > 1) { + // + prev = this.colorManager.colorHistory[input][this.colorManager.colorHistory[input].length - 2]; + alpha = prev.a; + // + cvs = this._buttons.previous[i].getElementsByTagName('canvas')[0]; + ctx = cvs.getContext('2d'); + ctx.clearRect(0, 0, cvs.width, cvs.height); + // + this._buttons.previous[i].style.background = 'none'; + this._buttons.previous[i].style.backgroundImage = 'none'; + this._buttons.previous[i].style.backgroundColor = 'none'; + // + switch (prev.m) { + case 'hsv': + hsv = prev.c; + color = this.colorManager.hsvToRgb(hsv.h / (Math.PI * 2), hsv.s, hsv.v); + this._buttons.previous[i].style.backgroundColor = this.historyCache.previous = 'rgba(' + color.r + ', ' + color.g + ', ' + color.b + ', ' + alpha + ')'; + break; + case 'hsl': + color = prev.c; + this._buttons.previous[i].style.backgroundColor = this.historyCache.previous = 'hsla(' + color.h + ', ' + color.s + '%, ' + color.l + '%, ' + alpha + ')'; + break; + case 'rgb': + color = prev.c; + this._buttons.previous[i].style.backgroundColor = this.historyCache.previous = 'rgba(' + color.r + ', ' + color.g + ', ' + color.b + ', ' + alpha + ')'; + break; + case 'hex': + this._buttons.previous[i].style.backgroundColor = this.historyCache.previous = prev.c.hex; + break; + case 'gradient': + this._buttons.previous[i].style.backgroundImage = this.historyCache.previous = prev.c.value.css; + break; + case 'nocolor': + ctx.beginPath(); + ctx.moveTo(0, cvs.height); + ctx.lineTo(cvs.width, 0); + ctx.lineWidth = 16; + ctx.strokeStyle = "#FF0000"; + ctx.stroke(); + this._buttons.previous[i].style.backgroundColor = 'white'; + this.historyCache.previous = 'nocolor'; + break; + default: + this._buttons.previous[i].style.backgroundColor = this.historyCache.previous = 'transparent'; + this._buttons.previous[i].style.backgroundImage = this.historyCache.previous = 'transparent'; +