Ejemplo n.º 1
0
static int gui_button_on_draw(gwidget *widget, gevent *event)
{
	gui_widget_draw(widget);
	gui_widget_set_text(widget, widget->string);
	gui_widget_react(widget->child, event);
	return 0;
}
Ejemplo n.º 2
0
void gui_progressbar_set_max( 
    GuiWidget *widget, int max )
{
    if ( widget->type != GUI_PROGRESSBAR ) return;
    /* set max */
    widget->spec.progressbar.max = max;
    gui_progressbar_adjust( widget );
    /* done */
    if ( widget->visible )
        gui_widget_draw( widget );
}
Ejemplo n.º 3
0
/*
====================================================================
Get/Set value and limit of progressbar.
====================================================================
*/
void gui_progressbar_set_value( 
    GuiWidget *widget, int value )
{
    if ( widget->type != GUI_PROGRESSBAR ) return;
    /* set value */
    widget->spec.progressbar.value = value;
    gui_progressbar_adjust( widget );
    /* done */
    if ( widget->visible )
        gui_widget_draw( widget );
}
Ejemplo n.º 4
0
static void default_event_handler( 
    GuiWidget *widget, GuiEvent *event )
{
    switch ( event->type ) {
        case GUI_DESTROY:
            break;
        case GUI_DRAW:
            /* display surface */
            stk_surface_blit( 
                widget->surface, 0,0,-1,-1, 
                stk_display, 
                widget->screen_region.x,
                widget->screen_region.y );
            /* add progress */
            stk_surface_apply_wallpaper( stk_display,
                widget->screen_region.x + widget->border,
                widget->screen_region.y + widget->border,
                widget->spec.progressbar.length,
                widget->screen_region.h - (widget->border<<1),
                widget->spec.progressbar.wallpaper, -1 );
            /* if focused add info */
            if ( widget->focused ) {
                gui_theme->progressbar_font->align = 
                    STK_FONT_ALIGN_CENTER_X | 
                    STK_FONT_ALIGN_CENTER_Y;
                snprintf( progressbar_hint, 32, "%i/%i",
                          widget->spec.progressbar.value,
                          widget->spec.progressbar.max );
                stk_font_write( gui_theme->progressbar_font, 
                    stk_display, 
                    widget->screen_region.x + 
                    widget->screen_region.w/2,
                    widget->screen_region.y + 
                    widget->screen_region.h/2,
                    -1, progressbar_hint );
            }
            break;
        case GUI_FOCUS_IN:
        case GUI_FOCUS_OUT:
            gui_widget_draw( widget );
            break;
    }
}
Ejemplo n.º 5
0
/*
====================================================================
Set or check if a checkbox in the radiogroup is set.
Stores refresh rects if visible.
====================================================================
*/
void gui_radiogroup_set_checked( 
    GuiWidget *widget, int id, int check )
{
    if ( widget->type != GUI_RADIOGROUP )
        return;
    if ( id >= widget->spec.radiogroup.size || id < 0 )
        return;
    /* if there is at maximum one item selectable
       we clear the selection to simplify usage */
    if ( widget->spec.radiogroup.max == 1 ) {
        memset( widget->spec.radiogroup.checks, 0, 
                widget->spec.radiogroup.size * sizeof( int ) );
        widget->spec.radiogroup.check_count = 0;
        widget->spec.radiogroup.single_check = -1;
    }
    if ( check ) {
        /* select item if possible */
        if ( widget->spec.radiogroup.check_count ==
             widget->spec.radiogroup.max )
            return;
        /* if only one selection is allowed unselect old checker */
        widget->spec.radiogroup.checks[id] = 1;
        widget->spec.radiogroup.single_check = id;
        widget->spec.radiogroup.check_count++;
    }
    else {
        /* unselect item if possible */
        if ( widget->spec.radiogroup.check_count ==
             widget->spec.radiogroup.min )
            return;
        if ( widget->spec.radiogroup.checks[id] == 0 )
            return;
        widget->spec.radiogroup.checks[id] = 0;
        widget->spec.radiogroup.single_check = -1;
        widget->spec.radiogroup.check_count--;
    }
    if ( widget->visible )
        gui_widget_draw( widget );
}
Ejemplo n.º 6
0
/*
====================================================================
Handle confirmation/cancelling of confirmation dialogue.
====================================================================
*/
void client_confirm( GuiWidget *widget, GuiEvent *event )
{
#ifdef NETWORK_ENABLED
	if ( event->type != GUI_CLICKED ) return;
	gui_widget_hide( dlg_confirm );
	msg_begin_writing( msgbuf, &msglen, MAX_MSG_SIZE );
	switch ( client_state ) {
		case CLIENT_ANSWER:
			msg_write_int8( MSG_ACCEPT_CHALLENGE );
			client_transmit( CODE_BLUE, msglen, msgbuf );

			/* play */
			gui_disable_event_filter();
			if ( client_game_init_network( mp_peer_name, mp_diff ) )
				client_game_run();
			client_game_finalize();
			gui_enable_event_filter();

			gui_widget_draw( dlg_chatroom );
			stk_display_fade( STK_FADE_IN, STK_FADE_DEFAULT_TIME );
			break;
	}
#endif
}
Ejemplo n.º 7
0
static void client_parse_packet()
{
	int i, num;
	char name[16];
	unsigned char type;
	int handled;
	
	while ( 1 ) {
		type = (unsigned)msg_read_int8(); handled = 0;
		
		if ( msg_read_failed() ) break; /* no more messages */

		switch ( type ) {
		    	case MSG_PREPARE_FULL_UPDATE:
				/* do only clear users as channels and
				 * levelsets are fixed */
				list_clear( client_users ); client_user = 0;
				handled = 1;
				break;
			case MSG_ERROR:
				client_printf_chatter( 1, _("ERROR: %s"), msg_read_string() );
				handled = 1;
				break;
			case MSG_BUSY:
				if ( client_state == CLIENT_AWAIT_ANSWER ||
				     client_state == CLIENT_AWAIT_TRANSFER_CONFIRMATION )
					client_popup_info( 
						_("%s is busy at the moment."), 
						mp_peer_name );
				handled = 1;
				break;
			case MSG_DISCONNECT:
				client_disconnect();
				handled = 1;
				break;
			case MSG_SET_COMM_DELAY:
				client_comm_delay = msg_read_int16();
				printf( _("comm_delay set to %i\n"), client_comm_delay );
				handled = 1;
				break;
			/* chatter */
			case MSG_SERVER_INFO:
				client_add_chatter( msg_read_string(), 1 );
				handled = 1;
				break;
			case MSG_CHATTER:
				client_add_chatter( msg_read_string(), 0 );
				handled = 1;
				break;
			/* users */
			case MSG_ADD_USER:
				num = msg_read_int32();
				snprintf( name, 16, "%s", msg_read_string() ); name[15] = 0;
				if ( msg_read_failed() ) break;
				client_add_user( num, name );
				gui_list_update( 
						list_users, 
						client_users->count );
				/* re-select current entry */
				if ( client_user ) {
					num = list_check( client_users, client_user );
					if ( num != -1 )
						gui_list_select( list_users, 0, num, 1 );
				}
				handled = 1;
				break;
			case MSG_REMOVE_USER:
				num = msg_read_int32();
				if ( msg_read_failed() ) break;
				client_remove_user( num );
				gui_list_update( 
					list_users, 
					client_users->count );
				/* re-select current entry */
				if ( client_user ) {
					num = list_check( client_users, client_user );
					if ( num != -1 )
						gui_list_select( list_users, 0, num, 1 );
				}
				handled = 1;
				break;
			case MSG_CHANNEL_LIST:
				list_clear( client_channels );
				num = msg_read_int8();
				for ( i = 0; i < num; i++ )
					list_add( client_channels, strdup(msg_read_string()) );
				handled = 1;
				break;
			case MSG_LEVELSET_LIST:
				list_clear( client_levelsets );
				num = msg_read_int8();
				for ( i = 0; i < num; i++ )
					list_add( client_levelsets, strdup(msg_read_string()) );
    				gui_list_update( list_levels, client_levelsets->count );
				handled = 1;
				break;
			case MSG_ADD_LEVELSET:
				list_add( client_levelsets, strdup(msg_read_string()) );
    				gui_list_update( list_levels, client_levelsets->count );
				handled = 1;
				break;
			case MSG_SET_CHANNEL:
				/* we only need to update the name */
				gui_label_set_text( label_channel, msg_read_string() );
				handled = 1;
				break;
			/* challenge */
			case MSG_CHALLENGE:
				/* the user may only be challenged if client state is NONE
				   because otherwise he is doing something that shouldn't be
				   interrupted */
				if ( client_state != CLIENT_NONE ) {
					msg_begin_writing( msgbuf, &msglen, 128 );
					msg_write_int8( MSG_BUSY );
					msg_write_int32( msg_read_int32() );
					client_transmit( CODE_BLUE, msglen, msgbuf );
					break;
				}
				snprintf( mp_peer_name, 15, "%s", msg_read_string() );
				snprintf( mp_levelset, 16, "%s", msg_read_string() );
				mp_diff = msg_read_int8();
				mp_rounds = msg_read_int8();
				mp_frags = msg_read_int8();
				mp_balls = msg_read_int8();
				if ( msg_read_failed() ) break;
				client_popup_confirm( _("    You have been challenged!##"\
						"    Challenger: %13s#"\
						"    Levelset:   %13s#"\
						"    Difficulty: %13s#"\
						"    Rounds:     %13i#"\
						"    Frag Limit: %13i#"\
						"    Balls:      %13i"),
						mp_peer_name, mp_levelset, mp_diff_names[mp_diff],
						mp_rounds, mp_frags, mp_balls );
				client_state = CLIENT_ANSWER;
				handled = 1;
				break;
			case MSG_REJECT_CHALLENGE:
				handled = 1;
				if ( client_state != CLIENT_AWAIT_ANSWER ) break;
				client_popup_info( 
					_("%s is too scared to accept your challenge."), 
					mp_peer_name );
				break;
			case MSG_CANCEL_GAME:
				handled = 1;
				if ( client_state != CLIENT_ANSWER ) break;
				gui_widget_hide( dlg_confirm );
				client_popup_info( _("%s got cold feet."), mp_peer_name );
				break;
			case MSG_ACCEPT_CHALLENGE:
				handled = 1;
				if ( client_state != CLIENT_AWAIT_ANSWER ) break;
				gui_widget_hide( dlg_info );

				/* play */
				gui_disable_event_filter();
				if ( client_game_init_network( mp_peer_name, mp_diff ) )
					client_game_run();
				client_game_finalize();
				gui_enable_event_filter();

				gui_widget_draw( dlg_chatroom );
				stk_display_fade( STK_FADE_IN, STK_FADE_DEFAULT_TIME );
				break;

			/* dummy parse game packets that may arrive after the QUIT_GAME
			 * message was sent because ADD_USER commands may be in the
			 * package and these we should get. */
			case MSG_PADDLE_STATE:
				comm_unpack_paddle_dummy( net_buffer, &msg_read_pos );
				handled = 1;
				break;
			case MSG_SHOT_POSITIONS:
				comm_unpack_shots_dummy( net_buffer, &msg_read_pos );
				handled = 1;
				break;
			case MSG_BALL_POSITIONS:
				comm_unpack_balls_dummy( net_buffer, &msg_read_pos );
				handled = 1;
				break;
			case MSG_SCORES:
				comm_unpack_scores_dummy( net_buffer, &msg_read_pos );
				handled = 1;
				break;
			case MSG_BRICK_HITS:
				comm_unpack_brick_hits_dummy( net_buffer, &msg_read_pos );
				handled = 1;
				break;
			case MSG_NEW_EXTRAS:
				comm_unpack_collected_extras_dummy( net_buffer, &msg_read_pos );
				handled = 1;
				break;
			case MSG_ROUND_OVER:
				i = msg_read_int8();
				handled = 1;
				break;
			case MSG_LAST_ROUND_OVER:
				i = msg_read_int8();
				handled = 1;
				break;

		}

		if ( !handled ) {
			printf( _("chat: state %i: invalid message %x: skipping %i bytes\n"),
				client_state, type, net_buffer_cur_size - msg_read_pos );
			msg_read_pos = net_buffer_cur_size;
		}
	}
}