aboutsummaryrefslogtreecommitdiff
path: root/js/components/colorwheel.reel/colorwheel.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/components/colorwheel.reel/colorwheel.js')
-rwxr-xr-xjs/components/colorwheel.reel/colorwheel.js710
1 files changed, 355 insertions, 355 deletions
diff --git a/js/components/colorwheel.reel/colorwheel.js b/js/components/colorwheel.reel/colorwheel.js
index a7c70038..d2664f14 100755
--- a/js/components/colorwheel.reel/colorwheel.js
+++ b/js/components/colorwheel.reel/colorwheel.js
@@ -30,14 +30,14 @@ POSSIBILITY OF SUCH DAMAGE.
30 30
31//////////////////////////////////////////////////////////////////////// 31////////////////////////////////////////////////////////////////////////
32// 32//
33var Montage = require("montage/core/core").Montage, 33var Montage = require("montage/core/core").Montage,
34 Component = require("montage/ui/component").Component; 34 Component = require("montage/ui/component").Component;
35//////////////////////////////////////////////////////////////////////// 35////////////////////////////////////////////////////////////////////////
36// 36//
37exports.ColorWheel = Montage.create(Component, { 37exports.ColorWheel = Montage.create(Component, {
38 //////////////////////////////////////////////////////////////////// 38 ////////////////////////////////////////////////////////////////////
39 // 39 //
40 hasTemplate: { 40 hasTemplate: {
41 value: true 41 value: true
42 }, 42 },
43 //////////////////////////////////////////////////////////////////// 43 ////////////////////////////////////////////////////////////////////
@@ -45,7 +45,7 @@ exports.ColorWheel = Montage.create(Component, {
45 _value: { 45 _value: {
46 value: {h: 0, s: 0, v: 0} 46 value: {h: 0, s: 0, v: 0}
47 }, 47 },
48 //////////////////////////////////////////////////////////////////// 48 ////////////////////////////////////////////////////////////////////
49 //Value of wheel in HSV (360, 100, 100) 49 //Value of wheel in HSV (360, 100, 100)
50 value: { 50 value: {
51 get: function() { 51 get: function() {
@@ -54,463 +54,463 @@ exports.ColorWheel = Montage.create(Component, {
54 set: function(value) { 54 set: function(value) {
55 this._value = value; 55 this._value = value;
56 if (this._wheelData) { 56 if (this._wheelData) {
57 if (value && !value.wasSetByCode) { 57 if (value && !value.wasSetByCode) {
58 this.wheelSelectorAngle(value.h/this._math.TAU*360); 58 this.wheelSelectorAngle(value.h/this._math.TAU*360);
59 this.drawSwatchColor(value.h/this._math.TAU*360); 59 this.drawSwatchColor(value.h/this._math.TAU*360);
60 this.drawSwatchSelector(value.s*100, value.v*100); 60 this.drawSwatchSelector(value.s*100, value.v*100);
61 } 61 }
62 if (!this._isMouseDown) { 62 if (!this._isMouseDown) {
63 this._dispatchEvent('change', true); 63 this._dispatchEvent('change', true);
64 } 64 }
65 } 65 }
66 } 66 }
67 }, 67 },
68 //////////////////////////////////////////////////////////////////// 68 ////////////////////////////////////////////////////////////////////
69 //Stroke size of wheel 69 //Stroke size of wheel
70 _strokeWidth: { 70 _strokeWidth: {
71 value: 2 71 value: 2
72 }, 72 },
73 //////////////////////////////////////////////////////////////////// 73 ////////////////////////////////////////////////////////////////////
74 //Size must be set in digits and interpreted as pixel 74 //Size must be set in digits and interpreted as pixel
75 strokeWidth: { 75 strokeWidth: {
76 get: function() { 76 get: function() {
77 return this._strokeWidth; 77 return this._strokeWidth;
78 }, 78 },
79 set: function(value) { 79 set: function(value) {
80 this._strokeWidth = value; 80 this._strokeWidth = value;
81 } 81 }
82 }, 82 },
83 //////////////////////////////////////////////////////////////////// 83 ////////////////////////////////////////////////////////////////////
84 //Stroke color of wheel 84 //Stroke color of wheel
85 _strokeColor: { 85 _strokeColor: {
86 value: 'rgb(255, 255, 255)' 86 value: 'rgb(255, 255, 255)'
87 }, 87 },
88 //////////////////////////////////////////////////////////////////// 88 ////////////////////////////////////////////////////////////////////
89 //Stroke only apply to wheel rim 89 //Stroke only apply to wheel rim
90 strokeColor: { 90 strokeColor: {
91 get: function() { 91 get: function() {
92 return this._strokeColor; 92 return this._strokeColor;
93 }, 93 },
94 set: function(value) { 94 set: function(value) {
95 this._strokeColor = value; 95 this._strokeColor = value;
96 } 96 }
97 }, 97 },
98 //////////////////////////////////////////////////////////////////// 98 ////////////////////////////////////////////////////////////////////
99 //Width of the rim 99 //Width of the rim
100 _rimWidth: { 100 _rimWidth: {
101 value: 2 101 value: 2
102 }, 102 },
103 //////////////////////////////////////////////////////////////////// 103 ////////////////////////////////////////////////////////////////////
104 //Width must be set using digits interpreted as pixel 104 //Width must be set using digits interpreted as pixel
105 rimWidth: { 105 rimWidth: {
106 get: function() { 106 get: function() {
107 return this._rimWidth; 107 return this._rimWidth;
108 }, 108 },
109 set: function(value) { 109 set: function(value) {
110 this._rimWidth = value; 110 this._rimWidth = value;
111 } 111 }
112 }, 112 },
113 //////////////////////////////////////////////////////////////////// 113 ////////////////////////////////////////////////////////////////////
114 // 114 //
115 _math: { 115 _math: {
116 value: {PI: Math.PI, TAU: Math.PI*2, RADIANS: Math.PI/180} 116 value: {PI: Math.PI, TAU: Math.PI*2, RADIANS: Math.PI/180}
117 }, 117 },
118 //////////////////////////////////////////////////////////////////// 118 ////////////////////////////////////////////////////////////////////
119 // 119 //
120 prepareForDraw: { 120 prepareForDraw: {
121 value: function() { 121 value: function() {
122 //Hidding component while it is drawn 122 //Hidding component while it is drawn
123 this.element.style.opacity = 0; 123 this.element.style.opacity = 0;
124 } 124 }
125 }, 125 },
126 //////////////////////////////////////////////////////////////////// 126 ////////////////////////////////////////////////////////////////////
127 // 127 //
128 willDraw: { 128 willDraw: {
129 value: function() { 129 value: function() {
130 // 130 //
131 } 131 }
132 }, 132 },
133 //////////////////////////////////////////////////////////////////// 133 ////////////////////////////////////////////////////////////////////
134 // 134 //
135 draw: { 135 draw: {
136 value: function() { 136 value: function() {
137 // 137 //
138 var slice, i, whlctx = this.wheel.getContext("2d"); 138 var slice, i, whlctx = this.wheel.getContext("2d");
139 //Determing radius by smallest factor of width or height 139 //Determing radius by smallest factor of width or height
140 if (this.element.offsetWidth > this.element.offsetHeight) { 140 if (this.element.offsetWidth > this.element.offsetHeight) {
141 this._math.diameter = this.element.offsetWidth; 141 this._math.diameter = this.element.offsetWidth;
142 } else { 142 } else {
143 this._math.diameter = this.element.offsetHeight; 143 this._math.diameter = this.element.offsetHeight;
144 } 144 }
145 //Setting the radius from diameter 145 //Setting the radius from diameter
146 this._math.radius = this._math.diameter/2; 146 this._math.radius = this._math.diameter/2;
147 //Inner radius of wheel 147 //Inner radius of wheel
148 this._math.innerRadius = this._math.radius - this.rimWidth; 148 this._math.innerRadius = this._math.radius - this.rimWidth;
149 //Setting the widths and heights to match the container's 149 //Setting the widths and heights to match the container's
150 this.wheel.width = this.wheel.height = this.wheelSelect.width = this.wheelSelect.height = this.swatchSelect.width = this.swatchSelect.height = this._math.diameter; 150 this.wheel.width = this.wheel.height = this.wheelSelect.width = this.wheelSelect.height = this.swatchSelect.width = this.swatchSelect.height = this._math.diameter;
151 // 151 //
152 this._math.swatchLength = Math.floor((this._math.radius - this.rimWidth - this.strokeWidth*4) * Math.sin(45 * this._math.RADIANS) * 2); 152 this._math.swatchLength = Math.floor((this._math.radius - this.rimWidth - this.strokeWidth*4) * Math.sin(45 * this._math.RADIANS) * 2);
153 this._math.swatchPosition = Math.round(this._math.radius - (this._math.swatchLength/2))+this.strokeWidth* Math.sin(45 * this._math.RADIANS); 153 this._math.swatchPosition = Math.round(this._math.radius - (this._math.swatchLength/2))+this.strokeWidth* Math.sin(45 * this._math.RADIANS);
154 // 154 //
155 this.swatch.style.top = this.swatch.style.left = this._math.swatchPosition+'px'; 155 this.swatch.style.top = this.swatch.style.left = this._math.swatchPosition+'px';
156 //Clearing wheel for redraw 156 //Clearing wheel for redraw
157 whlctx.clearRect(0, 0, this._math.diameter, this._math.diameter); 157 whlctx.clearRect(0, 0, this._math.diameter, this._math.diameter);
158 //////////////////////////////////////////////////////////////// 158 ////////////////////////////////////////////////////////////////
159 //Drawing color wheel circle 159 //Drawing color wheel circle
160 whlctx.save(); 160 whlctx.save();
161 whlctx.beginPath(); 161 whlctx.beginPath();
162 whlctx.moveTo(0,0); 162 whlctx.moveTo(0,0);
163 whlctx.lineTo(this._math.diameter,0); 163 whlctx.lineTo(this._math.diameter,0);
164 whlctx.lineTo(this._math.diameter,this._math.diameter); 164 whlctx.lineTo(this._math.diameter,this._math.diameter);
165 whlctx.lineTo(0,this._math.diameter); 165 whlctx.lineTo(0,this._math.diameter);
166 whlctx.closePath(); 166 whlctx.closePath();
167 whlctx.clip(); 167 whlctx.clip();
168 whlctx.strokeStyle = 'rgba(0,0,0,0)'; 168 whlctx.strokeStyle = 'rgba(0,0,0,0)';
169 whlctx.lineCap = 'butt'; 169 whlctx.lineCap = 'butt';