Debian Codegraph @

src/lcl/castlepropedits_rangeset.inc

raw
1 {%MainUnit castlepropedits.pas}
2 {
3 Copyright 2010-2023 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 { Editor for sets of integers. }
18
19 type
20 { Simple property editor that shows range set value as editor name. }
21 TRangeSetPropertyEditor = class (TSetPropertyEditor)
22 public
23 procedure GetProperties(Proc: TGetPropEditProc); override;
24 function OrdValueToVisualValue(OrdValue: Integer): string; override;
25 end;
26
27 { Row editor for TRangeSetPropertyEditor }
28 TRangeSetElementPropertyEditor = class (TSetElementPropertyEditor)
29 protected
30 FElementToShow: Integer;
31 public
32 constructor Create(Parent: TPropertyEditor; AElement: Integer); reintroduce;
33 function GetName: shortstring; override;
34 end;
35
36 { TRangeSetPropertyEditor ---------------------------------------------------- }
37
38 procedure TRangeSetPropertyEditor.GetProperties(Proc: TGetPropEditProc);
39 var
40 I: Integer;
41 begin
42 with GetTypeData(GetTypeData(GetPropType)^.CompType)^ do
43 for I := MinValue to MaxValue do
44 Proc(TRangeSetElementPropertyEditor.Create(Self, I));
45 end;
46
47 function TRangeSetPropertyEditor.OrdValueToVisualValue(OrdValue: Integer): String;
48
49 { Note: This is unused for now.
50 All actual usage of TRangeSetPropertyEditor is through T3DCoordsRangeSetPropertyEditor,
51 that overrides this. }
52
53 var
54 S: TIntegerSet;
55 I: Integer;
56 begin
57 Integer(S) := OrdValue;
58 Result := '';
59 for I := 0 to SizeOf(Integer) * 8 - 1 do
60 if I in S then
61 Result := SAppendPart(Result, ',', IntToStr(I));
62 Result := '[' + Result + ']';
63 end;
64
65 { TRangeSetElementPropertyEditor ---------------------------------------------------- }
66
67 constructor TRangeSetElementPropertyEditor.Create(Parent: TPropertyEditor;
68 AElement: Integer);
69 begin
70 inherited Create(Parent, AElement);
71 FElementToShow := AElement;
72 end;
73
74 function TRangeSetElementPropertyEditor.GetName: shortstring;
75 begin
76 Result := IntToStr(FElementToShow);
77 end;