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;
81 TOnKeyDownEvent
= procedure(Key
: Byte);
82 TOnKeyDownEventEx
= procedure(win
: TGUIWindow
; Key
: Byte);
83 TOnCloseEvent
= procedure;
84 TOnShowEvent
= procedure;
85 TOnClickEvent
= procedure;
86 TOnChangeEvent
= procedure(Sender
: TGUIControl
);
87 TOnEnterEvent
= procedure(Sender
: TGUIControl
);
89 TGUIControl
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
96 FRightAlign
: Boolean; //HACK! this works only for "normal" menus, only for menu text labels, and generally sux. sorry.
97 FMaxWidth
: Integer; //HACK! used for right-aligning labels
100 procedure OnMessage(var Msg
: TMessage
); virtual;
101 procedure Update
; virtual;
102 function GetWidth(): Integer; virtual;
103 function GetHeight(): Integer; virtual;
104 function WantActivationKey (key
: LongInt): Boolean; virtual;
105 property X
: Integer read FX write FX
;
106 property Y
: Integer read FY write FY
;
107 property Enabled
: Boolean read FEnabled write FEnabled
;
108 property Name
: string read FName write FName
;
109 property UserData
: Pointer read FUserData write FUserData
;
110 property RightAlign
: Boolean read FRightAlign write FRightAlign
; // for menu
111 property CMaxWidth
: Integer read FMaxWidth
;
113 property Window
: TGUIWindow read FWindow
;
116 TGUIWindow
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
118 FActiveControl
: TGUIControl
;
120 FPrevWindow
: TGUIWindow
;
122 FBackTexture
: string;
123 FMainWindow
: Boolean;
124 FOnKeyDown
: TOnKeyDownEvent
;
125 FOnKeyDownEx
: TOnKeyDownEventEx
;
126 FOnCloseEvent
: TOnCloseEvent
;
127 FOnShowEvent
: TOnShowEvent
;
130 Childs
: array of TGUIControl
;
131 constructor Create(Name
: string);
132 destructor Destroy
; override;
133 function AddChild(Child
: TGUIControl
): TGUIControl
;
134 procedure OnMessage(var Msg
: TMessage
);
136 procedure SetActive(Control
: TGUIControl
);
137 function GetControl(Name
: string): TGUIControl
;
138 property OnKeyDown
: TOnKeyDownEvent read FOnKeyDown write FOnKeyDown
;
139 property OnKeyDownEx
: TOnKeyDownEventEx read FOnKeyDownEx write FOnKeyDownEx
;
140 property OnClose
: TOnCloseEvent read FOnCloseEvent write FOnCloseEvent
;
141 property OnShow
: TOnShowEvent read FOnShowEvent write FOnShowEvent
;
142 property Name
: string read FName
;
143 property DefControl
: string read FDefControl write FDefControl
;
144 property BackTexture
: string read FBackTexture write FBackTexture
;
145 property MainWindow
: Boolean read FMainWindow write FMainWindow
;
146 property UserData
: Pointer read FUserData write FUserData
;
148 property ActiveControl
: TGUIControl read FActiveControl
;
151 TGUITextButton
= class(TGUIControl
)
160 ProcEx
: procedure (sender
: TGUITextButton
);
161 constructor Create(aProc
: Pointer; BigFont
: Boolean; Text: string);
162 destructor Destroy(); override;
163 procedure OnMessage(var Msg
: TMessage
); override;
164 procedure Update(); override;
165 procedure Click(Silent
: Boolean = False);
166 property Caption
: string read FText write FText
;
167 property Color
: TRGB read FColor write FColor
;
168 property BigFont
: Boolean read FBigFont write FBigFont
;
169 property ShowWindow
: string read FShowWindow write FShowWindow
;
172 TGUILabel
= class(TGUIControl
)
178 FOnClickEvent
: TOnClickEvent
;
180 constructor Create(Text: string; BigFont
: Boolean);
181 procedure OnMessage(var Msg
: TMessage
); override;
182 property OnClick
: TOnClickEvent read FOnClickEvent write FOnClickEvent
;
183 property FixedLength
: Word read FFixedLen write FFixedLen
;
184 property Text: string read FText write FText
;
185 property Color
: TRGB read FColor write FColor
;
186 property BigFont
: Boolean read FBigFont write FBigFont
;
189 TGUIScroll
= class(TGUIControl
)
193 FOnChangeEvent
: TOnChangeEvent
;
194 procedure FSetValue(a
: Integer);
196 constructor Create();
197 procedure OnMessage(var Msg
: TMessage
); override;
198 procedure Update
; override;
199 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
200 property Max
: Word read FMax write FMax
;
201 property Value
: Integer read FValue write FSetValue
;
204 TGUIItemsList
= array of string;
206 TGUISwitch
= class(TGUIControl
)
209 FItems
: TGUIItemsList
;
212 FOnChangeEvent
: TOnChangeEvent
;
214 constructor Create(BigFont
: Boolean);
215 procedure OnMessage(var Msg
: TMessage
); override;
216 procedure AddItem(Item
: string);
217 procedure Update
; override;
218 function GetText
: string;
219 property ItemIndex
: Integer read FIndex write FIndex
;
220 property Color
: TRGB read FColor write FColor
;
221 property BigFont
: Boolean read FBigFont write FBigFont
;
222 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
223 property Items
: TGUIItemsList read FItems
;
226 TGUIEdit
= class(TGUIControl
)
234 FOnlyDigits
: Boolean;
235 FOnChangeEvent
: TOnChangeEvent
;
236 FOnEnterEvent
: TOnEnterEvent
;
238 procedure SetText(Text: string);
240 constructor Create(BigFont
: Boolean);
241 procedure OnMessage(var Msg
: TMessage
); override;
242 procedure Update
; override;
243 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
244 property OnEnter
: TOnEnterEvent read FOnEnterEvent write FOnEnterEvent
;
245 property Width
: Word read FWidth write FWidth
;
246 property MaxLength
: Word read FMaxLength write FMaxLength
;
247 property OnlyDigits
: Boolean read FOnlyDigits write FOnlyDigits
;
248 property Text: string read FText write SetText
;
249 property Color
: TRGB read FColor write FColor
;
250 property BigFont
: Boolean read FBigFont write FBigFont
;
251 property Invalid
: Boolean read FInvalid write FInvalid
;
253 property CaretPos
: Integer read FCaretPos
;
256 TGUIKeyRead
= class(TGUIControl
)
263 constructor Create(BigFont
: Boolean);
264 procedure OnMessage(var Msg
: TMessage
); override;
265 function WantActivationKey (key
: LongInt): Boolean; override;
266 property Key
: Word read FKey write FKey
;
267 property Color
: TRGB read FColor write FColor
;
268 property BigFont
: Boolean read FBigFont write FBigFont
;
270 property IsQuery
: Boolean read FIsQuery
;
274 TGUIKeyRead2
= class(TGUIControl
)
278 FKey0
, FKey1
: Word; // this should be an array. sorry.
281 FMaxKeyNameWdt
: Integer;
283 constructor Create(BigFont
: Boolean);
284 procedure OnMessage(var Msg
: TMessage
); override;
285 function WantActivationKey (key
: LongInt): Boolean; override;
286 property Key0
: Word read FKey0 write FKey0
;
287 property Key1
: Word read FKey1 write FKey1
;
288 property Color
: TRGB read FColor write FColor
;
289 property BigFont
: Boolean read FBigFont write FBigFont
;
291 property IsQuery
: Boolean read FIsQuery
;
292 property MaxKeyNameWdt
: Integer read FMaxKeyNameWdt
;
293 property KeyIdx
: Integer read FKeyIdx
;
296 TGUIModelView
= class(TGUIControl
)
298 FModel
: TPlayerModel
;
302 destructor Destroy
; override;
303 procedure OnMessage(var Msg
: TMessage
); override;
304 procedure SetModel(ModelName
: string);
305 procedure SetColor(Red
, Green
, Blue
: Byte);
306 procedure NextAnim();
307 procedure NextWeapon();
308 procedure Update
; override;
309 property Model
: TPlayerModel read FModel
;
312 TPreviewPanel
= record
313 X1
, Y1
, X2
, Y2
: Integer;
317 TPreviewPanelArray
= array of TPreviewPanel
;
319 TGUIMapPreview
= class(TGUIControl
)
321 FMapData
: TPreviewPanelArray
;
325 constructor Create();
326 destructor Destroy(); override;
327 procedure OnMessage(var Msg
: TMessage
); override;
328 procedure SetMap(Res
: string);
329 procedure ClearMap();
330 procedure Update(); override;
331 function GetScaleStr
: String;
333 property MapData
: TPreviewPanelArray read FMapData
;
334 property MapSize
: TDFPoint read FMapSize
;
335 property Scale
: Single read FScale
;
338 TGUIImage
= class(TGUIControl
)
343 constructor Create();
344 destructor Destroy(); override;
345 procedure OnMessage(var Msg
: TMessage
); override;
346 procedure SetImage(Res
: string);
347 procedure ClearImage();
348 procedure Update(); override;
350 property DefaultRes
: string read FDefaultRes write FDefaultRes
;
351 property ImageRes
: string read FImageRes
;
354 TGUIListBox
= class(TGUIControl
)
358 FUnActiveColor
: TRGB
;
366 FDrawScroll
: Boolean;
367 FOnChangeEvent
: TOnChangeEvent
;
369 procedure FSetItems(Items
: SSArray
);
370 procedure FSetIndex(aIndex
: Integer);
373 constructor Create(BigFont
: Boolean; Width
, Height
: Word);
374 procedure OnMessage(var Msg
: TMessage
); override;
375 procedure AddItem(Item
: String);
376 function ItemExists (item
: String): Boolean;
377 procedure SelectItem(Item
: String);
379 function SelectedItem(): String;
381 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
382 property Sort
: Boolean read FSort write FSort
;
383 property ItemIndex
: Integer read FIndex write FSetIndex
;
384 property Items
: SSArray read FItems write FSetItems
;
385 property DrawBack
: Boolean read FDrawBack write FDrawBack
;
386 property DrawScrollBar
: Boolean read FDrawScroll write FDrawScroll
;
387 property ActiveColor
: TRGB read FActiveColor write FActiveColor
;
388 property UnActiveColor
: TRGB read FUnActiveColor write FUnActiveColor
;
389 property BigFont
: Boolean read FBigFont write FBigFont
;
391 property Width
: Word read FWidth
;
392 property Height
: Word read FHeight
;
393 property StartLine
: Integer read FStartLine
;
396 TGUIFileListBox
= class(TGUIListBox
)
401 FBaseList
: SSArray
; // highter index have highter priority
406 procedure OnMessage (var Msg
: TMessage
); override;
407 procedure SetBase (dirs
: SSArray
; path
: String = '');
408 function SelectedItem(): String;
409 procedure UpdateFileList
;
411 property Dirs
: Boolean read FDirs write FDirs
;
412 property FileMask
: String read FFileMask write FFileMask
;
415 TGUIMemo
= class(TGUIControl
)
424 FDrawScroll
: Boolean;
426 constructor Create(BigFont
: Boolean; Width
, Height
: Word);
427 procedure OnMessage(var Msg
: TMessage
); override;
429 procedure SetText(Text: string);
430 property DrawBack
: Boolean read FDrawBack write FDrawBack
;
431 property DrawScrollBar
: Boolean read FDrawScroll write FDrawScroll
;
432 property Color
: TRGB read FColor write FColor
;
433 property BigFont
: Boolean read FBigFont write FBigFont
;
435 property Width
: Word read FWidth
;
436 property Height
: Word read FHeight
;
437 property StartLine
: Integer read FStartLine
;
438 property Lines
: SSArray read FLines
;
441 TGUITextButtonList
= array of TGUITextButton
;
443 TGUIMainMenu
= class(TGUIControl
)
445 FButtons
: TGUITextButtonList
;
449 FCounter
: Byte; // !!! update it within render
451 constructor Create(BigFont
: Boolean; Header
: string);
452 destructor Destroy
; override;
453 procedure OnMessage(var Msg
: TMessage
); override;
454 function AddButton(fProc
: Pointer; Caption
: string; ShowWindow
: string = ''): TGUITextButton
;
455 function GetButton(aName
: string): TGUITextButton
;
456 procedure EnableButton(aName
: string; e
: Boolean);
457 procedure AddSpace();
458 procedure Update
; override;
460 property Header
: TGUILabel read FHeader
;
461 property Buttons
: TGUITextButtonList read FButtons
;
462 property Index
: Integer read FIndex
;
463 property Counter
: Byte read FCounter
;
466 TControlType
= class of TGUIControl
;
468 PMenuItem
= ^TMenuItem
;
471 ControlType
: TControlType
;
472 Control
: TGUIControl
;
474 TMenuItemList
= array of TMenuItem
;
476 TGUIMenu
= class(TGUIControl
)
478 FItems
: TMenuItemList
;
486 function NewItem(): Integer;
488 constructor Create(HeaderBigFont
, ItemsBigFont
: Boolean; Header
: string);
489 destructor Destroy
; override;
490 procedure OnMessage(var Msg
: TMessage
); override;
491 procedure AddSpace();
492 procedure AddLine(fText
: string);
493 procedure AddText(fText
: string; MaxWidth
: Word);
494 function AddLabel(fText
: string): TGUILabel
;
495 function AddButton(Proc
: Pointer; fText
: string; _ShowWindow
: string = ''): TGUITextButton
;
496 function AddScroll(fText
: string): TGUIScroll
;
497 function AddSwitch(fText
: string): TGUISwitch
;
498 function AddEdit(fText
: string): TGUIEdit
;
499 function AddKeyRead(fText
: string): TGUIKeyRead
;
500 function AddKeyRead2(fText
: string): TGUIKeyRead2
;
501 function AddList(fText
: string; Width
, Height
: Word): TGUIListBox
;
502 function AddFileList(fText
: string; Width
, Height
: Word): TGUIFileListBox
;
503 function AddMemo(fText
: string; Width
, Height
: Word): TGUIMemo
;
505 function GetControl(aName
: string): TGUIControl
;
506 function GetControlsText(aName
: string): TGUILabel
;
507 procedure Update
; override;
508 procedure UpdateIndex();
509 property Align
: Boolean read FAlign write FAlign
;
510 property Left
: Integer read FLeft write FLeft
;
511 property YesNo
: Boolean read FYesNo write FYesNo
;
513 property Header
: TGUILabel read FHeader
;
514 property Counter
: Byte read FCounter
;
515 property Index
: Integer read FIndex
;
516 property Items
: TMenuItemList read FItems
;
517 property BigFont
: Boolean read FBigFont
;
521 g_GUIWindows
: array of TGUIWindow
;
522 g_ActiveWindow
: TGUIWindow
= nil;
523 g_GUIGrabInput
: Boolean = False;
525 function g_GUI_AddWindow(Window
: TGUIWindow
): TGUIWindow
;
526 function g_GUI_GetWindow(Name
: string): TGUIWindow
;
527 procedure g_GUI_ShowWindow(Name
: string);
528 procedure g_GUI_HideWindow(PlaySound
: Boolean = True);
529 function g_GUI_Destroy(): Boolean;
530 procedure g_GUI_SaveMenuPos();
531 procedure g_GUI_LoadMenuPos();
537 {$IFDEF ENABLE_TOUCH}
540 {$IFDEF ENABLE_RENDER}
543 g_sound
, SysUtils
, e_res
,
544 g_game
, Math
, StrUtils
, g_player
, g_options
,
545 g_map
, g_weapons
, xdynrec
, wadreader
;
549 Saved_Windows
: SSArray
;
551 function GetLines (Text: string; BigFont
: Boolean; MaxWidth
: Word): SSArray
;
552 var i
, j
, len
, lines
: Integer;
554 function GetLine (j
, i
: Integer): String;
556 result
:= Copy(text, j
, i
- j
+ 1);
559 function GetWidth (j
, i
: Integer): Integer;
562 r_GUI_GetStringSize(BigFont
, GetLine(j
, i
), w
, h
);
567 result
:= nil; lines
:= 0;
568 j
:= 1; i
:= 1; len
:= Length(Text);
569 // e_LogWritefln('GetLines @%s len=%s [%s]', [MaxWidth, len, Text]);
572 (* --- Get longest possible sequence --- *)
573 while (i
+ 1 <= len
) and (GetWidth(j
, i
+ 1) <= MaxWidth
) do Inc(i
);
574 (* --- Do not include part of word --- *)
575 if (i
< len
) and (text[i
] <> ' ') then
576 while (i
>= j
) and (text[i
] <> ' ') do Dec(i
);
577 (* --- Do not include spaces --- *)
578 while (i
>= j
) and (text[i
] = ' ') do Dec(i
);
579 (* --- Add line --- *)
580 SetLength(result
, lines
+ 1);
581 result
[lines
] := GetLine(j
, i
);
582 // e_LogWritefln(' -> (%s:%s::%s) [%s]', [j, i, GetWidth(j, i), result[lines]]);
584 (* --- Skip spaces --- *)
585 while (i
<= len
) and (text[i
] = ' ') do Inc(i
);
590 procedure Sort (var a
: SSArray
);
591 var i
, j
: Integer; s
: string;
593 if a
= nil then Exit
;
595 for i
:= High(a
) downto Low(a
) do
596 for j
:= Low(a
) to High(a
) - 1 do
597 if LowerCase(a
[j
]) > LowerCase(a
[j
+ 1]) then
605 function g_GUI_Destroy(): Boolean;
609 Result
:= (Length(g_GUIWindows
) > 0);
611 for i
:= 0 to High(g_GUIWindows
) do
612 g_GUIWindows
[i
].Free();
615 g_ActiveWindow
:= nil;
618 function g_GUI_AddWindow(Window
: TGUIWindow
): TGUIWindow
;
620 SetLength(g_GUIWindows
, Length(g_GUIWindows
)+1);
621 g_GUIWindows
[High(g_GUIWindows
)] := Window
;
626 function g_GUI_GetWindow(Name
: string): TGUIWindow
;
632 if g_GUIWindows
<> nil then
633 for i
:= 0 to High(g_GUIWindows
) do
634 if g_GUIWindows
[i
].FName
= Name
then
636 Result
:= g_GUIWindows
[i
];
640 Assert(Result
<> nil, 'GUI_Window "'+Name
+'" not found');
643 procedure g_GUI_ShowWindow(Name
: string);
647 if g_GUIWindows
= nil then
650 for i
:= 0 to High(g_GUIWindows
) do
651 if g_GUIWindows
[i
].FName
= Name
then
653 g_GUIWindows
[i
].FPrevWindow
:= g_ActiveWindow
;
654 g_ActiveWindow
:= g_GUIWindows
[i
];
656 if g_ActiveWindow
.MainWindow
then
657 g_ActiveWindow
.FPrevWindow
:= nil;
659 if g_ActiveWindow
.FDefControl
<> '' then
660 g_ActiveWindow
.SetActive(g_ActiveWindow
.GetControl(g_ActiveWindow
.FDefControl
))
662 g_ActiveWindow
.SetActive(nil);
664 if @g_ActiveWindow
.FOnShowEvent
<> nil then
665 g_ActiveWindow
.FOnShowEvent();
671 procedure g_GUI_HideWindow(PlaySound
: Boolean = True);
673 if g_ActiveWindow
<> nil then
675 if @g_ActiveWindow
.OnClose
<> nil then
676 g_ActiveWindow
.OnClose();
677 g_ActiveWindow
:= g_ActiveWindow
.FPrevWindow
;
679 g_Sound_PlayEx(WINDOW_CLOSESOUND
);
683 procedure g_GUI_SaveMenuPos();
688 SetLength(Saved_Windows
, 0);
689 win
:= g_ActiveWindow
;
693 len
:= Length(Saved_Windows
);
694 SetLength(Saved_Windows
, len
+ 1);
696 Saved_Windows
[len
] := win
.Name
;
698 if win
.MainWindow
then
701 win
:= win
.FPrevWindow
;
705 procedure g_GUI_LoadMenuPos();
707 i
, j
, k
, len
: Integer;
710 g_ActiveWindow
:= nil;
711 len
:= Length(Saved_Windows
);
716 // Îêíî ñ ãëàâíûì ìåíþ:
717 g_GUI_ShowWindow(Saved_Windows
[len
-1]);
719 // Íå ïåðåêëþ÷èëîñü (èëè íåêóäà äàëüøå):
720 if (len
= 1) or (g_ActiveWindow
= nil) then
723 // Èùåì êíîïêè â îñòàëüíûõ îêíàõ:
724 for k
:= len
-1 downto 1 do
728 for i
:= 0 to Length(g_ActiveWindow
.Childs
)-1 do
730 if g_ActiveWindow
.Childs
[i
] is TGUIMainMenu
then
731 begin // GUI_MainMenu
732 with TGUIMainMenu(g_ActiveWindow
.Childs
[i
]) do
733 for j
:= 0 to Length(FButtons
)-1 do
734 if FButtons
[j
].ShowWindow
= Saved_Windows
[k
-1] then
736 FButtons
[j
].Click(True);
742 if g_ActiveWindow
.Childs
[i
] is TGUIMenu
then
743 with TGUIMenu(g_ActiveWindow
.Childs
[i
]) do
744 for j
:= 0 to Length(FItems
)-1 do
745 if FItems
[j
].ControlType
= TGUITextButton
then
746 if TGUITextButton(FItems
[j
].Control
).ShowWindow
= Saved_Windows
[k
-1] then
748 TGUITextButton(FItems
[j
].Control
).Click(True);
759 (g_ActiveWindow
.Name
= Saved_Windows
[k
]) then
766 constructor TGUIWindow
.Create(Name
: string);
769 FActiveControl
:= nil;
773 FOnCloseEvent
:= nil;
777 destructor TGUIWindow
.Destroy
;
784 for i
:= 0 to High(Childs
) do
788 function TGUIWindow
.AddChild(Child
: TGUIControl
): TGUIControl
;
790 Child
.FWindow
:= Self
;
792 SetLength(Childs
, Length(Childs
) + 1);
793 Childs
[High(Childs
)] := Child
;
798 procedure TGUIWindow
.Update
;
802 for i
:= 0 to High(Childs
) do
803 if Childs
[i
] <> nil then Childs
[i
].Update
;
806 procedure TGUIWindow
.OnMessage(var Msg
: TMessage
);
808 if FActiveControl
<> nil then FActiveControl
.OnMessage(Msg
);
809 if @FOnKeyDown
<> nil then FOnKeyDown(Msg
.wParam
);
810 if @FOnKeyDownEx
<> nil then FOnKeyDownEx(self
, Msg
.wParam
);
812 if Msg
.Msg
= WM_KEYDOWN
then
824 procedure TGUIWindow
.SetActive(Control
: TGUIControl
);
826 FActiveControl
:= Control
;
829 function TGUIWindow
.GetControl(Name
: String): TGUIControl
;
835 if Childs
<> nil then
836 for i
:= 0 to High(Childs
) do
837 if Childs
[i
] <> nil then
838 if LowerCase(Childs
[i
].FName
) = LowerCase(Name
) then
844 Assert(Result
<> nil, 'Window Control "'+Name
+'" not Found!');
849 constructor TGUIControl
.Create();
855 FRightAlign
:= false;
859 procedure TGUIControl
.OnMessage(var Msg
: TMessage
);
865 procedure TGUIControl
.Update();
869 function TGUIControl
.WantActivationKey (key
: LongInt): Boolean;
874 function TGUIControl
.GetWidth (): Integer;
875 {$IFDEF ENABLE_RENDER}
879 {$IFDEF ENABLE_RENDER}
880 r_GUI_GetSize(Self
, Result
, h
);
886 function TGUIControl
.GetHeight (): Integer;
887 {$IFDEF ENABLE_RENDER}
891 {$IFDEF ENABLE_RENDER}
892 r_GUI_GetSize(Self
, w
, Result
);
900 procedure TGUITextButton
.Click(Silent
: Boolean = False);
902 if (FSound
<> '') and (not Silent
) then g_Sound_PlayEx(FSound
);
904 if @Proc
<> nil then Proc();
905 if @ProcEx
<> nil then ProcEx(self
);
907 if FShowWindow
<> '' then g_GUI_ShowWindow(FShowWindow
);
910 constructor TGUITextButton
.Create(aProc
: Pointer; BigFont
: Boolean; Text: string);
921 destructor TGUITextButton
.Destroy
;
927 procedure TGUITextButton
.OnMessage(var Msg
: TMessage
);
929 if not FEnabled
then Exit
;
936 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
: Click();
941 procedure TGUITextButton
.Update
;
948 function TGUIMainMenu
.AddButton(fProc
: Pointer; Caption
: string; ShowWindow
: string = ''): TGUITextButton
;
957 SetLength(FButtons
, Length(FButtons
)+1);
958 FButtons
[High(FButtons
)] := TGUITextButton
.Create(fProc
, FBigFont
, Caption
);
959 FButtons
[High(FButtons
)].ShowWindow
:= ShowWindow
;
960 with FButtons
[High(FButtons
)] do
962 if (fProc
<> nil) or (ShowWindow
<> '') then FColor
:= MAINMENU_ITEMS_COLOR
963 else FColor
:= MAINMENU_UNACTIVEITEMS_COLOR
;
964 FSound
:= MAINMENU_CLICKSOUND
;
967 _x
:= gScreenWidth
div 2;
969 for a
:= 0 to High(FButtons
) do
970 if FButtons
[a
] <> nil then
971 _x
:= Min(_x
, (gScreenWidth
div 2)-(FButtons
[a
].GetWidth
div 2));
973 if FHeader
= nil then
974 r_GUI_GetLogoSize(lw
, lh
);
975 hh
:= FButtons
[High(FButtons
)].GetHeight
;
977 if FHeader
= nil then h
:= lh
+ hh
* (1 + Length(FButtons
)) + MAINMENU_SPACE
* (Length(FButtons
) - 1)
978 else h
:= hh
* (2 + Length(FButtons
)) + MAINMENU_SPACE
* (Length(FButtons
) - 1);
979 h
:= (gScreenHeight
div 2) - (h
div 2);
981 if FHeader
<> nil then with FHeader
do
987 if FHeader
= nil then Inc(h
, lh
)
990 for a
:= 0 to High(FButtons
) do
992 if FButtons
[a
] <> nil then
999 Inc(h
, hh
+MAINMENU_SPACE
);
1002 Result
:= FButtons
[High(FButtons
)];
1005 procedure TGUIMainMenu
.AddSpace
;
1007 SetLength(FButtons
, Length(FButtons
)+1);
1008 FButtons
[High(FButtons
)] := nil;
1011 constructor TGUIMainMenu
.Create(BigFont
: Boolean; Header
: string);
1016 FBigFont
:= BigFont
;
1017 FCounter
:= MAINMENU_MARKERDELAY
;
1019 if Header
<> '' then
1021 FHeader
:= TGUILabel
.Create(Header
, BigFont
);
1024 FColor
:= MAINMENU_HEADER_COLOR
;
1025 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1026 FY
:= (gScreenHeight
div 2)-(GetHeight
div 2);
1031 destructor TGUIMainMenu
.Destroy
;
1035 if FButtons
<> nil then
1036 for a
:= 0 to High(FButtons
) do
1044 procedure TGUIMainMenu
.EnableButton(aName
: string; e
: Boolean);
1048 if FButtons
= nil then Exit
;
1050 for a
:= 0 to High(FButtons
) do
1051 if (FButtons
[a
] <> nil) and (FButtons
[a
].Name
= aName
) then
1053 if e
then FButtons
[a
].FColor
:= MAINMENU_ITEMS_COLOR
1054 else FButtons
[a
].FColor
:= MAINMENU_UNACTIVEITEMS_COLOR
;
1055 FButtons
[a
].Enabled
:= e
;
1060 function TGUIMainMenu
.GetButton(aName
: string): TGUITextButton
;
1066 if FButtons
= nil then Exit
;
1068 for a
:= 0 to High(FButtons
) do
1069 if (FButtons
[a
] <> nil) and (FButtons
[a
].Name
= aName
) then
1071 Result
:= FButtons
[a
];
1076 procedure TGUIMainMenu
.OnMessage(var Msg
: TMessage
);
1081 if not FEnabled
then Exit
;
1085 if FButtons
= nil then Exit
;
1088 for a
:= 0 to High(FButtons
) do
1089 if FButtons
[a
] <> nil then
1095 if not ok
then Exit
;
1100 IK_UP
, IK_KPUP
, VK_UP
, JOY0_UP
, JOY1_UP
, JOY2_UP
, JOY3_UP
:
1104 if FIndex
< 0 then FIndex
:= High(FButtons
);
1105 until FButtons
[FIndex
] <> nil;
1107 g_Sound_PlayEx(MENU_CHANGESOUND
);
1109 IK_DOWN
, IK_KPDOWN
, VK_DOWN
, JOY0_DOWN
, JOY1_DOWN
, JOY2_DOWN
, JOY3_DOWN
:
1113 if FIndex
> High(FButtons
) then FIndex
:= 0;
1114 until FButtons
[FIndex
] <> nil;
1116 g_Sound_PlayEx(MENU_CHANGESOUND
);
1118 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
;
1123 procedure TGUIMainMenu
.Update
;
1126 FCounter
:= (FCounter
+ 1) MOD (2 * MAINMENU_MARKERDELAY
)
1131 constructor TGUILabel
.Create(Text: string; BigFont
: Boolean);
1135 FBigFont
:= BigFont
;
1138 FOnClickEvent
:= nil;
1141 procedure TGUILabel
.OnMessage(var Msg
: TMessage
);
1143 if not FEnabled
then Exit
;
1150 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
: if @FOnClickEvent
<> nil then FOnClickEvent();
1157 function TGUIMenu
.AddButton(Proc
: Pointer; fText
: string; _ShowWindow
: string = ''): TGUITextButton
;
1164 Control
:= TGUITextButton
.Create(Proc
, FBigFont
, fText
);
1165 with Control
as TGUITextButton
do
1167 ShowWindow
:= _ShowWindow
;
1168 FColor
:= MENU_ITEMSCTRL_COLOR
;
1172 ControlType
:= TGUITextButton
;
1174 Result
:= (Control
as TGUITextButton
);
1177 if FIndex
= -1 then FIndex
:= i
;
1182 procedure TGUIMenu
.AddLine(fText
: string);
1189 Text := TGUILabel
.Create(fText
, FBigFont
);
1192 FColor
:= MENU_ITEMSTEXT_COLOR
;
1201 procedure TGUIMenu
.AddText(fText
: string; MaxWidth
: Word);
1206 l
:= GetLines(fText
, FBigFont
, MaxWidth
);
1208 if l
= nil then Exit
;
1210 for a
:= 0 to High(l
) do
1215 Text := TGUILabel
.Create(l
[a
], FBigFont
);
1218 with Text do begin FColor
:= _RGB(255, 0, 0); end;
1222 with Text do begin FColor
:= MENU_ITEMSTEXT_COLOR
; end;
1232 procedure TGUIMenu
.AddSpace
;
1246 constructor TGUIMenu
.Create(HeaderBigFont
, ItemsBigFont
: Boolean; Header
: string);
1252 FBigFont
:= ItemsBigFont
;
1253 FCounter
:= MENU_MARKERDELAY
;
1257 FHeader
:= TGUILabel
.Create(Header
, HeaderBigFont
);
1260 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1262 FColor
:= MAINMENU_HEADER_COLOR
;
1266 destructor TGUIMenu
.Destroy
;
1270 if FItems
<> nil then
1271 for a
:= 0 to High(FItems
) do
1285 function TGUIMenu
.GetControl(aName
: String): TGUIControl
;
1291 if FItems
<> nil then
1292 for a
:= 0 to High(FItems
) do
1293 if FItems
[a
].Control
<> nil then
1294 if LowerCase(FItems
[a
].Control
.Name
) = LowerCase(aName
) then
1296 Result
:= FItems
[a
].Control
;
1300 Assert(Result
<> nil, 'GUI control "'+aName
+'" not found!');
1303 function TGUIMenu
.GetControlsText(aName
: String): TGUILabel
;
1309 if FItems
<> nil then
1310 for a
:= 0 to High(FItems
) do
1311 if FItems
[a
].Control
<> nil then
1312 if LowerCase(FItems
[a
].Control
.Name
) = LowerCase(aName
) then
1314 Result
:= FItems
[a
].Text;
1318 Assert(Result
<> nil, 'GUI control''s text "'+aName
+'" not found!');
1321 function TGUIMenu
.NewItem
: Integer;
1323 SetLength(FItems
, Length(FItems
)+1);
1324 Result
:= High(FItems
);
1327 procedure TGUIMenu
.OnMessage(var Msg
: TMessage
);
1332 if not FEnabled
then Exit
;
1336 if FItems
= nil then Exit
;
1339 for a
:= 0 to High(FItems
) do
1340 if FItems
[a
].Control
<> nil then
1346 if not ok
then Exit
;
1348 if (Msg
.Msg
= WM_KEYDOWN
) and (FIndex
<> -1) and (FItems
[FIndex
].Control
<> nil) and
1349 (FItems
[FIndex
].Control
.WantActivationKey(Msg
.wParam
)) then
1351 FItems
[FIndex
].Control
.OnMessage(Msg
);
1352 g_Sound_PlayEx(MENU_CLICKSOUND
);
1360 IK_UP
, IK_KPUP
, VK_UP
,JOY0_UP
, JOY1_UP
, JOY2_UP
, JOY3_UP
:
1365 if c
> Length(FItems
) then
1372 if FIndex
< 0 then FIndex
:= High(FItems
);
1373 until (FItems
[FIndex
].Control
<> nil) and
1374 (FItems
[FIndex
].Control
.Enabled
);
1378 g_Sound_PlayEx(MENU_CHANGESOUND
);
1381 IK_DOWN
, IK_KPDOWN
, VK_DOWN
, JOY0_DOWN
, JOY1_DOWN
, JOY2_DOWN
, JOY3_DOWN
:
1386 if c
> Length(FItems
) then
1393 if FIndex
> High(FItems
) then FIndex
:= 0;
1394 until (FItems
[FIndex
].Control
<> nil) and
1395 (FItems
[FIndex
].Control
.Enabled
);
1399 g_Sound_PlayEx(MENU_CHANGESOUND
);
1402 IK_LEFT
, IK_RIGHT
, IK_KPLEFT
, IK_KPRIGHT
, VK_LEFT
, VK_RIGHT
,
1403 JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
,
1404 JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
1406 if FIndex
<> -1 then
1407 if FItems
[FIndex
].Control
<> nil then
1408 FItems
[FIndex
].Control
.OnMessage(Msg
);
1410 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
1412 if FIndex
<> -1 then
1414 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1416 g_Sound_PlayEx(MENU_CLICKSOUND
);
1420 if FYesNo
and (length(FItems
) > 1) then
1422 Msg
.wParam
:= IK_RETURN
; // to register keypress
1423 FIndex
:= High(FItems
)-1;
1424 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1427 if FYesNo
and (length(FItems
) > 1) then
1429 Msg
.wParam
:= IK_RETURN
; // to register keypress
1430 FIndex
:= High(FItems
);
1431 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1438 procedure TGUIMenu
.ReAlign();
1440 a
, tx
, cx
, w
, h
, fw
, fh
: Integer;
1441 cww
: array of Integer; // cached widths
1444 if FItems
= nil then Exit
;
1446 SetLength(cww
, length(FItems
));
1448 for a
:= 0 to High(FItems
) do
1450 if FItems
[a
].Text <> nil then
1452 cww
[a
] := FItems
[a
].Text.GetWidth
;
1453 if maxcww
< cww
[a
] then maxcww
:= cww
[a
];
1464 for a
:= 0 to High(FItems
) do
1467 if FItems
[a
].Text <> nil then w
:= FItems
[a
].Text.GetWidth
;
1468 if FItems
[a
].Control
<> nil then
1471 if FItems
[a
].ControlType
= TGUILabel
then w
:= w
+(FItems
[a
].Control
as TGUILabel
).GetWidth
1472 else if FItems
[a
].ControlType
= TGUITextButton
then w
:= w
+(FItems
[a
].Control
as TGUITextButton
).GetWidth
1473 else if FItems
[a
].ControlType
= TGUIScroll
then w
:= w
+(FItems
[a
].Control
as TGUIScroll
).GetWidth
1474 else if FItems
[a
].ControlType
= TGUISwitch
then w
:= w
+(FItems
[a
].Control
as TGUISwitch
).GetWidth
1475 else if FItems
[a
].ControlType
= TGUIEdit
then w
:= w
+(FItems
[a
].Control
as TGUIEdit
).GetWidth
1476 else if FItems
[a
].ControlType
= TGUIKeyRead
then w
:= w
+(FItems
[a
].Control
as TGUIKeyRead
).GetWidth
1477 else if FItems
[a
].ControlType
= TGUIKeyRead2
then w
:= w
+(FItems
[a
].Control
as TGUIKeyRead2
).GetWidth
1478 else if FItems
[a
].ControlType
= TGUIListBox
then w
:= w
+(FItems
[a
].Control
as TGUIListBox
).GetWidth
1479 else if FItems
[a
].ControlType
= TGUIFileListBox
then w
:= w
+(FItems
[a
].Control
as TGUIFileListBox
).GetWidth
1480 else if FItems
[a
].ControlType
= TGUIMemo
then w
:= w
+(FItems
[a
].Control
as TGUIMemo
).GetWidth
;
1482 tx
:= Min(tx
, (gScreenWidth
div 2)-(w
div 2));
1487 for a
:= 0 to High(FItems
) do
1491 if (Text <> nil) and (Control
= nil) then Continue
;
1493 if Text <> nil then w
:= tx
+Text.GetWidth
;
1494 if w
> cx
then cx
:= w
;
1498 cx
:= cx
+MENU_HSPACE
;
1500 h
:= FHeader
.GetHeight
*2+MENU_VSPACE
*(Length(FItems
)-1);
1502 for a
:= 0 to High(FItems
) do
1506 if (ControlType
= TGUIListBox
) or (ControlType
= TGUIFileListBox
) then
1507 h
:= h
+(FItems
[a
].Control
as TGUIListBox
).GetHeight()
1510 r_GUI_GetMaxFontSize(FBigFont
, fw
, fh
);
1516 h
:= (gScreenHeight
div 2)-(h
div 2);
1520 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1523 Inc(h
, GetHeight
*2);
1526 for a
:= 0 to High(FItems
) do
1538 if Text.RightAlign
and (length(cww
) > a
) then
1540 //Text.FX := Text.FX+maxcww;
1541 Text.FMaxWidth
:= maxcww
;
1545 if Control
<> nil then
1562 if (ControlType
= TGUIListBox
) or (ControlType
= TGUIFileListBox
) then Inc(h
, (Control
as TGUIListBox
).GetHeight
+MENU_VSPACE
)
1563 else if ControlType
= TGUIMemo
then Inc(h
, (Control
as TGUIMemo
).GetHeight
+MENU_VSPACE
)
1566 r_GUI_GetMaxFontSize(FBigFont
, fw
, fh
);
1567 h
:= h
+ fh
+ MENU_VSPACE
;
1572 // another ugly hack
1573 if FYesNo
and (length(FItems
) > 1) then
1576 for a
:= High(FItems
)-1 to High(FItems
) do
1578 if (FItems
[a
].Control
<> nil) and (FItems
[a
].ControlType
= TGUITextButton
) then
1580 cx
:= (FItems
[a
].Control
as TGUITextButton
).GetWidth
;
1581 if cx
> w
then w
:= cx
;
1586 for a
:= High(FItems
)-1 to High(FItems
) do
1588 if (FItems
[a
].Control
<> nil) and (FItems
[a
].ControlType
= TGUITextButton
) then
1590 FItems
[a
].Control
.FX
:= (gScreenWidth
-w
) div 2;
1597 function TGUIMenu
.AddScroll(fText
: string): TGUIScroll
;
1604 Control
:= TGUIScroll
.Create();
1606 Text := TGUILabel
.Create(fText
, FBigFont
);
1609 FColor
:= MENU_ITEMSTEXT_COLOR
;
1612 ControlType
:= TGUIScroll
;
1614 Result
:= (Control
as TGUIScroll
);
1617 if FIndex
= -1 then FIndex
:= i
;
1622 function TGUIMenu
.AddSwitch(fText
: string): TGUISwitch
;
1629 Control
:= TGUISwitch
.Create(FBigFont
);
1630 (Control
as TGUISwitch
).FColor
:= MENU_ITEMSCTRL_COLOR
;
1632 Text := TGUILabel
.Create(fText
, FBigFont
);
1635 FColor
:= MENU_ITEMSTEXT_COLOR
;
1638 ControlType
:= TGUISwitch
;
1640 Result
:= (Control
as TGUISwitch
);
1643 if FIndex
= -1 then FIndex
:= i
;
1648 function TGUIMenu
.AddEdit(fText
: string): TGUIEdit
;
1655 Control
:= TGUIEdit
.Create(FBigFont
);
1656 with Control
as TGUIEdit
do
1658 FWindow
:= Self
.FWindow
;
1659 FColor
:= MENU_ITEMSCTRL_COLOR
;
1662 if fText
= '' then Text := nil else
1664 Text := TGUILabel
.Create(fText
, FBigFont
);
1665 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
1668 ControlType
:= TGUIEdit
;
1670 Result
:= (Control
as TGUIEdit
);
1673 if FIndex
= -1 then FIndex
:= i
;
1678 procedure TGUIMenu
.Update
;
1684 if FCounter
= 0 then FCounter
:= MENU_MARKERDELAY
else Dec(FCounter
);
1686 if FItems
<> nil then
1687 for a
:= 0 to High(FItems
) do
1688 if FItems
[a
].Control
<> nil then
1689 (FItems
[a
].Control
as FItems
[a
].ControlType
).Update
;
1692 function TGUIMenu
.AddKeyRead(fText
: string): TGUIKeyRead
;
1699 Control
:= TGUIKeyRead
.Create(FBigFont
);
1700 with Control
as TGUIKeyRead
do
1702 FWindow
:= Self
.FWindow
;
1703 FColor
:= MENU_ITEMSCTRL_COLOR
;
1706 Text := TGUILabel
.Create(fText
, FBigFont
);
1709 FColor
:= MENU_ITEMSTEXT_COLOR
;
1712 ControlType
:= TGUIKeyRead
;
1714 Result
:= (Control
as TGUIKeyRead
);
1717 if FIndex
= -1 then FIndex
:= i
;
1722 function TGUIMenu
.AddKeyRead2(fText
: string): TGUIKeyRead2
;
1729 Control
:= TGUIKeyRead2
.Create(FBigFont
);
1730 with Control
as TGUIKeyRead2
do
1732 FWindow
:= Self
.FWindow
;
1733 FColor
:= MENU_ITEMSCTRL_COLOR
;
1736 Text := TGUILabel
.Create(fText
, FBigFont
);
1739 FColor
:= MENU_ITEMSCTRL_COLOR
; //MENU_ITEMSTEXT_COLOR;
1743 ControlType
:= TGUIKeyRead2
;
1745 Result
:= (Control
as TGUIKeyRead2
);
1748 if FIndex
= -1 then FIndex
:= i
;
1753 function TGUIMenu
.AddList(fText
: string; Width
, Height
: Word): TGUIListBox
;
1760 Control
:= TGUIListBox
.Create(FBigFont
, Width
, Height
);
1761 with Control
as TGUIListBox
do
1763 FWindow
:= Self
.FWindow
;
1764 FActiveColor
:= MENU_ITEMSCTRL_COLOR
;
1765 FUnActiveColor
:= MENU_ITEMSTEXT_COLOR
;
1768 Text := TGUILabel
.Create(fText
, FBigFont
);
1771 FColor
:= MENU_ITEMSTEXT_COLOR
;
1774 ControlType
:= TGUIListBox
;
1776 Result
:= (Control
as TGUIListBox
);
1779 if FIndex
= -1 then FIndex
:= i
;
1784 function TGUIMenu
.AddFileList(fText
: string; Width
, Height
: Word): TGUIFileListBox
;
1791 Control
:= TGUIFileListBox
.Create(FBigFont
, Width
, Height
);
1792 with Control
as TGUIFileListBox
do
1794 FWindow
:= Self
.FWindow
;
1795 FActiveColor
:= MENU_ITEMSCTRL_COLOR
;
1796 FUnActiveColor
:= MENU_ITEMSTEXT_COLOR
;
1799 if fText
= '' then Text := nil else
1801 Text := TGUILabel
.Create(fText
, FBigFont
);
1802 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
1805 ControlType
:= TGUIFileListBox
;
1807 Result
:= (Control
as TGUIFileListBox
);
1810 if FIndex
= -1 then FIndex
:= i
;
1815 function TGUIMenu
.AddLabel(fText
: string): TGUILabel
;
1822 Control
:= TGUILabel
.Create('', FBigFont
);
1823 with Control
as TGUILabel
do
1825 FWindow
:= Self
.FWindow
;
1826 FColor
:= MENU_ITEMSCTRL_COLOR
;
1829 Text := TGUILabel
.Create(fText
, FBigFont
);
1832 FColor
:= MENU_ITEMSTEXT_COLOR
;
1835 ControlType
:= TGUILabel
;
1837 Result
:= (Control
as TGUILabel
);
1840 if FIndex
= -1 then FIndex
:= i
;
1845 function TGUIMenu
.AddMemo(fText
: string; Width
, Height
: Word): TGUIMemo
;
1852 Control
:= TGUIMemo
.Create(FBigFont
, Width
, Height
);
1853 with Control
as TGUIMemo
do
1855 FWindow
:= Self
.FWindow
;
1856 FColor
:= MENU_ITEMSTEXT_COLOR
;
1859 if fText
= '' then Text := nil else
1861 Text := TGUILabel
.Create(fText
, FBigFont
);
1862 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
1865 ControlType
:= TGUIMemo
;
1867 Result
:= (Control
as TGUIMemo
);
1870 if FIndex
= -1 then FIndex
:= i
;
1875 procedure TGUIMenu
.UpdateIndex();
1883 if (FIndex
< 0) or (FIndex
> High(FItems
)) then
1889 if FItems
[FIndex
].Control
.Enabled
then
1898 constructor TGUIScroll
.Create
;
1903 FOnChangeEvent
:= nil;
1906 procedure TGUIScroll
.FSetValue(a
: Integer);
1908 if a
> FMax
then FValue
:= FMax
else FValue
:= a
;
1911 procedure TGUIScroll
.OnMessage(var Msg
: TMessage
);
1913 if not FEnabled
then Exit
;
1921 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
1925 g_Sound_PlayEx(SCROLL_SUBSOUND
);
1926 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
1928 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
1929 if FValue
< FMax
then
1932 g_Sound_PlayEx(SCROLL_ADDSOUND
);
1933 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
1940 procedure TGUIScroll
.Update
;
1948 procedure TGUISwitch
.AddItem(Item
: string);
1950 SetLength(FItems
, Length(FItems
)+1);
1951 FItems
[High(FItems
)] := Item
;
1953 if FIndex
= -1 then FIndex
:= 0;
1956 constructor TGUISwitch
.Create(BigFont
: Boolean);
1962 FBigFont
:= BigFont
;
1965 function TGUISwitch
.GetText
: string;
1967 if FIndex
<> -1 then Result
:= FItems
[FIndex
]
1971 procedure TGUISwitch
.OnMessage(var Msg
: TMessage
);
1973 if not FEnabled
then Exit
;
1977 if FItems
= nil then Exit
;
1982 IK_RETURN
, IK_RIGHT
, IK_KPRETURN
, IK_KPRIGHT
, VK_FIRE
, VK_OPEN
, VK_RIGHT
,
1983 JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
,
1984 JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
1986 if FIndex
< High(FItems
) then
1991 g_Sound_PlayEx(SCROLL_ADDSOUND
);
1993 if @FOnChangeEvent
<> nil then
1994 FOnChangeEvent(Self
);
1997 IK_LEFT
, IK_KPLEFT
, VK_LEFT
,
1998 JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
2003 FIndex
:= High(FItems
);
2005 g_Sound_PlayEx(SCROLL_SUBSOUND
);
2007 if @FOnChangeEvent
<> nil then
2008 FOnChangeEvent(Self
);
2014 procedure TGUISwitch
.Update
;
2022 constructor TGUIEdit
.Create(BigFont
: Boolean);
2026 FBigFont
:= BigFont
;
2032 procedure TGUIEdit
.OnMessage(var Msg
: TMessage
);
2034 if not FEnabled
then Exit
;
2043 if (wParam
in [48..57]) and (Chr(wParam
) <> '`') then
2044 if Length(Text) < FMaxLength
then
2046 Insert(Chr(wParam
), FText
, FCaretPos
+ 1);
2052 if (wParam
in [32..255]) and (Chr(wParam
) <> '`') then
2053 if Length(Text) < FMaxLength
then
2055 Insert(Chr(wParam
), FText
, FCaretPos
+ 1);
2063 Delete(FText
, FCaretPos
, 1);
2064 if FCaretPos
> 0 then Dec(FCaretPos
);
2066 IK_DELETE
: Delete(FText
, FCaretPos
+ 1, 1);
2067 IK_END
, IK_KPEND
: FCaretPos
:= Length(FText
);
2068 IK_HOME
, IK_KPHOME
: FCaretPos
:= 0;
2069 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
: if FCaretPos
> 0 then Dec(FCaretPos
);
2070 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
: if FCaretPos
< Length(FText
) then Inc(FCaretPos
);
2071 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2074 if FActiveControl
<> Self
then
2077 if @FOnEnterEvent
<> nil then FOnEnterEvent(Self
);
2081 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
2082 else SetActive(nil);
2083 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2089 g_GUIGrabInput
:= (@FOnEnterEvent
= nil) and (FWindow
.FActiveControl
= Self
);
2091 {$IFDEF ENABLE_TOUCH}
2092 sys_ShowKeyboard(g_GUIGrabInput
)
2096 procedure TGUIEdit
.SetText(Text: string);
2098 if Length(Text) > FMaxLength
then SetLength(Text, FMaxLength
);
2100 FCaretPos
:= Length(FText
);
2103 procedure TGUIEdit
.Update
;
2110 constructor TGUIKeyRead
.Create(BigFont
: Boolean);
2115 FBigFont
:= BigFont
;
2118 function TGUIKeyRead
.WantActivationKey (key
: LongInt): Boolean;
2121 (key
= IK_BACKSPACE
) or
2125 procedure TGUIKeyRead
.OnMessage(var Msg
: TMessage
);
2126 procedure actDefCtl ();
2129 if FDefControl
<> '' then
2130 SetActive(GetControl(FDefControl
))
2138 if not FEnabled
then
2147 if FIsQuery
then actDefCtl();
2150 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2152 if not FIsQuery
then
2155 if FActiveControl
<> Self
then
2160 else if (wParam
< VK_FIRSTKEY
) and (wParam
> VK_LASTKEY
) then
2162 // FKey := IK_ENTER; // <Enter>
2168 IK_BACKSPACE
: // clear keybinding if we aren't waiting for a key
2170 if not FIsQuery
then
2180 if not FIsQuery
and (wParam
= IK_BACKSPACE
) then
2185 else if FIsQuery
then
2188 IK_ENTER
, IK_KPRETURN
, VK_FIRSTKEY
..VK_LASTKEY (*, JOY0_ATTACK, JOY1_ATTACK, JOY2_ATTACK, JOY3_ATTACK*): // Not <Enter
2190 if e_KeyNames
[wParam
] <> '' then
2199 g_GUIGrabInput
:= FIsQuery
2204 constructor TGUIKeyRead2
.Create(BigFont
: Boolean);
2205 var a
: Byte; w
, h
: Integer;
2214 FBigFont
:= BigFont
;
2216 FMaxKeyNameWdt
:= 0;
2218 FMaxKeyNameWdt
:= 0;
2220 for a
:= 0 to 255 do
2222 r_GUI_GetStringSize(BigFont
, e_KeyNames
[a
], w
, h
);
2223 FMaxKeyNameWdt
:= Max(FMaxKeyNameWdt
, w
);
2226 FMaxKeyNameWdt
:= FMaxKeyNameWdt
-(FMaxKeyNameWdt
div 3);
2228 r_GUI_GetStringSize(BigFont
, KEYREAD_QUERY
, w
, h
);
2229 if w
> FMaxKeyNameWdt
then FMaxKeyNameWdt
:= w
;
2231 r_GUI_GetStringSize(BigFont
, KEYREAD_CLEAR
, w
, h
);
2232 if w
> FMaxKeyNameWdt
then FMaxKeyNameWdt
:= w
;
2235 function TGUIKeyRead2
.WantActivationKey (key
: LongInt): Boolean;
2238 IK_BACKSPACE
, IK_LEFT
, IK_RIGHT
, IK_KPLEFT
, IK_KPRIGHT
, VK_LEFT
, VK_RIGHT
,
2239 JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
,
2240 JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
2247 procedure TGUIKeyRead2
.OnMessage(var Msg
: TMessage
);
2248 procedure actDefCtl ();
2251 if FDefControl
<> '' then
2252 SetActive(GetControl(FDefControl
))
2260 if not FEnabled
then
2269 if FIsQuery
then actDefCtl();
2272 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2274 if not FIsQuery
then
2277 if FActiveControl
<> Self
then
2282 else if (wParam
< VK_FIRSTKEY
) and (wParam
> VK_LASTKEY
) then
2284 // if (FKeyIdx = 0) then FKey0 := IK_ENTER else FKey1 := IK_ENTER; // <Enter>
2285 if (FKeyIdx
= 0) then FKey0
:= wParam
else FKey1
:= wParam
;
2290 IK_BACKSPACE
: // clear keybinding if we aren't waiting for a key
2292 if not FIsQuery
then
2294 if (FKeyIdx
= 0) then FKey0
:= 0 else FKey1
:= 0;
2298 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
2299 if not FIsQuery
then
2304 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
2305 if not FIsQuery
then
2314 if not FIsQuery
and (wParam
= IK_BACKSPACE
) then
2316 if (FKeyIdx
= 0) then FKey0
:= 0 else FKey1
:= 0;
2319 else if FIsQuery
then
2322 IK_ENTER
, IK_KPRETURN
, VK_FIRSTKEY
..VK_LASTKEY (*, JOY0_ATTACK, JOY1_ATTACK, JOY2_ATTACK, JOY3_ATTACK*): // Not <Enter
2324 if e_KeyNames
[wParam
] <> '' then
2326 if (FKeyIdx
= 0) then FKey0
:= wParam
else FKey1
:= wParam
;
2335 g_GUIGrabInput
:= FIsQuery
2341 constructor TGUIModelView
.Create
;
2348 destructor TGUIModelView
.Destroy
;
2355 procedure TGUIModelView
.NextAnim();
2357 if FModel
= nil then
2360 if FModel
.Animation
< A_PAIN
then
2361 FModel
.ChangeAnimation(FModel
.Animation
+1, True)
2363 FModel
.ChangeAnimation(A_STAND
, True);
2366 procedure TGUIModelView
.NextWeapon();
2368 if FModel
= nil then
2371 if FModel
.Weapon
< WP_LAST
then
2372 FModel
.SetWeapon(FModel
.Weapon
+1)
2374 FModel
.SetWeapon(WEAPON_KASTET
);
2377 procedure TGUIModelView
.OnMessage(var Msg
: TMessage
);
2383 procedure TGUIModelView
.SetColor(Red
, Green
, Blue
: Byte);
2385 if FModel
<> nil then FModel
.SetColor(Red
, Green
, Blue
);
2388 procedure TGUIModelView
.SetModel(ModelName
: string);
2392 FModel
:= g_PlayerModel_Get(ModelName
);
2395 procedure TGUIModelView
.Update
;
2402 if FModel
<> nil then FModel
.Update
;
2407 constructor TGUIMapPreview
.Create();
2413 destructor TGUIMapPreview
.Destroy();
2419 procedure TGUIMapPreview
.OnMessage(var Msg
: TMessage
);
2425 procedure TGUIMapPreview
.SetMap(Res
: string);
2430 //header: TMapHeaderRec_1;
2435 map
: TDynRecord
= nil;
2442 FileName
:= g_ExtractWadName(Res
);
2444 WAD
:= TWADFile
.Create();
2445 if not WAD
.ReadFile(FileName
) then
2451 //k8: ignores path again
2452 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
2461 map
:= g_Map_ParseMap(Data
, Len
);
2471 if (map
= nil) then exit
;
2474 panlist
:= map
.field
['panel'];
2475 //header := GetMapHeader(map);
2477 FMapSize
.X
:= map
.Width
div 16;
2478 FMapSize
.Y
:= map
.Height
div 16;
2480 rX
:= Ceil(map
.Width
/ (MAPPREVIEW_WIDTH
*256.0));
2481 rY
:= Ceil(map
.Height
/ (MAPPREVIEW_HEIGHT
*256.0));
2482 FScale
:= max(rX
, rY
);
2486 if (panlist
<> nil) then
2488 for pan
in panlist
do
2490 if (pan
.PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or
2491 PANEL_STEP
or PANEL_WATER
or
2492 PANEL_ACID1
or PANEL_ACID2
)) <> 0 then
2494 SetLength(FMapData
, Length(FMapData
)+1);
2495 with FMapData
[High(FMapData
)] do
2500 X2
:= (pan
.X
+ pan
.Width
) div 16;
2501 Y2
:= (pan
.Y
+ pan
.Height
) div 16;
2503 X1
:= Trunc(X1
/FScale
+ 0.5);
2504 Y1
:= Trunc(Y1
/FScale
+ 0.5);
2505 X2
:= Trunc(X2
/FScale
+ 0.5);
2506 Y2
:= Trunc(Y2
/FScale
+ 0.5);
2508 if (X1
<> X2
) or (Y1
<> Y2
) then
2516 PanelType
:= pan
.PanelType
;
2522 //writeln('freeing map');
2527 procedure TGUIMapPreview
.ClearMap();
2529 SetLength(FMapData
, 0);
2536 procedure TGUIMapPreview
.Update();
2542 function TGUIMapPreview
.GetScaleStr(): String;
2544 if FScale
> 0.0 then
2546 Result
:= FloatToStrF(FScale
*16.0, ffFixed
, 3, 3);
2547 while (Result
[Length(Result
)] = '0') do
2548 Delete(Result
, Length(Result
), 1);
2549 if (Result
[Length(Result
)] = ',') or (Result
[Length(Result
)] = '.') then
2550 Delete(Result
, Length(Result
), 1);
2551 Result
:= '1 : ' + Result
;
2559 procedure TGUIListBox
.AddItem(Item
: string);
2561 SetLength(FItems
, Length(FItems
)+1);
2562 FItems
[High(FItems
)] := Item
;
2564 if FSort
then g_gui
.Sort(FItems
);
2567 function TGUIListBox
.ItemExists (item
: String): Boolean;
2571 while (i
<= High(FItems
)) and (FItems
[i
] <> item
) do Inc(i
);
2572 result
:= i
<= High(FItems
)
2575 procedure TGUIListBox
.Clear
;
2583 constructor TGUIListBox
.Create(BigFont
: Boolean; Width
, Height
: Word);
2587 FBigFont
:= BigFont
;
2591 FOnChangeEvent
:= nil;
2593 FDrawScroll
:= True;
2596 procedure TGUIListBox
.OnMessage(var Msg
: TMessage
);
2600 if not FEnabled
then Exit
;
2604 if FItems
= nil then Exit
;
2617 FIndex
:= High(FItems
);
2618 FStartLine
:= Max(High(FItems
)-FHeight
+1, 0);
2620 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
2624 if FIndex
< FStartLine
then Dec(FStartLine
);
2625 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2627 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
2628 if FIndex
< High(FItems
) then
2631 if FIndex
> FStartLine
+FHeight
-1 then Inc(FStartLine
);
2632 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2634 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2637 if FActiveControl
<> Self
then SetActive(Self
)
2639 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
2640 else SetActive(nil);
2644 for a
:= 0 to High(FItems
) do
2645 if (Length(FItems
[a
]) > 0) and (LowerCase(FItems
[a
][1]) = LowerCase(Chr(wParam
))) then
2648 FStartLine
:= Min(Max(FIndex
-1, 0), Length(FItems
)-FHeight
);
2649 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2655 function TGUIListBox
.SelectedItem(): String;
2659 if (FIndex
< 0) or (FItems
= nil) or
2660 (FIndex
> High(FItems
)) then
2663 Result
:= FItems
[FIndex
];
2666 procedure TGUIListBox
.FSetItems(Items
: SSArray
);
2668 if FItems
<> nil then
2676 if FSort
then g_gui
.Sort(FItems
);
2679 procedure TGUIListBox
.SelectItem(Item
: String);
2683 if FItems
= nil then
2687 Item
:= LowerCase(Item
);
2689 for a
:= 0 to High(FItems
) do
2690 if LowerCase(FItems
[a
]) = Item
then
2696 if FIndex
< FHeight
then
2699 FStartLine
:= Min(FIndex
, Length(FItems
)-FHeight
);
2702 procedure TGUIListBox
.FSetIndex(aIndex
: Integer);
2704 if FItems
= nil then
2707 if (aIndex
< 0) or (aIndex
> High(FItems
)) then
2712 if FIndex
<= FHeight
then
2715 FStartLine
:= Min(FIndex
, Length(FItems
)-FHeight
);
2720 procedure TGUIFileListBox
.OnMessage(var Msg
: TMessage
);
2722 a
, b
: Integer; s
: AnsiString;
2724 if not FEnabled
then
2727 if FItems
= nil then
2738 if @FOnChangeEvent
<> nil then
2739 FOnChangeEvent(Self
);
2744 FIndex
:= High(FItems
);
2745 FStartLine
:= Max(High(FItems
)-FHeight
+1, 0);
2746 if @FOnChangeEvent
<> nil then
2747 FOnChangeEvent(Self
);
2750 IK_PAGEUP
, IK_KPPAGEUP
:
2752 if FIndex
> FHeight
then
2753 FIndex
:= FIndex
-FHeight
2757 if FStartLine
> FHeight
then
2758 FStartLine
:= FStartLine
-FHeight
2763 IK_PAGEDN
, IK_KPPAGEDN
:
2765 if FIndex
< High(FItems
)-FHeight
then
2766 FIndex
:= FIndex
+FHeight
2768 FIndex
:= High(FItems
);
2770 if FStartLine
< High(FItems
)-FHeight
then
2771 FStartLine
:= FStartLine
+FHeight
2773 FStartLine
:= High(FItems
)-FHeight
+1;
2776 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
, VK_UP
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
2780 if FIndex
< FStartLine
then
2782 if @FOnChangeEvent
<> nil then
2783 FOnChangeEvent(Self
);
2786 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
, VK_DOWN
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
2787 if FIndex
< High(FItems
) then
2790 if FIndex
> FStartLine
+FHeight
-1 then
2792 if @FOnChangeEvent
<> nil then
2793 FOnChangeEvent(Self
);
2796 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2799 if FActiveControl
<> Self
then
2803 if FItems
[FIndex
][1] = #29 then // Ïàïêà
2805 if FItems
[FIndex
] = #29 + '..' then
2807 e_LogWritefln('TGUIFileListBox: Upper dir "%s" -> "%s"', [FSubPath
, e_UpperDir(FSubPath
)]);
2808 FSubPath
:= e_UpperDir(FSubPath
)
2812 s
:= Copy(AnsiString(FItems
[FIndex
]), 2);
2813 e_LogWritefln('TGUIFileListBox: Enter dir "%s" -> "%s"', [FSubPath
, e_CatPath(FSubPath
, s
)]);
2814 FSubPath
:= e_CatPath(FSubPath
, s
);
2821 if FDefControl
<> '' then
2822 SetActive(GetControl(FDefControl
))
2830 for b
:= FIndex
+ 1 to High(FItems
) + FIndex
do
2832 a
:= b
mod Length(FItems
);
2833 if ( (Length(FItems
[a
]) > 0) and
2834 (LowerCase(FItems
[a
][1]) = LowerCase(Chr(wParam
))) ) or
2835 ( (Length(FItems
[a
]) > 1) and
2836 (FItems
[a
][1] = #29) and // Ïàïêà
2837 (LowerCase(FItems
[a
][2]) = LowerCase(Chr(wParam
))) ) then
2840 FStartLine
:= Min(Max(FIndex
-1, 0), Length(FItems
)-FHeight
);
2841 if @FOnChangeEvent
<> nil then
2842 FOnChangeEvent(Self
);
2849 procedure TGUIFileListBox
.ScanDirs
;
2850 var i
, j
: Integer; path
: AnsiString; SR
: TSearchRec
; sm
, sc
: String;
2854 i
:= High(FBaseList
);
2857 path
:= e_CatPath(FBaseList
[i
], FSubPath
);
2860 if FindFirst(path
+ '/' + '*', faDirectory
, SR
) = 0 then
2863 if LongBool(SR
.Attr
and faDirectory
) then
2864 if (SR
.Name
<> '.') and ((FSubPath
<> '') or (SR
.Name
<> '..')) then
2865 if Self
.ItemExists(#1 + SR
.Name
) = false then
2866 Self
.AddItem(#1 + SR
.Name
)
2867 until FindNext(SR
) <> 0
2874 i
:= High(FBaseList
);
2877 path
:= e_CatPath(FBaseList
[i
], FSubPath
);
2883 j
:= length(sm
) + 1;
2884 sc
:= Copy(sm
, 1, j
- 1);
2886 if FindFirst(path
+ '/' + sc
, faAnyFile
, SR
) = 0 then
2889 if Self
.ItemExists(SR
.Name
) = false then
2891 until FindNext(SR
) <> 0
2898 for i
:= 0 to High(FItems
) do
2899 if FItems
[i
][1] = #1 then
2900 FItems
[i
][1] := #29;
2903 procedure TGUIFileListBox
.SetBase (dirs
: SSArray
; path
: String = '');
2910 function TGUIFileListBox
.SelectedItem (): String;
2914 if (FIndex
>= 0) and (FIndex
<= High(FItems
)) and (FItems
[FIndex
][1] <> '/') and (FItems
[FIndex
][1] <> '\') then
2916 s
:= e_CatPath(FSubPath
, FItems
[FIndex
]);
2917 if e_FindResource(FBaseList
, s
) = true then
2918 result
:= ExpandFileName(s
)
2920 e_LogWritefln('TGUIFileListBox.SelectedItem -> "%s"', [result
]);
2923 procedure TGUIFileListBox
.UpdateFileList();
2927 if (FIndex
= -1) or (FItems
= nil) or
2928 (FIndex
> High(FItems
)) or
2929 (FItems
[FIndex
][1] = '/') or
2930 (FItems
[FIndex
][1] = '\') then
2933 fn
:= FItems
[FIndex
];
2944 procedure TGUIMemo
.Clear
;
2950 constructor TGUIMemo
.Create(BigFont
: Boolean; Width
, Height
: Word);
2954 FBigFont
:= BigFont
;
2958 FDrawScroll
:= True;
2961 procedure TGUIMemo
.OnMessage(var Msg
: TMessage
);
2963 if not FEnabled
then Exit
;
2967 if FLines
= nil then Exit
;
2973 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
, VK_UP
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
2974 if FStartLine
> 0 then
2976 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
, VK_DOWN
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
2977 if FStartLine
< Length(FLines
)-FHeight
then
2979 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2982 if FActiveControl
<> Self
then
2988 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
2989 else SetActive(nil);
2995 procedure TGUIMemo
.SetText(Text: string);
2998 FLines
:= GetLines(Text, FBigFont
, FWidth
* 16);
3003 procedure TGUIimage
.ClearImage();
3008 constructor TGUIimage
.Create();
3015 destructor TGUIimage
.Destroy();
3020 procedure TGUIimage
.OnMessage(var Msg
: TMessage
);
3025 procedure TGUIimage
.SetImage(Res
: string);
3030 procedure TGUIimage
.Update();