Debian Codegraph @

src/ui/castlecontrols_crosshair.inc

raw
1 {%MainUnit castlecontrols.pas}
2 {
3 Copyright 2010-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 { Possible crosshair shape, for @link(TCastleCrosshair.Shape). }
20 TCastleCrosshairShape = (csCross, csCrossRect);
21
22 { Display a simple crosshair in the middle of the parent control. }
23 TCastleCrosshair = class(TCastleUserInterface)
24 strict private
25 FColor: TCastleColor;
26 FShape: TCastleCrosshairShape;
27 procedure SetShape(const Value: TCastleCrosshairShape);
28 function ImageType: TThemeImage;
29 procedure SetColor(const Value: TCastleColor);
30 public
31 const
32 DefaultSize = 16.0;
33
34 constructor Create(AOwner: TComponent); override;
35 destructor Destroy; override;
36 procedure Render; override;
37 function PropertySections(const PropertyName: String): TPropertySections; override;
38
39 { Color tint of the crosshair. This simply multiplies the crosshair RGBA image.
40 By default this is opaque white. }
41 property Color: TCastleColor read FColor write SetColor;
42 published
43 property Shape: TCastleCrosshairShape read FShape write SetShape default csCross;
44
45 { By default, crosshair is centered. }
46 property HorizontalAnchorSelf default hpMiddle;
47 property HorizontalAnchorParent default hpMiddle;
48 property VerticalAnchorSelf default vpMiddle;
49 property VerticalAnchorParent default vpMiddle;
50
51 {$ifdef FPC}
52 property Width default DefaultSize;
53 property Height default DefaultSize;
54 {$endif}
55
56 {$define read_interface_class}
57 {$I auto_generated_persistent_vectors/tcastlecrosshair_persistent_vectors.inc}
58 {$undef read_interface_class}
59 end;
60
61 {$endif read_interface}
62
63 {$ifdef read_implementation}
64
65 { TCastleCrosshair ---------------------------------------------------- }
66
67 constructor TCastleCrosshair.Create(AOwner: TComponent);
68 begin
69 inherited;
70 FShape := csCross;
71 FColor := White;
72 Anchor(hpMiddle);
73 Anchor(vpMiddle);
74 Width := DefaultSize;
75 Height := DefaultSize;
76
77 {$define read_implementation_constructor}
78 {$I auto_generated_persistent_vectors/tcastlecrosshair_persistent_vectors.inc}
79 {$undef read_implementation_constructor}
80 end;
81
82 destructor TCastleCrosshair.Destroy;
83 begin
84 {$define read_implementation_destructor}
85 {$I auto_generated_persistent_vectors/tcastlecrosshair_persistent_vectors.inc}
86 {$undef read_implementation_destructor}
87 inherited;
88 end;
89
90 procedure TCastleCrosshair.SetShape(const Value: TCastleCrosshairShape);
91 begin
92 if FShape <> Value then
93 begin
94 FShape := Value;
95 VisibleChange([chRectangle]);
96 end;
97 end;
98
99 function TCastleCrosshair.ImageType: TThemeImage;
100 begin
101 if FShape = csCrossRect then
102 Result := tiCrosshair2
103 else
104 Result := tiCrosshair1;
105 end;
106
107 procedure TCastleCrosshair.Render;
108 begin
109 inherited;
110 Theme.Draw(RenderRect, ImageType, UIScale, FColor);
111 end;
112
113 procedure TCastleCrosshair.SetColor(const Value: TCastleColor);
114 begin
115 if not TCastleColor.PerfectlyEquals(FColor, Value) then
116 begin
117 FColor := Value;
118 VisibleChange([chRender]);
119 end;
120 end;
121
122 function TCastleCrosshair.PropertySections(const PropertyName: String): TPropertySections;
123 begin
124 if ArrayContainsString(PropertyName, [
125 'ColorPersistent', 'Shape'
126 ]) then
127 Result := [psBasic]
128 else
129 Result := inherited PropertySections(PropertyName);
130 end;
131
132 {$define read_implementation_methods}
133 {$I auto_generated_persistent_vectors/tcastlecrosshair_persistent_vectors.inc}
134 {$undef read_implementation_methods}
135
136 {$endif read_implementation}