From 3380d2ba0bc019de40473ff7aa73d10827ed548b Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Wed, 30 May 2018 15:47:30 -0400 Subject: [PATCH] Fix problem where you can't see price moves when mouse is over a cell in the ladder --- .../spark/view/Extensions/WPFExtensions.cs | 5 ++ .../view/Spark/Ladder/LadderTactileAdorner.cs | 71 ++++++------------- 2 files changed, 26 insertions(+), 50 deletions(-) diff --git a/src/client/spark/view/Extensions/WPFExtensions.cs b/src/client/spark/view/Extensions/WPFExtensions.cs index c8201ecef..a112ff112 100644 --- a/src/client/spark/view/Extensions/WPFExtensions.cs +++ b/src/client/spark/view/Extensions/WPFExtensions.cs @@ -77,6 +77,11 @@ namespace mbts.ui { return (uint)color.A << 24 | (uint)color.R << 16 | (uint)color.G << 8 | (uint)color.B; } + public static Pen frozen(this Pen pen) { + pen.Freeze(); + return pen; + } + // Perform a breadth first traversal of all children returning any that match the predicate. // Matching children are *not* further traversed public static IEnumerable visual_children_where(this FrameworkElement v, Func match) { diff --git a/src/client/spark/view/Spark/Ladder/LadderTactileAdorner.cs b/src/client/spark/view/Spark/Ladder/LadderTactileAdorner.cs index dcd485ce5..d2687010d 100644 --- a/src/client/spark/view/Spark/Ladder/LadderTactileAdorner.cs +++ b/src/client/spark/view/Spark/Ladder/LadderTactileAdorner.cs @@ -17,12 +17,15 @@ namespace mbts.spark { // I'm not sure that all the properties could be captured with a single column style class. // Although bid_busy_stroke and ask_busy_stroke are the same, I was playing around with different colors during developement, // and decided to leave the infrastructure for them to be different in place. - readonly (Typeface typeface, double font_size, Brush background, Pen stroke) - _bid_style, - _ask_style, - _bid_mouse_down_style, - _ask_mouse_down_style; - readonly Pen _bid_busy_stroke = new Pen(Brushes.PaleGreen, 1), _ask_busy_stroke = new Pen(Brushes.PaleGreen, 1); + readonly Pen + _bid_pen, + _ask_pen, + _bid_mouse_down_pen, + _ask_mouse_down_pen; + readonly Pen + _bid_busy_stroke = new Pen(Brushes.PaleGreen, 1).frozen(), + _ask_busy_stroke = new Pen(Brushes.PaleGreen, 1).frozen(), + _navy_pen = new Pen(Brushes.Navy, 1).frozen(); readonly Dictionary> _busy_cells = new Dictionary>(); readonly LadderGridHost _host; readonly IList _hooks; @@ -33,33 +36,10 @@ namespace mbts.spark { public LadderTactileAdorner(LadderGridHost host, VisualHost visual_host, ScrollViewer scroll_viewer) : base(visual_host) { _host = host; - Typeface - bid_typeface = new Typeface(_host._settings.bid_column.font_family), - ask_typeface = new Typeface(_host._settings.ask_column.font_family); - _bid_style = ( - bid_typeface, - _host._settings.bid_column.font_size, - new SolidColorBrush(_host._settings.bid_column.background.rgb_color()), - new Pen(new SolidColorBrush(Color.FromRgb(102, 178, 255)), 1) - ); - _ask_style = ( - ask_typeface, - _host._settings.ask_column.font_size, - new SolidColorBrush(_host._settings.ask_column.background.rgb_color()), - new Pen(new SolidColorBrush(Color.FromRgb(255, 52, 52)), 1) - ); - _bid_mouse_down_style = ( - bid_typeface, - _host._settings.bid_column.font_size, - new SolidColorBrush(Color.FromRgb(153, 204, 255)), - new Pen(new SolidColorBrush(Color.FromRgb(102, 178, 255)), 1) - ); - _ask_mouse_down_style = ( - ask_typeface, - _host._settings.ask_column.font_size, - new SolidColorBrush(Color.FromRgb(255, 102, 102)), - new Pen(new SolidColorBrush(Color.FromRgb(255, 178, 102)), 1) - ); + _bid_pen = new Pen(new SolidColorBrush(Color.FromRgb(102, 178, 255)), 1).frozen(); + _ask_pen = new Pen(new SolidColorBrush(Color.FromRgb(255, 52, 52)), 1).frozen(); + _bid_mouse_down_pen = new Pen(new SolidColorBrush(Color.FromRgb(102, 178, 255)), 1).frozen(); + _ask_mouse_down_pen = new Pen(new SolidColorBrush(Color.FromRgb(255, 178, 102)), 1).frozen(); _hooks = new List { _host.SubscribeMouseEnter(_host_MouseEnter), _host.SubscribeMouseMove(_host_MouseMove), @@ -105,37 +85,28 @@ namespace mbts.spark { if (_curr_column.column_type == ColumnType.Order) { double y = _curr_row * _host._settings.row_height; double x = _curr_column.x_left; - _draw_cell(drawingContext, null, new Pen(Brushes.Navy, 1), x, y, _curr_column.settings.width); + _draw_cell(drawingContext, _navy_pen, x, y, _curr_column.settings.width); } } else if (_is_mouse_over && (_curr_column.column_type == ColumnType.Bid || _curr_column.column_type == ColumnType.Ask)) { double y = _curr_row * _host._settings.row_height; double x = _curr_column.x_left; - ushort? size = null; - (Typeface typeface, double font_size, Brush background, Pen stroke) style = default; + Pen style = default; switch (_curr_column.column_type) { case ColumnType.Bid: - size = _host._bid_size_from_row(_curr_row); - style = _is_mouse_down ? _bid_mouse_down_style : _bid_style; + style = _is_mouse_down ? _bid_mouse_down_pen : _bid_pen; break; default: - size = _host._ask_size_from_row(_curr_row); - style = _is_mouse_down ? _ask_mouse_down_style : _ask_style; + style = _is_mouse_down ? _ask_mouse_down_pen : _ask_pen; break; } - _draw_cell(drawingContext, style.background, style.stroke, x, y, _curr_column.settings.width); - if (size.HasValue) { - var gr = _curr_column.visual_tup.glyph_context.get_glyph_run( - size.Value.ToString(), _curr_column.settings.font_size, _curr_column.settings.width, _host._settings.row_height, - HorizontalAlignment.Center, x, VerticalAlignment.Center, y); - drawingContext.DrawGlyphRun(new SolidColorBrush(_curr_column.settings.foreground.rgb_color()), gr); - } + _draw_cell(drawingContext, style, x, y, _curr_column.settings.width); } foreach (var row in _busy_cells) { double y = row.Key * _host._settings.row_height; foreach (var cell in row.Value) { if (cell.Key == ColumnType.Bid || cell.Key == ColumnType.Ask) { - _draw_cell(drawingContext, null, cell.Key == ColumnType.Bid ? _bid_busy_stroke : _ask_busy_stroke, _host._column_start(cell.Key), y, _host._column_width(cell.Key)); + _draw_cell(drawingContext, cell.Key == ColumnType.Bid ? _bid_busy_stroke : _ask_busy_stroke, _host._column_start(cell.Key), y, _host._column_width(cell.Key)); } } } @@ -200,8 +171,8 @@ namespace mbts.spark { InvalidateVisual(); #endregion - void _draw_cell(DrawingContext drawing_context, Brush background, Pen stroke, double x, double y, double col_width) => - drawing_context.DrawRectangle(background, stroke, new Rect(x + 1, y, col_width - 2, _host._settings.row_height)); + void _draw_cell(DrawingContext drawing_context, Pen stroke, double x, double y, double col_width) => + drawing_context.DrawRectangle(null, stroke, new Rect(x + 1, y, col_width - 2, _host._settings.row_height)); void _set_current_row_and_column(Point current_posn) { var row = _host._row_for_point(current_posn);