-
-
Notifications
You must be signed in to change notification settings - Fork 156
Expand file tree
/
Copy pathcastlecontrols_imagecontrol.inc
More file actions
764 lines (630 loc) · 24.8 KB
/
castlecontrols_imagecontrol.inc
File metadata and controls
764 lines (630 loc) · 24.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
{%MainUnit castlecontrols.pas}
{
Copyright 2010-2023 Michalis Kamburelis.
This file is part of "Castle Game Engine".
"Castle Game Engine" is free software; see the file COPYING.txt,
included in this distribution, for details about the copyright.
"Castle Game Engine" is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
----------------------------------------------------------------------------
}
{$ifdef read_interface}
{ Indicate stretching approach for @link(TCastleImageControl.ProportionalScaling). }
TProportionalScaling = (
{ Adjust to the requested area, ignoring proportions. }
psNone,
{ Adjust to the requested area, honoring proportions, such that the image
may be larger than the requested area. }
psEnclose,
{ Adjust to the requested area, honoring proportions, such that the image
may be smaller than the requested area. }
psFit
);
{ Image control.
Size is automatically adjusted to the image size, if Stretch is @false (default).
You should set TCastleImageControl.Left, TCastleImageControl.Bottom properties,
and load your image by setting TCastleImageControl.Url property
or straight TCastleImageControl.Image.
We automatically use alpha test or alpha blending based
on loaded image alpha channel (see @link(TDrawableImage.Alpha)).
You can influence this by @link(AlphaChannel) property. }
TCastleImageControl = class(TCastleUserInterface)
strict private
FStretch: boolean;
FProportionalScaling: TProportionalScaling;
FDetectScaleFromUrl: Boolean;
FContent: TCastleImagePersistent;
{ Properties simply synchronized with the same properties of FContent. }
function GetUrl: String;
function GetDrawableImage: TDrawableImage;
function GetOwnsDrawableImage: Boolean;
function GetImage: TEncodedImage;
function GetOwnsImage: Boolean;
function GetRotation: Single;
function GetRotationCenter: TVector2;
function GetAlphaChannel: TAutoAlphaChannel;
function GetColor: TCastleColor;
function GetClip: boolean;
function GetClipLine: TVector3;
function GetCustomShader: TGLSLProgram;
function GetFlipVertical: Boolean;
function GetFlipHorizontal: Boolean;
function GetSmoothScaling: Boolean;
function GetCache: Boolean;
function GetProtectedSides: TBorder;
function GetRegion: TFloatRectangle;
procedure SetUrl(const Value: String);
procedure SetDrawableImage(const Value: TDrawableImage);
procedure SetOwnsDrawableImage(const Value: Boolean);
procedure SetImage(const Value: TEncodedImage);
procedure SetOwnsImage(const Value: Boolean);
procedure SetRotation(const Value: Single);
procedure SetRotationCenter(const Value: TVector2);
procedure SetAlphaChannel(const Value: TAutoAlphaChannel);
procedure SetColor(const Value: TCastleColor);
procedure SetClip(const Value: boolean);
procedure SetClipLine(const Value: TVector3);
procedure SetRegion(const Value: TFloatRectangle);
procedure SetCustomShader(const Value: TGLSLProgram);
procedure SetFlipVertical(const Value: Boolean);
procedure SetFlipHorizontal(const Value: Boolean);
procedure SetSmoothScaling(const Value: boolean);
procedure SetCache(const Value: boolean);
{ Properties maintained for backward compatibility. }
function GetCenterX: Single;
function GetCenterY: Single;
procedure SetCenterX(const Value: Single);
procedure SetCenterY(const Value: Single);
function GetBlending: boolean;
procedure SetBlending(const Value: boolean);
function GetCorners: TVector4Integer;
procedure SetCorners(const Value: TVector4Integer);
procedure SetStretch(const Value: boolean);
procedure SetProportionalScaling(const Value: TProportionalScaling);
function GetProportional: boolean;
procedure SetProportional(const Value: boolean);
procedure SetDetectScaleFromUrl(const Value: Boolean);
procedure ContentChanged(Sender: TObject);
protected
procedure PreferredSize(var PreferredWidth, PreferredHeight: Single); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Render; override;
procedure GLContextOpen; override;
procedure EditorAllowResize(
out ResizeWidth, ResizeHeight: Boolean; out Reason: String); override;
function PropertySections(const PropertyName: String): TPropertySections; override;
{ Image contents, or @nil if none. You can set it by setting @link(Url),
or by setting this property directly,
or by setting @link(DrawableImage).
Note that by default the TEncodedImage instance assigned here is owned
by this component (see @link(OwnsImage)).
So if you set this property to your custom TEncodedImage instance you should
leave memory management of this instance to this component.
You can either create a copy by TEncodedImage.MakeCopy
if you want to give here only a copy, or you can change @link(OwnsImage)
to @false.
It is allowed to modify the contents or even size of this image.
Just make sure to call @link(ImageChanged) after the modifications
are done to update the rendered image (and possibly
the UI control size, e.g. in case TCastleImageControl
uses this TCastleImagePersistent, and TCastleImageControl.Stretch=false).
@seealso TCastleImagePersistent.Image }
property Image: TEncodedImage read GetImage write SetImage;
{ Whether the memory management of assigned @link(Image) is automatic.
See @link(Image) documentation for details.
Note that setting @link(Url) changes @link(Image),
and changes OwnsImage unconditionally to @true.
Note that setting @link(DrawableImage) changes @link(Image) too,
and changes OwnsImage to the value present in @link(TDrawableImage.OwnsImage).
@seealso TCastleImagePersistent.OwnsImage }
property OwnsImage: boolean read GetOwnsImage write SetOwnsImage default true;
{ Image used for drawing. Never @nil.
Always @link(TDrawableImage.Image) equals our @link(Image).
Usually you do not want to change this property.
You can change @link(Url), or @link(Image), and the drawable
image will reflect this.
But there are good use-cases to change the @link(DrawableImage)
directly: e.g. you can use fast image-to-image
drawing using @link(TDrawableImage.DrawFrom).
Or you can set a new instance of TDrawableImage here.
Be sure to adjust @link(OwnsDrawableImage) as needed.
Note that when OpenGL(ES) context is lost and recreated (which can
happen at any moment on mobile devices), the contents of this are
reinitialized from @link(Image).
@seealso TCastleImagePersistent.DrawableImage }
property DrawableImage: TDrawableImage read GetDrawableImage write SetDrawableImage;
{ Whether we should automatically free the @link(DrawableImage) instance.
Note that this is restored to @true when we need to recreate the
TDrawableImage internally, e.g. when @link(Image) instance changed
(when even size changed, we have to recreate TDrawableImage).
@seealso TCastleImagePersistent.OwnsDrawableImage }
property OwnsDrawableImage: boolean read GetOwnsDrawableImage write SetOwnsDrawableImage default true;
{ If you modified the @link(Image) contents
(colors, or maybe even image size) you need to call this.
@seealso TCastleImagePersistent.ImageChanged }
procedure ImageChanged;
{ Color tint of the image. This simply multiplies the image RGBA components,
just like @link(TDrawableImage.Color). By default this is opaque white,
which means that image colors are unchanged.
@seealso TCastleImagePersistent.Color }
property Color: TCastleColor read GetColor write SetColor;
{$ifdef FPC}
{ Corners and edges of the image that are not stretched even
when @link(Stretch) is used.
See @link(TDrawableImage.Draw3x3) for the details how such drawing works. }
property Corners: TVector4Integer read GetCorners write SetCorners;
deprecated 'use ProtectedSides';
{ X coordinate of the center of rotation. Value from 0 to 1. Default value 0.5. }
property CenterX: Single read GetCenterX write SetCenterX default 0.5;
deprecated 'use RotationCenter';
{ Y coordinate of the center of rotation. Value from 0 to 1. Default value 0.5. }
property CenterY: Single read GetCenterY write SetCenterY default 0.5;
deprecated 'use RotationCenter';
{$endif}
{ Center of rotation.
Expressed as a fraction within the drawn ScreenRectangle,
(0,0) means bottom-left corner, (1,1) means top-right corner.
Default (0.5,0.5).
@seealso TCastleImagePersistent.RotationCenter }
property RotationCenter: TVector2 read GetRotationCenter write SetRotationCenter;
{ If @link(Clip), this is the line equation used to determine whether
we clip the given pixel. Given a line (A, B, C) and pixel (x, y),
the pixel is clipped (rejected) if @code(A * x + B * y + C < 0).
The equation is calculated in the coordinates in which image
X, Y spans from (0, 0) (bottom-left) to (1, 1) (top-right).
For example ClipLine = (1, 0, -0.5) means that we reject pixels
where @code(1 * x + 0 * y - 0.5 < 0). In other words,
we reject pixels where @code(x < 0.5), so we reject the left half of the image.
@seealso TCastleImagePersistent.ClipLine }
property ClipLine: TVector3 read GetClipLine write SetClipLine;
{ Image region to which we should limit the display.
Empty (following @link(TFloatRectangle.Empty)) means using the whole image. }
property Region: TFloatRectangle read GetRegion write SetRegion;
{ Custom GLSL shading code.
See TDrawableImage.CustomShader for explanation.
@seealso TCastleImagePersistent.CustomShader }
property CustomShader: TGLSLProgram read GetCustomShader write SetCustomShader;
{$ifdef FPC}
property Blending: boolean read GetBlending write SetBlending stored false;
deprecated 'use AlphaChannel';
property Proportional: boolean read GetProportional write SetProportional stored false default false;
deprecated 'use ProportionalScaling';
property FileName: string read GetUrl write SetUrl stored false;
deprecated 'use Url';
{$endif}
published
{ Image contents to display. }
property Content: TCastleImagePersistent read FContent;
{ URL of the image.
Set this to load a new image, you can set to '' to clear the image.
@seealso TCastleImagePersistent.Url }
property Url: String read GetUrl write SetUrl stored false;
{ How to treat alpha channel of the assigned image.
By default, this is acAuto, which means that image contents
together with current @link(Color) determine how
the alpha of image is treated (opaque, alpha test, alpha blending).
Set this to force specific treatment.
@seealso TCastleImagePersistent.AlphaChannel }
property AlphaChannel: TAutoAlphaChannel
read GetAlphaChannel write SetAlphaChannel stored false default acAuto;
{ Is the image scaling mode smooth (bilinear filtering)
or not (nearest-pixel filtering).
See @link(TDrawableImage.SmoothScaling).
@seealso TCastleImagePersistent.SmoothScaling }
property SmoothScaling: boolean
read GetSmoothScaling write SetSmoothScaling stored false default true;
{ How does the loaded image size affect the size of the image control.
@unorderedList(
@item(
When @link(FullSize) or @link(AutoSizeToChildren) is @true,
then the value of @link(Stretch), and loaded image size, are ignored.
When @link(AutoSizeToChildren),
the image is always stretched to surround the children.
When @link(FullSize),
the image is always stretched to fill the parent.
Otherwise:
)
@item(If Stretch = @false (default), then
the displayed size corresponds to the underlying image size.)
@item(If Stretch = @true, the image will be stretched to fill
the requested area. The property
@link(ProportionalScaling) determines how the image will
be adjusted to fit the requested size
(by @link(Width), @link(WidthFraction), @link(Height), @link(HeightFraction)).
@definitionList(
@itemLabel psNone
@item(The image will be scaled to exactly fill
the requested Width and Height
(without paying attention to the aspect ratio of the image).
This is the case when you fully force the displayed size
and position, regardless of image size. Displayed image will
always exactly fill the requested area.)
@itemLabel psFit
@item(The image will be proportionally scaled to fit within
the requested Width and Height.
If the aspect ratio of image
will be different than aspect ratio of Width/Height, the scaled image
will be centered inside the Width/Height.)
@itemLabel psEnclose
@item(The image will be proportionally scaled to enclode
the requested Width and Height.
If the aspect ratio of image
will be different than aspect ratio of Width/Height, the scaled image
will be larger then the requested area.)
)
)
)
@groupBegin }
property Stretch: boolean read FStretch write SetStretch default false;
property ProportionalScaling: TProportionalScaling
read FProportionalScaling write SetProportionalScaling default psNone;
{ @groupEnd }
{ If @true, the image is loaded and freed using a cache.
This can save memory and loading time a lot, if you reuse the same
URL in many TCastleImageControl instances.
@seealso TCastleImagePersistent.Cache }
property Cache: boolean read GetCache write SetCache stored false default true;
{ Display image horizontally flipped.
@seealso TCastleImagePersistent.FlipHorizontal }
property FlipHorizontal: Boolean read GetFlipHorizontal write SetFlipHorizontal
stored false default false;
{ Display image vertically flipped.
@seealso TCastleImagePersistent.FlipVertical }
property FlipVertical: Boolean read GetFlipVertical write SetFlipVertical
stored false default false;
{ Corners and edges of the image that are protected from scaling distortion
when @link(Stretch) is used.
We use the 9-slicing algorithm,
described at @link(TDrawableImage.Draw3x3)
and https://en.wikipedia.org/wiki/9-slice_scaling to scale the image.
@seealso TCastleImagePersistent.ProtectedSides }
property ProtectedSides: TBorder read GetProtectedSides stored false;
{ Set this to auto-detect that image is scaled compared to it's desired size.
This detects URL endings like '[email protected]', and we will automatically adjust
to it (the size determined by AutoSize will be actually 2x smaller than
the PNG size).
Preparing images at a 2x or 4x larger size than "desired" is a useful trick
when using UI scaling, when you want the image to look good at various scales. }
property DetectScaleFromUrl: Boolean
read FDetectScaleFromUrl write SetDetectScaleFromUrl default false;
{ Rotation in radians. Default value 0.
@seealso TCastleImagePersistent.Rotation }
property Rotation: Single read GetRotation write SetRotation stored false {$ifdef FPC}default 0{$endif};
{ Clip the image by an arbitrary 2D line defined in @link(ClipLine).
@seealso TCastleImagePersistent.Clip }
property Clip: boolean read GetClip write SetClip stored false default false;
{$define read_interface_class}
{$I auto_generated_persistent_vectors/tcastleimagecontrol_persistent_vectors.inc}
{$undef read_interface_class}
end;
{$endif read_interface}
{$ifdef read_implementation}
{ TCastleImageControl -------------------------------------------------------- }
constructor TCastleImageControl.Create(AOwner: TComponent);
begin
inherited;
FContent := TCastleImagePersistent.Create;
FContent.OnChange := {$ifdef FPC}@{$endif}ContentChanged;
{$define read_implementation_constructor}
{$I auto_generated_persistent_vectors/tcastleimagecontrol_persistent_vectors.inc}
{$undef read_implementation_constructor}
end;
destructor TCastleImageControl.Destroy;
begin
FreeAndNil(FContent);
{$define read_implementation_destructor}
{$I auto_generated_persistent_vectors/tcastleimagecontrol_persistent_vectors.inc}
{$undef read_implementation_destructor}
inherited;
end;
function TCastleImageControl.GetProtectedSides: TBorder;
begin
Result := FContent.ProtectedSides;
end;
function TCastleImageControl.GetRegion: TFloatRectangle;
begin
Result := FContent.Region;
end;
function TCastleImageControl.GetSmoothScaling: Boolean;
begin
Result := FContent.SmoothScaling;
end;
procedure TCastleImageControl.SetSmoothScaling(const Value: boolean);
begin
FContent.SmoothScaling := Value;
end;
function TCastleImageControl.GetClip: boolean;
begin
Result := FContent.Clip;
end;
procedure TCastleImageControl.SetClip(const Value: boolean);
begin
FContent.Clip := Value;
end;
function TCastleImageControl.GetClipLine: TVector3;
begin
Result := FContent.ClipLine;
end;
procedure TCastleImageControl.SetClipLine(const Value: TVector3);
begin
FContent.ClipLine := Value;
end;
procedure TCastleImageControl.SetRegion(const Value: TFloatRectangle);
begin
FContent.Region := Value;
end;
function TCastleImageControl.GetRotation: Single;
begin
Result := FContent.Rotation;
end;
procedure TCastleImageControl.SetRotation(const Value: Single);
begin
FContent.Rotation := Value;
end;
function TCastleImageControl.GetRotationCenter: TVector2;
begin
Result := FContent.RotationCenter;
end;
procedure TCastleImageControl.SetRotationCenter(const Value: TVector2);
begin
FContent.RotationCenter := Value;
end;
procedure TCastleImageControl.GLContextOpen;
begin;
inherited;
{ Calling this is not strictly necessary. It means we load the OpenGL
resources *now*, instead of on-demand right before 1st render. }
FContent.DrawableImage.PrepareResources;
end;
procedure TCastleImageControl.Render;
begin
inherited;
FContent.DrawUiBegin(UIScale);
FContent.Draw(RenderRect);
FContent.DrawUiEnd;
end;
procedure TCastleImageControl.PreferredSize(var PreferredWidth, PreferredHeight: Single);
var
ImageWidth, ImageHeight: Single;
begin
inherited;
ImageWidth := FContent.Width;
ImageHeight := FContent.Height;
if FDetectScaleFromUrl and (FContent.ScaleFromUrl <> 1) then
begin
ImageWidth := ImageWidth / FContent.ScaleFromUrl;
ImageHeight := ImageHeight / FContent.ScaleFromUrl;
end;
if not Stretch then
begin
PreferredWidth := ImageWidth * UIScale;
PreferredHeight := ImageHeight * UIScale;
end else
if (ProportionalScaling in [psFit, psEnclose]) and
(ImageWidth <> 0) and
(ImageHeight <> 0) then
begin
if (ProportionalScaling = psFit) =
(PreferredWidth / PreferredHeight >
ImageWidth / ImageHeight) then
begin
PreferredWidth := ImageWidth * PreferredHeight / ImageHeight;
end else
begin
PreferredHeight := ImageHeight * PreferredWidth / ImageWidth;
end;
end;
end;
procedure TCastleImageControl.EditorAllowResize(
out ResizeWidth, ResizeHeight: Boolean; out Reason: String);
begin
inherited;
if not Stretch then
begin
ResizeWidth := false;
ResizeHeight := false;
Reason := SAppendPart(Reason, NL, 'Turn on "TCastleImageControl.Stretch" to change size.');
end;
end;
procedure TCastleImageControl.ContentChanged(Sender: TObject);
begin
VisibleChange([chRectangle]);
end;
procedure TCastleImageControl.ImageChanged;
begin
FContent.ImageChanged;
end;
function TCastleImageControl.GetAlphaChannel: TAutoAlphaChannel;
begin
Result := FContent.AlphaChannel;
end;
procedure TCastleImageControl.SetAlphaChannel(const Value: TAutoAlphaChannel);
begin
FContent.AlphaChannel := Value;
end;
function TCastleImageControl.GetBlending: boolean;
begin
Result := AlphaChannel <> acBlending;
end;
procedure TCastleImageControl.SetBlending(const Value: boolean);
begin
if Value then
AlphaChannel := acBlending
else
AlphaChannel := acTest;
end;
procedure TCastleImageControl.SetStretch(const Value: boolean);
begin
if FStretch <> Value then
begin
FStretch := Value;
VisibleChange([chRectangle]);
end;
end;
function TCastleImageControl.GetProportional: boolean;
begin
Result := ProportionalScaling <> psNone;
end;
procedure TCastleImageControl.SetProportional(const Value: boolean);
begin
if Value then
ProportionalScaling := psFit
else
ProportionalScaling := psNone;
end;
procedure TCastleImageControl.SetProportionalScaling(const Value: TProportionalScaling);
begin
if FProportionalScaling <> Value then
begin
FProportionalScaling := Value;
VisibleChange([chRectangle]);
end;
end;
function TCastleImageControl.GetUrl: String;
begin
Result := FContent.Url;
end;
procedure TCastleImageControl.SetUrl(const Value: String);
begin
FContent.Url := Value;
end;
function TCastleImageControl.GetColor: TCastleColor;
begin
Result := FContent.Color;
end;
procedure TCastleImageControl.SetColor(const Value: TCastleColor);
begin
FContent.Color := Value;
end;
function TCastleImageControl.GetCustomShader: TGLSLProgram;
begin
Result := FContent.CustomShader;
end;
procedure TCastleImageControl.SetCustomShader(const Value: TGLSLProgram);
begin
FContent.CustomShader := Value;
end;
function TCastleImageControl.GetDrawableImage: TDrawableImage;
begin
Result := FContent.DrawableImage;
end;
procedure TCastleImageControl.SetDrawableImage(const Value: TDrawableImage);
begin
FContent.DrawableImage := Value;
end;
function TCastleImageControl.GetOwnsDrawableImage: Boolean;
begin
Result := FContent.OwnsDrawableImage;
end;
procedure TCastleImageControl.SetOwnsDrawableImage(const Value: Boolean);
begin
FContent.OwnsDrawableImage := Value;
end;
function TCastleImageControl.GetImage: TEncodedImage;
begin
Result := FContent.Image;
end;
procedure TCastleImageControl.SetImage(const Value: TEncodedImage);
begin
FContent.Image := Value;
end;
function TCastleImageControl.GetOwnsImage: Boolean;
begin
Result := FContent.OwnsImage;
end;
procedure TCastleImageControl.SetOwnsImage(const Value: Boolean);
begin
FContent.OwnsImage := Value;
end;
function TCastleImageControl.GetFlipVertical: Boolean;
begin
Result := FContent.FlipVertical;
end;
procedure TCastleImageControl.SetFlipVertical(const Value: Boolean);
begin
FContent.FlipVertical := Value;
end;
function TCastleImageControl.GetFlipHorizontal: Boolean;
begin
Result := FContent.FlipHorizontal;
end;
procedure TCastleImageControl.SetFlipHorizontal(const Value: Boolean);
begin
FContent.FlipHorizontal := Value;
end;
function TCastleImageControl.GetCache: Boolean;
begin
Result := FContent.Cache;
end;
procedure TCastleImageControl.SetCache(const Value: boolean);
begin
FContent.Cache := Value;
end;
procedure TCastleImageControl.SetDetectScaleFromUrl(const Value: Boolean);
begin
if FDetectScaleFromUrl <> Value then
begin
FDetectScaleFromUrl := Value;
VisibleChange([chRender]);
end;
end;
function TCastleImageControl.GetCorners: TVector4Integer;
begin
Result := Vector4Integer(
Round(ProtectedSides.TotalTop),
Round(ProtectedSides.TotalRight),
Round(ProtectedSides.TotalBottom),
Round(ProtectedSides.TotalLeft)
);
end;
procedure TCastleImageControl.SetCorners(const Value: TVector4Integer);
begin
ProtectedSides.AllSides := 0;
ProtectedSides.Top := Value[0];
ProtectedSides.Right := Value[1];
ProtectedSides.Bottom := Value[2];
ProtectedSides.Left := Value[3];
end;
function TCastleImageControl.PropertySections(
const PropertyName: String): TPropertySections;
begin
if ArrayContainsString(PropertyName, ['Url', 'Stretch', 'ProportionalScaling',
'ColPersistent', 'SmoothScaling', 'AlphaChannel', 'FlipHizontal',
'FlipVertical', 'ProtectedSides', 'RegionPersistent',
'Rotation', 'Content'
]) then
Result := [psBasic]
else
Result := inherited PropertySections(PropertyName);
end;
function TCastleImageControl.GetCenterX: Single;
begin
Result := RotationCenter.X;
end;
function TCastleImageControl.GetCenterY: Single;
begin
Result := RotationCenter.Y;
end;
procedure TCastleImageControl.SetCenterX(const Value: Single);
var
V: TVector2;
begin
V := RotationCenter;
V.X := Value;
RotationCenter := V;
end;
procedure TCastleImageControl.SetCenterY(const Value: Single);
var
V: TVector2;
begin
V := RotationCenter;
V.Y := Value;
RotationCenter := V;
end;
{$define read_implementation_methods}
{$I auto_generated_persistent_vectors/tcastleimagecontrol_persistent_vectors.inc}
{$undef read_implementation_methods}
{$endif read_implementation}