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, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 e_graphics
, e_input
, e_log
, g_playermodel
, g_basic
, MAPSTRUCT
, wadreader
;
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;
69 BSCROLL_UPA
= 'BSCROLL_UP_A';
70 BSCROLL_UPU
= 'BSCROLL_UP_U';
71 BSCROLL_DOWNA
= 'BSCROLL_DOWN_A';
72 BSCROLL_DOWNU
= 'BSCROLL_DOWN_U';
73 BSCROLL_MIDDLE
= 'BSCROLL_MIDDLE';
85 TFontType
= (FONT_TEXTURE
, FONT_CHAR
);
87 TFont
= class(TObject
)
93 constructor Create(FontID
: DWORD
; FontType
: TFontType
);
94 destructor Destroy
; override;
95 procedure Draw(X
, Y
: Integer; Text: string; R
, G
, B
: Byte);
96 procedure GetTextSize(Text: string; var w
, h
: Word);
97 property Scale
: Single read FScale write FScale
;
103 TOnKeyDownEvent
= procedure(Key
: Byte);
104 TOnKeyDownEventEx
= procedure(win
: TGUIWindow
; Key
: Byte);
105 TOnCloseEvent
= procedure;
106 TOnShowEvent
= procedure;
107 TOnClickEvent
= procedure;
108 TOnChangeEvent
= procedure(Sender
: TGUIControl
);
109 TOnEnterEvent
= procedure(Sender
: TGUIControl
);
115 FWindow
: TGUIWindow
;
120 procedure OnMessage(var Msg
: TMessage
); virtual;
121 procedure Update
; virtual;
122 procedure Draw
; virtual;
123 function WantActivationKey (key
: LongInt): Boolean; virtual;
124 property X
: Integer read FX write FX
;
125 property Y
: Integer read FY write FY
;
126 property Enabled
: Boolean read FEnabled write FEnabled
;
127 property Name
: string read FName write FName
;
128 property UserData
: Pointer read FUserData write FUserData
;
133 FActiveControl
: TGUIControl
;
135 FPrevWindow
: TGUIWindow
;
137 FBackTexture
: string;
138 FMainWindow
: Boolean;
139 FOnKeyDown
: TOnKeyDownEvent
;
140 FOnKeyDownEx
: TOnKeyDownEventEx
;
141 FOnCloseEvent
: TOnCloseEvent
;
142 FOnShowEvent
: TOnShowEvent
;
145 Childs
: array of TGUIControl
;
146 constructor Create(Name
: string);
147 destructor Destroy
; override;
148 function AddChild(Child
: TGUIControl
): TGUIControl
;
149 procedure OnMessage(var Msg
: TMessage
);
152 procedure SetActive(Control
: TGUIControl
);
153 function GetControl(Name
: string): TGUIControl
;
154 property OnKeyDown
: TOnKeyDownEvent read FOnKeyDown write FOnKeyDown
;
155 property OnKeyDownEx
: TOnKeyDownEventEx read FOnKeyDownEx write FOnKeyDownEx
;
156 property OnClose
: TOnCloseEvent read FOnCloseEvent write FOnCloseEvent
;
157 property OnShow
: TOnShowEvent read FOnShowEvent write FOnShowEvent
;
158 property Name
: string read FName
;
159 property DefControl
: string read FDefControl write FDefControl
;
160 property BackTexture
: string read FBackTexture write FBackTexture
;
161 property MainWindow
: Boolean read FMainWindow write FMainWindow
;
162 property UserData
: Pointer read FUserData write FUserData
;
165 TGUITextButton
= class(TGUIControl
)
174 ProcEx
: procedure (sender
: TGUITextButton
);
175 constructor Create(Proc
: Pointer; FontID
: DWORD
; Text: string);
176 destructor Destroy(); override;
177 procedure OnMessage(var Msg
: TMessage
); override;
178 procedure Update(); override;
179 procedure Draw(); override;
180 function GetWidth(): Integer;
181 function GetHeight(): Integer;
182 procedure Click(Silent
: Boolean = False);
183 property Caption
: string read FText write FText
;
184 property Color
: TRGB read FColor write FColor
;
185 property Font
: TFont read FFont write FFont
;
186 property ShowWindow
: string read FShowWindow write FShowWindow
;
189 TGUILabel
= class(TGUIControl
)
195 FOnClickEvent
: TOnClickEvent
;
197 constructor Create(Text: string; FontID
: DWORD
);
198 procedure OnMessage(var Msg
: TMessage
); override;
199 procedure Draw
; override;
200 function GetWidth
: Integer;
201 function GetHeight
: Integer;
202 property OnClick
: TOnClickEvent read FOnClickEvent write FOnClickEvent
;
203 property FixedLength
: Word read FFixedLen write FFixedLen
;
204 property Text: string read FText write FText
;
205 property Color
: TRGB read FColor write FColor
;
206 property Font
: TFont read FFont write FFont
;
209 TGUIScroll
= class(TGUIControl
)
217 FOnChangeEvent
: TOnChangeEvent
;
218 procedure FSetValue(a
: Integer);
220 constructor Create();
221 procedure OnMessage(var Msg
: TMessage
); override;
222 procedure Update
; override;
223 procedure Draw
; override;
224 function GetWidth(): Word;
225 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
226 property Max
: Word read FMax write FMax
;
227 property Value
: Integer read FValue write FSetValue
;
230 TGUISwitch
= class(TGUIControl
)
233 FItems
: array of string;
236 FOnChangeEvent
: TOnChangeEvent
;
238 constructor Create(FontID
: DWORD
);
239 procedure OnMessage(var Msg
: TMessage
); override;
240 procedure AddItem(Item
: string);
241 procedure Update
; override;
242 procedure Draw
; override;
243 function GetWidth(): Word;
244 function GetText
: string;
245 property ItemIndex
: Integer read FIndex write FIndex
;
246 property Color
: TRGB read FColor write FColor
;
247 property Font
: TFont read FFont write FFont
;
248 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
251 TGUIEdit
= class(TGUIControl
)
259 FOnlyDigits
: Boolean;
263 FOnChangeEvent
: TOnChangeEvent
;
264 FOnEnterEvent
: TOnEnterEvent
;
265 procedure SetText(Text: string);
267 constructor Create(FontID
: DWORD
);
268 procedure OnMessage(var Msg
: TMessage
); override;
269 procedure Update
; override;
270 procedure Draw
; override;
271 function GetWidth(): Word;
272 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
273 property OnEnter
: TOnEnterEvent read FOnEnterEvent write FOnEnterEvent
;
274 property Width
: Word read FWidth write FWidth
;
275 property MaxLength
: Word read FMaxLength write FMaxLength
;
276 property OnlyDigits
: Boolean read FOnlyDigits write FOnlyDigits
;
277 property Text: string read FText write SetText
;
278 property Color
: TRGB read FColor write FColor
;
279 property Font
: TFont read FFont write FFont
;
282 TGUIKeyRead
= class(TGUIControl
)
289 constructor Create(FontID
: DWORD
);
290 procedure OnMessage(var Msg
: TMessage
); override;
291 procedure Draw
; override;
292 function GetWidth(): Word;
293 function WantActivationKey (key
: LongInt): Boolean; override;
294 property Key
: Word read FKey write FKey
;
295 property Color
: TRGB read FColor write FColor
;
296 property Font
: TFont read FFont write FFont
;
300 TGUIKeyRead2
= class(TGUIControl
)
305 FKey0
, FKey1
: Word; // this should be an array. sorry.
308 FMaxKeyNameWdt
: Integer;
310 constructor Create(FontID
: DWORD
);
311 procedure OnMessage(var Msg
: TMessage
); override;
312 procedure Draw
; override;
313 function GetWidth(): Word;
314 function WantActivationKey (key
: LongInt): Boolean; override;
315 property Key0
: Word read FKey0 write FKey0
;
316 property Key1
: Word read FKey1 write FKey1
;
317 property Color
: TRGB read FColor write FColor
;
318 property Font
: TFont read FFont write FFont
;
321 TGUIModelView
= class(TGUIControl
)
323 FModel
: TPlayerModel
;
327 destructor Destroy
; override;
328 procedure OnMessage(var Msg
: TMessage
); override;
329 procedure SetModel(ModelName
: string);
330 procedure SetColor(Red
, Green
, Blue
: Byte);
331 procedure NextAnim();
332 procedure NextWeapon();
333 procedure Update
; override;
334 procedure Draw
; override;
335 property Model
: TPlayerModel read FModel
;
338 TPreviewPanel
= record
339 X1
, Y1
, X2
, Y2
: Integer;
343 TGUIMapPreview
= class(TGUIControl
)
345 FMapData
: array of TPreviewPanel
;
349 constructor Create();
350 destructor Destroy(); override;
351 procedure OnMessage(var Msg
: TMessage
); override;
352 procedure SetMap(Res
: string);
353 procedure ClearMap();
354 procedure Update(); override;
355 procedure Draw(); override;
356 function GetScaleStr
: String;
359 TGUIImage
= class(TGUIControl
)
364 constructor Create();
365 destructor Destroy(); override;
366 procedure OnMessage(var Msg
: TMessage
); override;
367 procedure SetImage(Res
: string);
368 procedure ClearImage();
369 procedure Update(); override;
370 procedure Draw(); override;
371 property DefaultRes
: string read FDefaultRes write FDefaultRes
;
374 TGUIListBox
= class(TGUIControl
)
378 FUnActiveColor
: TRGB
;
386 FDrawScroll
: Boolean;
387 FOnChangeEvent
: TOnChangeEvent
;
389 procedure FSetItems(Items
: SArray
);
390 procedure FSetIndex(aIndex
: Integer);
393 constructor Create(FontID
: DWORD
; Width
, Height
: Word);
394 procedure OnMessage(var Msg
: TMessage
); override;
395 procedure Draw(); override;
396 procedure AddItem(Item
: String);
397 procedure SelectItem(Item
: String);
399 function GetWidth(): Word;
400 function GetHeight(): Word;
401 function SelectedItem(): String;
403 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
404 property Sort
: Boolean read FSort write FSort
;
405 property ItemIndex
: Integer read FIndex write FSetIndex
;
406 property Items
: SArray read FItems write FSetItems
;
407 property DrawBack
: Boolean read FDrawBack write FDrawBack
;
408 property DrawScrollBar
: Boolean read FDrawScroll write FDrawScroll
;
409 property ActiveColor
: TRGB read FActiveColor write FActiveColor
;
410 property UnActiveColor
: TRGB read FUnActiveColor write FUnActiveColor
;
411 property Font
: TFont read FFont write FFont
;
414 TGUIFileListBox
= class (TGUIListBox
)
421 procedure OpenDir(path
: String);
424 procedure OnMessage(var Msg
: TMessage
); override;
425 procedure SetBase(path
: String);
426 function SelectedItem(): String;
427 procedure UpdateFileList();
429 property Dirs
: Boolean read FDirs write FDirs
;
430 property FileMask
: String read FFileMask write FFileMask
;
431 property Path
: String read FPath
;
434 TGUIMemo
= class(TGUIControl
)
443 FDrawScroll
: Boolean;
445 constructor Create(FontID
: DWORD
; Width
, Height
: Word);
446 procedure OnMessage(var Msg
: TMessage
); override;
447 procedure Draw
; override;
449 function GetWidth(): Word;
450 function GetHeight(): Word;
451 procedure SetText(Text: string);
452 property DrawBack
: Boolean read FDrawBack write FDrawBack
;
453 property DrawScrollBar
: Boolean read FDrawScroll write FDrawScroll
;
454 property Color
: TRGB read FColor write FColor
;
455 property Font
: TFont read FFont write FFont
;
458 TGUIMainMenu
= class(TGUIControl
)
460 FButtons
: array of TGUITextButton
;
468 constructor Create(FontID
: DWORD
; Header
: string);
469 destructor Destroy
; override;
470 procedure OnMessage(var Msg
: TMessage
); override;
471 function AddButton(fProc
: Pointer; Caption
: string; ShowWindow
: string = ''): TGUITextButton
;
472 function GetButton(Name
: string): TGUITextButton
;
473 procedure EnableButton(Name
: string; e
: Boolean);
474 procedure AddSpace();
475 procedure Update
; override;
476 procedure Draw
; override;
479 TControlType
= class of TGUIControl
;
481 PMenuItem
= ^TMenuItem
;
484 ControlType
: TControlType
;
485 Control
: TGUIControl
;
488 TGUIMenu
= class(TGUIControl
)
490 FItems
: array of TMenuItem
;
498 function NewItem(): Integer;
500 constructor Create(HeaderFont
, ItemsFont
: DWORD
; Header
: string);
501 destructor Destroy
; override;
502 procedure OnMessage(var Msg
: TMessage
); override;
503 procedure AddSpace();
504 procedure AddLine(fText
: string);
505 procedure AddText(fText
: string; MaxWidth
: Word);
506 function AddLabel(fText
: string): TGUILabel
;
507 function AddButton(Proc
: Pointer; fText
: string; _ShowWindow
: string = ''): TGUITextButton
;
508 function AddScroll(fText
: string): TGUIScroll
;
509 function AddSwitch(fText
: string): TGUISwitch
;
510 function AddEdit(fText
: string): TGUIEdit
;
511 function AddKeyRead(fText
: string): TGUIKeyRead
;
512 function AddKeyRead2(fText
: string): TGUIKeyRead2
;
513 function AddList(fText
: string; Width
, Height
: Word): TGUIListBox
;
514 function AddFileList(fText
: string; Width
, Height
: Word): TGUIFileListBox
;
515 function AddMemo(fText
: string; Width
, Height
: Word): TGUIMemo
;
517 function GetControl(Name
: string): TGUIControl
;
518 function GetControlsText(Name
: string): TGUILabel
;
519 procedure Draw
; override;
520 procedure Update
; override;
521 procedure UpdateIndex();
522 property Align
: Boolean read FAlign write FAlign
;
523 property Left
: Integer read FLeft write FLeft
;
524 property YesNo
: Boolean read FYesNo write FYesNo
;
528 g_GUIWindows
: array of TGUIWindow
;
529 g_ActiveWindow
: TGUIWindow
= nil;
531 procedure g_GUI_Init();
532 function g_GUI_AddWindow(Window
: TGUIWindow
): TGUIWindow
;
533 function g_GUI_GetWindow(Name
: string): TGUIWindow
;
534 procedure g_GUI_ShowWindow(Name
: string);
535 procedure g_GUI_HideWindow(PlaySound
: Boolean = True);
536 function g_GUI_Destroy(): Boolean;
537 procedure g_GUI_SaveMenuPos();
538 procedure g_GUI_LoadMenuPos();
543 GL
, GLExt
, g_textures
, g_sound
, SysUtils
,
544 g_game
, Math
, StrUtils
, g_player
, g_options
, MAPREADER
,
545 g_map
, MAPDEF
, g_weapons
;
548 Box
: Array [0..8] of DWORD
;
549 Saved_Windows
: SArray
;
551 procedure g_GUI_Init();
553 g_Texture_Get(BOX1
, Box
[0]);
554 g_Texture_Get(BOX2
, Box
[1]);
555 g_Texture_Get(BOX3
, Box
[2]);
556 g_Texture_Get(BOX4
, Box
[3]);
557 g_Texture_Get(BOX5
, Box
[4]);
558 g_Texture_Get(BOX6
, Box
[5]);
559 g_Texture_Get(BOX7
, Box
[6]);
560 g_Texture_Get(BOX8
, Box
[7]);
561 g_Texture_Get(BOX9
, Box
[8]);
564 function g_GUI_Destroy(): Boolean;
568 Result
:= (Length(g_GUIWindows
) > 0);
570 for i
:= 0 to High(g_GUIWindows
) do
571 g_GUIWindows
[i
].Free();
574 g_ActiveWindow
:= nil;
577 function g_GUI_AddWindow(Window
: TGUIWindow
): TGUIWindow
;
579 SetLength(g_GUIWindows
, Length(g_GUIWindows
)+1);
580 g_GUIWindows
[High(g_GUIWindows
)] := Window
;
585 function g_GUI_GetWindow(Name
: string): TGUIWindow
;
591 if g_GUIWindows
<> nil then
592 for i
:= 0 to High(g_GUIWindows
) do
593 if g_GUIWindows
[i
].FName
= Name
then
595 Result
:= g_GUIWindows
[i
];
599 Assert(Result
<> nil, 'GUI_Window "'+Name
+'" not found');
602 procedure g_GUI_ShowWindow(Name
: string);
606 if g_GUIWindows
= nil then
609 for i
:= 0 to High(g_GUIWindows
) do
610 if g_GUIWindows
[i
].FName
= Name
then
612 g_GUIWindows
[i
].FPrevWindow
:= g_ActiveWindow
;
613 g_ActiveWindow
:= g_GUIWindows
[i
];
615 if g_ActiveWindow
.MainWindow
then
616 g_ActiveWindow
.FPrevWindow
:= nil;
618 if g_ActiveWindow
.FDefControl
<> '' then
619 g_ActiveWindow
.SetActive(g_ActiveWindow
.GetControl(g_ActiveWindow
.FDefControl
))
621 g_ActiveWindow
.SetActive(nil);
623 if @g_ActiveWindow
.FOnShowEvent
<> nil then
624 g_ActiveWindow
.FOnShowEvent();
630 procedure g_GUI_HideWindow(PlaySound
: Boolean = True);
632 if g_ActiveWindow
<> nil then
634 if @g_ActiveWindow
.OnClose
<> nil then
635 g_ActiveWindow
.OnClose();
636 g_ActiveWindow
:= g_ActiveWindow
.FPrevWindow
;
638 g_Sound_PlayEx(WINDOW_CLOSESOUND
);
642 procedure g_GUI_SaveMenuPos();
647 SetLength(Saved_Windows
, 0);
648 win
:= g_ActiveWindow
;
652 len
:= Length(Saved_Windows
);
653 SetLength(Saved_Windows
, len
+ 1);
655 Saved_Windows
[len
] := win
.Name
;
657 if win
.MainWindow
then
660 win
:= win
.FPrevWindow
;
664 procedure g_GUI_LoadMenuPos();
666 i
, j
, k
, len
: Integer;
669 g_ActiveWindow
:= nil;
670 len
:= Length(Saved_Windows
);
675 // Îêíî ñ ãëàâíûì ìåíþ:
676 g_GUI_ShowWindow(Saved_Windows
[len
-1]);
678 // Íå ïåðåêëþ÷èëîñü (èëè íåêóäà äàëüøå):
679 if (len
= 1) or (g_ActiveWindow
= nil) then
682 // Èùåì êíîïêè â îñòàëüíûõ îêíàõ:
683 for k
:= len
-1 downto 1 do
687 for i
:= 0 to Length(g_ActiveWindow
.Childs
)-1 do
689 if g_ActiveWindow
.Childs
[i
] is TGUIMainMenu
then
690 begin // GUI_MainMenu
691 with TGUIMainMenu(g_ActiveWindow
.Childs
[i
]) do
692 for j
:= 0 to Length(FButtons
)-1 do
693 if FButtons
[j
].ShowWindow
= Saved_Windows
[k
-1] then
695 FButtons
[j
].Click(True);
701 if g_ActiveWindow
.Childs
[i
] is TGUIMenu
then
702 with TGUIMenu(g_ActiveWindow
.Childs
[i
]) do
703 for j
:= 0 to Length(FItems
)-1 do
704 if FItems
[j
].ControlType
= TGUITextButton
then
705 if TGUITextButton(FItems
[j
].Control
).ShowWindow
= Saved_Windows
[k
-1] then
707 TGUITextButton(FItems
[j
].Control
).Click(True);
718 (g_ActiveWindow
.Name
= Saved_Windows
[k
]) then
723 procedure DrawBox(X
, Y
: Integer; Width
, Height
: Word);
725 e_Draw(Box
[0], X
, Y
, 0, False, False);
726 e_DrawFill(Box
[1], X
+4, Y
, Width
*4, 1, 0, False, False);
727 e_Draw(Box
[2], X
+4+Width
*16, Y
, 0, False, False);
728 e_DrawFill(Box
[3], X
, Y
+4, 1, Height
*4, 0, False, False);
729 e_DrawFill(Box
[4], X
+4, Y
+4, Width
, Height
, 0, False, False);
730 e_DrawFill(Box
[5], X
+4+Width
*16, Y
+4, 1, Height
*4, 0, False, False);
731 e_Draw(Box
[6], X
, Y
+4+Height
*16, 0, False, False);
732 e_DrawFill(Box
[7], X
+4, Y
+4+Height
*16, Width
*4, 1, 0, False, False);
733 e_Draw(Box
[8], X
+4+Width
*16, Y
+4+Height
*16, 0, False, False);
736 procedure DrawScroll(X
, Y
: Integer; Height
: Word; Up
, Down
: Boolean);
740 if Height
< 3 then Exit
;
743 g_Texture_Get(BSCROLL_UPA
, ID
)
745 g_Texture_Get(BSCROLL_UPU
, ID
);
746 e_Draw(ID
, X
, Y
, 0, False, False);
749 g_Texture_Get(BSCROLL_DOWNA
, ID
)
751 g_Texture_Get(BSCROLL_DOWNU
, ID
);
752 e_Draw(ID
, X
, Y
+(Height
-1)*16, 0, False, False);
754 g_Texture_Get(BSCROLL_MIDDLE
, ID
);
755 e_DrawFill(ID
, X
, Y
+16, 1, Height
-2, 0, False, False);
760 constructor TGUIWindow
.Create(Name
: string);
763 FActiveControl
:= nil;
767 FOnCloseEvent
:= nil;
771 destructor TGUIWindow
.Destroy
;
778 for i
:= 0 to High(Childs
) do
782 function TGUIWindow
.AddChild(Child
: TGUIControl
): TGUIControl
;
784 Child
.FWindow
:= Self
;
786 SetLength(Childs
, Length(Childs
) + 1);
787 Childs
[High(Childs
)] := Child
;
792 procedure TGUIWindow
.Update
;
796 for i
:= 0 to High(Childs
) do
797 if Childs
[i
] <> nil then Childs
[i
].Update
;
800 procedure TGUIWindow
.Draw
;
805 if FBackTexture
<> '' then
806 if g_Texture_Get(FBackTexture
, ID
) then
807 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
809 e_Clear(GL_COLOR_BUFFER_BIT
, 0.5, 0.5, 0.5);
811 for i
:= 0 to High(Childs
) do
812 if Childs
[i
] <> nil then Childs
[i
].Draw
;
815 procedure TGUIWindow
.OnMessage(var Msg
: TMessage
);
817 if FActiveControl
<> nil then FActiveControl
.OnMessage(Msg
);
818 if @FOnKeyDown
<> nil then FOnKeyDown(Msg
.wParam
);
819 if @FOnKeyDownEx
<> nil then FOnKeyDownEx(self
, Msg
.wParam
);
821 if Msg
.Msg
= WM_KEYDOWN
then
822 if Msg
.wParam
= IK_ESCAPE
then
829 procedure TGUIWindow
.SetActive(Control
: TGUIControl
);
831 FActiveControl
:= Control
;
834 function TGUIWindow
.GetControl(Name
: String): TGUIControl
;
840 if Childs
<> nil then
841 for i
:= 0 to High(Childs
) do
842 if Childs
[i
] <> nil then
843 if LowerCase(Childs
[i
].FName
) = LowerCase(Name
) then
849 Assert(Result
<> nil, 'Window Control "'+Name
+'" not Found!');
854 constructor TGUIControl
.Create();
862 procedure TGUIControl
.OnMessage(var Msg
: TMessage
);
868 procedure TGUIControl
.Update();
872 procedure TGUIControl
.Draw();
876 function TGUIControl
.WantActivationKey (key
: LongInt): Boolean;
883 procedure TGUITextButton
.Click(Silent
: Boolean = False);
885 if (FSound
<> '') and (not Silent
) then g_Sound_PlayEx(FSound
);
887 if @Proc
<> nil then Proc();
888 if @ProcEx
<> nil then ProcEx(self
);
890 if FShowWindow
<> '' then g_GUI_ShowWindow(FShowWindow
);
893 constructor TGUITextButton
.Create(Proc
: Pointer; FontID
: DWORD
; Text: string);
900 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
905 destructor TGUITextButton
.Destroy
;
911 procedure TGUITextButton
.Draw
;
913 FFont
.Draw(FX
, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
)
916 function TGUITextButton
.GetHeight
: Integer;
920 FFont
.GetTextSize(FText
, w
, h
);
924 function TGUITextButton
.GetWidth
: Integer;
928 FFont
.GetTextSize(FText
, w
, h
);
932 procedure TGUITextButton
.OnMessage(var Msg
: TMessage
);
934 if not FEnabled
then Exit
;
941 IK_RETURN
, IK_KPRETURN
: Click();
946 procedure TGUITextButton
.Update
;
953 constructor TFont
.Create(FontID
: DWORD
; FontType
: TFontType
);
958 FFontType
:= FontType
;
961 destructor TFont
.Destroy
;
967 procedure TFont
.Draw(X
, Y
: Integer; Text: string; R
, G
, B
: Byte);
969 if FFontType
= FONT_CHAR
then e_CharFont_PrintEx(ID
, X
, Y
, Text, _RGB(R
, G
, B
), FScale
)
970 else e_TextureFontPrintEx(X
, Y
, Text, ID
, R
, G
, B
, FScale
);
973 procedure TFont
.GetTextSize(Text: string; var w
, h
: Word);
977 if FFontType
= FONT_CHAR
then e_CharFont_GetSize(ID
, Text, w
, h
)
980 e_TextureFontGetSize(ID
, cw
, ch
);
981 w
:= cw
*Length(Text);
985 w
:= Round(w
*FScale
);
986 h
:= Round(h
*FScale
);
991 function TGUIMainMenu
.AddButton(fProc
: Pointer; Caption
: string; ShowWindow
: string = ''): TGUITextButton
;
998 SetLength(FButtons
, Length(FButtons
)+1);
999 FButtons
[High(FButtons
)] := TGUITextButton
.Create(fProc
, FFontID
, Caption
);
1000 FButtons
[High(FButtons
)].ShowWindow
:= ShowWindow
;
1001 with FButtons
[High(FButtons
)] do
1003 if (fProc
<> nil) or (ShowWindow
<> '') then FColor
:= MAINMENU_ITEMS_COLOR
1004 else FColor
:= MAINMENU_UNACTIVEITEMS_COLOR
;
1005 FSound
:= MAINMENU_CLICKSOUND
;
1008 _x
:= gScreenWidth
div 2;
1010 for a
:= 0 to High(FButtons
) do
1011 if FButtons
[a
] <> nil then
1012 _x
:= Min(_x
, (gScreenWidth
div 2)-(FButtons
[a
].GetWidth
div 2));
1014 hh
:= FHeader
.GetHeight
;
1016 h
:= hh
*(2+Length(FButtons
))+MAINMENU_SPACE
*(Length(FButtons
)-1);
1017 h
:= (gScreenHeight
div 2)-(h
div 2);
1027 for a
:= 0 to High(FButtons
) do
1029 if FButtons
[a
] <> nil then
1036 Inc(h
, hh
+MAINMENU_SPACE
);
1039 Result
:= FButtons
[High(FButtons
)];
1042 procedure TGUIMainMenu
.AddSpace
;
1044 SetLength(FButtons
, Length(FButtons
)+1);
1045 FButtons
[High(FButtons
)] := nil;
1048 constructor TGUIMainMenu
.Create(FontID
: DWORD
; Header
: string);
1054 FCounter
:= MAINMENU_MARKERDELAY
;
1056 g_Texture_Get(MAINMENU_MARKER1
, FMarkerID1
);
1057 g_Texture_Get(MAINMENU_MARKER2
, FMarkerID2
);
1059 FHeader
:= TGUILabel
.Create(Header
, FFontID
);
1062 FColor
:= MAINMENU_HEADER_COLOR
;
1063 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1064 FY
:= (gScreenHeight
div 2)-(GetHeight
div 2);
1068 destructor TGUIMainMenu
.Destroy
;
1072 if FButtons
<> nil then
1073 for a
:= 0 to High(FButtons
) do
1081 procedure TGUIMainMenu
.Draw
;
1089 if FButtons
<> nil then
1091 for a
:= 0 to High(FButtons
) do
1092 if FButtons
[a
] <> nil then FButtons
[a
].Draw
;
1094 if FIndex
<> -1 then
1095 e_Draw(FMarkerID1
, FButtons
[FIndex
].FX
-48, FButtons
[FIndex
].FY
, 0, True, False);
1099 procedure TGUIMainMenu
.EnableButton(Name
: string; e
: Boolean);
1103 if FButtons
= nil then Exit
;
1105 for a
:= 0 to High(FButtons
) do
1106 if (FButtons
[a
] <> nil) and (FButtons
[a
].Name
= Name
) then
1108 if e
then FButtons
[a
].FColor
:= MAINMENU_ITEMS_COLOR
1109 else FButtons
[a
].FColor
:= MAINMENU_UNACTIVEITEMS_COLOR
;
1110 FButtons
[a
].Enabled
:= e
;
1115 function TGUIMainMenu
.GetButton(Name
: string): TGUITextButton
;
1121 if FButtons
= nil then Exit
;
1123 for a
:= 0 to High(FButtons
) do
1124 if (FButtons
[a
] <> nil) and (FButtons
[a
].Name
= Name
) then
1126 Result
:= FButtons
[a
];
1131 procedure TGUIMainMenu
.OnMessage(var Msg
: TMessage
);
1136 if not FEnabled
then Exit
;
1140 if FButtons
= nil then Exit
;
1143 for a
:= 0 to High(FButtons
) do
1144 if FButtons
[a
] <> nil then
1150 if not ok
then Exit
;
1159 if FIndex
< 0 then FIndex
:= High(FButtons
);
1160 until FButtons
[FIndex
] <> nil;
1162 g_Sound_PlayEx(MENU_CHANGESOUND
);
1168 if FIndex
> High(FButtons
) then FIndex
:= 0;
1169 until FButtons
[FIndex
] <> nil;
1171 g_Sound_PlayEx(MENU_CHANGESOUND
);
1173 IK_RETURN
, IK_KPRETURN
: if (FIndex
<> -1) and FButtons
[FIndex
].FEnabled
then FButtons
[FIndex
].Click
;
1178 procedure TGUIMainMenu
.Update
;
1184 if FCounter
= 0 then
1187 FMarkerID1
:= FMarkerID2
;
1190 FCounter
:= MAINMENU_MARKERDELAY
;
1191 end else Dec(FCounter
);
1196 constructor TGUILabel
.Create(Text: string; FontID
: DWORD
);
1200 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
1204 FOnClickEvent
:= nil;
1207 procedure TGUILabel
.Draw
;
1209 FFont
.Draw(FX
, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
);
1212 function TGUILabel
.GetHeight
: Integer;
1216 FFont
.GetTextSize(FText
, w
, h
);
1220 function TGUILabel
.GetWidth
: Integer;
1224 if FFixedLen
= 0 then
1225 FFont
.GetTextSize(FText
, w
, h
)
1227 w
:= e_CharFont_GetMaxWidth(FFont
.ID
)*FFixedLen
;
1231 procedure TGUILabel
.OnMessage(var Msg
: TMessage
);
1233 if not FEnabled
then Exit
;
1240 IK_RETURN
, IK_KPRETURN
: if @FOnClickEvent
<> nil then FOnClickEvent();
1247 function TGUIMenu
.AddButton(Proc
: Pointer; fText
: string; _ShowWindow
: string = ''): TGUITextButton
;
1254 Control
:= TGUITextButton
.Create(Proc
, FFontID
, fText
);
1255 with Control
as TGUITextButton
do
1257 ShowWindow
:= _ShowWindow
;
1258 FColor
:= MENU_ITEMSCTRL_COLOR
;
1262 ControlType
:= TGUITextButton
;
1264 Result
:= (Control
as TGUITextButton
);
1267 if FIndex
= -1 then FIndex
:= i
;
1272 procedure TGUIMenu
.AddLine(fText
: string);
1279 Text := TGUILabel
.Create(fText
, FFontID
);
1282 FColor
:= MENU_ITEMSTEXT_COLOR
;
1291 procedure TGUIMenu
.AddText(fText
: string; MaxWidth
: Word);
1296 l
:= GetLines(fText
, FFontID
, MaxWidth
);
1298 if l
= nil then Exit
;
1300 for a
:= 0 to High(l
) do
1305 Text := TGUILabel
.Create(l
[a
], FFontID
);
1308 with Text do begin FColor
:= _RGB(255, 0, 0); end;
1312 with Text do begin FColor
:= MENU_ITEMSTEXT_COLOR
; end;
1322 procedure TGUIMenu
.AddSpace
;
1336 constructor TGUIMenu
.Create(HeaderFont
, ItemsFont
: DWORD
; Header
: string);
1342 FFontID
:= ItemsFont
;
1343 FCounter
:= MENU_MARKERDELAY
;
1347 FHeader
:= TGUILabel
.Create(Header
, HeaderFont
);
1350 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1352 FColor
:= MAINMENU_HEADER_COLOR
;
1356 destructor TGUIMenu
.Destroy
;
1360 if FItems
<> nil then
1361 for a
:= 0 to High(FItems
) do
1375 procedure TGUIMenu
.Draw
;
1381 if FHeader
<> nil then FHeader
.Draw
;
1383 if FItems
<> nil then
1384 for a
:= 0 to High(FItems
) do
1386 if FItems
[a
].Text <> nil then FItems
[a
].Text.Draw
;
1387 if FItems
[a
].Control
<> nil then FItems
[a
].Control
.Draw
;
1390 if (FIndex
<> -1) and (FCounter
> MENU_MARKERDELAY
div 2) then
1395 if FItems
[FIndex
].Text <> nil then
1397 x
:= FItems
[FIndex
].Text.FX
;
1398 y
:= FItems
[FIndex
].Text.FY
;
1400 else if FItems
[FIndex
].Control
<> nil then
1402 x
:= FItems
[FIndex
].Control
.FX
;
1403 y
:= FItems
[FIndex
].Control
.FY
;
1406 x
:= x
-e_CharFont_GetMaxWidth(FFontID
);
1408 e_CharFont_PrintEx(FFontID
, x
, y
, #16, _RGB(255, 0, 0));
1412 function TGUIMenu
.GetControl(Name
: String): TGUIControl
;
1418 if FItems
<> nil then
1419 for a
:= 0 to High(FItems
) do
1420 if FItems
[a
].Control
<> nil then
1421 if LowerCase(FItems
[a
].Control
.Name
) = LowerCase(Name
) then
1423 Result
:= FItems
[a
].Control
;
1427 Assert(Result
<> nil, 'GUI control "'+Name
+'" not found!');
1430 function TGUIMenu
.GetControlsText(Name
: String): TGUILabel
;
1436 if FItems
<> nil then
1437 for a
:= 0 to High(FItems
) do
1438 if FItems
[a
].Control
<> nil then
1439 if LowerCase(FItems
[a
].Control
.Name
) = LowerCase(Name
) then
1441 Result
:= FItems
[a
].Text;
1445 Assert(Result
<> nil, 'GUI control''s text "'+Name
+'" not found!');
1448 function TGUIMenu
.NewItem
: Integer;
1450 SetLength(FItems
, Length(FItems
)+1);
1451 Result
:= High(FItems
);
1454 procedure TGUIMenu
.OnMessage(var Msg
: TMessage
);
1459 if not FEnabled
then Exit
;
1463 if FItems
= nil then Exit
;
1466 for a
:= 0 to High(FItems
) do
1467 if FItems
[a
].Control
<> nil then
1473 if not ok
then Exit
;
1475 if (Msg
.Msg
= WM_KEYDOWN
) and (FIndex
<> -1) and (FItems
[FIndex
].Control
<> nil) and
1476 (FItems
[FIndex
].Control
.WantActivationKey(Msg
.wParam
)) then
1478 FItems
[FIndex
].Control
.OnMessage(Msg
);
1479 g_Sound_PlayEx(MENU_CLICKSOUND
);
1492 if c
> Length(FItems
) then
1499 if FIndex
< 0 then FIndex
:= High(FItems
);
1500 until (FItems
[FIndex
].Control
<> nil) and
1501 (FItems
[FIndex
].Control
.Enabled
);
1505 g_Sound_PlayEx(MENU_CHANGESOUND
);
1513 if c
> Length(FItems
) then
1520 if FIndex
> High(FItems
) then FIndex
:= 0;
1521 until (FItems
[FIndex
].Control
<> nil) and
1522 (FItems
[FIndex
].Control
.Enabled
);
1526 g_Sound_PlayEx(MENU_CHANGESOUND
);
1529 IK_LEFT
, IK_RIGHT
, IK_KPLEFT
, IK_KPRIGHT
:
1531 if FIndex
<> -1 then
1532 if FItems
[FIndex
].Control
<> nil then
1533 FItems
[FIndex
].Control
.OnMessage(Msg
);
1535 IK_RETURN
, IK_KPRETURN
:
1537 if FIndex
<> -1 then
1539 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1541 g_Sound_PlayEx(MENU_CLICKSOUND
);
1545 if FYesNo
and (length(FItems
) > 1) then
1547 Msg
.wParam
:= IK_RETURN
; // to register keypress
1548 FIndex
:= High(FItems
)-1;
1549 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1552 if FYesNo
and (length(FItems
) > 1) then
1554 Msg
.wParam
:= IK_RETURN
; // to register keypress
1555 FIndex
:= High(FItems
);
1556 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1563 procedure TGUIMenu
.ReAlign();
1565 a
, tx
, cx
, w
, h
: Integer;
1567 if FItems
= nil then Exit
;
1569 if not FAlign
then tx
:= FLeft
else
1572 for a
:= 0 to High(FItems
) do
1575 if FItems
[a
].Text <> nil then w
:= FItems
[a
].Text.GetWidth
;
1576 if FItems
[a
].Control
<> nil then
1580 if FItems
[a
].ControlType
= TGUILabel
then
1581 w
:= w
+(FItems
[a
].Control
as TGUILabel
).GetWidth
1582 else if FItems
[a
].ControlType
= TGUITextButton
then
1583 w
:= w
+(FItems
[a
].Control
as TGUITextButton
).GetWidth
1584 else if FItems
[a
].ControlType
= TGUIScroll
then
1585 w
:= w
+(FItems
[a
].Control
as TGUIScroll
).GetWidth
1586 else if FItems
[a
].ControlType
= TGUISwitch
then
1587 w
:= w
+(FItems
[a
].Control
as TGUISwitch
).GetWidth
1588 else if FItems
[a
].ControlType
= TGUIEdit
then
1589 w
:= w
+(FItems
[a
].Control
as TGUIEdit
).GetWidth
1590 else if FItems
[a
].ControlType
= TGUIKeyRead
then
1591 w
:= w
+(FItems
[a
].Control
as TGUIKeyRead
).GetWidth
1592 else if FItems
[a
].ControlType
= TGUIKeyRead2
then
1593 w
:= w
+(FItems
[a
].Control
as TGUIKeyRead2
).GetWidth
1594 else if (FItems
[a
].ControlType
= TGUIListBox
) then
1595 w
:= w
+(FItems
[a
].Control
as TGUIListBox
).GetWidth
1596 else if (FItems
[a
].ControlType
= TGUIFileListBox
) then
1597 w
:= w
+(FItems
[a
].Control
as TGUIFileListBox
).GetWidth
1598 else if FItems
[a
].ControlType
= TGUIMemo
then
1599 w
:= w
+(FItems
[a
].Control
as TGUIMemo
).GetWidth
;
1602 tx
:= Min(tx
, (gScreenWidth
div 2)-(w
div 2));
1607 for a
:= 0 to High(FItems
) do
1611 if (Text <> nil) and (Control
= nil) then Continue
;
1613 if Text <> nil then w
:= tx
+Text.GetWidth
;
1614 if w
> cx
then cx
:= w
;
1618 cx
:= cx
+MENU_HSPACE
;
1620 h
:= FHeader
.GetHeight
*2+MENU_VSPACE
*(Length(FItems
)-1);
1622 for a
:= 0 to High(FItems
) do
1626 if (ControlType
= TGUIListBox
) or (ControlType
= TGUIFileListBox
) then
1627 h
:= h
+(FItems
[a
].Control
as TGUIListBox
).GetHeight()
1629 h
:= h
+e_CharFont_GetMaxHeight(FFontID
);
1633 h
:= (gScreenHeight
div 2)-(h
div 2);
1637 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1640 Inc(h
, GetHeight
*2);
1643 for a
:= 0 to High(FItems
) do
1653 if Control
<> nil then
1666 if (ControlType
= TGUIListBox
) or (ControlType
= TGUIFileListBox
) then
1667 Inc(h
, (Control
as TGUIListBox
).GetHeight
+MENU_VSPACE
)
1668 else if ControlType
= TGUIMemo
then
1669 Inc(h
, (Control
as TGUIMemo
).GetHeight
+MENU_VSPACE
)
1671 Inc(h
, e_CharFont_GetMaxHeight(FFontID
)+MENU_VSPACE
);
1674 // another ugly hack
1675 if FYesNo
and (length(FItems
) > 1) then
1678 for a
:= High(FItems
)-1 to High(FItems
) do
1680 if (FItems
[a
].Control
<> nil) and (FItems
[a
].ControlType
= TGUITextButton
) then
1682 cx
:= (FItems
[a
].Control
as TGUITextButton
).GetWidth
;
1683 if cx
> w
then w
:= cx
;
1688 for a
:= High(FItems
)-1 to High(FItems
) do
1690 if (FItems
[a
].Control
<> nil) and (FItems
[a
].ControlType
= TGUITextButton
) then
1692 FItems
[a
].Control
.FX
:= (gScreenWidth
-w
) div 2;
1699 function TGUIMenu
.AddScroll(fText
: string): TGUIScroll
;
1706 Control
:= TGUIScroll
.Create();
1708 Text := TGUILabel
.Create(fText
, FFontID
);
1711 FColor
:= MENU_ITEMSTEXT_COLOR
;
1714 ControlType
:= TGUIScroll
;
1716 Result
:= (Control
as TGUIScroll
);
1719 if FIndex
= -1 then FIndex
:= i
;
1724 function TGUIMenu
.AddSwitch(fText
: string): TGUISwitch
;
1731 Control
:= TGUISwitch
.Create(FFontID
);
1732 (Control
as TGUISwitch
).FColor
:= MENU_ITEMSCTRL_COLOR
;
1734 Text := TGUILabel
.Create(fText
, FFontID
);
1737 FColor
:= MENU_ITEMSTEXT_COLOR
;
1740 ControlType
:= TGUISwitch
;
1742 Result
:= (Control
as TGUISwitch
);
1745 if FIndex
= -1 then FIndex
:= i
;
1750 function TGUIMenu
.AddEdit(fText
: string): TGUIEdit
;
1757 Control
:= TGUIEdit
.Create(FFontID
);
1758 with Control
as TGUIEdit
do
1760 FWindow
:= Self
.FWindow
;
1761 FColor
:= MENU_ITEMSCTRL_COLOR
;
1764 if fText
= '' then Text := nil else
1766 Text := TGUILabel
.Create(fText
, FFontID
);
1767 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
1770 ControlType
:= TGUIEdit
;
1772 Result
:= (Control
as TGUIEdit
);
1775 if FIndex
= -1 then FIndex
:= i
;
1780 procedure TGUIMenu
.Update
;
1786 if FCounter
= 0 then FCounter
:= MENU_MARKERDELAY
else Dec(FCounter
);
1788 if FItems
<> nil then
1789 for a
:= 0 to High(FItems
) do
1790 if FItems
[a
].Control
<> nil then
1791 (FItems
[a
].Control
as FItems
[a
].ControlType
).Update
;
1794 function TGUIMenu
.AddKeyRead(fText
: string): TGUIKeyRead
;
1801 Control
:= TGUIKeyRead
.Create(FFontID
);
1802 with Control
as TGUIKeyRead
do
1804 FWindow
:= Self
.FWindow
;
1805 FColor
:= MENU_ITEMSCTRL_COLOR
;
1808 Text := TGUILabel
.Create(fText
, FFontID
);
1811 FColor
:= MENU_ITEMSTEXT_COLOR
;
1814 ControlType
:= TGUIKeyRead
;
1816 Result
:= (Control
as TGUIKeyRead
);
1819 if FIndex
= -1 then FIndex
:= i
;
1824 function TGUIMenu
.AddKeyRead2(fText
: string): TGUIKeyRead2
;
1831 Control
:= TGUIKeyRead2
.Create(FFontID
);
1832 with Control
as TGUIKeyRead2
do
1834 FWindow
:= Self
.FWindow
;
1835 FColor
:= MENU_ITEMSCTRL_COLOR
;
1838 Text := TGUILabel
.Create(fText
, FFontID
);
1841 FColor
:= MENU_ITEMSTEXT_COLOR
;
1844 ControlType
:= TGUIKeyRead2
;
1846 Result
:= (Control
as TGUIKeyRead2
);
1849 if FIndex
= -1 then FIndex
:= i
;
1854 function TGUIMenu
.AddList(fText
: string; Width
, Height
: Word): TGUIListBox
;
1861 Control
:= TGUIListBox
.Create(FFontID
, Width
, Height
);
1862 with Control
as TGUIListBox
do
1864 FWindow
:= Self
.FWindow
;
1865 FActiveColor
:= MENU_ITEMSCTRL_COLOR
;
1866 FUnActiveColor
:= MENU_ITEMSTEXT_COLOR
;
1869 Text := TGUILabel
.Create(fText
, FFontID
);
1872 FColor
:= MENU_ITEMSTEXT_COLOR
;
1875 ControlType
:= TGUIListBox
;
1877 Result
:= (Control
as TGUIListBox
);
1880 if FIndex
= -1 then FIndex
:= i
;
1885 function TGUIMenu
.AddFileList(fText
: string; Width
, Height
: Word): TGUIFileListBox
;
1892 Control
:= TGUIFileListBox
.Create(FFontID
, Width
, Height
);
1893 with Control
as TGUIFileListBox
do
1895 FWindow
:= Self
.FWindow
;
1896 FActiveColor
:= MENU_ITEMSCTRL_COLOR
;
1897 FUnActiveColor
:= MENU_ITEMSTEXT_COLOR
;
1900 if fText
= '' then Text := nil else
1902 Text := TGUILabel
.Create(fText
, FFontID
);
1903 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
1906 ControlType
:= TGUIFileListBox
;
1908 Result
:= (Control
as TGUIFileListBox
);
1911 if FIndex
= -1 then FIndex
:= i
;
1916 function TGUIMenu
.AddLabel(fText
: string): TGUILabel
;
1923 Control
:= TGUILabel
.Create('', FFontID
);
1924 with Control
as TGUILabel
do
1926 FWindow
:= Self
.FWindow
;
1927 FColor
:= MENU_ITEMSCTRL_COLOR
;
1930 Text := TGUILabel
.Create(fText
, FFontID
);
1933 FColor
:= MENU_ITEMSTEXT_COLOR
;
1936 ControlType
:= TGUILabel
;
1938 Result
:= (Control
as TGUILabel
);
1941 if FIndex
= -1 then FIndex
:= i
;
1946 function TGUIMenu
.AddMemo(fText
: string; Width
, Height
: Word): TGUIMemo
;
1953 Control
:= TGUIMemo
.Create(FFontID
, Width
, Height
);
1954 with Control
as TGUIMemo
do
1956 FWindow
:= Self
.FWindow
;
1957 FColor
:= MENU_ITEMSTEXT_COLOR
;
1960 if fText
= '' then Text := nil else
1962 Text := TGUILabel
.Create(fText
, FFontID
);
1963 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
1966 ControlType
:= TGUIMemo
;
1968 Result
:= (Control
as TGUIMemo
);
1971 if FIndex
= -1 then FIndex
:= i
;
1976 procedure TGUIMenu
.UpdateIndex();
1984 if (FIndex
< 0) or (FIndex
> High(FItems
)) then
1990 if FItems
[FIndex
].Control
.Enabled
then
1999 constructor TGUIScroll
.Create
;
2004 FOnChangeEvent
:= nil;
2006 g_Texture_Get(SCROLL_LEFT
, FLeftID
);
2007 g_Texture_Get(SCROLL_RIGHT
, FRightID
);
2008 g_Texture_Get(SCROLL_MIDDLE
, FMiddleID
);
2009 g_Texture_Get(SCROLL_MARKER
, FMarkerID
);
2012 procedure TGUIScroll
.Draw
;
2018 e_Draw(FLeftID
, FX
, FY
, 0, True, False);
2019 e_Draw(FRightID
, FX
+8+(FMax
+1)*8, FY
, 0, True, False);
2021 for a
:= 0 to FMax
do
2022 e_Draw(FMiddleID
, FX
+8+a
*8, FY
, 0, True, False);
2024 e_Draw(FMarkerID
, FX
+8+FValue
*8, FY
, 0, True, False);
2027 procedure TGUIScroll
.FSetValue(a
: Integer);
2029 if a
> FMax
then FValue
:= FMax
else FValue
:= a
;
2032 function TGUIScroll
.GetWidth
: Word;
2034 Result
:= 16+(FMax
+1)*8;
2037 procedure TGUIScroll
.OnMessage(var Msg
: TMessage
);
2039 if not FEnabled
then Exit
;
2051 g_Sound_PlayEx(SCROLL_SUBSOUND
);
2052 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2054 IK_RIGHT
, IK_KPRIGHT
:
2055 if FValue
< FMax
then
2058 g_Sound_PlayEx(SCROLL_ADDSOUND
);
2059 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2066 procedure TGUIScroll
.Update
;
2074 procedure TGUISwitch
.AddItem(Item
: string);
2076 SetLength(FItems
, Length(FItems
)+1);
2077 FItems
[High(FItems
)] := Item
;
2079 if FIndex
= -1 then FIndex
:= 0;
2082 constructor TGUISwitch
.Create(FontID
: DWORD
);
2088 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
2091 procedure TGUISwitch
.Draw
;
2095 FFont
.Draw(FX
, FY
, FItems
[FIndex
], FColor
.R
, FColor
.G
, FColor
.B
);
2098 function TGUISwitch
.GetText
: string;
2100 if FIndex
<> -1 then Result
:= FItems
[FIndex
]
2104 function TGUISwitch
.GetWidth
: Word;
2111 if FItems
= nil then Exit
;
2113 for a
:= 0 to High(FItems
) do
2115 FFont
.GetTextSize(FItems
[a
], w
, h
);
2116 if w
> Result
then Result
:= w
;
2120 procedure TGUISwitch
.OnMessage(var Msg
: TMessage
);
2122 if not FEnabled
then Exit
;
2126 if FItems
= nil then Exit
;
2131 IK_RETURN
, IK_RIGHT
, IK_KPRETURN
, IK_KPRIGHT
:
2133 if FIndex
< High(FItems
) then
2138 if @FOnChangeEvent
<> nil then
2139 FOnChangeEvent(Self
);
2147 FIndex
:= High(FItems
);
2149 if @FOnChangeEvent
<> nil then
2150 FOnChangeEvent(Self
);
2156 procedure TGUISwitch
.Update
;
2164 constructor TGUIEdit
.Create(FontID
: DWORD
);
2168 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
2173 g_Texture_Get(EDIT_LEFT
, FLeftID
);
2174 g_Texture_Get(EDIT_RIGHT
, FRightID
);
2175 g_Texture_Get(EDIT_MIDDLE
, FMiddleID
);
2178 procedure TGUIEdit
.Draw
;
2184 e_Draw(FLeftID
, FX
, FY
, 0, True, False);
2185 e_Draw(FRightID
, FX
+8+FWidth
*16, FY
, 0, True, False);
2187 for c
:= 0 to FWidth
-1 do
2188 e_Draw(FMiddleID
, FX
+8+c
*16, FY
, 0, True, False);
2190 FFont
.Draw(FX
+8, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
);
2192 if FWindow
.FActiveControl
= Self
then
2194 FFont
.GetTextSize(Copy(FText
, 1, FCaretPos
), w
, h
);
2195 h
:= e_CharFont_GetMaxHeight(FFont
.ID
);
2196 e_DrawLine(2, FX
+8+w
, FY
+h
-3, FX
+8+w
+EDIT_CURSORLEN
, FY
+h
-3,
2197 EDIT_CURSORCOLOR
.R
, EDIT_CURSORCOLOR
.G
, EDIT_CURSORCOLOR
.B
);
2201 function TGUIEdit
.GetWidth
: Word;
2203 Result
:= 16+FWidth
*16;
2206 procedure TGUIEdit
.OnMessage(var Msg
: TMessage
);
2208 if not FEnabled
then Exit
;
2217 if (wParam
in [48..57]) and (Chr(wParam
) <> '`') then
2218 if Length(Text) < FMaxLength
then
2220 Insert(Chr(wParam
), FText
, FCaretPos
+ 1);
2226 if (wParam
in [32..255]) and (Chr(wParam
) <> '`') then
2227 if Length(Text) < FMaxLength
then
2229 Insert(Chr(wParam
), FText
, FCaretPos
+ 1);
2237 Delete(FText
, FCaretPos
, 1);
2238 if FCaretPos
> 0 then Dec(FCaretPos
);
2240 IK_DELETE
: Delete(FText
, FCaretPos
+ 1, 1);
2241 IK_END
, IK_KPEND
: FCaretPos
:= Length(FText
);
2242 IK_HOME
, IK_KPHOME
: FCaretPos
:= 0;
2243 IK_LEFT
, IK_KPLEFT
: if FCaretPos
> 0 then Dec(FCaretPos
);
2244 IK_RIGHT
, IK_KPRIGHT
: if FCaretPos
< Length(FText
) then Inc(FCaretPos
);
2245 IK_RETURN
, IK_KPRETURN
:
2248 if FActiveControl
<> Self
then
2251 if @FOnEnterEvent
<> nil then FOnEnterEvent(Self
);
2255 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
2256 else SetActive(nil);
2257 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2264 procedure TGUIEdit
.SetText(Text: string);
2266 if Length(Text) > FMaxLength
then SetLength(Text, FMaxLength
);
2268 FCaretPos
:= Length(FText
);
2271 procedure TGUIEdit
.Update
;
2278 constructor TGUIKeyRead
.Create(FontID
: DWORD
);
2284 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
2287 procedure TGUIKeyRead
.Draw
;
2291 FFont
.Draw(FX
, FY
, IfThen(FIsQuery
, KEYREAD_QUERY
, IfThen(FKey
<> 0, e_KeyNames
[FKey
], KEYREAD_CLEAR
)),
2292 FColor
.R
, FColor
.G
, FColor
.B
);
2295 function TGUIKeyRead
.GetWidth
: Word;
2302 for a
:= 0 to 255 do
2304 FFont
.GetTextSize(e_KeyNames
[a
], w
, h
);
2305 Result
:= Max(Result
, w
);
2308 FFont
.GetTextSize(KEYREAD_QUERY
, w
, h
);
2309 if w
> Result
then Result
:= w
;
2311 FFont
.GetTextSize(KEYREAD_CLEAR
, w
, h
);
2312 if w
> Result
then Result
:= w
;
2315 function TGUIKeyRead
.WantActivationKey (key
: LongInt): Boolean;
2318 (key
= IK_BACKSPACE
) or
2322 procedure TGUIKeyRead
.OnMessage(var Msg
: TMessage
);
2323 procedure actDefCtl ();
2326 if FDefControl
<> '' then
2327 SetActive(GetControl(FDefControl
))
2335 if not FEnabled
then
2344 if FIsQuery
then actDefCtl();
2347 IK_RETURN
, IK_KPRETURN
:
2349 if not FIsQuery
then
2352 if FActiveControl
<> Self
then
2359 FKey
:= IK_ENTER
; // <Enter>
2364 IK_BACKSPACE
: // clear keybinding if we aren't waiting for a key
2366 if not FIsQuery
then
2376 if not FIsQuery
and (wParam
= IK_BACKSPACE
) then
2381 else if FIsQuery
and (wParam
<> IK_ENTER
) and (wParam
<> IK_KPRETURN
) then // Not <Enter
2383 if e_KeyNames
[wParam
] <> '' then
2394 constructor TGUIKeyRead2
.Create(FontID
: DWORD
);
2407 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
2409 FMaxKeyNameWdt
:= 0;
2410 for a
:= 0 to 255 do
2412 FFont
.GetTextSize(e_KeyNames
[a
], w
, h
);
2413 FMaxKeyNameWdt
:= Max(FMaxKeyNameWdt
, w
);
2416 FFont
.GetTextSize(KEYREAD_QUERY
, w
, h
);
2417 if w
> FMaxKeyNameWdt
then FMaxKeyNameWdt
:= w
;
2419 FFont
.GetTextSize(KEYREAD_CLEAR
, w
, h
);
2420 if w
> FMaxKeyNameWdt
then FMaxKeyNameWdt
:= w
;
2423 procedure TGUIKeyRead2
.Draw
;
2424 procedure drawText (idx
: Integer);
2430 if idx
= 0 then kk
:= FKey0
else kk
:= FKey1
;
2432 if idx
= 0 then x
:= FX
+8 else x
:= FX
+8+FMaxKeyNameWdt
+16;
2436 if FKeyIdx
= idx
then g
:= 127;
2437 if FIsQuery
and (FKeyIdx
= idx
) then
2438 FFont
.Draw(x
, y
, KEYREAD_QUERY
, r
, g
, b
)
2440 FFont
.Draw(x
, y
, IfThen(kk
<> 0, e_KeyNames
[kk
], KEYREAD_CLEAR
), r
, g
, b
);
2446 //FFont.Draw(FX+8, FY, IfThen(FIsQuery and (FKeyIdx = 0), KEYREAD_QUERY, IfThen(FKey0 <> 0, e_KeyNames[FKey0], KEYREAD_CLEAR)), FColor.R, FColor.G, FColor.B);
2447 //FFont.Draw(FX+8+FMaxKeyNameWdt+16, FY, IfThen(FIsQuery and (FKeyIdx = 1), KEYREAD_QUERY, IfThen(FKey1 <> 0, e_KeyNames[FKey1], KEYREAD_CLEAR)), FColor.R, FColor.G, FColor.B);
2452 function TGUIKeyRead2
.GetWidth
: Word;
2454 Result
:= FMaxKeyNameWdt
*2+8+8+16;
2457 function TGUIKeyRead2
.WantActivationKey (key
: LongInt): Boolean;
2460 (key
= IK_BACKSPACE
) or
2461 (key
= IK_LEFT
) or (key
= IK_RIGHT
) or
2462 (key
= IK_KPLEFT
) or (key
= IK_KPRIGHT
) or
2466 procedure TGUIKeyRead2
.OnMessage(var Msg
: TMessage
);
2467 procedure actDefCtl ();
2470 if FDefControl
<> '' then
2471 SetActive(GetControl(FDefControl
))
2479 if not FEnabled
then
2488 if FIsQuery
then actDefCtl();
2491 IK_RETURN
, IK_KPRETURN
:
2493 if not FIsQuery
then
2496 if FActiveControl
<> Self
then
2503 if (FKeyIdx
= 0) then FKey0
:= IK_ENTER
else FKey1
:= IK_ENTER
; // <Enter>
2508 IK_BACKSPACE
: // clear keybinding if we aren't waiting for a key
2510 if not FIsQuery
then
2512 if (FKeyIdx
= 0) then FKey0
:= 0 else FKey1
:= 0;
2517 if not FIsQuery
then
2522 IK_RIGHT
, IK_KPRIGHT
:
2523 if not FIsQuery
then
2532 if not FIsQuery
and (wParam
= IK_BACKSPACE
) then
2534 if (FKeyIdx
= 0) then FKey0
:= 0 else FKey1
:= 0;
2537 else if FIsQuery
and (wParam
<> IK_ENTER
) and (wParam
<> IK_KPRETURN
) then // Not <Enter
2539 if e_KeyNames
[wParam
] <> '' then
2541 if (FKeyIdx
= 0) then FKey0
:= wParam
else FKey1
:= wParam
;
2553 constructor TGUIModelView
.Create
;
2560 destructor TGUIModelView
.Destroy
;
2567 procedure TGUIModelView
.Draw
;
2571 DrawBox(FX
, FY
, 4, 4);
2573 if FModel
<> nil then FModel
.Draw(FX
+4, FY
+4);
2576 procedure TGUIModelView
.NextAnim();
2578 if FModel
= nil then
2581 if FModel
.Animation
< A_PAIN
then
2582 FModel
.ChangeAnimation(FModel
.Animation
+1, True)
2584 FModel
.ChangeAnimation(A_STAND
, True);
2587 procedure TGUIModelView
.NextWeapon();
2589 if FModel
= nil then
2592 if FModel
.Weapon
< WEAPON_SUPERPULEMET
then
2593 FModel
.SetWeapon(FModel
.Weapon
+1)
2595 FModel
.SetWeapon(WEAPON_KASTET
);
2598 procedure TGUIModelView
.OnMessage(var Msg
: TMessage
);
2604 procedure TGUIModelView
.SetColor(Red
, Green
, Blue
: Byte);
2606 if FModel
<> nil then FModel
.SetColor(Red
, Green
, Blue
);
2609 procedure TGUIModelView
.SetModel(ModelName
: string);
2613 FModel
:= g_PlayerModel_Get(ModelName
);
2616 procedure TGUIModelView
.Update
;
2623 if FModel
<> nil then FModel
.Update
;
2628 constructor TGUIMapPreview
.Create();
2634 destructor TGUIMapPreview
.Destroy();
2640 procedure TGUIMapPreview
.Draw();
2647 DrawBox(FX
, FY
, MAPPREVIEW_WIDTH
, MAPPREVIEW_HEIGHT
);
2649 if (FMapSize
.X
<= 0) or (FMapSize
.Y
<= 0) then
2652 e_DrawFillQuad(FX
+4, FY
+4,
2653 FX
+4 + Trunc(FMapSize
.X
/ FScale
) - 1,
2654 FY
+4 + Trunc(FMapSize
.Y
/ FScale
) - 1,
2657 if FMapData
<> nil then
2658 for a
:= 0 to High(FMapData
) do
2661 if X1
> MAPPREVIEW_WIDTH
*16 then Continue
;
2662 if Y1
> MAPPREVIEW_HEIGHT
*16 then Continue
;
2664 if X2
< 0 then Continue
;
2665 if Y2
< 0 then Continue
;
2667 if X2
> MAPPREVIEW_WIDTH
*16 then X2
:= MAPPREVIEW_WIDTH
*16;
2668 if Y2
> MAPPREVIEW_HEIGHT
*16 then Y2
:= MAPPREVIEW_HEIGHT
*16;
2670 if X1
< 0 then X1
:= 0;
2671 if Y1
< 0 then Y1
:= 0;
2712 if ((X2
-X1
) > 0) and ((Y2
-Y1
) > 0) then
2713 e_DrawFillQuad(FX
+4 + X1
, FY
+4 + Y1
,
2714 FX
+4 + X2
- 1, FY
+4 + Y2
- 1, r
, g
, b
, 0);
2718 procedure TGUIMapPreview
.OnMessage(var Msg
: TMessage
);
2724 procedure TGUIMapPreview
.SetMap(Res
: string);
2727 MapReader
: TMapReader_1
;
2728 panels
: TPanelsRec1Array
;
2729 header
: TMapHeaderRec_1
;
2736 FileName
:= g_ExtractWadName(Res
);
2738 WAD
:= TWADFile
.Create();
2739 if not WAD
.ReadFile(FileName
) then
2745 //k8: ignores path again
2746 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
2754 MapReader
:= TMapReader_1
.Create();
2756 if not MapReader
.LoadMap(Data
) then
2769 panels
:= MapReader
.GetPanels();
2770 header
:= MapReader
.GetMapHeader();
2772 FMapSize
.X
:= header
.Width
div 16;
2773 FMapSize
.Y
:= header
.Height
div 16;
2775 rX
:= Ceil(header
.Width
/ (MAPPREVIEW_WIDTH
*256.0));
2776 rY
:= Ceil(header
.Height
/ (MAPPREVIEW_HEIGHT
*256.0));
2777 FScale
:= max(rX
, rY
);
2781 if panels
<> nil then
2782 for a
:= 0 to High(panels
) do
2783 if WordBool(panels
[a
].PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or
2784 PANEL_STEP
or PANEL_WATER
or
2785 PANEL_ACID1
or PANEL_ACID2
)) then
2787 SetLength(FMapData
, Length(FMapData
)+1);
2788 with FMapData
[High(FMapData
)] do
2790 X1
:= panels
[a
].X
div 16;
2791 Y1
:= panels
[a
].Y
div 16;
2793 X2
:= (panels
[a
].X
+ panels
[a
].Width
) div 16;
2794 Y2
:= (panels
[a
].Y
+ panels
[a
].Height
) div 16;
2796 X1
:= Trunc(X1
/FScale
+ 0.5);
2797 Y1
:= Trunc(Y1
/FScale
+ 0.5);
2798 X2
:= Trunc(X2
/FScale
+ 0.5);
2799 Y2
:= Trunc(Y2
/FScale
+ 0.5);
2801 if (X1
<> X2
) or (Y1
<> Y2
) then
2809 PanelType
:= panels
[a
].PanelType
;
2818 procedure TGUIMapPreview
.ClearMap();
2820 SetLength(FMapData
, 0);
2827 procedure TGUIMapPreview
.Update();
2833 function TGUIMapPreview
.GetScaleStr(): String;
2835 if FScale
> 0.0 then
2837 Result
:= FloatToStrF(FScale
*16.0, ffFixed
, 3, 3);
2838 while (Result
[Length(Result
)] = '0') do
2839 Delete(Result
, Length(Result
), 1);
2840 if (Result
[Length(Result
)] = ',') or (Result
[Length(Result
)] = '.') then
2841 Delete(Result
, Length(Result
), 1);
2842 Result
:= '1 : ' + Result
;
2850 procedure TGUIListBox
.AddItem(Item
: string);
2852 SetLength(FItems
, Length(FItems
)+1);
2853 FItems
[High(FItems
)] := Item
;
2855 if FSort
then g_Basic
.Sort(FItems
);
2858 procedure TGUIListBox
.Clear();
2866 constructor TGUIListBox
.Create(FontID
: DWORD
; Width
, Height
: Word);
2870 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
2875 FOnChangeEvent
:= nil;
2877 FDrawScroll
:= True;
2880 procedure TGUIListBox
.Draw
;
2888 if FDrawBack
then DrawBox(FX
, FY
, FWidth
+1, FHeight
);
2890 DrawScroll(FX
+4+FWidth
*16, FY
+4, FHeight
, (FStartLine
> 0) and (FItems
<> nil),
2891 (FStartLine
+FHeight
-1 < High(FItems
)) and (FItems
<> nil));
2893 if FItems
<> nil then
2894 for a
:= FStartLine
to Min(High(FItems
), FStartLine
+FHeight
-1) do
2898 FFont
.GetTextSize(s
, w2
, h2
);
2899 while (Length(s
) > 0) and (w2
> FWidth
*16) do
2901 SetLength(s
, Length(s
)-1);
2902 FFont
.GetTextSize(s
, w2
, h2
);
2906 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, s
, FActiveColor
.R
, FActiveColor
.G
, FActiveColor
.B
)
2908 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, s
, FUnActiveColor
.R
, FUnActiveColor
.G
, FUnActiveColor
.B
);
2912 function TGUIListBox
.GetHeight
: Word;
2914 Result
:= 8+FHeight
*16;
2917 function TGUIListBox
.GetWidth
: Word;
2919 Result
:= 8+(FWidth
+1)*16;
2922 procedure TGUIListBox
.OnMessage(var Msg
: TMessage
);
2926 if not FEnabled
then Exit
;
2930 if FItems
= nil then Exit
;
2943 FIndex
:= High(FItems
);
2944 FStartLine
:= Max(High(FItems
)-FHeight
+1, 0);
2946 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
:
2950 if FIndex
< FStartLine
then Dec(FStartLine
);
2951 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2953 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
:
2954 if FIndex
< High(FItems
) then
2957 if FIndex
> FStartLine
+FHeight
-1 then Inc(FStartLine
);
2958 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2960 IK_RETURN
, IK_KPRETURN
:
2963 if FActiveControl
<> Self
then SetActive(Self
)
2965 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
2966 else SetActive(nil);
2970 for a
:= 0 to High(FItems
) do
2971 if (Length(FItems
[a
]) > 0) and (LowerCase(FItems
[a
][1]) = LowerCase(Chr(wParam
))) then
2974 FStartLine
:= Min(Max(FIndex
-1, 0), Length(FItems
)-FHeight
);
2975 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2981 function TGUIListBox
.SelectedItem(): String;
2985 if (FIndex
< 0) or (FItems
= nil) or
2986 (FIndex
> High(FItems
)) then
2989 Result
:= FItems
[FIndex
];
2992 procedure TGUIListBox
.FSetItems(Items
: SArray
);
2994 if FItems
<> nil then
3002 if FSort
then g_Basic
.Sort(FItems
);
3005 procedure TGUIListBox
.SelectItem(Item
: String);
3009 if FItems
= nil then
3013 Item
:= LowerCase(Item
);
3015 for a
:= 0 to High(FItems
) do
3016 if LowerCase(FItems
[a
]) = Item
then
3022 if FIndex
< FHeight
then
3025 FStartLine
:= Min(FIndex
, Length(FItems
)-FHeight
);
3028 procedure TGUIListBox
.FSetIndex(aIndex
: Integer);
3030 if FItems
= nil then
3033 if (aIndex
< 0) or (aIndex
> High(FItems
)) then
3038 if FIndex
<= FHeight
then
3041 FStartLine
:= Min(FIndex
, Length(FItems
)-FHeight
);
3046 procedure TGUIFileListBox
.OnMessage(var Msg
: TMessage
);
3050 if not FEnabled
then
3053 if FItems
= nil then
3064 if @FOnChangeEvent
<> nil then
3065 FOnChangeEvent(Self
);
3070 FIndex
:= High(FItems
);
3071 FStartLine
:= Max(High(FItems
)-FHeight
+1, 0);
3072 if @FOnChangeEvent
<> nil then
3073 FOnChangeEvent(Self
);
3076 IK_PAGEUP
, IK_KPPAGEUP
:
3078 if FIndex
> FHeight
then
3079 FIndex
:= FIndex
-FHeight
3083 if FStartLine
> FHeight
then
3084 FStartLine
:= FStartLine
-FHeight
3089 IK_PAGEDN
, IK_KPPAGEDN
:
3091 if FIndex
< High(FItems
)-FHeight
then
3092 FIndex
:= FIndex
+FHeight
3094 FIndex
:= High(FItems
);
3096 if FStartLine
< High(FItems
)-FHeight
then
3097 FStartLine
:= FStartLine
+FHeight
3099 FStartLine
:= High(FItems
)-FHeight
+1;
3102 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
:
3106 if FIndex
< FStartLine
then
3108 if @FOnChangeEvent
<> nil then
3109 FOnChangeEvent(Self
);
3112 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
:
3113 if FIndex
< High(FItems
) then
3116 if FIndex
> FStartLine
+FHeight
-1 then
3118 if @FOnChangeEvent
<> nil then
3119 FOnChangeEvent(Self
);
3122 IK_RETURN
, IK_KPRETURN
:
3125 if FActiveControl
<> Self
then
3129 if FItems
[FIndex
][1] = #29 then // Ïàïêà
3131 OpenDir(FPath
+Copy(FItems
[FIndex
], 2, 255));
3136 if FDefControl
<> '' then
3137 SetActive(GetControl(FDefControl
))
3145 for a
:= 0 to High(FItems
) do
3146 if ( (Length(FItems
[a
]) > 0) and
3147 (LowerCase(FItems
[a
][1]) = LowerCase(Chr(wParam
))) ) or
3148 ( (Length(FItems
[a
]) > 1) and
3149 (FItems
[a
][1] = #29) and // Ïàïêà
3150 (LowerCase(FItems
[a
][2]) = LowerCase(Chr(wParam
))) ) then
3153 FStartLine
:= Min(Max(FIndex
-1, 0), Length(FItems
)-FHeight
);
3154 if @FOnChangeEvent
<> nil then
3155 FOnChangeEvent(Self
);
3161 procedure TGUIFileListBox
.OpenDir(path
: String);
3169 path
:= IncludeTrailingPathDelimiter(path
);
3170 path
:= ExpandFileName(path
);
3175 if FindFirst(path
+'*', faDirectory
, SR
) = 0 then
3177 if not LongBool(SR
.Attr
and faDirectory
) then
3179 if (SR
.Name
= '.') or
3180 ((SR
.Name
= '..') and (path
= ExpandFileName(FBasePath
))) then
3183 AddItem(#1 + SR
.Name
);
3184 until FindNext(SR
) <> 0;
3194 if i
= 0 then i
:= length(sm
)+1;
3195 sc
:= Copy(sm
, 1, i
-1);
3197 if FindFirst(path
+sc
, faAnyFile
, SR
) = 0 then repeat AddItem(SR
.Name
); until FindNext(SR
) <> 0;
3201 for i
:= 0 to High(FItems
) do
3202 if FItems
[i
][1] = #1 then
3203 FItems
[i
][1] := #29;
3208 procedure TGUIFileListBox
.SetBase(path
: String);
3214 function TGUIFileListBox
.SelectedItem(): String;
3218 if (FIndex
= -1) or (FItems
= nil) or
3219 (FIndex
> High(FItems
)) or
3220 (FItems
[FIndex
][1] = '/') or
3221 (FItems
[FIndex
][1] = '\') then
3224 Result
:= FPath
+ FItems
[FIndex
];
3227 procedure TGUIFileListBox
.UpdateFileList();
3231 if (FIndex
= -1) or (FItems
= nil) or
3232 (FIndex
> High(FItems
)) or
3233 (FItems
[FIndex
][1] = '/') or
3234 (FItems
[FIndex
][1] = '\') then
3237 fn
:= FItems
[FIndex
];
3247 procedure TGUIMemo
.Clear
;
3253 constructor TGUIMemo
.Create(FontID
: DWORD
; Width
, Height
: Word);
3257 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
3262 FDrawScroll
:= True;
3265 procedure TGUIMemo
.Draw
;
3271 if FDrawBack
then DrawBox(FX
, FY
, FWidth
+1, FHeight
);
3273 DrawScroll(FX
+4+FWidth
*16, FY
+4, FHeight
, (FStartLine
> 0) and (FLines
<> nil),
3274 (FStartLine
+FHeight
-1 < High(FLines
)) and (FLines
<> nil));
3276 if FLines
<> nil then
3277 for a
:= FStartLine
to Min(High(FLines
), FStartLine
+FHeight
-1) do
3278 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, FLines
[a
], FColor
.R
, FColor
.G
, FColor
.B
);
3281 function TGUIMemo
.GetHeight
: Word;
3283 Result
:= 8+FHeight
*16;
3286 function TGUIMemo
.GetWidth
: Word;
3288 Result
:= 8+(FWidth
+1)*16;
3291 procedure TGUIMemo
.OnMessage(var Msg
: TMessage
);
3293 if not FEnabled
then Exit
;
3297 if FLines
= nil then Exit
;
3303 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
:
3304 if FStartLine
> 0 then
3306 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
:
3307 if FStartLine
< Length(FLines
)-FHeight
then
3309 IK_RETURN
, IK_KPRETURN
:
3312 if FActiveControl
<> Self
then
3318 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
3319 else SetActive(nil);
3325 procedure TGUIMemo
.SetText(Text: string);
3328 FLines
:= GetLines(Text, FFont
.ID
, FWidth
*16);
3333 procedure TGUIimage
.ClearImage();
3335 if FImageRes
= '' then Exit
;
3337 g_Texture_Delete(FImageRes
);
3341 constructor TGUIimage
.Create();
3348 destructor TGUIimage
.Destroy();
3353 procedure TGUIimage
.Draw();
3359 if FImageRes
= '' then
3361 if g_Texture_Get(FDefaultRes
, ID
) then e_Draw(ID
, FX
, FY
, 0, True, False);
3364 if g_Texture_Get(FImageRes
, ID
) then e_Draw(ID
, FX
, FY
, 0, True, False);
3367 procedure TGUIimage
.OnMessage(var Msg
: TMessage
);
3372 procedure TGUIimage
.SetImage(Res
: string);
3376 if g_Texture_CreateWADEx(Res
, Res
) then FImageRes
:= Res
;
3379 procedure TGUIimage
.Update();