Esempio n. 1
0
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    if (msg == WM_SETCURSOR)
    {
        if (LOWORD(lParam) == HTCLIENT && !MouseShouldBeGrabbed())
        {
            SetCursor(LoadCursor(NULL, IDC_ARROW));
            return true;
        }
    }
    else if (msg == WM_SYSCOMMAND)
    {
        if ((wParam & 0xFFF0) == SC_MAXIMIZE)
        {
            I_ToggleFullscreen();
            return true;
        }
        else if ((wParam & 0xFFF0) == SC_KEYMENU)
            return false;
    }
    else if (msg == WM_SYSKEYDOWN && wParam == VK_RETURN && !(lParam & 0x40000000))
    {
        I_ToggleFullscreen();
        return true;
    }
    else if (msg == WM_DEVICECHANGE)
        I_InitGamepad();
    else if (msg == WM_SIZE && !vid_fullscreen)
        blitfunc();
    else if (msg == WM_GETMINMAXINFO)
    {
        LPMINMAXINFO    minmaxinfo = (LPMINMAXINFO)lParam;

        minmaxinfo->ptMinTrackSize.x = ORIGINALWIDTH + windowborderwidth;
        minmaxinfo->ptMinTrackSize.y = ORIGINALWIDTH * 3 / 4 + windowborderheight;

        return false;
    }

    return CallWindowProc(oldProc, hwnd, msg, wParam, lParam);
}
Esempio n. 2
0
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);
}