aboutsummaryrefslogtreecommitdiff
path: root/js/components/colorbar.reel/colorbar.js
diff options
context:
space:
mode:
authorJonathan Duran2012-07-17 09:30:22 -0700
committerJonathan Duran2012-07-17 09:30:22 -0700
commit53051672a62208fbc96957719d8285fac6431ed6 (patch)
tree79d542ee811044e8af2ef84aa0d6662c6eb895c4 /js/components/colorbar.reel/colorbar.js
parent7e2c2dbd040ed79a3f0678f91bd4b6db9cf69231 (diff)
parent5146f224258929415adf4a8022e492454b4e2476 (diff)
downloadninja-53051672a62208fbc96957719d8285fac6431ed6.tar.gz
Merge branch 'refs/heads/NINJA-master' into TimelineUber
Conflicts: js/panels/Timeline/DragDrop.js js/panels/Timeline/Keyframe.reel/Keyframe.js js/panels/Timeline/Layer.reel/Layer.js js/panels/Timeline/PropertyTrack.reel/PropertyTrack.js js/panels/Timeline/Span.reel/Span.js js/panels/Timeline/Style.reel/Style.js js/panels/Timeline/TimelinePanel.reel/TimelinePanel.js js/panels/Timeline/TimelineTrack.reel/TimelineTrack.js js/panels/Timeline/Track.reel/Track.html js/panels/Timeline/Track.reel/Track.js js/panels/Timeline/Track.reel/css/Track.css js/panels/Timeline/TrackSpacer.reel/TrackSpacer.html js/panels/Timeline/TrackSpacer.reel/TrackSpacer.js js/panels/Timeline/TrackSpacer.reel/css/TrackSpacer.css js/panels/Timeline/Tween.reel/Tween.js Signed-off-by: Jonathan Duran <jduran@motorola.com>
Diffstat (limited to 'js/components/colorbar.reel/colorbar.js')
-rwxr-xr-xjs/components/colorbar.reel/colorbar.js259
1 files changed, 130 insertions, 129 deletions
diff --git a/js/components/colorbar.reel/colorbar.js b/js/components/colorbar.reel/colorbar.js
index 4f3577d9..524f3c55 100755
--- a/js/components/colorbar.reel/colorbar.js
+++ b/js/components/colorbar.reel/colorbar.js
@@ -1,24 +1,25 @@
1/* <copyright> 1/* <copyright>
2Copyright (c) 2012, Motorola Mobility, Inc 2Copyright (c) 2012, Motorola Mobility LLC.
3All Rights Reserved. 3All Rights Reserved.
4BSD License.
5 4
6Redistribution and use in source and binary forms, with or without 5Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met: 6modification, are permitted provided that the following conditions are met:
8 7
9 - Redistributions of source code must retain the above copyright notice, 8* Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer. 9 this list of conditions and the following disclaimer.
11 - Redistributions in binary form must reproduce the above copyright 10
12 notice, this list of conditions and the following disclaimer in the 11* Redistributions in binary form must reproduce the above copyright notice,
13 documentation and/or other materials provided with the distribution. 12 this list of conditions and the following disclaimer in the documentation
14 - Neither the name of Motorola Mobility nor the names of its contributors 13 and/or other materials provided with the distribution.
15 may be used to endorse or promote products derived from this software 14
16 without specific prior written permission. 15* Neither the name of Motorola Mobility LLC nor the names of its
16 contributors may be used to endorse or promote products derived from this
17 software without specific prior written permission.
17 18
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
@@ -30,152 +31,152 @@ POSSIBILITY OF SUCH DAMAGE.
30 31
31//////////////////////////////////////////////////////////////////////// 32////////////////////////////////////////////////////////////////////////
32// 33//
33var Montage = require("montage/core/core").Montage, 34var Montage = require("montage/core/core").Montage,
34 Component = require("montage/ui/component").Component; 35 Component = require("montage/ui/component").Component;
35//////////////////////////////////////////////////////////////////////// 36////////////////////////////////////////////////////////////////////////
36//Exporting as ColorBar 37//Exporting as ColorBar
37exports.ColorBar = Montage.create(Component, { 38exports.ColorBar = Montage.create(Component, {
38 //////////////////////////////////////////////////////////////////// 39 ////////////////////////////////////////////////////////////////////
39 //No reel needed since it's just a bar component 40 //No reel needed since it's just a bar component
40 hasTemplate: { 41 hasTemplate: {
41 value: true 42 value: true
42 }, 43 },
43 //////////////////////////////////////////////////////////////////// 44 ////////////////////////////////////////////////////////////////////
44 //Width of spectrum (not including b/w buttons) 45 //Width of spectrum (not including b/w buttons)
45 _colorBarSpectrumWidth: { 46 _colorBarSpectrumWidth: {
46 value: null 47 value: null
47 }, 48 },
48 //////////////////////////////////////////////////////////////////// 49 ////////////////////////////////////////////////////////////////////
49 //Width of spectrum steps (used to calculate size of B/W buttons) 50 //Width of spectrum steps (used to calculate size of B/W buttons)
50 _colorBarSpectrumWidthSteps: { 51 _colorBarSpectrumWidthSteps: {
51 value: 10 52 value: 10
52 }, 53 },
53 //////////////////////////////////////////////////////////////////// 54 ////////////////////////////////////////////////////////////////////
54 //Default value 55 //Default value
55 _value: { 56 _value: {
56 value: {h: 0, s: 0, v: 0} 57 value: {h: 0, s: 0, v: 0}
57 }, 58 },
58 //////////////////////////////////////////////////////////////////// 59 ////////////////////////////////////////////////////////////////////
59 //HSV Value selected from bar 60 //HSV Value selected from bar
60 value: { 61 value: {
61 get: function() {return this._value;}, 62 get: function() {return this._value;},
62 set: function(value) { 63 set: function(value) {
63 if (value) { 64 if (value) {
64 //Checking for limits (Max and Min HSV values) 65 //Checking for limits (Max and Min HSV values)
65 if (value.h > Math.PI*2) { 66 if (value.h > Math.PI*2) {
66 value.h = Math.PI*2; 67 value.h = Math.PI*2;
67 } else if (value.h < 0) { 68 } else if (value.h < 0) {
68 value.h = 0; 69 value.h = 0;
69 } 70 }
70 // 71 //
71 if (value.s > 1) { 72 if (value.s > 1) {
72 value.s = 1; 73 value.s = 1;
73 } else if (value.s < 0) { 74 } else if (value.s < 0) {
74 value.s = 0; 75 value.s = 0;
75 } 76 }
76 // 77 //
77 if (value.v > 1) { 78 if (value.v > 1) {
78 value.v = 1; 79 value.v = 1;
79 } else if (value.v < 0) { 80 } else if (value.v < 0) {
80 value.v = 0; 81 value.v = 0;
81 } 82 }
82 //Setting value 83 //Setting value
83 this._value = value; 84 this._value = value;
84 // 85 //
85 if (!this._isMouseDown) { 86 if (!this._isMouseDown) {
86 this._dispatchActionEvent('change', true); 87 this._dispatchActionEvent('change', true);
87 } 88 }
88 } 89 }
89 } 90 }
90 }, 91 },
91 //////////////////////////////////////////////////////////////////// 92 ////////////////////////////////////////////////////////////////////
92 // 93 //
93 prepareForDraw: { 94 prepareForDraw: {
94 value: function() { 95 value: function() {
95 //Nothing 96 //Nothing
96 } 97 }
97 }, 98 },
98 //////////////////////////////////////////////////////////////////// 99 ////////////////////////////////////////////////////////////////////
99 //Setting up and drawing canvas to object 100 //Setting up and drawing canvas to object
100 willDraw: { 101 willDraw: {
101 value: function() { 102 value: function() {
102 //Setting the width and height of the canvas to match container 103 //Setting the width and height of the canvas to match container
103 this.element.width = parseInt(window.getComputedStyle(this.element, null).width); 104 this.element.width = parseInt(window.getComputedStyle(this.element, null).width);
104 this.element.height = parseInt(window.getComputedStyle(this.element, null).height); 105 this.element.height = parseInt(window.getComputedStyle(this.element, null).height);
105 } 106 }
106 }, 107 },
107 //////////////////////////////////////////////////////////////////// 108 ////////////////////////////////////////////////////////////////////
108 // 109 //
109 draw: { 110 draw: {
110 value: function () { 111 value: function () {
111 //Local variables 112 //Local variables
112 var cb_canvas = this.element, cb_ctx, cb_grdnt, cb_slc, cb_gwidth, PI = Math.PI, i; 113 var cb_canvas = this.element, cb_ctx, cb_grdnt, cb_slc, cb_gwidth, PI = Math.PI, i;
113 //calculating width of spectrum (remainder is used for B/W buttons) 114 //calculating width of spectrum (remainder is used for B/W buttons)
114 cb_gwidth = Math.round(cb_canvas.width - cb_canvas.width/this._colorBarSpectrumWidthSteps); 115 cb_gwidth = Math.round(cb_canvas.width - cb_canvas.width/this._colorBarSpectrumWidthSteps);
115 //Context and Gradient 116 //Context and Gradient
116 cb_ctx = cb_canvas.getContext('2d'); 117 cb_ctx = cb_canvas.getContext('2d');
117 cb_grdnt = cb_ctx.createLinearGradient(0, cb_canvas.height, cb_gwidth, cb_canvas.height); 118 cb_grdnt = cb_ctx.createLinearGradient(0, cb_canvas.height, cb_gwidth, cb_canvas.height);
118 //////////////////////////////////////////////////////// 119 ////////////////////////////////////////////////////////
119 //Looping through set intervals (Creating spectrum) 120 //Looping through set intervals (Creating spectrum)
120 for (i=0; i<60; i++) { 121 for (i=0; i<60; i++) {
121 //Calculating slice number 122 //Calculating slice number
122 cb_slc = Math.round(255*i/60); 123 cb_slc = Math.round(255*i/60);
123 //Creating gradient slices (6 colors in color theory) 124 //Creating gradient slices (6 colors in color theory)
124 cb_grdnt.addColorStop(i/360, 'rgb(255, '+cb_slc+', 0)'); 125 cb_grdnt.addColorStop(i/360, 'rgb(255, '+cb_slc+', 0)');
125 cb_grdnt.addColorStop((i+60)/360, 'rgb('+(255-cb_slc)+', 255, 0)'); 126 cb_grdnt.addColorStop((i+60)/360, 'rgb('+(255-cb_slc)+', 255, 0)');
126 cb_grdnt.addColorStop((i+120)/360, 'rgb(0, 255, '+cb_slc+')'); 127 cb_grdnt.addColorStop((i+120)/360, 'rgb(0, 255, '+cb_slc+')');
127 cb_grdnt.addColorStop((i+180)/360, 'rgb(0, '+(255-cb_slc)+', 255)'); 128 cb_grdnt.addColorStop((i+180)/360, 'rgb(0, '+(255-cb_slc)+', 255)');
128 cb_grdnt.addColorStop((i+240)/360, 'rgb('+cb_slc+', 0, 255)'); 129 cb_grdnt.addColorStop((i+240)/360, 'rgb('+cb_slc+', 0, 255)');
129 cb_grdnt.addColorStop((i+300)/360, 'rgb(255, 0,'+(255-cb_slc)+')'); 130 cb_grdnt.addColorStop((i+300)/360, 'rgb(255, 0,'+(255-cb_slc)+')');
130 } 131 }
131 //Adding Color Bar to the canvas (Gradients) 132 //Adding Color Bar to the canvas (Gradients)
132 cb_ctx.fillStyle = cb_grdnt; 133 cb_ctx.fillStyle = cb_grdnt;
133 cb_ctx.fillRect(0, 0, cb_gwidth, cb_canvas.height); 134 cb_ctx.fillRect(0, 0, cb_gwidth, cb_canvas.height);