X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=gl_draw.c;h=3e33b3444aeb2896d2273720978f12cb993be11c;hb=be135a8eb4c9f12f7f561671b7c7684b4fba5587;hp=686ffb5b9724e0d0cca3b3fbe95d0f16ad6a540b;hpb=8637b1ec26ca72f92d1ef8faf23a2f124c1f4ff3;p=xonotic%2Fdarkplaces.git diff --git a/gl_draw.c b/gl_draw.c index 686ffb5b..3e33b344 100644 --- a/gl_draw.c +++ b/gl_draw.c @@ -235,9 +235,9 @@ void Draw_Frame(void) int i; cachepic_t *pic; static double nextpurgetime; - if (nextpurgetime > realtime) + if (nextpurgetime > host.realtime) return; - nextpurgetime = realtime + 0.05; + nextpurgetime = host.realtime + 0.05; for (i = 0, pic = cachepics;i < numcachepics;i++, pic++) { if (pic->autoload && pic->skinframe && pic->skinframe->base && pic->lastusedframe < draw_frame - 3) @@ -670,7 +670,7 @@ static void LoadFont_f(cmd_state_t *cmd) if (sizes == MAX_FONT_SIZES) { - Con_Warnf("Warning: specified more than %i different font sizes, exceding ones are ignored\n", MAX_FONT_SIZES); + Con_Printf(CON_WARN "Warning: specified more than %i different font sizes, exceding ones are ignored\n", MAX_FONT_SIZES); sizes = -1; continue; } @@ -884,16 +884,38 @@ static void DrawQ_GetTextColor(float color[4], int colorindex, float r, float g, } } +// returns a colorindex (format 0x1RGBA) if str is a valid RGB string +// returns 0 otherwise +static int RGBstring_to_colorindex(const char *str) +{ + Uchar ch; + int ind = 0x0001 << 4; + do { + if (*str <= '9' && *str >= '0') + ind |= (*str - '0'); + else + { + ch = tolower(*str); + if (ch >= 'a' && ch <= 'f') + ind |= (ch - 87); + else + return 0; + } + ++str; + ind <<= 4; + } while(!(ind & 0x10000)); + return ind | 0xf; // add costant alpha value +} + // NOTE: this function always draws exactly one character if maxwidth <= 0 float DrawQ_TextWidth_UntilWidth_TrackColors_Scale(const char *text, size_t *maxlen, float w, float h, float sw, float sh, int *outcolor, qboolean ignorecolorcodes, const dp_font_t *fnt, float maxwidth) { const char *text_start = text; - int colorindex = STRING_COLOR_DEFAULT; + int colorindex; size_t i; float x = 0; Uchar ch, mapch, nextch; Uchar prevch = 0; // used for kerning - int tempcolorindex; float kx; int map_index = 0; size_t bytes_left; @@ -940,7 +962,7 @@ float DrawQ_TextWidth_UntilWidth_TrackColors_Scale(const char *text, size_t *max // maxwidth /= fnt->scale; // w and h are multiplied by it already // ftbase_x = snap_to_pixel_x(0); - + if(maxwidth <= 0) { least_one = true; @@ -974,7 +996,6 @@ float DrawQ_TextWidth_UntilWidth_TrackColors_Scale(const char *text, size_t *max x += width_of[(int) ' '] * dw; continue; } - // i points to the char after ^ if (ch == STRING_COLOR_TAG && !ignorecolorcodes && i < *maxlen) { ch = *text; // colors are ascii, so no u8_ needed @@ -985,41 +1006,19 @@ float DrawQ_TextWidth_UntilWidth_TrackColors_Scale(const char *text, size_t *max ++i; continue; } - // i points to the char after ^... - // i+3 points to 3 in ^x123 - // i+3 == *maxlen would mean that char is missing else if (ch == STRING_COLOR_RGB_TAG_CHAR && i + 3 < *maxlen ) // ^x found { - // building colorindex... - ch = tolower(text[1]); - tempcolorindex = 0x10000; // binary: 1,0000,0000,0000,0000 - if (ch <= '9' && ch >= '0') tempcolorindex |= (ch - '0') << 12; - else if (ch >= 'a' && ch <= 'f') tempcolorindex |= (ch - 87) << 12; - else tempcolorindex = 0; + const char *text_p = &text[1]; + int tempcolorindex = RGBstring_to_colorindex(text_p); if (tempcolorindex) { - ch = tolower(text[2]); - if (ch <= '9' && ch >= '0') tempcolorindex |= (ch - '0') << 8; - else if (ch >= 'a' && ch <= 'f') tempcolorindex |= (ch - 87) << 8; - else tempcolorindex = 0; - if (tempcolorindex) - { - ch = tolower(text[3]); - if (ch <= '9' && ch >= '0') tempcolorindex |= (ch - '0') << 4; - else if (ch >= 'a' && ch <= 'f') tempcolorindex |= (ch - 87) << 4; - else tempcolorindex = 0; - if (tempcolorindex) - { - colorindex = tempcolorindex | 0xf; - // ...done! now colorindex has rgba codes (1,rrrr,gggg,bbbb,aaaa) - i+=4; - text += 4; - continue; - } - } + colorindex = tempcolorindex; + i+=4; + text += 4; + continue; } } - else if (ch == STRING_COLOR_TAG) // ^^ found, ignore the first ^ and go to print the second + else if (ch == STRING_COLOR_TAG) // ^^ found { i++; text++; @@ -1081,7 +1080,6 @@ float DrawQ_String_Scale(float startx, float starty, const char *text, size_t ma float x = startx, y, s, t, u, v, thisw; Uchar ch, mapch, nextch; Uchar prevch = 0; // used for kerning - int tempcolorindex; int map_index = 0; //ft2_font_map_t *prevmap = NULL; // the previous map ft2_font_map_t *map = NULL; // the currently used map @@ -1195,35 +1193,15 @@ float DrawQ_String_Scale(float startx, float starty, const char *text, size_t ma } else if (ch == STRING_COLOR_RGB_TAG_CHAR && i+3 < maxlen ) // ^x found { - // building colorindex... - ch = tolower(text[1]); - tempcolorindex = 0x10000; // binary: 1,0000,0000,0000,0000 - if (ch <= '9' && ch >= '0') tempcolorindex |= (ch - '0') << 12; - else if (ch >= 'a' && ch <= 'f') tempcolorindex |= (ch - 87) << 12; - else tempcolorindex = 0; - if (tempcolorindex) + const char *text_p = &text[1]; + int tempcolorindex = RGBstring_to_colorindex(text_p); + if(tempcolorindex) { - ch = tolower(text[2]); - if (ch <= '9' && ch >= '0') tempcolorindex |= (ch - '0') << 8; - else if (ch >= 'a' && ch <= 'f') tempcolorindex |= (ch - 87) << 8; - else tempcolorindex = 0; - if (tempcolorindex) - { - ch = tolower(text[3]); - if (ch <= '9' && ch >= '0') tempcolorindex |= (ch - '0') << 4; - else if (ch >= 'a' && ch <= 'f') tempcolorindex |= (ch - 87) << 4; - else tempcolorindex = 0; - if (tempcolorindex) - { - colorindex = tempcolorindex | 0xf; - // ...done! now colorindex has rgba codes (1,rrrr,gggg,bbbb,aaaa) - //Con_Printf("^1colorindex:^7 %x\n", colorindex); - DrawQ_GetTextColor(DrawQ_Color, colorindex, basered, basegreen, baseblue, basealpha, shadow != 0); - i+=4; - text+=4; - continue; - } - } + colorindex = tempcolorindex; + DrawQ_GetTextColor(DrawQ_Color, colorindex, basered, basegreen, baseblue, basealpha, shadow != 0); + i+=4; + text+=4; + continue; } } else if (ch == STRING_COLOR_TAG) @@ -1337,7 +1315,7 @@ out: if (outcolor) *outcolor = colorindex; - + // note: this relies on the proper text (not shadow) being drawn last return x; } @@ -1503,7 +1481,7 @@ void DrawQ_FlushUI(void) return; } - // this is roughly equivalent to R_Q1BSP_Draw, so the UI can use full material feature set + // this is roughly equivalent to R_Mod_Draw, so the UI can use full material feature set r_refdef.view.colorscale = 1; r_textureframe++; // used only by R_GetCurrentTexture GL_DepthMask(false);