DEADSOFTWARE

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