예제 #1
0
int mouse_moving(void)
{
    m_event mevent;

    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);
        }

        mouse_cursor(mx, my);
    }
    return 0;
}
예제 #2
0
파일: Mzscrn.c 프로젝트: meesokim/mz700win
// Change to Full-Screen
BOOL chg_screen_mode(int mode)
{
	HANDLE hProcess;
	
	if (mode == SCRN_FULL)
	{
		if (!CreateDirectDraw(hwndApp))	return FALSE;
		
		// Change to fullscreen
		fullmode = ChangeToFullScreen();

		if (fullmode<0)
		{
			MessageBox(hwndApp, "Display Mode Change Error!",
					   "Error", MB_ICONERROR);
			return FALSE;
		}

		// 全画面であれば、プロセスの優先度をあげる
	    hProcess = GetCurrentProcess();
		if (hProcess)
		{
			SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS);
		}
		//
		mouse_cursor(FALSE);											/* clear mouse cursor */
	}
	else
	{
		// Window
		EndDirectDraw();
		mouse_cursor(TRUE);												/* mouse cursor on */

	}

	mz_refresh_screen(REFSC_ALL);

	return TRUE;
}
예제 #3
0
파일: main.c 프로젝트: nishuihan/five-chess
int main(void)
{
    //int x = 0, y = 0;
    create_fb();    
    //scan_screen();
    fb_backgound(0, 0, fb_v.w - 1, fb_v.h - 1, 0x00996600);
    fb_backgound(STARTX, STARTY, STARTX + (V_NUM - 1) * SPACE, STARTY + (H_NUM - 1) * SPACE, 0x00ffcc33);
    fb_board(0x000000ff);
    print_color();
    mouse_cursor(512, 384);
    //save_shape(300, 300);
    //mouse_cursor(300, 300);
    //restore_shape(300, 300);
    //mouse_cursor(512, 384);
    //mouse_doing();
    server_op();
    while(1)
    {
        //mouse_doing();
    }
    return 0;   
}
예제 #4
0
파일: screen_3.cpp 프로젝트: HiiYL/uttc
int screen_3::Run(sf::RenderWindow &App) {
    Cursor mouse_cursor(App,resources->textures.get("MouseCursor"));

    sf::Sprite mock_cursor;
    mock_cursor.setTexture(resources->textures.get("MockCursor"));

    sf::Sprite background;
    background.setTexture(resources->textures.get("GameBackground"));

    bool Running = true;
    int starting_index = resources->start_index;
    Sidebar sidebar(App, resources);

    sf::Clock clock;

    Board board(starting_index,App, resources);
    board.move(0,50);
    board.animateMovement(sf::Vector2f(200,50),3);
    Replay replay(App, resources);

    Player* player1 (new Player(board.getBoardGrid(),'X'));
    Player* player2 (new Player(board.getBoardGrid(),'O'));
    Player* curr_player;
    player1->setTexture(&resources->textures.get("Player1Mark"));
    player2->setTexture(&resources->textures.get("Player2Mark"));

    Button waiting(App);
    waiting.load(resources->textures.get("WaitingBase"),resources->textures.get("WaitingHover"));
    //waiting.setScale(0.7);
    waiting.setPosition((App.getSize().x-waiting.getGlobalBounds().x)/2+40,App.getSize().y-waiting.getGlobalBounds().y+5);
    VictoryBanner victory_banner(App,player1,player2,replay, resources);
    Messenger messenger(App, resources);
    PauseOverlay pause_screen(App, resources, true);
    while (Running)
    {
        sf::Event event;

        while (App.pollEvent(event))
        {

            if(messageSocket->receive(packet) == sf::Socket::Disconnected)
            {
                sidebar.stopMusic();
                pause_screen.setString("    DISCONNECTED");
                pause_screen.isDisconnected(true);
                pause_screen.setPaused(true);
            }
            else    {
                board.handleEvents(event);             //if not disconnected
                if(sidebar.updateEvents(event))
                    pause_screen.setPaused(true);
            }
            if(pause_screen.updateEvent(event))
            {
               return pause_screen.getActionKeyCode();
            }
            messenger.updateEvents(event);
            if (event.type == sf::Event::Closed)
            {
                return (-1);
            }
            if(victory_banner.handleEvents(event))
            {
                return victory_banner.getActionKeyCode();
            }
        }
        board.updateAnimation();
        messenger.update(messageSocket);
        if((is_host&&player_turn) || (!is_host && !player_turn)) {
            curr_player = player1;
        }
        else {
            curr_player = player2;
        }
        mouse_cursor.update();
        replay.record(player_turn , replaySocket);
        mock_cursor.setPosition(replay.getCurrPosition());
        if(!board.game_done)
            {
                 if(sidebar.checkTimer(resources->isTimerActivated,resources->turn_timer))   {
                    if(player_turn) {
                        is_waiting = false;
                        board.update(curr_player,is_host,socket);
                    }
                    else{
                        is_waiting = true;
                        board.update(curr_player,socket);  //receiver
                    }
                    if(board.round_done)    {
                        sidebar.restartClock();
                        player_turn = !player_turn;
                        board.round_done = false;
                    }
                }
                else    {
                    player_turn = !player_turn;
                    sidebar.restartClock();
                }
            }

            else    {
                replay.save();
                sidebar.stopMusic();
                victory_banner. displayBanner(is_host);
            }
        App.clear();
        App.draw(background);
        App.draw(board);
        if(!player_turn)
            App.draw(mock_cursor);
        if(is_waiting)
            App.draw(waiting);
        App.draw(sidebar);
        if(board.game_done)    {
            App.draw(victory_banner);
        }
        if(pause_screen.isPaused())    {
            App.draw(pause_screen);
        }
        App.draw(messenger);

        App.draw(mouse_cursor);
        App.display();
    }
    return (-1);
}
예제 #5
0
파일: input.c 프로젝트: Oreolek/instead
int input(struct inp_event *inp, int wait)
{
    int rc;
    SDL_Event event;
    SDL_Event peek;
    memset(&event, 0, sizeof(event));
    memset(&peek, 0, sizeof(peek));
    if (wait) {
        rc = SDL_WaitEvent(&event);
    } else
        rc = SDL_PollEvent(&event);
    if (!rc)
        return 0;
    inp->sym[0] = 0;
    inp->type = 0;
    inp->count = 1;
    switch(event.type) {
#if SDL_VERSION_ATLEAST(2,0,0)
    case SDL_MULTIGESTURE:
    case SDL_FINGERMOTION:
        if (DIRECT_MODE && !game_paused())
            return AGAIN;
        if (SDL_PeepEvents(&peek, 1, SDL_PEEKEVENT, event.type, event.type) > 0)
            return AGAIN; /* to avoid flickering */
        break;
    case SDL_FINGERUP:
#ifdef IOS
        touch_num = 0;
#endif
    case SDL_FINGERDOWN:
#ifdef IOS
        if (event.type == SDL_FINGERDOWN) {
            if (gfx_ticks() - touch_stamp > 100) {
                touch_num = 0;
                touch_stamp = gfx_ticks();
            }
            touch_num ++;
            if (touch_num >= 3) {
                inp->type = KEY_DOWN;
                inp->code = 0;
                strncpy(inp->sym, "escape", sizeof(inp->sym));
                break;
            }
        }
#endif
        gfx_finger_pos_scale(event.tfinger.x, event.tfinger.y, &inp->x, &inp->y);
        inp->type = (event.type == SDL_FINGERDOWN) ? FINGER_DOWN : FINGER_UP;
#ifndef PRIx64
        snprintf(inp->sym, sizeof(inp->sym), "%llx:%llx",
                 event.tfinger.fingerId,
                 event.tfinger.touchId);
#else
        snprintf(inp->sym, sizeof(inp->sym), "%"PRIx64":%"PRIx64,
                 event.tfinger.fingerId,
                 event.tfinger.touchId);
#endif
        break;
    case SDL_WINDOWEVENT:
        switch (event.window.event) {
        /*		case SDL_WINDOWEVENT_SHOWN: */
        case SDL_WINDOWEVENT_EXPOSED:
            gfx_flip();
            gfx_commit();
            break;
        case SDL_WINDOWEVENT_MINIMIZED:
        case SDL_WINDOWEVENT_RESTORED:
            m_minimized = (event.window.event == SDL_WINDOWEVENT_MINIMIZED && !opt_fs);
            snd_pause(!nopause_sw && m_minimized);
            break;
        case SDL_WINDOWEVENT_ENTER:
        case SDL_WINDOWEVENT_FOCUS_GAINED:
            m_focus = 1;
            if (opt_fs)
                mouse_cursor(0);
            break;
        case SDL_WINDOWEVENT_LEAVE:
            m_focus = 0;
            if (opt_fs)
                mouse_cursor(1); /* is it hack?*/
            break;
        default:
            break;
        }
        if (SDL_PeepEvents(&peek, 1, SDL_PEEKEVENT, SDL_WINDOWEVENT, SDL_WINDOWEVENT) > 0)
            return AGAIN; /* to avoid flickering */
        return 0;
#else
    case SDL_ACTIVEEVENT:
        if (event.active.state & SDL_APPACTIVE) {
            m_minimized = !event.active.gain;
            snd_pause(!nopause_sw && m_minimized);
        }
        if (event.active.state & (SDL_APPMOUSEFOCUS | SDL_APPINPUTFOCUS)) {
            if (event.active.gain) {
                m_focus = 1;
                if (opt_fs)
                    mouse_cursor(0);
            } else if (event.active.state & SDL_APPMOUSEFOCUS) {
                m_focus = 0;
                if (opt_fs)
                    mouse_cursor(1); /* is it hack?*/
            }
        }
#if SDL_VERSION_ATLEAST(1,3,0)
        if (SDL_PeepEvents(&peek, 1, SDL_PEEKEVENT, SDL_ACTIVEEVENT, SDL_ACTIVEEVENT) > 0)
#else
        if (SDL_PeepEvents(&peek, 1, SDL_PEEKEVENT, SDL_EVENTMASK(SDL_ACTIVEEVENT)) > 0)
#endif
            return AGAIN; /* to avoid flickering */
        return 0;
#endif
    case SDL_USEREVENT: {
        void (*p) (void*) = (void (*)(void*))event.user.data1;
        p(event.user.data2);
        return AGAIN;
    }
    case SDL_QUIT:
        game_running = 0;
        return -1;
    case SDL_KEYDOWN:	/* A key has been pressed */
#if SDL_VERSION_ATLEAST(2,0,0)
        if (event.key.repeat) {
            if (DIRECT_MODE && !game_paused()) /* do not send key repeats */
                return AGAIN;
            if (gfx_ticks() - last_press_ms < INPUT_REP_DELAY_MS)
                return AGAIN;
            if ((gfx_ticks() - last_repeat_ms) < INPUT_REP_INTERVAL_MS)
                return AGAIN;
            last_repeat_ms = gfx_ticks();
        } else {
            last_press_ms = gfx_ticks();
            last_repeat_ms = gfx_ticks();
        }
#endif
        inp->type = KEY_DOWN;
        inp->code = event.key.keysym.scancode;
#if SDL_VERSION_ATLEAST(1,3,0)
        strncpy(inp->sym, SDL_GetScancodeName(inp->code), sizeof(inp->sym));
#else
        strncpy(inp->sym, SDL_GetKeyName(event.key.keysym.sym), sizeof(inp->sym));
#endif
        inp->sym[sizeof(inp->sym) - 1] = 0;
        tolow(inp->sym);
#if SDL_VERSION_ATLEAST(1,3,0)
        key_compat(inp);
#endif
#if SDL_VERSION_ATLEAST(1,3,0) /* strange bug in some SDL2 env, with up/down events storm */
        if (SDL_PeepEvents(&peek, 1, SDL_PEEKEVENT, SDL_KEYDOWN, SDL_KEYUP) > 0) {
            if (peek.key.keysym.scancode == event.key.keysym.scancode &&
                    peek.key.repeat == 0)
                return AGAIN;
        }
#endif
        break;
    case SDL_KEYUP:
        inp->type = KEY_UP;
        inp->code = event.key.keysym.scancode;
#if SDL_VERSION_ATLEAST(1,3,0)
        strncpy(inp->sym, SDL_GetScancodeName(inp->code), sizeof(inp->sym));
#else
        strncpy(inp->sym, SDL_GetKeyName(event.key.keysym.sym), sizeof(inp->sym));
#endif
        inp->sym[sizeof(inp->sym) - 1] = 0;
        tolow(inp->sym);
#if SDL_VERSION_ATLEAST(1,3,0)
        key_compat(inp);
#endif
#if SDL_VERSION_ATLEAST(1,3,0) /* strange bug in some SDL2 env, with up/down events storm */
        if (SDL_PeepEvents(&peek, 1, SDL_PEEKEVENT, SDL_KEYDOWN, SDL_KEYUP) > 0) {
            if (event.key.keysym.scancode == peek.key.keysym.scancode &&
                    peek.key.repeat == 0)
                return AGAIN;
        }
#endif
        break;
    case SDL_MOUSEMOTION:
        m_focus = 1; /* ahhh */
        if (DIRECT_MODE && !game_paused())
            return AGAIN;
        inp->type = MOUSE_MOTION;
        inp->x = event.button.x;
        inp->y = event.button.y;
#if SDL_VERSION_ATLEAST(1,3,0)
        while (SDL_PeepEvents(&peek, 1, SDL_GETEVENT, SDL_MOUSEMOTION, SDL_MOUSEMOTION) > 0) {
#else
        while (SDL_PeepEvents(&peek, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION)) > 0) {
#endif
            inp->x = peek.button.x;
            inp->y = peek.button.y;
        }
        break;
    case SDL_MOUSEBUTTONUP:
        inp->type = MOUSE_UP;
        inp->x = event.button.x;
        inp->y = event.button.y;
        inp->code = event.button.button;
        if (event.button.button == 4)
            inp->type = 0;
        else if (event.button.button == 5)
            inp->type = 0;
        break;
#if SDL_VERSION_ATLEAST(2,0,0)
    case SDL_MOUSEWHEEL:
        if (DIRECT_MODE && !game_paused())
            return AGAIN;

        inp->type = (event.wheel.y > 0) ? MOUSE_WHEEL_UP : MOUSE_WHEEL_DOWN;

        while (SDL_PeepEvents(&peek, 1, SDL_GETEVENT, SDL_MOUSEWHEEL, SDL_MOUSEWHEEL) > 0) {
            if (!((event.wheel.y > 0 &&
                    inp->type == MOUSE_WHEEL_UP) ||
                    (event.wheel.y < 0 &&
                     inp->type == MOUSE_WHEEL_DOWN)))
                break;
            inp->count ++;
        }
        break;
#endif
    case SDL_MOUSEBUTTONDOWN:
        m_focus = 1; /* ahhh */
        inp->type = MOUSE_DOWN;
        inp->x = event.button.x;
        inp->y = event.button.y;
        inp->code = event.button.button;
        if (event.button.button == 4)
            inp->type = MOUSE_WHEEL_UP;
        else if (event.button.button == 5)
            inp->type = MOUSE_WHEEL_DOWN;
#if SDL_VERSION_ATLEAST(1,3,0)
        while (SDL_PeepEvents(&peek, 1, SDL_GETEVENT, SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONDOWN) > 0) {
#else
        while (SDL_PeepEvents(&peek, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEBUTTONDOWN)) > 0) {
#endif
            if (!((event.button.button == 4 &&
                    inp->type == MOUSE_WHEEL_UP) ||
                    (event.button.button == 5 &&
                     inp->type == MOUSE_WHEEL_DOWN)))
                break;
            inp->count ++;
        }
        break;
    default:
        break;
    }
    return 1;
}
예제 #6
0
int mouse_doing(void)
{
    m_event mevent;
    //int fd;
    //int mx = 512;
    //int my = 384;
    char victory = -1;

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

    //print_color();
    //mouse_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);
        }

        mouse_cursor(mx, my);
        switch(mevent.mode)
        {
        case 1:
            restore_shape(mx, my);
            if (scan_point(mx, my) == 0)
            {
                //if(global_color == 0x00ffffff)
                //{
                //global_color = 0x00000000;
                //who = 1;
                //}
                //else
                //{
                //global_color = 0x00ffffff;
                //who = 2;
                //}
                flag = 1;
                chess_count(mx, my);
                //global_x = mx - STARTX;
                //global_y = my - STARTY;
                //global_x = mx;
                //global_y = my;
                victory = check_all();
            }
            mouse_cursor(mx, my);
            break;
        case 2:
            break;
        case 4:
            break;
        default:
            break;
        }
#if 0
        if(victory == 1)
        {
            printf("play%d won!\n", who);
            printf("contniue ? y/n\n");
            if(getchar() == 'n')
                return 0;
            else
            {
                memset((u8_t *)fb_v.fb_men, 0, fb_v.h * fb_v.w *fb_v.bpp/8);
                memset(board, 0, H_NUM * V_NUM);
                fb_backgound(0, 0, fb_v.w - 1, fb_v.h - 1, 0x00996600);
                fb_backgound(STARTX, STARTY, STARTX + (V_NUM - 1) * SPACE, STARTY + (H_NUM - 1) * SPACE, 0x00ffcc33);
                fb_board(0x000000ff);
                print_color();
                mouse_cursor(512, 384);
                global_color = 0xffffffff;
                who = 1;
                victory = -1;
                mx = 512;
                my = 384;
                mouse_cursor(mx, my);
            }
            getchar();
        }
#endif
    }
    usleep(1000);
    //}
    return 0;
}