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 rgbwatcher(color
)
42 field
= document
.getElementById(color
+ "input");
45 if (triad
= field
.value
.match(/(rgb
)?\(?([0-9]{1,3}),\s
?([0-9]{1,3}),\s
?([0-9]{1,3})\)?/))
47 document
.getElementById("redinput").value
= triad
[2];
48 document
.getElementById("greeninput").value
= triad
[3];
49 document
.getElementById("blueinput").value
= triad
[4];
57 // sanitize the number
58 var newval
= field
.value
.replace(/[^0-9\-\.]*/g
, "");
59 newval
= Math
.floor(newval
);
61 // make sure we don't go over 255
71 // update the text field
75 colors_
[color] = newval
;
84 // ###################################################################
87 var canvas
= document
.getElementById('wheel');
88 var context
= canvas
.getContext('2d');
89 var radius
= canvas
.width
/ 2 - 3;
90 var center
= [canvas
.width
/ 2, canvas
.height
/ 2];
91 context
.strokeStyle
= 'black';
93 context
.clearRect(0, 0, canvas
.width
, canvas
.height
);
96 // Draw dark baground gradient.
98 context
.arc(center
[0], center
[1], radius
, 0, Math
.PI
* 2, true);
99 var gradient
= context
.createLinearGradient(0, 0, 0, canvas
.height
);
100 gradient
.addColorStop(0, 'rgb(200, 200, 200)');
101 gradient
.addColorStop(1, 'rgb(30, 30, 30)');
102 context
.fillStyle
= gradient
;
108 // Draw the individual components. Start with red.
110 context
.moveTo(center
[0], center
[1]);
111 context
.arc(canvas
.width
/ 2,
117 context
.lineTo(center
[0], center
[1]);
118 context
.fillStyle
= _GetComponentColorString('red');
124 context
.moveTo(center
[0], center
[1]);
125 context
.arc(canvas
.width
/ 2,
131 context
.lineTo(center
[0], center
[1]);
132 context
.fillStyle
= _GetComponentColorString('green');
138 context
.moveTo(center
[0], center
[1]);
139 context
.arc(canvas
.width
/ 2,
145 context
.lineTo(center
[0], center
[1]);
146 context
.fillStyle
= _GetComponentColorString('blue');
150 // Draw the sheen gradient.
152 context
.arc(center
[0], center
[1], radius
, 0, Math
.PI
* 2, true);
153 var gradient
= context
.createLinearGradient(0, 0, 0, canvas
.height
);
154 gradient
.addColorStop(0, 'rgba(255,255,255,.5)');
155 gradient
.addColorStop(1, 'rgba(0,0,0,0)');
156 context
.fillStyle
= gradient
;
160 // Draw the inner wheel. WebKit in 10.6.5 (and maybe earlier) has a bug in
161 // which you can't fill a path after stroking it, or vice versa.
162 var _arc
= function(c
) {
163 c
.arc(center
[0], center
[1], canvas
.width
/ 4.75, 0, Math
.PI
* 2, true);
168 context
.strokeStyle
= 'rgb(30,30,30)';
173 context
.fillStyle
= _GetRGBColorString();
179 // ###################################################################
180 // Returns the rgb(,,,) color string.
182 function _GetRGBColorString()
184 return 'rgb(' + colors_
.red
+ ',' + colors_
.green
+ ',' + colors_
.blue
+ ')';
187 // ###################################################################
188 // Returns an individual color component's color string.
190 function _GetComponentColorString(color
)
192 if (color
== 'red') {
193 return 'rgb(' + colors_
.red
+ ',0,0)';
194 } else if (color
== 'green') {
195 return 'rgb(0,' + colors_
.green
+ ',0)';
196 } else if (color
== 'blue') {
197 return 'rgb(0,0,' + colors_
.blue
+ ')';
199 alert('Invalid color ' + color
);
202 // ###################################################################
203 // watches the hex field for updates
204 function hexwatcher()
206 field
= document
.getElementById("hexinput");
209 var newval
= field
.value
.replace(/[^0-9a
-f
]*/gi
, "");
212 var length
= newval
.length
;
214 // make sure we're always 6
217 newval
= newval
.substr(0, 6);
219 else if (length
== 3)
221 newval
= newval
.substr(0, 1) + newval
.substr(0, 1) + newval
.substr(1, 1) + newval
.substr(1, 1) + newval
.substr(2, 1) + newval
.substr(2, 1);
225 for (var i
= length
; i
<= 6; i
++)
227 newval
= "" + newval
+ "0";
232 field
.value
= newval
;
235 colors_
.hex
= newval
;
244 // ###################################################################
245 // update the hex value
246 function update_hex()
248 var hexstr
= dec2hex(colors_
.red
) + dec2hex(colors_
.green
) + dec2hex(colors_
.blue
);
249 colors_
.hex
= hexstr
;
250 document
.getElementById("hexinput").value
= hexstr
;
253 // ###################################################################
254 // update the RGB values
255 function update_rgb()
257 // regex match the bits
258 var bits
= colors_
.hex
.match(/(..)(..)(..)/);
260 colors_
.red
= hex2dec(bits
[1]);
261 colors_
.green
= hex2dec(bits
[2]);
262 colors_
.blue
= hex2dec(bits
[3]);
264 // construct the hex values
265 document
.getElementById("redinput").value
= colors_
.red
;
266 document
.getElementById("greeninput").value
= colors_
.green
;
267 document
.getElementById("blueinput").value
= colors_
.blue
;
270 // ###################################################################
271 // convert a decimal to a hexidecimal
272 function dec2hex(dec
)
274 var hexstr
= "0123456789ABCDEF";
276 var high
= (dec
- low
) / 16;
277 hex
= "" + hexstr
.charAt(high
) + hexstr
.charAt(low
);
279 return hex
.toString();
282 // ###################################################################
283 // converts a hexidecimal to a decimal
284 function hex2dec(hex
)
286 return parseInt(hex
, 16);
289 // ###################################################################
290 // ###################################################################
291 // ###################################################################
299 var front
= document
.getElementById("front");
300 var back
= document
.getElementById("back");
304 widget
.prepareForTransition("ToBack");
307 front
.style
.display
= "none";
308 back
.style
.display
= "block";
312 setTimeout("widget.performTransition();", 0);
315 document
.getElementById("fliprollie").style
.display
= "none";
322 backShowing_
= false;
324 var front
= document
.getElementById("front");
325 var back
= document
.getElementById("back");
329 widget
.prepareForTransition("ToFront");
332 back
.style
.display
= "none";
333 front
.style
.display
= "block";
337 setTimeout("widget.performTransition();", 0);
343 var flipShown
= false;
355 function mousemove(event
)
362 if (animation
.timer
!= null)
364 clearInterval(animation
.timer
);
365 animation
.timer
= null;
368 var starttime
= (new Date
).getTime() - 13;
370 animation
.duration
= 500;
371 animation
.starttime
= starttime
;
372 animation
.firstElement
= document
.getElementById("flip");
373 animation
.timer
= setInterval("animate();", 13);
374 animation
.from
= animation
.now
;
381 function mouseexit(event
)
388 // fade in the flip widget
389 if (animation
.timer
!= null)
391 clearInterval (animation
.timer
);
392 animation
.timer
= null;
395 var starttime
= (new Date
).getTime() - 13;
397 animation
.duration
= 500;
398 animation
.starttime
= starttime
;
399 animation
.firstElement
= document
.getElementById("flip");
400 animation
.timer
= setInterval("animate();", 13);
401 animation
.from
= animation
.now
;
413 var time
= (new Date
).getTime();
415 T
= limit_3(time
- animation
.starttime
, 0, animation
.duration
);
417 if (T
>= animation
.duration
)
419 clearInterval(animation
.timer
);
420 animation
.timer
= null;
421 animation
.now
= animation
.to
;
425 ease
= 0.5 - (0.5 * Math
.cos(Math
.PI
* T
/ animation
.duration
));
426 animation
.now
= compute_next_float(animation
.from
, animation
.to
, ease
);
429 animation
.firstElement
.style
.opacity
= animation
.now
;
432 function limit_3 (a
, b
, c
)
434 return a
< b
? b
: (a
> c
? c
: a
);
437 function compute_next_float(from
, to
, ease
)
439 return from
+ (to
- from
) * ease
;
442 function enterflip(event
)
444 document
.getElementById("fliprollie").style
.display
= "block";
447 function exitflip(event
)
449 document
.getElementById("fliprollie").style
.display
= "none";