Skip to content

Commit

Permalink
Scroll console with look stick
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-drexler committed Dec 24, 2023
1 parent 6b48cee commit 8eed3ee
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 9 deletions.
27 changes: 27 additions & 0 deletions Quake/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,33 @@ void Con_CheckResize (void)
}


/*
================
Con_Scroll
================
*/
void Con_Scroll (int lines)
{
if (!lines)
return;

con_backscroll += lines;

if (lines > 0)
{
if (con_backscroll > con_totallines - (vid.height>>3) - 1)
con_backscroll = con_totallines - (vid.height>>3) - 1;
}
else
{
if (con_backscroll < 0)
con_backscroll = 0;
}

Con_ForceMouseMove ();
}


/*
================
Con_Init
Expand Down
1 change: 1 addition & 0 deletions Quake/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ extern byte *con_chars;
extern char con_lastcenterstring[]; //johnfitz

void Con_CheckResize (void);
void Con_Scroll (int lines);
void Con_Init (void);
void Con_DrawConsole (int lines, qboolean drawinput);
void Con_Printf (const char *fmt, ...) FUNC_PRINTF(1,2);
Expand Down
36 changes: 35 additions & 1 deletion Quake/in_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,41 @@ void IN_Commands (void)
IN_JoyKeyEvent(joy_axisstate.axisvalue[SDL_CONTROLLER_AXIS_LEFTY] < -stickthreshold, newaxisstate.axisvalue[SDL_CONTROLLER_AXIS_LEFTY] < -stickthreshold, K_UPARROW, &joy_emulatedkeytimer[2]);
IN_JoyKeyEvent(joy_axisstate.axisvalue[SDL_CONTROLLER_AXIS_LEFTY] > stickthreshold, newaxisstate.axisvalue[SDL_CONTROLLER_AXIS_LEFTY] > stickthreshold, K_DOWNARROW, &joy_emulatedkeytimer[3]);
}


// scroll console with look stick
if (key_dest == key_console)
{
const float scrollthreshold = 0.1f;
const float maxscrollspeed = 72.f; // lines per second
const float scrollinterval = 1.f / maxscrollspeed;
static double timer = 0.0;
joyaxis_t raw, deadzone, eased;
float scale;

raw.x = newaxisstate.axisvalue[joy_swapmovelook.value ? SDL_CONTROLLER_AXIS_LEFTX : SDL_CONTROLLER_AXIS_RIGHTX];
raw.y = newaxisstate.axisvalue[joy_swapmovelook.value ? SDL_CONTROLLER_AXIS_LEFTY : SDL_CONTROLLER_AXIS_RIGHTY];
deadzone = IN_ApplyDeadzone (raw, joy_deadzone_look.value, joy_outer_threshold_look.value);
eased = IN_ApplyEasing (deadzone, joy_exponent.value);
if (joy_invert.value)
eased.y = -eased.y;

scale = fabs (eased.y);
if (scale > scrollthreshold)
{
timer -= scale * host_rawframetime;
if (timer < 0.0)
{
int ticks = (int) ceil (-timer / scrollinterval);
timer += ticks * scrollinterval;
Con_Scroll (eased.y < 0.0f ? ticks : -ticks);
}
}
else
{
timer = 0.0;
}
}

// emit emulated keys for the analog triggers
IN_JoyKeyEvent(joy_axisstate.axisvalue[SDL_CONTROLLER_AXIS_TRIGGERLEFT] > triggerthreshold, newaxisstate.axisvalue[SDL_CONTROLLER_AXIS_TRIGGERLEFT] > triggerthreshold, K_LTRIGGER, &joy_emulatedkeytimer[4]);
IN_JoyKeyEvent(joy_axisstate.axisvalue[SDL_CONTROLLER_AXIS_TRIGGERRIGHT] > triggerthreshold, newaxisstate.axisvalue[SDL_CONTROLLER_AXIS_TRIGGERRIGHT] > triggerthreshold, K_RTRIGGER, &joy_emulatedkeytimer[5]);
Expand Down
10 changes: 2 additions & 8 deletions Quake/keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,18 +383,12 @@ void Key_Console (int key)

case K_PGUP:
case K_MWHEELUP:
con_backscroll += keydown[K_CTRL] ? ((con_vislines>>3) - 4) : 2;
if (con_backscroll > con_totallines - (vid.height>>3) - 1)
con_backscroll = con_totallines - (vid.height>>3) - 1;
Con_ForceMouseMove ();
Con_Scroll (keydown[K_CTRL] ? ((con_vislines>>3) - 4) : 2);
return;

case K_PGDN:
case K_MWHEELDOWN:
con_backscroll -= keydown[K_CTRL] ? ((con_vislines>>3) - 4) : 2;
if (con_backscroll < 0)
con_backscroll = 0;
Con_ForceMouseMove ();
Con_Scroll (keydown[K_CTRL] ? -((con_vislines>>3) - 4) : -2);
return;

case K_LEFTARROW:
Expand Down

0 comments on commit 8eed3ee

Please sign in to comment.