Author: cazfi
Date: Fri Jan  9 05:43:26 2015
New Revision: 27584

URL: http://svn.gna.org/viewcvs/freeciv?rev=27584&view=rev
Log:
Handle SDL_TEXTINPUT for sdl2-client edit widgets.

See patch #4766

Modified:
    trunk/client/gui-sdl2/cma_fe.c
    trunk/client/gui-sdl2/gui_main.c
    trunk/client/gui-sdl2/gui_main.h
    trunk/client/gui-sdl2/repodlgs.c
    trunk/client/gui-sdl2/widget_edit.c
    trunk/client/gui-sdl2/widget_scrollbar.c
    trunk/client/gui-sdl2/widget_window.c

Modified: trunk/client/gui-sdl2/cma_fe.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl2/cma_fe.c?rev=27584&r1=27583&r2=27584&view=diff
==============================================================================
--- trunk/client/gui-sdl2/cma_fe.c      (original)
+++ trunk/client/gui-sdl2/cma_fe.c      Fri Jan  9 05:43:26 2015
@@ -162,7 +162,7 @@
     MOVE_STEP_Y = 0;
     /* Filter mouse motion events */
     SDL_SetEventFilter(FilterMouseMotionEvents, NULL);
-    gui_event_loop((void *)(&pMotion), NULL, NULL, NULL, NULL,
+    gui_event_loop((void *)(&pMotion), NULL, NULL, NULL, NULL, NULL,
                    scroll_mouse_button_up, scroll_mouse_motion_handler);
     /* Turn off Filter mouse motion events */
     SDL_SetEventFilter(NULL, NULL);
@@ -201,7 +201,7 @@
     MOVE_STEP_Y = 0;
     /* Filter mouse motion events */
     SDL_SetEventFilter(FilterMouseMotionEvents, NULL);
-    gui_event_loop((void *)(&pMotion), NULL, NULL, NULL, NULL,
+    gui_event_loop((void *)(&pMotion), NULL, NULL, NULL, NULL, NULL,
                    scroll_mouse_button_up, scroll_mouse_motion_handler);
     /* Turn off Filter mouse motion events */
     SDL_SetEventFilter(NULL, NULL);

Modified: trunk/client/gui-sdl2/gui_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl2/gui_main.c?rev=27584&r1=27583&r2=27584&view=diff
==============================================================================
--- trunk/client/gui-sdl2/gui_main.c    (original)
+++ trunk/client/gui-sdl2/gui_main.c    Fri Jan  9 05:43:26 2015
@@ -512,12 +512,16 @@
   SDL2-client main loop.
 **************************************************************************/
 Uint16 gui_event_loop(void *pData,
-       void (*loop_action)(void *pData),
-       Uint16 (*key_down_handler)(SDL_Keysym Key, void *pData),
-       Uint16 (*key_up_handler)(SDL_Keysym Key, void *pData),
-       Uint16 (*mouse_button_down_handler)(SDL_MouseButtonEvent *pButtonEvent, 
void *pData),
-       Uint16 (*mouse_button_up_handler)(SDL_MouseButtonEvent *pButtonEvent, 
void *pData),
-       Uint16 (*mouse_motion_handler)(SDL_MouseMotionEvent *pMotionEvent, void 
*pData))
+                      void (*loop_action)(void *pData),
+                      Uint16 (*key_down_handler)(SDL_Keysym Key, void *pData),
+                      Uint16 (*key_up_handler)(SDL_Keysym Key, void *pData),
+                      Uint16 (*textinput_handler)(char *text, void *pData),
+                      Uint16 (*mouse_button_down_handler)(SDL_MouseButtonEvent 
*pButtonEvent,
+                                                          void *pData),
+                      Uint16 (*mouse_button_up_handler)(SDL_MouseButtonEvent 
*pButtonEvent,
+                                                        void *pData),
+                      Uint16 (*mouse_motion_handler)(SDL_MouseMotionEvent 
*pMotionEvent,
+                                                     void *pData))
 {
   Uint16 ID;
   static struct timeval tv;
@@ -676,6 +680,12 @@
           }
         break;
 
+        case SDL_TEXTINPUT:
+          if (textinput_handler) {
+            ID = textinput_handler(Main.event.text.text, pData);
+          }
+        break;
+
         case SDL_MOUSEBUTTONDOWN:
           if (mouse_button_down_handler) {
             ID = mouse_button_down_handler(&Main.event.button, pData);
@@ -963,7 +973,7 @@
   set_client_state(C_S_DISCONNECTED);
 
   /* Main game loop */
-  gui_event_loop(NULL, NULL, main_key_down_handler, main_key_up_handler,
+  gui_event_loop(NULL, NULL, main_key_down_handler, main_key_up_handler, NULL,
                  main_mouse_button_down_handler, main_mouse_button_up_handler,
                  main_mouse_motion_handler);
 }

Modified: trunk/client/gui-sdl2/gui_main.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl2/gui_main.h?rev=27584&r1=27583&r2=27584&view=diff
==============================================================================
--- trunk/client/gui-sdl2/gui_main.h    (original)
+++ trunk/client/gui-sdl2/gui_main.h    Fri Jan  9 05:43:26 2015
@@ -92,11 +92,15 @@
 int FilterMouseMotionEvents(void *data, SDL_Event *event);
 
 Uint16 gui_event_loop(void *pData, void (*loop_action)(void *pData),
-       Uint16 (*key_down_handler)(SDL_Keysym Key, void *pData),
-        Uint16 (*key_up_handler)(SDL_Keysym Key, void *pData),
-       Uint16 (*mouse_button_down_handler)(SDL_MouseButtonEvent *pButtonEvent, 
void *pData),
-        Uint16 (*mouse_button_up_handler)(SDL_MouseButtonEvent *pButtonEvent, 
void *pData),
-        Uint16 (*mouse_motion_handler)(SDL_MouseMotionEvent *pMotionEvent, 
void *pData));
+                      Uint16 (*key_down_handler)(SDL_Keysym Key, void *pData),
+                      Uint16 (*key_up_handler)(SDL_Keysym Key, void *pData),
+                      Uint16 (*textinput_handler)(char *text, void *pData),
+                      Uint16 (*mouse_button_down_handler)(SDL_MouseButtonEvent 
*pButtonEvent,
+                                                          void *pData),
+                      Uint16 (*mouse_button_up_handler)(SDL_MouseButtonEvent 
*pButtonEvent,
+                                                        void *pData),
+                      Uint16 (*mouse_motion_handler)(SDL_MouseMotionEvent 
*pMotionEvent,
+                                                     void *pData));
 
 /* shrink sizes for 320x240 screen */
 #ifdef SMALL_SCREEN

Modified: trunk/client/gui-sdl2/repodlgs.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl2/repodlgs.c?rev=27584&r1=27583&r2=27584&view=diff
==============================================================================
--- trunk/client/gui-sdl2/repodlgs.c    (original)
+++ trunk/client/gui-sdl2/repodlgs.c    Fri Jan  9 05:43:26 2015
@@ -1337,7 +1337,7 @@
     MOVE_STEP_Y = 0;
     /* Filter mouse motion events */
     SDL_SetEventFilter(FilterMouseMotionEvents, NULL);
-    gui_event_loop((void *)(&pMotion), NULL, NULL, NULL, NULL,
+    gui_event_loop((void *)(&pMotion), NULL, NULL, NULL, NULL, NULL,
                    report_scroll_mouse_button_up,
                    report_scroll_mouse_motion_handler);
     /* Turn off Filter mouse motion events */

Modified: trunk/client/gui-sdl2/widget_edit.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl2/widget_edit.c?rev=27584&r1=27583&r2=27584&view=diff
==============================================================================
--- trunk/client/gui-sdl2/widget_edit.c (original)
+++ trunk/client/gui-sdl2/widget_edit.c Fri Jan  9 05:43:26 2015
@@ -552,64 +552,73 @@
       }
     }
     break;
