Beispiel #1
0
int Fl_Scrollbar::value(int p, int w, int t, int l)
{
    //	p = position, first line displayed
    //	w = window, number of lines displayed
    //	t = top, number of first line
    //	l = length, total number of lines
    if (p+w > t+l) l = p+w-t;
    if (l <= 0) l = 1;
    int b = l-w+t;
    int X=0; int Y=0; int W=this->w(); int H=h(); box()->inset(X,Y,W,H);
    if (vertical()) {int T = W; W = H; H = T; T = b; b = t; t = T;}
    if (W >= 3*H) W -= 2*H;
    int S = W*w/l; if (S < H) S = H; if (S > W) S = W;
    if (S != slider_size() || t != minimum() || b != maximum())
    {
        slider_size(S); minimum(t); maximum(b); redraw();
    }
    int ls = int(linesize());
    pagesize(w>2*ls ? w-ls : ls);
    return Fl_Slider::value(p);
}
Beispiel #2
0
void dark_style::slider_groove( const std::shared_ptr<draw::canvas> &c, const rect &rect )
{
	construct( c );

	coord rad = slider_size( rect );
	coord h = rect.height() - 7;
	rect tmp( rect );
	tmp.trim( rad, rad, h/2, h/2 );

	_slider_groove->set( c, tmp );
	_slider_groove->draw( *c );
}
Beispiel #3
0
void DIPSwitchSlider::paint(QPainter *painter, bool value, bool vreverse)
{
    // Draw outer Rectangle
    painter->setBrush(Qt::darkGray);
    painter->setPen(QPen(Qt::black, 2));
    painter->drawRect(QRect(m_pos, m_size));

    // Draw inner Rectangle (slider position)
    painter->setPen(Qt::white);
    painter->setBrush(Qt::white);

    QPoint slider_pos(m_pos.x() + 1, m_pos.y() + 1);
    QSize slider_size(m_size.width() - 3, m_size.width() - 3);
    if (slider_size.height() > m_size.height() / 2)
        slider_size.setHeight(m_size.height() / 2);

    if (value == vreverse) // down
        slider_pos.setY(slider_pos.y() + m_size.height() - slider_size.height() - 3);

    painter->drawRect(QRect(slider_pos, slider_size));
}
Beispiel #4
0
int Fl_Slider::handle(int event, int x, int y, int w, int h)
{

    switch (event)
    {
        case FL_FOCUS:
        case FL_UNFOCUS:
            redraw(FL_DAMAGE_ALL);
            return 1;
        case FL_PUSH:
            redraw(FL_DAMAGE_HIGHLIGHT);
            handle_push();
        case FL_DRAG:
            {
            // figure out the space the slider moves in and where the event is:
                int mx;
                if (horizontal())
                {
                    w = w-box()->dw();
                    mx = Fl::event_x()-x-box()->dx();
                }
                else
                {
                    w = h-box()->dh();
                    mx = Fl::event_y()-y-box()->dy();
                }
                if (w <= slider_size_) return 1;
                static int offcenter;
                int X = slider_position(value(), w);
                if (event == FL_PUSH)
                {
                    offcenter = mx-X;
                // we are done if they clicked on the slider:
                    if (offcenter >= (slider_size() ? 0 : -8) && offcenter <= slider_size_)
                        return 1;
                    if (Fl::event_button() > 1)
                    {
                    // Move the near end of the slider to the cursor. This is good
                    // for scrollbars.
                        offcenter = (offcenter < 0) ? 0 : slider_size_;
                    }
                    else
                    {
                    // Center the slider under the cursor, what most toolkits do
                        offcenter = slider_size_/2;
                    }
                }
                double v;
            RETRY:
                X = mx-offcenter;
                if (X < 0)
                {
                    X = 0;
                    offcenter = mx; if (offcenter < 0) offcenter = 0;
                }
                else if (X > (w-slider_size_))
                {
                    X = w-slider_size_;
                    offcenter = mx-X; if (offcenter > slider_size_) offcenter = slider_size_;
                }
                v = position_value(X, w);
                handle_drag(v);
            // make sure a click outside the sliderbar moves it:
                if (event == FL_PUSH && value() == previous_value())
                {
                    offcenter = slider_size_/2;
                    event = FL_DRAG;
                    goto RETRY;
                }
                return 1;
            }
        case FL_RELEASE:
            handle_release();
            redraw(FL_DAMAGE_HIGHLIGHT);
            return 1;
        case FL_KEY:
            // Only arrows in the correct direction are used.  This allows the
            // opposite arrows to be used to navigate between a set of parellel
            // sliders.
            switch (Fl::event_key())
            {
                case FL_Up:
                case FL_Down:
                    if (horizontal()) return 0;
                    break;
                case FL_Left:
                case FL_Right:
                    if (!horizontal()) return 0;
            }
        default:
            return Fl_Valuator::handle(event);
    }
}
Beispiel #5
0
bool Fl_Slider::draw(int ix, int iy, int iw, int ih, Fl_Flags flags, bool slot)
{
    // for back compatability, use type flag to set slider size:
    if (type()&FILL) slider_size(0);

    // if user directly set selected_color we use it:
    if (style()->selection_color) flags.set(FL_SELECTED);

    // figure out where the slider should be:
    int sx = ix, sy = iy, sw = iw, sh = ih;
    int sp;
    if (horizontal())
    {
        sx = sp = ix+slider_position(value(),iw);
        sw = slider_size_;
        if (!sw)                 // fill slider
        {
            sw = sx-ix; sx = ix;
        }
    }
    else
    {
        sy = sp = iy+slider_position(value(),ih);
        sh = slider_size_;
        if (!sh) sh = iy+ih-sy;  // fill slider
    }

    if (damage()&FL_DAMAGE_ALL)
    {
        fl_push_clip(0, 0, w(), h());
        // draw the slider
        draw_glyph(0, sx, sy, sw, sh, flags);
        // clip out the area of the slider
        fl_clip_out(sx, sy, sw, sh);

    }
    else if (sp != old_position)
    {

        // update a moving slider:
        // draw slider in new position
        draw_glyph(0, sx, sy, sw, sh, flags);
        // clip to the region the old slider was in:
        if (horizontal())
        {
            if (slider_size_) fl_push_clip(old_position, sy, sw, sh);
            else fl_push_clip(ix, iy, old_position, ih);
        }
        else
        {
            if (slider_size_) fl_push_clip(sx, old_position, sw, sh);
            else fl_push_clip(ix, old_position, iw, iy+ih-old_position);
        }
        // don't erase new slider
        fl_clip_out(sx, sy, sw, sh);
    }
    else
    {
        // update for the highlight turning on/off
        if (damage() & FL_DAMAGE_HIGHLIGHT) draw_glyph(0, sx, sy, sw, sh, flags);
        // otherwise no changes
        return false;
    }
    old_position = sp;

    // we draw a slot if it seems the box has no border:
    if (slot)
    {
        const int slot_size_ = 6;
        int slx, sly, slw, slh;
        int dx = (slider_size_-slot_size_)/2; if (dx < 0) dx = 0;
        if (horizontal())
        {
            slx = dx;
            slw = iw-2*dx;
            slx += ix;
            sly = iy+(ih-slot_size_+1)/2;
            slh = slot_size_;
        }
        else
        {
            sly = dx;
            slh = ih-2*dx;
            sly += iy;
            slx = ix+(iw-slot_size_+1)/2;
            slw = slot_size_;
        }
        button_box()->draw(slx, sly, slw, slh, FL_BLACK,
            flags&FL_INACTIVE|FL_VALUE);
        fl_clip_out(slx, sly, slw, slh);
    }
    return true;
}
Beispiel #6
0
int Fl_Scrollbar::handle(int event)
{
    // area of scrollbar:
    int X=0; int Y=0; int W=w(); int H=h(); box()->inset(X,Y,W,H);

    // adjust slider area to be inside the arrow buttons:
    if (vertical())
    {
        if (H >= 3*W) {Y += W; H -= 2*W;}
    }
    else
    {
        if (W >= 3*H) {X += H; W -= 2*H;}
    }

    // which widget part is highlighted?
    int mx = Fl::event_x();
    int my = Fl::event_y();
    int which_part;
    if (!Fl::event_inside(0, 0, w(), h())) which_part = NOTHING;
    else if (vertical())
    {
        if (my < Y) which_part = UP_ARROW;
        else if (my >= Y+H) which_part = DOWN_ARROW;
        else
        {
            int slidery = slider_position(value(), H);
            if (my < Y+slidery) which_part = ABOVE_SLIDER;
            else if (my >= Y+slidery+slider_size()) which_part = BELOW_SLIDER;
            else which_part = SLIDER;
        }
    }                            // horizontal
    else
    {
        if (mx < X) which_part = UP_ARROW;
        else if (mx >= X+W) which_part = DOWN_ARROW;
        else
        {
            int sliderx = slider_position(value(), W);
            if (mx < X+sliderx) which_part = ABOVE_SLIDER;
            else if (mx >= X+sliderx+slider_size()) which_part = BELOW_SLIDER;
            else which_part = SLIDER;
        }
    }
    switch (event)
    {
        case FL_FOCUS:
            return 0;
        case FL_ENTER:
        case FL_MOVE:
            if (!highlight_color()) return 1;
            if (which_part != which_highlight)
            {
                which_highlight = which_part;
                redraw(FL_DAMAGE_HIGHLIGHT);
            }
            return 1;
        case FL_LEAVE:
            if (which_highlight)
            {
                which_highlight = 0;
                redraw(FL_DAMAGE_HIGHLIGHT);
            }
            return 1;
        case FL_PUSH:
            // Clicking on the slider or middle or right click on the trough
            // gives us normal slider behavior:
            if (which_part == SLIDER ||
                Fl::event_button() > 1 && which_part > DOWN_ARROW)
            {
                which_pushed = SLIDER;
                return Fl_Slider::handle(event, X,Y,W,H);
            }
            handle_push();
            goto J1;
        case FL_DRAG:
            if (which_pushed==SLIDER) return Fl_Slider::handle(event, X,Y,W,H);
            if (which_part == SLIDER) which_part = NOTHING;
            // it is okay to switch between arrows and nothing, but no other
            // changes are allowed:
            if (!which_pushed && which_part <= DOWN_ARROW) ;
            else if (!which_part && which_pushed <= DOWN_ARROW) ;
            else which_part = which_pushed;
            J1:
            if (which_part != which_pushed)
            {
                Fl::remove_timeout(timeout_cb, this);
                which_highlight = which_pushed = which_part;
                redraw(FL_DAMAGE_HIGHLIGHT);
                if (which_part)
                {
                    Fl::add_timeout(INITIALREPEAT, timeout_cb, this);
                    increment_cb();
                }
            }
            return 1;
        case FL_RELEASE:
            if (which_pushed == SLIDER)
            {
                Fl_Slider::handle(event, X,Y,W,H);
            }
            else if (which_pushed)
            {
                Fl::remove_timeout(timeout_cb, this);
                handle_release();
                redraw(FL_DAMAGE_HIGHLIGHT);
            }
            which_pushed = NOTHING;
            return 1;
        case FL_MOUSEWHEEL:
            {
                float n = (vertical() ? Fl::event_dy() : Fl::event_dx())
                    * Fl_Style::wheel_scroll_lines * linesize();
                if (fabsf(n) > pagesize()) n = (n<0)?-pagesize():pagesize();
                handle_drag(value()+n);
                return 1;
            }
        case FL_KEY:
            if (vertical()) switch(Fl::event_key())
            {
                case FL_Home: handle_drag(maximum()); return 1;
                case FL_End:  handle_drag(minimum()); return 1;
                case FL_Page_Up: handle_drag(value()-pagesize()); return 1;
                case FL_Page_Down: handle_drag(value()+pagesize()); return 1;
            }                    // else fall through...
        default:
            return Fl_Slider::handle(event);
    }
}