From 8eed3ee9a966873d4f7cd069f6b879c1dcf94ec6 Mon Sep 17 00:00:00 2001 From: Andrei Drexler Date: Sun, 24 Dec 2023 11:21:19 +0100 Subject: [PATCH] Scroll console with look stick --- Quake/console.c | 27 +++++++++++++++++++++++++++ Quake/console.h | 1 + Quake/in_sdl.c | 36 +++++++++++++++++++++++++++++++++++- Quake/keys.c | 10 ++-------- 4 files changed, 65 insertions(+), 9 deletions(-) diff --git a/Quake/console.c b/Quake/console.c index d40616bca..5f7efe5f4 100644 --- a/Quake/console.c +++ b/Quake/console.c @@ -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 diff --git a/Quake/console.h b/Quake/console.h index 119916326..acb8f4d5c 100644 --- a/Quake/console.h +++ b/Quake/console.h @@ -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); diff --git a/Quake/in_sdl.c b/Quake/in_sdl.c index 8ed9e259e..03653bb70 100644 --- a/Quake/in_sdl.c +++ b/Quake/in_sdl.c @@ -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]); diff --git a/Quake/keys.c b/Quake/keys.c index 5372ae036..106c26c30 100644 --- a/Quake/keys.c +++ b/Quake/keys.c @@ -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: