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}
22 {$IFDEF USE_MEMPOOL}mempool
,{$ENDIF}
23 e_graphics
, e_input
, e_log
, g_playermodel
, g_basic
, MAPDEF
, utils
;
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
= (Texture
, Character
);
88 TFont
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
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{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
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{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
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
: SSArray
);
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
: SSArray 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();
557 g_textures
, g_sound
, SysUtils
,
558 g_game
, Math
, StrUtils
, g_player
, g_options
,
559 g_map
, g_weapons
, xdynrec
, wadreader
;
563 Box
: Array [0..8] of DWORD
;
564 Saved_Windows
: SSArray
;
567 procedure g_GUI_Init();
569 g_Texture_Get(BOX1
, Box
[0]);
570 g_Texture_Get(BOX2
, Box
[1]);
571 g_Texture_Get(BOX3
, Box
[2]);
572 g_Texture_Get(BOX4
, Box
[3]);
573 g_Texture_Get(BOX5
, Box
[4]);
574 g_Texture_Get(BOX6
, Box
[5]);
575 g_Texture_Get(BOX7
, Box
[6]);
576 g_Texture_Get(BOX8
, Box
[7]);
577 g_Texture_Get(BOX9
, Box
[8]);
580 function g_GUI_Destroy(): Boolean;
584 Result
:= (Length(g_GUIWindows
) > 0);
586 for i
:= 0 to High(g_GUIWindows
) do
587 g_GUIWindows
[i
].Free();
590 g_ActiveWindow
:= nil;
593 function g_GUI_AddWindow(Window
: TGUIWindow
): TGUIWindow
;
595 SetLength(g_GUIWindows
, Length(g_GUIWindows
)+1);
596 g_GUIWindows
[High(g_GUIWindows
)] := Window
;
601 function g_GUI_GetWindow(Name
: string): TGUIWindow
;
607 if g_GUIWindows
<> nil then
608 for i
:= 0 to High(g_GUIWindows
) do
609 if g_GUIWindows
[i
].FName
= Name
then
611 Result
:= g_GUIWindows
[i
];
615 Assert(Result
<> nil, 'GUI_Window "'+Name
+'" not found');
618 procedure g_GUI_ShowWindow(Name
: string);
622 if g_GUIWindows
= nil then
625 for i
:= 0 to High(g_GUIWindows
) do
626 if g_GUIWindows
[i
].FName
= Name
then
628 g_GUIWindows
[i
].FPrevWindow
:= g_ActiveWindow
;
629 g_ActiveWindow
:= g_GUIWindows
[i
];
631 if g_ActiveWindow
.MainWindow
then
632 g_ActiveWindow
.FPrevWindow
:= nil;
634 if g_ActiveWindow
.FDefControl
<> '' then
635 g_ActiveWindow
.SetActive(g_ActiveWindow
.GetControl(g_ActiveWindow
.FDefControl
))
637 g_ActiveWindow
.SetActive(nil);
639 if @g_ActiveWindow
.FOnShowEvent
<> nil then
640 g_ActiveWindow
.FOnShowEvent();
646 procedure g_GUI_HideWindow(PlaySound
: Boolean = True);
648 if g_ActiveWindow
<> nil then
650 if @g_ActiveWindow
.OnClose
<> nil then
651 g_ActiveWindow
.OnClose();
652 g_ActiveWindow
:= g_ActiveWindow
.FPrevWindow
;
654 g_Sound_PlayEx(WINDOW_CLOSESOUND
);
658 procedure g_GUI_SaveMenuPos();
663 SetLength(Saved_Windows
, 0);
664 win
:= g_ActiveWindow
;
668 len
:= Length(Saved_Windows
);
669 SetLength(Saved_Windows
, len
+ 1);
671 Saved_Windows
[len
] := win
.Name
;
673 if win
.MainWindow
then
676 win
:= win
.FPrevWindow
;
680 procedure g_GUI_LoadMenuPos();
682 i
, j
, k
, len
: Integer;
685 g_ActiveWindow
:= nil;
686 len
:= Length(Saved_Windows
);
691 // Îêíî ñ ãëàâíûì ìåíþ:
692 g_GUI_ShowWindow(Saved_Windows
[len
-1]);
694 // Íå ïåðåêëþ÷èëîñü (èëè íåêóäà äàëüøå):
695 if (len
= 1) or (g_ActiveWindow
= nil) then
698 // Èùåì êíîïêè â îñòàëüíûõ îêíàõ:
699 for k
:= len
-1 downto 1 do
703 for i
:= 0 to Length(g_ActiveWindow
.Childs
)-1 do
705 if g_ActiveWindow
.Childs
[i
] is TGUIMainMenu
then
706 begin // GUI_MainMenu
707 with TGUIMainMenu(g_ActiveWindow
.Childs
[i
]) do
708 for j
:= 0 to Length(FButtons
)-1 do
709 if FButtons
[j
].ShowWindow
= Saved_Windows
[k
-1] then
711 FButtons
[j
].Click(True);
717 if g_ActiveWindow
.Childs
[i
] is TGUIMenu
then
718 with TGUIMenu(g_ActiveWindow
.Childs
[i
]) do
719 for j
:= 0 to Length(FItems
)-1 do
720 if FItems
[j
].ControlType
= TGUITextButton
then
721 if TGUITextButton(FItems
[j
].Control
).ShowWindow
= Saved_Windows
[k
-1] then
723 TGUITextButton(FItems
[j
].Control
).Click(True);
734 (g_ActiveWindow
.Name
= Saved_Windows
[k
]) then
739 procedure DrawBox(X
, Y
: Integer; Width
, Height
: Word);
741 e_Draw(Box
[0], X
, Y
, 0, False, False);
742 e_DrawFill(Box
[1], X
+4, Y
, Width
*4, 1, 0, False, False);
743 e_Draw(Box
[2], X
+4+Width
*16, Y
, 0, False, False);
744 e_DrawFill(Box
[3], X
, Y
+4, 1, Height
*4, 0, False, False);
745 e_DrawFill(Box
[4], X
+4, Y
+4, Width
, Height
, 0, False, False);
746 e_DrawFill(Box
[5], X
+4+Width
*16, Y
+4, 1, Height
*4, 0, False, False);
747 e_Draw(Box
[6], X
, Y
+4+Height
*16, 0, False, False);
748 e_DrawFill(Box
[7], X
+4, Y
+4+Height
*16, Width
*4, 1, 0, False, False);
749 e_Draw(Box
[8], X
+4+Width
*16, Y
+4+Height
*16, 0, False, False);
752 procedure DrawScroll(X
, Y
: Integer; Height
: Word; Up
, Down
: Boolean);
756 if Height
< 3 then Exit
;
759 g_Texture_Get(BSCROLL_UPA
, ID
)
761 g_Texture_Get(BSCROLL_UPU
, ID
);
762 e_Draw(ID
, X
, Y
, 0, False, False);
765 g_Texture_Get(BSCROLL_DOWNA
, ID
)
767 g_Texture_Get(BSCROLL_DOWNU
, ID
);
768 e_Draw(ID
, X
, Y
+(Height
-1)*16, 0, False, False);
770 g_Texture_Get(BSCROLL_MIDDLE
, ID
);
771 e_DrawFill(ID
, X
, Y
+16, 1, Height
-2, 0, False, False);
776 constructor TGUIWindow
.Create(Name
: string);
779 FActiveControl
:= nil;
783 FOnCloseEvent
:= nil;
787 destructor TGUIWindow
.Destroy
;
794 for i
:= 0 to High(Childs
) do
798 function TGUIWindow
.AddChild(Child
: TGUIControl
): TGUIControl
;
800 Child
.FWindow
:= Self
;
802 SetLength(Childs
, Length(Childs
) + 1);
803 Childs
[High(Childs
)] := Child
;
808 procedure TGUIWindow
.Update
;
812 for i
:= 0 to High(Childs
) do
813 if Childs
[i
] <> nil then Childs
[i
].Update
;
816 procedure TGUIWindow
.Draw
;
821 if FBackTexture
<> '' then
822 if g_Texture_Get(FBackTexture
, ID
) then
823 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
825 e_Clear(GL_COLOR_BUFFER_BIT
, 0.5, 0.5, 0.5);
827 for i
:= 0 to High(Childs
) do
828 if Childs
[i
] <> nil then Childs
[i
].Draw
;
831 procedure TGUIWindow
.OnMessage(var Msg
: TMessage
);
833 if FActiveControl
<> nil then FActiveControl
.OnMessage(Msg
);
834 if @FOnKeyDown
<> nil then FOnKeyDown(Msg
.wParam
);
835 if @FOnKeyDownEx
<> nil then FOnKeyDownEx(self
, Msg
.wParam
);
837 if Msg
.Msg
= WM_KEYDOWN
then
838 if Msg
.wParam
= IK_ESCAPE
then
845 procedure TGUIWindow
.SetActive(Control
: TGUIControl
);
847 FActiveControl
:= Control
;
850 function TGUIWindow
.GetControl(Name
: String): TGUIControl
;
856 if Childs
<> nil then
857 for i
:= 0 to High(Childs
) do
858 if Childs
[i
] <> nil then
859 if LowerCase(Childs
[i
].FName
) = LowerCase(Name
) then
865 Assert(Result
<> nil, 'Window Control "'+Name
+'" not Found!');
870 constructor TGUIControl
.Create();
876 FRightAlign
:= false;
880 procedure TGUIControl
.OnMessage(var Msg
: TMessage
);
886 procedure TGUIControl
.Update();
890 procedure TGUIControl
.Draw();
894 function TGUIControl
.WantActivationKey (key
: LongInt): Boolean;
899 function TGUIControl
.GetWidth(): Integer;
904 function TGUIControl
.GetHeight(): Integer;
911 procedure TGUITextButton
.Click(Silent
: Boolean = False);
913 if (FSound
<> '') and (not Silent
) then g_Sound_PlayEx(FSound
);
915 if @Proc
<> nil then Proc();
916 if @ProcEx
<> nil then ProcEx(self
);
918 if FShowWindow
<> '' then g_GUI_ShowWindow(FShowWindow
);
921 constructor TGUITextButton
.Create(aProc
: Pointer; FontID
: DWORD
; Text: string);
928 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
933 destructor TGUITextButton
.Destroy
;
939 procedure TGUITextButton
.Draw
;
941 FFont
.Draw(FX
, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
)
944 function TGUITextButton
.GetHeight
: Integer;
948 FFont
.GetTextSize(FText
, w
, h
);
952 function TGUITextButton
.GetWidth
: Integer;
956 FFont
.GetTextSize(FText
, w
, h
);
960 procedure TGUITextButton
.OnMessage(var Msg
: TMessage
);
962 if not FEnabled
then Exit
;
969 IK_RETURN
, IK_KPRETURN
: Click();
974 procedure TGUITextButton
.Update
;
981 constructor TFont
.Create(FontID
: DWORD
; FontType
: TFontType
);
986 FFontType
:= FontType
;
989 destructor TFont
.Destroy
;
995 procedure TFont
.Draw(X
, Y
: Integer; Text: string; R
, G
, B
: Byte);
997 if FFontType
= TFontType
.Character
then e_CharFont_PrintEx(ID
, X
, Y
, Text, _RGB(R
, G
, B
), FScale
)
998 else e_TextureFontPrintEx(X
, Y
, Text, ID
, R
, G
, B
, FScale
);
1001 procedure TFont
.GetTextSize(Text: string; var w
, h
: Word);
1005 if FFontType
= TFontType
.Character
then e_CharFont_GetSize(ID
, Text, w
, h
)
1008 e_TextureFontGetSize(ID
, cw
, ch
);
1009 w
:= cw
*Length(Text);
1013 w
:= Round(w
*FScale
);
1014 h
:= Round(h
*FScale
);
1019 function TGUIMainMenu
.AddButton(fProc
: Pointer; Caption
: string; ShowWindow
: string = ''): TGUITextButton
;
1026 SetLength(FButtons
, Length(FButtons
)+1);
1027 FButtons
[High(FButtons
)] := TGUITextButton
.Create(fProc
, FFontID
, Caption
);
1028 FButtons
[High(FButtons
)].ShowWindow
:= ShowWindow
;
1029 with FButtons
[High(FButtons
)] do
1031 if (fProc
<> nil) or (ShowWindow
<> '') then FColor
:= MAINMENU_ITEMS_COLOR
1032 else FColor
:= MAINMENU_UNACTIVEITEMS_COLOR
;
1033 FSound
:= MAINMENU_CLICKSOUND
;
1036 _x
:= gScreenWidth
div 2;
1038 for a
:= 0 to High(FButtons
) do
1039 if FButtons
[a
] <> nil then
1040 _x
:= Min(_x
, (gScreenWidth
div 2)-(FButtons
[a
].GetWidth
div 2));
1042 hh
:= FHeader
.GetHeight
;
1044 h
:= hh
*(2+Length(FButtons
))+MAINMENU_SPACE
*(Length(FButtons
)-1);
1045 h
:= (gScreenHeight
div 2)-(h
div 2);
1055 for a
:= 0 to High(FButtons
) do
1057 if FButtons
[a
] <> nil then
1064 Inc(h
, hh
+MAINMENU_SPACE
);
1067 Result
:= FButtons
[High(FButtons
)];
1070 procedure TGUIMainMenu
.AddSpace
;
1072 SetLength(FButtons
, Length(FButtons
)+1);
1073 FButtons
[High(FButtons
)] := nil;
1076 constructor TGUIMainMenu
.Create(FontID
: DWORD
; Header
: string);
1082 FCounter
:= MAINMENU_MARKERDELAY
;
1084 g_Texture_Get(MAINMENU_MARKER1
, FMarkerID1
);
1085 g_Texture_Get(MAINMENU_MARKER2
, FMarkerID2
);
1087 FHeader
:= TGUILabel
.Create(Header
, FFontID
);
1090 FColor
:= MAINMENU_HEADER_COLOR
;
1091 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1092 FY
:= (gScreenHeight
div 2)-(GetHeight
div 2);
1096 destructor TGUIMainMenu
.Destroy
;
1100 if FButtons
<> nil then
1101 for a
:= 0 to High(FButtons
) do
1109 procedure TGUIMainMenu
.Draw
;
1117 if FButtons
<> nil then
1119 for a
:= 0 to High(FButtons
) do
1120 if FButtons
[a
] <> nil then FButtons
[a
].Draw
;
1122 if FIndex
<> -1 then
1123 e_Draw(FMarkerID1
, FButtons
[FIndex
].FX
-48, FButtons
[FIndex
].FY
, 0, True, False);
1127 procedure TGUIMainMenu
.EnableButton(aName
: string; e
: Boolean);
1131 if FButtons
= nil then Exit
;
1133 for a
:= 0 to High(FButtons
) do
1134 if (FButtons
[a
] <> nil) and (FButtons
[a
].Name
= aName
) then
1136 if e
then FButtons
[a
].FColor
:= MAINMENU_ITEMS_COLOR
1137 else FButtons
[a
].FColor
:= MAINMENU_UNACTIVEITEMS_COLOR
;
1138 FButtons
[a
].Enabled
:= e
;
1143 function TGUIMainMenu
.GetButton(aName
: string): TGUITextButton
;
1149 if FButtons
= nil then Exit
;
1151 for a
:= 0 to High(FButtons
) do
1152 if (FButtons
[a
] <> nil) and (FButtons
[a
].Name
= aName
) then
1154 Result
:= FButtons
[a
];
1159 procedure TGUIMainMenu
.OnMessage(var Msg
: TMessage
);
1164 if not FEnabled
then Exit
;
1168 if FButtons
= nil then Exit
;
1171 for a
:= 0 to High(FButtons
) do
1172 if FButtons
[a
] <> nil then
1178 if not ok
then Exit
;
1187 if FIndex
< 0 then FIndex
:= High(FButtons
);
1188 until FButtons
[FIndex
] <> nil;
1190 g_Sound_PlayEx(MENU_CHANGESOUND
);
1196 if FIndex
> High(FButtons
) then FIndex
:= 0;
1197 until FButtons
[FIndex
] <> nil;
1199 g_Sound_PlayEx(MENU_CHANGESOUND
);
1201 IK_RETURN
, IK_KPRETURN
: if (FIndex
<> -1) and FButtons
[FIndex
].FEnabled
then FButtons
[FIndex
].Click
;
1206 procedure TGUIMainMenu
.Update
;
1212 if FCounter
= 0 then
1215 FMarkerID1
:= FMarkerID2
;
1218 FCounter
:= MAINMENU_MARKERDELAY
;
1219 end else Dec(FCounter
);
1224 constructor TGUILabel
.Create(Text: string; FontID
: DWORD
);
1228 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
1232 FOnClickEvent
:= nil;
1235 procedure TGUILabel
.Draw
;
1241 FFont
.GetTextSize(FText
, w
, h
);
1242 FFont
.Draw(FX
+FMaxWidth
-w
, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
);
1246 FFont
.Draw(FX
, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
);
1250 function TGUILabel
.GetHeight
: Integer;
1254 FFont
.GetTextSize(FText
, w
, h
);
1258 function TGUILabel
.GetWidth
: Integer;
1262 if FFixedLen
= 0 then
1263 FFont
.GetTextSize(FText
, w
, h
)
1265 w
:= e_CharFont_GetMaxWidth(FFont
.ID
)*FFixedLen
;
1269 procedure TGUILabel
.OnMessage(var Msg
: TMessage
);
1271 if not FEnabled
then Exit
;
1278 IK_RETURN
, IK_KPRETURN
: if @FOnClickEvent
<> nil then FOnClickEvent();
1285 function TGUIMenu
.AddButton(Proc
: Pointer; fText
: string; _ShowWindow
: string = ''): TGUITextButton
;
1292 Control
:= TGUITextButton
.Create(Proc
, FFontID
, fText
);
1293 with Control
as TGUITextButton
do
1295 ShowWindow
:= _ShowWindow
;
1296 FColor
:= MENU_ITEMSCTRL_COLOR
;
1300 ControlType
:= TGUITextButton
;
1302 Result
:= (Control
as TGUITextButton
);
1305 if FIndex
= -1 then FIndex
:= i
;
1310 procedure TGUIMenu
.AddLine(fText
: string);
1317 Text := TGUILabel
.Create(fText
, FFontID
);
1320 FColor
:= MENU_ITEMSTEXT_COLOR
;
1329 procedure TGUIMenu
.AddText(fText
: string; MaxWidth
: Word);
1334 l
:= GetLines(fText
, FFontID
, MaxWidth
);
1336 if l
= nil then Exit
;
1338 for a
:= 0 to High(l
) do
1343 Text := TGUILabel
.Create(l
[a
], FFontID
);
1346 with Text do begin FColor
:= _RGB(255, 0, 0); end;
1350 with Text do begin FColor
:= MENU_ITEMSTEXT_COLOR
; end;
1360 procedure TGUIMenu
.AddSpace
;
1374 constructor TGUIMenu
.Create(HeaderFont
, ItemsFont
: DWORD
; Header
: string);
1380 FFontID
:= ItemsFont
;
1381 FCounter
:= MENU_MARKERDELAY
;
1385 FHeader
:= TGUILabel
.Create(Header
, HeaderFont
);
1388 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1390 FColor
:= MAINMENU_HEADER_COLOR
;
1394 destructor TGUIMenu
.Destroy
;
1398 if FItems
<> nil then
1399 for a
:= 0 to High(FItems
) do
1413 procedure TGUIMenu
.Draw
;
1415 a
, locx
, locy
: Integer;
1419 if FHeader
<> nil then FHeader
.Draw
;
1421 if FItems
<> nil then
1422 for a
:= 0 to High(FItems
) do
1424 if FItems
[a
].Text <> nil then FItems
[a
].Text.Draw
;
1425 if FItems
[a
].Control
<> nil then FItems
[a
].Control
.Draw
;
1428 if (FIndex
<> -1) and (FCounter
> MENU_MARKERDELAY
div 2) then
1433 if FItems
[FIndex
].Text <> nil then
1435 locx
:= FItems
[FIndex
].Text.FX
;
1436 locy
:= FItems
[FIndex
].Text.FY
;
1438 if FItems
[FIndex
].Text.RightAlign
then
1440 locx
:= locx
+FItems
[FIndex
].Text.FMaxWidth
-FItems
[FIndex
].Text.GetWidth
;
1443 else if FItems
[FIndex
].Control
<> nil then
1445 locx
:= FItems
[FIndex
].Control
.FX
;
1446 locy
:= FItems
[FIndex
].Control
.FY
;
1449 locx
:= locx
-e_CharFont_GetMaxWidth(FFontID
);
1451 e_CharFont_PrintEx(FFontID
, locx
, locy
, #16, _RGB(255, 0, 0));
1455 function TGUIMenu
.GetControl(aName
: String): TGUIControl
;
1461 if FItems
<> nil then
1462 for a
:= 0 to High(FItems
) do
1463 if FItems
[a
].Control
<> nil then
1464 if LowerCase(FItems
[a
].Control
.Name
) = LowerCase(aName
) then
1466 Result
:= FItems
[a
].Control
;
1470 Assert(Result
<> nil, 'GUI control "'+aName
+'" not found!');
1473 function TGUIMenu
.GetControlsText(aName
: String): TGUILabel
;
1479 if FItems
<> nil then
1480 for a
:= 0 to High(FItems
) do
1481 if FItems
[a
].Control
<> nil then
1482 if LowerCase(FItems
[a
].Control
.Name
) = LowerCase(aName
) then
1484 Result
:= FItems
[a
].Text;
1488 Assert(Result
<> nil, 'GUI control''s text "'+aName
+'" not found!');
1491 function TGUIMenu
.NewItem
: Integer;
1493 SetLength(FItems
, Length(FItems
)+1);
1494 Result
:= High(FItems
);
1497 procedure TGUIMenu
.OnMessage(var Msg
: TMessage
);
1502 if not FEnabled
then Exit
;
1506 if FItems
= nil then Exit
;
1509 for a
:= 0 to High(FItems
) do
1510 if FItems
[a
].Control
<> nil then
1516 if not ok
then Exit
;
1518 if (Msg
.Msg
= WM_KEYDOWN
) and (FIndex
<> -1) and (FItems
[FIndex
].Control
<> nil) and
1519 (FItems
[FIndex
].Control
.WantActivationKey(Msg
.wParam
)) then
1521 FItems
[FIndex
].Control
.OnMessage(Msg
);
1522 g_Sound_PlayEx(MENU_CLICKSOUND
);
1535 if c
> Length(FItems
) then
1542 if FIndex
< 0 then FIndex
:= High(FItems
);
1543 until (FItems
[FIndex
].Control
<> nil) and
1544 (FItems
[FIndex
].Control
.Enabled
);
1548 g_Sound_PlayEx(MENU_CHANGESOUND
);
1556 if c
> Length(FItems
) then
1563 if FIndex
> High(FItems
) then FIndex
:= 0;
1564 until (FItems
[FIndex
].Control
<> nil) and
1565 (FItems
[FIndex
].Control
.Enabled
);
1569 g_Sound_PlayEx(MENU_CHANGESOUND
);
1572 IK_LEFT
, IK_RIGHT
, IK_KPLEFT
, IK_KPRIGHT
:
1574 if FIndex
<> -1 then
1575 if FItems
[FIndex
].Control
<> nil then
1576 FItems
[FIndex
].Control
.OnMessage(Msg
);
1578 IK_RETURN
, IK_KPRETURN
:
1580 if FIndex
<> -1 then
1582 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1584 g_Sound_PlayEx(MENU_CLICKSOUND
);
1588 if FYesNo
and (length(FItems
) > 1) then
1590 Msg
.wParam
:= IK_RETURN
; // to register keypress
1591 FIndex
:= High(FItems
)-1;
1592 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1595 if FYesNo
and (length(FItems
) > 1) then
1597 Msg
.wParam
:= IK_RETURN
; // to register keypress
1598 FIndex
:= High(FItems
);
1599 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1606 procedure TGUIMenu
.ReAlign();
1608 a
, tx
, cx
, w
, h
: Integer;
1609 cww
: array of Integer; // cached widths
1612 if FItems
= nil then Exit
;
1614 SetLength(cww
, length(FItems
));
1616 for a
:= 0 to High(FItems
) do
1618 if FItems
[a
].Text <> nil then
1620 cww
[a
] := FItems
[a
].Text.GetWidth
;
1621 if maxcww
< cww
[a
] then maxcww
:= cww
[a
];
1632 for a
:= 0 to High(FItems
) do
1635 if FItems
[a
].Text <> nil then w
:= FItems
[a
].Text.GetWidth
;
1636 if FItems
[a
].Control
<> nil then
1639 if FItems
[a
].ControlType
= TGUILabel
then w
:= w
+(FItems
[a
].Control
as TGUILabel
).GetWidth
1640 else if FItems
[a
].ControlType
= TGUITextButton
then w
:= w
+(FItems
[a
].Control
as TGUITextButton
).GetWidth
1641 else if FItems
[a
].ControlType
= TGUIScroll
then w
:= w
+(FItems
[a
].Control
as TGUIScroll
).GetWidth
1642 else if FItems
[a
].ControlType
= TGUISwitch
then w
:= w
+(FItems
[a
].Control
as TGUISwitch
).GetWidth
1643 else if FItems
[a
].ControlType
= TGUIEdit
then w
:= w
+(FItems
[a
].Control
as TGUIEdit
).GetWidth
1644 else if FItems
[a
].ControlType
= TGUIKeyRead
then w
:= w
+(FItems
[a
].Control
as TGUIKeyRead
).GetWidth
1645 else if FItems
[a
].ControlType
= TGUIKeyRead2
then w
:= w
+(FItems
[a
].Control
as TGUIKeyRead2
).GetWidth
1646 else if FItems
[a
].ControlType
= TGUIListBox
then w
:= w
+(FItems
[a
].Control
as TGUIListBox
).GetWidth
1647 else if FItems
[a
].ControlType
= TGUIFileListBox
then w
:= w
+(FItems
[a
].Control
as TGUIFileListBox
).GetWidth
1648 else if FItems
[a
].ControlType
= TGUIMemo
then w
:= w
+(FItems
[a
].Control
as TGUIMemo
).GetWidth
;
1650 tx
:= Min(tx
, (gScreenWidth
div 2)-(w
div 2));
1655 for a
:= 0 to High(FItems
) do
1659 if (Text <> nil) and (Control
= nil) then Continue
;
1661 if Text <> nil then w
:= tx
+Text.GetWidth
;
1662 if w
> cx
then cx
:= w
;
1666 cx
:= cx
+MENU_HSPACE
;
1668 h
:= FHeader
.GetHeight
*2+MENU_VSPACE
*(Length(FItems
)-1);
1670 for a
:= 0 to High(FItems
) do
1674 if (ControlType
= TGUIListBox
) or (ControlType
= TGUIFileListBox
) then
1675 h
:= h
+(FItems
[a
].Control
as TGUIListBox
).GetHeight()
1677 h
:= h
+e_CharFont_GetMaxHeight(FFontID
);
1681 h
:= (gScreenHeight
div 2)-(h
div 2);
1685 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1688 Inc(h
, GetHeight
*2);
1691 for a
:= 0 to High(FItems
) do
1703 if Text.RightAlign
and (length(cww
) > a
) then
1705 //Text.FX := Text.FX+maxcww;
1706 Text.FMaxWidth
:= maxcww
;
1710 if Control
<> nil then
1727 if (ControlType
= TGUIListBox
) or (ControlType
= TGUIFileListBox
) then Inc(h
, (Control
as TGUIListBox
).GetHeight
+MENU_VSPACE
)
1728 else if ControlType
= TGUIMemo
then Inc(h
, (Control
as TGUIMemo
).GetHeight
+MENU_VSPACE
)
1729 else Inc(h
, e_CharFont_GetMaxHeight(FFontID
)+MENU_VSPACE
);
1733 // another ugly hack
1734 if FYesNo
and (length(FItems
) > 1) then
1737 for a
:= High(FItems
)-1 to High(FItems
) do
1739 if (FItems
[a
].Control
<> nil) and (FItems
[a
].ControlType
= TGUITextButton
) then
1741 cx
:= (FItems
[a
].Control
as TGUITextButton
).GetWidth
;
1742 if cx
> w
then w
:= cx
;
1747 for a
:= High(FItems
)-1 to High(FItems
) do
1749 if (FItems
[a
].Control
<> nil) and (FItems
[a
].ControlType
= TGUITextButton
) then
1751 FItems
[a
].Control
.FX
:= (gScreenWidth
-w
) div 2;
1758 function TGUIMenu
.AddScroll(fText
: string): TGUIScroll
;
1765 Control
:= TGUIScroll
.Create();
1767 Text := TGUILabel
.Create(fText
, FFontID
);
1770 FColor
:= MENU_ITEMSTEXT_COLOR
;
1773 ControlType
:= TGUIScroll
;
1775 Result
:= (Control
as TGUIScroll
);
1778 if FIndex
= -1 then FIndex
:= i
;
1783 function TGUIMenu
.AddSwitch(fText
: string): TGUISwitch
;
1790 Control
:= TGUISwitch
.Create(FFontID
);
1791 (Control
as TGUISwitch
).FColor
:= MENU_ITEMSCTRL_COLOR
;
1793 Text := TGUILabel
.Create(fText
, FFontID
);
1796 FColor
:= MENU_ITEMSTEXT_COLOR
;
1799 ControlType
:= TGUISwitch
;
1801 Result
:= (Control
as TGUISwitch
);
1804 if FIndex
= -1 then FIndex
:= i
;
1809 function TGUIMenu
.AddEdit(fText
: string): TGUIEdit
;
1816 Control
:= TGUIEdit
.Create(FFontID
);
1817 with Control
as TGUIEdit
do
1819 FWindow
:= Self
.FWindow
;
1820 FColor
:= MENU_ITEMSCTRL_COLOR
;
1823 if fText
= '' then Text := nil else
1825 Text := TGUILabel
.Create(fText
, FFontID
);
1826 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
1829 ControlType
:= TGUIEdit
;
1831 Result
:= (Control
as TGUIEdit
);
1834 if FIndex
= -1 then FIndex
:= i
;
1839 procedure TGUIMenu
.Update
;
1845 if FCounter
= 0 then FCounter
:= MENU_MARKERDELAY
else Dec(FCounter
);
1847 if FItems
<> nil then
1848 for a
:= 0 to High(FItems
) do
1849 if FItems
[a
].Control
<> nil then
1850 (FItems
[a
].Control
as FItems
[a
].ControlType
).Update
;
1853 function TGUIMenu
.AddKeyRead(fText
: string): TGUIKeyRead
;
1860 Control
:= TGUIKeyRead
.Create(FFontID
);
1861 with Control
as TGUIKeyRead
do
1863 FWindow
:= Self
.FWindow
;
1864 FColor
:= MENU_ITEMSCTRL_COLOR
;
1867 Text := TGUILabel
.Create(fText
, FFontID
);
1870 FColor
:= MENU_ITEMSTEXT_COLOR
;
1873 ControlType
:= TGUIKeyRead
;
1875 Result
:= (Control
as TGUIKeyRead
);
1878 if FIndex
= -1 then FIndex
:= i
;
1883 function TGUIMenu
.AddKeyRead2(fText
: string): TGUIKeyRead2
;
1890 Control
:= TGUIKeyRead2
.Create(FFontID
);
1891 with Control
as TGUIKeyRead2
do
1893 FWindow
:= Self
.FWindow
;
1894 FColor
:= MENU_ITEMSCTRL_COLOR
;
1897 Text := TGUILabel
.Create(fText
, FFontID
);
1900 FColor
:= MENU_ITEMSCTRL_COLOR
; //MENU_ITEMSTEXT_COLOR;
1904 ControlType
:= TGUIKeyRead2
;
1906 Result
:= (Control
as TGUIKeyRead2
);
1909 if FIndex
= -1 then FIndex
:= i
;
1914 function TGUIMenu
.AddList(fText
: string; Width
, Height
: Word): TGUIListBox
;
1921 Control
:= TGUIListBox
.Create(FFontID
, Width
, Height
);
1922 with Control
as TGUIListBox
do
1924 FWindow
:= Self
.FWindow
;
1925 FActiveColor
:= MENU_ITEMSCTRL_COLOR
;
1926 FUnActiveColor
:= MENU_ITEMSTEXT_COLOR
;
1929 Text := TGUILabel
.Create(fText
, FFontID
);
1932 FColor
:= MENU_ITEMSTEXT_COLOR
;
1935 ControlType
:= TGUIListBox
;
1937 Result
:= (Control
as TGUIListBox
);
1940 if FIndex
= -1 then FIndex
:= i
;
1945 function TGUIMenu
.AddFileList(fText
: string; Width
, Height
: Word): TGUIFileListBox
;
1952 Control
:= TGUIFileListBox
.Create(FFontID
, Width
, Height
);
1953 with Control
as TGUIFileListBox
do
1955 FWindow
:= Self
.FWindow
;
1956 FActiveColor
:= MENU_ITEMSCTRL_COLOR
;
1957 FUnActiveColor
:= MENU_ITEMSTEXT_COLOR
;
1960 if fText
= '' then Text := nil else
1962 Text := TGUILabel
.Create(fText
, FFontID
);
1963 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
1966 ControlType
:= TGUIFileListBox
;
1968 Result
:= (Control
as TGUIFileListBox
);
1971 if FIndex
= -1 then FIndex
:= i
;
1976 function TGUIMenu
.AddLabel(fText
: string): TGUILabel
;
1983 Control
:= TGUILabel
.Create('', FFontID
);
1984 with Control
as TGUILabel
do
1986 FWindow
:= Self
.FWindow
;
1987 FColor
:= MENU_ITEMSCTRL_COLOR
;
1990 Text := TGUILabel
.Create(fText
, FFontID
);
1993 FColor
:= MENU_ITEMSTEXT_COLOR
;
1996 ControlType
:= TGUILabel
;
1998 Result
:= (Control
as TGUILabel
);
2001 if FIndex
= -1 then FIndex
:= i
;
2006 function TGUIMenu
.AddMemo(fText
: string; Width
, Height
: Word): TGUIMemo
;
2013 Control
:= TGUIMemo
.Create(FFontID
, Width
, Height
);
2014 with Control
as TGUIMemo
do
2016 FWindow
:= Self
.FWindow
;
2017 FColor
:= MENU_ITEMSTEXT_COLOR
;
2020 if fText
= '' then Text := nil else
2022 Text := TGUILabel
.Create(fText
, FFontID
);
2023 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
2026 ControlType
:= TGUIMemo
;
2028 Result
:= (Control
as TGUIMemo
);
2031 if FIndex
= -1 then FIndex
:= i
;
2036 procedure TGUIMenu
.UpdateIndex();
2044 if (FIndex
< 0) or (FIndex
> High(FItems
)) then
2050 if FItems
[FIndex
].Control
.Enabled
then
2059 constructor TGUIScroll
.Create
;
2064 FOnChangeEvent
:= nil;
2066 g_Texture_Get(SCROLL_LEFT
, FLeftID
);
2067 g_Texture_Get(SCROLL_RIGHT
, FRightID
);
2068 g_Texture_Get(SCROLL_MIDDLE
, FMiddleID
);
2069 g_Texture_Get(SCROLL_MARKER
, FMarkerID
);
2072 procedure TGUIScroll
.Draw
;
2078 e_Draw(FLeftID
, FX
, FY
, 0, True, False);
2079 e_Draw(FRightID
, FX
+8+(FMax
+1)*8, FY
, 0, True, False);
2081 for a
:= 0 to FMax
do
2082 e_Draw(FMiddleID
, FX
+8+a
*8, FY
, 0, True, False);
2084 e_Draw(FMarkerID
, FX
+8+FValue
*8, FY
, 0, True, False);
2087 procedure TGUIScroll
.FSetValue(a
: Integer);
2089 if a
> FMax
then FValue
:= FMax
else FValue
:= a
;
2092 function TGUIScroll
.GetWidth
: Integer;
2094 Result
:= 16+(FMax
+1)*8;
2097 procedure TGUIScroll
.OnMessage(var Msg
: TMessage
);
2099 if not FEnabled
then Exit
;
2111 g_Sound_PlayEx(SCROLL_SUBSOUND
);
2112 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2114 IK_RIGHT
, IK_KPRIGHT
:
2115 if FValue
< FMax
then
2118 g_Sound_PlayEx(SCROLL_ADDSOUND
);
2119 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2126 procedure TGUIScroll
.Update
;
2134 procedure TGUISwitch
.AddItem(Item
: string);
2136 SetLength(FItems
, Length(FItems
)+1);
2137 FItems
[High(FItems
)] := Item
;
2139 if FIndex
= -1 then FIndex
:= 0;
2142 constructor TGUISwitch
.Create(FontID
: DWORD
);
2148 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2151 procedure TGUISwitch
.Draw
;
2155 FFont
.Draw(FX
, FY
, FItems
[FIndex
], FColor
.R
, FColor
.G
, FColor
.B
);
2158 function TGUISwitch
.GetText
: string;
2160 if FIndex
<> -1 then Result
:= FItems
[FIndex
]
2164 function TGUISwitch
.GetWidth
: Integer;
2171 if FItems
= nil then Exit
;
2173 for a
:= 0 to High(FItems
) do
2175 FFont
.GetTextSize(FItems
[a
], w
, h
);
2176 if w
> Result
then Result
:= w
;
2180 procedure TGUISwitch
.OnMessage(var Msg
: TMessage
);
2182 if not FEnabled
then Exit
;
2186 if FItems
= nil then Exit
;
2191 IK_RETURN
, IK_RIGHT
, IK_KPRETURN
, IK_KPRIGHT
:
2193 if FIndex
< High(FItems
) then
2198 if @FOnChangeEvent
<> nil then
2199 FOnChangeEvent(Self
);
2207 FIndex
:= High(FItems
);
2209 if @FOnChangeEvent
<> nil then
2210 FOnChangeEvent(Self
);
2216 procedure TGUISwitch
.Update
;
2224 constructor TGUIEdit
.Create(FontID
: DWORD
);
2228 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2234 g_Texture_Get(EDIT_LEFT
, FLeftID
);
2235 g_Texture_Get(EDIT_RIGHT
, FRightID
);
2236 g_Texture_Get(EDIT_MIDDLE
, FMiddleID
);
2239 procedure TGUIEdit
.Draw
;
2246 e_Draw(FLeftID
, FX
, FY
, 0, True, False);
2247 e_Draw(FRightID
, FX
+8+FWidth
*16, FY
, 0, True, False);
2249 for c
:= 0 to FWidth
-1 do
2250 e_Draw(FMiddleID
, FX
+8+c
*16, FY
, 0, True, False);
2255 if FInvalid
and (FWindow
.FActiveControl
<> self
) then begin r
:= 128; g
:= 128; b
:= 128; end;
2256 FFont
.Draw(FX
+8, FY
, FText
, r
, g
, b
);
2258 if (FWindow
.FActiveControl
= self
) then
2260 FFont
.GetTextSize(Copy(FText
, 1, FCaretPos
), w
, h
);
2261 h
:= e_CharFont_GetMaxHeight(FFont
.ID
);
2262 e_DrawLine(2, FX
+8+w
, FY
+h
-3, FX
+8+w
+EDIT_CURSORLEN
, FY
+h
-3,
2263 EDIT_CURSORCOLOR
.R
, EDIT_CURSORCOLOR
.G
, EDIT_CURSORCOLOR
.B
);
2267 function TGUIEdit
.GetWidth
: Integer;
2269 Result
:= 16+FWidth
*16;
2272 procedure TGUIEdit
.OnMessage(var Msg
: TMessage
);
2274 if not FEnabled
then Exit
;
2283 if (wParam
in [48..57]) and (Chr(wParam
) <> '`') then
2284 if Length(Text) < FMaxLength
then
2286 Insert(Chr(wParam
), FText
, FCaretPos
+ 1);
2292 if (wParam
in [32..255]) and (Chr(wParam
) <> '`') then
2293 if Length(Text) < FMaxLength
then
2295 Insert(Chr(wParam
), FText
, FCaretPos
+ 1);
2303 Delete(FText
, FCaretPos
, 1);
2304 if FCaretPos
> 0 then Dec(FCaretPos
);
2306 IK_DELETE
: Delete(FText
, FCaretPos
+ 1, 1);
2307 IK_END
, IK_KPEND
: FCaretPos
:= Length(FText
);
2308 IK_HOME
, IK_KPHOME
: FCaretPos
:= 0;
2309 IK_LEFT
, IK_KPLEFT
: if FCaretPos
> 0 then Dec(FCaretPos
);
2310 IK_RIGHT
, IK_KPRIGHT
: if FCaretPos
< Length(FText
) then Inc(FCaretPos
);
2311 IK_RETURN
, IK_KPRETURN
:
2314 if FActiveControl
<> Self
then
2317 if @FOnEnterEvent
<> nil then FOnEnterEvent(Self
);
2321 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
2322 else SetActive(nil);
2323 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2330 procedure TGUIEdit
.SetText(Text: string);
2332 if Length(Text) > FMaxLength
then SetLength(Text, FMaxLength
);
2334 FCaretPos
:= Length(FText
);
2337 procedure TGUIEdit
.Update
;
2344 constructor TGUIKeyRead
.Create(FontID
: DWORD
);
2350 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2353 procedure TGUIKeyRead
.Draw
;
2357 FFont
.Draw(FX
, FY
, IfThen(FIsQuery
, KEYREAD_QUERY
, IfThen(FKey
<> 0, e_KeyNames
[FKey
], KEYREAD_CLEAR
)),
2358 FColor
.R
, FColor
.G
, FColor
.B
);
2361 function TGUIKeyRead
.GetWidth
: Integer;
2368 for a
:= 0 to 255 do
2370 FFont
.GetTextSize(e_KeyNames
[a
], w
, h
);
2371 Result
:= Max(Result
, w
);
2374 FFont
.GetTextSize(KEYREAD_QUERY
, w
, h
);
2375 if w
> Result
then Result
:= w
;
2377 FFont
.GetTextSize(KEYREAD_CLEAR
, w
, h
);
2378 if w
> Result
then Result
:= w
;
2381 function TGUIKeyRead
.WantActivationKey (key
: LongInt): Boolean;
2384 (key
= IK_BACKSPACE
) or
2388 procedure TGUIKeyRead
.OnMessage(var Msg
: TMessage
);
2389 procedure actDefCtl ();
2392 if FDefControl
<> '' then
2393 SetActive(GetControl(FDefControl
))
2401 if not FEnabled
then
2410 if FIsQuery
then actDefCtl();
2413 IK_RETURN
, IK_KPRETURN
:
2415 if not FIsQuery
then
2418 if FActiveControl
<> Self
then
2425 FKey
:= IK_ENTER
; // <Enter>
2430 IK_BACKSPACE
: // clear keybinding if we aren't waiting for a key
2432 if not FIsQuery
then
2442 if not FIsQuery
and (wParam
= IK_BACKSPACE
) then
2447 else if FIsQuery
and (wParam
<> IK_ENTER
) and (wParam
<> IK_KPRETURN
) then // Not <Enter
2449 if e_KeyNames
[wParam
] <> '' then
2460 constructor TGUIKeyRead2
.Create(FontID
: DWORD
);
2473 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2475 FMaxKeyNameWdt
:= 0;
2476 for a
:= 0 to 255 do
2478 FFont
.GetTextSize(e_KeyNames
[a
], w
, h
);
2479 FMaxKeyNameWdt
:= Max(FMaxKeyNameWdt
, w
);
2482 FMaxKeyNameWdt
:= FMaxKeyNameWdt
-(FMaxKeyNameWdt
div 3);
2484 FFont
.GetTextSize(KEYREAD_QUERY
, w
, h
);
2485 if w
> FMaxKeyNameWdt
then FMaxKeyNameWdt
:= w
;
2487 FFont
.GetTextSize(KEYREAD_CLEAR
, w
, h
);
2488 if w
> FMaxKeyNameWdt
then FMaxKeyNameWdt
:= w
;
2491 procedure TGUIKeyRead2
.Draw
;
2492 procedure drawText (idx
: Integer);
2498 if idx
= 0 then kk
:= FKey0
else kk
:= FKey1
;
2500 if idx
= 0 then x
:= FX
+8 else x
:= FX
+8+FMaxKeyNameWdt
+16;
2504 if FKeyIdx
= idx
then begin r
:= 255; g
:= 255; b
:= 255; end;
2505 if FIsQuery
and (FKeyIdx
= idx
) then
2506 FFont
.Draw(x
, y
, KEYREAD_QUERY
, r
, g
, b
)
2508 FFont
.Draw(x
, y
, IfThen(kk
<> 0, e_KeyNames
[kk
], KEYREAD_CLEAR
), r
, g
, b
);
2514 //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);
2515 //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);
2520 function TGUIKeyRead2
.GetWidth
: Integer;
2522 Result
:= FMaxKeyNameWdt
*2+8+8+16;
2525 function TGUIKeyRead2
.WantActivationKey (key
: LongInt): Boolean;
2528 (key
= IK_BACKSPACE
) or
2529 (key
= IK_LEFT
) or (key
= IK_RIGHT
) or
2530 (key
= IK_KPLEFT
) or (key
= IK_KPRIGHT
) or
2534 procedure TGUIKeyRead2
.OnMessage(var Msg
: TMessage
);
2535 procedure actDefCtl ();
2538 if FDefControl
<> '' then
2539 SetActive(GetControl(FDefControl
))
2547 if not FEnabled
then
2556 if FIsQuery
then actDefCtl();
2559 IK_RETURN
, IK_KPRETURN
:
2561 if not FIsQuery
then
2564 if FActiveControl
<> Self
then
2571 if (FKeyIdx
= 0) then FKey0
:= IK_ENTER
else FKey1
:= IK_ENTER
; // <Enter>
2576 IK_BACKSPACE
: // clear keybinding if we aren't waiting for a key
2578 if not FIsQuery
then
2580 if (FKeyIdx
= 0) then FKey0
:= 0 else FKey1
:= 0;
2585 if not FIsQuery
then
2590 IK_RIGHT
, IK_KPRIGHT
:
2591 if not FIsQuery
then
2600 if not FIsQuery
and (wParam
= IK_BACKSPACE
) then
2602 if (FKeyIdx
= 0) then FKey0
:= 0 else FKey1
:= 0;
2605 else if FIsQuery
and (wParam
<> IK_ENTER
) and (wParam
<> IK_KPRETURN
) then // Not <Enter
2607 if e_KeyNames
[wParam
] <> '' then
2609 if (FKeyIdx
= 0) then FKey0
:= wParam
else FKey1
:= wParam
;
2621 constructor TGUIModelView
.Create
;
2628 destructor TGUIModelView
.Destroy
;
2635 procedure TGUIModelView
.Draw
;
2639 DrawBox(FX
, FY
, 4, 4);
2641 if FModel
<> nil then FModel
.Draw(FX
+4, FY
+4);
2644 procedure TGUIModelView
.NextAnim();
2646 if FModel
= nil then
2649 if FModel
.Animation
< A_PAIN
then
2650 FModel
.ChangeAnimation(FModel
.Animation
+1, True)
2652 FModel
.ChangeAnimation(A_STAND
, True);
2655 procedure TGUIModelView
.NextWeapon();
2657 if FModel
= nil then
2660 if FModel
.Weapon
< WP_LAST
then
2661 FModel
.SetWeapon(FModel
.Weapon
+1)
2663 FModel
.SetWeapon(WEAPON_KASTET
);
2666 procedure TGUIModelView
.OnMessage(var Msg
: TMessage
);
2672 procedure TGUIModelView
.SetColor(Red
, Green
, Blue
: Byte);
2674 if FModel
<> nil then FModel
.SetColor(Red
, Green
, Blue
);
2677 procedure TGUIModelView
.SetModel(ModelName
: string);
2681 FModel
:= g_PlayerModel_Get(ModelName
);
2684 procedure TGUIModelView
.Update
;
2691 if FModel
<> nil then FModel
.Update
;
2696 constructor TGUIMapPreview
.Create();
2702 destructor TGUIMapPreview
.Destroy();
2708 procedure TGUIMapPreview
.Draw();
2715 DrawBox(FX
, FY
, MAPPREVIEW_WIDTH
, MAPPREVIEW_HEIGHT
);
2717 if (FMapSize
.X
<= 0) or (FMapSize
.Y
<= 0) then
2720 e_DrawFillQuad(FX
+4, FY
+4,
2721 FX
+4 + Trunc(FMapSize
.X
/ FScale
) - 1,
2722 FY
+4 + Trunc(FMapSize
.Y
/ FScale
) - 1,
2725 if FMapData
<> nil then
2726 for a
:= 0 to High(FMapData
) do
2729 if X1
> MAPPREVIEW_WIDTH
*16 then Continue
;
2730 if Y1
> MAPPREVIEW_HEIGHT
*16 then Continue
;
2732 if X2
< 0 then Continue
;
2733 if Y2
< 0 then Continue
;
2735 if X2
> MAPPREVIEW_WIDTH
*16 then X2
:= MAPPREVIEW_WIDTH
*16;
2736 if Y2
> MAPPREVIEW_HEIGHT
*16 then Y2
:= MAPPREVIEW_HEIGHT
*16;
2738 if X1
< 0 then X1
:= 0;
2739 if Y1
< 0 then Y1
:= 0;
2780 if ((X2
-X1
) > 0) and ((Y2
-Y1
) > 0) then
2781 e_DrawFillQuad(FX
+4 + X1
, FY
+4 + Y1
,
2782 FX
+4 + X2
- 1, FY
+4 + Y2
- 1, r
, g
, b
, 0);
2786 procedure TGUIMapPreview
.OnMessage(var Msg
: TMessage
);
2792 procedure TGUIMapPreview
.SetMap(Res
: string);
2797 //header: TMapHeaderRec_1;
2802 map
: TDynRecord
= nil;
2809 FileName
:= g_ExtractWadName(Res
);
2811 WAD
:= TWADFile
.Create();
2812 if not WAD
.ReadFile(FileName
) then
2818 //k8: ignores path again
2819 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
2828 map
:= g_Map_ParseMap(Data
, Len
);
2838 if (map
= nil) then exit
;
2841 panlist
:= map
.field
['panel'];
2842 //header := GetMapHeader(map);
2844 FMapSize
.X
:= map
.Width
div 16;
2845 FMapSize
.Y
:= map
.Height
div 16;
2847 rX
:= Ceil(map
.Width
/ (MAPPREVIEW_WIDTH
*256.0));
2848 rY
:= Ceil(map
.Height
/ (MAPPREVIEW_HEIGHT
*256.0));
2849 FScale
:= max(rX
, rY
);
2853 if (panlist
<> nil) then
2855 for pan
in panlist
do
2857 if (pan
.PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or
2858 PANEL_STEP
or PANEL_WATER
or
2859 PANEL_ACID1
or PANEL_ACID2
)) <> 0 then
2861 SetLength(FMapData
, Length(FMapData
)+1);
2862 with FMapData
[High(FMapData
)] do
2867 X2
:= (pan
.X
+ pan
.Width
) div 16;
2868 Y2
:= (pan
.Y
+ pan
.Height
) div 16;
2870 X1
:= Trunc(X1
/FScale
+ 0.5);
2871 Y1
:= Trunc(Y1
/FScale
+ 0.5);
2872 X2
:= Trunc(X2
/FScale
+ 0.5);
2873 Y2
:= Trunc(Y2
/FScale
+ 0.5);
2875 if (X1
<> X2
) or (Y1
<> Y2
) then
2883 PanelType
:= pan
.PanelType
;
2889 //writeln('freeing map');
2894 procedure TGUIMapPreview
.ClearMap();
2896 SetLength(FMapData
, 0);
2903 procedure TGUIMapPreview
.Update();
2909 function TGUIMapPreview
.GetScaleStr(): String;
2911 if FScale
> 0.0 then
2913 Result
:= FloatToStrF(FScale
*16.0, ffFixed
, 3, 3);
2914 while (Result
[Length(Result
)] = '0') do
2915 Delete(Result
, Length(Result
), 1);
2916 if (Result
[Length(Result
)] = ',') or (Result
[Length(Result
)] = '.') then
2917 Delete(Result
, Length(Result
), 1);
2918 Result
:= '1 : ' + Result
;
2926 procedure TGUIListBox
.AddItem(Item
: string);
2928 SetLength(FItems
, Length(FItems
)+1);
2929 FItems
[High(FItems
)] := Item
;
2931 if FSort
then g_Basic
.Sort(FItems
);
2934 procedure TGUIListBox
.Clear();
2942 constructor TGUIListBox
.Create(FontID
: DWORD
; Width
, Height
: Word);
2946 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2951 FOnChangeEvent
:= nil;
2953 FDrawScroll
:= True;
2956 procedure TGUIListBox
.Draw
;
2964 if FDrawBack
then DrawBox(FX
, FY
, FWidth
+1, FHeight
);
2966 DrawScroll(FX
+4+FWidth
*16, FY
+4, FHeight
, (FStartLine
> 0) and (FItems
<> nil),
2967 (FStartLine
+FHeight
-1 < High(FItems
)) and (FItems
<> nil));
2969 if FItems
<> nil then
2970 for a
:= FStartLine
to Min(High(FItems
), FStartLine
+FHeight
-1) do
2974 FFont
.GetTextSize(s
, w2
, h2
);
2975 while (Length(s
) > 0) and (w2
> FWidth
*16) do
2977 SetLength(s
, Length(s
)-1);
2978 FFont
.GetTextSize(s
, w2
, h2
);
2982 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, s
, FActiveColor
.R
, FActiveColor
.G
, FActiveColor
.B
)
2984 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, s
, FUnActiveColor
.R
, FUnActiveColor
.G
, FUnActiveColor
.B
);
2988 function TGUIListBox
.GetHeight
: Integer;
2990 Result
:= 8+FHeight
*16;
2993 function TGUIListBox
.GetWidth
: Integer;
2995 Result
:= 8+(FWidth
+1)*16;
2998 procedure TGUIListBox
.OnMessage(var Msg
: TMessage
);
3002 if not FEnabled
then Exit
;
3006 if FItems
= nil then Exit
;
3019 FIndex
:= High(FItems
);
3020 FStartLine
:= Max(High(FItems
)-FHeight
+1, 0);
3022 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
:
3026 if FIndex
< FStartLine
then Dec(FStartLine
);
3027 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
3029 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
:
3030 if FIndex
< High(FItems
) then
3033 if FIndex
> FStartLine
+FHeight
-1 then Inc(FStartLine
);
3034 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
3036 IK_RETURN
, IK_KPRETURN
:
3039 if FActiveControl
<> Self
then SetActive(Self
)
3041 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
3042 else SetActive(nil);
3046 for a
:= 0 to High(FItems
) do
3047 if (Length(FItems
[a
]) > 0) and (LowerCase(FItems
[a
][1]) = LowerCase(Chr(wParam
))) then
3050 FStartLine
:= Min(Max(FIndex
-1, 0), Length(FItems
)-FHeight
);
3051 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
3057 function TGUIListBox
.SelectedItem(): String;
3061 if (FIndex
< 0) or (FItems
= nil) or
3062 (FIndex
> High(FItems
)) then
3065 Result
:= FItems
[FIndex
];
3068 procedure TGUIListBox
.FSetItems(Items
: SSArray
);
3070 if FItems
<> nil then
3078 if FSort
then g_Basic
.Sort(FItems
);
3081 procedure TGUIListBox
.SelectItem(Item
: String);
3085 if FItems
= nil then
3089 Item
:= LowerCase(Item
);
3091 for a
:= 0 to High(FItems
) do
3092 if LowerCase(FItems
[a
]) = Item
then
3098 if FIndex
< FHeight
then
3101 FStartLine
:= Min(FIndex
, Length(FItems
)-FHeight
);
3104 procedure TGUIListBox
.FSetIndex(aIndex
: Integer);
3106 if FItems
= nil then
3109 if (aIndex
< 0) or (aIndex
> High(FItems
)) then
3114 if FIndex
<= FHeight
then
3117 FStartLine
:= Min(FIndex
, Length(FItems
)-FHeight
);
3122 procedure TGUIFileListBox
.OnMessage(var Msg
: TMessage
);
3126 if not FEnabled
then
3129 if FItems
= nil then
3140 if @FOnChangeEvent
<> nil then
3141 FOnChangeEvent(Self
);
3146 FIndex
:= High(FItems
);
3147 FStartLine
:= Max(High(FItems
)-FHeight
+1, 0);
3148 if @FOnChangeEvent
<> nil then
3149 FOnChangeEvent(Self
);
3152 IK_PAGEUP
, IK_KPPAGEUP
:
3154 if FIndex
> FHeight
then
3155 FIndex
:= FIndex
-FHeight
3159 if FStartLine
> FHeight
then
3160 FStartLine
:= FStartLine
-FHeight
3165 IK_PAGEDN
, IK_KPPAGEDN
:
3167 if FIndex
< High(FItems
)-FHeight
then
3168 FIndex
:= FIndex
+FHeight
3170 FIndex
:= High(FItems
);
3172 if FStartLine
< High(FItems
)-FHeight
then
3173 FStartLine
:= FStartLine
+FHeight
3175 FStartLine
:= High(FItems
)-FHeight
+1;
3178 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
:
3182 if FIndex
< FStartLine
then
3184 if @FOnChangeEvent
<> nil then
3185 FOnChangeEvent(Self
);
3188 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
:
3189 if FIndex
< High(FItems
) then
3192 if FIndex
> FStartLine
+FHeight
-1 then
3194 if @FOnChangeEvent
<> nil then
3195 FOnChangeEvent(Self
);
3198 IK_RETURN
, IK_KPRETURN
:
3201 if FActiveControl
<> Self
then
3205 if FItems
[FIndex
][1] = #29 then // Ïàïêà
3207 OpenDir(FPath
+Copy(FItems
[FIndex
], 2, 255));
3212 if FDefControl
<> '' then
3213 SetActive(GetControl(FDefControl
))
3221 for a
:= 0 to High(FItems
) do
3222 if ( (Length(FItems
[a
]) > 0) and
3223 (LowerCase(FItems
[a
][1]) = LowerCase(Chr(wParam
))) ) or
3224 ( (Length(FItems
[a
]) > 1) and
3225 (FItems
[a
][1] = #29) and // Ïàïêà
3226 (LowerCase(FItems
[a
][2]) = LowerCase(Chr(wParam
))) ) then
3229 FStartLine
:= Min(Max(FIndex
-1, 0), Length(FItems
)-FHeight
);
3230 if @FOnChangeEvent
<> nil then
3231 FOnChangeEvent(Self
);
3237 procedure TGUIFileListBox
.OpenDir(path
: String);
3245 path
:= IncludeTrailingPathDelimiter(path
);
3246 path
:= ExpandFileName(path
);
3251 if FindFirst(path
+'*', faDirectory
, SR
) = 0 then
3253 if not LongBool(SR
.Attr
and faDirectory
) then
3255 if (SR
.Name
= '.') or
3256 ((SR
.Name
= '..') and (path
= ExpandFileName(FBasePath
))) then
3259 AddItem(#1 + SR
.Name
);
3260 until FindNext(SR
) <> 0;
3270 if i
= 0 then i
:= length(sm
)+1;
3271 sc
:= Copy(sm
, 1, i
-1);
3273 if FindFirst(path
+sc
, faAnyFile
, SR
) = 0 then repeat AddItem(SR
.Name
); until FindNext(SR
) <> 0;
3277 for i
:= 0 to High(FItems
) do
3278 if FItems
[i
][1] = #1 then
3279 FItems
[i
][1] := #29;
3284 procedure TGUIFileListBox
.SetBase(path
: String);
3290 function TGUIFileListBox
.SelectedItem(): String;
3294 if (FIndex
= -1) or (FItems
= nil) or
3295 (FIndex
> High(FItems
)) or
3296 (FItems
[FIndex
][1] = '/') or
3297 (FItems
[FIndex
][1] = '\') then
3300 Result
:= FPath
+ FItems
[FIndex
];
3303 procedure TGUIFileListBox
.UpdateFileList();
3307 if (FIndex
= -1) or (FItems
= nil) or
3308 (FIndex
> High(FItems
)) or
3309 (FItems
[FIndex
][1] = '/') or
3310 (FItems
[FIndex
][1] = '\') then
3313 fn
:= FItems
[FIndex
];
3323 procedure TGUIMemo
.Clear
;
3329 constructor TGUIMemo
.Create(FontID
: DWORD
; Width
, Height
: Word);
3333 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
3338 FDrawScroll
:= True;
3341 procedure TGUIMemo
.Draw
;
3347 if FDrawBack
then DrawBox(FX
, FY
, FWidth
+1, FHeight
);
3349 DrawScroll(FX
+4+FWidth
*16, FY
+4, FHeight
, (FStartLine
> 0) and (FLines
<> nil),
3350 (FStartLine
+FHeight
-1 < High(FLines
)) and (FLines
<> nil));
3352 if FLines
<> nil then
3353 for a
:= FStartLine
to Min(High(FLines
), FStartLine
+FHeight
-1) do
3354 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, FLines
[a
], FColor
.R
, FColor
.G
, FColor
.B
);
3357 function TGUIMemo
.GetHeight
: Integer;
3359 Result
:= 8+FHeight
*16;
3362 function TGUIMemo
.GetWidth
: Integer;
3364 Result
:= 8+(FWidth
+1)*16;
3367 procedure TGUIMemo
.OnMessage(var Msg
: TMessage
);
3369 if not FEnabled
then Exit
;
3373 if FLines
= nil then Exit
;
3379 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
:
3380 if FStartLine
> 0 then
3382 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
:
3383 if FStartLine
< Length(FLines
)-FHeight
then
3385 IK_RETURN
, IK_KPRETURN
:
3388 if FActiveControl
<> Self
then
3394 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
3395 else SetActive(nil);
3401 procedure TGUIMemo
.SetText(Text: string);
3404 FLines
:= GetLines(Text, FFont
.ID
, FWidth
*16);
3409 procedure TGUIimage
.ClearImage();
3411 if FImageRes
= '' then Exit
;
3413 g_Texture_Delete(FImageRes
);
3417 constructor TGUIimage
.Create();
3424 destructor TGUIimage
.Destroy();
3429 procedure TGUIimage
.Draw();
3435 if FImageRes
= '' then
3437 if g_Texture_Get(FDefaultRes
, ID
) then e_Draw(ID
, FX
, FY
, 0, True, False);
3440 if g_Texture_Get(FImageRes
, ID
) then e_Draw(ID
, FX
, FY
, 0, True, False);
3443 procedure TGUIimage
.OnMessage(var Msg
: TMessage
);
3448 procedure TGUIimage
.SetImage(Res
: string);
3452 if g_Texture_CreateWADEx(Res
, Res
) then FImageRes
:= Res
;
3455 procedure TGUIimage
.Update();