Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scrollbar padding and dragging #271

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion EndlessClient/ControlSets/CreateAccountControlSet.cs
Expand Up @@ -188,7 +188,7 @@ private IXNAPanel GetCreateAccountLabels()
{
Texture = _labelsTexture,
SourceRectangle = new Rectangle(0, srcYIndex * (srcYIndex < 2 ? 14 : 15), 149, 15),
DrawPosition = new Vector2(358, (srcYIndex < 3 ? 50 : 241) + srcYIndex % 3 * 51)
DrawPosition = new Vector2(435, (srcYIndex < 3 ? 55 : 250) + (srcYIndex < 3 ? 3+(srcYIndex % 3 * 51) : (srcYIndex % 3 * 50)))
};
texturePictureBox.SetParentControl(labelsPanel);
}
Expand Down
24 changes: 15 additions & 9 deletions EndlessClient/UIControls/ScrollBar.cs
Expand Up @@ -68,6 +68,7 @@ public class ScrollBar : XNAControl
_scrollButton.SetParentControl(this);

_totalHeight = DrawAreaWithParentOffset.Height;
this.ScrollToTop();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the ScrollToTop call here is a no-op since ScrollOffset is already set to 0

If you want the +1 offset then just add that to the _scrollButton position parameter in its constructor call.

}

public override void Initialize()
Expand All @@ -88,7 +89,7 @@ public void ScrollToTop()
{
ScrollOffset = 0;
var pixelsPerLine = (float)(scrollArea.Height - _scrollButton.DrawArea.Height * 2) / (_totalHeight - LinesToRender);
_scrollButton.DrawPosition = new Vector2(_scrollButton.DrawArea.X, _scrollButton.DrawArea.Height + pixelsPerLine * ScrollOffset);
_scrollButton.DrawPosition = new Vector2(_scrollButton.DrawArea.X, 1 + _scrollButton.DrawArea.Height + pixelsPerLine * ScrollOffset);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since ScrollOffset is zero, the + pixelsPerLine * ScrollOffset could be removed (it will always be zero). Oversight on my part when I first wrote it

}

public void ScrollToEnd()
Expand Down Expand Up @@ -141,10 +142,10 @@ private void arrowClicked(object btn, EventArgs e)
}

var pixelsPerLine = (float)(scrollArea.Height - _scrollButton.DrawArea.Height * 2) / (_totalHeight - LinesToRender);
_scrollButton.DrawPosition = new Vector2(_scrollButton.DrawPosition.X, _scrollButton.DrawArea.Height + pixelsPerLine * ScrollOffset);
if (_scrollButton.DrawPosition.Y > scrollArea.Height - _scrollButton.DrawArea.Height)
_scrollButton.DrawPosition = new Vector2(_scrollButton.DrawPosition.X, 1 + _scrollButton.DrawArea.Height + pixelsPerLine * ScrollOffset);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why the +1 and -1 offsets were added to a bunch of the position calculations? Also curious if there's a cleaner way to do the offset without scattering these +1/-1 adjustments everywhere

if (_scrollButton.DrawPosition.Y > 1 + scrollArea.Height - _scrollButton.DrawArea.Height)
{
_scrollButton.DrawPosition = new Vector2(_scrollButton.DrawPosition.X, scrollArea.Height - _scrollButton.DrawArea.Height);
_scrollButton.DrawPosition = new Vector2(_scrollButton.DrawPosition.X, 1 + scrollArea.Height - _scrollButton.DrawArea.Height);
}
}

Expand All @@ -160,12 +161,17 @@ private void OnScrollButtonDragged(object btn, EventArgs e)
else if (y > scrollArea.Height - _scrollButton.DrawArea.Height)
y = scrollArea.Height - _scrollButton.DrawArea.Height;

_scrollButton.DrawPosition = new Vector2(0, y);
var dif = (CurrentMouseState.ScrollWheelValue - PreviousMouseState.ScrollWheelValue) / -160;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If 160 is the height of the scrollbar, different scrollbars have different heights (chat vs shop dialog vs account create dialog), so it can't be hard-coded

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also don't see where this variable is being used

var pixelsPerLine = (float)(scrollArea.Height - _scrollButton.DrawArea.Height * 2) /
(_totalHeight - LinesToRender);
_scrollButton.DrawPosition = new Vector2(_scrollButton.DrawPosition.X, 1 + (_scrollButton.DrawArea.Height + pixelsPerLine * ScrollOffset));

if (_scrollButton.DrawPosition.Y >= (scrollArea.Height - 1) - _scrollButton.DrawArea.Height)
_scrollButton.DrawPosition = new Vector2(_scrollButton.DrawPosition.X, (scrollArea.Height - 1) - _scrollButton.DrawArea.Height);

if (_totalHeight <= LinesToRender)
return;

var pixelsPerLine = (double)(scrollArea.Height - _scrollButton.DrawArea.Height * 2) / (_totalHeight - LinesToRender);
ScrollOffset = (int)Math.Round((y - _scrollButton.DrawArea.Height) / pixelsPerLine);
}

Expand All @@ -183,10 +189,10 @@ protected override void OnUpdateControl(GameTime gt)

var pixelsPerLine = (float)(scrollArea.Height - _scrollButton.DrawArea.Height * 2) /
(_totalHeight - LinesToRender);
_scrollButton.DrawPosition = new Vector2(_scrollButton.DrawPosition.X, _scrollButton.DrawArea.Height + pixelsPerLine * ScrollOffset);
_scrollButton.DrawPosition = new Vector2(_scrollButton.DrawPosition.X, 1 + (_scrollButton.DrawArea.Height + pixelsPerLine * ScrollOffset));

if (_scrollButton.DrawPosition.Y > scrollArea.Height - _scrollButton.DrawArea.Height)
_scrollButton.DrawPosition = new Vector2(_scrollButton.DrawPosition.X, scrollArea.Height - _scrollButton.DrawArea.Height);
if (_scrollButton.DrawPosition.Y >= (scrollArea.Height - 1) - _scrollButton.DrawArea.Height)
_scrollButton.DrawPosition = new Vector2(_scrollButton.DrawPosition.X, (scrollArea.Height - 1) - _scrollButton.DrawArea.Height);
}
}

Expand Down