DEADSOFTWARE

Corrected aspect for menu background
[d2df-sdl.git] / src / game / g_gui.pas
index 8a599fd7a3a9a0c99c05245216c0f1882937dec6..ef5645962bdc2e0bcdedd2f992979fd0c816f360 100644 (file)
@@ -535,6 +535,7 @@ type
 var
   g_GUIWindows: array of TGUIWindow;
   g_ActiveWindow: TGUIWindow = nil;
+  g_GUIGrabInput: Boolean = False;
 
 procedure g_GUI_Init();
 function  g_GUI_AddWindow(Window: TGUIWindow): TGUIWindow;
@@ -684,14 +685,14 @@ begin
   if len = 0 then
     Exit;
 
-// Îêíî ñ ãëàâíûì ìåíþ:
+// ���� � ������� ����:
   g_GUI_ShowWindow(Saved_Windows[len-1]);
 
-// Íå ïåðåêëþ÷èëîñü (èëè íåêóäà äàëüøå):
+// �� ������������� (��� ������ ������):
   if (len = 1) or (g_ActiveWindow = nil) then
     Exit;
 
-// Èùåì êíîïêè â îñòàëüíûõ îêíàõ:
+// ���� ������ � ��������� �����:
   for k := len-1 downto 1 do
   begin
     ok := False;
@@ -725,7 +726,7 @@ begin
         Break;
     end;
 
-  // Íå ïåðåêëþ÷èëîñü:
+  // �� �������������:
     if (not ok) or
        (g_ActiveWindow.Name = Saved_Windows[k]) then
       Break;
@@ -813,10 +814,19 @@ procedure TGUIWindow.Draw;
 var
   i: Integer;
   ID: DWORD;
+  tw, th: Word;
 begin
-  if FBackTexture <> '' then
+  if FBackTexture <> '' then  // Here goes code duplication from g_game.pas:DrawMenuBackground()
     if g_Texture_Get(FBackTexture, ID) then
-      e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight)
+    begin
+      e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
+      e_GetTextureSize(ID, @tw, @th);
+      if tw = th then
+        tw := round(tw * 1.333 * (gScreenHeight / th))
+      else
+        tw := trunc(tw * (gScreenHeight / th));
+        e_DrawSize(ID, (gScreenWidth - tw) div 2, 0, 0, False, False, tw, gScreenHeight);
+    end
     else
       e_Clear(GL_COLOR_BUFFER_BIT, 0.5, 0.5, 0.5);
 
@@ -837,7 +847,7 @@ begin
   if Msg.Msg = WM_KEYDOWN then
   begin
     case Msg.wParam of
-      IK_ESCAPE, VK_ESCAPE, JOY0_JUMP, JOY1_JUMP, JOY2_JUMP, JOY3_JUMP:
+      VK_ESCAPE:
         begin
           g_GUI_HideWindow;
           Exit
@@ -2335,7 +2345,8 @@ begin
         end;
     end;
 
-  g_Touch_ShowKeyboard(FWindow.FActiveControl = Self);
+  g_GUIGrabInput := (@FOnEnterEvent = nil) and (FWindow.FActiveControl = Self);
+  g_Touch_ShowKeyboard(g_GUIGrabInput)
 end;
 
 procedure TGUIEdit.SetText(Text: string);
@@ -2416,7 +2427,7 @@ begin
     case Msg of
       WM_KEYDOWN:
         case wParam of
-          IK_ESCAPE, VK_ESCAPE, JOY0_JUMP, JOY1_JUMP, JOY2_JUMP, JOY3_JUMP:
+          VK_ESCAPE:
             begin
               if FIsQuery then actDefCtl();
               FIsQuery := False;
@@ -2431,9 +2442,10 @@ begin
 
                   FIsQuery := True;
                 end
-              else
+              else if (wParam < VK_FIRSTKEY) and (wParam > VK_LASTKEY) then
                 begin
-                  FKey := IK_ENTER; // <Enter>
+                  // FKey := IK_ENTER; // <Enter>
+                  FKey := wParam;
                   FIsQuery := False;
                   actDefCtl();
                 end;
@@ -2458,7 +2470,7 @@ begin
           else if FIsQuery then
           begin
             case wParam of
