3463a9ea100bc06167283342cceed2a9b1ddc622
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, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../../shared/a_modes.inc}
25 procedure r_GUI_GetSize (ctrl
: TGUIControl
; out w
, h
: Integer);
26 procedure r_GUI_GetLogoSize (out w
, h
: WORD);
27 procedure r_GUI_GetMaxFontSize (BigFont
: Boolean; out w
, h
: Integer);
28 procedure r_GUI_GetStringSize (BigFont
: Boolean; str
: String; out w
, h
: Integer);
29 procedure r_GUI_Draw_Window (win
: TGUIWindow
);
36 g_basic
, g_base
, e_input
, g_options
,
37 r_graphics
, r_textures
, r_playermodel
, r_game
,
53 TFontType
= (Texture
, Character
);
55 TFont
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
61 constructor Create(FontID
: DWORD
; FontType
: TFontType
);
62 destructor Destroy
; override;
63 procedure Draw(X
, Y
: Integer; Text: string; R
, G
, B
: Byte);
64 procedure GetTextSize(Text: string; var w
, h
: Word);
65 property Scale
: Single read FScale write FScale
;
66 property ID
: DWORD read FID
;
70 Box
: Array [0..8] of DWORD
;
71 MarkerID
: array [Boolean] of DWORD
;
72 ScrollLeft
, ScrollRight
, ScrollMiddle
, ScrollMarker
: DWORD
;
73 EditLeft
, EditRight
, EditMiddle
: DWORD
;
75 Font
: array [boolean] of TFont
; (* Small[FALSE] / Big[TRUE] *)
78 constructor TFont
.Create (FontID
: DWORD
; FontType
: TFontType
);
82 FFontType
:= FontType
;
85 destructor TFont
.Destroy
;
90 procedure TFont
.Draw (X
, Y
: Integer; Text: string; R
, G
, B
: Byte);
92 if FFontType
= TFontType
.Character
then
93 e_CharFont_PrintEx(ID
, X
, Y
, Text, _RGB(R
, G
, B
), FScale
)
95 e_TextureFontPrintEx(X
, Y
, Text, ID
, R
, G
, B
, FScale
)
98 procedure TFont
.GetTextSize (Text: string; var w
, h
: Word);
101 if FFontType
= TFontType
.Character
then
102 e_CharFont_GetSize(ID
, Text, w
, h
)
105 e_TextureFontGetSize(ID
, cw
, ch
);
106 w
:= cw
* Length(Text);
109 w
:= Round(w
* FScale
);
110 h
:= Round(h
* FScale
);
113 procedure r_GUI_GetMaxFontSize (BigFont
: Boolean; out w
, h
: Integer);
117 w
:= e_CharFont_GetMaxWidth(f
.ID
);
118 h
:= e_CharFont_GetMaxHeight(f
.ID
);
121 procedure r_GUI_GetStringSize (BigFont
: Boolean; str
: String; out w
, h
: Integer);
124 e_CharFont_GetSize(Font
[BigFont
].ID
, str
, ww
, hh
);
129 procedure r_GUI_GetLogoSize (out w
, h
: WORD);
134 e_GetTextureSize(LogoTex
, @w
, @h
);
137 procedure r_GUI_Load
;
139 g_Texture_CreateWADEx('MAINMENU_LOGO', GameWAD
+ ':TEXTURES\MAINLOGO');
140 g_Texture_CreateWADEx('MAINMENU_MARKER1', GameWAD
+ ':TEXTURES\MARKER1');
141 g_Texture_CreateWADEx('MAINMENU_MARKER2', GameWAD
+ ':TEXTURES\MARKER2');
142 g_Texture_CreateWADEx('SCROLL_LEFT', GameWAD
+ ':TEXTURES\SLEFT');
143 g_Texture_CreateWADEx('SCROLL_RIGHT', GameWAD
+ ':TEXTURES\SRIGHT');
144 g_Texture_CreateWADEx('SCROLL_MIDDLE', GameWAD
+ ':TEXTURES\SMIDDLE');
145 g_Texture_CreateWADEx('SCROLL_MARKER', GameWAD
+ ':TEXTURES\SMARKER');
146 g_Texture_CreateWADEx('EDIT_LEFT', GameWAD
+ ':TEXTURES\ELEFT');
147 g_Texture_CreateWADEx('EDIT_RIGHT', GameWAD
+ ':TEXTURES\ERIGHT');
148 g_Texture_CreateWADEx('EDIT_MIDDLE', GameWAD
+ ':TEXTURES\EMIDDLE');
149 g_Texture_CreateWADEx('BOX1', GameWAD
+ ':TEXTURES\BOX1');
150 g_Texture_CreateWADEx('BOX2', GameWAD
+ ':TEXTURES\BOX2');
151 g_Texture_CreateWADEx('BOX3', GameWAD
+ ':TEXTURES\BOX3');
152 g_Texture_CreateWADEx('BOX4', GameWAD
+ ':TEXTURES\BOX4');
153 g_Texture_CreateWADEx('BOX5', GameWAD
+ ':TEXTURES\BOX5');
154 g_Texture_CreateWADEx('BOX6', GameWAD
+ ':TEXTURES\BOX6');
155 g_Texture_CreateWADEx('BOX7', GameWAD
+ ':TEXTURES\BOX7');
156 g_Texture_CreateWADEx('BOX8', GameWAD
+ ':TEXTURES\BOX8');
157 g_Texture_CreateWADEx('BOX9', GameWAD
+ ':TEXTURES\BOX9');
158 g_Texture_CreateWADEx('BSCROLL_UP_A', GameWAD
+ ':TEXTURES\SCROLLUPA');
159 g_Texture_CreateWADEx('BSCROLL_UP_U', GameWAD
+ ':TEXTURES\SCROLLUPU');
160 g_Texture_CreateWADEx('BSCROLL_DOWN_A', GameWAD
+ ':TEXTURES\SCROLLDOWNA');
161 g_Texture_CreateWADEx('BSCROLL_DOWN_U', GameWAD
+ ':TEXTURES\SCROLLDOWNU');
162 g_Texture_CreateWADEx('BSCROLL_MIDDLE', GameWAD
+ ':TEXTURES\SCROLLMIDDLE');
163 g_Texture_CreateWADEx('NOPIC', GameWAD
+ ':TEXTURES\NOPIC');
165 g_Texture_Get(MAINMENU_MARKER1
, MarkerID
[FALSE]);
166 g_Texture_Get(MAINMENU_MARKER2
, MarkerID
[TRUE]);
168 g_Texture_Get(BOX1
, Box
[0]);
169 g_Texture_Get(BOX2
, Box
[1]);
170 g_Texture_Get(BOX3
, Box
[2]);
171 g_Texture_Get(BOX4
, Box
[3]);
172 g_Texture_Get(BOX5
, Box
[4]);
173 g_Texture_Get(BOX6
, Box
[5]);
174 g_Texture_Get(BOX7
, Box
[6]);
175 g_Texture_Get(BOX8
, Box
[7]);
176 g_Texture_Get(BOX9
, Box
[8]);
178 g_Texture_Get(SCROLL_LEFT
, ScrollLeft
);
179 g_Texture_Get(SCROLL_RIGHT
, ScrollRight
);
180 g_Texture_Get(SCROLL_MIDDLE
, ScrollMiddle
);
181 g_Texture_Get(SCROLL_MARKER
, ScrollMarker
);
183 g_Texture_Get(EDIT_LEFT
, EditLeft
);
184 g_Texture_Get(EDIT_RIGHT
, EditRight
);
185 g_Texture_Get(EDIT_MIDDLE
, EditMiddle
);
187 Font
[FALSE] := TFont
.Create(gMenuSmallFont
, TFontType
.Character
);
188 Font
[TRUE] := TFont
.Create(gMenuFont
, TFontType
.Character
);
190 g_Texture_Get('MAINMENU_LOGO', LogoTex
)
193 procedure r_GUI_Free
;
195 g_Texture_Delete('MAINMENU_LOGO');
196 g_Texture_Delete('MAINMENU_MARKER1');
197 g_Texture_Delete('MAINMENU_MARKER2');
198 g_Texture_Delete('SCROLL_LEFT');
199 g_Texture_Delete('SCROLL_RIGHT');
200 g_Texture_Delete('SCROLL_MIDDLE');
201 g_Texture_Delete('SCROLL_MARKER');
202 g_Texture_Delete('EDIT_LEFT');
203 g_Texture_Delete('EDIT_RIGHT');
204 g_Texture_Delete('EDIT_MIDDLE');
205 g_Texture_Delete('BOX1');
206 g_Texture_Delete('BOX2');
207 g_Texture_Delete('BOX3');
208 g_Texture_Delete('BOX4');
209 g_Texture_Delete('BOX5');
210 g_Texture_Delete('BOX6');
211 g_Texture_Delete('BOX7');
212 g_Texture_Delete('BOX8');
213 g_Texture_Delete('BOX9');
214 g_Texture_Delete('BSCROLL_UP_A');
215 g_Texture_Delete('BSCROLL_UP_U');
216 g_Texture_Delete('BSCROLL_DOWN_A');
217 g_Texture_Delete('BSCROLL_DOWN_U');
218 g_Texture_Delete('BSCROLL_MIDDLE');
219 g_Texture_Delete('NOPIC');
222 procedure r_GUI_GetSize_TextButton (ctrl
: TGUITextButton
; out w
, h
: Integer);
223 var ww
, hh
: WORD; f
: TFont
;
225 f
:= Font
[ctrl
.BigFont
];
226 f
.GetTextSize(ctrl
.Caption
, ww
, hh
);
231 procedure r_GUI_GetSize_Label (ctrl
: TGUILabel
; out w
, h
: Integer);
232 var ww
, hh
: WORD; f
: TFont
;
234 f
:= Font
[ctrl
.BigFont
];
235 f
.GetTextSize(ctrl
.Text, ww
, hh
);
237 if ctrl
.FixedLength
= 0 then
240 w
:= e_CharFont_GetMaxWidth(f
.ID
) * ctrl
.FixedLength
243 procedure r_GUI_GetSize_Switch (ctrl
: TGUISwitch
; out w
, h
: Integer);
244 var i
: Integer; ww
, hh
: WORD; f
: TFont
;
248 if ctrl
.Items
<> nil then
250 for i
:= 0 to High(ctrl
.Items
) do
252 f
:= Font
[ctrl
.BigFont
];
253 f
.GetTextSize(ctrl
.Items
[i
], ww
, hh
);
260 procedure r_GUI_GetSize_KeyRead (ctrl
: TGUIKeyRead
; out w
, h
: Integer);
261 var i
: Integer; ww
, hh
: WORD; f
: TFont
;
264 h
:= 0; // ??? always 0
265 f
:= Font
[ctrl
.BigFont
];
268 f
.GetTextSize(e_KeyNames
[i
], ww
, hh
);
271 f
.GetTextSize(KEYREAD_QUERY
, ww
, hh
);
272 if ww
> w
then w
:= ww
;
273 f
.GetTextSize(KEYREAD_CLEAR
, ww
, hh
);
274 if ww
> w
then w
:= ww
;
277 procedure r_GUI_GetSize (ctrl
: TGUIControl
; out w
, h
: Integer);
281 if ctrl
is TGUITextButton
then
282 r_GUI_GetSize_TextButton(ctrl
as TGUITextButton
, w
, h
)
283 else if ctrl
is TGUILabel
then
284 r_GUI_GetSize_Label(ctrl
as TGUILabel
, w
, h
)
285 else if ctrl
is TGUIScroll
then
286 w
:= 16 + ((ctrl
as TGUIScroll
).Max
+ 1) * 8 // ??? but h = 0
287 else if ctrl
is TGUISwitch
then
288 r_GUI_GetSize_Switch(ctrl
as TGUISwitch
, w
, h
)
289 else if ctrl
is TGUIEdit
then
290 w
:= 16 + (ctrl
as TGUIEdit
).Width
* 16 // ??? but h = 0
291 else if ctrl
is TGUIKeyRead
then
292 r_GUI_GetSize_KeyRead(ctrl
as TGUIKeyRead
, w
, h
)
293 else if ctrl
is TGUIKeyRead2
then
294 w
:= (ctrl
as TGUIKeyRead2
).MaxKeyNameWdt
* 2 + 8 + 8 + 16 // ??? but h = 0
295 else if ctrl
is TGUIListBox
then
297 w
:= 8 + ((ctrl
as TGUIListBox
).Width
+ 1) * 16; // recheck w & h
298 h
:= 8 + (ctrl
as TGUIListBox
).Height
* 16;
300 else if ctrl
is TGUIMemo
then
302 w
:= 8 + ((ctrl
as TGUIMemo
).Width
+ 1) * 16;
303 h
:= 8 + (ctrl
as TGUIMemo
).Height
* 16;
307 w
:= ctrl
.GetWidth();
308 h
:= ctrl
.GetHeight();
312 procedure r_GUI_Draw_Control (ctrl
: TGUIControl
); forward;
314 procedure r_GUI_Draw_TextButton (ctrl
: TGUITextButton
);
317 f
:= Font
[ctrl
.BigFont
];
318 f
.Draw(ctrl
.X
, ctrl
.Y
, ctrl
.Caption
, ctrl
.Color
.R
, ctrl
.Color
.G
, ctrl
.Color
.B
)
321 procedure r_GUI_Draw_Label (ctrl
: TGUILabel
);
322 var w
, h
: Word; f
: TFont
;
324 f
:= Font
[ctrl
.BigFont
];
325 if ctrl
.RightAlign
then
327 f
.GetTextSize(ctrl
.Text, w
, h
);
328 f
.Draw(ctrl
.X
+ ctrl
.CMaxWidth
- w
, ctrl
.Y
, ctrl
.Text, ctrl
.Color
.R
, ctrl
.Color
.G
, ctrl
.Color
.B
);
331 f
.Draw(ctrl
.X
, ctrl
.Y
, ctrl
.Text, ctrl
.Color
.R
, ctrl
.Color
.G
, ctrl
.Color
.B
);
334 procedure r_GUI_Draw_Scroll (ctrl
: TGUIScroll
);
337 e_Draw(ScrollLeft
, ctrl
.X
, ctrl
.Y
, 0, True, False);
338 e_Draw(ScrollRight
, ctrl
.X
+ 8 + (ctrl
.Max
+ 1) * 8, ctrl
.Y
, 0, True, False);
339 for a
:= 0 to ctrl
.Max
do
340 e_Draw(ScrollMiddle
, ctrl
.X
+ 8 + a
* 8, ctrl
.Y
, 0, True, False);
341 e_Draw(ScrollMarker
, ctrl
.X
+ 8 + ctrl
.Value
* 8, ctrl
.Y
, 0, True, False);
344 procedure r_GUI_Draw_Switch (ctrl
: TGUISwitch
);
347 f
:= Font
[ctrl
.BigFont
];
348 f
.Draw(ctrl
.X
, ctrl
.Y
, ctrl
.Items
[ctrl
.ItemIndex
], ctrl
.Color
.R
, ctrl
.Color
.G
, ctrl
.Color
.B
);
351 procedure r_GUI_Draw_Edit (ctrl
: TGUIEdit
);
352 var c
, w
, h
: Word; r
, g
, b
: Byte; f
: TFont
;
354 e_Draw(EditLeft
, ctrl
.X
, ctrl
.Y
, 0, True, False);
355 e_Draw(EditRight
, ctrl
.X
+ 8 + ctrl
.Width
* 16, ctrl
.Y
, 0, True, False);
356 for c
:= 0 to ctrl
.Width
- 1 do
357 e_Draw(EditMiddle
, ctrl
.X
+ 8 + c
* 16, ctrl
.Y
, 0, True, False);
361 if ctrl
.Invalid
and (ctrl
.Window
.ActiveControl
<> ctrl
) then
367 f
:= Font
[ctrl
.BigFont
];
368 f
.Draw(ctrl
.X
+ 8, ctrl
.Y
, ctrl
.Text, r
, g
, b
);
369 if ctrl
.Window
.ActiveControl
= ctrl
then
371 f
.GetTextSize(Copy(ctrl
.Text, 1, ctrl
.CaretPos
), w
, h
);
372 h
:= e_CharFont_GetMaxHeight(f
.ID
);
373 e_DrawLine(2, ctrl
.X
+ 8 + w
, ctrl
.Y
+ h
- 3, ctrl
.X
+ 8 + w
+ EDIT_CURSORLEN
, ctrl
.Y
+ h
- 3, EDIT_CURSORCOLOR
.R
, EDIT_CURSORCOLOR
.G
, EDIT_CURSORCOLOR
.B
);
377 procedure r_GUI_Draw_KeyRead (ctrl
: TGUIKeyRead
);
378 var k
: AnsiString; f
: TFont
;
382 else if ctrl
.Key
<> 0 then
383 k
:= e_KeyNames
[ctrl
.Key
]
386 f
:= Font
[ctrl
.BigFont
];
387 f
.Draw(ctrl
.X
, ctrl
.Y
, k
, ctrl
.Color
.R
, ctrl
.Color
.G
, ctrl
.Color
.B
);
390 procedure r_GUI_Draw_KeyRead2 (ctrl
: TGUIKeyRead2
);
392 procedure drawText (idx
: Integer);
393 var x
, y
: Integer; r
, g
, b
: Byte; kk
: DWORD
; str
: AnsiString; f
: TFont
;
395 if idx
= 0 then kk
:= ctrl
.Key0
else kk
:= ctrl
.Key1
;
397 if idx
= 0 then x
:= ctrl
.X
+ 8 else x
:= ctrl
.X
+ 8 + ctrl
.MaxKeyNameWdt
+ 16;
401 if ctrl
.KeyIdx
= idx
then
403 r
:= 255; g
:= 255; b
:= 255;
405 f
:= Font
[ctrl
.BigFont
];
406 if ctrl
.IsQuery
and (ctrl
.KeyIdx
= idx
) then
408 f
.Draw(x
, y
, KEYREAD_QUERY
, r
, g
, b
)
413 str
:= e_KeyNames
[kk
]
415 str
:= KEYREAD_CLEAR
;
416 f
.Draw(x
, y
, str
, r
, g
, b
);
425 procedure DrawBox(X
, Y
: Integer; Width
, Height
: Word);
427 e_Draw(Box
[0], X
, Y
, 0, False, False);
428 e_DrawFill(Box
[1], X
+ 4, Y
, Width
* 4, 1, 0, False, False);
429 e_Draw(Box
[2], X
+ 4 + Width
* 16, Y
, 0, False, False);
430 e_DrawFill(Box
[3], X
, Y
+ 4, 1, Height
* 4, 0, False, False);
431 e_DrawFill(Box
[4], X
+ 4, Y
+ 4, Width
, Height
, 0, False, False);
432 e_DrawFill(Box
[5], X
+ 4 + Width
* 16, Y
+ 4, 1, Height
* 4, 0, False, False);
433 e_Draw(Box
[6], X
, Y
+ 4 + Height
* 16, 0, False, False);
434 e_DrawFill(Box
[7], X
+ 4, Y
+ 4 + Height
* 16, Width
* 4, 1, 0, False, False);
435 e_Draw(Box
[8], X
+ 4 + Width
* 16, Y
+ 4 + Height
* 16, 0, False, False);
438 procedure r_GUI_Draw_ModelView (ctrl
: TGUIModelView
);
440 DrawBox(ctrl
.X
, ctrl
.Y
, 4, 4);
441 if ctrl
.Model
<> nil then
442 r_PlayerModel_Draw(ctrl
.Model
, ctrl
.X
+ 4, ctrl
.Y
+ 4);
445 procedure r_GUI_Draw_MapPreview (ctrl
: TGUIMapPreview
);
446 var a
: Integer; r
, g
, b
: Byte;
448 DrawBox(ctrl
.X
, ctrl
.Y
, MAPPREVIEW_WIDTH
, MAPPREVIEW_HEIGHT
);
449 if (ctrl
.MapSize
.X
<= 0) or (ctrl
.MapSize
.Y
<= 0) then
451 e_DrawFillQuad(ctrl
.X
+ 4, ctrl
.Y
+ 4, ctrl
.X
+ 4 + Trunc(ctrl
.MapSize
.X
/ ctrl
.Scale
) - 1, ctrl
.Y
+ 4 + Trunc(ctrl
.MapSize
.Y
/ ctrl
.Scale
) - 1, 32, 32, 32, 0);
452 if ctrl
.MapData
<> nil then
453 for a
:= 0 to High(ctrl
.MapData
) do
454 with ctrl
.MapData
[a
] do
456 if X1
> MAPPREVIEW_WIDTH
* 16 then Continue
;
457 if Y1
> MAPPREVIEW_HEIGHT
* 16 then Continue
;
458 if X2
< 0 then Continue
;
459 if Y2
< 0 then Continue
;
460 if X2
> MAPPREVIEW_WIDTH
* 16 then X2
:= MAPPREVIEW_WIDTH
* 16;
461 if Y2
> MAPPREVIEW_HEIGHT
* 16 then Y2
:= MAPPREVIEW_HEIGHT
* 16;
462 if X1
< 0 then X1
:= 0;
463 if Y1
< 0 then Y1
:= 0;
467 r
:= 255; g
:= 255; b
:= 255;
471 r
:= 255; g
:= 255; b
:= 0;
475 r
:= 0; g
:= 0; b
:= 192;
479 r
:= 0; g
:= 176; b
:= 0;
483 r
:= 176; g
:= 0; b
:= 0;
486 r
:= 128; g
:= 128; b
:= 128;
488 if ((X2
- X1
) > 0) and ((Y2
- Y1
) > 0) then
489 e_DrawFillQuad(ctrl
.X
+ 4 + X1
, ctrl
.Y
+ 4 + Y1
, ctrl
.X
+ 4 + X2
- 1, ctrl
.Y
+ 4 + Y2
- 1, r
, g
, b
, 0);
493 procedure r_GUI_Draw_Image (ctrl
: TGUIImage
);
496 if ctrl
.ImageRes
= '' then
498 if g_Texture_Get(ctrl
.DefaultRes
, ID
) then
499 e_Draw(ID
, ctrl
.X
, ctrl
.Y
, 0, True, False);
503 if g_Texture_Get(ctrl
.ImageRes
, ID
) then
504 e_Draw(ID
, ctrl
.X
, ctrl
.Y
, 0, True, False);
508 procedure DrawScroll(X
, Y
: Integer; Height
: Word; Up
, Down
: Boolean);
514 g_Texture_Get(BSCROLL_UPA
, ID
)
516 g_Texture_Get(BSCROLL_UPU
, ID
);
517 e_Draw(ID
, X
, Y
, 0, False, False);
519 g_Texture_Get(BSCROLL_DOWNA
, ID
)
521 g_Texture_Get(BSCROLL_DOWNU
, ID
);
522 e_Draw(ID
, X
, Y
+ (Height
- 1) * 16, 0, False, False);
523 g_Texture_Get(BSCROLL_MIDDLE
, ID
);
524 e_DrawFill(ID
, X
, Y
+ 16, 1, Height
- 2, 0, False, False);
527 procedure r_GUI_Draw_ListBox (ctrl
: TGUIListBox
); // + TGUIFileListBox
528 var w2
, h2
: Word; a
: Integer; s
: string; f
: TFont
;
530 if ctrl
.DrawBack
then
531 DrawBox(ctrl
.X
, ctrl
.Y
, ctrl
.Width
+ 1, ctrl
.Height
);
532 if ctrl
.DrawScrollBar
then
533 DrawScroll(ctrl
.X
+ 4 + ctrl
.Width
* 16, ctrl
.Y
+ 4, ctrl
.Height
, (ctrl
.StartLine
> 0) and (ctrl
.Items
<> nil), (ctrl
.StartLine
+ ctrl
.Height
- 1 < High(ctrl
.Items
)) and (ctrl
.Items
<> nil));
534 if ctrl
.Items
<> nil then
536 f
:= Font
[ctrl
.BigFont
];
537 for a
:= ctrl
.StartLine
to Min(High(ctrl
.Items
), ctrl
.StartLine
+ ctrl
.Height
- 1) do
540 f
.GetTextSize(s
, w2
, h2
);
541 while (Length(s
) > 0) and (w2
> ctrl
.Width
* 16) do
543 SetLength(s
, Length(s
) - 1);
544 f
.GetTextSize(s
, w2
, h2
);
546 if a
= ctrl
.ItemIndex
then
547 f
.Draw(ctrl
.X
+ 4, ctrl
.Y
+ 4 + (a
- ctrl
.StartLine
) * 16, s
, ctrl
.ActiveColor
.R
, ctrl
.ActiveColor
.G
, ctrl
.ActiveColor
.B
)
549 f
.Draw(ctrl
.X
+ 4, ctrl
.Y
+ 4 + (a
- ctrl
.StartLine
) * 16, s
, ctrl
.UnActiveColor
.R
, ctrl
.UnActiveColor
.G
, ctrl
.UnActiveColor
.B
);
554 procedure r_GUI_Draw_Memo (ctrl
: TGUIMemo
);
555 var a
: Integer; f
: TFont
;
557 f
:= Font
[ctrl
.BigFont
];
558 if ctrl
.DrawBack
then
559 DrawBox(ctrl
.X
, ctrl
.Y
, ctrl
.Width
+ 1, ctrl
.Height
);
560 if ctrl
.DrawScrollBar
then
561 DrawScroll(ctrl
.X
+ 4 + ctrl
.Width
* 16, ctrl
.Y
+ 4, ctrl
.Height
, (ctrl
.StartLine
> 0) and (ctrl
.Lines
<> nil), (ctrl
.StartLine
+ ctrl
.Height
- 1 < High(ctrl
.Lines
)) and (ctrl
.Lines
<> nil));
562 if ctrl
.Lines
<> nil then
563 for a
:= ctrl
.StartLine
to Min(High(ctrl
.Lines
), ctrl
.StartLine
+ ctrl
.Height
- 1) do
564 f
.Draw(ctrl
.X
+ 4, ctrl
.Y
+ 4 + (a
- ctrl
.StartLine
) * 16, ctrl
.Lines
[a
], ctrl
.Color
.R
, ctrl
.Color
.G
, ctrl
.Color
.B
);
567 procedure r_GUI_Draw_MainMenu (ctrl
: TGUIMainMenu
);
568 var a
: Integer; w
, h
: Word; ID
: DWORD
;
570 if ctrl
.Header
<> nil then
572 r_GUI_Draw_Label(ctrl
.Header
)
574 else if LogoTex
<> 0 then
576 e_GetTextureSize(LogoTex
, @w
, @h
);
577 e_Draw(LogoTex
, ((gScreenWidth
div 2) - (w
div 2)), ctrl
.Buttons
[0].Y
- ctrl
.Buttons
[0].GetHeight
- h
, 0, True, False);
579 if ctrl
.Buttons
<> nil then
581 for a
:= 0 to High(ctrl
.Buttons
) do
582 if ctrl
.Buttons
[a
] <> nil then
583 r_GUI_Draw_TextButton(ctrl
.Buttons
[a
]);
584 if ctrl
.Index
<> -1 then
586 ID
:= MarkerID
[ctrl
.Counter
DIV MAINMENU_MARKERDELAY
MOD 2 <> 0];
587 e_Draw(ID
, ctrl
.Buttons
[ctrl
.Index
].X
- 48, ctrl
.Buttons
[ctrl
.Index
].Y
, 0, True, False);
592 procedure r_GUI_Draw_Menu (ctrl
: TGUIMenu
);
593 var a
, locx
, locy
: Integer; f
: TFont
;
595 if ctrl
.Header
<> nil then
596 r_GUI_Draw_Label(ctrl
.Header
);
597 if ctrl
.Items
<> nil then
599 for a
:= 0 to High(ctrl
.Items
) do
601 if ctrl
.Items
[a
].Text <> nil then
602 r_GUI_Draw_Control(ctrl
.Items
[a
].Text);
603 if ctrl
.Items
[a
].Control
<> nil then
604 r_GUI_Draw_Control(ctrl
.Items
[a
].Control
);
607 if (ctrl
.Index
<> -1) and (ctrl
.Counter
> MENU_MARKERDELAY
div 2) then
611 if ctrl
.Items
[ctrl
.Index
].Text <> nil then
613 locx
:= ctrl
.Items
[ctrl
.Index
].Text.X
;
614 locy
:= ctrl
.Items
[ctrl
.Index
].Text.Y
;
616 if ctrl
.Items
[ctrl
.Index
].Text.RightAlign
then
618 locx
:= locx
+ ctrl
.Items
[ctrl
.Index
].Text.CMaxWidth
- ctrl
.Items
[ctrl
.Index
].Text.GetWidth
;
621 else if ctrl
.Items
[ctrl
.Index
].Control
<> nil then
623 locx
:= ctrl
.Items
[ctrl
.Index
].Control
.X
;
624 locy
:= ctrl
.Items
[ctrl
.Index
].Control
.Y
;
626 f
:= Font
[ctrl
.BigFont
];
627 locx
:= locx
- e_CharFont_GetMaxWidth(f
.ID
);
628 e_CharFont_PrintEx(f
.ID
, locx
, locy
, #16, _RGB(255, 0, 0));
632 procedure r_GUI_Draw_Control (ctrl
: TGUIControl
);
634 if ctrl
is TGUITextButton
then
635 r_GUI_Draw_TextButton(TGUITextButton(ctrl
))
636 else if ctrl
is TGUILabel
then
637 r_GUI_Draw_Label(TGUILabel(ctrl
))
638 else if ctrl
is TGUIScroll
then
639 r_GUI_Draw_Scroll(TGUIScroll(ctrl
))
640 else if ctrl
is TGUISwitch
then
641 r_GUI_Draw_Switch(TGUISwitch(ctrl
))
642 else if ctrl
is TGUIEdit
then
643 r_GUI_Draw_Edit(TGUIEdit(ctrl
))
644 else if ctrl
is TGUIKeyRead
then
645 r_GUI_Draw_KeyRead(TGUIKeyRead(ctrl
))
646 else if ctrl
is TGUIKeyRead2
then
647 r_GUI_Draw_KeyRead2(TGUIKeyRead2(ctrl
))
648 else if ctrl
is TGUIModelView
then
649 r_GUI_Draw_ModelView(TGUIModelView(ctrl
))
650 else if ctrl
is TGUIMapPreview
then
651 r_GUI_Draw_MapPreview(TGUIMapPreview(ctrl
))
652 else if ctrl
is TGUIImage
then
653 r_GUI_Draw_Image(TGUIImage(ctrl
))
654 else if ctrl
is TGUIListBox
then
655 r_GUI_Draw_ListBox(TGUIListBox(ctrl
)) // + TGUIFileListBox
656 else if ctrl
is TGUIMemo
then
657 r_GUI_Draw_Memo(TGUIMemo(ctrl
))
658 else if ctrl
is TGUIMainMenu
then
659 r_GUI_Draw_MainMenu(TGUIMainMenu(ctrl
))
660 else if ctrl
is TGUIMenu
then
661 r_GUI_Draw_Menu(TGUIMenu(ctrl
))
666 procedure r_GUI_Draw_Window (win
: TGUIWindow
);
667 var i
: Integer; ID
: DWORD
; tw
, th
: Word;
669 // Here goes code duplication from g_game.pas:DrawMenuBackground()
670 if win
.BackTexture
<> '' then
671 if g_Texture_Get(win
.BackTexture
, ID
) then
674 e_GetTextureSize(ID
, @tw
, @th
);
676 tw
:= round(tw
* 1.333 * (gScreenHeight
/ th
))
678 tw
:= trunc(tw
* (gScreenHeight
/ th
));
679 e_DrawSize(ID
, (gScreenWidth
- tw
) div 2, 0, 0, False, False, tw
, gScreenHeight
);
682 e_Clear(0.5, 0.5, 0.5);
685 if win
.Name
= 'AuthorsMenu' then
686 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
687 for i
:= 0 to High(win
.Childs
) do
688 if win
.Childs
[i
] <> nil then
689 r_GUI_Draw_Control(win
.Childs
[i
]);