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 e_graphics
, e_input
, e_log
, g_playermodel
, g_basic
, MAPDEF
, 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
;
118 FRightAlign
: Boolean; //HACK! this works only for "normal" menus, only for menu text labels, and generally sux. sorry.
119 FMaxWidth
: Integer; //HACK! used for right-aligning labels
122 procedure OnMessage(var Msg
: TMessage
); virtual;
123 procedure Update
; virtual;
124 procedure Draw
; virtual;
125 function GetWidth(): Integer; virtual;
126 function GetHeight(): Integer; virtual;
127 function WantActivationKey (key
: LongInt): Boolean; virtual;
128 property X
: Integer read FX write FX
;
129 property Y
: Integer read FY write FY
;
130 property Enabled
: Boolean read FEnabled write FEnabled
;
131 property Name
: string read FName write FName
;
132 property UserData
: Pointer read FUserData write FUserData
;
133 property RightAlign
: Boolean read FRightAlign write FRightAlign
; // for menu
138 FActiveControl
: TGUIControl
;
140 FPrevWindow
: TGUIWindow
;
142 FBackTexture
: string;
143 FMainWindow
: Boolean;
144 FOnKeyDown
: TOnKeyDownEvent
;
145 FOnKeyDownEx
: TOnKeyDownEventEx
;
146 FOnCloseEvent
: TOnCloseEvent
;
147 FOnShowEvent
: TOnShowEvent
;
150 Childs
: array of TGUIControl
;
151 constructor Create(Name
: string);
152 destructor Destroy
; override;
153 function AddChild(Child
: TGUIControl
): TGUIControl
;
154 procedure OnMessage(var Msg
: TMessage
);
157 procedure SetActive(Control
: TGUIControl
);
158 function GetControl(Name
: string): TGUIControl
;
159 property OnKeyDown
: TOnKeyDownEvent read FOnKeyDown write FOnKeyDown
;
160 property OnKeyDownEx
: TOnKeyDownEventEx read FOnKeyDownEx write FOnKeyDownEx
;
161 property OnClose
: TOnCloseEvent read FOnCloseEvent write FOnCloseEvent
;
162 property OnShow
: TOnShowEvent read FOnShowEvent write FOnShowEvent
;
163 property Name
: string read FName
;
164 property DefControl
: string read FDefControl write FDefControl
;
165 property BackTexture
: string read FBackTexture write FBackTexture
;
166 property MainWindow
: Boolean read FMainWindow write FMainWindow
;
167 property UserData
: Pointer read FUserData write FUserData
;
170 TGUITextButton
= class(TGUIControl
)
179 ProcEx
: procedure (sender
: TGUITextButton
);
180 constructor Create(aProc
: Pointer; FontID
: DWORD
; Text: string);
181 destructor Destroy(); override;
182 procedure OnMessage(var Msg
: TMessage
); override;
183 procedure Update(); override;
184 procedure Draw(); override;
185 function GetWidth(): Integer; override;
186 function GetHeight(): Integer; override;
187 procedure Click(Silent
: Boolean = False);
188 property Caption
: string read FText write FText
;
189 property Color
: TRGB read FColor write FColor
;
190 property Font
: TFont read FFont write FFont
;
191 property ShowWindow
: string read FShowWindow write FShowWindow
;
194 TGUILabel
= class(TGUIControl
)
200 FOnClickEvent
: TOnClickEvent
;
202 constructor Create(Text: string; FontID
: DWORD
);
203 procedure OnMessage(var Msg
: TMessage
); override;
204 procedure Draw
; override;
205 function GetWidth
: Integer; override;
206 function GetHeight
: Integer; override;
207 property OnClick
: TOnClickEvent read FOnClickEvent write FOnClickEvent
;
208 property FixedLength
: Word read FFixedLen write FFixedLen
;
209 property Text: string read FText write FText
;
210 property Color
: TRGB read FColor write FColor
;
211 property Font
: TFont read FFont write FFont
;
214 TGUIScroll
= class(TGUIControl
)
222 FOnChangeEvent
: TOnChangeEvent
;
223 procedure FSetValue(a
: Integer);
225 constructor Create();
226 procedure OnMessage(var Msg
: TMessage
); override;
227 procedure Update
; override;
228 procedure Draw
; override;
229 function GetWidth(): Integer; override;
230 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
231 property Max
: Word read FMax write FMax
;
232 property Value
: Integer read FValue write FSetValue
;
235 TGUISwitch
= class(TGUIControl
)
238 FItems
: array of string;
241 FOnChangeEvent
: TOnChangeEvent
;
243 constructor Create(FontID
: DWORD
);
244 procedure OnMessage(var Msg
: TMessage
); override;
245 procedure AddItem(Item
: string);
246 procedure Update
; override;
247 procedure Draw
; override;
248 function GetWidth(): Integer; override;
249 function GetText
: string;
250 property ItemIndex
: Integer read FIndex write FIndex
;
251 property Color
: TRGB read FColor write FColor
;
252 property Font
: TFont read FFont write FFont
;
253 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
256 TGUIEdit
= class(TGUIControl
)
264 FOnlyDigits
: Boolean;
268 FOnChangeEvent
: TOnChangeEvent
;
269 FOnEnterEvent
: TOnEnterEvent
;
270 procedure SetText(Text: string);
272 constructor Create(FontID
: DWORD
);
273 procedure OnMessage(var Msg
: TMessage
); override;
274 procedure Update
; override;
275 procedure Draw
; override;
276 function GetWidth(): Integer; override;
277 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
278 property OnEnter
: TOnEnterEvent read FOnEnterEvent write FOnEnterEvent
;
279 property Width
: Word read FWidth write FWidth
;
280 property MaxLength
: Word read FMaxLength write FMaxLength
;
281 property OnlyDigits
: Boolean read FOnlyDigits write FOnlyDigits
;
282 property Text: string read FText write SetText
;
283 property Color
: TRGB read FColor write FColor
;
284 property Font
: TFont read FFont write FFont
;
287 TGUIKeyRead
= class(TGUIControl
)
294 constructor Create(FontID
: DWORD
);
295 procedure OnMessage(var Msg
: TMessage
); override;
296 procedure Draw
; override;
297 function GetWidth(): Integer; override;
298 function WantActivationKey (key
: LongInt): Boolean; override;
299 property Key
: Word read FKey write FKey
;
300 property Color
: TRGB read FColor write FColor
;
301 property Font
: TFont read FFont write FFont
;
305 TGUIKeyRead2
= class(TGUIControl
)
310 FKey0
, FKey1
: Word; // this should be an array. sorry.
313 FMaxKeyNameWdt
: Integer;
315 constructor Create(FontID
: DWORD
);
316 procedure OnMessage(var Msg
: TMessage
); override;
317 procedure Draw
; override;
318 function GetWidth(): Integer; override;
319 function WantActivationKey (key
: LongInt): Boolean; override;
320 property Key0
: Word read FKey0 write FKey0
;
321 property Key1
: Word read FKey1 write FKey1
;
322 property Color
: TRGB read FColor write FColor
;
323 property Font
: TFont read FFont write FFont
;
326 TGUIModelView
= class(TGUIControl
)
328 FModel
: TPlayerModel
;
332 destructor Destroy
; override;
333 procedure OnMessage(var Msg
: TMessage
); override;
334 procedure SetModel(ModelName
: string);
335 procedure SetColor(Red
, Green
, Blue
: Byte);
336 procedure NextAnim();
337 procedure NextWeapon();
338 procedure Update
; override;
339 procedure Draw
; override;
340 property Model
: TPlayerModel read FModel
;
343 TPreviewPanel
= record
344 X1
, Y1
, X2
, Y2
: Integer;
348 TGUIMapPreview
= class(TGUIControl
)
350 FMapData
: array of TPreviewPanel
;
354 constructor Create();
355 destructor Destroy(); override;
356 procedure OnMessage(var Msg
: TMessage
); override;
357 procedure SetMap(Res
: string);
358 procedure ClearMap();
359 procedure Update(); override;
360 procedure Draw(); override;
361 function GetScaleStr
: String;
364 TGUIImage
= class(TGUIControl
)
369 constructor Create();
370 destructor Destroy(); override;
371 procedure OnMessage(var Msg
: TMessage
); override;
372 procedure SetImage(Res
: string);
373 procedure ClearImage();
374 procedure Update(); override;
375 procedure Draw(); override;
376 property DefaultRes
: string read FDefaultRes write FDefaultRes
;
379 TGUIListBox
= class(TGUIControl
)
383 FUnActiveColor
: TRGB
;
391 FDrawScroll
: Boolean;
392 FOnChangeEvent
: TOnChangeEvent
;
394 procedure FSetItems(Items
: SArray
);
395 procedure FSetIndex(aIndex
: Integer);
398 constructor Create(FontID
: DWORD
; Width
, Height
: Word);
399 procedure OnMessage(var Msg
: TMessage
); override;
400 procedure Draw(); override;
401 procedure AddItem(Item
: String);
402 procedure SelectItem(Item
: String);
404 function GetWidth(): Integer; override;
405 function GetHeight(): Integer; override;
406 function SelectedItem(): String;
408 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
409 property Sort
: Boolean read FSort write FSort
;
410 property ItemIndex
: Integer read FIndex write FSetIndex
;
411 property Items
: SArray read FItems write FSetItems
;
412 property DrawBack
: Boolean read FDrawBack write FDrawBack
;
413 property DrawScrollBar
: Boolean read FDrawScroll write FDrawScroll
;
414 property ActiveColor
: TRGB read FActiveColor write FActiveColor
;
415 property UnActiveColor
: TRGB read FUnActiveColor write FUnActiveColor
;
416 property Font
: TFont read FFont write FFont
;
419 TGUIFileListBox
= class (TGUIListBox
)
426 procedure OpenDir(path
: String);
429 procedure OnMessage(var Msg
: TMessage
); override;
430 procedure SetBase(path
: String);
431 function SelectedItem(): String;
432 procedure UpdateFileList();
434 property Dirs
: Boolean read FDirs write FDirs
;
435 property FileMask
: String read FFileMask write FFileMask
;
436 property Path
: String read FPath
;
439 TGUIMemo
= class(TGUIControl
)
448 FDrawScroll
: Boolean;
450 constructor Create(FontID
: DWORD
; Width
, Height
: Word);
451 procedure OnMessage(var Msg
: TMessage
); override;
452 procedure Draw
; override;
454 function GetWidth(): Integer; override;
455 function GetHeight(): Integer; override;
456 procedure SetText(Text: string);
457 property DrawBack
: Boolean read FDrawBack write FDrawBack
;
458 property DrawScrollBar
: Boolean read FDrawScroll write FDrawScroll
;
459 property Color
: TRGB read FColor write FColor
;
460 property Font
: TFont read FFont write FFont
;
463 TGUIMainMenu
= class(TGUIControl
)
465 FButtons
: array of TGUITextButton
;
473 constructor Create(FontID
: DWORD
; Header
: string);
474 destructor Destroy
; override;
475 procedure OnMessage(var Msg
: TMessage
); override;
476 function AddButton(fProc
: Pointer; Caption
: string; ShowWindow
: string = ''): TGUITextButton
;
477 function GetButton(aName
: string): TGUITextButton
;
478 procedure EnableButton(aName
: string; e
: Boolean);
479 procedure AddSpace();
480 procedure Update
; override;
481 procedure Draw
; override;
484 TControlType
= class of TGUIControl
;
486 PMenuItem
= ^TMenuItem
;
489 ControlType
: TControlType
;
490 Control
: TGUIControl
;
493 TGUIMenu
= class(TGUIControl
)
495 FItems
: array of TMenuItem
;
503 function NewItem(): Integer;
505 constructor Create(HeaderFont
, ItemsFont
: DWORD
; Header
: string);
506 destructor Destroy
; override;
507 procedure OnMessage(var Msg
: TMessage
); override;
508 procedure AddSpace();
509 procedure AddLine(fText
: string);
510 procedure AddText(fText
: string; MaxWidth
: Word);
511 function AddLabel(fText
: string): TGUILabel
;
512 function AddButton(Proc
: Pointer; fText
: string; _ShowWindow
: string = ''): TGUITextButton
;
513 function AddScroll(fText
: string): TGUIScroll
;
514 function AddSwitch(fText
: string): TGUISwitch
;
515 function AddEdit(fText
: string): TGUIEdit
;
516 function AddKeyRead(fText
: string): TGUIKeyRead
;
517 function AddKeyRead2(fText
: string): TGUIKeyRead2
;
518 function AddList(fText
: string; Width
, Height
: Word): TGUIListBox
;
519 function AddFileList(fText
: string; Width
, Height
: Word): TGUIFileListBox
;
520 function AddMemo(fText
: string; Width
, Height
: Word): TGUIMemo
;
522 function GetControl(aName
: string): TGUIControl
;
523 function GetControlsText(aName
: string): TGUILabel
;
524 procedure Draw
; override;
525 procedure Update
; override;
526 procedure UpdateIndex();
527 property Align
: Boolean read FAlign write FAlign
;
528 property Left
: Integer read FLeft write FLeft
;
529 property YesNo
: Boolean read FYesNo write FYesNo
;
533 g_GUIWindows
: array of TGUIWindow
;
534 g_ActiveWindow
: TGUIWindow
= nil;
536 procedure g_GUI_Init();
537 function g_GUI_AddWindow(Window
: TGUIWindow
): TGUIWindow
;
538 function g_GUI_GetWindow(Name
: string): TGUIWindow
;
539 procedure g_GUI_ShowWindow(Name
: string);
540 procedure g_GUI_HideWindow(PlaySound
: Boolean = True);
541 function g_GUI_Destroy(): Boolean;
542 procedure g_GUI_SaveMenuPos();
543 procedure g_GUI_LoadMenuPos();
548 GL
, GLExt
, g_textures
, g_sound
, SysUtils
,
549 g_game
, Math
, StrUtils
, g_player
, g_options
,
550 g_map
, g_weapons
, xdynrec
;
553 Box
: Array [0..8] of DWORD
;
554 Saved_Windows
: SArray
;
556 procedure g_GUI_Init();
558 g_Texture_Get(BOX1
, Box
[0]);
559 g_Texture_Get(BOX2
, Box
[1]);
560 g_Texture_Get(BOX3
, Box
[2]);
561 g_Texture_Get(BOX4
, Box
[3]);
562 g_Texture_Get(BOX5
, Box
[4]);
563 g_Texture_Get(BOX6
, Box
[5]);
564 g_Texture_Get(BOX7
, Box
[6]);
565 g_Texture_Get(BOX8
, Box
[7]);
566 g_Texture_Get(BOX9
, Box
[8]);
569 function g_GUI_Destroy(): Boolean;
573 Result
:= (Length(g_GUIWindows
) > 0);
575 for i
:= 0 to High(g_GUIWindows
) do
576 g_GUIWindows
[i
].Free();
579 g_ActiveWindow
:= nil;
582 function g_GUI_AddWindow(Window
: TGUIWindow
): TGUIWindow
;
584 SetLength(g_GUIWindows
, Length(g_GUIWindows
)+1);
585 g_GUIWindows
[High(g_GUIWindows
)] := Window
;
590 function g_GUI_GetWindow(Name
: string): TGUIWindow
;
596 if g_GUIWindows
<> nil then
597 for i
:= 0 to High(g_GUIWindows
) do
598 if g_GUIWindows
[i
].FName
= Name
then
600 Result
:= g_GUIWindows
[i
];
604 Assert(Result
<> nil, 'GUI_Window "'+Name
+'" not found');
607 procedure g_GUI_ShowWindow(Name
: string);
611 if g_GUIWindows
= nil then
614 for i
:= 0 to High(g_GUIWindows
) do
615 if g_GUIWindows
[i
].FName
= Name
then
617 g_GUIWindows
[i
].FPrevWindow
:= g_ActiveWindow
;
618 g_ActiveWindow
:= g_GUIWindows
[i
];
620 if g_ActiveWindow
.MainWindow
then
621 g_ActiveWindow
.FPrevWindow
:= nil;
623 if g_ActiveWindow
.FDefControl
<> '' then
624 g_ActiveWindow
.SetActive(g_ActiveWindow
.GetControl(g_ActiveWindow
.FDefControl
))
626 g_ActiveWindow
.SetActive(nil);
628 if @g_ActiveWindow
.FOnShowEvent
<> nil then
629 g_ActiveWindow
.FOnShowEvent();
635 procedure g_GUI_HideWindow(PlaySound
: Boolean = True);
637 if g_ActiveWindow
<> nil then
639 if @g_ActiveWindow
.OnClose
<> nil then
640 g_ActiveWindow
.OnClose();
641 g_ActiveWindow
:= g_ActiveWindow
.FPrevWindow
;
643 g_Sound_PlayEx(WINDOW_CLOSESOUND
);
647 procedure g_GUI_SaveMenuPos();
652 SetLength(Saved_Windows
, 0);
653 win
:= g_ActiveWindow
;
657 len
:= Length(Saved_Windows
);
658 SetLength(Saved_Windows
, len
+ 1);
660 Saved_Windows
[len
] := win
.Name
;
662 if win
.MainWindow
then
665 win
:= win
.FPrevWindow
;
669 procedure g_GUI_LoadMenuPos();
671 i
, j
, k
, len
: Integer;
674 g_ActiveWindow
:= nil;
675 len
:= Length(Saved_Windows
);
680 // Îêíî ñ ãëàâíûì ìåíþ:
681 g_GUI_ShowWindow(Saved_Windows
[len
-1]);
683 // Íå ïåðåêëþ÷èëîñü (èëè íåêóäà äàëüøå):
684 if (len
= 1) or (g_ActiveWindow
= nil) then
687 // Èùåì êíîïêè â îñòàëüíûõ îêíàõ:
688 for k
:= len
-1 downto 1 do
692 for i
:= 0 to Length(g_ActiveWindow
.Childs
)-1 do
694 if g_ActiveWindow
.Childs
[i
] is TGUIMainMenu
then
695 begin // GUI_MainMenu
696 with TGUIMainMenu(g_ActiveWindow
.Childs
[i
]) do
697 for j
:= 0 to Length(FButtons
)-1 do
698 if FButtons
[j
].ShowWindow
= Saved_Windows
[k
-1] then
700 FButtons
[j
].Click(True);
706 if g_ActiveWindow
.Childs
[i
] is TGUIMenu
then
707 with TGUIMenu(g_ActiveWindow
.Childs
[i
]) do
708 for j
:= 0 to Length(FItems
)-1 do
709 if FItems
[j
].ControlType
= TGUITextButton
then
710 if TGUITextButton(FItems
[j
].Control
).ShowWindow
= Saved_Windows
[k
-1] then
712 TGUITextButton(FItems
[j
].Control
).Click(True);
723 (g_ActiveWindow
.Name
= Saved_Windows
[k
]) then
728 procedure DrawBox(X
, Y
: Integer; Width
, Height
: Word);
730 e_Draw(Box
[0], X
, Y
, 0, False, False);
731 e_DrawFill(Box
[1], X
+4, Y
, Width
*4, 1, 0, False, False);
732 e_Draw(Box
[2], X
+4+Width
*16, Y
, 0, False, False);
733 e_DrawFill(Box
[3], X
, Y
+4, 1, Height
*4, 0, False, False);
734 e_DrawFill(Box
[4], X
+4, Y
+4, Width
, Height
, 0, False, False);
735 e_DrawFill(Box
[5], X
+4+Width
*16, Y
+4, 1, Height
*4, 0, False, False);
736 e_Draw(Box
[6], X
, Y
+4+Height
*16, 0, False, False);
737 e_DrawFill(Box
[7], X
+4, Y
+4+Height
*16, Width
*4, 1, 0, False, False);
738 e_Draw(Box
[8], X
+4+Width
*16, Y
+4+Height
*16, 0, False, False);
741 procedure DrawScroll(X
, Y
: Integer; Height
: Word; Up
, Down
: Boolean);
745 if Height
< 3 then Exit
;
748 g_Texture_Get(BSCROLL_UPA
, ID
)
750 g_Texture_Get(BSCROLL_UPU
, ID
);
751 e_Draw(ID
, X
, Y
, 0, False, False);
754 g_Texture_Get(BSCROLL_DOWNA
, ID
)
756 g_Texture_Get(BSCROLL_DOWNU
, ID
);
757 e_Draw(ID
, X
, Y
+(Height
-1)*16, 0, False, False);
759 g_Texture_Get(BSCROLL_MIDDLE
, ID
);
760 e_DrawFill(ID
, X
, Y
+16, 1, Height
-2, 0, False, False);
765 constructor TGUIWindow
.Create(Name
: string);
768 FActiveControl
:= nil;
772 FOnCloseEvent
:= nil;
776 destructor TGUIWindow
.Destroy
;
783 for i
:= 0 to High(Childs
) do
787 function TGUIWindow
.AddChild(Child
: TGUIControl
): TGUIControl
;
789 Child
.FWindow
:= Self
;
791 SetLength(Childs
, Length(Childs
) + 1);
792 Childs
[High(Childs
)] := Child
;
797 procedure TGUIWindow
.Update
;
801 for i
:= 0 to High(Childs
) do
802 if Childs
[i
] <> nil then Childs
[i
].Update
;
805 procedure TGUIWindow
.Draw
;
810 if FBackTexture
<> '' then
811 if g_Texture_Get(FBackTexture
, ID
) then
812 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
814 e_Clear(GL_COLOR_BUFFER_BIT
, 0.5, 0.5, 0.5);
816 for i
:= 0 to High(Childs
) do
817 if Childs
[i
] <> nil then Childs
[i
].Draw
;
820 procedure TGUIWindow
.OnMessage(var Msg
: TMessage
);
822 if FActiveControl
<> nil then FActiveControl
.OnMessage(Msg
);
823 if @FOnKeyDown
<> nil then FOnKeyDown(Msg
.wParam
);
824 if @FOnKeyDownEx
<> nil then FOnKeyDownEx(self
, Msg
.wParam
);
826 if Msg
.Msg
= WM_KEYDOWN
then
827 if Msg
.wParam
= IK_ESCAPE
then
834 procedure TGUIWindow
.SetActive(Control
: TGUIControl
);
836 FActiveControl
:= Control
;
839 function TGUIWindow
.GetControl(Name
: String): TGUIControl
;
845 if Childs
<> nil then
846 for i
:= 0 to High(Childs
) do
847 if Childs
[i
] <> nil then
848 if LowerCase(Childs
[i
].FName
) = LowerCase(Name
) then
854 Assert(Result
<> nil, 'Window Control "'+Name
+'" not Found!');
859 constructor TGUIControl
.Create();
865 FRightAlign
:= false;
869 procedure TGUIControl
.OnMessage(var Msg
: TMessage
);
875 procedure TGUIControl
.Update();
879 procedure TGUIControl
.Draw();
883 function TGUIControl
.WantActivationKey (key
: LongInt): Boolean;
888 function TGUIControl
.GetWidth(): Integer;
893 function TGUIControl
.GetHeight(): Integer;
900 procedure TGUITextButton
.Click(Silent
: Boolean = False);
902 if (FSound
<> '') and (not Silent
) then g_Sound_PlayEx(FSound
);
904 if @Proc
<> nil then Proc();
905 if @ProcEx
<> nil then ProcEx(self
);
907 if FShowWindow
<> '' then g_GUI_ShowWindow(FShowWindow
);
910 constructor TGUITextButton
.Create(aProc
: Pointer; FontID
: DWORD
; Text: string);
917 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
922 destructor TGUITextButton
.Destroy
;
928 procedure TGUITextButton
.Draw
;
930 FFont
.Draw(FX
, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
)
933 function TGUITextButton
.GetHeight
: Integer;
937 FFont
.GetTextSize(FText
, w
, h
);
941 function TGUITextButton
.GetWidth
: Integer;
945 FFont
.GetTextSize(FText
, w
, h
);
949 procedure TGUITextButton
.OnMessage(var Msg
: TMessage
);
951 if not FEnabled
then Exit
;
958 IK_RETURN
, IK_KPRETURN
: Click();
963 procedure TGUITextButton
.Update
;
970 constructor TFont
.Create(FontID
: DWORD
; FontType
: TFontType
);
975 FFontType
:= FontType
;
978 destructor TFont
.Destroy
;
984 procedure TFont
.Draw(X
, Y
: Integer; Text: string; R
, G
, B
: Byte);
986 if FFontType
= FONT_CHAR
then e_CharFont_PrintEx(ID
, X
, Y
, Text, _RGB(R
, G
, B
), FScale
)
987 else e_TextureFontPrintEx(X
, Y
, Text, ID
, R
, G
, B
, FScale
);
990 procedure TFont
.GetTextSize(Text: string; var w
, h
: Word);
994 if FFontType
= FONT_CHAR
then e_CharFont_GetSize(ID
, Text, w
, h
)
997 e_TextureFontGetSize(ID
, cw
, ch
);
998 w
:= cw
*Length(Text);
1002 w
:= Round(w
*FScale
);
1003 h
:= Round(h
*FScale
);
1008 function TGUIMainMenu
.AddButton(fProc
: Pointer; Caption
: string; ShowWindow
: string = ''): TGUITextButton
;
1015 SetLength(FButtons
, Length(FButtons
)+1);
1016 FButtons
[High(FButtons
)] := TGUITextButton
.Create(fProc
, FFontID
, Caption
);
1017 FButtons
[High(FButtons
)].ShowWindow
:= ShowWindow
;
1018 with FButtons
[High(FButtons
)] do
1020 if (fProc
<> nil) or (ShowWindow
<> '') then FColor
:= MAINMENU_ITEMS_COLOR
1021 else FColor
:= MAINMENU_UNACTIVEITEMS_COLOR
;
1022 FSound
:= MAINMENU_CLICKSOUND
;
1025 _x
:= gScreenWidth
div 2;
1027 for a
:= 0 to High(FButtons
) do
1028 if FButtons
[a
] <> nil then
1029 _x
:= Min(_x
, (gScreenWidth
div 2)-(FButtons
[a
].GetWidth
div 2));
1031 hh
:= FHeader
.GetHeight
;
1033 h
:= hh
*(2+Length(FButtons
))+MAINMENU_SPACE
*(Length(FButtons
)-1);
1034 h
:= (gScreenHeight
div 2)-(h
div 2);
1044 for a
:= 0 to High(FButtons
) do
1046 if FButtons
[a
] <> nil then
1053 Inc(h
, hh
+MAINMENU_SPACE
);
1056 Result
:= FButtons
[High(FButtons
)];
1059 procedure TGUIMainMenu
.AddSpace
;
1061 SetLength(FButtons
, Length(FButtons
)+1);
1062 FButtons
[High(FButtons
)] := nil;
1065 constructor TGUIMainMenu
.Create(FontID
: DWORD
; Header
: string);
1071 FCounter
:= MAINMENU_MARKERDELAY
;
1073 g_Texture_Get(MAINMENU_MARKER1
, FMarkerID1
);
1074 g_Texture_Get(MAINMENU_MARKER2
, FMarkerID2
);
1076 FHeader
:= TGUILabel
.Create(Header
, FFontID
);
1079 FColor
:= MAINMENU_HEADER_COLOR
;
1080 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1081 FY
:= (gScreenHeight
div 2)-(GetHeight
div 2);
1085 destructor TGUIMainMenu
.Destroy
;
1089 if FButtons
<> nil then
1090 for a
:= 0 to High(FButtons
) do
1098 procedure TGUIMainMenu
.Draw
;
1106 if FButtons
<> nil then
1108 for a
:= 0 to High(FButtons
) do
1109 if FButtons
[a
] <> nil then FButtons
[a
].Draw
;
1111 if FIndex
<> -1 then
1112 e_Draw(FMarkerID1
, FButtons
[FIndex
].FX
-48, FButtons
[FIndex
].FY
, 0, True, False);
1116 procedure TGUIMainMenu
.EnableButton(aName
: string; e
: Boolean);
1120 if FButtons
= nil then Exit
;
1122 for a
:= 0 to High(FButtons
) do
1123 if (FButtons
[a
] <> nil) and (FButtons
[a
].Name
= aName
) then
1125 if e
then FButtons
[a
].FColor
:= MAINMENU_ITEMS_COLOR
1126 else FButtons
[a
].FColor
:= MAINMENU_UNACTIVEITEMS_COLOR
;
1127 FButtons
[a
].Enabled
:= e
;
1132 function TGUIMainMenu
.GetButton(aName
: string): TGUITextButton
;
1138 if FButtons
= nil then Exit
;
1140 for a
:= 0 to High(FButtons
) do
1141 if (FButtons
[a
] <> nil) and (FButtons
[a
].Name
= aName
) then
1143 Result
:= FButtons
[a
];
1148 procedure TGUIMainMenu
.OnMessage(var Msg
: TMessage
);
1153 if not FEnabled
then Exit
;
1157 if FButtons
= nil then Exit
;
1160 for a
:= 0 to High(FButtons
) do
1161 if FButtons
[a
] <> nil then
1167 if not ok
then Exit
;
1176 if FIndex
< 0 then FIndex
:= High(FButtons
);
1177 until FButtons
[FIndex
] <> nil;
1179 g_Sound_PlayEx(MENU_CHANGESOUND
);
1185 if FIndex
> High(FButtons
) then FIndex
:= 0;
1186 until FButtons
[FIndex
] <> nil;
1188 g_Sound_PlayEx(MENU_CHANGESOUND
);
1190 IK_RETURN
, IK_KPRETURN
: if (FIndex
<> -1) and FButtons
[FIndex
].FEnabled
then FButtons
[FIndex
].Click
;
1195 procedure TGUIMainMenu
.Update
;
1201 if FCounter
= 0 then
1204 FMarkerID1
:= FMarkerID2
;
1207 FCounter
:= MAINMENU_MARKERDELAY
;
1208 end else Dec(FCounter
);
1213 constructor TGUILabel
.Create(Text: string; FontID
: DWORD
);
1217 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
1221 FOnClickEvent
:= nil;
1224 procedure TGUILabel
.Draw
;
1230 FFont
.GetTextSize(FText
, w
, h
);
1231 FFont
.Draw(FX
+FMaxWidth
-w
, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
);
1235 FFont
.Draw(FX
, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
);
1239 function TGUILabel
.GetHeight
: Integer;
1243 FFont
.GetTextSize(FText
, w
, h
);
1247 function TGUILabel
.GetWidth
: Integer;
1251 if FFixedLen
= 0 then
1252 FFont
.GetTextSize(FText
, w
, h
)
1254 w
:= e_CharFont_GetMaxWidth(FFont
.ID
)*FFixedLen
;
1258 procedure TGUILabel
.OnMessage(var Msg
: TMessage
);
1260 if not FEnabled
then Exit
;
1267 IK_RETURN
, IK_KPRETURN
: if @FOnClickEvent
<> nil then FOnClickEvent();
1274 function TGUIMenu
.AddButton(Proc
: Pointer; fText
: string; _ShowWindow
: string = ''): TGUITextButton
;
1281 Control
:= TGUITextButton
.Create(Proc
, FFontID
, fText
);
1282 with Control
as TGUITextButton
do
1284 ShowWindow
:= _ShowWindow
;
1285 FColor
:= MENU_ITEMSCTRL_COLOR
;
1289 ControlType
:= TGUITextButton
;
1291 Result
:= (Control
as TGUITextButton
);
1294 if FIndex
= -1 then FIndex
:= i
;
1299 procedure TGUIMenu
.AddLine(fText
: string);
1306 Text := TGUILabel
.Create(fText
, FFontID
);
1309 FColor
:= MENU_ITEMSTEXT_COLOR
;
1318 procedure TGUIMenu
.AddText(fText
: string; MaxWidth
: Word);
1323 l
:= GetLines(fText
, FFontID
, MaxWidth
);
1325 if l
= nil then Exit
;
1327 for a
:= 0 to High(l
) do
1332 Text := TGUILabel
.Create(l
[a
], FFontID
);
1335 with Text do begin FColor
:= _RGB(255, 0, 0); end;
1339 with Text do begin FColor
:= MENU_ITEMSTEXT_COLOR
; end;
1349 procedure TGUIMenu
.AddSpace
;
1363 constructor TGUIMenu
.Create(HeaderFont
, ItemsFont
: DWORD
; Header
: string);
1369 FFontID
:= ItemsFont
;
1370 FCounter
:= MENU_MARKERDELAY
;
1374 FHeader
:= TGUILabel
.Create(Header
, HeaderFont
);
1377 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1379 FColor
:= MAINMENU_HEADER_COLOR
;
1383 destructor TGUIMenu
.Destroy
;
1387 if FItems
<> nil then
1388 for a
:= 0 to High(FItems
) do
1402 procedure TGUIMenu
.Draw
;
1404 a
, locx
, locy
: Integer;
1408 if FHeader
<> nil then FHeader
.Draw
;
1410 if FItems
<> nil then
1411 for a
:= 0 to High(FItems
) do
1413 if FItems
[a
].Text <> nil then FItems
[a
].Text.Draw
;
1414 if FItems
[a
].Control
<> nil then FItems
[a
].Control
.Draw
;
1417 if (FIndex
<> -1) and (FCounter
> MENU_MARKERDELAY
div 2) then
1422 if FItems
[FIndex
].Text <> nil then
1424 locx
:= FItems
[FIndex
].Text.FX
;
1425 locy
:= FItems
[FIndex
].Text.FY
;
1427 if FItems
[FIndex
].Text.RightAlign
then
1429 locx
:= locx
+FItems
[FIndex
].Text.FMaxWidth
-FItems
[FIndex
].Text.GetWidth
;
1432 else if FItems
[FIndex
].Control
<> nil then
1434 locx
:= FItems
[FIndex
].Control
.FX
;
1435 locy
:= FItems
[FIndex
].Control
.FY
;
1438 locx
:= locx
-e_CharFont_GetMaxWidth(FFontID
);
1440 e_CharFont_PrintEx(FFontID
, locx
, locy
, #16, _RGB(255, 0, 0));
1444 function TGUIMenu
.GetControl(aName
: String): TGUIControl
;
1450 if FItems
<> nil then
1451 for a
:= 0 to High(FItems
) do
1452 if FItems
[a
].Control
<> nil then
1453 if LowerCase(FItems
[a
].Control
.Name
) = LowerCase(aName
) then
1455 Result
:= FItems
[a
].Control
;
1459 Assert(Result
<> nil, 'GUI control "'+aName
+'" not found!');
1462 function TGUIMenu
.GetControlsText(aName
: String): TGUILabel
;
1468 if FItems
<> nil then
1469 for a
:= 0 to High(FItems
) do
1470 if FItems
[a
].Control
<> nil then
1471 if LowerCase(FItems
[a
].Control
.Name
) = LowerCase(aName
) then
1473 Result
:= FItems
[a
].Text;
1477 Assert(Result
<> nil, 'GUI control''s text "'+aName
+'" not found!');
1480 function TGUIMenu
.NewItem
: Integer;
1482 SetLength(FItems
, Length(FItems
)+1);
1483 Result
:= High(FItems
);
1486 procedure TGUIMenu
.OnMessage(var Msg
: TMessage
);
1491 if not FEnabled
then Exit
;
1495 if FItems
= nil then Exit
;
1498 for a
:= 0 to High(FItems
) do
1499 if FItems
[a
].Control
<> nil then
1505 if not ok
then Exit
;
1507 if (Msg
.Msg
= WM_KEYDOWN
) and (FIndex
<> -1) and (FItems
[FIndex
].Control
<> nil) and
1508 (FItems
[FIndex
].Control
.WantActivationKey(Msg
.wParam
)) then
1510 FItems
[FIndex
].Control
.OnMessage(Msg
);
1511 g_Sound_PlayEx(MENU_CLICKSOUND
);
1524 if c
> Length(FItems
) then
1531 if FIndex
< 0 then FIndex
:= High(FItems
);
1532 until (FItems
[FIndex
].Control
<> nil) and
1533 (FItems
[FIndex
].Control
.Enabled
);
1537 g_Sound_PlayEx(MENU_CHANGESOUND
);
1545 if c
> Length(FItems
) then
1552 if FIndex
> High(FItems
) then FIndex
:= 0;
1553 until (FItems
[FIndex
].Control
<> nil) and
1554 (FItems
[FIndex
].Control
.Enabled
);
1558 g_Sound_PlayEx(MENU_CHANGESOUND
);
1561 IK_LEFT
, IK_RIGHT
, IK_KPLEFT
, IK_KPRIGHT
:
1563 if FIndex
<> -1 then
1564 if FItems
[FIndex
].Control
<> nil then
1565 FItems
[FIndex
].Control
.OnMessage(Msg
);
1567 IK_RETURN
, IK_KPRETURN
:
1569 if FIndex
<> -1 then
1571 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1573 g_Sound_PlayEx(MENU_CLICKSOUND
);
1577 if FYesNo
and (length(FItems
) > 1) then
1579 Msg
.wParam
:= IK_RETURN
; // to register keypress
1580 FIndex
:= High(FItems
)-1;
1581 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1584 if FYesNo
and (length(FItems
) > 1) then
1586 Msg
.wParam
:= IK_RETURN
; // to register keypress
1587 FIndex
:= High(FItems
);
1588 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1595 procedure TGUIMenu
.ReAlign();
1597 a
, tx
, cx
, w
, h
: Integer;
1598 cww
: array of Integer; // cached widths
1601 if FItems
= nil then Exit
;
1603 SetLength(cww
, length(FItems
));
1605 for a
:= 0 to High(FItems
) do
1607 if FItems
[a
].Text <> nil then
1609 cww
[a
] := FItems
[a
].Text.GetWidth
;
1610 if maxcww
< cww
[a
] then maxcww
:= cww
[a
];
1621 for a
:= 0 to High(FItems
) do
1624 if FItems
[a
].Text <> nil then w
:= FItems
[a
].Text.GetWidth
;
1625 if FItems
[a
].Control
<> nil then
1628 if FItems
[a
].ControlType
= TGUILabel
then w
:= w
+(FItems
[a
].Control
as TGUILabel
).GetWidth
1629 else if FItems
[a
].ControlType
= TGUITextButton
then w
:= w
+(FItems
[a
].Control
as TGUITextButton
).GetWidth
1630 else if FItems
[a
].ControlType
= TGUIScroll
then w
:= w
+(FItems
[a
].Control
as TGUIScroll
).GetWidth
1631 else if FItems
[a
].ControlType
= TGUISwitch
then w
:= w
+(FItems
[a
].Control
as TGUISwitch
).GetWidth
1632 else if FItems
[a
].ControlType
= TGUIEdit
then w
:= w
+(FItems
[a
].Control
as TGUIEdit
).GetWidth
1633 else if FItems
[a
].ControlType
= TGUIKeyRead
then w
:= w
+(FItems
[a
].Control
as TGUIKeyRead
).GetWidth
1634 else if FItems
[a
].ControlType
= TGUIKeyRead2
then w
:= w
+(FItems
[a
].Control
as TGUIKeyRead2
).GetWidth
1635 else if FItems
[a
].ControlType
= TGUIListBox
then w
:= w
+(FItems
[a
].Control
as TGUIListBox
).GetWidth
1636 else if FItems
[a
].ControlType
= TGUIFileListBox
then w
:= w
+(FItems
[a
].Control
as TGUIFileListBox
).GetWidth
1637 else if FItems
[a
].ControlType
= TGUIMemo
then w
:= w
+(FItems
[a
].Control
as TGUIMemo
).GetWidth
;
1639 tx
:= Min(tx
, (gScreenWidth
div 2)-(w
div 2));
1644 for a
:= 0 to High(FItems
) do
1648 if (Text <> nil) and (Control
= nil) then Continue
;
1650 if Text <> nil then w
:= tx
+Text.GetWidth
;
1651 if w
> cx
then cx
:= w
;
1655 cx
:= cx
+MENU_HSPACE
;
1657 h
:= FHeader
.GetHeight
*2+MENU_VSPACE
*(Length(FItems
)-1);
1659 for a
:= 0 to High(FItems
) do
1663 if (ControlType
= TGUIListBox
) or (ControlType
= TGUIFileListBox
) then
1664 h
:= h
+(FItems
[a
].Control
as TGUIListBox
).GetHeight()
1666 h
:= h
+e_CharFont_GetMaxHeight(FFontID
);
1670 h
:= (gScreenHeight
div 2)-(h
div 2);
1674 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1677 Inc(h
, GetHeight
*2);
1680 for a
:= 0 to High(FItems
) do
1692 if Text.RightAlign
and (length(cww
) > a
) then
1694 //Text.FX := Text.FX+maxcww;
1695 Text.FMaxWidth
:= maxcww
;
1699 if Control
<> nil then
1716 if (ControlType
= TGUIListBox
) or (ControlType
= TGUIFileListBox
) then Inc(h
, (Control
as TGUIListBox
).GetHeight
+MENU_VSPACE
)
1717 else if ControlType
= TGUIMemo
then Inc(h
, (Control
as TGUIMemo
).GetHeight
+MENU_VSPACE
)
1718 else Inc(h
, e_CharFont_GetMaxHeight(FFontID
)+MENU_VSPACE
);
1722 // another ugly hack
1723 if FYesNo
and (length(FItems
) > 1) then
1726 for a
:= High(FItems
)-1 to High(FItems
) do
1728 if (FItems
[a
].Control
<> nil) and (FItems
[a
].ControlType
= TGUITextButton
) then
1730 cx
:= (FItems
[a
].Control
as TGUITextButton
).GetWidth
;
1731 if cx
> w
then w
:= cx
;
1736 for a
:= High(FItems
)-1 to High(FItems
) do
1738 if (FItems
[a
].Control
<> nil) and (FItems
[a
].ControlType
= TGUITextButton
) then
1740 FItems
[a
].Control
.FX
:= (gScreenWidth
-w
) div 2;
1747 function TGUIMenu
.AddScroll(fText
: string): TGUIScroll
;
1754 Control
:= TGUIScroll
.Create();
1756 Text := TGUILabel
.Create(fText
, FFontID
);
1759 FColor
:= MENU_ITEMSTEXT_COLOR
;
1762 ControlType
:= TGUIScroll
;
1764 Result
:= (Control
as TGUIScroll
);
1767 if FIndex
= -1 then FIndex
:= i
;
1772 function TGUIMenu
.AddSwitch(fText
: string): TGUISwitch
;
1779 Control
:= TGUISwitch
.Create(FFontID
);
1780 (Control
as TGUISwitch
).FColor
:= MENU_ITEMSCTRL_COLOR
;
1782 Text := TGUILabel
.Create(fText
, FFontID
);
1785 FColor
:= MENU_ITEMSTEXT_COLOR
;
1788 ControlType
:= TGUISwitch
;
1790 Result
:= (Control
as TGUISwitch
);
1793 if FIndex
= -1 then FIndex
:= i
;
1798 function TGUIMenu
.AddEdit(fText
: string): TGUIEdit
;
1805 Control
:= TGUIEdit
.Create(FFontID
);
1806 with Control
as TGUIEdit
do
1808 FWindow
:= Self
.FWindow
;
1809 FColor
:= MENU_ITEMSCTRL_COLOR
;
1812 if fText
= '' then Text := nil else
1814 Text := TGUILabel
.Create(fText
, FFontID
);
1815 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
1818 ControlType
:= TGUIEdit
;
1820 Result
:= (Control
as TGUIEdit
);
1823 if FIndex
= -1 then FIndex
:= i
;
1828 procedure TGUIMenu
.Update
;
1834 if FCounter
= 0 then FCounter
:= MENU_MARKERDELAY
else Dec(FCounter
);
1836 if FItems
<> nil then
1837 for a
:= 0 to High(FItems
) do
1838 if FItems
[a
].Control
<> nil then
1839 (FItems
[a
].Control
as FItems
[a
].ControlType
).Update
;
1842 function TGUIMenu
.AddKeyRead(fText
: string): TGUIKeyRead
;
1849 Control
:= TGUIKeyRead
.Create(FFontID
);
1850 with Control
as TGUIKeyRead
do
1852 FWindow
:= Self
.FWindow
;
1853 FColor
:= MENU_ITEMSCTRL_COLOR
;
1856 Text := TGUILabel
.Create(fText
, FFontID
);
1859 FColor
:= MENU_ITEMSTEXT_COLOR
;
1862 ControlType
:= TGUIKeyRead
;
1864 Result
:= (Control
as TGUIKeyRead
);
1867 if FIndex
= -1 then FIndex
:= i
;
1872 function TGUIMenu
.AddKeyRead2(fText
: string): TGUIKeyRead2
;
1879 Control
:= TGUIKeyRead2
.Create(FFontID
);
1880 with Control
as TGUIKeyRead2
do
1882 FWindow
:= Self
.FWindow
;
1883 FColor
:= MENU_ITEMSCTRL_COLOR
;
1886 Text := TGUILabel
.Create(fText
, FFontID
);
1889 FColor
:= MENU_ITEMSCTRL_COLOR
; //MENU_ITEMSTEXT_COLOR;
1893 ControlType
:= TGUIKeyRead2
;
1895 Result
:= (Control
as TGUIKeyRead2
);
1898 if FIndex
= -1 then FIndex
:= i
;
1903 function TGUIMenu
.AddList(fText
: string; Width
, Height
: Word): TGUIListBox
;
1910 Control
:= TGUIListBox
.Create(FFontID
, Width
, Height
);
1911 with Control
as TGUIListBox
do
1913 FWindow
:= Self
.FWindow
;
1914 FActiveColor
:= MENU_ITEMSCTRL_COLOR
;
1915 FUnActiveColor
:= MENU_ITEMSTEXT_COLOR
;
1918 Text := TGUILabel
.Create(fText
, FFontID
);
1921 FColor
:= MENU_ITEMSTEXT_COLOR
;
1924 ControlType
:= TGUIListBox
;
1926 Result
:= (Control
as TGUIListBox
);
1929 if FIndex
= -1 then FIndex
:= i
;
1934 function TGUIMenu
.AddFileList(fText
: string; Width
, Height
: Word): TGUIFileListBox
;
1941 Control
:= TGUIFileListBox
.Create(FFontID
, Width
, Height
);
1942 with Control
as TGUIFileListBox
do
1944 FWindow
:= Self
.FWindow
;
1945 FActiveColor
:= MENU_ITEMSCTRL_COLOR
;
1946 FUnActiveColor
:= MENU_ITEMSTEXT_COLOR
;
1949 if fText
= '' then Text := nil else
1951 Text := TGUILabel
.Create(fText
, FFontID
);
1952 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
1955 ControlType
:= TGUIFileListBox
;
1957 Result
:= (Control
as TGUIFileListBox
);
1960 if FIndex
= -1 then FIndex
:= i
;
1965 function TGUIMenu
.AddLabel(fText
: string): TGUILabel
;
1972 Control
:= TGUILabel
.Create('', FFontID
);
1973 with Control
as TGUILabel
do
1975 FWindow
:= Self
.FWindow
;
1976 FColor
:= MENU_ITEMSCTRL_COLOR
;
1979 Text := TGUILabel
.Create(fText
, FFontID
);
1982 FColor
:= MENU_ITEMSTEXT_COLOR
;
1985 ControlType
:= TGUILabel
;
1987 Result
:= (Control
as TGUILabel
);
1990 if FIndex
= -1 then FIndex
:= i
;
1995 function TGUIMenu
.AddMemo(fText
: string; Width
, Height
: Word): TGUIMemo
;
2002 Control
:= TGUIMemo
.Create(FFontID
, Width
, Height
);
2003 with Control
as TGUIMemo
do
2005 FWindow
:= Self
.FWindow
;
2006 FColor
:= MENU_ITEMSTEXT_COLOR
;
2009 if fText
= '' then Text := nil else
2011 Text := TGUILabel
.Create(fText
, FFontID
);
2012 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
2015 ControlType
:= TGUIMemo
;
2017 Result
:= (Control
as TGUIMemo
);
2020 if FIndex
= -1 then FIndex
:= i
;
2025 procedure TGUIMenu
.UpdateIndex();
2033 if (FIndex
< 0) or (FIndex
> High(FItems
)) then
2039 if FItems
[FIndex
].Control
.Enabled
then
2048 constructor TGUIScroll
.Create
;
2053 FOnChangeEvent
:= nil;
2055 g_Texture_Get(SCROLL_LEFT
, FLeftID
);
2056 g_Texture_Get(SCROLL_RIGHT
, FRightID
);
2057 g_Texture_Get(SCROLL_MIDDLE
, FMiddleID
);
2058 g_Texture_Get(SCROLL_MARKER
, FMarkerID
);
2061 procedure TGUIScroll
.Draw
;
2067 e_Draw(FLeftID
, FX
, FY
, 0, True, False);
2068 e_Draw(FRightID
, FX
+8+(FMax
+1)*8, FY
, 0, True, False);
2070 for a
:= 0 to FMax
do
2071 e_Draw(FMiddleID
, FX
+8+a
*8, FY
, 0, True, False);
2073 e_Draw(FMarkerID
, FX
+8+FValue
*8, FY
, 0, True, False);
2076 procedure TGUIScroll
.FSetValue(a
: Integer);
2078 if a
> FMax
then FValue
:= FMax
else FValue
:= a
;
2081 function TGUIScroll
.GetWidth
: Integer;
2083 Result
:= 16+(FMax
+1)*8;
2086 procedure TGUIScroll
.OnMessage(var Msg
: TMessage
);
2088 if not FEnabled
then Exit
;
2100 g_Sound_PlayEx(SCROLL_SUBSOUND
);
2101 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2103 IK_RIGHT
, IK_KPRIGHT
:
2104 if FValue
< FMax
then
2107 g_Sound_PlayEx(SCROLL_ADDSOUND
);
2108 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2115 procedure TGUIScroll
.Update
;
2123 procedure TGUISwitch
.AddItem(Item
: string);
2125 SetLength(FItems
, Length(FItems
)+1);
2126 FItems
[High(FItems
)] := Item
;
2128 if FIndex
= -1 then FIndex
:= 0;
2131 constructor TGUISwitch
.Create(FontID
: DWORD
);
2137 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
2140 procedure TGUISwitch
.Draw
;
2144 FFont
.Draw(FX
, FY
, FItems
[FIndex
], FColor
.R
, FColor
.G
, FColor
.B
);
2147 function TGUISwitch
.GetText
: string;
2149 if FIndex
<> -1 then Result
:= FItems
[FIndex
]
2153 function TGUISwitch
.GetWidth
: Integer;
2160 if FItems
= nil then Exit
;
2162 for a
:= 0 to High(FItems
) do
2164 FFont
.GetTextSize(FItems
[a
], w
, h
);
2165 if w
> Result
then Result
:= w
;
2169 procedure TGUISwitch
.OnMessage(var Msg
: TMessage
);
2171 if not FEnabled
then Exit
;
2175 if FItems
= nil then Exit
;
2180 IK_RETURN
, IK_RIGHT
, IK_KPRETURN
, IK_KPRIGHT
:
2182 if FIndex
< High(FItems
) then
2187 if @FOnChangeEvent
<> nil then
2188 FOnChangeEvent(Self
);
2196 FIndex
:= High(FItems
);
2198 if @FOnChangeEvent
<> nil then
2199 FOnChangeEvent(Self
);
2205 procedure TGUISwitch
.Update
;
2213 constructor TGUIEdit
.Create(FontID
: DWORD
);
2217 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
2222 g_Texture_Get(EDIT_LEFT
, FLeftID
);
2223 g_Texture_Get(EDIT_RIGHT
, FRightID
);
2224 g_Texture_Get(EDIT_MIDDLE
, FMiddleID
);
2227 procedure TGUIEdit
.Draw
;
2233 e_Draw(FLeftID
, FX
, FY
, 0, True, False);
2234 e_Draw(FRightID
, FX
+8+FWidth
*16, FY
, 0, True, False);
2236 for c
:= 0 to FWidth
-1 do
2237 e_Draw(FMiddleID
, FX
+8+c
*16, FY
, 0, True, False);
2239 FFont
.Draw(FX
+8, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
);
2241 if FWindow
.FActiveControl
= Self
then
2243 FFont
.GetTextSize(Copy(FText
, 1, FCaretPos
), w
, h
);
2244 h
:= e_CharFont_GetMaxHeight(FFont
.ID
);
2245 e_DrawLine(2, FX
+8+w
, FY
+h
-3, FX
+8+w
+EDIT_CURSORLEN
, FY
+h
-3,
2246 EDIT_CURSORCOLOR
.R
, EDIT_CURSORCOLOR
.G
, EDIT_CURSORCOLOR
.B
);
2250 function TGUIEdit
.GetWidth
: Integer;
2252 Result
:= 16+FWidth
*16;
2255 procedure TGUIEdit
.OnMessage(var Msg
: TMessage
);
2257 if not FEnabled
then Exit
;
2266 if (wParam
in [48..57]) and (Chr(wParam
) <> '`') then
2267 if Length(Text) < FMaxLength
then
2269 Insert(Chr(wParam
), FText
, FCaretPos
+ 1);
2275 if (wParam
in [32..255]) and (Chr(wParam
) <> '`') then
2276 if Length(Text) < FMaxLength
then
2278 Insert(Chr(wParam
), FText
, FCaretPos
+ 1);
2286 Delete(FText
, FCaretPos
, 1);
2287 if FCaretPos
> 0 then Dec(FCaretPos
);
2289 IK_DELETE
: Delete(FText
, FCaretPos
+ 1, 1);
2290 IK_END
, IK_KPEND
: FCaretPos
:= Length(FText
);
2291 IK_HOME
, IK_KPHOME
: FCaretPos
:= 0;
2292 IK_LEFT
, IK_KPLEFT
: if FCaretPos
> 0 then Dec(FCaretPos
);
2293 IK_RIGHT
, IK_KPRIGHT
: if FCaretPos
< Length(FText
) then Inc(FCaretPos
);
2294 IK_RETURN
, IK_KPRETURN
:
2297 if FActiveControl
<> Self
then
2300 if @FOnEnterEvent
<> nil then FOnEnterEvent(Self
);
2304 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
2305 else SetActive(nil);
2306 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2313 procedure TGUIEdit
.SetText(Text: string);
2315 if Length(Text) > FMaxLength
then SetLength(Text, FMaxLength
);
2317 FCaretPos
:= Length(FText
);
2320 procedure TGUIEdit
.Update
;
2327 constructor TGUIKeyRead
.Create(FontID
: DWORD
);
2333 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
2336 procedure TGUIKeyRead
.Draw
;
2340 FFont
.Draw(FX
, FY
, IfThen(FIsQuery
, KEYREAD_QUERY
, IfThen(FKey
<> 0, e_KeyNames
[FKey
], KEYREAD_CLEAR
)),
2341 FColor
.R
, FColor
.G
, FColor
.B
);
2344 function TGUIKeyRead
.GetWidth
: Integer;
2351 for a
:= 0 to 255 do
2353 FFont
.GetTextSize(e_KeyNames
[a
], w
, h
);
2354 Result
:= Max(Result
, w
);
2357 FFont
.GetTextSize(KEYREAD_QUERY
, w
, h
);
2358 if w
> Result
then Result
:= w
;
2360 FFont
.GetTextSize(KEYREAD_CLEAR
, w
, h
);
2361 if w
> Result
then Result
:= w
;
2364 function TGUIKeyRead
.WantActivationKey (key
: LongInt): Boolean;
2367 (key
= IK_BACKSPACE
) or
2371 procedure TGUIKeyRead
.OnMessage(var Msg
: TMessage
);
2372 procedure actDefCtl ();
2375 if FDefControl
<> '' then
2376 SetActive(GetControl(FDefControl
))
2384 if not FEnabled
then
2393 if FIsQuery
then actDefCtl();
2396 IK_RETURN
, IK_KPRETURN
:
2398 if not FIsQuery
then
2401 if FActiveControl
<> Self
then
2408 FKey
:= IK_ENTER
; // <Enter>
2413 IK_BACKSPACE
: // clear keybinding if we aren't waiting for a key
2415 if not FIsQuery
then
2425 if not FIsQuery
and (wParam
= IK_BACKSPACE
) then
2430 else if FIsQuery
and (wParam
<> IK_ENTER
) and (wParam
<> IK_KPRETURN
) then // Not <Enter
2432 if e_KeyNames
[wParam
] <> '' then
2443 constructor TGUIKeyRead2
.Create(FontID
: DWORD
);
2456 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
2458 FMaxKeyNameWdt
:= 0;
2459 for a
:= 0 to 255 do
2461 FFont
.GetTextSize(e_KeyNames
[a
], w
, h
);
2462 FMaxKeyNameWdt
:= Max(FMaxKeyNameWdt
, w
);
2465 FMaxKeyNameWdt
:= FMaxKeyNameWdt
-(FMaxKeyNameWdt
div 3);
2467 FFont
.GetTextSize(KEYREAD_QUERY
, w
, h
);
2468 if w
> FMaxKeyNameWdt
then FMaxKeyNameWdt
:= w
;
2470 FFont
.GetTextSize(KEYREAD_CLEAR
, w
, h
);
2471 if w
> FMaxKeyNameWdt
then FMaxKeyNameWdt
:= w
;
2474 procedure TGUIKeyRead2
.Draw
;
2475 procedure drawText (idx
: Integer);
2481 if idx
= 0 then kk
:= FKey0
else kk
:= FKey1
;
2483 if idx
= 0 then x
:= FX
+8 else x
:= FX
+8+FMaxKeyNameWdt
+16;
2487 if FKeyIdx
= idx
then begin r
:= 255; g
:= 255; b
:= 255; end;
2488 if FIsQuery
and (FKeyIdx
= idx
) then
2489 FFont
.Draw(x
, y
, KEYREAD_QUERY
, r
, g
, b
)
2491 FFont
.Draw(x
, y
, IfThen(kk
<> 0, e_KeyNames
[kk
], KEYREAD_CLEAR
), r
, g
, b
);
2497 //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);
2498 //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);
2503 function TGUIKeyRead2
.GetWidth
: Integer;
2505 Result
:= FMaxKeyNameWdt
*2+8+8+16;
2508 function TGUIKeyRead2
.WantActivationKey (key
: LongInt): Boolean;
2511 (key
= IK_BACKSPACE
) or
2512 (key
= IK_LEFT
) or (key
= IK_RIGHT
) or
2513 (key
= IK_KPLEFT
) or (key
= IK_KPRIGHT
) or
2517 procedure TGUIKeyRead2
.OnMessage(var Msg
: TMessage
);
2518 procedure actDefCtl ();
2521 if FDefControl
<> '' then
2522 SetActive(GetControl(FDefControl
))
2530 if not FEnabled
then
2539 if FIsQuery
then actDefCtl();
2542 IK_RETURN
, IK_KPRETURN
:
2544 if not FIsQuery
then
2547 if FActiveControl
<> Self
then
2554 if (FKeyIdx
= 0) then FKey0
:= IK_ENTER
else FKey1
:= IK_ENTER
; // <Enter>
2559 IK_BACKSPACE
: // clear keybinding if we aren't waiting for a key
2561 if not FIsQuery
then
2563 if (FKeyIdx
= 0) then FKey0
:= 0 else FKey1
:= 0;
2568 if not FIsQuery
then
2573 IK_RIGHT
, IK_KPRIGHT
:
2574 if not FIsQuery
then
2583 if not FIsQuery
and (wParam
= IK_BACKSPACE
) then
2585 if (FKeyIdx
= 0) then FKey0
:= 0 else FKey1
:= 0;
2588 else if FIsQuery
and (wParam
<> IK_ENTER
) and (wParam
<> IK_KPRETURN
) then // Not <Enter
2590 if e_KeyNames
[wParam
] <> '' then
2592 if (FKeyIdx
= 0) then FKey0
:= wParam
else FKey1
:= wParam
;
2604 constructor TGUIModelView
.Create
;
2611 destructor TGUIModelView
.Destroy
;
2618 procedure TGUIModelView
.Draw
;
2622 DrawBox(FX
, FY
, 4, 4);
2624 if FModel
<> nil then FModel
.Draw(FX
+4, FY
+4);
2627 procedure TGUIModelView
.NextAnim();
2629 if FModel
= nil then
2632 if FModel
.Animation
< A_PAIN
then
2633 FModel
.ChangeAnimation(FModel
.Animation
+1, True)
2635 FModel
.ChangeAnimation(A_STAND
, True);
2638 procedure TGUIModelView
.NextWeapon();
2640 if FModel
= nil then
2643 if FModel
.Weapon
< WP_LAST
then
2644 FModel
.SetWeapon(FModel
.Weapon
+1)
2646 FModel
.SetWeapon(WEAPON_KASTET
);
2649 procedure TGUIModelView
.OnMessage(var Msg
: TMessage
);
2655 procedure TGUIModelView
.SetColor(Red
, Green
, Blue
: Byte);
2657 if FModel
<> nil then FModel
.SetColor(Red
, Green
, Blue
);
2660 procedure TGUIModelView
.SetModel(ModelName
: string);
2664 FModel
:= g_PlayerModel_Get(ModelName
);
2667 procedure TGUIModelView
.Update
;
2674 if FModel
<> nil then FModel
.Update
;
2679 constructor TGUIMapPreview
.Create();
2685 destructor TGUIMapPreview
.Destroy();
2691 procedure TGUIMapPreview
.Draw();
2698 DrawBox(FX
, FY
, MAPPREVIEW_WIDTH
, MAPPREVIEW_HEIGHT
);
2700 if (FMapSize
.X
<= 0) or (FMapSize
.Y
<= 0) then
2703 e_DrawFillQuad(FX
+4, FY
+4,
2704 FX
+4 + Trunc(FMapSize
.X
/ FScale
) - 1,
2705 FY
+4 + Trunc(FMapSize
.Y
/ FScale
) - 1,
2708 if FMapData
<> nil then
2709 for a
:= 0 to High(FMapData
) do
2712 if X1
> MAPPREVIEW_WIDTH
*16 then Continue
;
2713 if Y1
> MAPPREVIEW_HEIGHT
*16 then Continue
;
2715 if X2
< 0 then Continue
;
2716 if Y2
< 0 then Continue
;
2718 if X2
> MAPPREVIEW_WIDTH
*16 then X2
:= MAPPREVIEW_WIDTH
*16;
2719 if Y2
> MAPPREVIEW_HEIGHT
*16 then Y2
:= MAPPREVIEW_HEIGHT
*16;
2721 if X1
< 0 then X1
:= 0;
2722 if Y1
< 0 then Y1
:= 0;
2763 if ((X2
-X1
) > 0) and ((Y2
-Y1
) > 0) then
2764 e_DrawFillQuad(FX
+4 + X1
, FY
+4 + Y1
,
2765 FX
+4 + X2
- 1, FY
+4 + Y2
- 1, r
, g
, b
, 0);
2769 procedure TGUIMapPreview
.OnMessage(var Msg
: TMessage
);
2775 procedure TGUIMapPreview
.SetMap(Res
: string);
2778 //MapReader: TMapReader_1;
2779 panels
: TPanelsRec1Array
;
2780 header
: TMapHeaderRec_1
;
2786 map
: TDynRecord
= nil;
2793 FileName
:= g_ExtractWadName(Res
);
2795 WAD
:= TWADFile
.Create();
2796 if not WAD
.ReadFile(FileName
) then
2802 //k8: ignores path again
2803 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
2812 map
:= g_Map_ParseMap(Data
, Len
);
2819 MapReader := TMapReader_1.Create();
2820 if not MapReader.LoadMap(Data) then
2834 panels
:= GetPanels(map
);
2835 header
:= GetMapHeader(map
);
2837 FMapSize
.X
:= header
.Width
div 16;
2838 FMapSize
.Y
:= header
.Height
div 16;
2840 rX
:= Ceil(header
.Width
/ (MAPPREVIEW_WIDTH
*256.0));
2841 rY
:= Ceil(header
.Height
/ (MAPPREVIEW_HEIGHT
*256.0));
2842 FScale
:= max(rX
, rY
);
2846 if panels
<> nil then
2847 for a
:= 0 to High(panels
) do
2848 if WordBool(panels
[a
].PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or
2849 PANEL_STEP
or PANEL_WATER
or
2850 PANEL_ACID1
or PANEL_ACID2
)) then
2852 SetLength(FMapData
, Length(FMapData
)+1);
2853 with FMapData
[High(FMapData
)] do
2855 X1
:= panels
[a
].X
div 16;
2856 Y1
:= panels
[a
].Y
div 16;
2858 X2
:= (panels
[a
].X
+ panels
[a
].Width
) div 16;
2859 Y2
:= (panels
[a
].Y
+ panels
[a
].Height
) div 16;
2861 X1
:= Trunc(X1
/FScale
+ 0.5);
2862 Y1
:= Trunc(Y1
/FScale
+ 0.5);
2863 X2
:= Trunc(X2
/FScale
+ 0.5);
2864 Y2
:= Trunc(Y2
/FScale
+ 0.5);
2866 if (X1
<> X2
) or (Y1
<> Y2
) then
2874 PanelType
:= panels
[a
].PanelType
;
2884 procedure TGUIMapPreview
.ClearMap();
2886 SetLength(FMapData
, 0);
2893 procedure TGUIMapPreview
.Update();
2899 function TGUIMapPreview
.GetScaleStr(): String;
2901 if FScale
> 0.0 then
2903 Result
:= FloatToStrF(FScale
*16.0, ffFixed
, 3, 3);
2904 while (Result
[Length(Result
)] = '0') do
2905 Delete(Result
, Length(Result
), 1);
2906 if (Result
[Length(Result
)] = ',') or (Result
[Length(Result
)] = '.') then
2907 Delete(Result
, Length(Result
), 1);
2908 Result
:= '1 : ' + Result
;
2916 procedure TGUIListBox
.AddItem(Item
: string);
2918 SetLength(FItems
, Length(FItems
)+1);
2919 FItems
[High(FItems
)] := Item
;
2921 if FSort
then g_Basic
.Sort(FItems
);
2924 procedure TGUIListBox
.Clear();
2932 constructor TGUIListBox
.Create(FontID
: DWORD
; Width
, Height
: Word);
2936 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
2941 FOnChangeEvent
:= nil;
2943 FDrawScroll
:= True;
2946 procedure TGUIListBox
.Draw
;
2954 if FDrawBack
then DrawBox(FX
, FY
, FWidth
+1, FHeight
);
2956 DrawScroll(FX
+4+FWidth
*16, FY
+4, FHeight
, (FStartLine
> 0) and (FItems
<> nil),
2957 (FStartLine
+FHeight
-1 < High(FItems
)) and (FItems
<> nil));
2959 if FItems
<> nil then
2960 for a
:= FStartLine
to Min(High(FItems
), FStartLine
+FHeight
-1) do
2964 FFont
.GetTextSize(s
, w2
, h2
);
2965 while (Length(s
) > 0) and (w2
> FWidth
*16) do
2967 SetLength(s
, Length(s
)-1);
2968 FFont
.GetTextSize(s
, w2
, h2
);
2972 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, s
, FActiveColor
.R
, FActiveColor
.G
, FActiveColor
.B
)
2974 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, s
, FUnActiveColor
.R
, FUnActiveColor
.G
, FUnActiveColor
.B
);
2978 function TGUIListBox
.GetHeight
: Integer;
2980 Result
:= 8+FHeight
*16;
2983 function TGUIListBox
.GetWidth
: Integer;
2985 Result
:= 8+(FWidth
+1)*16;
2988 procedure TGUIListBox
.OnMessage(var Msg
: TMessage
);
2992 if not FEnabled
then Exit
;
2996 if FItems
= nil then Exit
;
3009 FIndex
:= High(FItems
);
3010 FStartLine
:= Max(High(FItems
)-FHeight
+1, 0);
3012 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
:
3016 if FIndex
< FStartLine
then Dec(FStartLine
);
3017 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
3019 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
:
3020 if FIndex
< High(FItems
) then
3023 if FIndex
> FStartLine
+FHeight
-1 then Inc(FStartLine
);
3024 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
3026 IK_RETURN
, IK_KPRETURN
:
3029 if FActiveControl
<> Self
then SetActive(Self
)
3031 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
3032 else SetActive(nil);
3036 for a
:= 0 to High(FItems
) do
3037 if (Length(FItems
[a
]) > 0) and (LowerCase(FItems
[a
][1]) = LowerCase(Chr(wParam
))) then
3040 FStartLine
:= Min(Max(FIndex
-1, 0), Length(FItems
)-FHeight
);
3041 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
3047 function TGUIListBox
.SelectedItem(): String;
3051 if (FIndex
< 0) or (FItems
= nil) or
3052 (FIndex
> High(FItems
)) then
3055 Result
:= FItems
[FIndex
];
3058 procedure TGUIListBox
.FSetItems(Items
: SArray
);
3060 if FItems
<> nil then
3068 if FSort
then g_Basic
.Sort(FItems
);
3071 procedure TGUIListBox
.SelectItem(Item
: String);
3075 if FItems
= nil then
3079 Item
:= LowerCase(Item
);
3081 for a
:= 0 to High(FItems
) do
3082 if LowerCase(FItems
[a
]) = Item
then
3088 if FIndex
< FHeight
then
3091 FStartLine
:= Min(FIndex
, Length(FItems
)-FHeight
);
3094 procedure TGUIListBox
.FSetIndex(aIndex
: Integer);
3096 if FItems
= nil then
3099 if (aIndex
< 0) or (aIndex
> High(FItems
)) then
3104 if FIndex
<= FHeight
then
3107 FStartLine
:= Min(FIndex
, Length(FItems
)-FHeight
);
3112 procedure TGUIFileListBox
.OnMessage(var Msg
: TMessage
);
3116 if not FEnabled
then
3119 if FItems
= nil then
3130 if @FOnChangeEvent
<> nil then
3131 FOnChangeEvent(Self
);
3136 FIndex
:= High(FItems
);
3137 FStartLine
:= Max(High(FItems
)-FHeight
+1, 0);
3138 if @FOnChangeEvent
<> nil then
3139 FOnChangeEvent(Self
);
3142 IK_PAGEUP
, IK_KPPAGEUP
:
3144 if FIndex
> FHeight
then
3145 FIndex
:= FIndex
-FHeight
3149 if FStartLine
> FHeight
then
3150 FStartLine
:= FStartLine
-FHeight
3155 IK_PAGEDN
, IK_KPPAGEDN
:
3157 if FIndex
< High(FItems
)-FHeight
then
3158 FIndex
:= FIndex
+FHeight
3160 FIndex
:= High(FItems
);
3162 if FStartLine
< High(FItems
)-FHeight
then
3163 FStartLine
:= FStartLine
+FHeight
3165 FStartLine
:= High(FItems
)-FHeight
+1;
3168 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
:
3172 if FIndex
< FStartLine
then
3174 if @FOnChangeEvent
<> nil then
3175 FOnChangeEvent(Self
);
3178 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
:
3179 if FIndex
< High(FItems
) then
3182 if FIndex
> FStartLine
+FHeight
-1 then
3184 if @FOnChangeEvent
<> nil then
3185 FOnChangeEvent(Self
);
3188 IK_RETURN
, IK_KPRETURN
:
3191 if FActiveControl
<> Self
then
3195 if FItems
[FIndex
][1] = #29 then // Ïàïêà
3197 OpenDir(FPath
+Copy(FItems
[FIndex
], 2, 255));
3202 if FDefControl
<> '' then
3203 SetActive(GetControl(FDefControl
))
3211 for a
:= 0 to High(FItems
) do
3212 if ( (Length(FItems
[a
]) > 0) and
3213 (LowerCase(FItems
[a
][1]) = LowerCase(Chr(wParam
))) ) or
3214 ( (Length(FItems
[a
]) > 1) and
3215 (FItems
[a
][1] = #29) and // Ïàïêà
3216 (LowerCase(FItems
[a
][2]) = LowerCase(Chr(wParam
))) ) then
3219 FStartLine
:= Min(Max(FIndex
-1, 0), Length(FItems
)-FHeight
);
3220 if @FOnChangeEvent
<> nil then
3221 FOnChangeEvent(Self
);
3227 procedure TGUIFileListBox
.OpenDir(path
: String);
3235 path
:= IncludeTrailingPathDelimiter(path
);
3236 path
:= ExpandFileName(path
);
3241 if FindFirst(path
+'*', faDirectory
, SR
) = 0 then
3243 if not LongBool(SR
.Attr
and faDirectory
) then
3245 if (SR
.Name
= '.') or
3246 ((SR
.Name
= '..') and (path
= ExpandFileName(FBasePath
))) then
3249 AddItem(#1 + SR
.Name
);
3250 until FindNext(SR
) <> 0;
3260 if i
= 0 then i
:= length(sm
)+1;
3261 sc
:= Copy(sm
, 1, i
-1);
3263 if FindFirst(path
+sc
, faAnyFile
, SR
) = 0 then repeat AddItem(SR
.Name
); until FindNext(SR
) <> 0;
3267 for i
:= 0 to High(FItems
) do
3268 if FItems
[i
][1] = #1 then
3269 FItems
[i
][1] := #29;
3274 procedure TGUIFileListBox
.SetBase(path
: String);
3280 function TGUIFileListBox
.SelectedItem(): String;
3284 if (FIndex
= -1) or (FItems
= nil) or
3285 (FIndex
> High(FItems
)) or
3286 (FItems
[FIndex
][1] = '/') or
3287 (FItems
[FIndex
][1] = '\') then
3290 Result
:= FPath
+ FItems
[FIndex
];
3293 procedure TGUIFileListBox
.UpdateFileList();
3297 if (FIndex
= -1) or (FItems
= nil) or
3298 (FIndex
> High(FItems
)) or
3299 (FItems
[FIndex
][1] = '/') or
3300 (FItems
[FIndex
][1] = '\') then
3303 fn
:= FItems
[FIndex
];
3313 procedure TGUIMemo
.Clear
;
3319 constructor TGUIMemo
.Create(FontID
: DWORD
; Width
, Height
: Word);
3323 FFont
:= TFont
.Create(FontID
, FONT_CHAR
);
3328 FDrawScroll
:= True;
3331 procedure TGUIMemo
.Draw
;
3337 if FDrawBack
then DrawBox(FX
, FY
, FWidth
+1, FHeight
);
3339 DrawScroll(FX
+4+FWidth
*16, FY
+4, FHeight
, (FStartLine
> 0) and (FLines
<> nil),
3340 (FStartLine
+FHeight
-1 < High(FLines
)) and (FLines
<> nil));
3342 if FLines
<> nil then
3343 for a
:= FStartLine
to Min(High(FLines
), FStartLine
+FHeight
-1) do
3344 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, FLines
[a
], FColor
.R
, FColor
.G
, FColor
.B
);
3347 function TGUIMemo
.GetHeight
: Integer;
3349 Result
:= 8+FHeight
*16;
3352 function TGUIMemo
.GetWidth
: Integer;
3354 Result
:= 8+(FWidth
+1)*16;
3357 procedure TGUIMemo
.OnMessage(var Msg
: TMessage
);
3359 if not FEnabled
then Exit
;
3363 if FLines
= nil then Exit
;
3369 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
:
3370 if FStartLine
> 0 then
3372 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
:
3373 if FStartLine
< Length(FLines
)-FHeight
then
3375 IK_RETURN
, IK_KPRETURN
:
3378 if FActiveControl
<> Self
then
3384 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
3385 else SetActive(nil);
3391 procedure TGUIMemo
.SetText(Text: string);
3394 FLines
:= GetLines(Text, FFont
.ID
, FWidth
*16);
3399 procedure TGUIimage
.ClearImage();
3401 if FImageRes
= '' then Exit
;
3403 g_Texture_Delete(FImageRes
);
3407 constructor TGUIimage
.Create();
3414 destructor TGUIimage
.Destroy();
3419 procedure TGUIimage
.Draw();
3425 if FImageRes
= '' then
3427 if g_Texture_Get(FDefaultRes
, ID
) then e_Draw(ID
, FX
, FY
, 0, True, False);
3430 if g_Texture_Get(FImageRes
, ID
) then e_Draw(ID
, FX
, FY
, 0, True, False);
3433 procedure TGUIimage
.OnMessage(var Msg
: TMessage
);
3438 procedure TGUIimage
.SetImage(Res
: string);
3442 if g_Texture_CreateWADEx(Res
, Res
) then FImageRes
:= Res
;
3445 procedure TGUIimage
.Update();