// Stop tracking a system popup submenu HRESULT CMenuFocusManager::PopTrackedPopup(HMENU popup) { StackEntryType type; HMENU hmenu; HRESULT hr; TRACE("PopTrackedPopup %p\n", popup); hr = PopFromArray(&type, NULL, &hmenu); if (FAILED_UNEXPECTEDLY(hr)) { UpdateFocus(); return hr; } _ASSERT(type == TrackedMenuEntry); if (type != TrackedMenuEntry) return E_FAIL; if (hmenu != popup) return E_FAIL; hr = UpdateFocus(); if (FAILED_UNEXPECTEDLY(hr)) return hr; return S_OK; }
void I_InitGraphics(void) { static int firsttime=1; if (firsttime) { firsttime = 0; atexit(I_ShutdownGraphics); lprintf(LO_INFO, "I_InitGraphics: %dx%d\n", SCREENWIDTH, SCREENHEIGHT); /* Set the video mode */ I_UpdateVideoMode(); //e6y: setup the window title I_SetWindowCaption(); //e6y: set the application icon I_SetWindowIcon(); /* Initialize the input system */ I_InitInputs(); //e6y: new mouse code UpdateFocus(); UpdateGrab(); } }
void NDPlayer::OnMoveEnd() { ScriptGlobalEvent::OnEvent(GE_ONMOVE_END); NDMapLayer* pkMaplayer = M_GetMapLayer(); if (pkMaplayer) { pkMaplayer->ShowRoadSign(false); } if (!isTeamLeader() && isTeamMember()) { return; } SetAction(false); NDManualRole::OnMoveEnd(); if (isTeamLeader()) { teamMemberAction(false); } //玩家停下来的时候 做聚焦改变处理 npc加载完成后,也做一次聚焦改变处理 UpdateFocus(); if (AutoPathTipObj.IsWorking()) { AutoPathTipObj.Arrive(); } processSwitch(); }
// // I_InitInput // bool I_InitInput (void) { if(Args.CheckParm("-nomouse")) { nomouse = true; } atterm (I_ShutdownInput); SDL_EnableUNICODE(true); I_DisableKeyRepeat(); // Initialize the joystick subsystem and open a joystick if use_joystick is enabled. -- Hyper_Eye Printf(PRINT_HIGH, "I_InitInput: Initializing SDL's joystick subsystem.\n"); SDL_InitSubSystem(SDL_INIT_JOYSTICK); if((int)use_joystick && I_GetJoystickCount()) { I_OpenJoystick(); EnableJoystickPolling(); } #ifdef WIN32 // denis - in fullscreen, prevent exit on accidental windows key press // [Russell] - Disabled because it screws with the mouse //g_hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, GetModuleHandle(NULL), 0); #endif //CreateCursors(); UpdateFocus(); UpdateGrab(); return true; }
FarControl *FarDialog::Show (bool SkipLayout) { if (!SkipLayout) Layout(); // Show dialog and validate data BOOL bValidData; int ExitCode; do { for (int k=0; k<fControls.Count(); k++) fControls [k]->BeforeShow(); bValidData = TRUE; ExitCode=Far::m_Info.Dialog (Far::m_Info.ModuleNumber, -1, -1, fItems [0].X2+m_BorderX+2, fItems [0].Y2+m_BorderY+1, fHelpTopic, fItems.GetItems(), fItems.Count()); if (ExitCode == -1) return NULL; if (!fControls [ExitCode]->m_flagsPlus & FCF_VALIDATE) break; for (int i=0; i<fControls.Count(); i++) if (!fControls [i]->Validate()) { SetFocusControl (fControls [i]); UpdateFocus(); bValidData = FALSE; break; } } while (!bValidData); return fControls [ExitCode]; }
/** * This is where we will update the interactor bounding box for the pawn. * In this example we will do this by projecting the extent points and selecting the most extreme ones to form the projected bounding box */ void AEyeXSimpleInteractorPawn::Tick(float DeltaSeconds) { Super::Tick(DeltaSeconds); UpdateRegion(); UpdateFocus(DeltaSeconds); }
// Stop tracking a shell menu HRESULT CMenuFocusManager::PopMenuPopup(CMenuBand * mb) { StackEntryType type; CMenuBand * mbc; HRESULT hr; TRACE("PopMenuPopup %p\n", mb); if (m_current == m_entryUnderMouse) { m_entryUnderMouse = NULL; } m_menuDepth--; hr = PopFromArray(&type, &mbc, NULL); if (FAILED_UNEXPECTEDLY(hr)) { UpdateFocus(); return hr; } _ASSERT(type == MenuPopupEntry); if (type != MenuPopupEntry) return E_FAIL; if (!mbc) return E_FAIL; mbc->_SetParentBand(NULL); mbc->Release(); hr = UpdateFocus(); if (FAILED_UNEXPECTEDLY(hr)) return hr; if (m_current) { _ASSERT(m_current->type != TrackedMenuEntry); m_current->mb->_SetChildBand(NULL); } return S_OK; }
void CWidget::SetFocus(bool f) { bool changed = f != m_bFocused; if (changed) { m_bFocused = f; m_bColorsChanged = true; UpdateFocus(); } }
// Begin tracking top-level menu bar (for file browser windows) HRESULT CMenuFocusManager::PushMenuBar(CMenuBand * mb) { TRACE("PushMenuBar %p\n", mb); mb->AddRef(); _ASSERT(m_bandCount == 0); HRESULT hr = PushToArray(MenuBarEntry, mb, NULL); if (FAILED_UNEXPECTEDLY(hr)) return hr; return UpdateFocus(); }
// Begin tracking a system popup submenu (submenu of the file browser windows) HRESULT CMenuFocusManager::PushTrackedPopup(HMENU popup) { TRACE("PushTrackedPopup %p\n", popup); _ASSERT(m_bandCount > 0); _ASSERT(!m_current || m_current->type != TrackedMenuEntry); HRESULT hr = PushToArray(TrackedMenuEntry, NULL, popup); if (FAILED_UNEXPECTEDLY(hr)) return hr; TRACE("PushTrackedPopup %p\n", popup); m_selectedMenu = popup; m_selectedItem = -1; m_selectedItemFlags = 0; return UpdateFocus(); }
// Begin tracking a shell menu popup (start menu or submenus) HRESULT CMenuFocusManager::PushMenuPopup(CMenuBand * mb) { TRACE("PushTrackedPopup %p\n", mb); mb->AddRef(); _ASSERT(!m_current || m_current->type != TrackedMenuEntry); HRESULT hr = PushToArray(MenuPopupEntry, mb, NULL); if (FAILED_UNEXPECTEDLY(hr)) return hr; hr = UpdateFocus(); m_menuDepth++; if (m_parent && m_parent->type != TrackedMenuEntry) { m_parent->mb->_SetChildBand(mb); mb->_SetParentBand(m_parent->mb); } return hr; }
static void I_GetEvent(SDL_Window *window) { SDL_Event ev; int sendmouseevent = 0; int buttons = 0; event_t d_event = { ev_keydown, 0, 0, 0, false }; event_t mouseevent = { ev_mouse, 0, 0, 0, false }; event_t tempevent = { ev_keydown, 0, 0, 0, false }; // [CG] 01/31/2012: Ensure we have the latest info about focus and mouse grabbing. UpdateFocus(window); UpdateGrab(window); while(SDL_PollEvent(&ev)) { // haleyjd 10/08/05: from Chocolate DOOM if(!window_focused && (ev.type == SDL_MOUSEMOTION || ev.type == SDL_MOUSEBUTTONDOWN || ev.type == SDL_MOUSEBUTTONUP)) { continue; } switch(ev.type) { case SDL_TEXTINPUT: for(unsigned int i = 0; i < SDL_strlen(ev.text.text); i++) { const char currchar = ev.text.text[i]; if(ectype::isPrint(currchar)) { event_t textevent = { ev_text, currchar, 0, 0, !!ev.key.repeat }; D_PostEvent(&textevent); } } break; case SDL_KEYDOWN: d_event.type = ev_keydown; d_event.repeat = !!ev.key.repeat; d_event.data1 = I_TranslateKey(&ev.key.keysym); #if (EE_CURRENT_PLATFORM != EE_PLATFORM_MACOSX) // This quick exit code is adapted from PRBoom+ // See PRBoom+'s I_GetEvent for a cross-platform implementation of how to get that input. if(ev.key.keysym.mod & KMOD_LALT) { // Prevent executing action on Alt-Tab if(ev.key.keysym.scancode == SDL_SCANCODE_TAB) break; // Immediately exit on Alt+F4 ("Boss Key") else if(ev.key.keysym.scancode == SDL_SCANCODE_F4) { I_QuitFast(); break; } else if(ev.key.keysym.scancode == SDL_SCANCODE_RETURN) { I_ToggleFullscreen(); break; } } #else // Also provide macOS option for quick exit and fullscreen toggle if(ev.key.keysym.mod & KMOD_GUI) { if(ev.key.keysym.scancode == SDL_SCANCODE_Q) { I_QuitFast(); break; } else if(ev.key.keysym.scancode == SDL_SCANCODE_F) { I_ToggleFullscreen(); break; } } #endif // MaxW: 2017/10/12: Removed deferred event adding for caps lock // MaxW: 2017/10/18: Removed character input D_PostEvent(&d_event); break; case SDL_KEYUP: d_event.type = ev_keyup; d_event.data1 = I_TranslateKey(&ev.key.keysym); D_PostEvent(&d_event); break; case SDL_MOUSEMOTION: if(!usemouse || ((mouseAccel_type == ACCELTYPE_CHOCO) || (mouseAccel_type == ACCELTYPE_CUSTOM))) continue; // haleyjd 06/14/10: no mouse motion at startup. if(gametic == 0) continue; // SoM 1-20-04 Ok, use xrel/yrel for mouse movement because most // people like it the most. if(mouseAccel_type == ACCELTYPE_NONE) { mouseevent.data2 += ev.motion.xrel; mouseevent.data3 -= ev.motion.yrel; } else if(mouseAccel_type == ACCELTYPE_LINEAR) { // Simple linear acceleration // Evaluates to 1.25 * x. So Why don't I just do that? .... shut up mouseevent.data2 += (ev.motion.xrel + (float)(ev.motion.xrel * 0.25f)); mouseevent.data3 -= (ev.motion.yrel + (float)(ev.motion.yrel * 0.25f)); } sendmouseevent = 1; break; case SDL_MOUSEBUTTONDOWN: if(!usemouse) continue; d_event.type = ev_keydown; switch(ev.button.button) { case SDL_BUTTON_LEFT: sendmouseevent = 1; buttons |= 1; d_event.data1 = KEYD_MOUSE1; break; case SDL_BUTTON_MIDDLE: // haleyjd 05/28/06: swapped MOUSE3/MOUSE2 sendmouseevent = 1; buttons |= 4; d_event.data1 = KEYD_MOUSE3; break; case SDL_BUTTON_RIGHT: sendmouseevent = 1; buttons |= 2; d_event.data1 = KEYD_MOUSE2; break; case SDL_BUTTON_X1: d_event.data1 = KEYD_MOUSE4; break; case SDL_BUTTON_X2: d_event.data1 = KEYD_MOUSE5; break; } D_PostEvent(&d_event); break; case SDL_MOUSEWHEEL: if(!usemouse) continue; d_event.type = ev_keydown; // SDL_TODO: Allow y to correspond to # of weps scrolled through? if(ev.wheel.y > 0) { d_event.data1 = KEYD_MWHEELUP; D_PostEvent(&d_event); // WHEELUP sends a button up event immediately. That won't work; // we need an input latency gap of at least one gametic. tempevent.type = ev_keyup; tempevent.data1 = KEYD_MWHEELUP; I_AddDeferredEvent(tempevent, gametic + 1); break; } else if(ev.wheel.y < 0) { d_event.data1 = KEYD_MWHEELDOWN; D_PostEvent(&d_event); // ditto, as above. tempevent.type = ev_keyup; tempevent.data1 = KEYD_MWHEELDOWN; I_AddDeferredEvent(tempevent, gametic + 1); break; } case SDL_MOUSEBUTTONUP: if(!usemouse) continue; d_event.type = ev_keyup; d_event.data1 = 0; switch(ev.button.button) { case SDL_BUTTON_LEFT: sendmouseevent = 1; buttons &= ~1; d_event.data1 = KEYD_MOUSE1; break; case SDL_BUTTON_MIDDLE: // haleyjd 05/28/06: swapped MOUSE3/MOUSE2 sendmouseevent = 1; buttons &= ~4; d_event.data1 = KEYD_MOUSE3; break; case SDL_BUTTON_RIGHT: sendmouseevent = 1; buttons &= ~2; d_event.data1 = KEYD_MOUSE2; break; case SDL_BUTTON_X1: d_event.data1 = KEYD_MOUSE4; break; case SDL_BUTTON_X2: d_event.data1 = KEYD_MOUSE5; break; } if(d_event.data1) D_PostEvent(&d_event); break; case SDL_QUIT: MN_QuitDoom(); break; case SDL_WINDOWEVENT: // haleyjd 10/08/05: from Chocolate DOOM: // need to update our focus state // 2/14/2011: Update mouse grabbing as well (thanks Catoptromancy) UpdateFocus(window); UpdateGrab(window); break; default: break; } } if(sendmouseevent) { mouseevent.data1 = buttons; D_PostEvent(&mouseevent); } // SoM: if paused, delay for a short amount of time to allow other threads // to process on the system. Otherwise Eternity will use almost 100% of the // CPU even while paused. if(paused || !window_focused) SDL_Delay(1); }
void I_InitGraphics(void) { SDL_Event dummy; byte *doompal; char *env; // Pass through the XSCREENSAVER_WINDOW environment variable to // SDL_WINDOWID, to embed the SDL window into the Xscreensaver // window. env = getenv("XSCREENSAVER_WINDOW"); if (env != NULL) { char winenv[30]; int winid; sscanf(env, "0x%x", &winid); M_snprintf(winenv, sizeof(winenv), "SDL_WINDOWID=%i", winid); putenv(winenv); } SetSDLVideoDriver(); SetWindowPositionVars(); if (SDL_Init(SDL_INIT_VIDEO) < 0) { I_Error("Failed to initialize video: %s", SDL_GetError()); } // Set up title and icon. Windows cares about the ordering; this // has to be done before the call to SDL_SetVideoMode. I_InitWindowTitle(); I_InitWindowIcon(); // Warning to OS X users... though they might never see it :( #ifdef __MACOSX__ if (fullscreen) { printf("Some old versions of OS X might crash in fullscreen mode.\n" "If this happens to you, switch back to windowed mode.\n"); } #endif // // Enter into graphics mode. // // When in screensaver mode, run full screen and auto detect // screen dimensions (don't change video mode) // if (screensaver_mode) { SetVideoMode(NULL, 0, 0); } else { int w, h; if (autoadjust_video_settings) { I_AutoAdjustSettings(); } w = screen_width; h = screen_height; screen_mode = I_FindScreenMode(w, h); if (screen_mode == NULL) { I_Error("I_InitGraphics: Unable to find a screen mode small " "enough for %ix%i", w, h); } if (w != screen_mode->width || h != screen_mode->height) { printf("I_InitGraphics: %s (%ix%i within %ix%i)\n", WindowBoxType(screen_mode, w, h), screen_mode->width, screen_mode->height, w, h); } SetVideoMode(screen_mode, w, h); } // Start with a clear black screen // (screen will be flipped after we set the palette) SDL_FillRect(screenbuffer, NULL, 0); // Set the palette doompal = W_CacheLumpName(DEH_String("PLAYPAL"), PU_CACHE); I_SetPalette(doompal); SDL_SetColors(screenbuffer, palette, 0, 256); CreateCursors(); UpdateFocus(); UpdateGrab(); // On some systems, it takes a second or so for the screen to settle // after changing modes. We include the option to add a delay when // setting the screen mode, so that the game doesn't start immediately // with the player unable to see anything. if (fullscreen && !screensaver_mode) { SDL_Delay(startup_delay); } // Check if we have a native surface we can use // If we have to lock the screen, draw to a buffer and copy // Likewise if the screen pitch is not the same as the width // If we have to multiply, drawing is done to a separate 320x200 buf native_surface = screen == screenbuffer && !SDL_MUSTLOCK(screen) && screen_mode == &mode_scale_1x && screen->pitch == SCREENWIDTH && aspect_ratio_correct; // If not, allocate a buffer and copy from that buffer to the // screen when we do an update if (native_surface) { I_VideoBuffer = (unsigned char *) screen->pixels; I_VideoBuffer += (screen->h - SCREENHEIGHT) / 2; } else { I_VideoBuffer = (unsigned char *) Z_Malloc (SCREENWIDTH * SCREENHEIGHT, PU_STATIC, NULL); } V_RestoreBuffer(); // Clear the screen to black. memset(I_VideoBuffer, 0, SCREENWIDTH * SCREENHEIGHT); // We need SDL to give us translated versions of keys as well SDL_EnableUNICODE(1); // Repeat key presses - this is what Vanilla Doom does // Not sure about repeat rate - probably dependent on which DOS // driver is used. This is good enough though. SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); // clear out any events waiting at the start and center the mouse while (SDL_PollEvent(&dummy)); initialized = true; // Call I_ShutdownGraphics on quit I_AtExit(I_ShutdownGraphics, true); }
// // SDLVideoDriver::InitGraphicsMode // // killough 11/98: New routine, for setting hires and page flipping // sf: now returns true if an error occurred // bool SDLVideoDriver::InitGraphicsMode() { // haleyjd 06/19/11: remember characteristics of last successful modeset static int fallback_w = 640; static int fallback_h = 480; static int fallback_bd = 8; static int fallback_flags = SDL_SWSURFACE; bool wantfullscreen = false; bool wantvsync = false; bool wanthardware = false; bool wantframe = true; int v_w = 640; int v_h = 480; int v_bd = 8; int flags = SDL_SWSURFACE; // haleyjd 12/03/07: cross-bit-depth support if(M_CheckParm("-8in32")) v_bd = 32; else if(i_softbitdepth > 8) { switch(i_softbitdepth) { case 16: // Valid screen bitdepth settings case 24: case 32: v_bd = i_softbitdepth; break; default: break; } } if(v_bd != 8) crossbitdepth = true; // haleyjd 04/11/03: "vsync" or page-flipping support if(use_vsync) wantvsync = true; // haleyjd 07/15/09: set defaults using geom string from configuration file I_ParseGeom(i_videomode, &v_w, &v_h, &wantfullscreen, &wantvsync, &wanthardware, &wantframe); // haleyjd 06/21/06: allow complete command line overrides but only // on initial video mode set (setting from menu doesn't support this) I_CheckVideoCmds(&v_w, &v_h, &wantfullscreen, &wantvsync, &wanthardware, &wantframe); if(wanthardware) flags = SDL_HWSURFACE; if(wantvsync) flags = SDL_HWSURFACE | SDL_DOUBLEBUF; if(wantfullscreen) flags |= SDL_FULLSCREEN; // haleyjd 10/27/09 if(!wantframe) flags |= SDL_NOFRAME; if(!SDL_VideoModeOK(v_w, v_h, v_bd, flags) || !(sdlscreen = SDL_SetVideoMode(v_w, v_h, v_bd, flags))) { // try 320x200w safety mode if(!SDL_VideoModeOK(fallback_w, fallback_h, fallback_bd, fallback_flags) || !(sdlscreen = SDL_SetVideoMode(fallback_w, fallback_h, fallback_bd, fallback_flags))) { I_FatalError(I_ERR_KILL, "I_SDLInitGraphicsMode: couldn't set mode %dx%dx%d;\n" " Also failed to restore fallback mode %dx%dx%d.\n" " Check your SDL video driver settings.\n", v_w, v_h, v_bd, fallback_w, fallback_h, fallback_bd); } // reset these for below population of video struct v_w = fallback_w; v_h = fallback_h; v_bd = fallback_bd; flags = fallback_flags; } // Record successful mode set for use as a fallback mode fallback_w = v_w; fallback_h = v_h; fallback_bd = v_bd; fallback_flags = flags; // haleyjd 10/14/09: wait for a bit so the screen can settle if(flags & SDL_FULLSCREEN) I_Sleep(500); // haleyjd 10/09/05: keep track of fullscreen state fullscreen = (sdlscreen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN; // haleyjd 12/03/07: if the video surface is not high-color, we // disable cross-bit-depth drawing for efficiency if(sdlscreen->format->BitsPerPixel == 8) crossbitdepth = false; SDL_WM_SetCaption(ee_wmCaption, ee_wmCaption); UpdateFocus(); UpdateGrab(); video.width = v_w; video.height = v_h; video.bitdepth = 8; video.pixelsize = 1; // haleyjd 11/12/09: set surface palettes immediately I_SDLSetPaletteDirect((byte *)wGlobalDir.cacheLumpName("PLAYPAL", PU_CACHE)); return false; }
static void HandleWindowEvent(SDL_WindowEvent *event) { int i; switch (event->event) { #if 0 // SDL2-TODO case SDL_ACTIVEEVENT: // need to update our focus state UpdateFocus(); break; #endif case SDL_WINDOWEVENT_EXPOSED: palette_to_set = true; break; case SDL_WINDOWEVENT_RESIZED: need_resize = true; last_resize_time = SDL_GetTicks(); break; // Don't render the screen when the window is minimized: case SDL_WINDOWEVENT_MINIMIZED: screenvisible = false; break; case SDL_WINDOWEVENT_MAXIMIZED: case SDL_WINDOWEVENT_RESTORED: screenvisible = true; break; // Update the value of window_focused when we get a focus event // // We try to make ourselves be well-behaved: the grab on the mouse // is removed if we lose focus (such as a popup window appearing), // and we dont move the mouse around if we aren't focused either. case SDL_WINDOWEVENT_FOCUS_GAINED: window_focused = true; break; case SDL_WINDOWEVENT_FOCUS_LOST: window_focused = false; break; // We want to save the user's preferred monitor to use for running the // game, so that next time we're run we start on the same display. So // every time the window is moved, find which display we're now on and // update the video_display config variable. case SDL_WINDOWEVENT_MOVED: i = SDL_GetWindowDisplayIndex(screen); if (i >= 0) { video_display = i; } break; default: break; } }
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; } }
// // SDLVideoDriver::InitGraphicsMode // // killough 11/98: New routine, for setting hires and page flipping // sf: now returns true if an error occurred // bool SDLVideoDriver::InitGraphicsMode() { // haleyjd 06/19/11: remember characteristics of last successful modeset static int fallback_w = 640; static int fallback_h = 480; static int fallback_w_flags = SDL_WINDOW_ALLOW_HIGHDPI; // SDL_RENDERER_SOFTWARE causes failures in creating renderer static int fallback_r_flags = SDL_RENDERER_TARGETTEXTURE; bool wantfullscreen = false; bool wantdesktopfs = false; bool wantvsync = false; bool wanthardware = false; bool wantframe = true; int v_w = 640; int v_h = 480; int v_displaynum = 0; int window_flags = SDL_WINDOW_ALLOW_HIGHDPI; // SDL_RENDERER_SOFTWARE causes failures in creating renderer int renderer_flags = SDL_RENDERER_TARGETTEXTURE; // haleyjd 04/11/03: "vsync" or page-flipping support if(use_vsync) wantvsync = true; // haleyjd 07/15/09: set defaults using geom string from configuration file I_ParseGeom(i_videomode, &v_w, &v_h, &wantfullscreen, &wantvsync, &wanthardware, &wantframe, &wantdesktopfs); // haleyjd 06/21/06: allow complete command line overrides but only // on initial video mode set (setting from menu doesn't support this) I_CheckVideoCmds(&v_w, &v_h, &wantfullscreen, &wantvsync, &wanthardware, &wantframe, &wantdesktopfs); // Wanting vsync forces framebuffer acceleration on if(wantvsync) { SDL_SetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION, "1"); renderer_flags |= SDL_RENDERER_PRESENTVSYNC; } else if(wanthardware) SDL_SetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION, "1"); else SDL_SetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION, "0"); // haleyjd 10/27/09 if(!wantframe) window_flags |= SDL_WINDOW_BORDERLESS; if(displaynum < SDL_GetNumVideoDisplays()) v_displaynum = displaynum; else displaynum = 0; if(!(window = SDL_CreateWindow(ee_wmCaption, SDL_WINDOWPOS_CENTERED_DISPLAY(v_displaynum), SDL_WINDOWPOS_CENTERED_DISPLAY(v_displaynum), v_w, v_h, window_flags))) { // try 320x200w safety mode if(!(window = SDL_CreateWindow(ee_wmCaption, SDL_WINDOWPOS_CENTERED_DISPLAY(v_displaynum), SDL_WINDOWPOS_CENTERED_DISPLAY(v_displaynum), fallback_w, fallback_h, fallback_w_flags))) { // SDL_TODO: Trim fat from this error message I_FatalError(I_ERR_KILL, "I_SDLInitGraphicsMode: couldn't create window for mode %dx%d;\n" " Also failed to restore fallback mode %dx%d.\n" " Check your SDL video driver settings.\n", v_w, v_h, fallback_w, fallback_h); } // reset these for below population of video struct v_w = fallback_w; v_h = fallback_h; window_flags = fallback_w_flags; } #if EE_CURRENT_PLATFORM == EE_PLATFORM_MACOSX // this and the below #else block are done here as monitor video mode isn't // set when SDL_WINDOW_FULLSCREEN (sans desktop) is ORed in during window creation if(wantfullscreen) SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP); #else if(wantfullscreen && wantdesktopfs) SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP); else if(wantfullscreen) // && !wantdesktopfs SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN); #endif if(!(renderer = SDL_CreateRenderer(window, -1, renderer_flags))) { if(!(renderer = SDL_CreateRenderer(window, -1, fallback_r_flags))) { // SDL_TODO: Trim fat from this error message I_FatalError(I_ERR_KILL, "I_SDLInitGraphicsMode: couldn't create renderer for mode %dx%d;\n" " Also failed to restore fallback mode %dx%d.\n" " Check your SDL video driver settings.\n", v_w, v_h, fallback_w, fallback_h); } fallback_r_flags = renderer_flags; } // Record successful mode set for use as a fallback mode fallback_w = v_w; fallback_h = v_h; fallback_w_flags = window_flags; fallback_r_flags = renderer_flags; // haleyjd 10/09/05: keep track of fullscreen state fullscreen = !!(SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN_DESKTOP); UpdateFocus(window); UpdateGrab(window); // check for letterboxing if(I_VideoShouldLetterbox(v_w, v_h)) { int hs = I_VideoLetterboxHeight(v_w); staticDestRect.x = 0; staticDestRect.y = static_cast<Sint16>(I_VideoLetterboxOffset(v_h, hs)); staticDestRect.w = static_cast<Uint16>(v_w); staticDestRect.h = static_cast<Uint16>(hs); video.width = v_w; video.height = hs; destrect = &staticDestRect; } else { video.width = v_w; video.height = v_h; destrect = nullptr; } video.bitdepth = 8; video.pixelsize = 1; UnsetPrimaryBuffer(); SetPrimaryBuffer(); // haleyjd 11/12/09: set surface palettes immediately I_SDLSetPaletteDirect(static_cast<byte *>(wGlobalDir.cacheLumpName("PLAYPAL", PU_CACHE))); return false; }
void I_InitGraphics(void) { SDL_Event dummy; byte *doompal; int flags = 0; char *env; // Pass through the XSCREENSAVER_WINDOW environment variable to // SDL_WINDOWID, to embed the SDL window into the Xscreensaver // window. env = getenv("XSCREENSAVER_WINDOW"); if (env != NULL) { char winenv[30]; int winid; sscanf(env, "0x%x", &winid); sprintf(winenv, "SDL_WINDOWID=%i", winid); putenv(winenv); } SetSDLVideoDriver(); if (SDL_Init(SDL_INIT_VIDEO) < 0) { I_Error("Failed to initialize video: %s", SDL_GetError()); } // Check for command-line video-related parameters. CheckCommandLine(); doompal = W_CacheLumpName (DEH_String("PLAYPAL"),PU_CACHE); if (screensaver_mode) { windowwidth = 0; windowheight = 0; } else { if (autoadjust_video_settings) { I_AutoAdjustSettings(); } windowwidth = screen_width; windowheight = screen_height; screen_mode = I_FindScreenMode(windowwidth, windowheight); if (screen_mode == NULL) { I_Error("I_InitGraphics: Unable to find a screen mode small " "enough for %ix%i", windowwidth, windowheight); } if (windowwidth != screen_mode->width || windowheight != screen_mode->height) { printf("I_InitGraphics: %s (%ix%i within %ix%i)\n", WindowBoxType(screen_mode, windowwidth, windowheight), screen_mode->width, screen_mode->height, windowwidth, windowheight); } // Generate lookup tables before setting the video mode. if (screen_mode->InitMode != NULL) { screen_mode->InitMode(doompal); } } // Set up title and icon. Windows cares about the ordering; this // has to be done before the call to SDL_SetVideoMode. I_SetWindowCaption(); #if !SDL_VERSION_ATLEAST(1, 3, 0) I_SetWindowIcon(); #endif // Set the video mode. flags |= SDL_SWSURFACE | SDL_HWPALETTE | SDL_DOUBLEBUF; if (fullscreen) { flags |= SDL_FULLSCREEN; } screen = SDL_SetVideoMode(windowwidth, windowheight, 8, flags); if (screen == NULL) { I_Error("Error setting video mode: %s\n", SDL_GetError()); } // Start with a clear black screen // (screen will be flipped after we set the palette) if (SDL_LockSurface(screen) >= 0) { byte *screenpixels; int y; screenpixels = (byte *) screen->pixels; for (y=0; y<screen->h; ++y) memset(screenpixels + screen->pitch * y, 0, screen->w); SDL_UnlockSurface(screen); } // Set the palette I_SetPalette(doompal); SDL_SetColors(screen, palette, 0, 256); CreateCursors(); UpdateFocus(); UpdateGrab(); // In screensaver mode, now find a screen_mode to use. if (screensaver_mode) { screen_mode = I_FindScreenMode(screen->w, screen->h); if (screen_mode == NULL) { I_Error("I_InitGraphics: Unable to find a screen mode small " "enough for %ix%i", screen->w, screen->h); } // Generate lookup tables before setting the video mode. if (screen_mode->InitMode != NULL) { screen_mode->InitMode(doompal); } } // On some systems, it takes a second or so for the screen to settle // after changing modes. We include the option to add a delay when // setting the screen mode, so that the game doesn't start immediately // with the player unable to see anything. if (fullscreen && !screensaver_mode) { SDL_Delay(startup_delay); } // Check if we have a native surface we can use // If we have to lock the screen, draw to a buffer and copy // Likewise if the screen pitch is not the same as the width // If we have to multiply, drawing is done to a separate 320x200 buf native_surface = !SDL_MUSTLOCK(screen) && screen_mode == &mode_scale_1x && screen->pitch == SCREENWIDTH && aspect_ratio_correct; // If not, allocate a buffer and copy from that buffer to the // screen when we do an update if (native_surface) { screens[0] = (unsigned char *) screen->pixels; screens[0] += (screen->h - SCREENHEIGHT) / 2; } else { screens[0] = (unsigned char *) Z_Malloc (SCREENWIDTH * SCREENHEIGHT, PU_STATIC, NULL); } // "Loading from disk" icon LoadDiskImage(); // Clear the screen to black. memset(screens[0], 0, SCREENWIDTH * SCREENHEIGHT); // We need SDL to give us translated versions of keys as well SDL_EnableUNICODE(1); // Repeat key presses - this is what Vanilla Doom does // Not sure about repeat rate - probably dependent on which DOS // driver is used. This is good enough though. SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); // clear out any events waiting at the start and center the mouse while (SDL_PollEvent(&dummy)); if (usemouse && !nomouse && (fullscreen || grabmouse)) { CenterMouse(); } initialized = true; }
void I_GetEvent(void) { SDL_Event sdlevent; event_t event; // possibly not needed SDL_PumpEvents(); // put event-grabbing stuff in here while (SDL_PollEvent(&sdlevent)) { // ignore mouse events when the window is not focused if (!window_focused && (sdlevent.type == SDL_MOUSEMOTION || sdlevent.type == SDL_MOUSEBUTTONDOWN || sdlevent.type == SDL_MOUSEBUTTONUP)) { continue; } if (screensaver_mode && sdlevent.type == SDL_QUIT) { I_Quit(); } UpdateShiftStatus(&sdlevent); // process event switch (sdlevent.type) { case SDL_KEYDOWN: // data1 has the key pressed, data2 has the character // (shift-translated, etc) event.type = ev_keydown; event.data1 = TranslateKey(&sdlevent.key.keysym); event.data2 = GetTypedChar(&sdlevent); if (event.data1 != 0) { D_PostEvent(&event); } break; case SDL_KEYUP: event.type = ev_keyup; event.data1 = TranslateKey(&sdlevent.key.keysym); // data2 is just initialized to zero for ev_keyup. // For ev_keydown it's the shifted Unicode character // that was typed, but if something wants to detect // key releases it should do so based on data1 // (key ID), not the printable char. event.data2 = 0; if (event.data1 != 0) { D_PostEvent(&event); } break; /* case SDL_MOUSEMOTION: event.type = ev_mouse; event.data1 = mouse_button_state; event.data2 = AccelerateMouse(sdlevent.motion.xrel); event.data3 = -AccelerateMouse(sdlevent.motion.yrel); D_PostEvent(&event); break; */ case SDL_MOUSEBUTTONDOWN: if (usemouse && !nomouse) { UpdateMouseButtonState(sdlevent.button.button, true); } break; case SDL_MOUSEBUTTONUP: if (usemouse && !nomouse) { UpdateMouseButtonState(sdlevent.button.button, false); } break; case SDL_QUIT: event.type = ev_quit; D_PostEvent(&event); break; case SDL_ACTIVEEVENT: // need to update our focus state UpdateFocus(); break; case SDL_VIDEOEXPOSE: palette_to_set = true; break; case SDL_RESIZABLE: need_resize = true; resize_w = sdlevent.resize.w; resize_h = sdlevent.resize.h; last_resize_time = SDL_GetTicks(); break; default: break; } } }
void I_GetEvent(void) { SDL_Event sdlevent; event_t event; // possibly not needed SDL_PumpEvents(); // put event-grabbing stuff in here while (SDL_PollEvent(&sdlevent)) { // ignore mouse events when the window is not focused if (!window_focused && (sdlevent.type == SDL_MOUSEMOTION || sdlevent.type == SDL_MOUSEBUTTONDOWN || sdlevent.type == SDL_MOUSEBUTTONUP)) { continue; } if (screensaver_mode && sdlevent.type == SDL_QUIT) { I_Quit(); } // process event switch (sdlevent.type) { case SDL_KEYDOWN: event.type = ev_keydown; event.data1 = TranslateKey(&sdlevent.key.keysym); // If Vanilla keyboard mapping enabled, the keyboard // scan code is used to give the character typed. // This does not change depending on keyboard layout. // If you have a German keyboard, pressing 'z' will // give 'y', for example. It is desirable to be able // to fix this so that people with non-standard // keyboard mappings can type properly. If vanilla // mode is disabled, use the properly translated // version. if (vanilla_keyboard_mapping) { event.data2 = event.data1; } else { event.data2 = sdlevent.key.keysym.unicode; } if (event.data1 != 0) { D_PostEvent(&event); } break; case SDL_KEYUP: event.type = ev_keyup; event.data1 = TranslateKey(&sdlevent.key.keysym); if (event.data1 != 0) { D_PostEvent(&event); } break; /* case SDL_MOUSEMOTION: event.type = ev_mouse; event.data1 = MouseButtonState(); event.data2 = AccelerateMouse(sdlevent.motion.xrel); event.data3 = -AccelerateMouse(sdlevent.motion.yrel); D_PostEvent(&event); break; */ case SDL_MOUSEBUTTONDOWN: if (usemouse && !nomouse) { event.type = ev_mouse; event.data1 = MouseButtonState(); event.data2 = event.data3 = 0; D_PostEvent(&event); } break; case SDL_MOUSEBUTTONUP: if (usemouse && !nomouse) { event.type = ev_mouse; event.data1 = MouseButtonState(); event.data2 = event.data3 = 0; D_PostEvent(&event); } break; case SDL_QUIT: // bring up the "quit doom?" prompt S_StartSound(NULL,sfx_swtchn); M_QuitDOOM(0); break; case SDL_ACTIVEEVENT: // need to update our focus state UpdateFocus(); break; case SDL_VIDEOEXPOSE: palette_to_set = true; break; default: break; } } }
// // I_GetEvent // void I_GetEvent (void) { event_t event; event_t mouseevent = {ev_mouse, 0, 0, 0}; static int mbuttons = 0; int sendmouseevent = 0; SDL_Event ev; if (!havefocus) I_PauseMouse(); else { I_ResumeMouse(); } while(SDL_PollEvent(&ev)) { event.data1 = event.data2 = event.data3 = 0; switch(ev.type) { case SDL_QUIT: AddCommandString("menu_quit"); break; // Resizable window mode resolutions case SDL_VIDEORESIZE: { if (!vid_fullscreen) { char Command[64]; mousegrabbed = false; snprintf(Command, sizeof(Command), "vid_setmode %d %d", ev.resize.w, ev.resize.h); AddCommandString(Command); vid_defwidth.Set((float)ev.resize.w); vid_defheight.Set((float)ev.resize.h); } } break; case SDL_ACTIVEEVENT: // need to update our focus state UpdateFocus(); break; case SDL_KEYDOWN: event.type = ev_keydown; event.data1 = ev.key.keysym.sym; if(event.data1 >= SDLK_KP0 && event.data1 <= SDLK_KP9) event.data2 = event.data3 = '0' + (event.data1 - SDLK_KP0); else if(event.data1 == SDLK_KP_PERIOD) event.data2 = event.data3 = '.'; else if(event.data1 == SDLK_KP_DIVIDE) event.data2 = event.data3 = '/'; else if(event.data1 == SDLK_KP_ENTER) event.data2 = event.data3 = '\r'; else if ( (ev.key.keysym.unicode & 0xFF80) == 0 ) event.data2 = event.data3 = ev.key.keysym.unicode; else event.data2 = event.data3 = 0; #ifdef _XBOX // Fix for ENTER key on Xbox if(event.data1 == SDLK_RETURN) event.data2 = event.data3 = '\r'; #endif #ifdef WIN32 //HeX9109: Alt+F4 for cheats! Thanks Spleen if(event.data1 == SDLK_F4 && SDL_GetModState() & (KMOD_LALT | KMOD_RALT)) AddCommandString("menu_quit"); // SoM: Ignore the tab portion of alt-tab presses if(event.data1 == SDLK_TAB && SDL_GetModState() & (KMOD_LALT | KMOD_RALT)) event.data1 = event.data2 = event.data3 = 0; else #endif D_PostEvent(&event); break; case SDL_KEYUP: event.type = ev_keyup; event.data1 = ev.key.keysym.sym; if ( (ev.key.keysym.unicode & 0xFF80) == 0 ) event.data2 = event.data3 = ev.key.keysym.unicode; else event.data2 = event.data3 = 0; D_PostEvent(&event); break; case SDL_MOUSEMOTION: if(flushmouse) { flushmouse = false; break; } if (!havefocus) break; // denis - ignore artificially inserted events (see SDL_WarpMouse below) if(ev.motion.x == screen->width/2 && ev.motion.y == screen->height/2) { break; } mouseevent.data2 += AccelerateMouse(ev.motion.xrel); mouseevent.data3 -= AccelerateMouse(ev.motion.yrel); sendmouseevent = 1; break; case SDL_MOUSEBUTTONDOWN: if(nomouse || !havefocus) break; event.type = ev_keydown; if(ev.button.button == SDL_BUTTON_LEFT) { event.data1 = KEY_MOUSE1; mbuttons |= 1; } else if(ev.button.button == SDL_BUTTON_RIGHT) { event.data1 = KEY_MOUSE2; mbuttons |= 2; } else if(ev.button.button == SDL_BUTTON_MIDDLE) { event.data1 = KEY_MOUSE3; mbuttons |= 4; } else if(ev.button.button == SDL_BUTTON_WHEELUP) event.data1 = KEY_MWHEELUP; else if(ev.button.button == SDL_BUTTON_WHEELDOWN) event.data1 = KEY_MWHEELDOWN; D_PostEvent(&event); break; case SDL_MOUSEBUTTONUP: if(nomouse || !havefocus) break; event.type = ev_keyup; if(ev.button.button == SDL_BUTTON_LEFT) { event.data1 = KEY_MOUSE1; mbuttons &= ~1; } else if(ev.button.button == SDL_BUTTON_RIGHT) { event.data1 = KEY_MOUSE2; mbuttons &= ~2; } else if(ev.button.button == SDL_BUTTON_MIDDLE) { event.data1 = KEY_MOUSE3; mbuttons &= ~4; } else if(ev.button.button == SDL_BUTTON_WHEELUP) event.data1 = KEY_MWHEELUP; else if(ev.button.button == SDL_BUTTON_WHEELDOWN) event.data1 = KEY_MWHEELDOWN; D_PostEvent(&event); break; case SDL_JOYBUTTONDOWN: if(ev.jbutton.which == joy_active) { event.type = ev_keydown; event.data1 = ev.jbutton.button + KEY_JOY1; event.data2 = event.data1; D_PostEvent(&event); break; } case SDL_JOYBUTTONUP: if(ev.jbutton.which == joy_active) { event.type = ev_keyup; event.data1 = ev.jbutton.button + KEY_JOY1; event.data2 = event.data1; D_PostEvent(&event); break; } case SDL_JOYAXISMOTION: if(ev.jaxis.which == joy_active) { event.type = ev_joystick; event.data1 = 0; event.data2 = ev.jaxis.axis; if( (ev.jaxis.value < JOY_DEADZONE) && (ev.jaxis.value > -JOY_DEADZONE) ) event.data3 = 0; else event.data3 = ev.jaxis.value; D_PostEvent(&event); break; } case SDL_JOYHATMOTION: if(ev.jhat.which == joy_active) { // Each of these need to be tested because more than one can be pressed and a // unique event is needed for each if(ev.jhat.value & SDL_HAT_UP) RegisterJoystickEvent(&ev, SDL_HAT_UP); if(ev.jhat.value & SDL_HAT_RIGHT) RegisterJoystickEvent(&ev, SDL_HAT_RIGHT); if(ev.jhat.value & SDL_HAT_DOWN) RegisterJoystickEvent(&ev, SDL_HAT_DOWN); if(ev.jhat.value & SDL_HAT_LEFT) RegisterJoystickEvent(&ev, SDL_HAT_LEFT); break; } }; } if(!nomouse) { if(sendmouseevent) { mouseevent.data1 = mbuttons; D_PostEvent(&mouseevent); } if(mousegrabbed && screen) { SDL_WarpMouse(screen->width/ 2, screen->height / 2); } } if(use_joystick) UpdateJoystickEvents(); }
void FarDialog::Layout() { // The core loop. Automatic control layout, default/focus management // and so on. unsigned int LastY=m_BorderY; unsigned int MaxX2=0; unsigned int MaxY2 = 0; // m_Controls [0] is the dialog frame. It is handled specially. for (int i=1; i<fControls.Count(); i++) { FarDialogItem *pCurItem=fControls [i]->fItem; // Layout if (pCurItem->Y1 == -1) { if (pCurItem->X1 == -1) // next Y, default X { pCurItem->Y1 = ++LastY; if (!(pCurItem->Flags & DIF_SEPARATOR)) { pCurItem->X1 = m_BorderX+3; if (pCurItem->X2) pCurItem->X2 += pCurItem->X1-1; } } else if (pCurItem->X1 == DIF_CENTERGROUP) // special case for buttons { pCurItem->Flags |= DIF_CENTERGROUP; FarDialogItem * pPrevItem = fControls[ i - 1 ]->fItem; if (pPrevItem->Type == DI_BUTTON || pPrevItem->Type == DI_RADIOBUTTON ) { pCurItem->Y1 = pPrevItem->Y1; pPrevItem->Flags |= DIF_CENTERGROUP; } else { pCurItem->Y1 = ++LastY; } pCurItem->X1 = 0; // not important for centered groups } else { if (fControls [i]->m_flagsPlus & FCF_NEXTY) pCurItem->Y1 = ++LastY; else { FarDialogItem * pPrevItem = fControls[ i - 1 ]->fItem; if ( pPrevItem->Flags & (DIF_SEPARATOR|DIF_SEPARATOR2 ) ) LastY ++; pCurItem->Y1 = LastY; } pCurItem->X1 += m_BorderX+3; if (pCurItem->X2) pCurItem->X2 += pCurItem->X1-1; } if (pCurItem->Type == DI_SINGLEBOX || pCurItem->Type == DI_DOUBLEBOX) { // convert height to bottom Y pCurItem->Y2 += pCurItem->Y1; MaxY2 = pCurItem->Y2; } } // Max width determination if (pCurItem->X2 > (int) MaxX2) MaxX2 = pCurItem->X2; else { int Width=0; if (pCurItem->Type == DI_TEXT && pCurItem->Data != NULL) { Width = strlen (pCurItem->Data); } else if (pCurItem->Type == DI_CHECKBOX || pCurItem->Type == DI_RADIOBUTTON) Width = strlen (pCurItem->Data)+4; int curX = pCurItem->X1; if (curX == -1 && pCurItem->Flags & DIF_SEPARATOR && pCurItem->Data != NULL) { curX = 3; Width++; } if (Width + curX > (int) MaxX2) MaxX2 = Width + curX; } // Default if (fControls [i] == m_DefaultControl) pCurItem->DefaultButton = TRUE; else if (m_DefaultControl == NULL && pCurItem->Type == DI_BUTTON) { m_DefaultControl = fControls [i]; pCurItem->DefaultButton = TRUE; } else pCurItem->DefaultButton = FALSE; } UpdateFocus(); // Set the size of the dialog frame if (MaxY2 > LastY) LastY = MaxY2; fItems [0].X1 = m_BorderX+1; fItems [0].Y1 = m_BorderY; fItems [0].X2 = fItems [0].X1+MaxX2-1; fItems [0].Y2 = LastY+1; }