source: trunk/Packages/CoolDocking/Common/URectangle.pas

Last change on this file was 73, checked in by chronos, 12 years ago
  • Modified: Packages are now stored as uncomporessed and are linked with relative path to project.
File size: 4.7 KB
Line 
1unit URectangle;
2
3// Date: 2011-03-20
4
5{$mode Delphi}{$H+}
6
7interface
8
9uses
10 Classes, SysUtils;
11
12type
13 { TRectangle }
14
15 TRectangle = class
16 private
17 function GetBottomLeft: TPoint;
18 function GetBottomRight: TPoint;
19 function GetHeight: Integer;
20 function GetSize: TPoint;
21 function GetTopLeft: TPoint;
22 function GetTopRight: TPoint;
23 function GetTRect: TRect;
24 function GetWidth: Integer;
25 procedure SetBottom(const AValue: Integer);
26 procedure SetBottomLeft(const AValue: TPoint);
27 procedure SetBottomRight(const AValue: TPoint);
28 procedure SetHeight(const AValue: Integer);
29 procedure SetLeft(const AValue: Integer);
30 procedure SetRight(const AValue: Integer);
31 procedure SetSize(const AValue: TPoint);
32 procedure SetTop(const AValue: Integer);
33 procedure SetTopLeft(const AValue: TPoint);
34 procedure SetTopRight(const AValue: TPoint);
35 procedure SetTRect(const AValue: TRect);
36 procedure SetWidth(const AValue: Integer);
37 public
38 FLeft: Integer;
39 FTop: Integer;
40 FRight: Integer;
41 FBottom: Integer;
42 KeepSize: Boolean;
43
44 property Left: Integer read FLeft write SetLeft;
45 property Top: Integer read FTop write SetTop;
46 property Right: Integer read FRight write SetRight;
47 property Bottom: Integer read FBottom write SetBottom;
48
49 procedure Assign(Source: TRectangle);
50 function IsInside(Pos: TPoint): Boolean;
51
52 property Width: Integer read GetWidth write SetWidth;
53 property Height: Integer read GetHeight write SetHeight;
54
55 property TopLeft: TPoint read GetTopLeft write SetTopLeft;
56 property TopRight: TPoint read GetTopRight write SetTopRight;
57 property BottomLeft: TPoint read GetBottomLeft write SetBottomLeft;
58 property BottomRight: TPoint read GetBottomRight write SetBottomRight;
59
60 property Size: TPoint read GetSize write SetSize;
61
62 property AsTRect: TRect read GetTRect write SetTRect;
63 end;
64
65implementation
66
67{ TRectangle }
68
69function TRectangle.GetBottomLeft: TPoint;
70begin
71 Result.X := Left;
72 Result.Y := Bottom;
73end;
74
75function TRectangle.GetBottomRight: TPoint;
76begin
77 Result.X := Right;
78 Result.Y := Bottom;
79end;
80
81function TRectangle.GetHeight: Integer;
82begin
83 Result := Bottom - Top;
84end;
85
86function TRectangle.GetSize: TPoint;
87begin
88 Result := Point(Width, Height);
89end;
90
91function TRectangle.GetTopLeft: TPoint;
92begin
93 Result.X := Left;
94 Result.Y := Top;
95end;
96
97function TRectangle.GetTopRight: TPoint;
98begin
99 Result.X := Right;
100 Result.Y := Top;
101end;
102
103function TRectangle.GetTRect: TRect;
104begin
105 Result.Left := Left;
106 Result.Top := Top;
107 Result.Bottom := Bottom;
108 Result.Right := Right;
109end;
110
111function TRectangle.GetWidth: Integer;
112begin
113 Result := Right - Left;
114end;
115
116procedure TRectangle.SetBottom(const AValue: Integer);
117begin
118 if FBottom = AValue then exit;
119 if KeepSize then Inc(FTop, AValue - FBottom);
120 FBottom := AValue;
121end;
122
123procedure TRectangle.SetBottomLeft(const AValue: TPoint);
124begin
125 Left := AValue.X;
126 Bottom := AValue.Y;
127end;
128
129procedure TRectangle.SetBottomRight(const AValue: TPoint);
130begin
131 Right := AValue.X;
132 Bottom := AValue.Y;
133end;
134
135procedure TRectangle.SetHeight(const AValue: Integer);
136begin
137 Bottom := Top + AValue;
138end;
139
140procedure TRectangle.SetLeft(const AValue: Integer);
141begin
142 if FLeft = AValue then Exit;
143 if KeepSize then Inc(FRight, AValue - FLeft);
144 FLeft := AValue;
145end;
146
147procedure TRectangle.SetRight(const AValue: Integer);
148begin
149 if FRight = AValue then Exit;
150 if KeepSize then Inc(FLeft, AValue - FRight);
151 FRight := AValue;
152end;
153
154procedure TRectangle.SetSize(const AValue: TPoint);
155begin
156 Width := AValue.X;
157 Height := AValue.Y;
158end;
159
160procedure TRectangle.SetTop(const AValue: Integer);
161begin
162 if FTop = AValue then Exit;
163 if KeepSize then Inc(FBottom, AValue - FTop);
164 FTop := AValue;
165end;
166
167procedure TRectangle.SetTopLeft(const AValue: TPoint);
168begin
169 Left := AValue.X;
170 Top := AValue.Y;
171end;
172
173procedure TRectangle.SetTopRight(const AValue: TPoint);
174begin
175 Right := AValue.X;
176 Top := AValue.Y;
177end;
178
179procedure TRectangle.SetTRect(const AValue: TRect);
180begin
181 Left := AValue.Left;
182 Top := AValue.Top;
183 Bottom := AValue.Bottom;
184 Right := AValue.Right;
185end;
186
187procedure TRectangle.SetWidth(const AValue: Integer);
188begin
189 Right := Left + AValue;
190end;
191
192procedure TRectangle.Assign(Source: TRectangle);
193begin
194 Left := Source.Left;
195 Top := Source.Top;
196 Right := Source.Right;
197 Bottom := Source.Bottom;
198end;
199
200function TRectangle.IsInside(Pos: TPoint): Boolean;
201begin
202 Result := (Pos.X >= Left) and (Pos.Y >= Top) and
203 (Pos.X <= Right) and (Pos.Y <= Bottom);
204end;
205
206end.
207
Note: See TracBrowser for help on using the repository browser.