Пример #1
0
/*
====================================================================
Close statistics
====================================================================
*/
void client_close_stats( GuiWidget *widget, GuiEvent *event )
{
	if ( event->type != GUI_CLICKED ) return;
	gui_widget_hide( dlg_stats );
	client_state = CLIENT_NONE;
	gui_label_set_text( label_stats, _("Awaiting stats...") );
	gui_label_set_text( label_winner, "..." );
}
Пример #2
0
/*
====================================================================
Popup confirm dialogue and _keep_ status.
====================================================================
*/
void client_popup_confirm( char *format, ... )
{
	char buffer[256];
	va_list args;
	va_start( args, format );
	vsnprintf( buffer, 256, format, args );
	va_end( args );
	gui_label_set_text( label_confirm, buffer );
	gui_widget_show( dlg_confirm );
}
Пример #3
0
/*
====================================================================
Popup info dialogue and set status to INFO.
====================================================================
*/
void client_popup_info( char *format, ... )
{
	char buffer[256];
	va_list args;
	va_start( args, format );
	vsnprintf( buffer, 256, format, args );
	va_end( args );
	gui_label_set_text( label_info, buffer );
	gui_widget_show( dlg_info );
	client_state = CLIENT_INFO;
}
Пример #4
0
/*
====================================================================
Disconnect from current server if any.
====================================================================
*/
void client_disconnect()
{
#ifdef NETWORK_ENABLED
	char buf[128];
	
	if ( !client_is_connected ) return;
	
	/* disconnect */
	socket_print_stats( &client );
	sprintf( buf, _("disconnected from %s"), 
		 net_addr_to_string(&client.remote_addr) );
	client_add_chatter( buf, 1 );
	buf[0] = MSG_DISCONNECT;
	client_transmit( CODE_BLUE, 1, buf );
	client_is_connected = 0;
	client_data_clear();
	gui_label_set_text( label_channel, "MAIN" );
#endif
}
Пример #5
0
void demo_init_gui(void)
{
    init_font();


    root1 = gui_create_control(GUI_CTRL_FORM, 6, 6, 1012, 756, 3, 0, 0, FORM_STYLE_XP_BORDER);    
    if(!root1)return;
    gui_form_init_private(root1, 32);
    gui_form_set_caption(root1, "Root1");

    root2 = gui_create_control(GUI_CTRL_FORM, 400, 360, 560, 345, 8, 64, 0, 0);
    if(!root2)return; 
    gui_form_init_private(root2, 32);
    gui_form_set_caption(root2, "Root2");

    form1 = gui_create_control(GUI_CTRL_FORM, 180, 50, 320, 82, 5, 0, 0, FORM_STYLE_XP_BORDER);
    if(!form1)return; 
    gui_form_init_private(form1, 32);
    gui_form_set_caption(form1, "Form1");

    label1 = gui_create_control(GUI_CTRL_LABEL, 50, 50, 100, 32, 4, 0, 0, LABEL_STYLE_BORDER);
    if(!label1)return; 
    gui_label_init_private(label1, 32);
    gui_label_set_text(label1, "标签");

    edit1 = gui_create_control(GUI_CTRL_EDIT, 50, 100, 100, 32, 9, 0, 0, 0);
    gui_edit_init_private(edit1, 32);
    gui_edit_set_text(edit1, "this is a edit!");
    if(!edit1)return; 

    button1 = gui_create_control(GUI_CTRL_BUTTON, 3, 3, 314, 32, 9, 0, 0, 0);
    if(!button1)return;
   
    progress1 = gui_create_control(GUI_CTRL_PROGRESS, 50, 150, 420, 32, 1, 0, 0, 0);
    if(!progress1)return; 
    gui_set_control_associated(progress1, &assoc1, 0);
    gui_progress_init_private(progress1);

    my_control = gui_create_control(my_ctrl_id, 0, 0, 0, 0, 0, 0, 0, 0);
    if(!my_control)return;

    about_system_root = gui_create_control(GUI_CTRL_FORM, 6, 6, 1012, 756, 3, 0, 0, FORM_STYLE_XP_BORDER);  
    if(!about_system_root)return;
    gui_form_init_private(about_system_root, 32);
    gui_form_set_caption(about_system_root, "about_system_root");
    
    sys_monitor = gui_create_control(GUI_CTRL_SYS_MNTR, 16, 16, 1, 1, 0, 0, 0, SYS_MNTR_STYLE_STATIC_BDR|SYS_MNTR_STYLE_NO_BORDER);
    if(!sys_monitor)return;
    gui_sys_mntr_init_private(sys_monitor);

    pic1 = gui_create_control(GUI_CTRL_PICTURE, 50, 200, 150, 100, 0, 0, 0, 0);
    gui_picture_init_private(pic1);
    if(1){
        InitBMPINFO(&info[0]);
        LoadBmp(&info[0], "demo.bmp");
        InitBMPINFO(&info[1]);
        LoadBmp(&info[1], "demo1.bmp");
        InitBMPINFO(&info[2]);
        LoadBmp(&info[2], "demo2.bmp");
        InitBMPINFO(&info[3]);
        LoadBmp(&info[3], "demo3.bmp");
        InitBMPINFO(&info[4]);
        LoadBmp(&info[4], "demo4.bmp");
        InitBMPINFO(&info[5]);
        LoadBmp(&info[5], "demo5.bmp");
        gui_picture_set_picture(pic1, &info);
    }
        
    gui_control_link(NULL, root1);
    gui_control_link(NULL, root2);

    gui_control_link(about_system_root, sys_monitor);
    
    gui_control_link(root2, form1);
    gui_control_link(root2, my_control);
    gui_control_link(root2, label1);
    gui_control_link(root2, edit1);
    gui_control_link(form1, button1);
    gui_control_link(root2, progress1);
    gui_control_link(root2, pic1);

    RegisterKeyHook(gui_keyhook);

    init_welcome_screen();

    StartGUI();
    return;
}
Пример #6
0
void __task refresh_task(void * data)
{
    long count = 0;
    char buf[64];
    int flag = 0;

    data = data;

    for (;;) {
        sprintf(buf, "[%d%%] %ld $ %ld", CPU_USED, count, 50000-count*3);
        count++;
        if (count >= 5000)
            count = 1;
        gui_label_set_text(label, buf);

        #if 0
        gui_form_set_caption(form, buf);
        #endif

        sprintf(buf, "[%d%%] %ld 将那个Label盖住", CPU_USED, count*3);
        gui_button_set_caption(button, buf);

        if (0) {
            static int f = 0, i = 0;
            static KEYCODE key, test_keys[] = {'d', ENTER, ESC, 'f', ENTER, 'h', ENTER, ESC};

            if (--f <= 0) {
                f = 1;
                /* key = test_keys[i++]; */
                key = (random(128) * random(128)) % 128;
                if (key < 0x10 && key != ESC) {
                    key += 0x10;
                }
                putkey(key);
                if (i >= sizeof(test_keys))
                    i = 0;
            }
        }

        if (1) {
            static int f = 0, x = 0, y = 0;

            if (--f <= 0) {
                f = 20;
                x = random(900);
                y = random(700);
                gui_window_moveto(window3, x, y);
            }
        }        
	
        if (1) {
            static int f = 0, x = 0;
            char buf[32];

            if (--f <= 0) {
                f = 10;
                x = random(20000);
                sprintf(buf, "random() = %d", x);
                gui_edit_set_text(edit, buf);
            }
        }

        if (moveto_now) {
            moveto_now = 0;
            gui_window_moveto(window3, moveto_x, moveto_y);
        }

        TaskSleep(20);
    }
}
Пример #7
0
void demo_init_gui(void)
{
    InitBMPINFO(&icon);
    LoadBmp(&icon, "icon.bmp");
    load_fonts();

    gui_desktop_enable();
    gui_desktop_set_color(CLRSCR_COLOR2);
    
    form = gui_create_widget(GUI_WIDGET_FORM, 180, 120, 632, 500, 0, 0, 0, FORM_STYLE_XP_BORDER|FORM_STYLE_TITLE);
    if(!form)
        goto err;
    gui_form_init_private(form, 128);
    gui_form_set_caption(form, "控件演示");
    gui_form_set_icon(form, &icon);

    edit = gui_create_widget(GUI_WIDGET_EDIT, 80, 270, 460, 48, color, bkcolor, 0, style);
    if(!edit)
        goto err;
    gui_edit_init_private(edit, 128);
    gui_edit_set_text(edit, "这是一个文本框");

    button = gui_create_widget(GUI_WIDGET_BUTTON, 235+156, 142+100, 236, 32, COLOR_YELLOW, 64, font16, 0); /*BUTTON_STYLE_CLIENT_BDR*/
    if(!edit)
        goto err;
    gui_button_init_private(button, 128);
    gui_button_set_caption(button, "将那个Label盖住");

    test = gui_create_widget(GUI_WIDGET_EDIT, 80, 330, 460, 32, 0, 0, 0, 0);
    if(!test)
        goto err;
    gui_edit_init_private(test, 128);
    gui_edit_set_text(test, "");

    label = gui_create_widget(GUI_WIDGET_LABEL, 80, 380, 460, 64, COLOR_WHITE, 66, font48, LABEL_STYLE_SUBSIDE);
    if(!edit)
        goto err;
    gui_label_init_private(label, 128);
    gui_label_set_text(label, "Startting...");

    view = gui_create_widget(GUI_WIDGET_VIEW, 80, 48, 460, 200, 0, 0, 0, VIEW_STYLE_NONE_FIRST|VIEW_STYLE_FIELDS_TITLE|VIEW_STYLE_STATISTIC_BAR);
    if(!view)
        goto err;
    init_view(view);

    progress1 = gui_create_widget(GUI_WIDGET_PROGRESS, 80, 251, 460, 14, 0, 0, 0, PROGRESS_STYLE_BORDER);
    if(!progress1)
        goto err;
    gui_progress_init_private(progress1, 100);

    dialog = input_dialog_initialize(&abcde);
    if(!dialog)
        goto err;

    gui_widget_link(NULL, form);
    gui_widget_link(form, view);
    gui_widget_link(form, edit);
    gui_widget_link(form, label);
    gui_widget_link(form, progress1);
    gui_widget_link(form, test);

    gui_widget_link(NULL, dialog);

    gui_widget_link(NULL, button);

    window1 = gui_create_window(form);
    gui_show_window(window1);

    window2 = gui_create_window(dialog);
    gui_show_window(window2);

    window3 = gui_create_window(button);
    gui_show_window(window3);

    gui_form_set_caption(form, os_get_description());

    StartGUI();
    
err:
    return;
}
Пример #8
0
void demo_init_gui(void)
{
    demo_init_font();

    my_ctrl_id=gui_register_usr_ctrl(&my_control_type);
    sys_monitor_id = gui_register_usr_ctrl(&sys_monitor_type);

    root1 = gui_create_control(GUI_CTRL_FORM, 60, 100, 800, 500, 3, 0, 0, 0);    
    if(!root1)return;

    root2 = gui_create_control(GUI_CTRL_FORM, 100, 200, 800, 368, 5, 0, 0, 0);
    if(!root2)return; 

    form1 = gui_create_control(GUI_CTRL_FORM, 180, 50, 320, 82, 5, 0, 0, FORM_STYLE_XP_BORDER);
    if(!form1)return; 

    label1 = gui_create_control(GUI_CTRL_LABEL, 50, 50, 100, 32, 7, 0, 0, LABEL_STYLE_BORDER);
    if(!label1)return; 
    gui_label_init_private(label1, 32);
    gui_label_set_text(label1, "this is a label!");

    edit1 = gui_create_control(GUI_CTRL_EDIT, 50, 100, 100, 32, 9, 0, 0, 0);
    gui_edit_init_private(edit1, 32);
    gui_edit_set_text(edit1, "this is a edit!");
    if(!edit1)return; 

    button1 = gui_create_control(GUI_CTRL_BUTTON, 3, 3, 314, 32, 9, 0, 0, 0);
    if(!button1)return;
   
    progress1 = gui_create_control(GUI_CTRL_PROGRESS, 50, 150, 700, 32, 0, 0, 0, 0);
    if(!progress1)return; 
    gui_set_control_associated(progress1, &assoc1, 0);
    gui_progress_init_private(progress1);

    my_control = gui_create_control(my_ctrl_id, 0, 0, 0, 0, 0, 0, 0, 0);
    if(!my_control)return;

    sys_monitor = gui_create_control(sys_monitor_id, 30, 6, 10, 10, 0, 0, 0, 0);
    if(!sys_monitor)return;

    pic1 = gui_create_control(GUI_CTRL_PICTURE, 50, 200, 150, 100, 0, 0, 0, 0);
    gui_picture_init_private(pic1);
    if(1){
        InitBMPINFO(&info[0]);
        LoadBmp(&info[0], "demo.bmp");
        InitBMPINFO(&info[1]);
        LoadBmp(&info[1], "demo1.bmp");
        InitBMPINFO(&info[2]);
        LoadBmp(&info[2], "demo2.bmp");
        InitBMPINFO(&info[3]);
        LoadBmp(&info[3], "demo3.bmp");
        InitBMPINFO(&info[4]);
        LoadBmp(&info[4], "demo4.bmp");
        InitBMPINFO(&info[5]);
        LoadBmp(&info[5], "demo5.bmp");
        gui_picture_set_picture(pic1, &info);
    }
        
    gui_control_link(NULL, root1);
    gui_control_link(NULL, root2);

    gui_control_link(root1, sys_monitor);

    gui_control_link(root2, form1);
    gui_control_link(root2, my_control);
    gui_control_link(root2, label1);
    gui_control_link(root2, edit1);
    gui_control_link(form1, button1);
    gui_control_link(root2, progress1);
    gui_control_link(root2, pic1);

    RegisterKeyHook(gui_keyhook);

    #if 0
    printf("root1-1: %d, %d, %d, %d, %d\n",
        root1->rect.x,
        root1->rect.y,
        root1->rect.width,
        root1->rect.height,
        root1->color);
    printf("root1-2: %d, %d, %d, %d, %d\n",
        root1->real_rect.x,
        root1->real_rect.y,
        root1->real_rect.width,
        root1->real_rect.height,
        root1->color);
    printf("root2-1: %d, %d, %d, %d, %d\n",
        root2->rect.x,
        root2->rect.y,
        root2->rect.width,
        root2->rect.height,
        root2->color);
    printf("root2-2: %d, %d, %d, %d, %d\n",
        root2->real_rect.x,
        root2->real_rect.y,
        root2->real_rect.width,
        root2->real_rect.height,
        root2->color);
    printf("label1-1: %d, %d, %d, %d, %d\n",
        label1->rect.x,
        label1->rect.y,
        label1->rect.width,
        label1->rect.height,
        label1->color);
    printf("label1-2: %d, %d, %d, %d, %d\n",
        label1->real_rect.x,
        label1->real_rect.y,
        label1->real_rect.width,
        label1->real_rect.height,
        label1->color);
    getch();
    #endif

    StartGUI();
    gui_set_root_control(root1);
    return;
}
Пример #9
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;
		}
	}
}