Zoom - proto, settings, UI
This commit is contained in:
1 parent
f0ba6b72fc
commit
dbd8a7d742
5 files changed
+84
-9
No files matched your search
@@ -181,6 +181,7 @@ namespace mbts.spark {
|
||||
[ProtoContract]
|
||||
class LadderSettings : IEquatable<LadderSettings> {
|
||||
const double _default_order_entry_panel_width = 110.0;
|
||||
const double _default_zoom_factor = 1.0;
|
||||
|
||||
// Default proto constructor
|
||||
// Added this so that when clients upgrade to a version with new settings,
|
||||
@@ -202,6 +203,7 @@ namespace mbts.spark {
|
||||
cancel_all_visible = true;
|
||||
auto_clear_visible = true;
|
||||
order_entry_panel_initial_width = _default_order_entry_panel_width;
|
||||
zoom_factor = _default_zoom_factor;
|
||||
}
|
||||
|
||||
public static LadderSettings Default {
|
||||
@@ -257,7 +259,9 @@ namespace mbts.spark {
|
||||
cancel_sells_visible = true,
|
||||
cancel_all_visible = true,
|
||||
auto_clear_visible = true,
|
||||
order_entry_panel_initial_width = _default_order_entry_panel_width
|
||||
order_entry_panel_initial_width = _default_order_entry_panel_width,
|
||||
zoom_slider_visible = false,
|
||||
zoom_factor = _default_zoom_factor
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -353,6 +357,14 @@ namespace mbts.spark {
|
||||
//
|
||||
[ProtoMember(42), DefaultValue(_default_order_entry_panel_width)]
|
||||
public double order_entry_panel_initial_width { get; set; }
|
||||
|
||||
// the zoom slider is the first new widget on the panel
|
||||
// since our initial general release, so its enablement
|
||||
// will be opt-in (default not visible)
|
||||
[ProtoMember(43)]
|
||||
public bool zoom_slider_visible { get; set; }
|
||||
[ProtoMember(44), DefaultValue(_default_zoom_factor)]
|
||||
public double zoom_factor { get; set; }
|
||||
|
||||
|
||||
public bool Equals(LadderSettings other) =>
|
||||
@@ -395,7 +407,9 @@ namespace mbts.spark {
|
||||
cancel_sells_visible == other.cancel_sells_visible &&
|
||||
cancel_all_visible == other.cancel_all_visible &&
|
||||
auto_clear_visible == other.auto_clear_visible &&
|
||||
order_entry_panel_initial_width == other.order_entry_panel_initial_width
|
||||
order_entry_panel_initial_width == other.order_entry_panel_initial_width &&
|
||||
zoom_slider_visible == other.zoom_slider_visible &&
|
||||
zoom_factor == other.zoom_factor
|
||||
;
|
||||
|
||||
public override bool Equals(object obj) => Equals(obj as LadderSettings);
|
||||
@@ -440,7 +454,9 @@ namespace mbts.spark {
|
||||
cancel_sells_visible.GetHashCode(),
|
||||
cancel_all_visible.GetHashCode(),
|
||||
auto_clear_visible.GetHashCode(),
|
||||
order_entry_panel_initial_width.GetHashCode()
|
||||
order_entry_panel_initial_width.GetHashCode(),
|
||||
zoom_slider_visible.GetHashCode(),
|
||||
zoom_factor.GetHashCode()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace mbts.spark {
|
||||
readonly Property<LadderSettings.BadgeStyle> _badge_style;
|
||||
readonly Property<uint> _alternate_order_size;
|
||||
readonly DelegateProperty<double> _row_height;
|
||||
Func<double> _get_order_entry_panel_width;
|
||||
Func<double> _get_order_entry_panel_width, _get_zoom_factor;
|
||||
LadderSettings _current;
|
||||
LadderColumnSettingsVM
|
||||
_orders = new OrdersColumnSettingsVM(),
|
||||
@@ -34,6 +34,7 @@ namespace mbts.spark {
|
||||
_session_high_mkt_line = new LadderMarketBreakLineVM("Session High", 2, 1, false),
|
||||
_session_range_fill = new LadderMarketBreakLineVM("Session Range", 0, 0, false);
|
||||
OrderEntryPanelItemVisibilityVM
|
||||
_zoom_slider_visbility = new OrderEntryPanelItemVisibilityVM("Zoom Slider"),
|
||||
_day_visibility = new OrderEntryPanelItemVisibilityVM("Day Change"),
|
||||
_high_visibility = new OrderEntryPanelItemVisibilityVM("High"),
|
||||
_low_visibility = new OrderEntryPanelItemVisibilityVM("Low"),
|
||||
@@ -51,7 +52,7 @@ namespace mbts.spark {
|
||||
_cancel_all_visibility = new OrderEntryPanelItemVisibilityVM("Cancel All");
|
||||
|
||||
|
||||
public LadderSettingsVM(bool is_synthetic, Func<double> get_left_panel_width) {
|
||||
public LadderSettingsVM(bool is_synthetic, Func<double> get_left_panel_width, Func<double> get_zoom_factor) {
|
||||
this.is_synthetic = is_synthetic;
|
||||
size_presets = new ObservableEditableCollection<IMutableValueWrapperVM<uint>>(_create_size_preset_vm);
|
||||
size_presets.CollectionChanged += (s, e) => RaisePropertyChanged(nameof(size_presets_text));
|
||||
@@ -59,6 +60,7 @@ namespace mbts.spark {
|
||||
_badge_style.Changed += _badge_style_Changed;
|
||||
_alternate_order_size = backing<uint>(nameof(alternate_order_size));
|
||||
_get_order_entry_panel_width = get_left_panel_width;
|
||||
_get_zoom_factor = get_zoom_factor;
|
||||
// be sure to initialize backings before this measure_row_height call
|
||||
_row_height = backing(nameof(row_height), () => LadderRender.measure_row_height(get_result()));
|
||||
_orders.font_size_changed += on_font_size_changed;
|
||||
@@ -130,6 +132,7 @@ namespace mbts.spark {
|
||||
|
||||
public IEnumerable<OrderEntryPanelItemVisibilityVM> order_entry_panel_items {
|
||||
get {
|
||||
yield return _zoom_slider_visbility;
|
||||
yield return _day_visibility;
|
||||
yield return _high_visibility;
|
||||
yield return _low_visibility;
|
||||
@@ -168,6 +171,7 @@ namespace mbts.spark {
|
||||
_session_low_mkt_line.assign_from(_current.session_low_line);
|
||||
_session_high_mkt_line.assign_from(_current.session_high_line);
|
||||
_session_range_fill.assign_from(_current.session_range_fill);
|
||||
_zoom_slider_visbility.show = settings.zoom_slider_visible;
|
||||
_day_visibility.show = settings.day_visible;
|
||||
_high_visibility.show = settings.high_visible;
|
||||
_low_visibility.show = settings.low_visible;
|
||||
@@ -224,6 +228,8 @@ namespace mbts.spark {
|
||||
clone.cancel_sells_visible = _cancel_sells_visibility.show;
|
||||
clone.cancel_all_visible = _cancel_all_visibility.show;
|
||||
clone.order_entry_panel_initial_width = _get_order_entry_panel_width();
|
||||
clone.zoom_slider_visible = _zoom_slider_visbility.show;
|
||||
clone.zoom_factor = _get_zoom_factor();
|
||||
return clone;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,12 +24,12 @@ namespace mbts.spark {
|
||||
|
||||
readonly IBus _bus;
|
||||
readonly LadderModel _model;
|
||||
readonly Property<double> _left_panel_width;
|
||||
readonly Property<double> _left_panel_width, _zoom_factor;
|
||||
readonly Property<double> _high, _low, _change, _open, _settlement, _position;
|
||||
readonly Property<ulong> _volume;
|
||||
readonly Property<bool> _auto_clear, _show_day, _show_high, _show_low, _show_open, _show_settle, _show_volume, _show_account,
|
||||
_show_tif, _show_order_type, _show_account_position, _show_size_preset, _show_auto_clear, _show_cancel_buys,
|
||||
_show_cancel_sells, _show_cancel_all;
|
||||
_show_cancel_sells, _show_cancel_all, _show_zoom;
|
||||
readonly Property<Brush> _bid_background, _bid_foreground, _ask_background, _ask_foreground;
|
||||
IWindowSettingsManager<LadderSettings> _settings_manager;
|
||||
ulong _misc_time = 0;
|
||||
@@ -79,12 +79,14 @@ namespace mbts.spark {
|
||||
_show_cancel_buys = bool_prop(nameof(show_cancel_buys), s => s.cancel_buys_visible);
|
||||
_show_cancel_sells = bool_prop(nameof(show_cancel_sells), s => s.cancel_sells_visible);
|
||||
_show_cancel_all = bool_prop(nameof(show_cancel_all), s => s.cancel_all_visible);
|
||||
_show_zoom = bool_prop(nameof(show_zoom), s => s.zoom_slider_visible);
|
||||
|
||||
Property<bool> bool_prop(string name, Func<LadderSettings, bool> get_bool) =>
|
||||
backing(name, settings_manager.subscribe_current().OnDispatcher(), get_bool);
|
||||
|
||||
//
|
||||
_left_panel_width = backing(nameof(left_panel_width), settings_manager.subscribe_current().OnDispatcher().Select(s => s.order_entry_panel_initial_width));
|
||||
_zoom_factor = backing(nameof(zoom_factor), settings_manager.subscribe_current().OnDispatcher().Select(s => s.zoom_factor), LadderSettings.Default.zoom_factor);
|
||||
position_click_command = new DelegateCommand(() => size_calculator.value = DoubleHelper.safe_convert_to_uint(Math.Abs(position)));
|
||||
send_order_command = new DelegateCommand<(double price, Side? side, bool size_from_alternate)>(send_order);
|
||||
cancel_command = new AsyncCommand<LadderModel.CancelType>(_model.cancel_orders, true);
|
||||
@@ -94,7 +96,7 @@ namespace mbts.spark {
|
||||
var vm = new WindowSettingsDialogVM<LadderSettings, LadderSettingsVM>(
|
||||
settings_manager, s => s.ladder, UserSettings.FileExtensions.LADDER,
|
||||
s => {
|
||||
var svm = new LadderSettingsVM(security.ContractCase == Security.ContractOneofCase.Synthetic, () => left_panel_width);
|
||||
var svm = new LadderSettingsVM(security.ContractCase == Security.ContractOneofCase.Synthetic, () => left_panel_width, () => zoom_factor);
|
||||
svm.load(s);
|
||||
return svm;
|
||||
});
|
||||
@@ -274,7 +276,9 @@ namespace mbts.spark {
|
||||
public bool show_cancel_buys { get => _show_cancel_buys.Value; set => _show_cancel_buys.set(value); }
|
||||
public bool show_cancel_sells { get => _show_cancel_sells.Value; set => _show_cancel_sells.set(value); }
|
||||
public bool show_cancel_all { get => _show_cancel_all.Value; set => _show_cancel_all.set(value); }
|
||||
public bool show_zoom { get => _show_zoom.Value; set => _show_zoom.set(value); }
|
||||
public double left_panel_width { get => _left_panel_width.Value; set => _left_panel_width.set(value); }
|
||||
public double zoom_factor { get => _zoom_factor.Value; set => _zoom_factor.set(value); }
|
||||
internal LadderModel model => _model;
|
||||
internal IObservable<LadderSettings> settings => _settings_manager.subscribe_current();
|
||||
|
||||
@@ -283,7 +287,10 @@ namespace mbts.spark {
|
||||
if (_settings_manager.instance_settings == null)
|
||||
return null;
|
||||
var settings_clone = SparkUtils.clone_proto(_settings_manager.instance_settings);
|
||||
settings_clone.default_order_type = order_properties_vm.selected_order_type?.order_type ?? settings_clone.default_order_type;
|
||||
settings_clone.default_order_type = order_properties_vm.selected_order_type?.order_type ?? settings_clone.default_order_type;
|
||||
// we're going to need a way to say we want to always save the zoom factor (when it's different from defaults) without going into Settings to create an instance of instance_settings
|
||||
// ditto the left panel width
|
||||
settings_clone.zoom_factor = zoom_factor;
|
||||
return settings_clone;
|
||||
}
|
||||
|
||||
|
||||
@@ -268,6 +268,12 @@
|
||||
</UserControl.Resources>
|
||||
<AdornerDecorator>
|
||||
<Grid x:Name="_root">
|
||||
<Grid.LayoutTransform>
|
||||
<ScaleTransform CenterX="0" CenterY="0"
|
||||
ScaleX="{Binding ElementName=_ui_scaler, Path=Value}"
|
||||
ScaleY="{Binding ElementName=_ui_scaler, Path=Value}"
|
||||
/>
|
||||
</Grid.LayoutTransform>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="{Binding left_panel_width, Mode=TwoWay, Converter={StaticResource GridLengthPixelConverter}}"
|
||||
MinWidth="70" MaxWidth="150"/>
|
||||
@@ -289,6 +295,13 @@
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch" />
|
||||
</Style>
|
||||
</StackPanel.Resources>
|
||||
<StackPanel x:Name="_slider_stack_panel" Margin="5,5,5,0">
|
||||
<Slider x:Name="_ui_scaler" Value="{Binding zoom_factor}"
|
||||
Minimum="0.5"
|
||||
Maximum="1.5"
|
||||
Width="{Binding Path=ActualWidth, ElementName=_slider_stack_panel}"
|
||||
Visibility="{Binding show_zoom, Converter={StaticResource BooleanToVisibilityConverter}}"/>
|
||||
</StackPanel>
|
||||
<Grid Margin="4,4,0,0">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace mbts.spark {
|
||||
public partial class LadderView : UserControl {
|
||||
@@ -16,8 +17,40 @@ namespace mbts.spark {
|
||||
this.vm = vm;
|
||||
DataContext = vm;
|
||||
DataContextChanged += datacontext_changed;
|
||||
_ui_scaler.MouseDoubleClick += _ui_scaler_MouseDoubleClick;
|
||||
this.PreviewMouseWheel += LadderView_PreviewMouseWheel;
|
||||
this.PreviewMouseDown += LadderView_PreviewMouseDown;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// (Left|Right) CTRL + Wheel to zoom
|
||||
// This is neat b/c the user doesn't even need to have the slider visible to zoom
|
||||
private void LadderView_PreviewMouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e) {
|
||||
base.OnPreviewMouseWheel(e);
|
||||
if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) {
|
||||
_ui_scaler.Value += (e.Delta > 0) ? 0.1 : -0.1;
|
||||
}
|
||||
}
|
||||
|
||||
// (Left|Right) CTRL + Wheel Click to reset
|
||||
private void LadderView_PreviewMouseDown(object sender, MouseButtonEventArgs e) {
|
||||
base.OnPreviewMouseDown(e);
|
||||
if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) {
|
||||
if (e.MiddleButton == MouseButtonState.Pressed) {
|
||||
_ui_scaler_MouseDoubleClick(_ui_scaler, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Double click on scaler itself to reset
|
||||
private void _ui_scaler_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e) {
|
||||
if (sender is Slider _the_slider) {
|
||||
_the_slider.Value = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void datacontext_changed(object sender, DependencyPropertyChangedEventArgs e) {
|
||||
this.vm = DataContext as LadderVM;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user