#include #include using std::min; using std::max; RgbFloat::RgbFloat(int x, int y) : Fl_Group(x,y,100,100) { int bw = w(); int bh = h(); int margen = 4; frame = new Fl_Box(x,y,w(),h()); frame->box(FL_EMBOSSED_BOX); int vfx = x+2*margen + 40; int vfy = y+2*margen; int vfw = 50; int vfh = 28; int sepVert = 30; vfRed = new Fl_Value_Input(vfx, vfy, vfw, vfh, "R real"); vfRed->maximum (1.0f); vfRed->step (1.0f/256.0f); vfRed->labelcolor(FL_RED); vfRed->callback(cambioCB,(long)FL_RED); vfGreen = new Fl_Value_Input(vfx, vfy+sepVert, vfw, vfh, "G real"); vfGreen->maximum(1.0f); vfGreen->step(1.0f/256.0f); vfGreen->labelcolor(FL_GREEN); vfGreen->callback(cambioCB,(long)FL_GREEN); vfBlue = new Fl_Value_Input(vfx, vfy+2*sepVert, vfw, vfh, "B real"); vfBlue->maximum(1.0f); vfBlue->step(1.0f/256.0f); vfBlue->labelcolor(FL_BLUE); vfBlue->callback(cambioCB,(long)FL_BLUE); end(); // importante!! } void RgbFloat::getRGB(uchar &r, uchar &g, uchar &b) { r = (uchar)(vfRed->value()*255.0); g = (uchar)(vfGreen->value()*255.0); b = (uchar)(vfBlue->value()*255.0); } void RgbFloat::_setRGB(int r, int g, int b) { vfRed->value(r/255.0); vfGreen->value(g/255.0); vfBlue->value(b/255.0); } void RgbFloat::setRGB(int r, int g, int b) { } void RgbFloat::cambioCB(Fl_Widget *w, long color) { static uchar r, g, b; const static double MIN = 0.0; const static double MAX = 255.0; RgbFloat *rgbFloat = (RgbFloat *)w->parent(); rgbFloat->getRGB(r,g,b); Fl_Value_Input *vi = (Fl_Value_Input *)w; double val = max(MIN, min(vi->value()*255.0, MAX)); switch (color) { case FL_RED: r = (uchar) val; break; case FL_GREEN: g = (uchar) val; break; case FL_BLUE: b = (uchar) val; break; } }