Revision: 2712
http://vexi.svn.sourceforge.net/vexi/?rev=2712&view=rev
Author: clrg
Date: 2008-01-05 08:32:42 -0800 (Sat, 05 Jan 2008)
Log Message:
-----------
Implementation of colorpicker has now been moved into the widgets under
vexi.contrib.colorpicker
Modified Paths:
--------------
trunk/widgets/org.vexi.demo/src/org/vexi/demo/feature/colorpicker.t
Modified: trunk/widgets/org.vexi.demo/src/org/vexi/demo/feature/colorpicker.t
===================================================================
--- trunk/widgets/org.vexi.demo/src/org/vexi/demo/feature/colorpicker.t
2008-01-05 16:31:28 UTC (rev 2711)
+++ trunk/widgets/org.vexi.demo/src/org/vexi/demo/feature/colorpicker.t
2008-01-05 16:32:42 UTC (rev 2712)
@@ -1,7 +1,6 @@
<!-- Copyright 2007 - see COPYING for details [LGPL] -->
-<vexi xmlns:ui="vexi://ui" xmlns:meta="vexi://meta" xmlns="org.vexi.demo"
- xmlns:lay="vexi.layout" xmlns:util="vexi.util" xmlns:wi="vexi.widget">
+<vexi xmlns:ui="vexi://ui" xmlns:meta="vexi://meta" xmlns="vexi.contrib">
<meta:doc>
<about>
A complex 24-bit colorpicker, modeled after the Gimp's.
@@ -13,301 +12,7 @@
static.name = "Colorpicker";
static.category = "Contributed";
- <util:redirect />
<ui:box>
- <ui:box />
- <wi:bevel form="thinup" margin="20" padding="20" vshrink="true">
- <ui:box width="5" shrink="true" />
- <ui:box align="topleft" orient="vertical" shrink="true">
- <ui:box>
- <ui:box fill=":.image.colorpicker" id="colorpicker"
layout="place" shrink="true">
- <ui:box fill=":.image.colorpicker_circle" id="circle"
shrink="true"/>
- </ui:box>
- <ui:box width="5"/>
- <ui:box layout="layer">
- <wi:bevel margintop="4" thickness="2" form="down"
orient="vertical" width="34" shrink="true" id="grad_back">
- <ui:box shrink="true" fill=":.image.gradient"
layout="layer" id="gradient">
-
- thisbox.gradient_move = function(v) {
- var pos = thisbox.mouse.y;
- if (pos > thisbox.height) {pos =
thisbox.height;}
- else if (0 > pos) {pos = 0;}
- dad.n = 1 - (pos/height);
- return;
- }
-
- thisbox.Press1 ++= function(v) {
- gradient_move(v);
- surface.addMoveTrap(gradient_move);
- surface.Release1 ++= function(v) {
- surface._Release1 --= callee;
- surface.delMoveTrap(gradient_move);
- return;
- }
- return;
- }
-
- </ui:box>
- </wi:bevel>
- <ui:box shrink="true" align="bottom" x="0" y="0"
id="marker" fill=":.image.colorpicker_marker" />
- </ui:box>
- $gradient.marker = $marker;
- </ui:box>
- <ui:box height="5"/>
- <ui:box>
- <wi:bevel thickness="2" form="down" width="135" height="30">
- <ui:box fill="#000000" id="colorleft"/>
- <ui:box fill="#000000" id="targetcolor"/>
- <ui:box fill="#FFFFFF" id="colorright"/>
- </wi:bevel>
- <ui:box width="35"/>
- </ui:box>
- <ui:box height="3"/>
- <ui:box>
- <ui:box shrink="true" width="65" text="HTML Code:"/>
- <ui:box width="3"/>
- // FIXME: replace box with edit once edit field cummlative bug
is gone.
- <wi:textfield width="70" vshrink="true" fill="white"
text="#000000" editable="false" id="hexcode"/>
- <ui:box width="30"/>
- </ui:box>
- </ui:box>
- <ui:box width="20" shrink="true" />
- <ui:box align="topleft" orient="vertical" shrink="true">
- <ui:box>
- <ui:box align="left" width="60" vshrink="true" text="Hue:"/>
- <wi:slider minvalue="0" maxvalue="1" interval="0.001"
width="100" id="Hue" margin="5"/>
- <ui:box align="left" width="55" id="HueValue"/>
- </ui:box>
- <ui:box>
- <ui:box align="left" width="60" vshrink="true"
text="Saturation:" />
- <wi:slider minvalue="0" maxvalue="1" interval="0.001"
width="100" id="Saturation" margin="5"/>
- <ui:box align="left" width="55" id="SaturationValue"/>
- </ui:box>
- <ui:box>
- <ui:box align="left" width="60" vshrink="true"
text="Intensity:"/>
- <wi:slider minvalue="0" maxvalue="1" interval="0.001"
width="100" id="Intensity" margin="5"/>
- <ui:box align="left" width="55" id="IntensityValue"/>
- </ui:box>
- <ui:box>
- <ui:box align="left" width="60" vshrink="true" text="Red:"/>
- <wi:slider minvalue="0" maxvalue="255" interval="1"
vshrink="true" width="100" id="Red" margin="5"/>
- <ui:box align="left" width="55" id="RedValue"/>
- </ui:box>
- <ui:box>
- <ui:box align="left" width="60" vshrink="true" text="Green:"/>
- <wi:slider minvalue="0" maxvalue="255" interval="1"
vshrink="true" width="100" id="Green" margin="5"/>
- <ui:box align="left" width="55" id="GreenValue"/>
- </ui:box>
- <ui:box>
- <ui:box align="left" width="60" vshrink="true" text="Blue:"/>
- <wi:slider minvalue="0" maxvalue="255" interval="1"
vshrink="true" width="100" id="Blue" margin="5"/>
- <ui:box align="left" width="55" id="BlueValue"/>
- </ui:box>
- </ui:box>
- </wi:bevel>
- <ui:box />
-
- thisbox.h ++= function() { return $Hue.value; }
- thisbox.h ++= function(v) { $Hue.value = v; cascade = v; }
- thisbox.s ++= function() { return $Saturation.value; }
- thisbox.s ++= function(v) { $Saturation.value = v; cascade = v; }
- thisbox.n ++= function() { return $Intensity.value; }
- thisbox.n ++= function(v) { $Intensity.value = v; cascade = v; }
- thisbox.r ++= function() { return $Red.value; }
- thisbox.r ++= function(v) { $Red.value = v; cascade = v; }
- thisbox.g ++= function() { return $Green.value; }
- thisbox.g ++= function(v) { $Green.value = v; cascade = v; }
- thisbox.b ++= function() { return $Blue.value; }
- thisbox.b ++= function(v) { $Blue.value = v; cascade = v; }
- thisbox.color_left ++= function() { return $colorleft.fill; }
- thisbox.color_left ++= function(v) { $colorleft.fill = v; cascade = v;
}
- thisbox.color_right ++= function() { return $colorright.fill; }
- thisbox.color_right ++= function(v) { $colorright.fill = v; cascade =
v; }
- thisbox.hex ++= function() { return $hexcode.text; }
-
- thisbox.hsnfunc1 = function(v) {
- if (v == trapee[trapname]) return;
- cascade = v;
- hsn_to_rgb();
- }
-
- $Hue.value ++= hsnfunc1;
- $Saturation.value ++= hsnfunc1;
-
- $Intensity.value ++= function(v) {
- if (v == trapee[trapname]) return;
- // Move the marker on the intensity gradient.
- $gradient.marker.y = 0 - vexi.math.round(v * $gradient.height);
- cascade = v;
- hsn_to_rgb();
- }
-
- thisbox.rgbfunc1 = function(v) {
- if (v == trapee[trapname]) return;
- cascade = v;
- rgb_to_hsn();
- }
-
- $Red.value ++= rgbfunc1;
- $Green.value ++= rgbfunc1;
- $Blue.value ++= rgbfunc1;
-
- thisbox.color_move = function(v) {
- var cx = $colorpicker.mouse.x - $colorpicker.width / 2;
- var cy = -1 * ($colorpicker.mouse.y - $colorpicker.height / 2);
- h = (vexi.math.atan(cy / cx) / 2 + vexi.math.PI / 4) / vexi.math.PI
+ (cx > 0 ? 0.5 : 0);
- s = vexi.math.min(1.0, vexi.math.sqrt(cy * cy + cx * cx) /
($colorpicker.width / 2));
- return;
- }
-
- $colorpicker.Press1 ++= function(v) {
- color_move(v);
- surface.addMoveTrap(color_move);
- surface.Release1 ++= function(v) {
- surface._Release1 --= callee;
- surface.delMoveTrap(color_move);
- return;
- }
- return;
- }
-
- thisbox.threadsleeping = false;
- thisbox.changelockout = false;
-
- thisbox.hsn_to_rgb = function() {
- if (changelockout) return;
- else changelockout = true;
-
- if (s == 0) {
- // this line doesn't work with traps set on the variables??
- // r = g = b = n * 255;
- var x = n * 255;
- b = x;
- r = x;
- g = x;
- } else {
- var i_ = vexi.math.floor(h*6);
- var f_ = h*6 - i_;
-
- if (i_%2 == 0) f_ = 1 - f_; // If i_ is even
-
- var v_ = vexi.math.round(n * 255);
- var p_ = vexi.math.round(n * (1 - s) * 255);
- var q_ = vexi.math.round(n * (1 - s * f_) * 255);
- if (i_ == 0) i_ = 6; // Case 0 is the same as case 6.
-
- switch (i_) {
- case 1: r = q_; g = v_; b = p_; break;
- case 2: r = p_; g = v_; b = q_; break;
- case 3: r = p_; g = q_; b = v_; break;
- case 4: r = q_; g = p_; b = v_; break;
- case 5: r = v_; g = p_; b = q_; break;
- case 6: r = v_; g = q_; b = p_; break;
- default: vexi.log.error("ERROR: i_="+i_+", which is
outside range 0-6.");
- }
- }
-
- update();
- changelockout = false;
- }
-
- thisbox.rgb_to_hsn = function() {
- if (changelockout) return;
- changelockout = true;
-
- // both v_ and x_ are in range 0-1.
- var maxvalue = vexi.math.max(vexi.math.max(r, g), b);
- var minvalue = vexi.math.min(vexi.math.min(r, g), b);
- var diff = (max - min)/255;
- var v_ = max/255;
-
- if (maxvalue == minvalue) {
- h = s = 0; n = v_;
- } else {
- // FIXME: have taken an algorithm designed to spit out h
- // in range 0-6 and added /6 on the end; remodel algorithm.
- var f_ = ( (r == min) ? g - b : ((g == min) ? b - r : r - g)
)/255; // f now in range 0-1.
- var i_ = (r == min) ? 3 : ((g == min) ? 5 : 1);
-
- h = (i_ - f_ / diff)/6;
- s = (max - min) / max;
- n = v_;
- }
-
- update();
- changelockout = false;
- }
-
- thisbox.update = function() {
- $circle.x = s * ($colorpicker.width / 2) *
vexi.math.cos(($Hue.value + 0.25) *
- vexi.math.PI * 2) + $circle.width / 2 -
$circle.width / 2;
- $circle.y = $colorpicker.height / 2 - (s * ($colorpicker.width /
2) * vexi.math.sin(($Hue.value + 0.25) *
- vexi.math.PI * 2)) - $colorpicker.height / 2;
-
- var hexval = toHexColor(r,g,b);
- $targetcolor.fill = hexval;
- $hexcode.text = hexval;
-
- // make sure there's a thread running, watching to see if rgb
remain
- // the same for more than one event cycle. If so, update the
gradient.
- if (!threadsleeping) {
- threadsleeping = true;
- vexi.thread = function() {
- while(true) {
- var r_ = r; var g_ = g; var b_ = b;
- vexi.thread.yield();
- if (r == r_ and g == g_ and b == b_) break;
- }
-
- // Recalculate the color from hsn, but this time with a
full intensity.
- var i_ = vexi.math.floor(h*6);
- var f_ = h*6 - i_;
- if (i_ == 0) i_ = 6; // Case 0 is the same as case
6.
- if (i_%2 == 0) f_ = 1 - f_; // If i_ is even
-
- var p_ = vexi.math.round((1 - s) * 255);
- var q_ = vexi.math.round((1 - s * f_) * 255);
-
- switch(i_) {
- case 1: $grad_back.fill = toHexColor(q_, 255, p_);
break;
- case 2: $grad_back.fill = toHexColor(p_, 255, q_);
break;
- case 3: $grad_back.fill = toHexColor(p_, q_, 255);
break;
- case 4: $grad_back.fill = toHexColor(q_, p_, 255);
break;
- case 5: $grad_back.fill = toHexColor(255, p_, q_);
break;
- case 6: $grad_back.fill = toHexColor(255, q_, p_);
break;
- default: $grad_back.fill = "#FFFFFF";
vexi.log.error("ERROR: update() i_="+i_+", which is outside range 0-6.");
- }
- threadsleeping = false;
- }
- }
- }
-
- thisbox.hexdid = [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"A", "B", "C", "D", "E", "F" ];
- thisbox.toHexColor = function(red, green, blue) {
- // REMARK - should be, but is, necessary
- // why are we receiving negative values?
- if(0>red) red = 0;
- if(0>green) green = 0;
- if(0>blue) blue = 0;
-
- return "#" + hexdid[vexi.math.floor(red/16)] +
hexdid[vexi.math.floor(red%16)] +
- hexdid[vexi.math.floor(green/16)] +
hexdid[vexi.math.floor(green%16)] +
- hexdid[vexi.math.floor(blue/16)] +
hexdid[vexi.math.floor(blue%16)];
- }
-
- thisbox.hsn_to_rgb();
-
- $gradient.dad = thisbox;
-
- $Hue.value ++= function(v) { $HueValue.text = v; cascade = v; }
- $Saturation.value ++= function(v) { $SaturationValue.text = v; cascade
= v; }
- $Intensity.value ++= function(v) { $IntensityValue.text = v; cascade =
v; }
- $Red.value ++= function(v) { $RedValue.text = v; cascade = v; }
- $Green.value ++= function(v) { $GreenValue.text = v; cascade = v; }
- $Blue.value ++= function(v) { $BlueValue.text = v; cascade = v; }
-
- // initialize values
- h=0; s=0; n=0; r=0; g=0; b=0;
-
+ <colorpicker />
</ui:box>
</vexi>
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: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Vexi-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vexi-svn