#include #include #include using std::min; using std::max; RgbSlide::RgbSlide(int x, int y, ColorRGB *s) : Fl_Group(x,y,272,100), sujeto(s) { int bw = w(); int bh = h(); int margen = 4; frame = new Fl_Box(x,y,w(),h()); frame->box(FL_EMBOSSED_BOX); int vsx = x+2*margen + 15; int vsy = y+2*margen; int vsw = 246;// w()-3*margen-15; int vsh = 28; int sepVert = 30; vsRed = new Fl_Value_Slider(vsx, vsy, vsw, vsh, "R"); vsRed->type (FL_HOR_SLIDER); vsRed->maximum (255); vsRed->step (1); vsRed->align (FL_ALIGN_LEFT); vsRed->labelcolor(FL_RED); vsRed->callback(cambioCB,(long)FL_RED); vsGreen = new Fl_Value_Slider(vsx, vsy+sepVert, vsw, vsh, "G"); vsGreen->type(FL_HOR_SLIDER); vsGreen->maximum(255); vsGreen->step(1); vsGreen->align(FL_ALIGN_LEFT); vsGreen->labelcolor(FL_GREEN); vsGreen->callback(cambioCB,(long)FL_GREEN); vsBlue = new Fl_Value_Slider(vsx, vsy+2*sepVert, vsw, vsh, "B"); vsBlue->type(FL_HOR_SLIDER); vsBlue->maximum(255); vsBlue->step(1); vsBlue->align(FL_ALIGN_LEFT); vsBlue->labelcolor(FL_BLUE); vsBlue->callback(cambioCB,(long)FL_BLUE); end(); // importante!! sujeto = s; sujeto->suscribir(this); } void RgbSlide::actualizar(Sujeto *s) { static uchar r, g, b; if (s == sujeto) { sujeto->getRGB(r,g,b); _setRGB(r,g,b); } } void RgbSlide::getRGB(uchar &r, uchar &g, uchar &b) { r = (uchar) vsRed->value(); g = (uchar) vsGreen->value(); b = (uchar) vsBlue->value(); } void RgbSlide::_setRGB(int r, int g, int b) { vsRed->value(r); vsGreen->value(g); vsBlue->value(b); } void RgbSlide::setRGB(int r, int g, int b) { sujeto->setRGB(r,g,b); } void RgbSlide::cambioCB(Fl_Widget *w, long color) { static uchar r, g, b; RgbSlide *rgbSlide = (RgbSlide *)w->parent(); rgbSlide->getRGB(r,g,b); Fl_Value_Slider *vs = (Fl_Value_Slider *)w; switch (color) { case FL_RED: r = (uchar) vs->value(); break; case FL_GREEN: g = (uchar) vs->value(); break; case FL_BLUE: b = (uchar) vs->value(); break; } rgbSlide->setRGB(r,g,b); }