void MIR_HandleInput(MirSurface* surface, MirEvent const* ev, void* context) { SDL_Window* window = (SDL_Window*)context; switch (ev->type) { case (mir_event_type_key): HandleKeyEvent(ev->key, window); break; case (mir_event_type_motion): HandleMotionEvent(ev->motion, window); break; default: break; } }
void EventLoop(void) { while (1) { if (PendingEvent()) /* got event */ { Event event; while (NextValidEvent(&event)) { switch (event.type) { case EVENT_BUTTONPRESS: case EVENT_BUTTONRELEASE: HandleButtonEvent((ButtonEvent *) &event); break; case EVENT_MOTIONNOTIFY: HandleMotionEvent((MotionEvent *) &event); break; case EVENT_KEYPRESS: case EVENT_KEYRELEASE: HandleKeyEvent((KeyEvent *) &event); break; default: HandleOtherEvents(&event); break; } } } else { /* when playing, display a special mouse pointer inside the playfield */ if (game_status == GAME_MODE_PLAYING && !tape.pausing) { if (!playfield_cursor_set && cursor_inside_playfield && DelayReached(&playfield_cursor_delay, 1000)) { SetMouseCursor(CURSOR_PLAYFIELD); playfield_cursor_set = TRUE; } } else if (playfield_cursor_set) { SetMouseCursor(CURSOR_DEFAULT); playfield_cursor_set = FALSE; } HandleNoEvent(); } /* don't use all CPU time when idle; the main loop while playing has its own synchronization and is CPU friendly, too */ if (game_status == GAME_MODE_PLAYING) { HandleGameActions(); } else { SyncDisplay(); if (!PendingEvent()) /* delay only if no pending events */ Delay(10); } /* refresh window contents from drawing buffer, if needed */ BackToFront(); if (game_status == GAME_MODE_QUIT) return; } }