LazUtils, LCL: Move LCLProc.CompareRect() -> GraphMath.SameRect(). Deprecate LCLProc.CompareRect().

This commit is contained in:
Juha 2023-07-03 16:51:51 +03:00
parent d8405a9db8
commit 0bc32656ed
12 changed files with 59 additions and 54 deletions

View File

@ -9,9 +9,9 @@ interface
uses
Types, Classes, SysUtils, Math,
// LCL
LCLProc, ExtCtrls, ComCtrls, Forms, Controls,
ExtCtrls, ComCtrls, Forms, Controls,
// LazUtils
AvgLvlTree, LazConfigStorage, Laz2_XMLCfg, LazLoggerBase, LazTracer,
AvgLvlTree, LazConfigStorage, Laz2_XMLCfg, LazLoggerBase, LazTracer, GraphMath,
// AnchorDocking
AnchorDockStr;
@ -916,7 +916,7 @@ end;
procedure TAnchorDockLayoutTreeNode.SetBoundsRect(const AValue: TRect);
begin
if CompareRect(@FBoundsRect,@AValue) then exit;
if SameRect(@FBoundsRect,@AValue) then exit;
FBoundsRect:=AValue;
IncreaseChangeStamp;
end;
@ -1001,7 +1001,7 @@ end;
procedure TAnchorDockLayoutTreeNode.SetWorkAreaRect(const AValue: TRect);
begin
if CompareRect(@FWorkAreaRect,@AValue) then exit;
if SameRect(@FWorkAreaRect,@AValue) then exit;
FWorkAreaRect:=AValue;
IncreaseChangeStamp;
end;
@ -1083,7 +1083,7 @@ var
a: TAnchorKind;
begin
Result:=false;
if (not CompareRect(@FBoundsRect,@Node.FBoundsRect))
if (not SameRect(@FBoundsRect,@Node.FBoundsRect))
or (Count<>Node.Count)
or (NodeType<>Node.NodeType)
or (Name<>Node.Name)
@ -1094,7 +1094,7 @@ begin
or (PageIndex<>Node.PageIndex)
or (BoundSplitterPos<>Node.BoundSplitterPos)
or (PixelsPerInch<>Node.PixelsPerInch)
or (not CompareRect(@FWorkAreaRect,@Node.FWorkAreaRect))
or (not SameRect(@FWorkAreaRect,@Node.FWorkAreaRect))
then
exit;
for a:=low(TAnchorKind) to high(TAnchorKind) do

View File

@ -25,9 +25,9 @@ interface
uses
Classes, SysUtils, Laz_AVL_Tree,
// LCL
LCLProc, LResources, Forms, Controls, Dialogs, XMLPropStorage,
LResources, Forms, Controls, Dialogs, XMLPropStorage,
// LazUtils
LazConfigStorage, FileUtil, LazFileUtils, LazFileCache,
LazConfigStorage, FileUtil, LazFileUtils, LazFileCache, GraphMath,
// CodeTools
CodeAtom, CodeTree, KeywordFuncLists, NonPascalCodeTools, BasicCodeTools,
FileProcs, CodeCache, SourceChanger, CodeToolManager,
@ -1789,7 +1789,7 @@ end;
procedure TH2PasConverter.SetWindowBounds(const AValue: TRect);
begin
if CompareRect(@FWindowBounds,@AValue) then exit;
if SameRect(@FWindowBounds,@AValue) then exit;
FWindowBounds:=AValue;
Modified:=true;
end;
@ -1847,7 +1847,7 @@ end;
function TH2PasConverter.IsEqual(AConverter: TH2PasConverter): boolean;
begin
if (FAutoOpenLastProject<>AConverter.FAutoOpenLastProject)
or (not CompareRect(@FWindowBounds,@AConverter.FWindowBounds))
or (not SameRect(@FWindowBounds,@AConverter.FWindowBounds))
or (Fh2pasFilename<>AConverter.h2pasFilename)
or (not FProjectHistory.Equals(AConverter.FProjectHistory))
then

View File

