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}
542 r_textures
, (* load/free image *)
544 g_sound
, SysUtils
, e_res
,
545 g_game
, Math
, StrUtils
, g_player
, g_options
,
546 g_map
, g_weapons
, xdynrec
, wadreader
;
550 Saved_Windows
: SSArray
;
552 function GetLines (Text: string; BigFont
: Boolean; MaxWidth
: Word): SSArray
;
553 var i
, j
, len
, lines
: Integer;
555 function GetLine (j
, i
: Integer): String;
557 result
:= Copy(text, j
, i
- j
+ 1);
560 function GetWidth (j
, i
: Integer): Integer;
563 r_GUI_GetStringSize(BigFont
, GetLine(j
, i
), w
, h
);
568 result
:= nil; lines
:= 0;
569 j
:= 1; i
:= 1; len
:= Length(Text);
570 // e_LogWritefln('GetLines @%s len=%s [%s]', [MaxWidth, len, Text]);
573 (* --- Get longest possible sequence --- *)
574 while (i
+ 1 <= len
) and (GetWidth(j
, i
+ 1) <= MaxWidth
) do Inc(i
);
575 (* --- Do not include part of word --- *)
576 if (i
< len
) and (text[i
] <> ' ') then
577 while (i
>= j
) and (text[i
] <> ' ') do Dec(i
);
578 (* --- Do not include spaces --- *)
579 while (i
>= j
) and (text[i
] = ' ') do Dec(i
);
580 (* --- Add line --- *)
581 SetLength(result
, lines
+ 1);
582 result
[lines
] := GetLine(j
, i
);
583 // e_LogWritefln(' -> (%s:%s::%s) [%s]', [j, i, GetWidth(j, i), result[lines]]);
585 (* --- Skip spaces --- *)
586 while (i
<= len
) and (text[i
] = ' ') do Inc(i
);
591 procedure Sort (var a
: SSArray
);
592 var i
, j
: Integer; s
: string;
594 if a
= nil then Exit
;
596 for i
:= High(a
) downto Low(a
) do
597 for j
:= Low(a
) to High(a
) - 1 do
598 if LowerCase(a
[j
]) > LowerCase(a
[j
+ 1]) then
606 function g_GUI_Destroy(): Boolean;
610 Result
:= (Length(g_GUIWindows
) > 0);
612 for i
:= 0 to High(g_GUIWindows
) do
613 g_GUIWindows
[i
].Free();
616 g_ActiveWindow
:= nil;
619 function g_GUI_AddWindow(Window
: TGUIWindow
): TGUIWindow
;
621 SetLength(g_GUIWindows
, Length(g_GUIWindows
)+1);
622 g_GUIWindows
[High(g_GUIWindows
)] := Window
;
627 function g_GUI_GetWindow(Name
: string): TGUIWindow
;
633 if g_GUIWindows
<> nil then
634 for i
:= 0 to High(g_GUIWindows
) do
635 if g_GUIWindows
[i
].FName
= Name
then
637 Result
:= g_GUIWindows
[i
];
641 Assert(Result
<> nil, 'GUI_Window "'+Name
+'" not found');
644 procedure g_GUI_ShowWindow(Name
: string);
648 if g_GUIWindows
= nil then
651 for i
:= 0 to High(g_GUIWindows
) do
652 if g_GUIWindows
[i
].FName
= Name
then
654 g_GUIWindows
[i
].FPrevWindow
:= g_ActiveWindow
;
655 g_ActiveWindow
:= g_GUIWindows
[i
];
657 if g_ActiveWindow
.MainWindow
then
658 g_ActiveWindow
.FPrevWindow
:= nil;
660 if g_ActiveWindow
.FDefControl
<> '' then
661 g_ActiveWindow
.SetActive(g_ActiveWindow
.GetControl(g_ActiveWindow
.FDefControl
))
663 g_ActiveWindow
.SetActive(nil);
665 if @g_ActiveWindow
.FOnShowEvent
<> nil then
666 g_ActiveWindow
.FOnShowEvent();
672 procedure g_GUI_HideWindow(PlaySound
: Boolean = True);
674 if g_ActiveWindow
<> nil then
676 if @g_ActiveWindow
.OnClose
<> nil then
677 g_ActiveWindow
.OnClose();
678 g_ActiveWindow
:= g_ActiveWindow
.FPrevWindow
;
680 g_Sound_PlayEx(WINDOW_CLOSESOUND
);
684 procedure g_GUI_SaveMenuPos();
689 SetLength(Saved_Windows
, 0);
690 win
:= g_ActiveWindow
;
694 len
:= Length(Saved_Windows
);
695 SetLength(Saved_Windows
, len
+ 1);
697 Saved_Windows
[len
] := win
.Name
;
699 if win
.MainWindow
then
702 win
:= win
.FPrevWindow
;
706 procedure g_GUI_LoadMenuPos();
708 i
, j
, k
, len
: Integer;
711 g_ActiveWindow
:= nil;
712 len
:= Length(Saved_Windows
);
717 // Îêíî ñ ãëàâíûì ìåíþ:
718 g_GUI_ShowWindow(Saved_Windows
[len
-1]);
720 // Íå ïåðåêëþ÷èëîñü (èëè íåêóäà äàëüøå):
721 if (len
= 1) or (g_ActiveWindow
= nil) then
724 // Èùåì êíîïêè â îñòàëüíûõ îêíàõ:
725 for k
:= len
-1 downto 1 do
729 for i
:= 0 to Length(g_ActiveWindow
.Childs
)-1 do
731 if g_ActiveWindow
.Childs
[i
] is TGUIMainMenu
then
732 begin // GUI_MainMenu
733 with TGUIMainMenu(g_ActiveWindow
.Childs
[i
]) do
734 for j
:= 0 to Length(FButtons
)-1 do
735 if FButtons
[j
].ShowWindow
= Saved_Windows
[k
-1] then
737 FButtons
[j
].Click(True);
743 if g_ActiveWindow
.Childs
[i
] is TGUIMenu
then
744 with TGUIMenu(g_ActiveWindow
.Childs
[i
]) do
745 for j
:= 0 to Length(FItems
)-1 do
746 if FItems
[j
].ControlType
= TGUITextButton
then
747 if TGUITextButton(FItems
[j
].Control
).ShowWindow
= Saved_Windows
[k
-1] then
749 TGUITextButton(FItems
[j
].Control
).Click(True);
760 (g_ActiveWindow
.Name
= Saved_Windows
[k
]) then
767 constructor TGUIWindow
.Create(Name
: string);
770 FActiveControl
:= nil;
774 FOnCloseEvent
:= nil;
778 destructor TGUIWindow
.Destroy
;
785 for i
:= 0 to High(Childs
) do
789 function TGUIWindow
.AddChild(Child
: TGUIControl
): TGUIControl
;
791 Child
.FWindow
:= Self
;
793 SetLength(Childs
, Length(Childs
) + 1);
794 Childs
[High(Childs
)] := Child
;
799 procedure TGUIWindow
.Update
;
803 for i
:= 0 to High(Childs
) do
804 if Childs
[i
] <> nil then Childs
[i
].Update
;
807 procedure TGUIWindow
.OnMessage(var Msg
: TMessage
);
809 if FActiveControl
<> nil then FActiveControl
.OnMessage(Msg
);
810 if @FOnKeyDown
<> nil then FOnKeyDown(Msg
.wParam
);
811 if @FOnKeyDownEx
<> nil then FOnKeyDownEx(self
, Msg
.wParam
);
813 if Msg
.Msg
= WM_KEYDOWN
then
825 procedure TGUIWindow
.SetActive(Control
: TGUIControl
);
827 FActiveControl
:= Control
;
830 function TGUIWindow
.GetControl(Name
: String): TGUIControl
;
836 if Childs
<> nil then
837 for i
:= 0 to High(Childs
) do
838 if Childs
[i
] <> nil then
839 if LowerCase(Childs
[i
].FName
) = LowerCase(Name
) then
845 Assert(Result
<> nil, 'Window Control "'+Name
+'" not Found!');
850 constructor TGUIControl
.Create();
856 FRightAlign
:= false;
860 procedure TGUIControl
.OnMessage(var Msg
: TMessage
);
866 procedure TGUIControl
.Update();
870 function TGUIControl
.WantActivationKey (key
: LongInt): Boolean;
875 function TGUIControl
.GetWidth (): Integer;
876 {$IFDEF ENABLE_RENDER}
880 {$IFDEF ENABLE_RENDER}
881 r_GUI_GetSize(Self
, Result
, h
);
887 function TGUIControl
.GetHeight (): Integer;
888 {$IFDEF ENABLE_RENDER}
892 {$IFDEF ENABLE_RENDER}
893 r_GUI_GetSize(Self
, w
, Result
);
901 procedure TGUITextButton
.Click(Silent
: Boolean = False);
903 if (FSound
<> '') and (not Silent
) then g_Sound_PlayEx(FSound
);
905 if @Proc
<> nil then Proc();
906 if @ProcEx
<> nil then ProcEx(self
);
908 if FShowWindow
<> '' then g_GUI_ShowWindow(FShowWindow
);
911 constructor TGUITextButton
.Create(aProc
: Pointer; BigFont
: Boolean; Text: string);
922 destructor TGUITextButton
.Destroy
;
928 procedure TGUITextButton
.OnMessage(var Msg
: TMessage
);
930 if not FEnabled
then Exit
;
937 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
: Click();
942 procedure TGUITextButton
.Update
;
949 function TGUIMainMenu
.AddButton(fProc
: Pointer; Caption
: string; ShowWindow
: string = ''): TGUITextButton
;
958 SetLength(FButtons
, Length(FButtons
)+1);
959 FButtons
[High(FButtons
)] := TGUITextButton
.Create(fProc
, FBigFont
, Caption
);
960 FButtons
[High(FButtons
)].ShowWindow
:= ShowWindow
;
961 with FButtons
[High(FButtons
)] do
963 if (fProc
<> nil) or (ShowWindow
<> '') then FColor
:= MAINMENU_ITEMS_COLOR
964 else FColor
:= MAINMENU_UNACTIVEITEMS_COLOR
;
965 FSound
:= MAINMENU_CLICKSOUND
;
968 _x
:= gScreenWidth
div 2;
970 for a
:= 0 to High(FButtons
) do
971 if FButtons
[a
] <> nil then
972 _x
:= Min(_x
, (gScreenWidth
div 2)-(FButtons
[a
].GetWidth
div 2));
974 if FHeader
= nil then
975 r_GUI_GetLogoSize(lw
, lh
);
976 hh
:= FButtons
[High(FButtons
)].GetHeight
;
978 if FHeader
= nil then h
:= lh
+ hh
* (1 + Length(FButtons
)) + MAINMENU_SPACE
* (Length(FButtons
) - 1)
979 else h
:= hh
* (2 + Length(FButtons
)) + MAINMENU_SPACE
* (Length(FButtons
) - 1);
980 h
:= (gScreenHeight
div 2) - (h
div 2);
982 if FHeader
<> nil then with FHeader
do
988 if FHeader
= nil then Inc(h
, lh
)
991 for a
:= 0 to High(FButtons
) do
993 if FButtons
[a
] <> nil then
1000 Inc(h
, hh
+MAINMENU_SPACE
);
1003 Result
:= FButtons
[High(FButtons
)];
1006 procedure TGUIMainMenu
.AddSpace
;
1008 SetLength(FButtons
, Length(FButtons
)+1);
1009 FButtons
[High(FButtons
)] := nil;
1012 constructor TGUIMainMenu
.Create(BigFont
: Boolean; Header
: string);
1017 FBigFont
:= BigFont
;
1018 FCounter
:= MAINMENU_MARKERDELAY
;
1020 if Header
<> '' then
1022 FHeader
:= TGUILabel
.Create(Header
, BigFont
);
1025 FColor
:= MAINMENU_HEADER_COLOR
;
1026 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1027 FY
:= (gScreenHeight
div 2)-(GetHeight
div 2);
1032 destructor TGUIMainMenu
.Destroy
;
1036 if FButtons
<> nil then
1037 for a
:= 0 to High(FButtons
) do
1045 procedure TGUIMainMenu
.EnableButton(aName
: string; e
: Boolean);
1049 if FButtons
= nil then Exit
;
1051 for a
:= 0 to High(FButtons
) do
1052 if (FButtons
[a
] <> nil) and (FButtons
[a
].Name
= aName
) then
1054 if e
then FButtons
[a
].FColor
:= MAINMENU_ITEMS_COLOR
1055 else FButtons
[a
].FColor
:= MAINMENU_UNACTIVEITEMS_COLOR
;
1056 FButtons
[a
].Enabled
:= e
;
1061 function TGUIMainMenu
.GetButton(aName
: string): TGUITextButton
;
1067 if FButtons
= nil then Exit
;
1069 for a
:= 0 to High(FButtons
) do
1070 if (FButtons
[a
] <> nil) and (FButtons
[a
].Name
= aName
) then
1072 Result
:= FButtons
[a
];
1077 procedure TGUIMainMenu
.OnMessage(var Msg
: TMessage
);
1082 if not FEnabled
then Exit
;
1086 if FButtons
= nil then Exit
;
1089 for a
:= 0 to High(FButtons
) do
1090 if FButtons
[a
] <> nil then
1096 if not ok
then Exit
;
1101 IK_UP
, IK_KPUP
, VK_UP
, JOY0_UP
, JOY1_UP
, JOY2_UP
, JOY3_UP
:
1105 if FIndex
< 0 then FIndex
:= High(FButtons
);
1106 until FButtons
[FIndex
] <> nil;
1108 g_Sound_PlayEx(MENU_CHANGESOUND
);
1110 IK_DOWN
, IK_KPDOWN
, VK_DOWN
, JOY0_DOWN
, JOY1_DOWN
, JOY2_DOWN
, JOY3_DOWN
:
1114 if FIndex
> High(FButtons
) then FIndex
:= 0;
1115 until FButtons
[FIndex
] <> nil;
1117 g_Sound_PlayEx(MENU_CHANGESOUND
);
1119 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
;
1124 procedure TGUIMainMenu
.Update
;
1127 FCounter
:= (FCounter
+ 1) MOD (2 * MAINMENU_MARKERDELAY
)
1132 constructor TGUILabel
.Create(Text: string; BigFont
: Boolean);
1136 FBigFont
:= BigFont
;
1139 FOnClickEvent
:= nil;
1142 procedure TGUILabel
.OnMessage(var Msg
: TMessage
);
1144 if not FEnabled
then Exit
;
1151 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
: if @FOnClickEvent
<> nil then FOnClickEvent();
1158 function TGUIMenu
.AddButton(Proc
: Pointer; fText
: string; _ShowWindow
: string = ''): TGUITextButton
;
1165 Control
:= TGUITextButton
.Create(Proc
, FBigFont
, fText
);
1166 with Control
as TGUITextButton
do
1168 ShowWindow
:= _ShowWindow
;
1169 FColor
:= MENU_ITEMSCTRL_COLOR
;
1173 ControlType
:= TGUITextButton
;
1175 Result
:= (Control
as TGUITextButton
);
1178 if FIndex
= -1 then FIndex
:= i
;
1183 procedure TGUIMenu
.AddLine(fText
: string);
1190 Text := TGUILabel
.Create(fText
, FBigFont
);
1193 FColor
:= MENU_ITEMSTEXT_COLOR
;
1202 procedure TGUIMenu
.AddText(fText
: string; MaxWidth
: Word);
1207 l
:= GetLines(fText
, FBigFont
, MaxWidth
);
1209 if l
= nil then Exit
;
1211 for a
:= 0 to High(l
) do
1216 Text := TGUILabel
.Create(l
[a
], FBigFont
);
1219 with Text do begin FColor
:= _RGB(255, 0, 0); end;
1223 with Text do begin FColor
:= MENU_ITEMSTEXT_COLOR
; end;
1233 procedure TGUIMenu
.AddSpace
;
1247 constructor TGUIMenu
.Create(HeaderBigFont
, ItemsBigFont
: Boolean; Header
: string);
1253 FBigFont
:= ItemsBigFont
;
1254 FCounter
:= MENU_MARKERDELAY
;
1258 FHeader
:= TGUILabel
.Create(Header
, HeaderBigFont
);
1261 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1263 FColor
:= MAINMENU_HEADER_COLOR
;
1267 destructor TGUIMenu
.Destroy
;
1271 if FItems
<> nil then
1272 for a
:= 0 to High(FItems
) do
1286 function TGUIMenu
.GetControl(aName
: String): TGUIControl
;
1292 if FItems
<> nil then
1293 for a
:= 0 to High(FItems
) do
1294 if FItems
[a
].Control
<> nil then
1295 if LowerCase(FItems
[a
].Control
.Name
) = LowerCase(aName
) then
1297 Result
:= FItems
[a
].Control
;
1301 Assert(Result
<> nil, 'GUI control "'+aName
+'" not found!');
1304 function TGUIMenu
.GetControlsText(aName
: String): TGUILabel
;
1310 if FItems
<> nil then
1311 for a
:= 0 to High(FItems
) do
1312 if FItems
[a
].Control
<> nil then
1313 if LowerCase(FItems
[a
].Control
.Name
) = LowerCase(aName
) then
1315 Result
:= FItems
[a
].Text;
1319 Assert(Result
<> nil, 'GUI control''s text "'+aName
+'" not found!');
1322 function TGUIMenu
.NewItem
: Integer;
1324 SetLength(FItems
, Length(FItems
)+1);
1325 Result
:= High(FItems
);
1328 procedure TGUIMenu
.OnMessage(var Msg
: TMessage
);
1333 if not FEnabled
then Exit
;
1337 if FItems
= nil then Exit
;
1340 for a
:= 0 to High(FItems
) do
1341 if FItems
[a
].Control
<> nil then
1347 if not ok
then Exit
;
1349 if (Msg
.Msg
= WM_KEYDOWN
) and (FIndex
<> -1) and (FItems
[FIndex
].Control
<> nil) and
1350 (FItems
[FIndex
].Control
.WantActivationKey(Msg
.wParam
)) then
1352 FItems
[FIndex
].Control
.OnMessage(Msg
);
1353 g_Sound_PlayEx(MENU_CLICKSOUND
);
1361 IK_UP
, IK_KPUP
, VK_UP
,JOY0_UP
, JOY1_UP
, JOY2_UP
, JOY3_UP
:
1366 if c
> Length(FItems
) then
1373 if FIndex
< 0 then FIndex
:= High(FItems
);
1374 until (FItems
[FIndex
].Control
<> nil) and
1375 (FItems
[FIndex
].Control
.Enabled
);
1379 g_Sound_PlayEx(MENU_CHANGESOUND
);
1382 IK_DOWN
, IK_KPDOWN
, VK_DOWN
, JOY0_DOWN
, JOY1_DOWN
, JOY2_DOWN
, JOY3_DOWN
:
1387 if c
> Length(FItems
) then
1394 if FIndex
> High(FItems
) then FIndex
:= 0;
1395 until (FItems
[FIndex
].Control
<> nil) and
1396 (FItems
[FIndex
].Control
.Enabled
);
1400 g_Sound_PlayEx(MENU_CHANGESOUND
);
1403 IK_LEFT
, IK_RIGHT
, IK_KPLEFT
, IK_KPRIGHT
, VK_LEFT
, VK_RIGHT
,
1404 JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
,
1405 JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
1407 if FIndex
<> -1 then
1408 if FItems
[FIndex
].Control
<> nil then
1409 FItems
[FIndex
].Control
.OnMessage(Msg
);
1411 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
1413 if FIndex
<> -1 then
1415 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1417 g_Sound_PlayEx(MENU_CLICKSOUND
);
1421 if FYesNo
and (length(FItems
) > 1) then
1423 Msg
.wParam
:= IK_RETURN
; // to register keypress
1424 FIndex
:= High(FItems
)-1;
1425 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1428 if FYesNo
and (length(FItems
) > 1) then
1430 Msg
.wParam
:= IK_RETURN
; // to register keypress
1431 FIndex
:= High(FItems
);
1432 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1439 procedure TGUIMenu
.ReAlign();
1441 a
, tx
, cx
, w
, h
, fw
, fh
: Integer;
1442 cww
: array of Integer; // cached widths
1445 if FItems
= nil then Exit
;
1447 SetLength(cww
, length(FItems
));
1449 for a
:= 0 to High(FItems
) do
1451 if FItems
[a
].Text <> nil then
1453 cww
[a
] := FItems
[a
].Text.GetWidth
;
1454 if maxcww
< cww
[a
] then maxcww
:= cww
[a
];
1465 for a
:= 0 to High(FItems
) do
1468 if FItems
[a
].Text <> nil then w
:= FItems
[a
].Text.GetWidth
;
1469 if FItems
[a
].Control
<> nil then
1472 if FItems
[a
].ControlType
= TGUILabel
then w
:= w
+(FItems
[a
].Control
as TGUILabel
).GetWidth
1473 else if FItems
[a
].ControlType
= TGUITextButton
then w
:= w
+(FItems
[a
].Control
as TGUITextButton
).GetWidth
1474 else if FItems
[a
].ControlType
= TGUIScroll
then w
:= w
+(FItems
[a
].Control
as TGUIScroll
).GetWidth
1475 else if FItems
[a
].ControlType
= TGUISwitch
then w
:= w
+(FItems
[a
].Control
as TGUISwitch
).GetWidth
1476 else if FItems
[a
].ControlType
= TGUIEdit
then w
:= w
+(FItems
[a
].Control
as TGUIEdit
).GetWidth
1477 else if FItems
[a
].ControlType
= TGUIKeyRead
then w
:= w
+(FItems
[a
].Control
as TGUIKeyRead
).GetWidth
1478 else if FItems
[a
].ControlType
= TGUIKeyRead2
then w
:= w
+(FItems
[a
].Control
as TGUIKeyRead2
).GetWidth
1479 else if FItems
[a
].ControlType
= TGUIListBox
then w
:= w
+(FItems
[a
].Control
as TGUIListBox
).GetWidth
1480 else if FItems
[a
].ControlType
= TGUIFileListBox
then w
:= w
+(FItems
[a
].Control
as TGUIFileListBox
).GetWidth
1481 else if FItems
[a
].ControlType
= TGUIMemo
then w
:= w
+(FItems
[a
].Control
as TGUIMemo
).GetWidth
;
1483 tx
:= Min(tx
, (gScreenWidth
div 2)-(w
div 2));
1488 for a
:= 0 to High(FItems
) do
1492 if (Text <> nil) and (Control
= nil) then Continue
;
1494 if Text <> nil then w
:= tx
+Text.GetWidth
;
1495 if w
> cx
then cx
:= w
;
1499 cx
:= cx
+MENU_HSPACE
;
1501 h
:= FHeader
.GetHeight
*2+MENU_VSPACE
*(Length(FItems
)-1);
1503 for a
:= 0 to High(FItems
) do
1507 if (ControlType
= TGUIListBox
) or (ControlType
= TGUIFileListBox
) then
1508 h
:= h
+(FItems
[a
].Control
as TGUIListBox
).GetHeight()
1511 r_GUI_GetMaxFontSize(FBigFont
, fw
, fh
);
1517 h
:= (gScreenHeight
div 2)-(h
div 2);
1521 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1524 Inc(h
, GetHeight
*2);
1527 for a
:= 0 to High(FItems
) do
1539 if Text.RightAlign
and (length(cww
) > a
) then
1541 //Text.FX := Text.FX+maxcww;
1542 Text.FMaxWidth
:= maxcww
;
1546 if Control
<> nil then
1563 if (ControlType
= TGUIListBox
) or (ControlType
= TGUIFileListBox
) then Inc(h
, (Control
as TGUIListBox
).GetHeight
+MENU_VSPACE
)
1564 else if ControlType
= TGUIMemo
then Inc(h
, (Control
as TGUIMemo
).GetHeight
+MENU_VSPACE
)
1567 r_GUI_GetMaxFontSize(FBigFont
, fw
, fh
);
1568 h
:= h
+ fh
+ MENU_VSPACE
;
1573 // another ugly hack
1574 if FYesNo
and (length(FItems
) > 1) then
1577 for a
:= High(FItems
)-1 to High(FItems
) do
1579 if (FItems
[a
].Control
<> nil) and (FItems
[a
].ControlType
= TGUITextButton
) then
1581 cx
:= (FItems
[a
].Control
as TGUITextButton
).GetWidth
;
1582 if cx
> w
then w
:= cx
;
1587 for a
:= High(FItems
)-1 to High(FItems
) do
1589 if (FItems
[a
].Control
<> nil) and (FItems
[a
].ControlType
= TGUITextButton
) then
1591 FItems
[a
].Control
.FX
:= (gScreenWidth
-w
) div 2;
1598 function TGUIMenu
.AddScroll(fText
: string): TGUIScroll
;
1605 Control
:= TGUIScroll
.Create();
1607 Text := TGUILabel
.Create(fText
, FBigFont
);
1610 FColor
:= MENU_ITEMSTEXT_COLOR
;
1613 ControlType
:= TGUIScroll
;
1615 Result
:= (Control
as TGUIScroll
);
1618 if FIndex
= -1 then FIndex
:= i
;
1623 function TGUIMenu
.AddSwitch(fText
: string): TGUISwitch
;
1630 Control
:= TGUISwitch
.Create(FBigFont
);
1631 (Control
as TGUISwitch
).FColor
:= MENU_ITEMSCTRL_COLOR
;
1633 Text := TGUILabel
.Create(fText
, FBigFont
);
1636 FColor
:= MENU_ITEMSTEXT_COLOR
;
1639 ControlType
:= TGUISwitch
;
1641 Result
:= (Control
as TGUISwitch
);
1644 if FIndex
= -1 then FIndex
:= i
;
1649 function TGUIMenu
.AddEdit(fText
: string): TGUIEdit
;
1656 Control
:= TGUIEdit
.Create(FBigFont
);
1657 with Control
as TGUIEdit
do
1659 FWindow
:= Self
.FWindow
;
1660 FColor
:= MENU_ITEMSCTRL_COLOR
;
1663 if fText
= '' then Text := nil else
1665 Text := TGUILabel
.Create(fText
, FBigFont
);
1666 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
1669 ControlType
:= TGUIEdit
;
1671 Result
:= (Control
as TGUIEdit
);
1674 if FIndex
= -1 then FIndex
:= i
;
1679 procedure TGUIMenu
.Update
;
1685 if FCounter
= 0 then FCounter
:= MENU_MARKERDELAY
else Dec(FCounter
);
1687 if FItems
<> nil then
1688 for a
:= 0 to High(FItems
) do
1689 if FItems
[a
].Control
<> nil then
1690 (FItems
[a
].Control
as FItems
[a
].ControlType
).Update
;
1693 function TGUIMenu
.AddKeyRead(fText
: string): TGUIKeyRead
;
1700 Control
:= TGUIKeyRead
.Create(FBigFont
);
1701 with Control
as TGUIKeyRead
do
1703 FWindow
:= Self
.FWindow
;
1704 FColor
:= MENU_ITEMSCTRL_COLOR
;
1707 Text := TGUILabel
.Create(fText
, FBigFont
);
1710 FColor
:= MENU_ITEMSTEXT_COLOR
;
1713 ControlType
:= TGUIKeyRead
;
1715 Result
:= (Control
as TGUIKeyRead
);
1718 if FIndex
= -1 then FIndex
:= i
;
1723 function TGUIMenu
.AddKeyRead2(fText
: string): TGUIKeyRead2
;
1730 Control
:= TGUIKeyRead2
.Create(FBigFont
);
1731 with Control
as TGUIKeyRead2
do
1733 FWindow
:= Self
.FWindow
;
1734 FColor
:= MENU_ITEMSCTRL_COLOR
;
1737 Text := TGUILabel
.Create(fText
, FBigFont
);
1740 FColor
:= MENU_ITEMSCTRL_COLOR
; //MENU_ITEMSTEXT_COLOR;
1744 ControlType
:= TGUIKeyRead2
;
1746 Result
:= (Control
as TGUIKeyRead2
);
1749 if FIndex
= -1 then FIndex
:= i
;
1754 function TGUIMenu
.AddList(fText
: string; Width
, Height
: Word): TGUIListBox
;
1761 Control
:= TGUIListBox
.Create(FBigFont
, Width
, Height
);
1762 with Control
as TGUIListBox
do
1764 FWindow
:= Self
.FWindow
;
1765 FActiveColor
:= MENU_ITEMSCTRL_COLOR
;
1766 FUnActiveColor
:= MENU_ITEMSTEXT_COLOR
;
1769 Text := TGUILabel
.Create(fText
, FBigFont
);
1772 FColor
:= MENU_ITEMSTEXT_COLOR
;
1775 ControlType
:= TGUIListBox
;
1777 Result
:= (Control
as TGUIListBox
);
1780 if FIndex
= -1 then FIndex
:= i
;
1785 function TGUIMenu
.AddFileList(fText
: string; Width
, Height
: Word): TGUIFileListBox
;
1792 Control
:= TGUIFileListBox
.Create(FBigFont
, Width
, Height
);
1793 with Control
as TGUIFileListBox
do
1795 FWindow
:= Self
.FWindow
;
1796 FActiveColor
:= MENU_ITEMSCTRL_COLOR
;
1797 FUnActiveColor
:= MENU_ITEMSTEXT_COLOR
;
1800 if fText
= '' then Text := nil else
1802 Text := TGUILabel
.Create(fText
, FBigFont
);
1803 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
1806 ControlType
:= TGUIFileListBox
;
1808 Result
:= (Control
as TGUIFileListBox
);
1811 if FIndex
= -1 then FIndex
:= i
;
1816 function TGUIMenu
.AddLabel(fText
: string): TGUILabel
;
1823 Control
:= TGUILabel
.Create('', FBigFont
);
1824 with Control
as TGUILabel
do
1826 FWindow
:= Self
.FWindow
;
1827 FColor
:= MENU_ITEMSCTRL_COLOR
;
1830 Text := TGUILabel
.Create(fText
, FBigFont
);
1833 FColor
:= MENU_ITEMSTEXT_COLOR
;
1836 ControlType
:= TGUILabel
;
1838 Result
:= (Control
as TGUILabel
);
1841 if FIndex
= -1 then FIndex
:= i
;
1846 function TGUIMenu
.AddMemo(fText
: string; Width
, Height
: Word): TGUIMemo
;
1853 Control
:= TGUIMemo
.Create(FBigFont
, Width
, Height
);
1854 with Control
as TGUIMemo
do
1856 FWindow
:= Self
.FWindow
;
1857 FColor
:= MENU_ITEMSTEXT_COLOR
;
1860 if fText
= '' then Text := nil else
1862 Text := TGUILabel
.Create(fText
, FBigFont
);
1863 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
1866 ControlType
:= TGUIMemo
;
1868 Result
:= (Control
as TGUIMemo
);
1871 if FIndex
= -1 then FIndex
:= i
;
1876 procedure TGUIMenu
.UpdateIndex();
1884 if (FIndex
< 0) or (FIndex
> High(FItems
)) then
1890 if FItems
[FIndex
].Control
.Enabled
then
1899 constructor TGUIScroll
.Create
;
1904 FOnChangeEvent
:= nil;
1907 procedure TGUIScroll
.FSetValue(a
: Integer);
1909 if a
> FMax
then FValue
:= FMax
else FValue
:= a
;
1912 procedure TGUIScroll
.OnMessage(var Msg
: TMessage
);
1914 if not FEnabled
then Exit
;
1922 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
1926 g_Sound_PlayEx(SCROLL_SUBSOUND
);
1927 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
1929 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
1930 if FValue
< FMax
then
1933 g_Sound_PlayEx(SCROLL_ADDSOUND
);
1934 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
1941 procedure TGUIScroll
.Update
;
1949 procedure TGUISwitch
.AddItem(Item
: string);
1951 SetLength(FItems
, Length(FItems
)+1);
1952 FItems
[High(FItems
)] := Item
;
1954 if FIndex
= -1 then FIndex
:= 0;
1957 constructor TGUISwitch
.Create(BigFont
: Boolean);
1963 FBigFont
:= BigFont
;
1966 function TGUISwitch
.GetText
: string;
1968 if FIndex
<> -1 then Result
:= FItems
[FIndex
]
1972 procedure TGUISwitch
.OnMessage(var Msg
: TMessage
);
1974 if not FEnabled
then Exit
;
1978 if FItems
= nil then Exit
;
1983 IK_RETURN
, IK_RIGHT
, IK_KPRETURN
, IK_KPRIGHT
, VK_FIRE
, VK_OPEN
, VK_RIGHT
,
1984 JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
,
1985 JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
1987 if FIndex
< High(FItems
) then
1992 g_Sound_PlayEx(SCROLL_ADDSOUND
);
1994 if @FOnChangeEvent
<> nil then
1995 FOnChangeEvent(Self
);
1998 IK_LEFT
, IK_KPLEFT
, VK_LEFT
,
1999 JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
2004 FIndex
:= High(FItems
);
2006 g_Sound_PlayEx(SCROLL_SUBSOUND
);
2008 if @FOnChangeEvent
<> nil then
2009 FOnChangeEvent(Self
);
2015 procedure TGUISwitch
.Update
;
2023 constructor TGUIEdit
.Create(BigFont
: Boolean);
2027 FBigFont
:= BigFont
;
2033 procedure TGUIEdit
.OnMessage(var Msg
: TMessage
);
2035 if not FEnabled
then Exit
;
2044 if (wParam
in [48..57]) and (Chr(wParam
) <> '`') then
2045 if Length(Text) < FMaxLength
then
2047 Insert(Chr(wParam
), FText
, FCaretPos
+ 1);
2053 if (wParam
in [32..255]) and (Chr(wParam
) <> '`') then
2054 if Length(Text) < FMaxLength
then
2056 Insert(Chr(wParam
), FText
, FCaretPos
+ 1);
2064 Delete(FText
, FCaretPos
, 1);
2065 if FCaretPos
> 0 then Dec(FCaretPos
);
2067 IK_DELETE
: Delete(FText
, FCaretPos
+ 1, 1);
2068 IK_END
, IK_KPEND
: FCaretPos
:= Length(FText
);
2069 IK_HOME
, IK_KPHOME
: FCaretPos
:= 0;
2070 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
: if FCaretPos
> 0 then Dec(FCaretPos
);
2071 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
: if FCaretPos
< Length(FText
) then Inc(FCaretPos
);
2072 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2075 if FActiveControl
<> Self
then
2078 if @FOnEnterEvent
<> nil then FOnEnterEvent(Self
);
2082 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
2083 else SetActive(nil);
2084 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2090 g_GUIGrabInput
:= (@FOnEnterEvent
= nil) and (FWindow
.FActiveControl
= Self
);
2092 {$IFDEF ENABLE_TOUCH}
2093 sys_ShowKeyboard(g_GUIGrabInput
)
2097 procedure TGUIEdit
.SetText(Text: string);
2099 if Length(Text) > FMaxLength
then SetLength(Text, FMaxLength
);
2101 FCaretPos
:= Length(FText
);
2104 procedure TGUIEdit
.Update
;
2111 constructor TGUIKeyRead
.Create(BigFont
: Boolean);
2116 FBigFont
:= BigFont
;
2119 function TGUIKeyRead
.WantActivationKey (key
: LongInt): Boolean;
2122 (key
= IK_BACKSPACE
) or
2126 procedure TGUIKeyRead
.OnMessage(var Msg
: TMessage
);
2127 procedure actDefCtl ();
2130 if FDefControl
<> '' then
2131 SetActive(GetControl(FDefControl
))
2139 if not FEnabled
then
2148 if FIsQuery
then actDefCtl();
2151 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2153 if not FIsQuery
then
2156 if FActiveControl
<> Self
then
2161 else if (wParam
< VK_FIRSTKEY
) and (wParam
> VK_LASTKEY
) then
2163 // FKey := IK_ENTER; // <Enter>
2169 IK_BACKSPACE
: // clear keybinding if we aren't waiting for a key
2171 if not FIsQuery
then
2181 if not FIsQuery
and (wParam
= IK_BACKSPACE
) then
2186 else if FIsQuery
then
2189 IK_ENTER
, IK_KPRETURN
, VK_FIRSTKEY
..VK_LASTKEY (*, JOY0_ATTACK, JOY1_ATTACK, JOY2_ATTACK, JOY3_ATTACK*): // Not <Enter
2191 if e_KeyNames
[wParam
] <> '' then
2200 g_GUIGrabInput
:= FIsQuery
2205 constructor TGUIKeyRead2
.Create(BigFont
: Boolean);
2206 var a
: Byte; w
, h
: Integer;
2215 FBigFont
:= BigFont
;
2217 FMaxKeyNameWdt
:= 0;
2219 FMaxKeyNameWdt
:= 0;
2221 for a
:= 0 to 255 do
2223 r_GUI_GetStringSize(BigFont
, e_KeyNames
[a
], w
, h
);
2224 FMaxKeyNameWdt
:= Max(FMaxKeyNameWdt
, w
);
2227 FMaxKeyNameWdt
:= FMaxKeyNameWdt
-(FMaxKeyNameWdt
div 3);
2229 r_GUI_GetStringSize(BigFont
, KEYREAD_QUERY
, w
, h
);
2230 if w
> FMaxKeyNameWdt
then FMaxKeyNameWdt
:= w
;
2232 r_GUI_GetStringSize(BigFont
, KEYREAD_CLEAR
, w
, h
);
2233 if w
> FMaxKeyNameWdt
then FMaxKeyNameWdt
:= w
;
2236 function TGUIKeyRead2
.WantActivationKey (key
: LongInt): Boolean;
2239 IK_BACKSPACE
, IK_LEFT
, IK_RIGHT
, IK_KPLEFT
, IK_KPRIGHT
, VK_LEFT
, VK_RIGHT
,
2240 JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
,
2241 JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
2248 procedure TGUIKeyRead2
.OnMessage(var Msg
: TMessage
);
2249 procedure actDefCtl ();
2252 if FDefControl
<> '' then
2253 SetActive(GetControl(FDefControl
))
2261 if not FEnabled
then
2270 if FIsQuery
then actDefCtl();
2273 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2275 if not FIsQuery
then
2278 if FActiveControl
<> Self
then
2283 else if (wParam
< VK_FIRSTKEY
) and (wParam
> VK_LASTKEY
) then
2285 // if (FKeyIdx = 0) then FKey0 := IK_ENTER else FKey1 := IK_ENTER; // <Enter>
2286 if (FKeyIdx
= 0) then FKey0
:= wParam
else FKey1
:= wParam
;
2291 IK_BACKSPACE
: // clear keybinding if we aren't waiting for a key
2293 if not FIsQuery
then
2295 if (FKeyIdx
= 0) then FKey0
:= 0 else FKey1
:= 0;
2299 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
2300 if not FIsQuery
then
2305 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
2306 if not FIsQuery
then
2315 if not FIsQuery
and (wParam
= IK_BACKSPACE
) then
2317 if (FKeyIdx
= 0) then FKey0
:= 0 else FKey1
:= 0;
2320 else if FIsQuery
then
2323 IK_ENTER
, IK_KPRETURN
, VK_FIRSTKEY
..VK_LASTKEY (*, JOY0_ATTACK, JOY1_ATTACK, JOY2_ATTACK, JOY3_ATTACK*): // Not <Enter
2325 if e_KeyNames
[wParam
] <> '' then
2327 if (FKeyIdx
= 0) then FKey0
:= wParam
else FKey1
:= wParam
;
2336 g_GUIGrabInput
:= FIsQuery
2342 constructor TGUIModelView
.Create
;
2349 destructor TGUIModelView
.Destroy
;
2356 procedure TGUIModelView
.NextAnim();
2358 if FModel
= nil then
2361 if FModel
.Animation
< A_PAIN
then
2362 FModel
.ChangeAnimation(FModel
.Animation
+1, True)
2364 FModel
.ChangeAnimation(A_STAND
, True);
2367 procedure TGUIModelView
.NextWeapon();
2369 if FModel
= nil then
2372 if FModel
.Weapon
< WP_LAST
then
2373 FModel
.SetWeapon(FModel
.Weapon
+1)
2375 FModel
.SetWeapon(WEAPON_KASTET
);
2378 procedure TGUIModelView
.OnMessage(var Msg
: TMessage
);
2384 procedure TGUIModelView
.SetColor(Red
, Green
, Blue
: Byte);
2386 if FModel
<> nil then FModel
.SetColor(Red
, Green
, Blue
);
2389 procedure TGUIModelView
.SetModel(ModelName
: string);
2393 FModel
:= g_PlayerModel_Get(ModelName
);
2396 procedure TGUIModelView
.Update
;
2403 if FModel
<> nil then FModel
.Update
;
2408 constructor TGUIMapPreview
.Create();
2414 destructor TGUIMapPreview
.Destroy();
2420 procedure TGUIMapPreview
.OnMessage(var Msg
: TMessage
);
2426 procedure TGUIMapPreview
.SetMap(Res
: string);
2431 //header: TMapHeaderRec_1;
2436 map
: TDynRecord
= nil;
2443 FileName
:= g_ExtractWadName(Res
);
2445 WAD
:= TWADFile
.Create();
2446 if not WAD
.ReadFile(FileName
) then
2452 //k8: ignores path again
2453 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
2462 map
:= g_Map_ParseMap(Data
, Len
);
2472 if (map
= nil) then exit
;
2475 panlist
:= map
.field
['panel'];
2476 //header := GetMapHeader(map);
2478 FMapSize
.X
:= map
.Width
div 16;
2479 FMapSize
.Y
:= map
.Height
div 16;
2481 rX
:= Ceil(map
.Width
/ (MAPPREVIEW_WIDTH
*256.0));
2482 rY
:= Ceil(map
.Height
/ (MAPPREVIEW_HEIGHT
*256.0));
2483 FScale
:= max(rX
, rY
);
2487 if (panlist
<> nil) then
2489 for pan
in panlist
do
2491 if (pan
.PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or
2492 PANEL_STEP
or PANEL_WATER
or
2493 PANEL_ACID1
or PANEL_ACID2
)) <> 0 then
2495 SetLength(FMapData
, Length(FMapData
)+1);
2496 with FMapData
[High(FMapData
)] do
2501 X2
:= (pan
.X
+ pan
.Width
) div 16;
2502 Y2
:= (pan
.Y
+ pan
.Height
) div 16;
2504 X1
:= Trunc(X1
/FScale
+ 0.5);
2505 Y1
:= Trunc(Y1
/FScale
+ 0.5);
2506 X2
:= Trunc(X2
/FScale
+ 0.5);
2507 Y2
:= Trunc(Y2
/FScale
+ 0.5);
2509 if (X1
<> X2
) or (Y1
<> Y2
) then
2517 PanelType
:= pan
.PanelType
;
2523 //writeln('freeing map');
2528 procedure TGUIMapPreview
.ClearMap();
2530 SetLength(FMapData
, 0);
2537 procedure TGUIMapPreview
.Update();
2543 function TGUIMapPreview
.GetScaleStr(): String;
2545 if FScale
> 0.0 then
2547 Result
:= FloatToStrF(FScale
*16.0, ffFixed
, 3, 3);
2548 while (Result
[Length(Result
)] = '0') do
2549 Delete(Result
, Length(Result
), 1);
2550 if (Result
[Length(Result
)] = ',') or (Result
[Length(Result
)] = '.') then
2551 Delete(Result
, Length(Result
), 1);
2552 Result
:= '1 : ' + Result
;
2560 procedure TGUIListBox
.AddItem(Item
: string);
2562 SetLength(FItems
, Length(FItems
)+1);
2563 FItems
[High(FItems
)] := Item
;
2565 if FSort
then g_gui
.Sort(FItems
);
2568 function TGUIListBox
.ItemExists (item
: String): Boolean;
2572 while (i
<= High(FItems
)) and (FItems
[i
] <> item
) do Inc(i
);
2573 result
:= i
<= High(FItems
)
2576 procedure TGUIListBox
.Clear
;
2584 constructor TGUIListBox
.Create(BigFont
: Boolean; Width
, Height
: Word);
2588 FBigFont
:= BigFont
;
2592 FOnChangeEvent
:= nil;
2594 FDrawScroll
:= True;
2597 procedure TGUIListBox
.OnMessage(var Msg
: TMessage
);
2601 if not FEnabled
then Exit
;
2605 if FItems
= nil then Exit
;
2618 FIndex
:= High(FItems
);
2619 FStartLine
:= Max(High(FItems
)-FHeight
+1, 0);
2621 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
2625 if FIndex
< FStartLine
then Dec(FStartLine
);
2626 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2628 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
2629 if FIndex
< High(FItems
) then
2632 if FIndex
> FStartLine
+FHeight
-1 then Inc(FStartLine
);
2633 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2635 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2638 if FActiveControl
<> Self
then SetActive(Self
)
2640 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
2641 else SetActive(nil);
2645 for a
:= 0 to High(FItems
) do
2646 if (Length(FItems
[a
]) > 0) and (LowerCase(FItems
[a
][1]) = LowerCase(Chr(wParam
))) then
2649 FStartLine
:= Min(Max(FIndex
-1, 0), Length(FItems
)-FHeight
);
2650 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2656 function TGUIListBox
.SelectedItem(): String;
2660 if (FIndex
< 0) or (FItems
= nil) or
2661 (FIndex
> High(FItems
)) then
2664 Result
:= FItems
[FIndex
];
2667 procedure TGUIListBox
.FSetItems(Items
: SSArray
);
2669 if FItems
<> nil then
2677 if FSort
then g_gui
.Sort(FItems
);
2680 procedure TGUIListBox
.SelectItem(Item
: String);
2684 if FItems
= nil then
2688 Item
:= LowerCase(Item
);
2690 for a
:= 0 to High(FItems
) do
2691 if LowerCase(FItems
[a
]) = Item
then
2697 if FIndex
< FHeight
then
2700 FStartLine
:= Min(FIndex
, Length(FItems
)-FHeight
);
2703 procedure TGUIListBox
.FSetIndex(aIndex
: Integer);
2705 if FItems
= nil then
2708 if (aIndex
< 0) or (aIndex
> High(FItems
)) then
2713 if FIndex
<= FHeight
then
2716 FStartLine
:= Min(FIndex
, Length(FItems
)-FHeight
);
2721 procedure TGUIFileListBox
.OnMessage(var Msg
: TMessage
);
2723 a
, b
: Integer; s
: AnsiString;
2725 if not FEnabled
then
2728 if FItems
= nil then
2739 if @FOnChangeEvent
<> nil then
2740 FOnChangeEvent(Self
);
2745 FIndex
:= High(FItems
);
2746 FStartLine
:= Max(High(FItems
)-FHeight
+1, 0);
2747 if @FOnChangeEvent
<> nil then
2748 FOnChangeEvent(Self
);
2751 IK_PAGEUP
, IK_KPPAGEUP
:
2753 if FIndex
> FHeight
then
2754 FIndex
:= FIndex
-FHeight
2758 if FStartLine
> FHeight
then
2759 FStartLine
:= FStartLine
-FHeight
2764 IK_PAGEDN
, IK_KPPAGEDN
:
2766 if FIndex
< High(FItems
)-FHeight
then
2767 FIndex
:= FIndex
+FHeight
2769 FIndex
:= High(FItems
);
2771 if FStartLine
< High(FItems
)-FHeight
then
2772 FStartLine
:= FStartLine
+FHeight
2774 FStartLine
:= High(FItems
)-FHeight
+1;
2777 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
, VK_UP
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
2781 if FIndex
< FStartLine
then
2783 if @FOnChangeEvent
<> nil then
2784 FOnChangeEvent(Self
);
2787 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
, VK_DOWN
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
2788 if FIndex
< High(FItems
) then
2791 if FIndex
> FStartLine
+FHeight
-1 then
2793 if @FOnChangeEvent
<> nil then
2794 FOnChangeEvent(Self
);
2797 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2800 if FActiveControl
<> Self
then
2804 if FItems
[FIndex
][1] = #29 then // Ïàïêà
2806 if FItems
[FIndex
] = #29 + '..' then
2808 e_LogWritefln('TGUIFileListBox: Upper dir "%s" -> "%s"', [FSubPath
, e_UpperDir(FSubPath
)]);
2809 FSubPath
:= e_UpperDir(FSubPath
)
2813 s
:= Copy(AnsiString(FItems
[FIndex
]), 2);
2814 e_LogWritefln('TGUIFileListBox: Enter dir "%s" -> "%s"', [FSubPath
, e_CatPath(FSubPath
, s
)]);
2815 FSubPath
:= e_CatPath(FSubPath
, s
);
2822 if FDefControl
<> '' then
2823 SetActive(GetControl(FDefControl
))
2831 for b
:= FIndex
+ 1 to High(FItems
) + FIndex
do
2833 a
:= b
mod Length(FItems
);
2834 if ( (Length(FItems
[a
]) > 0) and
2835 (LowerCase(FItems
[a
][1]) = LowerCase(Chr(wParam
))) ) or
2836 ( (Length(FItems
[a
]) > 1) and
2837 (FItems
[a
][1] = #29) and // Ïàïêà
2838 (LowerCase(FItems
[a
][2]) = LowerCase(Chr(wParam
))) ) then
2841 FStartLine
:= Min(Max(FIndex
-1, 0), Length(FItems
)-FHeight
);
2842 if @FOnChangeEvent
<> nil then
2843 FOnChangeEvent(Self
);
2850 procedure TGUIFileListBox
.ScanDirs
;
2851 var i
, j
: Integer; path
: AnsiString; SR
: TSearchRec
; sm
, sc
: String;
2855 i
:= High(FBaseList
);
2858 path
:= e_CatPath(FBaseList
[i
], FSubPath
);
2861 if FindFirst(path
+ '/' + '*', faDirectory
, SR
) = 0 then
2864 if LongBool(SR
.Attr
and faDirectory
) then
2865 if (SR
.Name
<> '.') and ((FSubPath
<> '') or (SR
.Name
<> '..')) then
2866 if Self
.ItemExists(#1 + SR
.Name
) = false then
2867 Self
.AddItem(#1 + SR
.Name
)
2868 until FindNext(SR
) <> 0
2875 i
:= High(FBaseList
);
2878 path
:= e_CatPath(FBaseList
[i
], FSubPath
);
2884 j
:= length(sm
) + 1;
2885 sc
:= Copy(sm
, 1, j
- 1);
2887 if FindFirst(path
+ '/' + sc
, faAnyFile
, SR
) = 0 then
2890 if Self
.ItemExists(SR
.Name
) = false then
2892 until FindNext(SR
) <> 0
2899 for i
:= 0 to High(FItems
) do
2900 if FItems
[i
][1] = #1 then
2901 FItems
[i
][1] := #29;
2904 procedure TGUIFileListBox
.SetBase (dirs
: SSArray
; path
: String = '');
2911 function TGUIFileListBox
.SelectedItem (): String;
2915 if (FIndex
>= 0) and (FIndex
<= High(FItems
)) and (FItems
[FIndex
][1] <> '/') and (FItems
[FIndex
][1] <> '\') then
2917 s
:= e_CatPath(FSubPath
, FItems
[FIndex
]);
2918 if e_FindResource(FBaseList
, s
) = true then
2919 result
:= ExpandFileName(s
)
2921 e_LogWritefln('TGUIFileListBox.SelectedItem -> "%s"', [result
]);
2924 procedure TGUIFileListBox
.UpdateFileList();
2928 if (FIndex
= -1) or (FItems
= nil) or
2929 (FIndex
> High(FItems
)) or
2930 (FItems
[FIndex
][1] = '/') or
2931 (FItems
[FIndex
][1] = '\') then
2934 fn
:= FItems
[FIndex
];
2945 procedure TGUIMemo
.Clear
;
2951 constructor TGUIMemo
.Create(BigFont
: Boolean; Width
, Height
: Word);
2955 FBigFont
:= BigFont
;
2959 FDrawScroll
:= True;
2962 procedure TGUIMemo
.OnMessage(var Msg
: TMessage
);
2964 if not FEnabled
then Exit
;
2968 if FLines
= nil then Exit
;
2974 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
, VK_UP
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
2975 if FStartLine
> 0 then
2977 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
, VK_DOWN
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
2978 if FStartLine
< Length(FLines
)-FHeight
then
2980 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2983 if FActiveControl
<> Self
then
2989 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
2990 else SetActive(nil);
2996 procedure TGUIMemo
.SetText(Text: string);
2999 FLines
:= GetLines(Text, FBigFont
, FWidth
* 16);
3004 procedure TGUIimage
.ClearImage();
3006 if FImageRes
= '' then Exit
;
3008 g_Texture_Delete(FImageRes
);
3012 constructor TGUIimage
.Create();
3019 destructor TGUIimage
.Destroy();
3024 procedure TGUIimage
.OnMessage(var Msg
: TMessage
);
3029 procedure TGUIimage
.SetImage(Res
: string);
3033 if g_Texture_CreateWADEx(Res
, Res
) then FImageRes
:= Res
;
3036 procedure TGUIimage
.Update();