source: trunk/Common/Rectangle.pas

Last change on this file was 74, checked in by chronos, 8 months ago
  • Modified: Updated Common package.
File size: 3.2 KB
Line 
1unit Rectangle;
2
3// Date: 2011-03-20
4
5interface
6
7uses
8 Classes, SysUtils;
9
10type
11 { TRectangle }
12
13 TRectangle = class
14 private
15 function GetBottomLeft: TPoint;
16 function GetBottomRight: TPoint;
17 function GetHeight: Integer;
18 function GetTopLeft: TPoint;
19 function GetTopRight: TPoint;
20 function GetTRect: TRect;
21 function GetWidth: Integer;
22 procedure SetBottomLeft(const AValue: TPoint);
23 procedure SetBottomRight(const AValue: TPoint);
24 procedure SetHeight(const AValue: Integer);
25 procedure SetTopLeft(const AValue: TPoint);
26 procedure SetTopRight(const AValue: TPoint);
27 procedure SetTRect(const AValue: TRect);
28 procedure SetWidth(const AValue: Integer);
29 public
30 Left: Integer;
31 Top: Integer;
32 Right: Integer;
33 Bottom: Integer;
34
35 procedure Assign(Source: TRectangle);
36 function IsInside(Pos: TPoint): Boolean;
37
38 property Width: Integer read GetWidth write SetWidth;
39 property Height: Integer read GetHeight write SetHeight;
40
41 property TopLeft: TPoint read GetTopLeft write SetTopLeft;
42 property TopRight: TPoint read GetTopRight write SetTopRight;
43 property BottomLeft: TPoint read GetBottomLeft write SetBottomLeft;
44 property BottomRight: TPoint read GetBottomRight write SetBottomRight;
45
46 property AsTRect: TRect read GetTRect write SetTRect;
47 end;
48
49
50implementation
51
52{ TRectangle }
53
54function TRectangle.GetBottomLeft: TPoint;
55begin
56 Result.X := Left;
57 Result.Y := Bottom;
58end;
59
60function TRectangle.GetBottomRight: TPoint;
61begin
62 Result.X := Right;
63 Result.Y := Bottom;
64end;
65
66function TRectangle.GetHeight: Integer;
67begin
68 Result := Bottom - Top;
69end;
70
71function TRectangle.GetTopLeft: TPoint;
72begin
73 Result.X := Left;
74 Result.Y := Top;
75end;
76
77function TRectangle.GetTopRight: TPoint;
78begin
79 Result.X := Right;
80 Result.Y := Top;
81end;
82
83function TRectangle.GetTRect: TRect;
84begin
85 Result.Left := Left;
86 Result.Top := Top;
87 Result.Bottom := Bottom;
88 Result.Right := Right;
89end;
90
91function TRectangle.GetWidth: Integer;
92begin
93 Result := Right - Left;
94end;
95
96procedure TRectangle.SetBottomLeft(const AValue: TPoint);
97begin
98 Left := AValue.X;
99 Bottom := AValue.Y;
100end;
101
102procedure TRectangle.SetBottomRight(const AValue: TPoint);
103begin
104 Right := AValue.X;
105 Bottom := AValue.Y;
106end;
107
108procedure TRectangle.SetHeight(const AValue: Integer);
109begin
110 Bottom := Top + AValue;
111end;
112
113procedure TRectangle.SetTopLeft(const AValue: TPoint);
114begin
115 Left := AValue.X;
116 Top := AValue.Y;
117end;
118
119procedure TRectangle.SetTopRight(const AValue: TPoint);
120begin
121 Right := AValue.X;
122 Top := AValue.Y;
123end;
124
125procedure TRectangle.SetTRect(const AValue: TRect);
126begin
127 Left := AValue.Left;
128 Top := AValue.Top;
129 Bottom := AValue.Bottom;
130 Right := AValue.Right;
131end;
132
133procedure TRectangle.SetWidth(const AValue: Integer);
134begin
135 Right := Left + AValue;
136end;
137
138procedure TRectangle.Assign(Source: TRectangle);
139begin
140 Left := Source.Left;
141 Top := Source.Top;
142 Right := Source.Right;
143 Bottom := Source.Bottom;
144end;
145
146function TRectangle.IsInside(Pos: TPoint): Boolean;
147begin
148 Result := (Pos.X >= Left) and (Pos.Y >= Top) and
149 (Pos.X <= Right) and (Pos.Y <= Bottom);
150end;
151
152end.
153
Note: See TracBrowser for help on using the repository browser.