| 1 | unit Xvcl.Classes;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | type
|
|---|
| 6 | TPoint = record
|
|---|
| 7 | X: Integer;
|
|---|
| 8 | Y: Integer;
|
|---|
| 9 | constructor Create(X, Y: Integer);
|
|---|
| 10 | function Add(Point: TPoint): TPoint;
|
|---|
| 11 | function Substract(Point: TPoint): TPoint;
|
|---|
| 12 | function IsZero: Boolean;
|
|---|
| 13 | class operator Add(A, B: TPoint): TPoint;
|
|---|
| 14 | class operator Subtract(A, B: TPoint): TPoint;
|
|---|
| 15 | end;
|
|---|
| 16 |
|
|---|
| 17 | TRectangle = record
|
|---|
| 18 | private
|
|---|
| 19 | function GetBottom: Integer;
|
|---|
| 20 | function GetPosition: TPoint;
|
|---|
| 21 | function GetRight: Integer;
|
|---|
| 22 | function GetSize: TPoint;
|
|---|
| 23 | function GetBottomLeft: TPoint;
|
|---|
| 24 | function GetBottomRight: TPoint;
|
|---|
| 25 | function GetTopLeft: TPoint;
|
|---|
| 26 | function GetTopRight: TPoint;
|
|---|
| 27 | procedure SetTopLeft(const Value: TPoint);
|
|---|
| 28 | procedure SetBottomRight(const Value: TPoint);
|
|---|
| 29 | procedure SetBottom(const Value: Integer);
|
|---|
| 30 | procedure SetRight(const Value: Integer);
|
|---|
| 31 | procedure SetTopRight(const Value: TPoint);
|
|---|
| 32 | public
|
|---|
| 33 | Left: Integer;
|
|---|
| 34 | Top: Integer;
|
|---|
| 35 | Width: Integer;
|
|---|
| 36 | Height: Integer;
|
|---|
| 37 | property Right: Integer read GetRight write SetRight;
|
|---|
| 38 | property Bottom: Integer read GetBottom write SetBottom;
|
|---|
| 39 | property Size: TPoint read GetSize;
|
|---|
| 40 | property Position: TPoint read GetPosition;
|
|---|
| 41 | property TopLeft: TPoint read GetTopLeft write SetTopLeft;
|
|---|
| 42 | property BottomRight: TPoint read GetBottomRight write SetBottomRight;
|
|---|
| 43 | property TopRight: TPoint read GetTopRight write SetTopRight;
|
|---|
| 44 | property BottomLeft: TPoint read GetBottomLeft;
|
|---|
| 45 | constructor Create(Left, Top, Width, Height: Integer);
|
|---|
| 46 | function Contains(Position: TPoint): Boolean;
|
|---|
| 47 | end;
|
|---|
| 48 |
|
|---|
| 49 | TComponent = class
|
|---|
| 50 | private
|
|---|
| 51 | FOwner: TComponent;
|
|---|
| 52 | FName: string;
|
|---|
| 53 | public
|
|---|
| 54 | constructor Create; virtual;
|
|---|
| 55 | property Owner: TComponent read FOwner write FOwner;
|
|---|
| 56 | property Name: string read FName write FName;
|
|---|
| 57 | end;
|
|---|
| 58 |
|
|---|
| 59 | TNotifyEvent = procedure (Sender: TObject) of object;
|
|---|
| 60 |
|
|---|
| 61 | TUpdateLock = class
|
|---|
| 62 | private
|
|---|
| 63 | FOnUpdate: TNotifyEvent;
|
|---|
| 64 | published
|
|---|
| 65 | Counter: Integer;
|
|---|
| 66 | procedure Start;
|
|---|
| 67 | procedure Stop;
|
|---|
| 68 | procedure Update;
|
|---|
| 69 | property OnUpdate: TNotifyEvent read FOnUpdate write FOnUpdate;
|
|---|
| 70 | end;
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 | implementation
|
|---|
| 74 |
|
|---|
| 75 | { TBounds }
|
|---|
| 76 |
|
|---|
| 77 | function TRectangle.Contains(Position: TPoint): Boolean;
|
|---|
| 78 | begin
|
|---|
| 79 | Result := (Position.X >= Left) and (Position.X < Right) and (Position.Y >= Top)
|
|---|
| 80 | and (Position.Y < Bottom);
|
|---|
| 81 | end;
|
|---|
| 82 |
|
|---|
| 83 | constructor TRectangle.Create(Left, Top, Width, Height: Integer);
|
|---|
| 84 | begin
|
|---|
| 85 | Self.Left := Left;
|
|---|
| 86 | Self.Top := Top;
|
|---|
| 87 | Self.Width := Width;
|
|---|
| 88 | Self.Height := Height;
|
|---|
| 89 | end;
|
|---|
| 90 |
|
|---|
| 91 | function TRectangle.GetBottom: Integer;
|
|---|
| 92 | begin
|
|---|
| 93 | Result := Top + Height;
|
|---|
| 94 | end;
|
|---|
| 95 |
|
|---|
| 96 | function TRectangle.GetBottomLeft: TPoint;
|
|---|
| 97 | begin
|
|---|
| 98 | Result := TPoint.Create(Left, Bottom);
|
|---|
| 99 | end;
|
|---|
| 100 |
|
|---|
| 101 | function TRectangle.GetBottomRight: TPoint;
|
|---|
| 102 | begin
|
|---|
| 103 | Result := TPoint.Create(Right, Bottom);
|
|---|
| 104 | end;
|
|---|
| 105 |
|
|---|
| 106 | function TRectangle.GetTopLeft: TPoint;
|
|---|
| 107 | begin
|
|---|
| 108 | Result := TPoint.Create(Left, Top);
|
|---|
| 109 | end;
|
|---|
| 110 |
|
|---|
| 111 | function TRectangle.GetPosition: TPoint;
|
|---|
| 112 | begin
|
|---|
| 113 | Result := TPoint.Create(Left, Top);
|
|---|
| 114 | end;
|
|---|
| 115 |
|
|---|
| 116 | function TRectangle.GetRight: Integer;
|
|---|
| 117 | begin
|
|---|
| 118 | Result := Left + Width;
|
|---|
| 119 | end;
|
|---|
| 120 |
|
|---|
| 121 | function TRectangle.GetTopRight: TPoint;
|
|---|
| 122 | begin
|
|---|
| 123 | Result := TPoint.Create(Right, Top);
|
|---|
| 124 | end;
|
|---|
| 125 |
|
|---|
| 126 | procedure TRectangle.SetBottom(const Value: Integer);
|
|---|
| 127 | begin
|
|---|
| 128 | Height := Value - Top;
|
|---|
| 129 | end;
|
|---|
| 130 |
|
|---|
| 131 | procedure TRectangle.SetBottomRight(const Value: TPoint);
|
|---|
| 132 | begin
|
|---|
| 133 | Right := Value.X;
|
|---|
| 134 | Bottom := Value.Y;
|
|---|
| 135 | end;
|
|---|
| 136 |
|
|---|
| 137 | procedure TRectangle.SetRight(const Value: Integer);
|
|---|
| 138 | begin
|
|---|
| 139 | Width := Value - Left;
|
|---|
| 140 | end;
|
|---|
| 141 |
|
|---|
| 142 | procedure TRectangle.SetTopLeft(const Value: TPoint);
|
|---|
| 143 | begin
|
|---|
| 144 | Left := Value.X;
|
|---|
| 145 | Top := Value.Y;
|
|---|
| 146 | end;
|
|---|
| 147 |
|
|---|
| 148 | procedure TRectangle.SetTopRight(const Value: TPoint);
|
|---|
| 149 | begin
|
|---|
| 150 | Top := Value.X;
|
|---|
| 151 | Right := Value.Y;
|
|---|
| 152 | end;
|
|---|
| 153 |
|
|---|
| 154 | function TRectangle.GetSize: TPoint;
|
|---|
| 155 | begin
|
|---|
| 156 | Result := TPoint.Create(Width, Height);
|
|---|
| 157 | end;
|
|---|
| 158 |
|
|---|
| 159 | { TComponent }
|
|---|
| 160 |
|
|---|
| 161 | constructor TComponent.Create;
|
|---|
| 162 | begin
|
|---|
| 163 | end;
|
|---|
| 164 |
|
|---|
| 165 | { TPoint }
|
|---|
| 166 |
|
|---|
| 167 | function TPoint.Add(Point: TPoint): TPoint;
|
|---|
| 168 | begin
|
|---|
| 169 | Result := TPoint.Create(X + Point.X, Y + Point.Y);
|
|---|
| 170 | end;
|
|---|
| 171 |
|
|---|
| 172 | class operator TPoint.Add(A, B: TPoint): TPoint;
|
|---|
| 173 | begin
|
|---|
| 174 | Result.X := A.X + B.X;
|
|---|
| 175 | Result.Y := A.Y + B.Y;
|
|---|
| 176 | end;
|
|---|
| 177 |
|
|---|
| 178 | constructor TPoint.Create(X, Y: Integer);
|
|---|
| 179 | begin
|
|---|
| 180 | Self.X := X;
|
|---|
| 181 | Self.Y := Y;
|
|---|
| 182 | end;
|
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 | function TPoint.IsZero: Boolean;
|
|---|
| 186 | begin
|
|---|
| 187 | Result := (X = 0) and (Y = 0);
|
|---|
| 188 | end;
|
|---|
| 189 |
|
|---|
| 190 | class operator TPoint.Subtract(A, B: TPoint): TPoint;
|
|---|
| 191 | begin
|
|---|
| 192 | Result.X := A.X - B.X;
|
|---|
| 193 | Result.Y := A.Y - B.Y;
|
|---|
| 194 | end;
|
|---|
| 195 |
|
|---|
| 196 | function TPoint.Substract(Point: TPoint): TPoint;
|
|---|
| 197 | begin
|
|---|
| 198 | Result := TPoint.Create(X - Point.X, Y - Point.Y);
|
|---|
| 199 | end;
|
|---|
| 200 |
|
|---|
| 201 | { TUpdateLock }
|
|---|
| 202 |
|
|---|
| 203 | procedure TUpdateLock.Start;
|
|---|
| 204 | begin
|
|---|
| 205 | Inc(Counter);
|
|---|
| 206 | end;
|
|---|
| 207 |
|
|---|
| 208 | procedure TUpdateLock.Stop;
|
|---|
| 209 | begin
|
|---|
| 210 | if Counter > 0 then begin
|
|---|
| 211 | Dec(Counter);
|
|---|
| 212 | Update;
|
|---|
| 213 | end;
|
|---|
| 214 | end;
|
|---|
| 215 |
|
|---|
| 216 | procedure TUpdateLock.Update;
|
|---|
| 217 | begin
|
|---|
| 218 | if (Counter = 0) and Assigned(FOnUpdate) then
|
|---|
| 219 | FOnUpdate(Self);
|
|---|
| 220 | end;
|
|---|
| 221 |
|
|---|
| 222 | end.
|
|---|