Exemple #1
0
void mouse_cursor(int x, int y)
{
    int i = 0, j = 0;
    save_shape(x, y);
    for(i = 0; i < C_HEIGHT; i++)
        for(j = 0; j < C_WIDTH; j++)
        {
            if(cursor_pixel[i * C_WIDTH + j]!=T___)
                fb_one_piexl(x + j, y + i, cursor_pixel[i * C_WIDTH + j]);
        }
}
Exemple #2
0
int draw_cursor(int x,int y)
{
    int i = 0;
    int j = 0;

    save_shape(x,y);
    for(i = 0;i < C_HEIGHT; i++)
    {
        for(j = 0;j < C_WIDTH; j++)
        {
            draw_point(x+j,y+i,cursor_pixel[j+C_WIDTH*i]);
        }
    }
    return 0;
}
Exemple #3
0
int draw_cursor(int x,int y)
{
    int i = 0;
    int j = 0;
    save_shape(x,y);
    for(i=0;i<C_HEIGHT;i++)
    {   
        for(j=0; j<C_WIDTH;j++)
        {
            if(cursor_pixel[j+i*C_WIDTH] != 0XFFFFFFFF )
            fb_one_pixel(x+j,y+i,cursor_pixel[j+i*C_WIDTH]);
        }
   }
    return 0;
}
Exemple #4
0
int mouse_doing(void)
{
    m_event mevent;
    fd_set input_fd;
    int fd;
    char c,victory = -1;
    int w=0;
    int who,n,flag1 = 1;;
    u32_t color = 0x00ffffff;
    int mx = 521;
    int my = 384;
    bzero(&board,sizeof(board));
    fd = open("/dev/input/mice",O_RDWR|O_NONBLOCK);
    if(fd < 0)
    {
        perror("open");
        exit(1);
    }
    draw_cursor(mx ,my);
    while(1)
    {
        FD_ZERO(&input_fd);
        FD_SET(client_sock,&input_fd);
        FD_SET(fd,&input_fd);
        if((select(fd+1,&input_fd,NULL,NULL,NULL)) < 0)
        {
            perror("select error");
            continue;
        }
        if((FD_ISSET(fd,&input_fd))&&(get_m_info(fd,&mevent)>0))
        {
            restore_shape(mx,my);
            mx += mevent.dx;
            my += mevent.dy;

            mx = ((mx >= 0)? mx:0);
            my = ((my >= 0)? my:0);
            if(mx >= (fb_v.w-C_WIDTH))
                mx = (fb_v.w-C_WIDTH);
            if(my >= (fb_v.h-C_HEIGHT))
                my = (fb_v.h-C_HEIGHT);

            switch(mevent.button)
            {
                case 1: 
                       if(flag1 == 1)
                       {
                            if((mx > 335)&&(mx < 1235)&&(my >55)&&(my < 775))
                            {
                                if( !check(mx,my) )
                                {
                                    color = ~color;
                                    who = create_spot(mx,my,color,w);
                                    save_shape(mx,my);
                                    chess_count(mx,my,who);
                                    victory = check_all();
                                    server_len = sizeof(server);
                                    n = sendto(client_sock, buffer, 12, 0, (struct sockaddr *)&server, server_len);
                                    flag1 = 0;
                                    w++;
                                }
                            }
                        }
                        break;
                case 2: break;
                case 4: break;
                default :break;
            }
            draw_cursor(mx,my);
        }
        usleep(1000);
        if(FD_ISSET(client_sock,&input_fd))
        {
            restore_shape(mx,my);
            server_len = sizeof(server);
            n = recvfrom(client_sock, buffer, BUFFER_SIZE, 0, (struct sockaddr *)&server, &server_len);
            mx = (p->x)*30 + 350;
            my = (p->y)*30 +70;
            if( !check(mx,my) )
            {
                color = ~color;
                who = create_spot(mx,my,color,w);
                save_shape(mx,my);
                chess_count(mx,my,who);
                victory = check_all();
                w++;
            }
            flag1 = 1;
            draw_cursor(mx,my);
        }
        if( victory == 1)
        {
            printf("play%d won!\n",who);
            printf("continue ? y/n\n");
            scanf("%c",&c);
            getchar();
            if( c=='n')
                break;
           else
            {
                create_scr_fb();
                print_board(350,70,0x008b6914);
                victory = -1;
                w=0;
                color = 0x00ffffff;
                mx = 521;
                my = 384;
                flag1 = 1;
                bzero(&board,sizeof(board)); 
                draw_cursor(mx,my);
            }
        }
     }
     close(fd); 
     return 0;
}
Exemple #5
0
int mouse_doing1(void)//(int x,int y)             //wang luo  hua qi zi  (zuo wei fu wu qi)
{
    m_event mevent;
	int len;
    int x,y;
    int kkk;
    int a;
    int p = 0;
    int fd;
    int k1,k2;
    int mx = 512;
    int my = 384;
    int aaaa;
    fd_set input_fd;
    fd = open("/dev/input/mice",O_RDWR);
    if(fd < 0)
    {
        perror("open");
        exit(1);
    }
    draw_cursor(mx, my);
    aaaa = fd > server_sock ? fd : server_sock;
    while(1)
    {
        FD_ZERO(&input_fd);
        FD_SET(fd,&input_fd);
        FD_SET(server_sock,&input_fd);
        if((select(aaaa+1,&input_fd,NULL,NULL,NULL)) < 0)
        {
            perror("select");
            continue;
        }
        if(FD_ISSET(fd,&input_fd))
        {
        if(get_m_info(fd, &mevent) > 0)
        {
            restore_shape(mx ,my);

            mx += mevent.dx;
            my += mevent.dy;

            mx = ((mx >= 0) ? mx : 0);
            my = ((my >= 0) ? my : 0);
            if(mx >= (fb_v.w-C_WIDTH))
            {
                mx = (fb_v.w-C_WIDTH);
            
            }
            if(my>= (fb_v.h-C_HEIGHT))
            {
                my = (fb_v.h-C_HEIGHT);
            
            }
            if(p%2 == 1)
            {
                switch(mevent.button)
                {
                    case 1 :

                             w= print_one_chess(mx,my,p);
                             save_shape(mx ,my);
                             chess_count(mx,my,w);
                             a = check_all();
                             p++;
	                  	     sendto(server_sock, buffer, BUFFER_SIZE, 0, (struct sockaddr *)&client, client_len);
                             break;
                    case 2 : break;
                    case 4 : break;
                    default: break;
            
                }
            }
//            if(a != 1)
            draw_cursor(mx ,my);
            if(a == 1)
            {
                bzero(&board,sizeof(board));
                printf("go: 0   exit: 1\n");
                scanf("%d",&kkk);
                break;
            }
        }
        usleep(1000);
        if(kkk == 1) close(fd);  
    }
    if(FD_ISSET(server_sock,&input_fd))
    {
    
        printf("dsads\n");
        restore_shape(mx,my);
		client_len = sizeof(client);
        printf("sdfsdf\n");
		len = recvfrom(server_sock, buffer, BUFFER_SIZE, 0, (struct sockaddr *)&client, &client_len);
        printf("%d\n",len);
		if (len < 0)
		{
			close(server_sock);
			fprintf(stderr, "%s\n", strerror(errno));
			exit(EXIT_FAILURE);
		}
		else
		{
			printf("recvfrom client ok!\n");
			in.s_addr = client.sin_addr.s_addr;
			printf("client ip  : %s\n", inet_ntoa(in));
			printf("client port: %d\n", ntohs(client.sin_port));
			printf("\n");
            x= pp->x ;
            y= pp->y ;
            printf("%d\n",pp->x);
            printf("%d\n",y);
            k1=x*30+100;
            k2=y*30+40;
            w= print_one1_chess(k1,k2);
            p++;
            chess_count(k1,k2,w);
            a = check_all();
		}
    }
    }
    return 0;
}
Exemple #6
0
int mouse_doing(void)                // zheng chang hua qi zi (dan  ji)
{
    m_event mevent;
    int kkk,a;
    int p = 0;
    int fd;
    int mx = 512;
    int my = 384;
    fd = open("/dev/input/mice",O_RDWR|O_NONBLOCK);
    if(fd < 0)
    {
        perror("open");
        exit(1);
    }
    draw_cursor(mx, my);
    while(1)
    {
        if(get_m_info(fd, &mevent) > 0)
        {
            restore_shape(mx ,my);

            mx += mevent.dx;
            my += mevent.dy;

            mx = ((mx >= 0) ? mx : 0);
            my = ((my >= 0) ? my : 0);
            if(mx >= (fb_v.w-C_WIDTH))
            {
                mx = (fb_v.w-C_WIDTH);
            
            }
            if(my >= (fb_v.h-C_HEIGHT))
            {
                my = (fb_v.h-C_HEIGHT);
            
            }
            switch(mevent.button)
            {
                case 1 :
                         w= print_one_chess(mx, my,p) ;
                         save_shape(mx ,my);
                         chess_count(mx,my,w);
                         a = check_all();
                         if(a == 1)
                         break;
                         p++;
                         break;
                case 2 : break;
                case 4 : break;
                default: break;
            
            }
            if(a != 1)
            draw_cursor(mx ,my);
          if(a == 1)
            {
                bzero(&board,sizeof(board));
                printf("go: 0   exit: 1\n");
                scanf("%d",&kkk);
                break;
            }
        }
        usleep(1000);
    }
    if(kkk == 1) close(fd);  
    return kkk;
}