> I'm still using ver 1.1.10 but, reading 1.3.0 docs, seems that nothing is
> changed about colors.
> For example, when drawing a selection box in a Fl_Overlay_Window, it would be
> nicer to fill it with a semi-transparent color: is there a method to get this
> in some FLTK version?
>
>
I am interested in getting semi-transparent selection rectangles, i.e. coloured
boxes that allow to see widgets or text under them with a "blended" colour
(with any method!)
I tried to rielaborate the image.cxx demo which uses alpha-blending, but I
don't get what I want: if I drag the "transparent" square over the sliders, it
covers completely them, even with alpha blending set.
Am I completely wrong?
I read the docs on offscreen drawing but it seems a bit obscure (for me!). Is
there some example?
Thanks N. Cassetta
//**************************************************************
#include <FL/Fl.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Value_Slider.H>
#include <FL/Fl_draw.H>
#include <FL/Fl_Image.H>
class TransparentBox : public Fl_Box {
public:
TransparentBox(int x, int y, int w, int h, char* l = 0) :
Fl_Box(x, y, w, h) , alpha(0x80) {
box(FL_NO_BOX);
buffer = new unsigned char[4*w*h];
img = new Fl_RGB_Image(buffer, w, h, 4);
image(img);
color((Fl_Color)0);
}
void color(Fl_Color c) {
r = (c >> 24);
g = (c >> 16);
b = (c >> 8);
fill_buffer();
img->uncache();
}
void set_alpha(unsigned char a) {
alpha = a;
fill_buffer();
img->uncache();
}
protected:
virtual int handle(int e) { // allows to drag the TransparentBox
static int xn, yn;
switch(e) {
case FL_PUSH:
xn = Fl::event_x() - x();
yn = Fl::event_y() - y();
return 1;
case FL_DRAG:
position(Fl::event_x() - xn, Fl::event_y() - yn);
window()->redraw();
return 1;
case FL_RELEASE:
return 1;
default:
return 0;
}
}
private:
void fill_buffer() {
uchar *p = buffer;
for (int i = 0; i < 4*w()*h(); i+=4) {
*p++ = r;
*p++ = g;
*p++ = b;
*p++ = alpha;
}
}
unsigned char* buffer;
unsigned char r;
unsigned char g;
unsigned char b;
unsigned char alpha;
Fl_RGB_Image* img;
};
class MainWindow : public Fl_Double_Window {
public:
MainWindow(): Fl_Double_Window(100, 100, 600, 300, "Try to drag the
square!") {
Sl_R = new Fl_Value_Slider(40, 40, 30, 100, "Red");
Sl_R->range(0, 255); Sl_R->step(1);
Sl_R->callback(slider_cb);
Sl_G = new Fl_Value_Slider(80, 40, 30, 100, "Green");
Sl_G->range(0, 255);
Sl_G->step(1);
Sl_G->callback(slider_cb);
Sl_B = new Fl_Value_Slider(120, 40, 30, 100, "Blue");
Sl_B->range(0,255);
Sl_B->step(1);
Sl_B->callback(slider_cb);
Sl_a = new Fl_Value_Slider(160, 40, 30, 100, "alpha");
Sl_a->range(0, 255);
Sl_a->step(1);
Sl_a->callback(slider_cb);
Tbox = new TransparentBox(200, 20, 200, 200);
Tbox->box(FL_FLAT_BOX);
end();
}
private:
static void slider_cb(Fl_Widget* w, void* p) {
MainWindow* mw = (MainWindow* )(w->window());
if (w == mw->Sl_a)
mw->Tbox->set_alpha(mw->Sl_a->value());
else
mw->Tbox->color(fl_rgb_color(mw->Sl_R->value(), mw->Sl_G->value(),
mw->Sl_B->value()));
mw->Tbox->redraw();
}
Fl_Value_Slider* Sl_R;
Fl_Value_Slider* Sl_G;
Fl_Value_Slider* Sl_B;
Fl_Value_Slider* Sl_a;
Fl_Box* Lbox;
TransparentBox* Tbox;
};
int main()
{
MainWindow* mwin = new MainWindow ();
mwin->show();
return Fl::run();
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk