Skip to content

Commit

Permalink
Improve RichTextBox scrolling logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Xanfre committed Jul 8, 2019
1 parent 1cb15e8 commit b04aae1
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions AngelLoader/CustomControls/RichTextBoxCustom/Workarounds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ internal sealed partial class RichTextBoxCustom
// No picture is used currently
private PictureBox pbGlyph;
private bool endOnMouseUp;
private int WheelAccum;

#endregion

Expand Down Expand Up @@ -80,6 +81,7 @@ protected override void OnVScroll(EventArgs e)

protected override async void OnEnter(EventArgs e)
{
WheelAccum = 0;
await SetScrollPositionToCorrect();

base.OnEnter(e);
Expand Down Expand Up @@ -144,8 +146,21 @@ private void InterceptMousewheel(ref Message m)
return;
}

int delta = (int)m.WParam;
if (delta != 0) BetterScroll(m.HWnd, delta < 0 ? 50 : -50);
int delta = 120;
WheelAccum += (int)m.WParam >> 16;
if (Math.Abs(WheelAccum) >= delta)
{
while (WheelAccum >= delta)
{
BetterScroll(m.HWnd, -50);
WheelAccum -= delta;
}
while (WheelAccum <= -delta)
{
BetterScroll(m.HWnd, 50);
WheelAccum += delta;
}
}
}

#endregion
Expand Down

0 comments on commit b04aae1

Please sign in to comment.