MCPcopy Create free account
hub / github.com/OpenDUNE/OpenDUNE / GUI_DrawText

Function GUI_DrawText

src/gui/gui.c:458–503  ·  view source on GitHub ↗

* Draw a string to the screen. * * @param string The string to draw. * @param left The most left position where to draw the string. * @param top The most top position where to draw the string. * @param fgColour The foreground colour of the text. * @param bgColour The background colour of the text. */

Source from the content-addressed store, hash-verified

456 * @param bgColour The background colour of the text.
457 */
458void GUI_DrawText(const char *string, int16 left, int16 top, uint8 fgColour, uint8 bgColour)
459{
460 uint8 colours[2];
461 uint16 x;
462 uint16 y;
463 const char *s;
464
465 if (g_fontCurrent == NULL) return;
466
467 if (left < 0) left = 0;
468 if (top < 0) top = 0;
469 if (left > SCREEN_WIDTH) return;
470 if (top > SCREEN_HEIGHT) return;
471
472 colours[0] = bgColour;
473 colours[1] = fgColour;
474
475 GUI_InitColors(colours, 0, 1);
476
477 s = string;
478 x = left;
479 y = top;
480 while (*s != '\0') {
481 uint16 width;
482
483 if (*s == '\n' || *s == '\r') {
484 x = left;
485 y += g_fontCurrent->height;
486
487 while (*s == '\n' || *s == '\r') s++;
488 }
489
490 width = Font_GetCharWidth(*s);
491
492 if (x + width > SCREEN_WIDTH) {
493 x = left;
494 y += g_fontCurrent->height;
495 }
496 if (y > SCREEN_HEIGHT) break;
497
498 GUI_DrawChar(*s, x, y);
499
500 x += width;
501 s++;
502 }
503}
504
505/**
506 * Draw a string to the screen, and so some magic.

Callers 6

GameCredits_PlayFunction · 0.85
Music_InitMT32Function · 0.85
GUI_DrawText_WrapperFunction · 0.85
GUI_DisplayModalMessageFunction · 0.85
GUI_DrawText_MonospaceFunction · 0.85
GUI_Widget_DrawFunction · 0.85

Calls 3

GUI_InitColorsFunction · 0.85
Font_GetCharWidthFunction · 0.85
GUI_DrawCharFunction · 0.85

Tested by

no test coverage detected