diff --git a/src/client/spark/Modules/Trading/OrderBook/View/OrderBookGridView.xaml b/src/client/spark/Modules/Trading/OrderBook/View/OrderBookGridView.xaml index 94f2043e5..b9c7a1421 100644 --- a/src/client/spark/Modules/Trading/OrderBook/View/OrderBookGridView.xaml +++ b/src/client/spark/Modules/Trading/OrderBook/View/OrderBookGridView.xaml @@ -4,13 +4,12 @@ x:Name="_grid" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:order="clr-namespace:bts.api.orderman;assembly=spark_api" xmlns:sp="clr-namespace:mbts.spark" - xmlns:u="clr-namespace:mbts.ui" xmlns:c="clr-namespace:mbts.ui.controls" xmlns:usp="clr-namespace:mbts.ui.spark" xmlns:uspcv="clr-namespace:mbts.ui.spark.converters" xmlns:sys="clr-namespace:System;assembly=mscorlib" + InactiveSelectionOpacity="0.3" > @@ -109,63 +108,4 @@ - - - - - - - - \ No newline at end of file diff --git a/src/client/spark/Modules/Trading/OrderBook/View/OrderBookGridView.xaml.cs b/src/client/spark/Modules/Trading/OrderBook/View/OrderBookGridView.xaml.cs index d5e489c78..e718abc21 100644 --- a/src/client/spark/Modules/Trading/OrderBook/View/OrderBookGridView.xaml.cs +++ b/src/client/spark/Modules/Trading/OrderBook/View/OrderBookGridView.xaml.cs @@ -1,4 +1,11 @@ +using bts.api.orderman; +using mbts.ui; using mbts.ui.controls; +using mbts.ui.converters; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Media; namespace mbts.spark { internal partial class OrderBookGridView : DIYGrid { @@ -45,8 +52,49 @@ namespace mbts.spark { RootAlgoType = 1 << 29 } - public OrderBookGridView() => + public OrderBookGridView() { InitializeComponent(); + var row_template_factory = new FrameworkElementFactory(typeof(OrderBookRowView)); + row_template_factory.SetValue(OrderBookRowView.BackgroundProperty, RowBackgroundHelper.row_background_binding); + RowTemplate = new DataTemplate { VisualTree = row_template_factory }; + } + + static class RowBackgroundHelper { + public static readonly BindingBase row_background_binding; + + static RowBackgroundHelper() { + var bg_binding = new MultiBinding(); + bg_binding.Bindings.Add(new Binding(nameof(OrderBookRowVM.status))); + bg_binding.Bindings.Add(new Binding(nameof(ListBoxItem.IsSelected)) { RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(ListBoxItem), 1) }); + double overlay_opacity = config.Configuration.get().status_color_opacity_when_selected; + if (overlay_opacity > 0.1 && overlay_opacity < 0.9) { + bg_binding.Converter = ValueConverter.create((status, is_selected) => { + var color = _status_color(status); + return color.HasValue ? new SolidColorBrush(color.Value) { Opacity = is_selected ? overlay_opacity : 1.0 } : null; + }); + } else { + bg_binding.Converter = ValueConverter.create((status, is_selected) => { + if (is_selected) + return null; + var color = _status_color(status); + return color.HasValue ? new SolidColorBrush(color.Value) : null; + }); + } + row_background_binding = bg_binding; + } + + static Color? _status_color(OrderStatus status) { + switch (status) { + case OrderStatus.Canceled: return BTSColors.Orders.canceled_order_background; + case OrderStatus.Completed: return BTSColors.Orders.completed_order_background; + case OrderStatus.Disconnected: + case OrderStatus.RejectedBySpark: + case OrderStatus.Error: + return BTSColors.Orders.error_order_background; + default: return null; + } + } + } } class OrderBookRowView : DIYGrid.HighPerformanceRow { diff --git a/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs b/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs index e1077760c..b3ff38bfa 100644 --- a/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs +++ b/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs @@ -242,6 +242,7 @@ namespace mbts.ui.controls { public static readonly SolidColorBrush DefaultSelectionHighlight = new SolidColorBrush(Colors.MediumSlateBlue) { Opacity = 0.4 }; public static readonly Pen DefaultSelectionStroke = new Pen(Brushes.MediumSlateBlue, 1); readonly NotifyCollectionChangedEventHandler _sort_descriptions_collection_changed_cb; + double _inactive_selection_opacity = 0.2; DataContextHooks _data_context_hooks; public static readonly DependencyProperty SelectionHighlightProperty = @@ -249,7 +250,7 @@ namespace mbts.ui.controls { nameof(SelectionHighlight), (o, v) => { o.Resources[ActiveSelectionHighlightKey] = v; - o.Resources[InactiveSelectionHighlightKey] = new SolidColorBrush(v.Color) { Opacity = 0.2 }.frozen(); + o._reset_inactive_selection_brush(); o.Resources[SelectionStrokeKey] = new Pen(o.SelectionHighlight.Color.to_solid_brush().frozen(), 1).frozen(); foreach (var col in o.Columns.empty_if_null().OfType()) col.on_selection_fill(v); @@ -322,14 +323,24 @@ namespace mbts.ui.controls { } } })); - Resources[InactiveSelectionHighlightKey] = new SolidColorBrush(SelectionHighlight.Color) { Opacity = 0.2 }; Resources[ActiveSelectionHighlightKey] = SelectionHighlight; + _reset_inactive_selection_brush(); _data_context_hooks = new DataContextHooks(this, DataContext); DataContextChanged += OnDataContextChanged; } public event DIYGridSortingEventHandler Sorting; + public double InactiveSelectionOpacity { + get => _inactive_selection_opacity; + set { + if (value != _inactive_selection_opacity && value.is_within_range(0.1, 0.9)) { + _inactive_selection_opacity = value; + _reset_inactive_selection_brush(); + } + } + } + public ItemContainerGenerator RowContainerGenerator => _row_presenter.ItemContainerGenerator; @@ -376,6 +387,18 @@ namespace mbts.ui.controls { void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e) => Disposable.replace(ref _data_context_hooks, new DataContextHooks(this, e.NewValue)); + void _reset_inactive_selection_brush() { + try { + if (TryFindResource(ActiveSelectionHighlightKey) is SolidColorBrush brush) { + var clone = brush.Clone(); + if (_inactive_selection_opacity < clone.Opacity) { + clone.Opacity = _inactive_selection_opacity; + } + Resources[InactiveSelectionHighlightKey] = clone; + } + } catch { } + } + #region Column Handling private void invalidate_column_layout(object sender = null, EventArgs args = null) { var geometry = GetColumnGeometry().ToList(); @@ -591,7 +614,7 @@ namespace mbts.ui.controls { _row_presenter.ItemContainerStyle = _row_style; } - public Style RowStyle { get => GetValue(RowStyleProperty) as Style; set => SetValue(StyleProperty, value); } + public Style RowStyle { get => GetValue(RowStyleProperty) as Style; set => SetValue(RowStyleProperty, value); } #endregion public static readonly DependencyProperty CurrentRowProperty = DependencyProperty.Register( @@ -915,4 +938,4 @@ namespace mbts.ui.controls { } }); } -} \ No newline at end of file +} diff --git a/src/client/spark/view/Controls/DIYGrid/Row/HighPerformanceRow.cs b/src/client/spark/view/Controls/DIYGrid/Row/HighPerformanceRow.cs index 77b375065..eb1213a7c 100644 --- a/src/client/spark/view/Controls/DIYGrid/Row/HighPerformanceRow.cs +++ b/src/client/spark/view/Controls/DIYGrid/Row/HighPerformanceRow.cs @@ -11,7 +11,22 @@ using System.Windows.Media; namespace mbts.ui.controls { partial class DIYGrid { - public class HighPerformanceRow : FrameworkElement where TRowVM : class, IRowVM { + public class HighPerformanceRowBase : FrameworkElement { + protected Brush cached_background; + + public static readonly DependencyProperty BackgroundProperty = + WPFHelper.create_dp( + nameof(Background), + FrameworkPropertyMetadataOptions.AffectsRender, + (o, v) => o.cached_background = v); + + public Brush Background { + get => GetValue(BackgroundProperty) as Brush; + set => SetValue(BackgroundProperty, value); + } + } + + public class HighPerformanceRow : HighPerformanceRowBase where TRowVM : class, IRowVM { double _row_height; ObservableCollection _columns; List _column_layout = new List(); @@ -85,6 +100,9 @@ namespace mbts.ui.controls { _element_cells.VisualAtIndex(index); protected override void OnRender(DrawingContext dc) { + if (cached_background != null) { + dc.DrawRectangle(cached_background, null, new Rect(0, 0, ActualWidth, ActualHeight)); + } if (_row != null) { foreach (var cell in _column_layout) { if (!cell.column.is_collapsed && cell.column is IRenderColumn rc) diff --git a/src/client/spark_api/utils/MathUtils.cs b/src/client/spark_api/utils/MathUtils.cs index 34b80caf2..7c2ebfaf4 100644 --- a/src/client/spark_api/utils/MathUtils.cs +++ b/src/client/spark_api/utils/MathUtils.cs @@ -53,6 +53,10 @@ namespace bts.utils { for (int i = 1; i < num2; i++) if ((num1 * i) % num2 == 0) return i * num1; return num1 * num2; } + + public static bool is_within_range(this double value, double min, double max) => + value >= min && value <= max; + public static int within_range(int min, int max, int value) { if (value < min) return min; if (value > max) return max; diff --git a/src/lib/config/protos/UI.proto b/src/lib/config/protos/UI.proto index e2aece834..ceaea14db 100644 --- a/src/lib/config/protos/UI.proto +++ b/src/lib/config/protos/UI.proto @@ -73,6 +73,7 @@ message LadderKnobs { message OrderBookOptions { optional bool animate_child_order_rows = 1 [default = false]; + optional double status_color_opacity_when_selected = 2 [default = 0.35]; } message ShellPingOptions {