color conversion in murgaLua
Forum: Programming and Scripting
Topic: color conversion in murgaLua
started by: mikshaw
Posted by mikshaw on Feb. 05 2007,20:53I 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.
Posted by mikshaw on Feb. 07 2007,20:33FINALLY 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:
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.