DEADSOFTWARE

7016db9b17456ed6c7ee0f8587b6b5e257a76b2a
[d2df-sdl.git] / src / game / renders / opengl / r_gui.pas
1 (* Copyright (C) Doom 2D: Forever Developers
2 *
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.
6 *
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.
11 *
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/>.
14 *)
15 {$INCLUDE ../../../shared/a_modes.inc}
16 unit r_gui;
18 interface
20 uses g_gui;
22 procedure r_GUI_Load;
23 procedure r_GUI_Free;
25 procedure r_GUI_GetSize (ctrl: TGUIControl; out w, h: Integer);
26 procedure r_GUI_GetLogoSize (out w, h: Integer);
27 procedure r_GUI_GetMaxFontSize (BigFont: Boolean; out w, h: Integer);
28 procedure r_GUI_GetStringSize (BigFont: Boolean; str: String; out w, h: Integer);
30 procedure r_GUI_Draw_Window (win: TGUIWindow);
32 implementation
34 uses
35 Classes, Math, SysUtils,
36 MAPDEF, utils,
37 g_basic, g_base, e_input, g_options,
38 r_draw, r_textures, r_common, r_map,
39 g_game, g_menu
40 ;
42 const
43 EDIT_CURSORLEN = 10;
45 type
46 THereTexture = record
47 name: AnsiString;
48 id: TGLTexture;
49 end;
51 var
52 Box: Array [0..8] of TGLTexture;
53 MarkerID: array [Boolean] of TGLTexture;
54 ScrollLeft, ScrollRight, ScrollMiddle, ScrollMarker: TGLTexture;
55 EditLeft, EditRight, EditMiddle: TGLTexture;
56 BScrollUp, BScrollDown: array [Boolean] of TGLTexture;
57 BScrollMiddle: TGLTexture;
59 Font: array [boolean] of TGLFont; (* Small[FALSE] / Big[TRUE] *)
60 LogoTex: TGLTexture;
61 nopic: TGLTexture;
63 Background: THereTexture;
64 ImageControl: THereTexture;
66 procedure r_GUI_FreeThis (var here: THereTexture);
67 begin
68 here.name := '';
69 if here.id <> nil then
70 here.id.Free;
71 here.id := nil;
72 end;
74 function r_GUI_LoadThis (const name: AnsiString; var here: THereTexture): Boolean;
75 begin
76 r_GUI_FreeThis(here);
77 if (name <> '') and (here.name <> name) then
78 here.id := r_Textures_LoadFromFile(name);
79 result := here.id <> nil;
80 end;
82 procedure r_GUI_Load;
83 var i: Integer;
84 begin
85 Font[FALSE] := smallfont;
86 Font[TRUE] := menufont;
88 MarkerID[FALSE] := r_Textures_LoadFromFile(GameWad + ':TEXTURES/MARKER1');
89 MarkerID[TRUE] := r_Textures_LoadFromFile(GameWad + ':TEXTURES/MARKER2');
91 for i := 0 to 8 do
92 Box[i] := r_Textures_LoadFromFile(GameWad + ':TEXTURES/BOX' + IntToStr(i + 1));
94 ScrollLeft := r_Textures_LoadFromFile(GameWad + ':TEXTURES/SLEFT');
95 ScrollRight := r_Textures_LoadFromFile(GameWad + ':TEXTURES/SRIGHT');
96 ScrollMiddle := r_Textures_LoadFromFile(GameWad + ':TEXTURES/SMIDDLE');
97 ScrollMarker := r_Textures_LoadFromFile(GameWad + ':TEXTURES/SMARKER');
99 EditLeft := r_Textures_LoadFromFile(GameWad + ':TEXTURES/ELEFT');
100 EditRight := r_Textures_LoadFromFile(GameWad + ':TEXTURES/ERIGHT');
101 EditMiddle := r_Textures_LoadFromFile(GameWad + ':TEXTURES/EMIDDLE');
103 BScrollUp[true] := r_Textures_LoadFromFile(GameWad + ':TEXTURES/SCROLLUPA');
104 BScrollUp[false] := r_Textures_LoadFromFile(GameWad + ':TEXTURES/SCROLLUPU');
105 BScrollDown[true] := r_Textures_LoadFromFile(GameWad + ':TEXTURES/SCROLLDOWNA');
106 BScrollDown[false] := r_Textures_LoadFromFile(GameWad + ':TEXTURES/SCROLLDOWNU');
107 BScrollMiddle := r_Textures_LoadFromFile(GameWad + ':TEXTURES/SCROLLMIDDLE');
109 LogoTex := r_Textures_LoadFromFile(GameWad + ':TEXTURES/MAINLOGO');
110 nopic := r_Textures_LoadFromFile(GameWad + ':TEXTURES/NOPIC');
111 end;
113 procedure r_GUI_Free;
114 var i: Integer;
115 begin
116 Font[FALSE] := nil;
117 Font[TRUE] := nil;
119 MarkerID[FALSE].Free;
120 MarkerID[TRUE].Free;
122 for i := 0 to 8 do
123 Box[i].Free;
125 ScrollLeft.Free;
126 ScrollRight.Free;
127 ScrollMiddle.Free;
128 ScrollMarker.Free;
130 EditLeft.Free;
131 EditRight.Free;
132 EditMiddle.Free;
134 BScrollUp[true].Free;
135 BScrollUp[false].Free;
136 BScrollDown[true].Free;
137 BScrollDown[false].Free;
138 BScrollMiddle.Free;
140 LogoTex.Free;
141 nopic.Free;
143 r_GUI_FreeThis(Background);
144 r_GUI_FreeThis(ImageControl);
145 end;
147 procedure r_GUI_GetMaxFontSize (BigFont: Boolean; out w, h: Integer);
148 var f: TGLFont;
149 begin
150 f := Font[BigFont];
151 w := f.GetMaxWidth();
152 h := f.GetMaxHeight();
153 end;
155 procedure r_GUI_GetStringSize (BigFont: Boolean; str: String; out w, h: Integer);
156 begin
157 r_Draw_GetTextSize(str, Font[BigFont], w, h);
158 end;
160 procedure r_GUI_GetLogoSize (out w, h: Integer);
161 begin
162 w := 0; h := 0;
163 if LogoTex <> nil then
164 begin
165 w := LogoTex.width;
166 h := LogoTex.height;
167 end;
168 end;
170 procedure r_GUI_GetSize_TextButton (ctrl: TGUITextButton; out w, h: Integer);
171 begin
172 r_Draw_GetTextSize(ctrl.Caption, Font[ctrl.BigFont], w, h);
173 end;
175 procedure r_GUI_GetSize_Label (ctrl: TGUILabel; out w, h: Integer);
176 var f: TGLFont;
177 begin
178 f := Font[ctrl.BigFont];
179 r_Draw_GetTextSize(ctrl.Text, f, w, h);
180 if ctrl.FixedLength <> 0 then
181 w := f.GetMaxWidth() * ctrl.FixedLength;
182 end;
184 procedure r_GUI_GetSize_Switch (ctrl: TGUISwitch; out w, h: Integer);
185 var i: Integer;
186 begin
187 w := 0; h := 0;
188 if ctrl.Items <> nil then
189 for i := 0 to High(ctrl.Items) do
190 r_Draw_GetTextSize(ctrl.Items[i], Font[ctrl.BigFont], w, h);
191 end;
193 procedure r_GUI_GetSize_KeyRead (ctrl: TGUIKeyRead; out w, h: Integer);
194 var i, ww, hh: Integer; f: TGLFont;
195 begin
196 w := 0; h := 0; // ??? h always 0
197 f := Font[ctrl.BigFont];
198 for i := 0 to 255 do
199 begin
200 r_Draw_GetTextSize(e_KeyNames[i], f, ww, hh);
201 w := MAX(w, ww);
202 end;
203 r_Draw_GetTextSize(KEYREAD_QUERY, f, ww, hh);
204 w := MAX(w, ww);
205 r_Draw_GetTextSize(KEYREAD_CLEAR, f, ww, hh);
206 w := MAX(w, ww);
207 end;
209 procedure r_GUI_GetSize (ctrl: TGUIControl; out w, h: Integer);
210 begin
211 w := 0;
212 h := 0;
213 if ctrl is TGUITextButton then
214 r_GUI_GetSize_TextButton(ctrl as TGUITextButton, w, h)
215 else if ctrl is TGUILabel then
216 r_GUI_GetSize_Label(ctrl as TGUILabel, w, h)
217 else if ctrl is TGUIScroll then
218 w := 16 + ((ctrl as TGUIScroll).Max + 1) * 8 // ??? but h = 0
219 else if ctrl is TGUISwitch then
220 r_GUI_GetSize_Switch(ctrl as TGUISwitch, w, h)
221 else if ctrl is TGUIEdit then
222 w := 16 + (ctrl as TGUIEdit).Width * 16 // ??? but h = 0
223 else if ctrl is TGUIKeyRead then
224 r_GUI_GetSize_KeyRead(ctrl as TGUIKeyRead, w, h)
225 else if ctrl is TGUIKeyRead2 then
226 w := (ctrl as TGUIKeyRead2).MaxKeyNameWdt * 2 + 8 + 8 + 16 // ??? but h = 0
227 else if ctrl is TGUIListBox then
228 begin
229 w := 8 + ((ctrl as TGUIListBox).Width + 1) * 16; // recheck w & h
230 h := 8 + (ctrl as TGUIListBox).Height * 16;
231 end
232 else if ctrl is TGUIMemo then
233 begin
234 w := 8 + ((ctrl as TGUIMemo).Width + 1) * 16;
235 h := 8 + (ctrl as TGUIMemo).Height * 16;
236 end
237 else
238 begin
239 w := ctrl.GetWidth();
240 h := ctrl.GetHeight();
241 end;
242 end;
244 procedure r_GUI_Draw_Control (ctrl: TGUIControl); forward;
246 procedure r_GUI_Draw_TextButton (ctrl: TGUITextButton);
247 begin
248 r_Draw_Text(ctrl.Caption, ctrl.x, ctrl.y, ctrl.Color.R, ctrl.Color.G, ctrl.Color.B, 255, Font[ctrl.BigFont]);
249 end;
251 procedure r_GUI_Draw_Label (ctrl: TGUILabel);
252 var w, h: Integer; f: TGLFont;
253 begin
254 f := Font[ctrl.BigFont];
255 if ctrl.RightAlign then
256 begin
257 r_Draw_GetTextSize(ctrl.Text, f, w, h);
258 r_Draw_Text(ctrl.Text, ctrl.X + ctrl.CMaxWidth - w, ctrl.Y, ctrl.Color.R, ctrl.Color.G, ctrl.Color.B, 255, f);
259 end
260 else
261 r_Draw_Text(ctrl.Text, ctrl.X, ctrl.Y, ctrl.Color.R, ctrl.Color.G, ctrl.Color.B, 255, f);
262 end;
264 procedure r_GUI_Draw_Scroll (ctrl: TGUIScroll);
265 begin
266 r_Draw_Texture(ScrollLeft, ctrl.X, ctrl.Y, ScrollLeft.width, ScrollLeft.height, false, 255, 255, 255, 255, false);
267 r_Draw_TextureRepeat(ScrollMiddle, ctrl.X + 8 + 0 * 8, ctrl.Y, 8 + ctrl.Max * 8, ScrollMiddle.height, false, 255, 255, 255, 255, false);
268 r_Draw_Texture(ScrollRight, ctrl.X + 8 + (ctrl.Max + 1) * 8, ctrl.Y, ScrollRight.width, ScrollRight.height, false, 255, 255, 255, 255, false);
269 r_Draw_Texture(ScrollMarker, ctrl.X + 8 + ctrl.Value * 8, ctrl.Y, ScrollMarker.width, ScrollMarker.height, false, 255, 255, 255, 255, false);
270 end;
272 procedure r_GUI_Draw_Switch (ctrl: TGUISwitch);
273 begin
274 r_Draw_Text(ctrl.Items[ctrl.ItemIndex], ctrl.X, ctrl.Y, ctrl.Color.R, ctrl.Color.G, ctrl.Color.B, 255, Font[ctrl.BigFont]);
275 end;
277 procedure r_GUI_Draw_Edit (ctrl: TGUIEdit);
278 var w, h: Integer; r, g, b: Byte; f: TGLFont;
279 begin
280 r_Draw_Texture(EditLeft, ctrl.X, ctrl.Y, EditLeft.width, EditLeft.height, false, 255, 255, 255, 255, false);
281 r_Draw_TextureRepeat(EditMiddle, ctrl.X + 8, ctrl.Y, 8 + (ctrl.Width - 1) * 16, EditMiddle.height, false, 255, 255, 255, 255, false);
282 r_Draw_Texture(EditRight, ctrl.X + 8 + ctrl.Width * 16, ctrl.Y, EditRight.width, EditRight.height, false, 255, 255, 255, 255, false);
283 r := ctrl.Color.R;
284 g := ctrl.Color.G;
285 b := ctrl.Color.B;
286 if ctrl.Invalid and (ctrl.Window.ActiveControl <> ctrl) then
287 begin
288 r := 128;
289 g := 128;
290 b := 128;
291 end;
292 f := Font[ctrl.BigFont];
293 r_Draw_Text(ctrl.Text, ctrl.X + 8, ctrl.Y, r, g, b, 255, f);
294 if ctrl.Window.ActiveControl = ctrl then
295 begin
296 r_Draw_GetTextSize(Copy(ctrl.Text, 1, ctrl.CaretPos), f, w, h);
297 r_Draw_FillRect(ctrl.X + 8 + w, ctrl.Y + h - 4, ctrl.X + 8 + w + EDIT_CURSORLEN, ctrl.Y + h - 2, 200, 0, 0, 255);
298 end;
299 end;
301 procedure r_GUI_Draw_KeyRead (ctrl: TGUIKeyRead);
302 var k: AnsiString;
303 begin
304 if ctrl.IsQuery then
305 k := KEYREAD_QUERY
306 else if ctrl.Key <> 0 then
307 k := e_KeyNames[ctrl.Key]
308 else
309 k := KEYREAD_CLEAR;
310 r_Draw_Text(k, ctrl.X, ctrl.Y, ctrl.Color.R, ctrl.Color.G, ctrl.Color.B, 255, Font[ctrl.BigFont]);
311 end;
313 procedure r_GUI_Draw_KeyRead2 (ctrl: TGUIKeyRead2);
315 procedure drawText (idx: Integer);
316 var x, y: Integer; r, g, b: Byte; kk: DWORD; str: AnsiString;
317 begin
318 if idx = 0 then kk := ctrl.Key0 else kk := ctrl.Key1;
319 y := ctrl.Y;
320 if idx = 0 then x := ctrl.X + 8 else x := ctrl.X + 8 + ctrl.MaxKeyNameWdt + 16;
321 r := 255; g := 0; b := 0;
322 if ctrl.KeyIdx = idx then
323 begin
324 r := 255; g := 255; b := 255;
325 end;
326 if ctrl.IsQuery and (ctrl.KeyIdx = idx) then
327 str := KEYREAD_QUERY
328 else if kk <> 0 then
329 str := e_KeyNames[kk]
330 else
331 str := KEYREAD_CLEAR;
332 r_Draw_Text(str, x, y, r, g, b, 255, Font[ctrl.BigFont]);
333 end;
335 begin
336 drawText(0);
337 drawText(1);
338 end;
340 procedure DrawBox (x, y, w, h: Integer);
341 begin
342 r_Draw_Texture(Box[0], x, y, 4, 4, false, 255, 255, 255, 255, false);
343 r_Draw_TextureRepeat(Box[1], x + 4, y, w * 16, 4, false, 255, 255, 255, 255, false);
344 r_Draw_Texture(Box[2], x + 4 + w * 16, y, 4, 4, false, 255, 255, 255, 255, false);
346 r_Draw_TextureRepeat(Box[3], x, y + 4, 4, h * 16, false, 255, 255, 255, 255, false);
347 r_Draw_TextureRepeat(Box[4], x + 4, y + 4, w * 16, h * 16, false, 255, 255, 255, 255, false);
348 r_Draw_TextureRepeat(Box[5], x + 4 + w * 16, y + 4, 4, h * 16, false, 255, 255, 255, 255, false);
350 r_Draw_Texture(Box[6], x, y + 4 + h * 16, 4, 4, false, 255, 255, 255, 255, false);
351 r_Draw_TextureRepeat(Box[7], x + 4, y + 4 + h * 16, w * 16, 4, false, 255, 255, 255, 255, false);
352 r_Draw_Texture(Box[8], x + 4 + w * 16, y + 4 + h * 16, 4, 4, false, 255, 255, 255, 255, false);
353 end;
355 procedure r_GUI_Draw_ModelView (ctrl: TGUIModelView);
356 begin
357 DrawBox(ctrl.X, ctrl.Y, 4, 4);
358 if ctrl.Model <> nil then
359 r_Map_DrawPlayerModel(ctrl.Model, ctrl.X + 4, ctrl.Y + 4, 255);
360 end;
362 procedure r_GUI_Draw_MapPreview (ctrl: TGUIMapPreview);
363 var a: Integer; r, g, b: Byte;
364 begin
365 DrawBox(ctrl.X, ctrl.Y, MAPPREVIEW_WIDTH, MAPPREVIEW_HEIGHT);
366 if (ctrl.MapSize.X <= 0) or (ctrl.MapSize.Y <= 0) then
367 Exit;
368 r_Draw_FillRect(ctrl.X + 4, ctrl.Y + 4, ctrl.X + 4 + Trunc(ctrl.MapSize.X / ctrl.Scale), ctrl.Y + 4 + Trunc(ctrl.MapSize.Y / ctrl.Scale), 32, 32, 32, 255);
369 if ctrl.MapData <> nil then
370 for a := 0 to High(ctrl.MapData) do
371 with ctrl.MapData[a] do
372 begin
373 if X1 > MAPPREVIEW_WIDTH * 16 then Continue;
374 if Y1 > MAPPREVIEW_HEIGHT * 16 then Continue;
375 if X2 < 0 then Continue;
376 if Y2 < 0 then Continue;
377 if X2 > MAPPREVIEW_WIDTH * 16 then X2 := MAPPREVIEW_WIDTH * 16;
378 if Y2 > MAPPREVIEW_HEIGHT * 16 then Y2 := MAPPREVIEW_HEIGHT * 16;
379 if X1 < 0 then X1 := 0;
380 if Y1 < 0 then Y1 := 0;
381 case PanelType of
382 PANEL_WALL:
383 begin
384 r := 255; g := 255; b := 255;
385 end;
386 PANEL_CLOSEDOOR:
387 begin
388 r := 255; g := 255; b := 0;
389 end;
390 PANEL_WATER:
391 begin
392 r := 0; g := 0; b := 192;
393 end;
394 PANEL_ACID1:
395 begin
396 r := 0; g := 176; b := 0;
397 end;
398 PANEL_ACID2:
399 begin
400 r := 176; g := 0; b := 0;
401 end;
402 else
403 r := 128; g := 128; b := 128;
404 end;
405 if ((X2 - X1) > 0) and ((Y2 - Y1) > 0) then
406 r_Draw_FillRect(ctrl.X + 4 + X1, ctrl.Y + 4 + Y1, ctrl.X + 4 + X2, ctrl.Y + 4 + Y2, r, g, b, 255);
407 end;
408 end;
410 procedure r_GUI_Draw_Image (ctrl: TGUIImage);
411 var pic: TGLTexture;
412 begin
413 pic := nopic;
414 if ctrl.ImageRes <> '' then
415 if r_GUI_LoadThis(ctrl.ImageRes, ImageControl) then
416 pic := ImageControl.id;
417 if pic <> nil then
418 r_Draw_Texture(pic, ctrl.x, ctrl.y, pic.width, pic.height, false, 255, 255, 255, 255, false);
419 end;
421 procedure DrawScroll(x, y, h: Integer; Up, Down: Boolean);
422 var t: TGLTexture;
423 begin
424 if h >= 3 then
425 begin
426 t := BScrollUp[Up];
427 r_Draw_Texture(t, x, y, t.width, t.height, false, 255, 255, 255, 255, false);
428 t := BScrollDown[Down];
429 r_Draw_Texture(t, x, y + (h - 1) * 16, t.width, t.height, false, 255, 255, 255, 255, false);
430 t := BScrollMiddle;
431 r_Draw_TextureRepeat(t, x, y + 16, t.width, (h - 2) * 16, false, 255, 255, 255, 255, false);
432 end;
433 end;
435 procedure r_GUI_Draw_ListBox (ctrl: TGUIListBox); // + TGUIFileListBox
436 var a, w2, h2: Integer; s: string; col: TRGB; f: TGLFont;
437 begin
438 if ctrl.DrawBack then
439 DrawBox(ctrl.X, ctrl.Y, ctrl.Width + 1, ctrl.Height);
440 if ctrl.DrawScrollBar then
441 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));
442 if ctrl.Items <> nil then
443 begin
444 f := Font[ctrl.BigFont];
445 for a := ctrl.StartLine to Min(High(ctrl.Items), ctrl.StartLine + ctrl.Height - 1) do
446 begin
447 s := ctrl.Items[a];
448 r_Draw_GetTextSize(s, f, w2, h2);
449 while (Length(s) > 0) and (w2 > ctrl.Width * 16) do
450 begin
451 SetLength(s, Length(s) - 1);
452 r_Draw_GetTextSize(s, f, w2, h2);
453 end;
454 if a = ctrl.ItemIndex then col := ctrl.ActiveColor else col := ctrl.UnActiveColor;
455 r_Draw_Text(s, ctrl.X + 4, ctrl.Y + 4 + (a - ctrl.StartLine) * 16, col.r, col.g, col.b, 255, f);
456 end;
457 end;
458 end;
460 procedure r_GUI_Draw_Memo (ctrl: TGUIMemo);
461 var i: Integer;
462 begin
463 if ctrl.DrawBack then
464 DrawBox(ctrl.X, ctrl.Y, ctrl.Width + 1, ctrl.Height);
465 if ctrl.DrawScrollBar then
466 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));
467 if ctrl.Lines <> nil then
468 for i := ctrl.StartLine to Min(High(ctrl.Lines), ctrl.StartLine + ctrl.Height - 1) do
469 r_Draw_Text(ctrl.Lines[i], ctrl.X + 4, ctrl.Y + 4 + (i - ctrl.StartLine) * 16, ctrl.Color.R, ctrl.Color.G, ctrl.Color.B, 255, Font[ctrl.BigFont]);
470 end;
472 procedure r_GUI_Draw_MainMenu (ctrl: TGUIMainMenu);
473 var i, w, h: Integer; ID: TGLTexture;
474 begin
475 if ctrl.Header <> nil then
476 begin
477 r_GUI_Draw_Label(ctrl.Header)
478 end
479 else if LogoTex <> nil then
480 begin
481 r_GUI_GetLogoSize(w, h);
482 r_Draw_Texture(LogoTex, ((gScreenWidth div 2) - (w div 2)), ctrl.Buttons[0].Y - ctrl.Buttons[0].GetHeight - h, w, h, false, 255, 255, 255, 255, false);
483 end;
484 if ctrl.Buttons <> nil then
485 begin
486 for i := 0 to High(ctrl.Buttons) do
487 if ctrl.Buttons[i] <> nil then
488 r_GUI_Draw_TextButton(ctrl.Buttons[i]);
489 if ctrl.Index <> -1 then
490 begin
491 ID := MarkerID[ctrl.Counter DIV MAINMENU_MARKERDELAY MOD 2 <> 0];
492 r_Draw_Texture(ID, ctrl.Buttons[ctrl.Index].X - 48, ctrl.Buttons[ctrl.Index].Y, ID.width, ID.height, false, 255, 255, 255, 255, false);
493 end
494 end;
495 end;
497 procedure r_GUI_Draw_Menu (ctrl: TGUIMenu);
498 var a, locx, locy: Integer; f: TGLFont;
499 begin
500 if ctrl.Header <> nil then
501 r_GUI_Draw_Label(ctrl.Header);
502 if ctrl.Items <> nil then
503 begin
504 for a := 0 to High(ctrl.Items) do
505 begin
506 if ctrl.Items[a].Text <> nil then
507 r_GUI_Draw_Control(ctrl.Items[a].Text);
508 if ctrl.Items[a].Control <> nil then
509 r_GUI_Draw_Control(ctrl.Items[a].Control);
510 end;
511 end;
512 if (ctrl.Index <> -1) and (ctrl.Counter > MENU_MARKERDELAY div 2) then
513 begin
514 locx := 0;
515 locy := 0;
516 if ctrl.Items[ctrl.Index].Text <> nil then
517 begin
518 locx := ctrl.Items[ctrl.Index].Text.X;
519 locy := ctrl.Items[ctrl.Index].Text.Y;
520 //HACK!
521 if ctrl.Items[ctrl.Index].Text.RightAlign then
522 begin
523 locx := locx + ctrl.Items[ctrl.Index].Text.CMaxWidth - ctrl.Items[ctrl.Index].Text.GetWidth;
524 end;
525 end
526 else if ctrl.Items[ctrl.Index].Control <> nil then
527 begin
528 locx := ctrl.Items[ctrl.Index].Control.X;
529 locy := ctrl.Items[ctrl.Index].Control.Y;
530 end;
531 f := Font[ctrl.BigFont];
532 locx := locx - f.GetMaxWidth();
533 r_Draw_Text(#16, locx, locy, 255, 0, 0, 255, f);
534 end;
535 end;
537 procedure r_GUI_Draw_Control (ctrl: TGUIControl);
538 begin
539 if ctrl is TGUITextButton then
540 r_GUI_Draw_TextButton(TGUITextButton(ctrl))
541 else if ctrl is TGUILabel then
542 r_GUI_Draw_Label(TGUILabel(ctrl))
543 else if ctrl is TGUIScroll then
544 r_GUI_Draw_Scroll(TGUIScroll(ctrl))
545 else if ctrl is TGUISwitch then
546 r_GUI_Draw_Switch(TGUISwitch(ctrl))
547 else if ctrl is TGUIEdit then
548 r_GUI_Draw_Edit(TGUIEdit(ctrl))
549 else if ctrl is TGUIKeyRead then
550 r_GUI_Draw_KeyRead(TGUIKeyRead(ctrl))
551 else if ctrl is TGUIKeyRead2 then
552 r_GUI_Draw_KeyRead2(TGUIKeyRead2(ctrl))
553 else if ctrl is TGUIModelView then
554 r_GUI_Draw_ModelView(TGUIModelView(ctrl))
555 else if ctrl is TGUIMapPreview then
556 r_GUI_Draw_MapPreview(TGUIMapPreview(ctrl))
557 else if ctrl is TGUIImage then
558 r_GUI_Draw_Image(TGUIImage(ctrl))
559 else if ctrl is TGUIListBox then
560 r_GUI_Draw_ListBox(TGUIListBox(ctrl)) // + TGUIFileListBox
561 else if ctrl is TGUIMemo then
562 r_GUI_Draw_Memo(TGUIMemo(ctrl))
563 else if ctrl is TGUIMainMenu then
564 r_GUI_Draw_MainMenu(TGUIMainMenu(ctrl))
565 else if ctrl is TGUIMenu then
566 r_GUI_Draw_Menu(TGUIMenu(ctrl))
567 else
568 Assert(False)
569 end;
571 procedure r_GUI_Draw_Window (win: TGUIWindow);
572 var i, tw, th: Integer;
573 begin
574 // Here goes code duplication from g_game.pas:DrawMenuBackground()
575 if win.BackTexture <> '' then
576 if r_GUI_LoadThis(win.BackTexture, Background) then
577 begin
578 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 255);
579 tw := Background.id.width;
580 th := Background.id.height;
581 if tw = th then
582 tw := round(tw * 1.333 * (gScreenHeight / th))
583 else
584 tw := trunc(tw * (gScreenHeight / th));
585 r_Draw_Texture(Background.id, (gScreenWidth - tw) div 2, 0, tw, gScreenHeight, false, 255, 255, 255, 255, false);
586 end
587 else
588 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 127, 127, 127, 255);
590 // small hack here
591 if win.Name = 'AuthorsMenu' then
592 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
593 for i := 0 to High(win.Childs) do
594 if win.Childs[i] <> nil then
595 r_GUI_Draw_Control(win.Childs[i]);
596 end;
598 end.