Beispiel #1
0
gg_rect_t gg_vbox_get_focus_pos(gg_widget_t *widget)
{
    gg_box_t *box = GG_BOX(widget);
    gg_container_t *container = GG_CONTAINER(widget);
    int size = gg_container_get_size(container);
    gg_widget_t *child;
    gg_rect_t focus;
    int nr = gg_container_get_size(container) - 1;

    assert(box->sel != -1);

    child = gg_container_get_child(container, box->sel);
    focus = child->get_focus_pos(child);

    while (nr > box->sel)
    {
        gg_widget_t *sibling = gg_container_get_child(container, nr);
        focus.y += sibling->height_a;
        nr--;
    }

    focus.y += (size - box->sel - 1) * box->spacing;

    return focus;
}
Beispiel #2
0
int gg_vbox_set_focus_pos(gg_widget_t *widget, int x , int y)
{
    gg_box_t *box = GG_BOX(widget);
    gg_container_t *container = GG_CONTAINER(widget);
    int size = gg_container_get_size(container);
    int cur_y = box->height_a - box->height;
    int prev = box->sel;

    box->sel = size;

    while (gg_select_prev(GG_SELECT(widget), 0, 0))
    {
        gg_widget_t *child = gg_container_get_child(container, box->sel);

        cur_y += child->height_a;
        if (cur_y > y)
        {
            if (!child->input || !child->enabled || !
                child->set_focus_pos(child, x, child->height_a - (cur_y - y)))
                break;
            else
                return 1;
        }
        cur_y += box->spacing;
    }

    box->sel = prev;
    return 0;
}
Beispiel #3
0
int gg_ticker_input(gg_widget_t *widget, gg_event_t event) {
	gg_select_t *select = GG_SELECT(widget);
	gg_box_t *box = GG_BOX(widget);
	gg_widget_t *child;

	event.mouse.x -= widget->width_a - GG_TICKER(widget)->offset;

	if (select->sel == -1)
		return 0;

	if (event.type == GG_EVENT_MOUSE)
	{
		int nr = 0;
		while (nr < select->sel)
		{
			gg_widget_t *child = gg_container_get_child(GG_CONTAINER(widget), nr);

			event.mouse.x -= child->width_a;
			event.mouse.x -= box->spacing;
			nr++;
		}
	}

	child = gg_container_get_child(GG_CONTAINER(widget), select->sel);

	if (child->input && child->input(child, event))
		return 1;

	return 0;
}
Beispiel #4
0
void gg_vbox_get_requested_size(gg_widget_t *widget, int *width, int *height)
{
    gg_container_t *container = GG_CONTAINER(widget);
    gg_box_t *box = GG_BOX(widget);
    int size = gg_container_get_size(container);
    int i;

    widget->width = 0;
    widget->height = (size - 1) * box->spacing;

    for (i = 0; i < size; i++)
    {
        int child_width, child_height;
        gg_widget_t *child = gg_container_get_child(container, i);

        child->get_requested_size(child, &child_width, &child_height);

        if (child_width > widget->width)
            widget->width = child_width;

        widget->height += child_height;

        if (child->enabled && child->input && (box->sel == -1))
            box->sel = i;
    }

    gg_widget_get_requested_size(widget, width, height);
}
Beispiel #5
0
gg_rect_t gg_ticker_get_focus_pos(gg_widget_t *widget)
{
	gg_box_t *box = GG_BOX(widget);
	gg_container_t *container = GG_CONTAINER(widget);
	gg_widget_t *child;
	gg_rect_t focus;
	int nr = 0;

	if (box->sel == -1)
	{
		focus.x = widget->width_a / 2;
		focus.y = widget->height_a / 2;
		return focus;
	}

	child = gg_container_get_child(container, box->sel);
	focus = child->get_focus_pos(child);

	while (nr < box->sel)
	{
		focus.x += child->width_a;
		nr++;
	}

	focus.x += box->sel * box->spacing;
	focus.x += widget->width_a - GG_TICKER(widget)->offset;

	return focus;
}
Beispiel #6
0
int gg_vbox_input(gg_widget_t *widget, gg_event_t event) {
	gg_select_t *select = GG_SELECT(widget);
	gg_box_t *box = GG_BOX(widget);
	gg_widget_t *child;
	gg_rect_t focus;
	int retval = 0, x, y;

	if (select->sel == -1)
		return 0;

	if (event.type == GG_EVENT_MOUSE) {
		int nr = gg_container_get_size(GG_CONTAINER(widget));

		event.mouse.y -= box->height_a - box->height;
		while (--nr > select->sel) {
			gg_widget_t *child = gg_container_get_child(GG_CONTAINER(widget), nr);

			event.mouse.y -= child->height_a;
			event.mouse.y -= box->spacing;
		}
	}

	child = gg_container_get_child(GG_CONTAINER(widget), select->sel);

	if (event.type == GG_EVENT_MOUSE) {
		if (event.mouse.x < 0 || event.mouse.x >= child->width_a || event.mouse.y < 0 ||
			event.mouse.y >= child->height_a)
			return 0;
	}

	if (child->input(child, event))
		return 1;

	focus = child->get_focus_pos(child);
	x = focus.x + focus.width / 2;

	if (event.type == GG_EVENT_KEY && event.key == GG_KEY_UP) {
		retval = gg_select_prev(select, 1, 1);
		child = gg_container_get_child(GG_CONTAINER(widget), select->sel);
		y = 0;
	}

	if (event.type == GG_EVENT_KEY && event.key == GG_KEY_DOWN) {
		retval = gg_select_next(select, 1, 1);
		child = gg_container_get_child(GG_CONTAINER(widget), select->sel);
		y = child->height_a - 1;
	}

	if (retval) {
		child->set_focus_pos(child, x, y);
		return retval;
	}

	return 0;
}
Beispiel #7
0
void gg_ticker_render(gg_widget_t *widget, int x, int y, int focus) {
	gg_box_t *box = GG_BOX(widget);
	gg_rect_t rect;
	rect.x = x;
	rect.y = y;
	rect.width = widget->width_a;
	rect.height = widget->height_a;

	gg_clipping_adjust(&rect);

	int size = gg_container_get_size(GG_CONTAINER(widget));
	int i;

	gg_ticker_t *ticker = GG_TICKER(widget);
	int child_x = ticker->width_a - ticker->offset;
	for (i = 0; i < size; i++) {
		gg_widget_t *child = gg_container_get_child(GG_CONTAINER(widget), i);
		if (child_x < widget->width_a && child_x + child->width_a > 0) {
			int focus_child;

			if (focus == GG_FOCUS_ALL)
				focus_child = GG_FOCUS_ALL;
			else if (focus == GG_FOCUS_ONE)
				focus_child = (box->sel == i ? GG_FOCUS_ONE : GG_FOCUS_NONE);
			else
				focus_child = 0;

			child->render(child, x + child_x, y, focus_child);
		}
		child_x += child->width_a + ticker->spacing;
	}

	gg_clipping_undo();
	if (child_x <= 0) {
		ticker->start_time = gg_system_get_ticks();
		ticker->offset = 0;
	} else {
		ticker->offset += 1;
	}

	ticker->offset = (gg_system_get_ticks() - ticker->start_time) * TICKER_SPEED / 1000;

	gg_ticker_set_focus_pos(widget, GG_TICKER(widget)->focus_x, 0);
}
Beispiel #8
0
void gg_vbox_render(gg_widget_t *widget, int x, int y, int focus) {
	gg_box_t *box = GG_BOX(widget);
	int nr = gg_container_get_size(GG_CONTAINER(widget));

	y += box->height_a - box->height;

	while (--nr >= 0) {
		int focus_child;
		gg_widget_t *child = gg_container_get_child(GG_CONTAINER(widget), nr);

		if (focus == GG_FOCUS_ALL)
			focus_child = GG_FOCUS_ALL;
		else if (focus == GG_FOCUS_ONE)
			focus_child = (box->sel == nr ? GG_FOCUS_ONE : GG_FOCUS_NONE);
		else
			focus_child = 0;

		child->render(child, x, y, focus_child);
		y += child->height_a;
		y += box->spacing;
	}
}
Beispiel #9
0
int gg_ticker_set_focus_pos(gg_widget_t *widget, int x, int y) {
	gg_box_t *box = GG_BOX(widget);
	gg_container_t *container = GG_CONTAINER(widget);
	int cur_x = widget->width_a - GG_TICKER(widget)->offset;

	box->sel = -1;
	GG_TICKER(widget)->focus_x = x;

	while (gg_select_next(GG_SELECT(widget), 0, 0))
	{
		gg_widget_t *child = gg_container_get_child(container, box->sel);

		if (x >= cur_x && cur_x + child->width_a > x) {
			if (!child->input || !child->enabled)
				box->sel = -1;
			return 1;
		}
		cur_x += child->width_a + box->spacing;
	}

	box->sel = -1;
	return 0;
}