DEADSOFTWARE

gl: draw menu background
[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 var
46 Box: Array [0..8] of TGLTexture;
47 MarkerID: array [Boolean] of TGLTexture;
48 ScrollLeft, ScrollRight, ScrollMiddle, ScrollMarker: TGLTexture;
49 EditLeft, EditRight, EditMiddle: TGLTexture;
50 BScrollUp, BScrollDown: array [Boolean] of TGLTexture;
51 BScrollMiddle: TGLTexture;
53 Font: array [boolean] of TGLFont; (* Small[FALSE] / Big[TRUE] *)
54 LogoTex: TGLTexture;
55 nopic: TGLTexture;
57 Background: THereTexture;
58 ImageControl: THereTexture;
60 procedure r_GUI_Load;
61 var i: Integer;
62 begin
63 Font[FALSE] := smallfont;
64 Font[TRUE] := menufont;
66 MarkerID[FALSE] := r_Textures_LoadFromFile(GameWad + ':TEXTURES/MARKER1');
67 MarkerID[TRUE] := r_Textures_LoadFromFile(GameWad + ':TEXTURES/MARKER2');
69 for i := 0 to 8 do
70 Box[i] := r_Textures_LoadFromFile(GameWad + ':TEXTURES/BOX' + IntToStr(i + 1));
72 ScrollLeft := r_Textures_LoadFromFile(GameWad + ':TEXTURES/SLEFT');
73 ScrollRight := r_Textures_LoadFromFile(GameWad + ':TEXTURES/SRIGHT');
74 ScrollMiddle := r_Textures_LoadFromFile(GameWad + ':TEXTURES/SMIDDLE');
75 ScrollMarker := r_Textures_LoadFromFile(GameWad + ':TEXTURES/SMARKER');
77 EditLeft := r_Textures_LoadFromFile(GameWad + ':TEXTURES/ELEFT');
78 EditRight := r_Textures_LoadFromFile(GameWad + ':TEXTURES/ERIGHT');
79 EditMiddle := r_Textures_LoadFromFile(GameWad + ':TEXTURES/EMIDDLE');
81 BScrollUp[true] := r_Textures_LoadFromFile(GameWad + ':TEXTURES/SCROLLUPA');
82 BScrollUp[false] := r_Textures_LoadFromFile(GameWad + ':TEXTURES/SCROLLUPU');
83 BScrollDown[true] := r_Textures_LoadFromFile(GameWad + ':TEXTURES/SCROLLDOWNA');
84 BScrollDown[false] := r_Textures_LoadFromFile(GameWad + ':TEXTURES/SCROLLDOWNU');
85 BScrollMiddle := r_Textures_LoadFromFile(GameWad + ':TEXTURES/SCROLLMIDDLE');
87 LogoTex := r_Textures_LoadFromFile(GameWad + ':TEXTURES/MAINLOGO');
88 nopic := r_Textures_LoadFromFile(GameWad + ':TEXTURES/NOPIC');
89 end;
91 procedure r_GUI_Free;
92 var i: Integer;
93 begin
94 Font[FALSE] := nil;
95 Font[TRUE] := nil;
97 MarkerID[FALSE].Free;
98 MarkerID[TRUE].Free;
100 for i := 0 to 8 do
101 Box[i].Free;
103 ScrollLeft.Free;
104 ScrollRight.Free;
105 ScrollMiddle.Free;
106 ScrollMarker.Free;
108 EditLeft.Free;
109 EditRight.Free;
110 EditMiddle.Free;
112 BScrollUp[true].Free;
113 BScrollUp[false].Free;
114 BScrollDown[true].Free;
115 BScrollDown[false].Free;
116 BScrollMiddle.Free;
118 LogoTex.Free;
119 nopic.Free;
121 r_Common_FreeThis(Background);
122 r_Common_FreeThis(ImageControl);
123 end;
125 procedure r_GUI_GetMaxFontSize (BigFont: Boolean; out w, h: Integer);
126 var f: TGLFont;
127 begin
128 f := Font[BigFont];
129 w := f.GetMaxWidth();
130 h := f.GetMaxHeight();
131 end;
133 procedure r_GUI_GetStringSize (BigFont: Boolean; str: String; out w, h: Integer);
134 begin
135 r_Draw_GetTextSize(str, Font[BigFont], w, h);
136 end;
138 procedure r_GUI_GetLogoSize (out w, h: Integer);
139 begin
140 w := 0; h := 0;
141 if LogoTex <> nil then
142 begin
143 w := LogoTex.width;
144 h := LogoTex.height;
145 end;
146 end;
148 procedure r_GUI_GetSize_TextButton (ctrl: TGUITextButton; out w, h: Integer);
149 begin
150 r_Draw_GetTextSize(ctrl.Caption, Font[ctrl.BigFont], w, h);
151 end;
153 procedure r_GUI_GetSize_Label (ctrl: TGUILabel; out w, h: Integer);
154 var f: TGLFont;
155 begin
156 f := Font[ctrl.BigFont];
157 r_Draw_GetTextSize(ctrl.Text, f, w, h);
158 if ctrl.FixedLength <> 0 then
159 w := f.GetMaxWidth() * ctrl.FixedLength;
160 end;
162 procedure r_GUI_GetSize_Switch (ctrl: TGUISwitch; out w, h: Integer);
163 var i: Integer;
164 begin
165 w := 0; h := 0;
166 if ctrl.Items <> nil then
167 for i := 0 to High(ctrl.Items) do
168 r_Draw_GetTextSize(ctrl.Items[i], Font[ctrl.BigFont], w, h);
169 end;
171 procedure r_GUI_GetSize_KeyRead (ctrl: TGUIKeyRead; out w, h: Integer);
172 var i, ww, hh: Integer; f: TGLFont;
173 begin
174 w := 0; h := 0; // ??? h always 0
175 f := Font[ctrl.BigFont];
176 for i := 0 to 255 do
177 begin
178 r_Draw_GetTextSize(e_KeyNames[i], f, ww, hh);
179 w := MAX(w, ww);
180 end;
181 r_Draw_GetTextSize(KEYREAD_QUERY, f, ww, hh);
182 w := MAX(w, ww);
183 r_Draw_GetTextSize(KEYREAD_CLEAR, f, ww, hh);
184 w := MAX(w, ww);
185 end;
187 procedure r_GUI_GetSize (ctrl: TGUIControl; out w, h: Integer);
188 begin
189 w := 0;
190 h := 0;
191 if ctrl is TGUITextButton then
192 r_GUI_GetSize_TextButton(ctrl as TGUITextButton, w, h)
193 else if ctrl is TGUILabel then
194 r_GUI_GetSize_Label(ctrl as TGUILabel, w, h)
195 else if ctrl is TGUIScroll then
196 w := 16 + ((ctrl as TGUIScroll).Max + 1) * 8 // ??? but h = 0
197 else if ctrl is TGUISwitch then
198 r_GUI_GetSize_Switch(ctrl as TGUISwitch, w, h)
199 else if ctrl is TGUIEdit then
200 w := 16 + (ctrl as TGUIEdit).Width * 16 // ??? but h = 0
201 else if ctrl is TGUIKeyRead then
202 r_GUI_GetSize_KeyRead(ctrl as TGUIKeyRead, w, h)
203 else if ctrl is TGUIKeyRead2 then
204 w := (ctrl as TGUIKeyRead2).MaxKeyNameWdt * 2 + 8 + 8 + 16 // ??? but h = 0
205 else if ctrl is TGUIListBox then
206 begin
207 w := 8 + ((ctrl as TGUIListBox).Width + 1) * 16; // recheck w & h
208 h := 8 + (ctrl as TGUIListBox).Height * 16;
209 end
210 else if ctrl is TGUIMemo then
211 begin
212 w := 8 + ((ctrl as TGUIMemo).Width + 1) * 16;
213 h := 8 + (ctrl as TGUIMemo).Height * 16;
214 end
215 else
216 begin
217 w := ctrl.GetWidth();
218 h := ctrl.GetHeight();
219 end;
220 end;
222 procedure r_GUI_Draw_Control (ctrl: TGUIControl); forward;
224 procedure r_GUI_Draw_TextButton (ctrl: TGUITextButton);
225 begin
226 r_Draw_Text(ctrl.Caption, ctrl.x, ctrl.y, ctrl.Color.R, ctrl.Color.G, ctrl.Color.B, 255, Font[ctrl.BigFont]);
227 end;
229 procedure r_GUI_Draw_Label (ctrl: TGUILabel);
230 var w, h: Integer; f: TGLFont;
231 begin
232 f := Font[ctrl.BigFont];
233 if ctrl.RightAlign then
234 begin
235 r_Draw_GetTextSize(ctrl.Text, f, w, h);
236 r_Draw_Text(ctrl.Text, ctrl.X + ctrl.CMaxWidth - w, ctrl.Y, ctrl.Color.R, ctrl.Color.G, ctrl.Color.B, 255, f);
237 end
238 else
239 r_Draw_Text(ctrl.Text, ctrl.X, ctrl.Y, ctrl.Color.R, ctrl.Color.G, ctrl.Color.B, 255, f);
240 end;
242 procedure r_GUI_Draw_Scroll (ctrl: TGUIScroll);
243 begin
244 r_Draw_Texture(ScrollLeft, ctrl.X, ctrl.Y, ScrollLeft.width, ScrollLeft.height, false, 255, 255, 255, 255, false);
245 r_Draw_TextureRepeat(ScrollMiddle, ctrl.X + 8 + 0 * 8, ctrl.Y, 8 + ctrl.Max * 8, ScrollMiddle.height, false, 255, 255, 255, 255, false);
246 r_Draw_Texture(ScrollRight, ctrl.X + 8 + (ctrl.Max + 1) * 8, ctrl.Y, ScrollRight.width, ScrollRight.height, false, 255, 255, 255, 255, false);
247 r_Draw_Texture(ScrollMarker, ctrl.X + 8 + ctrl.Value * 8, ctrl.Y, ScrollMarker.width, ScrollMarker.height, false, 255, 255, 255, 255, false);
248 end;
250 procedure r_GUI_Draw_Switch (ctrl: TGUISwitch);
251 begin
252 r_Draw_Text(ctrl.Items[ctrl.ItemIndex], ctrl.X, ctrl.Y, ctrl.Color.R, ctrl.Color.G, ctrl.Color.B, 255, Font[ctrl.BigFont]);
253 end;
255 procedure r_GUI_Draw_Edit (ctrl: TGUIEdit);
256 var w, h: Integer; r, g, b: Byte; f: TGLFont;
257 begin
258 r_Draw_Texture(EditLeft, ctrl.X, ctrl.Y, EditLeft.width, EditLeft.height, false, 255, 255, 255, 255, false);
259 r_Draw_TextureRepeat(EditMiddle, ctrl.X + 8, ctrl.Y, 8 + (ctrl.Width - 1) * 16, EditMiddle.height, false, 255, 255, 255, 255, false);
260 r_Draw_Texture(EditRight, ctrl.X + 8 + ctrl.Width * 16, ctrl.Y, EditRight.width, EditRight.height, false, 255, 255, 255, 255, false);
261 r := ctrl.Color.R;
262 g := ctrl.Color.G;
263 b := ctrl.Color.B;
264 if ctrl.Invalid and (ctrl.Window.ActiveControl <> ctrl) then
265 begin
266 r := 128;
267 g := 128;
268 b := 128;
269 end;
270 f := Font[ctrl.BigFont];
271 r_Draw_Text(ctrl.Text, ctrl.X + 8, ctrl.Y, r, g, b, 255, f);
272 if ctrl.Window.ActiveControl = ctrl then
273 begin
274 r_Draw_GetTextSize(Copy(ctrl.Text, 1, ctrl.CaretPos), f, w, h);
275 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);
276 end;
277 end;
279 procedure r_GUI_Draw_KeyRead (ctrl: TGUIKeyRead);
280 var k: AnsiString;
281 begin
282 if ctrl.IsQuery then
283 k := KEYREAD_QUERY
284 else if ctrl.Key <> 0 then
285 k := e_KeyNames[ctrl.Key]
286 else
287 k := KEYREAD_CLEAR;
288 r_Draw_Text(k, ctrl.X, ctrl.Y, ctrl.Color.R, ctrl.Color.G, ctrl.Color.B, 255, Font[ctrl.BigFont]);
289 end;
291 procedure r_GUI_Draw_KeyRead2 (ctrl: TGUIKeyRead2);
293 procedure drawText (idx: Integer);
294 var x, y: Integer; r, g, b: Byte; kk: DWORD; str: AnsiString;
295 begin
296 if idx = 0 then kk := ctrl.Key0 else kk := ctrl.Key1;
297 y := ctrl.Y;
298 if idx = 0 then x := ctrl.X + 8 else x := ctrl.X + 8 + ctrl.MaxKeyNameWdt + 16;
299 r := 255; g := 0; b := 0;
300 if ctrl.KeyIdx = idx then
301 begin
302 r := 255; g := 255; b := 255;
303 end;
304 if ctrl.IsQuery and (ctrl.KeyIdx = idx) then
305 str := KEYREAD_QUERY
306 else if kk <> 0 then
307 str := e_KeyNames[kk]
308 else
309 str := KEYREAD_CLEAR;
310 r_Draw_Text(str, x, y, r, g, b, 255, Font[ctrl.BigFont]);
311 end;
313 begin
314 drawText(0);
315 drawText(1);
316 end;
318 procedure DrawBox (x, y, w, h: Integer);
319 begin
320 r_Draw_Texture(Box[0], x, y, 4, 4, false, 255, 255, 255, 255, false);
321 r_Draw_TextureRepeat(Box[1], x + 4, y, w * 16, 4, false, 255, 255, 255, 255, false);
322 r_Draw_Texture(Box[2], x + 4 + w * 16, y, 4, 4, false, 255, 255, 255, 255, false);
324 r_Draw_TextureRepeat(Box[3], x, y + 4, 4, h * 16, false, 255, 255, 255, 255, false);
325 r_Draw_TextureRepeat(Box[4], x + 4, y + 4, w * 16, h * 16, false, 255, 255, 255, 255, false);
326 r_Draw_TextureRepeat(Box[5], x + 4 + w * 16, y + 4, 4, h * 16, false, 255, 255, 255, 255, false);
328 r_Draw_Texture(Box[6], x, y + 4 + h * 16, 4, 4, false, 255, 255, 255, 255, false);
329 r_Draw_TextureRepeat(Box[7], x + 4, y + 4 + h * 16, w * 16, 4, false, 255, 255, 255, 255, false);
330 r_Draw_Texture(Box[8], x + 4 + w * 16, y + 4 + h * 16, 4, 4, false, 255, 255, 255, 255, false);
331 end;
333 procedure r_GUI_Draw_ModelView (ctrl: TGUIModelView);
334 begin
335 DrawBox(ctrl.X, ctrl.Y, 4, 4);
336 if ctrl.Model <> nil then
337 r_Map_DrawPlayerModel(ctrl.Model, ctrl.X + 4, ctrl.Y + 4, 255);
338 end;
340 procedure r_GUI_Draw_MapPreview (ctrl: TGUIMapPreview);
341 var a: Integer; r, g, b: Byte;
342 begin
343 DrawBox(ctrl.X, ctrl.Y, MAPPREVIEW_WIDTH, MAPPREVIEW_HEIGHT);
344 if (ctrl.MapSize.X <= 0) or (ctrl.MapSize.Y <= 0) then
345 Exit;
346 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);
347 if ctrl.MapData <> nil then
348 for a := 0 to High(ctrl.MapData) do
349 with ctrl.MapData[a] do
350 begin
351 if X1 > MAPPREVIEW_WIDTH * 16 then Continue;
352 if Y1 > MAPPREVIEW_HEIGHT * 16 then Continue;
353 if X2 < 0 then Continue;
354 if Y2 < 0 then Continue;
355 if X2 > MAPPREVIEW_WIDTH * 16 then X2 := MAPPREVIEW_WIDTH * 16;
356 if Y2 > MAPPREVIEW_HEIGHT * 16 then Y2 := MAPPREVIEW_HEIGHT * 16;
357 if X1 < 0 then X1 := 0;
358 if Y1 < 0 then Y1 := 0;
359 case PanelType of
360 PANEL_WALL:
361 begin
362 r := 255; g := 255; b := 255;
363 end;
364 PANEL_CLOSEDOOR:
365 begin
366 r := 255; g := 255; b := 0;
367 end;
368 PANEL_WATER:
369 begin
370 r := 0; g := 0; b := 192;
371 end;
372 PANEL_ACID1:
373 begin
374 r := 0; g := 176; b := 0;
375 end;
376 PANEL_ACID2:
377 begin
378 r := 176; g := 0; b := 0;
379 end;
380 else
381 r := 128; g := 128; b := 128;
382 end;
383 if ((X2 - X1) > 0) and ((Y2 - Y1) > 0) then
384 r_Draw_FillRect(ctrl.X + 4 + X1, ctrl.Y + 4 + Y1, ctrl.X + 4 + X2, ctrl.Y + 4 + Y2, r, g, b, 255);
385 end;
386 end;
388 procedure r_GUI_Draw_Image (ctrl: TGUIImage);
389 var pic: TGLTexture;
390 begin
391 pic := nopic;
392 if ctrl.ImageRes <> '' then
393 if r_Common_LoadThis(ctrl.ImageRes, ImageControl) then
394 pic := ImageControl.id;
395 if pic <> nil then
396 r_Draw_Texture(pic, ctrl.x, ctrl.y, pic.width, pic.height, false, 255, 255, 255, 255, false);
397 end;
399 procedure DrawScroll(x, y, h: Integer; Up, Down: Boolean);
400 var t: TGLTexture;
401 begin
402 if h >= 3 then
403 begin
404 t := BScrollUp[Up];
405 r_Draw_Texture(t, x, y, t.width, t.height, false, 255, 255, 255, 255, false);
406 t := BScrollDown[Down];
407 r_Draw_Texture(t, x, y + (h - 1) * 16, t.width, t.height, false, 255, 255, 255, 255, false);
408 t := BScrollMiddle;
409 r_Draw_TextureRepeat(t, x, y + 16, t.width, (h - 2) * 16, false, 255, 255, 255, 255, false);
410 end;
411 end;
413 procedure r_GUI_Draw_ListBox (ctrl: TGUIListBox); // + TGUIFileListBox
414 var a, w2, h2: Integer; s: string; col: TRGB; f: TGLFont;
415 begin
416 if ctrl.DrawBack then
417 DrawBox(ctrl.X, ctrl.Y, ctrl.Width + 1, ctrl.Height);
418 if ctrl.DrawScrollBar then
419 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));
420 if ctrl.Items <> nil then
421 begin
422 f := Font[ctrl.BigFont];
423 for a := ctrl.StartLine to Min(High(ctrl.Items), ctrl.StartLine + ctrl.Height - 1) do
424 begin
425 s := ctrl.Items[a];
426 r_Draw_GetTextSize(s, f, w2, h2);
427 while (Length(s) > 0) and (w2 > ctrl.Width * 16) do
428 begin
429 SetLength(s, Length(s) - 1);
430 r_Draw_GetTextSize(s, f, w2, h2);
431 end;
432 if a = ctrl.ItemIndex then col := ctrl.ActiveColor else col := ctrl.UnActiveColor;
433 r_Draw_Text(s, ctrl.X + 4, ctrl.Y + 4 + (a - ctrl.StartLine) * 16, col.r, col.g, col.b, 255, f);
434 end;
435 end;
436 end;
438 procedure r_GUI_Draw_Memo (ctrl: TGUIMemo);
439 var i: Integer;
440 begin
441 if ctrl.DrawBack then
442 DrawBox(ctrl.X, ctrl.Y, ctrl.Width + 1, ctrl.Height);
443 if ctrl.DrawScrollBar then
444 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));
445 if ctrl.Lines <> nil then
446 for i := ctrl.StartLine to Min(High(ctrl.Lines), ctrl.StartLine + ctrl.Height - 1) do
447 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]);
448 end;
450 procedure r_GUI_Draw_MainMenu (ctrl: TGUIMainMenu);
451 var i, w, h: Integer; ID: TGLTexture;
452 begin
453 if ctrl.Header <> nil then
454 begin
455 r_GUI_Draw_Label(ctrl.Header)
456 end
457 else if LogoTex <> nil then
458 begin
459 r_GUI_GetLogoSize(w, h);
460 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);
461 end;
462 if ctrl.Buttons <> nil then
463 begin
464 for i := 0 to High(ctrl.Buttons) do
465 if ctrl.Buttons[i] <> nil then
466 r_GUI_Draw_TextButton(ctrl.Buttons[i]);
467 if ctrl.Index <> -1 then
468 begin
469 ID := MarkerID[ctrl.Counter DIV MAINMENU_MARKERDELAY MOD 2 <> 0];
470 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);
471 end
472 end;
473 end;
475 procedure r_GUI_Draw_Menu (ctrl: TGUIMenu);
476 var a, locx, locy: Integer; f: TGLFont;
477 begin
478 if ctrl.Header <> nil then
479 r_GUI_Draw_Label(ctrl.Header);
480 if ctrl.Items <> nil then
481 begin
482 for a := 0 to High(ctrl.Items) do
483 begin
484 if ctrl.Items[a].Text <> nil then
485 r_GUI_Draw_Control(ctrl.Items[a].Text);
486 if ctrl.Items[a].Control <> nil then
487 r_GUI_Draw_Control(ctrl.Items[a].Control);
488 end;
489 end;
490 if (ctrl.Index <> -1) and (ctrl.Counter > MENU_MARKERDELAY div 2) then
491 begin
492 locx := 0;
493 locy := 0;
494 if ctrl.Items[ctrl.Index].Text <> nil then
495 begin
496 locx := ctrl.Items[ctrl.Index].Text.X;
497 locy := ctrl.Items[ctrl.Index].Text.Y;
498 //HACK!
499 if ctrl.Items[ctrl.Index].Text.RightAlign then
500 begin
501 locx := locx + ctrl.Items[ctrl.Index].Text.CMaxWidth - ctrl.Items[ctrl.Index].Text.GetWidth;
502 end;
503 end
504 else if ctrl.Items[ctrl.Index].Control <> nil then
505 begin
506 locx := ctrl.Items[ctrl.Index].Control.X;
507 locy := ctrl.Items[ctrl.Index].Control.Y;
508 end;
509 f := Font[ctrl.BigFont];
510 locx := locx - f.GetMaxWidth();
511 r_Draw_Text(#16, locx, locy, 255, 0, 0, 255, f);
512 end;
513 end;
515 procedure r_GUI_Draw_Control (ctrl: TGUIControl);
516 begin
517 if ctrl is TGUITextButton then
518 r_GUI_Draw_TextButton(TGUITextButton(ctrl))
519 else if ctrl is TGUILabel then
520 r_GUI_Draw_Label(TGUILabel(ctrl))
521 else if ctrl is TGUIScroll then
522 r_GUI_Draw_Scroll(TGUIScroll(ctrl))
523 else if ctrl is TGUISwitch then
524 r_GUI_Draw_Switch(TGUISwitch(ctrl))
525 else if ctrl is TGUIEdit then
526 r_GUI_Draw_Edit(TGUIEdit(ctrl))
527 else if ctrl is TGUIKeyRead then
528 r_GUI_Draw_KeyRead(TGUIKeyRead(ctrl))
529 else if ctrl is TGUIKeyRead2 then
530 r_GUI_Draw_KeyRead2(TGUIKeyRead2(ctrl))
531 else if ctrl is TGUIModelView then
532 r_GUI_Draw_ModelView(TGUIModelView(ctrl))
533 else if ctrl is TGUIMapPreview then
534 r_GUI_Draw_MapPreview(TGUIMapPreview(ctrl))
535 else if ctrl is TGUIImage then
536 r_GUI_Draw_Image(TGUIImage(ctrl))
537 else if ctrl is TGUIListBox then
538 r_GUI_Draw_ListBox(TGUIListBox(ctrl)) // + TGUIFileListBox
539 else if ctrl is TGUIMemo then
540 r_GUI_Draw_Memo(TGUIMemo(ctrl))
541 else if ctrl is TGUIMainMenu then
542 r_GUI_Draw_MainMenu(TGUIMainMenu(ctrl))
543 else if ctrl is TGUIMenu then
544 r_GUI_Draw_Menu(TGUIMenu(ctrl))
545 else
546 Assert(False)
547 end;
549 procedure r_GUI_Draw_Window (win: TGUIWindow);
550 var i, tw, th: Integer;
551 begin
552 // Here goes code duplication from g_game.pas:DrawMenuBackground()
553 if win.BackTexture <> '' then
554 if r_Common_LoadThis(win.BackTexture, Background) then
555 begin
556 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 255);
557 tw := Background.id.width;
558 th := Background.id.height;
559 if tw = th then
560 tw := round(tw * 1.333 * (gScreenHeight / th))
561 else
562 tw := trunc(tw * (gScreenHeight / th));
563 r_Draw_Texture(Background.id, (gScreenWidth - tw) div 2, 0, tw, gScreenHeight, false, 255, 255, 255, 255, false);
564 end
565 else
566 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 127, 127, 127, 255);
568 // small hack here
569 if win.Name = 'AuthorsMenu' then
570 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
571 for i := 0 to High(win.Childs) do
572 if win.Childs[i] <> nil then
573 r_GUI_Draw_Control(win.Childs[i]);
574 end;
576 end.