On 07/31/12 18:53, Todd wrote:
> #include <FL/Fl.H>
> #include <FL/Fl_Window.H>
> #include <FL/Fl_Check_Button.H>
>
> int main() {
> Fl_Window window( 10, 10, 100, 100, "Window" );
> Fl_Check_Button button( 10, 20, 70, 25, "Button" );
> button.color( FL_BLACK, FL_RED ); // How black square with red check?
> window.end();
> window.show();
> return Fl::run();
> }
AFAIK from looking at the draw() function in Fl_Light_Button (from which
Fl_Check_Button derives, and where the code is that draws the 'check'),
it appears the box's background color /hardwired/ to
FL_BACKGROUND2_COLOR.
So it looks like you can't change its color, only the check's color
(which can be controlled by the selection_color())
So to get what you want, I think you have to derive your own class
(below) to take full control of how to draw the button.
Fortunately not that much code, but it is a PITA.
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Check_Button.H>
#include <FL/fl_draw.H>
class MyCheckButton : public Fl_Check_Button {
public:
MyCheckButton(int X,int Y,int W,int H,const char *L=0) :
Fl_Check_Button(X,Y,W,H,L) {
}
void draw_check() {
int W = labelsize();
int dx = Fl::box_dx(box()) + 2;
int dy = (h() - W) / 2;
int tx = x() + dx + 3;
int tw = W - 6;
int d1 = tw/3;
int d2 = tw-d1;
int ty = y() + dy + (W+d2)/2-d1-2;
for (int n = 0; n < 3; n++, ty++) {
fl_line(tx, ty, tx+d1, ty+d1);
fl_line(tx+d1, ty+d1, tx+tw-1, ty+d1-d2+1);
}
}
void draw() {
Fl_Color bgcolor = active_r() ? color() : fl_inactive(color());
Fl_Color chkcolor = selection_color();
if ( value() ) { // Clicked?
draw_box(FL_DOWN_BOX, bgcolor);
fl_color(chkcolor); draw_check();
} else { // Not clicked?
draw_box(FL_UP_BOX, bgcolor);
}
}
};
int main() {
Fl_Window window( 10, 10, 100, 100, "Window" );
MyCheckButton button(10, 20, 20, 20, "Button" );
button.color(FL_BLACK);
button.selection_color(FL_RED);
window.end();
window.show();
return Fl::run();
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk