From 9f44ff166a80043e3f1ceb7a12f0261200f26f54 Mon Sep 17 00:00:00 2001 From: FenPhoenix Date: Sun, 21 Feb 2021 00:56:40 -0800 Subject: [PATCH] Cache thumb rect for mouse handlers --- DarkUI/Controls/ScrollBarVisualOnly_Base.cs | 30 +++++++++++++-------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/DarkUI/Controls/ScrollBarVisualOnly_Base.cs b/DarkUI/Controls/ScrollBarVisualOnly_Base.cs index a829e2b55..64bba8e60 100644 --- a/DarkUI/Controls/ScrollBarVisualOnly_Base.cs +++ b/DarkUI/Controls/ScrollBarVisualOnly_Base.cs @@ -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)) { @@ -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); @@ -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); @@ -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)