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 // ###################################################################
33 createGenericButton(document
.getElementById("backbutton"), "Done", hide_back
, 0);
34 document
.getElementById("revision").innerHTML
= "(r" + document
.getElementById("revision").innerHTML
.replace(/[^0-9]/g
, "") + ")";
37 // ###################################################################
38 // watches the three RGB fields to make sure they don't go over the limites
39 function rgbwatcher(color
)
41 field
= document
.getElementById(color
+ "input");
44 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
70 // update the text field
74 colors_
[color] = newval
;
83 // ###################################################################
86 var canvas
= document
.getElementById('wheel');
87 var context
= canvas
.getContext('2d');
88 var radius
= canvas
.width
/ 2 - 3;
89 var center
= [canvas
.width
/ 2, canvas
.height
/ 2];
90 context
.strokeStyle
= 'black';
92 // Draw the individual components. Start with red.
94 context
.moveTo(center
[0], center
[1]);
95 context
.arc(canvas
.width
/ 2,
101 context
.lineTo(center
[0], center
[1]);
102 context
.fillStyle
= _GetComponentColorString('red');
108 context
.moveTo(center
[0], center
[1]);
109 context
.arc(canvas
.width
/ 2,
115 context
.lineTo(center
[0], center
[1]);
116 context
.fillStyle
= _GetComponentColorString('green');
122 context
.moveTo(center
[0], center
[1]);
123 context
.arc(canvas
.width
/ 2,
129 context
.lineTo(center
[0], center
[1]);
130 context
.fillStyle
= _GetComponentColorString('blue');
134 // Draw the sheen gradient.
136 context
.arc(center
[0], center
[1], radius
, 0, Math
.PI
* 2, true);
137 var gradient
= context
.createLinearGradient(0, 0, 0, canvas
.height
);
138 gradient
.addColorStop(0, 'rgba(255,255,255,.5)');
139 gradient
.addColorStop(1, 'rgba(0,0,0,0)');
140 context
.fillStyle
= gradient
;
144 // Draw the inner wheel.
146 context
.arc(center
[0], center
[1], canvas
.width
/ 4.75, 0, Math
.PI
* 2, true);
147 context
.fillStyle
= _GetRGBColorString();
149 context
.strokeStyle
= 'black';
154 // ###################################################################
155 // Returns the rgb(,,,) color string.
157 function _GetRGBColorString()
159 return 'rgb(' + colors_
.red
+ ',' + colors_
.green
+ ',' + colors_
.blue
+ ')';
162 // ###################################################################
163 // Returns an individual color component's color string.
165 function _GetComponentColorString(color
)
167 if (color
== 'red') {
168 return 'rgb(' + colors_
.red
+ ',0,0)';
169 } else if (color
== 'green') {
170 return 'rgb(0,' + colors_
.green
+ ',0)';
171 } else if (color
== 'blue') {
172 return 'rgb(0,0,' + colors_
.blue
+ ')';
174 alert('Invalid color ' + color
);
177 // ###################################################################
178 // watches the hex field for updates
179 function hexwatcher()
181 field
= document
.getElementById("hexinput");
184 var newval
= field
.value
.replace(/[^0-9a
-f
]*/gi
, "");
187 var length
= newval
.length
;
189 // make sure we're always 6
192 newval
= newval
.substr(0, 6);
194 else if (length
== 3)
196 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);
200 for (var i
= length
; i
<= 6; i
++)
202 newval
= "" + newval
+ "0";
207 field
.value
= newval
;
210 colors_
.hex
= newval
;
219 // ###################################################################
220 // update the hex value
221 function update_hex()
223 var hexstr
= dec2hex(colors_
.red
) + dec2hex(colors_
.green
) + dec2hex(colors_
.blue
);
224 colors_
.hex
= hexstr
;
225 document
.getElementById("hexinput").value
= hexstr
;
228 // ###################################################################
229 // update the RGB values
230 function update_rgb()
232 // regex match the bits
233 var bits
= colors_
.hex
.match(/(..)(..)(..)/);
235 colors_
.red
= hex2dec(bits
[1]);
236 colors_
.green
= hex2dec(bits
[2]);
237 colors_
.blue
= hex2dec(bits
[3]);
239 // construct the hex values
240 document
.getElementById("redinput").value
= colors_
.red
;
241 document
.getElementById("greeninput").value
= colors_
.green
;
242 document
.getElementById("blueinput").value
= colors_
.blue
;
245 // ###################################################################
246 // convert a decimal to a hexidecimal
247 function dec2hex(dec
)
249 var hexstr
= "0123456789ABCDEF";
251 var high
= (dec
- low
) / 16;
252 hex
= "" + hexstr
.charAt(high
) + hexstr
.charAt(low
);
254 return hex
.toString();
257 // ###################################################################
258 // converts a hexidecimal to a decimal
259 function hex2dec(hex
)
261 return parseInt(hex
, 16);
264 // ###################################################################
265 // ###################################################################
266 // ###################################################################
272 var front
= document
.getElementById("front");
273 var back
= document
.getElementById("back");
277 widget
.prepareForTransition("ToBack");
280 front
.style
.display
= "none";
281 back
.style
.display
= "block";
285 setTimeout("widget.performTransition();", 0);
288 document
.getElementById("fliprollie").style
.display
= "none";
293 var front
= document
.getElementById("front");
294 var back
= document
.getElementById("back");
298 widget
.prepareForTransition("ToFront");
301 back
.style
.display
= "none";
302 front
.style
.display
= "block";
306 setTimeout("widget.performTransition();", 0);
310 var flipShown
= false;
322 function mousemove(event
)
326 if (animation
.timer
!= null)
328 clearInterval(animation
.timer
);
329 animation
.timer
= null;
332 var starttime
= (new Date
).getTime() - 13;
334 animation
.duration
= 500;
335 animation
.starttime
= starttime
;
336 animation
.firstElement
= document
.getElementById("flip");
337 animation
.timer
= setInterval("animate();", 13);
338 animation
.from
= animation
.now
;
345 function mouseexit(event
)
349 // fade in the flip widget
350 if (animation
.timer
!= null)
352 clearInterval (animation
.timer
);
353 animation
.timer
= null;
356 var starttime
= (new Date
).getTime() - 13;
358 animation
.duration
= 500;
359 animation
.starttime
= starttime
;
360 animation
.firstElement
= document
.getElementById("flip");
361 animation
.timer
= setInterval("animate();", 13);
362 animation
.from
= animation
.now
;
374 var time
= (new Date
).getTime();
376 T
= limit_3(time
- animation
.starttime
, 0, animation
.duration
);
378 if (T
>= animation
.duration
)
380 clearInterval(animation
.timer
);
381 animation
.timer
= null;
382 animation
.now
= animation
.to
;
386 ease
= 0.5 - (0.5 * Math
.cos(Math
.PI
* T
/ animation
.duration
));
387 animation
.now
= compute_next_float(animation
.from
, animation
.to
, ease
);
390 animation
.firstElement
.style
.opacity
= animation
.now
;
393 function limit_3 (a
, b
, c
)
395 return a
< b
? b
: (a
> c
? c
: a
);
398 function compute_next_float(from
, to
, ease
)
400 return from
+ (to
- from
) * ease
;
403 function enterflip(event
)
405 document
.getElementById("fliprollie").style
.display
= "block";
408 function exitflip(event
)
410 document
.getElementById("fliprollie").style
.display
= "none";
413 /*=====================================================================*\
414 || ###################################################################
417 || ###################################################################
418 \*=====================================================================*/