Ejemplo n.º 1
0
int mouse_doing(void)
{
    int fd;
    int press_flag = 0;
    int end_flag = 0;
    mouse_event m_event;
    fd = open("/dev/input/mice", O_RDWR|O_NONBLOCK); //?
    if (fd == -1) 
    {
        perror("mice");
        exit(0);
    }

    mx = fb_v.w / 2;    //initial the coordinates.
    my = fb_v.h / 2;

    draw_cursor(mx, my);

    while (1) 
    {
        if (get_m_info(fd, &m_event) > 0) 
        {
            restore(mx, my);
            mx += m_event.dx;
            my += m_event.dy;
            mx = (mx < 0) ? 0 : mx;
            my = (my < 0) ? 0 : my;

            if (mx > (fb_v.w - C_W)) 
            {
                mx = fb_v.w - C_W;
            }
            if (my > (fb_v.h - C_H)) 
            {
                my = fb_v.h - C_H;
            }

            switch (m_event.button)
            {
                case 0: 
                    if (press_flag == 1) 
                    {
                        press_flag = 0;
                        if (end_flag == 0) 
                        {
                            end_flag = chess_do();
                        }
                        else 
                        {
                            print_board(GRAY, YELLOW);
                            end_flag = 0;
                        }
                    }
                    else if (press_flag == 2) 
                    {
                        press_flag = 0;
                        chess_do();
                    }
                    break;
                case 1: press_flag = 1; break;
                case 2: press_flag = 2; break;
                case 3:  break;
                case 4:  break;
                default: break;
            }

            draw_cursor(mx, my);
        }
        usleep(1000);
    }
    
    return 0;
}
Ejemplo n.º 2
0
int  mouse_doing(void)
{
    int fd;
    mouse_event m_event;

    fd = open ("/dev/input/mice", O_RDWR|O_NONBLOCK);
    if (-1 == fd) 
    {
        perror ("mice");
        exit(0);
    }

    mx = fb_v.w/2;
    my = fb_v.h/2;

    int press_flag = 0;
    int end_flag = 0;

    draw_curser(mx ,my);
    while(1)
    {
        if (get_m_info(fd, &m_event)>0) 
        {
            restore(mx, my);
            mx += m_event.dx;
            my += m_event.dy;

            mx = ((mx<0) ? 0 : mx);
            my = ((my<0) ? 0 : my);
    
            if (mx > (fb_v.w-C_W)) 
            {
                mx = fb_v.w-C_W;
            }
            if (my >(fb_v.h-C_H)) 
            {
                my = fb_v.h-C_H;
            }
            switch(m_event.button)
            {
                case 0:
                    if (1 == press_flag) 
                    {

                        press_flag = 0;
                        if (0 == end_flag) 
                        {
                           end_flag =  chess_do();
                        }
                        else 
                        {
                           print_board(); 
                           end_flag = 0;
                        }
                    }
                    break;
                case 1: 
                    press_flag = 1; 
                    break;
                case 2: 
                    break;
                case 4: 
                break;
                default:
                break;
            }
            
            draw_curser(mx, my);    
        }

        usleep(100);
    }

    return 0;
}