All I want is to receive some events... sdl2transition
authorunc0rr
Sun, 10 Nov 2013 01:45:43 +0400
branchsdl2transition
changeset 9697 198c3ed28fe8
parent 9694 e8d0fe885169
child 9699 fab319c85a39
All I want is to receive some events...
hedgewars/SDLh.pas
hedgewars/hwengine.pas
hedgewars/uChat.pas
--- a/hedgewars/SDLh.pas	Fri Nov 08 17:53:02 2013 +0400
+++ b/hedgewars/SDLh.pas	Sun Nov 10 01:45:43 2013 +0400
@@ -139,6 +139,9 @@
 
 
 {$IFDEF SDL2}
+    SDL_TEXTEDITINGEVENT_TEXT_SIZE = 32;
+    SDL_TEXTINPUTEVENT_TEXT_SIZE   = 32;
+
     // SDL_Event types
     // pascal does not support unions as is, so we list here every possible event
     // and later associate a struct type each
@@ -543,21 +546,20 @@
         data1, data2: LongInt;
         end;
 
-    // available in sdl12 but not exposed
     TSDL_TextEditingEvent = record
-        type_: LongWord;
-        timestamp: LongWord;
-        windowID: LongWord;
-        text: array[0..31] of Byte;
-        start, lenght: LongInt;
+        type_: Longword;
+        timestamp: Longword;
+        windowID: Longword;
+        text: array [0..SDL_TEXTEDITINGEVENT_TEXT_SIZE - 1] of char;
+        start: LongInt;
+        length: LongInt;
         end;
 
-    // available in sdl12 but not exposed
     TSDL_TextInputEvent = record
-        type_: LongWord;
-        timestamp: LongWord;
-        windowID: LongWord;
-        text: array[0..31] of Byte;
+        type_: Longword;
+        timestamp: Longword;
+        windowID: Longword;
+        text: array [0..SDL_TEXTINPUTEVENT_TEXT_SIZE - 1] of char;
         end;
 
     TSDL_TouchFingerEvent = record
@@ -796,7 +798,7 @@
             SDL_KEYDOWN,
             SDL_KEYUP: (key: TSDL_KeyboardEvent);
             SDL_TEXTEDITING: (edit: TSDL_TextEditingEvent);
-            SDL_TEXTINPUT: (tedit: TSDL_TextInputEvent);
+            SDL_TEXTINPUT: (text: TSDL_TextInputEvent);
             SDL_MOUSEMOTION: (motion: TSDL_MouseMotionEvent);
             SDL_MOUSEBUTTONDOWN,
             SDL_MOUSEBUTTONUP: (button: TSDL_MouseButtonEvent);
@@ -1031,6 +1033,7 @@
 procedure SDL_WarpMouseInWindow(window: PSDL_Window; x, y: LongInt); cdecl; external SDLLibName;
 function  SDL_SetHint(name, value: PChar): Boolean; cdecl; external SDLLibName;
 procedure SDL_StartTextInput; cdecl; external SDLLibName;
+procedure SDL_StopTextInput; cdecl; external SDLLibName;
 
 function  SDL_PeepEvents(event: PSDL_Event; numevents: LongInt; action: TSDL_eventaction; minType, maxType: LongWord): LongInt; cdecl; external SDLLibName;
 
--- a/hedgewars/hwengine.pas	Fri Nov 08 17:53:02 2013 +0400
+++ b/hedgewars/hwengine.pas	Sun Nov 10 01:45:43 2013 +0400
@@ -154,13 +154,8 @@
             case event.type_ of
 {$IFDEF SDL2}
                 SDL_KEYDOWN:
-                    if GameState = gsChat then
-                        begin
-                    // sdl on iphone supports only ashii keyboards and the unicode field is deprecated in sdl 1.3
-                        KeyPressChat(SDL_GetKeyFromScancode(event.key.keysym.sym), event.key.keysym.sym); //TODO correct for keymodifiers
-                        end
-                    else
-                        if GameState >= gsGame then ProcessKey(event.key);
+                    if (GameState <> gsChat) and (GameState >= gsGame) then
+                        ProcessKey(event.key);
                 SDL_KEYUP:
                     if (GameState <> gsChat) and (GameState >= gsGame) then
                         ProcessKey(event.key);
@@ -177,6 +172,9 @@
                 SDL_MOUSEWHEEL:
                     ProcessMouseWheel(event.wheel.x, event.wheel.y);
 
+                SDL_TEXTINPUT: AddFileLog('[Text input] ' + event.text.text);
+                SDL_TEXTEDITING: AddFileLog('[Text edit] ''' + event.edit.text + ''' ' + inttostr(event.edit.start) + ' ' + inttostr(event.edit.length));
+
                 SDL_WINDOWEVENT:
                     if event.window.event = SDL_WINDOWEVENT_SHOWN then
                     begin
@@ -352,7 +350,7 @@
     WriteLnToConsole(msgOK);
 
 {$IFDEF SDL2}
-    SDL_StartTextInput();
+    //SDL_StartTextInput();
 {$ELSE}
     SDL_EnableUNICODE(1);
 {$ENDIF}
--- a/hedgewars/uChat.pas	Fri Nov 08 17:53:02 2013 +0400
+++ b/hedgewars/uChat.pas	Sun Nov 10 01:45:43 2013 +0400
@@ -306,7 +306,9 @@
 begin
     FreezeEnterKey;
     history:= 0;
-{$IFNDEF SDL2}
+{$IFDEF SDL2}
+    SDL_StopTextInput();
+{$ELSE}
     SDL_EnableKeyRepeat(0,0);
 {$ENDIF}
     GameState:= gsGame;
@@ -431,7 +433,9 @@
 begin
     s:= s; // avoid compiler hint
     GameState:= gsChat;
-{$IFNDEF SDL2}
+{$IFDEF SDL2}
+    SDL_StartTextInput();
+{$ELSE}
     SDL_EnableKeyRepeat(200,45);
 {$ENDIF}
     if length(s) = 0 then