DEADSOFTWARE

Little changes in alt vkbd layout
[d2df-sdl.git] / src / game / g_touch.pas
index 52167bd57b0b8f099ef43732fc0a0f9171071a33..9256fb8e79411f362c9873beeb7dc11114c49086 100644 (file)
@@ -21,6 +21,12 @@ interface
   uses
     SDL2;
 
+  var
+    g_touch_size: Single = 1.0;
+    g_touch_offset: Single = 50;
+    g_touch_fire: Boolean = True;
+
+  procedure g_Touch_Init;
   procedure g_Touch_ShowKeyboard(yes: Boolean);
   procedure g_Touch_HandleEvent(const ev: TSDL_TouchFingerEvent);
   procedure g_Touch_Draw;
@@ -33,9 +39,8 @@ implementation
 
   var
     jab: Boolean;
-    size: Single;
     enabled: Boolean;
-    angleFireEnabled, angleFire: Boolean;
+    angleFire: Boolean;
     keyFinger: array [VK_FIRSTKEY..VK_LASTKEY] of Integer;
 
   procedure GetKeyRect(key: Word; out x, y, w, h: Integer; out founded: Boolean);
@@ -47,31 +52,32 @@ implementation
       dpi := 96;
 
     founded := true;
-    sz := Trunc(size * dpi);
+    sz := Trunc(g_touch_size * dpi);
     sw := gScreenWidth; sh := gScreenHeight;
     if jab 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 - w - 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
@@ -80,21 +86,21 @@ implementation
     end
     else
     begin
-      x := 0; y := 0; w := sz; h := sz;
+      x := 0; y := Round(sh * g_touch_offset / 100); w := sz; h := sz;
       case key of
-        VK_LSTRAFE: begin x := 0;            y := sh div 2 - h div 2; w := w div 2 end;
-        VK_LEFT:    begin x := w div 2;      y := sh div 2 - h div 2 end;
-        VK_RIGHT:   begin x := w div 2 + 1*w;y := sh div 2 - h div 2 end;
-        VK_RSTRAFE: begin x := w div 2 + 2*w;y := sh div 2 - h div 2; w := w div 2 end;
-        VK_UP:      begin x := sw - w - 1;   y := sh div 2 - h div 2 - h end;
-        VK_FIRE:    begin x := sw - 1*w - 1; y := sh div 2 - h div 2 end;
-        VK_DOWN:    begin x := sw - w - 1;   y := sh div 2 - h div 2 + h end;
-        VK_NEXT:    begin x := sw - 2*w - 1; y := sh div 2 - h div 2 - h end;
-        VK_JUMP:    begin x := sw - 2*w - 1; y := sh div 2 - h div 2 end;
-        VK_PREV:    begin x := sw - 3*w - 1; y := sh div 2 - h div 2 - h end;
-        VK_OPEN:    begin x := sw - 3*w - 1; y := sh div 2 - h div 2 end;
+        VK_LSTRAFE: begin x := 0;             y := y - h div 2; w := w div 2 end;
+        VK_LEFT:    begin x := w div 2;       y := y - h div 2 end;
+        VK_RIGHT:   begin x := w div 2 + 1*w; y := y - h div 2 end;
+        VK_RSTRAFE: begin x := w div 2 + 2*w; y := y - h div 2; w := w div 2 end;
+        VK_UP:      begin x := sw - w - 1;    y := y - h div 2 - h end;
+        VK_FIRE:    begin x := sw - 1*w - 1;  y := y - h div 2 end;
+        VK_DOWN:    begin x := sw - w - 1;    y := y - h div 2 + h end;
+        VK_NEXT:    begin x := sw - 2*w - 1;  y := y - h div 2 - h end;
+        VK_JUMP:    begin x := sw - 2*w - 1;  y := y - h div 2 end;
+        VK_PREV:    begin x := sw - 3*w - 1;  y := y - h div 2 - h end;
+        VK_OPEN:    begin x := sw - 3*w - 1;  y := y - h div 2 end;
       else
-        w := sz div 2; h := sz div 2;
+        x := 0; y := 0; w := sz div 2; h := sz div 2;
         case key of
           VK_0:       begin x := sw div 2 - w div 2 - 5*w - 1; y := sh - 1*h - 1 end;
           VK_1:       begin x := sw div 2 - w div 2 - 4*w - 1; y := sh - 1*h - 1 end;
@@ -176,6 +182,13 @@ implementation
     result := founded and (xx >= x) and (yy >= y) and (xx <= x + w) and (yy <= y + h);
   end;
 
+  procedure g_Touch_Init;
+  begin
+{$IFNDEF HEADLESS}
+    enabled := SDL_GetNumTouchDevices() > 0
+{$ENDIF}
+  end;
+
   procedure g_Touch_ShowKeyboard(yes: Boolean);
   begin
 {$IFNDEF HEADLESS}
@@ -228,7 +241,7 @@ implementation
     end;
 
     (* emulate up+fire / donw+fire *)
-    if angleFireEnabled and (gGameSettings.GameType <> GT_NONE) then
+    if g_touch_fire and (gGameSettings.GameType <> GT_NONE) then
     begin
       if keyFinger[VK_UP] <> 0 then
       begin
@@ -303,15 +316,9 @@ implementation
   end;
 
 initialization
-{$IFDEF ANDROID}
-  enabled := true;
-{$ENDIF}
-  size := 1;
-  angleFire := true;
   conRegVar('touch_enable', @enabled, 'enable/disable virtual buttons', 'draw buttons');
-  conRegVar('touch_anglefire', @angleFireEnabled, 'enable/disable fire when press virtual up/down', 'fire when press up/down');
-  conRegVar('touch_size', @size, 0.1, 10, 'size of virtual buttons', 'button size');
+  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');
 end.
-
-