2
// This unit is part of the GLScene Engine https://github.com/glscene
5
In GL windows management classes and structures
8
15/04/11 - Yar - Added TGLGuiLayout.Assign
9
16/03/11 - Yar - Fixes after emergence of GLMaterialEx
10
23/08/10 - Yar - Added OpenGLTokens to uses, replaced OpenGL1x functions to OpenGLAdapter
11
11/06/10 - YP - Link GUI elements to their parent
12
06/06/10 - Yar - Fixed warnings
13
30/03/07 - DaStr - Added $I GLScene.inc, cosmetic changes
14
17/02/07 - DaStr - TGLGuiElement.Create - vectors creation fixed
15
Changed some types from TGLCoordinates to TGLCoordinates2
16
Removed some empty lines
17
16/12/05 - DK - Removed GuiSkinEditorFormUnit dependancy
18
30/11/04 - DB - Fixed memory leaks (thanks dikoe Kenguru)
19
16/07/03 - EG - TGLBaseGuiObject moved in along with RecursiveVisible mechanism
20
25/11/02 - EG - TGLGuiLayout.Clear fix (Sternas Stefanos)
21
06/09/02 - JAJ - Updated and added to CVS..
22
01/06/02 - JAJ - Base Unit built..
34
GLScene, GLBitmapFont, GLMaterial, GLCrossPlatform, OpenGLTokens, GLContext,
35
GLPersistentClasses, GLVectorGeometry, GLCoordinates, GLBaseClasses;
39
TGLBaseGuiObject = class(TGLBaseSceneObject)
41
FRecursiveVisible: Boolean;
46
// self notification on hide. Also notifies children.
47
procedure NotifyHide; dynamic;
48
// child notification on show. Also notifies children.
49
procedure NotifyShow; dynamic;
51
procedure SetLeft(const Value: TGLFloat);
52
function GetLeft: TGLFloat;
53
procedure SetTop(const Value: TGLFloat);
54
function GetTop: TGLFloat;
55
procedure SetWidth(const val: Single);
56
procedure SetHeight(const val: Single);
57
procedure SetVisible(aValue: Boolean); override;
60
constructor Create(AOwner: TComponent); override;
62
procedure AddChild(AChild: TGLBaseSceneObject); override;
63
procedure Insert(aIndex: Integer; aChild: TGLBaseSceneObject); override;
65
{ GuiComponent Width in 3D world units. }
66
property Width: Single read FWidth write SetWidth;
67
{ GuiComponent Height in 3D world units. }
68
property Height: Single read FHeight write SetHeight;
69
{ GuiComponent Left in 3D world units. }
70
property Left: TGLFloat read GetLeft write SetLeft;
71
{ GuiComponent Top in 3D world units. }
72
property Top: TGLFloat read GetTop write SetTop;
74
property RecursiveVisible: Boolean read FRecursiveVisible;
77
TGUIAlignments = (GLAlTopLeft, GLAlTop, GLAlTopRight, GLAlLeft, GLAlCenter,
78
GLAlRight, GLAlBottomLeft, GLAlBottom, GLAlBottomRight, GLAlBorder);
87
TGUIDrawResult = array[TGUIAlignments] of TGUIRect;
89
TGLGuiElementName = string;
90
TGLGuiElement = class(TCollectionItem)
92
FTopLeft: TGLCoordinates2;
93
FBottomRight: TGLCoordinates2;
94
FScale: TGLCoordinates2;
95
FAlign: TGUIAlignments;
96
FName: TGLGuiElementName;
98
function GetDisplayName: string; override;
99
procedure SetName(const val: TGLGuiElementName);
101
constructor Create(Collection: TCollection); override;
102
destructor Destroy; override;
103
procedure AssignTo(Dest: TPersistent); override;
105
property TopLeft: TGLCoordinates2 read FTopLeft write FTopLeft;
106
property BottomRight: TGLCoordinates2 read FBottomRight write FBottomRight;
107
property Scale: TGLCoordinates2 read FScale write FScale;
108
property Align: TGUIAlignments read FAlign write FAlign;
109
property Name: TGLGuiElementName read FName write SetName;
112
TGLGuiComponent = class;
114
TGLGuiElementList = class(TOwnedCollection)
116
FGuiComponent: TGLGuiComponent;
118
procedure SetItems(index: Integer; const val: TGLGuiElement);
119
function GetItems(index: Integer): TGLGuiElement;
121
constructor Create(AOwner: TGLGuiComponent);
122
procedure AssignTo(Dest: TPersistent); override;
124
function GetOwner: TPersistent; override;
125
function IndexOf(const Item: TGLGuiElement): Integer;
126
property Items[index: Integer]: TGLGuiElement read GetItems write SetItems;
130
TGLGuiComponentName = string;
132
TGLGuiComponentList = class;
133
TGLGuiComponent = class(TCollectionItem)
135
FElements: TGLGuiElementList;
136
FName: TGLGuiComponentName;
138
function GetDisplayName: string; override;
139
procedure SetName(const val: TGLGuiComponentName);
141
constructor Create(Collection: TCollection); override;
142
destructor Destroy; override;
143
procedure AssignTo(Dest: TPersistent); override;
144
procedure RenderToArea(X1, Y1, X2, Y2: TGLFloat; var Res: TGUIDrawResult;
145
Refresh: Boolean = True; Scale: TGLFloat = 1);
146
function GetOwnerList: TGLGuiComponentList;
147
property Owner: TGLGuiComponentList read GetOwnerList;
149
property Elements: TGLGuiElementList read FElements write FElements;
150
property Name: TGLGuiComponentName read FName write SetName;
153
TGLGuiLayout = class;
154
TGLGuiComponentList = class(TOwnedCollection)
156
FLayout: TGLGuiLayout;
158
procedure SetItems(index: Integer; const val: TGLGuiComponent);
159
function GetItems(index: Integer): TGLGuiComponent;
161
constructor Create(AOwner: TGLGuiLayout);
163
function GetOwner: TPersistent; override;
164
function FindItem(name: TGLGuiComponentName): TGLGuiComponent;
165
property Items[index: Integer]: TGLGuiComponent read GetItems write
169
TGLGuiLayout = class(TGLUpdateableComponent)
171
FBitmapFont: TGLCustomBitmapFont;
172
FMaterial: TGLMaterial;
173
FGuiComponents: TGLGuiComponentList;
175
FGuiComponentList: TList;
177
procedure Notification(AComponent: TComponent; Operation: TOperation);
180
procedure SetFileName(newName: string);
182
constructor Create(AOwner: TComponent); override;
183
destructor Destroy; override;
184
procedure Assign(Source: TPersistent); override;
186
procedure LoadFromStream(Stream: TStream);
187
procedure LoadFromFile(FN: string);
191
procedure SaveToStream(Stream: TStream);
192
procedure SaveToFile(FN: string);
193
procedure AddGuiComponent(Component: TGLUpdateableComponent);
194
procedure RemoveGuiComponent(Component: TGLUpdateableComponent);
196
procedure NotifyChange(Sender: TObject); override;
198
property BitmapFont: TGLCustomBitmapFont read FBitmapFont write FBitmapFont;
199
property Material: TGLMaterial read FMaterial write FMaterial;
200
property GuiComponents: TGLGuiComponentList read FGuiComponents write
202
property FileName: string read FFileName write SetFileName;
206
GuiNullRect: TGUIRect = (X1: 0.0; Y1: 0.0; X2: 0.0; Y2: 0.0; XTiles: 0.0;
209
function IsInRect(const R: TGUIRect; X, Y: Single): Boolean;
213
function IsInRect(const R: TGUIRect; X, Y: Single): Boolean;
216
Result := (R.X1 <= X) and (R.X2 >= X) and (R.Y1 <= Y) and (R.Y2 >= Y);
220
// ------------------ TGLBaseGuiObject ------------------
226
constructor TGLBaseGuiObject.Create(AOwner: TComponent);
228
inherited Create(AOwner);
229
FRecursiveVisible := Visible;
235
procedure TGLBaseGuiObject.SetLeft(const Value: TGLFloat);
241
if Assigned(Parent) and (Parent is TGLBaseGuiObject) then
242
NewPosX := (Parent as TGLBaseGuiObject).Position.X + Value
246
if Position.X <> NewPosX then
248
Diff := NewPosX - Position.X;
249
Position.X := NewPosX;
251
for i := 0 to Count - 1 do
252
if Children[i] is TGLBaseGuiObject then
254
(Children[i] as TGLBaseGuiObject).Left := (Children[i] as
255
TGLBaseGuiObject).Left + Diff;
263
function TGLBaseGuiObject.GetLeft: TGLFloat;
265
if Assigned(Parent) and (Parent is TGLBaseGuiObject) then
266
Result := Position.X - (Parent as TGLBaseGuiObject).Position.X
268
Result := Position.X;
274
procedure TGLBaseGuiObject.SetTop(const Value: TGLFloat);
280
if Assigned(Parent) and (Parent is TGLBaseGuiObject) then
281
NewPosY := (Parent as TGLBaseGuiObject).Position.Y + Value
285
if Position.Y <> NewPosY then
287
Diff := NewPosY - Position.Y;
288
Position.Y := NewPosY;
290
for i := 0 to Count - 1 do
291
if Children[i] is TGLBaseGuiObject then
293
(Children[i] as TGLBaseGuiObject).Top := (Children[i] as
294
TGLBaseGuiObject).Top + Diff;
302
function TGLBaseGuiObject.GetTop: TGLFloat;
304
if Assigned(Parent) and (Parent is TGLBaseGuiObject) then
305
Result := Position.Y - (Parent as TGLBaseGuiObject).Position.Y
307
Result := Position.Y;
313
procedure TGLBaseGuiObject.SetWidth(const val: TGLFloat);
315
if FWidth <> val then
325
procedure TGLBaseGuiObject.SetHeight(const val: TGLFloat);
327
if FHeight <> val then
337
procedure TGLBaseGuiObject.NotifyHide;
339
child: TGLBaseSceneObject;
342
if RecursiveVisible then
344
FRecursiveVisible := False;
345
for xc := 0 to Count - 1 do
347
child := Children[xc];
348
if child is TGLBaseGuiObject then
349
TGLBaseGuiObject(child).NotifyHide;
357
procedure TGLBaseGuiObject.NotifyShow;
359
child: TGLBaseSceneObject;
362
if not RecursiveVisible then
364
FRecursiveVisible := True;
365
for xc := 0 to Count - 1 do
367
child := Children[xc];
368
if child is TGLBaseGuiObject then
369
TGLBaseGuiObject(child).NotifyShow;
377
procedure TGLBaseGuiObject.AddChild(aChild: TGLBaseSceneObject);
380
if AChild is TGLBaseGuiObject then
382
if RecursiveVisible then
383
TGLBaseGuiObject(AChild).NotifyShow
385
TGLBaseGuiObject(AChild).NotifyHide;
392
procedure TGLBaseGuiObject.Insert(aIndex: Integer; aChild: TGLBaseSceneObject);
395
if AChild is TGLBaseGuiObject then
397
if RecursiveVisible then
398
TGLBaseGuiObject(AChild).NotifyShow
400
TGLBaseGuiObject(AChild).NotifyHide;
407
procedure TGLBaseGuiObject.SetVisible(aValue: Boolean);
409
if Visible <> aValue then
411
inherited SetVisible(aValue);
414
if Parent <> nil then
415
if Parent is TGLBaseGuiObject then
417
if TGLBaseGuiObject(Parent).RecursiveVisible then
422
if Parent.Visible then
428
if RecursiveVisible then
434
constructor TGLGuiLayout.Create(AOwner: TComponent);
436
FGuiComponentList := TList.Create;
438
FGuiComponents := TGLGuiComponentList.Create(Self);
439
FMaterial := TGLMaterial.Create(Self);
442
destructor TGLGuiLayout.Destroy;
448
FGuiComponentList.Free;
451
procedure TGLGuiLayout.SetFileName(newName: string);
453
if newName <> FFileName then
455
FFileName := newName;
456
if FileExists(FFileName) then
459
loadFromFile(FFileName);
464
procedure TGLGuiLayout.LoadFromFile(FN: string);
466
Stream: TMemoryStream;
469
Stream := TMemoryStream.Create;
471
Stream.LoadFromFile(FN);
472
LoadFromStream(stream);
479
procedure TGLGuiLayout.SaveToFile(FN: string);
481
Stream: TMemoryStream;
483
Stream := TMemoryStream.Create;
485
SaveToStream(Stream);
486
Stream.SaveToFile(FN);
493
procedure TGLGuiLayout.AddGuiComponent(Component: TGLUpdateableComponent);
495
if FGuiComponentList.IndexOf(Component) < 0 then
497
FreeNotification(Component);
498
FGuiComponentList.Add(Component);
502
procedure TGLGuiLayout.RemoveGuiComponent(Component: TGLUpdateableComponent);
504
FGuiComponentList.Remove(Component);
505
RemoveFreeNotification(Component);
508
procedure TGLGuiLayout.Assign(Source: TPersistent);
510
LLayout: TGLGuiLayout;
511
LComponent: TGLGuiComponent;
514
if Source is TGLGuiLayout then
516
LLayout := TGLGuiLayout(Source);
517
FBitmapFont := LLayout.FBitmapFont;
518
FMaterial.Assign(LLayout.Material);
519
FFileName := LLayout.FFileName;
521
for I := 0 to LLayout.FGuiComponents.Count - 1 do
523
LComponent := TGLGuiComponent(FGuiComponents.Add);
524
LLayout.FGuiComponents[I].AssignTo(LComponent);
525
LComponent.Name := LLayout.FGuiComponents[I].Name;
527
for I := 0 to FGuiComponentList.Count - 1 do
528
TGLUpdateAbleComponent(FGuiComponentList[I]).RemoveFreeNotification(Self);
529
FGuiComponentList.Assign(LLayout.FGuiComponentList);
530
for I := 0 to FGuiComponentList.Count - 1 do
531
TGLUpdateAbleComponent(FGuiComponentList[I]).FreeNotification(Self);
534
inherited; // Assigned Error
537
procedure TGLGuiLayout.Clear;
542
for XC := FGuiComponents.Count - 1 downto 0 do
544
FGuiComponents.Delete(XC);
549
procedure TGLGuiLayout.NotifyChange(Sender: TObject);
555
for XC := FGuiComponentList.Count - 1 downto 0 do
556
TGLUpdateAbleComponent(FGuiComponentList[XC]).NotifyChange(Self);
559
procedure TGLGuiLayout.LoadFromStream(Stream: TStream);
562
TmpComponent: TGLGuiComponent;
564
TmpElement: TGLGuiElement;
565
TmpAlignment: TGUIAlignments;
570
Data := TBinaryReader.Create(Stream);
573
Version := Data.ReadInteger;
577
for XC := 0 to Data.ReadInteger - 1 do
579
TmpComponent := FGuiComponents.Add as TGLGuiComponent;
580
TmpComponent.FName := Data.ReadString;
581
for YC := 0 to Data.ReadInteger - 1 do
583
TmpElement := TmpComponent.FElements.add as TGLGuiElement;
585
TmpElement.FName := Data.ReadString;
587
TmpElement.FTopLeft.X := Data.ReadFloat;
588
TmpElement.FTopLeft.Y := Data.ReadFloat;
589
TmpElement.FTopLeft.Z := Data.ReadFloat;
591
TmpElement.FBottomRight.X := Data.ReadFloat;
592
TmpElement.FBottomRight.Y := Data.ReadFloat;
593
TmpElement.FBottomRight.Z := Data.ReadFloat;
595
TmpElement.FScale.X := Data.ReadFloat;
596
TmpElement.FScale.Y := Data.ReadFloat;
597
TmpElement.FScale.Z := Data.ReadFloat;
599
for ZC := 0 to Data.ReadInteger - 1 do
601
TmpAlignment := TGUIAlignments(Data.ReadInteger);
602
TmpElement.FAlign := TmpAlignment;
612
procedure TGLGuiLayout.SaveToStream(stream: TStream);
614
TmpComponent: TGLGuiComponent;
615
Alignments, XC, YC: Integer;
616
TmpElement: TGLGuiElement;
617
TmpAlignment: TGUIAlignments;
621
Data := TBinaryWriter.Create(Stream);
623
Data.WriteInteger(1);
624
Data.WriteInteger(FGuiComponents.Count);
625
for XC := 0 to FGuiComponents.Count - 1 do
627
TmpComponent := FGuiComponents.Items[XC];
628
Data.WriteString(TmpComponent.FName);
630
Data.WriteInteger(TmpComponent.FElements.Count);
632
for YC := 0 to TmpComponent.FElements.Count - 1 do
634
TmpElement := TmpComponent.FElements.Items[YC];
636
Data.WriteString(TmpElement.FName);
638
Data.WriteFloat(TmpElement.FTopLeft.X);
639
Data.WriteFloat(TmpElement.FTopLeft.Y);
640
Data.WriteFloat(TmpElement.FTopLeft.Z);
642
Data.WriteFloat(TmpElement.FBottomRight.X);
643
Data.WriteFloat(TmpElement.FBottomRight.Y);
644
Data.WriteFloat(TmpElement.FBottomRight.Z);
646
Data.WriteFloat(TmpElement.FScale.X);
647
Data.WriteFloat(TmpElement.FScale.Y);
648
Data.WriteFloat(TmpElement.FScale.Z);
651
for TmpAlignMent := GLAlTopLeft to GLAlBorder do
653
if TmpAlignMent = TmpElement.FAlign then
657
Data.WriteInteger(Alignments);
659
for TmpAlignMent := GLAlTopLeft to GLAlBorder do
661
if TmpAlignMent = TmpElement.FAlign then
662
Data.WriteInteger(Integer(TmpAlignMent));
671
constructor TGLGuiComponentList.Create(AOwner: TGLGuiLayout);
673
inherited Create(AOwner, TGLGuiComponent);
677
function TGLGuiComponentList.GetOwner: TPersistent;
682
procedure TGLGuiComponentList.SetItems(index: Integer; const val:
685
inherited Items[index] := val;
688
function TGLGuiComponentList.FindItem(name: TGLGuiComponentName):
697
for XC := 0 to Count - 1 do
700
if gc.FName = Name then
708
function TGLGuiComponentList.GetItems(index: Integer): TGLGuiComponent;
710
Result := TGLGuiComponent(inherited Items[index]);
713
procedure TGLGuiComponent.RenderToArea(X1, Y1, X2, Y2: TGLFloat; var Res:
714
TGUIDrawResult; Refresh: Boolean = True; Scale: TGLFloat = 1);
717
ThisElement: TGLGuiElement;
719
Len1, Len2: TGLFloat;
720
Layout: TGLGuiLayout;
721
LibMaterial: TGLLibMaterial;
722
Material: TGLMaterial;
725
AlignCount: TGUIAlignments;
729
Len1 := (ThisElement.FTopLeft.x - ThisElement.FBottomRight.x) *
730
ThisElement.Scale.X * Scale;
731
Len2 := (ThisElement.FTopLeft.y - ThisElement.FBottomRight.y) *
732
ThisElement.Scale.Y * Scale;
761
procedure RenderIt(var ARect: TGuiRect; AElement: TGLGuiElement);
765
XPos, X2Pos: TGLFloat;
766
YPos, y2Pos: TGLFloat;
767
tx1, ty1, tx2, ty2: TGLFloat;
768
XTileSize, YTileSize: TGLFloat;
773
if (ARect.XTiles = 1) and (ARect.YTiles = 1) then
775
GL.TexCoord2f(AElement.TopLeft.X / TexWidth, -AElement.TopLeft.Y /
777
GL.Vertex2f(ARect.X1, -ARect.Y1);
779
GL.TexCoord2f(AElement.TopLeft.X / TexWidth, -AElement.BottomRight.Y /
781
GL.Vertex2f(ARect.X1, -ARect.Y2);
783
GL.TexCoord2f(AElement.BottomRight.X / TexWidth, -AElement.BottomRight.Y /
785
GL.Vertex2f(ARect.X2, -ARect.Y2);
787
GL.TexCoord2f(AElement.BottomRight.X / TexWidth, -AElement.TopLeft.Y /
789
GL.Vertex2f(ARect.X2, -ARect.Y1);
793
XTileSize := (ARect.X2 - ARect.X1) / ARect.XTiles;
794
YTileSize := (ARect.Y2 - ARect.Y1) / ARect.YTiles;
795
tx1 := AElement.TopLeft.X / TexWidth;
796
ty1 := -AElement.TopLeft.Y / TexHeight;
797
tx2 := AElement.BottomRight.X / TexWidth;
798
ty2 := -AElement.BottomRight.Y / TexHeight;
799
tx3 := (AElement.TopLeft.X + (AElement.BottomRight.X - AElement.TopLeft.X)
800
* Frac(ARect.XTiles)) / TexWidth;
801
ty3 := -(AElement.TopLeft.y + (AElement.BottomRight.y - AElement.TopLeft.y)
802
* Frac(ARect.yTiles)) / TexHeight;
814
X2Pos := XPos + XTileSize
824
Y2Pos := YPos + YTileSize
831
GL.TexCoord2f(tx1, ty1);
832
GL.Vertex2f(XPos, -YPos);
834
GL.TexCoord2f(tx1, ty);
835
GL.Vertex2f(XPos, -Y2Pos);
837
GL.TexCoord2f(tx, ty);
838
GL.Vertex2f(X2Pos, -Y2Pos);
840
GL.TexCoord2f(tx, ty1);
841
GL.Vertex2f(X2Pos, -YPos);
851
procedure RenderBorder(AElement: TGLGuiElement);
853
TmpElement: TGLGuiElement;
856
TmpElement := TGLGuiElement.Create(nil);
857
TmpElement.FTopLeft.X := ThisElement.FTopLeft.X;
858
TmpElement.FTopLeft.Y := ThisElement.FTopLeft.Y;
859
TmpElement.FBottomRight.X := ThisElement.FTopLeft.X + ThisElement.Scale.X;
860
TmpElement.FBottomRight.Y := ThisElement.FTopLeft.Y + ThisElement.Scale.Y;
861
TmpElement.Scale.SetPoint2D(1, 1);
862
RenderIt(Res[GLALTopLeft], TmpElement);
864
TmpElement.FTopLeft.X := ThisElement.FTopLeft.X + ThisElement.Scale.X;
865
TmpElement.FBottomRight.X := ThisElement.FBottomRight.X -
867
RenderIt(Res[GLALTop], TmpElement);
869
TmpElement.FTopLeft.X := ThisElement.FBottomRight.X - ThisElement.Scale.X;
870
TmpElement.FBottomRight.X := ThisElement.FBottomRight.X;
871
RenderIt(Res[GLALTopRight], TmpElement);
873
TmpElement.FTopLeft.Y := ThisElement.FTopLeft.Y + ThisElement.Scale.Y;
874
TmpElement.FBottomRight.Y := ThisElement.FBottomRight.Y -
876
RenderIt(Res[GLALRight], TmpElement);
878
TmpElement.FTopLeft.X := ThisElement.FBottomRight.X - ThisElement.Scale.X;
879
TmpElement.FTopLeft.Y := ThisElement.FBottomRight.Y - ThisElement.Scale.Y;
880
TmpElement.FBottomRight.X := ThisElement.FBottomRight.X;
881
TmpElement.FBottomRight.Y := ThisElement.FBottomRight.Y;
882
RenderIt(Res[GLALBottomRight], TmpElement);
884
TmpElement.FTopLeft.X := ThisElement.FTopLeft.X + ThisElement.Scale.X;
885
TmpElement.FTopLeft.Y := ThisElement.FBottomRight.Y - ThisElement.Scale.Y;
886
TmpElement.FBottomRight.X := ThisElement.FBottomRight.X -
888
TmpElement.FBottomRight.Y := ThisElement.FBottomRight.Y;
889
RenderIt(Res[GLALBottom], TmpElement);
891
TmpElement.FTopLeft.X := ThisElement.FTopLeft.X;
892
TmpElement.FTopLeft.Y := ThisElement.FBottomRight.Y - ThisElement.Scale.Y;
893
TmpElement.FBottomRight.X := ThisElement.FTopLeft.X + ThisElement.Scale.X;
894
TmpElement.FBottomRight.Y := ThisElement.FBottomRight.Y;
895
RenderIt(Res[GLALBottomLeft], TmpElement);
897
TmpElement.FTopLeft.X := ThisElement.FTopLeft.X;
898
TmpElement.FTopLeft.Y := ThisElement.FTopLeft.Y + ThisElement.Scale.Y;
899
TmpElement.FBottomRight.X := ThisElement.FTopLeft.X + ThisElement.Scale.X;
900
TmpElement.FBottomRight.Y := ThisElement.FBottomRight.Y -
902
RenderIt(Res[GLALLeft], TmpElement);
904
TmpElement.FTopLeft.X := ThisElement.FTopLeft.X + ThisElement.Scale.X;
905
TmpElement.FTopLeft.Y := ThisElement.FTopLeft.Y + ThisElement.Scale.Y;
906
TmpElement.FBottomRight.X := ThisElement.FBottomRight.X -
908
TmpElement.FBottomRight.Y := ThisElement.FBottomRight.Y -
910
RenderIt(Res[GLALCenter], TmpElement);
914
Layout := ((GetOwner as TGLGuiComponentList).GetOwner as TGLGuiLayout);
916
if Assigned(Layout.Material.MaterialLibrary)
917
and (Layout.Material.MaterialLibrary is TGLMaterialLibrary)
918
and (Layout.Material.LibMaterialName <> '') then
921
TGLMaterialLibrary(Layout.Material.MaterialLibrary).Materials.GetLibMaterialByName(Layout.Material.LibMaterialName);
922
if Assigned(LibMaterial) then
923
Material := LibMaterial.Material;
925
if not Assigned(Material) then
927
Material := Layout.Material;
932
Res[GLALtopLeft].X1 := X1;
933
Res[GLALtopLeft].Y1 := Y1;
934
Res[GLALtopLeft].X2 := X1;
935
Res[GLALtopLeft].Y2 := Y1;
937
Res[GLALtopRight].X1 := X2;
938
Res[GLALtopRight].Y1 := Y1;
939
Res[GLALtopRight].X2 := X2;
940
Res[GLALtopRight].Y2 := Y1;
942
Res[GLALBottomLeft].X1 := X1;
943
Res[GLALBottomLeft].Y1 := Y2;
944
Res[GLALBottomLeft].X2 := X1;
945
Res[GLALBottomLeft].Y2 := Y2;
947
Res[GLALBottomRight].X1 := X2;
948
Res[GLALBottomRight].Y1 := Y2;
949
Res[GLALBottomRight].X2 := X2;
950
Res[GLALBottomRight].Y2 := Y2;
952
for XC := 0 to FElements.Count - 1 do
954
ThisElement := FElements[XC];
955
if GLAlBorder = ThisElement.Align then
957
Res[GLALtopLeft].X1 := X1;
958
Res[GLALtopLeft].Y1 := Y1;
959
Res[GLALtopLeft].X2 := X1 + ThisElement.Scale.X * Scale *
961
Res[GLALtopLeft].Y2 := Y1 + ThisElement.Scale.Y * Scale *
964
Res[GLALtop].X1 := X1 + ThisElement.Scale.X * Scale *
966
Res[GLALtop].Y1 := Y1;
967
Res[GLALtop].X2 := X2 - ThisElement.Scale.X * Scale *
969
Res[GLALtop].Y2 := Y1 + ThisElement.Scale.Y * Scale *
972
Res[GLALtopRight].X1 := X2 - ThisElement.Scale.X * Scale *
974
Res[GLALtopRight].Y1 := Y1;
975
Res[GLALtopRight].X2 := X2;
976
Res[GLALtopRight].Y2 := Y1 + ThisElement.Scale.Y * Scale *
979
Res[GLALRight].X1 := X2 - ThisElement.Scale.X * Scale *
981
Res[GLALRight].Y1 := Y1 + ThisElement.Scale.Y * Scale *
983
Res[GLALRight].X2 := X2;
984
Res[GLALRight].Y2 := Y2 - ThisElement.Scale.Y * Scale *
987
Res[GLALBottomRight].X1 := X2 - ThisElement.Scale.X * Scale *
989
Res[GLALBottomRight].Y1 := Y2 - ThisElement.Scale.Y * Scale *
991
Res[GLALBottomRight].X2 := X2;
992
Res[GLALBottomRight].Y2 := Y2;
994
Res[GLALBottom].X1 := X1 + ThisElement.Scale.X * Scale *
996
Res[GLALBottom].Y1 := Y2 - ThisElement.Scale.Y * Scale *
998
Res[GLALBottom].X2 := X2 - ThisElement.Scale.X * Scale *
1000
Res[GLALBottom].Y2 := Y2;
1002
Res[GLALBottomLeft].X1 := X1;
1003
Res[GLALBottomLeft].Y1 := Y2 - ThisElement.Scale.Y * Scale *
1004
ThisElement.Scale.Z;
1005
Res[GLALBottomLeft].X2 := X1 + ThisElement.Scale.X * Scale *
1006
ThisElement.Scale.Z;
1007
Res[GLALBottomLeft].Y2 := Y2;
1009
Res[GLALLeft].X1 := X1;
1010
Res[GLALLeft].Y1 := Y1 + ThisElement.Scale.Y * Scale *
1011
ThisElement.Scale.Z;
1012
Res[GLALLeft].X2 := X1 + ThisElement.Scale.X * Scale *
1013
ThisElement.Scale.Z;
1014
Res[GLALLeft].Y2 := Y2 - ThisElement.Scale.Y * Scale *
1015
ThisElement.Scale.Z;
1017
Res[GLALCenter].X1 := X1 + ThisElement.Scale.X * Scale *
1018
ThisElement.Scale.Z;
1019
Res[GLALCenter].Y1 := Y1 + ThisElement.Scale.Y * Scale *
1020
ThisElement.Scale.Z;
1021
Res[GLALCenter].X2 := X2 - ThisElement.Scale.X * Scale *
1022
ThisElement.Scale.Z;
1023
Res[GLALCenter].Y2 := Y2 - ThisElement.Scale.Y * Scale *
1024
ThisElement.Scale.Z;
1027
if GLALtopLeft = ThisElement.Align then
1030
Res[GLALtopLeft].X1 := X1;
1031
Res[GLALtopLeft].Y1 := Y1;
1032
Res[GLALtopLeft].X2 := X1 + W;
1033
Res[GLALtopLeft].Y2 := Y1 + H;
1035
if GLALtopRight = ThisElement.Align then
1038
Res[GLALtopRight].X1 := X2 - W;
1039
Res[GLALtopRight].Y1 := Y1;
1040
Res[GLALtopRight].X2 := X2;
1041
Res[GLALtopRight].Y2 := Y1 + H;
1043
if GLALBottomLeft = ThisElement.Align then
1046
Res[GLALBottomLeft].X1 := X1;
1047
Res[GLALBottomLeft].Y1 := Y2 - H;
1048
Res[GLALBottomLeft].X2 := X1 + W;
1049
Res[GLALBottomLeft].Y2 := Y2;
1051
if GLALBottomRight = ThisElement.Align then
1054
Res[GLALBottomRight].X1 := X2 - W;
1055
Res[GLALBottomRight].Y1 := Y2 - H;
1056
Res[GLALBottomRight].X2 := X2;
1057
Res[GLALBottomRight].Y2 := Y2;
1061
Res[GLALtop].X1 := Res[GLALtopLeft].X2;
1062
Res[GLALtop].Y1 := Res[GLALtopRight].Y1;
1063
Res[GLALtop].X2 := Res[GLALtopRight].X1;
1064
Res[GLALtop].Y2 := Res[GLALtopLeft].Y2;
1066
Res[GLALBottom].X1 := Res[GLALBottomLeft].X2;
1067
Res[GLALBottom].Y1 := Res[GLALBottomLeft].Y1;
1068
Res[GLALBottom].X2 := Res[GLALBottomRight].X1;
1069
Res[GLALBottom].Y2 := Res[GLALBottomRight].Y2;
1071
Res[GLALLeft].X1 := Res[GLALtopLeft].X1;
1072
Res[GLALLeft].Y1 := Res[GLALtopLeft].Y2;
1073
Res[GLALLeft].X2 := Res[GLALBottomLeft].X2;
1074
Res[GLALLeft].Y2 := Res[GLALBottomLeft].Y1;
1076
Res[GLALRight].X1 := Res[GLALtopRight].X1;
1077
Res[GLALRight].Y1 := Res[GLALtopRight].Y2;
1078
Res[GLALRight].X2 := Res[GLALBottomRight].X2;
1079
Res[GLALRight].Y2 := Res[GLALBottomRight].Y1;
1081
for XC := 0 to FElements.Count - 1 do
1083
ThisElement := FElements[XC];
1084
if GLALtop = ThisElement.Align then
1087
Res[GLALtop].Y1 := Y1;
1088
Res[GLALtop].Y2 := Y1 + H;
1090
if GLALBottom = ThisElement.Align then
1093
Res[GLALBottom].Y1 := Y2 - H;
1094
Res[GLALBottom].Y2 := Y2;
1096
if GLALLeft = ThisElement.Align then
1099
Res[GLALLeft].X1 := X1;
1100
Res[GLALLeft].X2 := X1 + W;
1102
if GLALRight = ThisElement.Align then
1105
Res[GLALRight].X1 := X2 - W;
1106
Res[GLALRight].X2 := X2;
1110
Res[GLALCenter].X1 := Res[GLALLeft].X2;
1111
Res[GLALCenter].Y1 := Res[GLALtop].Y2;
1112
Res[GLALCenter].X2 := Res[GLALRight].X1;
1113
Res[GLALCenter].Y2 := Res[GLALBottom].Y1;
1116
TexWidth := Material.Texture.TexWidth;
1117
if TexWidth = 0 then
1118
TexWidth := Material.Texture.Image.Width;
1120
TexHeight := Material.Texture.TexHeight;
1121
if TexHeight = 0 then
1122
TexHeight := Material.Texture.Image.Height;
1124
GL.Begin_(GL_QUADS);
1126
for XC := 0 to FElements.Count - 1 do
1128
ThisElement := FElements[XC];
1129
for AlignCount := GLAlTopLeft to GLAlBottomRight do
1130
if (AlignCount = ThisElement.Align) then
1134
Res[AlignCount].XTiles := ((Res[AlignCount].X2 - Res[AlignCount].X1) /
1135
(ThisElement.FBottomRight.X - ThisElement.FTopLeft.X)) /
1136
ThisElement.Scale.X;
1137
Res[AlignCount].YTiles := ((Res[AlignCount].Y2 - Res[AlignCount].Y1) /
1138
(ThisElement.FBottomRight.Y - ThisElement.FTopLeft.Y)) /
1139
ThisElement.Scale.Y;
1141
RenderIt(Res[AlignCount], ThisElement);
1143
if (GLALBorder = ThisElement.Align) then
1145
RenderBorder(ThisElement);
1152
function TGLGuiComponent.GetOwnerList: TGLGuiComponentList;
1154
Result := GetOwner as TGLGuiComponentList;
1157
function TGLGuiComponent.GetDisplayName: string;
1162
procedure TGLGuiComponent.SetName(const val: TGLGuiComponentName);
1167
constructor TGLGuiComponent.Create(Collection: TCollection);
1170
FElements := TGLGuiElementList.Create(Self);
1173
destructor TGLGuiComponent.Destroy;
1179
constructor TGLGuiElementList.Create(AOwner: TGLGuiComponent);
1181
inherited Create(AOwner, TGLGuiElement);
1182
FGuiComponent := AOwner;
1185
function TGLGuiElementList.GetOwner: TPersistent;
1187
Result := FGuiComponent;
1190
procedure TGLGuiElementList.SetItems(index: Integer; const val: TGLGuiElement);
1192
inherited Items[index] := val;
1195
function TGLGuiElementList.IndexOf(const Item: TGLGuiElement): Integer;
1201
for I := 0 to Count - 1 do
1202
if GetItems(I) = Item then
1209
function TGLGuiElementList.GetItems(index: Integer): TGLGuiElement;
1211
Result := TGLGuiElement(inherited Items[index]);
1214
function TGLGuiElement.GetDisplayName: string;
1219
procedure TGLGuiElement.SetName(const val: TGLGuiElementName);
1224
constructor TGLGuiElement.Create(Collection: TCollection);
1227
FTopLeft := TGLCoordinates2.CreateInitialized(Self, NullHmgVector, csPoint2D);
1228
FBottomRight := TGLCoordinates2.CreateInitialized(Self, NullHmgVector,
1230
FScale := TGLCoordinates2.CreateInitialized(Self, XYHmgVector, csPoint2D);
1233
destructor TGLGuiElement.Destroy;
1241
procedure TGLGuiLayout.Notification(AComponent: TComponent;
1242
Operation: TOperation);
1244
if Operation = opRemove then
1246
if AComponent = FBitmapFont then
1249
FGuiComponentList.Remove(AComponent);
1251
NotifyChange(Self); // EG : looks suspicious...
1255
procedure TGLGuiComponent.AssignTo(Dest: TPersistent);
1257
if Dest is TGLGuiComponent then
1259
TGLGuiComponent(Dest).Elements.Assign(Elements);
1265
procedure TGLGuiElementList.AssignTo(Dest: TPersistent);
1269
if Dest is TGLGuiElementList then
1271
for i := 0 to Count - 1 do
1273
TGLGuiElementList(Dest).Add.Assign(Items[i]);
1280
procedure TGLGuiElement.AssignTo(Dest: TPersistent);
1282
element: TGLGuiElement;
1284
if Dest is TGLGuiElement then
1286
element := TGLGuiElement(Dest);
1288
element.TopLeft.Assign(TopLeft);
1289
element.BottomRight.Assign(BottomRight);
1290
element.Scale.Assign(Scale);
1291
element.Align := Align;
1292
element.Name := Name;