static void I_GetEvent(SDL_Event *Event) { event_t event; switch (Event->type) { case SDL_KEYDOWN: event.type = ev_keydown; event.data1 = I_TranslateKey(&Event->key.keysym); D_PostEvent(&event); break; case SDL_KEYUP: { event.type = ev_keyup; event.data1 = I_TranslateKey(&Event->key.keysym); D_PostEvent(&event); } break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: if (mouse_enabled) // recognise clicks even if the pointer isn't grabbed { event.type = ev_mouse; event.data1 = I_SDLtoDoomMouseState(SDL_GetMouseState(NULL, NULL)); event.data2 = event.data3 = 0; D_PostEvent(&event); } break; case SDL_MOUSEMOTION: if (mouse_currently_grabbed) { event.type = ev_mouse; event.data1 = I_SDLtoDoomMouseState(Event->motion.state); event.data2 = Event->motion.xrel << 5; event.data3 = -Event->motion.yrel << 5; D_PostEvent(&event); } break; case SDL_QUIT: S_StartSound(NULL, sfx_swtchn); M_QuitDOOM(0); default: break; } }
// // Read the change in mouse state to generate mouse motion events // // This is to combine all mouse movement for a tic into one mouse // motion event. static void I_ReadMouse(void) { static int mouse_currently_grabbed = true; int x, y; event_t ev; if (!usemouse) return; if (!MouseShouldBeGrabbed()) { mouse_currently_grabbed = false; return; } if (!mouse_currently_grabbed && !desired_fullscreen) { CenterMouse(); mouse_currently_grabbed = true; } SDL_GetRelativeMouseState(&x, &y); if (x != 0 || y != 0) { ev.type = ev_mouse; ev.data1 = I_SDLtoDoomMouseState(SDL_GetMouseState(NULL, NULL)); ev.data2 = x << 5; ev.data3 = (-y) << 5; D_PostEvent(&ev); } CenterMouse(); }
static void I_GetEvent(void) { event_t event; SDL_Event SDLEvent; SDL_Event *Event = &SDLEvent; static int mwheeluptic = 0, mwheeldowntic = 0; while (SDL_PollEvent(Event)) { switch (Event->type) { case SDL_KEYDOWN: #ifdef MACOSX if (Event->key.keysym.mod & KMOD_META) { // Switch windowed<->fullscreen if pressed <Command-F> if (Event->key.keysym.sym == SDLK_f) { V_ToggleFullscreen(); break; } } #else if (Event->key.keysym.mod & KMOD_LALT) { // Prevent executing action on Alt-Tab if (Event->key.keysym.sym == SDLK_TAB) { break; } // Switch windowed<->fullscreen if pressed Alt-Enter else if (Event->key.keysym.sym == SDLK_RETURN) { V_ToggleFullscreen(); break; } } #endif event.type = ev_keydown; event.data1 = I_TranslateKey(&Event->key.keysym); D_PostEvent(&event); break; case SDL_KEYUP: { event.type = ev_keyup; event.data1 = I_TranslateKey(&Event->key.keysym); D_PostEvent(&event); } break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: if (mouse_enabled && window_focused) { event.type = ev_mouse; event.data1 = I_SDLtoDoomMouseState(SDL_GetMouseState(NULL, NULL)); event.data2 = event.data3 = 0; if (Event->type == SDL_MOUSEBUTTONDOWN) { switch(Event->button.button) { case SDL_BUTTON_WHEELUP: event.type = ev_keydown; event.data1 = KEYD_MWHEELUP; mwheeluptic = gametic; break; case SDL_BUTTON_WHEELDOWN: event.type = ev_keydown; event.data1 = KEYD_MWHEELDOWN; mwheeldowntic = gametic; break; } } D_PostEvent(&event); } break; //e6y: new mouse code case SDL_ACTIVEEVENT: UpdateFocus(); break; case SDL_VIDEORESIZE: ApplyWindowResize(Event); break; case SDL_QUIT: S_StartSound(NULL, sfx_swtchn); M_QuitDOOM(0); default: break; } } if(mwheeluptic && mwheeluptic + 1 < gametic) { event.type = ev_keyup; event.data1 = KEYD_MWHEELUP; D_PostEvent(&event); mwheeluptic = 0; } if(mwheeldowntic && mwheeldowntic + 1 < gametic) { event.type = ev_keyup; event.data1 = KEYD_MWHEELDOWN; D_PostEvent(&event); mwheeldowntic = 0; } }