Skip to content

Commit

Permalink
Add code to make the anchordesigner more dpi aware
Browse files Browse the repository at this point in the history
  • Loading branch information
cheat-engine committed Aug 19, 2019
1 parent 65c7150 commit 32b970a
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 6 deletions.
8 changes: 4 additions & 4 deletions Cheat Engine/DPIHelper.pas
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ procedure AdjustSpeedButtonSize(sb: TSpeedButton);
procedure AdjustToolbar(tb: TToolbar);
procedure AdjustImageList(il: TImageList);
procedure AdjustComboboxSize(cb: TComboBox; canvas: TCanvas);
procedure AdjustEditBoxSize(editbox: TEdit; mintextwidth: integer);
function GetEditBoxMargins(editbox: TEdit): integer;
procedure AdjustEditBoxSize(editbox: TCustomEdit; mintextwidth: integer);
function GetEditBoxMargins(editbox: TCustomEdit): integer;

function getDPIScaleFactor: single;

Expand All @@ -28,7 +28,7 @@ function getDPIScaleFactor: single;
result:=screen.PixelsPerInch/designtimedpi;
end;

function GetEditBoxMargins(editbox: TEdit): integer;
function GetEditBoxMargins(editbox: TCustomEdit): integer;
var m: dword;
begin
if WindowsVersion>=wvVista then
Expand All @@ -39,7 +39,7 @@ function GetEditBoxMargins(editbox: TEdit): integer;
result:=(m shr 16)+(m and $ffff);
end;

procedure AdjustEditBoxSize(editbox: TEdit; mintextwidth: integer);
procedure AdjustEditBoxSize(editbox: TCustomEdit; mintextwidth: integer);
var marginsize: integer;
begin
marginsize:=GetEditBoxMargins(editbox);
Expand Down
62 changes: 60 additions & 2 deletions Cheat Engine/formdesignerunit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ implementation
{ TFormDesigner }


uses mainunit, DPIHelper{$if lcl_fullversion>=2000000}, LazMsgDialogs{$endif};
uses mainunit, DPIHelper{$if lcl_fullversion>=2000000}, LazMsgDialogs{$endif}, IDEImagesIntf;

resourcestring
rsInvalidObject = '{Invalid object}';
Expand Down Expand Up @@ -279,11 +279,69 @@ procedure TFormDesigner.miAddTabClick(Sender: TObject);
end;

procedure TFormDesigner.miAnchorEditorClick(Sender: TObject);
var defaultwidth: integer;
begin
if AnchorDesigner=nil then
begin
AnchorDesigner:=TAnchorDesigner.Create(self);
AnchorDesigner.show;

//this this is the most dpi unaware window I've seen
with AnchorDesigner do
begin
DPIHelper.AdjustSpeedButtonSize(LeftRefLeftSpeedButton);
DPIHelper.AdjustSpeedButtonSize(LeftRefCenterSpeedButton);
DPIHelper.AdjustSpeedButtonSize(LeftRefRightSpeedButton);
DPIHelper.AdjustSpeedButtonSize(RightRefLeftSpeedButton);
DPIHelper.AdjustSpeedButtonSize(RightRefCenterSpeedButton);
DPIHelper.AdjustSpeedButtonSize(RightRefRightSpeedButton);
DPIHelper.AdjustSpeedButtonSize(TopRefTopSpeedButton);
DPIHelper.AdjustSpeedButtonSize(TopRefCenterSpeedButton);
DPIHelper.AdjustSpeedButtonSize(TopRefBottomSpeedButton);
DPIHelper.AdjustSpeedButtonSize(BottomRefTopSpeedButton);
DPIHelper.AdjustSpeedButtonSize(BottomRefCenterSpeedButton);
DPIHelper.AdjustSpeedButtonSize(BottomRefBottomSpeedButton);

defaultWidth:=canvas.TextWidth('10 ');
DPIHelper.AdjustEditBoxSize(LeftBorderSpaceSpinEdit, defaultwidth);
DPIHelper.AdjustEditBoxSize(TopBorderSpaceSpinEdit, defaultwidth);
DPIHelper.AdjustEditBoxSize(RightBorderSpaceSpinEdit, defaultwidth);
DPIHelper.AdjustEditBoxSize(BottomBorderSpaceSpinEdit, defaultwidth);
DPIHelper.AdjustEditBoxSize(AroundBorderSpaceSpinEdit, defaultwidth);

BorderSpaceGroupBox.Width:=(AroundBorderSpaceSpinEdit.width+5)*3;
Constraints.MinWidth:=(BorderSpaceGroupBox.Width)*4;


IDEImages.AssignImage(LeftRefLeftSpeedButton, 'anchor_left_left');
IDEImages.AssignImage(LeftRefCenterSpeedButton, 'anchor_left_center');
IDEImages.AssignImage(LeftRefRightSpeedButton, 'anchor_left_right');
IDEImages.AssignImage(RightRefLeftSpeedButton, 'anchor_right_left');
IDEImages.AssignImage(RightRefCenterSpeedButton, 'anchor_right_center');
IDEImages.AssignImage(RightRefRightSpeedButton, 'anchor_right_right');
IDEImages.AssignImage(TopRefTopSpeedButton, 'anchor_top_top');
IDEImages.AssignImage(TopRefCenterSpeedButton, 'anchor_top_center');
IDEImages.AssignImage(TopRefBottomSpeedButton, 'anchor_top_bottom');
IDEImages.AssignImage(BottomRefTopSpeedButton, 'anchor_bottom_top');
IDEImages.AssignImage(BottomRefCenterSpeedButton, 'anchor_bottom_center');
IDEImages.AssignImage(BottomRefBottomSpeedButton, 'anchor_bottom_bottom');

show;

DoAutoSize;

TopGroupBox.left:=BorderSpaceGroupBox.left;
BottomGroupBox.Left:=BorderSpaceGroupBox.left;
TopGroupBox.width:=BorderSpaceGroupBox.Width;
BottomGroupBox.Width:=BorderSpaceGroupBox.Width;


Constraints.MinHeight:=trunc(TopGroupBox.Height*3.2);

if height<Constraints.MinHeight then
height:=Constraints.MinHeight;


end;
end
else
AnchorDesigner.Show;
Expand Down

0 comments on commit 32b970a

Please sign in to comment.