2
// This unit is part of the GLScene Engine https://github.com/glscene
5
OpenGL windows management classes and structures
8
10/11/12 - PW - Added CPP compatibility: changed vector arrays to records,
9
renamed lowercase sender and accept to uppercase Sender and Accept
10
16/03/11 - Yar - Fixes after emergence of GLMaterialEx
11
23/08/10 - Yar - Added OpenGLTokens to uses, replaced OpenGL1x functions to OpenGLAdapter
12
11/06/10 - YP - Link GUI elements to their parent
13
22/04/10 - Yar - Fixes after GLState revision
14
05/03/10 - DanB - More state added to TGLStateCache
15
17/10/08 - DanB - reversed order of vertices in TGLCustomControl.InternalRender,
16
which fixes the GUIPaint demo
17
27/04/08 - DaStr - Fixed bug in TGLButton.InternalRender()
18
(thanks Nicoara Adrian) (BugtrackerID = 1952711)
19
06/06/07 - DaStr - Added GLColor to uses (BugtrackerID = 1732211)
20
20/12/06 - DaStr - Added: TGLEdit.ReadOnly, TGLScrollbar.Locked,
21
TGLStringGrid.ColSelect
22
10/11/05 - Mathx - Fixed TGLPopupMenu stack overflow on method internalRender.
23
Related to bug 1193909.
24
24/05/02 - JAJ - Base Unit built on basis of Jan Horn's demo at
25
(http://www.sulaco.co.za/opengl/windows.zip)
26
01/06/02 - JAJ - After not having received Jan Horn's blessing, the
27
system have been revised all parts have been rewritten.
28
01/01/03 - JAJ - Updated so that focused controls pass focus on hide...
29
05/01/03 - JAJ - Cleaned up the DesignTime AccessViolations...
30
07/01/03 - JAJ - Jeremy Darling modified the TGLEdit's Render, more
31
updates on TGLEdit expected...
32
18/01/03 - JAJ - Added TGLStringList, TGLScrollbar, TGLPopupMenu...
33
08/08/03 - PS - Added Horizontal to GLScrollbar...
34
14/08/03 - SG - Fixed TGLBaseComponent.SetGuiLayout (Joen Joensen)
35
08/08/03 - JAJ - Merged PS's and SG's update... Added TitleOffset...
36
03/07/04 - LR - Added constant for Keyboard (glKey_TAB, ...)
37
Added function GLOKMessageBox to avoid the uses of Forms
38
Replace TColor, TBitmap, TMouseEvent, TKeyEvent, ...
39
by TGLColor, TGLBitmap, TGLMouseEvent, TGLKeyEvent, ...
40
25/01/05 - AX - Corrected AlphaChannel default value, must be 1
41
TGLButton, TGLForm - AlphaChannel behaviour text.
42
Added events OnMouseEnter/OnMouseLeave for all controls
43
05/02/05 - AX - TGLLabel correct layout depending on Aligment and TextLayout.
55
GLScene, GLHUDObjects, GLMaterial, OpenGLTokens, GLContext,
56
GLBitmapFont, GLWindowsFont, GLVectorGeometry, GLGui,
57
GLCrossPlatform, GLColor, GLRenderContextInfo, GLBaseClasses;
61
TGLBaseComponent = class(TGLBaseGuiObject)
64
FGuiLayout: TGLGuiLayout;
65
FGuiLayoutName: TGLGuiComponentName;
66
FGuiComponent: TGLGuiComponent;
68
FRedrawAtOnce: Boolean;
69
MoveX, MoveY: TGLFloat;
70
FRenderStatus: TGUIDrawResult;
72
FAlphaChannel: Single;
76
BlockRendering: Boolean;
77
RenderingCount: Integer;
78
BlockedCount: Integer;
79
GuiDestroying: Boolean;
80
FDoChangesOnProgress: Boolean;
83
procedure SetGUIRedraw(value: Boolean);
84
procedure SetDoChangesOnProgress(const Value: Boolean);
85
procedure SetAutosize(const Value: Boolean);
87
procedure RenderHeader(var rci: TGLRenderContextInfo; renderSelf,
88
renderChildren: Boolean);
89
procedure RenderFooter(var rci: TGLRenderContextInfo; renderSelf,
90
renderChildren: Boolean);
92
procedure SetGuiLayout(NewGui: TGLGuiLayout); virtual;
93
procedure SetGuiLayoutName(NewName: TGLGuiComponentName);
95
procedure Notification(AComponent: TComponent; Operation: TOperation);
98
procedure SetRotation(const val: TGLFloat);
99
procedure SetAlphaChannel(const val: Single);
100
function StoreAlphaChannel: Boolean;
101
procedure SetNoZWrite(const val: Boolean);
104
procedure BlockRender;
105
procedure UnBlockRender;
107
constructor Create(AOwner: TComponent); override;
108
destructor Destroy; override;
110
procedure NotifyChange(Sender: TObject); override;
111
procedure DoChanges; virtual;
112
procedure MoveGUI(XRel, YRel: Single);
113
procedure PlaceGUI(XPos, YPos: Single);
115
procedure DoProgress(const progressTime: TProgressTimes); override;
117
procedure DoRender(var rci: TGLRenderContextInfo; renderSelf, renderChildren:
119
procedure InternalRender(var rci: TGLRenderContextInfo; renderSelf,
120
renderChildren: Boolean); virtual;
121
property GUIRedraw: Boolean read FGUIRedraw write SetGUIRedraw;
122
property ReBuildGui: Boolean read FReBuildGui write FReBuildGui;
124
property Autosize: Boolean read FAutosize write SetAutosize;
125
property RedrawAtOnce: Boolean read FRedrawAtOnce write FRedrawAtOnce;
126
property GuiLayout: TGLGuiLayout read FGuiLayout write SetGuiLayout;
127
property GuiLayoutName: TGLGuiComponentName read FGuiLayoutName write
130
{ This the ON-SCREEN rotation of the GuiComponent.
131
Rotatation=0 is handled faster. }
132
property Rotation: TGLFloat read FRotation write SetRotation;
133
{ If different from 1, this value will replace that of Diffuse.Alpha }
134
property AlphaChannel: Single read FAlphaChannel write SetAlphaChannel stored
136
{ If True, GuiComponent will not write to Z-Buffer.
137
GuiComponent will STILL be maskable by ZBuffer test. }
138
property NoZWrite: Boolean read FNoZWrite write SetNoZWrite;
140
property DoChangesOnProgress: Boolean read FDoChangesOnProgress write
141
SetDoChangesOnProgress;
150
TGLFocusControl = class;
151
TGLBaseControl = class;
153
TGLMouseAction = (ma_mouseup, ma_mousedown, ma_mousemove);
155
TGLAcceptMouseQuery = procedure(Sender: TGLBaseControl; Shift: TShiftState;
156
Action: TGLMouseAction; Button: TGLMouseButton; X, Y: Integer; var Accept:
158
TGLBaseControl = class(TGLBaseComponent)
160
FOnMouseDown: TGLMouseEvent;
161
FOnMouseMove: TGLMouseMoveEvent;
162
FOnMouseUp: TGLMouseEvent;
163
FKeepMouseEvents: Boolean;
164
FActiveControl: TGLBaseControl;
165
FFocusedControl: TGLFocusControl;
166
FOnAcceptMouseQuery: TGLAcceptMouseQuery;
167
FOnMouseLeave: TNotifyEvent;
168
FOnMouseEnter: TNotifyEvent;
169
FEnteredControl: TGLBaseControl;
171
procedure InternalMouseDown(Shift: TShiftState; Button: TGLMouseButton; X,
172
Y: Integer); virtual;
173
procedure InternalMouseUp(Shift: TShiftState; Button: TGLMouseButton; X, Y:
175
procedure InternalMouseMove(Shift: TShiftState; X, Y: Integer); virtual;
176
procedure SetActiveControl(NewControl: TGLBaseControl);
177
procedure SetFocusedControl(NewControl: TGLFocusControl);
178
function FindFirstGui: TGLBaseControl;
179
procedure Notification(AComponent: TComponent; Operation: TOperation);
182
procedure DoMouseEnter;
183
procedure DoMouseLeave;
185
function MouseDown(Sender: TObject; Button: TGLMouseButton; Shift:
186
TShiftState; X, Y: Integer): Boolean; virtual;
187
function MouseUp(Sender: TObject; Button: TGLMouseButton; Shift:
188
TShiftState; X, Y: Integer): Boolean; virtual;
189
function MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer):
191
procedure KeyPress(Sender: TObject; var Key: Char); virtual;
192
procedure KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
194
procedure KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
196
property ActiveControl: TGLBaseControl read FActiveControl write
198
property KeepMouseEvents: Boolean read FKeepMouseEvents write
199
FKeepMouseEvents default false;
201
property FocusedControl: TGLFocusControl read FFocusedControl write
203
property OnMouseDown: TGLMouseEvent read FOnMouseDown write FOnMouseDown;
204
property OnMouseMove: TGLMouseMoveEvent read FOnMouseMove write
206
property OnMouseUp: TGLMouseEvent read FOnMouseUp write FOnMouseUp;
207
property OnMouseEnter: TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
208
property OnMouseLeave: TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
209
property OnAcceptMouseQuery: TGLAcceptMouseQuery read FOnAcceptMouseQuery
210
write FOnAcceptMouseQuery;
213
TGLBaseFontControl = class(TGLBaseControl)
215
FBitmapFont: TGLCustomBitmapFont;
216
FDefaultColor: TColorVector;
218
function GetDefaultColor: TDelphiColor;
219
procedure SetDefaultColor(value: TDelphiColor);
220
procedure SetBitmapFont(NewFont: TGLCustomBitmapFont);
221
function GetBitmapFont: TGLCustomBitmapFont;
222
procedure WriteTextAt(var rci: TGLRenderContextInfo; const X, Y: TGLFloat;
223
const Data: UnicodeString; const Color: TColorVector); overload;
224
procedure WriteTextAt(var rci: TGLRenderContextInfo; const X1, Y1, X2, Y2:
225
TGLFloat; const Data: UnicodeString; const Color: TColorVector); overload;
226
function GetFontHeight: Integer;
228
constructor Create(AOwner: TComponent); override;
229
destructor Destroy; override;
230
procedure Notification(AComponent: TComponent; Operation: TOperation);
233
property BitmapFont: TGLCustomBitmapFont read GetBitmapFont write
235
property DefaultColor: TDelphiColor read GetDefaultColor write
239
TGLBaseTextControl = class(TGLBaseFontControl)
241
FCaption: UnicodeString;
243
procedure SetCaption(const NewCaption: UnicodeString);
246
property Caption: UnicodeString read FCaption write SetCaption;
249
TGLFocusControl = class(TGLBaseTextControl)
251
FRootControl: TGLBaseControl;
253
FOnKeyDown: TGLKeyEvent;
254
FOnKeyUp: TGLKeyEvent;
255
FOnKeyPress: TGLKeyPressEvent;
256
FShiftState: TShiftState;
257
FFocusedColor: TColorVector;
259
procedure InternalKeyPress(var Key: Char); virtual;
260
procedure InternalKeyDown(var Key: Word; Shift: TShiftState); virtual;
261
procedure InternalKeyUp(var Key: Word; Shift: TShiftState); virtual;
262
procedure SetFocused(Value: Boolean); virtual;
263
function GetRootControl: TGLBaseControl;
264
function GetFocusedColor: TDelphiColor;
265
procedure SetFocusedColor(const Val: TDelphiColor);
267
destructor Destroy; override;
268
procedure NotifyHide; override;
269
procedure MoveTo(newParent: TGLBaseSceneObject); override;
270
procedure ReGetRootControl;
272
procedure PrevControl;
273
procedure NextControl;
274
procedure KeyPress(Sender: TObject; var Key: Char); override;
275
procedure KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
277
procedure KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
280
property RootControl: TGLBaseControl read GetRootControl;
281
property Focused: Boolean read FFocused write SetFocused;
282
property FocusedColor: TDelphiColor read GetFocusedColor write
284
property OnKeyDown: TGLKeyEvent read FOnKeyDown write FOnKeyDown;
285
property OnKeyUp: TGLKeyEvent read FOnKeyUp write FOnKeyUp;
286
property OnKeyPress: TGLKeyPressEvent read FOnKeyPress write FOnKeyPress;
289
TGLCustomControl = class;
290
TGLCustomRenderEvent = procedure(Sender: TGLCustomControl; Bitmap: TGLBitmap)
292
TGLCustomControl = class(TGLFocusControl)
294
FCustomData: Pointer;
295
FCustomObject: TObject;
296
FOnRender: TGLCustomRenderEvent;
297
FMaterial: TGLMaterial;
299
FInternalBitmap: TGLBitmap;
300
FBitmapChanged: Boolean;
303
FInvalidRenderCount: Integer;
304
FMaxInvalidRenderCount: Integer;
306
procedure SetCentered(const Value: Boolean);
308
procedure OnBitmapChanged(Sender: TObject);
309
procedure SetBitmap(ABitmap: TGLBitmap);
311
constructor Create(AOwner: TComponent); override;
312
destructor Destroy; override;
313
procedure InternalRender(var rci: TGLRenderContextInfo; renderSelf,
314
renderChildren: Boolean); override;
315
procedure SetMaterial(AMaterial: TGLMaterial);
316
property CustomData: Pointer read FCustomData write FCustomData;
317
property CustomObject: TObject read FCustomObject write FCustomObject;
319
property OnRender: TGLCustomRenderEvent read FOnRender write FOnRender;
320
property Centered: Boolean read FCentered write SetCentered;
321
property Material: TGLMaterial read FMaterial write SetMaterial;
322
property Bitmap: TGLBitmap read FBitmap write SetBitmap;
323
property MaxInvalidRenderCount: Integer read FMaxInvalidRenderCount write
324
FMaxInvalidRenderCount;
327
TGLPopupMenu = class;
328
TGLPopupMenuClick = procedure(Sender: TGLPopupMenu; index: Integer; const
329
MenuItemText: string) of object;
331
TGLPopupMenu = class(TGLFocusControl)
333
FOnClick: TGLPopupMenuClick;
334
FMenuItems: TStrings;
339
procedure SetFocused(Value: Boolean); override;
340
procedure SetMenuItems(Value: TStrings);
341
procedure SetMarginSize(const val: Single);
342
procedure SetSelIndex(const val: Integer);
343
procedure InternalMouseDown(Shift: TShiftState; Button: TGLMouseButton; X,
344
Y: Integer); override;
345
procedure InternalMouseMove(Shift: TShiftState; X, Y: Integer); override;
346
procedure OnStringListChange(Sender: TObject);
348
constructor Create(AOwner: TComponent); override;
349
destructor Destroy; override;
350
procedure PopUp(Px, Py: Integer);
351
procedure InternalRender(var rci: TGLRenderContextInfo; renderSelf,
352
renderChildren: Boolean); override;
353
procedure DoRender(var rci: TGLRenderContextInfo; renderSelf, renderChildren:
355
function MouseDown(Sender: TObject; Button: TGLMouseButton; Shift:
356
TShiftState; X, Y: Integer): Boolean; override;
358
property MenuItems: TStrings read FMenuItems write SetMenuItems;
359
property OnClick: TGLPopupMenuClick read FOnClick write FOnClick;
360
property MarginSize: Single read FMarginSize write SetMarginSize;
361
property SelIndex: Integer read FSelIndex write SetSelIndex;
365
TGLFormCanRequest = procedure(Sender: TGLForm; var Can: Boolean) of object;
366
TGLFormCloseOptions = (co_Hide, co_Ignore, co_Destroy);
367
TGLFormCanClose = procedure(Sender: TGLForm; var CanClose: TGLFormCloseOptions)
369
TGLFormNotify = procedure(Sender: TGLForm) of object;
370
TGLFormMove = procedure(Sender: TGLForm; var Left, Top: Single) of object;
372
TGLForm = class(TGLBaseTextControl)
374
FOnCanMove: TGLFormCanRequest;
375
FOnCanResize: TGLFormCanRequest;
376
FOnCanClose: TGLFormCanClose;
377
FOnShow: TGLFormNotify;
378
FOnHide: TGLFormNotify;
379
FOnMoving: TGLFormMove;
383
FTitleColor: TColorVector;
384
FTitleOffset: Single;
386
procedure InternalMouseDown(Shift: TShiftState; Button: TGLMouseButton; X,
387
Y: Integer); override;
388
procedure InternalMouseUp(Shift: TShiftState; Button: TGLMouseButton; X, Y:
390
procedure InternalMouseMove(Shift: TShiftState; X, Y: Integer); override;
391
function GetTitleColor: TDelphiColor;
392
procedure SetTitleColor(value: TDelphiColor);
394
constructor Create(AOwner: TComponent); override;
397
procedure NotifyShow; override;
398
procedure NotifyHide; override;
399
function MouseUp(Sender: TObject; Button: TGLMouseButton; Shift:
400
TShiftState; X, Y: Integer): Boolean; override;
401
function MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer):
403
procedure InternalRender(var rci: TGLRenderContextInfo; renderSelf,
404
renderChildren: Boolean); override;
406
property TitleColor: TDelphiColor read GetTitleColor write SetTitleColor;
407
property OnCanMove: TGLFormCanRequest read FOnCanMove write FOnCanMove;
408
property OnCanResize: TGLFormCanRequest read FOnCanResize write
410
property OnCanClose: TGLFormCanClose read FOnCanClose write FOnCanClose;
411
property OnShow: TGLFormNotify read FOnShow write FOnShow;
412
property OnHide: TGLFormNotify read FOnHide write FOnHide;
413
property OnMoving: TGLFormMove read FOnMoving write FOnMoving;
414
property TitleOffset: Single read FTitleOffset write FTitleOffset;
417
TGLPanel = class(TGLBaseControl)
420
TGLCheckBox = class(TGLBaseControl)
423
FOnChange: TNotifyEvent;
424
FGuiLayoutNameChecked: TGLGuiComponentName;
425
FGuiCheckedComponent: TGLGuiComponent;
428
procedure SetChecked(NewChecked: Boolean);
429
procedure InternalMouseDown(Shift: TShiftState; Button: TGLMouseButton; X,
430
Y: Integer); override;
431
procedure InternalMouseUp(Shift: TShiftState; Button: TGLMouseButton; X, Y:
433
procedure SetGuiLayoutNameChecked(newName: TGLGuiComponentName);
434
procedure SetGuiLayout(NewGui: TGLGuiLayout); override;
435
procedure SetGroup(const val: Integer);
437
constructor Create(AOwner: TComponent); override;
438
procedure InternalRender(var rci: TGLRenderContextInfo; renderSelf,
439
renderChildren: Boolean); override;
440
procedure NotifyChange(Sender: TObject); override;
442
property Group: Integer read FGroup write SetGroup;
443
property Checked: Boolean read FChecked write SetChecked;
444
property OnChange: TNotifyEvent read FOnChange write FOnChange;
445
property GuiLayoutNameChecked: TGLGuiComponentName read FGuiLayoutNameChecked
446
write SetGuiLayoutNameChecked;
449
TGLButton = class(TGLFocusControl)
452
FOnButtonClick: TNotifyEvent;
453
FGuiLayoutNamePressed: TGLGuiComponentName;
454
FGuiPressedComponent: TGLGuiComponent;
455
FBitBtn: TGLMaterial;
458
FLogicHeight: Single;
463
procedure SetPressed(NewPressed: Boolean);
464
procedure InternalMouseDown(Shift: TShiftState; Button: TGLMouseButton; X,
465
Y: Integer); override;
466
procedure InternalMouseUp(Shift: TShiftState; Button: TGLMouseButton; X, Y:
468
procedure InternalKeyDown(var Key: Word; Shift: TShiftState); override;
469
procedure InternalKeyUp(var Key: Word; Shift: TShiftState); override;
470
procedure SetFocused(Value: Boolean); override;
471
procedure SetGuiLayoutNamePressed(newName: TGLGuiComponentName);
472
procedure SetGuiLayout(NewGui: TGLGuiLayout); override;
473
procedure SetBitBtn(AValue: TGLMaterial);
474
procedure DestroyHandle; override;
475
procedure SetGroup(const val: Integer);
476
procedure SetLogicWidth(const val: single);
477
procedure SetLogicHeight(const val: single);
478
procedure SetXOffset(const val: single);
479
procedure SetYOffset(const val: single);
481
constructor Create(AOwner: TComponent); override;
482
destructor Destroy; override;
483
procedure InternalRender(var rci: TGLRenderContextInfo; renderSelf,
484
renderChildren: Boolean); override;
486
property Group: Integer read FGroup write SetGroup;
487
property BitBtn: TGLMaterial read FBitBtn write SetBitBtn;
488
property Pressed: Boolean read FPressed write SetPressed;
489
property OnButtonClick: TNotifyEvent read FOnButtonClick write
491
property GuiLayoutNamePressed: TGLGuiComponentName read FGuiLayoutNamePressed
492
write SetGuiLayoutNamePressed;
493
property LogicWidth: Single read FLogicWidth write SetLogicWidth;
494
property LogicHeight: Single read FLogicHeight write SetLogicHeight;
495
property XOffset: Single read FXOffset write SetXOffset;
496
property YOffset: Single read FYOffset write SetYOffset;
497
property AllowUp: Boolean read FAllowUp write FAllowUp;
500
TGLEdit = class(TGLFocusControl)
502
FOnChange: TNotifyEvent;
507
procedure InternalMouseDown(Shift: TShiftState; Button: TGLMouseButton; X,
508
Y: Integer); override;
509
procedure InternalKeyPress(var Key: Char); override;
510
procedure InternalKeyDown(var Key: Word; Shift: TShiftState); override;
511
procedure InternalKeyUp(var Key: Word; Shift: TShiftState); override;
512
procedure SetFocused(Value: Boolean); override;
513
procedure SetSelStart(const Value: Integer);
514
procedure SetEditChar(const Value: string);
516
constructor Create(AOwner: TComponent); override;
517
procedure InternalRender(var rci: TGLRenderContextInfo; renderSelf,
518
renderChildren: Boolean); override;
520
property EditChar: string read FEditChar write SetEditChar;
521
property ReadOnly: Boolean read FReadOnly write FReadOnly default False;
522
property OnChange: TNotifyEvent read FOnChange write FOnChange;
523
property SelStart: Integer read FSelStart write SetSelStart;
526
TGLLabel = class(TGLBaseTextControl)
528
FAlignment: TAlignment;
529
FTextLayout: TGLTextLayout;
530
procedure SetAlignment(const Value: TAlignment);
531
procedure SetTextLayout(const Value: TGLTextLayout);
534
constructor Create(AOwner: TComponent); override;
535
procedure InternalRender(var rci: TGLRenderContextInfo; renderSelf,
536
renderChildren: Boolean); override;
538
property Alignment: TAlignment read FAlignment write SetAlignment;
539
property TextLayout: TGLTextLayout read FTextLayout write SetTextLayout;
542
TGLAdvancedLabel = class(TGLFocusControl)
546
procedure InternalRender(var rci: TGLRenderContextInfo; renderSelf,
547
renderChildren: Boolean); override;
551
TGLScrollbar = class(TGLFocusControl)
558
FOnChange: TNotifyEvent;
559
FGuiLayoutKnobName: TGLGuiComponentName;
560
FGuiKnobComponent: TGLGuiComponent;
561
FKnobRenderStatus: TGUIDrawResult;
564
FHorizontal: Boolean;
567
procedure SetMin(const val: Single);
568
procedure SetMax(const val: Single);
569
procedure SetPos(const val: Single);
570
procedure SetPageSize(const val: Single);
571
procedure SetHorizontal(const val: Boolean);
572
procedure SetGuiLayoutKnobName(newName: TGLGuiComponentName);
573
procedure SetGuiLayout(NewGui: TGLGuiLayout); override;
575
function GetScrollPosY(ScrollPos: Single): Single;
576
function GetYScrollPos(Y: Single): Single;
578
function GetScrollPosX(ScrollPos: Single): Single;
579
function GetXScrollPos(X: Single): Single;
581
procedure InternalMouseDown(Shift: TShiftState; Button: TGLMouseButton; X,
582
Y: Integer); override;
583
procedure InternalMouseUp(Shift: TShiftState; Button: TGLMouseButton; X, Y:
585
procedure InternalMouseMove(Shift: TShiftState; X, Y: Integer); override;
587
constructor Create(AOwner: TComponent); override;
593
function MouseUp(Sender: TObject; Button: TGLMouseButton; Shift:
594
TShiftState; X, Y: Integer): Boolean; override;
595
function MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer):
597
procedure InternalRender(var rci: TGLRenderContextInfo; renderSelf,
598
renderChildren: Boolean); override;
600
property Horizontal: Boolean read FHorizontal write SetHorizontal;
601
property Pos: Single read FPos write SetPos;
602
property Min: Single read FMin write SetMin;
603
property Max: Single read FMax write SetMax;
604
property Step: Single read FStep write FStep;
605
property PageSize: Single read FPageSize write SetPageSize;
606
property OnChange: TNotifyEvent read FOnChange write FOnChange;
607
property GuiLayoutKnobName: TGLGuiComponentName read FGuiLayoutKnobName write
608
SetGuiLayoutKnobName;
609
property Locked: Boolean read FLocked write FLocked default False;
612
TGLStringGrid = class(TGLFocusControl)
614
FSelCol, FSelRow: Integer;
619
FHeaderColor: TColorVector;
620
FMarginSize: Integer;
621
FColumnSize: Integer;
623
FScrollbar: TGLScrollbar;
624
FDrawHeader: Boolean;
626
function GetCell(X, Y: Integer; out oCol, oRow: Integer): Boolean;
627
procedure InternalMouseDown(Shift: TShiftState; Button: TGLMouseButton; X,
628
Y: Integer); override;
629
procedure SetColumns(const val: TStrings);
630
procedure SetColSelect(const val: Boolean);
631
function GetRow(index: Integer): TStringList;
632
procedure SetRow(index: Integer; const val: TStringList);
633
function GetRowCount: Integer;
634
procedure SetRowCount(const val: Integer);
635
procedure SetSelCol(const val: Integer);
636
procedure SetSelRow(const val: Integer);
637
procedure SetRowSelect(const val: Boolean);
638
procedure SetDrawHeader(const val: Boolean);
639
function GetHeaderColor: TDelphiColor;
640
procedure SetHeaderColor(const val: TDelphiColor);
641
procedure SetMarginSize(const val: Integer);
642
procedure SetColumnSize(const val: Integer);
643
procedure SetRowHeight(const val: Integer);
644
procedure SetScrollbar(const val: TGLScrollbar);
645
procedure SetGuiLayout(NewGui: TGLGuiLayout); override;
647
constructor Create(AOwner: TComponent); override;
648
destructor Destroy; override;
650
function Add(Data: array of string): Integer; overload;
651
function Add(const Data: string): Integer; overload;
652
procedure SetText(Data: string);
653
procedure Notification(AComponent: TComponent; Operation: TOperation);
655
procedure NotifyChange(Sender: TObject); override;
656
procedure InternalRender(var rci: TGLRenderContextInfo; renderSelf,
657
renderChildren: Boolean); override;
658
procedure OnStringListChange(Sender: TObject);
659
property Row[index: Integer]: TStringList read GetRow write SetRow;
661
property HeaderColor: TDelphiColor read GetHeaderColor write SetHeaderColor;
662
property Columns: TStrings read FColumns write SetColumns;
663
property MarginSize: Integer read FMarginSize write SetMarginSize;
664
property ColumnSize: Integer read FColumnSize write SetColumnSize;
665
property RowHeight: Integer read FRowHeight write SetRowHeight;
666
property RowCount: Integer read GetRowCount write SetRowCount;
667
property SelCol: Integer read FSelCol write SetSelCol;
668
property SelRow: Integer read FSelRow write SetSelRow;
669
property RowSelect: Boolean read FRowSelect write SetRowSelect;
670
property ColSelect: Boolean read FColSelect write SetColSelect;
671
property DrawHeader: Boolean read FDrawHeader write SetDrawHeader;
672
property Scrollbar: TGLScrollbar read FScrollbar write SetScrollbar;
675
function UnpressGroup(CurrentObject: TGLBaseSceneObject; AGroupID: Integer):
680
uses GLObjects, GLState, GLUtils, Math;
682
function UnpressGroup(CurrentObject: TGLBaseSceneObject; AGroupID: Integer):
690
if CurrentObject is TGLButton then
691
with CurrentObject as TGLButton do
693
if Group = AGroupID then
702
if CurrentObject is TGLCheckBox then
703
with CurrentObject as TGLCheckBox do
705
if Group = AGroupID then
714
for XC := 0 to CurrentObject.Count - 1 do
716
if UnpressGroup(CurrentObject.Children[XC], AGroupID) then
724
procedure TGLBaseComponent.SetGUIRedraw(value: Boolean);
730
if csDestroying in ComponentState then
732
if (FRedrawAtOnce) or (csDesigning in ComponentState) then
740
procedure TGLBaseComponent.BlockRender;
743
while BlockedCount <> 0 do
745
BlockRendering := True;
746
while RenderingCount <> BlockedCount do
750
procedure TGLBaseComponent.UnBlockRender;
753
BlockRendering := False;
756
procedure TGLBaseComponent.RenderHeader(var rci: TGLRenderContextInfo; renderSelf,
757
renderChildren: Boolean);
762
FGuiLayout.Material.Apply(rci);
763
if AlphaChannel <> 1 then
764
rci.GLStates.SetGLMaterialAlphaChannel(GL_FRONT, AlphaChannel);
766
GL.MatrixMode(GL_MODELVIEW);
768
GL.LoadMatrixf(@TGLSceneBuffer(rci.buffer).BaseProjectionMatrix);
769
if rci.renderDPI = 96 then
772
f := rci.renderDPI / 96;
773
GL.Scalef(f * 2 / rci.viewPortSize.cx, f * 2 / rci.viewPortSize.cy, 1);
774
GL.Translatef(f * Position.X - rci.viewPortSize.cx * 0.5,
775
rci.viewPortSize.cy * 0.5 - f * Position.Y, 0);
776
if Rotation <> 0 then
777
GL.Rotatef(Rotation, 0, 0, 1);
778
GL.MatrixMode(GL_PROJECTION);
781
rci.GLStates.Disable(stDepthTest);
782
rci.GLStates.DepthWriteMask := False;
785
procedure TGLBaseComponent.RenderFooter(var rci: TGLRenderContextInfo; renderSelf,
786
renderChildren: Boolean);
790
GL.MatrixMode(GL_MODELVIEW);
792
FGuiLayout.Material.UnApply(rci);
795
procedure TGLBaseComponent.SetGuiLayout(NewGui: TGLGuiLayout);
798
if FGuiLayout <> NewGui then
800
if Assigned(FGuiLayout) then
802
FGuiLayout.RemoveGuiComponent(Self);
804
FGuiComponent := nil;
805
FGuiLayout := NewGui;
806
if Assigned(FGuiLayout) then
807
if FGuiLayoutName <> '' then
808
FGuiComponent := FGuiLayout.GuiComponents.FindItem(FGuiLayoutName);
810
// in effect this code have been moved...
811
if Assigned(FGuiLayout) then
812
FGuiLayout.AddGuiComponent(Self);
818
procedure TGLBaseComponent.SetGuiLayoutName(NewName: TGLGuiComponentName);
821
if FGuiLayoutName <> NewName then
823
FGuiComponent := nil;
824
FGuiLayoutName := NewName;
825
if FGuiLayoutName <> '' then
826
if Assigned(FGuiLayout) then
828
FGuiComponent := FGuiLayout.GuiComponents.FindItem(FGuiLayoutName);
834
procedure TGLBaseComponent.Notification(AComponent: TComponent; Operation:
838
if Operation = opRemove then
840
if AComponent = FGuiLayout then
854
procedure TGLBaseComponent.SetRotation(const val: TGLFloat);
856
if FRotation <> val then
866
procedure TGLBaseComponent.SetAlphaChannel(const val: Single);
868
if val <> FAlphaChannel then
875
FAlphaChannel := val;
880
procedure TGLBaseComponent.SetAutosize(const Value: Boolean);
882
MarginLeft, MarginCenter, MarginRight: TGLFloat;
883
MarginTop, MarginMiddle, MarginBottom: TGLFloat;
888
if FAutosize <> Value then
892
if FAutosize and Assigned(FGuiComponent) then
901
for i := 0 to FGuiComponent.Elements.Count - 1 do
902
with FGuiComponent.Elements[i] do
905
GLAlTopLeft, GLAlLeft, GLAlBottomLeft:
907
MarginLeft := Max(MarginLeft, abs(BottomRight.X - TopLeft.X) *
910
GLAlTop, GLAlCenter, GLAlBottom:
912
MarginCenter := Max(MarginCenter, abs(BottomRight.X - TopLeft.X)
915
GLAlTopRight, GLAlRight, GLAlBottomRight:
917
MarginRight := Max(MarginRight, abs(BottomRight.X - TopLeft.X) *
923
for i := 0 to FGuiComponent.Elements.Count - 1 do
924
with FGuiComponent.Elements[i] do
927
GLAlTopLeft, GLAlTop, GLAlTopRight:
929
MarginTop := Max(MarginTop, abs(BottomRight.Y - TopLeft.Y) *
932
GLAlLeft, GLAlCenter, GLAlRight:
934
MarginMiddle := Max(MarginMiddle, abs(BottomRight.Y - TopLeft.Y)
937
GLAlBottomLeft, GLAlBottom, GLAlBottomRight:
939
MarginBottom := Max(MarginBottom, abs(BottomRight.Y - TopLeft.Y)
945
MaxWidth := MarginLeft + MarginCenter + MarginRight;
946
MaxHeight := MarginTop + MarginMiddle + MarginBottom;
951
if MaxHeight > 0 then
960
function TGLBaseComponent.StoreAlphaChannel: Boolean;
962
Result := (FAlphaChannel <> 1);
968
procedure TGLBaseComponent.SetNoZWrite(const val: Boolean);
974
constructor TGLBaseComponent.Create(AOwner: TComponent);
979
FGuiComponent := nil;
980
BlockRendering := False;
986
GuiDestroying := False;
990
destructor TGLBaseComponent.Destroy;
993
GuiDestroying := True;
994
while RenderingCount > 0 do
1001
procedure TGLBaseComponent.NotifyChange(Sender: TObject);
1004
if Sender = FGuiLayout then
1006
if (FGuiLayoutName <> '') and (GuiLayout <> nil) then
1009
FGuiComponent := GuiLayout.GuiComponents.FindItem(FGuiLayoutName);
1017
FGuiComponent := nil;
1023
if Sender = Self then
1031
procedure TGLBaseComponent.MoveGUI(XRel, YRel: Single);
1037
if RedrawAtOnce then
1041
MoveX := MoveX + XRel;
1042
MoveY := MoveY + YRel;
1043
for XC := 0 to Count - 1 do
1044
if Children[XC] is TGLBaseComponent then
1046
(Children[XC] as TGLBaseComponent).MoveGUI(XRel, YRel);
1056
MoveX := MoveX + XRel;
1057
MoveY := MoveY + YRel;
1058
for XC := 0 to Count - 1 do
1059
if Children[XC] is TGLBaseComponent then
1061
(Children[XC] as TGLBaseComponent).MoveGUI(XRel, YRel);
1067
procedure TGLBaseComponent.PlaceGUI(XPos, YPos: Single);
1069
MoveGUI(XPos - Position.X, YPos - Position.Y);
1072
procedure TGLBaseComponent.DoChanges;
1084
Position.X := Position.X + MoveX;
1086
Position.Y := Position.Y + MoveY;
1090
for XC := 0 to Count - 1 do
1091
if Children[XC] is TGLBaseComponent then
1093
(Children[XC] as TGLBaseComponent).DoChanges;
1101
for XC := 0 to Count - 1 do
1102
if Children[XC] is TGLBaseComponent then
1104
(Children[XC] as TGLBaseComponent).DoChanges;
1109
procedure TGLBaseComponent.InternalRender(var rci: TGLRenderContextInfo;
1110
renderSelf, renderChildren: Boolean);
1113
if Assigned(FGuiComponent) then
1116
FGuiComponent.RenderToArea(0, 0, Width, Height, FRenderStatus,
1120
GLOKMessageBox(E.Message,
1121
'Exception in GuiComponents InternalRender function');
1126
procedure TGLBaseComponent.DoRender(var rci: TGLRenderContextInfo; renderSelf,
1127
renderChildren: Boolean);
1132
Inc(RenderingCount);
1133
B := BlockRendering;
1137
while BlockRendering do
1142
if not GuiDestroying then
1144
if FGuiLayout <> nil then
1146
RenderHeader(rci, renderSelf, renderChildren);
1148
InternalRender(rci, RenderSelf, RenderChildren);
1150
RenderFooter(rci, renderSelf, renderChildren);
1151
FReBuildGui := False;
1154
if renderChildren then
1156
Self.RenderChildren(0, Count - 1, rci);
1157
Dec(RenderingCount);
1160
procedure TGLBaseControl.InternalMouseDown(Shift: TShiftState; Button:
1161
TGLMouseButton; X, Y: Integer);
1164
if Assigned(FOnMouseDown) then
1165
FOnMouseDown(Self, Button, Shift, X, Y);
1168
procedure TGLBaseControl.InternalMouseUp(Shift: TShiftState; Button:
1169
TGLMouseButton; X, Y: Integer);
1172
if Assigned(FOnMouseUp) then
1173
FOnMouseUp(Self, Button, Shift, X, Y);
1176
procedure TGLBaseControl.InternalMouseMove(Shift: TShiftState; X, Y: Integer);
1179
if Assigned(FOnMouseMove) then
1180
FOnMouseMove(Self, Shift, X, Y);
1183
procedure TGLBaseControl.SetActiveControl(NewControl: TGLBaseControl);
1186
FActiveControl := NewControl;
1189
procedure TGLBaseControl.SetFocusedControl(NewControl: TGLFocusControl);
1192
if NewControl <> FFocusedControl then
1194
if Assigned(FFocusedControl) then
1195
FFocusedControl.Focused := False;
1196
FFocusedControl := NewControl;
1197
if Assigned(FFocusedControl) then
1198
FFocusedControl.Focused := True;
1202
function TGLBaseControl.FindFirstGui: TGLBaseControl;
1205
tmpFirst: TGLBaseControl;
1206
TmpRoot: TGLBaseSceneObject;
1212
while (TmpRoot is TGLBaseComponent) do
1214
if Assigned(TmpRoot.parent) then
1216
if TmpRoot.parent is TGLBaseComponent then
1218
TmpRoot := TmpRoot.parent as TGLBaseComponent;
1219
if TmpRoot is TGLBaseControl then
1220
tmpFirst := TmpRoot as TGLBaseControl;
1231
procedure TGLBaseControl.Notification(AComponent: TComponent;
1232
Operation: TOperation);
1234
if Operation = opRemove then
1236
if FEnteredControl <> nil then
1238
FEnteredControl.DoMouseLeave;
1239
FEnteredControl := nil;
1246
function TGLBaseControl.MouseDown(Sender: TObject; Button: TGLMouseButton;
1247
Shift: TShiftState; X, Y: Integer): Boolean;
1250
AcceptMouseEvent: Boolean;
1255
AcceptMouseEvent := RecursiveVisible and ((Position.X <= X) and (Position.X +
1256
Width > X) and (Position.Y <= Y) and (Position.Y + Height > Y));
1257
if Assigned(OnAcceptMouseQuery) then
1258
OnAcceptMouseQuery(Self, shift, ma_mousedown, Button, X, Y,
1261
if AcceptMouseEvent then
1264
if not FKeepMouseEvents then
1266
if Assigned(FActiveControl) then
1267
if FActiveControl.MouseDown(Sender, Button, Shift, X, Y) then
1270
for XC := count - 1 downto 0 do
1271
if FActiveControl <> Children[XC] then
1273
if Children[XC] is TGLBaseControl then
1275
if (Children[XC] as TGLBaseControl).MouseDown(Sender, button, shift,
1281
InternalMouseDown(Shift, Button, X, Y);
1285
function TGLBaseControl.MouseUp(Sender: TObject; Button: TGLMouseButton; Shift:
1286
TShiftState; X, Y: Integer): Boolean;
1289
AcceptMouseEvent: Boolean;
1294
AcceptMouseEvent := RecursiveVisible and ((Position.X <= X) and (Position.X +
1295
Width > X) and (Position.Y <= Y) and (Position.Y + Height > Y));
1296
if Assigned(OnAcceptMouseQuery) then
1297
OnAcceptMouseQuery(Self, shift, ma_mouseup, Button, X, Y, AcceptMouseEvent);
1299
if AcceptMouseEvent then
1302
if not FKeepMouseEvents then
1304
if Assigned(FActiveControl) then
1305
if FActiveControl.MouseUp(Sender, button, shift, x, y) then
1308
for XC := count - 1 downto 0 do
1309
if FActiveControl <> Children[XC] then
1311
if Children[XC] is TGLBaseControl then
1313
if (Children[XC] as TGLBaseControl).MouseUp(Sender, button, shift,
1319
InternalMouseUp(Shift, Button, X, Y);
1323
function TGLBaseControl.MouseMove(Sender: TObject; Shift: TShiftState; X, Y:
1327
AcceptMouseEvent: Boolean;
1332
AcceptMouseEvent := RecursiveVisible and ((Position.X <= X) and (Position.X +
1333
Width > X) and (Position.Y <= Y) and (Position.Y + Height > Y));
1334
if Assigned(OnAcceptMouseQuery) then
1335
OnAcceptMouseQuery(Self, shift, ma_mousemove, mbMiddle, X, Y,
1338
if AcceptMouseEvent then
1341
if not FKeepMouseEvents then
1343
if Assigned(FActiveControl) then
1344
if FActiveControl.MouseMove(Sender, shift, x, y) then
1347
for XC := count - 1 downto 0 do
1348
if FActiveControl <> Children[XC] then
1350
if Children[XC] is TGLBaseControl then
1352
if (Children[XC] as TGLBaseControl).MouseMove(Sender, shift, x, y)
1355
if FEnteredControl <> (Children[XC] as TGLBaseControl) then
1357
if FEnteredControl <> nil then
1359
FEnteredControl.DoMouseLeave;
1362
FEnteredControl := (Children[XC] as TGLBaseControl);
1364
if FEnteredControl <> nil then
1366
FEnteredControl.DoMouseEnter;
1376
if FEnteredControl <> nil then
1378
FEnteredControl.DoMouseLeave;
1379
FEnteredControl := nil;
1382
InternalMouseMove(Shift, X, Y);
1386
procedure TGLBaseControl.KeyDown(Sender: TObject; var Key: Word; Shift:
1389
if Assigned(FFocusedControl) then
1391
FFocusedControl.KeyDown(Sender, Key, Shift);
1395
procedure TGLBaseControl.KeyUp(Sender: TObject; var Key: Word; Shift:
1398
if Assigned(FFocusedControl) then
1400
FFocusedControl.KeyUp(Sender, Key, Shift);
1404
procedure TGLBaseControl.KeyPress(Sender: TObject; var Key: Char);
1407
if Assigned(FFocusedControl) then
1409
FFocusedControl.KeyPress(Sender, Key);
1413
procedure TGLFocusControl.InternalKeyPress(var Key: Char);
1415
if assigned(FOnKeyPress) then
1416
FOnKeyPress(Self, Key);
1419
procedure TGLFocusControl.InternalKeyDown(var Key: Word; Shift: TShiftState);
1421
if assigned(FOnKeyDown) then
1422
FOnKeyDown(Self, Key, shift);
1425
procedure TGLFocusControl.InternalKeyUp(var Key: Word; Shift: TShiftState);
1427
if assigned(FOnKeyUp) then
1428
FOnKeyUp(Self, Key, shift);
1431
procedure TGLBaseControl.DoMouseEnter;
1433
if Assigned(OnMouseEnter) then
1437
procedure TGLBaseControl.DoMouseLeave;
1439
//leave all child controls
1440
if FEnteredControl <> nil then
1442
FEnteredControl.DoMouseLeave;
1443
FEnteredControl := nil;
1446
if Assigned(OnMouseLeave) then
1450
procedure TGLFocusControl.SetFocused(Value: Boolean);
1452
if Value <> FFocused then
1459
function TGLFocusControl.GetRootControl: TGLBaseControl;
1462
if not Assigned(FRootControl) then
1464
FRootControl := FindFirstGui;
1466
Result := FRootControl;
1469
procedure TGLFocusControl.NotifyHide;
1473
if (RootControl.FFocusedControl = Self) and (self.focused) then
1475
RootControl.FocusedControl.PrevControl;
1479
procedure TGLFocusControl.ReGetRootControl;
1482
FRootControl := FindFirstGui;
1485
function TGLFocusControl.GetFocusedColor: TDelphiColor;
1488
Result := ConvertColorVector(FFocusedColor);
1491
procedure TGLFocusControl.SetFocusedColor(const Val: TDelphiColor);
1494
FFocusedColor := ConvertWinColor(val);
1498
procedure TGLFocusControl.SetFocus;
1501
RootControl.FocusedControl := Self;
1504
procedure TGLFocusControl.NextControl;
1507
Host: TGLBaseComponent;
1509
IndexedChild: TGLBaseComponent;
1510
RestartedLoop: Boolean;
1513
RestartedLoop := False;
1514
if Parent is TGLBaseComponent then
1516
Host := Parent as TGLBaseComponent;
1517
Index := Host.IndexOfChild(Self);
1518
while not Host.RecursiveVisible do
1520
if Host.Parent is TGLBaseComponent then
1522
IndexedChild := Host;
1523
Host := Host.Parent as TGLBaseComponent;
1524
Index := Host.IndexOfChild(IndexedChild);
1528
RootControl.FocusedControl := nil;
1538
if Host.Children[Index] is TGLFocusControl then
1540
with (Host.Children[Index] as TGLFocusControl) do
1541
if RecursiveVisible then
1549
if Host.Children[Index] is TGLBaseComponent then
1551
IndexedChild := Host.Children[Index] as TGLBaseComponent;
1552
if IndexedChild.RecursiveVisible then
1554
Host := IndexedChild;
1555
Index := Host.Count;
1562
if Host.Parent is TGLBaseComponent then
1564
Index := Host.Parent.IndexOfChild(Host);
1565
Host := Host.Parent as TGLBaseComponent;
1569
if RestartedLoop then
1574
Index := Host.Count;
1575
RestartedLoop := True;
1582
procedure TGLFocusControl.PrevControl;
1585
Host: TGLBaseComponent;
1587
IndexedChild: TGLBaseComponent;
1588
RestartedLoop: Boolean;
1591
RestartedLoop := False;
1592
if Parent is TGLBaseComponent then
1594
Host := Parent as TGLBaseComponent;
1595
Index := Host.IndexOfChild(Self);
1596
while not Host.RecursiveVisible do
1598
if Host.Parent is TGLBaseComponent then
1600
IndexedChild := Host;
1601
Host := Host.Parent as TGLBaseComponent;
1602
Index := Host.IndexOfChild(IndexedChild);
1606
RootControl.FocusedControl := nil;
1615
if Index < Host.Count then
1617
if Host.Children[Index] is TGLFocusControl then
1619
with (Host.Children[Index] as TGLFocusControl) do
1620
if RecursiveVisible then
1626
if Host.Children[Index] is TGLBaseComponent then
1628
IndexedChild := Host.Children[Index] as TGLBaseComponent;
1629
if IndexedChild.RecursiveVisible then
1631
Host := IndexedChild;
1638
if Host.Parent is TGLBaseComponent then
1640
IndexedChild := Host;
1641
Host := Host.Parent as TGLBaseComponent;
1642
Index := Host.IndexOfChild(IndexedChild);
1646
if RestartedLoop then
1648
RootControl.FocusedControl := nil;
1652
RestartedLoop := True;
1659
procedure TGLFocusControl.KeyPress(Sender: TObject; var Key: Char);
1662
InternalKeyPress(Key);
1665
if ssShift in FShiftState then
1676
procedure TGLFocusControl.KeyDown(Sender: TObject; var Key: Word; Shift:
1679
FShiftState := Shift;
1680
InternalKeyDown(Key, Shift);
1681
if Key = glKey_TAB then
1683
if ssShift in FShiftState then
1694
procedure TGLFocusControl.KeyUp(Sender: TObject; var Key: Word; Shift:
1697
FShiftState := Shift;
1698
InternalKeyUp(Key, Shift);
1699
if Key = glKey_TAB then
1701
if ssShift in FShiftState then
1713
{ base font control }
1715
constructor TGLBaseFontControl.Create(AOwner: TComponent);
1720
FDefaultColor := clrBlack;
1723
destructor TGLBaseFontControl.Destroy;
1729
procedure TGLBaseFontControl.SetBitmapFont(NewFont: TGLCustomBitmapFont);
1732
if NewFont <> FBitmapFont then
1734
if Assigned(FBitmapFont) then
1736
FBitmapFont.RemoveFreeNotification(Self);
1737
FBitmapFont.UnRegisterUser(Self);
1739
FBitmapFont := NewFont;
1740
if Assigned(FBitmapFont) then
1742
FBitmapFont.RegisterUser(Self);
1743
FBitmapFont.FreeNotification(Self);
1749
function TGLBaseFontControl.GetBitmapFont: TGLCustomBitmapFont;
1753
if Assigned(FBitmapFont) then
1754
Result := FBitmapFont
1755
else if Assigned(GuiLayout) then
1756
if Assigned(GuiLayout.BitmapFont) then
1758
if not (csDesigning in ComponentState) then
1760
if not GuiDestroying then
1762
BitmapFont := GuiLayout.BitmapFont;
1763
Result := FBitmapFont;
1767
Result := GuiLayout.BitmapFont;
1771
function TGLBaseFontControl.GetDefaultColor: TDelphiColor;
1774
Result := ConvertColorVector(FDefaultColor);
1777
procedure TGLBaseFontControl.SetDefaultColor(value: TDelphiColor);
1780
FDefaultColor := ConvertWinColor(value);
1785
procedure TGLBaseFontControl.Notification(AComponent: TComponent; Operation:
1788
if (Operation = opRemove) and (AComponent = FBitmapFont) then
1799
procedure TGLBaseTextControl.SetCaption(const NewCaption: UnicodeString);
1802
FCaption := NewCaption;
1806
procedure TGLBaseFontControl.WriteTextAt(var rci: TGLRenderContextInfo; const X,
1807
Y: TGLFloat; const Data: UnicodeString; const Color: TColorVector);
1811
if Assigned(BitmapFont) then
1813
Position.V[0] := Round(X);
1814
Position.V[1] := Round(Y);
1817
BitmapFont.RenderString(rci, Data, taLeftJustify, tlTop, Color, @Position);
1821
procedure TGLBaseFontControl.WriteTextAt(var rci: TGLRenderContextInfo; const X1,
1822
Y1, X2, Y2: TGLFloat; const Data: UnicodeString; const Color: TColorVector);
1826
if Assigned(BitmapFont) then
1828
Position.V[0] := Round(((X2 + X1 -
1829
BitmapFont.CalcStringWidth(Data)) * 0.5));
1830
Position.V[1] := Round(-((Y2 + Y1 - GetFontHeight) * 0.5)) + 2;
1833
BitmapFont.RenderString(rci, Data, taLeftJustify, tlTop, Color, @Position);
1837
function TGLBaseFontControl.GetFontHeight: Integer;
1840
if Assigned(BitmapFont) then
1841
if BitmapFont is TGLWindowsBitmapFont then
1842
Result := Abs((BitmapFont as TGLWindowsBitmapFont).Font.Height)
1844
Result := BitmapFont.CharHeight
1849
constructor TGLCustomControl.Create(AOwner: TComponent);
1853
FMaterial := TGLMaterial.create(Self);
1854
FBitmap := TGLBitmap.create;
1855
FBitmap.OnChange := OnBitmapChanged;
1856
FInternalBitmap := nil;
1857
FInvalidRenderCount := 0;
1863
destructor TGLCustomControl.Destroy;
1865
if Assigned(FInternalBitmap) then
1866
FInternalBitmap.Free;
1872
procedure TGLCustomControl.SetCentered(const Value: Boolean);
1877
procedure TGLCustomControl.OnBitmapChanged(Sender: TObject);
1879
FBitmapChanged := True;
1882
procedure TGLCustomControl.SetBitmap(ABitmap: TGLBitmap);
1884
FBitmap.Assign(ABitmap);
1887
procedure TGLCustomControl.InternalRender(var rci: TGLRenderContextInfo;
1888
renderSelf, renderChildren: Boolean);
1891
X1, X2, Y1, Y2: Single;
1894
if Assigned(OnRender) then
1895
OnRender(self, FBitmap);
1897
if FBitmapChanged then
1898
if FInvalidRenderCount >= FMaxInvalidRenderCount then
1900
FInvalidRenderCount := 0;
1901
if not Assigned(FInternalBitmap) then
1902
FInternalBitmap := TGLBitmap.Create;
1904
FInternalBitmap.PixelFormat := FBitmap.PixelFormat;
1905
FInternalBitmap.Width := RoundUpToPowerOf2(FBitmap.Width);
1906
FInternalBitmap.Height := RoundUpToPowerOf2(FBitmap.Height);
1907
FInternalBitmap.Canvas.CopyRect(FBitmap.Canvas.ClipRect, FBitmap.Canvas,
1908
FBitmap.Canvas.ClipRect);
1909
FBitmapChanged := False;
1910
with Material.GetActualPrimaryTexture do
1913
Image.Assign(FInternalBitmap);
1915
FXTexCoord := FBitmap.Width / FInternalBitmap.Width;
1916
FYTexCoord := FBitmap.Height / FInternalBitmap.Height;
1919
Inc(FInvalidRenderCount);
1921
if Assigned(FGuiComponent) then
1925
FGuiComponent.RenderToArea(-Width / 2, -Height / 2, Width, Height,
1926
FRenderStatus, FReBuildGui)
1928
FGuiComponent.RenderToArea(0, 0, Width, Height, FRenderStatus,
1932
GLOKMessageBox(E.Message,
1933
'Exception in TGLCustomControl InternalRender function');
1935
X1 := FRenderStatus[GLAlCenter].X1;
1936
X2 := FRenderStatus[GLAlCenter].X2;
1937
Y1 := -FRenderStatus[GLAlCenter].Y2;
1938
Y2 := -FRenderStatus[GLAlCenter].Y1;
1958
GuiLayout.Material.UnApply(rci);
1959
Material.Apply(rci);
1960
GL.Begin_(GL_QUADS);
1962
GL.TexCoord2f(FXTexCoord, -FYTexCoord);
1963
GL.Vertex2f(X2, Y2);
1965
GL.TexCoord2f(FXTexCoord, 0);
1966
GL.Vertex2f(X2, Y1);
1968
GL.TexCoord2f(0, 0);
1969
GL.Vertex2f(X1, Y1);
1971
GL.TexCoord2f(0, -FYTexCoord);
1972
GL.Vertex2f(X1, Y2);
1976
Material.UnApply(rci);
1977
GuiLayout.Material.Apply(rci);
1980
procedure TGLCustomControl.SetMaterial(AMaterial: TGLMaterial);
1983
FMaterial.Assign(AMaterial);
1986
procedure TGLPopupMenu.SetFocused(Value: Boolean);
1990
if not (csDesigning in ComponentState) then
1991
if not FFocused then
1995
procedure TGLPopupMenu.SetMenuItems(Value: TStrings);
1998
FMenuItems.Assign(Value);
2002
procedure TGLPopupMenu.SetMarginSize(const val: Single);
2005
if FMarginSize <> val then
2012
procedure TGLPopupMenu.SetSelIndex(const val: Integer);
2015
if FSelIndex <> val then
2022
procedure TGLPopupMenu.InternalMouseDown(Shift: TShiftState; Button:
2023
TGLMouseButton; X, Y: Integer);
2025
ClickIndex: Integer;
2030
Tx := X - Position.X;
2031
Ty := Y - Position.Y;
2032
if Button = mbLeft then
2033
if IsInRect(fRenderStatus[glAlCenter], Tx, Ty) then
2034
if Assigned(BitmapFont) then
2036
ClickIndex := Round(Int((Ty - fRenderStatus[glAlCenter].y1) /
2037
BitmapFont.CharHeight));
2038
if (ClickIndex >= 0) and (ClickIndex < FMenuItems.Count) then
2040
if Assigned(OnClick) then
2041
OnClick(Self, ClickIndex, FMenuItems[ClickIndex]);
2047
procedure TGLPopupMenu.InternalMouseMove(Shift: TShiftState; X, Y: Integer);
2052
Tx := X - Position.X;
2053
Ty := Y - Position.Y;
2054
if IsInRect(fRenderStatus[glAlCenter], Tx, Ty) then
2055
if Assigned(BitmapFont) then
2057
SelIndex := Round(Int((Ty - fRenderStatus[glAlCenter].y1) /
2058
BitmapFont.CharHeight));
2062
procedure TGLPopupMenu.OnStringListChange(Sender: TObject);
2065
CenterHeight: Single;
2068
if not FReBuildGui then
2070
if Assigned(BitmapFont) then
2071
with FRenderStatus[GLalCenter] do
2073
CenterHeight := Y2 - Y1;
2074
CenterHeight := Round(CenterHeight + 0.499);
2075
TextHeight := BitmapFont.CharHeight * FMenuItems.Count;
2076
if CenterHeight <> TextHeight then // allways round up!
2078
Height := Height + TextHeight - CenterHeight;
2084
constructor TGLPopupMenu.Create(AOwner: TComponent);
2088
FMenuItems := TStringList.Create;
2089
(FMenuItems as TStringList).OnChange := OnStringListChange;
2094
destructor TGLPopupMenu.Destroy;
2100
procedure TGLPopupMenu.PopUp(Px, Py: Integer);
2106
RootControl.ActiveControl := Self;
2109
procedure TGLPopupMenu.InternalRender(var rci: TGLRenderContextInfo; renderSelf,
2110
renderChildren: Boolean);
2113
CenterHeight: Single;
2118
changedHeight: single;
2120
if Assigned(FGuiComponent) then
2123
if NewHeight <> -1 then
2124
FGuiComponent.RenderToArea(0, 0, Width, NewHeight, FRenderStatus,
2127
FGuiComponent.RenderToArea(0, 0, Width, Height, FRenderStatus,
2131
GLOKMessageBox(E.Message,
2132
'Exception in GuiComponents InternalRender function');
2135
if Assigned(BitmapFont) and (FMenuItems.Count > 0) then
2136
with FRenderStatus[GLalCenter] do
2138
CenterHeight := Y2 - Y1;
2139
CenterHeight := Round(CenterHeight + 0.499);
2140
TextHeight := BitmapFont.CharHeight * FMenuItems.Count;
2141
if CenterHeight <> TextHeight then // allways round up!
2143
changedHeight := Height + TextHeight - CenterHeight;
2144
if changedHeight <> newHeight then
2146
newHeight := changedHeight;
2147
InternalRender(rci, RenderSelf, RenderChildren);
2153
XPos := X1 + MarginSize;
2154
for XC := 0 to FMenuItems.count - 1 do
2156
if FSelIndex = XC then
2157
WriteTextAt(rci, XPos, YPos, FMenuItems[XC], FFocusedColor)
2159
WriteTextAt(rci, XPos, YPos, FMenuItems[XC], FDefaultColor);
2160
YPos := YPos - BitmapFont.CharHeight;
2166
procedure TGLPopupMenu.DoRender(var rci: TGLRenderContextInfo; renderSelf,
2167
renderChildren: Boolean);
2171
// to avoid gui render-block deadlock!
2172
if NewHeight <> -1 then
2174
Height := NewHeight;
2179
function TGLPopupMenu.MouseDown(Sender: TObject; Button: TGLMouseButton; Shift:
2180
TShiftState; X, Y: Integer): Boolean;
2182
Result := inherited MouseDown(Sender, Button, Shift, X, Y);
2184
if (not Result) and (RootControl.ActiveControl = Self) then
2186
RootControl.ActiveControl := nil;
2191
procedure TGLForm.InternalMouseDown(Shift: TShiftState; Button: TGLMouseButton;
2199
YHere := Y - Position.Y;
2200
if YHere < FRenderStatus[GLALTop].Y2 then
2202
if Button = mbLeft then
2204
{ If contains(Width-22,Width-6,XHere) and contains(8,24,YHere) then
2210
if Assigned(FOnCanMove) then
2211
FOnCanMove(Self, CanMove);
2217
if Parent is TGLFocusControl then
2218
(Parent as TGLFocusControl).ActiveControl := Self;
2227
procedure TGLForm.InternalMouseUp(Shift: TShiftState; Button: TGLMouseButton; X,
2231
if (Button = mbLeft) and Moving then
2234
if Parent is TGLFocusControl then
2235
(Parent as TGLFocusControl).ActiveControl := nil;
2239
if Y - Position.Y < 27 then
2246
procedure TGLForm.InternalMouseMove(Shift: TShiftState; X, Y: Integer);
2254
if (X <> OldX) or (Y <> OldY) then
2259
XRel := XRel + Position.X;
2260
YRel := YRel + Position.Y;
2261
if Assigned(OnMoving) then
2262
OnMoving(Self, XRel, YRel);
2263
XRel := XRel - Position.X;
2264
YRel := YRel - Position.Y;
2266
MoveGUI(XRel, YRel);
2272
else if Y - Position.Y < 27 then
2280
function TGLForm.GetTitleColor: TDelphiColor;
2283
Result := ConvertColorVector(FTitleColor);
2286
procedure TGLForm.SetTitleColor(value: TDelphiColor);
2289
FTitleColor := ConvertWinColor(value);
2293
constructor TGLForm.Create(AOwner: TComponent);
2300
procedure TGLForm.Close;
2303
HowClose: TGLFormCloseOptions;
2306
HowClose := co_hide;
2307
if Assigned(FOnCanClose) then
2308
FOnCanClose(Self, HowClose);
2310
co_hide: Visible := False;
2316
procedure TGLForm.NotifyShow;
2320
if Assigned(FOnShow) then
2324
procedure TGLForm.NotifyHide;
2328
if Assigned(FOnHide) then
2332
function TGLForm.MouseUp(Sender: TObject; Button: TGLMouseButton; Shift:
2333
TShiftState; X, Y: Integer): Boolean;
2336
if (Button = mbLeft) and (Moving) then
2339
InternalMouseUp(Shift, Button, X, Y);
2342
Result := inherited MouseUp(Sender, Button, Shift, X, Y);
2345
function TGLForm.MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer):
2352
InternalMouseMove(Shift, X, Y);
2355
Result := inherited MouseMove(Sender, Shift, X, Y);
2358
procedure TGLForm.InternalRender(var rci: TGLRenderContextInfo; renderSelf,
2359
renderChildren: Boolean);
2361
ATitleColor: TColorVector;
2363
if Assigned(FGuiComponent) then
2365
FGuiComponent.RenderToArea(0, 0, Width, Height, FRenderStatus, FReBuildGui);
2367
ATitleColor := FTitleColor;
2368
ATitleColor.V[3] := AlphaChannel;
2370
WriteTextAt(rci, ((FRenderStatus[GLAlTop].X2 + FRenderStatus[GLAlTop].X1 -
2371
BitmapFont.CalcStringWidth(Caption)) * 0.5),
2372
-((FRenderStatus[GLAlTop].Y2 + FRenderStatus[GLAlTop].Y1 - GetFontHeight) *
2373
0.5) + TitleOffset, Caption, ATitleColor);
2377
procedure TGLCheckBox.SetChecked(NewChecked: Boolean);
2380
if NewChecked <> FChecked then
2386
UnpressGroup(FindFirstGui, Group);
2388
FChecked := NewChecked;
2394
if Assigned(FOnChange) then
2399
procedure TGLCheckBox.InternalMouseDown(Shift: TShiftState; Button:
2400
TGLMouseButton; X, Y: Integer);
2402
Checked := not Checked;
2406
procedure TGLCheckBox.InternalMouseUp(Shift: TShiftState; Button:
2407
TGLMouseButton; X, Y: Integer);
2413
procedure TGLCheckBox.SetGuiLayoutNameChecked(newName: TGLGuiComponentName);
2416
if FGuiLayoutNameChecked <> NewName then
2418
FGuiCheckedComponent := nil;
2419
FGuiLayoutNameChecked := NewName;
2420
if Assigned(FGuiLayout) then
2422
FGuiCheckedComponent :=
2423
FGuiLayout.GuiComponents.FindItem(FGuiLayoutNameChecked);
2424
FReBuildGui := True;
2430
procedure TGLCheckBox.SetGuiLayout(NewGui: TGLGuiLayout);
2433
FGuiCheckedComponent := nil;
2435
if Assigned(FGuiLayout) then
2437
FGuiCheckedComponent :=
2438
FGuiLayout.GuiComponents.FindItem(FGuiLayoutNameChecked);
2439
FReBuildGui := True;
2444
procedure TGLCheckBox.SetGroup(const val: Integer);
2452
UnpressGroup(FindFirstGui, val);
2458
constructor TGLCheckBox.Create(AOwner: TComponent);
2466
procedure TGLCheckBox.InternalRender(var rci: TGLRenderContextInfo; renderSelf,
2467
renderChildren: Boolean);
2471
if Assigned(FGuiCheckedComponent) then
2473
FGuiCheckedComponent.RenderToArea(0, 0, Width, Height, FRenderStatus,
2479
if Assigned(FGuiComponent) then
2481
FGuiComponent.RenderToArea(0, 0, Width, Height, FRenderStatus,
2487
procedure TGLCheckBox.NotifyChange(Sender: TObject);
2490
if Sender = FGuiLayout then
2492
if (FGuiLayoutNameChecked <> '') and (GuiLayout <> nil) then
2495
FGuiCheckedComponent :=
2496
GuiLayout.GuiComponents.FindItem(FGuiLayoutNameChecked);
2504
FGuiCheckedComponent := nil;
2513
procedure TGLButton.SetPressed(NewPressed: Boolean);
2516
if FPressed <> NewPressed then
2522
UnpressGroup(RootControl, Group);
2524
FPressed := NewPressed;
2530
if Assigned(FOnButtonClick) then
2531
FOnButtonClick(Self);
2537
procedure TGLButton.InternalMouseDown(Shift: TShiftState; Button:
2538
TGLMouseButton; X, Y: Integer);
2542
if Button = mbLeft then
2544
Pressed := not Pressed
2549
procedure TGLButton.InternalMouseUp(Shift: TShiftState; Button: TGLMouseButton;
2553
if (Button = mbLeft) and (Group < 0) then
2558
procedure TGLButton.InternalKeyDown(var Key: Word; Shift: TShiftState);
2562
if Key = glKey_SPACE then
2566
if Key = glKey_RETURN then
2572
procedure TGLButton.InternalKeyUp(var Key: Word; Shift: TShiftState);
2575
if ((Key = glKey_SPACE) or (Key = glKey_RETURN)) and (Group < 0) then
2582
procedure TGLButton.SetFocused(Value: Boolean);
2585
if (not FFocused) and (Group < 0) then
2589
procedure TGLButton.SetGuiLayoutNamePressed(newName: TGLGuiComponentName);
2592
if FGuiLayoutNamePressed <> NewName then
2594
FGuiPressedComponent := nil;
2595
FGuiLayoutNamePressed := NewName;
2596
if Assigned(FGuiLayout) then
2598
FGuiPressedComponent :=
2599
FGuiLayout.GuiComponents.FindItem(FGuiLayoutNamePressed);
2600
FReBuildGui := True;
2606
procedure TGLButton.SetGuiLayout(NewGui: TGLGuiLayout);
2609
FGuiPressedComponent := nil;
2611
if Assigned(FGuiLayout) then
2613
FGuiPressedComponent :=
2614
FGuiLayout.GuiComponents.FindItem(FGuiLayoutNamePressed);
2615
FReBuildGui := True;
2620
procedure TGLButton.SetBitBtn(AValue: TGLMaterial);
2623
FBitBtn.Assign(AValue);
2627
procedure TGLButton.DestroyHandle;
2630
FBitBtn.DestroyHandles;
2633
procedure TGLButton.SetGroup(const val: Integer);
2641
UnpressGroup(RootControl, Group);
2647
procedure TGLButton.SetLogicWidth(const val: single);
2654
procedure TGLButton.SetLogicHeight(const val: single);
2657
FLogicHeight := val;
2661
procedure TGLButton.SetXOffset(const val: single);
2668
procedure TGLButton.SetYOffset(const val: single);
2675
constructor TGLButton.Create(AOwner: TComponent);
2677
inherited Create(AOwner);
2678
FBitBtn := TGLMaterial.Create(Self);
2683
destructor TGLButton.Destroy;
2689
procedure TGLButton.InternalRender(var rci: TGLRenderContextInfo; renderSelf,
2690
renderChildren: Boolean);
2696
Material: TGLMaterial;
2697
LibMaterial: TGLLibMaterial;
2698
TextColor: TColorVector;
2703
if Assigned(FGuiPressedComponent) then
2705
FGuiPressedComponent.RenderToArea(0, 0, Width, Height, FRenderStatus,
2711
if Assigned(FGuiComponent) then
2713
FGuiComponent.RenderToArea(0, 0, Width, Height, FRenderStatus,
2718
B := not BitBtn.Texture.Disabled;
2722
if (BitBtn.MaterialLibrary <> nil) and (BitBtn.MaterialLibrary is
2723
TGLMaterialLibrary) then
2727
TGLMaterialLibrary(BitBtn.MaterialLibrary).Materials.GetLibMaterialByName(BitBtn.LibMaterialName);
2728
if LibMaterial <> nil then
2730
Material := LibMaterial.Material;
2741
with FRenderStatus[GLAlCenter] do
2743
GuiLayout.Material.UnApply(rci);
2746
TexWidth := Material.Texture.TexWidth;
2747
if TexWidth = 0 then
2748
TexWidth := Material.Texture.Image.Width;
2750
TexHeight := Material.Texture.TexHeight;
2751
if TexHeight = 0 then
2752
TexHeight := Material.Texture.Image.Height;
2754
GL.Begin_(GL_QUADS);
2756
GL.TexCoord2f(0, 0);
2757
GL.Vertex2f(X1 - XOffSet, -Y1 + YOffSet);
2759
GL.TexCoord2f(0, -(LogicHeight - 1) / TexHeight);
2760
GL.Vertex2f(X1 - XOffSet, -Y1 + YOffset - LogicHeight + 1);
2762
GL.TexCoord2f((LogicWidth - 1) / TexWidth, -(LogicHeight - 1) /
2764
GL.Vertex2f(X1 - XOffSet + LogicWidth - 1, -Y1 + YOffset - LogicHeight +
2767
GL.TexCoord2f((LogicWidth - 1) / TexWidth, 0);
2768
GL.Vertex2f(X1 - XOffSet + LogicWidth - 1, -Y1 + YOffSet);
2771
BitBtn.UnApply(rci);
2772
GuiLayout.Material.Apply(rci);
2775
if Assigned(BitmapFont) then
2780
TextColor := FFocusedColor;
2784
TextColor := FDefaultColor;
2786
TextColor.V[3] := AlphaChannel;
2788
WriteTextAt(rci, FRenderStatus[GLALCenter].X1,
2789
FRenderStatus[GLALCenter].Y1,
2790
FRenderStatus[GLALCenter].X2,
2791
FRenderStatus[GLALCenter].Y2,
2797
procedure TGLEdit.InternalMouseDown(Shift: TShiftState; Button: TGLMouseButton;
2800
if not FReadOnly then
2805
procedure TGLEdit.InternalKeyPress(var Key: Char);
2813
if FSelStart > 1 then
2815
system.Delete(FCaption, FSelStart - 1, 1);
2824
system.Insert(Key, FCaption, SelStart);
2832
procedure TGLEdit.InternalKeyDown(var Key: Word; Shift: TShiftState);
2840
if FSelStart <= Length(Caption) then
2842
System.Delete(FCaption, FSelStart, 1);
2848
if FSelStart > 1 then
2856
if FSelStart < Length(Caption) + 1 then
2864
if FSelStart > 1 then
2872
if FSelStart < Length(Caption) + 1 then
2874
FSelStart := Length(Caption) + 1;
2882
procedure TGLEdit.InternalKeyUp(var Key: Word; Shift: TShiftState);
2888
procedure TGLEdit.SetFocused(Value: Boolean);
2893
SelStart := Length(Caption) + 1;
2896
procedure TGLEdit.SetSelStart(const Value: Integer);
2903
procedure TGLEdit.SetEditChar(const Value: string);
2910
constructor TGLEdit.Create(AOwner: TComponent);
2917
procedure TGLEdit.InternalRender(var rci: TGLRenderContextInfo; renderSelf,
2918
renderChildren: Boolean);
2920
Tekst: UnicodeString;
2923
// Renders the background
2924
if Assigned(FGuiComponent) then
2926
FGuiComponent.RenderToArea(0, 0, Width, Height, FRenderStatus, FReBuildGui);
2929
if Assigned(FBitmapFont) then
2935
// First put in the edit character where it should be.
2936
system.insert(FEditChar, Tekst, SelStart);
2937
// Next figure out if the string is too long.
2938
if FBitmapFont.CalcStringWidth(Tekst) > Width - 2 then
2940
// if it is then we need to check to see where SelStart is
2941
if SelStart >= Length(Tekst) - 1 then
2943
// SelStart is within close proximity of the end of the string
2944
// Calculate the % of text that we can use and return it against the length of the string.
2945
pBig := Trunc(Int(((Width - 2) /
2946
FBitmapFont.CalcStringWidth(Tekst)) * Length(Tekst)));
2948
Tekst := Copy(Tekst, Length(Tekst) - pBig + 1, pBig);
2952
// SelStart is within close proximity of the end of the string
2953
// Calculate the % of text that we can use and return it against the length of the string.
2954
pBig := Trunc(Int(((Width - 2) /
2955
FBitmapFont.CalcStringWidth(Tekst)) * Length(Tekst)));
2957
if SelStart + pBig < Length(Tekst) then
2958
Tekst := Copy(Tekst, SelStart, pBig)
2960
Tekst := Copy(Tekst, Length(Tekst) - pBig + 1, pBig);
2965
{ if FFocused then } if FBitmapFont.CalcStringWidth(Tekst) >
2968
// The while loop should never execute more then once, but just in case its here.
2969
while FBitmapFont.CalcStringWidth(Tekst) > Width - 2 do
2971
// Calculate the % of text that we can use and return it against the length of the string.
2972
pBig := Trunc(Int(((Width - 2) /
2973
FBitmapFont.CalcStringWidth(Tekst)) * Length(Tekst)));
2974
Tekst := Copy(Tekst, 1, pBig);
2980
WriteTextAt(rci, FRenderStatus[GLAlLeft].X1, FRenderStatus[GLAlCenter].Y1,
2981
FRenderStatus[GLALCenter].X2, FRenderStatus[GLALCenter].Y2, Tekst,
2986
WriteTextAt(rci, FRenderStatus[GLAlLeft].X1, FRenderStatus[GLAlCenter].Y1,
2987
FRenderStatus[GLALCenter].X2, FRenderStatus[GLALCenter].Y2, Tekst,
2993
constructor TGLLabel.Create(AOwner: TComponent);
2996
FTextLayout := tlCenter;
2999
procedure TGLLabel.InternalRender(var rci: TGLRenderContextInfo; renderSelf,
3000
renderChildren: Boolean);
3004
Tekst: UnicodeString;
3005
TextColor: TColorVector;
3007
if Assigned(BitmapFont) then
3016
TekstPos.V[0] := Width / 2;
3020
TekstPos.V[0] := Width;
3031
TekstPos.V[1] := Round(-Height / 2);
3035
TekstPos.V[1] := -Height;
3044
TextColor := FDefaultColor;
3045
TextColor.V[3] := AlphaChannel;
3047
BitmapFont.RenderString(rci, Tekst, FAlignment, FTextLayout, TextColor,
3052
procedure TGLLabel.SetAlignment(const Value: TAlignment);
3054
if FAlignment <> Value then
3056
FAlignment := Value;
3061
procedure TGLLabel.SetTextLayout(const Value: TGLTextLayout);
3063
if FTextLayout <> Value then
3065
FTextLayout := Value;
3070
procedure TGLAdvancedLabel.InternalRender(var rci: TGLRenderContextInfo;
3071
renderSelf, renderChildren: Boolean);
3074
if Assigned(BitmapFont) then
3078
WriteTextAt(rci, 8, -((Height - GetFontHeight) / 2) + 1, Caption,
3083
WriteTextAt(rci, 8, -((Height - GetFontHeight) / 2) + 1, Caption,
3089
procedure TGLScrollbar.SetMin(const val: Single);
3100
procedure TGLScrollbar.SetMax(const val: Single);
3107
if FPos > (FMax - FPageSize + 1) then
3108
Pos := (FMax - FPageSize + 1);
3113
procedure TGLScrollbar.SetPos(const val: Single);
3120
if FPos > (FMax - FPageSize + 1) then
3121
FPos := (FMax - FPageSize + 1);
3124
if Assigned(FOnChange) then
3129
procedure TGLScrollbar.SetPageSize(const val: Single);
3132
if FPageSize <> val then
3135
if FPos > (FMax - FPageSize + 1) then
3136
Pos := (FMax - FPageSize + 1);
3141
procedure TGLScrollbar.SetHorizontal(const val: Boolean);
3144
if FHorizontal <> val then
3151
procedure TGLScrollbar.SetGuiLayoutKnobName(newName: TGLGuiComponentName);
3154
if newName <> FGuiLayoutKnobName then
3156
FGuiKnobComponent := nil;
3157
FGuiLayoutKnobName := NewName;
3158
if Assigned(FGuiLayout) then
3160
FGuiKnobComponent :=
3161
FGuiLayout.GuiComponents.FindItem(FGuiLayoutKnobName);
3162
FReBuildGui := True;
3168
procedure TGLScrollbar.SetGuiLayout(NewGui: TGLGuiLayout);
3171
FGuiKnobComponent := nil;
3173
if Assigned(FGuiLayout) then
3175
FGuiKnobComponent := FGuiLayout.GuiComponents.FindItem(FGuiLayoutKnobName);
3176
FReBuildGui := True;
3181
function TGLScrollbar.GetScrollPosY(ScrollPos: Single): Single;
3183
with FRenderStatus[GLAlCenter] do
3185
Result := (ScrollPos - FMin) / (FMax - FMin) * (Y2 - Y1) + Y1;
3189
function TGLScrollbar.GetYScrollPos(Y: Single): Single;
3191
with FRenderStatus[GLAlCenter] do
3193
Result := (Y - Y1) / (Y2 - Y1) * (FMax - FMin) + FMin;
3197
function TGLScrollbar.GetScrollPosX(ScrollPos: Single): Single;
3199
with FRenderStatus[GLAlCenter] do
3201
Result := (ScrollPos - FMin) / (FMax - FMin) * (X2 - X1) + X1;
3205
function TGLScrollbar.GetXScrollPos(X: Single): Single;
3207
with FRenderStatus[GLAlCenter] do
3209
Result := (X - X1) / (X2 - X1) * (FMax - FMin) + FMin;
3213
procedure TGLScrollbar.InternalMouseDown(Shift: TShiftState; Button:
3214
TGLMouseButton; X, Y: Integer);
3220
if (Button = mbLeft)
3221
and not FLocked then
3223
Tx := x - Position.X;
3224
Ty := y - Position.Y;
3226
if IsInRect(FRenderStatus[GLAlCenter], Tx, Ty) then
3230
Tx := GetxScrollPos(Tx);
3233
else if Tx > FPos + FPageSize - 1 then
3238
FScrollOffs := Tx - FPos;
3239
RootControl.ActiveControl := Self;
3244
Ty := GetYScrollPos(Ty);
3247
else if Ty > FPos + FPageSize - 1 then
3252
FScrollOffs := Ty - FPos;
3253
RootControl.ActiveControl := Self;
3259
// if not, is at end buttons ?
3262
if IsInRect(FRenderStatus[GLAlLeft], Tx, Ty) then
3264
if IsInRect(FRenderStatus[GLAlRight], Tx, Ty) then
3269
if IsInRect(FRenderStatus[GLAlTop], Tx, Ty) then
3271
if IsInRect(FRenderStatus[GLAlBottom], Tx, Ty) then
3279
procedure TGLScrollbar.InternalMouseUp(Shift: TShiftState; Button:
3280
TGLMouseButton; X, Y: Integer);
3284
fScrolling := False;
3285
RootControl.ActiveControl := nil;
3291
procedure TGLScrollbar.InternalMouseMove(Shift: TShiftState; X, Y: Integer);
3300
Tx := GetXScrollPos(x - Position.X) - FScrollOffs;
3305
Ty := GetYScrollPos(y - Position.Y) - FScrollOffs;
3312
constructor TGLScrollbar.Create(AOwner: TComponent);
3316
FGuiKnobComponent := nil;
3323
FGuiLayoutKnobName := '';
3325
FScrolling := False;
3326
FHorizontal := False;
3329
procedure TGLScrollbar.StepUp;
3335
procedure TGLScrollbar.StepDown;
3340
procedure TGLScrollbar.PageUp;
3342
Pos := Pos - FPageSize;
3345
procedure TGLScrollbar.PageDown;
3347
Pos := Pos + FPageSize;
3350
function TGLScrollbar.MouseUp(Sender: TObject; Button: TGLMouseButton; Shift:
3351
TShiftState; X, Y: Integer): Boolean;
3354
if (Button = mbLeft) and (FScrolling) then
3357
InternalMouseUp(Shift, Button, X, Y);
3360
Result := inherited MouseUp(Sender, Button, Shift, X, Y);
3363
function TGLScrollbar.MouseMove(Sender: TObject; Shift: TShiftState; X, Y:
3367
if (FScrolling) then
3370
InternalMouseMove(Shift, X, Y);
3373
Result := inherited MouseMove(Sender, Shift, X, Y);
3376
procedure TGLScrollbar.InternalRender(var rci: TGLRenderContextInfo; renderSelf,
3377
renderChildren: Boolean);
3380
Start, Size: Integer;
3382
if Assigned(FGuiComponent) then
3385
FGuiComponent.RenderToArea(0, 0, Width, Height, FRenderStatus,
3389
GLOKMessageBox(E.Message,
3390
'Exception in GuiComponents InternalRender function');
3393
if Assigned(FGuiKnobComponent) then
3396
with FRenderStatus[GLAlCenter] do
3400
Start := Round(GetScrollPosX(FPos));
3401
if FPageSize + FPos > FMax + 1 then
3402
Size := Round(GetScrollPosX(FMax) - X1)
3404
Size := Round(GetScrollPosX(FPageSize) - X1);
3406
FGuiKnobComponent.RenderToArea(Start, Y1, Start + Size, Y2,
3407
FKnobRenderStatus, True);
3409
// tagfloat := size;
3413
Start := Round(GetScrollPosY(FPos));
3414
if FPageSize + FPos > FMax + 1 then
3415
Size := Round(GetScrollPosY(FMax) - Y1)
3417
Size := Round(GetScrollPosY(FPageSize) - Y1);
3418
FGuiKnobComponent.RenderToArea(X1, Start, X2, Start + Size,
3419
FKnobRenderStatus, True);
3421
// tagfloat := size;
3426
GLOKMessageBox(E.Message,
3427
'Exception in GuiComponents InternalRender function');
3432
function TGLStringGrid.GetCell(X, Y: Integer; out oCol, oRow: Integer): Boolean;
3435
ClientRect: TRectangle;
3442
if Assigned(BitmapFont) then
3444
if Assigned(FGuiComponent) then
3446
ClientRect.Left := Round(FRenderStatus[GLAlCenter].X1);
3447
ClientRect.Top := Round(FRenderStatus[GLAlCenter].Y1);
3448
ClientRect.Width := Round(FRenderStatus[GLAlCenter].X2);
3449
ClientRect.Height := Round(FRenderStatus[GLAlCenter].Y2);
3453
ClientRect.Left := 0;
3454
ClientRect.Top := 0;
3455
ClientRect.Width := Round(Width);
3456
ClientRect.Height := Round(Height);
3459
YPos := ClientRect.Top;
3461
YPos := YPos + RowHeight;
3462
XPos := ClientRect.Left;
3469
XPos := XPos + MarginSize;
3471
for XC := 0 to Columns.Count - 1 do
3473
XPos := XPos + Integer(Columns.Objects[XC]);
3478
for YC := 0 to RowCount - 1 do
3480
YPos := YPos + RowHeight;
3484
if Assigned(Scrollbar) then
3485
oRow := YC + Round(Scrollbar.Pos) - 1
3497
procedure TGLStringGrid.InternalMouseDown(Shift: TShiftState; Button:
3498
TGLMouseButton; X, Y: Integer);
3501
tRow, tCol: Integer;
3504
if GetCell(Round(X - Position.X), Round(Y - Position.Y), tCol, tRow) then
3512
procedure TGLStringGrid.SetColumns(const val: TStrings);
3516
FColumns.Assign(val);
3517
for XC := 0 to Columns.Count - 1 do
3518
Columns.Objects[XC] := TObject(ColumnSize);
3521
procedure TGLStringGrid.SetColSelect(const val: Boolean);
3527
function TGLStringGrid.GetRow(index: Integer): TStringList;
3530
if (index >= 0) and (index < FRows.Count) then
3531
Result := TStringList(FRows[index])
3536
procedure TGLStringGrid.SetRow(index: Integer; const val: TStringList);
3539
if (index >= 0) then
3541
if (index >= RowCount) then
3542
RowCount := index + 1;
3544
TStringList(FRows[index]).Assign(val);
3548
function TGLStringGrid.GetRowCount: Integer;
3551
Result := FRows.count;
3554
procedure TGLStringGrid.SetRowCount(const val: Integer);
3566
for XC := XC to val - 1 do
3568
FRows[XC] := TStringList.Create;
3569
TStringList(FRows[XC]).OnChange := OnStringListChange;
3574
for XC := XC - 1 downto val do
3576
TStringList(FRows[XC]).Free;
3580
if Assigned(Scrollbar) then
3581
Scrollbar.FMax := FRows.Count;
3586
procedure TGLStringGrid.SetSelCol(const val: Integer);
3588
if FSelCol <> Val then
3595
procedure TGLStringGrid.SetSelRow(const val: Integer);
3597
if FSelRow <> Val then
3604
procedure TGLStringGrid.SetRowSelect(const val: Boolean);
3610
procedure TGLStringGrid.SetDrawHeader(const val: Boolean);
3617
function TGLStringGrid.GetHeaderColor: TDelphiColor;
3620
Result := ConvertColorVector(FHeaderColor);
3623
procedure TGLStringGrid.SetHeaderColor(const val: TDelphiColor);
3626
FHeaderColor := ConvertWinColor(val);
3630
procedure TGLStringGrid.SetMarginSize(const val: Integer);
3633
if FMarginSize <> val then
3640
procedure TGLStringGrid.SetColumnSize(const val: Integer);
3646
if FColumnSize <> val then
3649
for XC := 0 to Columns.Count - 1 do
3650
Columns.Objects[XC] := TObject(ColumnSize);
3655
procedure TGLStringGrid.SetRowHeight(const val: Integer);
3658
if FRowHeight <> val then
3665
procedure TGLStringGrid.SetScrollbar(const val: TGLScrollbar);
3668
if FScrollbar <> Val then
3670
if Assigned(FScrollbar) then
3671
FScrollbar.RemoveFreeNotification(Self);
3673
if Assigned(FScrollbar) then
3674
FScrollbar.FreeNotification(Self);
3678
procedure TGLStringGrid.SetGuiLayout(NewGui: TGLGuiLayout);
3682
if Assigned(Scrollbar) then
3683
if Scrollbar.GuiLayout <> nil then
3684
Scrollbar.GuiLayout := NewGui;
3687
constructor TGLStringGrid.Create(AOwner: TComponent);
3691
FRows := TList.Create;
3692
FColumns := TStringList.Create;
3693
TStringList(FColumns).OnChange := OnStringListChange;
3698
FDrawHeader := True;
3701
destructor TGLStringGrid.Destroy;
3711
procedure TGLStringGrid.Clear;
3717
procedure TGLStringGrid.Notification(AComponent: TComponent; Operation:
3721
if (AComponent = FScrollbar) and (Operation = opRemove) then
3728
procedure TGLStringGrid.NotifyChange(Sender: TObject);
3731
if Sender = Scrollbar then
3739
procedure TGLStringGrid.InternalRender(var rci: TGLRenderContextInfo; renderSelf,
3740
renderChildren: Boolean);
3742
function CellSelected(X, Y: Integer): Boolean;
3744
if (RowSelect and ColSelect) then
3745
Result := (Y = SelRow) or (x = SelCol)
3746
else if RowSelect then
3747
Result := Y = SelRow
3748
else if ColSelect then
3749
Result := X = SelCol
3751
Result := (Y = SelRow) and (x = SelCol);
3754
function CellText(X, Y: Integer): string;
3758
if (X >= 0) and (X < Count) then
3759
Result := strings[x]
3765
ClientRect: TRectangle;
3769
From, Till: Integer;
3772
if Assigned(FGuiComponent) then
3775
FGuiComponent.RenderToArea(0, 0, Width, Height, FRenderStatus,
3777
ClientRect.Left := Round(FRenderStatus[GLAlCenter].X1);
3778
ClientRect.Top := Round(FRenderStatus[GLAlCenter].Y1);
3779
ClientRect.Width := Round(FRenderStatus[GLAlCenter].X2);
3780
ClientRect.Height := Round(FRenderStatus[GLAlCenter].Y2);
3783
GLOKMessageBox(E.Message,
3784
'Exception in GuiComponents InternalRender function');
3789
ClientRect.Left := 0;
3790
ClientRect.Top := 0;
3791
ClientRect.Width := Round(Width);
3792
ClientRect.Height := Round(Height);
3795
if Assigned(BitmapFont) then
3797
XPos := ClientRect.Left + MarginSize;
3799
if Assigned(Scrollbar) then
3801
Scrollbar.Position.X := Position.X + FRenderStatus[GLAlCenter].X2 -
3803
Scrollbar.Position.Y := Position.Y + FRenderStatus[GLAlCenter].Y1;
3804
Scrollbar.Height := FRenderStatus[GLAlCenter].Y2 -
3805
FRenderStatus[GLAlCenter].Y1;
3806
XC := (ClientRect.Height - ClientRect.Top);
3808
YC := (XC div RowHeight) - 1
3810
YC := (XC div RowHeight);
3812
Scrollbar.PageSize := YC;
3813
From := Round(Scrollbar.pos - 1);
3814
Till := Round(Scrollbar.pageSize + From - 1);
3815
if Till > RowCount - 1 then
3816
Till := RowCount - 1;
3821
Till := RowCount - 1;
3824
for XC := 0 to Columns.Count - 1 do
3826
YPos := -ClientRect.Top;
3829
WriteTextAt(rci, XPos, YPos, Columns[XC], FHeaderColor);
3830
YPos := YPos - RowHeight;
3832
for YC := From to Till do
3834
if CellSelected(XC, YC) then
3835
WriteTextAt(rci, XPos, YPos, CellText(XC, YC), FFocusedColor)
3837
WriteTextAt(rci, XPos, YPos, CellText(XC, YC), FDefaultColor);
3838
YPos := YPos - RowHeight;
3840
XPos := XPos + Integer(Columns.Objects[XC]);
3845
procedure TGLStringGrid.OnStringListChange(Sender: TObject);
3851
function TGLStringGrid.Add(Data: array of string): Integer;
3856
RowCount := RowCount + 1;
3857
for XC := 0 to Length(Data) - 1 do
3858
Row[Result].Add(Data[XC]);
3861
function TGLStringGrid.Add(const Data: string): Integer;
3863
Result := Add([Data]);
3864
if Assigned(Scrollbar) then
3866
if Result > Round(Scrollbar.pageSize + Scrollbar.pos - 2) then
3867
Scrollbar.pos := Result - Scrollbar.pageSize + 2;
3871
procedure TGLStringGrid.SetText(Data: string);
3879
Posi := Pos(#13#10, Data);
3882
Add(Copy(Data, 1, Posi - 1));
3883
Delete(Data, 1, Posi + 1);
3893
destructor TGLFocusControl.Destroy;
3896
RootControl.FocusedControl := nil;
3900
procedure TGLBaseComponent.DoProgress(const progressTime: TProgressTimes);
3903
if FDoChangesOnProgress then
3908
procedure TGLBaseComponent.SetDoChangesOnProgress(const Value: Boolean);
3910
FDoChangesOnProgress := Value;
3913
procedure TGLFocusControl.MoveTo(newParent: TGLBaseSceneObject);
3920
RegisterClasses([TGLBaseControl, TGLPopupMenu, TGLForm, TGLPanel, TGLButton,
3921
TGLCheckBox, TGLEdit, TGLLabel, TGLAdvancedLabel, TGLScrollbar, TGLStringGrid,