Start drawing the color wheel with HTML5 canvas.
authorrsesek <rsesek@ad1dcce9-c9fe-0310-b82b-83ea1733dbb0>
Sat, 11 Dec 2010 18:05:01 +0000 (18:05 +0000)
committerrsesek <rsesek@ad1dcce9-c9fe-0310-b82b-83ea1733dbb0>
Sat, 11 Dec 2010 18:05:01 +0000 (18:05 +0000)
git-svn-id: svn://depot/macosx/RGBConverter/trunk@632 ad1dcce9-c9fe-0310-b82b-83ea1733dbb0

RGB Converter.wdgt/Info.plist
RGB Converter.wdgt/Widget.css
RGB Converter.wdgt/Widget.html
RGB Converter.wdgt/Widget.js

index 40d81e82aad3e8f4f7ce7d46c823b359453860f0..e1828c3935607986a91766f502b534416905d0b1 100644 (file)
@@ -7,7 +7,7 @@
        <key>CFBundleDisplayName</key>
        <string>RGB Converter</string>
        <key>CFBundleIdentifier</key>
-       <string>org.bluestatic.rgbconverter</string>
+       <string>org.bluestatic.rgbconverter3</string>
        <key>CFBundleShortVersionString</key>
        <string>2.2</string>
        <key>CFBundleVersion</key>
@@ -15,8 +15,8 @@
        <key>MainHTML</key>
        <string>Widget.html</string>
        <key>Width</key>
-       <integer>550</integer>
+       <integer>200</integer>
        <key>Height</key>
-       <integer>85</integer>
+       <integer>200</integer>
 </dict>
 </plist>
\ No newline at end of file
index 75b0aa28706e9f7f236f59fb346a500a00dd3c2a..3e978c1f970c4e6f1855089838d9a28e930ff81b 100644 (file)
@@ -1,7 +1,7 @@
 /*=====================================================================*\
 || ###################################################################
 || # RGB Converter
-|| # Copyright ©2002-2007 Blue Static
+|| # Copyright (c)2002-2010 Blue Static
 || #
 || # This program is free software; you can redistribute it and/or modify
 || # it under the terms of the GNU General Public License as published by
@@ -191,7 +191,7 @@ a
 
 #front
 {
-       display: block;
+       display: none;
 } 
 
 #back
index 096141a065e0a5f596b5355b0d6c06787d23a683..9f01b36be15c7cfcf0a6f83fce70c38cf73a63a7 100644 (file)
@@ -2,7 +2,7 @@
 /*=====================================================================*\
 || ###################################################################
 || # RGB Converter
-|| # Copyright ©2002-2007 Blue Static
+|| # Copyright (c)2002-2010 Blue Static
 || #
 || # This program is free software; you can redistribute it and/or modify
 || # it under the terms of the GNU General Public License as published by
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 <head>
        <title>RGB Conveter $Revision$</title>
+       <style type="text/css">
+               @import "Widget.css";
+       </style>
+       <script src="Widget.js" type="text/javascript"></script>
+       <script src="file:///System/Library/WidgetResources/button/genericButton.js" type="text/javascript"></script>
 </head>
 
-<style type="text/css">
-       @import "Widget.css";
-</style>
-
-<script src="Widget.js" type="text/javascript" />
-<script src="file:///System/Library/WidgetResources/button/genericButton.js" type="text/javascript" />
-
 <body onload="setup()">
+    <canvas id="wheel" width="180" height="180"></canvas>
        <!-- front -->
     <div id="front" onmousemove="mousemove(event);" onmouseout="mouseexit(event);">
     
index f966bd6006f9a561a3d2c487aeb81a30bbcef7a6..cd10c3a1dc1c0c3f2ffe8271cd1fccad4202a1eb 100644 (file)
@@ -1,7 +1,7 @@
 /*=====================================================================*\
 || ###################################################################
 || # RGB Converter
-|| # Copyright ©2002-2007 Blue Static
+|| # Copyright (c)2002-2010 Blue Static
 || #
 || # This program is free software; you can redistribute it and/or modify
 || # it under the terms of the GNU General Public License as published by
 || ###################################################################
 \*=====================================================================*/
 
