1 /*=====================================================================*\
2 || ###################################################################
4 || # Copyright (c)2002-2010 Blue Static
6 || # This program is free software; you can redistribute it and/or modify
7 || # it under the terms of the GNU General Public License as published by
8 || # the Free Software Foundation; version 2 of the License.
10 || # This program is distributed in the hope that it will be useful, but
11 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 || # You should have received a copy of the GNU General Public License along
16 || # with this program; if not, write to the Free Software Foundation, Inc.,
17 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
18 || ###################################################################
19 \*=====================================================================*/
28 var backShowing_
= false;
30 // ###################################################################
35 createGenericButton(document
.getElementById("backbutton"), "Done", hide_back
, 0);
38 // ###################################################################
39 // watches the three RGB fields to make sure they don't go over the limites
40 function OnRGBChange(color
)
42 var field
= document
.getElementById(color
+ "input");
44 // Handle RGB triads that are pased into a single box.
45 if (triad
= field
.value
.match(/(rgb
)?\(?([0-9]{1,3}),\s
?([0-9]{1,3}),\s
?([0-9]{1,3})\)?/)) {
46 document
.getElementById("redinput").value
= triad
[2];
47 document
.getElementById("greeninput").value
= triad
[3];
48 document
.getElementById("blueinput").value
= triad
[4];
56 // sanitize the number
57 var newval
= field
.value
.replace(/[^0-9\-\.]*/g
, "");
58 newval
= Math
.floor(newval
);
60 // make sure we don't go over 255
63 } else if (newval
< 0) {
67 // update the text field
71 colors_
[color] = newval
;
80 // ###################################################################
83 var canvas
= document
.getElementById('wheel');
84 var context
= canvas
.getContext('2d');
85 var radius
= canvas
.width
/ 2 - 3;
86 var center
= [canvas
.width
/ 2, canvas
.height
/ 2];
87 context
.strokeStyle
= 'black';
89 context
.clearRect(0, 0, canvas
.width
, canvas
.height
);
92 // Draw dark baground gradient.
94 context
.arc(center
[0], center
[1], radius
, 0, Math
.PI
* 2, true);
95 var gradient
= context
.createLinearGradient(0, 0, 0, canvas
.height
);
96 gradient
.addColorStop(0, 'rgb(200, 200, 200)');
97 gradient
.addColorStop(1, 'rgb(30, 30, 30)');
98 context
.fillStyle
= gradient
;
104 // Draw the individual components. Start with red.
106 context
.moveTo(center
[0], center
[1]);
107 context
.arc(canvas
.width
/ 2,
113 context
.lineTo(center
[0], center
[1]);
114 context
.fillStyle
= _GetComponentColorString('red');
120 context
.moveTo(center
[0], center
[1]);
121 context
.arc(canvas
.width
/ 2,
127 context
.lineTo(center
[0], center
[1]);
128 context
.fillStyle
= _GetComponentColorString('green');
134 context
.moveTo(center
[0], center
[1]);
135 context
.arc(canvas
.width
/ 2,
141 context
.lineTo(center
[0], center
[1]);
142 context
.fillStyle
= _GetComponentColorString('blue');
146 // Draw the sheen gradient.
148 context
.arc(center
[0], center
[1], radius
, 0, Math
.PI
* 2, true);
149 var gradient
= context
.createLinearGradient(0, 0, 0, canvas
.height
);
150 gradient
.addColorStop(0, 'rgba(255,255,255,.5)');
151 gradient
.addColorStop(1, 'rgba(0,0,0,0)');
152 context
.fillStyle
= gradient
;
156 // Draw the inner wheel. WebKit in 10.6.5 (and maybe earlier) has a bug in
157 // which you can't fill a path after stroking it, or vice versa.
158 var _arc
= function(c
) {
159 c
.arc(center
[0], center
[1], canvas
.width
/ 4.75, 0, Math
.PI
* 2, true);
164 context
.strokeStyle
= 'rgb(30,30,30)';
169 context
.fillStyle
= _GetRGBColorString();
175 // ###################################################################
176 // Returns the rgb(,,,) color string.
178 function _GetRGBColorString()
180 return 'rgb(' + colors_
.red
+ ',' + colors_
.green
+ ',' + colors_
.blue
+ ')';
183 // ###################################################################
184 // Returns an individual color component's color string.
186 function _GetComponentColorString(color
)
188 if (color
== 'red') {
189 return 'rgb(' + colors_
.red
+ ',0,0)';
190 } else if (color
== 'green') {
191 return 'rgb(0,' + colors_
.green
+ ',0)';
192 } else if (color
== 'blue') {
193 return 'rgb(0,0,' + colors_
.blue
+ ')';
195 alert('Invalid color ' + color
);
198 // ###################################################################
199 // watches the hex field for updates
200 function OnHexChanged()
202 var field
= document
.getElementById("hexinput");
205 var newval
= field
.value
.replace(/[^0-9a
-f
]*/gi
, "");
208 var length
= newval
.length
;
212 newval
= newval
.substr(0, 6);
213 } else if (length
== 3) {
214 newval
= newval
.substr(0, 1) + newval
.substr(0, 1) +
215 newval
.substr(1, 1) + newval
.substr(1, 1) +
216 newval
.substr(2, 1) + newval
.substr(2, 1);
217 } else if (length
< 6) {
218 for (var i
= length
; i
<= 6; i
++) {
219 newval
= "" + newval
+ "0";
224 field
.value
= newval
;
227 colors_
.hex
= newval
;
236 // ###################################################################
237 // update the hex value
240 var hexstr
= _Dec2Hex(colors_
.red
) + _Dec2Hex(colors_
.green
) + _Dec2Hex(colors_
.blue
);
241 colors_
.hex
= hexstr
;
242 document
.getElementById("hexinput").value
= hexstr
;
245 // ###################################################################
246 // update the RGB values
249 // regex match the bits
250 var bits
= colors_
.hex
.match(/(..)(..)(..)/);
252 colors_
.red
= _Hex2dDc(bits
[1]);
253 colors_
.green
= _Hex2dDc(bits
[2]);
254 colors_
.blue
= _Hex2dDc(bits
[3]);
256 // construct the hex values
257 document
.getElementById("redinput").value
= colors_
.red
;
258 document
.getElementById("greeninput").value
= colors_
.green
;
259 document
.getElementById("blueinput").value
= colors_
.blue
;
262 // ###################################################################
263 // convert a decimal to a hexidecimal
264 function _Dec2Hex(dec
)
266 var hexstr
= "0123456789ABCDEF";
268 var high
= (dec
- low
) / 16;
269 hex
= "" + hexstr
.charAt(high
) + hexstr
.charAt(low
);
271 return hex
.toString();
274 // ###################################################################
275 // converts a hexidecimal to a decimal
276 function _Hex2dDc(hex
)
278 return parseInt(hex
, 16);
281 // ###################################################################
282 // ###################################################################
283 // ###################################################################
291 var front
= document
.getElementById("front");
292 var back
= document
.getElementById("back");
296 widget
.prepareForTransition("ToBack");
299 front
.style
.display
= "none";
300 back
.style
.display
= "block";
304 setTimeout("widget.performTransition();", 0);
307 document
.getElementById("fliprollie").style
.display
= "none";
314 backShowing_
= false;
316 var front
= document
.getElementById("front");
317 var back
= document
.getElementById("back");
321 widget
.prepareForTransition("ToFront");
324 back
.style
.display
= "none";
325 front
.style
.display
= "block";
329 setTimeout("widget.performTransition();", 0);
335 var flipShown
= false;
347 function mousemove(event
)
354 if (animation
.timer
!= null)
356 clearInterval(animation
.timer
);
357 animation
.timer
= null;
360 var starttime
= (new Date
).getTime() - 13;
362 animation
.duration
= 500;
363 animation
.starttime
= starttime
;
364 animation
.firstElement
= document
.getElementById("flip");
365 animation
.timer
= setInterval("animate();", 13);
366 animation
.from
= animation
.now
;
373 function mouseexit(event
)
380 // fade in the flip widget
381 if (animation
.timer
!= null)
383 clearInterval (animation
.timer
);
384 animation
.timer
= null;
387 var starttime
= (new Date
).getTime() - 13;
389 animation
.duration
= 500;
390 animation
.starttime
= starttime
;
391 animation
.firstElement
= document
.getElementById("flip");
392 animation
.timer
= setInterval("animate();", 13);
393 animation
.from
= animation
.now
;
405 var time
= (new Date
).getTime();
407 T
= limit_3(time
- animation
.starttime
, 0, animation
.duration
);
409 if (T
>= animation
.duration
)
411 clearInterval(animation
.timer
);
412 animation
.timer
= null;
413 animation
.now
= animation
.to
;
417 ease
= 0.5 - (0.5 * Math
.cos(Math
.PI
* T
/ animation
.duration
));
418 animation
.now
= compute_next_float(animation
.from
, animation
.to
, ease
);
421 animation
.firstElement
.style
.opacity
= animation
.now
;
424 function limit_3 (a
, b
, c
)
426 return a
< b
? b
: (a
> c
? c
: a
);
429 function compute_next_float(from
, to
, ease
)
431 return from
+ (to
- from
) * ease
;
434 function enterflip(event
)
436 document
.getElementById("fliprollie").style
.display
= "block";
439 function exitflip(event
)
441 document
.getElementById("fliprollie").style
.display
= "none";