diff --git a/.editorconfig b/.editorconfig index 0470d8c..c53ad35 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,6 +11,7 @@ insert_final_newline = true indent_style = space indent_size = 4 trim_trailing_whitespace = true +end_of_line = lf [project.json] indent_size = 2 @@ -54,15 +55,15 @@ dotnet_style_predefined_type_for_member_access = true:suggestion # name all constant fields using PascalCase dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields -dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style -dotnet_naming_symbols.constant_fields.applicable_kinds = field +dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style +dotnet_naming_symbols.constant_fields.applicable_kinds = field dotnet_naming_symbols.constant_fields.required_modifiers = const dotnet_naming_style.pascal_case_style.capitalization = pascal_case # static fields should have s_ prefix dotnet_naming_rule.static_fields_should_have_prefix.severity = suggestion dotnet_naming_rule.static_fields_should_have_prefix.symbols = static_fields -dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style +dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style dotnet_naming_symbols.static_fields.applicable_kinds = field dotnet_naming_symbols.static_fields.required_modifiers = static dotnet_naming_symbols.static_fields.applicable_accessibilities = private, internal, private_protected @@ -72,7 +73,7 @@ dotnet_naming_style.static_prefix_style.capitalization = camel_case # internal and private fields should be _camelCase dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields -dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style +dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style dotnet_naming_symbols.private_internal_fields.applicable_kinds = field dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal dotnet_naming_style.camel_case_underscore_style.required_prefix = _ diff --git a/LibreHardwareMonitor/UI/Themes/ThemedHScrollIndicator.cs b/LibreHardwareMonitor/UI/Themes/ThemedHScrollIndicator.cs index d66438b..17a0775 100644 --- a/LibreHardwareMonitor/UI/Themes/ThemedHScrollIndicator.cs +++ b/LibreHardwareMonitor/UI/Themes/ThemedHScrollIndicator.cs @@ -6,6 +6,9 @@ namespace LibreHardwareMonitor.UI.Themes public class ThemedHScrollIndicator : Control { private readonly HScrollBar _scrollbar; + private int _startValue = 0; + private int _startPos = 0; + private bool _isScrolling = false; public static void AddToControl(Control control) { @@ -39,6 +42,54 @@ namespace LibreHardwareMonitor.UI.Themes scrollBar.ValueChanged += (s, e) => Invalidate(); scrollBar.Height = 0; + this.MouseDown += OnMouseDown; + } + + private void OnMouseDown(object sender, MouseEventArgs e) + { + if (_isScrolling) + return; + + _isScrolling = true; + + //note: this.Capture is true when the control is clicked, no need to handle this + + _startPos = e.X; + _startValue = _scrollbar.Value; + + this.MouseUp += OnMouseUp; + this.MouseMove += OnMouseMove; + } + + private void OnMouseUp(object sender, MouseEventArgs e) + { + _isScrolling = false; + this.MouseUp -= OnMouseUp; + this.MouseMove -= OnMouseMove; + } + + private void OnMouseMove(object sender, MouseEventArgs e) + { + if (!_isScrolling) + return; + + //pixel to range scaling: + double totalRange = _scrollbar.Maximum - _scrollbar.Minimum; + + if (totalRange <= 0) + return; + + double scaleToPercent = totalRange / Bounds.Width; + double scrollValue = _startValue + (e.X - _startPos) * scaleToPercent; + + if (scrollValue < _scrollbar.Minimum) + scrollValue = _scrollbar.Minimum; + + if (scrollValue > (_scrollbar.Maximum - _scrollbar.LargeChange)) + scrollValue = _scrollbar.Maximum - _scrollbar.LargeChange; + + _scrollbar.Value = (int)scrollValue; + Refresh(); } protected override void OnPaint(PaintEventArgs e) diff --git a/LibreHardwareMonitor/UI/Themes/ThemedVScrollIndicator.cs b/LibreHardwareMonitor/UI/Themes/ThemedVScrollIndicator.cs index 6cdb70a..16b15f5 100644 --- a/LibreHardwareMonitor/UI/Themes/ThemedVScrollIndicator.cs +++ b/LibreHardwareMonitor/UI/Themes/ThemedVScrollIndicator.cs @@ -6,6 +6,9 @@ namespace LibreHardwareMonitor.UI.Themes public class ThemedVScrollIndicator : Control { private readonly VScrollBar _scrollbar; + private int _startValue = 0; + private int _startPos = 0; + private bool _isScrolling = false; public static void AddToControl(Control control) { @@ -39,6 +42,54 @@ namespace LibreHardwareMonitor.UI.Themes scrollBar.ValueChanged += (s, e) => Invalidate(); scrollBar.Width = 0; + this.MouseDown += OnMouseDown; + } + + private void OnMouseDown(object sender, MouseEventArgs e) + { + if (_isScrolling) + return; + + _isScrolling = true; + + //note: this.Capture is true when the control is clicked, no need to handle this + + _startPos = e.Y; + _startValue = _scrollbar.Value; + + this.MouseUp += OnMouseUp; + this.MouseMove += OnMouseMove; + } + + private void OnMouseUp(object sender, MouseEventArgs e) + { + _isScrolling = false; + this.MouseUp -= OnMouseUp; + this.MouseMove -= OnMouseMove; + } + + private void OnMouseMove(object sender, MouseEventArgs e) + { + if (!_isScrolling) + return; + + //pixel to range scaling: + double totalRange = _scrollbar.Maximum - _scrollbar.Minimum; + + if (totalRange <= 0) + return; + + double scaleToPercent = totalRange / Bounds.Height; + double scrollValue = _startValue + (e.Y - _startPos) * scaleToPercent; + + if (scrollValue < _scrollbar.Minimum) + scrollValue = _scrollbar.Minimum; + + if (scrollValue > (_scrollbar.Maximum - _scrollbar.LargeChange)) + scrollValue = _scrollbar.Maximum - _scrollbar.LargeChange; + + _scrollbar.Value = (int)scrollValue; + Refresh(); } protected override void OnPaint(PaintEventArgs e)