Author: cazfi
Date: Sun Feb  8 07:39:37 2015
New Revision: 28033

URL: http://svn.gna.org/viewcvs/freeciv?rev=28033&view=rev
Log:
Register event for freeciv specific messages in sdl2-client.

See patch #5787

Modified:
    trunk/client/gui-sdl2/gui_main.c

Modified: trunk/client/gui-sdl2/gui_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl2/gui_main.c?rev=28033&r1=28032&r2=28033&view=diff
==============================================================================
--- trunk/client/gui-sdl2/gui_main.c    (original)
+++ trunk/client/gui-sdl2/gui_main.c    Sun Feb  8 07:39:37 2015
@@ -123,6 +123,8 @@
 static void parse_options(int argc, char **argv);
 static int check_scroll_area(int x, int y);
 
+int user_event_type;
+
 enum USER_EVENT_ID {
   EVENT_ERROR = 0,
   NET,
@@ -479,7 +481,7 @@
 {
   SDL_Event Event;
 
-  Event.type = SDL_USEREVENT;
+  Event.type = user_event_type;
   Event.user.code = EXIT_FROM_EVENT_LOOP;
   Event.user.data1 = NULL;
   Event.user.data2 = NULL;
@@ -605,11 +607,45 @@
 
     while (SDL_PollEvent(&Main.event) == 1) {
 
-      switch (Main.event.type) {
+      if (Main.event.type == user_event_type) {
+        switch(Main.event.user.code) {
+        case NET:
+          input_from_server(net_socket);
+          break;
+        case ANIM:
+          update_button_hold_state();
+          animate_mouse_cursor();
+          draw_mouse_cursor();
+          break;
+        case SHOW_WIDGET_INFO_LABEL:
+          draw_widget_info_label();
+          break;
+        case TRY_AUTO_CONNECT:
+          if (try_to_autoconnect()) {
+            pInfo_User_Event->user.code = SHOW_WIDGET_INFO_LABEL;
+            autoconnect = FALSE;
+          }
+          break;
+        case FLUSH:
+          unqueue_flush();
+          break;
+        case MAP_SCROLL:
+          scroll_mapview(scroll_dir);
+          break;
+        case EXIT_FROM_EVENT_LOOP:
+          return MAX_ID;
+          break;
+        default:
+          break;
+        }
+
+      } else {
+
+        switch (Main.event.type) {
 
         case SDL_QUIT:
           return MAX_ID;
-        break;
+          break;
 
         case SDL_KEYUP:
           switch (Main.event.key.keysym.sym) {
@@ -678,65 +714,32 @@
               }
             break;
           }
-        break;
+          break;
 
         case SDL_TEXTINPUT:
           if (textinput_handler) {
             ID = textinput_handler(Main.event.text.text, pData);
           }
-        break;
+          break;
 
         case SDL_MOUSEBUTTONDOWN:
           if (mouse_button_down_handler) {
             ID = mouse_button_down_handler(&Main.event.button, pData);
           }
-        break;
+          break;
 
         case SDL_MOUSEBUTTONUP:
           if (mouse_button_up_handler) {
             ID = mouse_button_up_handler(&Main.event.button, pData);
           }
-        break;
+          break;
 
         case SDL_MOUSEMOTION:
           if (mouse_motion_handler) {
             ID = mouse_motion_handler(&Main.event.motion, pData);
           }    
-        break;
-
-        case SDL_USEREVENT:
-          switch(Main.event.user.code) {
-            case NET:
-              input_from_server(net_socket);
-            break;
-            case ANIM:
-              update_button_hold_state();
-              animate_mouse_cursor();
-              draw_mouse_cursor();
-            break;
-            case SHOW_WIDGET_INFO_LABEL:
-              draw_widget_info_label();
-            break;
-            case TRY_AUTO_CONNECT:
-              if (try_to_autoconnect()) {
-                pInfo_User_Event->user.code = SHOW_WIDGET_INFO_LABEL;
-                autoconnect = FALSE;
-              }
-            break;
-            case FLUSH:
-              unqueue_flush();
-            break;
-            case MAP_SCROLL:
-                scroll_mapview(scroll_dir);
-            break;
-            case EXIT_FROM_EVENT_LOOP:
-              return MAX_ID;
-            break;
-            default:
-            break;
-          }
-        break;
-
+          break;
+        }
       }
     }
 
@@ -914,31 +917,38 @@
   log_normal(_("Using Video Output: %s"), SDL_GetCurrentVideoDriver());
   set_video_mode(options.gui_sdl2_screen.width, 
options.gui_sdl2_screen.height, flags);
 
-  __Net_User_Event.type = SDL_USEREVENT;
+  user_event_type = SDL_RegisterEvents(1);
+
+  SDL_zero(__Net_User_Event);
+  __Net_User_Event.type = user_event_type;
   __Net_User_Event.user.code = NET;
   __Net_User_Event.user.data1 = NULL;
   __Net_User_Event.user.data2 = NULL;
   pNet_User_Event = &__Net_User_Event;
 
-  __Anim_User_Event.type = SDL_USEREVENT;
+  SDL_zero(__Anim_User_Event);
+  __Anim_User_Event.type = user_event_type;
   __Anim_User_Event.user.code = EVENT_ERROR;
   __Anim_User_Event.user.data1 = NULL;
   __Anim_User_Event.user.data2 = NULL;
   pAnim_User_Event = &__Anim_User_Event;
 
-  __Info_User_Event.type = SDL_USEREVENT;
+  SDL_zero(__Info_User_Event);
+  __Info_User_Event.type = user_event_type;
   __Info_User_Event.user.code = SHOW_WIDGET_INFO_LABEL;
   __Info_User_Event.user.data1 = NULL;
   __Info_User_Event.user.data2 = NULL;
   pInfo_User_Event = &__Info_User_Event;
 
-  __Flush_User_Event.type = SDL_USEREVENT;
+  SDL_zero(__Flush_User_Event);
+  __Flush_User_Event.type = user_event_type;
   __Flush_User_Event.user.code = FLUSH;
   __Flush_User_Event.user.data1 = NULL;
   __Flush_User_Event.user.data2 = NULL;
   flush_event = &__Flush_User_Event;
 
-  __pMap_Scroll_User_Event.type = SDL_USEREVENT;
+  SDL_zero(__pMap_Scroll_User_Event);
+  __pMap_Scroll_User_Event.type = user_event_type;
   __pMap_Scroll_User_Event.user.code = MAP_SCROLL;
   __pMap_Scroll_User_Event.user.data1 = NULL;
   __pMap_Scroll_User_Event.user.data2 = NULL;


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to