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

Function grtext_DrawTextLineClip

grtext/grtext.cpp:851–940  ·  view source on GitHub ↗

These internal routines just draw a line of text. depending on the function we clip or don't clip */

Source from the content-addressed store, hash-verified

849 we clip or don't clip
850*/
851void grtext_DrawTextLineClip(int x, int y, char *str) {
852 int ch_y, ch_x, ch_w, ch_h; // what part of the character to draw
853 int i, cur_x, draw_x, draw_y; // where to draw character section
854 int h;
855 tCharBlt cbi;
856 int strsize = strlen(str);
857
858 /* by clipping, we should first determine what our vertical clipping is. then
859 go through each character in the line and determine what is totally clipped,
860 partially clipped and by how much, and not clipped at all and draw accordingly
861 */
862 h = CHAR_HEIGHT(Grtext_font);
863 ch_y = 0;
864 ch_h = h;
865 draw_y = y;
866 // determine each character bitmap y and height to blt.
867 if (CLIP_TOP >= y) {
868 ch_y = CLIP_TOP - y;
869 draw_y = CLIP_TOP;
870 }
871 if (CLIP_BOTTOM < (y + CHAR_HEIGHT(Grtext_font))) {
872 ch_h = CLIP_BOTTOM - y;
873 }
874 ch_h = ch_h - ch_y; // do this to clip both top and bottom
875
876 cur_x = x;
877 for (i = 0; i < strsize; i++) {
878 uint8_t ch, ch2;
879 int w;
880 ch = (uint8_t)str[i];
881 ch2 = (uint8_t)str[i + 1];
882
883 w = CHAR_WIDTH(Grtext_font, ch);
884
885 if (ch == GR_COLOR_CHAR) {
886 ddgr_color col;
887 if ((i + 3) >= strsize)
888 break; // This shouldn't happen! bad string!
889 col = GR_RGB(str[i + 1], str[i + 2], str[i + 3]);
890 rend_SetFlatColor(col);
891 // rend_SetCharacterParameters(col, col, col, col);
892 i += 3;
893 } else if (ch == '\t') { // tab char
894 int space_width;
895 space_width = (CHAR_WIDTH(Grtext_font, ' ') + Grtext_spacing) * Grtext_tabspace;
896 cur_x = (cur_x + space_width) / space_width * space_width;
897 } else if (((cur_x + w) < CLIP_LEFT) || (cur_x > CLIP_RIGHT)) {
898 cur_x += (Grtext_spacing + w);
899 } else if (ch == GRTEXT_FORMAT_CHAR) {
900 if ((i + 1) >= strsize)
901 break; // This shouldn't happen! bad string!
902 cur_x = x + ((int)str[i + 1] * GRTEXT_FORMAT_SCALAR);
903 i++;
904 } else if (ch == ' ') {
905 cur_x += (CHAR_WIDTH(Grtext_font, ' ') + Grtext_spacing + CHAR_SPACING(Grtext_font, ch, ch2));
906 } else {
907 ch_x = 0;
908 ch_w = w;

Callers 1

grtext_RenderStringFunction · 0.85

Calls 6

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

Tested by

no test coverage detected