示例#1
0
/** Implements widget::input for scrollbox widgets. */
int gg_scrollbox_input(gg_widget_t *widget, gg_event_t event)
{
    gg_widget_t *child = gg_bin_get_child(GG_BIN(widget));
    gg_scrollbox_t *scrollbox = GG_SCROLLBOX(widget);
    gg_widget_t *view_child = gg_bin_get_child(GG_BIN(child));
    float yscroll=GG_VIEWPORT(child)->yscroll;
    int sliderpos=1;
    int slidersize=16;
    float newpos=0;

    if ( event.type == GG_EVENT_MOUSE && event.mouse.x>(widget->width-16) && 
        event.mouse.x<(widget->width) )
    {
        if ( event.mouse.y < 16 && yscroll-0.05>=0.0f && event.mouse.type == GG_MOUSE_BUTTON_UP )
            gg_viewport_set_scroll_ypos(GG_VIEWPORT(child), yscroll-=0.05 );

        if ( event.mouse.y > widget->height-16 && yscroll+0.05<=1.0f && event.mouse.type == GG_MOUSE_BUTTON_UP )
            gg_viewport_set_scroll_ypos(GG_VIEWPORT(child), yscroll+=0.05 );

        /* Are we over the grabber? */
        slidersize=((float)child->height/(float)view_child->height)*(widget->height-32);
        sliderpos=((widget->height-(32)+1-slidersize)*(1.0-yscroll))-1;

        if ( event.mouse.y >= widget->height-16-slidersize-sliderpos && event.mouse.y <= 
            widget->height-16-sliderpos && event.mouse.type == GG_MOUSE_BUTTON_DOWN )
        {
            GG_SCROLLBOX(widget)->grabbed=TRUE;          
        } 
      
        if ( event.mouse.type == GG_MOUSE_BUTTON_UP )      
        {
            GG_SCROLLBOX(widget)->grabbed=FALSE;   
        }

        if ( GG_SCROLLBOX(widget)->grabbed )
        {      
            newpos=((float)event.mouse.y-16.0f)/((float)widget->height-32.0f);            

            if ( newpos >= 0.0f && newpos <= 1.0f )
                gg_viewport_set_scroll_ypos(GG_VIEWPORT(child), ((float)event.mouse.y-16.0f)/((float)widget->height-32.0f) );
            /*printf( "Moved %f / %f = %f\n", (float)(event.mouse.y-16.0f), (widget->height-32), GG_VIEWPORT(child)->yscroll );*/
        }

        return 1;
    }
    else
        return child->input(child, event);

    return 0;
}
示例#2
0
int gg_bin_input(gg_widget_t *widget, gg_event_t event)
{
    gg_widget_t *child = gg_bin_get_child(GG_BIN(widget));

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

    return 0;
}
示例#3
0
int gg_bin_set_focus_pos(gg_widget_t *widget, int x, int y)
{
    gg_widget_t *child = gg_bin_get_child(GG_BIN(widget));

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

    return 0;
}
示例#4
0
void gg_bin_set_size(gg_widget_t *widget, int width, int height)
{
    gg_widget_t *child = gg_bin_get_child(GG_BIN(widget));

    if (child)
        child->set_size(child, width, height);

    gg_set_size(widget, width, height);
}
示例#5
0
/** Implements widget::render for scrollbox widgets. */
void gg_scrollbox_render(gg_widget_t *widget, int x, int y, int focus)
{
    gg_widget_t *child = gg_bin_get_child(GG_BIN(widget));
    gg_scrollbox_t *scrollbox = GG_SCROLLBOX(widget);
    gg_widget_t *view_child = gg_bin_get_child(GG_BIN(child));
    gg_rect_t source, dest;
    int sliderpos=1;
    int slidersize=16;
    float yscroll=GG_VIEWPORT(child)->yscroll;
    gg_widget_t *parent=widget;
    gg_dialog_style_t *style;

    source.x=source.y=0;
    source.width=source.height=16;

    /* Draw Top Left Corner */
    dest.x = x+widget->width-16.0f; dest.y = y;
    dest.width = 16; dest.height = 16;
    gg_system_draw_image(gg_dialog_get_current_style()->widget_images[1], source, dest, 
        GG_MODE_TILE, GG_MODE_SCALE, &col_white, FALSE);

    dest.x = x+widget->width-16.0f; dest.y = y+16;
    dest.width = 16; dest.height = widget->height-(32);
    gg_system_draw_image(gg_dialog_get_current_style()->widget_images[4], source, dest, 
        GG_MODE_TILE, GG_MODE_SCALE, &col_white, FALSE);

    dest.x = x+widget->width-16.0f; dest.y = y+widget->height-16;
    dest.width = 16; dest.height = 16;
    gg_system_draw_image(gg_dialog_get_current_style()->widget_images[0], source, dest, 
        GG_MODE_TILE, GG_MODE_SCALE, &col_white, FALSE);

    /* Draw the slider! */
    slidersize=((float)child->height/(float)view_child->height)*(widget->height-32);
    sliderpos=((widget->height-(32)+1-slidersize)*yscroll)-1;

    dest.x = x+widget->width-16.0f; dest.y = y+16+sliderpos;
    dest.width = 16; dest.height = slidersize;
    gg_system_draw_image(gg_dialog_get_current_style()->widget_images[7], source, dest, 
        GG_MODE_TILE, GG_MODE_SCALE, &col_white, FALSE);

    child->render(child, x, y, GG_FOCUS_NONE);
}
示例#6
0
/** @brief Renders a dialog.
 *
 *	Renders a dialog in a specific style and at a specific position.
 *
 *	@param menu The dialog to render.
 *	@param style The style to render in.
 *	@param pos The position to render at.
 */
