DEADSOFTWARE

3463a9ea100bc06167283342cceed2a9b1ddc622
[d2df-sdl.git] / src / game / 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: 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);
31 implementation
33 uses
34 Classes, Math,
35 MAPDEF, utils,
36 g_basic, g_base, e_input, g_options,
37 r_graphics, r_textures, r_playermodel, r_game,
38 g_game, g_menu
39 ;
41 const
42 BOX1 = 'BOX1';
43 BOX2 = 'BOX2';
44 BOX3 = 'BOX3';
45 BOX4 = 'BOX4';
46 BOX5 = 'BOX5';
47 BOX6 = 'BOX6';
48 BOX7 = 'BOX7';
49 BOX8 = 'BOX8';
50 BOX9 = 'BOX9';
52 type
53 TFontType = (Texture, Character);
55 TFont = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF}
56 private
57 FID: DWORD;
58 FScale: Single;
59 FFontType: TFontType;
60 public
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;
67 end;
69 var
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] *)
76 LogoTex: DWORD;
78 constructor TFont.Create (FontID: DWORD; FontType: TFontType);
79 begin
80 FID := FontID;
81 FScale := 1;
82 FFontType := FontType;
83 end;
85 destructor TFont.Destroy;
86 begin
87 inherited;
88 end;
90 procedure TFont.Draw (X, Y: Integer; Text: string; R, G, B: Byte);
91 begin
92 if FFontType = TFontType.Character then
93 e_CharFont_PrintEx(ID, X, Y, Text, _RGB(R, G, B), FScale)
94 else
95 e_TextureFontPrintEx(X, Y, Text, ID, R, G, B, FScale)
96 end;
98 procedure TFont.GetTextSize (Text: string; var w, h: Word);
99 var cw, ch: Byte;
100 begin
101 if FFontType = TFontType.Character then
102 e_CharFont_GetSize(ID, Text, w, h)
103 else
104 begin
105 e_TextureFontGetSize(ID, cw, ch);
106 w := cw * Length(Text);
107 h := ch;
108 end;
109 w := Round(w * FScale);
110 h := Round(h * FScale);
111 end;
113 procedure r_GUI_GetMaxFontSize (BigFont: Boolean; out w, h: Integer);
114 var f: TFont;
115 begin
116 f := Font[BigFont];
117 w := e_CharFont_GetMaxWidth(f.ID);
118 h := e_CharFont_GetMaxHeight(f.ID);
119 end;
121 procedure r_GUI_GetStringSize (BigFont: Boolean; str: String; out w, h: Integer);
122 var ww, hh: WORD;
123 begin
124 e_CharFont_GetSize(Font[BigFont].ID, str, ww, hh);
125 w := ww;
126 h := hh;
127 end;
129 procedure r_GUI_GetLogoSize (out w, h: WORD);
130 begin
131 w := 0;
132 h := 0;
133 if LogoTex <> 0 then
134 e_GetTextureSize(LogoTex, @w, @h);
135 end;
137 procedure r_GUI_Load;
138 begin
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)
191 end;
193 procedure r_GUI_Free;
194 begin
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');
220 end;
222 procedure r_GUI_GetSize_TextButton (ctrl: TGUITextButton; out w, h: Integer);
223 var ww, hh: WORD; f: TFont;
224 begin
225 f := Font[ctrl.BigFont];
226 f.GetTextSize(ctrl.Caption, ww, hh);
227 w := ww;
228 h := hh;
229 end;
231 procedure r_GUI_GetSize_Label (ctrl: TGUILabel; out w, h: Integer);
232 var ww, hh: WORD; f: TFont;
233 begin
234 f := Font[ctrl.BigFont];
235 f.GetTextSize(ctrl.Text, ww, hh);
236 h := hh;
237 if ctrl.FixedLength = 0 then
238 w := ww
239 else
240 w := e_CharFont_GetMaxWidth(f.ID) * ctrl.FixedLength
241 end;
243 procedure r_GUI_GetSize_Switch (ctrl: TGUISwitch; out w, h: Integer);
244 var i: Integer; ww, hh: WORD; f: TFont;
245 begin
246 w := 0;
247 h := 0;
248 if ctrl.Items <> nil then
249 begin
250 for i := 0 to High(ctrl.Items) do
251 begin
252 f := Font[ctrl.BigFont];
253 f.GetTextSize(ctrl.Items[i], ww, hh);
254 if ww > w then
255 w := ww;
256 end;
257 end;
258 end;
260 procedure r_GUI_GetSize_KeyRead (ctrl: TGUIKeyRead; out w, h: Integer);
261 var i: Integer; ww, hh: WORD; f: TFont;
262 begin
263 w := 0;
264 h := 0; // ??? always 0
265 f := Font[ctrl.BigFont];
266 for i := 0 to 255 do
267 begin
268 f.GetTextSize(e_KeyNames[i], ww, hh);
269 w := MAX(w, ww);
270 end;
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;
275 end;
277 procedure r_GUI_GetSize (ctrl: TGUIControl; out w, h: Integer);
278 begin
279 w := 0;
280 h := 0;
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
296 begin
297 w := 8 + ((ctrl as TGUIListBox).Width + 1) * 16; // recheck w & h
298 h := 8 + (ctrl as TGUIListBox).Height * 16;
299 end
300 else if ctrl is TGUIMemo then
301 begin
302 w := 8 + ((ctrl as TGUIMemo).Width + 1) * 16;
303 h := 8 + (ctrl as TGUIMemo).Height * 16;
304 end
305 else
306 begin
307 w := ctrl.GetWidth();
308 h := ctrl.GetHeight();
309 end;
310 end;
312 procedure r_GUI_Draw_Control (ctrl: TGUIControl); forward;
314 procedure r_GUI_Draw_TextButton (ctrl: TGUITextButton);
315 var f: TFont;
316 begin
317 f := Font[ctrl.BigFont];
318 f.Draw(ctrl.X, ctrl.Y, ctrl.Caption, ctrl.Color.R, ctrl.Color.G, ctrl.Color.B)
319 end;
321 procedure r_GUI_Draw_Label (ctrl: TGUILabel);
322 var w, h: Word; f: TFont;
323 begin
324 f := Font[ctrl.BigFont];
325 if ctrl.RightAlign then
326 begin
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);
329 end
330 else
331 f.Draw(ctrl.X, ctrl.Y, ctrl.Text, ctrl.Color.R, ctrl.Color.G, ctrl.Color.B);
332 end;
334 procedure r_GUI_Draw_Scroll (ctrl: TGUIScroll);
335 var a: Integer;
336 begin
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);
342 end;
344 procedure r_GUI_Draw_Switch (ctrl: TGUISwitch);
345 var f: TFont;
346 begin
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);
349 end;
351 procedure r_GUI_Draw_Edit (ctrl: TGUIEdit);
352 var c, w, h: Word; r, g, b: Byte; f: TFont;
353 begin
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);
358 r := ctrl.Color.R;
359 g := ctrl.Color.G;
360 b := ctrl.Color.B;
361 if ctrl.Invalid and (ctrl.Window.ActiveControl <> ctrl) then
362 begin
363 r := 128;
364 g := 128;
365 b := 128;
366 end;
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
370 begin
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);
374 end;
375 end;
377 procedure r_GUI_Draw_KeyRead (ctrl: TGUIKeyRead);
378 var k: AnsiString; f: TFont;
379 begin
380 if ctrl.IsQuery then
381 k := KEYREAD_QUERY
382 else if ctrl.Key <> 0 then
383 k := e_KeyNames[ctrl.Key]
384 else
385 k := KEYREAD_CLEAR;
386 f := Font[ctrl.BigFont];
387 f.Draw(ctrl.X, ctrl.Y, k, ctrl.Color.R, ctrl.Color.G, ctrl.Color.B);
388 end;
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;
394 begin
395 if idx = 0 then kk := ctrl.Key0 else kk := ctrl.Key1;
396 y := ctrl.Y;
397 if idx = 0 then x := ctrl.X + 8 else x := ctrl.X + 8 + ctrl.MaxKeyNameWdt + 16;
398 r := 255;
399 g := 0;
400 b := 0;
401 if ctrl.KeyIdx = idx then
402 begin
403 r := 255; g := 255; b := 255;
404 end;
405 f := Font[ctrl.BigFont];
406 if ctrl.IsQuery and (ctrl.KeyIdx = idx) then
407 begin
408 f.Draw(x, y, KEYREAD_QUERY, r, g, b)
409 end
410 else
411 begin
412 if kk <> 0 then
413 str := e_KeyNames[kk]
414 else
415 str := KEYREAD_CLEAR;
416 f.Draw(x, y, str, r, g, b);
417 end
418 end;
420 begin
421 drawText(0);
422 drawText(1);
423 end;
425 procedure DrawBox(X, Y: Integer; Width, Height: Word);
426 begin
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);
436 end;
438 procedure r_GUI_Draw_ModelView (ctrl: TGUIModelView);
439 begin
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);
443 end;
445 procedure r_GUI_Draw_MapPreview (ctrl: TGUIMapPreview);
446 var a: Integer; r, g, b: Byte;
447 begin
448 DrawBox(ctrl.X, ctrl.Y, MAPPREVIEW_WIDTH, MAPPREVIEW_HEIGHT);
449 if (ctrl.MapSize.X <= 0) or (ctrl.MapSize.Y <= 0) then
450 Exit;
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
455 begin
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;
464 case PanelType of
465 PANEL_WALL:
466 begin
467 r := 255; g := 255; b := 255;
468 end;
469 PANEL_CLOSEDOOR:
470 begin
471 r := 255; g := 255; b := 0;
472 end;
473 PANEL_WATER:
474 begin
475 r := 0; g := 0; b := 192;
476 end;
477 PANEL_ACID1:
478 begin
479 r := 0; g := 176; b := 0;
480 end;
481 PANEL_ACID2:
482 begin
483 r := 176; g := 0; b := 0;
484 end;
485 else
486 r := 128; g := 128; b := 128;
487 end;
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);
490 end;
491 end;
493 procedure r_GUI_Draw_Image (ctrl: TGUIImage);
494 var ID: DWORD;
495 begin
496 if ctrl.ImageRes = '' then
497 begin
498 if g_Texture_Get(ctrl.DefaultRes, ID) then
499 e_Draw(ID, ctrl.X, ctrl.Y, 0, True, False);
500 end
501 else
502 begin
503 if g_Texture_Get(ctrl.ImageRes, ID) then
504 e_Draw(ID, ctrl.X, ctrl.Y, 0, True, False);
505 end;
506 end;
508 procedure DrawScroll(X, Y: Integer; Height: Word; Up, Down: Boolean);
509 var ID: DWORD;
510 begin
511 if Height < 3 then
512 Exit;
513 if Up then
514 g_Texture_Get(BSCROLL_UPA, ID)
515 else
516 g_Texture_Get(BSCROLL_UPU, ID);
517 e_Draw(ID, X, Y, 0, False, False);
518 if Down then
519 g_Texture_Get(BSCROLL_DOWNA, ID)
520 else
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);
525 end;
527 procedure r_GUI_Draw_ListBox (ctrl: TGUIListBox); // + TGUIFileListBox
528 var w2, h2: Word; a: Integer; s: string; f: TFont;
529 begin
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
535 begin
536 f := Font[ctrl.BigFont];
537 for a := ctrl.StartLine to Min(High(ctrl.Items), ctrl.StartLine + ctrl.Height - 1) do
538 begin
539 s := ctrl.Items[a];
540 f.GetTextSize(s, w2, h2);
541 while (Length(s) > 0) and (w2 > ctrl.Width * 16) do
542 begin
543 SetLength(s, Length(s) - 1);
544 f.GetTextSize(s, w2, h2);
545 end;
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)
548 else
549 f.Draw(ctrl.X + 4, ctrl.Y + 4 + (a - ctrl.StartLine) * 16, s, ctrl.UnActiveColor.R, ctrl.UnActiveColor.G, ctrl.UnActiveColor.B);
550 end;
551 end;
552 end;
554 procedure r_GUI_Draw_Memo (ctrl: TGUIMemo);
555 var a: Integer; f: TFont;
556 begin
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);
565 end;
567 procedure r_GUI_Draw_MainMenu (ctrl: TGUIMainMenu);
568 var a: Integer; w, h: Word; ID: DWORD;
569 begin
570 if ctrl.Header <> nil then
571 begin
572 r_GUI_Draw_Label(ctrl.Header)
573 end
574 else if LogoTex <> 0 then
575 begin
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);
578 end;
579 if ctrl.Buttons <> nil then
580 begin
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
585 begin
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);
588 end
589 end;
590 end;
592 procedure r_GUI_Draw_Menu (ctrl: TGUIMenu);
593 var a, locx, locy: Integer; f: TFont;
594 begin
595 if ctrl.Header <> nil then
596 r_GUI_Draw_Label(ctrl.Header);
597 if ctrl.Items <> nil then
598 begin
599 for a := 0 to High(ctrl.Items) do
600 begin
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);
605 end;
606 end;
607 if (ctrl.Index <> -1) and (ctrl.Counter > MENU_MARKERDELAY div 2) then
608 begin
609 locx := 0;
610 locy := 0;
611 if ctrl.Items[ctrl.Index].Text <> nil then
612 begin
613 locx := ctrl.Items[ctrl.Index].Text.X;
614 locy := ctrl.Items[ctrl.Index].Text.Y;
615 //HACK!
616 if ctrl.Items[ctrl.Index].Text.RightAlign then
617 begin
618 locx := locx + ctrl.Items[ctrl.Index].Text.CMaxWidth - ctrl.Items[ctrl.Index].Text.GetWidth;
619 end;
620 end
621 else if ctrl.Items[ctrl.Index].Control <> nil then
622 begin
623 locx := ctrl.Items[ctrl.Index].Control.X;
624 locy := ctrl.Items[ctrl.Index].Control.Y;
625 end;
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));
629 end;
630 end;
632 procedure r_GUI_Draw_Control (ctrl: TGUIControl);
633 begin
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))
662 else
663 Assert(False)
664 end;
666 procedure r_GUI_Draw_Window (win: TGUIWindow);
667 var i: Integer; ID: DWORD; tw, th: Word;
668 begin
669 // Here goes code duplication from g_game.pas:DrawMenuBackground()
670 if win.BackTexture <> '' then
671 if g_Texture_Get(win.BackTexture, ID) then
672 begin
673 e_Clear(0, 0, 0);
674 e_GetTextureSize(ID, @tw, @th);
675 if tw = th then
676 tw := round(tw * 1.333 * (gScreenHeight / th))
677 else
678 tw := trunc(tw * (gScreenHeight / th));
679 e_DrawSize(ID, (gScreenWidth - tw) div 2, 0, 0, False, False, tw, gScreenHeight);
680 end
681 else
682 e_Clear(0.5, 0.5, 0.5);
684 // small hack here
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]);
690 end;
692 end.