Skip to content

Commit

Permalink
Add mouse wheel scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
devo1929 committed May 15, 2022
1 parent 023e80d commit 2a63c12
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions DXMainClient/DXGUI/Multiplayer/QuickMatch/QuickMatchMapList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace DTAClient.DXGUI.Multiplayer.QuickMatch
{
public class QuickMatchMapList : INItializableWindow
{
private const int ScrollRate = 6;
public const int ItemHeight = 22;
public event EventHandler<QmMapSelectedEventArgs> MapSelected;

Expand All @@ -30,6 +31,27 @@ public override void Initialize()
scrollBar.ClientRectangle = new Rectangle(Width - scrollBar.ScrollWidth - 1, 1, scrollBar.ScrollWidth, Height - 2);
scrollBar.Scrolled += ScrollBarScrolled;
AddChild(scrollBar);

MouseScrolled += OnMouseScrolled;
}

private void OnMouseScrolled(object sender, EventArgs e)
{
int scrollWheelValue = Cursor.ScrollWheelValue;
int viewTop = scrollBar.ViewTop - (scrollWheelValue * ScrollRate);
int maxViewTop = scrollBar.Length - scrollBar.DisplayedPixelCount;

if (viewTop < 0)
viewTop = 0;
else if (viewTop > maxViewTop)
viewTop = maxViewTop;

if (viewTop == scrollBar.ViewTop)
return;

scrollBar.ViewTop = viewTop;
RefreshScrollbar();
RefreshItemLocations();
}

public void AddItem(QuickMatchMapItem item)
Expand Down

0 comments on commit 2a63c12

Please sign in to comment.