-              IK_ENTER, IK_KPRETURN, VK_FIRE, VK_OPEN, JOY0_ATTACK, JOY1_ATTACK, JOY2_ATTACK, JOY3_ATTACK: // Not <Enter
+              IK_ENTER, IK_KPRETURN, VK_FIRSTKEY..VK_LASTKEY, JOY0_ATTACK, JOY1_ATTACK, JOY2_ATTACK, JOY3_ATTACK: // Not <Enter
             else
               if e_KeyNames[wParam] <> '' then
                 FKey := wParam;
@@ -2468,6 +2480,8 @@ begin
           end;
         end;
     end;
+
+  g_GUIGrabInput := FIsQuery
 end;
 
 { TGUIKeyRead2 }
@@ -2569,7 +2583,7 @@ begin
     case Msg of
       WM_KEYDOWN:
         case wParam of
-          IK_ESCAPE, VK_ESCAPE, JOY0_JUMP, JOY1_JUMP, JOY2_JUMP, JOY3_JUMP:
+          VK_ESCAPE:
             begin
               if FIsQuery then actDefCtl();
               FIsQuery := False;
@@ -2584,9 +2598,10 @@ begin
 
                   FIsQuery := True;
                 end
-              else
+              else if (wParam < VK_FIRSTKEY) and (wParam > VK_LASTKEY) then
                 begin
-                  if (FKeyIdx = 0) then FKey0 := IK_ENTER else FKey1 := IK_ENTER; // <Enter>
+                  // if (FKeyIdx = 0) then FKey0 := IK_ENTER else FKey1 := IK_ENTER; // <Enter>
+                  if (FKeyIdx = 0) then FKey0 := wParam else FKey1 := wParam;
                   FIsQuery := False;
                   actDefCtl();
                 end;
@@ -2623,8 +2638,7 @@ begin
           else if FIsQuery then
           begin
             case wParam of
-              IK_ENTER, IK_KPRETURN, VK_FIRE, VK_OPEN,
-              JOY0_ATTACK, JOY1_ATTACK, JOY2_ATTACK, JOY3_ATTACK: // Not <Enter
+              IK_ENTER, IK_KPRETURN, VK_FIRSTKEY..VK_LASTKEY, JOY0_ATTACK, JOY1_ATTACK, JOY2_ATTACK, JOY3_ATTACK: // Not <Enter
             else
               if e_KeyNames[wParam] <> '' then
               begin
@@ -2636,6 +2650,8 @@ begin
           end;
         end;
     end;
+
+  g_GUIGrabInput := FIsQuery
 end;
 
 
@@ -3144,7 +3160,7 @@ end;
 
 procedure TGUIFileListBox.OnMessage(var Msg: TMessage);
 var
-  a: Integer;
+  a, b: Integer;
 begin
   if not FEnabled then
     Exit;
@@ -3225,7 +3241,7 @@ begin
                 SetActive(Self)
               else
                 begin
-                  if FItems[FIndex][1] = #29 then // Ïàïêà
+                  if FItems[FIndex][1] = #29 then // �����
                   begin
                     OpenDir(FPath+Copy(FItems[FIndex], 2, 255));
                     FIndex := 0;
@@ -3241,11 +3257,13 @@ begin
         end;
 
       WM_CHAR:
-        for a := 0 to High(FItems) do
+        for b := FIndex + 1 to High(FItems) + FIndex do
+        begin
+          a := b mod Length(FItems);
           if ( (Length(FItems[a]) > 0) and
                (LowerCase(FItems[a][1]) = LowerCase(Chr(wParam))) ) or
              ( (Length(FItems[a]) > 1) and
-               (FItems[a][1] = #29) and // Ïàïêà
+               (FItems[a][1] = #29) and // �����
                (LowerCase(FItems[a][2]) = LowerCase(Chr(wParam))) ) then
           begin
             FIndex := a;
@@ -3254,6 +3272,7 @@ begin
               FOnChangeEvent(Self);
             Break;
           end;
+        end;
     end;
 end;
 
@@ -3268,7 +3287,7 @@ begin
   path := IncludeTrailingPathDelimiter(path);
   path := ExpandFileName(path);
 
-  // Êàòàëîãè:
+  // ��������:
   if FDirs then
   begin
     if FindFirst(path+'*', faDirectory, SR) = 0 then
@@ -3285,7 +3304,7 @@ begin
     FindClose(SR);
   end;
 
-  // Ôàéëû:
+  // �����:
   sm := FFileMask;
   while sm <> '' do
   begin