Ejemplo n.º 1
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;
}
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
0
void gg_vbox_set_size(gg_widget_t *widget, int width, int height) {
	int i;

	for (i = 0; i < gg_container_get_size(GG_CONTAINER(widget)); i++) {
		gg_widget_t *child = gg_container_get_child(GG_CONTAINER(widget), i);
		int item_height;

		child->get_requested_size(child, NULL, &item_height);
		child->set_size(child, width, item_height);
	}

	gg_set_size(widget, width, height);
}
Ejemplo n.º 4
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;
}
Ejemplo n.º 5
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;
}
Ejemplo n.º 6
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);
}
Ejemplo n.º 7
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;
}
Ejemplo n.º 8
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);
}
Ejemplo n.º 9
0
void gg_bin_init(gg_bin_t *bin, gg_widget_t *child)
{
    gg_container_init((gg_container_t *) bin);

    bin->set_size = gg_bin_set_size;
    bin->set_focus_pos = gg_bin_set_focus_pos;
    bin->input = gg_bin_input;
    bin->id = gg_bin_get_class_id();
    bin->enabled = child->enabled;
    gg_container_append(GG_CONTAINER(bin), child);
}
Ejemplo n.º 10
0
static gg_dialog_t *create_current_tiles_dialog()
{
    gg_widget_t *dialog;
    gg_widget_t *hbox;
    gg_widget_t *widget;
    gg_widget_t *vbox;

    hbox = gg_hbox_create(0);

    slots[0] = gg_image_create(get_tile_tex(get_tile_slot(0)));
    widget = gg_action_create(slots[0]);
    gg_action_set_callback(GG_ACTION(widget), open_selector, (int*)0);
    gg_container_append(GG_CONTAINER(hbox), widget);

    slots[1] = gg_image_create(get_tile_tex(get_tile_slot(1)));
    widget = gg_action_create(slots[1]);
    gg_action_set_callback(GG_ACTION(widget), open_selector, (int*)1);
    gg_container_append(GG_CONTAINER(hbox), widget);

    slots[2] = gg_image_create(get_tile_tex(get_tile_slot(2)));
    widget = gg_action_create(slots[2]);
    gg_action_set_callback(GG_ACTION(widget), open_selector, (int*)2);
    gg_container_append(GG_CONTAINER(hbox), widget);
 
    vbox = gg_vbox_create(0);
    gg_container_append(GG_CONTAINER(vbox), hbox);

    widget = gg_option_create();
    gg_option_append_label(GG_OPTION(widget), "PL", 0.5f, 0.0f);
    gg_option_append_label(GG_OPTION(widget), "FG", 0.5f, 0.0f);
    gg_option_append_label(GG_OPTION(widget), "Obs", 0.5f, 0.0f);

    gg_option_set_callback(GG_OPTION(widget), edit_layer_changed, NULL);
    gg_container_append(GG_CONTAINER(vbox), widget);

    dialog = gg_dialog_create(vbox, "Tiles", CURRENT_TILES_DIALOG);
    gg_dialog_set_position(GG_DIALOG(dialog), 510, 375, 0.0f, 0.0f);
    gg_dialog_set_style(GG_DIALOG(dialog), get_menu_style() );

    return GG_DIALOG(dialog);
}
Ejemplo n.º 11
0
void gg_container_destroy(gg_widget_t *widget) {
	gg_container_t *container = GG_CONTAINER(widget);
	int i;

	for (i = 0; i < list_get_size(container->widget_list); i++) {
		gg_widget_t *item = GG_WIDGET(list_get_item(container->widget_list, i));
		item->destroy(item);
	}

	list_destroy(container->widget_list);
	gg_widget_destroy(widget);
}
Ejemplo n.º 12
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;
	}
}
Ejemplo n.º 13
0
void gg_ticker_get_requested_size(gg_widget_t *widget, int *width, int *height) {
	gg_container_t *container = GG_CONTAINER(widget);
	int size = gg_container_get_size(container);
	int i;

	widget->height = 0;

	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_height > widget->height)
			widget->height = child_height;
	}

	gg_widget_get_requested_size(widget, width, height);
}
Ejemplo n.º 14
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;
}
Ejemplo n.º 15
0
gg_widget_t *gg_bin_get_child(gg_bin_t *bin)
{
    return gg_container_get_child(GG_CONTAINER(bin), 0);
}
Ejemplo n.º 16
0
gg_dialog_t *dialog_saveload_create(gg_dialog_t *parent, int saving)
{
    gg_widget_t *dialog;
    gg_widget_t *rootvbox = gg_vbox_create(0);
    gg_widget_t *vbox = gg_vbox_create(0);
    gg_widget_t *hbox = gg_vbox_create(0);
    gg_widget_t *hboxtemp;
    gg_widget_t *widget;
    char temp[80];
    char whiteis[80], blackis[80];
    int i=0,j=0;
    int padding=0;

    change_saving=saving;

    if ( !changing_slot )
        saveload_selected=0;

    /*DBG_LOG( "dialog opened with saveselected of %i", saveload_selected );*/

    /* Right side.. */
    if (!changing_slot)
    {
#ifdef _arch_dreamcast
        dc_restore_savegames();
#endif
        for ( i=0; i<SAVEGAME_SLOTS; i++ )
            load_save_xml( i );
    }

    if ( get_slots() & (1 << saveload_selected) )
    {
        gg_widget_t *board_box = gg_vbox_create(0);

        sprintf( temp, "Saved: %s", get_time_save(saveload_selected) );
        widget = gg_label_create(temp);
        gg_container_append(GG_CONTAINER(vbox), widget);

        switch ( get_config_save(saveload_selected)->player[WHITE] )
        {
        case PLAYER_ENGINE:
            sprintf( whiteis, "CPU" );
            break;
        case PLAYER_UI:
            sprintf( whiteis, "Human" );
            break;
        default:
            /* Whoops */
            sprintf( whiteis, "Oh no.." );
            break;
        }

        switch ( get_config_save(saveload_selected)->player[BLACK] )
        {
        case PLAYER_ENGINE:
            sprintf( blackis, "CPU" );
            break;
        case PLAYER_UI:
            sprintf( blackis, "Human" );
            break;
        default:
            /* Whoops */
            sprintf( blackis, "Oh no.." );
            break;
        }

        sprintf( temp, "%s vs %s", whiteis, blackis );
        widget = gg_label_create(temp);
        gg_container_append(GG_CONTAINER(vbox), widget);

        sprintf( temp, "Difficulty: %s",
            get_config_save(saveload_selected)->difficulty ? "Normal" : "Easy" );
        widget = gg_label_create(temp);
        gg_container_append(GG_CONTAINER(vbox), widget);

        sprintf( temp, "Level: %i",
            get_config_save(saveload_selected)->cpu_level );
        widget = gg_label_create(temp);
        gg_container_append(GG_CONTAINER(vbox), widget);

        widget = gg_label_create(" ");
        gg_container_append(GG_CONTAINER(vbox), widget);

        /* create board.. */

        for ( i=7; i>=0; i-- )
        {
            gg_widget_t *hboxtemp2;
            gg_colour_t col_white =
                {
                    1.0f, 1.0f, 1.0f, 1.0f
                };
            /*gg_colour_t col_grey =
                {
                    0.3f, 0.3f, 0.3f, 1.0f
                };*/
            hboxtemp = gg_hbox_create(0);
            hboxtemp2 = gg_hbox_create(0);
            gg_set_requested_size(hboxtemp2, 20, 20);
            gg_container_append(GG_CONTAINER(hboxtemp), hboxtemp2);

            for ( j=0; j<8; j++ )
            {
                gg_colour_t col_green = {0.5, 0.6, 0.5, 1.0};
                gg_colour_t col_yellow = {0.8, 0.7, 0.4, 1.0};
                gg_colour_t front, *back;
                int square = get_saved_board(saveload_selected)->square[i * 8 + j];

                sprintf(temp, "%c", xmlsquaretofont(square));
                widget = gg_label_create( temp );
                gg_set_requested_size(widget, 20, 20);
                gg_align_set_alignment(GG_ALIGN(widget), 0.5, 0.5);

                if (COLOUR(square) == WHITE)
                    front = col_white;
                else
                    front = *get_col(COL_BLACK);

                if ((i + j) % 2 == 0)
                    back = &col_green;
                else
                    back = &col_yellow;

                /* FIXME Hack to turn off shadow */
                front.a = 2.0f;

                gg_label_set_colour(GG_LABEL(widget), &front, back);
                gg_container_append(GG_CONTAINER(hboxtemp), widget);
            }
            gg_container_append(GG_CONTAINER(board_box), hboxtemp);
        }
        gg_container_append(GG_CONTAINER(vbox), board_box);
    }
    else
    {
        sprintf( temp, "Empty slot" );
        widget = gg_label_create(temp);
        gg_container_append(GG_CONTAINER(vbox), widget);

        for ( i=0; i<12; i++ )
        {
            widget = gg_label_create(" ");
            gg_container_append(GG_CONTAINER(vbox), widget);
        }
    }
    gg_set_requested_size(vbox, 201, 0);
    gg_container_append(GG_CONTAINER(hbox), gg_frame_create(vbox));

    /* left side */
    vbox = gg_vbox_create(0);
    /* padding.. */
    for ( i=0; i<padding; i++ )
    {
        widget = gg_label_create(" ");
        gg_container_append(GG_CONTAINER(vbox), widget);
    }

    widget = gg_option_create();
    for ( i=0; i<SAVEGAME_SLOTS; i++ )
    {
        sprintf( temp, "Save slot: %i", i+1 );
        gg_option_append_label(GG_OPTION(widget), temp, 0.5f, 0.0f);
    }
    gg_widget_subscribe_signal_name(widget, widget->id, "option_changed", 
        dialog_saveload_change, widget);
    gg_container_append(GG_CONTAINER(vbox), widget);

    if ( changing_slot )
        gg_option_set_selected(GG_OPTION(widget), saveload_selected);

    if ( saving )
    {
        widget = gg_action_create_with_label("Save Game", 0.5f, 0.0f);
        gg_widget_subscribe_signal_name(widget, widget->id, "action_pressed", 
            dialog_savegame_save, vbox);
    }
    else
    {
        widget = gg_action_create_with_label("Load Game", 0.5f, 0.0f);
        gg_widget_subscribe_signal_name(widget, widget->id, "action_pressed", 
            dialog_loadgame_load, vbox);
    }
    gg_container_append(GG_CONTAINER(vbox), widget);

    widget = gg_action_create_with_label("Cancel", 0.5f, 0.0f);
    gg_widget_subscribe_signal_name(widget, widget->id, "action_pressed", 
        dialog_close_cb, NULL);
    gg_container_append(GG_CONTAINER(vbox), widget);

    /*for ( i=0; i<SAVEGAME_SLOTS; i++ )
    {
        sprintf( temp, "%i:  ", i );
        widget = gg_action_create_with_label(temp, 0.0f, 0.0f);

        gg_action_set_callback(GG_ACTION(widget), dialog_saveload_change, vbox);

        gg_container_append(GG_CONTAINER(vbox), widget);
    }*/

    gg_container_append(GG_CONTAINER(hbox), vbox );

    if ( changing_slot )
        gg_vbox_set_selected(vbox, padding );

    /* Dialog stuff */
    gg_container_append(GG_CONTAINER(rootvbox), hbox);
    dialog = gg_dialog_create(rootvbox, NULL, parent, GG_DIALOG_AUTOHIDE_PARENT);

    if ( saving )
        gg_dialog_set_style(GG_DIALOG(dialog), get_ingame_style());
    else
        gg_dialog_set_style(GG_DIALOG(dialog), get_menu_style());

    return GG_DIALOG(dialog);
}