Statistics
| Branch: | Tag: | Revision:

root / URectList.pas

History | View | Annotate | Download (2.3 kB)

1
(*
2
 * CDDL HEADER START
3
 *
4
 * The contents of this file are subject to the terms of the
5
 * Common Development and Distribution License, Version 1.0 only
6
 * (the "License").  You may not use this file except in compliance
7
 * with the License.
8
 *
9
 * You can obtain a copy of the license at
10
 * http://www.opensource.org/licenses/cddl1.php.
11
 * See the License for the specific language governing permissions
12
 * and limitations under the License.
13
 *
14
 * When distributing Covered Code, include this CDDL HEADER in each
15
 * file and include the License file at
16
 * http://www.opensource.org/licenses/cddl1.php.  If applicable,
17
 * add the following below this CDDL HEADER, with the fields enclosed
18
 * by brackets "[]" replaced with your own identifying * information:
19
 *      Portions Copyright [yyyy] [name of copyright owner]
20
 *
21
 * CDDL HEADER END
22
 *
23
 *
24
 *      Portions Copyright 2008 Andreas Schneider
25
 *)
26
unit URectList;
27
28
{$mode objfpc}{$H+}
29
30
interface
31
32
uses
33
  SysUtils,Classes;
34
  
35
type
36
  TRectList = class(TList)
37
  protected
38
    function GetRect(AIndex: Integer): TRect;
39
    procedure SetRect(AIndex: Integer; ARect: TRect);
40
  public
41
    function Add(ALeft, ATop, ARight, ABottom: Integer): Integer;
42
    procedure Clear; override;
43
    procedure Delete(AIndex: Integer); reintroduce;
44
    property Rects[Index: Integer]: TRect read GetRect write SetRect;
45
  end;
46
  PRect = ^TRect;
47
48
implementation
49
50
{ TRectList }
51
52
function TRectList.GetRect(AIndex: Integer): TRect;
53
begin
54
  Result := PRect(Items[AIndex])^;
55
end;
56
57
procedure TRectList.SetRect(AIndex: Integer; ARect: TRect);
58
var
59
  internalRect: PRect;
60
begin
61
  internalRect := Items[AIndex];
62
  System.Move(ARect, internalRect^, SizeOf(TRect));
63
end;
64
65
function TRectList.Add(ALeft, ATop, ARight, ABottom: Integer): Integer;
66
var
67
  internalRect: PRect;
68
begin
69
  new(internalRect);
70
  internalRect^.Left := ALeft;
71
  internalRect^.Top := ATop;
72
  internalRect^.Right := ARight;
73
  internalRect^.Bottom := ABottom;
74
  Result := inherited Add(internalRect);
75
end;
76
77
procedure TRectList.Clear;
78
var
79
  i: Integer;
80
  internalRect: PRect;
81
begin
82
  for i := 0 to Count - 1 do
83
  begin
84
    internalRect := Items[i];
85
    dispose(internalRect);
86
  end;
87
  inherited;
88
end;
89
90
procedure TRectList.Delete(AIndex: Integer);
91
var
92
  internalRect: PRect;
93
begin
94
  internalRect := Items[AIndex];
95
  dispose(internalRect);
96
  inherited Delete(AIndex);
97
end;
98
99
end.
100