Skip to content

Commit a64f179

Browse files
committed
Click/drag scroll bar thumb to scroll in console
1 parent 0695bd7 commit a64f179

File tree

2 files changed

+61
-20
lines changed

2 files changed

+61
-20
lines changed

releasenotes.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@
5656
* A bug is fixed whereby the player’s weapon could bleed from the right side of the screen to the left in some rare instances.
5757
* When *DOOM Retro* is run for the first time and an installation of *DOOM* is found, the IWAD in the “File name” field of the WAD launcher is now in the correct case.
5858
* The console will now be closed while the `resetall` CCMD’s confirmation message is displayed.
59-
* The console’s input can now be selected by clicking and dragging the mouse when the `m_pointer` CVAR is `on`.
59+
* When the `m_pointer` CVAR is `on`:
60+
* The console’s input can now be selected by clicking and dragging the mouse.
61+
* You can now scroll up and down in the console by clicking and dragging the mouse on the scroll bar.
6062

6163
![](https://github.com/bradharding/www.doomretro.com/raw/master/wiki/bigdivider.png)
6264

src/c_console.c

Lines changed: 58 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2555,6 +2555,8 @@ bool C_Responder(event_t *ev)
25552555
static int scrollspeed = TICRATE;
25562556
static bool selectingwithmouse = false;
25572557
static int mouseselectanchor = 0;
2558+
static bool draggingconsolescrollbar = false;
2559+
static int dragconsolescrollbaroffset = 0;
25582560
int i;
25592561
int len;
25602562

@@ -3122,6 +3124,30 @@ bool C_Responder(event_t *ev)
31223124
const int x = (ev->data2 - (vid_widescreen ? 0 : MAXWIDESCREENDELTA)) * 2;
31233125
const int y = ev->data3 * 2;
31243126

3127+
// dragging console scrollbar thumb
3128+
if (draggingconsolescrollbar && scrollbardrawn)
3129+
{
3130+
int newfacecenter = MAX(0, MIN(y - dragconsolescrollbaroffset,
3131+
CONSOLESCROLLBARHEIGHT - (scrollbarfaceend - scrollbarfacestart)));
3132+
3133+
scrollbarfacestart = newfacecenter;
3134+
scrollbarfaceend = scrollbarfacestart
3135+
+ CONSOLESCROLLBARHEIGHT - CONSOLESCROLLBARHEIGHT
3136+
* MAX(0, numconsolestrings - CONSOLEBLANKLINES - CONSOLELINES) / numconsolestrings;
3137+
3138+
if (numconsolestrings > CONSOLELINES)
3139+
{
3140+
int top = scrollbarfacestart * numconsolestrings / CONSOLESCROLLBARHEIGHT + CONSOLEBLANKLINES;
3141+
3142+
if (top <= 0 || top + CONSOLELINES >= numconsolestrings)
3143+
outputhistory = -1;
3144+
else
3145+
outputhistory = MAX(0, MIN(numconsolestrings - CONSOLELINES, top));
3146+
}
3147+
3148+
return true;
3149+
}
3150+
31253151
if (selectingwithmouse && len && y >= CONSOLEINPUTY - 2 && y < CONSOLEINPUTY + CONSOLELINEHEIGHT)
31263152
{
31273153
for (i = 0; i < len; i++)
@@ -3142,16 +3168,16 @@ bool C_Responder(event_t *ev)
31423168

31433169
caretpos = i;
31443170

3145-
if (caretpos >= mouseselectanchor)
3146-
{
3147-
selectstart = mouseselectanchor;
3148-
selectend = caretpos;
3149-
}
3150-
else
3151-
{
3152-
selectstart = caretpos;
3153-
selectend = mouseselectanchor;
3154-
}
3171+
if (caretpos >= mouseselectanchor)
3172+
{
3173+
selectstart = mouseselectanchor;
3174+
selectend = caretpos;
3175+
}
3176+
else
3177+
{
3178+
selectstart = caretpos;
3179+
selectend = mouseselectanchor;
3180+
}
31553181

31563182
caretwait = I_GetTimeMS() + CARETBLINKTIME;
31573183
showcaret = true;
@@ -3195,16 +3221,26 @@ bool C_Responder(event_t *ev)
31953221
}
31963222
else if (scrollbardrawn && x >= CONSOLESCROLLBARX && x <= CONSOLESCROLLBARX + CONSOLESCROLLBARWIDTH)
31973223
{
3198-
// scroll output up
3199-
if (y < scrollbarfacestart)
3200-
outputhistory = (outputhistory == -1 ? numconsolestrings - (CONSOLELINES + 1) :
3201-
MAX(0, outputhistory - scrollspeed / TICRATE));
3202-
3203-
// scroll output down
3204-
else if (y > scrollbarfaceend && y < CONSOLESCROLLBARHEIGHT - (CONSOLEHEIGHT - consoleheight))
3224+
// click inside scrollbar: start dragging if on face
3225+
if (y >= scrollbarfacestart && y <= scrollbarfaceend)
32053226
{
3206-
if ((outputhistory += scrollspeed / TICRATE) + CONSOLELINES >= numconsolestrings)
3207-
outputhistory = -1;
3227+
draggingconsolescrollbar = true;
3228+
dragconsolescrollbaroffset = y - scrollbarfacestart;
3229+
return true;
3230+
}
3231+
else
3232+
{
3233+
// scroll output up
3234+
if (y < scrollbarfacestart)
3235+
outputhistory = (outputhistory == -1 ? numconsolestrings - (CONSOLELINES + 1) :
3236+
MAX(0, outputhistory - scrollspeed / TICRATE));
3237+
3238+
// scroll output down
3239+
else if (y > scrollbarfaceend && y < CONSOLESCROLLBARHEIGHT - (CONSOLEHEIGHT - consoleheight))
3240+
{
3241+
if ((outputhistory += scrollspeed / TICRATE) + CONSOLELINES >= numconsolestrings)
3242+
outputhistory = -1;
3243+
}
32083244
}
32093245
}
32103246
}
@@ -3213,7 +3249,10 @@ bool C_Responder(event_t *ev)
32133249
{
32143250
// left button released: stop mouse selection
32153251
if (!(ev->data1 & MOUSE_LEFTBUTTON))
3252+
{
32163253
selectingwithmouse = false;
3254+
draggingconsolescrollbar = false;
3255+
}
32173256

32183257
// hide console with right button
32193258
if (ev->data1 & MOUSE_RIGHTBUTTON)

0 commit comments

Comments
 (0)