Revision: 3143
          http://vexi.svn.sourceforge.net/vexi/?rev=3143&view=rev
Author:   clrg
Date:     2008-10-27 16:35:41 +0000 (Mon, 27 Oct 2008)

Log Message:
-----------
Beginnings of vexi.util.color (currently just one static function: 
getReadableColor)

Added Paths:
-----------
    trunk/widgets/org.vexi.widgets/src/vexi/util/color.t
    trunk/widgets/org.vexi.widgets/src_dev/test/color.t

Added: trunk/widgets/org.vexi.widgets/src/vexi/util/color.t
===================================================================
--- trunk/widgets/org.vexi.widgets/src/vexi/util/color.t                        
        (rev 0)
+++ trunk/widgets/org.vexi.widgets/src/vexi/util/color.t        2008-10-27 
16:35:41 UTC (rev 3143)
@@ -0,0 +1,27 @@
+<!-- Copyright 2008 - see COPYING for details [LGPL] -->
+
+<vexi xmlns:ui="vexi://ui" xmlns:meta="vexi://meta">
+    <meta:doc>
+        <author>Charles Goodwin</author>
+        <name>Color</name>
+        <desc>Utility functions for working with colors</desc>
+    </meta:doc>
+    
+    <ui:box />
+    
+    var readable = {};
+    
+    /** takes a string 'v' and parses it as a date for 'o' */
+    static.getReadableColor = function(c) {
+        if (readable[c]) return readable[c];
+        if (c.charAt(0)!='#') throw "Color must be in hex format";
+        var r = vexi.string.parseInt(c.substring(1,3), 16)
+              + vexi.string.parseInt(c.substring(3,5), 16)
+              + vexi.string.parseInt(c.substring(5,7), 16);
+        r = vexi.math.ceil(r/3);
+        r = r>128 ? "black" : "white";
+        readable[c] = r;
+        return r;
+    }
+    
+</vexi>

Added: trunk/widgets/org.vexi.widgets/src_dev/test/color.t
===================================================================
--- trunk/widgets/org.vexi.widgets/src_dev/test/color.t                         
(rev 0)
+++ trunk/widgets/org.vexi.widgets/src_dev/test/color.t 2008-10-27 16:35:41 UTC 
(rev 3143)
@@ -0,0 +1,18 @@
+<vexi xmlns:ui="vexi://ui" xmlns="vexi.util">
+    <ui:box orient="vertical">
+        
+        vexi.ui.frame = thisbox;
+        
+        var colors = ["#CC0000", "#00CC00", "#0000CC", "#CCCCCC",
+        "#660000", "#006600", "#000066", "#666666", "#333333"];
+        
+        for (var i=0; colors.length>i; i++) {
+            var b = vexi.box;
+            b.fill = colors[i];
+            b.text = colors[i];
+            b.textcolor = .color..getReadableColor(colors[i]);
+            thisbox[numchildren] = b;
+        }
+        
+    </ui:box>
+</vexi>
\ No newline at end of file


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Vexi-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to