-var fields = {
-       red : 60,
-       green : 60,
-       blue : 60,
-       hex : '3C3C3C'
+var colors_ = {
+  red   : 60,
+  green : 60,
+  blue  : 60,
+  hex   : '3C3C3C'
 };
 
 // ###################################################################
 // widget init
 function setup()
 {
+  Draw();
        createGenericButton(document.getElementById("backbutton"), "Done", hide_back, 0);
        document.getElementById("revision").innerHTML = "(r" + document.getElementById("revision").innerHTML.replace(/[^0-9]/g, "") + ")";
 }
@@ -79,6 +80,100 @@ function rgbwatcher(colour)
        update_swatch();
 }
 
+// ###################################################################
+function Draw()
+{
+  var canvas  = document.getElementById('wheel');
+  var context = canvas.getContext('2d');
+  var radius  = canvas.width / 2 - 3;
+  var center  = [canvas.width / 2, canvas.height / 2];
+  context.strokeStyle = 'black';
+
+  // Draw the individual components. Start with red.
+  context.beginPath();
+  context.moveTo(center[0], center[1]);
+  context.arc(canvas.width / 2,
+              canvas.height / 2,
+              radius,
+              Math.PI * 4/3,
+              Math.PI * 6/3,
+              false);
+  context.lineTo(center[0], center[1]);
+  context.fillStyle = _GetComponentColorString('red');
+  context.fill();
+  context.stroke();
+
+  // Green component.
+  context.beginPath();
+  context.moveTo(center[0], center[1]);
+  context.arc(canvas.width / 2,
+              canvas.height / 2,
+              radius,
+              Math.PI * 0,
+              Math.PI * 2/3,
+              false);
+  context.lineTo(center[0], center[1]);
+  context.fillStyle = _GetComponentColorString('green');
+  context.fill();
+  context.stroke();
+
+  // Blue component.
+  context.beginPath();
+  context.moveTo(center[0], center[1]);
+  context.arc(canvas.width / 2,
+              canvas.height / 2,
+              radius,
+              Math.PI * 2/3,
+              Math.PI * 4/3,
+              false);
+  context.lineTo(center[0], center[1]);
+  context.fillStyle = _GetComponentColorString('blue');
+  context.fill();
+  context.stroke();
+
+  // Draw the sheen gradient.
+  context.beginPath();
+  context.arc(center[0], center[1], radius, 0, Math.PI * 2, true);
+  var gradient = context.createLinearGradient(0, 0, 0, canvas.height);
+  gradient.addColorStop(0, 'rgba(255,255,255,.5)');
+  gradient.addColorStop(1, 'rgba(0,0,0,0)');
+  context.fillStyle = gradient;
+  context.fill();
+  context.closePath();
+
+  // Draw the inner wheel.
+  context.beginPath();
+  context.arc(center[0], center[1], canvas.width / 4.5, 0, Math.PI * 2, true);
+  context.fillStyle = _GetRGBColorString();
+  context.fill();
+  context.strokeStyle = 'black';
+  context.stroke();
+  context.closePath();
+}
+
+// ###################################################################
+// Returns the rgb(,,,) color string.
+
+function _GetRGBColorString()
+{
+  return 'rgb(' + colors_.red + ',' + colors_.green + ',' + colors_.blue + ')';
+}
+
+// ###################################################################
+// Returns an individual color component's color string.
+
+function _GetComponentColorString(color)
+{
+  if (color == 'red') {
+    return 'rgb(' + colors_.red + ',0,0)';
+  } else if (color == 'green') {
+    return 'rgb(0,' + colors_.green + ',0)';
+  } else if (color == 'blue') {
+    return 'rgb(0,0,' + colors_.blue + ')';
+  }
+  alert('Invalid color ' + color);
+}
+
 // ###################################################################
 // watches the hex field for updates
 function hexwatcher()