@ -81,6 +81,7 @@ procedure MakeMinMax(var i1, i2: integer);
procedure MoveRect(var ARect: TRect; x, y: Integer);
procedure MoveRectToFit(var ARect: TRect; const MaxRect: TRect);
function SameRect(R1, R2: PRect): Boolean;
procedure PolyBezier2Polyline(Beziers: Array of TBezier;
var Points : PPoint; var Count : Longint); Overload;
@ -872,6 +873,16 @@ begin
end;
end;
function SameRect(R1, R2: PRect): Boolean;
begin
Result:=(R1^.Left=R2^.Left) and (R1^.Top=R2^.Top) and
(R1^.Bottom=R2^.Bottom) and (R1^.Right=R2^.Right);
{if not Result then begin
DebugLn(' DIFFER: ',R1^.Left,',',R1^.Top,',',R1^.Right,',',R1^.Bottom
,' <> ',R2^.Left,',',R2^.Top,',',R2^.Right,',',R2^.Bottom);
end;}
end;
{------------------------------------------------------------------------------
Method: PolyBezier2Polyline
Params: Beziers, Points, Count

View File

@ -39,9 +39,9 @@ interface
uses
Types, Classes, SysUtils, Math, FPCanvas,
// LCL
LCLIntf, LCLProc, Controls, Forms, Graphics, Menus, ComCtrls,
LCLIntf, Controls, Forms, Graphics, Menus, ComCtrls,
// LazUtils
GraphType, GraphMath,
GraphType, GraphMath, LazLoggerBase,
// IDEIntf
PropEditUtils, ComponentEditors, FormEditingIntf,
// IDE
@ -772,7 +772,7 @@ var
r: TRect;
begin
r:=GetBounds;
Result:=not CompareRect(@r,@FMovedResizedBounds);
Result:=not SameRect(@r,@FMovedResizedBounds);
end;
function TSelectedControl.IsTopLvl: boolean;
@ -2838,7 +2838,6 @@ end;
procedure TControlSelection.SetRubberBandBounds(ARect:TRect);
var
i :integer;
InvFrame: TRect;
begin
if FForm = nil then exit;
@ -2847,7 +2846,7 @@ begin
MakeMinMax(ARect.Left, ARect.Right);
MakeMinMax(ARect.Top, ARect.Bottom);
if not CompareRect(@FRubberBandBounds, @ARect) then
if not SameRect(@FRubberBandBounds, @ARect) then
begin
if (FForm <> nil) and (cssRubberbandPainted in FStates) then
begin

View File

@ -40,10 +40,10 @@ uses
// RTL + FCL
Types, Classes, Math, SysUtils, Variants, TypInfo,
// LCL
LCLProc, LCLType, LResources, LCLIntf, LMessages, InterfaceBase,
LCLType, LResources, LCLIntf, LMessages, InterfaceBase,
Forms, Controls, Graphics, Dialogs, ExtCtrls, Menus, ClipBrd,
// LazUtils
GraphType, LazFileUtils, LazFileCache, LazLoggerBase, LazUtilities,
GraphType, GraphMath, LazFileUtils, LazFileCache, LazLoggerBase, LazUtilities,
// IDEIntf
IDEDialogs, PropEdits, PropEditUtils, ComponentEditors, MenuIntf,
IDEImagesIntf, FormEditingIntf, ComponentReg, IDECommands, LazIDEIntf,
@ -3716,8 +3716,8 @@ var
begin
NewFormBounds:=Form.BoundsRect;
if FDefaultFormBoundsValid then begin
if (not CompareRect(@NewFormBounds,@FLastFormBounds))
and (not CompareRect(@NewFormBounds,@FDefaultFormBounds)) then begin
if (not SameRect(@NewFormBounds,@FLastFormBounds))
and (not SameRect(@NewFormBounds,@FDefaultFormBounds)) then begin
//debugln('TDesigner.CheckFormBounds');
Modified;
if Selection.SelectionForm=Form then begin
@ -4179,7 +4179,7 @@ var
if not (Ancestor is TControl) then exit;
OldBounds:=AControl.BoundsRect;
NewBounds:=Ancestor.BoundsRect;
if not CompareRect(@OldBounds,@NewBounds) then begin
if not SameRect(@OldBounds,@NewBounds) then begin
AControl.BoundsRect:=NewBounds;
HasChanged:=true;
end;

View File

@ -42,7 +42,7 @@ uses
LCLProc, LCLType, LCLIntf, LResources, LMessages, Forms, Controls,
Graphics, Dialogs, Themes, Buttons,
// LazUtils
LazStringUtils,
LazStringUtils, GraphMath,
// SynEdit
SynEdit, SynEditKeyCmds,
// CodeTools
@ -882,7 +882,7 @@ var
inc(y,(LineHeight-FBtnWidth) div 2);
Item.NewBounds:=Bounds(AHintRect.Right-RightSpace-1,y,FBtnWidth,FBtnWidth);
r:=Item.CopyAllButton.BoundsRect;
if not CompareRect(@r,@Item.NewBounds) then
if not SameRect(@r,@Item.NewBounds) then
IdleConnected:=true;
end;
//debugln(['DrawHint ',y,' Line="',dbgstr(Line),'" LineHeight=',LineHeight,' ']);

View File

@ -3109,7 +3109,7 @@ end;
function SendAppMessage(Msg: Cardinal; WParam: WParam; LParam: LParam): Longint;
begin
Result:=LCLProc.SendApplicationMessage(Msg,WParam,LParam);
Result:=SendApplicationMessage(Msg,WParam,LParam);
end;
procedure MoveWindowOrg(dc: hdc; X, Y: Integer);

View File

@ -1384,7 +1384,7 @@ begin
if [csLoading,csDestroying]*ComponentState<>[] then exit;
CurBounds:=BoundsRect;
CurClientSize:=Point(ClientWidth,ClientHeight);
if (not CompareRect(@FLastDoChangeBounds,@CurBounds))
if (not SameRect(@FLastDoChangeBounds,@CurBounds))
or (ComparePoints(CurClientSize,FLastDoChangeClientSize)<>0) then begin
if FormIsUpdating then begin
Include(FControlFlags,cfOnChangeBoundsNeeded);
@ -4137,7 +4137,7 @@ begin
end else
NewBaseParentClientSize:=FBaseParentClientSize;
if (not CompareRect(@NewBaseBounds,@FBaseBounds))
if (not SameRect(@NewBaseBounds,@FBaseBounds))
or (NewBaseParentClientSize.cx<>FBaseParentClientSize.cx)
or (NewBaseParentClientSize.cy<>FBaseParentClientSize.cy)
then begin

View File

@ -189,7 +189,7 @@ end;
procedure TDragDockObject.MoveDockImage;
begin
//Draw the form outlines when the position has changed
if not CompareRect(@DockRect, @EraseDockRect) then
if not SameRect(@DockRect, @EraseDockRect) then
begin
if HasOnDrawImage then
OnDrawDockImage(Self, EraseDockRect, DockRect, disMove)

View File

@ -2277,7 +2277,7 @@ begin
if CurControl=nil then continue;
NewBounds:=ControlBox.NewControlBounds;
OldBounds:=CurControl.BoundsRect;
if not CompareRect(@NewBounds,@OldBounds) then begin
if not SameRect(@NewBounds,@OldBounds) then begin
Result:=true;
CurControl.SetBoundsKeepBase(NewBounds.Left,
NewBounds.Top,
@ -3045,7 +3045,7 @@ var
Control.SetBoundsKeepBase(NewLeft, NewTop, NewWidth, NewHeight);
//DebugLn(['DoPosition ',DbgSName(Control),' ',cfAutoSizeNeeded in Control.FControlFlags]);
NewBounds:=Control.BoundsRect;
BoundsMutated:=not CompareRect(@OldBounds,@NewBounds);
BoundsMutated:=not SameRect(@OldBounds,@NewBounds);
if BoundsMutated then begin
LastBoundsMutated:=Control;
LastBoundsMutatedOld:=OldBounds;
@ -3414,7 +3414,7 @@ begin
end;
// Important: change the BaseBounds too, otherwise the changes will be undone by AlignControls
OldChildBounds:=AControl.BoundsRect;
if not CompareRect(@OldChildBounds,@NewChildBounds) then begin
if not SameRect(@OldChildBounds,@NewChildBounds) then begin
//DebugLn(['TWinControl.DoAutoSize moving child: ',DbgSName(AControl),' Old=',dbgs(OldChildBounds),' New=',dbgs(NewChildBounds)]);
AControl.BoundsRect:=NewChildBounds;
//DebugLn(['TWinControl.DoAutoSize AFTER ',DbgSName(AControl),' ',dbgs(AControl.BoundsRect)]);
@ -3721,8 +3721,8 @@ begin
R := GetClientRect;
AdjustClientRect(R);
//if CheckPosition(Self) then
//DebugLn(['TWinControl.DoAdjustClientRectChange ',DbgSName(Self),' new=',dbgs(r),' old=',dbgs(FAdjustClientRectRealized),' ',CompareRect(@r,@FAdjustClientRectRealized)]);
if not CompareRect(@R, @FAdjustClientRectRealized) then
//DebugLn(['TWinControl.DoAdjustClientRectChange ',DbgSName(Self),' new=',dbgs(r),' old=',dbgs(FAdjustClientRectRealized),' ',SameRect(@r,@FAdjustClientRectRealized)]);
if not SameRect(@R, @FAdjustClientRectRealized) then
begin
// client rect changed since last AlignControl
{$IF defined(VerboseAllAutoSize) or defined(VerboseClientRectBugFix) or defined(VerboseIntfSizing) or defined(VerboseOnResize)}
@ -6452,7 +6452,7 @@ begin
// some widgetsets updates their clientrect when the first child was moved
// do a second pass if ClientRect changed
NewRect:=GetLogicalClientRect;
if not CompareRect(@ARect,@NewRect) then
if not SameRect(@ARect,@NewRect) then
AlignControls(AControl, NewRect);
finally
EnableAlign;
@ -6933,7 +6933,7 @@ begin
GetWindowSize(Handle, NewWidth, NewHeight);
NewBoundsRealized:=Bounds(Message.XPos, Message.YPos, NewWidth, NewHeight);
if CompareRect(@NewBoundsRealized,@FBoundsRealized) then exit;
if SameRect(@NewBoundsRealized,@FBoundsRealized) then exit;
TopParent:=GetTopParent;
if (TopParent is TWinControl)
@ -7024,7 +7024,7 @@ begin
NewBoundsRealized := Bounds(NewLeft, NewTop, Message.Width, Message.Height);
OldClientSize := Size(0, 0);
NewClientSize := Size(0, 0);
if CompareRect(@NewBoundsRealized, @FBoundsRealized) then
if SameRect(@NewBoundsRealized, @FBoundsRealized) then
begin
if not (wcfClientRectNeedsUpdate in FWinControlFlags) then
begin
@ -7146,7 +7146,7 @@ begin
{$ENDIF}
//DebugLn('TWinControl.WMSize B ',Name,':',ClassName,' ',NewLeft,',',NewTop);
NewBoundsRealized := Bounds(NewLeft, NewTop, NewWidth, NewHeight);
if CompareRect(@NewBoundsRealized,@FBoundsRealized)
if SameRect(@NewBoundsRealized,@FBoundsRealized)
and (not (wcfClientRectNeedsUpdate in FWinControlFlags)) then
exit;
@ -8118,7 +8118,7 @@ begin
OldBounds := BoundsRect;
NewBounds := Bounds(ALeft, ATop, AWidth, AHeight);
if not CompareRect(@NewBounds, @OldBounds) then
if not SameRect(@NewBounds, @OldBounds) then
begin
if [csDesigning,csDestroying,csLoading]*ComponentState=[csDesigning] then
CheckDesignBounds;
@ -8516,7 +8516,7 @@ begin
// this can trigger WMSize messages
TWSWinControlClass(WidgetSetClass).SetBounds(Self, Left, Top, Width, Height);
NewClientRect := ClientRect;
if Visible and (not CompareRect(@OldClientRect,@NewClientRect)) then
if Visible and (not SameRect(@OldClientRect,@NewClientRect)) then
begin
// the widgetset has changed the clientrect in an unexpected way
{$IFDEF VerboseIntfSizing}
@ -8553,7 +8553,7 @@ begin
if HandleAllocated
and ([csLoading,csDestroying]*ComponentState=[])
and (not (csDestroyingHandle in ControlState))
and (not CompareRect(@NewBounds,@FBoundsRealized))
and (not SameRect(@NewBounds,@FBoundsRealized))
then begin
// the new bounds were not yet sent to the InterfaceObject -> send them
{$IFDEF CHECK_POSITION}
@ -8579,7 +8579,7 @@ begin
if not HandleAllocated then debugln('not HandleAllocated');
if (csLoading in ComponentState) then debugln('csLoading');
if (csDestroying in ComponentState) then debugln('csDestroying');
if (CompareRect(@NewBounds,@FBoundsRealized)) then debugln('bounds not changed');
if (SameRect(@NewBounds,@FBoundsRealized)) then debugln('bounds not changed');
end;
{$ENDIF}
if not HandleAllocated then Check;

View File

@ -113,6 +113,7 @@ procedure OwnerFormDesignerModified(AComponent: TComponent);
// Deprecated in version 2.3, 2023-06.
procedure FreeThenNil(var obj); deprecated 'Use LazUtilities.FreeThenNil instead';
function CompareRect(R1, R2: PRect): Boolean; deprecated 'Use GraphMath.SameRect instead';
function OffsetRect(var Rect: TRect; DX, DY: Integer): Boolean; deprecated 'Use Types.OffsetRect instead';
procedure MoveRect(var ARect: TRect; x, y: Integer); deprecated 'Use GraphMath.MoveRect instead';
procedure MoveRectToFit(var ARect: TRect; const MaxRect: TRect); deprecated 'Use GraphMath.MoveRectToFit instead';
@ -134,7 +135,6 @@ function RemoveAmpersands(const ASource: String): String;
function RemoveAmpersands(Src: PChar; var LineLength: Longint): PChar;
function CompareHandles(h1, h2: TLCLHandle): integer;
function CompareRect(R1, R2: PRect): Boolean;
function ComparePoints(const p1, p2: TPoint): integer;
function CompareCaret(const FirstCaret, SecondCaret: TPoint): integer;
@ -835,6 +835,11 @@ begin
LazUtilities.FreeThenNil(obj);
end;
function CompareRect(R1, R2: PRect): Boolean;
begin
Result := GraphMath.SameRect(R1, R2);
end;
function OffsetRect(var Rect: TRect; DX, DY: Integer): Boolean;
begin
Result := Types.OffsetRect(Rect, DX, DY);
@ -897,16 +902,6 @@ begin
Result:=0;
end;
function CompareRect(R1, R2: PRect): Boolean;
begin
Result:=(R1^.Left=R2^.Left) and (R1^.Top=R2^.Top) and
(R1^.Bottom=R2^.Bottom) and (R1^.Right=R2^.Right);
{if not Result then begin
DebugLn(' DIFFER: ',R1^.Left,',',R1^.Top,',',R1^.Right,',',R1^.Bottom
,' <> ',R2^.Left,',',R2^.Top,',',R2^.Right,',',R2^.Bottom);
end;}
end;
function ComparePoints(const p1, p2: TPoint): integer;
begin
if p1.Y>p2.Y then

View File

@ -99,9 +99,9 @@ interface
uses
Math, Types, Classes, SysUtils, typinfo,
// LazUtils
LazLoggerBase,
LazLoggerBase, LazTracer, GraphMath,
// LCL
LCLProc, LCLType, LCLIntf, LCLStrConsts, Graphics, Controls, ExtCtrls, Forms,
LCLType, LCLIntf, Graphics, Controls, ExtCtrls, Forms,
Menus, Themes, ComCtrls, LMessages, LResources;
type
@ -1573,7 +1573,7 @@ procedure TLazDockTree.MessageHandler(Sender: TControl; var Message: TLMessage);
NewMouseState.IsMouseDown := (GetKeyState(VK_LBUTTON) and $80) <> 0;
if not CompareMem(@FMouseState, @NewMouseState, SizeOf(NewMouseState)) then
begin
if not CompareRect(@FMouseState.Rect, @NewMouseState.Rect) then
if not SameRect(@FMouseState.Rect, @NewMouseState.Rect) then
InvalidateRect(DockSite.Handle, @FMouseState.Rect, False);
FMouseState := NewMouseState;
InvalidateRect(DockSite.Handle, @NewMouseState.Rect, False);
@ -2006,7 +2006,7 @@ begin
end;
if not CompareMem(@FMouseState, @NewMouseState, SizeOf(NewMouseState)) then
begin
if not CompareRect(@FMouseState.Rect, @NewMouseState.Rect) then
if not SameRect(@FMouseState.Rect, @NewMouseState.Rect) then
InvalidateRect(Handle, @FMouseState.Rect, False);
FMouseState := NewMouseState;
InvalidateRect(Handle, @NewMouseState.Rect, False);