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();
552 GL
, GLExt
, g_textures
, g_sound
, SysUtils
,
553 g_game
, Math
, StrUtils
, g_player
, g_options
,
554 g_map
, g_weapons
, xdynrec
, wadreader
;
558 Box
: Array [0..8] of DWORD
;
559 Saved_Windows
: SSArray
;
562 procedure g_GUI_Init();
564 g_Texture_Get(BOX1
, Box
[0]);
565 g_Texture_Get(BOX2
, Box
[1]);
566 g_Texture_Get(BOX3
, Box
[2]);
567 g_Texture_Get(BOX4
, Box
[3]);
568 g_Texture_Get(BOX5
, Box
[4]);
569 g_Texture_Get(BOX6
, Box
[5]);
570 g_Texture_Get(BOX7
, Box
[6]);
571 g_Texture_Get(BOX8
, Box
[7]);
572 g_Texture_Get(BOX9
, Box
[8]);
575 function g_GUI_Destroy(): Boolean;
579 Result
:= (Length(g_GUIWindows
) > 0);
581 for i
:= 0 to High(g_GUIWindows
) do
582 g_GUIWindows
[i
].Free();
585 g_ActiveWindow
:= nil;
588 function g_GUI_AddWindow(Window
: TGUIWindow
): TGUIWindow
;
590 SetLength(g_GUIWindows
, Length(g_GUIWindows
)+1);
591 g_GUIWindows
[High(g_GUIWindows
)] := Window
;
596 function g_GUI_GetWindow(Name
: string): TGUIWindow
;
602 if g_GUIWindows
<> nil then
603 for i
:= 0 to High(g_GUIWindows
) do
604 if g_GUIWindows
[i
].FName
= Name
then
606 Result
:= g_GUIWindows
[i
];
610 Assert(Result
<> nil, 'GUI_Window "'+Name
+'" not found');
613 procedure g_GUI_ShowWindow(Name
: string);
617 if g_GUIWindows
= nil then
620 for i
:= 0 to High(g_GUIWindows
) do
621 if g_GUIWindows
[i
].FName
= Name
then
623 g_GUIWindows
[i
].FPrevWindow
:= g_ActiveWindow
;
624 g_ActiveWindow
:= g_GUIWindows
[i
];
626 if g_ActiveWindow
.MainWindow
then
627 g_ActiveWindow
.FPrevWindow
:= nil;
629 if g_ActiveWindow
.FDefControl
<> '' then
630 g_ActiveWindow
.SetActive(g_ActiveWindow
.GetControl(g_ActiveWindow
.FDefControl
))
632 g_ActiveWindow
.SetActive(nil);
634 if @g_ActiveWindow
.FOnShowEvent
<> nil then
635 g_ActiveWindow
.FOnShowEvent();
641 procedure g_GUI_HideWindow(PlaySound
: Boolean = True);
643 if g_ActiveWindow
<> nil then
645 if @g_ActiveWindow
.OnClose
<> nil then
646 g_ActiveWindow
.OnClose();
647 g_ActiveWindow
:= g_ActiveWindow
.FPrevWindow
;
649 g_Sound_PlayEx(WINDOW_CLOSESOUND
);
653 procedure g_GUI_SaveMenuPos();
658 SetLength(Saved_Windows
, 0);
659 win
:= g_ActiveWindow
;
663 len
:= Length(Saved_Windows
);
664 SetLength(Saved_Windows
, len
+ 1);
666 Saved_Windows
[len
] := win
.Name
;
668 if win
.MainWindow
then
671 win
:= win
.FPrevWindow
;
675 procedure g_GUI_LoadMenuPos();
677 i
, j
, k
, len
: Integer;
680 g_ActiveWindow
:= nil;
681 len
:= Length(Saved_Windows
);
686 // Îêíî ñ ãëàâíûì ìåíþ:
687 g_GUI_ShowWindow(Saved_Windows
[len
-1]);
689 // Íå ïåðåêëþ÷èëîñü (èëè íåêóäà äàëüøå):
690 if (len
= 1) or (g_ActiveWindow
= nil) then
693 // Èùåì êíîïêè â îñòàëüíûõ îêíàõ:
694 for k
:= len
-1 downto 1 do
698 for i
:= 0 to Length(g_ActiveWindow
.Childs
)-1 do
700 if g_ActiveWindow
.Childs
[i
] is TGUIMainMenu
then
701 begin // GUI_MainMenu
702 with TGUIMainMenu(g_ActiveWindow
.Childs
[i
]) do
703 for j
:= 0 to Length(FButtons
)-1 do
704 if FButtons
[j
].ShowWindow
= Saved_Windows
[k
-1] then
706 FButtons
[j
].Click(True);
712 if g_ActiveWindow
.Childs
[i
] is TGUIMenu
then
713 with TGUIMenu(g_ActiveWindow
.Childs
[i
]) do
714 for j
:= 0 to Length(FItems
)-1 do
715 if FItems
[j
].ControlType
= TGUITextButton
then
716 if TGUITextButton(FItems
[j
].Control
).ShowWindow
= Saved_Windows
[k
-1] then
718 TGUITextButton(FItems
[j
].Control
).Click(True);
729 (g_ActiveWindow
.Name
= Saved_Windows
[k
]) then
734 procedure DrawBox(X
, Y
: Integer; Width
, Height
: Word);
736 e_Draw(Box
[0], X
, Y
, 0, False, False);
737 e_DrawFill(Box
[1], X
+4, Y
, Width
*4, 1, 0, False, False);
738 e_Draw(Box
[2], X
+4+Width
*16, Y
, 0, False, False);
739 e_DrawFill(Box
[3], X
, Y
+4, 1, Height
*4, 0, False, False);
740 e_DrawFill(Box
[4], X
+4, Y
+4, Width
, Height
, 0, False, False);
741 e_DrawFill(Box
[5], X
+4+Width
*16, Y
+4, 1, Height
*4, 0, False, False);
742 e_Draw(Box
[6], X
, Y
+4+Height
*16, 0, False, False);
743 e_DrawFill(Box
[7], X
+4, Y
+4+Height
*16, Width
*4, 1, 0, False, False);
744 e_Draw(Box
[8], X
+4+Width
*16, Y
+4+Height
*16, 0, False, False);
747 procedure DrawScroll(X
, Y
: Integer; Height
: Word; Up
, Down
: Boolean);
751 if Height
< 3 then Exit
;
754 g_Texture_Get(BSCROLL_UPA
, ID
)
756 g_Texture_Get(BSCROLL_UPU
, ID
);
757 e_Draw(ID
, X
, Y
, 0, False, False);
760 g_Texture_Get(BSCROLL_DOWNA
, ID
)
762 g_Texture_Get(BSCROLL_DOWNU
, ID
);
763 e_Draw(ID
, X
, Y
+(Height
-1)*16, 0, False, False);
765 g_Texture_Get(BSCROLL_MIDDLE
, ID
);
766 e_DrawFill(ID
, X
, Y
+16, 1, Height
-2, 0, False, False);
771 constructor TGUIWindow
.Create(Name
: string);
774 FActiveControl
:= nil;
778 FOnCloseEvent
:= nil;
782 destructor TGUIWindow
.Destroy
;
789 for i
:= 0 to High(Childs
) do
793 function TGUIWindow
.AddChild(Child
: TGUIControl
): TGUIControl
;
795 Child
.FWindow
:= Self
;
797 SetLength(Childs
, Length(Childs
) + 1);
798 Childs
[High(Childs
)] := Child
;
803 procedure TGUIWindow
.Update
;
807 for i
:= 0 to High(Childs
) do
808 if Childs
[i
] <> nil then Childs
[i
].Update
;
811 procedure TGUIWindow
.Draw
;
816 if FBackTexture
<> '' then
817 if g_Texture_Get(FBackTexture
, ID
) then
818 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
820 e_Clear(GL_COLOR_BUFFER_BIT
, 0.5, 0.5, 0.5);
822 for i
:= 0 to High(Childs
) do
823 if Childs
[i
] <> nil then Childs
[i
].Draw
;
826 procedure TGUIWindow
.OnMessage(var Msg
: TMessage
);
828 if FActiveControl
<> nil then FActiveControl
.OnMessage(Msg
);
829 if @FOnKeyDown
<> nil then FOnKeyDown(Msg
.wParam
);
830 if @FOnKeyDownEx
<> nil then FOnKeyDownEx(self
, Msg
.wParam
);
832 if Msg
.Msg
= WM_KEYDOWN
then
833 if Msg
.wParam
= IK_ESCAPE
then
840 procedure TGUIWindow
.SetActive(Control
: TGUIControl
);
842 FActiveControl
:= Control
;
845 function TGUIWindow
.GetControl(Name
: String): TGUIControl
;
851 if Childs
<> nil then
852 for i
:= 0 to High(Childs
) do
853 if Childs
[i
] <> nil then
854 if LowerCase(Childs
[i
].FName
) = LowerCase(Name
) then
860 Assert(Result
<> nil, 'Window Control "'+Name
+'" not Found!');
865 constructor TGUIControl
.Create();
871 FRightAlign
:= false;
875 procedure TGUIControl
.OnMessage(var Msg
: TMessage
);
881 procedure TGUIControl
.Update();
885 procedure TGUIControl
.Draw();
889 function TGUIControl
.WantActivationKey (key
: LongInt): Boolean;
894 function TGUIControl
.GetWidth(): Integer;
899 function TGUIControl
.GetHeight(): Integer;
906 procedure TGUITextButton
.Click(Silent
: Boolean = False);
908 if (FSound
<> '') and (not Silent
) then g_Sound_PlayEx(FSound
);
910 if @Proc
<> nil then Proc();
911 if @ProcEx
<> nil then ProcEx(self
);
913 if FShowWindow
<> '' then g_GUI_ShowWindow(FShowWindow
);
916 constructor TGUITextButton
.Create(aProc
: Pointer; FontID
: DWORD
; Text: string);
923 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
928 destructor TGUITextButton
.Destroy
;
934 procedure TGUITextButton
.Draw
;
936 FFont
.Draw(FX
, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
)
939 function TGUITextButton
.GetHeight
: Integer;
943 FFont
.GetTextSize(FText
, w
, h
);
947 function TGUITextButton
.GetWidth
: Integer;
951 FFont
.GetTextSize(FText
, w
, h
);
955 procedure TGUITextButton
.OnMessage(var Msg
: TMessage
);
957 if not FEnabled
then Exit
;
964 IK_RETURN
, IK_KPRETURN
: Click();
969 procedure TGUITextButton
.Update
;
976 constructor TFont
.Create(FontID
: DWORD
; FontType
: TFontType
);
981 FFontType
:= FontType
;
984 destructor TFont
.Destroy
;
990 procedure TFont
.Draw(X
, Y
: Integer; Text: string; R
, G
, B
: Byte);
992 if FFontType
= TFontType
.Character
then e_CharFont_PrintEx(ID
, X
, Y
, Text, _RGB(R
, G
, B
), FScale
)
993 else e_TextureFontPrintEx(X
, Y
, Text, ID
, R
, G
, B
, FScale
);
996 procedure TFont
.GetTextSize(Text: string; var w
, h
: Word);
1000 if FFontType
= TFontType
.Character
then e_CharFont_GetSize(ID
, Text, w
, h
)
1003 e_TextureFontGetSize(ID
, cw
, ch
);
1004 w
:= cw
*Length(Text);
1008 w
:= Round(w
*FScale
);
1009 h
:= Round(h
*FScale
);
1014 function TGUIMainMenu
.AddButton(fProc
: Pointer; Caption
: string; ShowWindow
: string = ''): TGUITextButton
;
1021 SetLength(FButtons
, Length(FButtons
)+1);
1022 FButtons
[High(FButtons
)] := TGUITextButton
.Create(fProc
, FFontID
, Caption
);
1023 FButtons
[High(FButtons
)].ShowWindow
:= ShowWindow
;
1024 with FButtons
[High(FButtons
)] do
1026 if (fProc
<> nil) or (ShowWindow
<> '') then FColor
:= MAINMENU_ITEMS_COLOR
1027 else FColor
:= MAINMENU_UNACTIVEITEMS_COLOR
;
1028 FSound
:= MAINMENU_CLICKSOUND
;
1031 _x
:= gScreenWidth
div 2;
1033 for a
:= 0 to High(FButtons
) do
1034 if FButtons
[a
] <> nil then
1035 _x
:= Min(_x
, (gScreenWidth
div 2)-(FButtons
[a
].GetWidth
div 2));
1037 hh
:= FHeader
.GetHeight
;
1039 h
:= hh
*(2+Length(FButtons
))+MAINMENU_SPACE
*(Length(FButtons
)-1);
1040 h
:= (gScreenHeight
div 2)-(h
div 2);
1050 for a
:= 0 to High(FButtons
) do
1052 if FButtons
[a
] <> nil then
1059 Inc(h
, hh
+MAINMENU_SPACE
);
1062 Result
:= FButtons
[High(FButtons
)];
1065 procedure TGUIMainMenu
.AddSpace
;
1067 SetLength(FButtons
, Length(FButtons
)+1);
1068 FButtons
[High(FButtons
)] := nil;
1071 constructor TGUIMainMenu
.Create(FontID
: DWORD
; Header
: string);
1077 FCounter
:= MAINMENU_MARKERDELAY
;
1079 g_Texture_Get(MAINMENU_MARKER1
, FMarkerID1
);
1080 g_Texture_Get(MAINMENU_MARKER2
, FMarkerID2
);
1082 FHeader
:= TGUILabel
.Create(Header
, FFontID
);
1085 FColor
:= MAINMENU_HEADER_COLOR
;
1086 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1087 FY
:= (gScreenHeight
div 2)-(GetHeight
div 2);
1091 destructor TGUIMainMenu
.Destroy
;
1095 if FButtons
<> nil then
1096 for a
:= 0 to High(FButtons
) do
1104 procedure TGUIMainMenu
.Draw
;
1112 if FButtons
<> nil then
1114 for a
:= 0 to High(FButtons
) do
1115 if FButtons
[a
] <> nil then FButtons
[a
].Draw
;
1117 if FIndex
<> -1 then
1118 e_Draw(FMarkerID1
, FButtons
[FIndex
].FX
-48, FButtons
[FIndex
].FY
, 0, True, False);
1122 procedure TGUIMainMenu
.EnableButton(aName
: string; e
: Boolean);
1126 if FButtons
= nil then Exit
;
1128 for a
:= 0 to High(FButtons
) do
1129 if (FButtons
[a
] <> nil) and (FButtons
[a
].Name
= aName
) then
1131 if e
then FButtons
[a
].FColor
:= MAINMENU_ITEMS_COLOR
1132 else FButtons
[a
].FColor
:= MAINMENU_UNACTIVEITEMS_COLOR
;
1133 FButtons
[a
].Enabled
:= e
;
1138 function TGUIMainMenu
.GetButton(aName
: string): TGUITextButton
;
1144 if FButtons
= nil then Exit
;
1146 for a
:= 0 to High(FButtons
) do
1147 if (FButtons
[a
] <> nil) and (FButtons
[a
].Name
= aName
) then
1149 Result
:= FButtons
[a
];
1154 procedure TGUIMainMenu
.OnMessage(var Msg
: TMessage
);
1159 if not FEnabled
then Exit
;
1163 if FButtons
= nil then Exit
;
1166 for a
:= 0 to High(FButtons
) do
1167 if FButtons
[a
] <> nil then
1173 if not ok
then Exit
;
1182 if FIndex
< 0 then FIndex
:= High(FButtons
);
1183 until FButtons
[FIndex
] <> nil;
1185 g_Sound_PlayEx(MENU_CHANGESOUND
);
1191 if FIndex
> High(FButtons
) then FIndex
:= 0;
1192 until FButtons
[FIndex
] <> nil;
1194 g_Sound_PlayEx(MENU_CHANGESOUND
);
1196 IK_RETURN
, IK_KPRETURN
: if (FIndex
<> -1) and FButtons
[FIndex
].FEnabled
then FButtons
[FIndex
].Click
;
1201 procedure TGUIMainMenu
.Update
;
1207 if FCounter
= 0 then
1210 FMarkerID1
:= FMarkerID2
;
1213 FCounter
:= MAINMENU_MARKERDELAY
;
1214 end else Dec(FCounter
);
1219 constructor TGUILabel
.Create(Text: string; FontID
: DWORD
);
1223 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
1227 FOnClickEvent
:= nil;
1230 procedure TGUILabel
.Draw
;
1236 FFont
.GetTextSize(FText
, w
, h
);
1237 FFont
.Draw(FX
+FMaxWidth
-w
, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
);
1241 FFont
.Draw(FX
, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
);
1245 function TGUILabel
.GetHeight
: Integer;
1249 FFont
.GetTextSize(FText
, w
, h
);
1253 function TGUILabel
.GetWidth
: Integer;
1257 if FFixedLen
= 0 then
1258 FFont
.GetTextSize(FText
, w
, h
)
1260 w
:= e_CharFont_GetMaxWidth(FFont
.ID
)*FFixedLen
;
1264 procedure TGUILabel
.OnMessage(var Msg
: TMessage
);
1266 if not FEnabled
then Exit
;
1273 IK_RETURN
, IK_KPRETURN
: if @FOnClickEvent
<> nil then FOnClickEvent();
1280 function TGUIMenu
.AddButton(Proc
: Pointer; fText
: string; _ShowWindow
: string = ''): TGUITextButton
;
1287 Control
:= TGUITextButton
.Create(Proc
, FFontID
, fText
);
1288 with Control
as TGUITextButton
do
1290 ShowWindow
:= _ShowWindow
;
1291 FColor
:= MENU_ITEMSCTRL_COLOR
;
1295 ControlType
:= TGUITextButton
;
1297 Result
:= (Control
as TGUITextButton
);
1300 if FIndex
= -1 then FIndex
:= i
;
1305 procedure TGUIMenu
.AddLine(fText
: string);
1312 Text := TGUILabel
.Create(fText
, FFontID
);
1315 FColor
:= MENU_ITEMSTEXT_COLOR
;
1324 procedure TGUIMenu
.AddText(fText
: string; MaxWidth
: Word);
1329 l
:= GetLines(fText
, FFontID
, MaxWidth
);
1331 if l
= nil then Exit
;
1333 for a
:= 0 to High(l
) do
1338 Text := TGUILabel
.Create(l
[a
], FFontID
);
1341 with Text do begin FColor
:= _RGB(255, 0, 0); end;
1345 with Text do begin FColor
:= MENU_ITEMSTEXT_COLOR
; end;
1355 procedure TGUIMenu
.AddSpace
;
1369 constructor TGUIMenu
.Create(HeaderFont
, ItemsFont
: DWORD
; Header
: string);
1375 FFontID
:= ItemsFont
;
1376 FCounter
:= MENU_MARKERDELAY
;
1380 FHeader
:= TGUILabel
.Create(Header
, HeaderFont
);
1383 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1385 FColor
:= MAINMENU_HEADER_COLOR
;
1389 destructor TGUIMenu
.Destroy
;
1393 if FItems
<> nil then
1394 for a
:= 0 to High(FItems
) do
1408 procedure TGUIMenu
.Draw
;
1410 a
, locx
, locy
: Integer;
1414 if FHeader
<> nil then FHeader
.Draw
;
1416 if FItems
<> nil then
1417 for a
:= 0 to High(FItems
) do
1419 if FItems
[a
].Text <> nil then FItems
[a
].Text.Draw
;
1420 if FItems
[a
].Control
<> nil then FItems
[a
].Control
.Draw
;
1423 if (FIndex
<> -1) and (FCounter
> MENU_MARKERDELAY
div 2) then
1428 if FItems
[FIndex
].Text <> nil then
1430 locx
:= FItems
[FIndex
].Text.FX
;
1431 locy
:= FItems
[FIndex
].Text.FY
;
1433 if FItems
[FIndex
].Text.RightAlign
then
1435 locx
:= locx
+FItems
[FIndex
].Text.FMaxWidth
-FItems
[FIndex
].Text.GetWidth
;
1438 else if FItems
[FIndex
].Control
<> nil then
1440 locx
:= FItems
[FIndex
].Control
.FX
;
1441 locy
:= FItems
[FIndex
].Control
.FY
;
1444 locx
:= locx
-e_CharFont_GetMaxWidth(FFontID
);
1446 e_CharFont_PrintEx(FFontID
, locx
, locy
, #16, _RGB(255, 0, 0));
1450 function TGUIMenu
.GetControl(aName
: String): TGUIControl
;
1456 if FItems
<> nil then
1457 for a
:= 0 to High(FItems
) do
1458 if FItems
[a
].Control
<> nil then
1459 if LowerCase(FItems
[a
].Control
.Name
) = LowerCase(aName
) then
1461 Result
:= FItems
[a
].Control
;
1465 Assert(Result
<> nil, 'GUI control "'+aName
+'" not found!');
1468 function TGUIMenu
.GetControlsText(aName
: String): TGUILabel
;
1474 if FItems
<> nil then
1475 for a
:= 0 to High(FItems
) do
1476 if FItems
[a
].Control
<> nil then
1477 if LowerCase(FItems
[a
].Control
.Name
) = LowerCase(aName
) then
1479 Result
:= FItems
[a
].Text;
1483 Assert(Result
<> nil, 'GUI control''s text "'+aName
+'" not found!');
1486 function TGUIMenu
.NewItem
: Integer;
1488 SetLength(FItems
, Length(FItems
)+1);
1489 Result
:= High(FItems
);
1492 procedure TGUIMenu
.OnMessage(var Msg
: TMessage
);
1497 if not FEnabled
then Exit
;
1501 if FItems
= nil then Exit
;
1504 for a
:= 0 to High(FItems
) do
1505 if FItems
[a
].Control
<> nil then
1511 if not ok
then Exit
;
1513 if (Msg
.Msg
= WM_KEYDOWN
) and (FIndex
<> -1) and (FItems
[FIndex
].Control
<> nil) and
1514 (FItems
[FIndex
].Control
.WantActivationKey(Msg
.wParam
)) then
1516 FItems
[FIndex
].Control
.OnMessage(Msg
);
1517 g_Sound_PlayEx(MENU_CLICKSOUND
);
1530 if c
> Length(FItems
) then
1537 if FIndex
< 0 then FIndex
:= High(FItems
);
1538 until (FItems
[FIndex
].Control
<> nil) and
1539 (FItems
[FIndex
].Control
.Enabled
);
1543 g_Sound_PlayEx(MENU_CHANGESOUND
);
1551 if c
> Length(FItems
) then
1558 if FIndex
> High(FItems
) then FIndex
:= 0;
1559 until (FItems
[FIndex
].Control
<> nil) and
1560 (FItems
[FIndex
].Control
.Enabled
);
1564 g_Sound_PlayEx(MENU_CHANGESOUND
);
1567 IK_LEFT
, IK_RIGHT
, IK_KPLEFT
, IK_KPRIGHT
:
1569 if FIndex
<> -1 then
1570 if FItems
[FIndex
].Control
<> nil then
1571 FItems
[FIndex
].Control
.OnMessage(Msg
);
1573 IK_RETURN
, IK_KPRETURN
:
1575 if FIndex
<> -1 then
1577 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1579 g_Sound_PlayEx(MENU_CLICKSOUND
);
1583 if FYesNo
and (length(FItems
) > 1) then
1585 Msg
.wParam
:= IK_RETURN
; // to register keypress
1586 FIndex
:= High(FItems
)-1;
1587 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1590 if FYesNo
and (length(FItems
) > 1) then
1592 Msg
.wParam
:= IK_RETURN
; // to register keypress
1593 FIndex
:= High(FItems
);
1594 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1601 procedure TGUIMenu
.ReAlign();
1603 a
, tx
, cx
, w
, h
: Integer;
1604 cww
: array of Integer; // cached widths
1607 if FItems
= nil then Exit
;
1609 SetLength(cww
, length(FItems
));
1611 for a
:= 0 to High(FItems
) do
1613 if FItems
[a
].Text <> nil then
1615 cww
[a
] := FItems
[a
].Text.GetWidth
;
1616 if maxcww
< cww
[a
] then maxcww
:= cww
[a
];
1627 for a
:= 0 to High(FItems
) do
1630 if FItems
[a
].Text <> nil then w
:= FItems
[a
].Text.GetWidth
;
1631 if FItems
[a
].Control
<> nil then
1634 if FItems
[a
].ControlType
= TGUILabel
then w
:= w
+(FItems
[a
].Control
as TGUILabel
).GetWidth
1635 else if FItems
[a
].ControlType
= TGUITextButton
then w
:= w
+(FItems
[a
].Control
as TGUITextButton
).GetWidth
1636 else if FItems
[a
].ControlType
= TGUIScroll
then w
:= w
+(FItems
[a
].Control
as TGUIScroll
).GetWidth
1637 else if FItems
[a
].ControlType
= TGUISwitch
then w
:= w
+(FItems
[a
].Control
as TGUISwitch
).GetWidth
1638 else if FItems
[a
].ControlType
= TGUIEdit
then w
:= w
+(FItems
[a
].Control
as TGUIEdit
).GetWidth
1639 else if FItems
[a
].ControlType
= TGUIKeyRead
then w
:= w
+(FItems
[a
].Control
as TGUIKeyRead
).GetWidth
1640 else if FItems
[a
].ControlType
= TGUIKeyRead2
then w
:= w
+(FItems
[a
].Control
as TGUIKeyRead2
).GetWidth
1641 else if FItems
[a
].ControlType
= TGUIListBox
then w
:= w
+(FItems
[a
].Control
as TGUIListBox
).GetWidth
1642 else if FItems
[a
].ControlType
= TGUIFileListBox
then w
:= w
+(FItems
[a
].Control
as TGUIFileListBox
).GetWidth
1643 else if FItems
[a
].ControlType
= TGUIMemo
then w
:= w
+(FItems
[a
].Control
as TGUIMemo
).GetWidth
;
1645 tx
:= Min(tx
, (gScreenWidth
div 2)-(w
div 2));
1650 for a
:= 0 to High(FItems
) do
1654 if (Text <> nil) and (Control
= nil) then Continue
;
1656 if Text <> nil then w
:= tx
+Text.GetWidth
;
1657 if w
> cx
then cx
:= w
;
1661 cx
:= cx
+MENU_HSPACE
;
1663 h
:= FHeader
.GetHeight
*2+MENU_VSPACE
*(Length(FItems
)-1);
1665 for a
:= 0 to High(FItems
) do
1669 if (ControlType
= TGUIListBox
) or (ControlType
= TGUIFileListBox
) then
1670 h
:= h
+(FItems
[a
].Control
as TGUIListBox
).GetHeight()
1672 h
:= h
+e_CharFont_GetMaxHeight(FFontID
);
1676 h
:= (gScreenHeight
div 2)-(h
div 2);
1680 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1683 Inc(h
, GetHeight
*2);
1686 for a
:= 0 to High(FItems
) do
1698 if Text.RightAlign
and (length(cww
) > a
) then
1700 //Text.FX := Text.FX+maxcww;
1701 Text.FMaxWidth
:= maxcww
;
1705 if Control
<> nil then
1722 if (ControlType
= TGUIListBox
) or (ControlType
= TGUIFileListBox
) then Inc(h
, (Control
as TGUIListBox
).GetHeight
+MENU_VSPACE
)
1723 else if ControlType
= TGUIMemo
then Inc(h
, (Control
as TGUIMemo
).GetHeight
+MENU_VSPACE
)
1724 else Inc(h
, e_CharFont_GetMaxHeight(FFontID
)+MENU_VSPACE
);
1728 // another ugly hack
1729 if FYesNo
and (length(FItems
) > 1) then
1732 for a
:= High(FItems
)-1 to High(FItems
) do
1734 if (FItems
[a
].Control
<> nil) and (FItems
[a
].ControlType
= TGUITextButton
) then
1736 cx
:= (FItems
[a
].Control
as TGUITextButton
).GetWidth
;
1737 if cx
> w
then w
:= cx
;
1742 for a
:= High(FItems
)-1 to High(FItems
) do
1744 if (FItems
[a
].Control
<> nil) and (FItems
[a
].ControlType
= TGUITextButton
) then
1746 FItems
[a
].Control
.FX
:= (gScreenWidth
-w
) div 2;
1753 function TGUIMenu
.AddScroll(fText
: string): TGUIScroll
;
1760 Control
:= TGUIScroll
.Create();
1762 Text := TGUILabel
.Create(fText
, FFontID
);
1765 FColor
:= MENU_ITEMSTEXT_COLOR
;
1768 ControlType
:= TGUIScroll
;
1770 Result
:= (Control
as TGUIScroll
);
1773 if FIndex
= -1 then FIndex
:= i
;
1778 function TGUIMenu
.AddSwitch(fText
: string): TGUISwitch
;
1785 Control
:= TGUISwitch
.Create(FFontID
);
1786 (Control
as TGUISwitch
).FColor
:= MENU_ITEMSCTRL_COLOR
;
1788 Text := TGUILabel
.Create(fText
, FFontID
);
1791 FColor
:= MENU_ITEMSTEXT_COLOR
;
1794 ControlType
:= TGUISwitch
;
1796 Result
:= (Control
as TGUISwitch
);
1799 if FIndex
= -1 then FIndex
:= i
;
1804 function TGUIMenu
.AddEdit(fText
: string): TGUIEdit
;
1811 Control
:= TGUIEdit
.Create(FFontID
);
1812 with Control
as TGUIEdit
do
1814 FWindow
:= Self
.FWindow
;
1815 FColor
:= MENU_ITEMSCTRL_COLOR
;
1818 if fText
= '' then Text := nil else
1820 Text := TGUILabel
.Create(fText
, FFontID
);
1821 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
1824 ControlType
:= TGUIEdit
;
1826 Result
:= (Control
as TGUIEdit
);
1829 if FIndex
= -1 then FIndex
:= i
;
1834 procedure TGUIMenu
.Update
;
1840 if FCounter
= 0 then FCounter
:= MENU_MARKERDELAY
else Dec(FCounter
);
1842 if FItems
<> nil then
1843 for a
:= 0 to High(FItems
) do
1844 if FItems
[a
].Control
<> nil then
1845 (FItems
[a
].Control
as FItems
[a
].ControlType
).Update
;
1848 function TGUIMenu
.AddKeyRead(fText
: string): TGUIKeyRead
;
1855 Control
:= TGUIKeyRead
.Create(FFontID
);
1856 with Control
as TGUIKeyRead
do
1858 FWindow
:= Self
.FWindow
;
1859 FColor
:= MENU_ITEMSCTRL_COLOR
;
1862 Text := TGUILabel
.Create(fText
, FFontID
);
1865 FColor
:= MENU_ITEMSTEXT_COLOR
;
1868 ControlType
:= TGUIKeyRead
;
1870 Result
:= (Control
as TGUIKeyRead
);
1873 if FIndex
= -1 then FIndex
:= i
;
1878 function TGUIMenu
.AddKeyRead2(fText
: string): TGUIKeyRead2
;
1885 Control
:= TGUIKeyRead2
.Create(FFontID
);
1886 with Control
as TGUIKeyRead2
do
1888 FWindow
:= Self
.FWindow
;
1889 FColor
:= MENU_ITEMSCTRL_COLOR
;
1892 Text := TGUILabel
.Create(fText
, FFontID
);
1895 FColor
:= MENU_ITEMSCTRL_COLOR
; //MENU_ITEMSTEXT_COLOR;
1899 ControlType
:= TGUIKeyRead2
;
1901 Result
:= (Control
as TGUIKeyRead2
);
1904 if FIndex
= -1 then FIndex
:= i
;
1909 function TGUIMenu
.AddList(fText
: string; Width
, Height
: Word): TGUIListBox
;
1916 Control
:= TGUIListBox
.Create(FFontID
, Width
, Height
);
1917 with Control
as TGUIListBox
do
1919 FWindow
:= Self
.FWindow
;
1920 FActiveColor
:= MENU_ITEMSCTRL_COLOR
;
1921 FUnActiveColor
:= MENU_ITEMSTEXT_COLOR
;
1924 Text := TGUILabel
.Create(fText
, FFontID
);
1927 FColor
:= MENU_ITEMSTEXT_COLOR
;
1930 ControlType
:= TGUIListBox
;
1932 Result
:= (Control
as TGUIListBox
);
1935 if FIndex
= -1 then FIndex
:= i
;
1940 function TGUIMenu
.AddFileList(fText
: string; Width
, Height
: Word): TGUIFileListBox
;
1947 Control
:= TGUIFileListBox
.Create(FFontID
, Width
, Height
);
1948 with Control
as TGUIFileListBox
do
1950 FWindow
:= Self
.FWindow
;
1951 FActiveColor
:= MENU_ITEMSCTRL_COLOR
;
1952 FUnActiveColor
:= MENU_ITEMSTEXT_COLOR
;
1955 if fText
= '' then Text := nil else
1957 Text := TGUILabel
.Create(fText
, FFontID
);
1958 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
1961 ControlType
:= TGUIFileListBox
;
1963 Result
:= (Control
as TGUIFileListBox
);
1966 if FIndex
= -1 then FIndex
:= i
;
1971 function TGUIMenu
.AddLabel(fText
: string): TGUILabel
;
1978 Control
:= TGUILabel
.Create('', FFontID
);
1979 with Control
as TGUILabel
do
1981 FWindow
:= Self
.FWindow
;
1982 FColor
:= MENU_ITEMSCTRL_COLOR
;
1985 Text := TGUILabel
.Create(fText
, FFontID
);
1988 FColor
:= MENU_ITEMSTEXT_COLOR
;
1991 ControlType
:= TGUILabel
;
1993 Result
:= (Control
as TGUILabel
);
1996 if FIndex
= -1 then FIndex
:= i
;
2001 function TGUIMenu
.AddMemo(fText
: string; Width
, Height
: Word): TGUIMemo
;
2008 Control
:= TGUIMemo
.Create(FFontID
, Width
, Height
);
2009 with Control
as TGUIMemo
do
2011 FWindow
:= Self
.FWindow
;
2012 FColor
:= MENU_ITEMSTEXT_COLOR
;
2015 if fText
= '' then Text := nil else
2017 Text := TGUILabel
.Create(fText
, FFontID
);
2018 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
2021 ControlType
:= TGUIMemo
;
2023 Result
:= (Control
as TGUIMemo
);
2026 if FIndex
= -1 then FIndex
:= i
;
2031 procedure TGUIMenu
.UpdateIndex();
2039 if (FIndex
< 0) or (FIndex
> High(FItems
)) then
2045 if FItems
[FIndex
].Control
.Enabled
then
2054 constructor TGUIScroll
.Create
;
2059 FOnChangeEvent
:= nil;
2061 g_Texture_Get(SCROLL_LEFT
, FLeftID
);
2062 g_Texture_Get(SCROLL_RIGHT
, FRightID
);
2063 g_Texture_Get(SCROLL_MIDDLE
, FMiddleID
);
2064 g_Texture_Get(SCROLL_MARKER
, FMarkerID
);
2067 procedure TGUIScroll
.Draw
;
2073 e_Draw(FLeftID
, FX
, FY
, 0, True, False);
2074 e_Draw(FRightID
, FX
+8+(FMax
+1)*8, FY
, 0, True, False);
2076 for a
:= 0 to FMax
do
2077 e_Draw(FMiddleID
, FX
+8+a
*8, FY
, 0, True, False);
2079 e_Draw(FMarkerID
, FX
+8+FValue
*8, FY
, 0, True, False);
2082 procedure TGUIScroll
.FSetValue(a
: Integer);
2084 if a
> FMax
then FValue
:= FMax
else FValue
:= a
;
2087 function TGUIScroll
.GetWidth
: Integer;
2089 Result
:= 16+(FMax
+1)*8;
2092 procedure TGUIScroll
.OnMessage(var Msg
: TMessage
);
2094 if not FEnabled
then Exit
;
2106 g_Sound_PlayEx(SCROLL_SUBSOUND
);
2107 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2109 IK_RIGHT
, IK_KPRIGHT
:
2110 if FValue
< FMax
then
2113 g_Sound_PlayEx(SCROLL_ADDSOUND
);
2114 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2121 procedure TGUIScroll
.Update
;
2129 procedure TGUISwitch
.AddItem(Item
: string);
2131 SetLength(FItems
, Length(FItems
)+1);
2132 FItems
[High(FItems
)] := Item
;
2134 if FIndex
= -1 then FIndex
:= 0;
2137 constructor TGUISwitch
.Create(FontID
: DWORD
);
2143 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2146 procedure TGUISwitch
.Draw
;
2150 FFont
.Draw(FX
, FY
, FItems
[FIndex
], FColor
.R
, FColor
.G
, FColor
.B
);
2153 function TGUISwitch
.GetText
: string;
2155 if FIndex
<> -1 then Result
:= FItems
[FIndex
]
2159 function TGUISwitch
.GetWidth
: Integer;
2166 if FItems
= nil then Exit
;
2168 for a
:= 0 to High(FItems
) do
2170 FFont
.GetTextSize(FItems
[a
], w
, h
);
2171 if w
> Result
then Result
:= w
;
2175 procedure TGUISwitch
.OnMessage(var Msg
: TMessage
);
2177 if not FEnabled
then Exit
;
2181 if FItems
= nil then Exit
;
2186 IK_RETURN
, IK_RIGHT
, IK_KPRETURN
, IK_KPRIGHT
:
2188 if FIndex
< High(FItems
) then
2193 if @FOnChangeEvent
<> nil then
2194 FOnChangeEvent(Self
);
2202 FIndex
:= High(FItems
);
2204 if @FOnChangeEvent
<> nil then
2205 FOnChangeEvent(Self
);
2211 procedure TGUISwitch
.Update
;
2219 constructor TGUIEdit
.Create(FontID
: DWORD
);
2223 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2229 g_Texture_Get(EDIT_LEFT
, FLeftID
);
2230 g_Texture_Get(EDIT_RIGHT
, FRightID
);
2231 g_Texture_Get(EDIT_MIDDLE
, FMiddleID
);
2234 procedure TGUIEdit
.Draw
;
2241 e_Draw(FLeftID
, FX
, FY
, 0, True, False);
2242 e_Draw(FRightID
, FX
+8+FWidth
*16, FY
, 0, True, False);
2244 for c
:= 0 to FWidth
-1 do
2245 e_Draw(FMiddleID
, FX
+8+c
*16, FY
, 0, True, False);
2250 if FInvalid
and (FWindow
.FActiveControl
<> self
) then begin r
:= 128; g
:= 128; b
:= 128; end;
2251 FFont
.Draw(FX
+8, FY
, FText
, r
, g
, b
);
2253 if (FWindow
.FActiveControl
= self
) then
2255 FFont
.GetTextSize(Copy(FText
, 1, FCaretPos
), w
, h
);
2256 h
:= e_CharFont_GetMaxHeight(FFont
.ID
);
2257 e_DrawLine(2, FX
+8+w
, FY
+h
-3, FX
+8+w
+EDIT_CURSORLEN
, FY
+h
-3,
2258 EDIT_CURSORCOLOR
.R
, EDIT_CURSORCOLOR
.G
, EDIT_CURSORCOLOR
.B
);
2262 function TGUIEdit
.GetWidth
: Integer;
2264 Result
:= 16+FWidth
*16;
2267 procedure TGUIEdit
.OnMessage(var Msg
: TMessage
);
2269 if not FEnabled
then Exit
;
2278 if (wParam
in [48..57]) and (Chr(wParam
) <> '`') then
2279 if Length(Text) < FMaxLength
then
2281 Insert(Chr(wParam
), FText
, FCaretPos
+ 1);
2287 if (wParam
in [32..255]) and (Chr(wParam
) <> '`') then
2288 if Length(Text) < FMaxLength
then
2290 Insert(Chr(wParam
), FText
, FCaretPos
+ 1);
2298 Delete(FText
, FCaretPos
, 1);
2299 if FCaretPos
> 0 then Dec(FCaretPos
);
2301 IK_DELETE
: Delete(FText
, FCaretPos
+ 1, 1);
2302 IK_END
, IK_KPEND
: FCaretPos
:= Length(FText
);
2303 IK_HOME
, IK_KPHOME
: FCaretPos
:= 0;
2304 IK_LEFT
, IK_KPLEFT
: if FCaretPos
> 0 then Dec(FCaretPos
);
2305 IK_RIGHT
, IK_KPRIGHT
: if FCaretPos
< Length(FText
) then Inc(FCaretPos
);
2306 IK_RETURN
, IK_KPRETURN
:
2309 if FActiveControl
<> Self
then
2312 if @FOnEnterEvent
<> nil then FOnEnterEvent(Self
);
2316 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
2317 else SetActive(nil);
2318 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2325 procedure TGUIEdit
.SetText(Text: string);
2327 if Length(Text) > FMaxLength
then SetLength(Text, FMaxLength
);
2329 FCaretPos
:= Length(FText
);
2332 procedure TGUIEdit
.Update
;
2339 constructor TGUIKeyRead
.Create(FontID
: DWORD
);
2345 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2348 procedure TGUIKeyRead
.Draw
;
2352 FFont
.Draw(FX
, FY
, IfThen(FIsQuery
, KEYREAD_QUERY
, IfThen(FKey
<> 0, e_KeyNames
[FKey
], KEYREAD_CLEAR
)),
2353 FColor
.R
, FColor
.G
, FColor
.B
);
2356 function TGUIKeyRead
.GetWidth
: Integer;
2363 for a
:= 0 to 255 do
2365 FFont
.GetTextSize(e_KeyNames
[a
], w
, h
);
2366 Result
:= Max(Result
, w
);
2369 FFont
.GetTextSize(KEYREAD_QUERY
, w
, h
);
2370 if w
> Result
then Result
:= w
;
2372 FFont
.GetTextSize(KEYREAD_CLEAR
, w
, h
);
2373 if w
> Result
then Result
:= w
;
2376 function TGUIKeyRead
.WantActivationKey (key
: LongInt): Boolean;
2379 (key
= IK_BACKSPACE
) or
2383 procedure TGUIKeyRead
.OnMessage(var Msg
: TMessage
);
2384 procedure actDefCtl ();
2387 if FDefControl
<> '' then
2388 SetActive(GetControl(FDefControl
))
2396 if not FEnabled
then
2405 if FIsQuery
then actDefCtl();
2408 IK_RETURN
, IK_KPRETURN
:
2410 if not FIsQuery
then
2413 if FActiveControl
<> Self
then
2420 FKey
:= IK_ENTER
; // <Enter>
2425 IK_BACKSPACE
: // clear keybinding if we aren't waiting for a key
2427 if not FIsQuery
then
2437 if not FIsQuery
and (wParam
= IK_BACKSPACE
) then
2442 else if FIsQuery
and (wParam
<> IK_ENTER
) and (wParam
<> IK_KPRETURN
) then // Not <Enter
2444 if e_KeyNames
[wParam
] <> '' then
2455 constructor TGUIKeyRead2
.Create(FontID
: DWORD
);
2468 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2470 FMaxKeyNameWdt
:= 0;
2471 for a
:= 0 to 255 do
2473 FFont
.GetTextSize(e_KeyNames
[a
], w
, h
);
2474 FMaxKeyNameWdt
:= Max(FMaxKeyNameWdt
, w
);
2477 FMaxKeyNameWdt
:= FMaxKeyNameWdt
-(FMaxKeyNameWdt
div 3);
2479 FFont
.GetTextSize(KEYREAD_QUERY
, w
, h
);
2480 if w
> FMaxKeyNameWdt
then FMaxKeyNameWdt
:= w
;
2482 FFont
.GetTextSize(KEYREAD_CLEAR
, w
, h
);
2483 if w
> FMaxKeyNameWdt
then FMaxKeyNameWdt
:= w
;
2486 procedure TGUIKeyRead2
.Draw
;
2487 procedure drawText (idx
: Integer);
2493 if idx
= 0 then kk
:= FKey0
else kk
:= FKey1
;
2495 if idx
= 0 then x
:= FX
+8 else x
:= FX
+8+FMaxKeyNameWdt
+16;
2499 if FKeyIdx
= idx
then begin r
:= 255; g
:= 255; b
:= 255; end;
2500 if FIsQuery
and (FKeyIdx
= idx
) then
2501 FFont
.Draw(x
, y
, KEYREAD_QUERY
, r
, g
, b
)
2503 FFont
.Draw(x
, y
, IfThen(kk
<> 0, e_KeyNames
[kk
], KEYREAD_CLEAR
), r
, g
, b
);
2509 //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);
2510 //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);
2515 function TGUIKeyRead2
.GetWidth
: Integer;
2517 Result
:= FMaxKeyNameWdt
*2+8+8+16;
2520 function TGUIKeyRead2
.WantActivationKey (key
: LongInt): Boolean;
2523 (key
= IK_BACKSPACE
) or
2524 (key
= IK_LEFT
) or (key
= IK_RIGHT
) or
2525 (key
= IK_KPLEFT
) or (key
= IK_KPRIGHT
) or
2529 procedure TGUIKeyRead2
.OnMessage(var Msg
: TMessage
);
2530 procedure actDefCtl ();
2533 if FDefControl
<> '' then
2534 SetActive(GetControl(FDefControl
))
2542 if not FEnabled
then
2551 if FIsQuery
then actDefCtl();
2554 IK_RETURN
, IK_KPRETURN
:
2556 if not FIsQuery
then
2559 if FActiveControl
<> Self
then
2566 if (FKeyIdx
= 0) then FKey0
:= IK_ENTER
else FKey1
:= IK_ENTER
; // <Enter>
2571 IK_BACKSPACE
: // clear keybinding if we aren't waiting for a key
2573 if not FIsQuery
then
2575 if (FKeyIdx
= 0) then FKey0
:= 0 else FKey1
:= 0;
2580 if not FIsQuery
then
2585 IK_RIGHT
, IK_KPRIGHT
:
2586 if not FIsQuery
then
2595 if not FIsQuery
and (wParam
= IK_BACKSPACE
) then
2597 if (FKeyIdx
= 0) then FKey0
:= 0 else FKey1
:= 0;
2600 else if FIsQuery
and (wParam
<> IK_ENTER
) and (wParam
<> IK_KPRETURN
) then // Not <Enter
2602 if e_KeyNames
[wParam
] <> '' then
2604 if (FKeyIdx
= 0) then FKey0
:= wParam
else FKey1
:= wParam
;
2616 constructor TGUIModelView
.Create
;
2623 destructor TGUIModelView
.Destroy
;
2630 procedure TGUIModelView
.Draw
;
2634 DrawBox(FX
, FY
, 4, 4);
2636 if FModel
<> nil then FModel
.Draw(FX
+4, FY
+4);
2639 procedure TGUIModelView
.NextAnim();
2641 if FModel
= nil then
2644 if FModel
.Animation
< A_PAIN
then
2645 FModel
.ChangeAnimation(FModel
.Animation
+1, True)
2647 FModel
.ChangeAnimation(A_STAND
, True);
2650 procedure TGUIModelView
.NextWeapon();
2652 if FModel
= nil then
2655 if FModel
.Weapon
< WP_LAST
then
2656 FModel
.SetWeapon(FModel
.Weapon
+1)
2658 FModel
.SetWeapon(WEAPON_KASTET
);
2661 procedure TGUIModelView
.OnMessage(var Msg
: TMessage
);
2667 procedure TGUIModelView
.SetColor(Red
, Green
, Blue
: Byte);
2669 if FModel
<> nil then FModel
.SetColor(Red
, Green
, Blue
);
2672 procedure TGUIModelView
.SetModel(ModelName
: string);
2676 FModel
:= g_PlayerModel_Get(ModelName
);
2679 procedure TGUIModelView
.Update
;
2686 if FModel
<> nil then FModel
.Update
;
2691 constructor TGUIMapPreview
.Create();
2697 destructor TGUIMapPreview
.Destroy();
2703 procedure TGUIMapPreview
.Draw();
2710 DrawBox(FX
, FY
, MAPPREVIEW_WIDTH
, MAPPREVIEW_HEIGHT
);
2712 if (FMapSize
.X
<= 0) or (FMapSize
.Y
<= 0) then
2715 e_DrawFillQuad(FX
+4, FY
+4,
2716 FX
+4 + Trunc(FMapSize
.X
/ FScale
) - 1,
2717 FY
+4 + Trunc(FMapSize
.Y
/ FScale
) - 1,
2720 if FMapData
<> nil then
2721 for a
:= 0 to High(FMapData
) do
2724 if X1
> MAPPREVIEW_WIDTH
*16 then Continue
;
2725 if Y1
> MAPPREVIEW_HEIGHT
*16 then Continue
;
2727 if X2
< 0 then Continue
;
2728 if Y2
< 0 then Continue
;
2730 if X2
> MAPPREVIEW_WIDTH
*16 then X2
:= MAPPREVIEW_WIDTH
*16;
2731 if Y2
> MAPPREVIEW_HEIGHT
*16 then Y2
:= MAPPREVIEW_HEIGHT
*16;
2733 if X1
< 0 then X1
:= 0;
2734 if Y1
< 0 then Y1
:= 0;
2775 if ((X2
-X1
) > 0) and ((Y2
-Y1
) > 0) then
2776 e_DrawFillQuad(FX
+4 + X1
, FY
+4 + Y1
,
2777 FX
+4 + X2
- 1, FY
+4 + Y2
- 1, r
, g
, b
, 0);
2781 procedure TGUIMapPreview
.OnMessage(var Msg
: TMessage
);
2787 procedure TGUIMapPreview
.SetMap(Res
: string);
2792 //header: TMapHeaderRec_1;
2797 map
: TDynRecord
= nil;
2804 FileName
:= g_ExtractWadName(Res
);
2806 WAD
:= TWADFile
.Create();
2807 if not WAD
.ReadFile(FileName
) then
2813 //k8: ignores path again
2814 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
2823 map
:= g_Map_ParseMap(Data
, Len
);
2833 if (map
= nil) then exit
;
2836 panlist
:= map
.field
['panel'];
2837 //header := GetMapHeader(map);
2839 FMapSize
.X
:= map
.Width
div 16;
2840 FMapSize
.Y
:= map
.Height
div 16;
2842 rX
:= Ceil(map
.Width
/ (MAPPREVIEW_WIDTH
*256.0));
2843 rY
:= Ceil(map
.Height
/ (MAPPREVIEW_HEIGHT
*256.0));
2844 FScale
:= max(rX
, rY
);
2848 if (panlist
<> nil) then
2850 for pan
in panlist
do
2852 if (pan
.PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or
2853 PANEL_STEP
or PANEL_WATER
or
2854 PANEL_ACID1
or PANEL_ACID2
)) <> 0 then
2856 SetLength(FMapData
, Length(FMapData
)+1);
2857 with FMapData
[High(FMapData
)] do
2862 X2
:= (pan
.X
+ pan
.Width
) div 16;
2863 Y2
:= (pan
.Y
+ pan
.Height
) div 16;
2865 X1
:= Trunc(X1
/FScale
+ 0.5);
2866 Y1
:= Trunc(Y1
/FScale
+ 0.5);
2867 X2
:= Trunc(X2
/FScale
+ 0.5);
2868 Y2
:= Trunc(Y2
/FScale
+ 0.5);
2870 if (X1
<> X2
) or (Y1
<> Y2
) then
2878 PanelType
:= pan
.PanelType
;
2884 //writeln('freeing map');
2889 procedure TGUIMapPreview
.ClearMap();
2891 SetLength(FMapData
, 0);
2898 procedure TGUIMapPreview
.Update();
2904 function TGUIMapPreview
.GetScaleStr(): String;
2906 if FScale
> 0.0 then
2908 Result
:= FloatToStrF(FScale
*16.0, ffFixed
, 3, 3);
2909 while (Result
[Length(Result
)] = '0') do
2910 Delete(Result
, Length(Result
), 1);
2911 if (Result
[Length(Result
)] = ',') or (Result
[Length(Result
)] = '.') then
2912 Delete(Result
, Length(Result
), 1);
2913 Result
:= '1 : ' + Result
;
2921 procedure TGUIListBox
.AddItem(Item
: string);
2923 SetLength(FItems
, Length(FItems
)+1);
2924 FItems
[High(FItems
)] := Item
;
2926 if FSort
then g_Basic
.Sort(FItems
);
2929 procedure TGUIListBox
.Clear();
2937 constructor TGUIListBox
.Create(FontID
: DWORD
; Width
, Height
: Word);
2941 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2946 FOnChangeEvent
:= nil;
2948 FDrawScroll
:= True;
2951 procedure TGUIListBox
.Draw
;
2959 if FDrawBack
then DrawBox(FX
, FY
, FWidth
+1, FHeight
);
2961 DrawScroll(FX
+4+FWidth
*16, FY
+4, FHeight
, (FStartLine
> 0) and (FItems
<> nil),
2962 (FStartLine
+FHeight
-1 < High(FItems
)) and (FItems
<> nil));
2964 if FItems
<> nil then
2965 for a
:= FStartLine
to Min(High(FItems
), FStartLine
+FHeight
-1) do
2969 FFont
.GetTextSize(s
, w2
, h2
);
2970 while (Length(s
) > 0) and (w2
> FWidth
*16) do
2972 SetLength(s
, Length(s
)-1);
2973 FFont
.GetTextSize(s
, w2
, h2
);
2977 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, s
, FActiveColor
.R
, FActiveColor
.G
, FActiveColor
.B
)
2979 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, s
, FUnActiveColor
.R
, FUnActiveColor
.G
, FUnActiveColor
.B
);
2983 function TGUIListBox
.GetHeight
: Integer;
2985 Result
:= 8+FHeight
*16;
2988 function TGUIListBox
.GetWidth
: Integer;
2990 Result
:= 8+(FWidth
+1)*16;
2993 procedure TGUIListBox
.OnMessage(var Msg
: TMessage
);
2997 if not FEnabled
then Exit
;
3001 if FItems
= nil then Exit
;
3014 FIndex
:= High(FItems
);
3015 FStartLine
:= Max(High(FItems
)-FHeight
+1, 0);
3017 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
:
3021 if FIndex
< FStartLine
then Dec(FStartLine
);
3022 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
3024 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
:
3025 if FIndex
< High(FItems
) then
3028 if FIndex
> FStartLine
+FHeight
-1 then Inc(FStartLine
);
3029 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
3031 IK_RETURN
, IK_KPRETURN
:
3034 if FActiveControl
<> Self
then SetActive(Self
)
3036 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
3037 else SetActive(nil);
3041 for a
:= 0 to High(FItems
) do
3042 if (Length(FItems
[a
]) > 0) and (LowerCase(FItems
[a
][1]) = LowerCase(Chr(wParam
))) then
3045 FStartLine
:= Min(Max(FIndex
-1, 0), Length(FItems
)-FHeight
);
3046 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
3052 function TGUIListBox
.SelectedItem(): String;
3056 if (FIndex
< 0) or (FItems
= nil) or
3057 (FIndex
> High(FItems
)) then
3060 Result
:= FItems
[FIndex
];
3063 procedure TGUIListBox
.FSetItems(Items
: SSArray
);
3065 if FItems
<> nil then
3073 if FSort
then g_Basic
.Sort(FItems
);
3076 procedure TGUIListBox
.SelectItem(Item
: String);
3080 if FItems
= nil then
3084 Item
:= LowerCase(Item
);
3086 for a
:= 0 to High(FItems
) do
3087 if LowerCase(FItems
[a
]) = Item
then
3093 if FIndex
< FHeight
then
3096 FStartLine
:= Min(FIndex
, Length(FItems
)-FHeight
);
3099 procedure TGUIListBox
.FSetIndex(aIndex
: Integer);
3101 if FItems
= nil then
3104 if (aIndex
< 0) or (aIndex
> High(FItems
)) then
3109 if FIndex
<= FHeight
then
3112 FStartLine
:= Min(FIndex
, Length(FItems
)-FHeight
);
3117 procedure TGUIFileListBox
.OnMessage(var Msg
: TMessage
);
3121 if not FEnabled
then
3124 if FItems
= nil then
3135 if @FOnChangeEvent
<> nil then
3136 FOnChangeEvent(Self
);
3141 FIndex
:= High(FItems
);
3142 FStartLine
:= Max(High(FItems
)-FHeight
+1, 0);
3143 if @FOnChangeEvent
<> nil then
3144 FOnChangeEvent(Self
);
3147 IK_PAGEUP
, IK_KPPAGEUP
:
3149 if FIndex
> FHeight
then
3150 FIndex
:= FIndex
-FHeight
3154 if FStartLine
> FHeight
then
3155 FStartLine
:= FStartLine
-FHeight
3160 IK_PAGEDN
, IK_KPPAGEDN
:
3162 if FIndex
< High(FItems
)-FHeight
then
3163 FIndex
:= FIndex
+FHeight
3165 FIndex
:= High(FItems
);
3167 if FStartLine
< High(FItems
)-FHeight
then
3168 FStartLine
:= FStartLine
+FHeight
3170 FStartLine
:= High(FItems
)-FHeight
+1;
3173 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
:
3177 if FIndex
< FStartLine
then
3179 if @FOnChangeEvent
<> nil then
3180 FOnChangeEvent(Self
);
3183 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
:
3184 if FIndex
< High(FItems
) then
3187 if FIndex
> FStartLine
+FHeight
-1 then
3189 if @FOnChangeEvent
<> nil then
3190 FOnChangeEvent(Self
);
3193 IK_RETURN
, IK_KPRETURN
:
3196 if FActiveControl
<> Self
then
3200 if FItems
[FIndex
][1] = #29 then // Ïàïêà
3202 OpenDir(FPath
+Copy(FItems
[FIndex
], 2, 255));
3207 if FDefControl
<> '' then
3208 SetActive(GetControl(FDefControl
))
3216 for a
:= 0 to High(FItems
) do
3217 if ( (Length(FItems
[a
]) > 0) and
3218 (LowerCase(FItems
[a
][1]) = LowerCase(Chr(wParam
))) ) or
3219 ( (Length(FItems
[a
]) > 1) and
3220 (FItems
[a
][1] = #29) and // Ïàïêà
3221 (LowerCase(FItems
[a
][2]) = LowerCase(Chr(wParam
))) ) then
3224 FStartLine
:= Min(Max(FIndex
-1, 0), Length(FItems
)-FHeight
);
3225 if @FOnChangeEvent
<> nil then
3226 FOnChangeEvent(Self
);
3232 procedure TGUIFileListBox
.OpenDir(path
: String);
3240 path
:= IncludeTrailingPathDelimiter(path
);
3241 path
:= ExpandFileName(path
);
3246 if FindFirst(path
+'*', faDirectory
, SR
) = 0 then
3248 if not LongBool(SR
.Attr
and faDirectory
) then
3250 if (SR
.Name
= '.') or
3251 ((SR
.Name
= '..') and (path
= ExpandFileName(FBasePath
))) then
3254 AddItem(#1 + SR
.Name
);
3255 until FindNext(SR
) <> 0;
3265 if i
= 0 then i
:= length(sm
)+1;
3266 sc
:= Copy(sm
, 1, i
-1);
3268 if FindFirst(path
+sc
, faAnyFile
, SR
) = 0 then repeat AddItem(SR
.Name
); until FindNext(SR
) <> 0;
3272 for i
:= 0 to High(FItems
) do
3273 if FItems
[i
][1] = #1 then
3274 FItems
[i
][1] := #29;
3279 procedure TGUIFileListBox
.SetBase(path
: String);
3285 function TGUIFileListBox
.SelectedItem(): String;
3289 if (FIndex
= -1) or (FItems
= nil) or
3290 (FIndex
> High(FItems
)) or
3291 (FItems
[FIndex
][1] = '/') or
3292 (FItems
[FIndex
][1] = '\') then
3295 Result
:= FPath
+ FItems
[FIndex
];
3298 procedure TGUIFileListBox
.UpdateFileList();
3302 if (FIndex
= -1) or (FItems
= nil) or
3303 (FIndex
> High(FItems
)) or
3304 (FItems
[FIndex
][1] = '/') or
3305 (FItems
[FIndex
][1] = '\') then
3308 fn
:= FItems
[FIndex
];
3318 procedure TGUIMemo
.Clear
;
3324 constructor TGUIMemo
.Create(FontID
: DWORD
; Width
, Height
: Word);
3328 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
3333 FDrawScroll
:= True;
3336 procedure TGUIMemo
.Draw
;
3342 if FDrawBack
then DrawBox(FX
, FY
, FWidth
+1, FHeight
);
3344 DrawScroll(FX
+4+FWidth
*16, FY
+4, FHeight
, (FStartLine
> 0) and (FLines
<> nil),
3345 (FStartLine
+FHeight
-1 < High(FLines
)) and (FLines
<> nil));
3347 if FLines
<> nil then
3348 for a
:= FStartLine
to Min(High(FLines
), FStartLine
+FHeight
-1) do
3349 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, FLines
[a
], FColor
.R
, FColor
.G
, FColor
.B
);
3352 function TGUIMemo
.GetHeight
: Integer;
3354 Result
:= 8+FHeight
*16;
3357 function TGUIMemo
.GetWidth
: Integer;
3359 Result
:= 8+(FWidth
+1)*16;
3362 procedure TGUIMemo
.OnMessage(var Msg
: TMessage
);
3364 if not FEnabled
then Exit
;
3368 if FLines
= nil then Exit
;
3374 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
:
3375 if FStartLine
> 0 then
3377 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
:
3378 if FStartLine
< Length(FLines
)-FHeight
then
3380 IK_RETURN
, IK_KPRETURN
:
3383 if FActiveControl
<> Self
then
3389 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
3390 else SetActive(nil);
3396 procedure TGUIMemo
.SetText(Text: string);
3399 FLines
:= GetLines(Text, FFont
.ID
, FWidth
*16);
3404 procedure TGUIimage
.ClearImage();
3406 if FImageRes
= '' then Exit
;
3408 g_Texture_Delete(FImageRes
);
3412 constructor TGUIimage
.Create();
3419 destructor TGUIimage
.Destroy();
3424 procedure TGUIimage
.Draw();
3430 if FImageRes
= '' then
3432 if g_Texture_Get(FDefaultRes
, ID
) then e_Draw(ID
, FX
, FY
, 0, True, False);
3435 if g_Texture_Get(FImageRes
, ID
) then e_Draw(ID
, FX
, FY
, 0, True, False);
3438 procedure TGUIimage
.OnMessage(var Msg
: TMessage
);
3443 procedure TGUIimage
.SetImage(Res
: string);
3447 if g_Texture_CreateWADEx(Res
, Res
) then FImageRes
:= Res
;
3450 procedure TGUIimage
.Update();