-    default:
-    {
-
-      /* add new element of chain (and move cursor right) */
-      if (pEdt->pInputChain != pEdt->pBeginTextChain) {
-        pInputChain_TMP = pEdt->pInputChain->prev;
-        pEdt->pInputChain->prev = fc_calloc(1, sizeof(struct UniChar));
-        pEdt->pInputChain->prev->next = pEdt->pInputChain;
-        pEdt->pInputChain->prev->prev = pInputChain_TMP;
-        pInputChain_TMP->next = pEdt->pInputChain->prev;
-      } else {
-        pEdt->pInputChain->prev = fc_calloc(1, sizeof(struct UniChar));
-        pEdt->pInputChain->prev->next = pEdt->pInputChain;
-        pEdt->pBeginTextChain = pEdt->pInputChain->prev;
-      }
-
-      if (LSHIFT || RSHIFT) {
-        pEdt->pInputChain->prev->chr[0] = toupper(key.sym);
-      } else {
-        pEdt->pInputChain->prev->chr[0] = key.sym;
-      }
-      pEdt->pInputChain->prev->chr[1] = '\0';
-
-      if (pEdt->pInputChain->prev->chr) {
-        if (get_wflags(pEdt->pWidget) & WF_PASSWD_EDIT) {
-          Uint16 passwd_chr[2] = {'*', '\0'};
-
-          pEdt->pInputChain->prev->pTsurf =
-            TTF_RenderUNICODE_Blended(pEdt->pWidget->string16->font,
-                                      passwd_chr,
-                                      pEdt->pWidget->string16->fgcol);
-        } else {
-          pEdt->pInputChain->prev->pTsurf =
-            TTF_RenderUNICODE_Blended(pEdt->pWidget->string16->font,
-                                      pEdt->pInputChain->prev->chr,
-                                      pEdt->pWidget->string16->fgcol);
-        }
-        pEdt->Truelength += pEdt->pInputChain->prev->pTsurf->w;
-      }
-
-      if (pEdt->InputChain_X >= pEdt->pWidget->size.x + pEdt->pBg->w - 
adj_size(10)) {
-        if (pEdt->pInputChain == pEdt->pEndTextChain) {
-          pEdt->Start_X = pEdt->pBg->w - adj_size(5) - pEdt->Truelength;
-        } else {
-          pEdt->Start_X -= pEdt->pInputChain->prev->pTsurf->w -
-            (pEdt->pWidget->size.x + pEdt->pBg->w - adj_size(5) - 
pEdt->InputChain_X);
-        }
-      }
-
-      pEdt->ChainLen++;
-      Redraw = TRUE;
-    }
+  default:
     break;
   } /* key pressed switch */
 
   if (Redraw) {
     redraw_edit_chain(pEdt);
   }
