DEADSOFTWARE

fix question char
[d2df-sdl.git] / src / game / sdl2 / g_system.pas
index 3e55f4510c99f411bfb28ad649ea34f97b278bc6..f46c3278669f208ae7258eef957b5caab3991d89 100644 (file)
@@ -24,7 +24,7 @@ interface
   procedure sys_Delay (ms: Integer);
 
   (* --- Graphics --- *)
-  function sys_GetDispalyModes (bpp: Integer): SSArray;
+  function sys_GetDisplayModes (bpp: Integer): SSArray;
   function sys_SetDisplayMode (w, h, bpp: Integer; fullscreen: Boolean): Boolean;
   procedure sys_EnableVSync (yes: Boolean);
   procedure sys_Repaint;
@@ -42,6 +42,7 @@ implementation
   uses
     SysUtils, SDL2, Math,
     e_log, e_graphics, e_input, e_sound,
+    {$INCLUDE ../nogl/noGLuses.inc}
     {$IFDEF ENABLE_HOLMES}
       g_holmes, sdlcarcass, fui_ctls,
     {$ENDIF}
@@ -87,7 +88,10 @@ implementation
     e_ResizeWindow(w, h);
     e_InitGL;
     g_Game_SetupScreenSize;
-    g_Menu_Reset;
+    {$IFNDEF ANDOIRD}
+      (* This will fix menu reset on keyboard showing *)
+      g_Menu_Reset;
+    {$ENDIF}
     g_Game_ClearLoading;
     {$IFDEF ENABLE_HOLMES}
       if assigned(oglInitCB) then oglInitCB;
@@ -124,6 +128,9 @@ implementation
         context := SDL_GL_CreateContext(window);
         if context <> nil then
         begin
+          {$IFDEF NOGL_INIT}
+            nogl_Init;
+          {$ENDIF}
           UpdateSize(w, h);
           result := true
         end
@@ -160,7 +167,7 @@ implementation
       SDL_GL_SetSwapInterval(0)
   end;
 
-  function sys_GetDispalyModes (bpp: Integer): SSArray;
+  function sys_GetDisplayModes (bpp: Integer): SSArray;
     var i, count, num, pw, ph: Integer; m: TSDL_DisplayMode;
   begin
     result := nil;
@@ -401,20 +408,19 @@ implementation
   procedure HandleTextInput (var ev: TSDL_TextInputEvent);
     var ch: UnicodeChar; sch: AnsiChar;
   begin
-    if g_dbg_input then
-      e_LogWritefln('Input Debug: text, text=%s', [ev.text]);
     Utf8ToUnicode(@ch, PChar(ev.text), 1);
-    if IsValid1251(Word(ch)) then
-    begin
-      sch := AnsiChar(wchar2win(ch));
+    sch := AnsiChar(wchar2win(ch));
+    if g_dbg_input then
+      e_LogWritefln('Input Debug: text, text="%s", ch = %s, sch = %s', [ev.text, Ord(ch), Ord(sch)]);
+    if IsValid1251(Word(ch)) and IsPrintable1251(ch) then
       CharPress(sch);
-    end;
   end;
 
   function sys_HandleInput (): Boolean;
     var ev: TSDL_Event;
   begin
     result := false;
+    ZeroMemory(@ev, sizeof(ev));
     while SDL_PollEvent(@ev) <> 0 do
     begin
       case ev.type_ of
@@ -445,7 +451,7 @@ implementation
   (* --------- Init --------- *)
 
   procedure sys_Init;
-    var flags: UInt32; ok: Boolean;
+    var flags: UInt32;
   begin
     e_WriteLog('Init SDL2', TMsgType.Notify);
     {$IFDEF HEADLESS}
@@ -460,9 +466,6 @@ implementation
     SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, '0');
     if SDL_Init(flags) <> 0 then
       raise Exception.Create('SDL: Init failed: ' + SDL_GetError);
-    ok := InitWindow(gScreenWidth, gScreenHeight, gBPP, gFullscreen);
-    if not ok then
-      raise Exception.Create('SDL: Failed to set videomode: ' + SDL_GetError);
     SDL_ShowCursor(SDL_DISABLE);
   end;
 
@@ -470,11 +473,18 @@ implementation
   begin
     e_WriteLog('Releasing SDL2', TMsgType.Notify);
     if context <> nil then
+    begin
+      {$IFDEF NOGL_INIT}
+        nogl_Quit;
+      {$ENDIF}
       SDL_GL_DeleteContext(context);
+      context := nil;
+    end;
     if window <> nil then
+    begin
       SDL_DestroyWindow(window);
-    window := nil;
-    context := nil;
+      window := nil;
+    end;
     SDL_Quit
   end;