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(colour
)
41 field
= document
.getElementById(colour
+ "inputf");
44 if (triad
= field
.value
.match(/(rgb
)?\(?([0-9]{1,3}),\s
?([0-9]{1,3}),\s
?([0-9]{1,3})\)?/))
46 document
.getElementById("redinputf").value
= triad
[2];
47 document
.getElementById("greeninputf").value
= triad
[3];
48 document
.getElementById("blueinputf").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 fields
[colour] = 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.5, 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("hexinputf");
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 fields
['hex'] = newval
;
219 // ###################################################################
220 // update the hex value
221 function update_hex()
223 var hexstr
= dec2hex(fields
['red']) + dec2hex(fields
['green']) + dec2hex(fields
['blue']);
224 fields
['hex'] = hexstr
;
225 document
.getElementById("hexinputf").value
= hexstr
;
228 // ###################################################################
229 // update the RGB values
230 function update_rgb()
232 // regex match the bits
233 var bits
= fields
['hex'].match(/(..)(..)(..)/);
235 fields
['red'] = hex2dec(bits
[1]);
236 fields
['green'] = hex2dec(bits
[2]);
237 fields
['blue'] = hex2dec(bits
[3]);
239 // construct the hex values
240 document
.getElementById("redinputf").value
= fields
['red'];
241 document
.getElementById("greeninputf").value
= fields
['green'];
242 document
.getElementById("blueinputf").value
= fields
['blue'];
245 // ###################################################################
246 // update the colour swatch
247 function update_swatch()
249 document
.getElementById("hexinputf").value
= document
.getElementById("hexinputf").value
.toUpperCase();
250 document
.getElementById("swatch").style
.backgroundColor
= "rgb(" + fields
['red'] + ", " + fields
['green'] + ", " + fields
['blue'] + ")";
251 document
.getElementById("swatch-red").style
.backgroundColor
= "rgb(" + fields
['red'] + ", 0, 0)";
252 document
.getElementById("swatch-green").style
.backgroundColor
= "rgb(0, " + fields
['green'] + ", 0)";
253 document
.getElementById("swatch-blue").style
.backgroundColor
= "rgb(0, 0, " + fields
['blue'] + ")";
256 // ###################################################################
257 // convert a decimal to a hexidecimal
258 function dec2hex(dec
)
260 var hexstr
= "0123456789ABCDEF";
262 var high
= (dec
- low
) / 16;
263 hex
= "" + hexstr
.charAt(high
) + hexstr
.charAt(low
);
265 return hex
.toString();
268 // ###################################################################
269 // converts a hexidecimal to a decimal
270 function hex2dec(hex
)
272 return parseInt(hex
, 16);
275 // ###################################################################
276 // ###################################################################
277 // ###################################################################
283 var front
= document
.getElementById("front");
284 var back
= document
.getElementById("back");
288 widget
.prepareForTransition("ToBack");
291 front
.style
.display
= "none";
292 back
.style
.display
= "block";
296 setTimeout("widget.performTransition();", 0);
299 document
.getElementById("fliprollie").style
.display
= "none";
304 var front
= document
.getElementById("front");
305 var back
= document
.getElementById("back");
309 widget
.prepareForTransition("ToFront");
312 back
.style
.display
= "none";
313 front
.style
.display
= "block";
317 setTimeout("widget.performTransition();", 0);
321 var flipShown
= false;
333 function mousemove(event
)
337 if (animation
.timer
!= null)
339 clearInterval(animation
.timer
);
340 animation
.timer
= null;
343 var starttime
= (new Date
).getTime() - 13;
345 animation
.duration
= 500;
346 animation
.starttime
= starttime
;
347 animation
.firstElement
= document
.getElementById("flip");
348 animation
.timer
= setInterval("animate();", 13);
349 animation
.from
= animation
.now
;
356 function mouseexit(event
)
360 // fade in the flip widget
361 if (animation
.timer
!= null)
363 clearInterval (animation
.timer
);
364 animation
.timer
= null;
367 var starttime
= (new Date
).getTime() - 13;
369 animation
.duration
= 500;
370 animation
.starttime
= starttime
;
371 animation
.firstElement
= document
.getElementById("flip");
372 animation
.timer
= setInterval("animate();", 13);
373 animation
.from
= animation
.now
;
385 var time
= (new Date
).getTime();
387 T
= limit_3(time
- animation
.starttime
, 0, animation
.duration
);
389 if (T
>= animation
.duration
)
391 clearInterval(animation
.timer
);
392 animation
.timer
= null;
393 animation
.now
= animation
.to
;
397 ease
= 0.5 - (0.5 * Math
.cos(Math
.PI
* T
/ animation
.duration
));
398 animation
.now
= compute_next_float(animation
.from
, animation
.to
, ease
);
401 animation
.firstElement
.style
.opacity
= animation
.now
;
404 function limit_3 (a
, b
, c
)
406 return a
< b
? b
: (a
> c
? c
: a
);
409 function compute_next_float(from
, to
, ease
)
411 return from
+ (to
- from
) * ease
;
414 function enterflip(event
)
416 document
.getElementById("fliprollie").style
.display
= "block";
419 function exitflip(event
)
421 document
.getElementById("fliprollie").style
.display
= "none";
424 /*=====================================================================*\
425 || ###################################################################
428 || ###################################################################
429 \*=====================================================================*/