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
;
272 procedure SetText(Text: string);
274 constructor Create(FontID
: DWORD
);
275 procedure OnMessage(var Msg
: TMessage
); override;
276 procedure Update
; override;
277 procedure Draw
; override;
278 function GetWidth(): Integer; override;
279 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
280 property OnEnter
: TOnEnterEvent read FOnEnterEvent write FOnEnterEvent
;
281 property Width
: Word read FWidth write FWidth
;
282 property MaxLength
: Word read FMaxLength write FMaxLength
;
283 property OnlyDigits
: Boolean read FOnlyDigits write FOnlyDigits
;
284 property Text: string read FText write SetText
;
285 property Color
: TRGB read FColor write FColor
;
286 property Font
: TFont read FFont write FFont
;
287 property Invalid
: Boolean read FInvalid write FInvalid
;
290 TGUIKeyRead
= class(TGUIControl
)
297 constructor Create(FontID
: DWORD
);
298 procedure OnMessage(var Msg
: TMessage
); override;
299 procedure Draw
; override;
300 function GetWidth(): Integer; override;
301 function WantActivationKey (key
: LongInt): Boolean; override;
302 property Key
: Word read FKey write FKey
;
303 property Color
: TRGB read FColor write FColor
;
304 property Font
: TFont read FFont write FFont
;
308 TGUIKeyRead2
= class(TGUIControl
)
313 FKey0
, FKey1
: Word; // this should be an array. sorry.
316 FMaxKeyNameWdt
: Integer;
318 constructor Create(FontID
: DWORD
);
319 procedure OnMessage(var Msg
: TMessage
); override;
320 procedure Draw
; override;
321 function GetWidth(): Integer; override;
322 function WantActivationKey (key
: LongInt): Boolean; override;
323 property Key0
: Word read FKey0 write FKey0
;
324 property Key1
: Word read FKey1 write FKey1
;
325 property Color
: TRGB read FColor write FColor
;
326 property Font
: TFont read FFont write FFont
;
329 TGUIModelView
= class(TGUIControl
)
331 FModel
: TPlayerModel
;
335 destructor Destroy
; override;
336 procedure OnMessage(var Msg
: TMessage
); override;
337 procedure SetModel(ModelName
: string);
338 procedure SetColor(Red
, Green
, Blue
: Byte);
339 procedure NextAnim();
340 procedure NextWeapon();
341 procedure Update
; override;
342 procedure Draw
; override;
343 property Model
: TPlayerModel read FModel
;
346 TPreviewPanel
= record
347 X1
, Y1
, X2
, Y2
: Integer;
351 TGUIMapPreview
= class(TGUIControl
)
353 FMapData
: array of TPreviewPanel
;
357 constructor Create();
358 destructor Destroy(); override;
359 procedure OnMessage(var Msg
: TMessage
); override;
360 procedure SetMap(Res
: string);
361 procedure ClearMap();
362 procedure Update(); override;
363 procedure Draw(); override;
364 function GetScaleStr
: String;
367 TGUIImage
= class(TGUIControl
)
372 constructor Create();
373 destructor Destroy(); override;
374 procedure OnMessage(var Msg
: TMessage
); override;
375 procedure SetImage(Res
: string);
376 procedure ClearImage();
377 procedure Update(); override;
378 procedure Draw(); override;
379 property DefaultRes
: string read FDefaultRes write FDefaultRes
;
382 TGUIListBox
= class(TGUIControl
)
386 FUnActiveColor
: TRGB
;
394 FDrawScroll
: Boolean;
395 FOnChangeEvent
: TOnChangeEvent
;
397 procedure FSetItems(Items
: SArray
);
398 procedure FSetIndex(aIndex
: Integer);
401 constructor Create(FontID
: DWORD
; Width
, Height
: Word);
402 procedure OnMessage(var Msg
: TMessage
); override;
403 procedure Draw(); override;
404 procedure AddItem(Item
: String);
405 procedure SelectItem(Item
: String);
407 function GetWidth(): Integer; override;
408 function GetHeight(): Integer; override;
409 function SelectedItem(): String;
411 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
412 property Sort
: Boolean read FSort write FSort
;
413 property ItemIndex
: Integer read FIndex write FSetIndex
;
414 property Items
: SArray read FItems write FSetItems
;
415 property DrawBack
: Boolean read FDrawBack write FDrawBack
;
416 property DrawScrollBar
: Boolean read FDrawScroll write FDrawScroll
;
417 property ActiveColor
: TRGB read FActiveColor write FActiveColor
;
418 property UnActiveColor
: TRGB read FUnActiveColor write FUnActiveColor
;
419 property Font
: TFont read FFont write FFont
;
422 TGUIFileListBox
= class(TGUIListBox
)
429 procedure OpenDir(path
: String);
432 procedure OnMessage(var Msg
: TMessage
); override;
433 procedure SetBase(path
: String);
434 function SelectedItem(): String;
435 procedure UpdateFileList();
437 property Dirs
: Boolean read FDirs write FDirs
;
438 property FileMask
: String read FFileMask write FFileMask
;
439 property Path
: String read FPath
;
442 TGUIMemo
= class(TGUIControl
)
451 FDrawScroll
: Boolean;
453 constructor Create(FontID
: DWORD
; Width
, Height
: Word);
454 procedure OnMessage(var Msg
: TMessage
); override;
455 procedure Draw
; override;
457 function GetWidth(): Integer; override;
458 function GetHeight(): Integer; override;
459 procedure SetText(Text: string);
460 property DrawBack
: Boolean read FDrawBack write FDrawBack
;
461 property DrawScrollBar
: Boolean read FDrawScroll write FDrawScroll
;
462 property Color
: TRGB read FColor write FColor
;
463 property Font
: TFont read FFont write FFont
;
466 TGUIMainMenu
= class(TGUIControl
)
468 FButtons
: array of TGUITextButton
;
476 constructor Create(FontID
: DWORD
; Header
: string);
477 destructor Destroy
; override;
478 procedure OnMessage(var Msg
: TMessage
); override;
479 function AddButton(fProc
: Pointer; Caption
: string; ShowWindow
: string = ''): TGUITextButton
;
480 function GetButton(aName
: string): TGUITextButton
;
481 procedure EnableButton(aName
: string; e
: Boolean);
482 procedure AddSpace();
483 procedure Update
; override;
484 procedure Draw
; override;
487 TControlType
= class of TGUIControl
;
489 PMenuItem
= ^TMenuItem
;
492 ControlType
: TControlType
;
493 Control
: TGUIControl
;
496 TGUIMenu
= class(TGUIControl
)
498 FItems
: array of TMenuItem
;
506 function NewItem(): Integer;
508 constructor Create(HeaderFont
, ItemsFont
: DWORD
; Header
: string);
509 destructor Destroy
; override;
510 procedure OnMessage(var Msg
: TMessage
); override;
511 procedure AddSpace();
512 procedure AddLine(fText
: string);
513 procedure AddText(fText
: string; MaxWidth
: Word);
514 function AddLabel(fText
: string): TGUILabel
;
515 function AddButton(Proc
: Pointer; fText
: string; _ShowWindow
: string = ''): TGUITextButton
;
516 function AddScroll(fText
: string): TGUIScroll
;
517 function AddSwitch(fText
: string): TGUISwitch
;
518 function AddEdit(fText
: string): TGUIEdit
;
519 function AddKeyRead(fText
: string): TGUIKeyRead
;
520 function AddKeyRead2(fText
: string): TGUIKeyRead2
;
521 function AddList(fText
: string; Width
, Height
: Word): TGUIListBox
;
522 function AddFileList(fText
: string; Width
, Height
: Word): TGUIFileListBox
;
523 function AddMemo(fText
: string; Width
, Height
: Word): TGUIMemo
;
525 function GetControl(aName
: string): TGUIControl
;
526 function GetControlsText(aName
: string): TGUILabel
;
527 procedure Draw
; override;
528 procedure Update
; override;
529 procedure UpdateIndex();
530 property Align
: Boolean read FAlign write FAlign
;
531 property Left
: Integer read FLeft write FLeft
;
532 property YesNo
: Boolean read FYesNo write FYesNo
;
536 g_GUIWindows
: array of TGUIWindow
;
537 g_ActiveWindow
: TGUIWindow
= nil;
539 procedure g_GUI_Init();
540 function g_GUI_AddWindow(Window
: TGUIWindow
): TGUIWindow
;
541 function g_GUI_GetWindow(Name
: string): TGUIWindow
;
542 procedure g_GUI_ShowWindow(Name
: string);
543 procedure g_GUI_HideWindow(PlaySound
: Boolean = True);
544 function g_GUI_Destroy(): Boolean;
545 procedure g_GUI_SaveMenuPos();
546 procedure g_GUI_LoadMenuPos();
551 GL
, GLExt
, g_textures
, g_sound
, SysUtils
,
552 g_game
, Math
, StrUtils
, g_player
, g_options
,
553 g_map
, g_weapons
, xdynrec
;
556 Box
: Array [0..8] of DWORD
;
557 Saved_Windows
: SArray
;
559 procedure g_GUI_Init();
561 g_Texture_Get(BOX1
, Box
[0]);
562 g_Texture_Get(BOX2
, Box
[1]);
563 g_Texture_Get(BOX3
, Box
[2]);
564 g_Texture_Get(BOX4
, Box
[3]);
565 g_Texture_Get(BOX5
, Box
[4]);
566 g_Texture_Get(BOX6
, Box
[5]);
567 g_Texture_Get(BOX7
, Box
[6]);
568 g_Texture_Get(BOX8
, Box
[7]);
569 g_Texture_Get(BOX9
, Box
[8]);
572 function g_GUI_Destroy(): Boolean;
576 Result
:= (Length(g_GUIWindows
) > 0);
578 for i
:= 0 to High(g_GUIWindows
) do
579 g_GUIWindows
[i
].Free();
582 g_ActiveWindow
:= nil;
585 function g_GUI_AddWindow(Window
: TGUIWindow
): TGUIWindow
;
587 SetLength(g_GUIWindows
, Length(g_GUIWindows
)+1);
588 g_GUIWindows
[High(g_GUIWindows
)] := Window
;
593 function g_GUI_GetWindow(Name
: string): TGUIWindow
;
599 if g_GUIWindows
<> nil then
600 for i
:= 0 to High(g_GUIWindows
) do
601 if g_GUIWindows
[i
].FName
= Name
then
603 Result
:= g_GUIWindows
[i
];
607 Assert(Result
<> nil, 'GUI_Window "'+Name
+'" not found');
610 procedure g_GUI_ShowWindow(Name
: string);
614 if g_GUIWindows
= nil then
617 for i
:= 0 to High(g_GUIWindows
) do
618 if g_GUIWindows
[i
].FName
= Name
then
620 g_GUIWindows
[i
].FPrevWindow
:= g_ActiveWindow
;
621 g_ActiveWindow
:= g_GUIWindows
[i
];
623 if g_ActiveWindow
.MainWindow
then
624 g_ActiveWindow
.FPrevWindow
:= nil;
626 if g_ActiveWindow
.FDefControl
<> '' then
627 g_ActiveWindow
.SetActive(g_ActiveWindow
.GetControl(g_ActiveWindow
.FDefControl
))
629 g_ActiveWindow
.SetActive(nil);
631 if @g_ActiveWindow
.FOnShowEvent
<> nil then
632 g_ActiveWindow
.FOnShowEvent();
638 procedure g_GUI_HideWindow(PlaySound
: Boolean = True);
640 if g_ActiveWindow
<> nil then
642 if @g_ActiveWindow
.OnClose
<> nil then
643 g_ActiveWindow
.OnClose();
644 g_ActiveWindow
:= g_ActiveWindow
.FPrevWindow
;
646 g_Sound_PlayEx(WINDOW_CLOSESOUND
);
650 procedure g_GUI_SaveMenuPos();
655 SetLength(Saved_Windows
, 0);
656 win
:= g_ActiveWindow
;
660 len
:= Length(Saved_Windows
);
661 SetLength(Saved_Windows
, len
+ 1);
663 Saved_Windows
[len
] := win
.Name
;
665 if win
.MainWindow
then
668 win
:= win
.FPrevWindow
;
672 procedure g_GUI_LoadMenuPos();
674 i
, j
, k
, len
: Integer;
677 g_ActiveWindow
:= nil;
678 len
:= Length(Saved_Windows
);
683 // Îêíî ñ ãëàâíûì ìåíþ:
684 g_GUI_ShowWindow(Saved_Windows
[len
-1]);
686 // Íå ïåðåêëþ÷èëîñü (èëè íåêóäà äàëüøå):
687 if (len
= 1) or (g_ActiveWindow
= nil) then
690 // Èùåì êíîïêè â îñòàëüíûõ îêíàõ:
691 for k
:= len
-1 downto 1 do
695 for i
:= 0 to Length(g_ActiveWindow
.Childs
)-1 do
697 if g_ActiveWindow
.Childs
[i
] is TGUIMainMenu
then
698 begin // GUI_MainMenu
699 with TGUIMainMenu(g_ActiveWindow
.Childs
[i
]) do
700 for j
:= 0 to Length(FButtons
)-1 do
701 if FButtons
[j
].ShowWindow
= Saved_Windows
[k
-1] then
703 FButtons
[j
].Click(True);
709 if g_ActiveWindow
.Childs
[i
] is TGUIMenu
then
710 with TGUIMenu(g_ActiveWindow
.Childs
[i
]) do
711 for j
:= 0 to Length(FItems
)-1 do
712 if FItems
[j
].ControlType
= TGUITextButton
then
713 if TGUITextButton(FItems
[j
].Control
).ShowWindow
= Saved_Windows
[k
-1] then
715 TGUITextButton(FItems
[j
].Control
).Click(True);
726 (g_ActiveWindow
.Name
= Saved_Windows
[k
]) then
731 procedure DrawBox(X
, Y
: Integer; Width
, Height
: Word);
733 e_Draw(Box
[0], X
, Y
, 0, False, False);
734 e_DrawFill(Box
[1], X
+4, Y
, Width
*4, 1, 0, False, False);
735 e_Draw(Box
[2], X
+4+Width
*16, Y
, 0, False, False);
736 e_DrawFill(Box
[3], X
, Y
+4, 1, Height
*4, 0, False, False);
737 e_DrawFill(Box
[4], X
+4, Y
+4, Width
, Height
, 0, False, False);
738 e_DrawFill(Box
[5], X
+4+Width
*16, Y
+4, 1, Height
*4, 0, False, False);
739 e_Draw(Box
[6], X
, Y
+4+Height
*16, 0, False, False);
740 e_DrawFill(Box
[7], X
+4, Y
+4+Height
*16, Width
*4, 1, 0, False, False);
741 e_Draw(Box
[8], X
+4+Width
*16, Y
+4+Height
*16, 0, False, False);
744 procedure DrawScroll(X
, Y
: Integer; Height
: Word; Up
, Down
: Boolean);
748 if Height
< 3 then Exit
;
751 g_Texture_Get(BSCROLL_UPA
, ID
)
753 g_Texture_Get(BSCROLL_UPU
, ID
);
754 e_Draw(ID
, X
, Y
, 0, False, False);
757 g_Texture_Get(BSCROLL_DOWNA
, ID
)
759 g_Texture_Get(BSCROLL_DOWNU
, ID
);
760 e_Draw(ID
, X
, Y
+(Height
-1)*16, 0, False, False);
762 g_Texture_Get(BSCROLL_MIDDLE
, ID
);
763 e_DrawFill(ID
, X
, Y
+16, 1, Height
-2, 0, False, False);
768 constructor TGUIWindow
.Create(Name
: string);
771 FActiveControl
:= nil;
775 FOnCloseEvent
:= nil;
779 destructor TGUIWindow
.Destroy
;
786 for i
:= 0 to High(Childs
) do
790 function TGUIWindow
.AddChild(Child
: TGUIControl
): TGUIControl
;
792 Child
.FWindow
:= Self
;
794 SetLength(Childs
, Length(Childs
) + 1);
795 Childs
[High(Childs
)] := Child
;
800 procedure TGUIWindow
.Update
;
804 for i
:= 0 to High(Childs
) do
805 if Childs
[i
] <> nil then Childs
[i
].Update
;
808 procedure TGUIWindow
.Draw
;
813 if FBackTexture
<> '' then
814 if g_Texture_Get(FBackTexture
, ID
) then
815 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
817 e_Clear(GL_COLOR_BUFFER_BIT
, 0.5, 0.5, 0.5);
819 for i
:= 0 to High(Childs
) do
820 if Childs
[i
] <> nil then Childs
[i
].Draw
;
823 procedure TGUIWindow
.OnMessage(var Msg
: TMessage
);
825 if FActiveControl
<> nil then FActiveControl
.OnMessage(Msg
);
826 if @FOnKeyDown
<> nil then FOnKeyDown(Msg
.wParam
);
827 if @FOnKeyDownEx
<> nil then FOnKeyDownEx(self
, Msg
.wParam
);
829 if Msg
.Msg
= WM_KEYDOWN
then
830 if Msg
.wParam
= IK_ESCAPE
then
837 procedure TGUIWindow
.SetActive(Control
: TGUIControl
);
839 FActiveControl
:= Control
;
842 function TGUIWindow
.GetControl(Name
: String): TGUIControl
;
848 if Childs
<> nil then
849 for i
:= 0 to High(Childs
) do
850 if Childs
[i
] <> nil then
851 if LowerCase(Childs
[i
].FName
) = LowerCase(Name
) then
857 Assert(Result
<> nil, 'Window Control "'+Name
+'" not Found!');
862 constructor TGUIControl
.Create();
868 FRightAlign
:= false;
872 procedure TGUIControl
.OnMessage(var Msg
: TMessage
);
878 procedure TGUIControl
.Update();
882 procedure TGUIControl
.Draw();
886 function TGUIControl
.WantActivationKey (key
: LongInt): Boolean;
891 function TGUIControl
.GetWidth(): Integer;
896 function TGUIControl
.GetHeight(): Integer;
903 procedure TGUITextButton
.Click(Silent
: Boolean = False);
905 if (FSound
<> '') and (not Silent
) then g_Sound_PlayEx(FSound
);
907 if @Proc
<> nil then Proc();
908 if @ProcEx
<> nil then ProcEx(self
);
910 if FShowWindow
<> '' then g_GUI_ShowWindow(FShowWindow
);
913 constructor TGUITextButton
.Create(aProc
: Pointer; FontID
: DWORD
; Text: string);
920 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
925 destructor TGUITextButton
.Destroy
;
931 procedure TGUITextButton
.Draw
;
933 FFont
.Draw(FX
, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
)
936 function TGUITextButton
.GetHeight
: Integer;
940 FFont
.GetTextSize(FText
, w
, h
);
944 function TGUITextButton
.GetWidth
: Integer;
948 FFont
.GetTextSize(FText
, w
, h
);
952 procedure TGUITextButton
.OnMessage(var Msg
: TMessage
);
954 if not FEnabled
then Exit
;
961 IK_RETURN
, IK_KPRETURN
: Click();
966 procedure TGUITextButton
.Update
;
973 constructor TFont
.Create(FontID
: DWORD
; FontType
: TFontType
);
978 FFontType
:= FontType
;
981 destructor TFont
.Destroy
;
987 procedure TFont
.Draw(X
, Y
: Integer; Text: string; R
, G
, B
: Byte);
989 if FFontType
= FONT_CHAR
then e_CharFont_PrintEx(ID
, X
, Y
, Text, _RGB(R
, G
, B
), FScale
)
990 else e_TextureFontPrintEx(X
, Y
, Text, ID
, R
, G
, B
, FScale
);
993 procedure TFont
.GetTextSize(Text: string; var w
, h
: Word);
997 if FFontType
= FONT_CHAR
then e_CharFont_GetSize(ID
, Text, w
, h
)
1000 e_TextureFontGetSize(ID
, cw
, ch
);
1001 w
:= cw
*Length(Text);
1005 w
:= Round(w
*FScale
);
1006 h
:= Round(h
*FScale
);
1011 function TGUIMainMenu
.AddButton(fProc
: Pointer; Caption
: string; ShowWindow
: string = ''): TGUITextButton
;
1018 SetLength(FButtons
, Length(FButtons
)+1);
1019 FButtons
[High(FButtons
)] := TGUITextButton
.Create(fProc
, FFontID
, Caption
);
1020 FButtons
[High(FButtons
)].ShowWindow
:= ShowWindow
;
1021 with FButtons
[High(FButtons
)] do
1023 if (fProc
<> nil) or (ShowWindow
<> '') then FColor
:= MAINMENU_ITEMS_COLOR
1024 else FColor
:= MAINMENU_UNACTIVEITEMS_COLOR
;
1025 FSound
:= MAINMENU_CLICKSOUND
;
1028 _x
:= gScreenWidth
div 2;
1030 for a
:= 0 to High(FButtons
) do
1031 if FButtons
[a
] <> nil then
1032 _x
:= Min(_x
, (gScreenWidth
div 2)-(FButtons
[a
].GetWidth
div 2));
1034 hh
:= FHeader
.GetHeight
;
1036 h
:= hh
*(2+Length(FButtons
))+MAINMENU_SPACE
*(Length(FButtons
)-1);
1037 h
:= (gScreenHeight
div 2)-(h
div 2);
1047 for a
:= 0 to High(FButtons
) do
1049 if FButtons
[a
] <> nil then
1056 Inc(h
, hh
+MAINMENU_SPACE
);
1059 Result
:= FButtons
[High(FButtons
)];
1062 procedure TGUIMainMenu
.AddSpace
;
1064 SetLength(FButtons
, Length(FButtons
)+1);
1065 FButtons
[High(FButtons
)] := nil;
1068 constructor TGUIMainMenu
.Create(FontID
: DWORD
; Header
: string);
1074 FCounter
:= MAINMENU_MARKERDELAY
;
1076 g_Texture_Get(MAINMENU_MARKER1
, FMarkerID1
);
1077 g_Texture_Get(MAINMENU_MARKER2
, FMarkerID2
);
1079 FHeader
:= TGUILabel
.Create(Header
, FFontID
);
1082 FColor
:= MAINMENU_HEADER_COLOR
;
1083 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1084 FY
:= (gScreenHeight
div 2)-(GetHeight
div 2);
1088 destructor TGUIMainMenu
.Destroy
;
1092 if FButtons
<> nil then
1093 for a
:= 0 to High(FButtons
) do
1101 procedure TGUIMainMenu
.Draw
;
1109 if FButtons
<> nil then
1111 for a
:= 0 to High(FButtons
) do
1112 if FButtons
[a
] <> nil then FButtons
[a
].Draw
;
1114 if FIndex
<> -1 then
1115 e_Draw(FMarkerID1
, FButtons
[FIndex
].FX
-48, FButtons
[FIndex
].FY
, 0, True, False);
1119 procedure TGUIMainMenu
.EnableButton(aName
: string; e
: Boolean);
1123 if FButtons
= nil then Exit
;
1125 for a
:= 0 to High(FButtons
) do
1126 if (FButtons
[a
] <> nil) and (FButtons
[a
].Name
= aName
) then
1128 if e
then FButtons
[a
].FColor
:= MAINMENU_ITEMS_COLOR
1129 else FButtons
[a
].FColor
:= MAINMENU_UNACTIVEITEMS_COLOR
;
1130 FButtons
[a
].Enabled
:= e
;
1135 function TGUIMainMenu
.GetButton(aName
: string): TGUITextButton
;
1141 if FButtons
= nil then Exit
;
1143 for a
:= 0 to High(FButtons
) do
1144 if (FButtons
[a
] <> nil) and (FButtons
[a
].Name
= aName
) then
1146 Result
:= FButtons
[a
];
1151 procedure TGUIMainMenu
.OnMessage(var Msg
: TMessage
);
1156 if not FEnabled
then Exit
;
1160 if FButtons
= nil then Exit
;
1163 for a
:= 0 to High(FButtons
) do
1164 if FButtons
[a
] <> nil then
1170 if not ok
then Exit
;
1179 if FIndex
< 0 then FIndex
:= High(FButtons
);
1180 until FButtons
[FIndex
] <> nil;
1182 g_Sound_PlayEx(MENU_CHANGESOUND
);
1188 if FIndex
> High(FButtons
) then FIndex
:= 0;
1189 until FButtons
[FIndex
] <> nil;
1191 g_Sound_PlayEx(MENU_CHANGESOUND
);
1193 IK_RETURN
, IK_KPRETURN
: if (FIndex
<> -1) and FButtons
[FIndex
].FEnabled
then FButtons
[FIndex
].Click
;
1198 procedure TGUIMainMenu
.Update
;
1204 if FCounter
= 0 then
1207 FMarkerID1
:= FMarkerID2
;
1210 FCounter
:= MAINMENU_MARKERDELAY
;
1211 end else Dec(FCounter
);
1216 constructor TGUILabel
.Create(Text: string; FontID
: DWORD
);
1220 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
1224 FOnClickEvent
:= nil;
1227 procedure TGUILabel
.Draw
;
1233 FFont
.GetTextSize(FText
, w
, h
);
1234 FFont
.Draw(FX
+FMaxWidth
-w
, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
);
1238 FFont
.Draw(FX
, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
);
1242 function TGUILabel
.GetHeight
: Integer;
1246 FFont
.GetTextSize(FText
, w
, h
);
1250 function TGUILabel
.GetWidth
: Integer;
1254 if FFixedLen
= 0 then
1255 FFont
.GetTextSize(FText
, w
, h
)
1257 w
:= e_CharFont_GetMaxWidth(FFont
.ID
)*FFixedLen
;
1261 procedure TGUILabel
.OnMessage(var Msg
: TMessage
);
1263 if not FEnabled
then Exit
;
1270 IK_RETURN
, IK_KPRETURN
: if @FOnClickEvent
<> nil then FOnClickEvent();
1277 function TGUIMenu
.AddButton(Proc
: Pointer; fText
: string; _ShowWindow
: string = ''): TGUITextButton
;
1284 Control
:= TGUITextButton
.Create(Proc
, FFontID
, fText
);
1285 with Control
as TGUITextButton
do
1287 ShowWindow
:= _ShowWindow
;
1288 FColor
:= MENU_ITEMSCTRL_COLOR
;
1292 ControlType
:= TGUITextButton
;
1294 Result
:= (Control
as TGUITextButton
);
1297 if FIndex
= -1 then FIndex
:= i
;
1302 procedure TGUIMenu
.AddLine(fText
: string);
1309 Text := TGUILabel
.Create(fText
, FFontID
);
1312 FColor
:= MENU_ITEMSTEXT_COLOR
;
1321 procedure TGUIMenu
.AddText(fText
: string; MaxWidth
: Word);
1326 l
:= GetLines(fText
, FFontID
, MaxWidth
);
1328 if l
= nil then Exit
;
1330 for a
:= 0 to High(l
) do
1335 Text := TGUILabel
.Create(l
[a
], FFontID
);
1338 with Text do begin FColor
:= _RGB(255, 0, 0); end;
1342 with Text do begin FColor
:= MENU_ITEMSTEXT_COLOR
; end;
1352 procedure TGUIMenu
.AddSpace
;
1366 constructor TGUIMenu
.Create(HeaderFont
, ItemsFont
: DWORD
; Header
: string);
1372 FFontID
:= ItemsFont
;
1373 FCounter
:= MENU_MARKERDELAY
;
1377 FHeader
:= TGUILabel
.Create(Header
, HeaderFont
);
1380 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1382 FColor
:= MAINMENU_HEADER_COLOR
;
1386 destructor TGUIMenu
.Destroy
;
1390 if FItems
<> nil then
1391 for a
:= 0 to High(FItems
) do
1405 procedure TGUIMenu
.Draw
;
1407 a
, locx
, locy
: Integer;
1411 if FHeader
<> nil then FHeader
.Draw
;
1413 if FItems
<> nil then
1414 for a
:= 0 to High(FItems
) do
1416 if FItems
[a
].Text <> nil then FItems
[a
].Text.Draw
;
1417 if FItems
[a
].Control
<> nil then FItems
[a
].Control
.Draw
;
1420 if (FIndex
<> -1) and (FCounter
> MENU_MARKERDELAY
div 2) then
1425 if FItems
[FIndex
].Text <> nil then
1427 locx
:= FItems
[FIndex
].Text.FX
;
1428 locy
:= FItems
[FIndex
].Text.FY
;
1430 if FItems
[FIndex
].Text.RightAlign
then
1432 locx
:= locx
+FItems
[FIndex
].Text.FMaxWidth
-FItems
[FIndex
].Text.GetWidth
;
1435 else if FItems
[FIndex
].Control
<> nil then
1437 locx
:= FItems
[FIndex
].Control
.FX
;
1438 locy
:= FItems
[FIndex
].Control
.FY
;
1441 locx
:= locx
-e_CharFont_GetMaxWidth(FFontID
);
1443 e_CharFont_PrintEx(FFontID
, locx
, locy
, #16, _RGB(255, 0, 0));
1447 function TGUIMenu
.GetControl(aName
: String): TGUIControl
;
1453 if FItems
<> nil then
1454 for a
:= 0 to High(FItems
) do
1455 if FItems
[a
].Control
<> nil then
1456 if LowerCase(FItems
[a
].Control
.Name
) = LowerCase(aName
) then
1458 Result
:= FItems
[a
].Control
;
1462 Assert(Result
<> nil, 'GUI control "'+aName
+'" not found!');
1465 function TGUIMenu
.GetControlsText(aName
: String): TGUILabel
;
1471 if FItems
<> nil then
1472 for a
:= 0 to High(FItems
) do
1473 if FItems
[a
].Control
<> nil then
1474 if LowerCase(FItems
[a
].Control
.Name
) = LowerCase(aName
) then
1476 Result
:= FItems
[a
].Text;
1480 Assert(Result
<> nil, 'GUI control''s text "'+aName
+'" not found!');
1483 function TGUIMenu
.NewItem
: Integer;
1485 SetLength(FItems
, Length(FItems
)+1);
1486 Result
:= High(FItems
);
1489 procedure TGUIMenu
.OnMessage(var Msg
: TMessage
);
1494 if not FEnabled
then Exit
;
1498 if FItems
= nil then Exit
;
1501 for a
:= 0 to High(FItems
) do
1502 if FItems
[a
].Control
<> nil then
1508 if not ok
then Exit
;
1510 if (Msg
.Msg
= WM_KEYDOWN
) and (FIndex
<> -1) and (FItems
[FIndex
].Control
<> nil) and
1511 (FItems
[FIndex
].Control
.WantActivationKey(Msg
.wParam
)) then
1513 FItems
[FIndex
].Control
.OnMessage(Msg
);
1514 g_Sound_PlayEx(MENU_CLICKSOUND
);
1527 if c
> Length(FItems
) then
1534 if FIndex
< 0 then FIndex
:= High(FItems
);
1535 until (FItems
[FIndex
].Control
<> nil) and
1536 (FItems
[FIndex
].Control
.Enabled
);
1540 g_Sound_PlayEx(MENU_CHANGESOUND
);
1548 if c
> Length(FItems
) then
1555 if FIndex
> High(FItems
) then FIndex
:= 0;
1556 until (FItems
[FIndex
].Control
<> nil) and
1557 (FItems
[FIndex
].Control
.Enabled
);
1561 g_Sound_PlayEx(MENU_CHANGESOUND
);
1564 IK_LEFT
, IK_RIGHT
, IK_KPLEFT
, IK_KPRIGHT
:
1566 if FIndex
<> -1 then
1567 if FItems
[FIndex
].Control
<> nil then
1568 FItems
[FIndex
].Control
.OnMessage(Msg
);
1570 IK_RETURN
, IK_KPRETURN
:
1572 if FIndex
<> -1 then
1574 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1576 g_Sound_PlayEx(MENU_CLICKSOUND
);
1580 if FYesNo
and (length(FItems
) > 1) then
1582 Msg
.wParam
:= IK_RETURN
; // to register keypress
1583 FIndex
:= High(FItems
)-1;
1584 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1587 if FYesNo
and (length(FItems
) > 1) then
1589 Msg
.wParam
:= IK_RETURN
; // to register keypress
1590 FIndex
:= High(FItems
);
1591 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1598 procedure TGUIMenu
.ReAlign();
1600 a
, tx
, cx
, w
, h
: Integer;
1601 cww
: array of Integer; // cached widths
1604 if FItems
= nil then Exit
;
1606 SetLength(cww
, length(FItems
));
1608 for a
:= 0 to High(FItems
) do
1610 if FItems
[a
].Text <> nil then
1612 cww
[a
] := FItems
[a
].Text.GetWidth
;
1613 if maxcww
< cww
[a
] then maxcww
:= cww
[a
];
1624 for a
:= 0 to High(FItems
) do
1627 if FItems
[a
].Text <> nil then w
:= FItems
[a
].Text.GetWidth
;
1628 if FItems
[a
].Control
<> nil then
1631 if FItems
[a
].ControlType
= TGUILabel
then w
:= w
+(FItems
[a
].Control
as TGUILabel
).GetWidth
1632 else if FItems
[a
].ControlType
= TGUITextButton
then w
:= w
+(FItems
[a
].Control
as TGUITextButton
).GetWidth
1633 else if FItems
[a
].ControlType
= TGUIScroll
then w
:= w
+(FItems
[a
].Control
as TGUIScroll
).GetWidth
1634 else if FItems
[a
].ControlType
= TGUISwitch
then w
:= w
+(FItems
[a
].Control
as TGUISwitch
).GetWidth
1635 else if FItems
[a
].ControlType
= TGUIEdit
then w
:= w
+(FItems
[a
].Control
as TGUIEdit
).GetWidth
1636 else if FItems
[a
].ControlType
= TGUIKeyRead
then w
:= w
+(FItems
[a
].Control
as TGUIKeyRead
).GetWidth
1637 else if FItems
[a
].ControlType
= TGUIKeyRead2
then w
:= w
+(FItems
[a
].Control
as TGUIKeyRead2
).GetWidth
1638 else if FItems
[a
].ControlType
= TGUIListBox
then w
:= w
+(FItems
[a
].Control
as TGUIListBox
).GetWidth
1639 else if FItems
[a
].ControlType
= TGUIFileListBox
then w
:= w
+(FItems
[a
].Control
as TGUIFileListBox
).GetWidth
1640 else if FItems
[a
].ControlType
= TGUIMemo
then w
:= w
+(FItems
[a
].Control
as TGUIMemo
).GetWidth
;
1642 tx
:= Min(tx
, (gScreenWidth
div 2)-(w
div 2));
1647 for a
:= 0 to High(FItems
) do
1651 if (Text <> nil) and (Control
= nil) then Continue
;
1653 if Text <> nil then w
:= tx
+Text.GetWidth
;
1654 if w
> cx
then cx
:= w
;
1658 cx
:= cx
+MENU_HSPACE
;
1660 h
:= FHeader
.GetHeight
*2+MENU_VSPACE
*(Length(FItems
)-1);
1662 for a
:= 0 to High(FItems
) do
1666 if (ControlType
= TGUIListBox
) or (ControlType
= TGUIFileListBox
) then
1667 h
:= h
+(FItems
[a
].Control
as TGUIListBox
).GetHeight()
1669 h
:= h
+e_CharFont_GetMaxHeight(FFontID
);
1673 h
:= (gScreenHeight
div 2)-(h
div 2);
1677 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1680 Inc(h
, GetHeight
*2);
1683 for a
:= 0 to High(FItems
) do
1695 if Text.RightAlign
and (length(cww
) > a
) then
1697 //Text.FX := Text.FX+maxcww;
1698 Text.FMaxWidth
:= maxcww
;
1702 if Control
<> nil then
1719 if (ControlType
= TGUIListBox
) or (ControlType
= TGUIFileListBox
) then Inc(h
, (Control
as TGUIListBox
).GetHeight
+MENU_VSPACE
)
1720 else if ControlType
= TGUIMemo
then Inc(h
, (Control
as TGUIMemo
).GetHeight
+MENU_VSPACE
)
1721 else Inc(h
, e_CharFont_GetMaxHeight(FFontID
)+MENU_VSPACE
);
1725 // another ugly hack
1726 if FYesNo
and (length(FItems
) > 1) then
1729 for a
:= High(FItems
)-1 to High(FItems
) do
1731 if (FItems
[a
].Control
<> nil) and (FItems
[a
].ControlType
= TGUITextButton
) then
1733 cx
:= (FItems
[a
].Control
as TGUITextButton
).GetWidth
;
1734 if cx
> w
then w
:= cx
;
1739 for a
:= High(FItems
)-1 to High(FItems
) do
1741 if (FItems
[a
].Control
<> nil) and (FItems
[a
].ControlType
= TGUITextButton
) then
1743 FItems
[a
].Control
.FX
:= (gScreenWidth
-w
) div 2;
1750 function TGUIMenu
.AddScroll(fText
: string): TGUIScroll
;
1757 Control
:= TGUIScroll
.Create();
1759 Text := TGUILabel
.Create(fText
, FFontID
);
1762 FColor
:= MENU_ITEMSTEXT_COLOR
;
1765 ControlType
:= TGUIScroll
;
1767 Result
:= (Control
as TGUIScroll
);
1770 if FIndex
= -1 then FIndex
:= i
;
1775 function TGUIMenu
.AddSwitch(fText
: string): TGUISwitch
;
1782 Control
:= TGUISwitch
.Create(FFontID
);
1783 (Control
as TGUISwitch
).FColor
:= MENU_ITEMSCTRL_COLOR
;
1785 Text := TGUILabel
.Create(fText
, FFontID
);
1788 FColor
:= MENU_ITEMSTEXT_COLOR
;
1791 ControlType
:= TGUISwitch
;
1793 Result
:= (Control
as TGUISwitch
);
1796 if FIndex
= -1 then FIndex
:= i
;
1801 function TGUIMenu
.AddEdit(fText
: string): TGUIEdit
;
1808 Control
:= TGUIEdit
.Create(FFontID
);
1809 with Control
as TGUIEdit
do
1811 FWindow
:= Self
.FWindow
;
1812 FColor
:= MENU_ITEMSCTRL_COLOR
;
1815 if fText
= '' then Text := nil else
1817 Text := TGUILabel
.Create(fText
, FFontID
);
1818 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
1821 ControlType
:= TGUIEdit
;
1823 Result
:= (Control
as TGUIEdit
);
1826 if FIndex
= -1 then FIndex
:= i
;
1831 procedure TGUIMenu
.Update
;
1837 if FCounter
= 0 then FCounter
:= MENU_MARKERDELAY
else Dec(FCounter
);
1839 if FItems
<> nil then
1840 for a
:= 0 to High(FItems
) do
1841 if FItems
[a
].Control
<> nil then
1842 (FItems
[a
].Control
as FItems
[a
].ControlType
).Update
;
1845 function TGUIMenu
.AddKeyRead(fText
: string): TGUIKeyRead
;
1852 Control
:= TGUIKeyRead
.Create(FFontID
);
1853 with Control
as TGUIKeyRead
do
1855 FWindow
:= Self
.FWindow
;
1856 FColor
:= MENU_ITEMSCTRL_COLOR
;
1859 Text := TGUILabel
.Create(fText
, FFontID
);
1862 FColor
:= MENU_ITEMSTEXT_COLOR
;
1865 ControlType
:= TGUIKeyRead
;
1867 Result
:= (Control
as TGUIKeyRead
);
1870 if FIndex
= -1 then FIndex
:= i
;
1875 function TGUIMenu
.AddKeyRead2(fText
: string): TGUIKeyRead2
;
1882 Control
:= TGUIKeyRead2
.Create(FFontID
);
1883 with Control
as TGUIKeyRead2
do
1885 FWindow
:= Self
.FWindow
;
1886 FColor
:= MENU_ITEMSCTRL_COLOR
;
1889 Text := TGUILabel
.Create(fText
, FFontID
);
1892 FColor
:= MENU_ITEMSCTRL_COLOR
; //MENU_ITEMSTEXT_COLOR;
1896 ControlType
:= TGUIKeyRead2
;
1898 Result
:= (Control
as TGUIKeyRead2
);
1901 if FIndex
= -1 then FIndex
:= i
;
1906 function TGUIMenu
.AddList(fText
: string; Width
, Height
: Word): TGUIListBox
;
1913 Control
:= TGUIListBox
.Create(FFontID
, Width
, Height
);
1914 with Control
as TGUIListBox
do
1916 FWindow
:= Self
.FWindow
;
1917 FActiveColor
:= MENU_ITEMSCTRL_COLOR
;
1918 FUnActiveColor
:= MENU_ITEMSTEXT_COLOR
;
1921 Text := TGUILabel
.Create(fText
, FFontID
);
1924 FColor
:= MENU_ITEMSTEXT_COLOR
;
1927 ControlType
:= TGUIListBox
;
1929 Result
:= (Control
as TGUIListBox
);
1932 if FIndex
= -1 then FIndex
:= i
;
1937 function TGUIMenu
.AddFileList(fText
: string; Width
, Height
: Word): TGUIFileListBox
;
1944 Control
:= TGUIFileListBox
.Create(FFontID
, Width
, Height
);
1945 with Control
as TGUIFileListBox
do
1947 FWindow
:= Self
.FWindow
;
1948 FActiveColor
:= MENU_ITEMSCTRL_COLOR
;
1949 FUnActiveColor
:= MENU_ITEMSTEXT_COLOR
;
1952 if fText
= '' then Text := nil else
1954 Text := TGUILabel
.Create(fText
, FFontID
);
1955 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
1958 ControlType
:= TGUIFileListBox
;
1960 Result
:= (Control
as TGUIFileListBox
);
1963 if FIndex
= -1 then FIndex
:= i
;
1968 function TGUIMenu
.AddLabel(fText
: string): TGUILabel
;
1975 Control
:= TGUILabel
.Create('', FFontID
);
1976 with Control
as TGUILabel
do
1978 FWindow
:= Self
.FWindow
;
1979 FColor
:= MENU_ITEMSCTRL_COLOR
;
1982 Text := TGUILabel
.Create(fText
, FFontID
);
1985 FColor
:= MENU_ITEMSTEXT_COLOR
;
1988 ControlType
:= TGUILabel
;
1990 Result
:= (Control
as TGUILabel
);
1993 if FIndex
= -1 then FIndex
:= i
;
1998 function TGUIMenu
.AddMemo(fText
: string; Width
, Height
: Word): TGUIMemo
;
2005 Control
:= TGUIMemo
.Create(FFontID
, Width
, Height
);
2006 with Control
as TGUIMemo
do
2008 FWindow
:= Self
.FWindow
;
2009 FColor
:= MENU_ITEMSTEXT_COLOR
;
2012 if fText
= '' then Text := nil else
2014 Text := TGUILabel
.Create(fText
, FFontID
);
2015 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
2018 ControlType
:= TGUIMemo
;
2020 Result
:= (Control
as TGUIMemo
);
2023 if FIndex
= -1 then FIndex
:= i
;
2028 procedure TGUIMenu
.UpdateIndex();
2036 if (FIndex
< 0) or (FIndex
> High(FItems
)) then
2042 if FItems
[FIndex
].Control
.Enabled
then
2051 constructor TGUIScroll
.Create
;
2056 FOnChangeEvent
:= nil;
2058 g_Texture_Get(SCROLL_LEFT
, FLeftID
);
2059 g_Texture_Get(SCROLL_RIGHT
, FRightID
);
2060 g_Texture_Get(SCROLL_MIDDLE
, FMiddleID
);
2061 g_Texture_Get(SCROLL_MARKER
, FMarkerID
);
2064 procedure TGUIScroll
.Draw
;
2070 e_Draw(FLeftID
, FX
, FY
, 0, True, False);
2071 e_Draw(FRightID
, FX
+8+(FMax
+1)*8, FY
, 0, True, False);
2073 for a
:= 0 to FMax
do
2074 e_Draw(FMiddleID
, FX
+8+a
*8, FY
, 0, True, False);
2076 e_Draw(FMarkerID
, FX
+8+FValue
*8, FY
, 0, True, False);
2079 procedure TGUIScroll
.FSetValue(a
: Integer);
2081 if a
> FMax
then FValue
:= FMax
else FValue
:= a
;
2084 function TGUIScroll
.GetWidth
: Integer;
2086 Result
:= 16+(FMax
+1)*8;
2089 procedure TGUIScroll
.OnMessage(var Msg
: TMessage
);
2091 if not FEnabled
then Exit
;
2103 g_Sound_PlayEx(SCROLL_SUBSOUND
);
2104 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2106 IK_RIGHT
, IK_KPRIGHT
:
2107 if FValue
< FMax
then
2110 g_Sound_PlayEx(SCROLL_ADDSOUND
);
2111 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2118 procedure TGUIScroll
.Update
;
2126 procedure TGUISwitch
.AddItem(Item
: string);
2128 SetLength(FItems
, Length(FItems
)+1);
2129 FItems
[High(FItems
)] := Item
;
2131 if FIndex
= -1 then FIndex
:= 0;
2134 constructor TGUISwitch
.Create(FontID
: DWORD
);
2140 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
2143 procedure TGUISwitch
.Draw
;
2147 FFont
.Draw(FX
, FY
, FItems
[FIndex
], FColor
.R
, FColor
.G
, FColor
.B
);
2150 function TGUISwitch
.GetText
: string;
2152 if FIndex
<> -1 then Result
:= FItems
[FIndex
]
2156 function TGUISwitch
.GetWidth
: Integer;
2163 if FItems
= nil then Exit
;
2165 for a
:= 0 to High(FItems
) do
2167 FFont
.GetTextSize(FItems
[a
], w
, h
);
2168 if w
> Result
then Result
:= w
;
2172 procedure TGUISwitch
.OnMessage(var Msg
: TMessage
);
2174 if not FEnabled
then Exit
;
2178 if FItems
= nil then Exit
;
2183 IK_RETURN
, IK_RIGHT
, IK_KPRETURN
, IK_KPRIGHT
:
2185 if FIndex
< High(FItems
) then
2190 if @FOnChangeEvent
<> nil then
2191 FOnChangeEvent(Self
);
2199 FIndex
:= High(FItems
);
2201 if @FOnChangeEvent
<> nil then
2202 FOnChangeEvent(Self
);
2208 procedure TGUISwitch
.Update
;
2216 constructor TGUIEdit
.Create(FontID
: DWORD
);
2220 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
2226 g_Texture_Get(EDIT_LEFT
, FLeftID
);
2227 g_Texture_Get(EDIT_RIGHT
, FRightID
);
2228 g_Texture_Get(EDIT_MIDDLE
, FMiddleID
);
2231 procedure TGUIEdit
.Draw
;
2238 e_Draw(FLeftID
, FX
, FY
, 0, True, False);
2239 e_Draw(FRightID
, FX
+8+FWidth
*16, FY
, 0, True, False);
2241 for c
:= 0 to FWidth
-1 do
2242 e_Draw(FMiddleID
, FX
+8+c
*16, FY
, 0, True, False);
2247 if FInvalid
and (FWindow
.FActiveControl
<> self
) then begin r
:= 128; g
:= 128; b
:= 128; end;
2248 FFont
.Draw(FX
+8, FY
, FText
, r
, g
, b
);
2250 if (FWindow
.FActiveControl
= self
) then
2252 FFont
.GetTextSize(Copy(FText
, 1, FCaretPos
), w
, h
);
2253 h
:= e_CharFont_GetMaxHeight(FFont
.ID
);
2254 e_DrawLine(2, FX
+8+w
, FY
+h
-3, FX
+8+w
+EDIT_CURSORLEN
, FY
+h
-3,
2255 EDIT_CURSORCOLOR
.R
, EDIT_CURSORCOLOR
.G
, EDIT_CURSORCOLOR
.B
);
2259 function TGUIEdit
.GetWidth
: Integer;
2261 Result
:= 16+FWidth
*16;
2264 procedure TGUIEdit
.OnMessage(var Msg
: TMessage
);
2266 if not FEnabled
then Exit
;
2275 if (wParam
in [48..57]) and (Chr(wParam
) <> '`') then
2276 if Length(Text) < FMaxLength
then
2278 Insert(Chr(wParam
), FText
, FCaretPos
+ 1);
2284 if (wParam
in [32..255]) and (Chr(wParam
) <> '`') then
2285 if Length(Text) < FMaxLength
then
2287 Insert(Chr(wParam
), FText
, FCaretPos
+ 1);
2295 Delete(FText
, FCaretPos
, 1);
2296 if FCaretPos
> 0 then Dec(FCaretPos
);
2298 IK_DELETE
: Delete(FText
, FCaretPos
+ 1, 1);
2299 IK_END
, IK_KPEND
: FCaretPos
:= Length(FText
);
2300 IK_HOME
, IK_KPHOME
: FCaretPos
:= 0;
2301 IK_LEFT
, IK_KPLEFT
: if FCaretPos
> 0 then Dec(FCaretPos
);
2302 IK_RIGHT
, IK_KPRIGHT
: if FCaretPos
< Length(FText
) then Inc(FCaretPos
);
2303 IK_RETURN
, IK_KPRETURN
:
2306 if FActiveControl
<> Self
then
2309 if @FOnEnterEvent
<> nil then FOnEnterEvent(Self
);
2313 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
2314 else SetActive(nil);
2315 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2322 procedure TGUIEdit
.SetText(Text: string);
2324 if Length(Text) > FMaxLength
then SetLength(Text, FMaxLength
);
2326 FCaretPos
:= Length(FText
);
2329 procedure TGUIEdit
.Update
;
2336 constructor TGUIKeyRead
.Create(FontID
: DWORD
);
2342 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
2345 procedure TGUIKeyRead
.Draw
;
2349 FFont
.Draw(FX
, FY
, IfThen(FIsQuery
, KEYREAD_QUERY
, IfThen(FKey
<> 0, e_KeyNames
[FKey
], KEYREAD_CLEAR
)),
2350 FColor
.R
, FColor
.G
, FColor
.B
);
2353 function TGUIKeyRead
.GetWidth
: Integer;
2360 for a
:= 0 to 255 do
2362 FFont
.GetTextSize(e_KeyNames
[a
], w
, h
);
2363 Result
:= Max(Result
, w
);
2366 FFont
.GetTextSize(KEYREAD_QUERY
, w
, h
);
2367 if w
> Result
then Result
:= w
;
2369 FFont
.GetTextSize(KEYREAD_CLEAR
, w
, h
);
2370 if w
> Result
then Result
:= w
;
2373 function TGUIKeyRead
.WantActivationKey (key
: LongInt): Boolean;
2376 (key
= IK_BACKSPACE
) or
2380 procedure TGUIKeyRead
.OnMessage(var Msg
: TMessage
);
2381 procedure actDefCtl ();
2384 if FDefControl
<> '' then
2385 SetActive(GetControl(FDefControl
))
2393 if not FEnabled
then
2402 if FIsQuery
then actDefCtl();
2405 IK_RETURN
, IK_KPRETURN
:
2407 if not FIsQuery
then
2410 if FActiveControl
<> Self
then
2417 FKey
:= IK_ENTER
; // <Enter>
2422 IK_BACKSPACE
: // clear keybinding if we aren't waiting for a key
2424 if not FIsQuery
then
2434 if not FIsQuery
and (wParam
= IK_BACKSPACE
) then
2439 else if FIsQuery
and (wParam
<> IK_ENTER
) and (wParam
<> IK_KPRETURN
) then // Not <Enter
2441 if e_KeyNames
[wParam
] <> '' then
2452 constructor TGUIKeyRead2
.Create(FontID
: DWORD
);
2465 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
2467 FMaxKeyNameWdt
:= 0;
2468 for a
:= 0 to 255 do
2470 FFont
.GetTextSize(e_KeyNames
[a
], w
, h
);
2471 FMaxKeyNameWdt
:= Max(FMaxKeyNameWdt
, w
);
2474 FMaxKeyNameWdt
:= FMaxKeyNameWdt
-(FMaxKeyNameWdt
div 3);
2476 FFont
.GetTextSize(KEYREAD_QUERY
, w
, h
);
2477 if w
> FMaxKeyNameWdt
then FMaxKeyNameWdt
:= w
;
2479 FFont
.GetTextSize(KEYREAD_CLEAR
, w
, h
);
2480 if w
> FMaxKeyNameWdt
then FMaxKeyNameWdt
:= w
;
2483 procedure TGUIKeyRead2
.Draw
;
2484 procedure drawText (idx
: Integer);
2490 if idx
= 0 then kk
:= FKey0
else kk
:= FKey1
;
2492 if idx
= 0 then x
:= FX
+8 else x
:= FX
+8+FMaxKeyNameWdt
+16;
2496 if FKeyIdx
= idx
then begin r
:= 255; g
:= 255; b
:= 255; end;
2497 if FIsQuery
and (FKeyIdx
= idx
) then
2498 FFont
.Draw(x
, y
, KEYREAD_QUERY
, r
, g
, b
)
2500 FFont
.Draw(x
, y
, IfThen(kk
<> 0, e_KeyNames
[kk
], KEYREAD_CLEAR
), r
, g
, b
);
2506 //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);
2507 //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);
2512 function TGUIKeyRead2
.GetWidth
: Integer;
2514 Result
:= FMaxKeyNameWdt
*2+8+8+16;
2517 function TGUIKeyRead2
.WantActivationKey (key
: LongInt): Boolean;
2520 (key
= IK_BACKSPACE
) or
2521 (key
= IK_LEFT
) or (key
= IK_RIGHT
) or
2522 (key
= IK_KPLEFT
) or (key
= IK_KPRIGHT
) or
2526 procedure TGUIKeyRead2
.OnMessage(var Msg
: TMessage
);
2527 procedure actDefCtl ();
2530 if FDefControl
<> '' then
2531 SetActive(GetControl(FDefControl
))
2539 if not FEnabled
then
2548 if FIsQuery
then actDefCtl();
2551 IK_RETURN
, IK_KPRETURN
:
2553 if not FIsQuery
then
2556 if FActiveControl
<> Self
then
2563 if (FKeyIdx
= 0) then FKey0
:= IK_ENTER
else FKey1
:= IK_ENTER
; // <Enter>
2568 IK_BACKSPACE
: // clear keybinding if we aren't waiting for a key
2570 if not FIsQuery
then
2572 if (FKeyIdx
= 0) then FKey0
:= 0 else FKey1
:= 0;
2577 if not FIsQuery
then
2582 IK_RIGHT
, IK_KPRIGHT
:
2583 if not FIsQuery
then
2592 if not FIsQuery
and (wParam
= IK_BACKSPACE
) then
2594 if (FKeyIdx
= 0) then FKey0
:= 0 else FKey1
:= 0;
2597 else if FIsQuery
and (wParam
<> IK_ENTER
) and (wParam
<> IK_KPRETURN
) then // Not <Enter
2599 if e_KeyNames
[wParam
] <> '' then
2601 if (FKeyIdx
= 0) then FKey0
:= wParam
else FKey1
:= wParam
;
2613 constructor TGUIModelView
.Create
;
2620 destructor TGUIModelView
.Destroy
;
2627 procedure TGUIModelView
.Draw
;
2631 DrawBox(FX
, FY
, 4, 4);
2633 if FModel
<> nil then FModel
.Draw(FX
+4, FY
+4);
2636 procedure TGUIModelView
.NextAnim();
2638 if FModel
= nil then
2641 if FModel
.Animation
< A_PAIN
then
2642 FModel
.ChangeAnimation(FModel
.Animation
+1, True)
2644 FModel
.ChangeAnimation(A_STAND
, True);
2647 procedure TGUIModelView
.NextWeapon();
2649 if FModel
= nil then
2652 if FModel
.Weapon
< WP_LAST
then
2653 FModel
.SetWeapon(FModel
.Weapon
+1)
2655 FModel
.SetWeapon(WEAPON_KASTET
);
2658 procedure TGUIModelView
.OnMessage(var Msg
: TMessage
);
2664 procedure TGUIModelView
.SetColor(Red
, Green
, Blue
: Byte);
2666 if FModel
<> nil then FModel
.SetColor(Red
, Green
, Blue
);
2669 procedure TGUIModelView
.SetModel(ModelName
: string);
2673 FModel
:= g_PlayerModel_Get(ModelName
);
2676 procedure TGUIModelView
.Update
;
2683 if FModel
<> nil then FModel
.Update
;
2688 constructor TGUIMapPreview
.Create();
2694 destructor TGUIMapPreview
.Destroy();
2700 procedure TGUIMapPreview
.Draw();
2707 DrawBox(FX
, FY
, MAPPREVIEW_WIDTH
, MAPPREVIEW_HEIGHT
);
2709 if (FMapSize
.X
<= 0) or (FMapSize
.Y
<= 0) then
2712 e_DrawFillQuad(FX
+4, FY
+4,
2713 FX
+4 + Trunc(FMapSize
.X
/ FScale
) - 1,
2714 FY
+4 + Trunc(FMapSize
.Y
/ FScale
) - 1,
2717 if FMapData
<> nil then
2718 for a
:= 0 to High(FMapData
) do
2721 if X1
> MAPPREVIEW_WIDTH
*16 then Continue
;
2722 if Y1
> MAPPREVIEW_HEIGHT
*16 then Continue
;
2724 if X2
< 0 then Continue
;
2725 if Y2
< 0 then Continue
;
2727 if X2
> MAPPREVIEW_WIDTH
*16 then X2
:= MAPPREVIEW_WIDTH
*16;
2728 if Y2
> MAPPREVIEW_HEIGHT
*16 then Y2
:= MAPPREVIEW_HEIGHT
*16;
2730 if X1
< 0 then X1
:= 0;
2731 if Y1
< 0 then Y1
:= 0;
2772 if ((X2
-X1
) > 0) and ((Y2
-Y1
) > 0) then
2773 e_DrawFillQuad(FX
+4 + X1
, FY
+4 + Y1
,
2774 FX
+4 + X2
- 1, FY
+4 + Y2
- 1, r
, g
, b
, 0);
2778 procedure TGUIMapPreview
.OnMessage(var Msg
: TMessage
);
2784 procedure TGUIMapPreview
.SetMap(Res
: string);
2789 //header: TMapHeaderRec_1;
2794 map
: TDynRecord
= nil;
2801 FileName
:= g_ExtractWadName(Res
);
2803 WAD
:= TWADFile
.Create();
2804 if not WAD
.ReadFile(FileName
) then
2810 //k8: ignores path again
2811 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
2820 map
:= g_Map_ParseMap(Data
, Len
);
2830 if (map
= nil) then exit
;
2833 panlist
:= map
.field
['panel'];
2834 //header := GetMapHeader(map);
2836 FMapSize
.X
:= map
.Width
div 16;
2837 FMapSize
.Y
:= map
.Height
div 16;
2839 rX
:= Ceil(map
.Width
/ (MAPPREVIEW_WIDTH
*256.0));
2840 rY
:= Ceil(map
.Height
/ (MAPPREVIEW_HEIGHT
*256.0));
2841 FScale
:= max(rX
, rY
);
2845 if (panlist
<> nil) then
2847 for pan
in panlist
do
2849 if (pan
.PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or
2850 PANEL_STEP
or PANEL_WATER
or
2851 PANEL_ACID1
or PANEL_ACID2
)) <> 0 then
2853 SetLength(FMapData
, Length(FMapData
)+1);
2854 with FMapData
[High(FMapData
)] do
2859 X2
:= (pan
.X
+ pan
.Width
) div 16;
2860 Y2
:= (pan
.Y
+ pan
.Height
) div 16;
2862 X1
:= Trunc(X1
/FScale
+ 0.5);
2863 Y1
:= Trunc(Y1
/FScale
+ 0.5);
2864 X2
:= Trunc(X2
/FScale
+ 0.5);
2865 Y2
:= Trunc(Y2
/FScale
+ 0.5);
2867 if (X1
<> X2
) or (Y1
<> Y2
) then
2875 PanelType
:= pan
.PanelType
;
2881 //writeln('freeing map');
2886 procedure TGUIMapPreview
.ClearMap();
2888 SetLength(FMapData
, 0);
2895 procedure TGUIMapPreview
.Update();
2901 function TGUIMapPreview
.GetScaleStr(): String;
2903 if FScale
> 0.0 then
2905 Result
:= FloatToStrF(FScale
*16.0, ffFixed
, 3, 3);
2906 while (Result
[Length(Result
)] = '0') do
2907 Delete(Result
, Length(Result
), 1);
2908 if (Result
[Length(Result
)] = ',') or (Result
[Length(Result
)] = '.') then
2909 Delete(Result
, Length(Result
), 1);
2910 Result
:= '1 : ' + Result
;
2918 procedure TGUIListBox
.AddItem(Item
: string);
2920 SetLength(FItems
, Length(FItems
)+1);
2921 FItems
[High(FItems
)] := Item
;
2923 if FSort
then g_Basic
.Sort(FItems
);
2926 procedure TGUIListBox
.Clear();
2934 constructor TGUIListBox
.Create(FontID
: DWORD
; Width
, Height
: Word);
2938 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
2943 FOnChangeEvent
:= nil;
2945 FDrawScroll
:= True;
2948 procedure TGUIListBox
.Draw
;
2956 if FDrawBack
then DrawBox(FX
, FY
, FWidth
+1, FHeight
);
2958 DrawScroll(FX
+4+FWidth
*16, FY
+4, FHeight
, (FStartLine
> 0) and (FItems
<> nil),
2959 (FStartLine
+FHeight
-1 < High(FItems
)) and (FItems
<> nil));
2961 if FItems
<> nil then
2962 for a
:= FStartLine
to Min(High(FItems
), FStartLine
+FHeight
-1) do
2966 FFont
.GetTextSize(s
, w2
, h2
);
2967 while (Length(s
) > 0) and (w2
> FWidth
*16) do
2969 SetLength(s
, Length(s
)-1);
2970 FFont
.GetTextSize(s
, w2
, h2
);
2974 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, s
, FActiveColor
.R
, FActiveColor
.G
, FActiveColor
.B
)
2976 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, s
, FUnActiveColor
.R
, FUnActiveColor
.G
, FUnActiveColor
.B
);
2980 function TGUIListBox
.GetHeight
: Integer;
2982 Result
:= 8+FHeight
*16;
2985 function TGUIListBox
.GetWidth
: Integer;
2987 Result
:= 8+(FWidth
+1)*16;
2990 procedure TGUIListBox
.OnMessage(var Msg
: TMessage
);
2994 if not FEnabled
then Exit
;
2998 if FItems
= nil then Exit
;
3011 FIndex
:= High(FItems
);
3012 FStartLine
:= Max(High(FItems
)-FHeight
+1, 0);
3014 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
:
3018 if FIndex
< FStartLine
then Dec(FStartLine
);
3019 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
3021 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
:
3022 if FIndex
< High(FItems
) then
3025 if FIndex
> FStartLine
+FHeight
-1 then Inc(FStartLine
);
3026 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
3028 IK_RETURN
, IK_KPRETURN
:
3031 if FActiveControl
<> Self
then SetActive(Self
)
3033 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
3034 else SetActive(nil);
3038 for a
:= 0 to High(FItems
) do
3039 if (Length(FItems
[a
]) > 0) and (LowerCase(FItems
[a
][1]) = LowerCase(Chr(wParam
))) then
3042 FStartLine
:= Min(Max(FIndex
-1, 0), Length(FItems
)-FHeight
);
3043 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
3049 function TGUIListBox
.SelectedItem(): String;
3053 if (FIndex
< 0) or (FItems
= nil) or
3054 (FIndex
> High(FItems
)) then
3057 Result
:= FItems
[FIndex
];
3060 procedure TGUIListBox
.FSetItems(Items
: SArray
);
3062 if FItems
<> nil then
3070 if FSort
then g_Basic
.Sort(FItems
);
3073 procedure TGUIListBox
.SelectItem(Item
: String);
3077 if FItems
= nil then
3081 Item
:= LowerCase(Item
);
3083 for a
:= 0 to High(FItems
) do
3084 if LowerCase(FItems
[a
]) = Item
then
3090 if FIndex
< FHeight
then
3093 FStartLine
:= Min(FIndex
, Length(FItems
)-FHeight
);
3096 procedure TGUIListBox
.FSetIndex(aIndex
: Integer);
3098 if FItems
= nil then
3101 if (aIndex
< 0) or (aIndex
> High(FItems
)) then
3106 if FIndex
<= FHeight
then
3109 FStartLine
:= Min(FIndex
, Length(FItems
)-FHeight
);
3114 procedure TGUIFileListBox
.OnMessage(var Msg
: TMessage
);
3118 if not FEnabled
then
3121 if FItems
= nil then
3132 if @FOnChangeEvent
<> nil then
3133 FOnChangeEvent(Self
);
3138 FIndex
:= High(FItems
);
3139 FStartLine
:= Max(High(FItems
)-FHeight
+1, 0);
3140 if @FOnChangeEvent
<> nil then
3141 FOnChangeEvent(Self
);
3144 IK_PAGEUP
, IK_KPPAGEUP
:
3146 if FIndex
> FHeight
then
3147 FIndex
:= FIndex
-FHeight
3151 if FStartLine
> FHeight
then
3152 FStartLine
:= FStartLine
-FHeight
3157 IK_PAGEDN
, IK_KPPAGEDN
:
3159 if FIndex
< High(FItems
)-FHeight
then
3160 FIndex
:= FIndex
+FHeight
3162 FIndex
:= High(FItems
);
3164 if FStartLine
< High(FItems
)-FHeight
then
3165 FStartLine
:= FStartLine
+FHeight
3167 FStartLine
:= High(FItems
)-FHeight
+1;
3170 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
:
3174 if FIndex
< FStartLine
then
3176 if @FOnChangeEvent
<> nil then
3177 FOnChangeEvent(Self
);
3180 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
:
3181 if FIndex
< High(FItems
) then
3184 if FIndex
> FStartLine
+FHeight
-1 then
3186 if @FOnChangeEvent
<> nil then
3187 FOnChangeEvent(Self
);
3190 IK_RETURN
, IK_KPRETURN
:
3193 if FActiveControl
<> Self
then
3197 if FItems
[FIndex
][1] = #29 then // Ïàïêà
3199 OpenDir(FPath
+Copy(FItems
[FIndex
], 2, 255));
3204 if FDefControl
<> '' then
3205 SetActive(GetControl(FDefControl
))
3213 for a
:= 0 to High(FItems
) do
3214 if ( (Length(FItems
[a
]) > 0) and
3215 (LowerCase(FItems
[a
][1]) = LowerCase(Chr(wParam
))) ) or
3216 ( (Length(FItems
[a
]) > 1) and
3217 (FItems
[a
][1] = #29) and // Ïàïêà
3218 (LowerCase(FItems
[a
][2]) = LowerCase(Chr(wParam
))) ) then
3221 FStartLine
:= Min(Max(FIndex
-1, 0), Length(FItems
)-FHeight
);
3222 if @FOnChangeEvent
<> nil then
3223 FOnChangeEvent(Self
);
3229 procedure TGUIFileListBox
.OpenDir(path
: String);
3237 path
:= IncludeTrailingPathDelimiter(path
);
3238 path
:= ExpandFileName(path
);
3243 if FindFirst(path
+'*', faDirectory
, SR
) = 0 then
3245 if not LongBool(SR
.Attr
and faDirectory
) then
3247 if (SR
.Name
= '.') or
3248 ((SR
.Name
= '..') and (path
= ExpandFileName(FBasePath
))) then
3251 AddItem(#1 + SR
.Name
);
3252 until FindNext(SR
) <> 0;
3262 if i
= 0 then i
:= length(sm
)+1;
3263 sc
:= Copy(sm
, 1, i
-1);
3265 if FindFirst(path
+sc
, faAnyFile
, SR
) = 0 then repeat AddItem(SR
.Name
); until FindNext(SR
) <> 0;
3269 for i
:= 0 to High(FItems
) do
3270 if FItems
[i
][1] = #1 then
3271 FItems
[i
][1] := #29;
3276 procedure TGUIFileListBox
.SetBase(path
: String);
3282 function TGUIFileListBox
.SelectedItem(): String;
3286 if (FIndex
= -1) or (FItems
= nil) or
3287 (FIndex
> High(FItems
)) or
3288 (FItems
[FIndex
][1] = '/') or
3289 (FItems
[FIndex
][1] = '\') then
3292 Result
:= FPath
+ FItems
[FIndex
];
3295 procedure TGUIFileListBox
.UpdateFileList();
3299 if (FIndex
= -1) or (FItems
= nil) or
3300 (FIndex
> High(FItems
)) or
3301 (FItems
[FIndex
][1] = '/') or
3302 (FItems
[FIndex
][1] = '\') then
3305 fn
:= FItems
[FIndex
];
3315 procedure TGUIMemo
.Clear
;
3321 constructor TGUIMemo
.Create(FontID
: DWORD
; Width
, Height
: Word);
3325 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
3330 FDrawScroll
:= True;
3333 procedure TGUIMemo
.Draw
;
3339 if FDrawBack
then DrawBox(FX
, FY
, FWidth
+1, FHeight
);
3341 DrawScroll(FX
+4+FWidth
*16, FY
+4, FHeight
, (FStartLine
> 0) and (FLines
<> nil),
3342 (FStartLine
+FHeight
-1 < High(FLines
)) and (FLines
<> nil));
3344 if FLines
<> nil then
3345 for a
:= FStartLine
to Min(High(FLines
), FStartLine
+FHeight
-1) do
3346 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, FLines
[a
], FColor
.R
, FColor
.G
, FColor
.B
);
3349 function TGUIMemo
.GetHeight
: Integer;
3351 Result
:= 8+FHeight
*16;
3354 function TGUIMemo
.GetWidth
: Integer;
3356 Result
:= 8+(FWidth
+1)*16;
3359 procedure TGUIMemo
.OnMessage(var Msg
: TMessage
);
3361 if not FEnabled
then Exit
;
3365 if FLines
= nil then Exit
;
3371 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
:
3372 if FStartLine
> 0 then
3374 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
:
3375 if FStartLine
< Length(FLines
)-FHeight
then
3377 IK_RETURN
, IK_KPRETURN
:
3380 if FActiveControl
<> Self
then
3386 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
3387 else SetActive(nil);
3393 procedure TGUIMemo
.SetText(Text: string);
3396 FLines
:= GetLines(Text, FFont
.ID
, FWidth
*16);
3401 procedure TGUIimage
.ClearImage();
3403 if FImageRes
= '' then Exit
;
3405 g_Texture_Delete(FImageRes
);
3409 constructor TGUIimage
.Create();
3416 destructor TGUIimage
.Destroy();
3421 procedure TGUIimage
.Draw();
3427 if FImageRes
= '' then
3429 if g_Texture_Get(FDefaultRes
, ID
) then e_Draw(ID
, FX
, FY
, 0, True, False);
3432 if g_Texture_Get(FImageRes
, ID
) then e_Draw(ID
, FX
, FY
, 0, True, False);
3435 procedure TGUIimage
.OnMessage(var Msg
: TMessage
);
3440 procedure TGUIimage
.SetImage(Res
: string);
3444 if g_Texture_CreateWADEx(Res
, Res
) then FImageRes
:= Res
;
3447 procedure TGUIimage
.Update();