source: branches/Xvcl/Xvcl.Classes.pas

Last change on this file was 23, checked in by chronos, 12 years ago
  • Added: Support for mouse move handling. Now forms can be moved by dragging title bar.
  • Fixed: Clearing background during painting in screen and forms.
File size: 4.8 KB
Line 
1unit Xvcl.Classes;
2
3interface
4
5type
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
73implementation
74
75{ TBounds }
76
77function TRectangle.Contains(Position: TPoint): Boolean;
78begin
79 Result := (Position.X >= Left) and (Position.X < Right) and (Position.Y >= Top)
80 and (Position.Y < Bottom);
81end;
82
83constructor TRectangle.Create(Left, Top, Width, Height: Integer);
84begin
85 Self.Left := Left;
86 Self.Top := Top;
87 Self.Width := Width;
88 Self.Height := Height;
89end;
90
91function TRectangle.GetBottom: Integer;
92begin
93 Result := Top + Height;
94end;
95
96function TRectangle.GetBottomLeft: TPoint;
97begin
98 Result := TPoint.Create(Left, Bottom);
99end;
100
101function TRectangle.GetBottomRight: TPoint;
102begin
103 Result := TPoint.Create(Right, Bottom);
104end;
105
106function TRectangle.GetTopLeft: TPoint;
107begin
108 Result := TPoint.Create(Left, Top);
109end;
110
111function TRectangle.GetPosition: TPoint;
112begin
113 Result := TPoint.Create(Left, Top);
114end;
115
116function TRectangle.GetRight: Integer;
117begin
118 Result := Left + Width;
119end;
120
121function TRectangle.GetTopRight: TPoint;
122begin
123 Result := TPoint.Create(Right, Top);
124end;
125
126procedure TRectangle.SetBottom(const Value: Integer);
127begin
128 Height := Value - Top;
129end;
130
131procedure TRectangle.SetBottomRight(const Value: TPoint);
132begin
133 Right := Value.X;
134 Bottom := Value.Y;
135end;
136
137procedure TRectangle.SetRight(const Value: Integer);
138begin
139 Width := Value - Left;
140end;
141
142procedure TRectangle.SetTopLeft(const Value: TPoint);
143begin
144 Left := Value.X;
145 Top := Value.Y;
146end;
147
148procedure TRectangle.SetTopRight(const Value: TPoint);
149begin
150 Top := Value.X;
151 Right := Value.Y;
152end;
153
154function TRectangle.GetSize: TPoint;
155begin
156 Result := TPoint.Create(Width, Height);
157end;
158
159{ TComponent }
160
161constructor TComponent.Create;
162begin
163end;
164
165{ TPoint }
166
167function TPoint.Add(Point: TPoint): TPoint;
168begin
169 Result := TPoint.Create(X + Point.X, Y + Point.Y);
170end;
171
172class operator TPoint.Add(A, B: TPoint): TPoint;
173begin
174 Result.X := A.X + B.X;
175 Result.Y := A.Y + B.Y;
176end;
177
178constructor TPoint.Create(X, Y: Integer);
179begin
180 Self.X := X;
181 Self.Y := Y;
182end;
183
184
185function TPoint.IsZero: Boolean;
186begin
187 Result := (X = 0) and (Y = 0);
188end;
189
190class operator TPoint.Subtract(A, B: TPoint): TPoint;
191begin
192 Result.X := A.X - B.X;
193 Result.Y := A.Y - B.Y;
194end;
195
196function TPoint.Substract(Point: TPoint): TPoint;
197begin
198 Result := TPoint.Create(X - Point.X, Y - Point.Y);
199end;
200
201{ TUpdateLock }
202
203procedure TUpdateLock.Start;
204begin
205 Inc(Counter);
206end;
207
208procedure TUpdateLock.Stop;
209begin
210 if Counter > 0 then begin
211 Dec(Counter);
212 Update;
213 end;
214end;
215
216procedure TUpdateLock.Update;
217begin
218 if (Counter = 0) and Assigned(FOnUpdate) then
219 FOnUpdate(Self);
220end;
221
222end.
Note: See TracBrowser for help on using the repository browser.