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/>.
16 {$INCLUDE ../shared/a_modes.inc}
23 e_graphics
, e_input
, e_log
, g_playermodel
, g_basic
, MAPDEF
, wadreader
;
26 MAINMENU_HEADER_COLOR
: TRGB
= (R
:255; G
:255; B
:255);
27 MAINMENU_ITEMS_COLOR
: TRGB
= (R
:255; G
:255; B
:255);
28 MAINMENU_UNACTIVEITEMS_COLOR
: TRGB
= (R
:192; G
:192; B
:192);
29 MAINMENU_CLICKSOUND
= 'MENU_SELECT';
30 MAINMENU_CHANGESOUND
= 'MENU_CHANGE';
32 MAINMENU_MARKER1
= 'MAINMENU_MARKER1';
33 MAINMENU_MARKER2
= 'MAINMENU_MARKER2';
34 MAINMENU_MARKERDELAY
= 24;
35 WINDOW_CLOSESOUND
= 'MENU_CLOSE';
36 MENU_HEADERCOLOR
: TRGB
= (R
:255; G
:255; B
:255);
37 MENU_ITEMSTEXT_COLOR
: TRGB
= (R
:255; G
:255; B
:255);
38 MENU_UNACTIVEITEMS_COLOR
: TRGB
= (R
:128; G
:128; B
:128);
39 MENU_ITEMSCTRL_COLOR
: TRGB
= (R
:255; G
:0; B
:0);
42 MENU_CLICKSOUND
= 'MENU_SELECT';
43 MENU_CHANGESOUND
= 'MENU_CHANGE';
44 MENU_MARKERDELAY
= 24;
45 SCROLL_LEFT
= 'SCROLL_LEFT';
46 SCROLL_RIGHT
= 'SCROLL_RIGHT';
47 SCROLL_MIDDLE
= 'SCROLL_MIDDLE';
48 SCROLL_MARKER
= 'SCROLL_MARKER';
49 SCROLL_ADDSOUND
= 'SCROLL_ADD';
50 SCROLL_SUBSOUND
= 'SCROLL_SUB';
51 EDIT_LEFT
= 'EDIT_LEFT';
52 EDIT_RIGHT
= 'EDIT_RIGHT';
53 EDIT_MIDDLE
= 'EDIT_MIDDLE';
54 EDIT_CURSORCOLOR
: TRGB
= (R
:200; G
:0; B
:0);
56 KEYREAD_QUERY
= '<...>';
57 KEYREAD_CLEAR
= '???';
60 MAPPREVIEW_HEIGHT
= 8;
70 BSCROLL_UPA
= 'BSCROLL_UP_A';
71 BSCROLL_UPU
= 'BSCROLL_UP_U';
72 BSCROLL_DOWNA
= 'BSCROLL_DOWN_A';
73 BSCROLL_DOWNU
= 'BSCROLL_DOWN_U';
74 BSCROLL_MIDDLE
= 'BSCROLL_MIDDLE';
86 TFontType
= (FONT_TEXTURE
, FONT_CHAR
);
88 TFont
= class(TPoolObject
)
94 constructor Create(FontID
: DWORD
; FontType
: TFontType
);
95 destructor Destroy
; override;
96 procedure Draw(X
, Y
: Integer; Text: string; R
, G
, B
: Byte);
97 procedure GetTextSize(Text: string; var w
, h
: Word);
98 property Scale
: Single read FScale write FScale
;
104 TOnKeyDownEvent
= procedure(Key
: Byte);
105 TOnKeyDownEventEx
= procedure(win
: TGUIWindow
; Key
: Byte);
106 TOnCloseEvent
= procedure;
107 TOnShowEvent
= procedure;
108 TOnClickEvent
= procedure;
109 TOnChangeEvent
= procedure(Sender
: TGUIControl
);
110 TOnEnterEvent
= procedure(Sender
: TGUIControl
);
112 TGUIControl
= class(TPoolObject
)
116 FWindow
: TGUIWindow
;
119 FRightAlign
: Boolean; //HACK! this works only for "normal" menus, only for menu text labels, and generally sux. sorry.
120 FMaxWidth
: Integer; //HACK! used for right-aligning labels
123 procedure OnMessage(var Msg
: TMessage
); virtual;
124 procedure Update
; virtual;
125 procedure Draw
; virtual;
126 function GetWidth(): Integer; virtual;
127 function GetHeight(): Integer; virtual;
128 function WantActivationKey (key
: LongInt): Boolean; virtual;
129 property X
: Integer read FX write FX
;
130 property Y
: Integer read FY write FY
;
131 property Enabled
: Boolean read FEnabled write FEnabled
;
132 property Name
: string read FName write FName
;
133 property UserData
: Pointer read FUserData write FUserData
;
134 property RightAlign
: Boolean read FRightAlign write FRightAlign
; // for menu
137 TGUIWindow
= class(TPoolObject
)
139 FActiveControl
: TGUIControl
;
141 FPrevWindow
: TGUIWindow
;
143 FBackTexture
: string;
144 FMainWindow
: Boolean;
145 FOnKeyDown
: TOnKeyDownEvent
;
146 FOnKeyDownEx
: TOnKeyDownEventEx
;
147 FOnCloseEvent
: TOnCloseEvent
;
148 FOnShowEvent
: TOnShowEvent
;
151 Childs
: array of TGUIControl
;
152 constructor Create(Name
: string);
153 destructor Destroy
; override;
154 function AddChild(Child
: TGUIControl
): TGUIControl
;
155 procedure OnMessage(var Msg
: TMessage
);
158 procedure SetActive(Control
: TGUIControl
);
159 function GetControl(Name
: string): TGUIControl
;
160 property OnKeyDown
: TOnKeyDownEvent read FOnKeyDown write FOnKeyDown
;
161 property OnKeyDownEx
: TOnKeyDownEventEx read FOnKeyDownEx write FOnKeyDownEx
;
162 property OnClose
: TOnCloseEvent read FOnCloseEvent write FOnCloseEvent
;
163 property OnShow
: TOnShowEvent read FOnShowEvent write FOnShowEvent
;
164 property Name
: string read FName
;
165 property DefControl
: string read FDefControl write FDefControl
;
166 property BackTexture
: string read FBackTexture write FBackTexture
;
167 property MainWindow
: Boolean read FMainWindow write FMainWindow
;
168 property UserData
: Pointer read FUserData write FUserData
;
171 TGUITextButton
= class(TGUIControl
)
180 ProcEx
: procedure (sender
: TGUITextButton
);
181 constructor Create(aProc
: Pointer; FontID
: DWORD
; Text: string);
182 destructor Destroy(); override;
183 procedure OnMessage(var Msg
: TMessage
); override;
184 procedure Update(); override;
185 procedure Draw(); override;
186 function GetWidth(): Integer; override;
187 function GetHeight(): Integer; override;
188 procedure Click(Silent
: Boolean = False);
189 property Caption
: string read FText write FText
;
190 property Color
: TRGB read FColor write FColor
;
191 property Font
: TFont read FFont write FFont
;
192 property ShowWindow
: string read FShowWindow write FShowWindow
;
195 TGUILabel
= class(TGUIControl
)
201 FOnClickEvent
: TOnClickEvent
;
203 constructor Create(Text: string; FontID
: DWORD
);
204 procedure OnMessage(var Msg
: TMessage
); override;
205 procedure Draw
; override;
206 function GetWidth
: Integer; override;
207 function GetHeight
: Integer; override;
208 property OnClick
: TOnClickEvent read FOnClickEvent write FOnClickEvent
;
209 property FixedLength
: Word read FFixedLen write FFixedLen
;
210 property Text: string read FText write FText
;
211 property Color
: TRGB read FColor write FColor
;
212 property Font
: TFont read FFont write FFont
;
215 TGUIScroll
= class(TGUIControl
)
223 FOnChangeEvent
: TOnChangeEvent
;
224 procedure FSetValue(a
: Integer);
226 constructor Create();
227 procedure OnMessage(var Msg
: TMessage
); override;
228 procedure Update
; override;
229 procedure Draw
; override;
230 function GetWidth(): Integer; override;
231 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
232 property Max
: Word read FMax write FMax
;
233 property Value
: Integer read FValue write FSetValue
;
236 TGUISwitch
= class(TGUIControl
)
239 FItems
: array of string;
242 FOnChangeEvent
: TOnChangeEvent
;
244 constructor Create(FontID
: DWORD
);
245 procedure OnMessage(var Msg
: TMessage
); override;
246 procedure AddItem(Item
: string);
247 procedure Update
; override;
248 procedure Draw
; override;
249 function GetWidth(): Integer; override;
250 function GetText
: string;
251 property ItemIndex
: Integer read FIndex write FIndex
;
252 property Color
: TRGB read FColor write FColor
;
253 property Font
: TFont read FFont write FFont
;
254 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
257 TGUIEdit
= class(TGUIControl
)
265 FOnlyDigits
: Boolean;
269 FOnChangeEvent
: TOnChangeEvent
;
270 FOnEnterEvent
: TOnEnterEvent
;
271 procedure SetText(Text: string);
273 constructor Create(FontID
: DWORD
);
274 procedure OnMessage(var Msg
: TMessage
); override;
275 procedure Update
; override;
276 procedure Draw
; override;
277 function GetWidth(): Integer; override;
278 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
279 property OnEnter
: TOnEnterEvent read FOnEnterEvent write FOnEnterEvent
;
280 property Width
: Word read FWidth write FWidth
;
281 property MaxLength
: Word read FMaxLength write FMaxLength
;
282 property OnlyDigits
: Boolean read FOnlyDigits write FOnlyDigits
;
283 property Text: string read FText write SetText
;
284 property Color
: TRGB read FColor write FColor
;
285 property Font
: TFont read FFont write FFont
;
288 TGUIKeyRead
= class(TGUIControl
)
295 constructor Create(FontID
: DWORD
);
296 procedure OnMessage(var Msg
: TMessage
); override;
297 procedure Draw
; override;
298 function GetWidth(): Integer; override;
299 function WantActivationKey (key
: LongInt): Boolean; override;
300 property Key
: Word read FKey write FKey
;
301 property Color
: TRGB read FColor write FColor
;
302 property Font
: TFont read FFont write FFont
;
306 TGUIKeyRead2
= class(TGUIControl
)
311 FKey0
, FKey1
: Word; // this should be an array. sorry.
314 FMaxKeyNameWdt
: Integer;
316 constructor Create(FontID
: DWORD
);
317 procedure OnMessage(var Msg
: TMessage
); override;
318 procedure Draw
; override;
319 function GetWidth(): Integer; override;
320 function WantActivationKey (key
: LongInt): Boolean; override;
321 property Key0
: Word read FKey0 write FKey0
;
322 property Key1
: Word read FKey1 write FKey1
;
323 property Color
: TRGB read FColor write FColor
;
324 property Font
: TFont read FFont write FFont
;
327 TGUIModelView
= class(TGUIControl
)
329 FModel
: TPlayerModel
;
333 destructor Destroy
; override;
334 procedure OnMessage(var Msg
: TMessage
); override;
335 procedure SetModel(ModelName
: string);
336 procedure SetColor(Red
, Green
, Blue
: Byte);
337 procedure NextAnim();
338 procedure NextWeapon();
339 procedure Update
; override;
340 procedure Draw
; override;
341 property Model
: TPlayerModel read FModel
;
344 TPreviewPanel
= record
345 X1
, Y1
, X2
, Y2
: Integer;
349 TGUIMapPreview
= class(TGUIControl
)
351 FMapData
: array of TPreviewPanel
;
355 constructor Create();
356 destructor Destroy(); override;
357 procedure OnMessage(var Msg
: TMessage
); override;
358 procedure SetMap(Res
: string);
359 procedure ClearMap();
360 procedure Update(); override;
361 procedure Draw(); override;
362 function GetScaleStr
: String;
365 TGUIImage
= class(TGUIControl
)
370 constructor Create();
371 destructor Destroy(); override;
372 procedure OnMessage(var Msg
: TMessage
); override;
373 procedure SetImage(Res
: string);
374 procedure ClearImage();
375 procedure Update(); override;
376 procedure Draw(); override;
377 property DefaultRes
: string read FDefaultRes write FDefaultRes
;
380 TGUIListBox
= class(TGUIControl
)
384 FUnActiveColor
: TRGB
;
392 FDrawScroll
: Boolean;
393 FOnChangeEvent
: TOnChangeEvent
;
395 procedure FSetItems(Items
: SArray
);
396 procedure FSetIndex(aIndex
: Integer);
399 constructor Create(FontID
: DWORD
; Width
, Height
: Word);
400 procedure OnMessage(var Msg
: TMessage
); override;
401 procedure Draw(); override;
402 procedure AddItem(Item
: String);
403 procedure SelectItem(Item
: String);
405 function GetWidth(): Integer; override;
406 function GetHeight(): Integer; override;
407 function SelectedItem(): String;
409 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
410 property Sort
: Boolean read FSort write FSort
;
411 property ItemIndex
: Integer read FIndex write FSetIndex
;
412 property Items
: SArray read FItems write FSetItems
;
413 property DrawBack
: Boolean read FDrawBack write FDrawBack
;
414 property DrawScrollBar
: Boolean read FDrawScroll write FDrawScroll
;
415 property ActiveColor
: TRGB read FActiveColor write FActiveColor
;
416 property UnActiveColor
: TRGB read FUnActiveColor write FUnActiveColor
;
417 property Font
: TFont read FFont write FFont
;
420 TGUIFileListBox
= class(TGUIListBox
)
427 procedure OpenDir(path
: String);
430 procedure OnMessage(var Msg
: TMessage
); override;
431 procedure SetBase(path
: String);
432 function SelectedItem(): String;
433 procedure UpdateFileList();
435 property Dirs
: Boolean read FDirs write FDirs
;
436 property FileMask
: String read FFileMask write FFileMask
;
437 property Path
: String read FPath
;
440 TGUIMemo
= class(TGUIControl
)
449 FDrawScroll
: Boolean;
451 constructor Create(FontID
: DWORD
; Width
, Height
: Word);
452 procedure OnMessage(var Msg
: TMessage
); override;
453 procedure Draw
; override;
455 function GetWidth(): Integer; override;
456 function GetHeight(): Integer; override;
457 procedure SetText(Text: string);
458 property DrawBack
: Boolean read FDrawBack write FDrawBack
;
459 property DrawScrollBar
: Boolean read FDrawScroll write FDrawScroll
;
460 property Color
: TRGB read FColor write FColor
;
461 property Font
: TFont read FFont write FFont
;
464 TGUIMainMenu
= class(TGUIControl
)
466 FButtons
: array of TGUITextButton
;
474 constructor Create(FontID
: DWORD
; Header
: string);
475 destructor Destroy
; override;
476 procedure OnMessage(var Msg
: TMessage
); override;
477 function AddButton(fProc
: Pointer; Caption
: string; ShowWindow
: string = ''): TGUITextButton
;
478 function GetButton(aName
: string): TGUITextButton
;
479 procedure EnableButton(aName
: string; e
: Boolean);
480 procedure AddSpace();
481 procedure Update
; override;
482 procedure Draw
; override;
485 TControlType
= class of TGUIControl
;
487 PMenuItem
= ^TMenuItem
;
490 ControlType
: TControlType
;
491 Control
: TGUIControl
;
494 TGUIMenu
= class(TGUIControl
)
496 FItems
: array of TMenuItem
;
504 function NewItem(): Integer;
506 constructor Create(HeaderFont
, ItemsFont
: DWORD
; Header
: string);
507 destructor Destroy
; override;
508 procedure OnMessage(var Msg
: TMessage
); override;
509 procedure AddSpace();
510 procedure AddLine(fText
: string);
511 procedure AddText(fText
: string; MaxWidth
: Word);
512 function AddLabel(fText
: string): TGUILabel
;
513 function AddButton(Proc
: Pointer; fText
: string; _ShowWindow
: string = ''): TGUITextButton
;
514 function AddScroll(fText
: string): TGUIScroll
;
515 function AddSwitch(fText
: string): TGUISwitch
;
516 function AddEdit(fText
: string): TGUIEdit
;
517 function AddKeyRead(fText
: string): TGUIKeyRead
;
518 function AddKeyRead2(fText
: string): TGUIKeyRead2
;
519 function AddList(fText
: string; Width
, Height
: Word): TGUIListBox
;
520 function AddFileList(fText
: string; Width
, Height
: Word): TGUIFileListBox
;
521 function AddMemo(fText
: string; Width
, Height
: Word): TGUIMemo
;
523 function GetControl(aName
: string): TGUIControl
;
524 function GetControlsText(aName
: string): TGUILabel
;
525 procedure Draw
; override;
526 procedure Update
; override;
527 procedure UpdateIndex();
528 property Align
: Boolean read FAlign write FAlign
;
529 property Left
: Integer read FLeft write FLeft
;
530 property YesNo
: Boolean read FYesNo write FYesNo
;
534 g_GUIWindows
: array of TGUIWindow
;
535 g_ActiveWindow
: TGUIWindow
= nil;
537 procedure g_GUI_Init();
538 function g_GUI_AddWindow(Window
: TGUIWindow
): TGUIWindow
;
539 function g_GUI_GetWindow(Name
: string): TGUIWindow
;
540 procedure g_GUI_ShowWindow(Name
: string);
541 procedure g_GUI_HideWindow(PlaySound
: Boolean = True);
542 function g_GUI_Destroy(): Boolean;
543 procedure g_GUI_SaveMenuPos();
544 procedure g_GUI_LoadMenuPos();
549 GL
, GLExt
, g_textures
, g_sound
, SysUtils
,
550 g_game
, Math
, StrUtils
, g_player
, g_options
,
551 g_map
, g_weapons
, xdynrec
;
554 Box
: Array [0..8] of DWORD
;
555 Saved_Windows
: SArray
;
557 procedure g_GUI_Init();
559 g_Texture_Get(BOX1
, Box
[0]);
560 g_Texture_Get(BOX2
, Box
[1]);
561 g_Texture_Get(BOX3
, Box
[2]);
562 g_Texture_Get(BOX4
, Box
[3]);
563 g_Texture_Get(BOX5
, Box
[4]);
564 g_Texture_Get(BOX6
, Box
[5]);
565 g_Texture_Get(BOX7
, Box
[6]);
566 g_Texture_Get(BOX8
, Box
[7]);
567 g_Texture_Get(BOX9
, Box
[8]);
570 function g_GUI_Destroy(): Boolean;
574 Result
:= (Length(g_GUIWindows
) > 0);
576 for i
:= 0 to High(g_GUIWindows
) do
577 g_GUIWindows
[i
].Free();
580 g_ActiveWindow
:= nil;
583 function g_GUI_AddWindow(Window
: TGUIWindow
): TGUIWindow
;
585 SetLength(g_GUIWindows
, Length(g_GUIWindows
)+1);
586 g_GUIWindows
[High(g_GUIWindows
)] := Window
;
591 function g_GUI_GetWindow(Name
: string): TGUIWindow
;
597 if g_GUIWindows
<> nil then
598 for i
:= 0 to High(g_GUIWindows
) do
599 if g_GUIWindows
[i
].FName
= Name
then
601 Result
:= g_GUIWindows
[i
];
605 Assert(Result
<> nil, 'GUI_Window "'+Name
+'" not found');
608 procedure g_GUI_ShowWindow(Name
: string);
612 if g_GUIWindows
= nil then
615 for i
:= 0 to High(g_GUIWindows
) do
616 if g_GUIWindows
[i
].FName
= Name
then
618 g_GUIWindows
[i
].FPrevWindow
:= g_ActiveWindow
;
619 g_ActiveWindow
:= g_GUIWindows
[i
];
621 if g_ActiveWindow
.MainWindow
then
622 g_ActiveWindow
.FPrevWindow
:= nil;
624 if g_ActiveWindow
.FDefControl
<> '' then
625 g_ActiveWindow
.SetActive(g_ActiveWindow
.GetControl(g_ActiveWindow
.FDefControl
))
627 g_ActiveWindow
.SetActive(nil);
629 if @g_ActiveWindow
.FOnShowEvent
<> nil then
630 g_ActiveWindow
.FOnShowEvent();
636 procedure g_GUI_HideWindow(PlaySound
: Boolean = True);
638 if g_ActiveWindow
<> nil then
640 if @g_ActiveWindow
.OnClose
<> nil then
641 g_ActiveWindow
.OnClose();
642 g_ActiveWindow
:= g_ActiveWindow
.FPrevWindow
;
644 g_Sound_PlayEx(WINDOW_CLOSESOUND
);
648 procedure g_GUI_SaveMenuPos();
653 SetLength(Saved_Windows
, 0);
654 win
:= g_ActiveWindow
;
658 len
:= Length(Saved_Windows
);
659 SetLength(Saved_Windows
, len
+ 1);
661 Saved_Windows
[len
] := win
.Name
;
663 if win
.MainWindow
then
666 win
:= win
.FPrevWindow
;
670 procedure g_GUI_LoadMenuPos();
672 i
, j
, k
, len
: Integer;
675 g_ActiveWindow
:= nil;
676 len
:= Length(Saved_Windows
);
681 // Îêíî ñ ãëàâíûì ìåíþ:
682 g_GUI_ShowWindow(Saved_Windows
[len
-1]);
684 // Íå ïåðåêëþ÷èëîñü (èëè íåêóäà äàëüøå):
685 if (len
= 1) or (g_ActiveWindow
= nil) then
688 // Èùåì êíîïêè â îñòàëüíûõ îêíàõ:
689 for k
:= len
-1 downto 1 do
693 for i
:= 0 to Length(g_ActiveWindow
.Childs
)-1 do
695 if g_ActiveWindow
.Childs
[i
] is TGUIMainMenu
then
696 begin // GUI_MainMenu
697 with TGUIMainMenu(g_ActiveWindow
.Childs
[i
]) do
698 for j
:= 0 to Length(FButtons
)-1 do
699 if FButtons
[j
].ShowWindow
= Saved_Windows
[k
-1] then
701 FButtons
[j
].Click(True);
707 if g_ActiveWindow
.Childs
[i
] is TGUIMenu
then
708 with TGUIMenu(g_ActiveWindow
.Childs
[i
]) do
709 for j
:= 0 to Length(FItems
)-1 do
710 if FItems
[j
].ControlType
= TGUITextButton
then
711 if TGUITextButton(FItems
[j
].Control
).ShowWindow
= Saved_Windows
[k
-1] then
713 TGUITextButton(FItems
[j
].Control
).Click(True);
724 (g_ActiveWindow
.Name
= Saved_Windows
[k
]) then
729 procedure DrawBox(X
, Y
: Integer; Width
, Height
: Word);
731 e_Draw(Box
[0], X
, Y
, 0, False, False);
732 e_DrawFill(Box
[1], X
+4, Y
, Width
*4, 1, 0, False, False);
733 e_Draw(Box
[2], X
+4+Width
*16, Y
, 0, False, False);
734 e_DrawFill(Box
[3], X
, Y
+4, 1, Height
*4, 0, False, False);
735 e_DrawFill(Box
[4], X
+4, Y
+4, Width
, Height
, 0, False, False);
736 e_DrawFill(Box
[5], X
+4+Width
*16, Y
+4, 1, Height
*4, 0, False, False);
737 e_Draw(Box
[6], X
, Y
+4+Height
*16, 0, False, False);
738 e_DrawFill(Box
[7], X
+4, Y
+4+Height
*16, Width
*4, 1, 0, False, False);
739 e_Draw(Box
[8], X
+4+Width
*16, Y
+4+Height
*16, 0, False, False);
742 procedure DrawScroll(X
, Y
: Integer; Height
: Word; Up
, Down
: Boolean);
746 if Height
< 3 then Exit
;
749 g_Texture_Get(BSCROLL_UPA
, ID
)
751 g_Texture_Get(BSCROLL_UPU
, ID
);
752 e_Draw(ID
, X
, Y
, 0, False, False);
755 g_Texture_Get(BSCROLL_DOWNA
, ID
)
757 g_Texture_Get(BSCROLL_DOWNU
, ID
);
758 e_Draw(ID
, X
, Y
+(Height
-1)*16, 0, False, False);
760 g_Texture_Get(BSCROLL_MIDDLE
, ID
);
761 e_DrawFill(ID
, X
, Y
+16, 1, Height
-2, 0, False, False);
766 constructor TGUIWindow
.Create(Name
: string);
769 FActiveControl
:= nil;
773 FOnCloseEvent
:= nil;
777 destructor TGUIWindow
.Destroy
;
784 for i
:= 0 to High(Childs
) do
788 function TGUIWindow
.AddChild(Child
: TGUIControl
): TGUIControl
;
790 Child
.FWindow
:= Self
;
792 SetLength(Childs
, Length(Childs
) + 1);
793 Childs
[High(Childs
)] := Child
;
798 procedure TGUIWindow
.Update
;
802 for i
:= 0 to High(Childs
) do
803 if Childs
[i
] <> nil then Childs
[i
].Update
;
806 procedure TGUIWindow
.Draw
;
811 if FBackTexture
<> '' then
812 if g_Texture_Get(FBackTexture
, ID
) then
813 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
815 e_Clear(GL_COLOR_BUFFER_BIT
, 0.5, 0.5, 0.5);
817 for i
:= 0 to High(Childs
) do
818 if Childs
[i
] <> nil then Childs
[i
].Draw
;
821 procedure TGUIWindow
.OnMessage(var Msg
: TMessage
);
823 if FActiveControl
<> nil then FActiveControl
.OnMessage(Msg
);
824 if @FOnKeyDown
<> nil then FOnKeyDown(Msg
.wParam
);
825 if @FOnKeyDownEx
<> nil then FOnKeyDownEx(self
, Msg
.wParam
);
827 if Msg
.Msg
= WM_KEYDOWN
then
828 if Msg
.wParam
= IK_ESCAPE
then
835 procedure TGUIWindow
.SetActive(Control
: TGUIControl
);
837 FActiveControl
:= Control
;
840 function TGUIWindow
.GetControl(Name
: String): TGUIControl
;
846 if Childs
<> nil then
847 for i
:= 0 to High(Childs
) do
848 if Childs
[i
] <> nil then
849 if LowerCase(Childs
[i
].FName
) = LowerCase(Name
) then
855 Assert(Result
<> nil, 'Window Control "'+Name
+'" not Found!');
860 constructor TGUIControl
.Create();
866 FRightAlign
:= false;
870 procedure TGUIControl
.OnMessage(var Msg
: TMessage
);
876 procedure TGUIControl
.Update();
880 procedure TGUIControl
.Draw();
884 function TGUIControl
.WantActivationKey (key
: LongInt): Boolean;
889 function TGUIControl
.GetWidth(): Integer;
894 function TGUIControl
.GetHeight(): Integer;
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; FontID
: DWORD
; Text: string);
918 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
923 destructor TGUITextButton
.Destroy
;
929 procedure TGUITextButton
.Draw
;
931 FFont
.Draw(FX
, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
)
934 function TGUITextButton
.GetHeight
: Integer;
938 FFont
.GetTextSize(FText
, w
, h
);
942 function TGUITextButton
.GetWidth
: Integer;
946 FFont
.GetTextSize(FText
, w
, h
);
950 procedure TGUITextButton
.OnMessage(var Msg
: TMessage
);
952 if not FEnabled
then Exit
;
959 IK_RETURN
, IK_KPRETURN
: Click();
964 procedure TGUITextButton
.Update
;
971 constructor TFont
.Create(FontID
: DWORD
; FontType
: TFontType
);
976 FFontType
:= FontType
;
979 destructor TFont
.Destroy
;
985 procedure TFont
.Draw(X
, Y
: Integer; Text: string; R
, G
, B
: Byte);
987 if FFontType
= FONT_CHAR
then e_CharFont_PrintEx(ID
, X
, Y
, Text, _RGB(R
, G
, B
), FScale
)
988 else e_TextureFontPrintEx(X
, Y
, Text, ID
, R
, G
, B
, FScale
);
991 procedure TFont
.GetTextSize(Text: string; var w
, h
: Word);
995 if FFontType
= FONT_CHAR
then e_CharFont_GetSize(ID
, Text, w
, h
)
998 e_TextureFontGetSize(ID
, cw
, ch
);
999 w
:= cw
*Length(Text);
1003 w
:= Round(w
*FScale
);
1004 h
:= Round(h
*FScale
);
1009 function TGUIMainMenu
.AddButton(fProc
: Pointer; Caption
: string; ShowWindow
: string = ''): TGUITextButton
;
1016 SetLength(FButtons
, Length(FButtons
)+1);
1017 FButtons
[High(FButtons
)] := TGUITextButton
.Create(fProc
, FFontID
, Caption
);
1018 FButtons
[High(FButtons
)].ShowWindow
:= ShowWindow
;
1019 with FButtons
[High(FButtons
)] do
1021 if (fProc
<> nil) or (ShowWindow
<> '') then FColor
:= MAINMENU_ITEMS_COLOR
1022 else FColor
:= MAINMENU_UNACTIVEITEMS_COLOR
;
1023 FSound
:= MAINMENU_CLICKSOUND
;
1026 _x
:= gScreenWidth
div 2;
1028 for a
:= 0 to High(FButtons
) do
1029 if FButtons
[a
] <> nil then
1030 _x
:= Min(_x
, (gScreenWidth
div 2)-(FButtons
[a
].GetWidth
div 2));
1032 hh
:= FHeader
.GetHeight
;
1034 h
:= hh
*(2+Length(FButtons
))+MAINMENU_SPACE
*(Length(FButtons
)-1);
1035 h
:= (gScreenHeight
div 2)-(h
div 2);
1045 for a
:= 0 to High(FButtons
) do
1047 if FButtons
[a
] <> nil then
1054 Inc(h
, hh
+MAINMENU_SPACE
);
1057 Result
:= FButtons
[High(FButtons
)];
1060 procedure TGUIMainMenu
.AddSpace
;
1062 SetLength(FButtons
, Length(FButtons
)+1);
1063 FButtons
[High(FButtons
)] := nil;
1066 constructor TGUIMainMenu
.Create(FontID
: DWORD
; Header
: string);
1072 FCounter
:= MAINMENU_MARKERDELAY
;
1074 g_Texture_Get(MAINMENU_MARKER1
, FMarkerID1
);
1075 g_Texture_Get(MAINMENU_MARKER2
, FMarkerID2
);
1077 FHeader
:= TGUILabel
.Create(Header
, FFontID
);
1080 FColor
:= MAINMENU_HEADER_COLOR
;
1081 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1082 FY
:= (gScreenHeight
div 2)-(GetHeight
div 2);
1086 destructor TGUIMainMenu
.Destroy
;
1090 if FButtons
<> nil then
1091 for a
:= 0 to High(FButtons
) do
1099 procedure TGUIMainMenu
.Draw
;
1107 if FButtons
<> nil then
1109 for a
:= 0 to High(FButtons
) do
1110 if FButtons
[a
] <> nil then FButtons
[a
].Draw
;
1112 if FIndex
<> -1 then
1113 e_Draw(FMarkerID1
, FButtons
[FIndex
].FX
-48, FButtons
[FIndex
].FY
, 0, True, False);
1117 procedure TGUIMainMenu
.EnableButton(aName
: string; e
: Boolean);
1121 if FButtons
= nil then Exit
;
1123 for a
:= 0 to High(FButtons
) do
1124 if (FButtons
[a
] <> nil) and (FButtons
[a
].Name
= aName
) then
1126 if e
then FButtons
[a
].FColor
:= MAINMENU_ITEMS_COLOR
1127 else FButtons
[a
].FColor
:= MAINMENU_UNACTIVEITEMS_COLOR
;
1128 FButtons
[a
].Enabled
:= e
;
1133 function TGUIMainMenu
.GetButton(aName
: string): TGUITextButton
;
1139 if FButtons
= nil then Exit
;
1141 for a
:= 0 to High(FButtons
) do
1142 if (FButtons
[a
] <> nil) and (FButtons
[a
].Name
= aName
) then
1144 Result
:= FButtons
[a
];
1149 procedure TGUIMainMenu
.OnMessage(var Msg
: TMessage
);
1154 if not FEnabled
then Exit
;
1158 if FButtons
= nil then Exit
;
1161 for a
:= 0 to High(FButtons
) do
1162 if FButtons
[a
] <> nil then
1168 if not ok
then Exit
;
1177 if FIndex
< 0 then FIndex
:= High(FButtons
);
1178 until FButtons
[FIndex
] <> nil;
1180 g_Sound_PlayEx(MENU_CHANGESOUND
);
1186 if FIndex
> High(FButtons
) then FIndex
:= 0;
1187 until FButtons
[FIndex
] <> nil;
1189 g_Sound_PlayEx(MENU_CHANGESOUND
);
1191 IK_RETURN
, IK_KPRETURN
: if (FIndex
<> -1) and FButtons
[FIndex
].FEnabled
then FButtons
[FIndex
].Click
;
1196 procedure TGUIMainMenu
.Update
;
1202 if FCounter
= 0 then
1205 FMarkerID1
:= FMarkerID2
;
1208 FCounter
:= MAINMENU_MARKERDELAY
;
1209 end else Dec(FCounter
);
1214 constructor TGUILabel
.Create(Text: string; FontID
: DWORD
);
1218 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
1222 FOnClickEvent
:= nil;
1225 procedure TGUILabel
.Draw
;
1231 FFont
.GetTextSize(FText
, w
, h
);
1232 FFont
.Draw(FX
+FMaxWidth
-w
, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
);
1236 FFont
.Draw(FX
, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
);
1240 function TGUILabel
.GetHeight
: Integer;
1244 FFont
.GetTextSize(FText
, w
, h
);
1248 function TGUILabel
.GetWidth
: Integer;
1252 if FFixedLen
= 0 then
1253 FFont
.GetTextSize(FText
, w
, h
)
1255 w
:= e_CharFont_GetMaxWidth(FFont
.ID
)*FFixedLen
;
1259 procedure TGUILabel
.OnMessage(var Msg
: TMessage
);
1261 if not FEnabled
then Exit
;
1268 IK_RETURN
, IK_KPRETURN
: if @FOnClickEvent
<> nil then FOnClickEvent();
1275 function TGUIMenu
.AddButton(Proc
: Pointer; fText
: string; _ShowWindow
: string = ''): TGUITextButton
;
1282 Control
:= TGUITextButton
.Create(Proc
, FFontID
, fText
);
1283 with Control
as TGUITextButton
do
1285 ShowWindow
:= _ShowWindow
;
1286 FColor
:= MENU_ITEMSCTRL_COLOR
;
1290 ControlType
:= TGUITextButton
;
1292 Result
:= (Control
as TGUITextButton
);
1295 if FIndex
= -1 then FIndex
:= i
;
1300 procedure TGUIMenu
.AddLine(fText
: string);
1307 Text := TGUILabel
.Create(fText
, FFontID
);
1310 FColor
:= MENU_ITEMSTEXT_COLOR
;
1319 procedure TGUIMenu
.AddText(fText
: string; MaxWidth
: Word);
1324 l
:= GetLines(fText
, FFontID
, MaxWidth
);
1326 if l
= nil then Exit
;
1328 for a
:= 0 to High(l
) do
1333 Text := TGUILabel
.Create(l
[a
], FFontID
);
1336 with Text do begin FColor
:= _RGB(255, 0, 0); end;
1340 with Text do begin FColor
:= MENU_ITEMSTEXT_COLOR
; end;
1350 procedure TGUIMenu
.AddSpace
;
1364 constructor TGUIMenu
.Create(HeaderFont
, ItemsFont
: DWORD
; Header
: string);
1370 FFontID
:= ItemsFont
;
1371 FCounter
:= MENU_MARKERDELAY
;
1375 FHeader
:= TGUILabel
.Create(Header
, HeaderFont
);
1378 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1380 FColor
:= MAINMENU_HEADER_COLOR
;
1384 destructor TGUIMenu
.Destroy
;
1388 if FItems
<> nil then
1389 for a
:= 0 to High(FItems
) do
1403 procedure TGUIMenu
.Draw
;
1405 a
, locx
, locy
: Integer;
1409 if FHeader
<> nil then FHeader
.Draw
;
1411 if FItems
<> nil then
1412 for a
:= 0 to High(FItems
) do
1414 if FItems
[a
].Text <> nil then FItems
[a
].Text.Draw
;
1415 if FItems
[a
].Control
<> nil then FItems
[a
].Control
.Draw
;
1418 if (FIndex
<> -1) and (FCounter
> MENU_MARKERDELAY
div 2) then
1423 if FItems
[FIndex
].Text <> nil then
1425 locx
:= FItems
[FIndex
].Text.FX
;
1426 locy
:= FItems
[FIndex
].Text.FY
;
1428 if FItems
[FIndex
].Text.RightAlign
then
1430 locx
:= locx
+FItems
[FIndex
].Text.FMaxWidth
-FItems
[FIndex
].Text.GetWidth
;
1433 else if FItems
[FIndex
].Control
<> nil then
1435 locx
:= FItems
[FIndex
].Control
.FX
;
1436 locy
:= FItems
[FIndex
].Control
.FY
;
1439 locx
:= locx
-e_CharFont_GetMaxWidth(FFontID
);
1441 e_CharFont_PrintEx(FFontID
, locx
, locy
, #16, _RGB(255, 0, 0));
1445 function TGUIMenu
.GetControl(aName
: String): TGUIControl
;
1451 if FItems
<> nil then
1452 for a
:= 0 to High(FItems
) do
1453 if FItems
[a
].Control
<> nil then
1454 if LowerCase(FItems
[a
].Control
.Name
) = LowerCase(aName
) then
1456 Result
:= FItems
[a
].Control
;
1460 Assert(Result
<> nil, 'GUI control "'+aName
+'" not found!');
1463 function TGUIMenu
.GetControlsText(aName
: String): TGUILabel
;
1469 if FItems
<> nil then
1470 for a
:= 0 to High(FItems
) do
1471 if FItems
[a
].Control
<> nil then
1472 if LowerCase(FItems
[a
].Control
.Name
) = LowerCase(aName
) then
1474 Result
:= FItems
[a
].Text;
1478 Assert(Result
<> nil, 'GUI control''s text "'+aName
+'" not found!');
1481 function TGUIMenu
.NewItem
: Integer;
1483 SetLength(FItems
, Length(FItems
)+1);
1484 Result
:= High(FItems
);
1487 procedure TGUIMenu
.OnMessage(var Msg
: TMessage
);
1492 if not FEnabled
then Exit
;
1496 if FItems
= nil then Exit
;
1499 for a
:= 0 to High(FItems
) do
1500 if FItems
[a
].Control
<> nil then
1506 if not ok
then Exit
;
1508 if (Msg
.Msg
= WM_KEYDOWN
) and (FIndex
<> -1) and (FItems
[FIndex
].Control
<> nil) and
1509 (FItems
[FIndex
].Control
.WantActivationKey(Msg
.wParam
)) then
1511 FItems
[FIndex
].Control
.OnMessage(Msg
);
1512 g_Sound_PlayEx(MENU_CLICKSOUND
);
1525 if c
> Length(FItems
) then
1532 if FIndex
< 0 then FIndex
:= High(FItems
);
1533 until (FItems
[FIndex
].Control
<> nil) and
1534 (FItems
[FIndex
].Control
.Enabled
);
1538 g_Sound_PlayEx(MENU_CHANGESOUND
);
1546 if c
> Length(FItems
) then
1553 if FIndex
> High(FItems
) then FIndex
:= 0;
1554 until (FItems
[FIndex
].Control
<> nil) and
1555 (FItems
[FIndex
].Control
.Enabled
);
1559 g_Sound_PlayEx(MENU_CHANGESOUND
);
1562 IK_LEFT
, IK_RIGHT
, IK_KPLEFT
, IK_KPRIGHT
:
1564 if FIndex
<> -1 then
1565 if FItems
[FIndex
].Control
<> nil then
1566 FItems
[FIndex
].Control
.OnMessage(Msg
);
1568 IK_RETURN
, IK_KPRETURN
:
1570 if FIndex
<> -1 then
1572 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1574 g_Sound_PlayEx(MENU_CLICKSOUND
);
1578 if FYesNo
and (length(FItems
) > 1) then
1580 Msg
.wParam
:= IK_RETURN
; // to register keypress
1581 FIndex
:= High(FItems
)-1;
1582 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1585 if FYesNo
and (length(FItems
) > 1) then
1587 Msg
.wParam
:= IK_RETURN
; // to register keypress
1588 FIndex
:= High(FItems
);
1589 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1596 procedure TGUIMenu
.ReAlign();
1598 a
, tx
, cx
, w
, h
: Integer;
1599 cww
: array of Integer; // cached widths
1602 if FItems
= nil then Exit
;
1604 SetLength(cww
, length(FItems
));
1606 for a
:= 0 to High(FItems
) do
1608 if FItems
[a
].Text <> nil then
1610 cww
[a
] := FItems
[a
].Text.GetWidth
;
1611 if maxcww
< cww
[a
] then maxcww
:= cww
[a
];
1622 for a
:= 0 to High(FItems
) do
1625 if FItems
[a
].Text <> nil then w
:= FItems
[a
].Text.GetWidth
;
1626 if FItems
[a
].Control
<> nil then
1629 if FItems
[a
].ControlType
= TGUILabel
then w
:= w
+(FItems
[a
].Control
as TGUILabel
).GetWidth
1630 else if FItems
[a
].ControlType
= TGUITextButton
then w
:= w
+(FItems
[a
].Control
as TGUITextButton
).GetWidth
1631 else if FItems
[a
].ControlType
= TGUIScroll
then w
:= w
+(FItems
[a
].Control
as TGUIScroll
).GetWidth
1632 else if FItems
[a
].ControlType
= TGUISwitch
then w
:= w
+(FItems
[a
].Control
as TGUISwitch
).GetWidth
1633 else if FItems
[a
].ControlType
= TGUIEdit
then w
:= w
+(FItems
[a
].Control
as TGUIEdit
).GetWidth
1634 else if FItems
[a
].ControlType
= TGUIKeyRead
then w
:= w
+(FItems
[a
].Control
as TGUIKeyRead
).GetWidth
1635 else if FItems
[a
].ControlType
= TGUIKeyRead2
then w
:= w
+(FItems
[a
].Control
as TGUIKeyRead2
).GetWidth
1636 else if FItems
[a
].ControlType
= TGUIListBox
then w
:= w
+(FItems
[a
].Control
as TGUIListBox
).GetWidth
1637 else if FItems
[a
].ControlType
= TGUIFileListBox
then w
:= w
+(FItems
[a
].Control
as TGUIFileListBox
).GetWidth
1638 else if FItems
[a
].ControlType
= TGUIMemo
then w
:= w
+(FItems
[a
].Control
as TGUIMemo
).GetWidth
;
1640 tx
:= Min(tx
, (gScreenWidth
div 2)-(w
div 2));
1645 for a
:= 0 to High(FItems
) do
1649 if (Text <> nil) and (Control
= nil) then Continue
;
1651 if Text <> nil then w
:= tx
+Text.GetWidth
;
1652 if w
> cx
then cx
:= w
;
1656 cx
:= cx
+MENU_HSPACE
;
1658 h
:= FHeader
.GetHeight
*2+MENU_VSPACE
*(Length(FItems
)-1);
1660 for a
:= 0 to High(FItems
) do
1664 if (ControlType
= TGUIListBox
) or (ControlType
= TGUIFileListBox
) then
1665 h
:= h
+(FItems
[a
].Control
as TGUIListBox
).GetHeight()
1667 h
:= h
+e_CharFont_GetMaxHeight(FFontID
);
1671 h
:= (gScreenHeight
div 2)-(h
div 2);
1675 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1678 Inc(h
, GetHeight
*2);
1681 for a
:= 0 to High(FItems
) do
1693 if Text.RightAlign
and (length(cww
) > a
) then
1695 //Text.FX := Text.FX+maxcww;
1696 Text.FMaxWidth
:= maxcww
;
1700 if Control
<> nil then
1717 if (ControlType
= TGUIListBox
) or (ControlType
= TGUIFileListBox
) then Inc(h
, (Control
as TGUIListBox
).GetHeight
+MENU_VSPACE
)
1718 else if ControlType
= TGUIMemo
then Inc(h
, (Control
as TGUIMemo
).GetHeight
+MENU_VSPACE
)
1719 else Inc(h
, e_CharFont_GetMaxHeight(FFontID
)+MENU_VSPACE
);
1723 // another ugly hack
1724 if FYesNo
and (length(FItems
) > 1) then
1727 for a
:= High(FItems
)-1 to High(FItems
) do
1729 if (FItems
[a
].Control
<> nil) and (FItems
[a
].ControlType
= TGUITextButton
) then
1731 cx
:= (FItems
[a
].Control
as TGUITextButton
).GetWidth
;
1732 if cx
> w
then w
:= cx
;
1737 for a
:= High(FItems
)-1 to High(FItems
) do
1739 if (FItems
[a
].Control
<> nil) and (FItems
[a
].ControlType
= TGUITextButton
) then
1741 FItems
[a
].Control
.FX
:= (gScreenWidth
-w
) div 2;
1748 function TGUIMenu
.AddScroll(fText
: string): TGUIScroll
;
1755 Control
:= TGUIScroll
.Create();
1757 Text := TGUILabel
.Create(fText
, FFontID
);
1760 FColor
:= MENU_ITEMSTEXT_COLOR
;
1763 ControlType
:= TGUIScroll
;
1765 Result
:= (Control
as TGUIScroll
);
1768 if FIndex
= -1 then FIndex
:= i
;
1773 function TGUIMenu
.AddSwitch(fText
: string): TGUISwitch
;
1780 Control
:= TGUISwitch
.Create(FFontID
);
1781 (Control
as TGUISwitch
).FColor
:= MENU_ITEMSCTRL_COLOR
;
1783 Text := TGUILabel
.Create(fText
, FFontID
);
1786 FColor
:= MENU_ITEMSTEXT_COLOR
;
1789 ControlType
:= TGUISwitch
;
1791 Result
:= (Control
as TGUISwitch
);
1794 if FIndex
= -1 then FIndex
:= i
;
1799 function TGUIMenu
.AddEdit(fText
: string): TGUIEdit
;
1806 Control
:= TGUIEdit
.Create(FFontID
);
1807 with Control
as TGUIEdit
do
1809 FWindow
:= Self
.FWindow
;
1810 FColor
:= MENU_ITEMSCTRL_COLOR
;
1813 if fText
= '' then Text := nil else
1815 Text := TGUILabel
.Create(fText
, FFontID
);
1816 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
1819 ControlType
:= TGUIEdit
;
1821 Result
:= (Control
as TGUIEdit
);
1824 if FIndex
= -1 then FIndex
:= i
;
1829 procedure TGUIMenu
.Update
;
1835 if FCounter
= 0 then FCounter
:= MENU_MARKERDELAY
else Dec(FCounter
);
1837 if FItems
<> nil then
1838 for a
:= 0 to High(FItems
) do
1839 if FItems
[a
].Control
<> nil then
1840 (FItems
[a
].Control
as FItems
[a
].ControlType
).Update
;
1843 function TGUIMenu
.AddKeyRead(fText
: string): TGUIKeyRead
;
1850 Control
:= TGUIKeyRead
.Create(FFontID
);
1851 with Control
as TGUIKeyRead
do
1853 FWindow
:= Self
.FWindow
;
1854 FColor
:= MENU_ITEMSCTRL_COLOR
;
1857 Text := TGUILabel
.Create(fText
, FFontID
);
1860 FColor
:= MENU_ITEMSTEXT_COLOR
;
1863 ControlType
:= TGUIKeyRead
;
1865 Result
:= (Control
as TGUIKeyRead
);
1868 if FIndex
= -1 then FIndex
:= i
;
1873 function TGUIMenu
.AddKeyRead2(fText
: string): TGUIKeyRead2
;
1880 Control
:= TGUIKeyRead2
.Create(FFontID
);
1881 with Control
as TGUIKeyRead2
do
1883 FWindow
:= Self
.FWindow
;
1884 FColor
:= MENU_ITEMSCTRL_COLOR
;
1887 Text := TGUILabel
.Create(fText
, FFontID
);
1890 FColor
:= MENU_ITEMSCTRL_COLOR
; //MENU_ITEMSTEXT_COLOR;
1894 ControlType
:= TGUIKeyRead2
;
1896 Result
:= (Control
as TGUIKeyRead2
);
1899 if FIndex
= -1 then FIndex
:= i
;
1904 function TGUIMenu
.AddList(fText
: string; Width
, Height
: Word): TGUIListBox
;
1911 Control
:= TGUIListBox
.Create(FFontID
, Width
, Height
);
1912 with Control
as TGUIListBox
do
1914 FWindow
:= Self
.FWindow
;
1915 FActiveColor
:= MENU_ITEMSCTRL_COLOR
;
1916 FUnActiveColor
:= MENU_ITEMSTEXT_COLOR
;
1919 Text := TGUILabel
.Create(fText
, FFontID
);
1922 FColor
:= MENU_ITEMSTEXT_COLOR
;
1925 ControlType
:= TGUIListBox
;
1927 Result
:= (Control
as TGUIListBox
);
1930 if FIndex
= -1 then FIndex
:= i
;
1935 function TGUIMenu
.AddFileList(fText
: string; Width
, Height
: Word): TGUIFileListBox
;
1942 Control
:= TGUIFileListBox
.Create(FFontID
, Width
, Height
);
1943 with Control
as TGUIFileListBox
do
1945 FWindow
:= Self
.FWindow
;
1946 FActiveColor
:= MENU_ITEMSCTRL_COLOR
;
1947 FUnActiveColor
:= MENU_ITEMSTEXT_COLOR
;
1950 if fText
= '' then Text := nil else
1952 Text := TGUILabel
.Create(fText
, FFontID
);
1953 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
1956 ControlType
:= TGUIFileListBox
;
1958 Result
:= (Control
as TGUIFileListBox
);
1961 if FIndex
= -1 then FIndex
:= i
;
1966 function TGUIMenu
.AddLabel(fText
: string): TGUILabel
;
1973 Control
:= TGUILabel
.Create('', FFontID
);
1974 with Control
as TGUILabel
do
1976 FWindow
:= Self
.FWindow
;
1977 FColor
:= MENU_ITEMSCTRL_COLOR
;
1980 Text := TGUILabel
.Create(fText
, FFontID
);
1983 FColor
:= MENU_ITEMSTEXT_COLOR
;
1986 ControlType
:= TGUILabel
;
1988 Result
:= (Control
as TGUILabel
);
1991 if FIndex
= -1 then FIndex
:= i
;
1996 function TGUIMenu
.AddMemo(fText
: string; Width
, Height
: Word): TGUIMemo
;
2003 Control
:= TGUIMemo
.Create(FFontID
, Width
, Height
);
2004 with Control
as TGUIMemo
do
2006 FWindow
:= Self
.FWindow
;
2007 FColor
:= MENU_ITEMSTEXT_COLOR
;
2010 if fText
= '' then Text := nil else
2012 Text := TGUILabel
.Create(fText
, FFontID
);
2013 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
2016 ControlType
:= TGUIMemo
;
2018 Result
:= (Control
as TGUIMemo
);
2021 if FIndex
= -1 then FIndex
:= i
;
2026 procedure TGUIMenu
.UpdateIndex();
2034 if (FIndex
< 0) or (FIndex
> High(FItems
)) then
2040 if FItems
[FIndex
].Control
.Enabled
then
2049 constructor TGUIScroll
.Create
;
2054 FOnChangeEvent
:= nil;
2056 g_Texture_Get(SCROLL_LEFT
, FLeftID
);
2057 g_Texture_Get(SCROLL_RIGHT
, FRightID
);
2058 g_Texture_Get(SCROLL_MIDDLE
, FMiddleID
);
2059 g_Texture_Get(SCROLL_MARKER
, FMarkerID
);
2062 procedure TGUIScroll
.Draw
;
2068 e_Draw(FLeftID
, FX
, FY
, 0, True, False);
2069 e_Draw(FRightID
, FX
+8+(FMax
+1)*8, FY
, 0, True, False);
2071 for a
:= 0 to FMax
do
2072 e_Draw(FMiddleID
, FX
+8+a
*8, FY
, 0, True, False);
2074 e_Draw(FMarkerID
, FX
+8+FValue
*8, FY
, 0, True, False);
2077 procedure TGUIScroll
.FSetValue(a
: Integer);
2079 if a
> FMax
then FValue
:= FMax
else FValue
:= a
;
2082 function TGUIScroll
.GetWidth
: Integer;
2084 Result
:= 16+(FMax
+1)*8;
2087 procedure TGUIScroll
.OnMessage(var Msg
: TMessage
);
2089 if not FEnabled
then Exit
;
2101 g_Sound_PlayEx(SCROLL_SUBSOUND
);
2102 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2104 IK_RIGHT
, IK_KPRIGHT
:
2105 if FValue
< FMax
then
2108 g_Sound_PlayEx(SCROLL_ADDSOUND
);
2109 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2116 procedure TGUIScroll
.Update
;
2124 procedure TGUISwitch
.AddItem(Item
: string);
2126 SetLength(FItems
, Length(FItems
)+1);
2127 FItems
[High(FItems
)] := Item
;
2129 if FIndex
= -1 then FIndex
:= 0;
2132 constructor TGUISwitch
.Create(FontID
: DWORD
);
2138 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
2141 procedure TGUISwitch
.Draw
;
2145 FFont
.Draw(FX
, FY
, FItems
[FIndex
], FColor
.R
, FColor
.G
, FColor
.B
);
2148 function TGUISwitch
.GetText
: string;
2150 if FIndex
<> -1 then Result
:= FItems
[FIndex
]
2154 function TGUISwitch
.GetWidth
: Integer;
2161 if FItems
= nil then Exit
;
2163 for a
:= 0 to High(FItems
) do
2165 FFont
.GetTextSize(FItems
[a
], w
, h
);
2166 if w
> Result
then Result
:= w
;
2170 procedure TGUISwitch
.OnMessage(var Msg
: TMessage
);
2172 if not FEnabled
then Exit
;
2176 if FItems
= nil then Exit
;
2181 IK_RETURN
, IK_RIGHT
, IK_KPRETURN
, IK_KPRIGHT
:
2183 if FIndex
< High(FItems
) then
2188 if @FOnChangeEvent
<> nil then
2189 FOnChangeEvent(Self
);
2197 FIndex
:= High(FItems
);
2199 if @FOnChangeEvent
<> nil then
2200 FOnChangeEvent(Self
);
2206 procedure TGUISwitch
.Update
;
2214 constructor TGUIEdit
.Create(FontID
: DWORD
);
2218 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
2223 g_Texture_Get(EDIT_LEFT
, FLeftID
);
2224 g_Texture_Get(EDIT_RIGHT
, FRightID
);
2225 g_Texture_Get(EDIT_MIDDLE
, FMiddleID
);
2228 procedure TGUIEdit
.Draw
;
2234 e_Draw(FLeftID
, FX
, FY
, 0, True, False);
2235 e_Draw(FRightID
, FX
+8+FWidth
*16, FY
, 0, True, False);
2237 for c
:= 0 to FWidth
-1 do
2238 e_Draw(FMiddleID
, FX
+8+c
*16, FY
, 0, True, False);
2240 FFont
.Draw(FX
+8, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
);
2242 if FWindow
.FActiveControl
= Self
then
2244 FFont
.GetTextSize(Copy(FText
, 1, FCaretPos
), w
, h
);
2245 h
:= e_CharFont_GetMaxHeight(FFont
.ID
);
2246 e_DrawLine(2, FX
+8+w
, FY
+h
-3, FX
+8+w
+EDIT_CURSORLEN
, FY
+h
-3,
2247 EDIT_CURSORCOLOR
.R
, EDIT_CURSORCOLOR
.G
, EDIT_CURSORCOLOR
.B
);
2251 function TGUIEdit
.GetWidth
: Integer;
2253 Result
:= 16+FWidth
*16;
2256 procedure TGUIEdit
.OnMessage(var Msg
: TMessage
);
2258 if not FEnabled
then Exit
;
2267 if (wParam
in [48..57]) and (Chr(wParam
) <> '`') then
2268 if Length(Text) < FMaxLength
then
2270 Insert(Chr(wParam
), FText
, FCaretPos
+ 1);
2276 if (wParam
in [32..255]) and (Chr(wParam
) <> '`') then
2277 if Length(Text) < FMaxLength
then
2279 Insert(Chr(wParam
), FText
, FCaretPos
+ 1);
2287 Delete(FText
, FCaretPos
, 1);
2288 if FCaretPos
> 0 then Dec(FCaretPos
);
2290 IK_DELETE
: Delete(FText
, FCaretPos
+ 1, 1);
2291 IK_END
, IK_KPEND
: FCaretPos
:= Length(FText
);
2292 IK_HOME
, IK_KPHOME
: FCaretPos
:= 0;
2293 IK_LEFT
, IK_KPLEFT
: if FCaretPos
> 0 then Dec(FCaretPos
);
2294 IK_RIGHT
, IK_KPRIGHT
: if FCaretPos
< Length(FText
) then Inc(FCaretPos
);
2295 IK_RETURN
, IK_KPRETURN
:
2298 if FActiveControl
<> Self
then
2301 if @FOnEnterEvent
<> nil then FOnEnterEvent(Self
);
2305 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
2306 else SetActive(nil);
2307 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2314 procedure TGUIEdit
.SetText(Text: string);
2316 if Length(Text) > FMaxLength
then SetLength(Text, FMaxLength
);
2318 FCaretPos
:= Length(FText
);
2321 procedure TGUIEdit
.Update
;
2328 constructor TGUIKeyRead
.Create(FontID
: DWORD
);
2334 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
2337 procedure TGUIKeyRead
.Draw
;
2341 FFont
.Draw(FX
, FY
, IfThen(FIsQuery
, KEYREAD_QUERY
, IfThen(FKey
<> 0, e_KeyNames
[FKey
], KEYREAD_CLEAR
)),
2342 FColor
.R
, FColor
.G
, FColor
.B
);
2345 function TGUIKeyRead
.GetWidth
: Integer;
2352 for a
:= 0 to 255 do
2354 FFont
.GetTextSize(e_KeyNames
[a
], w
, h
);
2355 Result
:= Max(Result
, w
);
2358 FFont
.GetTextSize(KEYREAD_QUERY
, w
, h
);
2359 if w
> Result
then Result
:= w
;
2361 FFont
.GetTextSize(KEYREAD_CLEAR
, w
, h
);
2362 if w
> Result
then Result
:= w
;
2365 function TGUIKeyRead
.WantActivationKey (key
: LongInt): Boolean;
2368 (key
= IK_BACKSPACE
) or
2372 procedure TGUIKeyRead
.OnMessage(var Msg
: TMessage
);
2373 procedure actDefCtl ();
2376 if FDefControl
<> '' then
2377 SetActive(GetControl(FDefControl
))
2385 if not FEnabled
then
2394 if FIsQuery
then actDefCtl();
2397 IK_RETURN
, IK_KPRETURN
:
2399 if not FIsQuery
then
2402 if FActiveControl
<> Self
then
2409 FKey
:= IK_ENTER
; // <Enter>
2414 IK_BACKSPACE
: // clear keybinding if we aren't waiting for a key
2416 if not FIsQuery
then
2426 if not FIsQuery
and (wParam
= IK_BACKSPACE
) then
2431 else if FIsQuery
and (wParam
<> IK_ENTER
) and (wParam
<> IK_KPRETURN
) then // Not <Enter
2433 if e_KeyNames
[wParam
] <> '' then
2444 constructor TGUIKeyRead2
.Create(FontID
: DWORD
);
2457 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
2459 FMaxKeyNameWdt
:= 0;
2460 for a
:= 0 to 255 do
2462 FFont
.GetTextSize(e_KeyNames
[a
], w
, h
);
2463 FMaxKeyNameWdt
:= Max(FMaxKeyNameWdt
, w
);
2466 FMaxKeyNameWdt
:= FMaxKeyNameWdt
-(FMaxKeyNameWdt
div 3);
2468 FFont
.GetTextSize(KEYREAD_QUERY
, w
, h
);
2469 if w
> FMaxKeyNameWdt
then FMaxKeyNameWdt
:= w
;
2471 FFont
.GetTextSize(KEYREAD_CLEAR
, w
, h
);
2472 if w
> FMaxKeyNameWdt
then FMaxKeyNameWdt
:= w
;
2475 procedure TGUIKeyRead2
.Draw
;
2476 procedure drawText (idx
: Integer);
2482 if idx
= 0 then kk
:= FKey0
else kk
:= FKey1
;
2484 if idx
= 0 then x
:= FX
+8 else x
:= FX
+8+FMaxKeyNameWdt
+16;
2488 if FKeyIdx
= idx
then begin r
:= 255; g
:= 255; b
:= 255; end;
2489 if FIsQuery
and (FKeyIdx
= idx
) then
2490 FFont
.Draw(x
, y
, KEYREAD_QUERY
, r
, g
, b
)
2492 FFont
.Draw(x
, y
, IfThen(kk
<> 0, e_KeyNames
[kk
], KEYREAD_CLEAR
), r
, g
, b
);
2498 //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);
2499 //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);
2504 function TGUIKeyRead2
.GetWidth
: Integer;
2506 Result
:= FMaxKeyNameWdt
*2+8+8+16;
2509 function TGUIKeyRead2
.WantActivationKey (key
: LongInt): Boolean;
2512 (key
= IK_BACKSPACE
) or
2513 (key
= IK_LEFT
) or (key
= IK_RIGHT
) or
2514 (key
= IK_KPLEFT
) or (key
= IK_KPRIGHT
) or
2518 procedure TGUIKeyRead2
.OnMessage(var Msg
: TMessage
);
2519 procedure actDefCtl ();
2522 if FDefControl
<> '' then
2523 SetActive(GetControl(FDefControl
))
2531 if not FEnabled
then
2540 if FIsQuery
then actDefCtl();
2543 IK_RETURN
, IK_KPRETURN
:
2545 if not FIsQuery
then
2548 if FActiveControl
<> Self
then
2555 if (FKeyIdx
= 0) then FKey0
:= IK_ENTER
else FKey1
:= IK_ENTER
; // <Enter>
2560 IK_BACKSPACE
: // clear keybinding if we aren't waiting for a key
2562 if not FIsQuery
then
2564 if (FKeyIdx
= 0) then FKey0
:= 0 else FKey1
:= 0;
2569 if not FIsQuery
then
2574 IK_RIGHT
, IK_KPRIGHT
:
2575 if not FIsQuery
then
2584 if not FIsQuery
and (wParam
= IK_BACKSPACE
) then
2586 if (FKeyIdx
= 0) then FKey0
:= 0 else FKey1
:= 0;
2589 else if FIsQuery
and (wParam
<> IK_ENTER
) and (wParam
<> IK_KPRETURN
) then // Not <Enter
2591 if e_KeyNames
[wParam
] <> '' then
2593 if (FKeyIdx
= 0) then FKey0
:= wParam
else FKey1
:= wParam
;
2605 constructor TGUIModelView
.Create
;
2612 destructor TGUIModelView
.Destroy
;
2619 procedure TGUIModelView
.Draw
;
2623 DrawBox(FX
, FY
, 4, 4);
2625 if FModel
<> nil then FModel
.Draw(FX
+4, FY
+4);
2628 procedure TGUIModelView
.NextAnim();
2630 if FModel
= nil then
2633 if FModel
.Animation
< A_PAIN
then
2634 FModel
.ChangeAnimation(FModel
.Animation
+1, True)
2636 FModel
.ChangeAnimation(A_STAND
, True);
2639 procedure TGUIModelView
.NextWeapon();
2641 if FModel
= nil then
2644 if FModel
.Weapon
< WP_LAST
then
2645 FModel
.SetWeapon(FModel
.Weapon
+1)
2647 FModel
.SetWeapon(WEAPON_KASTET
);
2650 procedure TGUIModelView
.OnMessage(var Msg
: TMessage
);
2656 procedure TGUIModelView
.SetColor(Red
, Green
, Blue
: Byte);
2658 if FModel
<> nil then FModel
.SetColor(Red
, Green
, Blue
);
2661 procedure TGUIModelView
.SetModel(ModelName
: string);
2665 FModel
:= g_PlayerModel_Get(ModelName
);
2668 procedure TGUIModelView
.Update
;
2675 if FModel
<> nil then FModel
.Update
;
2680 constructor TGUIMapPreview
.Create();
2686 destructor TGUIMapPreview
.Destroy();
2692 procedure TGUIMapPreview
.Draw();
2699 DrawBox(FX
, FY
, MAPPREVIEW_WIDTH
, MAPPREVIEW_HEIGHT
);
2701 if (FMapSize
.X
<= 0) or (FMapSize
.Y
<= 0) then
2704 e_DrawFillQuad(FX
+4, FY
+4,
2705 FX
+4 + Trunc(FMapSize
.X
/ FScale
) - 1,
2706 FY
+4 + Trunc(FMapSize
.Y
/ FScale
) - 1,
2709 if FMapData
<> nil then
2710 for a
:= 0 to High(FMapData
) do
2713 if X1
> MAPPREVIEW_WIDTH
*16 then Continue
;
2714 if Y1
> MAPPREVIEW_HEIGHT
*16 then Continue
;
2716 if X2
< 0 then Continue
;
2717 if Y2
< 0 then Continue
;
2719 if X2
> MAPPREVIEW_WIDTH
*16 then X2
:= MAPPREVIEW_WIDTH
*16;
2720 if Y2
> MAPPREVIEW_HEIGHT
*16 then Y2
:= MAPPREVIEW_HEIGHT
*16;
2722 if X1
< 0 then X1
:= 0;
2723 if Y1
< 0 then Y1
:= 0;
2764 if ((X2
-X1
) > 0) and ((Y2
-Y1
) > 0) then
2765 e_DrawFillQuad(FX
+4 + X1
, FY
+4 + Y1
,
2766 FX
+4 + X2
- 1, FY
+4 + Y2
- 1, r
, g
, b
, 0);
2770 procedure TGUIMapPreview
.OnMessage(var Msg
: TMessage
);
2776 procedure TGUIMapPreview
.SetMap(Res
: string);
2781 //header: TMapHeaderRec_1;
2786 map
: TDynRecord
= nil;
2793 FileName
:= g_ExtractWadName(Res
);
2795 WAD
:= TWADFile
.Create();
2796 if not WAD
.ReadFile(FileName
) then
2802 //k8: ignores path again
2803 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
2812 map
:= g_Map_ParseMap(Data
, Len
);
2822 if (map
= nil) then exit
;
2825 panlist
:= map
.field
['panel'];
2826 //header := GetMapHeader(map);
2828 FMapSize
.X
:= map
.Width
div 16;
2829 FMapSize
.Y
:= map
.Height
div 16;
2831 rX
:= Ceil(map
.Width
/ (MAPPREVIEW_WIDTH
*256.0));
2832 rY
:= Ceil(map
.Height
/ (MAPPREVIEW_HEIGHT
*256.0));
2833 FScale
:= max(rX
, rY
);
2837 if (panlist
<> nil) then
2839 for pan
in panlist
do
2841 if (pan
.PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or
2842 PANEL_STEP
or PANEL_WATER
or
2843 PANEL_ACID1
or PANEL_ACID2
)) <> 0 then
2845 SetLength(FMapData
, Length(FMapData
)+1);
2846 with FMapData
[High(FMapData
)] do
2851 X2
:= (pan
.X
+ pan
.Width
) div 16;
2852 Y2
:= (pan
.Y
+ pan
.Height
) div 16;
2854 X1
:= Trunc(X1
/FScale
+ 0.5);
2855 Y1
:= Trunc(Y1
/FScale
+ 0.5);
2856 X2
:= Trunc(X2
/FScale
+ 0.5);
2857 Y2
:= Trunc(Y2
/FScale
+ 0.5);
2859 if (X1
<> X2
) or (Y1
<> Y2
) then
2867 PanelType
:= pan
.PanelType
;
2873 //writeln('freeing map');
2878 procedure TGUIMapPreview
.ClearMap();
2880 SetLength(FMapData
, 0);
2887 procedure TGUIMapPreview
.Update();
2893 function TGUIMapPreview
.GetScaleStr(): String;
2895 if FScale
> 0.0 then
2897 Result
:= FloatToStrF(FScale
*16.0, ffFixed
, 3, 3);
2898 while (Result
[Length(Result
)] = '0') do
2899 Delete(Result
, Length(Result
), 1);
2900 if (Result
[Length(Result
)] = ',') or (Result
[Length(Result
)] = '.') then
2901 Delete(Result
, Length(Result
), 1);
2902 Result
:= '1 : ' + Result
;
2910 procedure TGUIListBox
.AddItem(Item
: string);
2912 SetLength(FItems
, Length(FItems
)+1);
2913 FItems
[High(FItems
)] := Item
;
2915 if FSort
then g_Basic
.Sort(FItems
);
2918 procedure TGUIListBox
.Clear();
2926 constructor TGUIListBox
.Create(FontID
: DWORD
; Width
, Height
: Word);
2930 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
2935 FOnChangeEvent
:= nil;
2937 FDrawScroll
:= True;
2940 procedure TGUIListBox
.Draw
;
2948 if FDrawBack
then DrawBox(FX
, FY
, FWidth
+1, FHeight
);
2950 DrawScroll(FX
+4+FWidth
*16, FY
+4, FHeight
, (FStartLine
> 0) and (FItems
<> nil),
2951 (FStartLine
+FHeight
-1 < High(FItems
)) and (FItems
<> nil));
2953 if FItems
<> nil then
2954 for a
:= FStartLine
to Min(High(FItems
), FStartLine
+FHeight
-1) do
2958 FFont
.GetTextSize(s
, w2
, h2
);
2959 while (Length(s
) > 0) and (w2
> FWidth
*16) do
2961 SetLength(s
, Length(s
)-1);
2962 FFont
.GetTextSize(s
, w2
, h2
);
2966 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, s
, FActiveColor
.R
, FActiveColor
.G
, FActiveColor
.B
)
2968 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, s
, FUnActiveColor
.R
, FUnActiveColor
.G
, FUnActiveColor
.B
);
2972 function TGUIListBox
.GetHeight
: Integer;
2974 Result
:= 8+FHeight
*16;
2977 function TGUIListBox
.GetWidth
: Integer;
2979 Result
:= 8+(FWidth
+1)*16;
2982 procedure TGUIListBox
.OnMessage(var Msg
: TMessage
);
2986 if not FEnabled
then Exit
;
2990 if FItems
= nil then Exit
;
3003 FIndex
:= High(FItems
);
3004 FStartLine
:= Max(High(FItems
)-FHeight
+1, 0);
3006 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
:
3010 if FIndex
< FStartLine
then Dec(FStartLine
);
3011 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
3013 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
:
3014 if FIndex
< High(FItems
) then
3017 if FIndex
> FStartLine
+FHeight
-1 then Inc(FStartLine
);
3018 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
3020 IK_RETURN
, IK_KPRETURN
:
3023 if FActiveControl
<> Self
then SetActive(Self
)
3025 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
3026 else SetActive(nil);
3030 for a
:= 0 to High(FItems
) do
3031 if (Length(FItems
[a
]) > 0) and (LowerCase(FItems
[a
][1]) = LowerCase(Chr(wParam
))) then
3034 FStartLine
:= Min(Max(FIndex
-1, 0), Length(FItems
)-FHeight
);
3035 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
3041 function TGUIListBox
.SelectedItem(): String;
3045 if (FIndex
< 0) or (FItems
= nil) or
3046 (FIndex
> High(FItems
)) then
3049 Result
:= FItems
[FIndex
];
3052 procedure TGUIListBox
.FSetItems(Items
: SArray
);
3054 if FItems
<> nil then
3062 if FSort
then g_Basic
.Sort(FItems
);
3065 procedure TGUIListBox
.SelectItem(Item
: String);
3069 if FItems
= nil then
3073 Item
:= LowerCase(Item
);
3075 for a
:= 0 to High(FItems
) do
3076 if LowerCase(FItems
[a
]) = Item
then
3082 if FIndex
< FHeight
then
3085 FStartLine
:= Min(FIndex
, Length(FItems
)-FHeight
);
3088 procedure TGUIListBox
.FSetIndex(aIndex
: Integer);
3090 if FItems
= nil then
3093 if (aIndex
< 0) or (aIndex
> High(FItems
)) then
3098 if FIndex
<= FHeight
then
3101 FStartLine
:= Min(FIndex
, Length(FItems
)-FHeight
);
3106 procedure TGUIFileListBox
.OnMessage(var Msg
: TMessage
);
3110 if not FEnabled
then
3113 if FItems
= nil then
3124 if @FOnChangeEvent
<> nil then
3125 FOnChangeEvent(Self
);
3130 FIndex
:= High(FItems
);
3131 FStartLine
:= Max(High(FItems
)-FHeight
+1, 0);
3132 if @FOnChangeEvent
<> nil then
3133 FOnChangeEvent(Self
);
3136 IK_PAGEUP
, IK_KPPAGEUP
:
3138 if FIndex
> FHeight
then
3139 FIndex
:= FIndex
-FHeight
3143 if FStartLine
> FHeight
then
3144 FStartLine
:= FStartLine
-FHeight
3149 IK_PAGEDN
, IK_KPPAGEDN
:
3151 if FIndex
< High(FItems
)-FHeight
then
3152 FIndex
:= FIndex
+FHeight
3154 FIndex
:= High(FItems
);
3156 if FStartLine
< High(FItems
)-FHeight
then
3157 FStartLine
:= FStartLine
+FHeight
3159 FStartLine
:= High(FItems
)-FHeight
+1;
3162 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
:
3166 if FIndex
< FStartLine
then
3168 if @FOnChangeEvent
<> nil then
3169 FOnChangeEvent(Self
);
3172 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
:
3173 if FIndex
< High(FItems
) then
3176 if FIndex
> FStartLine
+FHeight
-1 then
3178 if @FOnChangeEvent
<> nil then
3179 FOnChangeEvent(Self
);
3182 IK_RETURN
, IK_KPRETURN
:
3185 if FActiveControl
<> Self
then
3189 if FItems
[FIndex
][1] = #29 then // Ïàïêà
3191 OpenDir(FPath
+Copy(FItems
[FIndex
], 2, 255));
3196 if FDefControl
<> '' then
3197 SetActive(GetControl(FDefControl
))
3205 for a
:= 0 to High(FItems
) do
3206 if ( (Length(FItems
[a
]) > 0) and
3207 (LowerCase(FItems
[a
][1]) = LowerCase(Chr(wParam
))) ) or
3208 ( (Length(FItems
[a
]) > 1) and
3209 (FItems
[a
][1] = #29) and // Ïàïêà
3210 (LowerCase(FItems
[a
][2]) = LowerCase(Chr(wParam
))) ) then
3213 FStartLine
:= Min(Max(FIndex
-1, 0), Length(FItems
)-FHeight
);
3214 if @FOnChangeEvent
<> nil then
3215 FOnChangeEvent(Self
);
3221 procedure TGUIFileListBox
.OpenDir(path
: String);
3229 path
:= IncludeTrailingPathDelimiter(path
);
3230 path
:= ExpandFileName(path
);
3235 if FindFirst(path
+'*', faDirectory
, SR
) = 0 then
3237 if not LongBool(SR
.Attr
and faDirectory
) then
3239 if (SR
.Name
= '.') or
3240 ((SR
.Name
= '..') and (path
= ExpandFileName(FBasePath
))) then
3243 AddItem(#1 + SR
.Name
);
3244 until FindNext(SR
) <> 0;
3254 if i
= 0 then i
:= length(sm
)+1;
3255 sc
:= Copy(sm
, 1, i
-1);
3257 if FindFirst(path
+sc
, faAnyFile
, SR
) = 0 then repeat AddItem(SR
.Name
); until FindNext(SR
) <> 0;
3261 for i
:= 0 to High(FItems
) do
3262 if FItems
[i
][1] = #1 then
3263 FItems
[i
][1] := #29;
3268 procedure TGUIFileListBox
.SetBase(path
: String);
3274 function TGUIFileListBox
.SelectedItem(): String;
3278 if (FIndex
= -1) or (FItems
= nil) or
3279 (FIndex
> High(FItems
)) or
3280 (FItems
[FIndex
][1] = '/') or
3281 (FItems
[FIndex
][1] = '\') then
3284 Result
:= FPath
+ FItems
[FIndex
];
3287 procedure TGUIFileListBox
.UpdateFileList();
3291 if (FIndex
= -1) or (FItems
= nil) or
3292 (FIndex
> High(FItems
)) or
3293 (FItems
[FIndex
][1] = '/') or
3294 (FItems
[FIndex
][1] = '\') then
3297 fn
:= FItems
[FIndex
];
3307 procedure TGUIMemo
.Clear
;
3313 constructor TGUIMemo
.Create(FontID
: DWORD
; Width
, Height
: Word);
3317 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
3322 FDrawScroll
:= True;
3325 procedure TGUIMemo
.Draw
;
3331 if FDrawBack
then DrawBox(FX
, FY
, FWidth
+1, FHeight
);
3333 DrawScroll(FX
+4+FWidth
*16, FY
+4, FHeight
, (FStartLine
> 0) and (FLines
<> nil),
3334 (FStartLine
+FHeight
-1 < High(FLines
)) and (FLines
<> nil));
3336 if FLines
<> nil then
3337 for a
:= FStartLine
to Min(High(FLines
), FStartLine
+FHeight
-1) do
3338 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, FLines
[a
], FColor
.R
, FColor
.G
, FColor
.B
);
3341 function TGUIMemo
.GetHeight
: Integer;
3343 Result
:= 8+FHeight
*16;
3346 function TGUIMemo
.GetWidth
: Integer;
3348 Result
:= 8+(FWidth
+1)*16;
3351 procedure TGUIMemo
.OnMessage(var Msg
: TMessage
);
3353 if not FEnabled
then Exit
;
3357 if FLines
= nil then Exit
;
3363 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
:
3364 if FStartLine
> 0 then
3366 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
:
3367 if FStartLine
< Length(FLines
)-FHeight
then
3369 IK_RETURN
, IK_KPRETURN
:
3372 if FActiveControl
<> Self
then
3378 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
3379 else SetActive(nil);
3385 procedure TGUIMemo
.SetText(Text: string);
3388 FLines
:= GetLines(Text, FFont
.ID
, FWidth
*16);
3393 procedure TGUIimage
.ClearImage();
3395 if FImageRes
= '' then Exit
;
3397 g_Texture_Delete(FImageRes
);
3401 constructor TGUIimage
.Create();
3408 destructor TGUIimage
.Destroy();
3413 procedure TGUIimage
.Draw();
3419 if FImageRes
= '' then
3421 if g_Texture_Get(FDefaultRes
, ID
) then e_Draw(ID
, FX
, FY
, 0, True, False);
3424 if g_Texture_Get(FImageRes
, ID
) then e_Draw(ID
, FX
, FY
, 0, True, False);
3427 procedure TGUIimage
.OnMessage(var Msg
: TMessage
);
3432 procedure TGUIimage
.SetImage(Res
: string);
3436 if g_Texture_CreateWADEx(Res
, Res
) then FImageRes
:= Res
;
3439 procedure TGUIimage
.Update();