void gg_dialog_render(gg_dialog_t *dialog, int active)
{
	gg_dialog_style_t *style = &dialog->style;
	gg_widget_t *child = gg_bin_get_child(GG_BIN(dialog));
	int size = 0;
	gg_rect_t area;

	int xmin, xmax, ymin, ymax;

	if (dialog->flags & GG_DIALOG_HIDDEN)
		return;

	gg_dialog_get_screen_pos(dialog, &xmin, &ymin);

	xmax = (xmin + dialog->width);
	ymax = (ymin + dialog->height);

	/* Draw the 'fade' */
	gg_system_draw_filled_rect(0, 0, 640, 480, &style->fade_col);

	if (style->textured)
		gg_system_get_image_size(style->border.image[0], &size, NULL);

	xmin += size;
	xmax -= size;
	ymin += size;
	ymax -= size;

	area.x = xmin;
	area.y = ymin;
	area.width = xmax - xmin;
	area.height = ymax - ymin;

	if (dialog_in_trans)
		area.height *= dialog_get_transition();

	if (style->textured)
		draw_border(style->border.image, dialog->title, active, area, size);

	xmin += style->hor_pad;
	xmax -= style->hor_pad;
	ymin += style->vert_pad;
	ymax -= style->vert_pad;

	if (!dialog_in_trans)
		child->render(child, xmin, ymin, active);

	dialog_get_transition();
}
示例#7
0
void gg_dialog_set_style(gg_dialog_t *dialog, gg_dialog_style_t *style)
{
	int size;
	gg_widget_t *child = gg_bin_get_child(GG_BIN(dialog));

	dialog->style = *style;
	dialog->width = child->width_a + 2 * dialog->style.hor_pad;
	dialog->height = child->height_a + 2 * dialog->style.vert_pad;

	if (style->textured)
	{
		gg_system_get_image_size(style->border.image[0], &size, NULL);
		dialog->width += 2 * size;
		dialog->height += 2 * size;
	}

	if (dialog->title)
	{
		int text_height;
		gg_system_get_string_size(dialog->title, NULL, &text_height);
		dialog->height += text_height * GG_DIALOG_TITLE_FACT;
		dialog->height += GG_DIALOG_TITLE_SEP_HEIGHT;
	}
}
示例#8
0
int gg_dialog_input(gg_widget_t *widget, gg_event_t event)
{
	gg_dialog_t *dialog = GG_DIALOG(widget);
	gg_widget_t *child = gg_bin_get_child(GG_BIN(widget));
	int x, y;

	if (dialog->flags & GG_DIALOG_HIDDEN)
		return 0;

	if (!dialog->modal && event.type == GG_EVENT_KEY && event.key == GG_KEY_ESCAPE )
		gg_dialog_close();

	if (!dialog->modal && event.type == GG_EVENT_MOUSE && event.mouse.type == GG_MOUSE_BUTTON_DOWN &&
		event.mouse.button == 2 )
		gg_dialog_close();

	gg_dialog_get_screen_pos(dialog, &x, &y);

	if (event.type == GG_EVENT_MOUSE)
	{
		int size = 0;

		event.mouse.x -= x;
		event.mouse.y -= y;

		if (dialog->style.textured)
			gg_system_get_image_size(dialog->style.border.image[0], &size, NULL);

		if (event.mouse.type == GG_MOUSE_BUTTON_DOWN
			&& event.mouse.button == 0)
		{
			if (dialog->title)
			{
				int text_height;
				int titlebar_height;
				gg_system_get_string_size(dialog->title, NULL, &text_height);
				titlebar_height = text_height * GG_DIALOG_TITLE_FACT;

				dialog->dialog_state |= GG_DIALOG_LEFT_BUTTON;

				/* Mouse click outside of dialog */
				if (event.mouse.y >= dialog->height || event.mouse.y < 0
					|| event.mouse.x >= dialog->width || event.mouse.x < 0)
					return 0;

				gg_dialog_set_active(dialog);

				/* Title bar click */
				if (event.mouse.y >= dialog->height - size - titlebar_height
					&& event.mouse.y < dialog->height - size
					&& event.mouse.x >= size
					&& event.mouse.x < dialog->width - size)
				{
					dialog->dialog_state |= GG_DIALOG_MOVING;
					dialog->movement_org_x = event.mouse.x;
					dialog->movement_org_y = event.mouse.y;
					return 1;
				}
			}
		}
		else if (event.mouse.type == GG_MOUSE_BUTTON_UP
			&& event.mouse.button == 0)
		{
			if (dialog->title)
			{
				dialog->dialog_state &= ~GG_DIALOG_LEFT_BUTTON;
				if (dialog->dialog_state & GG_DIALOG_MOVING)
				{
					dialog->dialog_state &= ~GG_DIALOG_MOVING;
					return 1;
				}
			}
		}

		if ((event.mouse.type == GG_MOUSE_MOVE)
			&& (dialog->dialog_state & GG_DIALOG_MOVING))
		{
			int xoff = dialog->width * dialog->pos.x_align;
			int yoff = dialog->height * dialog->pos.y_align;

			gg_dialog_set_position(dialog, x + event.mouse.x - dialog->movement_org_x + xoff,
								   y + event.mouse.y - dialog->movement_org_y + yoff,
								   dialog->pos.x_align, dialog->pos.y_align);
		}

		event.mouse.x -= size + dialog->style.hor_pad;
		event.mouse.y -= size + dialog->style.vert_pad;

		if (!(event.mouse.type == GG_MOUSE_MOVE
			&& dialog->dialog_state & GG_DIALOG_LEFT_BUTTON))
		{
			gg_widget_t *child = gg_bin_get_child(GG_BIN(dialog));

			if (event.mouse.x >= 0 && event.mouse.x < child->width_a
				&& event.mouse.y >= 0 && event.mouse.y < child->height_a)
				dialog->set_focus_pos(GG_WIDGET(dialog), event.mouse.x, event.mouse.y);
		}
	}

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

	return 0;
}