requesting a sanity check here
This commit is contained in:
1 parent
eb739b33f9
commit
0ad1103f78
3 files changed
+62
No files matched your search
@@ -25,9 +25,11 @@ namespace mbts.ui.controls {
|
||||
DefaultFontSize = 10,
|
||||
DefaultWidth = 63; // **
|
||||
public static readonly FontFamily DefaultFontFamily = new FontFamily("Consolas");
|
||||
public static readonly bool DefaultIsExchangeOrder = false;
|
||||
|
||||
readonly GlyphContentRect _gcr = new GlyphContentRect();
|
||||
Brush _background, _foreground, _border_brush;
|
||||
bool _is_exchange_order, _is_multiple_orders_at_level;
|
||||
|
||||
static Badge() {
|
||||
DefaultStyleKeyProperty.OverrideMetadata(typeof(Badge), new FrameworkPropertyMetadata(typeof(Badge)));
|
||||
@@ -166,6 +168,8 @@ namespace mbts.ui.controls {
|
||||
_border_brush = BorderBrush;
|
||||
_gcr.font_size = FontSize;
|
||||
_gcr.text_lines = TextLines;
|
||||
_is_exchange_order = IsExchangeOrder;
|
||||
_is_multiple_orders_at_level = IsMultipleOrdersAtLevel;
|
||||
_gcr.glyph_context = GlyphContext.create(FontFamily, FontWeight);
|
||||
}
|
||||
|
||||
@@ -190,6 +194,26 @@ namespace mbts.ui.controls {
|
||||
public static readonly DependencyProperty CornerRadiusProperty =
|
||||
WPFHelper.create_dp<double, Badge>(nameof(CornerRadius), DefaultCornerRadius);
|
||||
|
||||
public bool IsExchangeOrder {
|
||||
get { return (bool)GetValue(IsExchangeOrderProperty); }
|
||||
set { SetValue(IsExchangeOrderProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsExchangeOrderProperty =
|
||||
WPFHelper.create_dp<bool, Badge>(nameof(IsExchangeOrder), DefaultIsExchangeOrder);
|
||||
|
||||
public static readonly DependencyProperty IsMultipleOrdersAtLevelProperty =
|
||||
WPFHelper.create_dp<bool, Badge>(
|
||||
nameof(IsMultipleOrdersAtLevel),
|
||||
FrameworkPropertyMetadataOptions.AffectsRender,
|
||||
(b, v) => b._is_multiple_orders_at_level = v,
|
||||
false);
|
||||
|
||||
public bool IsMultipleOrdersAtLevel {
|
||||
get { return (bool)GetValue(IsMultipleOrdersAtLevelProperty); }
|
||||
set { SetValue(IsMultipleOrdersAtLevelProperty, value); }
|
||||
}
|
||||
|
||||
protected override Size ArrangeOverride(Size finalSize) => finalSize;
|
||||
|
||||
protected override Size MeasureOverride(Size availableSize) {
|
||||
@@ -202,9 +226,31 @@ namespace mbts.ui.controls {
|
||||
double border_thickness = BorderThickness.Top;
|
||||
var pen = new Pen(BorderBrush, border_thickness);
|
||||
dc.DrawRoundedRectangle(Background, pen, new Rect(0, border_thickness, _gcr.layout_size.Width, _gcr.layout_size.Height), CornerRadius, CornerRadius);
|
||||
if (IsExchangeOrder) {
|
||||
// for the y-component, since we start the RoundedRectangle at border_thickness, we have to include that in our y pos start position as well.
|
||||
dc.DrawEllipse(Brushes.Black, new Pen(Brushes.Black, border_thickness), new Point(_gcr.layout_size.Width - 2 * border_thickness - CornerRadius, 0 + border_thickness + 2 * border_thickness + CornerRadius), 2, 2);
|
||||
}
|
||||
if (IsMultipleOrdersAtLevel) {
|
||||
_draw_triangle(
|
||||
new Point(_gcr.layout_size.Width - (border_thickness - CornerRadius + 2), _gcr.layout_size.Height - 5), // top right
|
||||
new Point(_gcr.layout_size.Width - (border_thickness - CornerRadius + 2), _gcr.layout_size.Height), // bottom right
|
||||
new Point(_gcr.layout_size.Width - (border_thickness - CornerRadius + 2) - 5, _gcr.layout_size.Height), // bottom left
|
||||
Brushes.IndianRed
|
||||
);
|
||||
}
|
||||
var gr = _gcr.glyph_run;
|
||||
if (gr != null)
|
||||
dc.DrawGlyphRun(_foreground, gr);
|
||||
|
||||
void _draw_triangle(Point p1, Point p2, Point p3, Brush b) {
|
||||
var sg = new StreamGeometry();
|
||||
using (var sgc = sg.Open()) {
|
||||
sgc.BeginFigure(p1, true, true);
|
||||
sgc.PolyLineTo(new Point[] { p2, p3 }, true, true);
|
||||
}
|
||||
//sg.Freeze();
|
||||
dc.DrawGeometry(b, new Pen(b, 1), sg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ namespace mbts.spark {
|
||||
readonly Property<FontWeight> _font_weight;
|
||||
readonly Property<double> _font_size;
|
||||
readonly Property<Brush> _foreground, _background, _hoverbackground, _border;
|
||||
readonly Property<bool> _is_exchange_order, _is_multiple_orders_at_same_level;
|
||||
readonly Property<string> _summary, _description;
|
||||
IObservable<LadderSettings.BadgeStyle> _bs;
|
||||
LadderSettings.BadgeStyle _current_badge_style;
|
||||
@@ -62,6 +63,8 @@ namespace mbts.spark {
|
||||
_border = backing(nameof(border), _color_bg_brush);
|
||||
_summary = backing(nameof(summary), string.Empty);
|
||||
_description = backing(nameof(description), string.Empty);
|
||||
_is_exchange_order = backing(nameof(is_exchage_order), false);
|
||||
_is_multiple_orders_at_same_level = backing(nameof(is_multiple_orders_at_same_level), false);
|
||||
FontFamily get_font_family(LadderSettings s) => new FontFamily(s.orders_column.font_family);
|
||||
FontWeight get_font_weight(LadderSettings s) => ui.utility.text.TextUtils.from_open_type_weight_safe(s.orders_column.font_weight);
|
||||
double get_font_size(LadderSettings s) => s.orders_column.font_size;
|
||||
@@ -96,6 +99,10 @@ namespace mbts.spark {
|
||||
working_quantity = _parent_and_child_not_sharing_slot().Select(order => order.working_quantity()).Sum();
|
||||
quantity = _parent_and_child_not_sharing_slot().Select(order => order.State.Quantity).Sum();
|
||||
|
||||
// TODO: call the appropriate taha-provided function in the future
|
||||
is_exchage_order = true;
|
||||
is_multiple_orders_at_same_level = _orders.Count > 1;
|
||||
|
||||
if (_orders.Count > 0)
|
||||
{
|
||||
summary = _orders.Values.Select(order => order.short_description(_parent.security.ContractSpec)).Aggregate((s1, s2) => $"{s1}{Environment.NewLine}{Environment.NewLine}{s2}");
|
||||
@@ -140,6 +147,7 @@ namespace mbts.spark {
|
||||
IEnumerable<OrderRecordImmutable> _parent_and_child_not_sharing_slot() => _orders.Values.Where(o => !_orders.ContainsKey(o.ParentKey));
|
||||
|
||||
public IReadOnlyList<string> text_lines { get; private set; }
|
||||
|
||||
public bool has_parent => _orders.Values.Any( order => order.has_parent());
|
||||
public bool has_phantom_price => !double.IsNaN(_phantom_price);
|
||||
|
||||
@@ -161,6 +169,9 @@ namespace mbts.spark {
|
||||
public Brush border { get => _border.Value; private set => _border.Value = value; }
|
||||
public string summary { get => _summary.Value; private set => _summary.Value = value; }
|
||||
public string description { get => _description.Value; private set => _description.Value = value; }
|
||||
public bool is_exchage_order { get => _is_exchange_order.Value; private set => _is_exchange_order.Value = value; }
|
||||
public bool is_multiple_orders_at_same_level { get => _is_multiple_orders_at_same_level.Value; private set => _is_multiple_orders_at_same_level.Value = value; }
|
||||
|
||||
public IEnumerable<OrderRecordImmutable> orders => _orders.Values;
|
||||
|
||||
void _cancel_order() {
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
@@ -108,6 +109,10 @@ namespace mbts.spark {
|
||||
|
||||
Badge mkbadge(LadderOrderVM order) {
|
||||
Badge b = new Badge();
|
||||
var binding = new Binding();
|
||||
binding.Source = order;
|
||||
binding.Path = new PropertyPath("is_multiple_orders_at_same_level");
|
||||
b.SetBinding(Badge.IsMultipleOrdersAtLevelProperty, binding);
|
||||
b.DataContext = order;
|
||||
// Hook up the style from xaml
|
||||
b.Style = this.TryFindResource(typeof(Badge)) as Style;
|
||||
|
||||
Reference in new issue
Block a user