DEADSOFTWARE

"hlm_ui_scale" convar; "--holmes_ui_scale" cli arg; (fgsfds request)
[d2df-sdl.git] / src / game / g_holmes_ui.inc
index 17cb20f644c3f86abae44cb1fc0b6f0a554b3e2a..d9909a2586a3540147eb716f3128443d75674226 100644 (file)
@@ -664,6 +664,10 @@ end;
 procedure THControl.setScissorGLInternal (x, y, w, h: Integer);
 begin
   if not scallowed then exit;
+  x := trunc(x*g_holmes_ui_scale);
+  y := trunc(y*g_holmes_ui_scale);
+  w := trunc(w*g_holmes_ui_scale);
+  h := trunc(h*g_holmes_ui_scale);
   y := gWinSizeY-(y+h);
   if not intersectRect(x, y, w, h, scxywh[0], scxywh[1], scxywh[2], scxywh[3]) then glScissor(0, 0, 0, 0) else glScissor(x, y, w, h);
 end;
@@ -785,7 +789,7 @@ begin
   if (topLevel.mFocused <> self) and isMyChild(topLevel.mFocused) and topLevel.mFocused.mEnabled then result := topLevel.mFocused.keyEvent(ev);
   if (mParent = nil) then
   begin
-    if (ev.kstate = THKeyEvent.ModShift) and (ev.scan = SDL_SCANCODE_TAB) then
+    if (ev.kind = ev.Press) and (ev = 'S-Tab') then
     begin
       result := true;
       if (ev.kind = ev.Press) then
@@ -799,7 +803,7 @@ begin
       end;
       exit;
     end;
-    if (ev.kstate = 0) and (ev.scan = SDL_SCANCODE_TAB) then
+    if (ev.kind = ev.Press) and (ev = 'Tab') then
     begin
       result := true;
       if (ev.kind = ev.Press) then
@@ -813,7 +817,7 @@ begin
       end;
       exit;
     end;
-    if mEscClose and (ev.kind = ev.Press) and (ev.kstate = 0) and (ev.scan = SDL_SCANCODE_ESCAPE) then
+    if mEscClose and (ev.kind = ev.Press) and (ev = 'Escape') then
     begin
       result := true;
       uiRemoveWindow(self);
@@ -849,8 +853,8 @@ procedure THTopWindow.centerInScreen ();
 begin
   if (mWidth > 0) and (mHeight > 0) then
   begin
-    mX := (gWinSizeX-mWidth) div 2;
-    mY := (gWinSizeY-mHeight) div 2;
+    mX := trunc((gWinSizeX/g_holmes_ui_scale-mWidth)/2);
+    mY := trunc((gWinSizeY/g_holmes_ui_scale-mHeight)/2);
   end;
 end;
 
@@ -885,7 +889,7 @@ begin
   if (Length(mTitle) > 0) then
   begin
     setScissor(mFrameWidth+3*8, 0, mWidth-mFrameWidth*2-3*8, 8);
-    tx := mX+(mWidth-Length(mTitle)*8) div 2;
+    tx := (mX+3*8)+((mWidth-3*8)-Length(mTitle)*8) div 2;
     fillRect(tx-3, mY, Length(mTitle)*8+3+2, 8, 0, 0, 128);
     drawText8(tx, mY, mTitle, r, g, b);
   end;
@@ -906,7 +910,7 @@ function THTopWindow.keyEvent (var ev: THKeyEvent): Boolean;
 begin
   result := inherited keyEvent(ev);
   if not getFocused then exit;
-  if (ev.kstate = ev.ModAlt) and (ev.kind = ev.Press) and (ev.scan = SDL_SCANCODE_F3) then
+  if (ev.kind = ev.Press) and (ev = 'M-F3') then
   begin
     uiRemoveWindow(self);
     result := true;
@@ -1156,7 +1160,7 @@ begin
   if not result and toLocal(lx, ly) then
   begin
     result := true;
