some PR suggestions
This commit is contained in:
1 parent
189ed40aa2
commit
237b59afe5
3 files changed
+24
-22
No files matched your search
@@ -30,12 +30,14 @@ namespace mbts.ui.controls {
|
||||
public static readonly FontFamily DefaultFontFamily = new FontFamily("Consolas");
|
||||
|
||||
// I am thinking that depending on how people have different ladder windows configured, the vertex points may be at different positions
|
||||
static ConcurrentDictionary<(Point p1, Point p2, Point p3), StreamGeometry> _sg_cache = new ConcurrentDictionary<(Point p1, Point p2, Point p3), StreamGeometry>();
|
||||
//static ConcurrentDictionary<(Point p1, Point p2, Point p3), StreamGeometry> _sg_cache = new ConcurrentDictionary<(Point p1, Point p2, Point p3), StreamGeometry>();
|
||||
|
||||
readonly GlyphContentRect _gcr = new GlyphContentRect();
|
||||
Brush _background, _foreground, _border_brush, _parent_algo_type_brush;
|
||||
bool _is_exchange_order, _is_multiple_orders_at_level, _is_hedge_order;
|
||||
bool _is_exchange_order, _has_multiple_orders_at_level, _is_hedge_order;
|
||||
CustomOrderDefinition.CustomOneofCase _parent_algo_type;
|
||||
Tuple<Point, Point, Point> _current_triangle_vertices;
|
||||
StreamGeometry _triangle_geometry;
|
||||
|
||||
|
||||
static Badge() {
|
||||
@@ -176,7 +178,7 @@ namespace mbts.ui.controls {
|
||||
_gcr.font_size = FontSize;
|
||||
_gcr.text_lines = TextLines;
|
||||
_is_exchange_order = IsExchangeOrder;
|
||||
_is_multiple_orders_at_level = IsMultipleOrdersAtLevel;
|
||||
_has_multiple_orders_at_level = HasMultipleOrdersAtLevel;
|
||||
_is_hedge_order = IsHedgeOrder;
|
||||
_gcr.glyph_context = GlyphContext.create(FontFamily, FontWeight);
|
||||
}
|
||||
@@ -214,16 +216,16 @@ namespace mbts.ui.controls {
|
||||
(b, v) => b._is_exchange_order = v,
|
||||
false);
|
||||
|
||||
public bool IsMultipleOrdersAtLevel {
|
||||
public bool HasMultipleOrdersAtLevel {
|
||||
get { return (bool)GetValue(IsMultipleOrdersAtLevelProperty); }
|
||||
set { SetValue(IsMultipleOrdersAtLevelProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsMultipleOrdersAtLevelProperty =
|
||||
WPFHelper.create_dp<bool, Badge>(
|
||||
nameof(IsMultipleOrdersAtLevel),
|
||||
nameof(HasMultipleOrdersAtLevel),
|
||||
FrameworkPropertyMetadataOptions.AffectsRender,
|
||||
(b, v) => b._is_multiple_orders_at_level = v,
|
||||
(b, v) => b._has_multiple_orders_at_level = v,
|
||||
false);
|
||||
|
||||
public CustomOrderDefinition.CustomOneofCase ParentAlgoType {
|
||||
@@ -273,12 +275,12 @@ namespace mbts.ui.controls {
|
||||
base.OnRender(dc);
|
||||
// this is the main badge rectangle
|
||||
double border_thickness = BorderThickness.Top;
|
||||
Pen pen;
|
||||
(pen = new Pen(BorderBrush, border_thickness)).Freeze();
|
||||
Pen pen = new Pen(BorderBrush, border_thickness);
|
||||
pen = pen.frozen();
|
||||
dc.DrawRoundedRectangle(Background, pen, new Rect(0, border_thickness, _gcr.layout_size.Width, _gcr.layout_size.Height), CornerRadius, CornerRadius);
|
||||
|
||||
|
||||
if (IsMultipleOrdersAtLevel) {
|
||||
if (HasMultipleOrdersAtLevel) {
|
||||
_draw_triangle(
|
||||
new Point(_gcr.layout_size.Width - (2 * border_thickness - CornerRadius), _gcr.layout_size.Height - 5), // top right
|
||||
new Point(_gcr.layout_size.Width - (2 * border_thickness - CornerRadius), _gcr.layout_size.Height), // bottom right
|
||||
@@ -306,7 +308,7 @@ namespace mbts.ui.controls {
|
||||
var palgo_type_name = utility.EnumHelper.get_display_name(ParentAlgoType);
|
||||
if (palgo_type_name.Length > 1) {
|
||||
var palgo_letter = palgo_type_name.Substring(0, 1);
|
||||
var a_glyph_context = TextUtils.StandardGlyphContext;
|
||||
var a_glyph_context = _gcr.glyph_context;
|
||||
var a_glyph_run = a_glyph_context.get_glyph_run(
|
||||
palgo_letter,
|
||||
12,
|
||||
@@ -329,18 +331,18 @@ namespace mbts.ui.controls {
|
||||
dc.DrawGlyphRun(_foreground, gr);
|
||||
|
||||
void _draw_triangle(Point p1, Point p2, Point p3, Brush b) {
|
||||
var key = (p1, p2, p3);
|
||||
if (!_sg_cache.TryGetValue(key, out StreamGeometry sg)) {
|
||||
sg = new StreamGeometry();
|
||||
using (var sgc = sg.Open()) {
|
||||
Tuple<Point, Point, Point> new_vertices = new Tuple<Point, Point, Point>(p1, p2, p3);
|
||||
if (!new_vertices.Equals(_current_triangle_vertices)) {
|
||||
_triangle_geometry = new StreamGeometry();
|
||||
using (var sgc = _triangle_geometry.Open()) {
|
||||
sgc.BeginFigure(p1, true, true);
|
||||
sgc.PolyLineTo(new Point[] { p2, p3 }, true, true);
|
||||
}
|
||||
sg.Freeze();
|
||||
_sg_cache[key] = sg;
|
||||
_current_triangle_vertices = new_vertices;
|
||||
_triangle_geometry.Freeze();
|
||||
}
|
||||
(pen = new Pen(b, 1)).Freeze();
|
||||
dc.DrawGeometry(b, pen, sg);
|
||||
dc.DrawGeometry(b, pen, _triangle_geometry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace mbts.spark {
|
||||
readonly Property<FontWeight> _font_weight;
|
||||
readonly Property<double> _font_size;
|
||||
readonly Property<Brush> _foreground, _background, _hoverbackground, _border, _parent_algo_type_brush;
|
||||
readonly Property<bool> _is_exchange_order, _is_multiple_orders_at_same_level, _is_hedge_order;
|
||||
readonly Property<bool> _is_exchange_order, _has_multiple_orders_at_same_level, _is_hedge_order;
|
||||
readonly Property<CustomOrderDefinition.CustomOneofCase> _parent_algo_type;
|
||||
readonly Property<string> _summary, _description;
|
||||
IObservable<LadderSettings.BadgeStyle> _bs;
|
||||
@@ -65,7 +65,7 @@ namespace mbts.spark {
|
||||
_summary = backing(nameof(summary), string.Empty);
|
||||
_description = backing(nameof(description), string.Empty);
|
||||
_is_exchange_order = backing(nameof(is_exchange_order), false);
|
||||
_is_multiple_orders_at_same_level = backing(nameof(is_multiple_orders_at_same_level), false);
|
||||
_has_multiple_orders_at_same_level = backing(nameof(has_multiple_orders_at_same_level), false);
|
||||
_is_hedge_order = backing(nameof(is_hedge_order), false);
|
||||
_parent_algo_type = backing(nameof(parent_algo_type), CustomOrderDefinition.CustomOneofCase.None);
|
||||
_parent_algo_type_brush = backing(nameof(parent_algo_type_brush), _color_bg_brush);
|
||||
@@ -117,7 +117,7 @@ namespace mbts.spark {
|
||||
border = new SolidColorBrush(color);
|
||||
is_exchange_order = false;
|
||||
}
|
||||
is_multiple_orders_at_same_level = _orders.Count > 1;
|
||||
has_multiple_orders_at_same_level = _orders.Count > 1;
|
||||
is_hedge_order = _orders.Any(o => o.Value.sub_type() == OrderSubType.HedgingLeg);
|
||||
|
||||
if (_orders.Any()) {
|
||||
@@ -187,7 +187,7 @@ namespace mbts.spark {
|
||||
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_exchange_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 bool has_multiple_orders_at_same_level { get => _has_multiple_orders_at_same_level.Value; private set => _has_multiple_orders_at_same_level.Value = value; }
|
||||
public bool is_hedge_order { get => _is_hedge_order.Value; private set => _is_hedge_order.Value = value; }
|
||||
public Brush parent_algo_type_brush { get => _parent_algo_type_brush.Value; private set => _parent_algo_type_brush.Value = value; }
|
||||
// the setter is public so that the LadderVM can set this field
|
||||
|
||||
@@ -452,7 +452,7 @@
|
||||
<Setter Property="Width" Value="{x:Static controls:Badge.DefaultWidth}"/>
|
||||
<Setter Property="ToolTip" Value="{Binding description}" />
|
||||
<Setter Property="IsExchangeOrder" Value="{Binding is_exchange_order}" />
|
||||
<Setter Property="IsMultipleOrdersAtLevel" Value="{Binding is_multiple_orders_at_same_level}" />
|
||||
<Setter Property="HasMultipleOrdersAtLevel" Value="{Binding has_multiple_orders_at_same_level}" />
|
||||
<Setter Property="IsHedgeOrder" Value="{Binding is_hedge_order}" />
|
||||
<Setter Property="ParentAlgoType" Value="{Binding parent_algo_type}" />
|
||||
<Setter Property="ParentAlgoTypeBrush" Value="{Binding parent_algo_type_brush}" />
|
||||
|
||||
Reference in new issue
Block a user