Example #1
0
EVENT UIAPI uieventsource( bool update )
/**************************************/
{
    register    EVENT                   ev;
    static      int                     ReturnIdle = 1;
    unsigned long                       start;

    start = uiclock();
    for( ; ; ) {
        ThreadSwitch();
        if( EnterForever )
            foreverloop();

        ev = forcedevent();
        if( ev > EV_NO_EVENT )
            break;

        /* There is no mouse support in NetWare. */
        //ev = mouseevent();
        //if( ev > EV_NO_EVENT )
        //    break;

        ev = keyboardevent();
        if( ev > EV_NO_EVENT ) {
            //uihidemouse();
            break;
        }
        if( ReturnIdle ) {
            ReturnIdle--;
            return( EV_IDLE );
        } else {
            if( update )
                uirefresh();
            if( uiclock() - start >= UIData->tick_delay ) {
                return( EV_CLOCK_TICK );
            } else if( UIData->busy_wait ) {
                return( EV_SINK );
            }
        }
        waitforevent();
    }
    ReturnIdle = 1;
    return( ev );
}
Example #2
0
void graphics_CheckEvents(void (*quitevent)(void), void (*mousebuttonevent)(int button, int release, int x, int y), void (*mousemoveevent)(int x, int y), void (*keyboardevent)(const char* button, int release), void (*textevent)(const char* text), void (*putinbackground)(int background)) {
    if (!graphics3d) {
        SDL_Event e;
        while (SDL_PollEvent(&e) == 1) {
            if (e.type == SDL_QUIT) {
                quitevent();
            }
            if (e.type == SDL_MOUSEMOTION) {
                mousemoveevent(e.motion.x, e.motion.y);
            }
            if (e.type == SDL_WINDOWEVENT &&
                (e.window.event == SDL_WINDOWEVENT_MINIMIZED
                || e.window.event == SDL_WINDOWEVENT_FOCUS_LOST)) {
                // app was put into background
                if (!inbackground) {
                    putinbackground(1);
                    inbackground = 1;
                }
            }
            if (e.type == SDL_WINDOWEVENT &&
                (e.window.event == SDL_WINDOWEVENT_RESTORED
                || e.window.event == SDL_WINDOWEVENT_FOCUS_GAINED)) {
                // app is pulled back into foreground
                if (inbackground) {
                    putinbackground(0);
                    inbackground = 0;
                }
            }
            if (e.type == SDL_MOUSEBUTTONDOWN || e.type == SDL_MOUSEBUTTONUP) {
                int release = 0;
                if (e.type == SDL_MOUSEBUTTONUP) {
                    release = 1;
                }
                int button = e.button.button;
                mousebuttonevent(button, release, e.button.x, e.button.y);
            }
            if (e.type == SDL_FINGERDOWN || e.type == SDL_FINGERUP) {
                int release = 0;
                int x,y;
                if (e.type == SDL_FINGERUP) {
                    // take fingerdown coordinates on fingerup
                    x = lastfingerdownx;
                    y = lastfingerdowny;
                    release = 1;
                } else {
                    // remember coordinates on fingerdown
                    x = e.tfinger.x;
                    y = e.tfinger.y;
                    lastfingerdownx = x;
                    lastfingerdowny = y;
                }
                // swap coordinates for landscape mode
                int temp = x;
                x = y;
                y = temp;
                int button = SDL_BUTTON_LEFT;
                mousebuttonevent(button, release, x, y);
            }
            if (e.type == SDL_TEXTINPUT) {
                textevent(e.text.text);
            }
            if (e.type == SDL_WINDOWEVENT) {
                if (e.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) {
#ifndef WINDOWS
#ifdef LINUX
                    // if we are a fullscreen window, ensure we are
                    // fullscreened
                    // FIXME: just a workaround for
                    // http://bugzilla.libsdl.org/show_bug.cgi?id=1349
                    if (mainwindowfullscreen) {
                        //SDL_SetWindowFullscreen(mainwindow, SDL_FALSE);
                        //SDL_SetWindowFullscreen(mainwindow, SDL_TRUE);
                    }
#endif
#endif
                }
            }
            if (e.type == SDL_KEYDOWN || e.type == SDL_KEYUP) {
                int release = 0;
                if (e.type == SDL_KEYUP) {
                    release = 1;
                }
                char keybuf[30] = "";
                if (e.key.keysym.sym >= SDLK_F1 &&
                    e.key.keysym.sym <= SDLK_F12) {
                    sprintf(keybuf, "f%d", (e.key.keysym.sym+1)-SDLK_F1);
                }
                if (e.key.keysym.sym >= SDLK_0 && e.key.keysym.sym <= SDLK_9) {
                    sprintf(keybuf, "%d", e.key.keysym.sym - SDLK_0);
                }
                if (e.key.keysym.sym >= SDLK_a && e.key.keysym.sym <= SDLK_z) {
                    sprintf(keybuf, "%c", e.key.keysym.sym - SDLK_a + 'a');
                }
                switch (e.key.keysym.sym) {
                    case SDLK_SPACE:
                        sprintf(keybuf, "space");break;
                    case SDLK_BACKSPACE:
                        sprintf(keybuf, "backspace");break;
                    case SDLK_RETURN:
                        sprintf(keybuf, "return");break;
                    case SDLK_ESCAPE:
                        sprintf(keybuf, "escape");break;
                    case SDLK_TAB:
                        sprintf(keybuf, "tab");break;
                    case SDLK_LSHIFT:
                        sprintf(keybuf, "lshift");break;
                    case SDLK_RSHIFT:
                        sprintf(keybuf, "rshift");break;
                    case SDLK_UP:
                        sprintf(keybuf,"up");break;
                    case SDLK_DOWN:
                        sprintf(keybuf,"down");break;
                    case SDLK_LEFT:
                        sprintf(keybuf,"left");break;
                    case SDLK_RIGHT:
                        sprintf(keybuf,"right");break;
                }
                if (strlen(keybuf) > 0) {
                    keyboardevent(keybuf, release);
                }
            }
        }
    }
}