예제 #1
0
파일: slider.c 프로젝트: kingcope/LikeOS
static void new_position(GuiObject *slid, int pos_neg)
{
	int old_position;

	check_object(slid, "slid", "new_position");

	old_position = slid->position;
	if (pos_neg < -1)
		slid->position -= slid->length;
	else if (pos_neg < 0)
		slid->position--;
	else if (pos_neg > 1)
		slid->position += slid->length;
	else if (pos_neg > 0)
		slid->position++;

	if (slid->position < 0)
		slid->position = 0;
	if (slid->position > slid->slider_length - slid->length)
		slid->position = slid->slider_length - slid->length;

	if (old_position != slid->position) {
		show_slider(slid);
		slid->object_callback(slid, slid->u_data);
	}
}
예제 #2
0
    void scroll_bar::
    set_length (
        unsigned long length
    )
    {
        // make the min length be at least 1
        if (length == 0)
        {
            length = 1;
        }

        auto_mutex M(m);

        parent.invalidate_rectangle(rect);

        if (ori == HORIZONTAL)
        {
            rect.set_right(rect.left() + length - 1);
            rect.set_bottom(rect.top() + width_ - 1);

            // if the length is too small then we have to smash up the arrow buttons
            // and hide the slider.
            if (length <= width_*2)
            {
                b1.set_size(length/2,width_);
                b2.set_size(length/2,width_);
            }
            else
            {
                b1.set_size(width_,width_);
                b2.set_size(width_,width_);

                // now adjust the slider
                if (max_pos != 0)
                {
                    slider.set_size(get_slider_size(),width_);
                }
            }

        }
        else
        {
            rect.set_right(rect.left() + width_ - 1);
            rect.set_bottom(rect.top() + length - 1);

            // if the length is too small then we have to smush up the arrow buttons
            // and hide the slider.
            if (length <= width_*2)
            {
                b1.set_size(width_,length/2);
                b2.set_size(width_,length/2);
            }
            else
            {

                b1.set_size(width_,width_);
                b2.set_size(width_,width_);

                // now adjust the slider
                if (max_pos != 0)
                {
                    slider.set_size(width_,get_slider_size());
                }
            }


        }

        // call this to put everything is in the right spot.
        set_pos (rect.left(),rect.top());

        if ((b2.get_rect().top() - b1.get_rect().bottom() - 1 <= 8 && ori == VERTICAL) || 
            (b2.get_rect().left() - b1.get_rect().right() - 1 <= 8 && ori == HORIZONTAL) || 
            max_pos == 0)
        {
            hide_slider();
        }
        else if (enabled && !hidden)
        {
            show_slider();
        }
    }
예제 #3
0
파일: slider.c 프로젝트: kingcope/LikeOS
void press_slider(GuiObject * slid)
{
	GuiWindow *win;
	GuiWinThread *win_thread;
	int position, old_x, old_y;
	int x, y;
	int old_position = 0, on_bar = FALSE;
	
	check_object(slid, "slid", "press_slider");
	win = slid->win;
	check_window(win, "press_slider");
	win_thread = win->win_thread;
	old_x = slid->x;
	old_y = slid->y;
	x = mouse.x - win->x;
	y = mouse.y - win->y;

	if ((slid->type == HOR_SLIDER &&	/* on slider bar? */
	     x >= slid->x + slid->position &&
	     x <= slid->x + slid->position + slid->length) ||
	    (slid->type == VERT_SLIDER &&
	     y >= slid->y + slid->slider_length - slid->position - slid->length &&
	     y <= slid->y + slid->slider_length - slid->position)) {
		old_x = x;
		old_y = y - slid->slider_length;
		old_position = slid->position;
		on_bar = TRUE;
	}
	if (!on_bar && (slid->type == HOR_SLIDER || slid->type == VERT_SLIDER)) {
		if (slid->type == HOR_SLIDER) {
			if (x > slid->x + slid->position)
				move_slider(slid, 2);
			else
				move_slider(slid, -2);
		}
		if (slid->type == VERT_SLIDER) {
			if (y > slid->y + slid->slider_length - slid->position)
				move_slider(slid, -2);
			else
				move_slider(slid, +2);
		}
		return;
	}
	do {
		usleep(sleep_time);
		do_window_functions(win_thread);
		if (GuiGetMessage() == GuiMouseEvent) {
			move_mouse();
			x = mouse.x - win->x;
			y = mouse.y - win->y;
			position = old_position;
			if (slid->type == HOR_SLIDER || slid->type == NICE_HOR_SLIDER)
				position += x - old_x;
			else
				position += slid->slider_length - (y - old_y);
			if (position > slid->slider_length - slid->length)
					position = slid->slider_length - slid->length;
			if (position < 0)
				position = 0;
			slid->position = position;
			show_slider(slid);
			slid->object_callback(slid, slid->u_data);
		}
	}
	while (GuiMouseGetButton() == GuiMouseLeftButton);

	/* check for double click on slider bar */
	if (on_bar)
		check_double_click(slid);
}