source: branches/overos/Os.Types.pas

Last change on this file was 39, checked in by chronos, 11 months ago
  • Modified: Simplified unit names.
File size: 2.6 KB
Line 
1unit Os.Types;
2
3interface
4
5uses
6 Classes, SysUtils;
7
8type
9
10 { TSize }
11
12 TSize = record
13 Width: Integer;
14 Height: Integer;
15 class function Create(Width, Height: Integer): TSize; static;
16 class operator Add(A, B: TSize): TSize;
17 class operator Subtract(A, B: TSize): TSize;
18 class operator Equal(A, B: TSize): Boolean;
19 end;
20
21 { TPosition }
22
23 TPosition = record
24 Left: Integer;
25 Top: Integer;
26 class function Create(Left, Top: Integer): TPosition; static;
27 class operator Add(A, B: TPosition): TPosition;
28 class operator Subtract(A, B: TPosition): TPosition;
29 class operator Equal(A, B: TPosition): Boolean;
30 end;
31
32 { TRectangle }
33
34 TRectangle = record
35 Position: TPosition;
36 Size: TSize;
37 class function Create(Position: TPosition; Size: TSize): TRectangle; static;
38 function Contains(Position: TPosition): Boolean;
39 class operator Equal(A, B: TRectangle): Boolean;
40 end;
41
42 TMessage = class
43 Handle: TObject;
44 end;
45
46
47implementation
48
49{ TRectangle }
50
51class function TRectangle.Create(Position: TPosition; Size: TSize): TRectangle;
52begin
53 Result.Position := Position;
54 Result.Size := Size;
55end;
56
57function TRectangle.Contains(Position: TPosition): Boolean;
58begin
59 Result := (Self.Position.Left <= Position.Left) and
60 (Self.Position.Top <= Position.Top) and
61 (Self.Position.Left + Self.Size.Width >= Position.Left) and
62 (Self.Position.Top + Self.Size.Height >= Position.Top);
63end;
64
65class operator TRectangle.Equal(A, B: TRectangle): Boolean;
66begin
67 Result := (A.Position = B.Position) and (A.Size = B.Size);
68end;
69
70{ TPosition }
71
72class function TPosition.Create(Left, Top: Integer): TPosition;
73begin
74 Result.Left := Left;
75 Result.Top := Top;
76end;
77
78class operator TPosition.Add(A, B: TPosition): TPosition;
79begin
80 Result.Left := A.Left + B.Left;
81 Result.Top := A.Top + B.Top;
82end;
83
84class operator TPosition.Subtract(A, B: TPosition): TPosition;
85begin
86 Result.Left := A.Left - B.Left;
87 Result.Top := A.Top - B.Top;
88end;
89
90class operator TPosition.Equal(A, B: TPosition): Boolean;
91begin
92 Result := (A.Left = B.Left) and (A.Top = B.Top);
93end;
94
95{ TSize }
96
97class function TSize.Create(Width, Height: Integer): TSize; static;
98begin
99 Result.Width := Width;
100 Result.Height := Height;
101end;
102
103class operator TSize.Add(A, B: TSize): TSize;
104begin
105 Result.Width := A.Width + B.Width;
106 Result.Height := A.Height + B.Height;
107end;
108
109class operator TSize.Subtract(A, B: TSize): TSize;
110begin
111 Result.Width := A.Width - B.Width;
112 Result.Height := A.Height - B.Height;
113end;
114
115class operator TSize.Equal(A, B: TSize): Boolean;
116begin
117 Result := (A.Width = B.Width) and (A.Height = B.Height);
118end;
119
120
121end.
122
Note: See TracBrowser for help on using the repository browser.