From 0f1135d5d623ff64fb0922557e2f8cc62ad2749a Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Fri, 9 Aug 2019 14:07:04 -0500 Subject: [PATCH 001/116] adding background color to settings and related infrastruture --- .../spark/view/Controls/DIYGrid/DIYGrid.cs | 1 + .../Controls/DIYGrid/Settings/GridSettings.cs | 26 ++++++++++++++----- .../DIYGrid/Settings/GridSettingsManager.cs | 6 +++-- .../DIYGrid/Settings/GridSettingsVM.cs | 4 ++- .../Settings/SimpleGridSettingsManager.cs | 6 +++-- .../DIYGrid/Settings/SimpleGridSettingsVM.cs | 5 +++- .../Shell/Settings/ShellSettingsDialog.xaml | 8 ++++-- 7 files changed, 42 insertions(+), 14 deletions(-) diff --git a/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs b/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs index fda5d6cc6..813a9ac31 100644 --- a/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs +++ b/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs @@ -247,6 +247,7 @@ namespace mbts.ui.controls { // and FrameworkElementColumns that paint the selection brush themselves // (e.g MarketView bid/ask columns, bc their background is not transparent, it covers the ListBoxItem selection-highlight). public static readonly SolidColorBrush DefaultSelectionHighlight = new SolidColorBrush(Colors.MediumSlateBlue) { Opacity = 0.4 }; + public static readonly SolidColorBrush DefaultBackgroundColor = new SolidColorBrush(BTSColors.Grid.input_cell_background) { Opacity = 0.40 }; public static readonly Pen DefaultSelectionStroke = new Pen(Brushes.MediumSlateBlue, 1); readonly NotifyCollectionChangedEventHandler _sort_descriptions_collection_changed_cb; double _inactive_selection_opacity = 0.2; diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettings.cs b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettings.cs index a46c203e3..ac0ddef91 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettings.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettings.cs @@ -19,7 +19,9 @@ namespace mbts.ui.settings { const ushort _default_font_weight = 400; public static GridSettings Default => - new GridSettings(selection_highlight: new ColorOpacityProto(FallbackValues.selection_highlight.Color, FallbackValues.selection_highlight.Opacity)); + new GridSettings( + selection_highlight: new ColorOpacityProto(FallbackValues.selection_highlight.Color, FallbackValues.selection_highlight.Opacity), + background_color: new ColorOpacityProto(FallbackValues.background_color.Color, FallbackValues.background_color.Opacity)); // corrects any inappropriate values that would render the grid unusable (usually nulls) // NOTE: if you add a property to GridSettings that could have such a value, please add a conditional-correction for it below) @@ -39,6 +41,7 @@ namespace mbts.ui.settings { public static Color font_color => _default_font_color.rgb_color(); public static FontWeight font_weight => FontWeight.FromOpenTypeWeight(_default_font_weight); public static SolidColorBrush selection_highlight => DIYGrid.DefaultSelectionHighlight; + public static SolidColorBrush background_color => DIYGrid.DefaultBackgroundColor; } public static IValueConverter selection_highlight_converter => ValueConverter.create(gs => gs.selection_highlight.to_brush().frozen()); @@ -65,17 +68,22 @@ namespace mbts.ui.settings { List _columns; [ProtoMember(7)] List _sorting_criterion; + [ProtoMember(8)] + readonly ColorOpacityProto _background_color; public GridSettings() { _font_family = _default_font_family; _font_size = _default_font_size; _font_weight = _default_font_weight; _font_color = _default_font_color; + + // new setting in proto defaulted here + _background_color = new ColorOpacityProto(DIYGrid.DefaultBackgroundColor.Color, DIYGrid.DefaultBackgroundColor.Opacity); } public GridSettings( string font_family = _default_font_family, double font_size = _default_font_size, FontWeight font_weight = default, uint font_color = _default_font_color, - ColorOpacityProto? selection_highlight = null, IEnumerable columns = null, IEnumerable sorting_criterion = null) { + ColorOpacityProto? selection_highlight = null, IEnumerable columns = null, IEnumerable sorting_criterion = null, ColorOpacityProto? background_color = null) { // _font_family = font_family; _font_size = font_size; @@ -84,6 +92,7 @@ namespace mbts.ui.settings { _selection_highlight = selection_highlight ?? new ColorOpacityProto(0, 1); _columns = new List(columns.empty_if_null()); _sorting_criterion = new List(sorting_criterion.empty_if_null()); + _background_color = background_color ?? new ColorOpacityProto(DIYGrid.DefaultBackgroundColor.Color, DIYGrid.DefaultBackgroundColor.Opacity); } public string font_family => _font_family; @@ -91,12 +100,14 @@ namespace mbts.ui.settings { public uint font_color => _font_color; public FontWeight font_weight => FontWeight.FromOpenTypeWeight(_font_weight); public ColorOpacityProto selection_highlight => _selection_highlight; + public ColorOpacityProto background_color => _background_color; public IReadOnlyList columns => _columns ?? (_columns = new List(0)); [Obsolete] // TODO: remove sorting_criterion from GridSettings entirely. This should be part of IShellWindow's StartupData, since it is an instance-specific setting, and prob not part of the shared defaults public IReadOnlyList sorting_criterion => _sorting_criterion ?? (_sorting_criterion = new List(0)); public static GridSettings get_default() => - new GridSettings(_default_font_family, _default_font_size, FontWeights.Normal, _default_font_color, new ColorOpacityProto(Colors.MediumSlateBlue, 0.4)); + new GridSettings(_default_font_family, _default_font_size, FontWeights.Normal, _default_font_color, new ColorOpacityProto(DIYGrid.DefaultSelectionHighlight.Color, DIYGrid.DefaultSelectionHighlight.Opacity), + background_color: new ColorOpacityProto(DIYGrid.DefaultBackgroundColor.Color, DIYGrid.DefaultBackgroundColor.Opacity)); public GridSettings with(IEnumerable columns = null, IEnumerable sorting_criterion = null, string font_family = null, double font_size = double.NaN) => new GridSettings( @@ -106,7 +117,8 @@ namespace mbts.ui.settings { _font_color, _selection_highlight, columns ?? _columns, - sorting_criterion ?? _sorting_criterion); + sorting_criterion ?? _sorting_criterion, + _background_color); public GridSettings clone() => with(); @@ -119,8 +131,9 @@ namespace mbts.ui.settings { selection_highlight == other.selection_highlight && EqualityComparer.safe_sequence_equals(columns, other.columns) && #pragma warning disable CS0612 // Type or member is obsolete - EqualityComparer.safe_sequence_equals(sorting_criterion, other.sorting_criterion); + EqualityComparer.safe_sequence_equals(sorting_criterion, other.sorting_criterion) && #pragma warning restore CS0612 // Type or member is obsolete + background_color == other.background_color; public override bool Equals(object obj) => Equals(obj as GridSettings); @@ -134,7 +147,8 @@ namespace mbts.ui.settings { selection_highlight.GetHashCode(), EqualityComparer.safe_aggregate_hash(columns), #pragma warning disable CS0612 // Type or member is obsolete - EqualityComparer.safe_aggregate_hash(sorting_criterion)); + EqualityComparer.safe_aggregate_hash(sorting_criterion), #pragma warning restore CS0612 // Type or member is obsolete + background_color.GetHashCode()); } } \ No newline at end of file diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsManager.cs b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsManager.cs index 11dc2d487..eed7af4cd 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsManager.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsManager.cs @@ -30,7 +30,7 @@ namespace mbts.ui { readonly DelegateProperty _font_family; readonly DelegateProperty _font_weight; readonly DelegateProperty _font_size; - readonly DelegateProperty _font_color, _selection_highlight; + readonly DelegateProperty _font_color, _selection_highlight, _background_color; readonly SetMap, AnimationDefinitionWrapper> _animation_defs = new SetMap, AnimationDefinitionWrapper>(); readonly Func _predicate_data_factory; readonly Func> _predicate_factory; @@ -77,6 +77,7 @@ namespace mbts.ui { _font_size = backing(nameof(font_size), () => grid_settings.font_size, nameof(font_size)); _font_color = backing(nameof(font_color), () => grid_settings.font_color.rgb_solid_brush().frozen(), nameof(grid_settings)); _selection_highlight = backing(nameof(selection_highlight), () => grid_settings.selection_highlight.to_brush().frozen(), nameof(grid_settings)); + _background_color = backing(nameof(background_color), () => grid_settings.background_color.to_brush().frozen(), nameof(grid_settings)); } public void Dispose() => @@ -88,6 +89,7 @@ namespace mbts.ui { public double font_size => _font_size.Value; public SolidColorBrush font_color => _font_color.Value; public SolidColorBrush selection_highlight => _selection_highlight.Value; + public SolidColorBrush background_color => _background_color.Value; public GridSettingsVM create_vm(GridSettings settings) { var vm = new GridSettingsVM(_bus, _orders_model, _predicate_data_factory, _notification_predicate_factory, _create_predicate_vm, _create_column_predicate_vm, _create_settings_obj, _column_flags.ToDictionary(kv => kv.Key, kv => kv.Value.flags)); @@ -112,7 +114,7 @@ namespace mbts.ui { var grid = value.general ?? GridSettings.Default; _grid_settings.set(grid); foreach (ColumnBase col in _columns) - col.set_fallback_font_params(new FontFamily(grid.font_family), grid.font_size, grid.font_color.rgb_color(), grid.font_weight); + col.set_fallback_font_params(new FontFamily(grid.font_family), grid.font_size, grid.font_color.rgb_color(), grid.font_weight, grid.background_color); _predicate_animations_data = value.predicate_animations; _animation_defs.clear(); foreach (var pa in _predicate_animations_data) { diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsVM.cs b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsVM.cs index 175940d56..8caeebfff 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsVM.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsVM.cs @@ -100,6 +100,7 @@ namespace mbts.spark { public FontWeight font_weight { get => _font_weight.Value; set => _font_weight.set(value); } public ColorPickerPopupVM font_color { get; } = new ColorPickerPopupVM(); public ColorPickerPopupVM selection_highlight { get; } = new ColorPickerPopupVM(); + public ColorPickerPopupVM background_color { get; } = new ColorPickerPopupVM(); public double font_size { get => _font_size.Value; set => _font_size.set(value); } public bool enable_sound_triggers => true; public bool show_predicate_animations { get => _show_predicate_animations.Value; set => _show_predicate_animations.set(value); } @@ -130,7 +131,7 @@ namespace mbts.spark { foreach (IGrouping g in animations) animation_map.AddOrUpdate(g.Key, p => animation_tuple(c: g), (p, t) => t.cell_animations.AddRange(g)); } - return _create_settings_obj(new GridSettings(font_family.name(), font_size, font_weight, font_color.color.rgb_color(), selection_highlight.to_proto(), col_settings), + return _create_settings_obj(new GridSettings(font_family.name(), font_size, font_weight, font_color.color.rgb_color(), selection_highlight.to_proto(), col_settings, background_color: background_color.to_proto()), animation_map.Select(kv => PredicateAnimations.create_data(kv.Key, kv.Value.cell_animations, kv.Value.row_animations, kv.Value.sounds))); // (List row_animations, List sounds, List cell_animations) animation_tuple(IEnumerable r = null, IEnumerable s = null, IGrouping c = null) => @@ -142,6 +143,7 @@ namespace mbts.spark { _font_weight.set(sd.general.font_weight); font_color.load_from(sd.general.font_color.rgb_solid_brush()); selection_highlight.load_from(sd.general.selection_highlight.to_brush()); + background_color.load_from(sd.general.background_color.to_brush()); _font_size.set(sd.general.font_size); var col_animations = new Dictionary>>(); predicate_animations.Clear(); diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsManager.cs b/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsManager.cs index 76823094e..4b66e19f6 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsManager.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsManager.cs @@ -20,7 +20,7 @@ namespace mbts.ui { readonly DelegateProperty _font_family; readonly DelegateProperty _font_weight; readonly DelegateProperty _font_size; - readonly DelegateProperty _font_color, _selection_highlight; + readonly DelegateProperty _font_color, _selection_highlight, _background_color; readonly IReadOnlyDictionary _column_flags; public SimpleGridSettingsManager(ObservableCollection columns) @@ -35,6 +35,7 @@ namespace mbts.ui { _font_size = backing(nameof(font_size), () => grid_settings.font_size, nameof(font_size)); _font_color = backing(nameof(font_color), () => grid_settings.font_color.rgb_solid_brush().frozen(), nameof(grid_settings)); _selection_highlight = backing(nameof(selection_highlight), () => grid_settings.selection_highlight.to_brush().frozen(), nameof(grid_settings)); + _background_color = backing(nameof(background_color), () => grid_settings.background_color.to_brush().frozen(), nameof(grid_settings)); _row_vms = row_vms; } @@ -44,6 +45,7 @@ namespace mbts.ui { public double font_size => _font_size.Value; public SolidColorBrush font_color => _font_color.Value; public SolidColorBrush selection_highlight => _selection_highlight.Value; + public SolidColorBrush background_color => _background_color.Value; public SimpleGridSettingsVM create_vm(GridSettings settings) { var vm = new SimpleGridSettingsVM(_column_flags.ToDictionary(kv => kv.Key, kv => kv.Value.flags)); @@ -86,7 +88,7 @@ namespace mbts.ui { grid = grid ?? GridSettings.Default; _grid_settings.set(grid); foreach (ColumnBase col in _columns) - col.set_fallback_font_params(new FontFamily(grid.font_family), grid.font_size, grid.font_color.rgb_color(), grid.font_weight); + col.set_fallback_font_params(new FontFamily(grid.font_family), grid.font_size, grid.font_color.rgb_color(), grid.font_weight, grid.background_color); // ** in the unfortunate event that we botch backwards compatability, and the columns don't bear a 1:1 relationship with the column-settings // don't add insult to injury by crashing ** if (grid_settings.columns != null) { diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs b/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs index c27cce279..220424bc6 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs @@ -79,6 +79,7 @@ namespace mbts.spark { public FontWeight font_weight { get => _font_weight.Value; set => _font_weight.set(value); } public ColorPickerPopupVM font_color { get; } = new ColorPickerPopupVM(); public ColorPickerPopupVM selection_highlight { get; } = new ColorPickerPopupVM(); + public ColorPickerPopupVM background_color { get; } = new ColorPickerPopupVM(); public double font_size { get => _font_size.Value; set => _font_size.set(value); } public bool enable_sound_triggers => false; public bool show_predicate_animations { get => _show_predicate_animations.Value; set => _show_predicate_animations.set(value); } @@ -98,12 +99,13 @@ namespace mbts.spark { get { yield return font_color; yield return selection_highlight; + yield return background_color; yield return this; } } public GridSettings create() => - new GridSettings(font_family.name(), font_size, font_weight, font_color.color.rgb_color(), selection_highlight.to_proto(), columns.Select(c => c.create())); + new GridSettings(font_family.name(), font_size, font_weight, font_color.color.rgb_color(), selection_highlight.to_proto(), columns.Select(c => c.create()), background_color: background_color.to_proto()); public void load_from(GridSettings value) { if (value == null) @@ -113,6 +115,7 @@ namespace mbts.spark { _font_weight.set(value.font_weight); font_color.load_from(value.font_color.rgb_solid_brush()); selection_highlight.load_from(value.selection_highlight.to_brush()); + background_color.load_from(value.background_color.to_brush()); _font_size.set(value.font_size); var curr_col_id = current_column?.id; columns.SetItems(value.columns.Select(col => { diff --git a/src/client/spark/view/Shell/Settings/ShellSettingsDialog.xaml b/src/client/spark/view/Shell/Settings/ShellSettingsDialog.xaml index 2173a5f7d..882871751 100644 --- a/src/client/spark/view/Shell/Settings/ShellSettingsDialog.xaml +++ b/src/client/spark/view/Shell/Settings/ShellSettingsDialog.xaml @@ -49,6 +49,8 @@ + + @@ -69,8 +71,10 @@ Font Color (default) - Selection Highlight - + Background Color (default) + + Selection Highlight + From 19729a276d1050fa24cfa42287fa43277fa4a272 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Fri, 9 Aug 2019 14:08:03 -0500 Subject: [PATCH 002/116] adding background color to ColumnBase as every column should be able to eventually override the grid default bg --- .../view/Controls/DIYGrid/Columns/ColumnBase.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/client/spark/view/Controls/DIYGrid/Columns/ColumnBase.cs b/src/client/spark/view/Controls/DIYGrid/Columns/ColumnBase.cs index 3d3e1e1f6..6de340375 100644 --- a/src/client/spark/view/Controls/DIYGrid/Columns/ColumnBase.cs +++ b/src/client/spark/view/Controls/DIYGrid/Columns/ColumnBase.cs @@ -1,4 +1,5 @@ -using mbts.spark; +using bts.proto; +using mbts.spark; using mbts.spark.filters; using mbts.ui.settings; using mbts.ui.shell; @@ -173,16 +174,19 @@ namespace mbts.ui.controls { //readonly ExternalProperty _font_weigh FontWeight _fallback_font_weight; Color _fallback_font_color; + ColorOpacityProto _fallback_background_color; double _fallback_font_size; FontFamily _fallback_font_family; FontWeight? _font_weight_override; Color? _font_color_override; + ColorOpacityProto? _background_color_override; object _header_copy; protected ColumnBase() { var gs = GridSettings.Default; _fallback_font_weight = gs.font_weight; _fallback_font_color = gs.font_color.rgb_color(); + _fallback_background_color = gs.background_color; _fallback_font_size = gs.font_size; _fallback_font_family = new FontFamily(gs.font_family); original_width = double.NaN; @@ -215,6 +219,9 @@ namespace mbts.ui.controls { public FontWeight font_weight => font_weight_override ?? _fallback_font_weight; public Color font_color => font_color_override ?? _fallback_font_color; public Brush font_brush => new SolidColorBrush(font_color); + public ColorOpacityProto? background_color_override { get => _background_color_override; set => _set_font_param(ref _background_color_override, value); } + public ColorOpacityProto background_color => background_color_override ?? _fallback_background_color; + public Brush background_brush => background_color.to_brush(); // TODO: find a better way to store the header-property in a thread-safe manner - a value for GridSettings.display_name, more specifically. // Since save_state is called from a different thread in IShared/SlowWindows, it is not safe to access the DependencyProperty store from that method. // By updating a local _header_copy field in the Header setter, the DependencyProperty lookup may be bypassed when appropriate (see create method below). @@ -235,7 +242,7 @@ namespace mbts.ui.controls { if (settings == null) return; using (ReflectionHelper.detect_property_changes(this, _raise_prop_changed, nameof(is_visible), nameof(is_collapsed), nameof(font_weight_override), nameof(font_weight), - nameof(font_color_override), nameof(font_color), nameof(font_brush), nameof(font_family), nameof(font_size), nameof(horizontal_alignment), nameof(horizontal_offset))) { + nameof(font_color_override), nameof(font_color), nameof(font_brush), nameof(font_family), nameof(font_size), nameof(horizontal_alignment), nameof(horizontal_offset), nameof(background_color), nameof(background_brush), nameof(background_color_override))) { // id = settings.id; if (!string.IsNullOrEmpty(settings.display_name)) @@ -246,6 +253,7 @@ namespace mbts.ui.controls { font_color_override = settings.font_color_override; horizontal_alignment = settings.horizontal_alignment; horizontal_offset = settings.horizontal_offset; + //background_color_override = settings.background_color_override; } if (original_width != settings.width) { original_width = settings.width; @@ -255,11 +263,12 @@ namespace mbts.ui.controls { } // 'fallback' font-params (aka 'grid-level' font-params) - public void set_fallback_font_params(FontFamily font_family, double font_size, Color font_color, FontWeight font_weight) { - using (ReflectionHelper.detect_property_changes(this, _raise_prop_changed, nameof(font_family), nameof(font_size), nameof(font_color), nameof(font_weight))) { + public void set_fallback_font_params(FontFamily font_family, double font_size, Color font_color, FontWeight font_weight, ColorOpacityProto background_color) { + using (ReflectionHelper.detect_property_changes(this, _raise_prop_changed, nameof(font_family), nameof(font_size), nameof(font_color), nameof(font_weight), nameof(background_color), nameof(background_brush))) { _fallback_font_family = font_family; _fallback_font_size = font_size; _fallback_font_color = font_color; + _fallback_background_color = background_color; _fallback_font_weight = font_weight; } font_params_changed?.Invoke(); From 14a86d7b29365268d838a752d8db33a190279bb6 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Fri, 9 Aug 2019 14:09:19 -0500 Subject: [PATCH 003/116] changing RenderColumn to use ColumnBase's background_brush; removed background property --- src/client/spark/view/Controls/DIYGrid/Columns/RenderColumn.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/client/spark/view/Controls/DIYGrid/Columns/RenderColumn.cs b/src/client/spark/view/Controls/DIYGrid/Columns/RenderColumn.cs index 4c58bc40d..f5779e1e5 100644 --- a/src/client/spark/view/Controls/DIYGrid/Columns/RenderColumn.cs +++ b/src/client/spark/view/Controls/DIYGrid/Columns/RenderColumn.cs @@ -30,7 +30,7 @@ namespace mbts.ui.controls { Func get_brush = null) : base() { _get_text = get_text; - Func get_default_background_brush = (TRowVM _) => this.background; + Func get_default_background_brush = (TRowVM _) => this.background_brush; _get_background_brush = get_brush ?? get_default_background_brush; this.filter = filter; this.filter_template = filter_template; @@ -42,7 +42,6 @@ namespace mbts.ui.controls { public IDataGridColumnFilter filter { get; } public string filter_template { get; } - public Brush background { get; set; } public VerticalAlignment vertical_alignment { get; set; } = VerticalAlignment.Center; public Thickness padding { get; set; } = DefaultCellPadding; public GlyphContext glyph_context { get; private set; } From a14d449b33927e915668f7a313ef06f7add12ad7 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Fri, 9 Aug 2019 15:06:25 -0500 Subject: [PATCH 004/116] this brush needs to be frozen, because of course it does --- src/client/spark/view/Controls/DIYGrid/DIYGrid.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs b/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs index 813a9ac31..7b32426c3 100644 --- a/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs +++ b/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs @@ -247,7 +247,8 @@ namespace mbts.ui.controls { // and FrameworkElementColumns that paint the selection brush themselves // (e.g MarketView bid/ask columns, bc their background is not transparent, it covers the ListBoxItem selection-highlight). public static readonly SolidColorBrush DefaultSelectionHighlight = new SolidColorBrush(Colors.MediumSlateBlue) { Opacity = 0.4 }; - public static readonly SolidColorBrush DefaultBackgroundColor = new SolidColorBrush(BTSColors.Grid.input_cell_background) { Opacity = 0.40 }; + // I have no idea why DefaultBackgroundColor needs to be frozen but DefaultSelectionHighlight is apparently fine as is + public static readonly SolidColorBrush DefaultBackgroundColor = new SolidColorBrush(BTSColors.Grid.input_cell_background) { Opacity = 0.40 }.frozen(); public static readonly Pen DefaultSelectionStroke = new Pen(Brushes.MediumSlateBlue, 1); readonly NotifyCollectionChangedEventHandler _sort_descriptions_collection_changed_cb; double _inactive_selection_opacity = 0.2; From d6499464cf9637f8aad0ba7fdca954792ed413bb Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Mon, 12 Aug 2019 13:01:34 -0500 Subject: [PATCH 005/116] fleshing out per Column bg color override --- .../data/Proto/NullableColorOpacityProto.cs | 45 +++++++++++++++++++ .../Controls/DIYGrid/Columns/ColumnBase.cs | 6 +-- .../DIYGrid/Settings/GridColumnSettings.cs | 18 +++++--- .../DIYGrid/Settings/GridColumnSettingsVM.cs | 26 +++++++++-- .../DIYGrid/Settings/GridSettingsView.xaml | 10 +++++ .../Settings/ImmutableColumnSettingsStore.cs | 16 +++++++ .../Settings/SimpleGridColumnSettingsVM.cs | 24 +++++++++- 7 files changed, 132 insertions(+), 13 deletions(-) create mode 100644 src/client/spark/core/data/Proto/NullableColorOpacityProto.cs diff --git a/src/client/spark/core/data/Proto/NullableColorOpacityProto.cs b/src/client/spark/core/data/Proto/NullableColorOpacityProto.cs new file mode 100644 index 000000000..77344d6a3 --- /dev/null +++ b/src/client/spark/core/data/Proto/NullableColorOpacityProto.cs @@ -0,0 +1,45 @@ +using bts.utils; +using mbts.ui; +using mbts.utils; +using ProtoBuf; +using System; +using System.Windows.Media; + +namespace bts.proto { + [ProtoContract] + struct NullableColorOpacityProto : IEquatable { + [ProtoMember(1)] + readonly uint? _color; + [ProtoMember(2)] + readonly double? _opacity; + + public NullableColorOpacityProto(ColorOpacityProto? cop = default) { + _color = cop?.color.rgb_color(); + _opacity = cop?.opacity; + } + + public ColorOpacityProto? value { + get { + if (_color.HasValue && _opacity.HasValue) + return new ColorOpacityProto(_color.Value, _opacity.Value); + return null; + } + } + + public bool Equals(NullableColorOpacityProto other) => + EqualityComparer.nullable_equals(_color, other._color) && + EqualityComparer.nullable_equals(_opacity, other._opacity); + + public override bool Equals(object obj) => + obj is NullableColorProto ncp && Equals(ncp); + + public override int GetHashCode() { + uint c = _color.HasValue ? _color.Value : 0; + double o = _opacity.HasValue ? _opacity.Value : 0; + return EqualityComparer.aggregate_hash(c, o); + } + + public static bool operator ==(NullableColorOpacityProto a, NullableColorOpacityProto b) => a.Equals(b); + public static bool operator !=(NullableColorOpacityProto a, NullableColorOpacityProto b) => !a.Equals(b); + } +} \ No newline at end of file diff --git a/src/client/spark/view/Controls/DIYGrid/Columns/ColumnBase.cs b/src/client/spark/view/Controls/DIYGrid/Columns/ColumnBase.cs index 6de340375..6bbaabe2c 100644 --- a/src/client/spark/view/Controls/DIYGrid/Columns/ColumnBase.cs +++ b/src/client/spark/view/Controls/DIYGrid/Columns/ColumnBase.cs @@ -231,7 +231,7 @@ namespace mbts.ui.controls { } public GridColumnSettings create() => - new GridColumnSettings(id, _header_copy?.ToString(), is_visible, is_collapsed, font_weight_override, font_color_override, ActualWidth, horizontal_alignment, horizontal_offset); + new GridColumnSettings(id, _header_copy?.ToString(), is_visible, is_collapsed, font_weight_override, font_color_override, ActualWidth, horizontal_alignment, horizontal_offset, background_color_override); void _set_font_param(ref T field, T value) { field = value; @@ -242,7 +242,7 @@ namespace mbts.ui.controls { if (settings == null) return; using (ReflectionHelper.detect_property_changes(this, _raise_prop_changed, nameof(is_visible), nameof(is_collapsed), nameof(font_weight_override), nameof(font_weight), - nameof(font_color_override), nameof(font_color), nameof(font_brush), nameof(font_family), nameof(font_size), nameof(horizontal_alignment), nameof(horizontal_offset), nameof(background_color), nameof(background_brush), nameof(background_color_override))) { + nameof(font_color_override), nameof(font_color), nameof(font_brush), nameof(font_family), nameof(font_size), nameof(horizontal_alignment), nameof(horizontal_offset), nameof(background_color_override), nameof(background_color), nameof(background_brush))) { // id = settings.id; if (!string.IsNullOrEmpty(settings.display_name)) @@ -253,7 +253,7 @@ namespace mbts.ui.controls { font_color_override = settings.font_color_override; horizontal_alignment = settings.horizontal_alignment; horizontal_offset = settings.horizontal_offset; - //background_color_override = settings.background_color_override; + background_color_override = settings.background_color_override; } if (original_width != settings.width) { original_width = settings.width; diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/GridColumnSettings.cs b/src/client/spark/view/Controls/DIYGrid/Settings/GridColumnSettings.cs index cce3f9388..73650567a 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/GridColumnSettings.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/GridColumnSettings.cs @@ -60,6 +60,9 @@ namespace mbts.ui.settings { [DefaultValue(_default_horizontal_offset)] readonly double _horizontal_offset; + [ProtoMember(10)] + readonly NullableColorOpacityProto _background_color_override; + public GridColumnSettings() { _is_visible = _default_is_visible; _is_collapsed = _default_is_collapsed; @@ -69,7 +72,7 @@ namespace mbts.ui.settings { } public GridColumnSettings(string id, string display_name = null, bool is_visible = _default_is_visible, bool is_collapsed = _default_is_collapsed, FontWeight? font_weight_override = null, Color? font_color_override = null, - double width = _default_width, HorizontalAlignment horizontal_alignment = _default_horizontal_alignment, double horizontal_offset = _default_horizontal_offset) { + double width = _default_width, HorizontalAlignment horizontal_alignment = _default_horizontal_alignment, double horizontal_offset = _default_horizontal_offset, ColorOpacityProto? background_color_override = null) { _id = id; _display_name = display_name; _is_visible = is_visible; @@ -79,6 +82,7 @@ namespace mbts.ui.settings { _width = width; _horizontal_alignment = horizontal_alignment; _horizontal_offset = horizontal_offset; + _background_color_override = new NullableColorOpacityProto(background_color_override); } public string id => _id; @@ -90,10 +94,11 @@ namespace mbts.ui.settings { public HorizontalAlignment horizontal_alignment => _horizontal_alignment; public double horizontal_offset => _horizontal_offset; public string display_name => _display_name; + public ColorOpacityProto? background_color_override => _background_color_override.value; public GridColumnSettings with( string display_name = null, bool? is_visible = null, bool? is_collapsed = null, NullableFontWeightProto? font_weight_override = null, NullableColorProto? font_color_override = null, - double? width = null, HorizontalAlignment? horizontal_alignment = null, double? horizontal_offset = null) => + double? width = null, HorizontalAlignment? horizontal_alignment = null, double? horizontal_offset = null, NullableColorOpacityProto? background_color_override = null) => // new GridColumnSettings(_id, display_name ?? this.display_name, @@ -103,7 +108,8 @@ namespace mbts.ui.settings { (font_color_override ?? _font_color_override).value, width ?? this.width, horizontal_alignment ?? this.horizontal_alignment, - horizontal_offset ?? this.horizontal_offset); + horizontal_offset ?? this.horizontal_offset, + (background_color_override ?? _background_color_override).value); public bool Equals(GridColumnSettings other) => other != null && @@ -116,7 +122,8 @@ namespace mbts.ui.settings { width == other.width && horizontal_alignment == other.horizontal_alignment && horizontal_offset == other.horizontal_offset && - display_name == other.display_name; + display_name == other.display_name && + background_color_override.Equals(other.background_color_override); public override bool Equals(object obj) => Equals(obj as GridColumnSettings); @@ -132,7 +139,8 @@ namespace mbts.ui.settings { width.GetHashCode(), horizontal_alignment.GetHashCode(), horizontal_offset.GetHashCode(), - display_name.GetHashCode() + display_name.GetHashCode(), + background_color_override.GetHashCode() ); public override string ToString() { diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/GridColumnSettingsVM.cs b/src/client/spark/view/Controls/DIYGrid/Settings/GridColumnSettingsVM.cs index c8aac5300..521924964 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/GridColumnSettingsVM.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/GridColumnSettingsVM.cs @@ -26,7 +26,8 @@ namespace mbts.spark { None = 0, ImmutableFontColor = 1, ImmutableFontWeight = 1 << 1, - ImmutableHeader = 1 << 2 + ImmutableHeader = 1 << 2, + ImmutableBackgroundColor = 1 << 3 } partial class GridSettingsVM { @@ -50,7 +51,9 @@ namespace mbts.spark { _can_override_font_color = true, _is_font_color_overridden, _can_override_font_weight = true, - _is_font_weight_overridden; + _is_font_weight_overridden, + _can_override_background_color = true, + _is_background_color_overridden; FontWeight _font_weight_override; GridColumnSettings _settings; @@ -78,6 +81,10 @@ namespace mbts.spark { public bool can_override_font_weight { get => _can_override_font_weight; private set => Set(ref _can_override_font_weight, value); } public bool is_font_weight_overridden { get => _is_font_weight_overridden; set => Set(ref _is_font_weight_overridden, value); } public FontWeight font_weight_override { get => _font_weight_override; set => Set(ref _font_weight_override, value); } + // background color override + public bool can_override_background_color { get => _can_override_background_color; private set => Set(ref _can_override_background_color, value); } + public bool is_background_color_overridden { get => _is_background_color_overridden; set => Set(ref _is_background_color_overridden, value); } + public ColorPickerPopupVM background_color_override { get; } = new ColorPickerPopupVM(); // animations public ObservableEditableCollection predicate_animations { get; } @@ -89,7 +96,10 @@ namespace mbts.spark { is_font_weight_overridden ? new NullableFontWeightProto(font_weight_override) : default, is_font_color_overridden ? new NullableColorProto(font_color_override.color) : default, width, - horizontal_alignment); + horizontal_alignment, + background_color_override: is_background_color_overridden ? + new NullableColorOpacityProto(new ColorOpacityProto(background_color_override.color, background_color_override.opacity)) + : default); var animations_lookup = predicate_animations.ToFlatLookup(pa => pa.predicate.create_assigned(owner._predicate_data_factory), pa => pa.animations.Select(a => a.create())); return (settings, animations_lookup); } @@ -111,6 +121,13 @@ namespace mbts.spark { if (is_font_weight_overridden) { _font_weight_override = _settings.font_weight_override.Value; } + // background color + is_background_color_overridden = _settings.background_color_override.HasValue; + if (is_background_color_overridden) { + background_color_override.load_from( + new SolidColorBrush(_settings.background_color_override.Value.color) { + Opacity = _settings.background_color_override.Value.opacity }); + } predicate_animations.SetItems(value.animations.empty_if_null().Select(g => { var vm = new PredicateCellAnimationVM(id, owner._create_column_predicate_vm(id), owner._predicate_data_factory); vm.load_from((g.Key, g)); @@ -129,6 +146,9 @@ namespace mbts.spark { // font weight can_override_font_weight = (flags & GridColumnSettingsFeatureFlags.ImmutableFontWeight) == 0; is_font_weight_overridden &= can_override_font_weight; + // background color + can_override_background_color = (flags & GridColumnSettingsFeatureFlags.ImmutableBackgroundColor) == 0; + is_background_color_overridden &= can_override_background_color; } public override string ToString() => $"{display_name} ({id})"; diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsView.xaml b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsView.xaml index a9dd99c68..e525965b0 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsView.xaml +++ b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsView.xaml @@ -642,6 +642,8 @@ + + @@ -672,6 +674,14 @@ Visibility="{Binding DataContext.current_column.is_font_color_overridden, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource AncestorType=usp:GridSettingsView}}" /> + Override Background Color + + diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/ImmutableColumnSettingsStore.cs b/src/client/spark/view/Controls/DIYGrid/Settings/ImmutableColumnSettingsStore.cs index 4ab50812d..01503387f 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/ImmutableColumnSettingsStore.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/ImmutableColumnSettingsStore.cs @@ -21,6 +21,9 @@ namespace mbts.ui { if ((flags & GridColumnSettingsFeatureFlags.ImmutableFontWeight) != 0) { stores_per_flag.Add(new ImmutableFontWeightOverrideStore()); } + if ((flags & GridColumnSettingsFeatureFlags.ImmutableBackgroundColor) != 0) { + stores_per_flag.Add(new ImmutableBackgroundColorOverrideStore()); + } return new CompositeImmutableSettingsStore(stores_per_flag, flags); } @@ -66,6 +69,19 @@ namespace mbts.ui { _value = new NullableFontWeightProto(settings.font_weight_override); } + class ImmutableBackgroundColorOverrideStore : ImmutableColumnSettingStore { + NullableColorOpacityProto _value; + + public ImmutableBackgroundColorOverrideStore() + : base(GridColumnSettingsFeatureFlags.ImmutableBackgroundColor) { } + + public override GridColumnSettings apply(GridColumnSettings settings) => + settings.with(background_color_override: _value); + + public override void store(GridColumnSettings settings) => + _value = new NullableColorOpacityProto(settings.background_color_override); + } + class CompositeImmutableSettingsStore : ImmutableColumnSettingStore { readonly IReadOnlyList _stores; public CompositeImmutableSettingsStore(IReadOnlyList stores, GridColumnSettingsFeatureFlags flags) diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridColumnSettingsVM.cs b/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridColumnSettingsVM.cs index 407f5b2d4..d4dc86c50 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridColumnSettingsVM.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridColumnSettingsVM.cs @@ -21,7 +21,9 @@ namespace mbts.spark { _can_override_font_color = true, _is_font_color_overridden, _can_override_font_weight = true, - _is_font_weight_overridden; + _is_font_weight_overridden, + _can_override_background_color = true, + _is_background_color_overridden; FontWeight _font_weight_override; GridColumnSettings _settings; @@ -43,6 +45,10 @@ namespace mbts.spark { public bool can_override_font_weight { get => _can_override_font_weight; private set => Set(ref _can_override_font_weight, value); } public bool is_font_weight_overridden { get => _is_font_weight_overridden; set => Set(ref _is_font_weight_overridden, value); } public FontWeight font_weight_override { get => _font_weight_override; set => Set(ref _font_weight_override, value); } + // background color override + public bool can_override_background_color { get => _can_override_background_color; private set => Set(ref _can_override_background_color, value); } + public bool is_background_color_overridden { get => _is_background_color_overridden; set => Set(ref _is_background_color_overridden, value); } + public ColorPickerPopupVM background_color_override { get; } = new ColorPickerPopupVM(); public GridColumnSettings create() => _settings.with( @@ -52,7 +58,10 @@ namespace mbts.spark { is_font_weight_overridden ? new NullableFontWeightProto(font_weight_override) : (NullableFontWeightProto?)null, is_font_color_overridden ? new NullableColorProto(font_color_override.color) : (NullableColorProto?)null, width, - horizontal_alignment); + horizontal_alignment, + background_color_override: is_background_color_overridden ? + new NullableColorOpacityProto(new ColorOpacityProto(background_color_override.color, background_color_override.opacity)) + : default); public void load_from(GridColumnSettings value) { _settings = value; @@ -71,6 +80,14 @@ namespace mbts.spark { if (is_font_weight_overridden) { _font_weight_override = _settings.font_weight_override.Value; } + // background color + is_background_color_overridden = _settings.background_color_override.HasValue; + if (is_background_color_overridden) { + background_color_override.load_from( + new SolidColorBrush(_settings.background_color_override.Value.color) { + Opacity = _settings.background_color_override.Value.opacity + }); + } } public void apply_flags(GridColumnSettingsFeatureFlags flags) { @@ -84,6 +101,9 @@ namespace mbts.spark { // font weight can_override_font_weight = (flags & GridColumnSettingsFeatureFlags.ImmutableFontWeight) == 0; is_font_weight_overridden &= can_override_font_weight; + // background color + can_override_background_color = (flags & GridColumnSettingsFeatureFlags.ImmutableBackgroundColor) == 0; + is_background_color_overridden &= can_override_background_color; } public override string ToString() => $"{display_name} ({id})"; From 7aaae817ac3b66f6bf27bfd0cbe4525c753c6684 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Mon, 12 Aug 2019 13:02:48 -0500 Subject: [PATCH 006/116] higher level changes as a result of previous checkin --- .../Modules/Market/MarketView/MarketViewVM.cs | 15 ++++++++------- .../Market/MarketView/MarketViewWindowFactory.cs | 5 +++-- .../FrameworkElementColumns/HyperlinkColumn.cs | 5 +++-- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs b/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs index 73581518c..6b79b98fd 100644 --- a/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs +++ b/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs @@ -1,5 +1,6 @@ using bts.api; using bts.collections; +using bts.proto; using bts.utils; using mbts.persist; using mbts.spark.filters; @@ -46,8 +47,8 @@ namespace mbts.spark { add_col(Columns.BidImpliedSize, implied_size_col_header, r => r.bid_implied_size.ToString(), nameof(Row.bid_implied_size), DefaultColumnWidths.ImpliedDirectMergedSize, bid_implied_size_filter, DataGridFilterKnownTemplates.UIntMinMax, font_color: BTSColors.MarketData.bid, h_alignment: System.Windows.HorizontalAlignment.Right); add_col(Columns.BidDirectSize, direct_size_col_header, r => r.bid_direct_size.ToString(), nameof(Row.bid_direct_size), DefaultColumnWidths.ImpliedDirectMergedSize, bid_direct_size_filter, DataGridFilterKnownTemplates.UIntMinMax, font_color: BTSColors.MarketData.bid, h_alignment: System.Windows.HorizontalAlignment.Right); add_hl_merged_size_col(Columns.BidMergedSize, merged_size_col_header, nameof(Row.bid_merged_size), nameof(Row.bid_merged_size_text), nameof(Row.bid_merged_size_click), bid_merged_size_filter, BTSColors.MarketData.bid, h_alignment: System.Windows.HorizontalAlignment.Right); - add_hl_price_col(Columns.Bid, "Bid", nameof(Row.bid_price), nameof(Row.bid_price_click), bid_price_filter, BTSColors.header_text, BTSColors.MarketData.bid_brush, h_alignment: System.Windows.HorizontalAlignment.Right); - add_hl_price_col(Columns.Ask, "Ask", nameof(Row.ask_price), nameof(Row.ask_price_click), ask_price_filter, BTSColors.header_text, BTSColors.MarketData.ask_brush, h_alignment: System.Windows.HorizontalAlignment.Right); + add_hl_price_col(Columns.Bid, "Bid", nameof(Row.bid_price), nameof(Row.bid_price_click), bid_price_filter, BTSColors.header_text, new ColorOpacityProto(BTSColors.MarketData.bid.ToUint()), h_alignment: System.Windows.HorizontalAlignment.Right); + add_hl_price_col(Columns.Ask, "Ask", nameof(Row.ask_price), nameof(Row.ask_price_click), ask_price_filter, BTSColors.header_text, new ColorOpacityProto(BTSColors.MarketData.ask.ToUint()), h_alignment: System.Windows.HorizontalAlignment.Right); add_hl_merged_size_col(Columns.AskMergedSize, merged_size_col_header, nameof(Row.ask_merged_size), nameof(Row.ask_merged_size_text), nameof(Row.ask_merged_size_click), ask_merged_size_filter, BTSColors.MarketData.ask, h_alignment: System.Windows.HorizontalAlignment.Right); add_col(Columns.AskDirectSize, direct_size_col_header, r => r.ask_direct_size.ToString(), nameof(Row.ask_direct_size), DefaultColumnWidths.ImpliedDirectMergedSize, ask_direct_size_filter, DataGridFilterKnownTemplates.UIntMinMax, font_color: BTSColors.MarketData.ask, h_alignment: System.Windows.HorizontalAlignment.Right); add_col(Columns.AskImpliedSize, implied_size_col_header, r => r.ask_implied_size.ToString(), nameof(Row.ask_implied_size), DefaultColumnWidths.ImpliedDirectMergedSize, ask_implied_size_filter, DataGridFilterKnownTemplates.UIntMinMax, font_color: BTSColors.MarketData.ask, h_alignment: System.Windows.HorizontalAlignment.Right); @@ -77,7 +78,7 @@ namespace mbts.spark { horizontal_alignment = h_alignment }); - void add_hl_price_col(Columns col_key, string header, string prop, string command_prop, IDataGridColumnFilter filter, Color foreground, Brush background, System.Windows.HorizontalAlignment h_alignment) => + void add_hl_price_col(Columns col_key, string header, string prop, string command_prop, IDataGridColumnFilter filter, Color foreground, ColorOpacityProto? background, System.Windows.HorizontalAlignment h_alignment) => add_hl_col(col_key, header, price_binding(prop), prop, command_prop, filter, DataGridFilterKnownTemplates.DoubleMinMax, DefaultColumnWidths.MViewPrice, foreground, background, DefaultSelectionHighlight, h_alignment); void add_hl_merged_size_col(Columns col_key, string header, string sort_prop, string text_prop, string command_prop, IDataGridColumnFilter filter, Color foreground, System.Windows.HorizontalAlignment h_alignment) => @@ -88,7 +89,7 @@ namespace mbts.spark { void add_hl_col( Columns col_key, string header, BindingBase binding, string prop, string command_prop, - IDataGridColumnFilter filter, string filter_template, double width, Color foreground, Brush background, Brush background_overlay, System.Windows.HorizontalAlignment h_alignment = System.Windows.HorizontalAlignment.Left) => + IDataGridColumnFilter filter, string filter_template, double width, Color foreground, ColorOpacityProto? background, Brush background_overlay, System.Windows.HorizontalAlignment h_alignment = System.Windows.HorizontalAlignment.Left) => columns.Add(new HyperlinkElementColumn( col_key, binding, new Binding(command_prop), filter, filter_template) { // it's necessary to have this id populated for grid settings @@ -96,7 +97,7 @@ namespace mbts.spark { Header = header, sort_member_path = prop, font_color_override = foreground, - background = background, + background_color_override = background, background_overlay = background_overlay, Width = DefaultColumnWidths.Price, horizontal_alignment = h_alignment @@ -111,8 +112,8 @@ namespace mbts.spark { // // make font-color immutable for Side, Size, (the font-color rule is hard-coded: MarketData.bid for Buy orders, MarketData.ask for Sells) var col_settings_flags = new Dictionary { - { Columns.Bid.ToString(), GridColumnSettingsFeatureFlags.ImmutableFontColor }, - { Columns.Ask.ToString(), GridColumnSettingsFeatureFlags.ImmutableFontColor }, + { Columns.Bid.ToString(), GridColumnSettingsFeatureFlags.ImmutableFontColor | GridColumnSettingsFeatureFlags.ImmutableBackgroundColor }, + { Columns.Ask.ToString(), GridColumnSettingsFeatureFlags.ImmutableFontColor | GridColumnSettingsFeatureFlags.ImmutableBackgroundColor}, { Columns.BidImpliedSize.ToString(), GridColumnSettingsFeatureFlags.ImmutableFontColor }, { Columns.BidDirectSize.ToString(), GridColumnSettingsFeatureFlags.ImmutableFontColor }, { Columns.BidMergedSize.ToString(), GridColumnSettingsFeatureFlags.ImmutableFontColor }, diff --git a/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs b/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs index 38931a3eb..a400f4cb8 100644 --- a/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs +++ b/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs @@ -1,4 +1,5 @@ using bts.api; +using bts.proto; using mbts.persist; using mbts.spark; using mbts.spark.filters; @@ -86,8 +87,8 @@ namespace bts.shell { public static GridColumnSettings bid_implied_size => new GridColumnSettings(col_id(Columns.BidImpliedSize), DefaultColumnHeaders.ImpliedSize, font_color_override: BTSColors.MarketData.bid, width: DefaultColumnWidths.ImpliedDirectMergedSize, horizontal_alignment: System.Windows.HorizontalAlignment.Right); public static GridColumnSettings bid_direct_size => new GridColumnSettings(col_id(Columns.BidDirectSize), DefaultColumnHeaders.DirectSize, font_color_override: BTSColors.MarketData.bid, width: DefaultColumnWidths.ImpliedDirectMergedSize, horizontal_alignment: System.Windows.HorizontalAlignment.Right); public static GridColumnSettings bid_merged_size => new GridColumnSettings(col_id(Columns.BidMergedSize), DefaultColumnHeaders.MergedSize, font_color_override: BTSColors.MarketData.bid, width: DefaultColumnWidths.ImpliedDirectMergedSize, horizontal_alignment: System.Windows.HorizontalAlignment.Right); - public static GridColumnSettings bid => new GridColumnSettings(col_id(Columns.Bid), DefaultColumnHeaders.Bid, font_color_override: BTSColors.header_text, width:DefaultColumnWidths.MViewPrice, horizontal_alignment: System.Windows.HorizontalAlignment.Right); - public static GridColumnSettings ask => new GridColumnSettings(col_id(Columns.Ask), DefaultColumnHeaders.Ask, font_color_override: BTSColors.header_text, width: DefaultColumnWidths.MViewPrice, horizontal_alignment: System.Windows.HorizontalAlignment.Right); + public static GridColumnSettings bid => new GridColumnSettings(col_id(Columns.Bid), DefaultColumnHeaders.Bid, font_color_override: BTSColors.header_text, width:DefaultColumnWidths.MViewPrice, horizontal_alignment: System.Windows.HorizontalAlignment.Right, background_color_override: new ColorOpacityProto(BTSColors.MarketData.bid.ToUint())); + public static GridColumnSettings ask => new GridColumnSettings(col_id(Columns.Ask), DefaultColumnHeaders.Ask, font_color_override: BTSColors.header_text, width: DefaultColumnWidths.MViewPrice, horizontal_alignment: System.Windows.HorizontalAlignment.Right, background_color_override: new ColorOpacityProto(BTSColors.MarketData.ask.ToUint())); public static GridColumnSettings ask_merged_size => new GridColumnSettings(col_id(Columns.AskMergedSize), DefaultColumnHeaders.MergedSize, font_color_override: BTSColors.MarketData.ask, width: DefaultColumnWidths.ImpliedDirectMergedSize, horizontal_alignment: System.Windows.HorizontalAlignment.Right); public static GridColumnSettings ask_direct_size => new GridColumnSettings(col_id(Columns.AskDirectSize), DefaultColumnHeaders.DirectSize, font_color_override: BTSColors.MarketData.ask, width: DefaultColumnWidths.ImpliedDirectMergedSize, horizontal_alignment: System.Windows.HorizontalAlignment.Right); public static GridColumnSettings ask_implied_size => new GridColumnSettings(col_id(Columns.AskImpliedSize), DefaultColumnHeaders.ImpliedSize, font_color_override: BTSColors.MarketData.ask, width: DefaultColumnWidths.ImpliedDirectMergedSize, horizontal_alignment: System.Windows.HorizontalAlignment.Right); diff --git a/src/client/spark/view/Controls/DIYGrid/Columns/FrameworkElementColumns/HyperlinkColumn.cs b/src/client/spark/view/Controls/DIYGrid/Columns/FrameworkElementColumns/HyperlinkColumn.cs index 258740e29..11750f370 100644 --- a/src/client/spark/view/Controls/DIYGrid/Columns/FrameworkElementColumns/HyperlinkColumn.cs +++ b/src/client/spark/view/Controls/DIYGrid/Columns/FrameworkElementColumns/HyperlinkColumn.cs @@ -22,20 +22,21 @@ namespace mbts.ui.controls { public IDataGridColumnFilter filter { get; } public string filter_template { get; } public Thickness padding { get; set; } = _default_padding; - public Brush background { get; set; } + public Brush background_overlay { get; set; } = DefaultSelectionHighlight; public void on_selection_fill(Brush selection_fill) => background_overlay = selection_fill; public override FrameworkElement view_factory() { - var hl = new HyperlinkCell { Foreground = font_brush, Background = background, Padding = padding }; + var hl = new HyperlinkCell { Foreground = font_brush, Padding = padding }; hl.SetBinding(HyperlinkCell.TextProperty, _binding); hl.SetBinding(HyperlinkCell.FontFamilyProperty, new Binding(nameof(font_family)) { Source = this }); hl.SetBinding(HyperlinkCell.FontSizeProperty, new Binding(nameof(font_size)) { Source = this }); hl.SetBinding(HyperlinkCell.HorizontalAlignmentProperty, new Binding(nameof(horizontal_alignment)) { Source = this }); hl.SetBinding(HyperlinkCell.CommandProperty, _command_binding); hl.SetBinding(HyperlinkCell.WidthProperty, new Binding(nameof(ActualWidth)) { Source = this }); + hl.SetBinding(HyperlinkCell.BackgroundProperty, new Binding(nameof(background_brush)) { Source = this }); if (background_overlay != null) { hl.SetBinding(BackgroundOverlayProperty, new Binding(nameof(ListBoxItem.IsSelected)) { Converter = new AnonymousValueConverter(val => val ? background_overlay : null), From 540559de3e73e0abc516740478f1ca4bf2713c26 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Mon, 12 Aug 2019 16:38:15 -0500 Subject: [PATCH 007/116] Adding sanitization routine for MarketViewWindowFactory --- .../MarketView/MarketViewWindowFactory.cs | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs b/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs index a400f4cb8..6c846e15c 100644 --- a/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs +++ b/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs @@ -39,7 +39,7 @@ namespace bts.shell { IShellWindow _create(StartupData state) { var settings_manager = new WindowSettingsManager(_settings_hub, state.grid, - get: us => us.market_view_grid, + get: us => StartupData.sanitize(us.market_view_grid), set: (us, gs) => us.with(provided_market_view_gridsettings: gs)); return new MarketViewWindow(this, _bus, _orders_model, state, settings_manager); } @@ -69,6 +69,26 @@ namespace bts.shell { _sorting_criteria = sort; } + public static GridSettings sanitize(GridSettings s) { + if (s == null) { + return null; + } + + var columns = s.columns.ToList(); + var bid_col_index = columns.FindIndex(x => x.id == col_id(Columns.Bid)); + var ask_col_index = columns.FindIndex(x => x.id == col_id(Columns.Ask)); + if (bid_col_index > -1 && ask_col_index > -1) { + if (!columns[bid_col_index].background_color_override.HasValue) { + columns[bid_col_index] = columns[bid_col_index].with(background_color_override: new NullableColorOpacityProto(new ColorOpacityProto(BTSColors.MarketData.bid.ToUint()))); + } + if (!columns[ask_col_index].background_color_override.HasValue) { + columns[ask_col_index] = columns[ask_col_index].with(background_color_override: new NullableColorOpacityProto(new ColorOpacityProto(BTSColors.MarketData.ask.ToUint()))); + } + } + return s.with(columns); + } + + public static GridSettings DefaultGridSettings => GridSettings.Default.with(DefaultColumns.all, DefaultColumns.default_sorting_criterion); public IReadOnlyList sorting_criterion => _sorting_criteria ?? (_sorting_criteria = DefaultColumns.default_sorting_criterion.ToList()); From decdae424d65af7cefd30c52129d6e7ae8b10c04 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Wed, 14 Aug 2019 09:22:02 -0500 Subject: [PATCH 008/116] new Adorner to convey row selection --- .../Controls/Adorners/RowSelectionAdorner.cs | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 src/client/spark/view/Controls/Adorners/RowSelectionAdorner.cs diff --git a/src/client/spark/view/Controls/Adorners/RowSelectionAdorner.cs b/src/client/spark/view/Controls/Adorners/RowSelectionAdorner.cs new file mode 100644 index 000000000..aa9daf6df --- /dev/null +++ b/src/client/spark/view/Controls/Adorners/RowSelectionAdorner.cs @@ -0,0 +1,93 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using bts.utils; +using mbts.ui.extensions; + +namespace mbts.ui.controls.adorners { + public class RowSelectionAdorner : Adorner, DIYGrid.ISelectionHighlightListener { + Brush _fill = DIYGrid.DefaultSelectionHighlight; + Pen _stroke = DIYGrid.DefaultSelectionStroke; + + DIYGridRowsPresenter _diy_rp; + ScrollViewer _diy_scroll; + ScrollContentPresenter _diy_scp; + + #region Fill + public static readonly DependencyProperty FillProperty = + WPFHelper.create_dp( + nameof(Fill), + FrameworkPropertyMetadataOptions.AffectsRender, + (o, v) => o._fill = v, + DIYGrid.DefaultSelectionHighlight); + + public SolidColorBrush Fill { + get => GetValue(FillProperty) as SolidColorBrush; + set => SetValue(FillProperty, value); + } + #endregion + #region Stroke + public static readonly DependencyProperty StrokeProperty = + WPFHelper.create_dp( + nameof(Stroke), + FrameworkPropertyMetadataOptions.AffectsRender, + (o, v) => o._stroke = v, + DIYGrid.DefaultSelectionStroke); + + public Pen Stroke { + get => GetValue(StrokeProperty) as Pen; + set => SetValue(StrokeProperty, value); + } + #endregion + + public RowSelectionAdorner(FrameworkElement adorned_element, ScrollViewer scroll_viewer) : base(adorned_element) { + // we want our clicks to go through to the underlying grid + IsHitTestVisible = false; + + _diy_rp = (DIYGridRowsPresenter)adorned_element; + _diy_scroll = scroll_viewer; + _diy_scp = _diy_rp.descendants_of_type().empty_if_null().FirstOrDefault(); + + // so that we clear out any previously selected highlighted rows + _diy_rp.SubscribePreviewMouseDown((s, e) => InvalidateVisual()); + // the main event + _diy_rp.SubscribePreviewMouseUp((s, e) => InvalidateVisual()); + // so that we update the highlight as the grid scrolls + _diy_scroll.SubscribeScrollChanged((s, e) => InvalidateVisual()); + } + + + protected override void OnRender(DrawingContext drawingContext) { + base.OnRender(drawingContext); + if (AdornedElement is ListBox lb && lb.SelectedItems != null && lb.SelectedItems.Count > 0) { + foreach(var lbi in lb.SelectedItems) { + if (_diy_rp.ItemContainerGenerator.ContainerFromItem(lbi) is FrameworkElement row && row.IsVisible) { + var top_left = lb.GetChildTopLeft(row); + var top_is_within_bounds = top_left.Y >= 0; + + // Note that the top of the row can still technically be visible but we wont show + // the adorner rectangle b/c the bottom of the row will be obscured by the scrollbar + var bottom_is_within_bounds = lb.GetChildBounds(row).BottomRight.Y <= _diy_scroll.ActualHeight; + if (top_is_within_bounds && bottom_is_within_bounds) { + drawingContext.DrawRectangle(_fill, + _stroke, + new Rect(top_left, new Point(top_left.X + row.ActualWidth, top_left.Y + row.ActualHeight))); + } + } + } + } + } + + public void on_selection_fill(Brush selection_fill) { + var selection_brush = (SolidColorBrush)selection_fill; + Fill = selection_brush; + Stroke = new Pen(selection_brush.Color.to_solid_brush(), 1); + InvalidateVisual(); + } + } +} \ No newline at end of file From 5ac8a46a6c19969f0a7de5d36f0a5db4d6481ef5 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Wed, 14 Aug 2019 09:22:49 -0500 Subject: [PATCH 009/116] DIYGrid makes use of new RowSelectionAdorner --- src/client/spark/view/Controls/DIYGrid/DIYGrid.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs b/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs index 7b32426c3..cfdf18b0d 100644 --- a/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs +++ b/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs @@ -126,6 +126,7 @@ namespace mbts.ui.controls { double _row_height = DIYGrid.DefaultRowHeight; DIYGrid _grid; DragRectAdorner _drag_rect_adorner; + RowSelectionAdorner _rsa; ScrollViewer _scroll_viewer; Point? _drag_start; double _drag_start_vertical_drift; @@ -148,12 +149,17 @@ namespace mbts.ui.controls { _drag_rect_adorner.SetResourceReference(DragRectAdorner.StrokeProperty, DIYGrid.SelectionStrokeKey); _drag_rect_adorner.attach(); } + _rsa = new RowSelectionAdorner(this, _scroll_viewer); + _rsa.attach(); }; Unloaded += (s, e) => { if (_drag_rect_adorner != null) { _drag_rect_adorner.detach(); Disposable.dispose(ref _drag_rect_adorner); } + if (_rsa != null) { + _rsa.detach(); + } }; void on_row_height_changed(double v) => _row_height = v; } @@ -263,6 +269,12 @@ namespace mbts.ui.controls { 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); + var ad_layer = System.Windows.Documents.AdornerLayer.GetAdornerLayer(o); + if (ad_layer != null) { + foreach (var ad in ad_layer.descendants_of_type()) { + ad.on_selection_fill(v); + } + } }, (o, v) => v as SolidColorBrush ?? DefaultSelectionHighlight, DefaultSelectionHighlight); From 910cf204734acec77cbf5e35f61f1b635e2bbe18 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Wed, 14 Aug 2019 10:05:46 -0500 Subject: [PATCH 010/116] sanitize existing persisted grid state --- .../Modules/Market/MarketView/MarketViewWindowFactory.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs b/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs index 6c846e15c..4e5edbf55 100644 --- a/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs +++ b/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs @@ -37,8 +37,8 @@ namespace bts.shell { _bus.post(SparkTags.ShowWindow, _create(StartupData.Default(criteria))); IShellWindow _create(StartupData state) { - var settings_manager = new WindowSettingsManager(_settings_hub, - state.grid, + var settings_manager = new WindowSettingsManager(_settings_hub, + StartupData.sanitize(state.grid), get: us => StartupData.sanitize(us.market_view_grid), set: (us, gs) => us.with(provided_market_view_gridsettings: gs)); return new MarketViewWindow(this, _bus, _orders_model, state, settings_manager); From b292f50d99a9a86329b8bc8172c7b5e34cf40b2d Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Wed, 14 Aug 2019 10:16:48 -0500 Subject: [PATCH 011/116] Removing Background selection/active highlighting from DIYGridRowStyle --- .../view/Controls/DIYGrid/DIYGridResources.xaml | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/client/spark/view/Controls/DIYGrid/DIYGridResources.xaml b/src/client/spark/view/Controls/DIYGrid/DIYGridResources.xaml index d066fbb96..45a875517 100644 --- a/src/client/spark/view/Controls/DIYGrid/DIYGridResources.xaml +++ b/src/client/spark/view/Controls/DIYGrid/DIYGridResources.xaml @@ -29,22 +29,6 @@ VerticalAlignment="{TemplateBinding VerticalContentAlignment}" /> - - - - - - - - - - - - - - - - From dd9ca350af64180550172632af40ffbb201ccc22 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Wed, 14 Aug 2019 10:51:06 -0500 Subject: [PATCH 012/116] RowSelectionAdorner bounds check should use ScrollContentPresenter for X point --- .../spark/view/Controls/Adorners/RowSelectionAdorner.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/client/spark/view/Controls/Adorners/RowSelectionAdorner.cs b/src/client/spark/view/Controls/Adorners/RowSelectionAdorner.cs index aa9daf6df..d76d7c663 100644 --- a/src/client/spark/view/Controls/Adorners/RowSelectionAdorner.cs +++ b/src/client/spark/view/Controls/Adorners/RowSelectionAdorner.cs @@ -74,9 +74,12 @@ namespace mbts.ui.controls.adorners { // the adorner rectangle b/c the bottom of the row will be obscured by the scrollbar var bottom_is_within_bounds = lb.GetChildBounds(row).BottomRight.Y <= _diy_scroll.ActualHeight; if (top_is_within_bounds && bottom_is_within_bounds) { + // we use the scroll content presenter in the X point calculation instead of the row + // because of the OB which has a right side panel that takes up some space over + // row width drawingContext.DrawRectangle(_fill, _stroke, - new Rect(top_left, new Point(top_left.X + row.ActualWidth, top_left.Y + row.ActualHeight))); + new Rect(top_left, new Point(top_left.X + _diy_scp.ActualWidth, top_left.Y + row.ActualHeight))); } } } From 3046871cf409d662a4414756e5bda8b4b749c1fd Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Wed, 14 Aug 2019 10:59:52 -0500 Subject: [PATCH 013/116] removing background_overlay property from HyperLinkColumn, et al --- .../Modules/Market/MarketView/MarketViewVM.cs | 9 ++++----- .../Controls/DIYGrid/CellRender/HyperlinkCell.cs | 5 ----- .../FrameworkElementColumns/HyperlinkColumn.cs | 14 +------------- src/client/spark/view/Controls/DIYGrid/DIYGrid.cs | 12 ------------ 4 files changed, 5 insertions(+), 35 deletions(-) diff --git a/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs b/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs index 6b79b98fd..e6673fc4e 100644 --- a/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs +++ b/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs @@ -79,17 +79,17 @@ namespace mbts.spark { }); void add_hl_price_col(Columns col_key, string header, string prop, string command_prop, IDataGridColumnFilter filter, Color foreground, ColorOpacityProto? background, System.Windows.HorizontalAlignment h_alignment) => - add_hl_col(col_key, header, price_binding(prop), prop, command_prop, filter, DataGridFilterKnownTemplates.DoubleMinMax, DefaultColumnWidths.MViewPrice, foreground, background, DefaultSelectionHighlight, h_alignment); + add_hl_col(col_key, header, price_binding(prop), prop, command_prop, filter, DataGridFilterKnownTemplates.DoubleMinMax, DefaultColumnWidths.MViewPrice, foreground, background, h_alignment); void add_hl_merged_size_col(Columns col_key, string header, string sort_prop, string text_prop, string command_prop, IDataGridColumnFilter filter, Color foreground, System.Windows.HorizontalAlignment h_alignment) => - add_hl_col(col_key, header, new Binding(text_prop), sort_prop, command_prop, filter, DataGridFilterKnownTemplates.UIntMinMax, DefaultColumnWidths.ImpliedDirectMergedSize, foreground, null, null, h_alignment); + add_hl_col(col_key, header, new Binding(text_prop), sort_prop, command_prop, filter, DataGridFilterKnownTemplates.UIntMinMax, DefaultColumnWidths.ImpliedDirectMergedSize, foreground, null, h_alignment); void add_hl_working_orders_col(Columns col_key, string header, string text_prop, string sort_prop, string command_prop, IDataGridColumnFilter filter, Color foreground, System.Windows.HorizontalAlignment h_alignment) => - add_hl_col(col_key, header, new Binding(text_prop), sort_prop, command_prop, filter, DataGridFilterKnownTemplates.IntMinMax, working_orders_col_width, foreground, null, null, h_alignment); + add_hl_col(col_key, header, new Binding(text_prop), sort_prop, command_prop, filter, DataGridFilterKnownTemplates.IntMinMax, working_orders_col_width, foreground, null, h_alignment); void add_hl_col( Columns col_key, string header, BindingBase binding, string prop, string command_prop, - IDataGridColumnFilter filter, string filter_template, double width, Color foreground, ColorOpacityProto? background, Brush background_overlay, System.Windows.HorizontalAlignment h_alignment = System.Windows.HorizontalAlignment.Left) => + IDataGridColumnFilter filter, string filter_template, double width, Color foreground, ColorOpacityProto? background, System.Windows.HorizontalAlignment h_alignment = System.Windows.HorizontalAlignment.Left) => columns.Add(new HyperlinkElementColumn( col_key, binding, new Binding(command_prop), filter, filter_template) { // it's necessary to have this id populated for grid settings @@ -98,7 +98,6 @@ namespace mbts.spark { sort_member_path = prop, font_color_override = foreground, background_color_override = background, - background_overlay = background_overlay, Width = DefaultColumnWidths.Price, horizontal_alignment = h_alignment }); diff --git a/src/client/spark/view/Controls/DIYGrid/CellRender/HyperlinkCell.cs b/src/client/spark/view/Controls/DIYGrid/CellRender/HyperlinkCell.cs index 8d9e326cb..e9e5ae634 100644 --- a/src/client/spark/view/Controls/DIYGrid/CellRender/HyperlinkCell.cs +++ b/src/client/spark/view/Controls/DIYGrid/CellRender/HyperlinkCell.cs @@ -304,11 +304,6 @@ namespace mbts.ui.controls { } drawingContext.Pop(); } - if (bg != null) { - var bgo = GetBackgroundOverlay(this); - if (bgo != null) - drawingContext.DrawRectangle(bgo, null, rect); - } } bool _point_horizontally_over_text(double x) { diff --git a/src/client/spark/view/Controls/DIYGrid/Columns/FrameworkElementColumns/HyperlinkColumn.cs b/src/client/spark/view/Controls/DIYGrid/Columns/FrameworkElementColumns/HyperlinkColumn.cs index 11750f370..efeaa83b7 100644 --- a/src/client/spark/view/Controls/DIYGrid/Columns/FrameworkElementColumns/HyperlinkColumn.cs +++ b/src/client/spark/view/Controls/DIYGrid/Columns/FrameworkElementColumns/HyperlinkColumn.cs @@ -7,7 +7,7 @@ using System.Windows.Media; namespace mbts.ui.controls { partial class DIYGrid { - internal class HyperlinkElementColumn : FrameworkElementColumnBase, IFrameworkElementColumn, IFilterableColumn, IKeyedColumn, ISelectionHighlightListener { + internal class HyperlinkElementColumn : FrameworkElementColumnBase, IFrameworkElementColumn, IFilterableColumn, IKeyedColumn { static readonly Thickness _default_padding = new Thickness(6, 0, 6, 0); readonly BindingBase _binding, _command_binding; @@ -23,11 +23,6 @@ namespace mbts.ui.controls { public string filter_template { get; } public Thickness padding { get; set; } = _default_padding; - public Brush background_overlay { get; set; } = DefaultSelectionHighlight; - - public void on_selection_fill(Brush selection_fill) => - background_overlay = selection_fill; - public override FrameworkElement view_factory() { var hl = new HyperlinkCell { Foreground = font_brush, Padding = padding }; hl.SetBinding(HyperlinkCell.TextProperty, _binding); @@ -37,13 +32,6 @@ namespace mbts.ui.controls { hl.SetBinding(HyperlinkCell.CommandProperty, _command_binding); hl.SetBinding(HyperlinkCell.WidthProperty, new Binding(nameof(ActualWidth)) { Source = this }); hl.SetBinding(HyperlinkCell.BackgroundProperty, new Binding(nameof(background_brush)) { Source = this }); - if (background_overlay != null) { - hl.SetBinding(BackgroundOverlayProperty, new Binding(nameof(ListBoxItem.IsSelected)) { - Converter = new AnonymousValueConverter(val => val ? background_overlay : null), - Mode = BindingMode.OneWay, - RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(ListBoxItem), 1) - }); - } return hl; } } diff --git a/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs b/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs index cfdf18b0d..b5687ebd0 100644 --- a/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs +++ b/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs @@ -608,18 +608,6 @@ namespace mbts.ui.controls { // Public Properties #region Public Properties - public static readonly DependencyProperty BackgroundOverlayProperty = - DependencyProperty.RegisterAttached( - "BackgroundOverlay", - typeof(Brush), - typeof(DIYGrid), - new FrameworkPropertyMetadata( - null, - FrameworkPropertyMetadataOptions.AffectsRender)); - - public static Brush GetBackgroundOverlay(DependencyObject d) => d.GetValue(BackgroundOverlayProperty) as Brush; - public static void SetBackgroundOverlay(DependencyObject d, Brush value) => d.SetValue(BackgroundOverlayProperty, value); - #region RowStyle public static readonly DependencyProperty RowStyleProperty = WPFHelper.create_dp( From 3c7dbc04892df463da118306b787c2599e06a257 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Wed, 14 Aug 2019 11:17:50 -0500 Subject: [PATCH 014/116] RowSelectionAdorner now implements IDisposable --- .../view/Controls/Adorners/RowSelectionAdorner.cs | 13 +++++++++---- src/client/spark/view/Controls/DIYGrid/DIYGrid.cs | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/client/spark/view/Controls/Adorners/RowSelectionAdorner.cs b/src/client/spark/view/Controls/Adorners/RowSelectionAdorner.cs index d76d7c663..c7625c654 100644 --- a/src/client/spark/view/Controls/Adorners/RowSelectionAdorner.cs +++ b/src/client/spark/view/Controls/Adorners/RowSelectionAdorner.cs @@ -10,13 +10,14 @@ using bts.utils; using mbts.ui.extensions; namespace mbts.ui.controls.adorners { - public class RowSelectionAdorner : Adorner, DIYGrid.ISelectionHighlightListener { + public class RowSelectionAdorner : Adorner, DIYGrid.ISelectionHighlightListener, IDisposable { Brush _fill = DIYGrid.DefaultSelectionHighlight; Pen _stroke = DIYGrid.DefaultSelectionStroke; DIYGridRowsPresenter _diy_rp; ScrollViewer _diy_scroll; ScrollContentPresenter _diy_scp; + List _disposables = new List(); #region Fill public static readonly DependencyProperty FillProperty = @@ -54,11 +55,11 @@ namespace mbts.ui.controls.adorners { _diy_scp = _diy_rp.descendants_of_type().empty_if_null().FirstOrDefault(); // so that we clear out any previously selected highlighted rows - _diy_rp.SubscribePreviewMouseDown((s, e) => InvalidateVisual()); + _disposables.Add(_diy_rp.SubscribePreviewMouseDown((s, e) => InvalidateVisual())); // the main event - _diy_rp.SubscribePreviewMouseUp((s, e) => InvalidateVisual()); + _disposables.Add(_diy_rp.SubscribePreviewMouseUp((s, e) => InvalidateVisual())); // so that we update the highlight as the grid scrolls - _diy_scroll.SubscribeScrollChanged((s, e) => InvalidateVisual()); + _disposables.Add(_diy_scroll.SubscribeScrollChanged((s, e) => InvalidateVisual())); } @@ -92,5 +93,9 @@ namespace mbts.ui.controls.adorners { Stroke = new Pen(selection_brush.Color.to_solid_brush(), 1); InvalidateVisual(); } + + public void Dispose() { + _disposables.DisposeAll(); + } } } \ No newline at end of file diff --git a/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs b/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs index b5687ebd0..c8267344d 100644 --- a/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs +++ b/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs @@ -159,6 +159,7 @@ namespace mbts.ui.controls { } if (_rsa != null) { _rsa.detach(); + Disposable.dispose(ref _rsa); } }; void on_row_height_changed(double v) => _row_height = v; From 231f596ad72dafede26096b8dd189a41a2d7b66b Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Wed, 14 Aug 2019 14:17:33 -0500 Subject: [PATCH 015/116] switching to NullableColorProto in wrap up attempt --- .../Modules/Market/MarketView/MarketViewVM.cs | 8 ++++---- .../Market/MarketView/MarketViewWindowFactory.cs | 8 ++++---- .../view/Controls/DIYGrid/Columns/ColumnBase.cs | 14 +++++++------- src/client/spark/view/Controls/DIYGrid/DIYGrid.cs | 2 +- .../DIYGrid/Settings/GridColumnSettings.cs | 10 +++++----- .../DIYGrid/Settings/GridColumnSettingsVM.cs | 8 ++++---- .../view/Controls/DIYGrid/Settings/GridSettings.cs | 14 +++++++------- .../DIYGrid/Settings/GridSettingsManager.cs | 4 ++-- .../Controls/DIYGrid/Settings/GridSettingsVM.cs | 7 +++++-- .../Settings/ImmutableColumnSettingsStore.cs | 4 ++-- .../DIYGrid/Settings/SimpleGridColumnSettingsVM.cs | 7 +++---- .../DIYGrid/Settings/SimpleGridSettingsManager.cs | 4 ++-- .../DIYGrid/Settings/SimpleGridSettingsVM.cs | 7 +++++-- 13 files changed, 51 insertions(+), 46 deletions(-) diff --git a/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs b/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs index e6673fc4e..9e67a4bb1 100644 --- a/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs +++ b/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs @@ -47,8 +47,8 @@ namespace mbts.spark { add_col(Columns.BidImpliedSize, implied_size_col_header, r => r.bid_implied_size.ToString(), nameof(Row.bid_implied_size), DefaultColumnWidths.ImpliedDirectMergedSize, bid_implied_size_filter, DataGridFilterKnownTemplates.UIntMinMax, font_color: BTSColors.MarketData.bid, h_alignment: System.Windows.HorizontalAlignment.Right); add_col(Columns.BidDirectSize, direct_size_col_header, r => r.bid_direct_size.ToString(), nameof(Row.bid_direct_size), DefaultColumnWidths.ImpliedDirectMergedSize, bid_direct_size_filter, DataGridFilterKnownTemplates.UIntMinMax, font_color: BTSColors.MarketData.bid, h_alignment: System.Windows.HorizontalAlignment.Right); add_hl_merged_size_col(Columns.BidMergedSize, merged_size_col_header, nameof(Row.bid_merged_size), nameof(Row.bid_merged_size_text), nameof(Row.bid_merged_size_click), bid_merged_size_filter, BTSColors.MarketData.bid, h_alignment: System.Windows.HorizontalAlignment.Right); - add_hl_price_col(Columns.Bid, "Bid", nameof(Row.bid_price), nameof(Row.bid_price_click), bid_price_filter, BTSColors.header_text, new ColorOpacityProto(BTSColors.MarketData.bid.ToUint()), h_alignment: System.Windows.HorizontalAlignment.Right); - add_hl_price_col(Columns.Ask, "Ask", nameof(Row.ask_price), nameof(Row.ask_price_click), ask_price_filter, BTSColors.header_text, new ColorOpacityProto(BTSColors.MarketData.ask.ToUint()), h_alignment: System.Windows.HorizontalAlignment.Right); + add_hl_price_col(Columns.Bid, "Bid", nameof(Row.bid_price), nameof(Row.bid_price_click), bid_price_filter, BTSColors.header_text, BTSColors.MarketData.bid, h_alignment: System.Windows.HorizontalAlignment.Right); + add_hl_price_col(Columns.Ask, "Ask", nameof(Row.ask_price), nameof(Row.ask_price_click), ask_price_filter, BTSColors.header_text, BTSColors.MarketData.ask, h_alignment: System.Windows.HorizontalAlignment.Right); add_hl_merged_size_col(Columns.AskMergedSize, merged_size_col_header, nameof(Row.ask_merged_size), nameof(Row.ask_merged_size_text), nameof(Row.ask_merged_size_click), ask_merged_size_filter, BTSColors.MarketData.ask, h_alignment: System.Windows.HorizontalAlignment.Right); add_col(Columns.AskDirectSize, direct_size_col_header, r => r.ask_direct_size.ToString(), nameof(Row.ask_direct_size), DefaultColumnWidths.ImpliedDirectMergedSize, ask_direct_size_filter, DataGridFilterKnownTemplates.UIntMinMax, font_color: BTSColors.MarketData.ask, h_alignment: System.Windows.HorizontalAlignment.Right); add_col(Columns.AskImpliedSize, implied_size_col_header, r => r.ask_implied_size.ToString(), nameof(Row.ask_implied_size), DefaultColumnWidths.ImpliedDirectMergedSize, ask_implied_size_filter, DataGridFilterKnownTemplates.UIntMinMax, font_color: BTSColors.MarketData.ask, h_alignment: System.Windows.HorizontalAlignment.Right); @@ -78,7 +78,7 @@ namespace mbts.spark { horizontal_alignment = h_alignment }); - void add_hl_price_col(Columns col_key, string header, string prop, string command_prop, IDataGridColumnFilter filter, Color foreground, ColorOpacityProto? background, System.Windows.HorizontalAlignment h_alignment) => + void add_hl_price_col(Columns col_key, string header, string prop, string command_prop, IDataGridColumnFilter filter, Color foreground, Color? background, System.Windows.HorizontalAlignment h_alignment) => add_hl_col(col_key, header, price_binding(prop), prop, command_prop, filter, DataGridFilterKnownTemplates.DoubleMinMax, DefaultColumnWidths.MViewPrice, foreground, background, h_alignment); void add_hl_merged_size_col(Columns col_key, string header, string sort_prop, string text_prop, string command_prop, IDataGridColumnFilter filter, Color foreground, System.Windows.HorizontalAlignment h_alignment) => @@ -89,7 +89,7 @@ namespace mbts.spark { void add_hl_col( Columns col_key, string header, BindingBase binding, string prop, string command_prop, - IDataGridColumnFilter filter, string filter_template, double width, Color foreground, ColorOpacityProto? background, System.Windows.HorizontalAlignment h_alignment = System.Windows.HorizontalAlignment.Left) => + IDataGridColumnFilter filter, string filter_template, double width, Color foreground, Color? background, System.Windows.HorizontalAlignment h_alignment = System.Windows.HorizontalAlignment.Left) => columns.Add(new HyperlinkElementColumn( col_key, binding, new Binding(command_prop), filter, filter_template) { // it's necessary to have this id populated for grid settings diff --git a/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs b/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs index 4e5edbf55..2d7b6e075 100644 --- a/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs +++ b/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs @@ -79,10 +79,10 @@ namespace bts.shell { var ask_col_index = columns.FindIndex(x => x.id == col_id(Columns.Ask)); if (bid_col_index > -1 && ask_col_index > -1) { if (!columns[bid_col_index].background_color_override.HasValue) { - columns[bid_col_index] = columns[bid_col_index].with(background_color_override: new NullableColorOpacityProto(new ColorOpacityProto(BTSColors.MarketData.bid.ToUint()))); + columns[bid_col_index] = columns[bid_col_index].with(background_color_override: new NullableColorProto(BTSColors.MarketData.bid.ToUint())); } if (!columns[ask_col_index].background_color_override.HasValue) { - columns[ask_col_index] = columns[ask_col_index].with(background_color_override: new NullableColorOpacityProto(new ColorOpacityProto(BTSColors.MarketData.ask.ToUint()))); + columns[ask_col_index] = columns[ask_col_index].with(background_color_override: new NullableColorProto(BTSColors.MarketData.ask.ToUint())); } } return s.with(columns); @@ -107,8 +107,8 @@ namespace bts.shell { public static GridColumnSettings bid_implied_size => new GridColumnSettings(col_id(Columns.BidImpliedSize), DefaultColumnHeaders.ImpliedSize, font_color_override: BTSColors.MarketData.bid, width: DefaultColumnWidths.ImpliedDirectMergedSize, horizontal_alignment: System.Windows.HorizontalAlignment.Right); public static GridColumnSettings bid_direct_size => new GridColumnSettings(col_id(Columns.BidDirectSize), DefaultColumnHeaders.DirectSize, font_color_override: BTSColors.MarketData.bid, width: DefaultColumnWidths.ImpliedDirectMergedSize, horizontal_alignment: System.Windows.HorizontalAlignment.Right); public static GridColumnSettings bid_merged_size => new GridColumnSettings(col_id(Columns.BidMergedSize), DefaultColumnHeaders.MergedSize, font_color_override: BTSColors.MarketData.bid, width: DefaultColumnWidths.ImpliedDirectMergedSize, horizontal_alignment: System.Windows.HorizontalAlignment.Right); - public static GridColumnSettings bid => new GridColumnSettings(col_id(Columns.Bid), DefaultColumnHeaders.Bid, font_color_override: BTSColors.header_text, width:DefaultColumnWidths.MViewPrice, horizontal_alignment: System.Windows.HorizontalAlignment.Right, background_color_override: new ColorOpacityProto(BTSColors.MarketData.bid.ToUint())); - public static GridColumnSettings ask => new GridColumnSettings(col_id(Columns.Ask), DefaultColumnHeaders.Ask, font_color_override: BTSColors.header_text, width: DefaultColumnWidths.MViewPrice, horizontal_alignment: System.Windows.HorizontalAlignment.Right, background_color_override: new ColorOpacityProto(BTSColors.MarketData.ask.ToUint())); + public static GridColumnSettings bid => new GridColumnSettings(col_id(Columns.Bid), DefaultColumnHeaders.Bid, font_color_override: BTSColors.header_text, width:DefaultColumnWidths.MViewPrice, horizontal_alignment: System.Windows.HorizontalAlignment.Right, background_color_override: BTSColors.MarketData.bid); + public static GridColumnSettings ask => new GridColumnSettings(col_id(Columns.Ask), DefaultColumnHeaders.Ask, font_color_override: BTSColors.header_text, width: DefaultColumnWidths.MViewPrice, horizontal_alignment: System.Windows.HorizontalAlignment.Right, background_color_override: BTSColors.MarketData.ask); public static GridColumnSettings ask_merged_size => new GridColumnSettings(col_id(Columns.AskMergedSize), DefaultColumnHeaders.MergedSize, font_color_override: BTSColors.MarketData.ask, width: DefaultColumnWidths.ImpliedDirectMergedSize, horizontal_alignment: System.Windows.HorizontalAlignment.Right); public static GridColumnSettings ask_direct_size => new GridColumnSettings(col_id(Columns.AskDirectSize), DefaultColumnHeaders.DirectSize, font_color_override: BTSColors.MarketData.ask, width: DefaultColumnWidths.ImpliedDirectMergedSize, horizontal_alignment: System.Windows.HorizontalAlignment.Right); public static GridColumnSettings ask_implied_size => new GridColumnSettings(col_id(Columns.AskImpliedSize), DefaultColumnHeaders.ImpliedSize, font_color_override: BTSColors.MarketData.ask, width: DefaultColumnWidths.ImpliedDirectMergedSize, horizontal_alignment: System.Windows.HorizontalAlignment.Right); diff --git a/src/client/spark/view/Controls/DIYGrid/Columns/ColumnBase.cs b/src/client/spark/view/Controls/DIYGrid/Columns/ColumnBase.cs index 6bbaabe2c..062e17c68 100644 --- a/src/client/spark/view/Controls/DIYGrid/Columns/ColumnBase.cs +++ b/src/client/spark/view/Controls/DIYGrid/Columns/ColumnBase.cs @@ -174,19 +174,19 @@ namespace mbts.ui.controls { //readonly ExternalProperty _font_weigh FontWeight _fallback_font_weight; Color _fallback_font_color; - ColorOpacityProto _fallback_background_color; + Color? _fallback_background_color; double _fallback_font_size; FontFamily _fallback_font_family; FontWeight? _font_weight_override; Color? _font_color_override; - ColorOpacityProto? _background_color_override; + Color? _background_color_override; object _header_copy; protected ColumnBase() { var gs = GridSettings.Default; _fallback_font_weight = gs.font_weight; _fallback_font_color = gs.font_color.rgb_color(); - _fallback_background_color = gs.background_color; + _fallback_background_color = gs.background_color.value; _fallback_font_size = gs.font_size; _fallback_font_family = new FontFamily(gs.font_family); original_width = double.NaN; @@ -219,9 +219,9 @@ namespace mbts.ui.controls { public FontWeight font_weight => font_weight_override ?? _fallback_font_weight; public Color font_color => font_color_override ?? _fallback_font_color; public Brush font_brush => new SolidColorBrush(font_color); - public ColorOpacityProto? background_color_override { get => _background_color_override; set => _set_font_param(ref _background_color_override, value); } - public ColorOpacityProto background_color => background_color_override ?? _fallback_background_color; - public Brush background_brush => background_color.to_brush(); + public Color? background_color_override { get => _background_color_override; set => _set_font_param(ref _background_color_override, value); } + public Color? background_color => background_color_override ?? _fallback_background_color; + public Brush background_brush => background_color?.to_brush(); // TODO: find a better way to store the header-property in a thread-safe manner - a value for GridSettings.display_name, more specifically. // Since save_state is called from a different thread in IShared/SlowWindows, it is not safe to access the DependencyProperty store from that method. // By updating a local _header_copy field in the Header setter, the DependencyProperty lookup may be bypassed when appropriate (see create method below). @@ -263,7 +263,7 @@ namespace mbts.ui.controls { } // 'fallback' font-params (aka 'grid-level' font-params) - public void set_fallback_font_params(FontFamily font_family, double font_size, Color font_color, FontWeight font_weight, ColorOpacityProto background_color) { + public void set_fallback_font_params(FontFamily font_family, double font_size, Color font_color, FontWeight font_weight, Color? background_color) { using (ReflectionHelper.detect_property_changes(this, _raise_prop_changed, nameof(font_family), nameof(font_size), nameof(font_color), nameof(font_weight), nameof(background_color), nameof(background_brush))) { _fallback_font_family = font_family; _fallback_font_size = font_size; diff --git a/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs b/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs index c8267344d..bfab02f71 100644 --- a/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs +++ b/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs @@ -255,7 +255,7 @@ namespace mbts.ui.controls { // (e.g MarketView bid/ask columns, bc their background is not transparent, it covers the ListBoxItem selection-highlight). public static readonly SolidColorBrush DefaultSelectionHighlight = new SolidColorBrush(Colors.MediumSlateBlue) { Opacity = 0.4 }; // I have no idea why DefaultBackgroundColor needs to be frozen but DefaultSelectionHighlight is apparently fine as is - public static readonly SolidColorBrush DefaultBackgroundColor = new SolidColorBrush(BTSColors.Grid.input_cell_background) { Opacity = 0.40 }.frozen(); + public static readonly SolidColorBrush DefaultBackgroundColor = null; //new SolidColorBrush(BTSColors.Grid.input_cell_background) { Opacity = 0.40 }.frozen(); public static readonly Pen DefaultSelectionStroke = new Pen(Brushes.MediumSlateBlue, 1); readonly NotifyCollectionChangedEventHandler _sort_descriptions_collection_changed_cb; double _inactive_selection_opacity = 0.2; diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/GridColumnSettings.cs b/src/client/spark/view/Controls/DIYGrid/Settings/GridColumnSettings.cs index 73650567a..770e7e52c 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/GridColumnSettings.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/GridColumnSettings.cs @@ -61,7 +61,7 @@ namespace mbts.ui.settings { readonly double _horizontal_offset; [ProtoMember(10)] - readonly NullableColorOpacityProto _background_color_override; + readonly NullableColorProto _background_color_override; public GridColumnSettings() { _is_visible = _default_is_visible; @@ -72,7 +72,7 @@ namespace mbts.ui.settings { } public GridColumnSettings(string id, string display_name = null, bool is_visible = _default_is_visible, bool is_collapsed = _default_is_collapsed, FontWeight? font_weight_override = null, Color? font_color_override = null, - double width = _default_width, HorizontalAlignment horizontal_alignment = _default_horizontal_alignment, double horizontal_offset = _default_horizontal_offset, ColorOpacityProto? background_color_override = null) { + double width = _default_width, HorizontalAlignment horizontal_alignment = _default_horizontal_alignment, double horizontal_offset = _default_horizontal_offset, Color? background_color_override = null) { _id = id; _display_name = display_name; _is_visible = is_visible; @@ -82,7 +82,7 @@ namespace mbts.ui.settings { _width = width; _horizontal_alignment = horizontal_alignment; _horizontal_offset = horizontal_offset; - _background_color_override = new NullableColorOpacityProto(background_color_override); + _background_color_override = new NullableColorProto(background_color_override); } public string id => _id; @@ -94,11 +94,11 @@ namespace mbts.ui.settings { public HorizontalAlignment horizontal_alignment => _horizontal_alignment; public double horizontal_offset => _horizontal_offset; public string display_name => _display_name; - public ColorOpacityProto? background_color_override => _background_color_override.value; + public Color? background_color_override => _background_color_override.value; public GridColumnSettings with( string display_name = null, bool? is_visible = null, bool? is_collapsed = null, NullableFontWeightProto? font_weight_override = null, NullableColorProto? font_color_override = null, - double? width = null, HorizontalAlignment? horizontal_alignment = null, double? horizontal_offset = null, NullableColorOpacityProto? background_color_override = null) => + double? width = null, HorizontalAlignment? horizontal_alignment = null, double? horizontal_offset = null, NullableColorProto? background_color_override = null) => // new GridColumnSettings(_id, display_name ?? this.display_name, diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/GridColumnSettingsVM.cs b/src/client/spark/view/Controls/DIYGrid/Settings/GridColumnSettingsVM.cs index 521924964..dcb799b83 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/GridColumnSettingsVM.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/GridColumnSettingsVM.cs @@ -98,8 +98,7 @@ namespace mbts.spark { width, horizontal_alignment, background_color_override: is_background_color_overridden ? - new NullableColorOpacityProto(new ColorOpacityProto(background_color_override.color, background_color_override.opacity)) - : default); + new NullableColorProto(background_color_override.color) : default); var animations_lookup = predicate_animations.ToFlatLookup(pa => pa.predicate.create_assigned(owner._predicate_data_factory), pa => pa.animations.Select(a => a.create())); return (settings, animations_lookup); } @@ -125,8 +124,9 @@ namespace mbts.spark { is_background_color_overridden = _settings.background_color_override.HasValue; if (is_background_color_overridden) { background_color_override.load_from( - new SolidColorBrush(_settings.background_color_override.Value.color) { - Opacity = _settings.background_color_override.Value.opacity }); + new SolidColorBrush(_settings.background_color_override.Value) { + //Opacity = _settings.background_color_override.Value.opacity + }); } predicate_animations.SetItems(value.animations.empty_if_null().Select(g => { var vm = new PredicateCellAnimationVM(id, owner._create_column_predicate_vm(id), owner._predicate_data_factory); diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettings.cs b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettings.cs index ac0ddef91..9e63e69d7 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettings.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettings.cs @@ -21,7 +21,7 @@ namespace mbts.ui.settings { public static GridSettings Default => new GridSettings( selection_highlight: new ColorOpacityProto(FallbackValues.selection_highlight.Color, FallbackValues.selection_highlight.Opacity), - background_color: new ColorOpacityProto(FallbackValues.background_color.Color, FallbackValues.background_color.Opacity)); + background_color: null);//new ColorOpacityProto(FallbackValues.background_color.Color, FallbackValues.background_color.Opacity)); // corrects any inappropriate values that would render the grid unusable (usually nulls) // NOTE: if you add a property to GridSettings that could have such a value, please add a conditional-correction for it below) @@ -69,7 +69,7 @@ namespace mbts.ui.settings { [ProtoMember(7)] List _sorting_criterion; [ProtoMember(8)] - readonly ColorOpacityProto _background_color; + readonly NullableColorProto _background_color; public GridSettings() { _font_family = _default_font_family; @@ -78,12 +78,12 @@ namespace mbts.ui.settings { _font_color = _default_font_color; // new setting in proto defaulted here - _background_color = new ColorOpacityProto(DIYGrid.DefaultBackgroundColor.Color, DIYGrid.DefaultBackgroundColor.Opacity); + _background_color = new NullableColorProto(); //new ColorOpacityProto(DIYGrid.DefaultBackgroundColor.Color, DIYGrid.DefaultBackgroundColor.Opacity); } public GridSettings( string font_family = _default_font_family, double font_size = _default_font_size, FontWeight font_weight = default, uint font_color = _default_font_color, - ColorOpacityProto? selection_highlight = null, IEnumerable columns = null, IEnumerable sorting_criterion = null, ColorOpacityProto? background_color = null) { + ColorOpacityProto? selection_highlight = null, IEnumerable columns = null, IEnumerable sorting_criterion = null, NullableColorProto? background_color = null) { // _font_family = font_family; _font_size = font_size; @@ -92,7 +92,7 @@ namespace mbts.ui.settings { _selection_highlight = selection_highlight ?? new ColorOpacityProto(0, 1); _columns = new List(columns.empty_if_null()); _sorting_criterion = new List(sorting_criterion.empty_if_null()); - _background_color = background_color ?? new ColorOpacityProto(DIYGrid.DefaultBackgroundColor.Color, DIYGrid.DefaultBackgroundColor.Opacity); + _background_color = background_color ?? new NullableColorProto(); } public string font_family => _font_family; @@ -100,14 +100,14 @@ namespace mbts.ui.settings { public uint font_color => _font_color; public FontWeight font_weight => FontWeight.FromOpenTypeWeight(_font_weight); public ColorOpacityProto selection_highlight => _selection_highlight; - public ColorOpacityProto background_color => _background_color; + public NullableColorProto background_color => _background_color; public IReadOnlyList columns => _columns ?? (_columns = new List(0)); [Obsolete] // TODO: remove sorting_criterion from GridSettings entirely. This should be part of IShellWindow's StartupData, since it is an instance-specific setting, and prob not part of the shared defaults public IReadOnlyList sorting_criterion => _sorting_criterion ?? (_sorting_criterion = new List(0)); public static GridSettings get_default() => new GridSettings(_default_font_family, _default_font_size, FontWeights.Normal, _default_font_color, new ColorOpacityProto(DIYGrid.DefaultSelectionHighlight.Color, DIYGrid.DefaultSelectionHighlight.Opacity), - background_color: new ColorOpacityProto(DIYGrid.DefaultBackgroundColor.Color, DIYGrid.DefaultBackgroundColor.Opacity)); + background_color: new NullableColorProto()); public GridSettings with(IEnumerable columns = null, IEnumerable sorting_criterion = null, string font_family = null, double font_size = double.NaN) => new GridSettings( diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsManager.cs b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsManager.cs index eed7af4cd..8cf976235 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsManager.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsManager.cs @@ -77,7 +77,7 @@ namespace mbts.ui { _font_size = backing(nameof(font_size), () => grid_settings.font_size, nameof(font_size)); _font_color = backing(nameof(font_color), () => grid_settings.font_color.rgb_solid_brush().frozen(), nameof(grid_settings)); _selection_highlight = backing(nameof(selection_highlight), () => grid_settings.selection_highlight.to_brush().frozen(), nameof(grid_settings)); - _background_color = backing(nameof(background_color), () => grid_settings.background_color.to_brush().frozen(), nameof(grid_settings)); + _background_color = backing(nameof(background_color), () => grid_settings.background_color.value?.rgb_color().rgb_solid_brush().frozen(), nameof(grid_settings)); } public void Dispose() => @@ -114,7 +114,7 @@ namespace mbts.ui { var grid = value.general ?? GridSettings.Default; _grid_settings.set(grid); foreach (ColumnBase col in _columns) - col.set_fallback_font_params(new FontFamily(grid.font_family), grid.font_size, grid.font_color.rgb_color(), grid.font_weight, grid.background_color); + col.set_fallback_font_params(new FontFamily(grid.font_family), grid.font_size, grid.font_color.rgb_color(), grid.font_weight, grid.background_color.value); _predicate_animations_data = value.predicate_animations; _animation_defs.clear(); foreach (var pa in _predicate_animations_data) { diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsVM.cs b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsVM.cs index 8caeebfff..539c17e36 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsVM.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsVM.cs @@ -1,5 +1,6 @@ using bts.api; using bts.collections; +using bts.proto; using bts.shell; using bts.utils; using mbts.collections; @@ -131,7 +132,7 @@ namespace mbts.spark { foreach (IGrouping g in animations) animation_map.AddOrUpdate(g.Key, p => animation_tuple(c: g), (p, t) => t.cell_animations.AddRange(g)); } - return _create_settings_obj(new GridSettings(font_family.name(), font_size, font_weight, font_color.color.rgb_color(), selection_highlight.to_proto(), col_settings, background_color: background_color.to_proto()), + return _create_settings_obj(new GridSettings(font_family.name(), font_size, font_weight, font_color.color.rgb_color(), selection_highlight.to_proto(), col_settings, background_color: new NullableColorProto(background_color.color.rgb_color())), animation_map.Select(kv => PredicateAnimations.create_data(kv.Key, kv.Value.cell_animations, kv.Value.row_animations, kv.Value.sounds))); // (List row_animations, List sounds, List cell_animations) animation_tuple(IEnumerable r = null, IEnumerable s = null, IGrouping c = null) => @@ -143,7 +144,9 @@ namespace mbts.spark { _font_weight.set(sd.general.font_weight); font_color.load_from(sd.general.font_color.rgb_solid_brush()); selection_highlight.load_from(sd.general.selection_highlight.to_brush()); - background_color.load_from(sd.general.background_color.to_brush()); + if (sd.general.background_color.value.HasValue) { + background_color.load_from(sd.general.background_color.value.Value.to_solid_brush()); + } _font_size.set(sd.general.font_size); var col_animations = new Dictionary>>(); predicate_animations.Clear(); diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/ImmutableColumnSettingsStore.cs b/src/client/spark/view/Controls/DIYGrid/Settings/ImmutableColumnSettingsStore.cs index 01503387f..5b6926814 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/ImmutableColumnSettingsStore.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/ImmutableColumnSettingsStore.cs @@ -70,7 +70,7 @@ namespace mbts.ui { } class ImmutableBackgroundColorOverrideStore : ImmutableColumnSettingStore { - NullableColorOpacityProto _value; + NullableColorProto _value; public ImmutableBackgroundColorOverrideStore() : base(GridColumnSettingsFeatureFlags.ImmutableBackgroundColor) { } @@ -79,7 +79,7 @@ namespace mbts.ui { settings.with(background_color_override: _value); public override void store(GridColumnSettings settings) => - _value = new NullableColorOpacityProto(settings.background_color_override); + _value = new NullableColorProto(settings.background_color_override); } class CompositeImmutableSettingsStore : ImmutableColumnSettingStore { diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridColumnSettingsVM.cs b/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridColumnSettingsVM.cs index d4dc86c50..51f0f532e 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridColumnSettingsVM.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridColumnSettingsVM.cs @@ -60,8 +60,7 @@ namespace mbts.spark { width, horizontal_alignment, background_color_override: is_background_color_overridden ? - new NullableColorOpacityProto(new ColorOpacityProto(background_color_override.color, background_color_override.opacity)) - : default); + new NullableColorProto(background_color_override.color) : default); public void load_from(GridColumnSettings value) { _settings = value; @@ -84,8 +83,8 @@ namespace mbts.spark { is_background_color_overridden = _settings.background_color_override.HasValue; if (is_background_color_overridden) { background_color_override.load_from( - new SolidColorBrush(_settings.background_color_override.Value.color) { - Opacity = _settings.background_color_override.Value.opacity + new SolidColorBrush(_settings.background_color_override.Value) { + //Opacity = _settings.background_color_override.Value.opacity }); } } diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsManager.cs b/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsManager.cs index 4b66e19f6..0a002ac62 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsManager.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsManager.cs @@ -35,7 +35,7 @@ namespace mbts.ui { _font_size = backing(nameof(font_size), () => grid_settings.font_size, nameof(font_size)); _font_color = backing(nameof(font_color), () => grid_settings.font_color.rgb_solid_brush().frozen(), nameof(grid_settings)); _selection_highlight = backing(nameof(selection_highlight), () => grid_settings.selection_highlight.to_brush().frozen(), nameof(grid_settings)); - _background_color = backing(nameof(background_color), () => grid_settings.background_color.to_brush().frozen(), nameof(grid_settings)); + _background_color = backing(nameof(background_color), () => grid_settings.background_color.value?.rgb_color().rgb_solid_brush().frozen(), nameof(grid_settings)); _row_vms = row_vms; } @@ -88,7 +88,7 @@ namespace mbts.ui { grid = grid ?? GridSettings.Default; _grid_settings.set(grid); foreach (ColumnBase col in _columns) - col.set_fallback_font_params(new FontFamily(grid.font_family), grid.font_size, grid.font_color.rgb_color(), grid.font_weight, grid.background_color); + col.set_fallback_font_params(new FontFamily(grid.font_family), grid.font_size, grid.font_color.rgb_color(), grid.font_weight, grid.background_color.value); // ** in the unfortunate event that we botch backwards compatability, and the columns don't bear a 1:1 relationship with the column-settings // don't add insult to injury by crashing ** if (grid_settings.columns != null) { diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs b/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs index 220424bc6..5c01ac440 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs @@ -1,4 +1,5 @@ using bts.collections; +using bts.proto; using bts.utils; using mbts.ui; using mbts.ui.controls; @@ -105,7 +106,7 @@ namespace mbts.spark { } public GridSettings create() => - new GridSettings(font_family.name(), font_size, font_weight, font_color.color.rgb_color(), selection_highlight.to_proto(), columns.Select(c => c.create()), background_color: background_color.to_proto()); + new GridSettings(font_family.name(), font_size, font_weight, font_color.color.rgb_color(), selection_highlight.to_proto(), columns.Select(c => c.create()), background_color: new NullableColorProto(background_color.color.rgb_color())); public void load_from(GridSettings value) { if (value == null) @@ -115,7 +116,9 @@ namespace mbts.spark { _font_weight.set(value.font_weight); font_color.load_from(value.font_color.rgb_solid_brush()); selection_highlight.load_from(value.selection_highlight.to_brush()); - background_color.load_from(value.background_color.to_brush()); + if (value.background_color.value.HasValue) { + background_color.load_from(value.background_color.value.Value.to_solid_brush()); + } _font_size.set(value.font_size); var curr_col_id = current_column?.id; columns.SetItems(value.columns.Select(col => { From 9a76d9c857e2ebf80323ba8997fddedc6db15d52 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Wed, 14 Aug 2019 14:21:58 -0500 Subject: [PATCH 016/116] argb-ness from John --- src/client/spark/core/data/Proto/NullableColorProto.cs | 10 ++-------- src/client/spark/view/Extensions/WPFExtensions.cs | 10 ++++++++++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/client/spark/core/data/Proto/NullableColorProto.cs b/src/client/spark/core/data/Proto/NullableColorProto.cs index 3fa15eba3..2fb827d08 100644 --- a/src/client/spark/core/data/Proto/NullableColorProto.cs +++ b/src/client/spark/core/data/Proto/NullableColorProto.cs @@ -16,14 +16,8 @@ namespace bts.proto { public NullableColorProto(uint value) => _value = value; - - public Color? value { - get { - if (_value.HasValue) - return _value.Value.rgb_color(); - return null; - } - } + public Color? value => _value?.rgb_color(); + public Color? argb => _value?.argb_color(); public bool Equals(NullableColorProto other) => EqualityComparer.nullable_equals(_value, other._value); diff --git a/src/client/spark/view/Extensions/WPFExtensions.cs b/src/client/spark/view/Extensions/WPFExtensions.cs index 643e20162..190eab50e 100644 --- a/src/client/spark/view/Extensions/WPFExtensions.cs +++ b/src/client/spark/view/Extensions/WPFExtensions.cs @@ -66,11 +66,18 @@ namespace mbts.ui { } } + // TODO: replace this method with 'argb_color' + // - before that, need to verify that no settings/colors become 'invisible' as a result. public static Color rgb_color(this UInt32 color) { var bytes = BitConverter.GetBytes(color); return Color.FromRgb(bytes[2], bytes[1], bytes[0]); } + public static Color argb_color(this uint color) { + var bytes = BitConverter.GetBytes(color); + return Color.FromArgb(bytes[3], bytes[2], bytes[1], bytes[0]); + } + public static SolidColorBrush to_brush(this BTSColor color) => new SolidColorBrush(color); @@ -103,6 +110,9 @@ namespace mbts.ui { return brush; } + public static Color with(this Color color, byte alpha) => + Color.FromArgb(alpha, color.R, color.G, color.B); + public static SolidColorBrush with(this SolidColorBrush brush, double opacity) { brush.Opacity = opacity; return brush; From ea2aee5044f8e2b3f7acba64a8df91128d48045a Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Wed, 14 Aug 2019 15:04:40 -0500 Subject: [PATCH 017/116] utilzing new argb --- .../spark/view/Controls/DIYGrid/Columns/ColumnBase.cs | 2 +- .../view/Controls/DIYGrid/Settings/GridSettingsManager.cs | 4 ++-- .../view/Controls/DIYGrid/Settings/GridSettingsVM.cs | 6 ++++-- .../DIYGrid/Settings/SimpleGridSettingsManager.cs | 4 ++-- .../Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs | 8 +++++--- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/client/spark/view/Controls/DIYGrid/Columns/ColumnBase.cs b/src/client/spark/view/Controls/DIYGrid/Columns/ColumnBase.cs index 062e17c68..51596963c 100644 --- a/src/client/spark/view/Controls/DIYGrid/Columns/ColumnBase.cs +++ b/src/client/spark/view/Controls/DIYGrid/Columns/ColumnBase.cs @@ -186,7 +186,7 @@ namespace mbts.ui.controls { var gs = GridSettings.Default; _fallback_font_weight = gs.font_weight; _fallback_font_color = gs.font_color.rgb_color(); - _fallback_background_color = gs.background_color.value; + _fallback_background_color = gs.background_color.argb; _fallback_font_size = gs.font_size; _fallback_font_family = new FontFamily(gs.font_family); original_width = double.NaN; diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsManager.cs b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsManager.cs index 8cf976235..bdf1e64f9 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsManager.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsManager.cs @@ -77,7 +77,7 @@ namespace mbts.ui { _font_size = backing(nameof(font_size), () => grid_settings.font_size, nameof(font_size)); _font_color = backing(nameof(font_color), () => grid_settings.font_color.rgb_solid_brush().frozen(), nameof(grid_settings)); _selection_highlight = backing(nameof(selection_highlight), () => grid_settings.selection_highlight.to_brush().frozen(), nameof(grid_settings)); - _background_color = backing(nameof(background_color), () => grid_settings.background_color.value?.rgb_color().rgb_solid_brush().frozen(), nameof(grid_settings)); + _background_color = backing(nameof(background_color), () => grid_settings.background_color.argb?.to_solid_brush().frozen(), nameof(grid_settings)); } public void Dispose() => @@ -114,7 +114,7 @@ namespace mbts.ui { var grid = value.general ?? GridSettings.Default; _grid_settings.set(grid); foreach (ColumnBase col in _columns) - col.set_fallback_font_params(new FontFamily(grid.font_family), grid.font_size, grid.font_color.rgb_color(), grid.font_weight, grid.background_color.value); + col.set_fallback_font_params(new FontFamily(grid.font_family), grid.font_size, grid.font_color.rgb_color(), grid.font_weight, grid.background_color.argb); _predicate_animations_data = value.predicate_animations; _animation_defs.clear(); foreach (var pa in _predicate_animations_data) { diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsVM.cs b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsVM.cs index 539c17e36..cd3bea93a 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsVM.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsVM.cs @@ -132,7 +132,9 @@ namespace mbts.spark { foreach (IGrouping g in animations) animation_map.AddOrUpdate(g.Key, p => animation_tuple(c: g), (p, t) => t.cell_animations.AddRange(g)); } - return _create_settings_obj(new GridSettings(font_family.name(), font_size, font_weight, font_color.color.rgb_color(), selection_highlight.to_proto(), col_settings, background_color: new NullableColorProto(background_color.color.rgb_color())), + return _create_settings_obj(new GridSettings(font_family.name(), font_size, font_weight, font_color.color.rgb_color(), selection_highlight.to_proto(), col_settings, + background_color: new NullableColorProto(background_color.color + .with((byte)(MathUtils.within_range(0, 1, background_color.opacity) * 255.0)))), animation_map.Select(kv => PredicateAnimations.create_data(kv.Key, kv.Value.cell_animations, kv.Value.row_animations, kv.Value.sounds))); // (List row_animations, List sounds, List cell_animations) animation_tuple(IEnumerable r = null, IEnumerable s = null, IGrouping c = null) => @@ -145,7 +147,7 @@ namespace mbts.spark { font_color.load_from(sd.general.font_color.rgb_solid_brush()); selection_highlight.load_from(sd.general.selection_highlight.to_brush()); if (sd.general.background_color.value.HasValue) { - background_color.load_from(sd.general.background_color.value.Value.to_solid_brush()); + background_color.load_from(sd.general.background_color.argb.Value.to_solid_brush()); } _font_size.set(sd.general.font_size); var col_animations = new Dictionary>>(); diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsManager.cs b/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsManager.cs index 0a002ac62..50a1cf7f7 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsManager.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsManager.cs @@ -35,7 +35,7 @@ namespace mbts.ui { _font_size = backing(nameof(font_size), () => grid_settings.font_size, nameof(font_size)); _font_color = backing(nameof(font_color), () => grid_settings.font_color.rgb_solid_brush().frozen(), nameof(grid_settings)); _selection_highlight = backing(nameof(selection_highlight), () => grid_settings.selection_highlight.to_brush().frozen(), nameof(grid_settings)); - _background_color = backing(nameof(background_color), () => grid_settings.background_color.value?.rgb_color().rgb_solid_brush().frozen(), nameof(grid_settings)); + _background_color = backing(nameof(background_color), () => grid_settings.background_color.argb?.to_solid_brush().frozen(), nameof(grid_settings)); _row_vms = row_vms; } @@ -88,7 +88,7 @@ namespace mbts.ui { grid = grid ?? GridSettings.Default; _grid_settings.set(grid); foreach (ColumnBase col in _columns) - col.set_fallback_font_params(new FontFamily(grid.font_family), grid.font_size, grid.font_color.rgb_color(), grid.font_weight, grid.background_color.value); + col.set_fallback_font_params(new FontFamily(grid.font_family), grid.font_size, grid.font_color.rgb_color(), grid.font_weight, grid.background_color.argb); // ** in the unfortunate event that we botch backwards compatability, and the columns don't bear a 1:1 relationship with the column-settings // don't add insult to injury by crashing ** if (grid_settings.columns != null) { diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs b/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs index 5c01ac440..f5945e1bd 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs @@ -106,7 +106,9 @@ namespace mbts.spark { } public GridSettings create() => - new GridSettings(font_family.name(), font_size, font_weight, font_color.color.rgb_color(), selection_highlight.to_proto(), columns.Select(c => c.create()), background_color: new NullableColorProto(background_color.color.rgb_color())); + new GridSettings(font_family.name(), font_size, font_weight, font_color.color.rgb_color(), selection_highlight.to_proto(), columns.Select(c => c.create()), + background_color: new NullableColorProto(background_color.color + .with((byte)(MathUtils.within_range(0, 1, background_color.opacity) * 255.0)))); public void load_from(GridSettings value) { if (value == null) @@ -116,8 +118,8 @@ namespace mbts.spark { _font_weight.set(value.font_weight); font_color.load_from(value.font_color.rgb_solid_brush()); selection_highlight.load_from(value.selection_highlight.to_brush()); - if (value.background_color.value.HasValue) { - background_color.load_from(value.background_color.value.Value.to_solid_brush()); + if (value.background_color.argb.HasValue) { + background_color.load_from(value.background_color.argb.Value.to_solid_brush()); } _font_size.set(value.font_size); var curr_col_id = current_column?.id; From 5f6742f1dbe4d1d229aeb99cdb7321fce7d7d13c Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Wed, 14 Aug 2019 16:48:08 -0500 Subject: [PATCH 018/116] adding enable_background_color to GridSettings and all the right spots --- .../Market/MarketView/MarketViewWindow.cs | 2 +- .../MarketView/MarketViewWindowFactory.cs | 6 +++-- .../Controls/DIYGrid/Settings/GridSettings.cs | 22 ++++++++++++++----- .../DIYGrid/Settings/SimpleGridSettingsVM.cs | 7 ++++-- .../Shell/Settings/ShellSettingsDialog.xaml | 4 ++-- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/client/spark/Modules/Market/MarketView/MarketViewWindow.cs b/src/client/spark/Modules/Market/MarketView/MarketViewWindow.cs index 35f22e89c..fe3520a6a 100644 --- a/src/client/spark/Modules/Market/MarketView/MarketViewWindow.cs +++ b/src/client/spark/Modules/Market/MarketView/MarketViewWindow.cs @@ -153,7 +153,7 @@ namespace mbts.spark { s => _vm.grid_settings_manager.create_vm( // we need to get the most up to date GridSettings when launching b/c users may // have changed some settings on the grid directly, like column widths. - s.with(_vm.columns.Select(c => c.create())) + s.with(_vm.columns.Select(c => c.create()), enable_background_color: true) ) ); vm.SubscribeDisposed(literal_title_source.OnDispatcher().Subscribe(t => vm.title = t)); diff --git a/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs b/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs index 2d7b6e075..c28013d6b 100644 --- a/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs +++ b/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs @@ -74,6 +74,7 @@ namespace bts.shell { return null; } + // column upgrade var columns = s.columns.ToList(); var bid_col_index = columns.FindIndex(x => x.id == col_id(Columns.Bid)); var ask_col_index = columns.FindIndex(x => x.id == col_id(Columns.Ask)); @@ -85,11 +86,12 @@ namespace bts.shell { columns[ask_col_index] = columns[ask_col_index].with(background_color_override: new NullableColorProto(BTSColors.MarketData.ask.ToUint())); } } - return s.with(columns); + // and enable background color upgrade + return s.with(columns, enable_background_color: true); } - public static GridSettings DefaultGridSettings => GridSettings.Default.with(DefaultColumns.all, DefaultColumns.default_sorting_criterion); + public static GridSettings DefaultGridSettings => GridSettings.Default.with(DefaultColumns.all, DefaultColumns.default_sorting_criterion, enable_background_color: true); public IReadOnlyList sorting_criterion => _sorting_criteria ?? (_sorting_criteria = DefaultColumns.default_sorting_criterion.ToList()); diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettings.cs b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettings.cs index 9e63e69d7..313fca866 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettings.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettings.cs @@ -21,7 +21,8 @@ namespace mbts.ui.settings { public static GridSettings Default => new GridSettings( selection_highlight: new ColorOpacityProto(FallbackValues.selection_highlight.Color, FallbackValues.selection_highlight.Opacity), - background_color: null);//new ColorOpacityProto(FallbackValues.background_color.Color, FallbackValues.background_color.Opacity)); + background_color: null, //new ColorOpacityProto(FallbackValues.background_color.Color, FallbackValues.background_color.Opacity)); + enable_background_color: false); // corrects any inappropriate values that would render the grid unusable (usually nulls) // NOTE: if you add a property to GridSettings that could have such a value, please add a conditional-correction for it below) @@ -70,6 +71,9 @@ namespace mbts.ui.settings { List _sorting_criterion; [ProtoMember(8)] readonly NullableColorProto _background_color; + [ProtoMember(9)] + [DefaultValue(false)] + readonly bool _enable_background_color; public GridSettings() { _font_family = _default_font_family; @@ -79,11 +83,12 @@ namespace mbts.ui.settings { // new setting in proto defaulted here _background_color = new NullableColorProto(); //new ColorOpacityProto(DIYGrid.DefaultBackgroundColor.Color, DIYGrid.DefaultBackgroundColor.Opacity); + _enable_background_color = false; } public GridSettings( string font_family = _default_font_family, double font_size = _default_font_size, FontWeight font_weight = default, uint font_color = _default_font_color, - ColorOpacityProto? selection_highlight = null, IEnumerable columns = null, IEnumerable sorting_criterion = null, NullableColorProto? background_color = null) { + ColorOpacityProto? selection_highlight = null, IEnumerable columns = null, IEnumerable sorting_criterion = null, NullableColorProto? background_color = null, bool enable_background_color = false) { // _font_family = font_family; _font_size = font_size; @@ -93,6 +98,7 @@ namespace mbts.ui.settings { _columns = new List(columns.empty_if_null()); _sorting_criterion = new List(sorting_criterion.empty_if_null()); _background_color = background_color ?? new NullableColorProto(); + _enable_background_color = enable_background_color; } public string font_family => _font_family; @@ -101,6 +107,7 @@ namespace mbts.ui.settings { public FontWeight font_weight => FontWeight.FromOpenTypeWeight(_font_weight); public ColorOpacityProto selection_highlight => _selection_highlight; public NullableColorProto background_color => _background_color; + public bool enable_background_color => _enable_background_color; public IReadOnlyList columns => _columns ?? (_columns = new List(0)); [Obsolete] // TODO: remove sorting_criterion from GridSettings entirely. This should be part of IShellWindow's StartupData, since it is an instance-specific setting, and prob not part of the shared defaults public IReadOnlyList sorting_criterion => _sorting_criterion ?? (_sorting_criterion = new List(0)); @@ -109,7 +116,7 @@ namespace mbts.ui.settings { new GridSettings(_default_font_family, _default_font_size, FontWeights.Normal, _default_font_color, new ColorOpacityProto(DIYGrid.DefaultSelectionHighlight.Color, DIYGrid.DefaultSelectionHighlight.Opacity), background_color: new NullableColorProto()); - public GridSettings with(IEnumerable columns = null, IEnumerable sorting_criterion = null, string font_family = null, double font_size = double.NaN) => + public GridSettings with(IEnumerable columns = null, IEnumerable sorting_criterion = null, string font_family = null, double font_size = double.NaN, bool? enable_background_color = null) => new GridSettings( font_family ?? _font_family, DoubleHelper.IsNaNOrInfinityOr(font_size, 0) ? _font_size : font_size, @@ -118,7 +125,8 @@ namespace mbts.ui.settings { _selection_highlight, columns ?? _columns, sorting_criterion ?? _sorting_criterion, - _background_color); + _background_color, + enable_background_color ?? _enable_background_color); public GridSettings clone() => with(); @@ -133,7 +141,8 @@ namespace mbts.ui.settings { #pragma warning disable CS0612 // Type or member is obsolete EqualityComparer.safe_sequence_equals(sorting_criterion, other.sorting_criterion) && #pragma warning restore CS0612 // Type or member is obsolete - background_color == other.background_color; + background_color == other.background_color && + enable_background_color == other.enable_background_color; public override bool Equals(object obj) => Equals(obj as GridSettings); @@ -149,6 +158,7 @@ namespace mbts.ui.settings { #pragma warning disable CS0612 // Type or member is obsolete EqualityComparer.safe_aggregate_hash(sorting_criterion), #pragma warning restore CS0612 // Type or member is obsolete - background_color.GetHashCode()); + background_color.GetHashCode(), + enable_background_color.GetHashCode()); } } \ No newline at end of file diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs b/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs index f5945e1bd..89ebfe4b6 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs @@ -37,7 +37,7 @@ namespace mbts.spark { readonly Property _font_weight; readonly Property _font_display_name; readonly Property _font_size; - readonly Property _show_predicate_animations, _show_cell_predicate_animations; + readonly Property _show_predicate_animations, _show_cell_predicate_animations, _show_background_color; readonly DeferrableActionWrapper _update; readonly IReadOnlyDictionary _column_flags; @@ -49,6 +49,7 @@ namespace mbts.spark { _font_display_name = backing(nameof(font_display_name), () => TextUtils.display_name(font_family, font_size), new[] { nameof(font_family), nameof(font_size) }); _show_predicate_animations = backing(nameof(show_predicate_animations), true); _show_cell_predicate_animations = backing(nameof(show_cell_predicate_animations), true); + _show_background_color = backing(nameof(show_background_color), false); _current_column = backing(nameof(current_column)); // update _update = new DeferrableActionWrapper(() => result_changed?.Invoke()); @@ -81,6 +82,7 @@ namespace mbts.spark { public ColorPickerPopupVM font_color { get; } = new ColorPickerPopupVM(); public ColorPickerPopupVM selection_highlight { get; } = new ColorPickerPopupVM(); public ColorPickerPopupVM background_color { get; } = new ColorPickerPopupVM(); + public bool show_background_color => _show_background_color.Value; public double font_size { get => _font_size.Value; set => _font_size.set(value); } public bool enable_sound_triggers => false; public bool show_predicate_animations { get => _show_predicate_animations.Value; set => _show_predicate_animations.set(value); } @@ -118,7 +120,8 @@ namespace mbts.spark { _font_weight.set(value.font_weight); font_color.load_from(value.font_color.rgb_solid_brush()); selection_highlight.load_from(value.selection_highlight.to_brush()); - if (value.background_color.argb.HasValue) { + _show_background_color.set(value.enable_background_color); + if (value.enable_background_color && value.background_color.argb.HasValue) { background_color.load_from(value.background_color.argb.Value.to_solid_brush()); } _font_size.set(value.font_size); diff --git a/src/client/spark/view/Shell/Settings/ShellSettingsDialog.xaml b/src/client/spark/view/Shell/Settings/ShellSettingsDialog.xaml index 882871751..c8d62d7c5 100644 --- a/src/client/spark/view/Shell/Settings/ShellSettingsDialog.xaml +++ b/src/client/spark/view/Shell/Settings/ShellSettingsDialog.xaml @@ -71,8 +71,8 @@ Font Color (default) - Background Color (default) - + Background Color (default) + Selection Highlight From 5c9c75463cffc9013e8cac331040d95fe7d31132 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Wed, 14 Aug 2019 17:39:03 -0500 Subject: [PATCH 019/116] GridSettings background_color should be a uint (can be tranparent by deafult), and not a NullableColorProto; fml --- .../view/Controls/DIYGrid/Columns/ColumnBase.cs | 6 +++--- .../Controls/DIYGrid/Settings/GridSettings.cs | 15 ++++++++------- .../DIYGrid/Settings/GridSettingsManager.cs | 4 ++-- .../Controls/DIYGrid/Settings/GridSettingsVM.cs | 7 +++---- .../DIYGrid/Settings/SimpleGridSettingsManager.cs | 4 ++-- .../DIYGrid/Settings/SimpleGridSettingsVM.cs | 7 +++---- 6 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/client/spark/view/Controls/DIYGrid/Columns/ColumnBase.cs b/src/client/spark/view/Controls/DIYGrid/Columns/ColumnBase.cs index 51596963c..4bd11dffd 100644 --- a/src/client/spark/view/Controls/DIYGrid/Columns/ColumnBase.cs +++ b/src/client/spark/view/Controls/DIYGrid/Columns/ColumnBase.cs @@ -174,7 +174,7 @@ namespace mbts.ui.controls { //readonly ExternalProperty _font_weigh FontWeight _fallback_font_weight; Color _fallback_font_color; - Color? _fallback_background_color; + Color _fallback_background_color; double _fallback_font_size; FontFamily _fallback_font_family; FontWeight? _font_weight_override; @@ -186,7 +186,7 @@ namespace mbts.ui.controls { var gs = GridSettings.Default; _fallback_font_weight = gs.font_weight; _fallback_font_color = gs.font_color.rgb_color(); - _fallback_background_color = gs.background_color.argb; + _fallback_background_color = gs.background_color.argb_color(); _fallback_font_size = gs.font_size; _fallback_font_family = new FontFamily(gs.font_family); original_width = double.NaN; @@ -263,7 +263,7 @@ namespace mbts.ui.controls { } // 'fallback' font-params (aka 'grid-level' font-params) - public void set_fallback_font_params(FontFamily font_family, double font_size, Color font_color, FontWeight font_weight, Color? background_color) { + public void set_fallback_font_params(FontFamily font_family, double font_size, Color font_color, FontWeight font_weight, Color background_color) { using (ReflectionHelper.detect_property_changes(this, _raise_prop_changed, nameof(font_family), nameof(font_size), nameof(font_color), nameof(font_weight), nameof(background_color), nameof(background_brush))) { _fallback_font_family = font_family; _fallback_font_size = font_size; diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettings.cs b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettings.cs index 313fca866..8459ba17d 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettings.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettings.cs @@ -17,11 +17,12 @@ namespace mbts.ui.settings { const double _default_font_size = 11; const uint _default_font_color = 0; const ushort _default_font_weight = 400; + const uint _default_background_color = 0x00FFFFFF; // Colors.Transparent public static GridSettings Default => new GridSettings( selection_highlight: new ColorOpacityProto(FallbackValues.selection_highlight.Color, FallbackValues.selection_highlight.Opacity), - background_color: null, //new ColorOpacityProto(FallbackValues.background_color.Color, FallbackValues.background_color.Opacity)); + background_color: _default_background_color, //new ColorOpacityProto(FallbackValues.background_color.Color, FallbackValues.background_color.Opacity)); enable_background_color: false); // corrects any inappropriate values that would render the grid unusable (usually nulls) @@ -70,7 +71,7 @@ namespace mbts.ui.settings { [ProtoMember(7)] List _sorting_criterion; [ProtoMember(8)] - readonly NullableColorProto _background_color; + readonly uint _background_color; [ProtoMember(9)] [DefaultValue(false)] readonly bool _enable_background_color; @@ -82,13 +83,13 @@ namespace mbts.ui.settings { _font_color = _default_font_color; // new setting in proto defaulted here - _background_color = new NullableColorProto(); //new ColorOpacityProto(DIYGrid.DefaultBackgroundColor.Color, DIYGrid.DefaultBackgroundColor.Opacity); + _background_color = _default_background_color; _enable_background_color = false; } public GridSettings( string font_family = _default_font_family, double font_size = _default_font_size, FontWeight font_weight = default, uint font_color = _default_font_color, - ColorOpacityProto? selection_highlight = null, IEnumerable columns = null, IEnumerable sorting_criterion = null, NullableColorProto? background_color = null, bool enable_background_color = false) { + ColorOpacityProto? selection_highlight = null, IEnumerable columns = null, IEnumerable sorting_criterion = null, uint background_color = 0, bool enable_background_color = false) { // _font_family = font_family; _font_size = font_size; @@ -97,7 +98,7 @@ namespace mbts.ui.settings { _selection_highlight = selection_highlight ?? new ColorOpacityProto(0, 1); _columns = new List(columns.empty_if_null()); _sorting_criterion = new List(sorting_criterion.empty_if_null()); - _background_color = background_color ?? new NullableColorProto(); + _background_color = background_color; _enable_background_color = enable_background_color; } @@ -106,7 +107,7 @@ namespace mbts.ui.settings { public uint font_color => _font_color; public FontWeight font_weight => FontWeight.FromOpenTypeWeight(_font_weight); public ColorOpacityProto selection_highlight => _selection_highlight; - public NullableColorProto background_color => _background_color; + public uint background_color => _background_color; public bool enable_background_color => _enable_background_color; public IReadOnlyList columns => _columns ?? (_columns = new List(0)); [Obsolete] // TODO: remove sorting_criterion from GridSettings entirely. This should be part of IShellWindow's StartupData, since it is an instance-specific setting, and prob not part of the shared defaults @@ -114,7 +115,7 @@ namespace mbts.ui.settings { public static GridSettings get_default() => new GridSettings(_default_font_family, _default_font_size, FontWeights.Normal, _default_font_color, new ColorOpacityProto(DIYGrid.DefaultSelectionHighlight.Color, DIYGrid.DefaultSelectionHighlight.Opacity), - background_color: new NullableColorProto()); + background_color: _default_background_color); public GridSettings with(IEnumerable columns = null, IEnumerable sorting_criterion = null, string font_family = null, double font_size = double.NaN, bool? enable_background_color = null) => new GridSettings( diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsManager.cs b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsManager.cs index bdf1e64f9..a006995f0 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsManager.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsManager.cs @@ -77,7 +77,7 @@ namespace mbts.ui { _font_size = backing(nameof(font_size), () => grid_settings.font_size, nameof(font_size)); _font_color = backing(nameof(font_color), () => grid_settings.font_color.rgb_solid_brush().frozen(), nameof(grid_settings)); _selection_highlight = backing(nameof(selection_highlight), () => grid_settings.selection_highlight.to_brush().frozen(), nameof(grid_settings)); - _background_color = backing(nameof(background_color), () => grid_settings.background_color.argb?.to_solid_brush().frozen(), nameof(grid_settings)); + _background_color = backing(nameof(background_color), () => grid_settings.background_color.argb_color().to_solid_brush().frozen(), nameof(grid_settings)); } public void Dispose() => @@ -114,7 +114,7 @@ namespace mbts.ui { var grid = value.general ?? GridSettings.Default; _grid_settings.set(grid); foreach (ColumnBase col in _columns) - col.set_fallback_font_params(new FontFamily(grid.font_family), grid.font_size, grid.font_color.rgb_color(), grid.font_weight, grid.background_color.argb); + col.set_fallback_font_params(new FontFamily(grid.font_family), grid.font_size, grid.font_color.rgb_color(), grid.font_weight, grid.background_color.argb_color()); _predicate_animations_data = value.predicate_animations; _animation_defs.clear(); foreach (var pa in _predicate_animations_data) { diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsVM.cs b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsVM.cs index cd3bea93a..38ae73a25 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsVM.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsVM.cs @@ -133,8 +133,7 @@ namespace mbts.spark { animation_map.AddOrUpdate(g.Key, p => animation_tuple(c: g), (p, t) => t.cell_animations.AddRange(g)); } return _create_settings_obj(new GridSettings(font_family.name(), font_size, font_weight, font_color.color.rgb_color(), selection_highlight.to_proto(), col_settings, - background_color: new NullableColorProto(background_color.color - .with((byte)(MathUtils.within_range(0, 1, background_color.opacity) * 255.0)))), + background_color: background_color.color.with((byte)(MathUtils.within_range(0, 1, background_color.opacity) * 255.0)).rgb_color()), animation_map.Select(kv => PredicateAnimations.create_data(kv.Key, kv.Value.cell_animations, kv.Value.row_animations, kv.Value.sounds))); // (List row_animations, List sounds, List cell_animations) animation_tuple(IEnumerable r = null, IEnumerable s = null, IGrouping c = null) => @@ -146,8 +145,8 @@ namespace mbts.spark { _font_weight.set(sd.general.font_weight); font_color.load_from(sd.general.font_color.rgb_solid_brush()); selection_highlight.load_from(sd.general.selection_highlight.to_brush()); - if (sd.general.background_color.value.HasValue) { - background_color.load_from(sd.general.background_color.argb.Value.to_solid_brush()); + if (sd.general.enable_background_color) { + background_color.load_from(sd.general.background_color.argb_color().to_solid_brush()); } _font_size.set(sd.general.font_size); var col_animations = new Dictionary>>(); diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsManager.cs b/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsManager.cs index 50a1cf7f7..d29df539d 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsManager.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsManager.cs @@ -35,7 +35,7 @@ namespace mbts.ui { _font_size = backing(nameof(font_size), () => grid_settings.font_size, nameof(font_size)); _font_color = backing(nameof(font_color), () => grid_settings.font_color.rgb_solid_brush().frozen(), nameof(grid_settings)); _selection_highlight = backing(nameof(selection_highlight), () => grid_settings.selection_highlight.to_brush().frozen(), nameof(grid_settings)); - _background_color = backing(nameof(background_color), () => grid_settings.background_color.argb?.to_solid_brush().frozen(), nameof(grid_settings)); + _background_color = backing(nameof(background_color), () => grid_settings.background_color.argb_color().to_solid_brush().frozen(), nameof(grid_settings)); _row_vms = row_vms; } @@ -88,7 +88,7 @@ namespace mbts.ui { grid = grid ?? GridSettings.Default; _grid_settings.set(grid); foreach (ColumnBase col in _columns) - col.set_fallback_font_params(new FontFamily(grid.font_family), grid.font_size, grid.font_color.rgb_color(), grid.font_weight, grid.background_color.argb); + col.set_fallback_font_params(new FontFamily(grid.font_family), grid.font_size, grid.font_color.rgb_color(), grid.font_weight, grid.background_color.argb_color()); // ** in the unfortunate event that we botch backwards compatability, and the columns don't bear a 1:1 relationship with the column-settings // don't add insult to injury by crashing ** if (grid_settings.columns != null) { diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs b/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs index 89ebfe4b6..0ff2b120c 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs @@ -109,8 +109,7 @@ namespace mbts.spark { public GridSettings create() => new GridSettings(font_family.name(), font_size, font_weight, font_color.color.rgb_color(), selection_highlight.to_proto(), columns.Select(c => c.create()), - background_color: new NullableColorProto(background_color.color - .with((byte)(MathUtils.within_range(0, 1, background_color.opacity) * 255.0)))); + background_color: background_color.color.with((byte)(MathUtils.within_range(0, 1, background_color.opacity) * 255.0)).rgb_color()); public void load_from(GridSettings value) { if (value == null) @@ -121,8 +120,8 @@ namespace mbts.spark { font_color.load_from(value.font_color.rgb_solid_brush()); selection_highlight.load_from(value.selection_highlight.to_brush()); _show_background_color.set(value.enable_background_color); - if (value.enable_background_color && value.background_color.argb.HasValue) { - background_color.load_from(value.background_color.argb.Value.to_solid_brush()); + if (value.enable_background_color) { + background_color.load_from(value.background_color.argb_color().to_solid_brush()); } _font_size.set(value.font_size); var curr_col_id = current_column?.id; From 6603e8ad86c5e722a438df6ea1affbc78119a1c4 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Thu, 15 Aug 2019 08:37:44 -0500 Subject: [PATCH 020/116] another sanitization spot --- src/client/spark/Modules/Market/MarketView/MarketViewWindow.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/spark/Modules/Market/MarketView/MarketViewWindow.cs b/src/client/spark/Modules/Market/MarketView/MarketViewWindow.cs index fe3520a6a..da46e6c8d 100644 --- a/src/client/spark/Modules/Market/MarketView/MarketViewWindow.cs +++ b/src/client/spark/Modules/Market/MarketView/MarketViewWindow.cs @@ -153,7 +153,7 @@ namespace mbts.spark { s => _vm.grid_settings_manager.create_vm( // we need to get the most up to date GridSettings when launching b/c users may // have changed some settings on the grid directly, like column widths. - s.with(_vm.columns.Select(c => c.create()), enable_background_color: true) + MarketViewWindowFactory.StartupData.sanitize(s).with(_vm.columns.Select(c => c.create())) ) ); vm.SubscribeDisposed(literal_title_source.OnDispatcher().Subscribe(t => vm.title = t)); From 0d4f97a02383fb19ba01fe8a9d5223f52ab01407 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Thu, 15 Aug 2019 09:11:47 -0500 Subject: [PATCH 021/116] visiblity of bg color Column-level override UI is now linked to GridSettings enable_background_color as well --- .../DIYGrid/Settings/GridSettingsView.xaml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsView.xaml b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsView.xaml index e525965b0..35a5ca3b9 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsView.xaml +++ b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsView.xaml @@ -674,14 +674,16 @@ Visibility="{Binding DataContext.current_column.is_font_color_overridden, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource AncestorType=usp:GridSettingsView}}" /> - Override Background Color - - + Override Background Color + + + + From d59f7a5bb1b70857cb797e90e273f53c99839b78 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Thu, 15 Aug 2019 10:32:32 -0500 Subject: [PATCH 022/116] new alpha-compliant ColorPickerPopupVM from John --- .../ColorPicker/ColorPickerPopup.xaml.cs | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/client/spark/view/Controls/ColorPicker/ColorPickerPopup.xaml.cs b/src/client/spark/view/Controls/ColorPicker/ColorPickerPopup.xaml.cs index e893b053c..a55734853 100644 --- a/src/client/spark/view/Controls/ColorPicker/ColorPickerPopup.xaml.cs +++ b/src/client/spark/view/Controls/ColorPicker/ColorPickerPopup.xaml.cs @@ -1,7 +1,9 @@ using bts.proto; +using bts.utils; using mbts.spark; using mbts.ui.controls.color_picker; using mbts.ui.shell; +using System; using System.Collections.ObjectModel; using System.Linq; using System.Windows; @@ -38,16 +40,42 @@ namespace mbts.ui.controls { class ColorPickerPopupVM : ViewModelBase, IValueFactory { readonly Property _color; readonly Property _opacity; + ObservableCollection _palettes; + bool _bind_opacity_to_alpha; + IDisposable _opacity_alpha_binding; public ColorPickerPopupVM() { _color = backing(nameof(color), Colors.Black); _opacity = backing(nameof(opacity), 1.0); - palettes = new ObservableCollection(ColorPalette.all_presets().Select(p => new ColorPaletteVM(p))); } public Color color { get => _color.Value; set => _color.set(value); } public double opacity { get => _opacity.Value; set => _opacity.set(value); } - public ObservableCollection palettes { get; } + public ObservableCollection palettes => _palettes ?? (_palettes = new ObservableCollection(ColorPalette.all_presets().Select(p => new ColorPaletteVM(p)))); + public bool bind_opacity_to_alpha { + get => _bind_opacity_to_alpha; + set { + if (_bind_opacity_to_alpha != value) { + Disposable.dispose(ref _opacity_alpha_binding); + _bind_opacity_to_alpha = value; + if (value) { + _opacity.Changed += opacity_changed; + _color.Changed += color_changed; + color_changed(default, color); + void opacity_changed(double oldval, double newval) { + _color.Changed -= color_changed; + _color.set(color.with((byte)(MathUtils.within_range(0, 1, newval) * 255.0))); + _color.Changed += color_changed; + } + void color_changed(Color oldval, Color newval) { + _opacity.Changed -= opacity_changed; + _opacity.set(newval.A / 255.0); + _opacity.Changed += opacity_changed; + } + } + } + } + } public SolidColorBrush create() => new SolidColorBrush(color) { Opacity = opacity }.frozen(); public void load_from(SolidColorBrush brush) { From c222181730231221ae5c4f700b5a68a25184581c Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Thu, 15 Aug 2019 10:33:42 -0500 Subject: [PATCH 023/116] ColorOpacityProto can now spit out a Color with the appropriate alpha bytes --- src/client/spark/core/data/Proto/ColorOpacityProto.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/client/spark/core/data/Proto/ColorOpacityProto.cs b/src/client/spark/core/data/Proto/ColorOpacityProto.cs index c67e51d37..b5d69b2d6 100644 --- a/src/client/spark/core/data/Proto/ColorOpacityProto.cs +++ b/src/client/spark/core/data/Proto/ColorOpacityProto.cs @@ -22,6 +22,7 @@ namespace bts.proto { } public Color color => _color.rgb_color(); + public Color argb_color => Color.FromArgb((byte)(MathUtils.within_range(0, 1, _opacity) * 255.0), color.R, color.G, color.B); public double opacity => _opacity; public ColorOpacityProto with(uint? color = null, double? opacity = null) => From 14f2ae481a0ef029640381e97f33472ebcdce7a4 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Thu, 15 Aug 2019 10:34:31 -0500 Subject: [PATCH 024/116] selection highlight and background color picker popupsnow make use of the new alpha hotness --- .../Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs b/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs index 0ff2b120c..9bb6232ca 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs @@ -80,8 +80,8 @@ namespace mbts.spark { public FontFamily font_family { get => _font_family.Value; set => _font_family.set(value); } public FontWeight font_weight { get => _font_weight.Value; set => _font_weight.set(value); } public ColorPickerPopupVM font_color { get; } = new ColorPickerPopupVM(); - public ColorPickerPopupVM selection_highlight { get; } = new ColorPickerPopupVM(); - public ColorPickerPopupVM background_color { get; } = new ColorPickerPopupVM(); + public ColorPickerPopupVM selection_highlight { get; } = new ColorPickerPopupVM(){ bind_opacity_to_alpha = true }; + public ColorPickerPopupVM background_color { get; } = new ColorPickerPopupVM() { bind_opacity_to_alpha = true }; public bool show_background_color => _show_background_color.Value; public double font_size { get => _font_size.Value; set => _font_size.set(value); } public bool enable_sound_triggers => false; @@ -118,10 +118,10 @@ namespace mbts.spark { _font_family.set(new FontFamily(value.font_family)); _font_weight.set(value.font_weight); font_color.load_from(value.font_color.rgb_solid_brush()); - selection_highlight.load_from(value.selection_highlight.to_brush()); + selection_highlight.color = value.selection_highlight.argb_color; _show_background_color.set(value.enable_background_color); if (value.enable_background_color) { - background_color.load_from(value.background_color.argb_color().to_solid_brush()); + background_color.color = value.background_color.argb_color(); } _font_size.set(value.font_size); var curr_col_id = current_column?.id; From ad819dca681960d02173bbbb0e01291e4290e3df Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Thu, 15 Aug 2019 13:27:04 -0500 Subject: [PATCH 025/116] can just use rgb_color() now that Popup is in alpha enabled mode --- .../view/Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs b/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs index 9bb6232ca..93b4c2552 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs @@ -109,7 +109,7 @@ namespace mbts.spark { public GridSettings create() => new GridSettings(font_family.name(), font_size, font_weight, font_color.color.rgb_color(), selection_highlight.to_proto(), columns.Select(c => c.create()), - background_color: background_color.color.with((byte)(MathUtils.within_range(0, 1, background_color.opacity) * 255.0)).rgb_color()); + background_color: background_color.color.rgb_color()); public void load_from(GridSettings value) { if (value == null) From 2e831aa90e93daa9f71a4bd197330174c7011ba9 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Thu, 15 Aug 2019 13:27:29 -0500 Subject: [PATCH 026/116] fixing alpha in column-level background override --- .../view/Controls/DIYGrid/Settings/GridColumnSettings.cs | 4 ++-- .../view/Controls/DIYGrid/Settings/GridColumnSettingsVM.cs | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/GridColumnSettings.cs b/src/client/spark/view/Controls/DIYGrid/Settings/GridColumnSettings.cs index 770e7e52c..5b1dc0184 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/GridColumnSettings.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/GridColumnSettings.cs @@ -94,7 +94,7 @@ namespace mbts.ui.settings { public HorizontalAlignment horizontal_alignment => _horizontal_alignment; public double horizontal_offset => _horizontal_offset; public string display_name => _display_name; - public Color? background_color_override => _background_color_override.value; + public Color? background_color_override => _background_color_override.argb; public GridColumnSettings with( string display_name = null, bool? is_visible = null, bool? is_collapsed = null, NullableFontWeightProto? font_weight_override = null, NullableColorProto? font_color_override = null, @@ -109,7 +109,7 @@ namespace mbts.ui.settings { width ?? this.width, horizontal_alignment ?? this.horizontal_alignment, horizontal_offset ?? this.horizontal_offset, - (background_color_override ?? _background_color_override).value); + (background_color_override ?? _background_color_override).argb); public bool Equals(GridColumnSettings other) => other != null && diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/GridColumnSettingsVM.cs b/src/client/spark/view/Controls/DIYGrid/Settings/GridColumnSettingsVM.cs index dcb799b83..0f59769b2 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/GridColumnSettingsVM.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/GridColumnSettingsVM.cs @@ -84,7 +84,7 @@ namespace mbts.spark { // background color override public bool can_override_background_color { get => _can_override_background_color; private set => Set(ref _can_override_background_color, value); } public bool is_background_color_overridden { get => _is_background_color_overridden; set => Set(ref _is_background_color_overridden, value); } - public ColorPickerPopupVM background_color_override { get; } = new ColorPickerPopupVM(); + public ColorPickerPopupVM background_color_override { get; } = new ColorPickerPopupVM() { bind_opacity_to_alpha = true }; // animations public ObservableEditableCollection predicate_animations { get; } @@ -123,10 +123,7 @@ namespace mbts.spark { // background color is_background_color_overridden = _settings.background_color_override.HasValue; if (is_background_color_overridden) { - background_color_override.load_from( - new SolidColorBrush(_settings.background_color_override.Value) { - //Opacity = _settings.background_color_override.Value.opacity - }); + background_color_override.color = _settings.background_color_override.Value; } predicate_animations.SetItems(value.animations.empty_if_null().Select(g => { var vm = new PredicateCellAnimationVM(id, owner._create_column_predicate_vm(id), owner._predicate_data_factory); From 6b97d559275a1cbbcbb61c8d5b8641f145a0d209 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Thu, 15 Aug 2019 14:09:47 -0500 Subject: [PATCH 027/116] adding show_background_color to main GridSettingsVM so that OB bg color settings are kept hidden for now; misc comment --- .../view/Controls/DIYGrid/Settings/GridSettingsVM.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsVM.cs b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsVM.cs index 38ae73a25..0d575483f 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsVM.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsVM.cs @@ -57,7 +57,7 @@ namespace mbts.spark { readonly Property _font_weight; readonly Property _font_display_name; readonly Property _font_size; - readonly Property _show_predicate_animations, _show_cell_predicate_animations; + readonly Property _show_predicate_animations, _show_cell_predicate_animations, _show_background_color; readonly OrdersModel _orders_model; readonly IReadOnlyDictionary _column_flags; @@ -84,6 +84,7 @@ namespace mbts.spark { _font_display_name = backing(nameof(font_display_name), () => TextUtils.display_name(font_family, font_size), new[] { nameof(font_family), nameof(font_size) }); _show_predicate_animations = backing(nameof(show_predicate_animations), true); _show_cell_predicate_animations = backing(nameof(show_cell_predicate_animations), true); + _show_background_color = backing(nameof(show_background_color), false); _current_column = backing(nameof(current_column)); predicate_animations = new ObservableEditableCollection(() => new PredicateRowAnimationVM(_create_predicate_vm(), _predicate_data_factory), true); @@ -102,6 +103,7 @@ namespace mbts.spark { public ColorPickerPopupVM font_color { get; } = new ColorPickerPopupVM(); public ColorPickerPopupVM selection_highlight { get; } = new ColorPickerPopupVM(); public ColorPickerPopupVM background_color { get; } = new ColorPickerPopupVM(); + public bool show_background_color => _show_background_color.Value; public double font_size { get => _font_size.Value; set => _font_size.set(value); } public bool enable_sound_triggers => true; public bool show_predicate_animations { get => _show_predicate_animations.Value; set => _show_predicate_animations.set(value); } @@ -145,7 +147,12 @@ namespace mbts.spark { _font_weight.set(sd.general.font_weight); font_color.load_from(sd.general.font_color.rgb_solid_brush()); selection_highlight.load_from(sd.general.selection_highlight.to_brush()); + _show_background_color.set(sd.general.enable_background_color); if (sd.general.enable_background_color) { + // note that when the OB is moved to allow background colors + // we can just background_color.color instead of load_from + // so that we get all the alpha goodness similar to SimpleGridSettingsVM + // assuming bind_opacity_to_alpha on the picker. background_color.load_from(sd.general.background_color.argb_color().to_solid_brush()); } _font_size.set(sd.general.font_size); From 0a1cf0198df888bccc18da68c9c4368e8097e25d Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Thu, 15 Aug 2019 14:20:59 -0500 Subject: [PATCH 028/116] sending my NullableColorOpacityProto to /dev/null --- .../data/Proto/NullableColorOpacityProto.cs | 45 ------------------- 1 file changed, 45 deletions(-) delete mode 100644 src/client/spark/core/data/Proto/NullableColorOpacityProto.cs diff --git a/src/client/spark/core/data/Proto/NullableColorOpacityProto.cs b/src/client/spark/core/data/Proto/NullableColorOpacityProto.cs deleted file mode 100644 index 77344d6a3..000000000 --- a/src/client/spark/core/data/Proto/NullableColorOpacityProto.cs +++ /dev/null @@ -1,45 +0,0 @@ -using bts.utils; -using mbts.ui; -using mbts.utils; -using ProtoBuf; -using System; -using System.Windows.Media; - -namespace bts.proto { - [ProtoContract] - struct NullableColorOpacityProto : IEquatable { - [ProtoMember(1)] - readonly uint? _color; - [ProtoMember(2)] - readonly double? _opacity; - - public NullableColorOpacityProto(ColorOpacityProto? cop = default) { - _color = cop?.color.rgb_color(); - _opacity = cop?.opacity; - } - - public ColorOpacityProto? value { - get { - if (_color.HasValue && _opacity.HasValue) - return new ColorOpacityProto(_color.Value, _opacity.Value); - return null; - } - } - - public bool Equals(NullableColorOpacityProto other) => - EqualityComparer.nullable_equals(_color, other._color) && - EqualityComparer.nullable_equals(_opacity, other._opacity); - - public override bool Equals(object obj) => - obj is NullableColorProto ncp && Equals(ncp); - - public override int GetHashCode() { - uint c = _color.HasValue ? _color.Value : 0; - double o = _opacity.HasValue ? _opacity.Value : 0; - return EqualityComparer.aggregate_hash(c, o); - } - - public static bool operator ==(NullableColorOpacityProto a, NullableColorOpacityProto b) => a.Equals(b); - public static bool operator !=(NullableColorOpacityProto a, NullableColorOpacityProto b) => !a.Equals(b); - } -} \ No newline at end of file From c4866253b86b83d8b506bbee230eb6669ee31d57 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Thu, 15 Aug 2019 15:14:33 -0500 Subject: [PATCH 029/116] need a KeyUp here --- .../spark/view/Extensions/UIElementExtensions.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/client/spark/view/Extensions/UIElementExtensions.cs b/src/client/spark/view/Extensions/UIElementExtensions.cs index 1a338ed9f..cc3e67da3 100644 --- a/src/client/spark/view/Extensions/UIElementExtensions.cs +++ b/src/client/spark/view/Extensions/UIElementExtensions.cs @@ -156,6 +156,19 @@ namespace mbts.ui.extensions { } } + public static IDisposable SubscribePreviewKeyUp(this UIElement target, KeyEventHandler callback) { + target.PreviewKeyUp += callback; + return Disposable.Create(() => target.PreviewKeyUp -= callback); + } + + public static IDisposable SubscribePreviewKeyUp(this UIElement target, Key key, Action callback) { + return SubscribePreviewKeyUp(target, on_preview_key_up); + void on_preview_key_up(object sender, KeyEventArgs e) { + if (e.Key == key) + callback(); + } + } + public static IObservable SubscribePreviewKeyDown(this UIElement target) => Observable.Create(o => { target.PreviewKeyDown += on_preview_key_down; From fe179d44f2019d264264166d0d75b9d0c986715d Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Thu, 15 Aug 2019 15:15:07 -0500 Subject: [PATCH 030/116] RowSelectionAdorner now responds to KeyUp (CTRL-A for example) --- src/client/spark/view/Controls/Adorners/RowSelectionAdorner.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/client/spark/view/Controls/Adorners/RowSelectionAdorner.cs b/src/client/spark/view/Controls/Adorners/RowSelectionAdorner.cs index c7625c654..7e59c46e0 100644 --- a/src/client/spark/view/Controls/Adorners/RowSelectionAdorner.cs +++ b/src/client/spark/view/Controls/Adorners/RowSelectionAdorner.cs @@ -58,6 +58,8 @@ namespace mbts.ui.controls.adorners { _disposables.Add(_diy_rp.SubscribePreviewMouseDown((s, e) => InvalidateVisual())); // the main event _disposables.Add(_diy_rp.SubscribePreviewMouseUp((s, e) => InvalidateVisual())); + // so that we update for potential mass keyboard combinations (CTRL-A) + _disposables.Add(_diy_rp.SubscribePreviewKeyUp((s, e) => InvalidateVisual())); // so that we update the highlight as the grid scrolls _disposables.Add(_diy_scroll.SubscribeScrollChanged((s, e) => InvalidateVisual())); } From ec4f88c68fe25711edea01d9fb5dd015be693a5d Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Thu, 15 Aug 2019 15:48:59 -0500 Subject: [PATCH 031/116] having row selection adorner reactor to selection changed events rather than key|mouse up|down --- .../spark/view/Controls/Adorners/RowSelectionAdorner.cs | 8 ++------ src/client/spark/view/Extensions/UIElementExtensions.cs | 7 +++++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/client/spark/view/Controls/Adorners/RowSelectionAdorner.cs b/src/client/spark/view/Controls/Adorners/RowSelectionAdorner.cs index 7e59c46e0..688be814d 100644 --- a/src/client/spark/view/Controls/Adorners/RowSelectionAdorner.cs +++ b/src/client/spark/view/Controls/Adorners/RowSelectionAdorner.cs @@ -54,12 +54,8 @@ namespace mbts.ui.controls.adorners { _diy_scroll = scroll_viewer; _diy_scp = _diy_rp.descendants_of_type().empty_if_null().FirstOrDefault(); - // so that we clear out any previously selected highlighted rows - _disposables.Add(_diy_rp.SubscribePreviewMouseDown((s, e) => InvalidateVisual())); - // the main event - _disposables.Add(_diy_rp.SubscribePreviewMouseUp((s, e) => InvalidateVisual())); - // so that we update for potential mass keyboard combinations (CTRL-A) - _disposables.Add(_diy_rp.SubscribePreviewKeyUp((s, e) => InvalidateVisual())); + // We actually don't need mouse up/down or key up/down when we can just respond to selection changes + _disposables.Add(((System.Windows.Controls.Primitives.Selector)_diy_rp).SubscribeSelectionChanged((s, e) => InvalidateVisual())); // so that we update the highlight as the grid scrolls _disposables.Add(_diy_scroll.SubscribeScrollChanged((s, e) => InvalidateVisual())); } diff --git a/src/client/spark/view/Extensions/UIElementExtensions.cs b/src/client/spark/view/Extensions/UIElementExtensions.cs index cc3e67da3..4a1096d23 100644 --- a/src/client/spark/view/Extensions/UIElementExtensions.cs +++ b/src/client/spark/view/Extensions/UIElementExtensions.cs @@ -210,6 +210,13 @@ namespace mbts.ui.extensions { } } + public static class SelectorExtensions { + public static IDisposable SubscribeSelectionChanged(this System.Windows.Controls.Primitives.Selector target, SelectionChangedEventHandler callback) { + target.SelectionChanged += callback; + return Disposable.Create(() => target.SelectionChanged -= callback); + } + } + public static class ScrollViewerExtensions { public static IDisposable SubscribeScrollChanged(this ScrollViewer target, ScrollChangedEventHandler callback) { target.ScrollChanged += callback; From 5e0f1d450cb3d769bd1fc5a2a473315e98ebf4b5 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Thu, 15 Aug 2019 15:49:26 -0500 Subject: [PATCH 032/116] removing unused property --- src/client/spark/view/Controls/DIYGrid/DIYGrid.cs | 2 -- src/client/spark/view/Controls/DIYGrid/Settings/GridSettings.cs | 1 - 2 files changed, 3 deletions(-) diff --git a/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs b/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs index bfab02f71..5cfc7ccbe 100644 --- a/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs +++ b/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs @@ -254,8 +254,6 @@ namespace mbts.ui.controls { // and FrameworkElementColumns that paint the selection brush themselves // (e.g MarketView bid/ask columns, bc their background is not transparent, it covers the ListBoxItem selection-highlight). public static readonly SolidColorBrush DefaultSelectionHighlight = new SolidColorBrush(Colors.MediumSlateBlue) { Opacity = 0.4 }; - // I have no idea why DefaultBackgroundColor needs to be frozen but DefaultSelectionHighlight is apparently fine as is - public static readonly SolidColorBrush DefaultBackgroundColor = null; //new SolidColorBrush(BTSColors.Grid.input_cell_background) { Opacity = 0.40 }.frozen(); public static readonly Pen DefaultSelectionStroke = new Pen(Brushes.MediumSlateBlue, 1); readonly NotifyCollectionChangedEventHandler _sort_descriptions_collection_changed_cb; double _inactive_selection_opacity = 0.2; diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettings.cs b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettings.cs index 8459ba17d..c125d1368 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettings.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettings.cs @@ -43,7 +43,6 @@ namespace mbts.ui.settings { public static Color font_color => _default_font_color.rgb_color(); public static FontWeight font_weight => FontWeight.FromOpenTypeWeight(_default_font_weight); public static SolidColorBrush selection_highlight => DIYGrid.DefaultSelectionHighlight; - public static SolidColorBrush background_color => DIYGrid.DefaultBackgroundColor; } public static IValueConverter selection_highlight_converter => ValueConverter.create(gs => gs.selection_highlight.to_brush().frozen()); From 133581303177791316c9656b1061de9a02c07cca Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Tue, 20 Aug 2019 10:10:30 -0500 Subject: [PATCH 033/116] bringing order to Workspaces dialog UI --- .../Workspaces/WorkspacesDialogView.xaml | 92 +++++++++---------- 1 file changed, 43 insertions(+), 49 deletions(-) diff --git a/src/client/spark/view/Shell/Workspaces/WorkspacesDialogView.xaml b/src/client/spark/view/Shell/Workspaces/WorkspacesDialogView.xaml index 38f388d91..a3fd90db6 100644 --- a/src/client/spark/view/Shell/Workspaces/WorkspacesDialogView.xaml +++ b/src/client/spark/view/Shell/Workspaces/WorkspacesDialogView.xaml @@ -14,53 +14,47 @@ Style="{StaticResource BTSDialog}" Title="Workspaces" > - - - - - - - - - - - - - - - - - - - - - - Save Current Workspace As: - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From ed10545d8a10c147069fe279a017567934ab6e8d Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Tue, 20 Aug 2019 10:12:41 -0500 Subject: [PATCH 034/116] Removing no longer valid VisualState changes --- .../Shell/Workspaces/WorkspaceViewModel.cs | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/src/client/spark/view/Shell/Workspaces/WorkspaceViewModel.cs b/src/client/spark/view/Shell/Workspaces/WorkspaceViewModel.cs index 49bb41138..476e6a438 100644 --- a/src/client/spark/view/Shell/Workspaces/WorkspaceViewModel.cs +++ b/src/client/spark/view/Shell/Workspaces/WorkspaceViewModel.cs @@ -9,8 +9,6 @@ namespace mbts.ui.shell { public class WorkspaceViewModel : ViewModelBase { - private const string INITIAL_VISUAL_STATE = "Normal"; - WorkspacesModel _parent; public WorkspaceViewModel(WorkspacesModel parent, string name, WorkspaceDefinition definition) { _parent = parent; @@ -24,24 +22,6 @@ namespace mbts.ui.shell get { return Icons.Window; } } - private string _vstate = INITIAL_VISUAL_STATE; - public string VisualState { - get { - // this unconventional getter acts as a reset after the VisualStateManager has played - // i.e. if we overwrite a workspace then save, then close the window, when we open the - // window back up, we'll see item animate b/c it has never been reset from the animate - // state. This is necessary b/c the lifetime of Workspaces is not tied to the lifetime - // of the View, rather it lives in the Model and is only instantiated on startup via MEF - var return_val = _vstate; - _vstate = INITIAL_VISUAL_STATE; - return return_val; - } - set { - _vstate = value; - RaisePropertyChanged("VisualState"); - } - } - internal WorkspaceDefinition Definition { get; private set; } public ICommand ActivateCommand { From 02062ee07b3a46653bcaee6e4b9861b400d5520c Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Tue, 20 Aug 2019 10:13:40 -0500 Subject: [PATCH 035/116] removing commands --- .../view/Shell/Workspaces/WorkspaceViewModel.cs | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/client/spark/view/Shell/Workspaces/WorkspaceViewModel.cs b/src/client/spark/view/Shell/Workspaces/WorkspaceViewModel.cs index 476e6a438..054c7b922 100644 --- a/src/client/spark/view/Shell/Workspaces/WorkspaceViewModel.cs +++ b/src/client/spark/view/Shell/Workspaces/WorkspaceViewModel.cs @@ -23,21 +23,5 @@ namespace mbts.ui.shell } internal WorkspaceDefinition Definition { get; private set; } - - public ICommand ActivateCommand { - get { - return new DelegateCommand(param => { - var unused = _parent.load_workspace(Definition, Name); - }); - } - } - - public ICommand DeleteCommand { - get { - return new DelegateCommand(param => { - _parent.delete_workspace(Name, Definition); - }); - } - } } } From 4e789388278ab77baa781e3f08ebebafb054149e Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Tue, 20 Aug 2019 10:14:45 -0500 Subject: [PATCH 036/116] adding last_save_lldatetime ulong to proto; populing said field in save_workspace --- src/client/spark/view/Shell/Workspaces/WorkspacesModel.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/client/spark/view/Shell/Workspaces/WorkspacesModel.cs b/src/client/spark/view/Shell/Workspaces/WorkspacesModel.cs index 867c34b18..7f55387d7 100644 --- a/src/client/spark/view/Shell/Workspaces/WorkspacesModel.cs +++ b/src/client/spark/view/Shell/Workspaces/WorkspacesModel.cs @@ -179,6 +179,7 @@ namespace mbts.ui.shell public void save_workspace(string name, bool persist=true, bool ispublic=false) { WorkspaceDefinition workspace = get_workspace(); workspace.is_shared = ispublic; + workspace.last_save_lldatetime = LLDateTime.now().value; if (ispublic) { name += SHARED_MONIKER; } // Remove the old one if a workspace by this name exists already @@ -282,5 +283,8 @@ namespace mbts.ui.shell [ProtoMember(10, IsRequired = false)] public bool is_shared { get; set; } + [ProtoMember(11, IsRequired = false)] + public ulong last_save_lldatetime { get; set; } + } } From aa3dda2c574ae76326e62c809907feeb36da16aa Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Tue, 20 Aug 2019 10:15:34 -0500 Subject: [PATCH 037/116] adding DisplayName property that displays last save info if available --- src/client/spark/view/Shell/Workspaces/WorkspaceViewModel.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/client/spark/view/Shell/Workspaces/WorkspaceViewModel.cs b/src/client/spark/view/Shell/Workspaces/WorkspaceViewModel.cs index 054c7b922..baf9b6f6d 100644 --- a/src/client/spark/view/Shell/Workspaces/WorkspaceViewModel.cs +++ b/src/client/spark/view/Shell/Workspaces/WorkspaceViewModel.cs @@ -1,4 +1,5 @@ -using System; +using mbts.utils; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -17,6 +18,7 @@ namespace mbts.ui.shell } public string Name { get; private set; } + public string DisplayName => Definition.last_save_lldatetime > 0 ? $"{Name} - {Definition.last_save_lldatetime.lldatetime().ToLocalTime()}" : Name; public bool IsShared { get { return Definition.is_shared; } } public object Icon { get { return Icons.Window; } From a8cd07e4d4541f3db0c48aebb1bf2da9fa572d70 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Tue, 20 Aug 2019 10:16:21 -0500 Subject: [PATCH 038/116] relocating commands here, adding confirmations, etc --- .../Workspaces/WorkspacesDialogViewModel.cs | 75 ++++++++++++++----- 1 file changed, 58 insertions(+), 17 deletions(-) diff --git a/src/client/spark/view/Shell/Workspaces/WorkspacesDialogViewModel.cs b/src/client/spark/view/Shell/Workspaces/WorkspacesDialogViewModel.cs index 80282e25e..3c2f01901 100644 --- a/src/client/spark/view/Shell/Workspaces/WorkspacesDialogViewModel.cs +++ b/src/client/spark/view/Shell/Workspaces/WorkspacesDialogViewModel.cs @@ -8,12 +8,15 @@ using System.Threading.Tasks; using mbts; using mbts.ui; using mbts.ui.shell; +using bts.spark; +using System.Windows; namespace mbts.ui.shell { public class WorkspacesDialogViewModel : ViewModelBaseWithValidation { private WorkspacesModel _work_model; + IRaiseCanExecuteChangedCommand _load_command, _delete_command, _save_command; public WorkspacesDialogViewModel(WorkspacesModel wm) { @@ -25,36 +28,74 @@ namespace mbts.ui.shell public bool IsPublicWorkspace { get; set; } public bool ShowWorkspaces { get; set; } - public ICommand SaveWorkspace + WorkspaceViewModel _selected_workspace; + public WorkspaceViewModel selected_workspace { + get => _selected_workspace; + set { + if (Set(ref _selected_workspace, value)) { + LoadCommand.TryRaiseCanExecuteChanged(); + DeleteCommand.TryRaiseCanExecuteChanged(); + SaveCommand.TryRaiseCanExecuteChanged(); + } + } + } + + private bool _command_can_execute() => selected_workspace != null; + private void _clear_error_state() => clear_error(nameof(SaveName)); + + public ICommand LoadCommand => _load_command ?? + (_load_command = new DelegateCommand( + () => { + _work_model.load_workspace(selected_workspace.Definition, selected_workspace.Name).ignore(); + _clear_error_state(); + }, _command_can_execute)); + public ICommand DeleteCommand => _delete_command ?? + (_delete_command = new DelegateCommand( + () => { + if (BTSMessageBox.Show( + $"Are you sure you with to delete the {selected_workspace.Name} workspace?", + "Delete Existing Workspace", + BTSMessageBoxButtons.Yes | BTSMessageBoxButtons.No + , MessageBoxImage.Question) == BTSMessageBoxButtons.Yes) { + _work_model.delete_workspace(selected_workspace.Name, selected_workspace.Definition).ignore(); + _clear_error_state(); + } + }, _command_can_execute)); + public ICommand SaveCommand => _save_command ?? + (_save_command = new DelegateCommand( + () => { + if (BTSMessageBox.Show( + $"Overwrite {selected_workspace.Name} with current layout?", + "Save Existing Workspace", + BTSMessageBoxButtons.Yes | BTSMessageBoxButtons.No + , MessageBoxImage.Question) == BTSMessageBoxButtons.Yes) { + _work_model.save_workspace(selected_workspace.Name, ispublic:selected_workspace.Definition.is_shared); + _clear_error_state(); + } + }, _command_can_execute)); + + public ICommand SaveNewWorkspace { get { return new DelegateCommand(arg => { + _clear_error_state(); // Check for errors in the input - if (string.IsNullOrEmpty(SaveName)) - { - set_error("SaveName", "Workspace must be named"); + if (string.IsNullOrEmpty(SaveName)) { + set_error(nameof(SaveName), "Workspace must be named"); return; } - if (SaveName.Contains(WorkspacesModel.ACTIVE_WORKSPACE_PREFIX)) - { - set_error("SaveName", "Workspace name cannot contains '{0}'".fmt(WorkspacesModel.ACTIVE_WORKSPACE_PREFIX)); + if (SaveName.Contains(WorkspacesModel.ACTIVE_WORKSPACE_PREFIX)) { + set_error(nameof(SaveName), "Workspace name cannot contains '{0}'".fmt(WorkspacesModel.ACTIVE_WORKSPACE_PREFIX)); return; } - else - { - clear_error("SaveName"); + if (Workspaces.Any(x => x.Name.Replace(WorkspacesModel.SHARED_MONIKER, string.Empty) == SaveName && x.IsShared == IsPublicWorkspace)) { + set_error(nameof(SaveName), $"Workspace already exists '{SaveName}'"); + return; } - var save_candidate_already_exists = Workspaces.Any(x => x.Name.Replace(WorkspacesModel.SHARED_MONIKER, string.Empty) == SaveName && x.IsShared == IsPublicWorkspace); - // Save _work_model.save_workspace(SaveName, ispublic: IsPublicWorkspace); - - // if we just overwrote something, have the vm reflect it - if (save_candidate_already_exists) - Workspaces.Where(x => x.Name.Replace(WorkspacesModel.SHARED_MONIKER, string.Empty) == SaveName && x.IsShared == IsPublicWorkspace).ForEach(x => x.VisualState = "Overridden"); }); } } - } } From 9a13fb36260fa5d70878b762622677aa8560e3bc Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Tue, 20 Aug 2019 13:00:39 -0500 Subject: [PATCH 039/116] adding LastSaveTime to VM for use in UI --- src/client/spark/view/Shell/Workspaces/WorkspaceViewModel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/spark/view/Shell/Workspaces/WorkspaceViewModel.cs b/src/client/spark/view/Shell/Workspaces/WorkspaceViewModel.cs index baf9b6f6d..a25bcc6ea 100644 --- a/src/client/spark/view/Shell/Workspaces/WorkspaceViewModel.cs +++ b/src/client/spark/view/Shell/Workspaces/WorkspaceViewModel.cs @@ -18,7 +18,7 @@ namespace mbts.ui.shell } public string Name { get; private set; } - public string DisplayName => Definition.last_save_lldatetime > 0 ? $"{Name} - {Definition.last_save_lldatetime.lldatetime().ToLocalTime()}" : Name; + public string LastSaveTime => Definition.last_save_lldatetime > 0 ? Definition.last_save_lldatetime.lldatetime().ToLocalTime().ToString() : string.Empty; public bool IsShared { get { return Definition.is_shared; } } public object Icon { get { return Icons.Window; } From 380d263c5ee3f72bd0d518fe8dbdac137ea787cd Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Tue, 20 Aug 2019 13:01:09 -0500 Subject: [PATCH 040/116] stylizing ComboBox for a 2 column layout --- .../Workspaces/WorkspacesDialogView.xaml | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/client/spark/view/Shell/Workspaces/WorkspacesDialogView.xaml b/src/client/spark/view/Shell/Workspaces/WorkspacesDialogView.xaml index a3fd90db6..06e7524af 100644 --- a/src/client/spark/view/Shell/Workspaces/WorkspacesDialogView.xaml +++ b/src/client/spark/view/Shell/Workspaces/WorkspacesDialogView.xaml @@ -31,7 +31,45 @@ - + + + + + + + + + + From b2be4c58c4767ab2bee010ab318bf46a8c0da881 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Tue, 20 Aug 2019 13:43:10 -0500 Subject: [PATCH 041/116] Workspaces ComboBox now has a table-like appearance --- .../Workspaces/WorkspacesDialogView.xaml | 65 ++++++++----------- 1 file changed, 28 insertions(+), 37 deletions(-) diff --git a/src/client/spark/view/Shell/Workspaces/WorkspacesDialogView.xaml b/src/client/spark/view/Shell/Workspaces/WorkspacesDialogView.xaml index 06e7524af..275c295fc 100644 --- a/src/client/spark/view/Shell/Workspaces/WorkspacesDialogView.xaml +++ b/src/client/spark/view/Shell/Workspaces/WorkspacesDialogView.xaml @@ -31,44 +31,35 @@ - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + From e8b1786411d348b281c47fc974de7e882ab85c6d Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Tue, 20 Aug 2019 14:24:07 -0500 Subject: [PATCH 042/116] splitting date and time in UI into separate columns; formatting DateTime is now done in Style --- .../Shell/Workspaces/WorkspaceViewModel.cs | 2 +- .../Workspaces/WorkspacesDialogView.xaml | 42 +++++++++++++++---- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/client/spark/view/Shell/Workspaces/WorkspaceViewModel.cs b/src/client/spark/view/Shell/Workspaces/WorkspaceViewModel.cs index a25bcc6ea..0ce33b9eb 100644 --- a/src/client/spark/view/Shell/Workspaces/WorkspaceViewModel.cs +++ b/src/client/spark/view/Shell/Workspaces/WorkspaceViewModel.cs @@ -18,7 +18,7 @@ namespace mbts.ui.shell } public string Name { get; private set; } - public string LastSaveTime => Definition.last_save_lldatetime > 0 ? Definition.last_save_lldatetime.lldatetime().ToLocalTime().ToString() : string.Empty; + public DateTime LastSaveTime => Definition.last_save_lldatetime.lldatetime().ToLocalTime(); public bool IsShared { get { return Definition.is_shared; } } public object Icon { get { return Icons.Window; } diff --git a/src/client/spark/view/Shell/Workspaces/WorkspacesDialogView.xaml b/src/client/spark/view/Shell/Workspaces/WorkspacesDialogView.xaml index 275c295fc..be390baef 100644 --- a/src/client/spark/view/Shell/Workspaces/WorkspacesDialogView.xaml +++ b/src/client/spark/view/Shell/Workspaces/WorkspacesDialogView.xaml @@ -6,6 +6,7 @@ xmlns:local="clr-namespace:mbts.ui.shell" mc:Ignorable="d" xmlns:controls="clr-namespace:mbts.ui.controls" + xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:ui="clr-namespace:mbts.ui" Width="250" MaxHeight="700" @@ -31,32 +32,59 @@ - + - + - + + + - + - + - + + + - + + + + + + + + + + From 8d5715d51079545d15d42c6f4aed5b39295a29d9 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Tue, 20 Aug 2019 14:37:29 -0500 Subject: [PATCH 043/116] adding comment --- .../spark/view/Shell/Workspaces/WorkspacesDialogView.xaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/client/spark/view/Shell/Workspaces/WorkspacesDialogView.xaml b/src/client/spark/view/Shell/Workspaces/WorkspacesDialogView.xaml index be390baef..a4e333963 100644 --- a/src/client/spark/view/Shell/Workspaces/WorkspacesDialogView.xaml +++ b/src/client/spark/view/Shell/Workspaces/WorkspacesDialogView.xaml @@ -33,6 +33,9 @@ + From 63434516f85b85ba799318d94cb7cb176ce23e4d Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Tue, 20 Aug 2019 14:44:14 -0500 Subject: [PATCH 044/116] quoting workspace names in confirmation dialogs --- .../Workspaces/WorkspacesDialogViewModel.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/client/spark/view/Shell/Workspaces/WorkspacesDialogViewModel.cs b/src/client/spark/view/Shell/Workspaces/WorkspacesDialogViewModel.cs index 3c2f01901..72c80dc7d 100644 --- a/src/client/spark/view/Shell/Workspaces/WorkspacesDialogViewModel.cs +++ b/src/client/spark/view/Shell/Workspaces/WorkspacesDialogViewModel.cs @@ -53,10 +53,10 @@ namespace mbts.ui.shell (_delete_command = new DelegateCommand( () => { if (BTSMessageBox.Show( - $"Are you sure you with to delete the {selected_workspace.Name} workspace?", - "Delete Existing Workspace", - BTSMessageBoxButtons.Yes | BTSMessageBoxButtons.No - , MessageBoxImage.Question) == BTSMessageBoxButtons.Yes) { + $"Delete the \"{selected_workspace.Name}\" workspace?", + "Delete Existing Workspace Confirmation", + BTSMessageBoxButtons.Yes | BTSMessageBoxButtons.No, + MessageBoxImage.Question) == BTSMessageBoxButtons.Yes) { _work_model.delete_workspace(selected_workspace.Name, selected_workspace.Definition).ignore(); _clear_error_state(); } @@ -65,10 +65,10 @@ namespace mbts.ui.shell (_save_command = new DelegateCommand( () => { if (BTSMessageBox.Show( - $"Overwrite {selected_workspace.Name} with current layout?", - "Save Existing Workspace", - BTSMessageBoxButtons.Yes | BTSMessageBoxButtons.No - , MessageBoxImage.Question) == BTSMessageBoxButtons.Yes) { + $"Overwrite \"{selected_workspace.Name}\" with current layout?", + "Save Existing Workspace Confirmation", + BTSMessageBoxButtons.Yes | BTSMessageBoxButtons.No, + MessageBoxImage.Question) == BTSMessageBoxButtons.Yes) { _work_model.save_workspace(selected_workspace.Name, ispublic:selected_workspace.Definition.is_shared); _clear_error_state(); } From 068e762f4485233d483e5ee43bcfe29f580d3513 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Wed, 21 Aug 2019 11:28:19 -0500 Subject: [PATCH 045/116] PR feedback - Workspaces are now Topmost true; gret suggestion Eric! --- src/client/spark/view/Shell/Workspaces/WorkspacesDialogView.xaml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/client/spark/view/Shell/Workspaces/WorkspacesDialogView.xaml b/src/client/spark/view/Shell/Workspaces/WorkspacesDialogView.xaml index a4e333963..19ecd7978 100644 --- a/src/client/spark/view/Shell/Workspaces/WorkspacesDialogView.xaml +++ b/src/client/spark/view/Shell/Workspaces/WorkspacesDialogView.xaml @@ -14,6 +14,7 @@ ui:WindowStyle.ShowMinimizeButton="False" Style="{StaticResource BTSDialog}" Title="Workspaces" + Topmost="True" > From dc43d25c534fcd3f593f7bcc5008b12f6aeaff69 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Wed, 21 Aug 2019 15:54:23 -0500 Subject: [PATCH 046/116] use Spreader AlgoFormat when security is synthetic --- src/client/spark/Modules/Trading/Ladder/VM/LadderSettingsVM.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/spark/Modules/Trading/Ladder/VM/LadderSettingsVM.cs b/src/client/spark/Modules/Trading/Ladder/VM/LadderSettingsVM.cs index 97db476d3..a1bd3fc6f 100644 --- a/src/client/spark/Modules/Trading/Ladder/VM/LadderSettingsVM.cs +++ b/src/client/spark/Modules/Trading/Ladder/VM/LadderSettingsVM.cs @@ -137,7 +137,7 @@ namespace mbts.spark { c.PropertyChanged -= on_prop_changed; } AccountTuple? account_factory(KeyValuePair kv) => new AccountTuple(kv.Key, kv.Value); - AlgoDefinitionVM algo_factory(AlgoData data) => AlgoDefinitionVM.create(_model, data); + AlgoDefinitionVM algo_factory(AlgoData data) => AlgoDefinitionVM.create(_model, data, is_synthetic ? AlgoFormats.Spreader : AlgoFormats.Exchange); } public event Action result_changed; From aacc5d8d270b1cc9fe455d1b058304ab62335c3b Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Fri, 23 Aug 2019 11:50:59 -0400 Subject: [PATCH 047/116] add entitlement logging to everyone's favorite super long md log --- src/lib/md/relay/RelayClient.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/lib/md/relay/RelayClient.cpp b/src/lib/md/relay/RelayClient.cpp index 341ff53fd..b7d4da066 100644 --- a/src/lib/md/relay/RelayClient.cpp +++ b/src/lib/md/relay/RelayClient.cpp @@ -240,6 +240,9 @@ public: log << Venue_Name(ch.exchange()).substr(sizeof("venue")); log << " " << (uint32_t)ch.time(); log << " " << (uint16_t)ch.segment_id(); + if (!ch.entitled()) { + log << " " << "Ent=0"; + } } log << "\n}"; auto encoded = websocketpp::base64_encode(log.str()); From e2d10bc51808391cf54bd0012518ceec44a0d047 Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Thu, 22 Aug 2019 17:26:15 -0400 Subject: [PATCH 048/116] SP-197 Move onixs license file into license.h --- src/data_files/files/Onixs.BTS.lic | 16 ----- .../sparkd/md/platforms/mdp3_onixs/License.h | 29 ++++++++ .../md/platforms/mdp3_onixs/MDP3Main.cpp | 69 +++++++++++++------ .../sparkd/md/platforms/mdp3_onixs/MDP3Main.h | 1 + 4 files changed, 77 insertions(+), 38 deletions(-) delete mode 100644 src/data_files/files/Onixs.BTS.lic create mode 100644 src/server/sparkd/md/platforms/mdp3_onixs/License.h diff --git a/src/data_files/files/Onixs.BTS.lic b/src/data_files/files/Onixs.BTS.lic deleted file mode 100644 index 9ff33e7a2..000000000 --- a/src/data_files/files/Onixs.BTS.lic +++ /dev/null @@ -1,16 +0,0 @@ - - production - - Blue Trading Systems OF 9420-2 - - - 2019-05-02 - 2020-05-13 - - - - - - - 5E50A1DACD94D7C1BECD316EEAE5AB02 - \ No newline at end of file diff --git a/src/server/sparkd/md/platforms/mdp3_onixs/License.h b/src/server/sparkd/md/platforms/mdp3_onixs/License.h new file mode 100644 index 000000000..60573cf0c --- /dev/null +++ b/src/server/sparkd/md/platforms/mdp3_onixs/License.h @@ -0,0 +1,29 @@ +#pragma once + +namespace bts { +namespace md { + +// The onixs checksum includes the line endings as \r\n +// to avoid the possibility of git mangling the line endings we store +// an array of lines instead of a single string and restore the lines +// when we write it out in MDP3main.cpp +const char * onixs_license[] = { +"", +" production", +" ", +" Blue Trading Systems OF 9420-2", +" ", +" ", +" 2019-05-02", +" 2020-05-13", +" ", +" ", +" ", +" ", +" ", +" ", +" 5E50A1DACD94D7C1BECD316EEAE5AB02", +"", +}; + +}} //namespace diff --git a/src/server/sparkd/md/platforms/mdp3_onixs/MDP3Main.cpp b/src/server/sparkd/md/platforms/mdp3_onixs/MDP3Main.cpp index af427f286..004171819 100644 --- a/src/server/sparkd/md/platforms/mdp3_onixs/MDP3Main.cpp +++ b/src/server/sparkd/md/platforms/mdp3_onixs/MDP3Main.cpp @@ -12,11 +12,13 @@ #include "lib/config/protos/MarketData.pb.h" #include "lib/config/protos/system.pb.h" #include "lib/utils/thread_manager.h" +#include "License.h" #include #include #include +#include using namespace std; using namespace bts::co2; @@ -25,6 +27,23 @@ using std::size_t; namespace bts { namespace md { +struct LicenseInfo { + boost::filesystem::path path; + std::optional default_license; +}; + +LicenseInfo license_info() { + const auto& options = config::get(); + boost::filesystem::path license_path = options.onixs_license(); + if (license_path == "{default}") { + license_path = boost::filesystem::path {os::bts_data_path()} / "licenses"; + return { license_path, { license_path / "11818aa9f7ad1685e877979f935cd8e4.lic" } }; + } + else { + return { license_path, std::nullopt }; + } +} + MDP3Main::MDP3Main() : _index(), _recorder ({ utils::Dispatcher::current(), [=](ExchangeKey k) { return SecurityKey(_index.get_key(k.value())); } }), @@ -160,41 +179,47 @@ void MDP3Main::start(std::vector& symbols, MBOWriter* mbo) { onixs::SessionSettings settings = session_settings_for_channel(pair.first, mbo); pair.second->start(settings); } + started(); LOG(md,Info, "** CME MDP3 Publisher started **"); } void MDP3Main::send_heartbeats() { - for (const auto& listener: _listeners) - listener->heartbeat(); - - // utils::DispatcherTimer settlement_timer(disp, 100, [&]() { - // _settlement_recorder.do_work(); - // }); - // settlement_timer.start(); + for (const auto& listener: _listeners) { + listener->heartbeat(); + } } void MDP3Main::initialize() { - const auto& options = config::get(); - auto license_location = os::bts_data_path() + "/licenses/"; - - if (!boost::filesystem::is_directory(license_location)) { - auto license_path =os::sparkd_wd() + "/data_files/Onixs.BTS.lic" ; - boost::filesystem::create_directories(license_location); - boost::filesystem::copy_file(license_path,license_location+"/Onixs.BTS.lic"); - } - - // - // License path onixs::InitializationSettings init_settings; - auto license = options.onixs_license(); - init_settings.licenseStore(license); - if (license == "{default}") { - init_settings.licenseStore(license_location); + auto linfo = license_info(); + if (linfo.default_license) { + boost::system::error_code ignore; + boost::filesystem::create_directories(linfo.path, ignore); + auto temp = linfo.default_license.value(); + std::ofstream out(temp.c_str(), std::ios::out | std::ios::binary); + if (out.good()) { + for (const char* line : onixs_license) { + if (line != onixs_license[0]) out << "\r\n"; + out << line; + } + } + else { + LOG(md,Warn, "Licensing error. Failed to write to '{}'. Please ensure it is writeable.", linfo.path); + } } + init_settings.licenseStore(linfo.path.string()); LOG(md,Info,"Loading onixs license from {}", init_settings.licenseStore()); onixs::initialize(init_settings); } +void MDP3Main::started() { + auto linfo = license_info(); + if (linfo.default_license) { + boost::system::error_code ignore; + boost::filesystem::remove(linfo.default_license.value(), ignore); + } +} + // // // Initialize HandlerSettings and allocate the channel Handler unique_ptr MDP3Main::prepare_handler(const string& channel_id, MBOWriter* mbo) { diff --git a/src/server/sparkd/md/platforms/mdp3_onixs/MDP3Main.h b/src/server/sparkd/md/platforms/mdp3_onixs/MDP3Main.h index bda70e4c6..4ca663844 100644 --- a/src/server/sparkd/md/platforms/mdp3_onixs/MDP3Main.h +++ b/src/server/sparkd/md/platforms/mdp3_onixs/MDP3Main.h @@ -36,6 +36,7 @@ public: void send_heartbeats() override; void initialize(); + void started(); std::unique_ptr prepare_handler(const std::string& channel, MBOWriter*); std::unique_ptr prepare_listener(onixs::Handler& handler, const CMEChannel& channel, MBOWriter*); From af83516e38fb2f5e4a16f66a665a55d7d6b3aaf1 Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Mon, 26 Aug 2019 10:22:48 -0400 Subject: [PATCH 049/116] Add user to KEYCODE logging --- src/lib/utils/AuthSessionManager.cpp | 8 ++++---- src/lib/utils/AuthSessionManager.h | 10 +++++----- src/lib/utils/AuthToken.cpp | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/lib/utils/AuthSessionManager.cpp b/src/lib/utils/AuthSessionManager.cpp index dddb415fd..8b1b74438 100644 --- a/src/lib/utils/AuthSessionManager.cpp +++ b/src/lib/utils/AuthSessionManager.cpp @@ -80,7 +80,7 @@ bool AuthSessionManager::validate_ip_port(const bts::config::KeyCode& kc) return portgood && ipgood; } -bool AuthSessionManager::add_or_replace_session(const api::user::TokenPayload& tok, std::string* msg) +bool AuthSessionManager::add_or_replace_session(const api::user::TokenPayload& tok, const admin::BTSUser& user, std::string* msg) { if(tok.wheel()) return true; @@ -105,18 +105,18 @@ bool AuthSessionManager::add_or_replace_session(const api::user::TokenPayload& t if(it != _map.end()) { _map[tok.id()] = Session{tok}; - LOG(User, Warn, "KEYCODE: Replacing session {} ", tok.id()); + LOG(User, Warn, "KEYCODE: Replacing session {} user:{}:{} ", tok.id(), user.id(), user.name()); return true; } else if(_map.size() < _nusers) { _map[tok.id()] = Session{tok}; - LOG(User, Warn, "KEYCODE: Creating session {} ", tok.id()); + LOG(User, Warn, "KEYCODE: Creating session {} user:{}:{}", tok.id(), user.id(), user.name()); return true; } if(msg) *msg = "KEYCODES: Not Enough Logins available for session"; - LOG(User, Error, "KEYCODES: Not Enough Logins available for session {}", tok.id()); + LOG(User, Error, "KEYCODES: Not Enough Logins available for session {} user:{}:{}", tok.id(), user.id(), user.name()); return false; } diff --git a/src/lib/utils/AuthSessionManager.h b/src/lib/utils/AuthSessionManager.h index 08e9d03cd..fa68d097e 100644 --- a/src/lib/utils/AuthSessionManager.h +++ b/src/lib/utils/AuthSessionManager.h @@ -8,7 +8,7 @@ namespace bts { namespace config { class KeyCode; } namespace api { namespace auth { - + struct Session { api::user::TokenPayload token; @@ -18,8 +18,8 @@ class AuthSessionManager { public: AuthSessionManager(); - - bool add_or_replace_session(const api::user::TokenPayload& tok, std::string* msg = nullptr); + + bool add_or_replace_session(const api::user::TokenPayload& tok, const admin::BTSUser& user, std::string* msg = nullptr); bool check_session(const api::user::TokenPayload& tok); private: @@ -33,6 +33,6 @@ private: bool _concurrent; }; - - + + }}} \ No newline at end of file diff --git a/src/lib/utils/AuthToken.cpp b/src/lib/utils/AuthToken.cpp index 2423638a8..9c062c592 100644 --- a/src/lib/utils/AuthToken.cpp +++ b/src/lib/utils/AuthToken.cpp @@ -89,7 +89,7 @@ AuthToken generate_token(const admin::BTSUser& user, std::string* msg) payload.set_wheel(true); if(requires_auth_session(user)) - session_manager().add_or_replace_session(payload, msg); + session_manager().add_or_replace_session(payload, user, msg); auto token = encrypt(payload.SerializeAsString()); bts_assert_d(token.size() < 255-8); AuthToken result; From 880dac06b9edba966ec16c70987aa2830ae62c44 Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Mon, 26 Aug 2019 15:31:44 -0400 Subject: [PATCH 050/116] SP-197 factor common code between onixs cme/ice --- src/lib/config/protos/MarketData.proto | 10 +- src/lib/md/cme/MDP3Utils.cpp | 1 + src/lib/md/cme/MDP3Utils.h | 3 + src/lib/md/vendor/OnixsUtils.cpp | 66 +++++++++++ src/lib/md/vendor/OnixsUtils.h | 16 +++ .../sparkd/md/platforms/ice_onixs/ICEMain.cpp | 111 ++++++++---------- .../sparkd/md/platforms/ice_onixs/ICEMain.h | 2 +- .../sparkd/md/platforms/mdp3_onixs/License.h | 29 ----- .../md/platforms/mdp3_onixs/MDP3Main.cpp | 52 +------- .../sparkd/md/platforms/mdp3_onixs/MDP3Main.h | 3 +- 10 files changed, 153 insertions(+), 140 deletions(-) create mode 100644 src/lib/md/vendor/OnixsUtils.cpp create mode 100644 src/lib/md/vendor/OnixsUtils.h delete mode 100644 src/server/sparkd/md/platforms/mdp3_onixs/License.h diff --git a/src/lib/config/protos/MarketData.proto b/src/lib/config/protos/MarketData.proto index 3992aaf7f..18c08950a 100755 --- a/src/lib/config/protos/MarketData.proto +++ b/src/lib/config/protos/MarketData.proto @@ -127,7 +127,8 @@ message CMEOptions optional bool validate_mbo = 35 [default = false]; } - optional string onixs_license = 1 [default = "{default}"]; + // optional string onixs_license = 1 [default = "{default}"]; + reserved 1; repeated CMEChannel channel = 3; repeated FeedEngineSettings feed_engine = 5; @@ -174,11 +175,16 @@ message ICEOptions optional bool load_security_db = 41 [default = true]; } - optional string onixs_license = 1 [default = "{default}"]; + // optional string onixs_license = 1 [default = "{default}"]; + reserved 1; optional string ice_config_file = 2 [default = "ConnectivityConfiguration.Production.xml"]; repeated ICEChannel channel = 3; } +message OnixsOptions { + optional string onixs_license = 1 [default = "{default}"]; +} + message RecordOptions { // optional string output_path = 2 [default = "/home/bts/md/today"]; optional bool enable_depth = 3 [default = false]; diff --git a/src/lib/md/cme/MDP3Utils.cpp b/src/lib/md/cme/MDP3Utils.cpp index 1f09eb931..f1a8d7b41 100644 --- a/src/lib/md/cme/MDP3Utils.cpp +++ b/src/lib/md/cme/MDP3Utils.cpp @@ -167,5 +167,6 @@ const vector parse_channels(const vector& symbols) { return result; } + }} //namespace #endif \ No newline at end of file diff --git a/src/lib/md/cme/MDP3Utils.h b/src/lib/md/cme/MDP3Utils.h index dab13ff8d..08caddeab 100644 --- a/src/lib/md/cme/MDP3Utils.h +++ b/src/lib/md/cme/MDP3Utils.h @@ -1,10 +1,12 @@ #pragma once #include "lib/md/coconut2.h" +#include "lib/utils/optional.h" #include #include #include + namespace bts { namespace md { @@ -99,5 +101,6 @@ inline int floorlog10(int64_t m) { } + }}//namespace diff --git a/src/lib/md/vendor/OnixsUtils.cpp b/src/lib/md/vendor/OnixsUtils.cpp new file mode 100644 index 000000000..af3ebe55c --- /dev/null +++ b/src/lib/md/vendor/OnixsUtils.cpp @@ -0,0 +1,66 @@ +#include "OnixsUtils.h" +#include "lib/logging/logging.h" +#include "lib/config/config.h" +#include "lib/config/protos/MarketData.pb.h" + +namespace bts { +namespace md { + +// The onixs checksum includes the line endings as \r\n +// to avoid the possibility of git mangling the line endings we store +// an array of lines instead of a single string and restore the lines +// when we write it out in MDP3main.cpp +const char * onixs_license[] = { +"", +" production", +" ", +" Blue Trading Systems OF 9420-2", +" ", +" ", +" 2019-05-02", +" 2020-05-13", +" ", +" ", +" ", +" ", +" ", +" ", +" 5E50A1DACD94D7C1BECD316EEAE5AB02", +"", +}; + +OnixsTemplLicense onixs_create_temporary_license() { + const auto& options = config::get(); + OnixsTemplLicense linfo; + linfo.path = options.onixs_license(); + if (linfo.path == "{default}") { + linfo.path = boost::filesystem::path {os::bts_data_path()} / "licenses"; + auto ident = boost::filesystem::unique_path("%%%%-%%%%-%%%%-%%%%.lic"); + linfo.license = { linfo.path / ident }; + } + + if (linfo.license) { + boost::system::error_code ignore; + boost::filesystem::create_directories(linfo.path, ignore); + auto temp = linfo.license.value(); + std::ofstream out(temp.c_str(), std::ios::out | std::ios::binary); + if (out.good()) { + for (const char* line : onixs_license) { + if (line != onixs_license[0]) out << "\r\n"; + out << line; + } + } + else { + LOG(md,Warn, "Licensing error. Failed to write to '{}'. Please ensure it is writeable.", linfo.path); + } + } + return linfo; +} +void onixs_destroy_temporary_license(const OnixsTemplLicense& lic) { + if (lic.license) { + boost::system::error_code ignore; + boost::filesystem::remove(lic.license.value(), ignore); + } +} + +}} //namespace diff --git a/src/lib/md/vendor/OnixsUtils.h b/src/lib/md/vendor/OnixsUtils.h new file mode 100644 index 000000000..0d46fc357 --- /dev/null +++ b/src/lib/md/vendor/OnixsUtils.h @@ -0,0 +1,16 @@ +#pragma once +#include "boost/filesystem.hpp" +#include "lib/utils/optional.h" + +namespace bts { +namespace md { + +struct OnixsTemplLicense { + boost::filesystem::path path; + std::optional license; +}; + +OnixsTemplLicense onixs_create_temporary_license(); +void onixs_destroy_temporary_license(const OnixsTemplLicense&); + +}} //namespace diff --git a/src/server/sparkd/md/platforms/ice_onixs/ICEMain.cpp b/src/server/sparkd/md/platforms/ice_onixs/ICEMain.cpp index f36be139d..ea2b3ef9b 100644 --- a/src/server/sparkd/md/platforms/ice_onixs/ICEMain.cpp +++ b/src/server/sparkd/md/platforms/ice_onixs/ICEMain.cpp @@ -1,6 +1,7 @@ #include "ICEMain.h" #include "lib/md/ice/ICEUtils.h" +#include "lib/md/vendor/OnixsUtils.h" #include "lib/config/config.h" #include "lib/md/coconut2.h" #include "lib/md/SecurityDB.h" @@ -24,16 +25,16 @@ void recursive_copy(const boost::filesystem::path &src, const boost::filesystem: { if (boost::filesystem::exists(dst)) throw std::runtime_error(dst.generic_string() + " exists"); - if (boost::filesystem::is_directory(src)) + if (boost::filesystem::is_directory(src)) { boost::filesystem::create_directories(dst); - for (boost::filesystem::directory_entry& item : boost::filesystem::directory_iterator(src)) - recursive_copy(item.path(), dst/item.path().filename()); - } - else if (boost::filesystem::is_regular_file(src)) - boost::filesystem::copy(src, dst); - else - throw std::runtime_error(dst.generic_string() + " not dir or file"); + for (boost::filesystem::directory_entry& item : boost::filesystem::directory_iterator(src)) + recursive_copy(item.path(), dst/item.path().filename()); + } + else if (boost::filesystem::is_regular_file(src)) + boost::filesystem::copy(src, dst); + else + throw std::runtime_error(dst.generic_string() + " not dir or file"); } using namespace std; @@ -55,10 +56,10 @@ ICEMain::ICEMain() : ICEMain::~ICEMain() {} -const ICEOptions::ICEChannel channel_settings_for(const ICEChannel& channel) +const ICEOptions::ICEChannel channel_settings_for(const ICEChannel& channel) { const auto& config = config::get(); - for (const auto& ch : config.channel()) + for (const auto& ch : config.channel()) { if(ch.name() == channel.name) return ch; @@ -67,7 +68,7 @@ const ICEOptions::ICEChannel channel_settings_for(const ICEChannel& channel) } -onixs_ice::MarketSubscriptions market_subcription_for_channel(const ICEChannel& chan) +onixs_ice::MarketSubscriptions market_subcription_for_channel(const ICEChannel& chan) { onixs_ice::MarketSubscriptions subs; for(const auto& x : chan.market_types) @@ -82,106 +83,96 @@ onixs_ice::MarketSubscriptions market_subcription_for_channel(const ICEChannel& } -void ICEMain::start(std::vector& symbols) +void ICEMain::start(std::vector& symbols) { - // License path and config file - auto license_location = os::bts_data_path() + "/licenses/"; - if (!boost::filesystem::is_directory(license_location)) - { - auto license_path =os::sparkd_wd() + "/data_files/Onixs.BTS.lic" ; - boost::filesystem::create_directories(license_location); - boost::filesystem::copy_file(license_path,license_location+"/Onixs.BTS.lic"); - } auto ice_conf_location = os::bts_data_path() + "/onixs_ice/"; - if (!boost::filesystem::is_directory(ice_conf_location)) + if (!boost::filesystem::is_directory(ice_conf_location)) { auto conf_path = os::sparkd_wd() + "/data_files/onixs_ice/" ; recursive_copy(boost::filesystem::path(conf_path), boost::filesystem::path(ice_conf_location)); } - + await_ice_config(); + auto license = onixs_create_temporary_license(); + const auto& channels = parse_ice_channels(symbols); - for (const auto& channel : channels) + for (const auto& channel : channels) { - unique_ptr phandler = prepare_handler(channel); + unique_ptr phandler = prepare_handler(channel, license.path.string()); _listeners.push_back(prepare_listener(*phandler, channel)); - _handlers.push_back(std::make_pair(channel, move(phandler))); - - std::stringstream symstr; - for (const auto& sym : channel.symbols) - symstr << sym.symbol() << "-" << SecurityType_Name(sym.type()) << " "; + _handlers.push_back(std::make_pair(channel, move(phandler))); + + std::stringstream symstr; + for (const auto& sym : channel.symbols) + symstr << sym.symbol() << "-" << SecurityType_Name(sym.type()) << " "; LOG(md,Info, "ICE: Initialized channel {} ({})", channel.to_string(), symstr.str()); } - for (auto& pair : _handlers) - { + for (auto& pair : _handlers) + { LOG(md,Info, "ICE: Init Handler {}", pair.first.to_string()); - sleep_for(16s); - onixs_ice::MarketSubscriptions subs = market_subcription_for_channel(pair.first); + sleep_for(16s); + onixs_ice::MarketSubscriptions subs = market_subcription_for_channel(pair.first); pair.second->start(subs); } + onixs_destroy_temporary_license(license); LOG(md,Info, "** ICE Publisher started **"); } void ICEMain::send_heartbeats() { - for (const auto& listener: _listeners) + for (const auto& listener: _listeners) listener->heartbeat(); } // // // Initialize HandlerSettings and allocate the channel Handler -unique_ptr ICEMain::prepare_handler(const ICEChannel& channel) +unique_ptr ICEMain::prepare_handler(const ICEChannel& channel, const std::string& license) { - const auto& ice_options = config::get(); - auto license = ice_options.onixs_license(); - if (license == "{default}") - license = os::bts_data_path() + "/licenses/"; - const auto& options = channel_settings_for(channel); LOG(md,Info,"Loaded channel options for channel {}:\n{}", channel.to_string(), options.DebugString()); - onixs_ice::HandlerSettings settings; - settings.licenseDirectory = license; + onixs_ice::HandlerSettings settings; + settings.licenseDirectory = license; // // Logging settings.logLevel = (onixs_ice::LogLevels::Enum) options.onixs_log_mode(); settings.logDirectory = ice_log_path(); - + // - // Config file + // Config file settings.connectivityConfiguration = ice_config_path(); - // + // // Network settings const auto& pub_options = config::get(); - if (pub_options.has_network_interface()) + if (pub_options.has_network_interface()) settings.networkInterface = pub_options.network_interface(); - else + else { std::string inter; - if (pub_options.has_network_interface_a() && !pub_options.has_network_interface_b()) + if (pub_options.has_network_interface_a() && !pub_options.has_network_interface_b()) inter = pub_options.network_interface_a(); - if (!pub_options.has_network_interface_a() && pub_options.has_network_interface_b()) + if (!pub_options.has_network_interface_a() && pub_options.has_network_interface_b()) inter = pub_options.network_interface_b(); - if (pub_options.has_network_interface_a() && pub_options.has_network_interface_b()) + if (pub_options.has_network_interface_a() && pub_options.has_network_interface_b()) inter = pub_options.network_interface_b() + ":" + pub_options.network_interface_b(); settings.networkInterface = inter; - } + } settings.udpBufferSize = options.udp_buffer_size(); settings.heartbeatInterval = options.heartbeat_interval(); settings.sequenceGapMargin = options.sequence_gap_margin(); settings.gapTimeoutInMilliseconds = options.gap_timeout_in_ms(); - + // // Snapshot recovery options settings.snapshotRecoveryOptions.snapshotRecoveryTimeoutInMilliseconds = options.snapshot_recovery_timeout_in_ms(); settings.snapshotRecoveryOptions.maximumNumberOfSnaphotRecoveryAttempts = options.maximum_number_of_snapshot_recovery_attempts(); settings.snapshotRecoveryOptions.maximumSizeOfSnapshotMessageQueue = options.maximum_size_of_snapshot_message_queue(); - settings.snapshotRecoveryOptions.maximumSizeOfLiveMessageQueue = options.maximum_size_of_live_message_queue(); + settings.snapshotRecoveryOptions.maximumSizeOfLiveMessageQueue = options.maximum_size_of_live_message_queue(); // - // Misc settings + // Misc settings if(options.processing_thread_affinity() != "" ) settings.processingThreadAffinity = onixs_ice::ThreadAffinity::deserialize(options.processing_thread_affinity()); // if(options.has_track_top_of_the_book_only() @@ -192,10 +183,10 @@ unique_ptr ICEMain::prepare_handler(const ICEChannel& channe settings.maxMulticastMessageBlockSize = options.max_multicast_message_block_size(); if(options.product_definition_cache_directory() != "" ) settings.productDefinitionCacheDirectory = options.product_definition_cache_directory(); - + // // return feed handler - try + try { auto handler = unique_ptr(new onixs_ice::Handler(settings)); return handler; @@ -208,18 +199,18 @@ unique_ptr ICEMain::prepare_handler(const ICEChannel& channe // // Create a listener for this channel and register callbacks -unique_ptr ICEMain::prepare_listener(onixs_ice::Handler& handler, const ICEChannel& channel) +unique_ptr ICEMain::prepare_listener(onixs_ice::Handler& handler, const ICEChannel& channel) { // We need to get a handler to the producer channels so we can produce heartbeats vector producer_channels; - for (auto& symbol : channel.symbols) + for (auto& symbol : channel.symbols) { producer_channels.push_back(_producer.get_channel(symbol.symbol().c_str(), symbol.type(), symbol.exchange())); } unique_ptr listener(new ICEListener(_index, _producer, /*_settlement_recorder,*/ producer_channels)); - for (auto& symbol : channel.symbols) - listener->add_filter_symbol(symbol.symbol()); + for (auto& symbol : channel.symbols) + listener->add_filter_symbol(symbol.symbol()); handler.registerExchangeListener(listener.get()); handler.registerFeedListener(listener.get()); diff --git a/src/server/sparkd/md/platforms/ice_onixs/ICEMain.h b/src/server/sparkd/md/platforms/ice_onixs/ICEMain.h index ec6f1dfb8..5c43220c5 100644 --- a/src/server/sparkd/md/platforms/ice_onixs/ICEMain.h +++ b/src/server/sparkd/md/platforms/ice_onixs/ICEMain.h @@ -34,7 +34,7 @@ public: void start(std::vector&); void send_heartbeats() override; - std::unique_ptr prepare_handler(const ICEChannel& channel); + std::unique_ptr prepare_handler(const ICEChannel& channel, const std::string& license); std::unique_ptr prepare_listener(onixs_ice::Handler& handler, const ICEChannel& channel); private: diff --git a/src/server/sparkd/md/platforms/mdp3_onixs/License.h b/src/server/sparkd/md/platforms/mdp3_onixs/License.h deleted file mode 100644 index 60573cf0c..000000000 --- a/src/server/sparkd/md/platforms/mdp3_onixs/License.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -namespace bts { -namespace md { - -// The onixs checksum includes the line endings as \r\n -// to avoid the possibility of git mangling the line endings we store -// an array of lines instead of a single string and restore the lines -// when we write it out in MDP3main.cpp -const char * onixs_license[] = { -"", -" production", -" ", -" Blue Trading Systems OF 9420-2", -" ", -" ", -" 2019-05-02", -" 2020-05-13", -" ", -" ", -" ", -" ", -" ", -" ", -" 5E50A1DACD94D7C1BECD316EEAE5AB02", -"", -}; - -}} //namespace diff --git a/src/server/sparkd/md/platforms/mdp3_onixs/MDP3Main.cpp b/src/server/sparkd/md/platforms/mdp3_onixs/MDP3Main.cpp index 004171819..78547f12a 100644 --- a/src/server/sparkd/md/platforms/mdp3_onixs/MDP3Main.cpp +++ b/src/server/sparkd/md/platforms/mdp3_onixs/MDP3Main.cpp @@ -1,6 +1,7 @@ #include "MDP3Main.h" #include "lib/md/cme/MDP3Utils.h" +#include "lib/md/vendor/OnixsUtils.h" #include "lib/md/MBOProcessor.h" #include "lib/config/config.h" #include "lib/md/coconut2.h" @@ -12,7 +13,6 @@ #include "lib/config/protos/MarketData.pb.h" #include "lib/config/protos/system.pb.h" #include "lib/utils/thread_manager.h" -#include "License.h" #include @@ -27,23 +27,6 @@ using std::size_t; namespace bts { namespace md { -struct LicenseInfo { - boost::filesystem::path path; - std::optional default_license; -}; - -LicenseInfo license_info() { - const auto& options = config::get(); - boost::filesystem::path license_path = options.onixs_license(); - if (license_path == "{default}") { - license_path = boost::filesystem::path {os::bts_data_path()} / "licenses"; - return { license_path, { license_path / "11818aa9f7ad1685e877979f935cd8e4.lic" } }; - } - else { - return { license_path, std::nullopt }; - } -} - MDP3Main::MDP3Main() : _index(), _recorder ({ utils::Dispatcher::current(), [=](ExchangeKey k) { return SecurityKey(_index.get_key(k.value())); } }), @@ -163,7 +146,8 @@ onixs::SessionSettings session_settings_for_channel(const string& channel_id, MB void MDP3Main::start(std::vector& symbols, MBOWriter* mbo) { await_cme_config(); - initialize(); + auto license = onixs_create_temporary_license(); + initialize(license.path.string()); const auto& channels = parse_channels(symbols); _engines = create_feed_engines(channels); for (const auto& channel : channels) { @@ -179,7 +163,7 @@ void MDP3Main::start(std::vector& symbols, MBOWriter* mbo) { onixs::SessionSettings settings = session_settings_for_channel(pair.first, mbo); pair.second->start(settings); } - started(); + onixs_destroy_temporary_license(license); LOG(md,Info, "** CME MDP3 Publisher started **"); } @@ -189,37 +173,13 @@ void MDP3Main::send_heartbeats() { } } -void MDP3Main::initialize() { +void MDP3Main::initialize(const std::string& license_store) { onixs::InitializationSettings init_settings; - auto linfo = license_info(); - if (linfo.default_license) { - boost::system::error_code ignore; - boost::filesystem::create_directories(linfo.path, ignore); - auto temp = linfo.default_license.value(); - std::ofstream out(temp.c_str(), std::ios::out | std::ios::binary); - if (out.good()) { - for (const char* line : onixs_license) { - if (line != onixs_license[0]) out << "\r\n"; - out << line; - } - } - else { - LOG(md,Warn, "Licensing error. Failed to write to '{}'. Please ensure it is writeable.", linfo.path); - } - } - init_settings.licenseStore(linfo.path.string()); + init_settings.licenseStore(license_store); LOG(md,Info,"Loading onixs license from {}", init_settings.licenseStore()); onixs::initialize(init_settings); } -void MDP3Main::started() { - auto linfo = license_info(); - if (linfo.default_license) { - boost::system::error_code ignore; - boost::filesystem::remove(linfo.default_license.value(), ignore); - } -} - // // // Initialize HandlerSettings and allocate the channel Handler unique_ptr MDP3Main::prepare_handler(const string& channel_id, MBOWriter* mbo) { diff --git a/src/server/sparkd/md/platforms/mdp3_onixs/MDP3Main.h b/src/server/sparkd/md/platforms/mdp3_onixs/MDP3Main.h index 4ca663844..baacdab35 100644 --- a/src/server/sparkd/md/platforms/mdp3_onixs/MDP3Main.h +++ b/src/server/sparkd/md/platforms/mdp3_onixs/MDP3Main.h @@ -35,8 +35,7 @@ public: void start(std::vector&, MBOWriter*); void send_heartbeats() override; - void initialize(); - void started(); + void initialize(const std::string& license_store); std::unique_ptr prepare_handler(const std::string& channel, MBOWriter*); std::unique_ptr prepare_listener(onixs::Handler& handler, const CMEChannel& channel, MBOWriter*); From 3b25e181fa6ae0a6207d2cad53721ebfc264066f Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Mon, 26 Aug 2019 16:22:33 -0500 Subject: [PATCH 051/116] fix ActionMenu binding in SimpleGrid template --- src/client/spark/view/Shell/Settings/ShellSettingsDialog.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/spark/view/Shell/Settings/ShellSettingsDialog.xaml b/src/client/spark/view/Shell/Settings/ShellSettingsDialog.xaml index 2173a5f7d..f47c46a37 100644 --- a/src/client/spark/view/Shell/Settings/ShellSettingsDialog.xaml +++ b/src/client/spark/view/Shell/Settings/ShellSettingsDialog.xaml @@ -181,7 +181,7 @@ - + From 4ea32e06a90054ed2155ea13b7cfce3722d65954 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Mon, 26 Aug 2019 16:22:33 -0500 Subject: [PATCH 052/116] fix ActionMenu binding in SimpleGrid template (cherry picked from commit 3b25e181fa6ae0a6207d2cad53721ebfc264066f) --- src/client/spark/view/Shell/Settings/ShellSettingsDialog.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/spark/view/Shell/Settings/ShellSettingsDialog.xaml b/src/client/spark/view/Shell/Settings/ShellSettingsDialog.xaml index c8d62d7c5..694b13a4a 100644 --- a/src/client/spark/view/Shell/Settings/ShellSettingsDialog.xaml +++ b/src/client/spark/view/Shell/Settings/ShellSettingsDialog.xaml @@ -185,7 +185,7 @@ - + From ce26c2acafb32928e5db8aa1582f2f78423736d7 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Tue, 27 Aug 2019 13:08:18 -0400 Subject: [PATCH 053/116] reduce ComboBox default padding --- src/client/spark/Themes/generic.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/spark/Themes/generic.xaml b/src/client/spark/Themes/generic.xaml index 52e66ff7d..8038e6b0b 100644 --- a/src/client/spark/Themes/generic.xaml +++ b/src/client/spark/Themes/generic.xaml @@ -338,7 +338,7 @@ - + From 3720a7728fb578bf30ce9aa7de854c253ce529b9 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Tue, 27 Aug 2019 13:08:52 -0400 Subject: [PATCH 054/116] added ThreadedWindowLauncher (will be used to launch GlobalAlertsDialog) --- .../view/Utility/ThreadedWindowLauncher.cs | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 src/client/spark/view/Utility/ThreadedWindowLauncher.cs diff --git a/src/client/spark/view/Utility/ThreadedWindowLauncher.cs b/src/client/spark/view/Utility/ThreadedWindowLauncher.cs new file mode 100644 index 000000000..c49e01129 --- /dev/null +++ b/src/client/spark/view/Utility/ThreadedWindowLauncher.cs @@ -0,0 +1,118 @@ +using bts; +using mbts.utils; +using System; +using System.Diagnostics; +using System.Threading; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Threading; + +namespace mbts.ui.utilities { + class ThreadedWindowLauncher { + const int _min_thread_count = 1, _max_thread_count = 16; + readonly string _name; + readonly int _thread_count; + int _counter; + DispatcherContainer[] _cache; + readonly LoggerContext _log; + + public ThreadedWindowLauncher(string name) + : this(name, Environment.ProcessorCount) { } + + public ThreadedWindowLauncher(string name, int thread_count) { + ExceptionAssert.Argument.Between(thread_count, _min_thread_count, _max_thread_count, nameof(thread_count)); + _log = new LoggerContext(Log.Ui, $"{nameof(ThreadedWindowLauncher)} {name ?? "(anon)"} ", null); + _name = name; + _thread_count = thread_count; + _cache = new DispatcherContainer[thread_count]; + } + + public void show(Func factory) => + _show(factory, Interlocked.Increment(ref _counter) % _thread_count); + + void _show(Func factory, int thread_id) { + var dc = _cache[thread_id]; + if (dc != null) { + if (Interlocked.Increment(ref dc.window_count) == 1) { + // If window_count was 0 (before incrementing), the dispatcher must be shutting down. + // Since its initial count is 1, the only way it could have reached 0 is if all windows were closed, which triggers a shutdown. + _init_dispatcher(dc); + } + } else { + // the container may have been assigned since we last checked (if another thread is simultaneously executing this code block). + var late_dc = Interlocked.Exchange(ref _cache[thread_id], dc = new DispatcherContainer(thread_id)); + if (late_dc == null) + _init_dispatcher(dc); + } + _show_on_dispatcher(dc, factory); + } + + async void _show_on_dispatcher(DispatcherContainer dc, Func factory) { + const int max_loops = 50; + int count = 0; + var stopwatch = new Stopwatch(); + stopwatch.Start(); + while (dc.dispatcher == null || dc.dispatcher.HasShutdownStarted) { + await Task.Delay(100); + if (++count == max_loops) { + stopwatch.Stop(); + // give up + _log.warn($"failed to open window: timed out waiting for dispatcher (looped {count} times over the course of {stopwatch.Elapsed:mm\\:ss\\.ff})."); + } + } + await dc.dispatcher.InvokeAsync(() => { + var win = factory(); + win.Closed += closed; + win.Show(); + void closed(object sender, EventArgs e) { + if (Interlocked.Decrement(ref dc.window_count) == 0 && !dc.dispatcher.HasShutdownStarted) + dc.dispatcher.BeginInvokeShutdown(DispatcherPriority.Background); + } + }); + } + + void _init_dispatcher(DispatcherContainer dc) { + // kick off the new thread, and setup the dispatcher + var thread = new Thread(start) { + IsBackground = true + }; + thread.SetApartmentState(ApartmentState.STA); + thread.Start(); + // + void start() { + dc.dispatcher = Dispatcher.CurrentDispatcher; + try { + dc.dispatcher.UnhandledException += on_dispatcher_unhandled_exception; + Dispatcher.Run(); + } catch (Exception ex) { + _log.warn($"dispatcher caught an exception (shutting down dispatcher): {ex}"); + dispose_core(); + } + void on_dispatcher_unhandled_exception(object sender, DispatcherUnhandledExceptionEventArgs e) { + BTSApplicationBootstrapper.CurrentDispatcher_HandleClipboardError(sender, e); + if (!e.Handled) { + _log.error($"unhandled exception in dispatcher: {e.Exception}"); + if (!e.Dispatcher.HasShutdownStarted) + e.Dispatcher.BeginInvokeShutdown(DispatcherPriority.Send); + } + } + void dispose_core() { + if (!dc.dispatcher.HasShutdownStarted) + dc.dispatcher.BeginInvokeShutdown(DispatcherPriority.Background); + } + } + } + + // This simple wrapper allows dispatchers to be 'read' atomically via Interlocked. + // Since creation of a new Dispatcher is asynchronous, the wrapper acts as a placeholder until it is finally assigned. + class DispatcherContainer { + public readonly int id; + + public DispatcherContainer(int id) => + this.id = id; + + public Dispatcher dispatcher { get; set; } + public int window_count = 1; + } + } +} \ No newline at end of file From cba1675da770d3c13b6337229f673815ebe820ca Mon Sep 17 00:00:00 2001 From: John Colvin Date: Tue, 27 Aug 2019 11:08:44 -0400 Subject: [PATCH 055/116] remove AnonymousMutablePredicate (don't need it) --- src/client/spark/Predicates/IPredicate.cs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/client/spark/Predicates/IPredicate.cs b/src/client/spark/Predicates/IPredicate.cs index bd881c697..b4ccd4041 100644 --- a/src/client/spark/Predicates/IPredicate.cs +++ b/src/client/spark/Predicates/IPredicate.cs @@ -88,7 +88,7 @@ namespace mbts { public static IPredicate state_transition(Func predicate) { // avoid false-positive in the first callback bool last_result = true; - return new AnonymousMutableTrigger(v => { + return new AnonymousTrigger(v => { bool curr_result = predicate(v); if (last_result == curr_result) { return false; @@ -266,12 +266,6 @@ namespace mbts { public override string ToString() => $"AnonymousTrigger ({typeof(T)})"; } - - class AnonymousMutableTrigger : IPredicate { - public AnonymousMutableTrigger(Func predicate) => this.predicate = predicate; - public Func predicate { get; set; } - public bool trigger(T value) => predicate(value); - } #endregion } } \ No newline at end of file From 50f6ce9fb46e6319971bdd60ce260808c78f8138 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Tue, 27 Aug 2019 11:09:25 -0400 Subject: [PATCH 056/116] fix 'TOutter' typo --- src/client/spark/Predicates/IPredicate.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/client/spark/Predicates/IPredicate.cs b/src/client/spark/Predicates/IPredicate.cs index b4ccd4041..81579f979 100644 --- a/src/client/spark/Predicates/IPredicate.cs +++ b/src/client/spark/Predicates/IPredicate.cs @@ -220,24 +220,24 @@ namespace mbts { public override string ToString() => $"InSetTrigger (Count: {_set.Count}, type: {typeof(T)})"; } - class WrapperTrigger : IPredicate { + class WrapperTrigger : IPredicate { readonly IPredicate _inner_trigger; - readonly Func _selector; + readonly Func _selector; - public WrapperTrigger(IPredicate inner_trigger, Func selector) { + public WrapperTrigger(IPredicate inner_trigger, Func selector) { _inner_trigger = inner_trigger; _selector = selector; } - public bool trigger(TOutter value) => _inner_trigger.trigger(_selector(value)); + public bool trigger(TOuter value) => _inner_trigger.trigger(_selector(value)); public override bool Equals(object obj) => - obj is WrapperTrigger t && _inner_trigger.Equals(t._inner_trigger) && _selector.Equals(t._selector); + obj is WrapperTrigger t && _inner_trigger.Equals(t._inner_trigger) && _selector.Equals(t._selector); public override int GetHashCode() => EqualityComparer.aggregate_hash(_inner_trigger.GetHashCode(), _selector.GetHashCode()); - public override string ToString() => $"WrapperTrigger (outter-type {typeof(TOutter)}, inner-trigger: {_inner_trigger})"; + public override string ToString() => $"WrapperTrigger (outer-type {typeof(TOuter)}, inner-trigger: {_inner_trigger})"; } class NegateTrigger : IPredicate { From 25dfa9a0a2d69347efcd3ca997d65e4c76603d96 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Tue, 27 Aug 2019 11:09:49 -0400 Subject: [PATCH 057/116] IEquatable impl for IPredicate impls --- src/client/spark/Predicates/IPredicate.cs | 191 +++++++++++++++++----- 1 file changed, 151 insertions(+), 40 deletions(-) diff --git a/src/client/spark/Predicates/IPredicate.cs b/src/client/spark/Predicates/IPredicate.cs index 81579f979..11edf88d6 100644 --- a/src/client/spark/Predicates/IPredicate.cs +++ b/src/client/spark/Predicates/IPredicate.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.Linq; namespace mbts { interface IPredicate { @@ -97,7 +98,7 @@ namespace mbts { } #region Implementation - class EqualsTrigger : IPredicate { + class EqualsTrigger : IPredicate, IEquatable> { readonly T _value; readonly IEqualityComparer _eq_comparer; @@ -106,12 +107,26 @@ namespace mbts { _eq_comparer = eq_comparer; } - public bool trigger(T value) => _eq_comparer.Equals(value, _value); + public bool trigger(T value) => + _eq_comparer.Equals(value, _value); - public override string ToString() => $"EqualsTrigger ({typeof(T)})"; + public override string ToString() => + $"EqualsTrigger ({typeof(T)})"; + + public bool Equals(EqualsTrigger other) => + other != null && + // check equality with both IEqualityComparers + _eq_comparer.Equals(_value, other._value) && + other._eq_comparer.Equals(_value, other._value); + + public override bool Equals(object obj) => + Equals(obj as EqualsTrigger); + + public override int GetHashCode() => + _eq_comparer.GetHashCode(_value); } - class AndTrigger : IPredicate { + class AndTrigger : IPredicate, IEquatable> { readonly IPredicate _first, _second; public AndTrigger(IPredicate first, IPredicate second) { @@ -119,18 +134,28 @@ namespace mbts { _second = second; } - public bool trigger(T value) => _first.trigger(value) && _second.trigger(value); + public bool trigger(T value) => + _first.trigger(value) && + _second.trigger(value); - public override string ToString() => $"AndTrigger ({_first}, {_second})"; + public bool Equals(AndTrigger other) => + other != null && + _first.Equals(other._first) && + _second.Equals(other._second); + + public override string ToString() => + $"AndTrigger ({_first}, {_second})"; public override bool Equals(object obj) => - obj is AndTrigger t && _first.Equals(t._first) && _second.Equals(t._second); + Equals(obj as AndTrigger); public override int GetHashCode() => - EqualityComparer.aggregate_hash(_first.GetHashCode(), _second.GetHashCode()); + EqualityComparer.aggregate_hash( + _first.GetHashCode(), + _second.GetHashCode()); } - class AndTrigger : IPredicate<(T1, T2)> { + class AndTrigger : IPredicate<(T1, T2)>, IEquatable> { readonly IPredicate _first; readonly IPredicate _second; @@ -139,18 +164,28 @@ namespace mbts { _second = second; } - public bool trigger((T1, T2) value) => _first.trigger(value.Item1) && _second.trigger(value.Item2); + public bool trigger((T1, T2) value) => + _first.trigger(value.Item1) && + _second.trigger(value.Item2); + + public bool Equals(AndTrigger other) => + other != null && + _first.Equals(other._first) && + _second.Equals(other._second); public override bool Equals(object obj) => - obj is AndTrigger t && _first.Equals(t._first) && _second.Equals(t._second); + Equals(obj as AndTrigger); public override int GetHashCode() => - EqualityComparer.aggregate_hash(_first.GetHashCode(), _second.GetHashCode()); + EqualityComparer.aggregate_hash( + _first.GetHashCode(), + _second.GetHashCode()); - public override string ToString() => $"AndTrigger ({_first}, {_second})"; + public override string ToString() => + $"AndTrigger ({_first}, {_second})"; } - class OrTrigger : IPredicate { + class OrTrigger : IPredicate, IEquatable> { readonly IPredicate _first, _second; public OrTrigger(IPredicate first, IPredicate second) { @@ -160,16 +195,24 @@ namespace mbts { public bool trigger(T value) => _first.trigger(value) || _second.trigger(value); + public bool Equals(OrTrigger other) => + other != null && + _first.Equals(other._first) && + _second.Equals(other._second); + public override bool Equals(object obj) => - obj is OrTrigger t && _first.Equals(t._first) && _second.Equals(t._second); + Equals(obj is OrTrigger); public override int GetHashCode() => - EqualityComparer.aggregate_hash(_first.GetHashCode(), _second.GetHashCode()); + EqualityComparer.aggregate_hash( + _first.GetHashCode(), + _second.GetHashCode()); - public override string ToString() => $"OrTrigger ({_first}, {_second})"; + public override string ToString() => + $"OrTrigger ({_first}, {_second})"; } - class OrTrigger : IPredicate<(T1, T2)> { + class OrTrigger : IPredicate<(T1, T2)>, IEquatable> { readonly IPredicate _first; readonly IPredicate _second; @@ -178,15 +221,25 @@ namespace mbts { _second = second; } - public bool trigger((T1, T2) value) => _first.trigger(value.Item1) || _second.trigger(value.Item2); + public bool trigger((T1, T2) value) => + _first.trigger(value.Item1) || + _second.trigger(value.Item2); + + public bool Equals(OrTrigger other) => + other != null && + _first.Equals(other._first) && + _second.Equals(other._second); public override bool Equals(object obj) => - obj is OrTrigger t && _first.Equals(t._first) && _second.Equals(t._second); + Equals(obj as OrTrigger); public override int GetHashCode() => - EqualityComparer.aggregate_hash(_first.GetHashCode(), _second.GetHashCode()); + EqualityComparer.aggregate_hash( + _first.GetHashCode(), + _second.GetHashCode()); - public override string ToString() => $"OrTrigger ({_first}, {_second})"; + public override string ToString() => + $"OrTrigger ({_first}, {_second})"; } class GreaterThanTrigger : IPredicate { @@ -198,29 +251,66 @@ namespace mbts { _comparer = comparer; } - public bool trigger(T value) => _comparer.Compare(value, _value) > 0; + public bool trigger(T value) => + _comparer.Compare(value, _value) > 0; - public override string ToString() => $"GreaterThanTrigger ({_value})"; + public override string ToString() => + $"GreaterThanTrigger ({_value})"; } - class InSetTrigger: IPredicate { + class GreaterThanOrEqualToTrigger : IPredicate, IEquatable> { + readonly T _value; + readonly IComparer _comparer; + + public GreaterThanOrEqualToTrigger(T value, IComparer comparer) { + _value = value; + _comparer = comparer; + } + + public bool trigger(T value) => + _comparer.Compare(value, _value) >= 0; + + public bool Equals(GreaterThanOrEqualToTrigger other) => + other != null && + _comparer.Equals(other._comparer) && + _comparer.Compare(_value, other._value) == 0; + + public override bool Equals(object obj) => + Equals(obj as GreaterThanOrEqualToTrigger); + + public override int GetHashCode() => + _value.GetHashCode(); + + public override string ToString() => + $"GreaterThanTrigger ({_value})"; + } + + class InSetTrigger : IPredicate, IEquatable> { readonly ISet _set; public InSetTrigger(ISet set) => _set = set; - public bool trigger(T value) => _set.Contains(value); + public bool trigger(T value) => + _set.Contains(value); + + public bool Equals(InSetTrigger other) => + other != null && + // check SetEquals with both sets (IEqualityComparers may differ) + _set.SetEquals(other._set) && + other._set.SetEquals(_set); public override bool Equals(object obj) => obj is InSetTrigger t && _set.SetEquals(t._set); public override int GetHashCode() => - _set.GetHashCode(); + EqualityComparer.auto_phase(_set.Take(8)); - public override string ToString() => $"InSetTrigger (Count: {_set.Count}, type: {typeof(T)})"; + public override string ToString() => + $"InSetTrigger (Count: {_set.Count}, type: {typeof(T)})"; } - class WrapperTrigger : IPredicate { + class WrapperTrigger : IPredicate, IEquatable> { readonly IPredicate _inner_trigger; readonly Func _selector; @@ -229,26 +319,41 @@ namespace mbts { _selector = selector; } - public bool trigger(TOuter value) => _inner_trigger.trigger(_selector(value)); + public bool trigger(TOuter value) => + _inner_trigger.trigger(_selector(value)); + + public bool Equals(WrapperTrigger other) => + other != null && + _selector.Equals(other._selector) && + _inner_trigger.Equals(other._inner_trigger); public override bool Equals(object obj) => - obj is WrapperTrigger t && _inner_trigger.Equals(t._inner_trigger) && _selector.Equals(t._selector); + Equals(obj as WrapperTrigger); public override int GetHashCode() => - EqualityComparer.aggregate_hash(_inner_trigger.GetHashCode(), _selector.GetHashCode()); + EqualityComparer.aggregate_hash( + _inner_trigger.GetHashCode(), + _selector.GetHashCode()); - public override string ToString() => $"WrapperTrigger (outer-type {typeof(TOuter)}, inner-trigger: {_inner_trigger})"; + public override string ToString() => + $"WrapperTrigger (outer-type {typeof(TOuter)}, inner-trigger: {_inner_trigger})"; } - class NegateTrigger : IPredicate { + class NegateTrigger : IPredicate, IEquatable> { readonly IPredicate _trigger; + public NegateTrigger(IPredicate trigger) => _trigger = trigger; - public bool trigger(T value) => !_trigger.trigger(value); + public bool trigger(T value) => + !_trigger.trigger(value); + + public bool Equals(NegateTrigger other) => + other != null && + _trigger.Equals(other._trigger); public override bool Equals(object obj) => - obj is NegateTrigger t && _trigger.Equals(t._trigger); + Equals(obj as NegateTrigger); public override int GetHashCode() => -_trigger.GetHashCode(); @@ -256,16 +361,22 @@ namespace mbts { public override string ToString() => $"NegateTrigger ({_trigger})"; } - class AnonymousTrigger : IPredicate { + class AnonymousTrigger : IPredicate, IEquatable> { readonly Func _trigger; public AnonymousTrigger(Func trigger) => _trigger = trigger; - public bool trigger(T value) => _trigger(value); + public bool Equals(AnonymousTrigger other) => + other != null && + _trigger.Equals(other._trigger); - public override string ToString() => $"AnonymousTrigger ({typeof(T)})"; + public bool trigger(T value) => + _trigger(value); + + public override string ToString() => + $"AnonymousTrigger ({typeof(T)})"; } #endregion } -} \ No newline at end of file +} From 6572c7344dadaf09c6d43ebe03a1bc1b52e53669 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Tue, 27 Aug 2019 11:10:04 -0400 Subject: [PATCH 058/116] move TradeInfo into its own file --- .../Market/TimeAndSales/TimeAndSalesModel.cs | 10 ---------- src/client/spark/Trades/TradeInfo.cs | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 10 deletions(-) create mode 100644 src/client/spark/Trades/TradeInfo.cs diff --git a/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesModel.cs b/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesModel.cs index 2b17345e6..b0121b166 100644 --- a/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesModel.cs +++ b/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesModel.cs @@ -7,16 +7,6 @@ using System.Linq; using System.Reactive.Linq; namespace mbts.spark { - struct TradeInfo { - public readonly SecurityImmutable security; - public readonly TradeMessageImmutable trade; - - public TradeInfo(SecurityImmutable security, TradeMessageImmutable trade) { - this.security = security; - this.trade = trade; - } - } - class TimeAndSalesModel : IDisposable { internal readonly SecurityCriteria security_criteria; diff --git a/src/client/spark/Trades/TradeInfo.cs b/src/client/spark/Trades/TradeInfo.cs new file mode 100644 index 000000000..e1ee23f7a --- /dev/null +++ b/src/client/spark/Trades/TradeInfo.cs @@ -0,0 +1,14 @@ +using bts.api; +using bts.co2; + +namespace mbts.spark { + struct TradeInfo { + public readonly SecurityImmutable security; + public readonly TradeMessageImmutable trade; + + public TradeInfo(SecurityImmutable security, TradeMessageImmutable trade) { + this.security = security; + this.trade = trade; + } + } +} \ No newline at end of file From 76cc77485a8d507ad4d5cb3932324f32bbcddde7 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Tue, 27 Aug 2019 11:10:19 -0400 Subject: [PATCH 059/116] added Side.to_aggressor extension --- src/client/spark/Orders/OrderUtils.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/client/spark/Orders/OrderUtils.cs b/src/client/spark/Orders/OrderUtils.cs index 090939148..e109fcdd4 100644 --- a/src/client/spark/Orders/OrderUtils.cs +++ b/src/client/spark/Orders/OrderUtils.cs @@ -1,5 +1,6 @@ using bts.api; using bts.api.orderman; +using bts.co2; using bts.spark; using bts.utils; using mbts.spark.utilities; @@ -328,5 +329,13 @@ namespace mbts.spark { return string.Empty; } } + + public static AggressorSide to_aggressor(this Side side) { + switch (side) { + case Side.Buy: return AggressorSide.Buy; + case Side.Sell: return AggressorSide.Sell; + default: return AggressorSide.None; + } + } } } From 8ef97d012af22aa1887ec2e48744ec8ebb511b1a Mon Sep 17 00:00:00 2001 From: John Colvin Date: Tue, 27 Aug 2019 11:10:43 -0400 Subject: [PATCH 060/116] EnumHelper.split_flags requires all bits to match and be non-zero --- src/client/spark/view/Utility/EnumHelper.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/client/spark/view/Utility/EnumHelper.cs b/src/client/spark/view/Utility/EnumHelper.cs index 3fc0c8926..ff87cca95 100644 --- a/src/client/spark/view/Utility/EnumHelper.cs +++ b/src/client/spark/view/Utility/EnumHelper.cs @@ -79,7 +79,8 @@ namespace mbts.ui.utility { long lflags = Convert.ToInt64(flags); foreach (TEnum e in get_values()) { long lval = Convert.ToInt64(e); - if ((lval & lflags)!= 0) + long common_bits = lval & lflags; + if (common_bits != 0 && common_bits == lval) yield return e; } } From d9bb6673513880ff18f1aff74f6d5f82ef5bdfdd Mon Sep 17 00:00:00 2001 From: John Colvin Date: Tue, 27 Aug 2019 11:12:38 -0400 Subject: [PATCH 061/116] added AppendTextConverter --- .../view/Converters/AppendTextConverter.cs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/client/spark/view/Converters/AppendTextConverter.cs diff --git a/src/client/spark/view/Converters/AppendTextConverter.cs b/src/client/spark/view/Converters/AppendTextConverter.cs new file mode 100644 index 000000000..c9de27145 --- /dev/null +++ b/src/client/spark/view/Converters/AppendTextConverter.cs @@ -0,0 +1,22 @@ +using System; +using System.Globalization; +using System.Text; +using System.Windows.Data; + +namespace mbts.ui.converters { + class AppendTextConverter : IValueConverter { + public string Prefix { get; set; } + public string Suffix { get; set; } + + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { + var sb = new StringBuilder(value?.ToString()); + // don't need to check for null (Insert/Append support it) + sb.Insert(0, Prefix); + sb.Append(Suffix); + return sb.ToString(); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => + throw new NotImplementedException(); + } +} \ No newline at end of file From d42ebd7ea5869f81b0ec124c8a6a7606f92299b6 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Tue, 27 Aug 2019 11:13:06 -0400 Subject: [PATCH 062/116] added ExceptionAssert.Between method --- src/client/spark_core/utils/Exceptions/ExceptionAssert.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/client/spark_core/utils/Exceptions/ExceptionAssert.cs b/src/client/spark_core/utils/Exceptions/ExceptionAssert.cs index 05a86f42e..e61beb3fe 100644 --- a/src/client/spark_core/utils/Exceptions/ExceptionAssert.cs +++ b/src/client/spark_core/utils/Exceptions/ExceptionAssert.cs @@ -44,6 +44,11 @@ namespace mbts.utils { throw new ArgumentException($"Must equal {value}.", name); } + public static void Between(T argument, T minimum, T maximum, string name) where T : struct, IComparable { + if (argument.CompareTo(minimum) < 0 || argument.CompareTo(maximum) > 0) + throw new ArgumentException($"Must be between {minimum} and {maximum}, inclusive (actually {argument}).", name); + } + public static void GreaterThan(T argument, T value, string name) where T : IComparable { if (argument.CompareTo(value) <= 0) throw new ArgumentException($"Must be greater than {value}.", name); From 258f4f394d6960379e3066c409f794715491db2f Mon Sep 17 00:00:00 2001 From: John Colvin Date: Tue, 27 Aug 2019 11:14:38 -0400 Subject: [PATCH 063/116] added NotificationProcessor.process_items (handles multiple items rather than 1) --- .../Notifications/INotificationService.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/client/spark/Notifications/INotificationService.cs b/src/client/spark/Notifications/INotificationService.cs index bb9437610..002ead80c 100644 --- a/src/client/spark/Notifications/INotificationService.cs +++ b/src/client/spark/Notifications/INotificationService.cs @@ -128,6 +128,31 @@ namespace bts.shell { if (sounds.Count > 0 || toast.Count > 0) _notifier.notify(toast, sounds); } + + public void process_items(IEnumerable source) { + var sounds = new HashSet(); + var toast = new HashSet(); + var temp_sound_triggers = _sound_trigger_refs; + if (temp_sound_triggers.Count > 0) { + foreach (var v in source) { + foreach (var trigger_kv in temp_sound_triggers) { + if (trigger_kv.Key.trigger(v)) + sounds.AddRange(trigger_kv.Value.Keys); + } + } + } + var temp_toast_triggers = _toast_trigger_refs; + if (temp_toast_triggers.Count > 0) { + foreach (var v in source) { + foreach (var trigger_kv in temp_toast_triggers) { + if (trigger_kv.Key.trigger(v) is IToastNotification tn && tn.pass) + toast.Add(tn); + } + } + } + if (sounds.Count > 0 || toast.Count > 0) + _notifier.notify(toast, sounds); + } } } } \ No newline at end of file From a9df42deec3840b06cd6f1a24942561587c833ef Mon Sep 17 00:00:00 2001 From: John Colvin Date: Tue, 27 Aug 2019 11:15:33 -0400 Subject: [PATCH 064/116] added SparkTag/Command to show GlobalAlerts dialog (not yet implemented) --- src/client/spark/Images/Icons.cs | 2 ++ src/client/spark/Images/Vector/Icons.xaml | 4 ++++ src/client/spark/core/Bus/SparkCommands.cs | 5 ++++- src/client/spark/core/Bus/SparkTags.cs | 2 ++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/client/spark/Images/Icons.cs b/src/client/spark/Images/Icons.cs index 3cc17164d..40ec41564 100644 --- a/src/client/spark/Images/Icons.cs +++ b/src/client/spark/Images/Icons.cs @@ -40,6 +40,7 @@ namespace mbts.ui { EditDocumentAltGeometryKey = nameof(EditDocumentAltGeometryKey), EditDocumentGeometryKey = nameof(EditDocumentGeometryKey), GearGeometryKey = nameof(GearGeometryKey), + HornGeometryKey = nameof(HornGeometryKey), LetterAKey = nameof(LetterAKey), LetterDKey = nameof(LetterDKey), OrdersGeometryKey = nameof(OrdersGeometryKey), @@ -168,6 +169,7 @@ namespace mbts.ui { public static ImageSource FilterActive { get { return load_resource_and_freeze("FilterActive"); } } public static ImageSource FilterError { get { return load_resource_and_freeze("FilterError"); } } public static ImageSource Gear => create_icon(GearGeometryKey); + public static ImageSource Horn => create_icon(HornGeometryKey); public static ImageSource Import => load_resource_and_freeze("Import"); public static ImageSource Knight { get { return load_resource_and_freeze("Knight"); } } public static ImageSource Payment => create_icon(PaymentGeometryKey); diff --git a/src/client/spark/Images/Vector/Icons.xaml b/src/client/spark/Images/Vector/Icons.xaml index a0ce61363..f0e4d9a61 100644 --- a/src/client/spark/Images/Vector/Icons.xaml +++ b/src/client/spark/Images/Vector/Icons.xaml @@ -274,6 +274,10 @@ M16.000015,9.6000061C12.500012,9.6000061 9.5999844,12.5 9.5999844,16 9.5999844,19.5 12.500012,22.399994 16.000015,22.399994 19.500019,22.399994 22.400015,19.5 22.400015,16 22.400015,12.5 19.500019,9.6000061 16.000015,9.6000061z M14.199995,0L17.800005,0C18.199999,0,18.599993,0.29998779,18.599993,0.79998779L18.599993,4.7999878C19.900013,5.1000061,21.000019,5.6000061,22.099997,6.2999878L25.000023,3.3999939C25.099999,3.2999878 25.300011,3.1999817 25.500025,3.1999817 25.700007,3.1999817 25.900019,3.2999878 26.000025,3.3999939L28.600033,6C28.900021,6.2999878,28.900021,6.7999878,28.600033,7.1000061L25.700007,10C26.400019,11.100006,26.900019,12.299988,27.200007,13.5L31.20001,13.5C31.600037,13.5,31.999998,13.799988,31.999998,14.299988L31.999998,17.899994C31.999998,18.299988,31.700012,18.699982,31.20001,18.699982L27.200007,18.699982C26.900019,20,26.400019,21.100006,25.700007,22.199982L28.600033,25.100006C28.700009,25.199982 28.799984,25.399994 28.799984,25.600006 28.799984,25.799988 28.700009,26 28.600033,26.100006L26.000025,28.600006C25.900019,28.699982 25.700007,28.799988 25.500025,28.799988 25.300011,28.799988 25.099999,28.699982 25.000023,28.600006L22.099997,25.699982C21.000019,26.399994,19.800007,26.899994,18.599993,27.199982L18.599993,31.199982C18.599993,31.600006,18.300005,32,17.800005,32L14.199995,32C13.8,32,13.400006,31.699982,13.400006,31.199982L13.400006,27.199982C12.099987,26.899994,11.000011,26.399994,9.9000027,25.699982L7.0000064,28.600006C6.9000003,28.699982 6.6999881,28.799988 6.5000059,28.799988 6.2999937,28.799988 6.099981,28.699982 6.0000054,28.600006L3.3999967,26C3.0999784,25.699982,3.0999784,25.199982,3.3999967,24.899994L6.2999937,22C5.5999805,20.899994,5.0999801,19.699982,4.7999923,18.5L0.79998828,18.5C0.39999409,18.5,-1.933513E-07,18.199982,0,17.699982L0,14.100006C-1.933513E-07,13.699982,0.2999879,13.299988,0.79998828,13.299988L4.7999923,13.299988C5.0999801,12,5.5999805,10.899994,6.2999937,9.7999878L3.3999967,7C3.2999908,6.8999939 3.1999845,6.6999817 3.1999845,6.5 3.1999845,6.2999878 3.2999908,6.1000061 3.3999967,6L6.0000054,3.3999939C6.099981,3.2999878 6.2999937,3.1999817 6.5000059,3.1999817 6.6999881,3.1999817 6.9000003,3.2999878 7.0000064,3.3999939L9.9000027,6.2999878C11.000011,5.6000061,12.199993,5.1000061,13.400006,4.7999878L13.400006,0.79998779C13.400006,0.29998779,13.8,0,14.199995,0z + + M4.0499969,7.0870913C2.9519978,7.0870913 2.0249984,8.4780906 2.0249987,10.125091 2.0249984,11.771091 2.9519978,13.162091 4.0499969,13.162091 5.1479961,13.162091 6.0749954,11.771091 6.0749955,10.125091 6.0749954,8.4780906 5.1479961,7.0870913 4.0499969,7.0870913z M29.975016,3.316155C23.883831,8.2016557,11.829888,8.9691842,8.1184387,9.0896781L8.0151367,9.0928462 8.0175586,9.1059306C8.0716033,9.4352315 8.0999939,9.7760909 8.0999942,10.125091 8.0999939,10.473966 8.0716033,10.814716 8.0175586,11.143921L8.0098858,11.185364 8.193316,11.195448C12.163719,11.420399,23.994581,12.458921,29.975016,17.005057z M31.176758,0.00019051835C31.280359,-0.0022594665 31.391857,0.01889403 31.514975,0.065146674 31.908983,0.21413228 31.999985,0.59114302 31.999985,1.0121596L31.999985,19.236969C31.999985,19.653958 31.913988,20.028956 31.525991,20.179955 31.405998,20.226952 31.450981,20.250023 31.32699,20.250023 31.050991,20.250023 30.778992,20.13601 30.583986,19.925928 25.229074,14.140572 9.6001122,13.269665 7.2865356,13.172559L7.2813506,13.172345 7.1739591,13.343056C6.4304952,14.468533 5.3060585,15.187091 4.0499969,15.187091 1.8169985,15.187091 0,12.916091 0,10.125091 0,7.3330911 1.8169985,5.0620912 4.0499969,5.0620912 5.3060585,5.0620912 6.4304952,5.78065 7.1739591,6.9063042L7.2852713,7.0832756 7.3087114,7.0828188C9.6077337,7.036146 25.141474,6.4939421 30.567997,0.34315929 30.75913,0.12521249 30.948835,0.005580858 31.176758,0.00019051835z + + M50.14375,33.389126C50.416863,33.394688,50.653496,33.587773,50.705998,33.864617L50.015995,45.114388C49.810295,46.291462,49.130394,45.097489,49.130394,45.097489L47.65659,42.640538C42.747776,49.635197 34.633152,54.221001 25.433924,54.221001 14.884193,54.221001 5.7437552,48.204125 1.2449617,39.419205 0.80087067,38.552021 0.21358696,37.705738 0.052086769,36.736958 -0.49735315,33.490925 3.4507786,32.901036 4.8049124,34.432404 5.3674143,35.067692 6.034036,36.16407 6.5079177,37.026051 10.106778,43.799416 17.2321,48.413819 25.433924,48.413819 32.656544,48.413819 39.026364,44.826695 42.903977,39.351506L40.229367,38.854115C40.229367,38.854115,38.677464,38.647118,39.742466,37.996033L50.024895,33.398526C50.064972,33.391365,50.104733,33.388333,50.14375,33.389126z M23.030291,9.0310004L27.889918,9.0310004 27.889918,13.028299C30.539786,13.205498,32.324932,13.958096,33.464161,14.528294L33.964176,14.775793 32.417435,20.038878 31.706417,19.68068C30.579987,19.11958 28.839241,18.244583 26.149073,18.244583 24.006916,18.244583 22.723183,19.122181 22.723183,20.590876 22.723183,21.894272 23.943314,22.804369 27.551308,24.187165 32.706444,26.124659 34.911,28.702853 34.911,32.817341 34.911,36.892929 32.090527,40.05172 27.673611,40.989117L27.673611,45.540001 22.767485,45.540001 22.767485,41.330414C20.252919,41.155815,17.695551,40.424118,16.101811,39.404721L15.683999,39.137619 17.221739,33.731438 17.969059,34.180634C19.088988,34.851235 21.402748,35.97873 24.340325,35.97873 26.734886,35.97873 28.276728,34.921635 28.276728,33.291336 28.276728,31.986641 27.547409,30.853846 23.986016,29.57255 20.083815,28.144253 16.095511,26.04406 16.095511,21.239174 16.095511,17.280985 18.737379,14.291395 23.030291,13.329098z M25.268765,0C35.819447,2.7347414E-07 44.961449,6.0155495 49.458798,14.804573 49.902695,15.669173 50.490094,16.516972 50.651287,17.48427 51.198281,20.734265 47.255726,21.318962 45.901341,19.789065 45.336346,19.153567 44.669552,18.051968 44.19566,17.19517 40.5957,10.421881 33.473275,5.8072398 25.268765,5.8072393 18.047545,5.8072398 11.678013,9.3918336 7.8003562,14.867073L10.474627,15.367072C10.474627,15.367072,12.026909,15.574172,10.962921,16.223872L0.67933281,20.826762C0.36037083,20.880062,0.057029126,20.669165,0.00099972012,20.354063L0.69093342,9.1118043C0.89552094,7.9296158,1.5738537,9.124924,1.5738539,9.124924L3.0452772,11.583379C7.9566038,4.584462,16.073666,2.7347414E-07,25.268765,0z diff --git a/src/client/spark/core/Bus/SparkCommands.cs b/src/client/spark/core/Bus/SparkCommands.cs index 726eff24a..b78e943cf 100644 --- a/src/client/spark/core/Bus/SparkCommands.cs +++ b/src/client/spark/core/Bus/SparkCommands.cs @@ -107,6 +107,9 @@ namespace bts.spark { public static SparkCommand ShowActivityLog => SparkCommand.create("Activity Log", Icons.Wrench, SparkTags.ShowActivityLog); + public static SparkCommand ShowGlobalAlerts => + SparkCommand.create("Alerts", Icons.Horn, SparkTags.ShowGlobalAlertsTag); + public static PartialCommand ShowReportIssue => SparkCommand.create("Report a Problem", Icons.Support, SparkTags.Support); @@ -122,7 +125,7 @@ namespace bts.spark { public static PartialCommand ShowModifyOrder => SparkCommand.create("Modify", Icons.ModifyOrder, SparkTags.ShowModifyOrderTag); public static PartialCommand> RecreateSelectedOrders => - SparkCommand.create("Recreate", Icons.Beaker, SparkTags.RecreateOrder); + SparkCommand.create("Recreate", Icons.Horn, SparkTags.RecreateOrder); // TODO: remove this method, eventually want all windows to use window_settings_command() public static SparkCommand change_securities_command(Func<(PartialCommand, SecurityCriteria)> get_param) => diff --git a/src/client/spark/core/Bus/SparkTags.cs b/src/client/spark/core/Bus/SparkTags.cs index eef9c6d4e..bf009631b 100644 --- a/src/client/spark/core/Bus/SparkTags.cs +++ b/src/client/spark/core/Bus/SparkTags.cs @@ -81,6 +81,8 @@ namespace mbts.spark public static ITag SyntheticDeleteTag { get; } = new SparkTag(nameof(SyntheticDeleteTag)); + public static ITag ShowGlobalAlertsTag { get; } = new SparkTag(nameof(ShowGlobalAlertsTag)); + public class Nothing { Nothing() { } } internal class SparkTag : ITag { From 6f68c0f6a148c2db6675a7b6401630db9531e77a Mon Sep 17 00:00:00 2001 From: John Colvin Date: Tue, 27 Aug 2019 11:16:07 -0400 Subject: [PATCH 065/116] PredicateBuilder.greater/less_than_or_equal_to factory methods --- src/client/spark/Predicates/IPredicate.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/client/spark/Predicates/IPredicate.cs b/src/client/spark/Predicates/IPredicate.cs index 11edf88d6..5b6d0df2c 100644 --- a/src/client/spark/Predicates/IPredicate.cs +++ b/src/client/spark/Predicates/IPredicate.cs @@ -35,9 +35,15 @@ namespace mbts { public static IPredicate greater_than(T value) => new GreaterThanTrigger(value, Comparer.Default); + public static IPredicate greater_than_or_equal_to(T value) => + new GreaterThanOrEqualToTrigger(value, Comparer.Default); + public static IPredicate less_than(T value) => greater_than(value).negate(); + public static IPredicate less_than_or_equal_to(T value) => + greater_than_or_equal_to(value).negate(); + public static IPredicate inside_range(T minimum, T maximum) => greater_than(minimum).and(less_than(maximum)); From 0fb69c8beb0db18ad59f50b00d3e5d1d87ec0401 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Tue, 27 Aug 2019 11:16:44 -0400 Subject: [PATCH 066/116] PredicateBuilder.and_safe factory method (handles null args gracefully) --- src/client/spark/Predicates/IPredicate.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/client/spark/Predicates/IPredicate.cs b/src/client/spark/Predicates/IPredicate.cs index 5b6d0df2c..c5ae09899 100644 --- a/src/client/spark/Predicates/IPredicate.cs +++ b/src/client/spark/Predicates/IPredicate.cs @@ -74,6 +74,14 @@ namespace mbts { public static IPredicate not_in_set(ISet set) => in_set(set).negate(); + public static IPredicate and_safe(this IPredicate first, IPredicate second) { + if (first == null) + return second; + if (second == null) + return first; + return and(first, second); + } + public static IPredicate and(this IPredicate first, IPredicate second) => new AndTrigger(first, second); From 2b12e7fee1beac368079287c4c6b0271cd37ae9e Mon Sep 17 00:00:00 2001 From: John Colvin Date: Tue, 27 Aug 2019 11:17:28 -0400 Subject: [PATCH 067/116] INotificationService.link_to_trades method/impl --- .../Notifications/INotificationService.cs | 65 ++++++++++++++++++- 1 file changed, 62 insertions(+), 3 deletions(-) diff --git a/src/client/spark/Notifications/INotificationService.cs b/src/client/spark/Notifications/INotificationService.cs index 002ead80c..47e61a63a 100644 --- a/src/client/spark/Notifications/INotificationService.cs +++ b/src/client/spark/Notifications/INotificationService.cs @@ -4,6 +4,7 @@ using bts.api.orderman; using bts.collections; using bts.spark; using mbts; +using mbts.co2; using mbts.collections; using mbts.spark; using mbts.ui; @@ -13,6 +14,7 @@ using System.Collections.Generic; using System.ComponentModel.Composition; using System.Linq; using System.Reactive.Linq; +using System.Reactive.Subjects; namespace bts.shell { interface INotificationService { @@ -22,25 +24,48 @@ namespace bts.shell { IDisposable link_to_activity(INotificationPredicate toast_notification_predicate); IDisposable link_to_order(IPredicate predicate, SoundNotification sound); IDisposable link_to_order(INotificationPredicate toast_notification_predicate); + // Note: security criteria should not be incorporated in the predicate's 'trigger' impl. + // It is easier/cleaner if the INotificationService incorporates the criteria internally. + IDisposable link_to_trades(SecurityCriteria security_criteria, IPredicate predicate, SoundNotification sound); } [Export(typeof(INotificationService))] partial class NotificationService : INotificationService, IDisposable { + // activity notifications readonly NotificationProcessor _activity_notifications; + // order notifications readonly NotificationProcessor _order_notifications; + // trade notifications + readonly NotificationProcessor _trade_notifications; + readonly MDConsumer _consumer; + readonly Subject> _trade_criteria_subject = new Subject>(); + readonly RefCountMap _trade_criteria_refs = new RefCountMap(); + readonly object _trade_lock = new object(); + // readonly DataCache _data_cache = new DataCache(); + readonly LoggerContext _log = new LoggerContext(Log.Ui, "Notification Service ", null); IDisposable _dispose; [ImportingConstructor] - public NotificationService(IBus bus, INotifier notifier, OrdersModel orders_model) { + public NotificationService(IBus bus, INotifier notifier, OrdersModel orders_model, MDConsumer consumer) { this.notifier = notifier; _activity_notifications = new NotificationProcessor(notifier); _order_notifications = new NotificationProcessor(notifier); + _trade_notifications = new NotificationProcessor(notifier); + _consumer = consumer; _dispose = Disposable.Create( bus.subscribe(SparkTags.LogActivity).Subscribe(_on_activity), - orders_model.on_orders.Subscribe(_on_orders) - ); + orders_model.on_orders.Subscribe(_on_orders), + TradesSource.create( + consumer, + bus.subscribe(SparkTags.SecuritiesTag).BufferLatest(TimeSpan.FromSeconds(2)) + .Table(s => s.security.Id) + .Where(t => t.has_changes()) + .Select(m => MappedDictionary.create(m.state, smd => smd.security)), + _trade_criteria_subject, + TimeSpan.FromSeconds(0.2)) + .Subscribe(_trade_notifications.process_items)); } [Export(typeof(INotificationServiceDataCache))] @@ -51,8 +76,42 @@ namespace bts.shell { public IDisposable link_to_activity(INotificationPredicate toast_notification_predicate) => _activity_notifications.link(toast_notification_predicate); public IDisposable link_to_order(IPredicate predicate, SoundNotification sound) => _order_notifications.link(predicate, sound); public IDisposable link_to_order(INotificationPredicate toast_notification_predicate) => _order_notifications.link(toast_notification_predicate); + + public IDisposable link_to_trades(SecurityCriteria security_criteria, IPredicate predicate, SoundNotification sound) { + if (predicate == null) { + _log.warn("cannot create trade alert sound because the specified predicate is null."); + return Disposable.empty; + } + if (!security_criteria.is_defined()) { + // there are simply too many trades to support universal-product predicates, therefor a product filter must be specified (aka SecrityCriteria). + _log.warn("cannot create trade alert sound because the specified security criteria is not defined."); + return Disposable.empty; + } + // This criteria predicate may be redundant, but it safe guards against a case + // where the criteria has not been incorporated into the predicate, + // as there doesn't seem to be a great way to require this in the interface. + // Note: verifying the criteria twice (instead of once) should not hurt on perf at all. + predicate = predicate.and(PredicateBuilder.create(t => ContractPickerModel.security_in_criteria(security_criteria, t.security))); + var link = _trade_notifications.link(predicate, sound); + lock (_trade_lock) { + if (_trade_criteria_refs.increment_adds_key(security_criteria)) + _reset_trade_readers(); + } + return Disposable.Create(() => { + Disposable.dispose(ref link); + lock (_trade_lock) { + if (_trade_criteria_refs.decrement_removes_key(security_criteria)) + _reset_trade_readers(); + } + }); + } + public void Dispose() => Disposable.dispose(ref _dispose); + /// should only call this within a locked scope () + void _reset_trade_readers() => + _trade_criteria_subject.OnNext(_trade_criteria_refs.Keys); + void _on_activity(Activity activity) => _activity_notifications.process_item(activity); From 171206953056d950d179a49f55f035cb5647b3df Mon Sep 17 00:00:00 2001 From: John Colvin Date: Tue, 27 Aug 2019 11:17:54 -0400 Subject: [PATCH 068/116] TradeMessage.price extension --- .../spark/Modules/Market/TimeAndSales/TimeAndSalesVM.cs | 2 +- src/client/spark/Trades/TradeMessageExtensions.cs | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/client/spark/Trades/TradeMessageExtensions.cs diff --git a/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesVM.cs b/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesVM.cs index 11a3a44ee..e2b5b8139 100644 --- a/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesVM.cs +++ b/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesVM.cs @@ -137,7 +137,7 @@ namespace mbts.spark { public Row(TimeAndSalesVM parent, SecurityImmutable security, TradeMessageImmutable trade) : base(security) { _trade_key = trade.Key; time = ((ulong)trade.Time).lldatetime().ToLocalTime(); - price = trade.Mantissa * Math.Pow(10, trade.Exponent); + price = trade.price(); size = trade.Size; aggressor_side = trade.AggressorSide; show_ladder = new DelegateCommand(() => parent._show_ladder_async(this).ignore()); diff --git a/src/client/spark/Trades/TradeMessageExtensions.cs b/src/client/spark/Trades/TradeMessageExtensions.cs new file mode 100644 index 000000000..f01a273d9 --- /dev/null +++ b/src/client/spark/Trades/TradeMessageExtensions.cs @@ -0,0 +1,9 @@ +using bts.co2; +using System; + +namespace mbts.spark { + static class TradeMessageExtensions { + public static double price(this TradeMessageImmutable trade) => + trade.Mantissa * Math.Pow(10, trade.Exponent); + } +} \ No newline at end of file From 67d62f0d8c311697ac51a3f476d49617d15ac311 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Tue, 27 Aug 2019 11:18:19 -0400 Subject: [PATCH 069/116] IPropertyWrapperVM.sync_with_models extension --- .../spark/core/Utility/IPropertyWrapperVM.cs | 16 ++++++++++++++++ .../spark_core/utils/GlobalExtensions.cs | 18 +++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/client/spark/core/Utility/IPropertyWrapperVM.cs b/src/client/spark/core/Utility/IPropertyWrapperVM.cs index 7db97a542..b8cd8b8da 100644 --- a/src/client/spark/core/Utility/IPropertyWrapperVM.cs +++ b/src/client/spark/core/Utility/IPropertyWrapperVM.cs @@ -59,6 +59,22 @@ namespace mbts.spark { interface ITemplatedPropertyWrapperVM : IPropertyWrapperVM, ITemplateSelectorKey { } + static class ValueFactoryUtils { + public static void sync_with_models(this IList target, IEnumerable models) where TValueFactory : IValueFactory, new() { + target.sync_with_models( + models, + m => { + var vf = new TValueFactory(); + vf.load_from(m); + return vf; + }, + (vf, m) => { + vf.load_from(m); + return vf; + }); + } + } + static class PropertyWrapperVMUtils { public static T create_assigned(this IPropertyWrapperVM vm) where T : new() => vm.create_assigned(() => new T()); diff --git a/src/client/spark_core/utils/GlobalExtensions.cs b/src/client/spark_core/utils/GlobalExtensions.cs index 7433968b4..b8d93f6bc 100644 --- a/src/client/spark_core/utils/GlobalExtensions.cs +++ b/src/client/spark_core/utils/GlobalExtensions.cs @@ -67,6 +67,22 @@ namespace mbts { } } - + public static void sync_with_models(this IList target, IEnumerable models, Func add_factory, Func update_factory) { + var model_list = models as IList ?? models.ToList(); + if (model_list.Count == 0) { + target.Clear(); + } else { + int stop = Math.Min(target.Count, model_list.Count); + for (int i = 0; i < stop; i++) { + target[i] = update_factory(target[i], model_list[i]); + } + while (target.Count < model_list.Count) { + target.Add(add_factory(model_list[target.Count])); + } + while (model_list.Count < target.Count) { + target.RemoveAt(model_list.Count); + } + } + } } } \ No newline at end of file From 298f9261b4802826a8fcfa499e15cfc8b8b3602a Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Tue, 27 Aug 2019 14:49:43 -0500 Subject: [PATCH 070/116] allow overrideable settings to not be overridden --- .../Controls/DIYGrid/Settings/SimpleGridColumnSettingsVM.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridColumnSettingsVM.cs b/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridColumnSettingsVM.cs index 51f0f532e..250bcfc3d 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridColumnSettingsVM.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridColumnSettingsVM.cs @@ -55,8 +55,8 @@ namespace mbts.spark { can_override_display_name ? display_name : null, is_visible, null, - is_font_weight_overridden ? new NullableFontWeightProto(font_weight_override) : (NullableFontWeightProto?)null, - is_font_color_overridden ? new NullableColorProto(font_color_override.color) : (NullableColorProto?)null, + can_override_font_weight ? (is_font_weight_overridden ? new NullableFontWeightProto(font_weight_override) : new NullableFontWeightProto()) : (NullableFontWeightProto?)null, + can_override_font_color ? (is_font_color_overridden ? new NullableColorProto(font_color_override.color) : new NullableColorProto()) : (NullableColorProto?)null, width, horizontal_alignment, background_color_override: is_background_color_overridden ? From e2d065f6b34f587d2b14c763cdafd6cd0768a164 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Tue, 27 Aug 2019 15:12:21 -0500 Subject: [PATCH 071/116] allow font color to change on bid/ask implied/direct/merged cols --- src/client/spark/Modules/Market/MarketView/MarketViewVM.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs b/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs index 9e67a4bb1..b8257083e 100644 --- a/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs +++ b/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs @@ -113,12 +113,6 @@ namespace mbts.spark { var col_settings_flags = new Dictionary { { Columns.Bid.ToString(), GridColumnSettingsFeatureFlags.ImmutableFontColor | GridColumnSettingsFeatureFlags.ImmutableBackgroundColor }, { Columns.Ask.ToString(), GridColumnSettingsFeatureFlags.ImmutableFontColor | GridColumnSettingsFeatureFlags.ImmutableBackgroundColor}, - { Columns.BidImpliedSize.ToString(), GridColumnSettingsFeatureFlags.ImmutableFontColor }, - { Columns.BidDirectSize.ToString(), GridColumnSettingsFeatureFlags.ImmutableFontColor }, - { Columns.BidMergedSize.ToString(), GridColumnSettingsFeatureFlags.ImmutableFontColor }, - { Columns.AskImpliedSize.ToString(), GridColumnSettingsFeatureFlags.ImmutableFontColor }, - { Columns.AskDirectSize.ToString(), GridColumnSettingsFeatureFlags.ImmutableFontColor }, - { Columns.AskMergedSize.ToString(), GridColumnSettingsFeatureFlags.ImmutableFontColor }, { Columns.WorkingAsks.ToString(), GridColumnSettingsFeatureFlags.ImmutableFontColor }, { Columns.WorkingBids.ToString(), GridColumnSettingsFeatureFlags.ImmutableFontColor } }; From d52ec704fbccbfd923e08a4ce03fb2568150d24b Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Tue, 27 Aug 2019 15:14:49 -0500 Subject: [PATCH 072/116] bind Foreground to font_brush --- .../DIYGrid/Columns/FrameworkElementColumns/HyperlinkColumn.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/client/spark/view/Controls/DIYGrid/Columns/FrameworkElementColumns/HyperlinkColumn.cs b/src/client/spark/view/Controls/DIYGrid/Columns/FrameworkElementColumns/HyperlinkColumn.cs index efeaa83b7..2b6b62bf0 100644 --- a/src/client/spark/view/Controls/DIYGrid/Columns/FrameworkElementColumns/HyperlinkColumn.cs +++ b/src/client/spark/view/Controls/DIYGrid/Columns/FrameworkElementColumns/HyperlinkColumn.cs @@ -24,7 +24,8 @@ namespace mbts.ui.controls { public Thickness padding { get; set; } = _default_padding; public override FrameworkElement view_factory() { - var hl = new HyperlinkCell { Foreground = font_brush, Padding = padding }; + var hl = new HyperlinkCell { Padding = padding }; + hl.SetBinding(HyperlinkCell.ForegroundProperty, new Binding(nameof(font_brush)) { Source = this }); hl.SetBinding(HyperlinkCell.TextProperty, _binding); hl.SetBinding(HyperlinkCell.FontFamilyProperty, new Binding(nameof(font_family)) { Source = this }); hl.SetBinding(HyperlinkCell.FontSizeProperty, new Binding(nameof(font_size)) { Source = this }); From b528e1c1ecf098d570e49efd8507b189d04ed6d8 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Tue, 27 Aug 2019 16:48:14 -0500 Subject: [PATCH 073/116] background color default should be transparent and not black --- .../spark/view/Controls/DIYGrid/Settings/GridSettings.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettings.cs b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettings.cs index c125d1368..5afc8d146 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettings.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettings.cs @@ -43,6 +43,7 @@ namespace mbts.ui.settings { public static Color font_color => _default_font_color.rgb_color(); public static FontWeight font_weight => FontWeight.FromOpenTypeWeight(_default_font_weight); public static SolidColorBrush selection_highlight => DIYGrid.DefaultSelectionHighlight; + public static uint background_color => _default_background_color; } public static IValueConverter selection_highlight_converter => ValueConverter.create(gs => gs.selection_highlight.to_brush().frozen()); @@ -88,7 +89,7 @@ namespace mbts.ui.settings { public GridSettings( string font_family = _default_font_family, double font_size = _default_font_size, FontWeight font_weight = default, uint font_color = _default_font_color, - ColorOpacityProto? selection_highlight = null, IEnumerable columns = null, IEnumerable sorting_criterion = null, uint background_color = 0, bool enable_background_color = false) { + ColorOpacityProto? selection_highlight = null, IEnumerable columns = null, IEnumerable sorting_criterion = null, uint background_color = _default_background_color, bool enable_background_color = false) { // _font_family = font_family; _font_size = font_size; From f90ef6e12c87741a91ee996ab25c81ea5e65d0ab Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Tue, 27 Aug 2019 16:49:30 -0500 Subject: [PATCH 074/116] changing can we set the background color override to check for can_override_background_color --- .../Controls/DIYGrid/Settings/SimpleGridColumnSettingsVM.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridColumnSettingsVM.cs b/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridColumnSettingsVM.cs index 250bcfc3d..9c6ffa28b 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridColumnSettingsVM.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridColumnSettingsVM.cs @@ -59,8 +59,9 @@ namespace mbts.spark { can_override_font_color ? (is_font_color_overridden ? new NullableColorProto(font_color_override.color) : new NullableColorProto()) : (NullableColorProto?)null, width, horizontal_alignment, - background_color_override: is_background_color_overridden ? - new NullableColorProto(background_color_override.color) : default); + background_color_override: + can_override_background_color ? (is_background_color_overridden ? new NullableColorProto(background_color_override.color) : new NullableColorProto()) : (NullableColorProto ?)null + ); public void load_from(GridColumnSettings value) { _settings = value; From 20df8a6597af5f5fcbd39fafd9a9da5ca15ce052 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Tue, 27 Aug 2019 16:50:47 -0500 Subject: [PATCH 075/116] if show_background, then set the background from the color popup, else default to the Fallback background color, transparent --- .../view/Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs b/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs index 93b4c2552..e90fda0da 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/SimpleGridSettingsVM.cs @@ -109,7 +109,7 @@ namespace mbts.spark { public GridSettings create() => new GridSettings(font_family.name(), font_size, font_weight, font_color.color.rgb_color(), selection_highlight.to_proto(), columns.Select(c => c.create()), - background_color: background_color.color.rgb_color()); + background_color: show_background_color ? background_color.color.rgb_color() : GridSettings.FallbackValues.background_color); public void load_from(GridSettings value) { if (value == null) From a38fb38f3375f0a8f383e3eefb74419340cd18ec Mon Sep 17 00:00:00 2001 From: John Colvin Date: Tue, 27 Aug 2019 11:20:18 -0400 Subject: [PATCH 076/116] added DoublePredicateVM (will use in GlobalAlertsVM) --- .../Data/Primitive/DoublePredicate.cs | 11 +++++++ .../spark/Predicates/VM/DoublePredicateVM.cs | 33 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/client/spark/Predicates/VM/DoublePredicateVM.cs diff --git a/src/client/spark/Predicates/Data/Primitive/DoublePredicate.cs b/src/client/spark/Predicates/Data/Primitive/DoublePredicate.cs index 814ba0b54..997e45b85 100644 --- a/src/client/spark/Predicates/Data/Primitive/DoublePredicate.cs +++ b/src/client/spark/Predicates/Data/Primitive/DoublePredicate.cs @@ -61,6 +61,17 @@ namespace mbts { } } + public static DoublePredicate create(PredicateTypeOneofCase type, double min, double max) { + var rv = new DoublePredicate(); + switch (type) { + case PredicateTypeOneofCase.GreaterThan: rv.greater_than = min; break; + case PredicateTypeOneofCase.LessThan: rv.less_than = max; break; + case PredicateTypeOneofCase.InsideRange: rv.inside_range = new DoubleRange(min, max); break; + case PredicateTypeOneofCase.OutsideRange: rv.outside_range = new DoubleRange(min, max); break; + } + return rv; + } + public IPredicate create() { switch (predicate_type_case) { case PredicateTypeOneofCase.GreaterThan: return PredicateBuilder.greater_than(_greater_than.Value); diff --git a/src/client/spark/Predicates/VM/DoublePredicateVM.cs b/src/client/spark/Predicates/VM/DoublePredicateVM.cs new file mode 100644 index 000000000..b386192e8 --- /dev/null +++ b/src/client/spark/Predicates/VM/DoublePredicateVM.cs @@ -0,0 +1,33 @@ +using bts.proto; +using mbts.ui.shell; + +namespace mbts.spark { + class DoublePredicateVM : ViewModelBase, IValueFactory { + double _minimum, _maximum; + DoublePredicate.PredicateTypeOneofCase _type; + + public DoublePredicate.PredicateTypeOneofCase type { get => _type; set => Set(ref _type, value); } + public double minimum { get => _minimum; set => Set(ref _minimum, value); } + public double maximum { get => _maximum; set => Set(ref _maximum, value); } + + public DoublePredicate create() => + DoublePredicate.create(type, minimum, maximum); + + public void load_from(DoublePredicate value) { + if (value == null) + return; + type = value.predicate_type_case; + switch (type) { + case DoublePredicate.PredicateTypeOneofCase.GreaterThan: minimum = value.greater_than.Value; break; + case DoublePredicate.PredicateTypeOneofCase.LessThan: maximum = value.less_than.Value; break; + case DoublePredicate.PredicateTypeOneofCase.InsideRange: _load_range(value.inside_range.Value); break; + case DoublePredicate.PredicateTypeOneofCase.OutsideRange: _load_range(value.outside_range.Value); break; + } + } + + void _load_range(DoubleRange range) { + minimum = range.minimum; + maximum = range.maximum; + } + } +} \ No newline at end of file From 19e40798648e65a14c5840fc8544ac033da5f647 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Tue, 27 Aug 2019 12:25:57 -0400 Subject: [PATCH 077/116] add 'LoggerContext' (snatched from pnl branch) --- src/client/spark_api/utils/Log.cs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/client/spark_api/utils/Log.cs b/src/client/spark_api/utils/Log.cs index 6526cb32a..d3b86f5d0 100644 --- a/src/client/spark_api/utils/Log.cs +++ b/src/client/spark_api/utils/Log.cs @@ -64,6 +64,31 @@ namespace bts { static extern void Logger_log (Level level, Subsystem subsystem, string message, string file, int line); } + public readonly struct LoggerContext { + readonly string _prefix, _suffix; + readonly Logger _logger; + + public LoggerContext(Logger logger, string prefix, string suffix) { + _prefix = prefix; + _suffix = suffix; + _logger = logger; + } + + public void diag(string message) => _logger.diag(_fmt(message)); + public void info(string message) => _logger.info(_fmt(message)); + public void warn(string message) => _logger.warn(_fmt(message)); + public void error(string message) => _logger.error(_fmt(message)); + public void fatal(string message) => _logger.fatal(_fmt(message)); + + string _fmt(string message) { + if (_prefix != null) + message = _prefix + message; + if (_suffix != null) + message += _suffix; + return message; + } + } + public static class Log { internal static Logger Gen => new Logger(Subsystem.gen); internal static Logger Config => new Logger(Subsystem.Config); @@ -130,5 +155,5 @@ namespace bts { logger.warn(message, file, line); #endif } - } + } } From fb4ffaeeb92cdc7191908c549a1200ce186e23c2 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Tue, 27 Aug 2019 12:55:20 -0400 Subject: [PATCH 078/116] DIYGrid.SyncWithColumnGeometry impl (snatched from pnl branch) --- .../spark/view/Controls/DIYGrid/DIYGrid.cs | 161 +++++++++++++++++- 1 file changed, 156 insertions(+), 5 deletions(-) diff --git a/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs b/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs index fda5d6cc6..a54d039a7 100644 --- a/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs +++ b/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs @@ -1,9 +1,9 @@ using bts; +using bts.utils; using mbts.spark.filters; using mbts.ui.controls.adorners; using mbts.ui.extensions; using mbts.ui.utility; -using bts.utils; using System; using System.Collections; using System.Collections.Generic; @@ -12,14 +12,13 @@ using System.Collections.Specialized; using System.ComponentModel; using System.Diagnostics; using System.Linq; +using System.Reactive.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Data; using System.Windows.Input; using System.Windows.Media; -using mbts.utils; -using System.Reactive.Linq; namespace mbts.ui.controls { interface IHandleGridSorting { @@ -562,6 +561,11 @@ namespace mbts.ui.controls { public static readonly DependencyProperty HeaderTotalSizeHackProperty = DependencyProperty.Register("HeaderTotalSizeHack", typeof(double), typeof(DIYGrid), new FrameworkPropertyMetadata(0.0, dp_invalidate_column_layout)); + public double HeaderTotalSizeHack { + get => (double)GetValue(HeaderTotalSizeHackProperty); + set => SetValue(HeaderTotalSizeHackProperty, value); + } + private static void dp_invalidate_column_layout(DependencyObject d, DependencyPropertyChangedEventArgs unused) { var grid = d as DIYGrid; if (grid != null) { @@ -594,6 +598,61 @@ namespace mbts.ui.controls { // Public Properties #region Public Properties + #region ColumnKey + public static readonly DependencyProperty ColumnKeyProperty = + DependencyProperty.RegisterAttached("ColumnKey", + typeof(object), + typeof(DIYGrid), + new PropertyMetadata((d, e) => { + if (!(d is UIElement child)) + return; + if (VisualTreeHelper.GetParent(child) is Grid panel) { + if (GetSyncWithColumnGeometrySource(d) is DIYGrid diy_grid || panel.try_find_ancestor_of_type(out diy_grid)) + ColumnGeometrySyncHelper.reset_panel_child(child, diy_grid, e.NewValue); + } + })); + + public static object GetColumnKey(DependencyObject d) => d.GetValue(ColumnKeyProperty); + public static void SetColumnKey(DependencyObject d, object value) => d.SetValue(ColumnKeyProperty, value); + #endregion + + #region SyncWithColumnGeometrySource + public static readonly DependencyProperty SyncWithColumnGeometrySourceProperty = + DependencyProperty.RegisterAttached( + "SyncWithColumnGeometrySource", + typeof(DIYGrid), + typeof(DIYGrid), + new PropertyMetadata(ColumnGeometrySyncHelper.reset_sync)); + + public static DIYGrid GetSyncWithColumnGeometrySource(DependencyObject d) => d.GetValue(SyncWithColumnGeometrySourceProperty) as DIYGrid; + public static void SetSyncWithColumnGeometrySource(DependencyObject d, DIYGrid value) => d.SetValue(SyncWithColumnGeometrySourceProperty, value); + #endregion + + #region SyncWithColumnGeometry + public static readonly DependencyProperty SyncWithColumnGeometryProperty = + DependencyProperty.RegisterAttached( + "SyncWithColumnGeometry", + typeof(bool), + typeof(DIYGrid), + new PropertyMetadata(false, ColumnGeometrySyncHelper.reset_sync)); + + public static bool GetSyncWithColumnGeometry(DependencyObject d) => (bool)d.GetValue(SyncWithColumnGeometryProperty); + public static void SetSyncWithColumnGeometry(DependencyObject d, bool value) => d.SetValue(SyncWithColumnGeometryProperty, value); + + static readonly DependencyPropertyKey SyncWithColumnGeometryHookPropertyKey = + DependencyProperty.RegisterAttachedReadOnly( + "SyncWithColumnGeometryHook", + typeof(IDisposable), + typeof(DIYGrid), + new PropertyMetadata(FrameworkElementLifeDependencyHelper.DisposeOld)); + + internal static IDisposable GetSyncWithColumnGeometryHook(DependencyObject d) => + d.GetValue(SyncWithColumnGeometryHookPropertyKey.DependencyProperty) as IDisposable; + + static void SetSyncWithColumnGeometryHook(DependencyObject d, IDisposable value) => + d.SetValue(SyncWithColumnGeometryHookPropertyKey, value); + #endregion + public static readonly DependencyProperty BackgroundOverlayProperty = DependencyProperty.RegisterAttached( "BackgroundOverlay", @@ -783,7 +842,7 @@ namespace mbts.ui.controls { /// Compute the geometry of all visible (or partially visible columns) columns /// This effectively replaces the entire Measure/Arrange pass of the grid rows (and enables column virtualization) /// Mouse events will be hit tested against this as well - internal IEnumerable GetColumnGeometry() { + internal IEnumerable GetColumnGeometry(bool include_obscured_cols = false) { if (_header_scroll_viewer != null && ActualWidth > 0) { double frozen_offset = 0; int vis_frozen_col_count = _get_visible_frozen_column_count(); @@ -805,7 +864,7 @@ namespace mbts.ui.controls { double left = Math.Max(offset, frozen_offset); double right = offset + col.ActualWidth; // If right < frozen_offset column is completely obscured - if (right > frozen_offset && left <= ActualWidth) { + if (include_obscured_cols || (right > frozen_offset && left <= ActualWidth)) { // fully visible yield return new ColumnGeometry() { column = col, @@ -883,6 +942,98 @@ namespace mbts.ui.controls { } #endregion + static class ColumnGeometrySyncHelper { + public static void reset_panel_child(UIElement child, DIYGrid diy_grid) => + reset_panel_child(child, diy_grid, GetColumnKey(child)); + + public static void reset_panel_child(UIElement child, DIYGrid diy_grid, object col_key) { + if (col_key == null) + return; + var key_str = col_key.ToString(); + if (diy_grid._visible_columns.TryGetFirst(c => string.Equals(c.id, key_str, StringComparison.CurrentCultureIgnoreCase), out var target_col, out int target_pos)) { + // set clip to null in case this child was hidden before (see 'else' block). + child.Clip = null; + Grid.SetColumn(child, target_pos); + } else { + // hide element by setting clip to 0x0 rect, rather than visibility to collapsed, + // to avoid incidentally breaking visibility bindings, triggers, animations, etc. + child.Clip = new RectangleGeometry(new Rect(0, 0, 0, 0)); + } + } + + public static void reset_sync(DependencyObject d, DependencyPropertyChangedEventArgs e) { + if (!GetSyncWithColumnGeometry(d)) + SetSyncWithColumnGeometryHook(d, null); + if (!(d is Grid g)) + return; + var hook = new DisposableContainer(); + if (g.IsLoaded) + hook.replace(impl()); + SetSyncWithColumnGeometryHook(d, Disposable.Create(g.SubscribeLoaded(on_loaded), hook)); + // + void on_loaded(object sender, RoutedEventArgs loaded_e) { + if (GetSyncWithColumnGeometry(d)) + hook.replace(impl()); + } + IDisposable impl() { + // Avoid resetting children on every collection change, as that could be very noisy and hurt perf. + // In the visible columns CollectionChanged handler, call reset_children inside a Dispatcher.InvokeAsync request + // to effectively wait for potential batch-changes to finish. + bool resetting_children = false; + if (!(GetSyncWithColumnGeometrySource(d) is DIYGrid diy_grid) && !g.try_find_ancestor_of_type(out diy_grid)) + return null; + g.SetBinding(Grid.WidthProperty, new Binding(nameof(HeaderTotalSizeHack)) { Source = diy_grid }); + reset_children(); + on_layout_changed(diy_grid.GetColumnGeometry(true).ToList()); + diy_grid.ColumnLayoutChanged += on_layout_changed; + diy_grid._visible_columns.CollectionChanged += on_vis_columns_changed; + return Disposable.Create(() => { + diy_grid.ColumnLayoutChanged -= on_layout_changed; + diy_grid._visible_columns.CollectionChanged -= on_vis_columns_changed; + }); + // + void on_vis_columns_changed(object sender, NotifyCollectionChangedEventArgs vce) { + if (!resetting_children) { + // avoid resetting children on every collection change, as that could be very noisy and hurt perf. + resetting_children = true; + diy_grid.Dispatcher.InvokeAsync(() => { + on_layout_changed(diy_grid.GetColumnGeometry().ToList()); + reset_children(); + resetting_children = false; + }); + } + } + void on_layout_changed(List layout) { + // TODO: figure out how to make the ColumnLayoutChanged event lazy, or somehow avoid making 2 lists of columns + // (the layout param does not include obscured cols, so we have to create a new list of ColumnGeoemtry to satisfy our needs). + layout = (from col in diy_grid._visible_columns + join pos in diy_grid.GetColumnGeometry(true) + on col.id equals pos.column.id + select pos).ToList(); + + int n_removed = g.ColumnDefinitions.Count - layout.Count; + if (n_removed > 0) + g.ColumnDefinitions.RemoveRange(g.ColumnDefinitions.Count - n_removed, n_removed); + int i = 0; + for (; i < g.ColumnDefinitions.Count; i++) { + var col_pos = layout[i]; + var col = g.ColumnDefinitions[i]; + if (col.Width.GridUnitType == GridUnitType.Pixel && col.Width.Value == col_pos.visible_width) + continue; + col.Width = new GridLength(col_pos.visible_width, GridUnitType.Pixel); + } + for (; i < layout.Count; i++) { + g.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(layout[i].visible_width, GridUnitType.Pixel) }); + } + } + void reset_children() { + foreach (UIElement child in g.Children) + reset_panel_child(child, diy_grid); + } + } + } + } + class DataContextHooks : IDisposable { List _hooks = new List(4); From d39d7b8f47d3c4e749e75f72abe0e3e630871285 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Tue, 27 Aug 2019 12:56:23 -0400 Subject: [PATCH 079/116] added ColumnBase default constructor, made 'key' prop mutable so columns can be defined in xaml (snatched from pnl branch) --- .../Controls/DIYGrid/Columns/ColumnBase.cs | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/client/spark/view/Controls/DIYGrid/Columns/ColumnBase.cs b/src/client/spark/view/Controls/DIYGrid/Columns/ColumnBase.cs index 3d3e1e1f6..32c76bd5b 100644 --- a/src/client/spark/view/Controls/DIYGrid/Columns/ColumnBase.cs +++ b/src/client/spark/view/Controls/DIYGrid/Columns/ColumnBase.cs @@ -1,9 +1,8 @@ -using mbts.spark; +using bts; +using mbts.spark; using mbts.spark.filters; using mbts.ui.settings; -using mbts.ui.shell; using System; -using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Reflection; @@ -11,7 +10,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Media; -namespace mbts.ui.controls { +namespace mbts.ui.controls { // Column types are nested inside the DIYGrid partial class DIYGrid { public static class DefaultColumnWidths { @@ -273,9 +272,25 @@ namespace mbts.ui.controls { } internal abstract class ColumnBase : ColumnBase, IKeyedColumn, IGridColumn { + TColKey _key; + bool _key_initialized; + // need a default constructor to support declaration in xaml + protected ColumnBase() { } protected ColumnBase(TColKey key) => this.key = key; - public TColKey key { get; } + public TColKey key { + get => _key; + set { + if (Equals(_key, value)) + return; + Log.assert(!_key_initialized, "Column key already initialized."); + _key_initialized = true; + _key = value; + on_key_initialized(value); + } + } + + protected virtual void on_key_initialized(TColKey key) { } } } } \ No newline at end of file From b6d1eb97736c28d1b1e4438c2a9411f3b7ba42a0 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Tue, 27 Aug 2019 17:42:03 -0400 Subject: [PATCH 080/116] set DIYGrid BorderBrush\Thickness TemplateBindings --- .../Controls/DIYGrid/DIYGridResources.xaml | 129 ++++++++++-------- 1 file changed, 69 insertions(+), 60 deletions(-) diff --git a/src/client/spark/view/Controls/DIYGrid/DIYGridResources.xaml b/src/client/spark/view/Controls/DIYGrid/DIYGridResources.xaml index d066fbb96..fb6b99060 100644 --- a/src/client/spark/view/Controls/DIYGrid/DIYGridResources.xaml +++ b/src/client/spark/view/Controls/DIYGrid/DIYGridResources.xaml @@ -61,6 +61,9 @@ + + + + + + + + + + + (N/A) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +