int mouse_doing(void) { int fd = 0 ; int button_release; int flag = 0; mouse_event m_e; fd = open("/dev/input/mice",O_RDWR|O_NONBLOCK); if (fd < 0) { perror("mice"); exit(0); } mx = fb_v.w/2; my = fb_v.h/2; draw_cursor(mx,my); while (1) { if(get_mouse_info(fd, &m_e) > 0) { restore_bg(mx,my); mx += m_e.dx; my += m_e.dy; if(mx < 0) { mx = 0; } if(mx >(fb_v.w - C_W)) { mx = (fb_v.w-C_W); } if(my < 0) { my = 0; } if(my >(fb_v.h - C_H)) { my = (fb_v.h-C_H); } switch(m_e.button) { case 0 : if (button_release == 1) { flag = chess_doing(); button_release = 0; } break; case 1 : button_release = 1;break ; case 2 : break; case 4 : break; default : break; } draw_cursor(mx,my); if (flag != 0) { break; } } } usleep(1); printf("winner is player %d\n",flag); return 0; }
int mouse_doing(void) { int fd = 0; mouse_event m_e; char press_do = 0; int flag = 0; fd = open("/dev/input/mice", O_RDWR|O_NONBLOCK); if(fd == -1) { perror("mice"); exit(0); } mx = fb_v.w/2; my = fb_v.h/2; draw_cursor(mx, my); while(1) { if(get_mouse_info(fd, &m_e) > 0) { restore_bg(mx, my); mx += m_e.dx; my += m_e.dy; if (mx<0) { mx = 0; } if (mx>(fb_v.w-C_W)) { mx = fb_v.w-C_W; } if (my<0) { my = 0; } if (my>(fb_v.h-C_H)) { my = fb_v.h-C_H; } switch(m_e.button) { case 0: if(press_do ==1) { press_do = 0; flag = chess_doing(); } break; case 1:press_do=1;break; case 2:break; case 4:break; default :break; } draw_cursor(mx, my); if(flag>0) { printf("winner is %d!\n",flag); getchar(); flag=0; reinit(); } } usleep(500); } close(fd); return 0; }