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.
162 context
.arc(center
[0], center
[1], canvas
.width
/ 4.75, 0, Math
.PI
* 2, true);
163 context
.fillStyle
= _GetRGBColorString();
165 context
.strokeStyle
= 'black';
170 // ###################################################################
171 // Returns the rgb(,,,) color string.
173 function _GetRGBColorString()
175 return 'rgb(' + colors_
.red
+ ',' + colors_
.green
+ ',' + colors_
.blue
+ ')';
178 // ###################################################################
179 // Returns an individual color component's color string.
181 function _GetComponentColorString(color
)
183 if (color
== 'red') {
184 return 'rgb(' + colors_
.red
+ ',0,0)';
185 } else if (color
== 'green') {
186 return 'rgb(0,' + colors_
.green
+ ',0)';
187 } else if (color
== 'blue') {
188 return 'rgb(0,0,' + colors_
.blue
+ ')';
190 alert('Invalid color ' + color
);
193 // ###################################################################
194 // watches the hex field for updates
195 function hexwatcher()
197 field
= document
.getElementById("hexinput");
200 var newval
= field
.value
.replace(/[^0-9a
-f
]*/gi
, "");
203 var length
= newval
.length
;
205 // make sure we're always 6
208 newval
= newval
.substr(0, 6);
210 else if (length
== 3)
212 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);
216 for (var i
= length
; i
<= 6; i
++)
218 newval
= "" + newval
+ "0";
223 field
.value
= newval
;
226 colors_
.hex
= newval
;
235 // ###################################################################
236 // update the hex value
237 function update_hex()
239 var hexstr
= dec2hex(colors_
.red
) + dec2hex(colors_
.green
) + dec2hex(colors_
.blue
);
240 colors_
.hex
= hexstr
;
241 document
.getElementById("hexinput").value
= hexstr
;
244 // ###################################################################
245 // update the RGB values
246 function update_rgb()
248 // regex match the bits
249 var bits
= colors_
.hex
.match(/(..)(..)(..)/);
251 colors_
.red
= hex2dec(bits
[1]);
252 colors_
.green
= hex2dec(bits
[2]);
253 colors_
.blue
= hex2dec(bits
[3]);
255 // construct the hex values
256 document
.getElementById("redinput").value
= colors_
.red
;
257 document
.getElementById("greeninput").value
= colors_
.green
;
258 document
.getElementById("blueinput").value
= colors_
.blue
;
261 // ###################################################################
262 // convert a decimal to a hexidecimal
263 function dec2hex(dec
)
265 var hexstr
= "0123456789ABCDEF";
267 var high
= (dec
- low
) / 16;
268 hex
= "" + hexstr
.charAt(high
) + hexstr
.charAt(low
);
270 return hex
.toString();
273 // ###################################################################
274 // converts a hexidecimal to a decimal
275 function hex2dec(hex
)
277 return parseInt(hex
, 16);
280 // ###################################################################
281 // ###################################################################
282 // ###################################################################
290 var front
= document
.getElementById("front");
291 var back
= document
.getElementById("back");
295 widget
.prepareForTransition("ToBack");
298 front
.style
.display
= "none";
299 back
.style
.display
= "block";
303 setTimeout("widget.performTransition();", 0);
306 document
.getElementById("fliprollie").style
.display
= "none";
313 backShowing_
= false;
315 var front
= document
.getElementById("front");
316 var back
= document
.getElementById("back");
320 widget
.prepareForTransition("ToFront");
323 back
.style
.display
= "none";
324 front
.style
.display
= "block";
328 setTimeout("widget.performTransition();", 0);
334 var flipShown
= false;
346 function mousemove(event
)
353 if (animation
.timer
!= null)
355 clearInterval(animation
.timer
);
356 animation
.timer
= null;
359 var starttime
= (new Date
).getTime() - 13;
361 animation
.duration
= 500;
362 animation
.starttime
= starttime
;
363 animation
.firstElement
= document
.getElementById("flip");
364 animation
.timer
= setInterval("animate();", 13);
365 animation
.from
= animation
.now
;
372 function mouseexit(event
)
379 // fade in the flip widget
380 if (animation
.timer
!= null)
382 clearInterval (animation
.timer
);
383 animation
.timer
= null;
386 var starttime
= (new Date
).getTime() - 13;
388 animation
.duration
= 500;
389 animation
.starttime
= starttime
;
390 animation
.firstElement
= document
.getElementById("flip");
391 animation
.timer
= setInterval("animate();", 13);
392 animation
.from
= animation
.now
;
404 var time
= (new Date
).getTime();
406 T
= limit_3(time
- animation
.starttime
, 0, animation
.duration
);
408 if (T
>= animation
.duration
)
410 clearInterval(animation
.timer
);
411 animation
.timer
= null;
412 animation
.now
= animation
.to
;
416 ease
= 0.5 - (0.5 * Math
.cos(Math
.PI
* T
/ animation
.duration
));
417 animation
.now
= compute_next_float(animation
.from
, animation
.to
, ease
);
420 animation
.firstElement
.style
.opacity
= animation
.now
;
423 function limit_3 (a
, b
, c
)
425 return a
< b
? b
: (a
> c
? c
: a
);
428 function compute_next_float(from
, to
, ease
)
430 return from
+ (to
- from
) * ease
;
433 function enterflip(event
)
435 document
.getElementById("fliprollie").style
.display
= "block";
438 function exitflip(event
)
440 document
.getElementById("fliprollie").style
.display
= "none";