1 (* Copyright (C) DooM 2D:Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 e_graphics
, e_input
, e_log
, g_playermodel
, g_basic
, MAPSTRUCT
, wadreader
;
25 MAINMENU_HEADER_COLOR
: TRGB
= (R
:255; G
:255; B
:255);
26 MAINMENU_ITEMS_COLOR
: TRGB
= (R
:255; G
:255; B
:255);
27 MAINMENU_UNACTIVEITEMS_COLOR
: TRGB
= (R
:192; G
:192; B
:192);
28 MAINMENU_CLICKSOUND
= 'MENU_SELECT';
29 MAINMENU_CHANGESOUND
= 'MENU_CHANGE';
31 MAINMENU_MARKER1
= 'MAINMENU_MARKER1';
32 MAINMENU_MARKER2
= 'MAINMENU_MARKER2';
33 MAINMENU_MARKERDELAY
= 24;
34 WINDOW_CLOSESOUND
= 'MENU_CLOSE';
35 MENU_HEADERCOLOR
: TRGB
= (R
:255; G
:255; B
:255);
36 MENU_ITEMSTEXT_COLOR
: TRGB
= (R
:255; G
:255; B
:255);
37 MENU_UNACTIVEITEMS_COLOR
: TRGB
= (R
:128; G
:128; B
:128);
38 MENU_ITEMSCTRL_COLOR
: TRGB
= (R
:255; G
:0; B
:0);
41 MENU_CLICKSOUND
= 'MENU_SELECT';
42 MENU_CHANGESOUND
= 'MENU_CHANGE';
43 MENU_MARKERDELAY
= 24;
44 SCROLL_LEFT
= 'SCROLL_LEFT';
45 SCROLL_RIGHT
= 'SCROLL_RIGHT';
46 SCROLL_MIDDLE
= 'SCROLL_MIDDLE';
47 SCROLL_MARKER
= 'SCROLL_MARKER';
48 SCROLL_ADDSOUND
= 'SCROLL_ADD';
49 SCROLL_SUBSOUND
= 'SCROLL_SUB';
50 EDIT_LEFT
= 'EDIT_LEFT';
51 EDIT_RIGHT
= 'EDIT_RIGHT';
52 EDIT_MIDDLE
= 'EDIT_MIDDLE';
53 EDIT_CURSORCOLOR
: TRGB
= (R
:200; G
:0; B
:0);
55 KEYREAD_QUERY
= '<...>';
56 KEYREAD_CLEAR
= '???';
59 MAPPREVIEW_HEIGHT
= 8;
69 BSCROLL_UPA
= 'BSCROLL_UP_A';
70 BSCROLL_UPU
= 'BSCROLL_UP_U';
71 BSCROLL_DOWNA
= 'BSCROLL_DOWN_A';
72 BSCROLL_DOWNU
= 'BSCROLL_DOWN_U';
73 BSCROLL_MIDDLE
= 'BSCROLL_MIDDLE';
85 TFontType
= (FONT_TEXTURE
, FONT_CHAR
);
87 TFont
= class(TObject
)
93 constructor Create(FontID
: DWORD
; FontType
: TFontType
);
94 destructor Destroy
; override;
95 procedure Draw(X
, Y
: Integer; Text: string; R
, G
, B
: Byte);
96 procedure GetTextSize(Text: string; var w
, h
: Word);
97 property Scale
: Single read FScale write FScale
;
103 TOnKeyDownEvent
= procedure(Key
: Byte);
104 TOnKeyDownEventEx
= procedure(win
: TGUIWindow
; Key
: Byte);
105 TOnCloseEvent
= procedure;
106 TOnShowEvent
= procedure;
107 TOnClickEvent
= procedure;
108 TOnChangeEvent
= procedure(Sender
: TGUIControl
);
109 TOnEnterEvent
= procedure(Sender
: TGUIControl
);
115 FWindow
: TGUIWindow
;
120 procedure OnMessage(var Msg
: TMessage
); virtual;
121 procedure Update
; virtual;
122 procedure Draw
; virtual;
123 function WantActivationKey (key
: LongInt): Boolean; virtual;
124 property X
: Integer read FX write FX
;
125 property Y
: Integer read FY write FY
;
126 property Enabled
: Boolean read FEnabled write FEnabled
;
127 property Name
: string read FName write FName
;
128 property UserData
: Pointer read FUserData write FUserData
;
133 FActiveControl
: TGUIControl
;
135 FPrevWindow
: TGUIWindow
;
137 FBackTexture
: string;
138 FMainWindow
: Boolean;
139 FOnKeyDown
: TOnKeyDownEvent
;
140 FOnKeyDownEx
: TOnKeyDownEventEx
;
141 FOnCloseEvent
: TOnCloseEvent
;
142 FOnShowEvent
: TOnShowEvent
;
145 Childs
: array of TGUIControl
;
146 constructor Create(Name
: string);
147 destructor Destroy
; override;
148 function AddChild(Child
: TGUIControl
): TGUIControl
;
149 procedure OnMessage(var Msg
: TMessage
);
152 procedure SetActive(Control
: TGUIControl
);
153 function GetControl(Name
: string): TGUIControl
;
154 property OnKeyDown
: TOnKeyDownEvent read FOnKeyDown write FOnKeyDown
;
155 property OnKeyDownEx
: TOnKeyDownEventEx read FOnKeyDownEx write FOnKeyDownEx
;
156 property OnClose
: TOnCloseEvent read FOnCloseEvent write FOnCloseEvent
;
157 property OnShow
: TOnShowEvent read FOnShowEvent write FOnShowEvent
;
158 property Name
: string read FName
;
159 property DefControl
: string read FDefControl write FDefControl
;
160 property BackTexture
: string read FBackTexture write FBackTexture
;
161 property MainWindow
: Boolean read FMainWindow write FMainWindow
;
162 property UserData
: Pointer read FUserData write FUserData
;
165 TGUITextButton
= class(TGUIControl
)
174 ProcEx
: procedure (sender
: TGUITextButton
);
175 constructor Create(Proc
: Pointer; FontID
: DWORD
; Text: string);
176 destructor Destroy(); override;
177 procedure OnMessage(var Msg
: TMessage
); override;
178 procedure Update(); override;
179 procedure Draw(); override;
180 function GetWidth(): Integer;
181 function GetHeight(): Integer;
182 procedure Click(Silent
: Boolean = False);
183 property Caption
: string read FText write FText
;
184 property Color
: TRGB read FColor write FColor
;
185 property Font
: TFont read FFont write FFont
;
186 property ShowWindow
: string read FShowWindow write FShowWindow
;
189 TGUILabel
= class(TGUIControl
)
195 FOnClickEvent
: TOnClickEvent
;
197 constructor Create(Text: string; FontID
: DWORD
);
198 procedure OnMessage(var Msg
: TMessage
); override;
199 procedure Draw
; override;
200 function GetWidth
: Integer;
201 function GetHeight
: Integer;
202 property OnClick
: TOnClickEvent read FOnClickEvent write FOnClickEvent
;
203 property FixedLength
: Word read FFixedLen write FFixedLen
;
204 property Text: string read FText write FText
;
205 property Color
: TRGB read FColor write FColor
;
206 property Font
: TFont read FFont write FFont
;
209 TGUIScroll
= class(TGUIControl
)
217 FOnChangeEvent
: TOnChangeEvent
;
218 procedure FSetValue(a
: Integer);
220 constructor Create();
221 procedure OnMessage(var Msg
: TMessage
); override;
222 procedure Update
; override;
223 procedure Draw
; override;
224 function GetWidth(): Word;
225 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
226 property Max
: Word read FMax write FMax
;
227 property Value
: Integer read FValue write FSetValue
;
230 TGUISwitch
= class(TGUIControl
)
233 FItems
: array of string;
236 FOnChangeEvent
: TOnChangeEvent
;
238 constructor Create(FontID
: DWORD
);
239 procedure OnMessage(var Msg
: TMessage
); override;
240 procedure AddItem(Item
: string);
241 procedure Update
; override;
242 procedure Draw
; override;
243 function GetWidth(): Word;
244 function GetText
: string;
245 property ItemIndex
: Integer read FIndex write FIndex
;
246 property Color
: TRGB read FColor write FColor
;
247 property Font
: TFont read FFont write FFont
;
248 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
251 TGUIEdit
= class(TGUIControl
)
259 FOnlyDigits
: Boolean;
263 FOnChangeEvent
: TOnChangeEvent
;
264 FOnEnterEvent
: TOnEnterEvent
;
265 procedure SetText(Text: string);
267 constructor Create(FontID
: DWORD
);
268 procedure OnMessage(var Msg
: TMessage
); override;
269 procedure Update
; override;
270 procedure Draw
; override;
271 function GetWidth(): Word;
272 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
273 property OnEnter
: TOnEnterEvent read FOnEnterEvent write FOnEnterEvent
;
274 property Width
: Word read FWidth write FWidth
;
275 property MaxLength
: Word read FMaxLength write FMaxLength
;
276 property OnlyDigits
: Boolean read FOnlyDigits write FOnlyDigits
;
277 property Text: string read FText write SetText
;
278 property Color
: TRGB read FColor write FColor
;
279 property Font
: TFont read FFont write FFont
;
282 TGUIKeyRead
= class(TGUIControl
)
289 constructor Create(FontID
: DWORD
);
290 procedure OnMessage(var Msg
: TMessage
); override;
291 procedure Draw
; override;
292 function GetWidth(): Word;
293 function WantActivationKey (key
: LongInt): Boolean; override;
294 property Key
: Word read FKey write FKey
;
295 property Color
: TRGB read FColor write FColor
;
296 property Font
: TFont read FFont write FFont
;
299 TGUIModelView
= class(TGUIControl
)
301 FModel
: TPlayerModel
;
305 destructor Destroy
; override;
306 procedure OnMessage(var Msg
: TMessage
); override;
307 procedure SetModel(ModelName
: string);
308 procedure SetColor(Red
, Green
, Blue
: Byte);
309 procedure NextAnim();
310 procedure NextWeapon();
311 procedure Update
; override;
312 procedure Draw
; override;
313 property Model
: TPlayerModel read FModel
;
316 TPreviewPanel
= record
317 X1
, Y1
, X2
, Y2
: Integer;
321 TGUIMapPreview
= class(TGUIControl
)
323 FMapData
: array of TPreviewPanel
;
327 constructor Create();
328 destructor Destroy(); override;
329 procedure OnMessage(var Msg
: TMessage
); override;
330 procedure SetMap(Res
: string);
331 procedure ClearMap();
332 procedure Update(); override;
333 procedure Draw(); override;
334 function GetScaleStr
: String;
337 TGUIImage
= class(TGUIControl
)
342 constructor Create();
343 destructor Destroy(); override;
344 procedure OnMessage(var Msg
: TMessage
); override;
345 procedure SetImage(Res
: string);
346 procedure ClearImage();
347 procedure Update(); override;
348 procedure Draw(); override;
349 property DefaultRes
: string read FDefaultRes write FDefaultRes
;
352 TGUIListBox
= class(TGUIControl
)
356 FUnActiveColor
: TRGB
;
364 FDrawScroll
: Boolean;
365 FOnChangeEvent
: TOnChangeEvent
;
367 procedure FSetItems(Items
: SArray
);
368 procedure FSetIndex(aIndex
: Integer);
371 constructor Create(FontID
: DWORD
; Width
, Height
: Word);
372 procedure OnMessage(var Msg
: TMessage
); override;
373 procedure Draw(); override;
374 procedure AddItem(Item
: String);
375 procedure SelectItem(Item
: String);
377 function GetWidth(): Word;
378 function GetHeight(): Word;
379 function SelectedItem(): String;
381 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
382 property Sort
: Boolean read FSort write FSort
;
383 property ItemIndex
: Integer read FIndex write FSetIndex
;
384 property Items
: SArray read FItems write FSetItems
;
385 property DrawBack
: Boolean read FDrawBack write FDrawBack
;
386 property DrawScrollBar
: Boolean read FDrawScroll write FDrawScroll
;
387 property ActiveColor
: TRGB read FActiveColor write FActiveColor
;
388 property UnActiveColor
: TRGB read FUnActiveColor write FUnActiveColor
;
389 property Font
: TFont read FFont write FFont
;
392 TGUIFileListBox
= class (TGUIListBox
)
399 procedure OpenDir(path
: String);
402 procedure OnMessage(var Msg
: TMessage
); override;
403 procedure SetBase(path
: String);
404 function SelectedItem(): String;
405 procedure UpdateFileList();
407 property Dirs
: Boolean read FDirs write FDirs
;
408 property FileMask
: String read FFileMask write FFileMask
;
409 property Path
: String read FPath
;
412 TGUIMemo
= class(TGUIControl
)
421 FDrawScroll
: Boolean;
423 constructor Create(FontID
: DWORD
; Width
, Height
: Word);
424 procedure OnMessage(var Msg
: TMessage
); override;
425 procedure Draw
; override;
427 function GetWidth(): Word;
428 function GetHeight(): Word;
429 procedure SetText(Text: string);
430 property DrawBack
: Boolean read FDrawBack write FDrawBack
;
431 property DrawScrollBar
: Boolean read FDrawScroll write FDrawScroll
;
432 property Color
: TRGB read FColor write FColor
;
433 property Font
: TFont read FFont write FFont
;
436 TGUIMainMenu
= class(TGUIControl
)
438 FButtons
: array of TGUITextButton
;
446 constructor Create(FontID
: DWORD
; Header
: string);
447 destructor Destroy
; override;
448 procedure OnMessage(var Msg
: TMessage
); override;
449 function AddButton(fProc
: Pointer; Caption
: string; ShowWindow
: string = ''): TGUITextButton
;
450 function GetButton(Name
: string): TGUITextButton
;
451 procedure EnableButton(Name
: string; e
: Boolean);
452 procedure AddSpace();
453 procedure Update
; override;
454 procedure Draw
; override;
457 TControlType
= class of TGUIControl
;
459 PMenuItem
= ^TMenuItem
;
462 ControlType
: TControlType
;
463 Control
: TGUIControl
;
466 TGUIMenu
= class(TGUIControl
)
468 FItems
: array of TMenuItem
;
476 function NewItem(): Integer;
478 constructor Create(HeaderFont
, ItemsFont
: DWORD
; Header
: string);
479 destructor Destroy
; override;
480 procedure OnMessage(var Msg
: TMessage
); override;
481 procedure AddSpace();
482 procedure AddLine(fText
: string);
483 procedure AddText(fText
: string; MaxWidth
: Word);
484 function AddLabel(fText
: string): TGUILabel
;
485 function AddButton(Proc
: Pointer; fText
: string; _ShowWindow
: string = ''): TGUITextButton
;
486 function AddScroll(fText
: string): TGUIScroll
;
487 function AddSwitch(fText
: string): TGUISwitch
;
488 function AddEdit(fText
: string): TGUIEdit
;
489 function AddKeyRead(fText
: string): TGUIKeyRead
;
490 function AddList(fText
: string; Width
, Height
: Word): TGUIListBox
;
491 function AddFileList(fText
: string; Width
, Height
: Word): TGUIFileListBox
;
492 function AddMemo(fText
: string; Width
, Height
: Word): TGUIMemo
;
494 function GetControl(Name
: string): TGUIControl
;
495 function GetControlsText(Name
: string): TGUILabel
;
496 procedure Draw
; override;
497 procedure Update
; override;
498 procedure UpdateIndex();
499 property Align
: Boolean read FAlign write FAlign
;
500 property Left
: Integer read FLeft write FLeft
;
501 property YesNo
: Boolean read FYesNo write FYesNo
;
505 g_GUIWindows
: array of TGUIWindow
;
506 g_ActiveWindow
: TGUIWindow
= nil;
508 procedure g_GUI_Init();
509 function g_GUI_AddWindow(Window
: TGUIWindow
): TGUIWindow
;
510 function g_GUI_GetWindow(Name
: string): TGUIWindow
;
511 procedure g_GUI_ShowWindow(Name
: string);
512 procedure g_GUI_HideWindow(PlaySound
: Boolean = True);
513 function g_GUI_Destroy(): Boolean;
514 procedure g_GUI_SaveMenuPos();
515 procedure g_GUI_LoadMenuPos();
520 GL
, GLExt
, g_textures
, g_sound
, SysUtils
,
521 g_game
, Math
, StrUtils
, g_player
, g_options
, MAPREADER
,
522 g_map
, MAPDEF
, g_weapons
;
525 Box
: Array [0..8] of DWORD
;
526 Saved_Windows
: SArray
;
528 procedure g_GUI_Init();
530 g_Texture_Get(BOX1
, Box
[0]);
531 g_Texture_Get(BOX2
, Box
[1]);
532 g_Texture_Get(BOX3
, Box
[2]);
533 g_Texture_Get(BOX4
, Box
[3]);
534 g_Texture_Get(BOX5
, Box
[4]);
535 g_Texture_Get(BOX6
, Box
[5]);
536 g_Texture_Get(BOX7
, Box
[6]);
537 g_Texture_Get(BOX8
, Box
[7]);
538 g_Texture_Get(BOX9
, Box
[8]);
541 function g_GUI_Destroy(): Boolean;
545 Result
:= (Length(g_GUIWindows
) > 0);
547 for i
:= 0 to High(g_GUIWindows
) do
548 g_GUIWindows
[i
].Free();
551 g_ActiveWindow
:= nil;
554 function g_GUI_AddWindow(Window
: TGUIWindow
): TGUIWindow
;
556 SetLength(g_GUIWindows
, Length(g_GUIWindows
)+1);
557 g_GUIWindows
[High(g_GUIWindows
)] := Window
;
562 function g_GUI_GetWindow(Name
: string): TGUIWindow
;
568 if g_GUIWindows
<> nil then
569 for i
:= 0 to High(g_GUIWindows
) do
570 if g_GUIWindows
[i
].FName
= Name
then
572 Result
:= g_GUIWindows
[i
];
576 Assert(Result
<> nil, 'GUI_Window "'+Name
+'" not found');
579 procedure g_GUI_ShowWindow(Name
: string);
583 if g_GUIWindows
= nil then
586 for i
:= 0 to High(g_GUIWindows
) do
587 if g_GUIWindows
[i
].FName
= Name
then
589 g_GUIWindows
[i
].FPrevWindow
:= g_ActiveWindow
;
590 g_ActiveWindow
:= g_GUIWindows
[i
];
592 if g_ActiveWindow
.MainWindow
then
593 g_ActiveWindow
.FPrevWindow
:= nil;
595 if g_ActiveWindow
.FDefControl
<> '' then
596 g_ActiveWindow
.SetActive(g_ActiveWindow
.GetControl(g_ActiveWindow
.FDefControl
))
598 g_ActiveWindow
.SetActive(nil);
600 if @g_ActiveWindow
.FOnShowEvent
<> nil then
601 g_ActiveWindow
.FOnShowEvent();
607 procedure g_GUI_HideWindow(PlaySound
: Boolean = True);
609 if g_ActiveWindow
<> nil then
611 if @g_ActiveWindow
.OnClose
<> nil then
612 g_ActiveWindow
.OnClose();
613 g_ActiveWindow
:= g_ActiveWindow
.FPrevWindow
;
615 g_Sound_PlayEx(WINDOW_CLOSESOUND
);
619 procedure g_GUI_SaveMenuPos();
624 SetLength(Saved_Windows
, 0);
625 win
:= g_ActiveWindow
;
629 len
:= Length(Saved_Windows
);
630 SetLength(Saved_Windows
, len
+ 1);
632 Saved_Windows
[len
] := win
.Name
;
634 if win
.MainWindow
then
637 win
:= win
.FPrevWindow
;
641 procedure g_GUI_LoadMenuPos();
643 i
, j
, k
, len
: Integer;
646 g_ActiveWindow
:= nil;
647 len
:= Length(Saved_Windows
);
652 // Îêíî ñ ãëàâíûì ìåíþ:
653 g_GUI_ShowWindow(Saved_Windows
[len
-1]);
655 // Íå ïåðåêëþ÷èëîñü (èëè íåêóäà äàëüøå):
656 if (len
= 1) or (g_ActiveWindow
= nil) then
659 // Èùåì êíîïêè â îñòàëüíûõ îêíàõ:
660 for k
:= len
-1 downto 1 do
664 for i
:= 0 to Length(g_ActiveWindow
.Childs
)-1 do
666 if g_ActiveWindow
.Childs
[i
] is TGUIMainMenu
then
667 begin // GUI_MainMenu
668 with TGUIMainMenu(g_ActiveWindow
.Childs
[i
]) do
669 for j
:= 0 to Length(FButtons
)-1 do
670 if FButtons
[j
].ShowWindow
= Saved_Windows
[k
-1] then
672 FButtons
[j
].Click(True);
678 if g_ActiveWindow
.Childs
[i
] is TGUIMenu
then
679 with TGUIMenu(g_ActiveWindow
.Childs
[i
]) do
680 for j
:= 0 to Length(FItems
)-1 do
681 if FItems
[j
].ControlType
= TGUITextButton
then
682 if TGUITextButton(FItems
[j
].Control
).ShowWindow
= Saved_Windows
[k
-1] then
684 TGUITextButton(FItems
[j
].Control
).Click(True);
695 (g_ActiveWindow
.Name
= Saved_Windows
[k
]) then
700 procedure DrawBox(X
, Y
: Integer; Width
, Height
: Word);
702 e_Draw(Box
[0], X
, Y
, 0, False, False);
703 e_DrawFill(Box
[1], X
+4, Y
, Width
*4, 1, 0, False, False);
704 e_Draw(Box
[2], X
+4+Width
*16, Y
, 0, False, False);
705 e_DrawFill(Box
[3], X
, Y
+4, 1, Height
*4, 0, False, False);
706 e_DrawFill(Box
[4], X
+4, Y
+4, Width
, Height
, 0, False, False);
707 e_DrawFill(Box
[5], X
+4+Width
*16, Y
+4, 1, Height
*4, 0, False, False);
708 e_Draw(Box
[6], X
, Y
+4+Height
*16, 0, False, False);
709 e_DrawFill(Box
[7], X
+4, Y
+4+Height
*16, Width
*4, 1, 0, False, False);
710 e_Draw(Box
[8], X
+4+Width
*16, Y
+4+Height
*16, 0, False, False);
713 procedure DrawScroll(X
, Y
: Integer; Height
: Word; Up
, Down
: Boolean);
717 if Height
< 3 then Exit
;
720 g_Texture_Get(BSCROLL_UPA
, ID
)
722 g_Texture_Get(BSCROLL_UPU
, ID
);
723 e_Draw(ID
, X
, Y
, 0, False, False);
726 g_Texture_Get(BSCROLL_DOWNA
, ID
)
728 g_Texture_Get(BSCROLL_DOWNU
, ID
);
729 e_Draw(ID
, X
, Y
+(Height
-1)*16, 0, False, False);
731 g_Texture_Get(BSCROLL_MIDDLE
, ID
);
732 e_DrawFill(ID
, X
, Y
+16, 1, Height
-2, 0, False, False);
737 constructor TGUIWindow
.Create(Name
: string);
740 FActiveControl
:= nil;
744 FOnCloseEvent
:= nil;
748 destructor TGUIWindow
.Destroy
;
755 for i
:= 0 to High(Childs
) do
759 function TGUIWindow
.AddChild(Child
: TGUIControl
): TGUIControl
;
761 Child
.FWindow
:= Self
;
763 SetLength(Childs
, Length(Childs
) + 1);
764 Childs
[High(Childs
)] := Child
;
769 procedure TGUIWindow
.Update
;
773 for i
:= 0 to High(Childs
) do
774 if Childs
[i
] <> nil then Childs
[i
].Update
;
777 procedure TGUIWindow
.Draw
;
782 if FBackTexture
<> '' then
783 if g_Texture_Get(FBackTexture
, ID
) then
784 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
786 e_Clear(GL_COLOR_BUFFER_BIT
, 0.5, 0.5, 0.5);
788 for i
:= 0 to High(Childs
) do
789 if Childs
[i
] <> nil then Childs
[i
].Draw
;
792 procedure TGUIWindow
.OnMessage(var Msg
: TMessage
);
794 if FActiveControl
<> nil then FActiveControl
.OnMessage(Msg
);
795 if @FOnKeyDown
<> nil then FOnKeyDown(Msg
.wParam
);
796 if @FOnKeyDownEx
<> nil then FOnKeyDownEx(self
, Msg
.wParam
);
798 if Msg
.Msg
= WM_KEYDOWN
then
799 if Msg
.wParam
= IK_ESCAPE
then
806 procedure TGUIWindow
.SetActive(Control
: TGUIControl
);
808 FActiveControl
:= Control
;
811 function TGUIWindow
.GetControl(Name
: String): TGUIControl
;
817 if Childs
<> nil then
818 for i
:= 0 to High(Childs
) do
819 if Childs
[i
] <> nil then
820 if LowerCase(Childs
[i
].FName
) = LowerCase(Name
) then
826 Assert(Result
<> nil, 'Window Control "'+Name
+'" not Found!');
831 constructor TGUIControl
.Create();
839 procedure TGUIControl
.OnMessage(var Msg
: TMessage
);
845 procedure TGUIControl
.Update();
849 procedure TGUIControl
.Draw();
853 function TGUIControl
.WantActivationKey (key
: LongInt): Boolean;
860 procedure TGUITextButton
.Click(Silent
: Boolean = False);
862 if (FSound
<> '') and (not Silent
) then g_Sound_PlayEx(FSound
);
864 if @Proc
<> nil then Proc();
865 if @ProcEx
<> nil then ProcEx(self
);
867 if FShowWindow
<> '' then g_GUI_ShowWindow(FShowWindow
);
870 constructor TGUITextButton
.Create(Proc
: Pointer; FontID
: DWORD
; Text: string);
877 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
882 destructor TGUITextButton
.Destroy
;
888 procedure TGUITextButton
.Draw
;
890 FFont
.Draw(FX
, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
)
893 function TGUITextButton
.GetHeight
: Integer;
897 FFont
.GetTextSize(FText
, w
, h
);
901 function TGUITextButton
.GetWidth
: Integer;
905 FFont
.GetTextSize(FText
, w
, h
);
909 procedure TGUITextButton
.OnMessage(var Msg
: TMessage
);
911 if not FEnabled
then Exit
;
918 IK_RETURN
, IK_KPRETURN
: Click();
923 procedure TGUITextButton
.Update
;
930 constructor TFont
.Create(FontID
: DWORD
; FontType
: TFontType
);
935 FFontType
:= FontType
;
938 destructor TFont
.Destroy
;
944 procedure TFont
.Draw(X
, Y
: Integer; Text: string; R
, G
, B
: Byte);
946 if FFontType
= FONT_CHAR
then e_CharFont_PrintEx(ID
, X
, Y
, Text, _RGB(R
, G
, B
), FScale
)
947 else e_TextureFontPrintEx(X
, Y
, Text, ID
, R
, G
, B
, FScale
);
950 procedure TFont
.GetTextSize(Text: string; var w
, h
: Word);
954 if FFontType
= FONT_CHAR
then e_CharFont_GetSize(ID
, Text, w
, h
)
957 e_TextureFontGetSize(ID
, cw
, ch
);
958 w
:= cw
*Length(Text);
962 w
:= Round(w
*FScale
);
963 h
:= Round(h
*FScale
);
968 function TGUIMainMenu
.AddButton(fProc
: Pointer; Caption
: string; ShowWindow
: string = ''): TGUITextButton
;
975 SetLength(FButtons
, Length(FButtons
)+1);
976 FButtons
[High(FButtons
)] := TGUITextButton
.Create(fProc
, FFontID
, Caption
);
977 FButtons
[High(FButtons
)].ShowWindow
:= ShowWindow
;
978 with FButtons
[High(FButtons
)] do
980 if (fProc
<> nil) or (ShowWindow
<> '') then FColor
:= MAINMENU_ITEMS_COLOR
981 else FColor
:= MAINMENU_UNACTIVEITEMS_COLOR
;
982 FSound
:= MAINMENU_CLICKSOUND
;
985 _x
:= gScreenWidth
div 2;
987 for a
:= 0 to High(FButtons
) do
988 if FButtons
[a
] <> nil then
989 _x
:= Min(_x
, (gScreenWidth
div 2)-(FButtons
[a
].GetWidth
div 2));
991 hh
:= FHeader
.GetHeight
;
993 h
:= hh
*(2+Length(FButtons
))+MAINMENU_SPACE
*(Length(FButtons
)-1);
994 h
:= (gScreenHeight
div 2)-(h
div 2);
1004 for a
:= 0 to High(FButtons
) do
1006 if FButtons
[a
] <> nil then
1013 Inc(h
, hh
+MAINMENU_SPACE
);
1016 Result
:= FButtons
[High(FButtons
)];
1019 procedure TGUIMainMenu
.AddSpace
;
1021 SetLength(FButtons
, Length(FButtons
)+1);
1022 FButtons
[High(FButtons
)] := nil;
1025 constructor TGUIMainMenu
.Create(FontID
: DWORD
; Header
: string);
1031 FCounter
:= MAINMENU_MARKERDELAY
;
1033 g_Texture_Get(MAINMENU_MARKER1
, FMarkerID1
);
1034 g_Texture_Get(MAINMENU_MARKER2
, FMarkerID2
);
1036 FHeader
:= TGUILabel
.Create(Header
, FFontID
);
1039 FColor
:= MAINMENU_HEADER_COLOR
;
1040 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1041 FY
:= (gScreenHeight
div 2)-(GetHeight
div 2);
1045 destructor TGUIMainMenu
.Destroy
;
1049 if FButtons
<> nil then
1050 for a
:= 0 to High(FButtons
) do
1058 procedure TGUIMainMenu
.Draw
;
1066 if FButtons
<> nil then
1068 for a
:= 0 to High(FButtons
) do
1069 if FButtons
[a
] <> nil then FButtons
[a
].Draw
;
1071 if FIndex
<> -1 then
1072 e_Draw(FMarkerID1
, FButtons
[FIndex
].FX
-48, FButtons
[FIndex
].FY
, 0, True, False);
1076 procedure TGUIMainMenu
.EnableButton(Name
: string; e
: Boolean);
1080 if FButtons
= nil then Exit
;
1082 for a
:= 0 to High(FButtons
) do
1083 if (FButtons
[a
] <> nil) and (FButtons
[a
].Name
= Name
) then
1085 if e
then FButtons
[a
].FColor
:= MAINMENU_ITEMS_COLOR
1086 else FButtons
[a
].FColor
:= MAINMENU_UNACTIVEITEMS_COLOR
;
1087 FButtons
[a
].Enabled
:= e
;
1092 function TGUIMainMenu
.GetButton(Name
: string): TGUITextButton
;
1098 if FButtons
= nil then Exit
;
1100 for a
:= 0 to High(FButtons
) do
1101 if (FButtons
[a
] <> nil) and (FButtons
[a
].Name
= Name
) then
1103 Result
:= FButtons
[a
];
1108 procedure TGUIMainMenu
.OnMessage(var Msg
: TMessage
);
1113 if not FEnabled
then Exit
;
1117 if FButtons
= nil then Exit
;
1120 for a
:= 0 to High(FButtons
) do
1121 if FButtons
[a
] <> nil then
1127 if not ok
then Exit
;
1136 if FIndex
< 0 then FIndex
:= High(FButtons
);
1137 until FButtons
[FIndex
] <> nil;
1139 g_Sound_PlayEx(MENU_CHANGESOUND
);
1145 if FIndex
> High(FButtons
) then FIndex
:= 0;
1146 until FButtons
[FIndex
] <> nil;
1148 g_Sound_PlayEx(MENU_CHANGESOUND
);
1150 IK_RETURN
, IK_KPRETURN
: if (FIndex
<> -1) and FButtons
[FIndex
].FEnabled
then FButtons
[FIndex
].Click
;
1155 procedure TGUIMainMenu
.Update
;
1161 if FCounter
= 0 then
1164 FMarkerID1
:= FMarkerID2
;
1167 FCounter
:= MAINMENU_MARKERDELAY
;
1168 end else Dec(FCounter
);
1173 constructor TGUILabel
.Create(Text: string; FontID
: DWORD
);
1177 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
1181 FOnClickEvent
:= nil;
1184 procedure TGUILabel
.Draw
;
1186 FFont
.Draw(FX
, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
);
1189 function TGUILabel
.GetHeight
: Integer;
1193 FFont
.GetTextSize(FText
, w
, h
);
1197 function TGUILabel
.GetWidth
: Integer;
1201 if FFixedLen
= 0 then
1202 FFont
.GetTextSize(FText
, w
, h
)
1204 w
:= e_CharFont_GetMaxWidth(FFont
.ID
)*FFixedLen
;
1208 procedure TGUILabel
.OnMessage(var Msg
: TMessage
);
1210 if not FEnabled
then Exit
;
1217 IK_RETURN
, IK_KPRETURN
: if @FOnClickEvent
<> nil then FOnClickEvent();
1224 function TGUIMenu
.AddButton(Proc
: Pointer; fText
: string; _ShowWindow
: string = ''): TGUITextButton
;
1231 Control
:= TGUITextButton
.Create(Proc
, FFontID
, fText
);
1232 with Control
as TGUITextButton
do
1234 ShowWindow
:= _ShowWindow
;
1235 FColor
:= MENU_ITEMSCTRL_COLOR
;
1239 ControlType
:= TGUITextButton
;
1241 Result
:= (Control
as TGUITextButton
);
1244 if FIndex
= -1 then FIndex
:= i
;
1249 procedure TGUIMenu
.AddLine(fText
: string);
1256 Text := TGUILabel
.Create(fText
, FFontID
);
1259 FColor
:= MENU_ITEMSTEXT_COLOR
;
1268 procedure TGUIMenu
.AddText(fText
: string; MaxWidth
: Word);
1273 l
:= GetLines(fText
, FFontID
, MaxWidth
);
1275 if l
= nil then Exit
;
1277 for a
:= 0 to High(l
) do
1282 Text := TGUILabel
.Create(l
[a
], FFontID
);
1285 with Text do begin FColor
:= _RGB(255, 0, 0); end;
1289 with Text do begin FColor
:= MENU_ITEMSTEXT_COLOR
; end;
1299 procedure TGUIMenu
.AddSpace
;
1313 constructor TGUIMenu
.Create(HeaderFont
, ItemsFont
: DWORD
; Header
: string);
1319 FFontID
:= ItemsFont
;
1320 FCounter
:= MENU_MARKERDELAY
;
1324 FHeader
:= TGUILabel
.Create(Header
, HeaderFont
);
1327 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1329 FColor
:= MAINMENU_HEADER_COLOR
;
1333 destructor TGUIMenu
.Destroy
;
1337 if FItems
<> nil then
1338 for a
:= 0 to High(FItems
) do
1352 procedure TGUIMenu
.Draw
;
1358 if FHeader
<> nil then FHeader
.Draw
;
1360 if FItems
<> nil then
1361 for a
:= 0 to High(FItems
) do
1363 if FItems
[a
].Text <> nil then FItems
[a
].Text.Draw
;
1364 if FItems
[a
].Control
<> nil then FItems
[a
].Control
.Draw
;
1367 if (FIndex
<> -1) and (FCounter
> MENU_MARKERDELAY
div 2) then
1372 if FItems
[FIndex
].Text <> nil then
1374 x
:= FItems
[FIndex
].Text.FX
;
1375 y
:= FItems
[FIndex
].Text.FY
;
1377 else if FItems
[FIndex
].Control
<> nil then
1379 x
:= FItems
[FIndex
].Control
.FX
;
1380 y
:= FItems
[FIndex
].Control
.FY
;
1383 x
:= x
-e_CharFont_GetMaxWidth(FFontID
);
1385 e_CharFont_PrintEx(FFontID
, x
, y
, #16, _RGB(255, 0, 0));
1389 function TGUIMenu
.GetControl(Name
: String): TGUIControl
;
1395 if FItems
<> nil then
1396 for a
:= 0 to High(FItems
) do
1397 if FItems
[a
].Control
<> nil then
1398 if LowerCase(FItems
[a
].Control
.Name
) = LowerCase(Name
) then
1400 Result
:= FItems
[a
].Control
;
1404 Assert(Result
<> nil, 'GUI control "'+Name
+'" not found!');
1407 function TGUIMenu
.GetControlsText(Name
: String): TGUILabel
;
1413 if FItems
<> nil then
1414 for a
:= 0 to High(FItems
) do
1415 if FItems
[a
].Control
<> nil then
1416 if LowerCase(FItems
[a
].Control
.Name
) = LowerCase(Name
) then
1418 Result
:= FItems
[a
].Text;
1422 Assert(Result
<> nil, 'GUI control''s text "'+Name
+'" not found!');
1425 function TGUIMenu
.NewItem
: Integer;
1427 SetLength(FItems
, Length(FItems
)+1);
1428 Result
:= High(FItems
);
1431 procedure TGUIMenu
.OnMessage(var Msg
: TMessage
);
1436 if not FEnabled
then Exit
;
1440 if FItems
= nil then Exit
;
1443 for a
:= 0 to High(FItems
) do
1444 if FItems
[a
].Control
<> nil then
1450 if not ok
then Exit
;
1452 if (Msg
.Msg
= WM_KEYDOWN
) and (FIndex
<> -1) and (FItems
[FIndex
].Control
<> nil) and
1453 (FItems
[FIndex
].Control
.WantActivationKey(Msg
.wParam
)) then
1455 FItems
[FIndex
].Control
.OnMessage(Msg
);
1456 g_Sound_PlayEx(MENU_CLICKSOUND
);
1469 if c
> Length(FItems
) then
1476 if FIndex
< 0 then FIndex
:= High(FItems
);
1477 until (FItems
[FIndex
].Control
<> nil) and
1478 (FItems
[FIndex
].Control
.Enabled
);
1482 g_Sound_PlayEx(MENU_CHANGESOUND
);
1490 if c
> Length(FItems
) then
1497 if FIndex
> High(FItems
) then FIndex
:= 0;
1498 until (FItems
[FIndex
].Control
<> nil) and
1499 (FItems
[FIndex
].Control
.Enabled
);
1503 g_Sound_PlayEx(MENU_CHANGESOUND
);
1506 IK_LEFT
, IK_RIGHT
, IK_KPLEFT
, IK_KPRIGHT
:
1508 if FIndex
<> -1 then
1509 if FItems
[FIndex
].Control
<> nil then
1510 FItems
[FIndex
].Control
.OnMessage(Msg
);
1512 IK_RETURN
, IK_KPRETURN
:
1514 if FIndex
<> -1 then
1516 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1518 g_Sound_PlayEx(MENU_CLICKSOUND
);
1522 if FYesNo
and (length(FItems
) > 1) then
1524 Msg
.wParam
:= IK_RETURN
; // to register keypress
1525 FIndex
:= High(FItems
)-1;
1526 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1529 if FYesNo
and (length(FItems
) > 1) then
1531 Msg
.wParam
:= IK_RETURN
; // to register keypress
1532 FIndex
:= High(FItems
);
1533 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1540 procedure TGUIMenu
.ReAlign();
1542 a
, tx
, cx
, w
, h
: Integer;
1544 if FItems
= nil then Exit
;
1546 if not FAlign
then tx
:= FLeft
else
1549 for a
:= 0 to High(FItems
) do
1552 if FItems
[a
].Text <> nil then w
:= FItems
[a
].Text.GetWidth
;
1553 if FItems
[a
].Control
<> nil then
1557 if FItems
[a
].ControlType
= TGUILabel
then
1558 w
:= w
+(FItems
[a
].Control
as TGUILabel
).GetWidth
1559 else if FItems
[a
].ControlType
= TGUITextButton
then
1560 w
:= w
+(FItems
[a
].Control
as TGUITextButton
).GetWidth
1561 else if FItems
[a
].ControlType
= TGUIScroll
then
1562 w
:= w
+(FItems
[a
].Control
as TGUIScroll
).GetWidth
1563 else if FItems
[a
].ControlType
= TGUISwitch
then
1564 w
:= w
+(FItems
[a
].Control
as TGUISwitch
).GetWidth
1565 else if FItems
[a
].ControlType
= TGUIEdit
then
1566 w
:= w
+(FItems
[a
].Control
as TGUIEdit
).GetWidth
1567 else if FItems
[a
].ControlType
= TGUIKeyRead
then
1568 w
:= w
+(FItems
[a
].Control
as TGUIKeyRead
).GetWidth
1569 else if (FItems
[a
].ControlType
= TGUIListBox
) then
1570 w
:= w
+(FItems
[a
].Control
as TGUIListBox
).GetWidth
1571 else if (FItems
[a
].ControlType
= TGUIFileListBox
) then
1572 w
:= w
+(FItems
[a
].Control
as TGUIFileListBox
).GetWidth
1573 else if FItems
[a
].ControlType
= TGUIMemo
then
1574 w
:= w
+(FItems
[a
].Control
as TGUIMemo
).GetWidth
;
1577 tx
:= Min(tx
, (gScreenWidth
div 2)-(w
div 2));
1582 for a
:= 0 to High(FItems
) do
1586 if (Text <> nil) and (Control
= nil) then Continue
;
1588 if Text <> nil then w
:= tx
+Text.GetWidth
;
1589 if w
> cx
then cx
:= w
;
1593 cx
:= cx
+MENU_HSPACE
;
1595 h
:= FHeader
.GetHeight
*2+MENU_VSPACE
*(Length(FItems
)-1);
1597 for a
:= 0 to High(FItems
) do
1601 if (ControlType
= TGUIListBox
) or (ControlType
= TGUIFileListBox
) then
1602 h
:= h
+(FItems
[a
].Control
as TGUIListBox
).GetHeight()
1604 h
:= h
+e_CharFont_GetMaxHeight(FFontID
);
1608 h
:= (gScreenHeight
div 2)-(h
div 2);
1612 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1615 Inc(h
, GetHeight
*2);
1618 for a
:= 0 to High(FItems
) do
1628 if Control
<> nil then
1641 if (ControlType
= TGUIListBox
) or (ControlType
= TGUIFileListBox
) then
1642 Inc(h
, (Control
as TGUIListBox
).GetHeight
+MENU_VSPACE
)
1643 else if ControlType
= TGUIMemo
then
1644 Inc(h
, (Control
as TGUIMemo
).GetHeight
+MENU_VSPACE
)
1646 Inc(h
, e_CharFont_GetMaxHeight(FFontID
)+MENU_VSPACE
);
1649 // another ugly hack
1650 if FYesNo
and (length(FItems
) > 1) then
1653 for a
:= High(FItems
)-1 to High(FItems
) do
1655 if (FItems
[a
].Control
<> nil) and (FItems
[a
].ControlType
= TGUITextButton
) then
1657 cx
:= (FItems
[a
].Control
as TGUITextButton
).GetWidth
;
1658 if cx
> w
then w
:= cx
;
1663 for a
:= High(FItems
)-1 to High(FItems
) do
1665 if (FItems
[a
].Control
<> nil) and (FItems
[a
].ControlType
= TGUITextButton
) then
1667 FItems
[a
].Control
.FX
:= (gScreenWidth
-w
) div 2;
1674 function TGUIMenu
.AddScroll(fText
: string): TGUIScroll
;
1681 Control
:= TGUIScroll
.Create();
1683 Text := TGUILabel
.Create(fText
, FFontID
);
1686 FColor
:= MENU_ITEMSTEXT_COLOR
;
1689 ControlType
:= TGUIScroll
;
1691 Result
:= (Control
as TGUIScroll
);
1694 if FIndex
= -1 then FIndex
:= i
;
1699 function TGUIMenu
.AddSwitch(fText
: string): TGUISwitch
;
1706 Control
:= TGUISwitch
.Create(FFontID
);
1707 (Control
as TGUISwitch
).FColor
:= MENU_ITEMSCTRL_COLOR
;
1709 Text := TGUILabel
.Create(fText
, FFontID
);
1712 FColor
:= MENU_ITEMSTEXT_COLOR
;
1715 ControlType
:= TGUISwitch
;
1717 Result
:= (Control
as TGUISwitch
);
1720 if FIndex
= -1 then FIndex
:= i
;
1725 function TGUIMenu
.AddEdit(fText
: string): TGUIEdit
;
1732 Control
:= TGUIEdit
.Create(FFontID
);
1733 with Control
as TGUIEdit
do
1735 FWindow
:= Self
.FWindow
;
1736 FColor
:= MENU_ITEMSCTRL_COLOR
;
1739 if fText
= '' then Text := nil else
1741 Text := TGUILabel
.Create(fText
, FFontID
);
1742 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
1745 ControlType
:= TGUIEdit
;
1747 Result
:= (Control
as TGUIEdit
);
1750 if FIndex
= -1 then FIndex
:= i
;
1755 procedure TGUIMenu
.Update
;
1761 if FCounter
= 0 then FCounter
:= MENU_MARKERDELAY
else Dec(FCounter
);
1763 if FItems
<> nil then
1764 for a
:= 0 to High(FItems
) do
1765 if FItems
[a
].Control
<> nil then
1766 (FItems
[a
].Control
as FItems
[a
].ControlType
).Update
;
1769 function TGUIMenu
.AddKeyRead(fText
: string): TGUIKeyRead
;
1776 Control
:= TGUIKeyRead
.Create(FFontID
);
1777 with Control
as TGUIKeyRead
do
1779 FWindow
:= Self
.FWindow
;
1780 FColor
:= MENU_ITEMSCTRL_COLOR
;
1783 Text := TGUILabel
.Create(fText
, FFontID
);
1786 FColor
:= MENU_ITEMSTEXT_COLOR
;
1789 ControlType
:= TGUIKeyRead
;
1791 Result
:= (Control
as TGUIKeyRead
);
1794 if FIndex
= -1 then FIndex
:= i
;
1799 function TGUIMenu
.AddList(fText
: string; Width
, Height
: Word): TGUIListBox
;
1806 Control
:= TGUIListBox
.Create(FFontID
, Width
, Height
);
1807 with Control
as TGUIListBox
do
1809 FWindow
:= Self
.FWindow
;
1810 FActiveColor
:= MENU_ITEMSCTRL_COLOR
;
1811 FUnActiveColor
:= MENU_ITEMSTEXT_COLOR
;
1814 Text := TGUILabel
.Create(fText
, FFontID
);
1817 FColor
:= MENU_ITEMSTEXT_COLOR
;
1820 ControlType
:= TGUIListBox
;
1822 Result
:= (Control
as TGUIListBox
);
1825 if FIndex
= -1 then FIndex
:= i
;
1830 function TGUIMenu
.AddFileList(fText
: string; Width
, Height
: Word): TGUIFileListBox
;
1837 Control
:= TGUIFileListBox
.Create(FFontID
, Width
, Height
);
1838 with Control
as TGUIFileListBox
do
1840 FWindow
:= Self
.FWindow
;
1841 FActiveColor
:= MENU_ITEMSCTRL_COLOR
;
1842 FUnActiveColor
:= MENU_ITEMSTEXT_COLOR
;
1845 if fText
= '' then Text := nil else
1847 Text := TGUILabel
.Create(fText
, FFontID
);
1848 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
1851 ControlType
:= TGUIFileListBox
;
1853 Result
:= (Control
as TGUIFileListBox
);
1856 if FIndex
= -1 then FIndex
:= i
;
1861 function TGUIMenu
.AddLabel(fText
: string): TGUILabel
;
1868 Control
:= TGUILabel
.Create('', FFontID
);
1869 with Control
as TGUILabel
do
1871 FWindow
:= Self
.FWindow
;
1872 FColor
:= MENU_ITEMSCTRL_COLOR
;
1875 Text := TGUILabel
.Create(fText
, FFontID
);
1878 FColor
:= MENU_ITEMSTEXT_COLOR
;
1881 ControlType
:= TGUILabel
;
1883 Result
:= (Control
as TGUILabel
);
1886 if FIndex
= -1 then FIndex
:= i
;
1891 function TGUIMenu
.AddMemo(fText
: string; Width
, Height
: Word): TGUIMemo
;
1898 Control
:= TGUIMemo
.Create(FFontID
, Width
, Height
);
1899 with Control
as TGUIMemo
do
1901 FWindow
:= Self
.FWindow
;
1902 FColor
:= MENU_ITEMSTEXT_COLOR
;
1905 if fText
= '' then Text := nil else
1907 Text := TGUILabel
.Create(fText
, FFontID
);
1908 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
1911 ControlType
:= TGUIMemo
;
1913 Result
:= (Control
as TGUIMemo
);
1916 if FIndex
= -1 then FIndex
:= i
;
1921 procedure TGUIMenu
.UpdateIndex();
1929 if (FIndex
< 0) or (FIndex
> High(FItems
)) then
1935 if FItems
[FIndex
].Control
.Enabled
then
1944 constructor TGUIScroll
.Create
;
1949 FOnChangeEvent
:= nil;
1951 g_Texture_Get(SCROLL_LEFT
, FLeftID
);
1952 g_Texture_Get(SCROLL_RIGHT
, FRightID
);
1953 g_Texture_Get(SCROLL_MIDDLE
, FMiddleID
);
1954 g_Texture_Get(SCROLL_MARKER
, FMarkerID
);
1957 procedure TGUIScroll
.Draw
;
1963 e_Draw(FLeftID
, FX
, FY
, 0, True, False);
1964 e_Draw(FRightID
, FX
+8+(FMax
+1)*8, FY
, 0, True, False);
1966 for a
:= 0 to FMax
do
1967 e_Draw(FMiddleID
, FX
+8+a
*8, FY
, 0, True, False);
1969 e_Draw(FMarkerID
, FX
+8+FValue
*8, FY
, 0, True, False);
1972 procedure TGUIScroll
.FSetValue(a
: Integer);
1974 if a
> FMax
then FValue
:= FMax
else FValue
:= a
;
1977 function TGUIScroll
.GetWidth
: Word;
1979 Result
:= 16+(FMax
+1)*8;
1982 procedure TGUIScroll
.OnMessage(var Msg
: TMessage
);
1984 if not FEnabled
then Exit
;
1996 g_Sound_PlayEx(SCROLL_SUBSOUND
);
1997 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
1999 IK_RIGHT
, IK_KPRIGHT
:
2000 if FValue
< FMax
then
2003 g_Sound_PlayEx(SCROLL_ADDSOUND
);
2004 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2011 procedure TGUIScroll
.Update
;
2019 procedure TGUISwitch
.AddItem(Item
: string);
2021 SetLength(FItems
, Length(FItems
)+1);
2022 FItems
[High(FItems
)] := Item
;
2024 if FIndex
= -1 then FIndex
:= 0;
2027 constructor TGUISwitch
.Create(FontID
: DWORD
);
2033 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
2036 procedure TGUISwitch
.Draw
;
2040 FFont
.Draw(FX
, FY
, FItems
[FIndex
], FColor
.R
, FColor
.G
, FColor
.B
);
2043 function TGUISwitch
.GetText
: string;
2045 if FIndex
<> -1 then Result
:= FItems
[FIndex
]
2049 function TGUISwitch
.GetWidth
: Word;
2056 if FItems
= nil then Exit
;
2058 for a
:= 0 to High(FItems
) do
2060 FFont
.GetTextSize(FItems
[a
], w
, h
);
2061 if w
> Result
then Result
:= w
;
2065 procedure TGUISwitch
.OnMessage(var Msg
: TMessage
);
2067 if not FEnabled
then Exit
;
2071 if FItems
= nil then Exit
;
2076 IK_RETURN
, IK_RIGHT
, IK_KPRETURN
, IK_KPRIGHT
:
2078 if FIndex
< High(FItems
) then
2083 if @FOnChangeEvent
<> nil then
2084 FOnChangeEvent(Self
);
2092 FIndex
:= High(FItems
);
2094 if @FOnChangeEvent
<> nil then
2095 FOnChangeEvent(Self
);
2101 procedure TGUISwitch
.Update
;
2109 constructor TGUIEdit
.Create(FontID
: DWORD
);
2113 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
2118 g_Texture_Get(EDIT_LEFT
, FLeftID
);
2119 g_Texture_Get(EDIT_RIGHT
, FRightID
);
2120 g_Texture_Get(EDIT_MIDDLE
, FMiddleID
);
2123 procedure TGUIEdit
.Draw
;
2129 e_Draw(FLeftID
, FX
, FY
, 0, True, False);
2130 e_Draw(FRightID
, FX
+8+FWidth
*16, FY
, 0, True, False);
2132 for c
:= 0 to FWidth
-1 do
2133 e_Draw(FMiddleID
, FX
+8+c
*16, FY
, 0, True, False);
2135 FFont
.Draw(FX
+8, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
);
2137 if FWindow
.FActiveControl
= Self
then
2139 FFont
.GetTextSize(Copy(FText
, 1, FCaretPos
), w
, h
);
2140 h
:= e_CharFont_GetMaxHeight(FFont
.ID
);
2141 e_DrawLine(2, FX
+8+w
, FY
+h
-3, FX
+8+w
+EDIT_CURSORLEN
, FY
+h
-3,
2142 EDIT_CURSORCOLOR
.R
, EDIT_CURSORCOLOR
.G
, EDIT_CURSORCOLOR
.B
);
2146 function TGUIEdit
.GetWidth
: Word;
2148 Result
:= 16+FWidth
*16;
2151 procedure TGUIEdit
.OnMessage(var Msg
: TMessage
);
2153 if not FEnabled
then Exit
;
2162 if (wParam
in [48..57]) and (Chr(wParam
) <> '`') then
2163 if Length(Text) < FMaxLength
then
2165 Insert(Chr(wParam
), FText
, FCaretPos
+ 1);
2171 if (wParam
in [32..255]) and (Chr(wParam
) <> '`') then
2172 if Length(Text) < FMaxLength
then
2174 Insert(Chr(wParam
), FText
, FCaretPos
+ 1);
2182 Delete(FText
, FCaretPos
, 1);
2183 if FCaretPos
> 0 then Dec(FCaretPos
);
2185 IK_DELETE
: Delete(FText
, FCaretPos
+ 1, 1);
2186 IK_END
, IK_KPEND
: FCaretPos
:= Length(FText
);
2187 IK_HOME
, IK_KPHOME
: FCaretPos
:= 0;
2188 IK_LEFT
, IK_KPLEFT
: if FCaretPos
> 0 then Dec(FCaretPos
);
2189 IK_RIGHT
, IK_KPRIGHT
: if FCaretPos
< Length(FText
) then Inc(FCaretPos
);
2190 IK_RETURN
, IK_KPRETURN
:
2193 if FActiveControl
<> Self
then
2196 if @FOnEnterEvent
<> nil then FOnEnterEvent(Self
);
2200 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
2201 else SetActive(nil);
2202 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2209 procedure TGUIEdit
.SetText(Text: string);
2211 if Length(Text) > FMaxLength
then SetLength(Text, FMaxLength
);
2213 FCaretPos
:= Length(FText
);
2216 procedure TGUIEdit
.Update
;
2223 constructor TGUIKeyRead
.Create(FontID
: DWORD
);
2227 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
2230 procedure TGUIKeyRead
.Draw
;
2234 FFont
.Draw(FX
, FY
, IfThen(FIsQuery
, KEYREAD_QUERY
, IfThen(FKey
<> 0, e_KeyNames
[FKey
], KEYREAD_CLEAR
)),
2235 FColor
.R
, FColor
.G
, FColor
.B
);
2238 function TGUIKeyRead
.GetWidth
: Word;
2245 for a
:= 0 to 255 do
2247 FFont
.GetTextSize(e_KeyNames
[a
], w
, h
);
2248 Result
:= Max(Result
, w
);
2251 FFont
.GetTextSize(KEYREAD_QUERY
, w
, h
);
2252 if w
> Result
then Result
:= w
;
2254 FFont
.GetTextSize(KEYREAD_CLEAR
, w
, h
);
2255 if w
> Result
then Result
:= w
;
2258 function TGUIKeyRead
.WantActivationKey (key
: LongInt): Boolean;
2261 (key
= IK_BACKSPACE
) or
2262 (key
= IK_LEFT
) or (key
= IK_RIGHT
) or
2263 (key
= IK_KPLEFT
) or (key
= IK_KPRIGHT
) or
2267 procedure TGUIKeyRead
.OnMessage(var Msg
: TMessage
);
2268 procedure actDefCtl ();
2271 if FDefControl
<> '' then
2272 SetActive(GetControl(FDefControl
))
2280 if not FEnabled
then
2289 if FIsQuery
then actDefCtl();
2292 IK_RETURN
, IK_KPRETURN
:
2294 if not FIsQuery
then
2297 if FActiveControl
<> Self
then
2304 FKey
:= IK_ENTER
; // <Enter>
2309 IK_BACKSPACE
: // clear keybinding if we aren't waiting for a key
2311 if not FIsQuery
then
2321 if not FIsQuery
and (wParam
= IK_BACKSPACE
) then
2326 else if FIsQuery
and (wParam
<> IK_ENTER
) and (wParam
<> IK_KPRETURN
) then // Not <Enter
2328 e_WriteLog(Format('HIT! %s', ['3']), MSG_WARNING
);
2329 if e_KeyNames
[wParam
] <> '' then
2340 constructor TGUIModelView
.Create
;
2347 destructor TGUIModelView
.Destroy
;
2354 procedure TGUIModelView
.Draw
;
2358 DrawBox(FX
, FY
, 4, 4);
2360 if FModel
<> nil then FModel
.Draw(FX
+4, FY
+4);
2363 procedure TGUIModelView
.NextAnim();
2365 if FModel
= nil then
2368 if FModel
.Animation
< A_PAIN
then
2369 FModel
.ChangeAnimation(FModel
.Animation
+1, True)
2371 FModel
.ChangeAnimation(A_STAND
, True);
2374 procedure TGUIModelView
.NextWeapon();
2376 if FModel
= nil then
2379 if FModel
.Weapon
< WEAPON_SUPERPULEMET
then
2380 FModel
.SetWeapon(FModel
.Weapon
+1)
2382 FModel
.SetWeapon(WEAPON_KASTET
);
2385 procedure TGUIModelView
.OnMessage(var Msg
: TMessage
);
2391 procedure TGUIModelView
.SetColor(Red
, Green
, Blue
: Byte);
2393 if FModel
<> nil then FModel
.SetColor(Red
, Green
, Blue
);
2396 procedure TGUIModelView
.SetModel(ModelName
: string);
2400 FModel
:= g_PlayerModel_Get(ModelName
);
2403 procedure TGUIModelView
.Update
;
2410 if FModel
<> nil then FModel
.Update
;
2415 constructor TGUIMapPreview
.Create();
2421 destructor TGUIMapPreview
.Destroy();
2427 procedure TGUIMapPreview
.Draw();
2434 DrawBox(FX
, FY
, MAPPREVIEW_WIDTH
, MAPPREVIEW_HEIGHT
);
2436 if (FMapSize
.X
<= 0) or (FMapSize
.Y
<= 0) then
2439 e_DrawFillQuad(FX
+4, FY
+4,
2440 FX
+4 + Trunc(FMapSize
.X
/ FScale
) - 1,
2441 FY
+4 + Trunc(FMapSize
.Y
/ FScale
) - 1,
2444 if FMapData
<> nil then
2445 for a
:= 0 to High(FMapData
) do
2448 if X1
> MAPPREVIEW_WIDTH
*16 then Continue
;
2449 if Y1
> MAPPREVIEW_HEIGHT
*16 then Continue
;
2451 if X2
< 0 then Continue
;
2452 if Y2
< 0 then Continue
;
2454 if X2
> MAPPREVIEW_WIDTH
*16 then X2
:= MAPPREVIEW_WIDTH
*16;
2455 if Y2
> MAPPREVIEW_HEIGHT
*16 then Y2
:= MAPPREVIEW_HEIGHT
*16;
2457 if X1
< 0 then X1
:= 0;
2458 if Y1
< 0 then Y1
:= 0;
2499 if ((X2
-X1
) > 0) and ((Y2
-Y1
) > 0) then
2500 e_DrawFillQuad(FX
+4 + X1
, FY
+4 + Y1
,
2501 FX
+4 + X2
- 1, FY
+4 + Y2
- 1, r
, g
, b
, 0);
2505 procedure TGUIMapPreview
.OnMessage(var Msg
: TMessage
);
2511 procedure TGUIMapPreview
.SetMap(Res
: string);
2514 MapReader
: TMapReader_1
;
2515 panels
: TPanelsRec1Array
;
2516 header
: TMapHeaderRec_1
;
2523 FileName
:= g_ExtractWadName(Res
);
2525 WAD
:= TWADFile
.Create();
2526 if not WAD
.ReadFile(FileName
) then
2532 //k8: ignores path again
2533 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
2541 MapReader
:= TMapReader_1
.Create();
2543 if not MapReader
.LoadMap(Data
) then
2556 panels
:= MapReader
.GetPanels();
2557 header
:= MapReader
.GetMapHeader();
2559 FMapSize
.X
:= header
.Width
div 16;
2560 FMapSize
.Y
:= header
.Height
div 16;
2562 rX
:= Ceil(header
.Width
/ (MAPPREVIEW_WIDTH
*256.0));
2563 rY
:= Ceil(header
.Height
/ (MAPPREVIEW_HEIGHT
*256.0));
2564 FScale
:= max(rX
, rY
);
2568 if panels
<> nil then
2569 for a
:= 0 to High(panels
) do
2570 if WordBool(panels
[a
].PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or
2571 PANEL_STEP
or PANEL_WATER
or
2572 PANEL_ACID1
or PANEL_ACID2
)) then
2574 SetLength(FMapData
, Length(FMapData
)+1);
2575 with FMapData
[High(FMapData
)] do
2577 X1
:= panels
[a
].X
div 16;
2578 Y1
:= panels
[a
].Y
div 16;
2580 X2
:= (panels
[a
].X
+ panels
[a
].Width
) div 16;
2581 Y2
:= (panels
[a
].Y
+ panels
[a
].Height
) div 16;
2583 X1
:= Trunc(X1
/FScale
+ 0.5);
2584 Y1
:= Trunc(Y1
/FScale
+ 0.5);
2585 X2
:= Trunc(X2
/FScale
+ 0.5);
2586 Y2
:= Trunc(Y2
/FScale
+ 0.5);
2588 if (X1
<> X2
) or (Y1
<> Y2
) then
2596 PanelType
:= panels
[a
].PanelType
;
2605 procedure TGUIMapPreview
.ClearMap();
2607 SetLength(FMapData
, 0);
2614 procedure TGUIMapPreview
.Update();
2620 function TGUIMapPreview
.GetScaleStr(): String;
2622 if FScale
> 0.0 then
2624 Result
:= FloatToStrF(FScale
*16.0, ffFixed
, 3, 3);
2625 while (Result
[Length(Result
)] = '0') do
2626 Delete(Result
, Length(Result
), 1);
2627 if (Result
[Length(Result
)] = ',') or (Result
[Length(Result
)] = '.') then
2628 Delete(Result
, Length(Result
), 1);
2629 Result
:= '1 : ' + Result
;
2637 procedure TGUIListBox
.AddItem(Item
: string);
2639 SetLength(FItems
, Length(FItems
)+1);
2640 FItems
[High(FItems
)] := Item
;
2642 if FSort
then g_Basic
.Sort(FItems
);
2645 procedure TGUIListBox
.Clear();
2653 constructor TGUIListBox
.Create(FontID
: DWORD
; Width
, Height
: Word);
2657 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
2662 FOnChangeEvent
:= nil;
2664 FDrawScroll
:= True;
2667 procedure TGUIListBox
.Draw
;
2675 if FDrawBack
then DrawBox(FX
, FY
, FWidth
+1, FHeight
);
2677 DrawScroll(FX
+4+FWidth
*16, FY
+4, FHeight
, (FStartLine
> 0) and (FItems
<> nil),
2678 (FStartLine
+FHeight
-1 < High(FItems
)) and (FItems
<> nil));
2680 if FItems
<> nil then
2681 for a
:= FStartLine
to Min(High(FItems
), FStartLine
+FHeight
-1) do
2685 FFont
.GetTextSize(s
, w2
, h2
);
2686 while (Length(s
) > 0) and (w2
> FWidth
*16) do
2688 SetLength(s
, Length(s
)-1);
2689 FFont
.GetTextSize(s
, w2
, h2
);
2693 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, s
, FActiveColor
.R
, FActiveColor
.G
, FActiveColor
.B
)
2695 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, s
, FUnActiveColor
.R
, FUnActiveColor
.G
, FUnActiveColor
.B
);
2699 function TGUIListBox
.GetHeight
: Word;
2701 Result
:= 8+FHeight
*16;
2704 function TGUIListBox
.GetWidth
: Word;
2706 Result
:= 8+(FWidth
+1)*16;
2709 procedure TGUIListBox
.OnMessage(var Msg
: TMessage
);
2713 if not FEnabled
then Exit
;
2717 if FItems
= nil then Exit
;
2730 FIndex
:= High(FItems
);
2731 FStartLine
:= Max(High(FItems
)-FHeight
+1, 0);
2733 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
:
2737 if FIndex
< FStartLine
then Dec(FStartLine
);
2738 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2740 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
:
2741 if FIndex
< High(FItems
) then
2744 if FIndex
> FStartLine
+FHeight
-1 then Inc(FStartLine
);
2745 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2747 IK_RETURN
, IK_KPRETURN
:
2750 if FActiveControl
<> Self
then SetActive(Self
)
2752 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
2753 else SetActive(nil);
2757 for a
:= 0 to High(FItems
) do
2758 if (Length(FItems
[a
]) > 0) and (LowerCase(FItems
[a
][1]) = LowerCase(Chr(wParam
))) then
2761 FStartLine
:= Min(Max(FIndex
-1, 0), Length(FItems
)-FHeight
);
2762 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2768 function TGUIListBox
.SelectedItem(): String;
2772 if (FIndex
< 0) or (FItems
= nil) or
2773 (FIndex
> High(FItems
)) then
2776 Result
:= FItems
[FIndex
];
2779 procedure TGUIListBox
.FSetItems(Items
: SArray
);
2781 if FItems
<> nil then
2789 if FSort
then g_Basic
.Sort(FItems
);
2792 procedure TGUIListBox
.SelectItem(Item
: String);
2796 if FItems
= nil then
2800 Item
:= LowerCase(Item
);
2802 for a
:= 0 to High(FItems
) do
2803 if LowerCase(FItems
[a
]) = Item
then
2809 if FIndex
< FHeight
then
2812 FStartLine
:= Min(FIndex
, Length(FItems
)-FHeight
);
2815 procedure TGUIListBox
.FSetIndex(aIndex
: Integer);
2817 if FItems
= nil then
2820 if (aIndex
< 0) or (aIndex
> High(FItems
)) then
2825 if FIndex
<= FHeight
then
2828 FStartLine
:= Min(FIndex
, Length(FItems
)-FHeight
);
2833 procedure TGUIFileListBox
.OnMessage(var Msg
: TMessage
);
2837 if not FEnabled
then
2840 if FItems
= nil then
2851 if @FOnChangeEvent
<> nil then
2852 FOnChangeEvent(Self
);
2857 FIndex
:= High(FItems
);
2858 FStartLine
:= Max(High(FItems
)-FHeight
+1, 0);
2859 if @FOnChangeEvent
<> nil then
2860 FOnChangeEvent(Self
);
2863 IK_PAGEUP
, IK_KPPAGEUP
:
2865 if FIndex
> FHeight
then
2866 FIndex
:= FIndex
-FHeight
2870 if FStartLine
> FHeight
then
2871 FStartLine
:= FStartLine
-FHeight
2876 IK_PAGEDN
, IK_KPPAGEDN
:
2878 if FIndex
< High(FItems
)-FHeight
then
2879 FIndex
:= FIndex
+FHeight
2881 FIndex
:= High(FItems
);
2883 if FStartLine
< High(FItems
)-FHeight
then
2884 FStartLine
:= FStartLine
+FHeight
2886 FStartLine
:= High(FItems
)-FHeight
+1;
2889 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
:
2893 if FIndex
< FStartLine
then
2895 if @FOnChangeEvent
<> nil then
2896 FOnChangeEvent(Self
);
2899 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
:
2900 if FIndex
< High(FItems
) then
2903 if FIndex
> FStartLine
+FHeight
-1 then
2905 if @FOnChangeEvent
<> nil then
2906 FOnChangeEvent(Self
);
2909 IK_RETURN
, IK_KPRETURN
:
2912 if FActiveControl
<> Self
then
2916 if FItems
[FIndex
][1] = #29 then // Ïàïêà
2918 OpenDir(FPath
+Copy(FItems
[FIndex
], 2, 255));
2923 if FDefControl
<> '' then
2924 SetActive(GetControl(FDefControl
))
2932 for a
:= 0 to High(FItems
) do
2933 if ( (Length(FItems
[a
]) > 0) and
2934 (LowerCase(FItems
[a
][1]) = LowerCase(Chr(wParam
))) ) or
2935 ( (Length(FItems
[a
]) > 1) and
2936 (FItems
[a
][1] = #29) and // Ïàïêà
2937 (LowerCase(FItems
[a
][2]) = LowerCase(Chr(wParam
))) ) then
2940 FStartLine
:= Min(Max(FIndex
-1, 0), Length(FItems
)-FHeight
);
2941 if @FOnChangeEvent
<> nil then
2942 FOnChangeEvent(Self
);
2948 procedure TGUIFileListBox
.OpenDir(path
: String);
2956 path
:= IncludeTrailingPathDelimiter(path
);
2957 path
:= ExpandFileName(path
);
2962 if FindFirst(path
+'*', faDirectory
, SR
) = 0 then
2964 if not LongBool(SR
.Attr
and faDirectory
) then
2966 if (SR
.Name
= '.') or
2967 ((SR
.Name
= '..') and (path
= ExpandFileName(FBasePath
))) then
2970 AddItem(#1 + SR
.Name
);
2971 until FindNext(SR
) <> 0;
2981 if i
= 0 then i
:= length(sm
)+1;
2982 sc
:= Copy(sm
, 1, i
-1);
2984 if FindFirst(path
+sc
, faAnyFile
, SR
) = 0 then repeat AddItem(SR
.Name
); until FindNext(SR
) <> 0;
2988 for i
:= 0 to High(FItems
) do
2989 if FItems
[i
][1] = #1 then
2990 FItems
[i
][1] := #29;
2995 procedure TGUIFileListBox
.SetBase(path
: String);
3001 function TGUIFileListBox
.SelectedItem(): String;
3005 if (FIndex
= -1) or (FItems
= nil) or
3006 (FIndex
> High(FItems
)) or
3007 (FItems
[FIndex
][1] = '/') or
3008 (FItems
[FIndex
][1] = '\') then
3011 Result
:= FPath
+ FItems
[FIndex
];
3014 procedure TGUIFileListBox
.UpdateFileList();
3018 if (FIndex
= -1) or (FItems
= nil) or
3019 (FIndex
> High(FItems
)) or
3020 (FItems
[FIndex
][1] = '/') or
3021 (FItems
[FIndex
][1] = '\') then
3024 fn
:= FItems
[FIndex
];
3034 procedure TGUIMemo
.Clear
;
3040 constructor TGUIMemo
.Create(FontID
: DWORD
; Width
, Height
: Word);
3044 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
3049 FDrawScroll
:= True;
3052 procedure TGUIMemo
.Draw
;
3058 if FDrawBack
then DrawBox(FX
, FY
, FWidth
+1, FHeight
);
3060 DrawScroll(FX
+4+FWidth
*16, FY
+4, FHeight
, (FStartLine
> 0) and (FLines
<> nil),
3061 (FStartLine
+FHeight
-1 < High(FLines
)) and (FLines
<> nil));
3063 if FLines
<> nil then
3064 for a
:= FStartLine
to Min(High(FLines
), FStartLine
+FHeight
-1) do
3065 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, FLines
[a
], FColor
.R
, FColor
.G
, FColor
.B
);
3068 function TGUIMemo
.GetHeight
: Word;
3070 Result
:= 8+FHeight
*16;
3073 function TGUIMemo
.GetWidth
: Word;
3075 Result
:= 8+(FWidth
+1)*16;
3078 procedure TGUIMemo
.OnMessage(var Msg
: TMessage
);
3080 if not FEnabled
then Exit
;
3084 if FLines
= nil then Exit
;
3090 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
:
3091 if FStartLine
> 0 then
3093 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
:
3094 if FStartLine
< Length(FLines
)-FHeight
then
3096 IK_RETURN
, IK_KPRETURN
:
3099 if FActiveControl
<> Self
then
3105 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
3106 else SetActive(nil);
3112 procedure TGUIMemo
.SetText(Text: string);
3115 FLines
:= GetLines(Text, FFont
.ID
, FWidth
*16);
3120 procedure TGUIimage
.ClearImage();
3122 if FImageRes
= '' then Exit
;
3124 g_Texture_Delete(FImageRes
);
3128 constructor TGUIimage
.Create();
3135 destructor TGUIimage
.Destroy();
3140 procedure TGUIimage
.Draw();
3146 if FImageRes
= '' then
3148 if g_Texture_Get(FDefaultRes
, ID
) then e_Draw(ID
, FX
, FY
, 0, True, False);
3151 if g_Texture_Get(FImageRes
, ID
) then e_Draw(ID
, FX
, FY
, 0, True, False);
3154 procedure TGUIimage
.OnMessage(var Msg
: TMessage
);
3159 procedure TGUIimage
.SetImage(Res
: string);
3163 if g_Texture_CreateWADEx(Res
, Res
) then FImageRes
:= Res
;
3166 procedure TGUIimage
.Update();