DEADSOFTWARE

Added option for alt vkbd layout
[d2df-sdl.git] / src / game / g_touch.pas
index d98d2df6074f17085969945cf8b184f5b2ef11b2..1778eca23bfcbfd96762b2bfbcae92ee79153fba 100644 (file)
@@ -22,9 +22,11 @@ interface
     SDL2;
 
   var
-    g_touch_size: Single = 1.0;
-    g_touch_offset: Single = 50;
-    g_touch_fire: Boolean = True;
+    g_touch_enabled: Boolean;
+    g_touch_size: Single;
+    g_touch_offset: Single;
+    g_touch_fire: Boolean;
+    g_touch_alt: Boolean;
 
   procedure g_Touch_Init;
   procedure g_Touch_ShowKeyboard(yes: Boolean);
@@ -38,8 +40,6 @@ implementation
     e_log, e_graphics, e_input, g_options, g_game, g_main, g_weapons, g_console;
 
   var
-    jab: Boolean;
-    enabled: Boolean;
     angleFire: Boolean;
     keyFinger: array [VK_FIRSTKEY..VK_LASTKEY] of Integer;
 
@@ -54,29 +54,30 @@ implementation
     founded := true;
     sz := Trunc(g_touch_size * dpi);
     sw := gScreenWidth; sh := gScreenHeight;
-    if jab then
+    if g_touch_alt then
     begin
-      w := sz div 2; h := sz div 3;
+      w := sz div 2; h := sz div 2;
       case key of
-        VK_CONSOLE: begin x := 0;                y := 0 end;
-        VK_ESCAPE:  begin x := sw - w - 1;       y := 0 end;
-        VK_CHAT:    begin x := sw div 2 - w - 4; y := 0 end;
-        VK_TEAM:    begin x := sw div 2 + 0 + 4; y := 0 end;
+        VK_CONSOLE: begin x := 0; y := 0 end;
+        VK_ESCAPE:  begin x := sw - w - 1; y := 0 end;
+        VK_CHAT:    begin x := sw div 2 - w div 2 - w; y := 0 end;
+        VK_STATUS:  begin x := sw div 2 - w div 2 + 0; y := 0 end;
+        VK_TEAM:    begin x := sw div 2 - w div 2 + w; y := 0 end;
+        VK_PREV:    begin x := 0; y := sh - 4*sz - 1; w := sz end;
+        VK_NEXT:    begin x := sw - sz - 1; y := sh - 4*sz - 1; w := sz end;
       else
-        w := sz; h := sz * 2;
+        w := sz; h := sz * 3;
         case key of
           VK_LEFT:  begin x := 0; y := sh - h - 1 end;
           VK_RIGHT: begin x := w; y := sh - h - 1 end;
         else
           w := sz; h := sz;
           case key of
-            VK_OPEN: begin h := sz;       x := sw - 1*w - 1; y := sh - 1*h - 1 end;
-            VK_JUMP: begin h := sz;       x := sw - 1*w - 1; y := sh - 2*h - 1 end;
-            VK_UP:   begin h := sz div 2; x := sw - 2*w - 1; y := sh - 2*sz - 1 end;
-            VK_FIRE: begin h := sz;       x := sw - 2*w - 1; y := sh - sz div 2 - sz - 1 end;
-            VK_DOWN: begin h := sz div 2; x := sw - 2*w - 1; y := sh - sz div 2 - 1 end;
-            VK_PREV: begin h := sz div 2; x := 0;            y := sh - 3*sz - 1 end;
-            VK_NEXT: begin h := sz div 2; x := sw - w - 1;   y := sh - 3*sz - 1 end;
+            VK_UP:   begin x := sw - 2*w - 1; y := sh - 3*h - 1 end;
+            VK_FIRE: begin x := sw - 2*w - 1; y := sh - 2*h - 1 end;
+            VK_DOWN: begin x := sw - 2*w - 1; y := sh - 1*h - 1 end;
+            VK_OPEN: begin x := sw - 1*w - 1; y := sh - 1*h - h div 2 - 1 end;
+            VK_JUMP: begin x := sw - 1*w - 1; y := sh - 2*h - h div 2 - 1 end;
           else
             founded := false
           end
@@ -184,14 +185,14 @@ implementation
   procedure g_Touch_Init;
   begin
 {$IFNDEF HEADLESS}
-    enabled := SDL_GetNumTouchDevices() > 0
+    g_touch_enabled := SDL_GetNumTouchDevices() > 0
 {$ENDIF}
   end;
 
   procedure g_Touch_ShowKeyboard(yes: Boolean);
   begin
 {$IFNDEF HEADLESS}
-    if not enabled then
+    if not g_touch_enabled then
       Exit;
 
     if yes then
@@ -205,7 +206,7 @@ implementation
     var
       x, y, i, finger: Integer;
   begin
-    if not enabled then
+    if not g_touch_enabled then
       Exit;
     if SDL_IsTextInputActive() = SDL_True then
       Exit;
@@ -297,7 +298,7 @@ implementation
       founded: Boolean;
   begin
 {$IFNDEF HEADLESS}
-    if not enabled then
+    if not g_touch_enabled then
       Exit;
     if SDL_IsTextInputActive() = SDL_True then
       Exit;
@@ -315,11 +316,9 @@ implementation
   end;
 
 initialization
-  conRegVar('touch_enable', @enabled, 'enable/disable virtual buttons', 'draw buttons');
+  conRegVar('touch_enable', @g_touch_enabled, 'enable/disable virtual buttons', 'draw buttons');
   conRegVar('touch_fire', @g_touch_fire, 'enable/disable fire when press virtual up/down', 'fire when press up/down');
   conRegVar('touch_size', @g_touch_size, 0.1, 10, 'size of virtual buttons', 'button size');
   conRegVar('touch_offset', @g_touch_offset, 0, 100, '', '');
-  conRegVar('touch_alt', @jab, 'althernative virtual buttons layout', 'althernative layout');
+  conRegVar('touch_alt', @g_touch_alt, 'althernative virtual buttons layout', 'althernative layout');
 end.
-
-