-    if (ev.kind = ev.Press) then
+    if (ev.kind = ev.Press) and (ev = 'lmb') then
     begin
       ly := ly div 8;
       if (ly >= 0) and (ly < Length(mItems)) then
@@ -1182,67 +1186,62 @@ begin
   result := inherited keyEvent(ev);
   if not getFocused then exit;
   //result := true;
-  if (ev.kstate = 0) and (ev.kind = ev.Press) then
+  if (ev.kind = ev.Press) then
   begin
-    case ev.scan of
-      SDL_SCANCODE_HOME,
-      SDL_SCANCODE_PAGEUP:
-        begin
-          result := true;
-          mCurIndex := 0;
-        end;
-      SDL_SCANCODE_END,
-      SDL_SCANCODE_PAGEDOWN:
-        begin
-          result := true;
-          mCurIndex := High(mItems);
-        end;
-      SDL_SCANCODE_UP:
-        begin
-          result := true;
-          if (Length(mItems) > 0) then
-          begin
-            if (mCurIndex < 0) then mCurIndex := Length(mItems);
-            while (mCurIndex > 0) do
-            begin
-              Dec(mCurIndex);
-              if (mItems[mCurIndex].varp <> nil) then break;
-            end;
-          end
-          else
-          begin
-            mCurIndex := -1;
-          end;
-        end;
-      SDL_SCANCODE_DOWN:
+    if (ev = 'Home') or (ev = 'PageUp') then
+    begin
+      result := true;
+      mCurIndex := 0;
+    end;
+    if (ev = 'End') or (ev = 'PageDown') then
+    begin
+      result := true;
+      mCurIndex := High(mItems);
+    end;
+    if (ev = 'Up') then
+    begin
+      result := true;
+      if (Length(mItems) > 0) then
+      begin
+        if (mCurIndex < 0) then mCurIndex := Length(mItems);
+        while (mCurIndex > 0) do
         begin
-          result := true;
-          if (Length(mItems) > 0) then
-          begin
-            if (mCurIndex < 0) then mCurIndex := -1;
-            while (mCurIndex < High(mItems)) do
-            begin
-              Inc(mCurIndex);
-              if (mItems[mCurIndex].varp <> nil) then break;
-            end;
-          end
-          else
-          begin
-            mCurIndex := -1;
-          end;
+          Dec(mCurIndex);
+          if (mItems[mCurIndex].varp <> nil) then break;
         end;
-      SDL_SCANCODE_SPACE,
-      SDL_SCANCODE_RETURN:
+      end
+      else
+      begin
+        mCurIndex := -1;
+      end;
+    end;
+    if (ev = 'Down') then
+    begin
+      result := true;
+      if (Length(mItems) > 0) then
+      begin
+        if (mCurIndex < 0) then mCurIndex := -1;
+        while (mCurIndex < High(mItems)) do
         begin
-          result := true;
-          if (mCurIndex >= 0) and (mCurIndex < Length(mItems)) and (mItems[mCurIndex].varp <> nil) then
-          begin
-            it := @mItems[mCurIndex];
-            it.varp^ := not it.varp^;
-            if assigned(it.actionCB) then it.actionCB(self, Integer(it.varp^));
-            if assigned(actionCB) then actionCB(self, mCurIndex);
-          end;
+          Inc(mCurIndex);
+          if (mItems[mCurIndex].varp <> nil) then break;
         end;
+      end
+      else
+      begin
+        mCurIndex := -1;
+      end;
+    end;
+    if (ev = 'Space') or (ev = 'Return') then
+    begin
+      result := true;
+      if (mCurIndex >= 0) and (mCurIndex < Length(mItems)) and (mItems[mCurIndex].varp <> nil) then
+      begin
+        it := @mItems[mCurIndex];
+        it.varp^ := not it.varp^;
+        if assigned(it.actionCB) then it.actionCB(self, Integer(it.varp^));
+        if assigned(actionCB) then actionCB(self, mCurIndex);
+      end;
     end;
   end;
 end;