Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
 

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: color conversion in murgaLua, color cube to RGB< Next Oldest | Next Newest >
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: Feb. 05 2007,20:53 QUOTE

I think colors are the most annoying thing about FLTK....maybe second only to fonts.

I've been trying to figure out how to get a 3-value color (as in rgb.txt) from an FLTK color index so I can plug it into a color chooser. For example, if 'button' has a color of 88 (red), I'd like to be able to get the values 255 0 0 from button:color(). I've also tried fltk.fl_rgb_color(button:color()), and this gives me *something* but i have no idea what format it is (a single integer of varying length).

In Lua-FLTK I could do this with get_color (or something similar to that, anyway), but this function does not seem to work in murgaLua.

An alternative would be to use the 256-color colormap, which allows me to use the FLTK colors taken from arbitrary widgets. However, in that situation I still need to get either the 3 values mentioned above, or an html equivalent for use in an external application.


--------------
http://www.tldp.org/LDP/intro-linux/html/index.html
Back to top
Profile PM WEB 
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: Feb. 07 2007,20:33 QUOTE

FINALLY got it =o)

I think i must have spent at least 3 or 4 hours in total digging through the FLTK and murgaLua docs and source files, and trying syntax variations.  I knew it was supported in murga because get_color is in the murga bindings, it came down to two things I overlooked:
1) "get_color" is under the "Fl" class rather than in the fl_* functions, so the syntax to call it is Fl:get_color rather than fltk:get_color
2) In order to get separate rgb values, the function needs not only to be set to 3 variables, but also needs three variables as arguments...i guess like pointers in C?

Anyway, here's what I'm using to get and set a button color:
Code Sample
function mycolor(self)
r,g,b=Fl:get_color(self:color(),r,g,b);
c_ok,r,g,b=fltk.fl_color_chooser("pick color",r,g,b);
if c_ok == 1 then
self:color(fltk.fl_color_cube(r*4/255,g*7/255,b*4/255));
end
end


The fl_color_cube function does an approximation of the RGB values in order to use one of the 256 colors in the fltk colormap. This means that you could set the button to a particular color, and then if you click the button again the RGB values shown will usually be a little different, causing a color shift.
It's good enough for my current script, but I'll look into something better later...probably use set_color instead of fl_color_cube.


--------------
http://www.tldp.org/LDP/intro-linux/html/index.html
Back to top
Profile PM WEB 
1 replies since Feb. 05 2007,20:53 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

 
reply to topic new topic new poll
Quick Reply: color conversion in murgaLua

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code