+
+  return ID_ERROR;
+}
+
+/**************************************************************************
+  Handle textinput strings coming to the edit widget
+**************************************************************************/
+static Uint16 edit_textinput(char *text, void *pData)
+{
+  struct EDIT *pEdt = (struct EDIT *)pData;
+  struct UniChar *pInputChain_TMP;
+  int i;
+
+  for (i = 0; text[i] != '\0'; i++) {
+    /* add new element of chain (and move cursor right) */
+    if (pEdt->pInputChain != pEdt->pBeginTextChain) {
+      pInputChain_TMP = pEdt->pInputChain->prev;
+      pEdt->pInputChain->prev = fc_calloc(1, sizeof(struct UniChar));
+      pEdt->pInputChain->prev->next = pEdt->pInputChain;
+      pEdt->pInputChain->prev->prev = pInputChain_TMP;
+      pInputChain_TMP->next = pEdt->pInputChain->prev;
+    } else {
+      pEdt->pInputChain->prev = fc_calloc(1, sizeof(struct UniChar));
+      pEdt->pInputChain->prev->next = pEdt->pInputChain;
+      pEdt->pBeginTextChain = pEdt->pInputChain->prev;
+    }
+
+    pEdt->pInputChain->prev->chr[0] = text[i];
+    pEdt->pInputChain->prev->chr[1] = '\0';
+
+    if (pEdt->pInputChain->prev->chr) {
+      if (get_wflags(pEdt->pWidget) & WF_PASSWD_EDIT) {
+        Uint16 passwd_chr[2] = {'*', '\0'};
+
+        pEdt->pInputChain->prev->pTsurf =
+          TTF_RenderUNICODE_Blended(pEdt->pWidget->string16->font,
+                                    passwd_chr,
+                                    pEdt->pWidget->string16->fgcol);
+      } else {
+        pEdt->pInputChain->prev->pTsurf =
+          TTF_RenderUNICODE_Blended(pEdt->pWidget->string16->font,
+                                    pEdt->pInputChain->prev->chr,
+                                    pEdt->pWidget->string16->fgcol);
+      }
+      pEdt->Truelength += pEdt->pInputChain->prev->pTsurf->w;
+    }
+
+    if (pEdt->InputChain_X >= pEdt->pWidget->size.x + pEdt->pBg->w - 
adj_size(10)) {
+      if (pEdt->pInputChain == pEdt->pEndTextChain) {
+        pEdt->Start_X = pEdt->pBg->w - adj_size(5) - pEdt->Truelength;
+      } else {
+        pEdt->Start_X -= pEdt->pInputChain->prev->pTsurf->w -
+          (pEdt->pWidget->size.x + pEdt->pBg->w - adj_size(5) - 
pEdt->InputChain_X);
+      }
+    }
+
+    pEdt->ChainLen++;
+  }
+
+  redraw_edit_chain(pEdt);
 
   return ID_ERROR;
 }
