1 | unit Os.Types;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils;
|
---|
7 |
|
---|
8 | type
|
---|
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 |
|
---|
47 | implementation
|
---|
48 |
|
---|
49 | { TRectangle }
|
---|
50 |
|
---|
51 | class function TRectangle.Create(Position: TPosition; Size: TSize): TRectangle;
|
---|
52 | begin
|
---|
53 | Result.Position := Position;
|
---|
54 | Result.Size := Size;
|
---|
55 | end;
|
---|
56 |
|
---|
57 | function TRectangle.Contains(Position: TPosition): Boolean;
|
---|
58 | begin
|
---|
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);
|
---|
63 | end;
|
---|
64 |
|
---|
65 | class operator TRectangle.Equal(A, B: TRectangle): Boolean;
|
---|
66 | begin
|
---|
67 | Result := (A.Position = B.Position) and (A.Size = B.Size);
|
---|
68 | end;
|
---|
69 |
|
---|
70 | { TPosition }
|
---|
71 |
|
---|
72 | class function TPosition.Create(Left, Top: Integer): TPosition;
|
---|
73 | begin
|
---|
74 | Result.Left := Left;
|
---|
75 | Result.Top := Top;
|
---|
76 | end;
|
---|
77 |
|
---|
78 | class operator TPosition.Add(A, B: TPosition): TPosition;
|
---|
79 | begin
|
---|
80 | Result.Left := A.Left + B.Left;
|
---|
81 | Result.Top := A.Top + B.Top;
|
---|
82 | end;
|
---|
83 |
|
---|
84 | class operator TPosition.Subtract(A, B: TPosition): TPosition;
|
---|
85 | begin
|
---|
86 | Result.Left := A.Left - B.Left;
|
---|
87 | Result.Top := A.Top - B.Top;
|
---|
88 | end;
|
---|
89 |
|
---|
90 | class operator TPosition.Equal(A, B: TPosition): Boolean;
|
---|
91 | begin
|
---|
92 | Result := (A.Left = B.Left) and (A.Top = B.Top);
|
---|
93 | end;
|
---|
94 |
|
---|
95 | { TSize }
|
---|
96 |
|
---|
97 | class function TSize.Create(Width, Height: Integer): TSize; static;
|
---|
98 | begin
|
---|
99 | Result.Width := Width;
|
---|
100 | Result.Height := Height;
|
---|
101 | end;
|
---|
102 |
|
---|
103 | class operator TSize.Add(A, B: TSize): TSize;
|
---|
104 | begin
|
---|
105 | Result.Width := A.Width + B.Width;
|
---|
106 | Result.Height := A.Height + B.Height;
|
---|
107 | end;
|
---|
108 |
|
---|
109 | class operator TSize.Subtract(A, B: TSize): TSize;
|
---|
110 | begin
|
---|
111 | Result.Width := A.Width - B.Width;
|
---|
112 | Result.Height := A.Height - B.Height;
|
---|
113 | end;
|
---|
114 |
|
---|
115 | class operator TSize.Equal(A, B: TSize): Boolean;
|
---|
116 | begin
|
---|
117 | Result := (A.Width = B.Width) and (A.Height = B.Height);
|
---|
118 | end;
|
---|
119 |
|
---|
120 |
|
---|
121 | end.
|
---|
122 |
|
---|