diff --git a/Quake/draw.h b/Quake/draw.h index a310c21cd..9a56361c5 100644 --- a/Quake/draw.h +++ b/Quake/draw.h @@ -44,8 +44,8 @@ void Draw_ConsoleBackground (void); //johnfitz -- removed parameter int lines void Draw_TileClear (int x, int y, int w, int h); void Draw_Fill (int x, int y, int w, int h, int c, float alpha); //johnfitz -- added alpha void Draw_FillEx (float x, float y, float w, float h, const float *rgb, float alpha); -void Draw_PartialFadeScreen (float x0, float x1, float y0, float y1); -void Draw_FadeScreen (void); +void Draw_PartialFadeScreen (float x0, float x1, float y0, float y1, float alpha); +void Draw_FadeScreen (float alpha); void Draw_String (int x, int y, const char *str); void Draw_StringEx (float x, float y, float dim, const char *str); qpic_t *Draw_PicFromWad2 (const char *name, unsigned int texflags); diff --git a/Quake/gl_draw.c b/Quake/gl_draw.c index 6b944249b..3ef986902 100644 --- a/Quake/gl_draw.c +++ b/Quake/gl_draw.c @@ -1002,14 +1002,15 @@ void Draw_Fill (int x, int y, int w, int h, int c, float alpha) //johnfitz -- ad Draw_PartialFadeScreen ================ */ -void Draw_PartialFadeScreen (float x0, float x1, float y0, float y1) +void Draw_PartialFadeScreen (float x0, float x1, float y0, float y1, float alpha) { guivertex_t *verts; int type; float smax = 0.f, tmax = 0.f, s; float u0, u1, v0, v1; - if (scr_menubgalpha.value <= 0.f) + alpha *= scr_menubgalpha.value; + if (alpha <= 0.f) return; u0 = GetFraction (x0, glcanvas.left, glcanvas.right); @@ -1040,7 +1041,7 @@ void Draw_PartialFadeScreen (float x0, float x1, float y0, float y1) Draw_SetTexture (whitetexture); /* first pass */ Draw_SetBlending (GLS_BLEND_MULTIPLY); - s = 1.f - CLAMP (0.f, scr_menubgalpha.value, 0.5f) * 2.f; + s = 1.f - CLAMP (0.f, alpha, 0.5f) * 2.f; clr[0] = LERP (0.56f, 1.f, s); clr[1] = LERP (0.43f, 1.f, s); clr[2] = LERP (0.13f, 1.f, s); @@ -1052,7 +1053,7 @@ void Draw_PartialFadeScreen (float x0, float x1, float y0, float y1) Draw_SetVertex (verts++, x0, y0, u0*smax, v0*tmax); /* second pass */ Draw_SetBlending (GLS_BLEND_ALPHA); - s = CLAMP (0.f, scr_menubgalpha.value, 1.f); + s = CLAMP (0.f, alpha, 1.f); s = (sqrt (s) + s) * 0.5f; // ~0.6 with scr_menubgalpha 0.5 GL_SetCanvasColor (0.095f, 0.08f, 0.045f, s); } @@ -1069,16 +1070,16 @@ void Draw_PartialFadeScreen (float x0, float x1, float y0, float y1) smax = glwidth / (winquakemenubg->width * s); tmax = glheight / (winquakemenubg->height * s); Draw_SetTexture (winquakemenubg); - if (scr_menubgalpha.value >= 0.5f) + if (alpha >= 0.5f) { Draw_SetBlending (GLS_BLEND_MULTIPLY); - s = 2.f - q_min (1.f, scr_menubgalpha.value) * 2.f; + s = 2.f - q_min (1.f, alpha) * 2.f; GL_PushCanvasColor (s, s, s, 1.f); } else { Draw_SetBlending (GLS_BLEND_ALPHA); - s = q_max (0.f, scr_menubgalpha.value) * 2.f; + s = q_max (0.f, alpha) * 2.f; GL_PushCanvasColor (0.f, 0.f, 0.f, s); } } @@ -1086,7 +1087,7 @@ void Draw_PartialFadeScreen (float x0, float x1, float y0, float y1) { Draw_SetTexture (whitetexture); Draw_SetBlending (GLS_BLEND_ALPHA); - GL_PushCanvasColor (0.f, 0.f, 0.f, scr_menubgalpha.value); + GL_PushCanvasColor (0.f, 0.f, 0.f, alpha); } verts = Draw_AllocQuad (); @@ -1106,9 +1107,9 @@ void Draw_PartialFadeScreen (float x0, float x1, float y0, float y1) Draw_FadeScreen -- johnfitz -- revised ================ */ -void Draw_FadeScreen (void) +void Draw_FadeScreen (float alpha) { - Draw_PartialFadeScreen (glcanvas.left, glcanvas.right, glcanvas.top, glcanvas.bottom); + Draw_PartialFadeScreen (glcanvas.left, glcanvas.right, glcanvas.top, glcanvas.bottom, alpha); } /* diff --git a/Quake/gl_screen.c b/Quake/gl_screen.c index bff07864f..2a10c71f3 100644 --- a/Quake/gl_screen.c +++ b/Quake/gl_screen.c @@ -82,6 +82,7 @@ float scr_conlines; // lines of console to display cvar_t scr_menuscale = {"scr_menuscale", "1", CVAR_ARCHIVE}; cvar_t scr_menubgalpha = {"scr_menubgalpha", "0.7", CVAR_ARCHIVE}; cvar_t scr_menubgstyle = {"scr_menubgstyle", "-1", CVAR_ARCHIVE}; +cvar_t scr_centerprintbg = {"scr_centerprintbg", "2", CVAR_ARCHIVE}; // 0 = off; 1 = text box; 2 = menu box; 3 = menu strip cvar_t scr_sbarscale = {"scr_sbarscale", "1", CVAR_ARCHIVE}; cvar_t scr_sbaralpha = {"scr_sbaralpha", "0.75", CVAR_ARCHIVE}; cvar_t scr_conwidth = {"scr_conwidth", "0", CVAR_ARCHIVE}; @@ -155,6 +156,7 @@ char scr_centerstring[1024]; float scr_centertime_start; // for slow victory printing float scr_centertime_off; int scr_center_lines; +int scr_center_maxcols; int scr_erase_lines; int scr_erase_center; @@ -168,7 +170,16 @@ for a few moments */ void SCR_CenterPrint (const char *str) //update centerprint data { - strncpy (scr_centerstring, str, sizeof(scr_centerstring)-1); + int cols; + + q_strlcpy (scr_centerstring, str, sizeof (scr_centerstring)); + if (!scr_centerstring[0]) + { + scr_center_lines = 0; + scr_center_maxcols = 0; + return; + } + scr_centertime_off = scr_centertime.value; scr_centertime_start = cl.time; if (!cl.intermission) @@ -176,12 +187,72 @@ void SCR_CenterPrint (const char *str) //update centerprint data // count the number of lines for centering scr_center_lines = 1; + scr_center_maxcols = 0; str = scr_centerstring; + cols = 0; while (*str) { if (*str == '\n') + { scr_center_lines++; + scr_center_maxcols = q_max (scr_center_maxcols, cols); + cols = -1; // compensate the following ++ + } + str++; + cols++; + } + scr_center_maxcols = q_max (scr_center_maxcols, cols); +} + +static void SCR_DrawCenterStringBG (int y, float alpha) +{ + const char *str; + int i, len, lines, x; + + if (q_min (scr_center_lines, scr_center_maxcols) <= 0) + return; + + // skip leading empty lines (might be there just to reposition the text) + str = scr_centerstring; + while (*str == '\n') + { str++; + y += CHARSIZE; + } + + // skip trailing empty lines + len = (int) strlen (str); + while (len > 0 && str[len - 1] == '\n') + --len; + + // count remaining lines + for (i = 0, lines = 1; i < len; i++) + if (str[i] == '\n') + lines++; + + // draw the background + switch ((int)scr_centerprintbg.value) + { + case 1: + len = (scr_center_maxcols + 3) & ~1; + x = (320 - len * 8) / 2; + GL_PushCanvasColor (1.f, 1.f, 1.f, alpha * scr_menubgalpha.value); + M_DrawTextBox (x - 8, y - 12, len, lines + 1); + GL_PopCanvasColor (); + break; + + case 2: + len = scr_center_maxcols + 2; + x = (320 - len* 8) / 2; + Draw_PartialFadeScreen (x, x + len * 8, y - 4, y + lines * 8 + 4, alpha); + break; + + case 3: + Draw_PartialFadeScreen (glcanvas.left, glcanvas.right, y - 4, y + lines * 8 + 4, alpha); + break; + + default: + return; } } @@ -192,7 +263,7 @@ void SCR_DrawCenterString (void) //actually do the drawing int j; int x, y; int remaining; - float alpha; + float alpha, forced; GL_SetCanvas (CANVAS_MENU); //johnfitz @@ -209,7 +280,11 @@ void SCR_DrawCenterString (void) //actually do the drawing alpha = fade ? q_min (scr_centertime_off / fade, 1.f) : 1.f; } - GL_SetCanvasColor (1.f, 1.f, 1.f, alpha); + forced = M_ForcedCenterPrint (); + if (forced > 0.f) + alpha *= forced * forced; + + GL_PushCanvasColor (1.f, 1.f, 1.f, alpha); scr_erase_center = 0; start = scr_centerstring; @@ -221,6 +296,8 @@ void SCR_DrawCenterString (void) //actually do the drawing if (crosshair.value && scr_viewsize.value < 130) y -= 8; + SCR_DrawCenterStringBG (y, alpha); + do { // scan the width of the line @@ -243,7 +320,7 @@ void SCR_DrawCenterString (void) //actually do the drawing start++; // skip the \n } while (1); - GL_SetCanvasColor (1.f, 1.f, 1.f, 1.f); + GL_PopCanvasColor (); } void SCR_CheckDrawCenterString (void) @@ -255,7 +332,7 @@ void SCR_CheckDrawCenterString (void) if (scr_centertime_off <= 0 && !cl.intermission) return; - if (key_dest != key_game) + if (key_dest != key_game && !M_ForcedCenterPrint ()) return; if (cl.paused) //johnfitz -- don't show centerprint during a pause return; @@ -543,6 +620,7 @@ void SCR_Init (void) Cvar_RegisterVariable (&scr_menuscale); Cvar_RegisterVariable (&scr_menubgalpha); Cvar_RegisterVariable (&scr_menubgstyle); + Cvar_RegisterVariable (&scr_centerprintbg); Cvar_RegisterVariable (&scr_sbarscale); Cvar_SetCallback (&scr_sbaralpha, SCR_Callback_refdef); Cvar_RegisterVariable (&scr_sbaralpha); @@ -1980,7 +2058,7 @@ void SCR_UpdateScreen (void) Draw_ConsoleBackground (); else Sbar_Draw (); - Draw_FadeScreen (); + Draw_FadeScreen (1.f); SCR_DrawNotifyString (); } else if (scr_drawloading) //loading diff --git a/Quake/menu.c b/Quake/menu.c index e4f16c2ac..1c76de41a 100644 --- a/Quake/menu.c +++ b/Quake/menu.c @@ -3275,6 +3275,7 @@ void M_Menu_Gamepad_f (void) item (SPACER, "") \ item (OPT_MENUBGSTYLE, "Menu BG Style") \ item (OPT_MENUBGALPHA, "Menu BG Alpha") \ + item (OPT_CENTERPRINTBG, "Center Text BG Style") \ item (OPT_CONALPHA, "Console Alpha") \ item (OPT_CONBRIGHTNESS, "Darken Console") \ item (OPT_CONFIRMQUIT, "Quit Prompt") \ @@ -3528,6 +3529,11 @@ static qboolean M_Options_WantsConsole (void) return optionsmenu.preview.id == OPT_CONALPHA || optionsmenu.preview.id == OPT_CONBRIGHTNESS; } +static float M_Options_ForcedCenterPrint (void) +{ + return optionsmenu.preview.id == OPT_CENTERPRINTBG ? optionsmenu.preview.frac : 0.f; +} + static void M_Options_Preview (int id) { if (cls.state == ca_connected && cls.signon == SIGNONS) @@ -3548,6 +3554,15 @@ static void M_Options_Preview (int id) case OPT_FOVDISTORT: break; + case OPT_CENTERPRINTBG: + SCR_CenterPrint ( + "Certain messages appear inconveniently\n" + "in the middle of your view. These are\n" + "always important, and you do not want\n" + "to ignore them!" + ); + break; + default: id = -1; break; @@ -3577,6 +3592,9 @@ static void M_Options_Preview (int id) static void M_Options_ResetPreview (void) { + if (M_Options_ForcedCenterPrint ()) + SCR_CenterPrint (""); + optionsmenu.preview.frac = 0.f; optionsmenu.preview.id = -1; optionsmenu.preview.frac_target = 0.f; @@ -3947,6 +3965,9 @@ void M_AdjustSliders (int dir) case OPT_CONBRIGHTNESS: Cvar_SetValueQuick (&scr_conbrightness, CLAMP (0.0f, scr_conbrightness.value - dir * 0.1f, 1.f)); break; + case OPT_CENTERPRINTBG: + M_CycleCvar (&scr_centerprintbg, 0, 3, dir); + break; // // Gamepad Options @@ -4313,6 +4334,17 @@ static void M_Options_DrawItem (int y, int item) M_DrawCheckbox (x, y, ui_live_preview.value); break; + case OPT_CENTERPRINTBG: + switch ((int)scr_centerprintbg.value) + { + case 1: str = "Classic Box"; break; + case 2: str = "Menu Box"; break; + case 3: str = "Menu Strip"; break; + default: str = "Off"; break; + } + M_Print (x, y, str); + break; + case OPT_CONFIRMQUIT: if (!cl_confirmquit.value) str = "Off"; @@ -4653,7 +4685,11 @@ static void M_Options_UpdatePreview (void) optionsmenu.preview.frac -= host_rawframetime / PREVIEW_FADEIN_TIME; optionsmenu.preview.frac = q_max (optionsmenu.preview.frac, optionsmenu.preview.frac_target); if (optionsmenu.preview.frac == optionsmenu.preview.frac_target) + { + if (M_Options_ForcedCenterPrint ()) + SCR_CenterPrint (""); optionsmenu.preview.id = -1; + } } } else if (optionsmenu.preview.hold_time > 0.f && !slider_grab) @@ -4669,7 +4705,7 @@ static void M_Options_UpdatePreview (void) /* ================ -M_Options_DrawFadeScreen +M_Options_DrawConsole ================ */ static void M_Options_DrawConsole (void) @@ -4705,7 +4741,7 @@ static void M_Options_DrawFadeScreen (void) y1 = LERP (y1, y + CHARSIZE, frac); } - Draw_PartialFadeScreen (glcanvas.left, glcanvas.right, y0, y1); + Draw_PartialFadeScreen (glcanvas.left, glcanvas.right, y0, y1, 1.f); } void M_Options_Draw (void) @@ -7129,7 +7165,7 @@ void M_Draw (void) if (M_GetBaseState (m_state) == m_options) M_Options_DrawFadeScreen (); else - Draw_FadeScreen (); + Draw_FadeScreen (1.f); } else { @@ -7517,6 +7553,11 @@ qboolean M_WantsConsole (void) return key_dest == key_menu && M_GetBaseState (m_state) == m_options && M_Options_WantsConsole (); } +float M_ForcedCenterPrint (void) +{ + return key_dest == key_menu && M_GetBaseState (m_state) == m_options ? M_Options_ForcedCenterPrint () : 0.f; +} + void M_ConfigureNetSubsystem(void) { diff --git a/Quake/menu.h b/Quake/menu.h index 01d4c675f..e825713fb 100644 --- a/Quake/menu.h +++ b/Quake/menu.h @@ -67,6 +67,7 @@ void M_Mousemove (int x, int y); enum textmode_t M_TextEntry (void); qboolean M_WaitingForKeyBinding (void); qboolean M_WantsConsole (void); +float M_ForcedCenterPrint (void); void M_ToggleMenu_f (void); void M_RefreshMods (void); diff --git a/Quake/screen.h b/Quake/screen.h index 819df5eb5..fea590834 100644 --- a/Quake/screen.h +++ b/Quake/screen.h @@ -99,6 +99,7 @@ typedef enum menubg_t extern cvar_t scr_menuscale; extern cvar_t scr_menubgalpha; extern cvar_t scr_menubgstyle; +extern cvar_t scr_centerprintbg; extern cvar_t scr_sbarscale; extern cvar_t scr_conwidth; extern cvar_t scr_conscale;