From 0a81209fb6ded3c7aeba05559f3c4cbb1ef61f2a Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Sun, 1 Oct 2017 01:13:50 +0300 Subject: [PATCH] Holmes: better UI hotkeys; fitting windows to screen --- src/game/g_holmes.pas | 7 ++-- src/gx/gh_ui.pas | 74 ++++++++++++++++++++++--------------------- 2 files changed, 41 insertions(+), 40 deletions(-) diff --git a/src/game/g_holmes.pas b/src/game/g_holmes.pas index 0cac2c7..e23c435 100644 --- a/src/game/g_holmes.pas +++ b/src/game/g_holmes.pas @@ -326,7 +326,6 @@ begin //winHelp.appendChild(llb); - winHelp.flMaxSize := TLaySize.Create(trunc(getScrWdt/gh_ui_scale), trunc(getScrHgt/gh_ui_scale)); uiLayoutCtl(winHelp); winHelp.centerInScreen(); end; @@ -363,6 +362,7 @@ var box: TUIVBox; begin winLayers := TUITopWindow.Create('layers'); + winLayers.flHoriz := false; winLayers.x0 := 10; winLayers.y0 := 10; winLayers.flHoriz := false; @@ -380,7 +380,6 @@ begin addCheckBox(box, '~foreground', @g_rlayer_fore); winLayers.appendChild(box); - winLayers.flMaxSize := TLaySize.Create(trunc(getScrWdt/gh_ui_scale), trunc(getScrHgt/gh_ui_scale)); uiLayoutCtl(winLayers); end; @@ -390,6 +389,7 @@ var box: TUIVBox; begin winOutlines := TUITopWindow.Create('outlines'); + winOutlines.flHoriz := false; winOutlines.x0 := 100; winOutlines.y0 := 30; winOutlines.flHoriz := false; @@ -416,7 +416,6 @@ begin addCheckBox(box, 'con~tours', @g_ol_nice); winOutlines.appendChild(box); - winOutlines.flMaxSize := TLaySize.Create(trunc(getScrWdt/gh_ui_scale), trunc(getScrHgt/gh_ui_scale)); uiLayoutCtl(winOutlines); end; @@ -428,6 +427,7 @@ var begin winOptions := TUITopWindow.Create('Holmes Options'); winOptions.flHoriz := false; + winOptions.flHoriz := false; winOptions.escClose := true; box := TUIVBox.Create(); @@ -454,7 +454,6 @@ begin addButton(box, '~outline', toggleOutlineWindowCB); winOptions.appendChild(box); - winOptions.flMaxSize := TLaySize.Create(trunc(getScrWdt/gh_ui_scale), trunc(getScrHgt/gh_ui_scale)); uiLayoutCtl(winOptions); winOptions.centerInScreen(); end; diff --git a/src/gx/gh_ui.pas b/src/gx/gh_ui.pas index 9027758..28311e3 100644 --- a/src/gx/gh_ui.pas +++ b/src/gx/gh_ui.pas @@ -287,6 +287,7 @@ type mInClose: Boolean; mFreeOnClose: Boolean; // default: false mDoCenter: Boolean; // after layouting + mFitToScreen: Boolean; protected procedure activated (); override; @@ -302,6 +303,8 @@ type function parseProperty (const prname: AnsiString; par: TTextParser): Boolean; override; + procedure flFitToScreen (); // call this before layouting + procedure centerInScreen (); // `sx` and `sy` are screen coordinates @@ -313,6 +316,7 @@ type public property freeOnClose: Boolean read mFreeOnClose write mFreeOnClose; + property fitToScreen: Boolean read mFitToScreen write mFitToScreen; end; // ////////////////////////////////////////////////////////////////////// // @@ -436,6 +440,8 @@ type function parseProperty (const prname: AnsiString; par: TTextParser): Boolean; override; + procedure doAction (); override; + procedure drawControl (gx, gy: Integer); override; procedure mouseEvent (var ev: THMouseEvent); override; @@ -459,7 +465,6 @@ type procedure mouseEvent (var ev: THMouseEvent); override; procedure keyEvent (var ev: THKeyEvent); override; - procedure keyEventPost (var ev: THKeyEvent); override; end; // ////////////////////////////////////////////////////////////////////// // @@ -488,7 +493,6 @@ type procedure mouseEvent (var ev: THMouseEvent); override; procedure keyEvent (var ev: THKeyEvent); override; - procedure keyEventPost (var ev: THKeyEvent); override; procedure setVar (pvar: PBoolean); @@ -638,6 +642,8 @@ begin if (ctl = nil) then exit; lay := TFlexLayouter.Create(); try + if (ctl is TUITopWindow) and (TUITopWindow(ctl).fitToScreen) then TUITopWindow(ctl).flFitToScreen(); + lay.setup(ctl); //lay.layout(); @@ -2023,6 +2029,7 @@ end; procedure TUITopWindow.AfterConstruction (); begin inherited; + mFitToScreen := true; mFrameWidth := 8; mFrameHeight := 8; if (mWidth < mFrameWidth*2+3*8) then mWidth := mFrameWidth*2+3*8; @@ -2068,6 +2075,12 @@ begin end; +procedure TUITopWindow.flFitToScreen (); +begin + flMaxSize := TLaySize.Create(trunc(getScrWdt/gh_ui_scale)-mFrameWidth*2-6, trunc(getScrHgt/gh_ui_scale)-mFrameHeight*2-6); +end; + + procedure TUITopWindow.centerInScreen (); begin if (mWidth > 0) and (mHeight > 0) then @@ -2756,20 +2769,35 @@ begin end; -procedure TUITextLabel.keyEventPost (var ev: THKeyEvent); +procedure TUITextLabel.doAction (); var ctl: TUIControl; +begin + if (assigned(actionCB)) then + begin + actionCB(self); + end + else + begin + ctl := topLevel[mLinkId]; + if (ctl <> nil) then + begin + if (ctl.canFocus) then ctl.focused := true; + end; + end; +end; + + +procedure TUITextLabel.keyEventPost (var ev: THKeyEvent); begin if (not enabled) then exit; - if (mHotChar = #0) or (Length(mLinkId) = 0) then exit; + if (mHotChar = #0) then exit; if (ev.eaten) or (ev.cancelled) or (not ev.press) then exit; + if (ev.kstate <> ev.ModAlt) then exit; if (not ev.isHot(mHotChar)) then exit; - ctl := topLevel[mLinkId]; - if (ctl <> nil) then - begin - ev.eat(); - if (ctl.canFocus) then ctl.focused := true; - end; + ev.eat(); + if (canFocus) then focused := true; + doAction(); end; @@ -2855,19 +2883,6 @@ begin end; -procedure TUIButton.keyEventPost (var ev: THKeyEvent); -begin - if (not enabled) then exit; - if (mHotChar = #0) then exit; - if (ev.eaten) or (ev.cancelled) or (not ev.press) then exit; - if (not ev.isHot(mHotChar)) then exit; - if (not canFocus) then exit; - ev.eat(); - focused := true; - doAction(); -end; - - // ////////////////////////////////////////////////////////////////////////// // procedure TUISwitchBox.AfterConstruction (); begin @@ -3006,19 +3021,6 @@ begin end; -procedure TUISwitchBox.keyEventPost (var ev: THKeyEvent); -begin - if (not enabled) then exit; - if (mHotChar = #0) then exit; - if (ev.eaten) or (ev.cancelled) or (not ev.press) then exit; - if (not ev.isHot(mHotChar)) then exit; - if (not canFocus) then exit; - ev.eat(); - focused := true; - doAction(); -end; - - // ////////////////////////////////////////////////////////////////////////// // procedure TUICheckBox.AfterConstruction (); begin -- 2.29.2