From 7b7ae9d7e2b5a5ffbb851cd1bf433f658d533216 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Thu, 29 Aug 2019 09:07:22 -0500 Subject: [PATCH] making hover effects optional --- .../DIYGrid/CellRender/HyperlinkCell.cs | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/client/spark/view/Controls/DIYGrid/CellRender/HyperlinkCell.cs b/src/client/spark/view/Controls/DIYGrid/CellRender/HyperlinkCell.cs index b7c45bd8f..1c73d6daf 100644 --- a/src/client/spark/view/Controls/DIYGrid/CellRender/HyperlinkCell.cs +++ b/src/client/spark/view/Controls/DIYGrid/CellRender/HyperlinkCell.cs @@ -14,6 +14,7 @@ namespace mbts.ui.controls { public class HyperlinkCell : FrameworkElement, ICommandSource { static Brush _hover_background_highlight = new SolidColorBrush(Colors.Yellow) { Opacity = 0.5 }.frozen(); static Brush _hover_foreground_brush = new SolidColorBrush(Colors.Black).frozen(); + static Pen _hover_underline_pen = new Pen(_hover_foreground_brush, 1); // these fields each represent properties that are accessed frequently, // they are stored locally to reduce repetative DependencyProperty lookups Thickness _padding; @@ -51,9 +52,6 @@ namespace mbts.ui.controls { _font_size = FontSize; _text = Text; _glyph_context = GlyphContext.create(FontFamily, FontWeight); - // underline line will only be drawn when IsMouseDirectlyOver, so have it - // match the _hover_foreground_brush; - _underline_pen = new Pen(_hover_foreground_brush, 1); IsMouseDirectlyOverChanged += (s, e) => { _toggle_mouse_cursor(); }; @@ -77,7 +75,7 @@ namespace mbts.ui.controls { FrameworkPropertyMetadataOptions.AffectsRender, (p, v) => { p._foreground = v; - //p._underline_pen = new Pen(v, 1); + p._underline_pen = new Pen(v, 1); }, Brushes.Black); public Brush Foreground { get => (Brush)GetValue(ForegroundProperty); set => SetValue(ForegroundProperty, value); } @@ -225,6 +223,17 @@ namespace mbts.ui.controls { #endregion + #region EnableHoverEffect + public static readonly DependencyProperty EnableHoverEffectProperty = + WPFHelper.create_dp(nameof(EnableHoverEffect), false); + + public bool EnableHoverEffect { + get => (bool)GetValue(EnableHoverEffectProperty); + set => SetValue(EnableHoverEffectProperty, value); + } + #endregion + + #region Paraphrased/Simplified from https://referencesource.microsoft.com/#PresentationFramework/src/Framework/System/Windows/Documents/Hyperlink.cs protected override void OnMouseDown(MouseButtonEventArgs e) { @@ -283,7 +292,7 @@ namespace mbts.ui.controls { var rect = new Rect(0, 0, rs.Width, rs.Height); var bg = Background; if (bg != null) { - if (_glyph_run != null && IsMouseDirectlyOver) { + if (_glyph_run != null && IsMouseDirectlyOver && EnableHoverEffect) { drawingContext.DrawRectangle(_hover_background_highlight, null, rect); } else { drawingContext.DrawRectangle(bg, null, rect); @@ -292,7 +301,11 @@ namespace mbts.ui.controls { if (_glyph_run != null) { drawingContext.PushClip(new RectangleGeometry(rect)); if (IsMouseDirectlyOver) { - drawingContext.DrawGlyphRun(_hover_foreground_brush, _glyph_run); + if (EnableHoverEffect) { + drawingContext.DrawGlyphRun(_hover_foreground_brush, _glyph_run); + } else { + drawingContext.DrawGlyphRun(_foreground, _glyph_run); + } // draw underline Point pt; switch (_horizontal_alignment) { @@ -307,7 +320,11 @@ namespace mbts.ui.controls { pt = new Point(0.5 * (ActualWidth - _glyph_width), 0.5 * (ActualHeight + _font_size) + 1); break; } - drawingContext.DrawLine(_underline_pen, pt, new Point(pt.X + _glyph_width, pt.Y)); + if (EnableHoverEffect) { + drawingContext.DrawLine(_hover_underline_pen, pt, new Point(pt.X + _glyph_width, pt.Y)); + } else { + drawingContext.DrawLine(_underline_pen, pt, new Point(pt.X + _glyph_width, pt.Y)); + } } else { drawingContext.DrawGlyphRun(_foreground, _glyph_run); }