Skip to content

Commit

Permalink
Ensure console live preview matches actual console
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-drexler committed Oct 6, 2024
1 parent bbda318 commit ebf4c36
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 32 deletions.
16 changes: 13 additions & 3 deletions Quake/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -2260,7 +2260,7 @@ void Con_DrawInput (void)
Con_DrawSelectionHighlight
================
*/
void Con_DrawSelectionHighlight (int x, int y, int line)
static void Con_DrawSelectionHighlight (int x, int y, int line, float alpha)
{
conofs_t selbegin, selend;
conofs_t begin, end;
Expand All @@ -2285,7 +2285,7 @@ void Con_DrawSelectionHighlight (int x, int y, int line)
if (!Con_IntersectRanges (&begin, &end, &selbegin, &selend))
return;

Draw_Fill (x + begin.col*8, y, (end.col-begin.col)*8, 8, 220, 1.f);
Draw_Fill (x + begin.col*8, y, (end.col-begin.col)*8, 8, 220, alpha);
}

/*
Expand All @@ -2300,6 +2300,8 @@ void Con_DrawConsole (int lines, qboolean drawbg, qboolean drawinput)
{
int i, x, y, j, sb, rows;
const char *text;
qboolean forced;
float alpha;

Con_UpdateMouseState ();

Expand All @@ -2313,6 +2315,12 @@ void Con_DrawConsole (int lines, qboolean drawbg, qboolean drawinput)
if (drawbg)
Draw_ConsoleBackground ();

// fade out during live previews for console options when there's no active game
forced = con_forcedup && M_WantsConsole (&alpha);
if (!forced)
alpha = 1.f;
GL_PushCanvasColor (1.f, 1.f, 1.f, alpha);

// draw the buffer text
rows = (con_vislines +7)/8;
y = vid.conheight - rows*8;
Expand All @@ -2325,7 +2333,7 @@ void Con_DrawConsole (int lines, qboolean drawbg, qboolean drawinput)
if (j < 0)
j = 0;
text = con_text + (j % con_totallines)*con_linewidth;
Con_DrawSelectionHighlight (8, y, j);
Con_DrawSelectionHighlight (8, y, j, alpha);
}

y = vid.conheight - (rows+2)*8; // +2 for input and version lines
Expand Down Expand Up @@ -2367,6 +2375,8 @@ void Con_DrawConsole (int lines, qboolean drawbg, qboolean drawinput)
//draw version number in bottom right
text = CONSOLE_TITLE_STRING;
M_PrintWhite (vid.conwidth - (strlen (text) << 3), vid.conheight - 8, text);

GL_PopCanvasColor ();
}


Expand Down
11 changes: 8 additions & 3 deletions Quake/gl_screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,7 @@ void SCR_SetUpToDrawConsole (void)
scr_conlines = glheight; //full screen //johnfitz -- glheight instead of vid.height
scr_con_current = scr_conlines;
}
else if (key_dest == key_console || M_WantsConsole ())
else if (key_dest == key_console || M_WantsConsole (NULL))
scr_conlines = glheight/2; //half screen //johnfitz -- glheight instead of vid.height
else
scr_conlines = 0; //none visible
Expand Down Expand Up @@ -1518,7 +1518,10 @@ void SCR_DrawConsole (void)
{
if (scr_con_current)
{
Con_DrawConsole (scr_con_current, true, true);
if (key_dest != key_menu || (!con_forcedup || M_WantsConsole (NULL)))
Con_DrawConsole (scr_con_current, true, key_dest == key_console);
else
Draw_ConsoleBackground ();
clearconsole = 0;
}
else
Expand Down Expand Up @@ -1847,7 +1850,9 @@ void SCR_BeginLoadingPlaque (void)
if (key_dest != key_console)
{
Con_ClearNotify ();
scr_con_current = 0;
// don't reset console when advancing to a new demo while previewing a console option
if (!M_WantsConsole (NULL))
scr_con_current = 0;
scr_drawloading = true;
}

Expand Down
30 changes: 5 additions & 25 deletions Quake/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -4642,19 +4642,6 @@ static void M_Options_UpdatePreview (void)
}
}

/*
================
M_Options_DrawConsole
================
*/
static void M_Options_DrawConsole (void)
{
Draw_ConsoleBackground ();
GL_PushCanvasColor (1.f, 1.f, 1.f, optionsmenu.preview.frac);
Con_DrawConsole (scr_con_current, false, false);
GL_PopCanvasColor ();
}

/*
================
M_Options_DrawFadeScreen
Expand Down Expand Up @@ -7091,16 +7078,6 @@ void M_Draw (void)

if (!m_recursiveDraw)
{
if (scr_con_current)
{
if (options)
M_Options_DrawConsole ();
else
Draw_ConsoleBackground ();

S_ExtraUpdate ();
}

//johnfitz -- fade even if console fills screen
if (M_GetBaseState (m_state) == m_options)
M_Options_DrawFadeScreen ();
Expand Down Expand Up @@ -7488,9 +7465,12 @@ qboolean M_WaitingForKeyBinding (void)
return key_dest == key_menu && m_state == m_keys && bind_grab;
}

qboolean M_WantsConsole (void)
qboolean M_WantsConsole (float *alpha)
{
return key_dest == key_menu && M_GetBaseState (m_state) == m_options && M_Options_WantsConsole ();
qboolean forced = (key_dest == key_menu && M_GetBaseState (m_state) == m_options && M_Options_WantsConsole ());
if (alpha)
*alpha = forced ? M_Options_PreviewAlpha () : 0.f;
return forced;
}

qboolean M_ForcedCenterPrint (float *alpha)
Expand Down
2 changes: 1 addition & 1 deletion Quake/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void M_Charinput (int key);
void M_Mousemove (int x, int y);
enum textmode_t M_TextEntry (void);
qboolean M_WaitingForKeyBinding (void);
qboolean M_WantsConsole (void);
qboolean M_WantsConsole (float *alpha);
qboolean M_ForcedCenterPrint (float *alpha);
qboolean M_ForcedUnderwater (void);
void M_ToggleMenu_f (void);
Expand Down

0 comments on commit ebf4c36

Please sign in to comment.