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);
36 document
.getElementById("revision").innerHTML
= "(r" + document
.getElementById("revision").innerHTML
.replace(/[^0-9]/g
, "") + ")";
39 // ###################################################################
40 // watches the three RGB fields to make sure they don't go over the limites
41 function rgbwatcher(color
)
43 field
= document
.getElementById(color
+ "input");
46 if (triad
= field
.value
.match(/(rgb
)?\(?([0-9]{1,3}),\s
?([0-9]{1,3}),\s
?([0-9]{1,3})\)?/))
48 document
.getElementById("redinput").value
= triad
[2];
49 document
.getElementById("greeninput").value
= triad
[3];
50 document
.getElementById("blueinput").value
= triad
[4];
58 // sanitize the number
59 var newval
= field
.value
.replace(/[^0-9\-\.]*/g
, "");
60 newval
= Math
.floor(newval
);
62 // make sure we don't go over 255
72 // update the text field
76 colors_
[color] = newval
;
85 // ###################################################################
88 var canvas
= document
.getElementById('wheel');
89 var context
= canvas
.getContext('2d');
90 var radius
= canvas
.width
/ 2 - 3;
91 var center
= [canvas
.width
/ 2, canvas
.height
/ 2];
92 context
.strokeStyle
= 'black';
94 context
.clearRect(0, 0, canvas
.width
, canvas
.height
);
97 // Draw the sheen gradient.
99 context
.arc(center
[0], center
[1], radius
, 0, Math
.PI
* 2, true);
100 var gradient
= context
.createLinearGradient(0, 0, 0, canvas
.height
);
101 gradient
.addColorStop(0, 'rgb(200, 200, 200)');
102 gradient
.addColorStop(1, 'rgb(0, 0, 0)');
103 context
.fillStyle
= gradient
;
109 // Draw the individual components. Start with red.
111 context
.moveTo(center
[0], center
[1]);
112 context
.arc(canvas
.width
/ 2,
118 context
.lineTo(center
[0], center
[1]);
119 context
.fillStyle
= _GetComponentColorString('red');
125 context
.moveTo(center
[0], center
[1]);
126 context
.arc(canvas
.width
/ 2,
132 context
.lineTo(center
[0], center
[1]);
133 context
.fillStyle
= _GetComponentColorString('green');
139 context
.moveTo(center
[0], center
[1]);
140 context
.arc(canvas
.width
/ 2,
146 context
.lineTo(center
[0], center
[1]);
147 context
.fillStyle
= _GetComponentColorString('blue');
151 // Draw the sheen gradient.
153 context
.arc(center
[0], center
[1], radius
, 0, Math
.PI
* 2, true);
154 var gradient
= context
.createLinearGradient(0, 0, 0, canvas
.height
);
155 gradient
.addColorStop(0, 'rgba(255,255,255,.5)');
156 gradient
.addColorStop(1, 'rgba(0,0,0,0)');
157 context
.fillStyle
= gradient
;
161 // Draw the inner wheel.
163 context
.arc(center
[0], center
[1], canvas
.width
/ 4.75, 0, Math
.PI
* 2, true);
164 context
.fillStyle
= _GetRGBColorString();
166 context
.strokeStyle
= 'black';
171 // ###################################################################
172 // Returns the rgb(,,,) color string.
174 function _GetRGBColorString()
176 return 'rgb(' + colors_
.red
+ ',' + colors_
.green
+ ',' + colors_
.blue
+ ')';
179 // ###################################################################
180 // Returns an individual color component's color string.
182 function _GetComponentColorString(color
)
184 if (color
== 'red') {
185 return 'rgb(' + colors_
.red
+ ',0,0)';
186 } else if (color
== 'green') {
187 return 'rgb(0,' + colors_
.green
+ ',0)';
188 } else if (color
== 'blue') {
189 return 'rgb(0,0,' + colors_
.blue
+ ')';
191 alert('Invalid color ' + color
);
194 // ###################################################################
195 // watches the hex field for updates
196 function hexwatcher()
198 field
= document
.getElementById("hexinput");
201 var newval
= field
.value
.replace(/[^0-9a
-f
]*/gi
, "");
204 var length
= newval
.length
;
206 // make sure we're always 6
209 newval
= newval
.substr(0, 6);
211 else if (length
== 3)
213 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);
217 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
238 function update_hex()
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
247 function update_rgb()
249 // regex match the bits
250 var bits
= colors_
.hex
.match(/(..)(..)(..)/);
252 colors_
.red
= hex2dec(bits
[1]);
253 colors_
.green
= hex2dec(bits
[2]);
254 colors_
.blue
= hex2dec(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 hex2dec(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";
444 /*=====================================================================*\
445 || ###################################################################
448 || ###################################################################
449 \*=====================================================================*/