MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / grtext_DrawTextLine

Function grtext_DrawTextLine

grtext/grtext.cpp:942–991  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

940}
941
942void grtext_DrawTextLine(int x, int y, char *str) {
943 int i, cur_x;
944 tCharBlt cbi;
945 int strsize = strlen(str);
946
947 /* by clipping, we should first determine what our vertical clipping is. then
948 go through each character in the line and determine what is totally clipped,
949 partially clipped and by how much, and not clipped at all and draw accordingly
950
951 perform string drawing without viewport clipping.
952 supports bitmap fonts or color(alpha) mapped fonts.
953 */
954 cur_x = x;
955 for (i = 0; i < strsize; i++) {
956 uint8_t ch, ch2;
957 int w;
958 ch = (uint8_t)str[i];
959 ch2 = (uint8_t)str[i + 1];
960 w = CHAR_WIDTH(Grtext_font, ch);
961
962 if (ch == GR_COLOR_CHAR) {
963 ddgr_color col;
964 if ((i + 3) >= strsize)
965 break; // This shouldn't happen! bad string!
966 col = GR_RGB(str[i + 1], str[i + 2], str[i + 3]);
967 rend_SetFlatColor(col);
968 // rend_SetCharacterParameters(col, col, col, col);
969 i += 3;
970 } else if (ch == '\t') { // tab char
971 int space_width;
972 space_width = (CHAR_WIDTH(Grtext_font, ' ') + Grtext_spacing) * Grtext_tabspace;
973 cur_x = (cur_x + space_width) / space_width * space_width;
974 } else if (ch == GRTEXT_FORMAT_CHAR) {
975 if ((i + 1) >= strsize)
976 break; // This shouldn't happen! bad string!
977 cur_x = x + ((int)str[i + 1] * GRTEXT_FORMAT_SCALAR);
978 i++;
979 } else if (ch == ' ') {
980 cur_x += (CHAR_WIDTH(Grtext_font, ' ') + Grtext_spacing);
981 } else {
982 cbi.ch = ch;
983 cbi.clipped = false; // if =1, use sx,sy,sw,sh
984 cbi.x = cur_x;
985 cbi.y = y;
986 cbi.dsw = cbi.dsh = Grtext_scale;
987 cur_x = grfont_BltChar(Grtext_font, &cbi);
988 cur_x += (Grtext_spacing + CHAR_SPACING(Grtext_font, ch, ch2));
989 }
990 }
991}

Callers 1

grtext_RenderStringFunction · 0.85

Calls 5

CHAR_WIDTHFunction · 0.85
grfont_BltCharFunction · 0.85
CHAR_SPACINGFunction · 0.85
GR_RGBFunction · 0.50
rend_SetFlatColorFunction · 0.50

Tested by

no test coverage detected