#include #include using std::min; using std::max; void ColorWin::inicializarValores() { red = green = blue = 0; margen = 4; } ColorWin::ColorWin(int x, int y, int w, int h, char *title) : Fl_Window(x,y,w,h,title) { inicializarValores(); crearBarraMenu(); crearValueSliders(); crearValueInputs(); crearFloatInputs(); crearOutputs(); // setCallbacks(); crearCajaColor(); end(); show(); } void ColorWin::finCB(Fl_Widget *w, void *data) { w->window()->hide(); } void ColorWin::updateAll() { updateBoxColor(); // updateValueSliders(); // ... // ... // ... } void ColorWin::updateBoxColor() { boxColor->color(fl_rgb_color(red, green, blue)); boxColor->redraw(); } void ColorWin::updateRealInputs() { // ... } void ColorWin::updateOutputs() { char s[50]; sprintf(s,"%02X",red); outRed->value((char *)s); sprintf(s,"%02X",green); outGreen->value((char *)s); sprintf(s,"%02X",blue); outBlue->value((char *)s); } void ColorWin::setRGB(int r, int g, int b) { static int MIN = 0; static int MAX = 255; // red = ... // green = ... // blue = max(...,min(...,MAX)); // ... } void ColorWin::setColor(int color, uchar widgetValue) { switch(color) { case FL_RED: red = widgetValue; break; case FL_GREEN: green = widgetValue; break; case FL_BLUE: blue = widgetValue; break; } } void ColorWin::slidersCB (Fl_Widget *w, void *data) { Fl_Value_Slider *vs = (Fl_Value_Slider *)w; int color = (int) data; ColorWin *win = (ColorWin *)vs->parent(); win->setColor(color,(uchar)vs->value()); win->updateBoxColor(); // ... // ... // ... } void ColorWin::crearValueSliders () { int bx = margen, by= barraMenu->h() + margen, bw = 270, bh = 100; int vsx = bx + margen + 14, vsy = by + margen, vsw = bw-2*margen-14, vsh = 28; int verticalStep= vsh + margen; boxRGB = new Fl_Box(bx, by, bw, bh); boxRGB->box(FL_EMBOSSED_BOX); 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); // vsGreen = ... // ... // ... // ... // ... // ... // vsBlue = ... // ... // ... // ... // ... // ... } void ColorWin::crearValueInputs () { int bx = margen, by = barraMenu->h() + 2*margen + 100, bw = 82, bh = 100; int vix = bx + margen + 36, viy = by + margen, viw = 36, vih = 28; int verticalStep = vih + margen; boxValRGB = new Fl_Box(bx, by, bw, bh); boxValRGB->box(FL_EMBOSSED_BOX); viRed= new Fl_Value_Input(vix, viy, viw, vih, "R ent"); viRed->labelcolor(FL_RED); viRed->maximum(255); viRed->step(1); // viGreen = ... // ... // ... // ... // ... // viBlue = new ... // ... // ... // ... // ... } void ColorWin::crearFloatInputs () { int bx = 2*margen+82, by = barraMenu->h() + 2*margen + 100, bw = 105, bh = 100; int fix = bx + 2*margen + 40, fiy = by + margen, fiw = 50, fih = 28; int verticalStep = fih + margen; boxRealRGB = new Fl_Box(bx, by, bw, bh); boxRealRGB->box(FL_EMBOSSED_BOX); fiRed = new Fl_Value_Input (fix, fiy, fiw, fih, "R real"); fiRed->labelcolor(FL_RED); fiRed->bounds(0.0f, 1.0f); fiRed->step(1.0f/256.0f); // fiGreen = new ... // ... // ... // ... // ... // fiBlue = ... // ... // ... // ... // ... } void ColorWin::crearOutputs () { int bx = 3*margen + 84 + 104, by = barraMenu->h() + 2*margen + 100, bw = 74, bh = 100; int ix = bx + margen + 42, iy = by + margen, iw = 26, ih = 28; int verticalStep = ih + margen; boxHexRGB = new Fl_Box(bx, by, bw, bh); boxHexRGB->box(FL_EMBOSSED_BOX); outRed = new Fl_Output (ix, iy, iw, ih, "R hex"); outRed->labelcolor(FL_RED); outRed->box(FL_FLAT_BOX); outRed->color(FL_GRAY); outRed->value("00"); // outGreen = ... // ... // ... // ... // ... // outBlue = new Fl_Output (ix, iy+2*verticalStep, iw, ih, "B hex"); // ... // ... // ... // ... } void ColorWin::setCallbacks() { // de los 'sliders' // vsRed->callback(slidersCB, ...); // vsGreen->callback(...); // vsBlue... // de los 'int input' ([0,255]) // ... // ... // ... // de los 'float input' ([0,1]) // fiRed->callback(...) // ... // ... fiRed->when(FL_WHEN_CHANGED); fiGreen->when(FL_WHEN_CHANGED); fiBlue->when(FL_WHEN_CHANGED); } void ColorWin::crearBarraMenu() { Fl_Menu_Item menu[] = { {"&Fichero", FL_ALT+'f', 0, 0, FL_SUBMENU}, {"&Salir", FL_ALT+'s', finCB}, {0}, {"&Ayuda", FL_ALT+'a', 0, 0, FL_SUBMENU}, {"Acerca de"}, {0}, {0} }; barraMenu = new Fl_Menu_Bar(0, 0, 640, 30); // ... } void ColorWin::crearCajaColor() { int mw = w(), mh = barraMenu->h(); boxColor = new Fl_Box (w()-margen-200, mh+margen, 200, h()-mh-2*margen); boxColor->box(FL_EMBOSSED_BOX); boxColor->color(fl_rgb_color (red, green, blue)); }