@@ -720,7 +729,7 @@
   {
     /* local loop */  
     Uint16 rety = gui_event_loop((void *)&pEdt, NULL,
-                                 edit_key_down, NULL,
+                                 edit_key_down, NULL, edit_textinput,
                                  edit_mouse_button_down, NULL, NULL);
 
     if (pEdt.pBeginTextChain == pEdt.pEndTextChain) {

Modified: trunk/client/gui-sdl2/widget_scrollbar.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl2/widget_scrollbar.c?rev=27584&r1=27583&r2=27584&view=diff
==============================================================================
--- trunk/client/gui-sdl2/widget_scrollbar.c    (original)
+++ trunk/client/gui-sdl2/widget_scrollbar.c    Fri Jan  9 05:43:26 2015
@@ -1082,7 +1082,7 @@
   pDown.pVscroll = pVscroll;
 
   gui_event_loop((void *)&pDown, inside_scroll_down_loop,
-                 NULL, NULL, NULL, scroll_mouse_button_up, NULL);
+                 NULL, NULL, NULL, NULL, scroll_mouse_button_up, NULL);
 
   return pDown.pBegin;
 }
@@ -1104,7 +1104,7 @@
   pUp.pVscroll = pVscroll;
 
   gui_event_loop((void *)&pUp, inside_scroll_up_loop,
-                 NULL, NULL, NULL, scroll_mouse_button_up, NULL);
+                 NULL, NULL, NULL, NULL, scroll_mouse_button_up, NULL);
 
   return pUp.pBegin;
 }
@@ -1132,7 +1132,7 @@
   MOVE_STEP_Y = 3;
   /* Filter mouse motion events */
   SDL_SetEventFilter(FilterMouseMotionEvents, NULL);
-  gui_event_loop((void *)&pMotion, NULL, NULL, NULL, NULL,
+  gui_event_loop((void *)&pMotion, NULL, NULL, NULL, NULL, NULL,
                  scroll_mouse_button_up, scroll_mouse_motion_handler);
   /* Turn off Filter mouse motion events */
   SDL_SetEventFilter(NULL, NULL);

Modified: trunk/client/gui-sdl2/widget_window.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl2/widget_window.c?rev=27584&r1=27583&r2=27584&view=diff
==============================================================================
--- trunk/client/gui-sdl2/widget_window.c       (original)
+++ trunk/client/gui-sdl2/widget_window.c       Fri Jan  9 05:43:26 2015
@@ -355,7 +355,7 @@
   SDL_GetMouseState(&pMove.prev_x, &pMove.prev_y);
   /* Filter mouse motion events */
   SDL_SetEventFilter(FilterMouseMotionEvents, NULL);
-  ret = (gui_event_loop((void *)&pMove, NULL, NULL, NULL, NULL,
+  ret = (gui_event_loop((void *)&pMove, NULL, NULL, NULL, NULL, NULL,
          move_window_button_up, move_window_motion) == ID_MOVED_WINDOW);
   /* Turn off Filter mouse motion events */
   SDL_SetEventFilter(NULL, NULL);


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

Reply via email to