Skip to content

Commit

Permalink
Cache thumb rect for mouse handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
FenPhoenix committed Feb 21, 2021
1 parent 827186a commit 9f44ff1
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions DarkUI/Controls/ScrollBarVisualOnly_Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ private void MouseDownExt_Handler(object sender, MouseEventExtArgs e)

Point cursorPos = PointToClient(e.Location);

var sbi = GetCurrentScrollBarInfo();
var thumbRect = GetThumbRect(ref sbi);
Rectangle thumbRect = GetThumbRect();

if (thumbRect.Contains(cursorPos))
{
Expand Down Expand Up @@ -205,8 +204,7 @@ private void MouseUpExt_Handler(object sender, MouseEventExtArgs e)

bool refresh = false;

var sbi = GetCurrentScrollBarInfo();
var thumbRect = GetThumbRect(ref sbi);
Rectangle thumbRect = GetThumbRect();
var firstArrowRect = GetArrowRect();
var secondArrowRect = GetArrowRect(second: true);

Expand Down Expand Up @@ -262,8 +260,7 @@ private void MouseMoveExt_Handler(object sender, MouseEventExtArgs e)
{
if (!Visible || !Enabled) return;

var sbi = GetCurrentScrollBarInfo();
var thumbRect = GetThumbRect(ref sbi);
Rectangle thumbRect = GetThumbRect();
var leftArrowRect = GetArrowRect();
var rightArrowRect = GetArrowRect(second: true);

Expand Down Expand Up @@ -358,12 +355,23 @@ private protected Rectangle GetVisualThumbRect(ref Native.SCROLLBARINFO sbi)
: new Rectangle(sbi.xyThumbTop, 1, thumbLength, Height - 2);
}

private Rectangle GetThumbRect(ref Native.SCROLLBARINFO sbi)
private Rectangle GetThumbRect()
{
int thumbLength = sbi.xyThumbBottom - sbi.xyThumbTop;
return _isVertical
? new Rectangle(0, sbi.xyThumbTop, Width, thumbLength)
: new Rectangle(sbi.xyThumbTop, 0, thumbLength, Height);
if (_xyThumbBottom != null && _xyThumbTop != null)
{
int thumbLength = (int)_xyThumbBottom - (int)_xyThumbTop;
return _isVertical
? new Rectangle(0, (int)_xyThumbTop, Width, thumbLength)
: new Rectangle((int)_xyThumbTop, 0, thumbLength, Height);
}
else
{
var sbi = GetCurrentScrollBarInfo();
int thumbLength = sbi.xyThumbBottom - sbi.xyThumbTop;
return _isVertical
? new Rectangle(0, sbi.xyThumbTop, Width, thumbLength)
: new Rectangle(sbi.xyThumbTop, 0, thumbLength, Height);
}
}

private Rectangle GetArrowRect(bool second = false)
Expand Down

0 comments on commit 9f44ff1

Please sign in to comment.