improved event handling of dialog (door/envelope) requests
[rocksndiamonds.git] / src / tools.c
index 247bcffd33d5a9de7d3a2afb9fce86270feabea0..a95b1f795ec8a65a1117732f8ab5add91214f933 100644 (file)
@@ -3389,109 +3389,110 @@ static int RequestHandleEvents(unsigned int req_state)
     {
       Event event;
 
-      NextEvent(&event);
-
-      switch (event.type)
+      while (NextValidEvent(&event))
       {
-       case EVENT_BUTTONPRESS:
-       case EVENT_BUTTONRELEASE:
-       case EVENT_MOTIONNOTIFY:
+       switch (event.type)
        {
-         if (event.type == EVENT_MOTIONNOTIFY)
-         {
-           if (!PointerInWindow(window))
-             continue; /* window and pointer are on different screens */
-
-           if (!button_status)
-             continue;
-
-           motion_status = TRUE;
-           mx = ((MotionEvent *) &event)->x;
-           my = ((MotionEvent *) &event)->y;
-         }
-         else
+         case EVENT_BUTTONPRESS:
+         case EVENT_BUTTONRELEASE:
+         case EVENT_MOTIONNOTIFY:
          {
-           motion_status = FALSE;
-           mx = ((ButtonEvent *) &event)->x;
-           my = ((ButtonEvent *) &event)->y;
-           if (event.type == EVENT_BUTTONPRESS)
-             button_status = ((ButtonEvent *) &event)->button;
+           if (event.type == EVENT_MOTIONNOTIFY)
+           {
+             if (!PointerInWindow(window))
+               continue;       /* window and pointer on different screens */
+
+             if (!button_status)
+               continue;
+
+             motion_status = TRUE;
+             mx = ((MotionEvent *) &event)->x;
+             my = ((MotionEvent *) &event)->y;
+           }
            else
-             button_status = MB_RELEASED;
-         }
-
-         /* this sets 'request_gadget_id' */
-         HandleGadgets(mx, my, button_status);
-
-         switch (request_gadget_id)
-         {
-           case TOOL_CTRL_ID_YES:
-             result = TRUE;
-             break;
-           case TOOL_CTRL_ID_NO:
-             result = FALSE;
-             break;
-           case TOOL_CTRL_ID_CONFIRM:
-             result = TRUE | FALSE;
-             break;
-
-           case TOOL_CTRL_ID_PLAYER_1:
-             result = 1;
-             break;
-           case TOOL_CTRL_ID_PLAYER_2:
-             result = 2;
-             break;
-           case TOOL_CTRL_ID_PLAYER_3:
-             result = 3;
-             break;
-           case TOOL_CTRL_ID_PLAYER_4:
-             result = 4;
-             break;
-
-           default:
-             break;
+           {
+             motion_status = FALSE;
+             mx = ((ButtonEvent *) &event)->x;
+             my = ((ButtonEvent *) &event)->y;
+             if (event.type == EVENT_BUTTONPRESS)
+               button_status = ((ButtonEvent *) &event)->button;
+             else
+               button_status = MB_RELEASED;
+           }
+
+           /* this sets 'request_gadget_id' */
+           HandleGadgets(mx, my, button_status);
+
+           switch (request_gadget_id)
+           {
+             case TOOL_CTRL_ID_YES:
+               result = TRUE;
+               break;
+             case TOOL_CTRL_ID_NO:
+               result = FALSE;
+               break;
+             case TOOL_CTRL_ID_CONFIRM:
+               result = TRUE | FALSE;
+               break;
+
+             case TOOL_CTRL_ID_PLAYER_1:
+               result = 1;
+               break;
+             case TOOL_CTRL_ID_PLAYER_2:
+               result = 2;
+               break;
+             case TOOL_CTRL_ID_PLAYER_3:
+               result = 3;
+               break;
+             case TOOL_CTRL_ID_PLAYER_4:
+               result = 4;
+               break;
+
+             default:
+               break;
+           }
+
+           break;
          }
 
-         break;
-       }
-
-       case EVENT_KEYPRESS:
-         switch (GetEventKey((KeyEvent *)&event, TRUE))
-         {
-           case KSYM_space:
-             if (req_state & REQ_CONFIRM)
-               result = 1;
-             break;
+         case EVENT_KEYPRESS:
+           switch (GetEventKey((KeyEvent *)&event, TRUE))
+           {
+             case KSYM_space:
+               if (req_state & REQ_CONFIRM)
+                 result = 1;
+               break;
 
-           case KSYM_Return:
+             case KSYM_Return:
 #if defined(TARGET_SDL2)
-           case KSYM_Menu:
+             case KSYM_Menu:
 #endif
-             result = 1;
-             break;
+               result = 1;
+               break;
 
-           case KSYM_Escape:
+             case KSYM_Escape:
 #if defined(TARGET_SDL2)
-           case KSYM_Back:
+             case KSYM_Back:
 #endif
-             result = 0;
-             break;
+               result = 0;
+               break;
 
-           default:
-             break;
-         }
+             default:
+               break;
+           }
 
-         if (req_state & REQ_PLAYER)
-           result = 0;
-         break;
+           if (req_state & REQ_PLAYER)
+             result = 0;
+           break;
 
-       case EVENT_KEYRELEASE:
-         ClearPlayerAction();
-         break;
+         case EVENT_KEYRELEASE:
+           ClearPlayerAction();
+           break;
 
-       default:
-         HandleOtherEvents(&event);
-         break;
+         default:
+           HandleOtherEvents(&event);
+           break;
+       }
       }
     }
     else if (AnyJoystickButton() == JOY_BUTTON_NEW_PRESSED)