1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
21 {$IFDEF USE_MEMPOOL}mempool
,{$ENDIF}
22 g_base
, e_input
, e_log
, g_playermodel
, g_basic
, MAPDEF
, utils
;
25 MAINMENU_HEADER_COLOR
: TRGB
= (R
:255; G
:255; B
:255);
26 MAINMENU_ITEMS_COLOR
: TRGB
= (R
:255; G
:255; B
:255);
27 MAINMENU_UNACTIVEITEMS_COLOR
: TRGB
= (R
:192; G
:192; B
:192);
28 MAINMENU_CLICKSOUND
= 'MENU_SELECT';
29 MAINMENU_CHANGESOUND
= 'MENU_CHANGE';
31 MAINMENU_MARKER1
= 'MAINMENU_MARKER1';
32 MAINMENU_MARKER2
= 'MAINMENU_MARKER2';
33 MAINMENU_MARKERDELAY
= 24;
34 WINDOW_CLOSESOUND
= 'MENU_CLOSE';
35 MENU_HEADERCOLOR
: TRGB
= (R
:255; G
:255; B
:255);
36 MENU_ITEMSTEXT_COLOR
: TRGB
= (R
:255; G
:255; B
:255);
37 MENU_UNACTIVEITEMS_COLOR
: TRGB
= (R
:128; G
:128; B
:128);
38 MENU_ITEMSCTRL_COLOR
: TRGB
= (R
:255; G
:0; B
:0);
41 MENU_CLICKSOUND
= 'MENU_SELECT';
42 MENU_CHANGESOUND
= 'MENU_CHANGE';
43 MENU_MARKERDELAY
= 24;
44 SCROLL_LEFT
= 'SCROLL_LEFT';
45 SCROLL_RIGHT
= 'SCROLL_RIGHT';
46 SCROLL_MIDDLE
= 'SCROLL_MIDDLE';
47 SCROLL_MARKER
= 'SCROLL_MARKER';
48 SCROLL_ADDSOUND
= 'SCROLL_ADD';
49 SCROLL_SUBSOUND
= 'SCROLL_SUB';
50 EDIT_LEFT
= 'EDIT_LEFT';
51 EDIT_RIGHT
= 'EDIT_RIGHT';
52 EDIT_MIDDLE
= 'EDIT_MIDDLE';
53 EDIT_CURSORCOLOR
: TRGB
= (R
:200; G
:0; B
:0);
55 KEYREAD_QUERY
= '<...>';
56 KEYREAD_CLEAR
= '???';
59 MAPPREVIEW_HEIGHT
= 8;
60 BSCROLL_UPA
= 'BSCROLL_UP_A';
61 BSCROLL_UPU
= 'BSCROLL_UP_U';
62 BSCROLL_DOWNA
= 'BSCROLL_DOWN_A';
63 BSCROLL_DOWNU
= 'BSCROLL_DOWN_U';
64 BSCROLL_MIDDLE
= 'BSCROLL_MIDDLE';
69 MESSAGE_DIKEY
= WM_USER
+ 1;
78 TFontType
= (Texture
, Character
);
80 TFont
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
86 constructor Create(FontID
: DWORD
; FontType
: TFontType
);
87 destructor Destroy
; override;
88 procedure Draw(X
, Y
: Integer; Text: string; R
, G
, B
: Byte);
89 procedure GetTextSize(Text: string; var w
, h
: Word);
90 property Scale
: Single read FScale write FScale
;
91 property ID
: DWORD read FID
;
97 TOnKeyDownEvent
= procedure(Key
: Byte);
98 TOnKeyDownEventEx
= procedure(win
: TGUIWindow
; Key
: Byte);
99 TOnCloseEvent
= procedure;
100 TOnShowEvent
= procedure;
101 TOnClickEvent
= procedure;
102 TOnChangeEvent
= procedure(Sender
: TGUIControl
);
103 TOnEnterEvent
= procedure(Sender
: TGUIControl
);
105 TGUIControl
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
109 FWindow
: TGUIWindow
;
112 FRightAlign
: Boolean; //HACK! this works only for "normal" menus, only for menu text labels, and generally sux. sorry.
113 FMaxWidth
: Integer; //HACK! used for right-aligning labels
116 procedure OnMessage(var Msg
: TMessage
); virtual;
117 procedure Update
; virtual;
118 function GetWidth(): Integer; virtual;
119 function GetHeight(): Integer; virtual;
120 function WantActivationKey (key
: LongInt): Boolean; virtual;
121 property X
: Integer read FX write FX
;
122 property Y
: Integer read FY write FY
;
123 property Enabled
: Boolean read FEnabled write FEnabled
;
124 property Name
: string read FName write FName
;
125 property UserData
: Pointer read FUserData write FUserData
;
126 property RightAlign
: Boolean read FRightAlign write FRightAlign
; // for menu
127 property CMaxWidth
: Integer read FMaxWidth
;
129 property Window
: TGUIWindow read FWindow
;
132 TGUIWindow
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
134 FActiveControl
: TGUIControl
;
136 FPrevWindow
: TGUIWindow
;
138 FBackTexture
: string;
139 FMainWindow
: Boolean;
140 FOnKeyDown
: TOnKeyDownEvent
;
141 FOnKeyDownEx
: TOnKeyDownEventEx
;
142 FOnCloseEvent
: TOnCloseEvent
;
143 FOnShowEvent
: TOnShowEvent
;
146 Childs
: array of TGUIControl
;
147 constructor Create(Name
: string);
148 destructor Destroy
; override;
149 function AddChild(Child
: TGUIControl
): TGUIControl
;
150 procedure OnMessage(var Msg
: TMessage
);
152 procedure SetActive(Control
: TGUIControl
);
153 function GetControl(Name
: string): TGUIControl
;
154 property OnKeyDown
: TOnKeyDownEvent read FOnKeyDown write FOnKeyDown
;
155 property OnKeyDownEx
: TOnKeyDownEventEx read FOnKeyDownEx write FOnKeyDownEx
;
156 property OnClose
: TOnCloseEvent read FOnCloseEvent write FOnCloseEvent
;
157 property OnShow
: TOnShowEvent read FOnShowEvent write FOnShowEvent
;
158 property Name
: string read FName
;
159 property DefControl
: string read FDefControl write FDefControl
;
160 property BackTexture
: string read FBackTexture write FBackTexture
;
161 property MainWindow
: Boolean read FMainWindow write FMainWindow
;
162 property UserData
: Pointer read FUserData write FUserData
;
164 property ActiveControl
: TGUIControl read FActiveControl
;
167 TGUITextButton
= class(TGUIControl
)
176 ProcEx
: procedure (sender
: TGUITextButton
);
177 constructor Create(aProc
: Pointer; FontID
: DWORD
; Text: string);
178 destructor Destroy(); override;
179 procedure OnMessage(var Msg
: TMessage
); override;
180 procedure Update(); override;
181 procedure Click(Silent
: Boolean = False);
182 property Caption
: string read FText write FText
;
183 property Color
: TRGB read FColor write FColor
;
184 property Font
: TFont read FFont write FFont
;
185 property ShowWindow
: string read FShowWindow write FShowWindow
;
188 TGUILabel
= class(TGUIControl
)
194 FOnClickEvent
: TOnClickEvent
;
196 constructor Create(Text: string; FontID
: DWORD
);
197 procedure OnMessage(var Msg
: TMessage
); override;
198 property OnClick
: TOnClickEvent read FOnClickEvent write FOnClickEvent
;
199 property FixedLength
: Word read FFixedLen write FFixedLen
;
200 property Text: string read FText write FText
;
201 property Color
: TRGB read FColor write FColor
;
202 property Font
: TFont read FFont write FFont
;
205 TGUIScroll
= class(TGUIControl
)
209 FOnChangeEvent
: TOnChangeEvent
;
210 procedure FSetValue(a
: Integer);
212 constructor Create();
213 procedure OnMessage(var Msg
: TMessage
); override;
214 procedure Update
; override;
215 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
216 property Max
: Word read FMax write FMax
;
217 property Value
: Integer read FValue write FSetValue
;
220 TGUIItemsList
= array of string;
222 TGUISwitch
= class(TGUIControl
)
225 FItems
: TGUIItemsList
;
228 FOnChangeEvent
: TOnChangeEvent
;
230 constructor Create(FontID
: DWORD
);
231 procedure OnMessage(var Msg
: TMessage
); override;
232 procedure AddItem(Item
: string);
233 procedure Update
; override;
234 function GetText
: string;
235 property ItemIndex
: Integer read FIndex write FIndex
;
236 property Color
: TRGB read FColor write FColor
;
237 property Font
: TFont read FFont write FFont
;
238 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
239 property Items
: TGUIItemsList read FItems
;
242 TGUIEdit
= class(TGUIControl
)
250 FOnlyDigits
: Boolean;
251 FOnChangeEvent
: TOnChangeEvent
;
252 FOnEnterEvent
: TOnEnterEvent
;
254 procedure SetText(Text: string);
256 constructor Create(FontID
: DWORD
);
257 procedure OnMessage(var Msg
: TMessage
); override;
258 procedure Update
; override;
259 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
260 property OnEnter
: TOnEnterEvent read FOnEnterEvent write FOnEnterEvent
;
261 property Width
: Word read FWidth write FWidth
;
262 property MaxLength
: Word read FMaxLength write FMaxLength
;
263 property OnlyDigits
: Boolean read FOnlyDigits write FOnlyDigits
;
264 property Text: string read FText write SetText
;
265 property Color
: TRGB read FColor write FColor
;
266 property Font
: TFont read FFont write FFont
;
267 property Invalid
: Boolean read FInvalid write FInvalid
;
269 property CaretPos
: Integer read FCaretPos
;
272 TGUIKeyRead
= class(TGUIControl
)
279 constructor Create(FontID
: DWORD
);
280 procedure OnMessage(var Msg
: TMessage
); override;
281 function WantActivationKey (key
: LongInt): Boolean; override;
282 property Key
: Word read FKey write FKey
;
283 property Color
: TRGB read FColor write FColor
;
284 property Font
: TFont read FFont write FFont
;
286 property IsQuery
: Boolean read FIsQuery
;
290 TGUIKeyRead2
= class(TGUIControl
)
295 FKey0
, FKey1
: Word; // this should be an array. sorry.
298 FMaxKeyNameWdt
: Integer;
300 constructor Create(FontID
: DWORD
);
301 procedure OnMessage(var Msg
: TMessage
); override;
302 function WantActivationKey (key
: LongInt): Boolean; override;
303 property Key0
: Word read FKey0 write FKey0
;
304 property Key1
: Word read FKey1 write FKey1
;
305 property Color
: TRGB read FColor write FColor
;
306 property Font
: TFont read FFont write FFont
;
308 property IsQuery
: Boolean read FIsQuery
;
309 property MaxKeyNameWdt
: Integer read FMaxKeyNameWdt
;
310 property KeyIdx
: Integer read FKeyIdx
;
313 TGUIModelView
= class(TGUIControl
)
315 FModel
: TPlayerModel
;
319 destructor Destroy
; override;
320 procedure OnMessage(var Msg
: TMessage
); override;
321 procedure SetModel(ModelName
: string);
322 procedure SetColor(Red
, Green
, Blue
: Byte);
323 procedure NextAnim();
324 procedure NextWeapon();
325 procedure Update
; override;
326 property Model
: TPlayerModel read FModel
;
329 TPreviewPanel
= record
330 X1
, Y1
, X2
, Y2
: Integer;
334 TPreviewPanelArray
= array of TPreviewPanel
;
336 TGUIMapPreview
= class(TGUIControl
)
338 FMapData
: TPreviewPanelArray
;
342 constructor Create();
343 destructor Destroy(); override;
344 procedure OnMessage(var Msg
: TMessage
); override;
345 procedure SetMap(Res
: string);
346 procedure ClearMap();
347 procedure Update(); override;
348 function GetScaleStr
: String;
350 property MapData
: TPreviewPanelArray read FMapData
;
351 property MapSize
: TDFPoint read FMapSize
;
352 property Scale
: Single read FScale
;
355 TGUIImage
= class(TGUIControl
)
360 constructor Create();
361 destructor Destroy(); override;
362 procedure OnMessage(var Msg
: TMessage
); override;
363 procedure SetImage(Res
: string);
364 procedure ClearImage();
365 procedure Update(); override;
367 property DefaultRes
: string read FDefaultRes write FDefaultRes
;
368 property ImageRes
: string read FImageRes
;
371 TGUIListBox
= class(TGUIControl
)
375 FUnActiveColor
: TRGB
;
383 FDrawScroll
: Boolean;
384 FOnChangeEvent
: TOnChangeEvent
;
386 procedure FSetItems(Items
: SSArray
);
387 procedure FSetIndex(aIndex
: Integer);
390 constructor Create(FontID
: DWORD
; Width
, Height
: Word);
391 procedure OnMessage(var Msg
: TMessage
); override;
392 procedure AddItem(Item
: String);
393 function ItemExists (item
: String): Boolean;
394 procedure SelectItem(Item
: String);
396 function SelectedItem(): String;
398 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
399 property Sort
: Boolean read FSort write FSort
;
400 property ItemIndex
: Integer read FIndex write FSetIndex
;
401 property Items
: SSArray read FItems write FSetItems
;
402 property DrawBack
: Boolean read FDrawBack write FDrawBack
;
403 property DrawScrollBar
: Boolean read FDrawScroll write FDrawScroll
;
404 property ActiveColor
: TRGB read FActiveColor write FActiveColor
;
405 property UnActiveColor
: TRGB read FUnActiveColor write FUnActiveColor
;
406 property Font
: TFont read FFont write FFont
;
408 property Width
: Word read FWidth
;
409 property Height
: Word read FHeight
;
410 property StartLine
: Integer read FStartLine
;
413 TGUIFileListBox
= class(TGUIListBox
)
418 FBaseList
: SSArray
; // highter index have highter priority
423 procedure OnMessage (var Msg
: TMessage
); override;
424 procedure SetBase (dirs
: SSArray
; path
: String = '');
425 function SelectedItem(): String;
426 procedure UpdateFileList
;
428 property Dirs
: Boolean read FDirs write FDirs
;
429 property FileMask
: String read FFileMask write FFileMask
;
432 TGUIMemo
= class(TGUIControl
)
441 FDrawScroll
: Boolean;
443 constructor Create(FontID
: DWORD
; Width
, Height
: Word);
444 procedure OnMessage(var Msg
: TMessage
); override;
446 procedure SetText(Text: string);
447 property DrawBack
: Boolean read FDrawBack write FDrawBack
;
448 property DrawScrollBar
: Boolean read FDrawScroll write FDrawScroll
;
449 property Color
: TRGB read FColor write FColor
;
450 property Font
: TFont read FFont write FFont
;
452 property Width
: Word read FWidth
;
453 property Height
: Word read FHeight
;
454 property StartLine
: Integer read FStartLine
;
455 property Lines
: SSArray read FLines
;
458 TGUITextButtonList
= array of TGUITextButton
;
460 TGUIMainMenu
= class(TGUIControl
)
462 FButtons
: TGUITextButtonList
;
466 FCounter
: Byte; // !!! update it within render
468 constructor Create(FontID
: DWORD
; Header
: string);
469 destructor Destroy
; override;
470 procedure OnMessage(var Msg
: TMessage
); override;
471 function AddButton(fProc
: Pointer; Caption
: string; ShowWindow
: string = ''): TGUITextButton
;
472 function GetButton(aName
: string): TGUITextButton
;
473 procedure EnableButton(aName
: string; e
: Boolean);
474 procedure AddSpace();
475 procedure Update
; override;
477 property Header
: TGUILabel read FHeader
;
478 property Buttons
: TGUITextButtonList read FButtons
;
479 property Index
: Integer read FIndex
;
480 property Counter
: Byte read FCounter
;
483 TControlType
= class of TGUIControl
;
485 PMenuItem
= ^TMenuItem
;
488 ControlType
: TControlType
;
489 Control
: TGUIControl
;
491 TMenuItemList
= array of TMenuItem
;
493 TGUIMenu
= class(TGUIControl
)
495 FItems
: TMenuItemList
;
503 function NewItem(): Integer;
505 constructor Create(HeaderFont
, ItemsFont
: DWORD
; Header
: string);
506 destructor Destroy
; override;
507 procedure OnMessage(var Msg
: TMessage
); override;
508 procedure AddSpace();
509 procedure AddLine(fText
: string);
510 procedure AddText(fText
: string; MaxWidth
: Word);
511 function AddLabel(fText
: string): TGUILabel
;
512 function AddButton(Proc
: Pointer; fText
: string; _ShowWindow
: string = ''): TGUITextButton
;
513 function AddScroll(fText
: string): TGUIScroll
;
514 function AddSwitch(fText
: string): TGUISwitch
;
515 function AddEdit(fText
: string): TGUIEdit
;
516 function AddKeyRead(fText
: string): TGUIKeyRead
;
517 function AddKeyRead2(fText
: string): TGUIKeyRead2
;
518 function AddList(fText
: string; Width
, Height
: Word): TGUIListBox
;
519 function AddFileList(fText
: string; Width
, Height
: Word): TGUIFileListBox
;
520 function AddMemo(fText
: string; Width
, Height
: Word): TGUIMemo
;
522 function GetControl(aName
: string): TGUIControl
;
523 function GetControlsText(aName
: string): TGUILabel
;
524 procedure Update
; override;
525 procedure UpdateIndex();
526 property Align
: Boolean read FAlign write FAlign
;
527 property Left
: Integer read FLeft write FLeft
;
528 property YesNo
: Boolean read FYesNo write FYesNo
;
530 property Header
: TGUILabel read FHeader
;
531 property Counter
: Byte read FCounter
;
532 property Index
: Integer read FIndex
;
533 property Items
: TMenuItemList read FItems
;
534 property FontID
: DWORD read FFontID
;
538 g_GUIWindows
: array of TGUIWindow
;
539 g_ActiveWindow
: TGUIWindow
= nil;
540 g_GUIGrabInput
: Boolean = False;
542 function g_GUI_AddWindow(Window
: TGUIWindow
): TGUIWindow
;
543 function g_GUI_GetWindow(Name
: string): TGUIWindow
;
544 procedure g_GUI_ShowWindow(Name
: string);
545 procedure g_GUI_HideWindow(PlaySound
: Boolean = True);
546 function g_GUI_Destroy(): Boolean;
547 procedure g_GUI_SaveMenuPos();
548 procedure g_GUI_LoadMenuPos();
554 {$IFDEF ENABLE_TOUCH}
557 {$IFDEF ENABLE_RENDER}
558 r_gui
, r_textures
, r_graphics
,
560 g_sound
, SysUtils
, e_res
,
561 g_game
, Math
, StrUtils
, g_player
, g_options
, g_console
,
562 g_map
, g_weapons
, xdynrec
, wadreader
;
566 Saved_Windows
: SSArray
;
568 function GetLines (text: string; FontID
: DWORD
; MaxWidth
: Word): SSArray
;
572 i
, len
, lastsep
: Integer;
574 function PrepareStep (): Boolean; inline;
576 // Skip leading spaces.
577 while PChar(text)[k
-1] = ' ' do k
+= 1;
582 function GetLine (j
: Integer; Strip
: Boolean): String; inline;
584 // Exclude trailing spaces from the line.
586 while text[j
] = ' ' do j
-= 1;
588 Result
:= Copy(text, k
, j
-k
+1);
591 function LineWidth (): Integer; inline;
594 e_CharFont_GetSize(FontID
, GetLine(i
, False), w
, h
);
601 //e_LogWritefln('GetLines @%s len=%s [%s]', [MaxWidth, len, text]);
603 while PrepareStep() do
605 // Get longest possible sequence (this is not constant because fonts are not monospaced).
608 if text[i
] in [' ', '.', ',', ':', ';']
611 until (i
> len
) or (LineWidth() > MaxWidth
);
613 // Do not include part of a word if possible.
614 if (lastsep
-k
> 3) and (i
<= len
) and (text[i
] <> ' ')
615 then i
:= lastsep
+ 1;
618 SetLength(Result
, lines
+ 1);
619 Result
[lines
] := GetLine(i
-1, True);
620 //e_LogWritefln(' -> (%s:%s::%s) [%s]', [k, i, LineWidth(), Result[lines]]);
627 procedure Sort(var a
: SSArray
);
632 if a
= nil then Exit
;
634 for i
:= High(a
) downto Low(a
) do
635 for j
:= Low(a
) to High(a
)-1 do
636 if LowerCase(a
[j
]) > LowerCase(a
[j
+1]) then
644 function g_GUI_Destroy(): Boolean;
648 Result
:= (Length(g_GUIWindows
) > 0);
650 for i
:= 0 to High(g_GUIWindows
) do
651 g_GUIWindows
[i
].Free();
654 g_ActiveWindow
:= nil;
657 function g_GUI_AddWindow(Window
: TGUIWindow
): TGUIWindow
;
659 SetLength(g_GUIWindows
, Length(g_GUIWindows
)+1);
660 g_GUIWindows
[High(g_GUIWindows
)] := Window
;
665 function g_GUI_GetWindow(Name
: string): TGUIWindow
;
671 if g_GUIWindows
<> nil then
672 for i
:= 0 to High(g_GUIWindows
) do
673 if g_GUIWindows
[i
].FName
= Name
then
675 Result
:= g_GUIWindows
[i
];
679 Assert(Result
<> nil, 'GUI_Window "'+Name
+'" not found');
682 procedure g_GUI_ShowWindow(Name
: string);
686 if g_GUIWindows
= nil then
689 for i
:= 0 to High(g_GUIWindows
) do
690 if g_GUIWindows
[i
].FName
= Name
then
692 g_GUIWindows
[i
].FPrevWindow
:= g_ActiveWindow
;
693 g_ActiveWindow
:= g_GUIWindows
[i
];
695 if g_ActiveWindow
.MainWindow
then
696 g_ActiveWindow
.FPrevWindow
:= nil;
698 if g_ActiveWindow
.FDefControl
<> '' then
699 g_ActiveWindow
.SetActive(g_ActiveWindow
.GetControl(g_ActiveWindow
.FDefControl
))
701 g_ActiveWindow
.SetActive(nil);
703 if @g_ActiveWindow
.FOnShowEvent
<> nil then
704 g_ActiveWindow
.FOnShowEvent();
710 procedure g_GUI_HideWindow(PlaySound
: Boolean = True);
712 if g_ActiveWindow
<> nil then
714 if @g_ActiveWindow
.OnClose
<> nil then
715 g_ActiveWindow
.OnClose();
716 g_ActiveWindow
:= g_ActiveWindow
.FPrevWindow
;
718 g_Sound_PlayEx(WINDOW_CLOSESOUND
);
722 procedure g_GUI_SaveMenuPos();
727 SetLength(Saved_Windows
, 0);
728 win
:= g_ActiveWindow
;
732 len
:= Length(Saved_Windows
);
733 SetLength(Saved_Windows
, len
+ 1);
735 Saved_Windows
[len
] := win
.Name
;
737 if win
.MainWindow
then
740 win
:= win
.FPrevWindow
;
744 procedure g_GUI_LoadMenuPos();
746 i
, j
, k
, len
: Integer;
749 g_ActiveWindow
:= nil;
750 len
:= Length(Saved_Windows
);
755 // Îêíî ñ ãëàâíûì ìåíþ:
756 g_GUI_ShowWindow(Saved_Windows
[len
-1]);
758 // Íå ïåðåêëþ÷èëîñü (èëè íåêóäà äàëüøå):
759 if (len
= 1) or (g_ActiveWindow
= nil) then
762 // Èùåì êíîïêè â îñòàëüíûõ îêíàõ:
763 for k
:= len
-1 downto 1 do
767 for i
:= 0 to Length(g_ActiveWindow
.Childs
)-1 do
769 if g_ActiveWindow
.Childs
[i
] is TGUIMainMenu
then
770 begin // GUI_MainMenu
771 with TGUIMainMenu(g_ActiveWindow
.Childs
[i
]) do
772 for j
:= 0 to Length(FButtons
)-1 do
773 if FButtons
[j
].ShowWindow
= Saved_Windows
[k
-1] then
775 FButtons
[j
].Click(True);
781 if g_ActiveWindow
.Childs
[i
] is TGUIMenu
then
782 with TGUIMenu(g_ActiveWindow
.Childs
[i
]) do
783 for j
:= 0 to Length(FItems
)-1 do
784 if FItems
[j
].ControlType
= TGUITextButton
then
785 if TGUITextButton(FItems
[j
].Control
).ShowWindow
= Saved_Windows
[k
-1] then
787 TGUITextButton(FItems
[j
].Control
).Click(True);
798 (g_ActiveWindow
.Name
= Saved_Windows
[k
]) then
805 constructor TGUIWindow
.Create(Name
: string);
808 FActiveControl
:= nil;
812 FOnCloseEvent
:= nil;
816 destructor TGUIWindow
.Destroy
;
823 for i
:= 0 to High(Childs
) do
827 function TGUIWindow
.AddChild(Child
: TGUIControl
): TGUIControl
;
829 Child
.FWindow
:= Self
;
831 SetLength(Childs
, Length(Childs
) + 1);
832 Childs
[High(Childs
)] := Child
;
837 procedure TGUIWindow
.Update
;
841 for i
:= 0 to High(Childs
) do
842 if Childs
[i
] <> nil then Childs
[i
].Update
;
845 procedure TGUIWindow
.OnMessage(var Msg
: TMessage
);
847 if FActiveControl
<> nil then FActiveControl
.OnMessage(Msg
);
848 if @FOnKeyDown
<> nil then FOnKeyDown(Msg
.wParam
);
849 if @FOnKeyDownEx
<> nil then FOnKeyDownEx(self
, Msg
.wParam
);
851 if Msg
.Msg
= WM_KEYDOWN
then
863 procedure TGUIWindow
.SetActive(Control
: TGUIControl
);
865 FActiveControl
:= Control
;
868 function TGUIWindow
.GetControl(Name
: String): TGUIControl
;
874 if Childs
<> nil then
875 for i
:= 0 to High(Childs
) do
876 if Childs
[i
] <> nil then
877 if LowerCase(Childs
[i
].FName
) = LowerCase(Name
) then
883 Assert(Result
<> nil, 'Window Control "'+Name
+'" not Found!');
888 constructor TGUIControl
.Create();
894 FRightAlign
:= false;
898 procedure TGUIControl
.OnMessage(var Msg
: TMessage
);
904 procedure TGUIControl
.Update();
908 function TGUIControl
.WantActivationKey (key
: LongInt): Boolean;
913 function TGUIControl
.GetWidth (): Integer;
914 {$IFDEF ENABLE_RENDER}
918 {$IFDEF ENABLE_RENDER}
919 r_GUI_GetSize(Self
, Result
, h
);
925 function TGUIControl
.GetHeight (): Integer;
926 {$IFDEF ENABLE_RENDER}
930 {$IFDEF ENABLE_RENDER}
931 r_GUI_GetSize(Self
, w
, Result
);
939 procedure TGUITextButton
.Click(Silent
: Boolean = False);
941 if (FSound
<> '') and (not Silent
) then g_Sound_PlayEx(FSound
);
943 if @Proc
<> nil then Proc();
944 if @ProcEx
<> nil then ProcEx(self
);
946 if FShowWindow
<> '' then g_GUI_ShowWindow(FShowWindow
);
949 constructor TGUITextButton
.Create(aProc
: Pointer; FontID
: DWORD
; Text: string);
956 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
961 destructor TGUITextButton
.Destroy
;
967 procedure TGUITextButton
.OnMessage(var Msg
: TMessage
);
969 if not FEnabled
then Exit
;
976 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
: Click();
981 procedure TGUITextButton
.Update
;
988 constructor TFont
.Create(FontID
: DWORD
; FontType
: TFontType
);
992 FFontType
:= FontType
;
995 destructor TFont
.Destroy
;
1001 procedure TFont
.Draw(X
, Y
: Integer; Text: string; R
, G
, B
: Byte);
1003 if FFontType
= TFontType
.Character
then e_CharFont_PrintEx(ID
, X
, Y
, Text, _RGB(R
, G
, B
), FScale
)
1004 else e_TextureFontPrintEx(X
, Y
, Text, ID
, R
, G
, B
, FScale
);
1007 procedure TFont
.GetTextSize(Text: string; var w
, h
: Word);
1011 if FFontType
= TFontType
.Character
then e_CharFont_GetSize(ID
, Text, w
, h
)
1014 e_TextureFontGetSize(ID
, cw
, ch
);
1015 w
:= cw
*Length(Text);
1019 w
:= Round(w
*FScale
);
1020 h
:= Round(h
*FScale
);
1025 function TGUIMainMenu
.AddButton(fProc
: Pointer; Caption
: string; ShowWindow
: string = ''): TGUITextButton
;
1034 SetLength(FButtons
, Length(FButtons
)+1);
1035 FButtons
[High(FButtons
)] := TGUITextButton
.Create(fProc
, FFontID
, Caption
);
1036 FButtons
[High(FButtons
)].ShowWindow
:= ShowWindow
;
1037 with FButtons
[High(FButtons
)] do
1039 if (fProc
<> nil) or (ShowWindow
<> '') then FColor
:= MAINMENU_ITEMS_COLOR
1040 else FColor
:= MAINMENU_UNACTIVEITEMS_COLOR
;
1041 FSound
:= MAINMENU_CLICKSOUND
;
1044 _x
:= gScreenWidth
div 2;
1046 for a
:= 0 to High(FButtons
) do
1047 if FButtons
[a
] <> nil then
1048 _x
:= Min(_x
, (gScreenWidth
div 2)-(FButtons
[a
].GetWidth
div 2));
1050 if FHeader
= nil then
1051 r_GUI_GetLogoSize(lw
, lh
);
1052 hh
:= FButtons
[High(FButtons
)].GetHeight
;
1054 if FHeader
= nil then h
:= lh
+ hh
* (1 + Length(FButtons
)) + MAINMENU_SPACE
* (Length(FButtons
) - 1)
1055 else h
:= hh
* (2 + Length(FButtons
)) + MAINMENU_SPACE
* (Length(FButtons
) - 1);
1056 h
:= (gScreenHeight
div 2) - (h
div 2);
1058 if FHeader
<> nil then with FHeader
do
1064 if FHeader
= nil then Inc(h
, lh
)
1067 for a
:= 0 to High(FButtons
) do
1069 if FButtons
[a
] <> nil then
1076 Inc(h
, hh
+MAINMENU_SPACE
);
1079 Result
:= FButtons
[High(FButtons
)];
1082 procedure TGUIMainMenu
.AddSpace
;
1084 SetLength(FButtons
, Length(FButtons
)+1);
1085 FButtons
[High(FButtons
)] := nil;
1088 constructor TGUIMainMenu
.Create(FontID
: DWORD
; Header
: string);
1094 FCounter
:= MAINMENU_MARKERDELAY
;
1096 if Header
<> '' then
1098 FHeader
:= TGUILabel
.Create(Header
, FFontID
);
1101 FColor
:= MAINMENU_HEADER_COLOR
;
1102 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1103 FY
:= (gScreenHeight
div 2)-(GetHeight
div 2);
1108 destructor TGUIMainMenu
.Destroy
;
1112 if FButtons
<> nil then
1113 for a
:= 0 to High(FButtons
) do
1121 procedure TGUIMainMenu
.EnableButton(aName
: string; e
: Boolean);
1125 if FButtons
= nil then Exit
;
1127 for a
:= 0 to High(FButtons
) do
1128 if (FButtons
[a
] <> nil) and (FButtons
[a
].Name
= aName
) then
1130 if e
then FButtons
[a
].FColor
:= MAINMENU_ITEMS_COLOR
1131 else FButtons
[a
].FColor
:= MAINMENU_UNACTIVEITEMS_COLOR
;
1132 FButtons
[a
].Enabled
:= e
;
1137 function TGUIMainMenu
.GetButton(aName
: string): TGUITextButton
;
1143 if FButtons
= nil then Exit
;
1145 for a
:= 0 to High(FButtons
) do
1146 if (FButtons
[a
] <> nil) and (FButtons
[a
].Name
= aName
) then
1148 Result
:= FButtons
[a
];
1153 procedure TGUIMainMenu
.OnMessage(var Msg
: TMessage
);
1158 if not FEnabled
then Exit
;
1162 if FButtons
= nil then Exit
;
1165 for a
:= 0 to High(FButtons
) do
1166 if FButtons
[a
] <> nil then
1172 if not ok
then Exit
;
1177 IK_UP
, IK_KPUP
, VK_UP
, JOY0_UP
, JOY1_UP
, JOY2_UP
, JOY3_UP
:
1181 if FIndex
< 0 then FIndex
:= High(FButtons
);
1182 until FButtons
[FIndex
] <> nil;
1184 g_Sound_PlayEx(MENU_CHANGESOUND
);
1186 IK_DOWN
, IK_KPDOWN
, VK_DOWN
, JOY0_DOWN
, JOY1_DOWN
, JOY2_DOWN
, JOY3_DOWN
:
1190 if FIndex
> High(FButtons
) then FIndex
:= 0;
1191 until FButtons
[FIndex
] <> nil;
1193 g_Sound_PlayEx(MENU_CHANGESOUND
);
1195 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
: if (FIndex
<> -1) and FButtons
[FIndex
].FEnabled
then FButtons
[FIndex
].Click
;
1200 procedure TGUIMainMenu
.Update
;
1203 FCounter
:= (FCounter
+ 1) MOD (2 * MAINMENU_MARKERDELAY
)
1208 constructor TGUILabel
.Create(Text: string; FontID
: DWORD
);
1212 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
1216 FOnClickEvent
:= nil;
1219 procedure TGUILabel
.OnMessage(var Msg
: TMessage
);
1221 if not FEnabled
then Exit
;
1228 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
: if @FOnClickEvent
<> nil then FOnClickEvent();
1235 function TGUIMenu
.AddButton(Proc
: Pointer; fText
: string; _ShowWindow
: string = ''): TGUITextButton
;
1242 Control
:= TGUITextButton
.Create(Proc
, FFontID
, fText
);
1243 with Control
as TGUITextButton
do
1245 ShowWindow
:= _ShowWindow
;
1246 FColor
:= MENU_ITEMSCTRL_COLOR
;
1250 ControlType
:= TGUITextButton
;
1252 Result
:= (Control
as TGUITextButton
);
1255 if FIndex
= -1 then FIndex
:= i
;
1260 procedure TGUIMenu
.AddLine(fText
: string);
1267 Text := TGUILabel
.Create(fText
, FFontID
);
1270 FColor
:= MENU_ITEMSTEXT_COLOR
;
1279 procedure TGUIMenu
.AddText(fText
: string; MaxWidth
: Word);
1284 l
:= GetLines(fText
, FFontID
, MaxWidth
);
1286 if l
= nil then Exit
;
1288 for a
:= 0 to High(l
) do
1293 Text := TGUILabel
.Create(l
[a
], FFontID
);
1296 with Text do begin FColor
:= _RGB(255, 0, 0); end;
1300 with Text do begin FColor
:= MENU_ITEMSTEXT_COLOR
; end;
1310 procedure TGUIMenu
.AddSpace
;
1324 constructor TGUIMenu
.Create(HeaderFont
, ItemsFont
: DWORD
; Header
: string);
1330 FFontID
:= ItemsFont
;
1331 FCounter
:= MENU_MARKERDELAY
;
1335 FHeader
:= TGUILabel
.Create(Header
, HeaderFont
);
1338 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1340 FColor
:= MAINMENU_HEADER_COLOR
;
1344 destructor TGUIMenu
.Destroy
;
1348 if FItems
<> nil then
1349 for a
:= 0 to High(FItems
) do
1363 function TGUIMenu
.GetControl(aName
: String): TGUIControl
;
1369 if FItems
<> nil then
1370 for a
:= 0 to High(FItems
) do
1371 if FItems
[a
].Control
<> nil then
1372 if LowerCase(FItems
[a
].Control
.Name
) = LowerCase(aName
) then
1374 Result
:= FItems
[a
].Control
;
1378 Assert(Result
<> nil, 'GUI control "'+aName
+'" not found!');
1381 function TGUIMenu
.GetControlsText(aName
: String): TGUILabel
;
1387 if FItems
<> nil then
1388 for a
:= 0 to High(FItems
) do
1389 if FItems
[a
].Control
<> nil then
1390 if LowerCase(FItems
[a
].Control
.Name
) = LowerCase(aName
) then
1392 Result
:= FItems
[a
].Text;
1396 Assert(Result
<> nil, 'GUI control''s text "'+aName
+'" not found!');
1399 function TGUIMenu
.NewItem
: Integer;
1401 SetLength(FItems
, Length(FItems
)+1);
1402 Result
:= High(FItems
);
1405 procedure TGUIMenu
.OnMessage(var Msg
: TMessage
);
1410 if not FEnabled
then Exit
;
1414 if FItems
= nil then Exit
;
1417 for a
:= 0 to High(FItems
) do
1418 if FItems
[a
].Control
<> nil then
1424 if not ok
then Exit
;
1426 if (Msg
.Msg
= WM_KEYDOWN
) and (FIndex
<> -1) and (FItems
[FIndex
].Control
<> nil) and
1427 (FItems
[FIndex
].Control
.WantActivationKey(Msg
.wParam
)) then
1429 FItems
[FIndex
].Control
.OnMessage(Msg
);
1430 g_Sound_PlayEx(MENU_CLICKSOUND
);
1438 IK_UP
, IK_KPUP
, VK_UP
,JOY0_UP
, JOY1_UP
, JOY2_UP
, JOY3_UP
:
1443 if c
> Length(FItems
) then
1450 if FIndex
< 0 then FIndex
:= High(FItems
);
1451 until (FItems
[FIndex
].Control
<> nil) and
1452 (FItems
[FIndex
].Control
.Enabled
);
1456 g_Sound_PlayEx(MENU_CHANGESOUND
);
1459 IK_DOWN
, IK_KPDOWN
, VK_DOWN
, JOY0_DOWN
, JOY1_DOWN
, JOY2_DOWN
, JOY3_DOWN
:
1464 if c
> Length(FItems
) then
1471 if FIndex
> High(FItems
) then FIndex
:= 0;
1472 until (FItems
[FIndex
].Control
<> nil) and
1473 (FItems
[FIndex
].Control
.Enabled
);
1477 g_Sound_PlayEx(MENU_CHANGESOUND
);
1480 IK_LEFT
, IK_RIGHT
, IK_KPLEFT
, IK_KPRIGHT
, VK_LEFT
, VK_RIGHT
,
1481 JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
,
1482 JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
1484 if FIndex
<> -1 then
1485 if FItems
[FIndex
].Control
<> nil then
1486 FItems
[FIndex
].Control
.OnMessage(Msg
);
1488 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
1490 if FIndex
<> -1 then
1492 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1494 g_Sound_PlayEx(MENU_CLICKSOUND
);
1498 if FYesNo
and (length(FItems
) > 1) then
1500 Msg
.wParam
:= IK_RETURN
; // to register keypress
1501 FIndex
:= High(FItems
)-1;
1502 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1505 if FYesNo
and (length(FItems
) > 1) then
1507 Msg
.wParam
:= IK_RETURN
; // to register keypress
1508 FIndex
:= High(FItems
);
1509 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1516 procedure TGUIMenu
.ReAlign();
1518 a
, tx
, cx
, w
, h
: Integer;
1519 cww
: array of Integer; // cached widths
1522 if FItems
= nil then Exit
;
1524 SetLength(cww
, length(FItems
));
1526 for a
:= 0 to High(FItems
) do
1528 if FItems
[a
].Text <> nil then
1530 cww
[a
] := FItems
[a
].Text.GetWidth
;
1531 if maxcww
< cww
[a
] then maxcww
:= cww
[a
];
1542 for a
:= 0 to High(FItems
) do
1545 if FItems
[a
].Text <> nil then w
:= FItems
[a
].Text.GetWidth
;
1546 if FItems
[a
].Control
<> nil then
1549 if FItems
[a
].ControlType
= TGUILabel
then w
:= w
+(FItems
[a
].Control
as TGUILabel
).GetWidth
1550 else if FItems
[a
].ControlType
= TGUITextButton
then w
:= w
+(FItems
[a
].Control
as TGUITextButton
).GetWidth
1551 else if FItems
[a
].ControlType
= TGUIScroll
then w
:= w
+(FItems
[a
].Control
as TGUIScroll
).GetWidth
1552 else if FItems
[a
].ControlType
= TGUISwitch
then w
:= w
+(FItems
[a
].Control
as TGUISwitch
).GetWidth
1553 else if FItems
[a
].ControlType
= TGUIEdit
then w
:= w
+(FItems
[a
].Control
as TGUIEdit
).GetWidth
1554 else if FItems
[a
].ControlType
= TGUIKeyRead
then w
:= w
+(FItems
[a
].Control
as TGUIKeyRead
).GetWidth
1555 else if FItems
[a
].ControlType
= TGUIKeyRead2
then w
:= w
+(FItems
[a
].Control
as TGUIKeyRead2
).GetWidth
1556 else if FItems
[a
].ControlType
= TGUIListBox
then w
:= w
+(FItems
[a
].Control
as TGUIListBox
).GetWidth
1557 else if FItems
[a
].ControlType
= TGUIFileListBox
then w
:= w
+(FItems
[a
].Control
as TGUIFileListBox
).GetWidth
1558 else if FItems
[a
].ControlType
= TGUIMemo
then w
:= w
+(FItems
[a
].Control
as TGUIMemo
).GetWidth
;
1560 tx
:= Min(tx
, (gScreenWidth
div 2)-(w
div 2));
1565 for a
:= 0 to High(FItems
) do
1569 if (Text <> nil) and (Control
= nil) then Continue
;
1571 if Text <> nil then w
:= tx
+Text.GetWidth
;
1572 if w
> cx
then cx
:= w
;
1576 cx
:= cx
+MENU_HSPACE
;
1578 h
:= FHeader
.GetHeight
*2+MENU_VSPACE
*(Length(FItems
)-1);
1580 for a
:= 0 to High(FItems
) do
1584 if (ControlType
= TGUIListBox
) or (ControlType
= TGUIFileListBox
) then
1585 h
:= h
+(FItems
[a
].Control
as TGUIListBox
).GetHeight()
1587 h
:= h
+e_CharFont_GetMaxHeight(FFontID
);
1591 h
:= (gScreenHeight
div 2)-(h
div 2);
1595 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1598 Inc(h
, GetHeight
*2);
1601 for a
:= 0 to High(FItems
) do
1613 if Text.RightAlign
and (length(cww
) > a
) then
1615 //Text.FX := Text.FX+maxcww;
1616 Text.FMaxWidth
:= maxcww
;
1620 if Control
<> nil then
1637 if (ControlType
= TGUIListBox
) or (ControlType
= TGUIFileListBox
) then Inc(h
, (Control
as TGUIListBox
).GetHeight
+MENU_VSPACE
)
1638 else if ControlType
= TGUIMemo
then Inc(h
, (Control
as TGUIMemo
).GetHeight
+MENU_VSPACE
)
1639 else Inc(h
, e_CharFont_GetMaxHeight(FFontID
)+MENU_VSPACE
);
1643 // another ugly hack
1644 if FYesNo
and (length(FItems
) > 1) then
1647 for a
:= High(FItems
)-1 to High(FItems
) do
1649 if (FItems
[a
].Control
<> nil) and (FItems
[a
].ControlType
= TGUITextButton
) then
1651 cx
:= (FItems
[a
].Control
as TGUITextButton
).GetWidth
;
1652 if cx
> w
then w
:= cx
;
1657 for a
:= High(FItems
)-1 to High(FItems
) do
1659 if (FItems
[a
].Control
<> nil) and (FItems
[a
].ControlType
= TGUITextButton
) then
1661 FItems
[a
].Control
.FX
:= (gScreenWidth
-w
) div 2;
1668 function TGUIMenu
.AddScroll(fText
: string): TGUIScroll
;
1675 Control
:= TGUIScroll
.Create();
1677 Text := TGUILabel
.Create(fText
, FFontID
);
1680 FColor
:= MENU_ITEMSTEXT_COLOR
;
1683 ControlType
:= TGUIScroll
;
1685 Result
:= (Control
as TGUIScroll
);
1688 if FIndex
= -1 then FIndex
:= i
;
1693 function TGUIMenu
.AddSwitch(fText
: string): TGUISwitch
;
1700 Control
:= TGUISwitch
.Create(FFontID
);
1701 (Control
as TGUISwitch
).FColor
:= MENU_ITEMSCTRL_COLOR
;
1703 Text := TGUILabel
.Create(fText
, FFontID
);
1706 FColor
:= MENU_ITEMSTEXT_COLOR
;
1709 ControlType
:= TGUISwitch
;
1711 Result
:= (Control
as TGUISwitch
);
1714 if FIndex
= -1 then FIndex
:= i
;
1719 function TGUIMenu
.AddEdit(fText
: string): TGUIEdit
;
1726 Control
:= TGUIEdit
.Create(FFontID
);
1727 with Control
as TGUIEdit
do
1729 FWindow
:= Self
.FWindow
;
1730 FColor
:= MENU_ITEMSCTRL_COLOR
;
1733 if fText
= '' then Text := nil else
1735 Text := TGUILabel
.Create(fText
, FFontID
);
1736 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
1739 ControlType
:= TGUIEdit
;
1741 Result
:= (Control
as TGUIEdit
);
1744 if FIndex
= -1 then FIndex
:= i
;
1749 procedure TGUIMenu
.Update
;
1755 if FCounter
= 0 then FCounter
:= MENU_MARKERDELAY
else Dec(FCounter
);
1757 if FItems
<> nil then
1758 for a
:= 0 to High(FItems
) do
1759 if FItems
[a
].Control
<> nil then
1760 (FItems
[a
].Control
as FItems
[a
].ControlType
).Update
;
1763 function TGUIMenu
.AddKeyRead(fText
: string): TGUIKeyRead
;
1770 Control
:= TGUIKeyRead
.Create(FFontID
);
1771 with Control
as TGUIKeyRead
do
1773 FWindow
:= Self
.FWindow
;
1774 FColor
:= MENU_ITEMSCTRL_COLOR
;
1777 Text := TGUILabel
.Create(fText
, FFontID
);
1780 FColor
:= MENU_ITEMSTEXT_COLOR
;
1783 ControlType
:= TGUIKeyRead
;
1785 Result
:= (Control
as TGUIKeyRead
);
1788 if FIndex
= -1 then FIndex
:= i
;
1793 function TGUIMenu
.AddKeyRead2(fText
: string): TGUIKeyRead2
;
1800 Control
:= TGUIKeyRead2
.Create(FFontID
);
1801 with Control
as TGUIKeyRead2
do
1803 FWindow
:= Self
.FWindow
;
1804 FColor
:= MENU_ITEMSCTRL_COLOR
;
1807 Text := TGUILabel
.Create(fText
, FFontID
);
1810 FColor
:= MENU_ITEMSCTRL_COLOR
; //MENU_ITEMSTEXT_COLOR;
1814 ControlType
:= TGUIKeyRead2
;
1816 Result
:= (Control
as TGUIKeyRead2
);
1819 if FIndex
= -1 then FIndex
:= i
;
1824 function TGUIMenu
.AddList(fText
: string; Width
, Height
: Word): TGUIListBox
;
1831 Control
:= TGUIListBox
.Create(FFontID
, Width
, Height
);
1832 with Control
as TGUIListBox
do
1834 FWindow
:= Self
.FWindow
;
1835 FActiveColor
:= MENU_ITEMSCTRL_COLOR
;
1836 FUnActiveColor
:= MENU_ITEMSTEXT_COLOR
;
1839 Text := TGUILabel
.Create(fText
, FFontID
);
1842 FColor
:= MENU_ITEMSTEXT_COLOR
;
1845 ControlType
:= TGUIListBox
;
1847 Result
:= (Control
as TGUIListBox
);
1850 if FIndex
= -1 then FIndex
:= i
;
1855 function TGUIMenu
.AddFileList(fText
: string; Width
, Height
: Word): TGUIFileListBox
;
1862 Control
:= TGUIFileListBox
.Create(FFontID
, Width
, Height
);
1863 with Control
as TGUIFileListBox
do
1865 FWindow
:= Self
.FWindow
;
1866 FActiveColor
:= MENU_ITEMSCTRL_COLOR
;
1867 FUnActiveColor
:= MENU_ITEMSTEXT_COLOR
;
1870 if fText
= '' then Text := nil else
1872 Text := TGUILabel
.Create(fText
, FFontID
);
1873 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
1876 ControlType
:= TGUIFileListBox
;
1878 Result
:= (Control
as TGUIFileListBox
);
1881 if FIndex
= -1 then FIndex
:= i
;
1886 function TGUIMenu
.AddLabel(fText
: string): TGUILabel
;
1893 Control
:= TGUILabel
.Create('', FFontID
);
1894 with Control
as TGUILabel
do
1896 FWindow
:= Self
.FWindow
;
1897 FColor
:= MENU_ITEMSCTRL_COLOR
;
1900 Text := TGUILabel
.Create(fText
, FFontID
);
1903 FColor
:= MENU_ITEMSTEXT_COLOR
;
1906 ControlType
:= TGUILabel
;
1908 Result
:= (Control
as TGUILabel
);
1911 if FIndex
= -1 then FIndex
:= i
;
1916 function TGUIMenu
.AddMemo(fText
: string; Width
, Height
: Word): TGUIMemo
;
1923 Control
:= TGUIMemo
.Create(FFontID
, Width
, Height
);
1924 with Control
as TGUIMemo
do
1926 FWindow
:= Self
.FWindow
;
1927 FColor
:= MENU_ITEMSTEXT_COLOR
;
1930 if fText
= '' then Text := nil else
1932 Text := TGUILabel
.Create(fText
, FFontID
);
1933 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
1936 ControlType
:= TGUIMemo
;
1938 Result
:= (Control
as TGUIMemo
);
1941 if FIndex
= -1 then FIndex
:= i
;
1946 procedure TGUIMenu
.UpdateIndex();
1954 if (FIndex
< 0) or (FIndex
> High(FItems
)) then
1960 if FItems
[FIndex
].Control
.Enabled
then
1969 constructor TGUIScroll
.Create
;
1974 FOnChangeEvent
:= nil;
1977 procedure TGUIScroll
.FSetValue(a
: Integer);
1979 if a
> FMax
then FValue
:= FMax
else FValue
:= a
;
1982 procedure TGUIScroll
.OnMessage(var Msg
: TMessage
);
1984 if not FEnabled
then Exit
;
1992 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
1996 g_Sound_PlayEx(SCROLL_SUBSOUND
);
1997 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
1999 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
2000 if FValue
< FMax
then
2003 g_Sound_PlayEx(SCROLL_ADDSOUND
);
2004 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2011 procedure TGUIScroll
.Update
;
2019 procedure TGUISwitch
.AddItem(Item
: string);
2021 SetLength(FItems
, Length(FItems
)+1);
2022 FItems
[High(FItems
)] := Item
;
2024 if FIndex
= -1 then FIndex
:= 0;
2027 constructor TGUISwitch
.Create(FontID
: DWORD
);
2033 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2036 function TGUISwitch
.GetText
: string;
2038 if FIndex
<> -1 then Result
:= FItems
[FIndex
]
2042 procedure TGUISwitch
.OnMessage(var Msg
: TMessage
);
2044 if not FEnabled
then Exit
;
2048 if FItems
= nil then Exit
;
2053 IK_RETURN
, IK_RIGHT
, IK_KPRETURN
, IK_KPRIGHT
, VK_FIRE
, VK_OPEN
, VK_RIGHT
,
2054 JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
,
2055 JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2057 if FIndex
< High(FItems
) then
2062 g_Sound_PlayEx(SCROLL_ADDSOUND
);
2064 if @FOnChangeEvent
<> nil then
2065 FOnChangeEvent(Self
);
2068 IK_LEFT
, IK_KPLEFT
, VK_LEFT
,
2069 JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
2074 FIndex
:= High(FItems
);
2076 g_Sound_PlayEx(SCROLL_SUBSOUND
);
2078 if @FOnChangeEvent
<> nil then
2079 FOnChangeEvent(Self
);
2085 procedure TGUISwitch
.Update
;
2093 constructor TGUIEdit
.Create(FontID
: DWORD
);
2097 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2104 procedure TGUIEdit
.OnMessage(var Msg
: TMessage
);
2106 if not FEnabled
then Exit
;
2115 if (wParam
in [48..57]) and (Chr(wParam
) <> '`') then
2116 if Length(Text) < FMaxLength
then
2118 Insert(Chr(wParam
), FText
, FCaretPos
+ 1);
2124 if (wParam
in [32..255]) and (Chr(wParam
) <> '`') then
2125 if Length(Text) < FMaxLength
then
2127 Insert(Chr(wParam
), FText
, FCaretPos
+ 1);
2135 Delete(FText
, FCaretPos
, 1);
2136 if FCaretPos
> 0 then Dec(FCaretPos
);
2138 IK_DELETE
: Delete(FText
, FCaretPos
+ 1, 1);
2139 IK_END
, IK_KPEND
: FCaretPos
:= Length(FText
);
2140 IK_HOME
, IK_KPHOME
: FCaretPos
:= 0;
2141 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
: if FCaretPos
> 0 then Dec(FCaretPos
);
2142 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
: if FCaretPos
< Length(FText
) then Inc(FCaretPos
);
2143 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2146 if FActiveControl
<> Self
then
2149 if @FOnEnterEvent
<> nil then FOnEnterEvent(Self
);
2153 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
2154 else SetActive(nil);
2155 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2161 g_GUIGrabInput
:= (@FOnEnterEvent
= nil) and (FWindow
.FActiveControl
= Self
);
2163 {$IFDEF ENABLE_TOUCH}
2164 sys_ShowKeyboard(g_GUIGrabInput
)
2168 procedure TGUIEdit
.SetText(Text: string);
2170 if Length(Text) > FMaxLength
then SetLength(Text, FMaxLength
);
2172 FCaretPos
:= Length(FText
);
2175 procedure TGUIEdit
.Update
;
2182 constructor TGUIKeyRead
.Create(FontID
: DWORD
);
2188 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2191 function TGUIKeyRead
.WantActivationKey (key
: LongInt): Boolean;
2194 (key
= IK_BACKSPACE
) or
2198 procedure TGUIKeyRead
.OnMessage(var Msg
: TMessage
);
2199 procedure actDefCtl ();
2202 if FDefControl
<> '' then
2203 SetActive(GetControl(FDefControl
))
2211 if not FEnabled
then
2217 if not FIsQuery
then
2220 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2223 if FActiveControl
<> Self
then
2227 IK_BACKSPACE
: // clear keybinding if we aren't waiting for a key
2240 VK_FIRSTKEY
..VK_LASTKEY
: // do not allow to bind virtual keys
2246 if (e_KeyNames
[wParam
] <> '') and not g_Console_MatchBind(wParam
, 'togglemenu') then
2254 g_GUIGrabInput
:= FIsQuery
2259 constructor TGUIKeyRead2
.Create(FontID
: DWORD
);
2272 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2274 FMaxKeyNameWdt
:= 0;
2275 for a
:= 0 to 255 do
2277 FFont
.GetTextSize(e_KeyNames
[a
], w
, h
);
2278 FMaxKeyNameWdt
:= Max(FMaxKeyNameWdt
, w
);
2281 FMaxKeyNameWdt
:= FMaxKeyNameWdt
-(FMaxKeyNameWdt
div 3);
2283 FFont
.GetTextSize(KEYREAD_QUERY
, w
, h
);
2284 if w
> FMaxKeyNameWdt
then FMaxKeyNameWdt
:= w
;
2286 FFont
.GetTextSize(KEYREAD_CLEAR
, w
, h
);
2287 if w
> FMaxKeyNameWdt
then FMaxKeyNameWdt
:= w
;
2290 function TGUIKeyRead2
.WantActivationKey (key
: LongInt): Boolean;
2293 IK_BACKSPACE
, IK_LEFT
, IK_RIGHT
, IK_KPLEFT
, IK_KPRIGHT
, VK_LEFT
, VK_RIGHT
,
2294 JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
,
2295 JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
2302 procedure TGUIKeyRead2
.OnMessage(var Msg
: TMessage
);
2303 procedure actDefCtl ();
2306 if FDefControl
<> '' then
2307 SetActive(GetControl(FDefControl
))
2315 if not FEnabled
then
2321 if not FIsQuery
then
2324 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2327 if FActiveControl
<> Self
then
2331 IK_BACKSPACE
: // clear keybinding if we aren't waiting for a key
2333 if (FKeyIdx
= 0) then FKey0
:= 0 else FKey1
:= 0;
2336 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
2341 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
2354 VK_FIRSTKEY
..VK_LASTKEY
: // do not allow to bind virtual keys
2360 if (e_KeyNames
[wParam
] <> '') and not g_Console_MatchBind(wParam
, 'togglemenu') then
2362 if (FKeyIdx
= 0) then FKey0
:= wParam
else FKey1
:= wParam
;
2370 g_GUIGrabInput
:= FIsQuery
2376 constructor TGUIModelView
.Create
;
2383 destructor TGUIModelView
.Destroy
;
2390 procedure TGUIModelView
.NextAnim();
2392 if FModel
= nil then
2395 if FModel
.Animation
< A_PAIN
then
2396 FModel
.ChangeAnimation(FModel
.Animation
+1, True)
2398 FModel
.ChangeAnimation(A_STAND
, True);
2401 procedure TGUIModelView
.NextWeapon();
2403 if FModel
= nil then
2406 if FModel
.Weapon
< WP_LAST
then
2407 FModel
.SetWeapon(FModel
.Weapon
+1)
2409 FModel
.SetWeapon(WEAPON_KASTET
);
2412 procedure TGUIModelView
.OnMessage(var Msg
: TMessage
);
2418 procedure TGUIModelView
.SetColor(Red
, Green
, Blue
: Byte);
2420 if FModel
<> nil then FModel
.SetColor(Red
, Green
, Blue
);
2423 procedure TGUIModelView
.SetModel(ModelName
: string);
2427 FModel
:= g_PlayerModel_Get(ModelName
);
2430 procedure TGUIModelView
.Update
;
2437 if FModel
<> nil then FModel
.Update
;
2442 constructor TGUIMapPreview
.Create();
2448 destructor TGUIMapPreview
.Destroy();
2454 procedure TGUIMapPreview
.OnMessage(var Msg
: TMessage
);
2460 procedure TGUIMapPreview
.SetMap(Res
: string);
2465 //header: TMapHeaderRec_1;
2470 map
: TDynRecord
= nil;
2477 FileName
:= g_ExtractWadName(Res
);
2479 WAD
:= TWADFile
.Create();
2480 if not WAD
.ReadFile(FileName
) then
2486 //k8: ignores path again
2487 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
2496 map
:= g_Map_ParseMap(Data
, Len
);
2506 if (map
= nil) then exit
;
2509 panlist
:= map
.field
['panel'];
2510 //header := GetMapHeader(map);
2512 FMapSize
.X
:= map
.Width
div 16;
2513 FMapSize
.Y
:= map
.Height
div 16;
2515 rX
:= Ceil(map
.Width
/ (MAPPREVIEW_WIDTH
*256.0));
2516 rY
:= Ceil(map
.Height
/ (MAPPREVIEW_HEIGHT
*256.0));
2517 FScale
:= max(rX
, rY
);
2521 if (panlist
<> nil) then
2523 for pan
in panlist
do
2525 if (pan
.PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or
2526 PANEL_STEP
or PANEL_WATER
or
2527 PANEL_ACID1
or PANEL_ACID2
)) <> 0 then
2529 SetLength(FMapData
, Length(FMapData
)+1);
2530 with FMapData
[High(FMapData
)] do
2535 X2
:= (pan
.X
+ pan
.Width
) div 16;
2536 Y2
:= (pan
.Y
+ pan
.Height
) div 16;
2538 X1
:= Trunc(X1
/FScale
+ 0.5);
2539 Y1
:= Trunc(Y1
/FScale
+ 0.5);
2540 X2
:= Trunc(X2
/FScale
+ 0.5);
2541 Y2
:= Trunc(Y2
/FScale
+ 0.5);
2543 if (X1
<> X2
) or (Y1
<> Y2
) then
2551 PanelType
:= pan
.PanelType
;
2557 //writeln('freeing map');
2562 procedure TGUIMapPreview
.ClearMap();
2564 SetLength(FMapData
, 0);
2571 procedure TGUIMapPreview
.Update();
2577 function TGUIMapPreview
.GetScaleStr(): String;
2579 if FScale
> 0.0 then
2581 Result
:= FloatToStrF(FScale
*16.0, ffFixed
, 3, 3);
2582 while (Result
[Length(Result
)] = '0') do
2583 Delete(Result
, Length(Result
), 1);
2584 if (Result
[Length(Result
)] = ',') or (Result
[Length(Result
)] = '.') then
2585 Delete(Result
, Length(Result
), 1);
2586 Result
:= '1 : ' + Result
;
2594 procedure TGUIListBox
.AddItem(Item
: string);
2596 SetLength(FItems
, Length(FItems
)+1);
2597 FItems
[High(FItems
)] := Item
;
2599 if FSort
then g_gui
.Sort(FItems
);
2602 function TGUIListBox
.ItemExists (item
: String): Boolean;
2606 while (i
<= High(FItems
)) and (FItems
[i
] <> item
) do Inc(i
);
2607 result
:= i
<= High(FItems
)
2610 procedure TGUIListBox
.Clear
;
2618 constructor TGUIListBox
.Create(FontID
: DWORD
; Width
, Height
: Word);
2622 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2627 FOnChangeEvent
:= nil;
2629 FDrawScroll
:= True;
2632 procedure TGUIListBox
.OnMessage(var Msg
: TMessage
);
2636 if not FEnabled
then Exit
;
2640 if FItems
= nil then Exit
;
2653 FIndex
:= High(FItems
);
2654 FStartLine
:= Max(High(FItems
)-FHeight
+1, 0);
2656 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
2660 if FIndex
< FStartLine
then Dec(FStartLine
);
2661 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2663 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
2664 if FIndex
< High(FItems
) then
2667 if FIndex
> FStartLine
+FHeight
-1 then Inc(FStartLine
);
2668 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2670 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2673 if FActiveControl
<> Self
then SetActive(Self
)
2675 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
2676 else SetActive(nil);
2680 for a
:= 0 to High(FItems
) do
2681 if (Length(FItems
[a
]) > 0) and (LowerCase(FItems
[a
][1]) = LowerCase(Chr(wParam
))) then
2684 FStartLine
:= Min(Max(FIndex
-1, 0), Length(FItems
)-FHeight
);
2685 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2691 function TGUIListBox
.SelectedItem(): String;
2695 if (FIndex
< 0) or (FItems
= nil) or
2696 (FIndex
> High(FItems
)) then
2699 Result
:= FItems
[FIndex
];
2702 procedure TGUIListBox
.FSetItems(Items
: SSArray
);
2704 if FItems
<> nil then
2712 if FSort
then g_gui
.Sort(FItems
);
2715 procedure TGUIListBox
.SelectItem(Item
: String);
2719 if FItems
= nil then
2723 Item
:= LowerCase(Item
);
2725 for a
:= 0 to High(FItems
) do
2726 if LowerCase(FItems
[a
]) = Item
then
2732 if FIndex
< FHeight
then
2735 FStartLine
:= Min(FIndex
, Length(FItems
)-FHeight
);
2738 procedure TGUIListBox
.FSetIndex(aIndex
: Integer);
2740 if FItems
= nil then
2743 if (aIndex
< 0) or (aIndex
> High(FItems
)) then
2748 if FIndex
<= FHeight
then
2751 FStartLine
:= Min(FIndex
, Length(FItems
)-FHeight
);
2756 procedure TGUIFileListBox
.OnMessage(var Msg
: TMessage
);
2758 a
, b
: Integer; s
: AnsiString;
2760 if not FEnabled
then
2763 if FItems
= nil then
2774 if @FOnChangeEvent
<> nil then
2775 FOnChangeEvent(Self
);
2780 FIndex
:= High(FItems
);
2781 FStartLine
:= Max(High(FItems
)-FHeight
+1, 0);
2782 if @FOnChangeEvent
<> nil then
2783 FOnChangeEvent(Self
);
2786 IK_PAGEUP
, IK_KPPAGEUP
:
2788 if FIndex
> FHeight
then
2789 FIndex
:= FIndex
-FHeight
2793 if FStartLine
> FHeight
then
2794 FStartLine
:= FStartLine
-FHeight
2799 IK_PAGEDN
, IK_KPPAGEDN
:
2801 if FIndex
< High(FItems
)-FHeight
then
2802 FIndex
:= FIndex
+FHeight
2804 FIndex
:= High(FItems
);
2806 if FStartLine
< High(FItems
)-FHeight
then
2807 FStartLine
:= FStartLine
+FHeight
2809 FStartLine
:= High(FItems
)-FHeight
+1;
2812 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
, VK_UP
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
2816 if FIndex
< FStartLine
then
2818 if @FOnChangeEvent
<> nil then
2819 FOnChangeEvent(Self
);
2822 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
, VK_DOWN
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
2823 if FIndex
< High(FItems
) then
2826 if FIndex
> FStartLine
+FHeight
-1 then
2828 if @FOnChangeEvent
<> nil then
2829 FOnChangeEvent(Self
);
2832 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2835 if FActiveControl
<> Self
then
2839 if FItems
[FIndex
][1] = #29 then // Ïàïêà
2841 if FItems
[FIndex
] = #29 + '..' then
2843 //e_LogWritefln('TGUIFileListBox: Upper dir "%s" -> "%s"', [FSubPath, e_UpperDir(FSubPath)]);
2844 FSubPath
:= e_UpperDir(FSubPath
)
2848 s
:= Copy(AnsiString(FItems
[FIndex
]), 2);
2849 //e_LogWritefln('TGUIFileListBox: Enter dir "%s" -> "%s"', [FSubPath, e_CatPath(FSubPath, s)]);
2850 FSubPath
:= e_CatPath(FSubPath
, s
);
2857 if FDefControl
<> '' then
2858 SetActive(GetControl(FDefControl
))
2866 for b
:= FIndex
+ 1 to High(FItems
) + FIndex
do
2868 a
:= b
mod Length(FItems
);
2869 if ( (Length(FItems
[a
]) > 0) and
2870 (LowerCase(FItems
[a
][1]) = LowerCase(Chr(wParam
))) ) or
2871 ( (Length(FItems
[a
]) > 1) and
2872 (FItems
[a
][1] = #29) and // Ïàïêà
2873 (LowerCase(FItems
[a
][2]) = LowerCase(Chr(wParam
))) ) then
2876 FStartLine
:= Min(Max(FIndex
-1, 0), Length(FItems
)-FHeight
);
2877 if @FOnChangeEvent
<> nil then
2878 FOnChangeEvent(Self
);
2885 procedure TGUIFileListBox
.ScanDirs
;
2886 var i
, j
: Integer; path
: AnsiString; SR
: TSearchRec
; sm
, sc
: String;
2890 i
:= High(FBaseList
);
2893 path
:= e_CatPath(FBaseList
[i
], FSubPath
);
2896 if FindFirst(path
+ '/' + '*', faDirectory
, SR
) = 0 then
2899 if LongBool(SR
.Attr
and faDirectory
) then
2900 if (SR
.Name
<> '.') and ((FSubPath
<> '') or (SR
.Name
<> '..')) then
2901 if Self
.ItemExists(#1 + SR
.Name
) = false then
2902 Self
.AddItem(#1 + SR
.Name
)
2903 until FindNext(SR
) <> 0
2910 i
:= High(FBaseList
);
2913 path
:= e_CatPath(FBaseList
[i
], FSubPath
);
2919 j
:= length(sm
) + 1;
2920 sc
:= Copy(sm
, 1, j
- 1);
2922 if FindFirst(path
+ '/' + sc
, faAnyFile
, SR
) = 0 then
2925 if Self
.ItemExists(SR
.Name
) = false then
2927 until FindNext(SR
) <> 0
2934 for i
:= 0 to High(FItems
) do
2935 if FItems
[i
][1] = #1 then
2936 FItems
[i
][1] := #29;
2939 procedure TGUIFileListBox
.SetBase (dirs
: SSArray
; path
: String = '');
2946 function TGUIFileListBox
.SelectedItem (): String;
2950 if (FIndex
>= 0) and (FIndex
<= High(FItems
)) and (FItems
[FIndex
][1] <> '/') and (FItems
[FIndex
][1] <> '\') then
2952 s
:= e_CatPath(FSubPath
, FItems
[FIndex
]);
2953 if e_FindResource(FBaseList
, s
) = true then
2954 result
:= ExpandFileName(s
)
2956 e_LogWritefln('TGUIFileListBox.SelectedItem -> "%s"', [result
]);
2959 procedure TGUIFileListBox
.UpdateFileList();
2963 if (FIndex
= -1) or (FItems
= nil) or
2964 (FIndex
> High(FItems
)) or
2965 (FItems
[FIndex
][1] = '/') or
2966 (FItems
[FIndex
][1] = '\') then
2969 fn
:= FItems
[FIndex
];
2980 procedure TGUIMemo
.Clear
;
2986 constructor TGUIMemo
.Create(FontID
: DWORD
; Width
, Height
: Word);
2990 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2995 FDrawScroll
:= True;
2998 procedure TGUIMemo
.OnMessage(var Msg
: TMessage
);
3000 if not FEnabled
then Exit
;
3004 if FLines
= nil then Exit
;
3010 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
, VK_UP
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
3011 if FStartLine
> 0 then
3013 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
, VK_DOWN
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
3014 if FStartLine
< Length(FLines
)-FHeight
then
3016 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
3019 if FActiveControl
<> Self
then
3025 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
3026 else SetActive(nil);
3032 procedure TGUIMemo
.SetText(Text: string);
3035 FLines
:= GetLines(Text, FFont
.ID
, FWidth
*16);
3040 procedure TGUIimage
.ClearImage();
3042 if FImageRes
= '' then Exit
;
3044 g_Texture_Delete(FImageRes
);
3048 constructor TGUIimage
.Create();
3055 destructor TGUIimage
.Destroy();
3060 procedure TGUIimage
.OnMessage(var Msg
: TMessage
);
3065 procedure TGUIimage
.SetImage(Res
: string);
3069 if g_Texture_CreateWADEx(Res
, Res
) then FImageRes
:= Res
;
3072 procedure TGUIimage
.Update();