Debian Codegraph @

src/transform/castletransform_transformlist.inc

raw
1 {%MainUnit castletransform.pas}
2 {
3 Copyright 2017-2022 Michalis Kamburelis.
4
5 This file is part of "Castle Game Engine".
6
7 "Castle Game Engine" is free software; see the file COPYING.txt,
8 included in this distribution, for details about the copyright.
9
10 "Castle Game Engine" is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
14 ----------------------------------------------------------------------------
15 }
16
17 {$ifdef read_interface}
18
19 //type
20 { List of TCastleTransform instances.
21 This inherits from TCastleObjectList, getting many
22 features like TList notification mechanism. }
23 TCastleTransformList = class(TCastleObjectList)
24 private
25 { Note: Using this class with FOwner <> nil is only for internal purposes. }
26 FOwner: TCastleTransform;
27 function GetItem(const I: Integer): TCastleTransform;
28 procedure SetItem(const I: Integer; const Item: TCastleTransform);
29 { TCastleTransform instance that owns this list.
30 May be @nil, for example when this list is used by TRayCollision. }
31 property Owner: TCastleTransform read FOwner;
32
33 procedure SortBackToFront2D;
34 deprecated 'use TCastleViewport.BlendingSort to sort objects for blending';
35 public
36 procedure Notify(Ptr: Pointer; Action: TListNotification); override;
37 property Items[const I: Integer]: TCastleTransform read GetItem write SetItem; default;
38
39 function First: TCastleTransform;
40 function Last: TCastleTransform;
41 end;
42
43 {$endif read_interface}
44
45 {$ifdef read_implementation}
46
47 function CompareBackToFront2D(A, B: Pointer): Integer;
48 begin
49 {$warnings off} // using deprecated in deprecated
50 Result := TBox3D.CompareBackToFront2D(TCastleTransform(A).BoundingBox, TCastleTransform(B).BoundingBox);
51 {$warnings on}
52 end;
53
54 { TCastleTransformList ------------------------------------------------------------ }
55
56 procedure TCastleTransformList.Notify(Ptr: Pointer; Action: TListNotification);
57 var
58 B: TCastleTransform;
59 begin
60 inherited;
61
62 if Owner <> nil then
63 begin
64 B := TCastleTransform(Ptr);
65
66 case Action of
67 lnAdded: B.AddParent(Owner);
68 lnExtracted, lnDeleted: B.RemoveParent(Owner);
69 {$ifndef COMPILER_CASE_ANALYSIS}
70 else raise EInternalError.Create('TCastleTransformList.Notify action?');
71 {$endif}
72 end;
73 end;
74 end;
75
76 function TCastleTransformList.GetItem(const I: Integer): TCastleTransform;
77 begin
78 Result := TCastleTransform(inherited Items[I]);
79 end;
80
81 procedure TCastleTransformList.SetItem(const I: Integer; const Item: TCastleTransform);
82 begin
83 inherited Items[I] := Item;
84 end;
85
86 function TCastleTransformList.First: TCastleTransform;
87 begin
88 Result := (inherited First) as TCastleTransform;
89 end;
90
91 function TCastleTransformList.Last: TCastleTransform;
92 begin
93 Result := (inherited Last) as TCastleTransform;
94 end;
95
96 procedure TCastleTransformList.SortBackToFront2D;
97 begin
98 Sort(@CompareBackToFront2D);
99 end;
100
101 {$endif read_implementation}