#include #include #include ContadorUpDown::ContadorUpDown(int x, int y, int w, int h, const char* label) : Fl_Valuator(x, y, w, h, label) { align(FL_ALIGN_LEFT); dondeClick = NINGUNO; } void ContadorUpDown::draw() { static Fl_Boxtype boxtype[ULTIMO+1]; // tipo de caja para contador y botones // caja del boton arriba boxtype[BOTON_ARRIBA] = (dondeClick == BOTON_ARRIBA) ? FL_DOWN_BOX : FL_UP_BOX; // caja del boton abajo boxtype[BOTON_ABAJO] = (dondeClick == BOTON_ABAJO) ? FL_DOWN_BOX : FL_UP_BOX; int xPos[2]; // posicion horizontal de contador y botones int ancho[2]; // ancho del contador y botones anchoBotones = (int)(0.2*w()); // 20% del ancho total del control xPos[CONTADOR] = x(); ancho[CONTADOR] = w() - anchoBotones; xPos[BOTON_ARRIBA] = x() + ancho[CONTADOR]; ancho[BOTON_ARRIBA] = anchoBotones; // dibujo del contador draw_box(FL_DOWN_BOX, x(), y(), ancho[CONTADOR], h(), FL_BACKGROUND_COLOR); fl_font(FL_HELVETICA, FL_NORMAL_SIZE); fl_color(FL_BLACK); static char str[125]; format(str); fl_draw(str, x(), y(), ancho[0], h(), FL_ALIGN_CENTER); // "dibujar" texto // dibujo del botón superior draw_box(boxtype[BOTON_ARRIBA], xPos[BOTON_ARRIBA], y(), ancho[BOTON_ARRIBA], h()/2, color()); fl_draw_symbol("@-42<", xPos[BOTON_ARRIBA], y(), ancho[BOTON_ARRIBA], h()/2, FL_BLACK); // dibujo del botón inferior draw_box(boxtype[BOTON_ABAJO], xPos[BOTON_ARRIBA], y()+h()/2, ancho[BOTON_ARRIBA], h()/2, color()); fl_draw_symbol("@-42>", xPos[BOTON_ARRIBA], y()+h()/2, ancho[BOTON_ARRIBA], h()/2, FL_BLACK); } void ContadorUpDown::incrementar() { double v = value(); switch (dondeClick) { case BOTON_ARRIBA: // ... break; case BOTON_ABAJO: // ... break; } // ... } int ContadorUpDown::calcularDondeSePulso() { int xx = x() + w() - anchoBotones; // x de ambos botones int yUp = y(); // y de boton Up int yDown = // ... // y de boton Down if (Fl::event_inside(xx, yUp, anchoBotones, h()/2)) return BOTON_ARRIBA; if (Fl::event_inside(/* ... */)) return BOTON_ABAJO; return NINGUNO; } int ContadorUpDown::handle(int event) { int donde; switch (event) { case FL_RELEASE: dondeClick = NINGUNO; // ... return 1; case FL_PUSH: donde = calcularDondeSePulso(); if ((donde == BOTON_ARRIBA) || (donde == BOTON_ABAJO)) { dondeClick = donde; redraw(); // ... } return 1; default: return 0; } }