]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_screen.c
If the new Key_Event breaks anything for you, you can set #if 0 and activate the old
[xonotic/darkplaces.git] / cl_screen.c
index 505366fed795eb1480e9861ea0eab00171b71ecc..5be03f47d4a82528ea2842607a9e08e217601bf8 100644 (file)
@@ -45,6 +45,99 @@ static void R_Envmap_f (void);
 // backend
 void R_ClearScreen(void);
 
+// color tag printing
+static vec4_t _draw_colors[] =
+{
+       // Quake3 colors
+       // LordHavoc: why on earth is cyan before magenta in Quake3?
+       // LordHavoc: note: Doom3 uses white for [0] and [7]
+       {0.0, 0.0, 0.0, 1.0}, // black
+       {1.0, 0.0, 0.0, 1.0}, // red
+       {0.0, 1.0, 0.0, 1.0}, // green
+       {1.0, 1.0, 0.0, 1.0}, // yellow
+       {0.0, 0.0, 1.0, 1.0}, // blue
+       {0.0, 1.0, 1.0, 1.0}, // cyan
+       {1.0, 0.0, 1.0, 1.0}, // magenta
+       {1.0, 1.0, 1.0, 1.0}  // white
+       // Black's color table
+       //{1.0, 1.0, 1.0, 1.0},
+       //{1.0, 0.0, 0.0, 1.0},
+       //{0.0, 1.0, 0.0, 1.0},
+       //{0.0, 0.0, 1.0, 1.0},
+       //{1.0, 1.0, 0.0, 1.0},
+       //{0.0, 1.0, 1.0, 1.0},
+       //{1.0, 0.0, 1.0, 1.0},
+       //{0.1, 0.1, 0.1, 1.0}
+};
+
+#define _draw_colors_count     (sizeof(_draw_colors) / sizeof(vec4_t))
+#define _draw_color_tag                '^'
+#define _draw_color_default 7
+
+// color is read and changed in the end
+void DrawQ_ColoredString( float x, float y, const char *text, int maxlen, float scalex, float scaley, float basered, float basegreen, float baseblue, float basealpha, int flags, int *outcolor )
+{
+       vec_t *color;
+       const char *first, *last;
+       int len;
+       int colorindex;
+       
+    if( !outcolor || *outcolor == -1 ) {
+               colorindex = _draw_color_default;
+       } else {
+               colorindex = *outcolor;
+       }
+
+       color = _draw_colors[colorindex];
+
+       if( maxlen < 1)
+               len = strlen( text );
+       else
+               len = min( maxlen, (signed) strlen( text ) );
+
+    first = last = text;
+       while( len ) {
+               // iterate until we get the next color tag or reach the end of the text part to draw
+               for( ; len && *last != _draw_color_tag ; len--, last++ )
+                       ;
+               // only draw the partial string if we have read anything
+               if( last != first ) {
+                       // draw the string
+                       DrawQ_String( x, y, first, last - first, scalex, scaley, basered * color[0], basegreen * color[1], baseblue * color[2], basealpha * color[3], flags );
+                       // update x to be at the new start position
+                       x += (last - first) * scalex;
+                       // if we have reached the end, we have finished
+                       if( !len )
+                               break;
+               }
+               first = last;
+               // jump over the tag
+               last++;
+               len--;
+               if( len && '0' <= *last && *last <= '9' ) {
+                       colorindex = 0;
+                       while( '0' <= *last && *last <= '9' && len ) {
+                               colorindex = colorindex * 10 + *last - '0';
+                               if( colorindex < _draw_colors_count ) {
+                                       last++;
+                                       len--;
+                               } else {
+                                       colorindex /= 10;
+                                       break;
+                               }
+                       }
+
+                       color = _draw_colors[colorindex];
+                       // we dont want to display the color tag and the color index
+                       first = last;
+               }
+       }
+
+       if( outcolor ) {
+               *outcolor = colorindex;
+       }
+}
+
 /*
 ===============================================================================
 
@@ -102,17 +195,17 @@ void SCR_DrawCenterString (void)
        start = scr_centerstring;
 
        if (scr_center_lines <= 4)
-               y = vid.conheight*0.35;
+               y = vid_conheight.integer*0.35;
        else
                y = 48;
 
        do
        {
        // scan the width of the line
-               for (l=0 ; l<vid.conwidth/8 ; l++)
+               for (l=0 ; l<vid_conwidth.integer/8 ; l++)
                        if (start[l] == '\n' || !start[l])
                                break;
-               x = (vid.conwidth - l*8)/2;
+               x = (vid_conwidth.integer - l*8)/2;
                if (l > 0)
                {
                        if (remaining < l)
@@ -217,7 +310,7 @@ void SCR_DrawPause (void)
                return;
 
        pic = Draw_CachePic ("gfx/pause", true);
-       DrawQ_Pic ((vid.conwidth - pic->width)/2, (vid.conheight - pic->height)/2, "gfx/pause", 0, 0, 1, 1, 1, 1, 0);
+       DrawQ_Pic ((vid_conwidth.integer - pic->width)/2, (vid_conheight.integer - pic->height)/2, "gfx/pause", 0, 0, 1, 1, 1, 1, 0);
 }
 
 
@@ -246,7 +339,7 @@ void SCR_SetUpToDrawConsole (void)
 
 // decide on the height of the console
        if (key_consoleactive & KEY_CONSOLEACTIVE_USER)
-               conlines = vid.conheight/2;     // half screen
+               conlines = vid_conheight.integer/2;     // half screen
        else
                conlines = 0;                           // none visible
 
@@ -280,7 +373,7 @@ void SCR_DrawConsole (void)
        if (key_consoleactive & KEY_CONSOLEACTIVE_FORCED)
        {
                // full screen
-               Con_DrawConsole (vid.conheight);
+               Con_DrawConsole (vid_conheight.integer);
        }
        else if (scr_con_current)
                Con_DrawConsole (scr_con_current);
@@ -324,25 +417,25 @@ void R_TimeReport(char *desc)
        r_timereport_current = Sys_DoubleTime();
        t = (int) ((r_timereport_current - r_timereport_temp) * 1000000.0);
 
-       sprintf(tempbuf, "%8i %s", t, desc);
+       dpsnprintf(tempbuf, sizeof(tempbuf), "%8i %s", t, desc);
        length = strlen(tempbuf);
        while (length < 20)
                tempbuf[length++] = ' ';
        tempbuf[length] = 0;
-       if (speedstringcount + length > (vid.conwidth / 8))
+       if (speedstringcount + length > (vid_conwidth.integer / 8))
        {
-               strcat(r_speeds_string, "\n");
+               strlcat(r_speeds_string, "\n", sizeof(r_speeds_string));
                speedstringcount = 0;
        }
        // skip the space at the beginning if it's the first on the line
        if (speedstringcount == 0)
        {
-               strcat(r_speeds_string, tempbuf + 1);
+               strlcat(r_speeds_string, tempbuf + 1, sizeof(r_speeds_string));
                speedstringcount = length - 1;
        }
        else
        {
-               strcat(r_speeds_string, tempbuf);
+               strlcat(r_speeds_string, tempbuf, sizeof(r_speeds_string));
                speedstringcount += length;
        }
 }
@@ -406,9 +499,9 @@ void R_TimeReport_End(void)
                for (i = 0;r_speeds_string[i];i++)
                        if (r_speeds_string[i] == '\n')
                                lines++;
-               y = vid.conheight - sb_lines - lines * 8;
+               y = vid_conheight.integer - sb_lines - lines * 8;
                i = j = 0;
-               DrawQ_Fill(0, y, vid.conwidth, lines * 8, 0, 0, 0, 0.5, 0);
+               DrawQ_Fill(0, y, vid_conwidth.integer, lines * 8, 0, 0, 0, 0.5, 0);
                while (r_speeds_string[i])
                {
                        j = i;
@@ -509,7 +602,7 @@ void DrawQ_String_Real(float x, float y, const char *string, int maxlen, float s
        for (;len > 0 && string[len - 1] == ' ';len--);
        if (len < 1)
                return;
-       if (x >= vid.conwidth || y >= vid.conheight || x < (-scalex * len) || y < (-scaley))
+       if (x >= vid_conwidth.integer || y >= vid_conheight.integer || x < (-scalex * len) || y < (-scaley))
                return;
        size = sizeof(*dq) + ((len + 1 + 3) & ~3);
        if (r_refdef.drawqueuesize + size > r_refdef.maxdrawqueuesize)
@@ -541,6 +634,8 @@ void DrawQ_String(float x, float y, const char *string, int maxlen, float scalex
        DrawQ_String_Real(x,y,string,maxlen,scalex,scaley,red,green,blue,alpha,flags);
 }
 
+
+
 void DrawQ_Fill (float x, float y, float w, float h, float red, float green, float blue, float alpha, int flags)
 {
        DrawQ_SuperPic(x,y,NULL,w,h,0,0,red,green,blue,alpha,1,0,red,green,blue,alpha,0,1,red,green,blue,alpha,1,1,red,green,blue,alpha,flags);
@@ -692,11 +787,11 @@ void SCR_ScreenShot_f (void)
 
        sprintf(filename, "%s%06d.%s", base, shotnumber, jpeg ? "jpg" : "tga");
 
-       buffer1 = Mem_Alloc(tempmempool, vid.realwidth * vid.realheight * 3);
-       buffer2 = Mem_Alloc(tempmempool, vid.realwidth * vid.realheight * 3);
-       buffer3 = Mem_Alloc(tempmempool, vid.realwidth * vid.realheight * 3 + 18);
+       buffer1 = Mem_Alloc(tempmempool, vid.width * vid.height * 3);
+       buffer2 = Mem_Alloc(tempmempool, vid.width * vid.height * 3);
+       buffer3 = Mem_Alloc(tempmempool, vid.width * vid.height * 3 + 18);
 
-       if (SCR_ScreenShot (filename, buffer1, buffer2, buffer3, vid.realx, vid.realy, vid.realwidth, vid.realheight, false, false, false, jpeg))
+       if (SCR_ScreenShot (filename, buffer1, buffer2, buffer3, 0, 0, vid.width, vid.height, false, false, false, jpeg, true))
                Con_Printf("Wrote %s\n", filename);
        else
                Con_Printf("unable to write %s\n", filename);
@@ -743,7 +838,7 @@ void SCR_CaptureVideo_BeginVideo(void)
        cl_capturevideo_framerate = bound(1, cl_capturevideo_fps.value, 1000);
        cl_capturevideo_soundrate = 0;
        cl_capturevideo_frame = 0;
-       cl_capturevideo_buffer = Mem_Alloc(tempmempool, vid.realwidth * vid.realheight * (3+3+3) + 18);
+       cl_capturevideo_buffer = Mem_Alloc(tempmempool, vid.width * vid.height * (3+3+3) + 18);
        gamma = 1.0/scr_screenshot_gamma.value;
 
        /*
@@ -881,11 +976,11 @@ void SCR_CaptureVideo_EndVideo(void)
 
 qboolean SCR_CaptureVideo_VideoFrame(int newframenum)
 {
-       int x = vid.realx, y = vid.realy, width = vid.realwidth, height = vid.realheight;
+       int x = 0, y = 0, width = vid.width, height = vid.height;
        unsigned char *b, *out;
        char filename[32];
        int outoffset = (width/2)*(height/2);
-       //return SCR_ScreenShot(filename, cl_capturevideo_buffer, cl_capturevideo_buffer + vid.realwidth * vid.realheight * 3, cl_capturevideo_buffer + vid.realwidth * vid.realheight * 6, vid.realx, vid.realy, vid.realwidth, vid.realheight, false, false, false, jpeg);
+       //return SCR_ScreenShot(filename, cl_capturevideo_buffer, cl_capturevideo_buffer + vid.width * vid.height * 3, cl_capturevideo_buffer + vid.width * vid.height * 6, 0, 0, vid.width, vid.height, false, false, false, jpeg, true);
        // speed is critical here, so do saving as directly as possible
        switch (cl_capturevideo_format)
        {
@@ -950,7 +1045,7 @@ qboolean SCR_CaptureVideo_VideoFrame(int newframenum)
                }
                return true;
        case CAPTUREVIDEOFORMAT_TARGA:
-               //return Image_WriteTGARGB_preflipped (filename, width, height, cl_capturevideo_buffer, cl_capturevideo_buffer + vid.realwidth * vid.realheight * 3, );
+               //return Image_WriteTGARGB_preflipped (filename, width, height, cl_capturevideo_buffer, cl_capturevideo_buffer + vid.width * vid.height * 3, );
                memset (cl_capturevideo_buffer, 0, 18);
                cl_capturevideo_buffer[2] = 2;          // uncompressed type
                cl_capturevideo_buffer[12] = (width >> 0) & 0xFF;
@@ -1039,12 +1134,12 @@ struct
 }
 envmapinfo[12] =
 {
-       {{  0,   0, 0}, "rt",  true, false, false},
-       {{  0,  90, 0}, "ft",  true, false, false},
-       {{  0, 180, 0}, "lf",  true, false, false},
-       {{  0, 270, 0}, "bk",  true, false, false},
-       {{-90, 180, 0}, "up", false,  true, false},
-       {{ 90, 180, 0}, "dn", false,  true, false},
+       {{  0,   0, 0}, "rt", false, false, false},
+       {{  0, 270, 0}, "ft", false, false, false},
+       {{  0, 180, 0}, "lf", false, false, false},
+       {{  0,  90, 0}, "bk", false, false, false},
+       {{-90, 180, 0}, "up",  true,  true, false},
+       {{ 90, 180, 0}, "dn",  true,  true, false},
 
        {{  0,   0, 0}, "px",  true,  true,  true},
        {{  0,  90, 0}, "py", false,  true, false},
@@ -1075,7 +1170,7 @@ static void R_Envmap_f (void)
                Con_Print("envmap: size must be one of 128, 256, 512, or 1024\n");
                return;
        }
-       if (size > vid.realwidth || size > vid.realheight)
+       if (size > vid.width || size > vid.height)
        {
                Con_Print("envmap: your resolution is not big enough to render that size\n");
                return;
@@ -1103,7 +1198,7 @@ static void R_Envmap_f (void)
                R_Mesh_Start();
                R_RenderView();
                R_Mesh_Finish();
-               SCR_ScreenShot(filename, buffer1, buffer2, buffer3, vid.realx, vid.realy + vid.realheight - (r_refdef.y + r_refdef.height), size, size, envmapinfo[j].flipx, envmapinfo[j].flipy, envmapinfo[j].flipdiagonaly, false);
+               SCR_ScreenShot(filename, buffer1, buffer2, buffer3, 0, vid.height - (r_refdef.y + r_refdef.height), size, size, envmapinfo[j].flipx, envmapinfo[j].flipy, envmapinfo[j].flipdiagonaly, false, false);
        }
 
        Mem_Free (buffer1);
@@ -1200,8 +1295,6 @@ void CL_SetupScreenSize(void)
 {
        float conwidth, conheight;
 
-       VID_GetWindowSize (&vid.realx, &vid.realy, &vid.realwidth, &vid.realheight);
-
        VID_UpdateGamma(false);
 
        conwidth = bound(320, vid_conwidth.value, 2048);
@@ -1211,16 +1304,8 @@ void CL_SetupScreenSize(void)
        if (vid_conheight.value != conheight)
                Cvar_SetValue("vid_conheight", conheight);
 
-       vid.conwidth = vid_conwidth.integer;
-       vid.conheight = vid_conheight.integer;
-
-/*     if (vid.realheight > 240)
-       {
-               vid.conheight = (vid.realheight - 240) * scr_2dresolution.value + 240;
-               vid.conheight = bound(240, vid.conheight, vid.realheight);
-       }
-       else
-               vid.conheight = 240;*/
+       vid_conwidth.integer = vid_conwidth.integer;
+       vid_conheight.integer = vid_conheight.integer;
 
        SCR_SetUpToDrawConsole();
 }