pr edits
This commit is contained in:
1 parent
38e8463717
commit
2115ef9b74
12 files changed
+307
-322
No files matched your search
@@ -80,7 +80,6 @@ namespace mbts.spark {
|
||||
_inside_bids.ObserveOnDispatcher().Subscribe(v => _animation.animate_working_bids_inside(v.newval)),
|
||||
_inside_asks.ObserveOnDispatcher().Subscribe(v => _animation.animate_working_asks_inside(v.newval)),
|
||||
_day_change.ObserveOnDispatcher().Subscribe(v => _animation.animate_day_change(v.newval > v.oldval)),
|
||||
_orders_model.on_security_orders(security.Id).ObserveOnDispatcher().Subscribe(_on_orders),
|
||||
Disposable.Create(() => _animation.AnimationsChanged -= on_animations_changed)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using mbts.ui.utility.text;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
|
||||
@@ -34,26 +35,18 @@ namespace mbts.ui.controls {
|
||||
DrawingContext dc, GlyphContext glyph_context, double font_size, string text, ColumnGeometry position, double row_height,
|
||||
Brush foreground, Brush background, HorizontalAlignment x_align, VerticalAlignment y_align, Thickness padding) {
|
||||
//
|
||||
var gt = glyph_context.get_glyph_text(text, font_size, position.left, 0, position.left + position.width, row_height, x_align, y_align, padding);
|
||||
draw_text(dc, gt, position, padding, row_height, foreground, background);
|
||||
}
|
||||
|
||||
public static void draw_text(DrawingContext dc, GlyphText glyph_text, ColumnGeometry position, Thickness padding, double row_height, Brush foreground, Brush background) {
|
||||
using (draw_with_clip(dc, glyph_text.width, glyph_text.font_size, padding, row_height, position)) {
|
||||
if (background != null)
|
||||
dc.DrawRectangle(background, null, new Rect(position.left, 0, position.width, row_height));
|
||||
dc.draw_glyph_run_anti_alias(foreground, glyph_text);
|
||||
if (!string.IsNullOrEmpty(text)) {
|
||||
var gr = glyph_context.get_glyph_run(text, font_size, position.unclipped_left, 0, position.right, row_height, x_align, y_align, padding);
|
||||
draw_text(dc, gr, gr.AdvanceWidths.Sum(), font_size, position, padding, row_height, foreground, background);
|
||||
}
|
||||
}
|
||||
|
||||
public static Size measure_text_cell(FrameworkElement cell, GlyphText glyph_text, Thickness padding, Size available_size) {
|
||||
double x = padding.Left + padding.Right, y = padding.Top + padding.Bottom;
|
||||
if (glyph_text != null) {
|
||||
x += glyph_text.width;
|
||||
y += glyph_text.font_size;
|
||||
public static void draw_text(DrawingContext dc, GlyphRun glyph_run, double glyph_width, double font_size, ColumnGeometry position, Thickness padding, double row_height, Brush foreground, Brush background) {
|
||||
using (draw_with_clip(dc, glyph_width, font_size, padding, row_height, position)) {
|
||||
if (background != null)
|
||||
dc.DrawRectangle(background, null, new Rect(position.left, 0, position.width, row_height));
|
||||
dc.DrawGlyphRun(foreground, glyph_run);
|
||||
}
|
||||
// stretch if smaller than container
|
||||
return new Size(Math.Max(x, available_size.Width), Math.Max(y, available_size.Height));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using mbts.ui.utility.text;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
@@ -16,16 +17,22 @@ namespace mbts.ui.controls {
|
||||
Thickness _padding;
|
||||
HorizontalAlignment _horizontal_alignment;
|
||||
Brush _background, _foreground;
|
||||
double _font_size;
|
||||
double _glyph_width, _font_size;
|
||||
string _text;
|
||||
GlyphRun _glyph_run;
|
||||
GlyphContext _glyph_context;
|
||||
GlyphText _glyph_text;
|
||||
bool _is_mouse_over_text, _can_execute;
|
||||
Pen _underline_pen;
|
||||
|
||||
static HyperlinkCell() =>
|
||||
WPFHelper.override_metadata<HorizontalAlignment, HyperlinkCell>(
|
||||
HorizontalAlignmentProperty, FrameworkPropertyMetadataOptions.AffectsRender, (o, v) => o._horizontal_alignment = v, HorizontalAlignment.Left);
|
||||
WPFHelper.override_metadata<HorizontalAlignment, HyperlinkCell>(
|
||||
HorizontalAlignmentProperty,
|
||||
FrameworkPropertyMetadataOptions.AffectsArrange |
|
||||
FrameworkPropertyMetadataOptions.AffectsRender,
|
||||
(o, v) => {
|
||||
o._horizontal_alignment = v;
|
||||
o._glyph_run = null;
|
||||
}, HorizontalAlignment.Left);
|
||||
|
||||
public HyperlinkCell() {
|
||||
_background = Background;
|
||||
@@ -76,7 +83,7 @@ namespace mbts.ui.controls {
|
||||
WPFHelper.prop_changed_callback<FontWeight, HyperlinkCell>(
|
||||
(p, v) => {
|
||||
p._glyph_context = p._glyph_context.with(v);
|
||||
p._set_glyph_text();
|
||||
p._glyph_run = null;
|
||||
})));
|
||||
|
||||
public FontWeight FontWeight { get => (FontWeight)GetValue(FontWeightProperty); set => SetValue(FontWeightProperty, value); }
|
||||
@@ -93,7 +100,7 @@ namespace mbts.ui.controls {
|
||||
WPFHelper.prop_changed_callback<FontFamily, HyperlinkCell>(
|
||||
(p, v) => {
|
||||
p._glyph_context = p._glyph_context.with(v);
|
||||
p._set_glyph_text();
|
||||
p._glyph_run = null;
|
||||
})));
|
||||
|
||||
public FontFamily FontFamily { get => GetValue(FontFamilyProperty) as FontFamily; set => SetValue(FontFamilyProperty, value); }
|
||||
@@ -111,7 +118,7 @@ namespace mbts.ui.controls {
|
||||
WPFHelper.prop_changed_callback<double, HyperlinkCell>(
|
||||
(p, v) => {
|
||||
p._font_size = v;
|
||||
p._set_glyph_text();
|
||||
p._glyph_run = null;
|
||||
})));
|
||||
|
||||
public double FontSize { get => (double)GetValue(FontSizeProperty); set => SetValue(FontSizeProperty, value); }
|
||||
@@ -125,7 +132,7 @@ namespace mbts.ui.controls {
|
||||
FrameworkPropertyMetadataOptions.AffectsRender,
|
||||
(p, v) => {
|
||||
p._padding = v;
|
||||
p._set_glyph_text();
|
||||
p._glyph_run = null;
|
||||
}, DefaultCellPadding);
|
||||
|
||||
public Thickness Padding { get => (Thickness)GetValue(PaddingProperty); set => SetValue(PaddingProperty, value); }
|
||||
@@ -139,7 +146,7 @@ namespace mbts.ui.controls {
|
||||
FrameworkPropertyMetadataOptions.AffectsRender,
|
||||
(o, v) => {
|
||||
o._text = v;
|
||||
o._set_glyph_text();
|
||||
o._glyph_run = null;
|
||||
}, string.Empty);
|
||||
|
||||
public string Text { get => GetValue(TextProperty) as string; set => SetValue(TextProperty, value); }
|
||||
@@ -243,25 +250,39 @@ namespace mbts.ui.controls {
|
||||
protected override void OnMouseEnter(MouseEventArgs e) => _check_mouse_over_text(e);
|
||||
protected override void OnMouseLeave(MouseEventArgs e) => _check_mouse_over_text(e);
|
||||
|
||||
protected override Size ArrangeOverride(Size finalSize) => finalSize;
|
||||
protected override Size MeasureOverride(Size availableSize) =>
|
||||
CellRender.measure_text_cell(this, _glyph_text, _padding, availableSize);
|
||||
protected override Size ArrangeOverride(Size finalSize) {
|
||||
if (_glyph_run == null)
|
||||
_set_glyph(finalSize);
|
||||
return finalSize;
|
||||
}
|
||||
|
||||
void _set_glyph_text() =>
|
||||
_glyph_text = _glyph_context.get_glyph_text(_text, _font_size, DesiredSize, _horizontal_alignment, VerticalAlignment.Center, _padding);
|
||||
protected override Size MeasureOverride(Size availableSize) {
|
||||
if (_glyph_run == null)
|
||||
_set_glyph(availableSize);
|
||||
return new Size(Math.Max(availableSize.Width, _padding.Left + _glyph_width + _padding.Right),
|
||||
Math.Max(availableSize.Height, _padding.Top + _font_size + _padding.Bottom));
|
||||
}
|
||||
|
||||
void _set_glyph(Size size) {
|
||||
_glyph_run = _glyph_context.get_glyph_run(_text, _font_size, size, _horizontal_alignment, VerticalAlignment.Center, _padding);
|
||||
_glyph_width = _glyph_run == null ? 0 : _glyph_run.AdvanceWidths.Sum();
|
||||
}
|
||||
|
||||
protected override void OnRender(DrawingContext drawingContext) {
|
||||
var rect = new Rect(0, 0, RenderSize.Width, RenderSize.Height);
|
||||
var rs = RenderSize;
|
||||
var rect = new Rect(0, 0, rs.Width, rs.Height);
|
||||
var bg = Background;
|
||||
if (bg != null)
|
||||
drawingContext.DrawRectangle(bg, null, rect);
|
||||
if (_glyph_text != null) {
|
||||
drawingContext.draw_glyph_run_anti_alias(_foreground, _glyph_text);
|
||||
if (_glyph_run != null) {
|
||||
drawingContext.PushClip(new RectangleGeometry(rect));
|
||||
drawingContext.DrawGlyphRun(_foreground, _glyph_run);
|
||||
if (_is_mouse_over_text) {
|
||||
// draw underline
|
||||
var pt = new Point(Padding.Left, 0.5 * (ActualHeight + _glyph_text.font_size) + 1);
|
||||
drawingContext.DrawLine(_underline_pen, pt, new Point(pt.X + _glyph_text.width, pt.Y));
|
||||
var pt = new Point(Padding.Left, 0.5 * (ActualHeight + _font_size) + 1);
|
||||
drawingContext.DrawLine(_underline_pen, pt, new Point(pt.X + _glyph_width, pt.Y));
|
||||
}
|
||||
drawingContext.Pop();
|
||||
}
|
||||
var bgo = GetBackgroundOverlay(this);
|
||||
if (bgo != null)
|
||||
@@ -271,11 +292,11 @@ namespace mbts.ui.controls {
|
||||
void _check_mouse_over_text(MouseEventArgs e) {
|
||||
var pt = e.GetPosition(this);
|
||||
bool over_text =
|
||||
_glyph_text != null &&
|
||||
_glyph_run != null &&
|
||||
pt.X >= _padding.Left &&
|
||||
pt.X <= _padding.Left + _glyph_text.width &&
|
||||
pt.X <= _padding.Left + _glyph_width &&
|
||||
pt.Y >= _padding.Top &&
|
||||
pt.Y <= _padding.Top + _glyph_text.height;
|
||||
pt.Y <= _padding.Top + _font_size;
|
||||
if (_is_mouse_over_text != over_text)
|
||||
_toggle_mouse_over_text();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
using bts.api;
|
||||
using mbts.spark;
|
||||
using mbts.ui.utility.text;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
@@ -15,14 +18,21 @@ namespace mbts.ui.controls {
|
||||
Thickness _padding;
|
||||
HorizontalAlignment _horizontal_alignment;
|
||||
Brush _background, _foreground;
|
||||
double _font_size, _value;
|
||||
ContractSpecificationImmutable _spec;
|
||||
double _glyph_width, _font_size, _value;
|
||||
GlyphRun _glyph_run;
|
||||
GlyphContext _glyph_context;
|
||||
GlyphText _glyph_text;
|
||||
ContractSpecificationImmutable _spec;
|
||||
|
||||
static PriceCell() =>
|
||||
WPFHelper.override_metadata<HorizontalAlignment, PriceCell>(
|
||||
HorizontalAlignmentProperty, FrameworkPropertyMetadataOptions.AffectsRender, (o, v) => o._horizontal_alignment = v, HorizontalAlignment.Left);
|
||||
WPFHelper.override_metadata<HorizontalAlignment, PriceCell>(
|
||||
HorizontalAlignmentProperty,
|
||||
FrameworkPropertyMetadataOptions.AffectsArrange |
|
||||
FrameworkPropertyMetadataOptions.AffectsRender,
|
||||
(o, v) => {
|
||||
o._horizontal_alignment = v;
|
||||
o._glyph_run = null;
|
||||
},
|
||||
HorizontalAlignment.Left);
|
||||
|
||||
public PriceCell() {
|
||||
_background = Background;
|
||||
@@ -68,7 +78,7 @@ namespace mbts.ui.controls {
|
||||
WPFHelper.prop_changed_callback<FontWeight, PriceCell>(
|
||||
(p, v) => {
|
||||
p._glyph_context = p._glyph_context.with(v);
|
||||
p._set_glyph_text();
|
||||
p._glyph_run = null;
|
||||
})));
|
||||
|
||||
public FontWeight FontWeight { get => (FontWeight)GetValue(FontWeightProperty); set => SetValue(FontWeightProperty, value); }
|
||||
@@ -85,7 +95,7 @@ namespace mbts.ui.controls {
|
||||
WPFHelper.prop_changed_callback<FontFamily, PriceCell>(
|
||||
(p, v) => {
|
||||
p._glyph_context = p._glyph_context.with(v);
|
||||
p._set_glyph_text();
|
||||
p._glyph_run = null;
|
||||
})));
|
||||
|
||||
public FontFamily FontFamily { get => GetValue(FontFamilyProperty) as FontFamily; set => SetValue(FontFamilyProperty, value); }
|
||||
@@ -103,7 +113,7 @@ namespace mbts.ui.controls {
|
||||
WPFHelper.prop_changed_callback<double, PriceCell>(
|
||||
(p, v) => {
|
||||
p._font_size = v;
|
||||
p._set_glyph_text();
|
||||
p._glyph_run = null;
|
||||
})));
|
||||
|
||||
public double FontSize { get => (double)GetValue(FontSizeProperty); set => SetValue(FontSizeProperty, value); }
|
||||
@@ -117,7 +127,7 @@ namespace mbts.ui.controls {
|
||||
FrameworkPropertyMetadataOptions.AffectsRender,
|
||||
(p, v) => {
|
||||
p._padding = v;
|
||||
p._set_glyph_text();
|
||||
p._glyph_run = null;
|
||||
}, DefaultCellPadding);
|
||||
|
||||
public Thickness Padding { get => (Thickness)GetValue(PaddingProperty); set => SetValue(PaddingProperty, value); }
|
||||
@@ -127,10 +137,11 @@ namespace mbts.ui.controls {
|
||||
public static readonly DependencyProperty ValueProperty =
|
||||
WPFHelper.create_dp<double, PriceCell>(
|
||||
nameof(Value),
|
||||
FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender,
|
||||
FrameworkPropertyMetadataOptions.AffectsMeasure |
|
||||
FrameworkPropertyMetadataOptions.AffectsRender,
|
||||
(p, v) => {
|
||||
p._value = v;
|
||||
p._set_glyph_text();
|
||||
p._glyph_run = null;
|
||||
}, double.NaN);
|
||||
|
||||
public double Value { get => (double)GetValue(ValueProperty); set => SetValue(ValueProperty, value); }
|
||||
@@ -144,7 +155,7 @@ namespace mbts.ui.controls {
|
||||
FrameworkPropertyMetadataOptions.AffectsRender,
|
||||
(p, v) => {
|
||||
p._spec = v;
|
||||
p._set_glyph_text();
|
||||
p._glyph_run = null;
|
||||
}, SecurityDataHelper.Defaults.ContractSpecificationImmutable);
|
||||
|
||||
public ContractSpecificationImmutable ContractSpec {
|
||||
@@ -153,18 +164,29 @@ namespace mbts.ui.controls {
|
||||
}
|
||||
#endregion
|
||||
|
||||
void _set_glyph_text() =>
|
||||
_glyph_text = _glyph_context.get_glyph_text(_spec.format(_value), _font_size, DesiredSize, _horizontal_alignment, VerticalAlignment.Center, _padding);
|
||||
protected override Size ArrangeOverride(Size finalSize) {
|
||||
if (_glyph_run == null)
|
||||
_set_glyph(finalSize);
|
||||
return finalSize;
|
||||
}
|
||||
|
||||
protected override Size ArrangeOverride(Size finalSize) => finalSize;
|
||||
protected override Size MeasureOverride(Size availableSize) =>
|
||||
CellRender.measure_text_cell(this, _glyph_text, _padding, availableSize);
|
||||
protected override Size MeasureOverride(Size availableSize) {
|
||||
if (_glyph_run == null)
|
||||
_set_glyph(availableSize);
|
||||
return new Size(Math.Max(availableSize.Width, _padding.Left + _glyph_width + _padding.Right),
|
||||
Math.Max(availableSize.Height, _padding.Top + _font_size + _padding.Bottom));
|
||||
}
|
||||
|
||||
void _set_glyph(Size size) {
|
||||
_glyph_run = _glyph_context.get_glyph_run(_spec.format(_value), _font_size, size, _horizontal_alignment, VerticalAlignment.Center, _padding);
|
||||
_glyph_width = _glyph_run == null ? 0 : _glyph_run.AdvanceWidths.Sum();
|
||||
}
|
||||
|
||||
protected override void OnRender(DrawingContext drawingContext) {
|
||||
if (_background != null)
|
||||
drawingContext.DrawRectangle(_background, null, new Rect(RenderSize));
|
||||
if (_glyph_text != null)
|
||||
drawingContext.draw_glyph_run_anti_alias(_foreground, _glyph_text);
|
||||
if (_glyph_run != null)
|
||||
drawingContext.DrawGlyphRun(_foreground, _glyph_run);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using mbts.ui.utility.text;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
@@ -7,19 +9,27 @@ using FontFamily = System.Windows.Media.FontFamily;
|
||||
|
||||
namespace mbts.ui.controls {
|
||||
public partial class DIYGrid : Control {
|
||||
class SizeCell : FrameworkElement {
|
||||
internal class SizeCell : FrameworkElement {
|
||||
// these fields each represent properties that are accessed frequently,
|
||||
// they are stored locally to reduce repetative DependencyProperty lookups
|
||||
Thickness _padding;
|
||||
HorizontalAlignment _horizontal_alignment;
|
||||
Brush _background, _foreground;
|
||||
double _font_size, _value;
|
||||
double _glyph_width, _font_size;
|
||||
ushort _value;
|
||||
GlyphRun _glyph_run;
|
||||
GlyphContext _glyph_context;
|
||||
GlyphText _glyph_text;
|
||||
|
||||
static SizeCell() =>
|
||||
WPFHelper.override_metadata<HorizontalAlignment, SizeCell>(
|
||||
HorizontalAlignmentProperty, FrameworkPropertyMetadataOptions.AffectsRender, (o, v) => o._horizontal_alignment = v, HorizontalAlignment.Left);
|
||||
HorizontalAlignmentProperty,
|
||||
FrameworkPropertyMetadataOptions.AffectsArrange |
|
||||
FrameworkPropertyMetadataOptions.AffectsRender,
|
||||
(o, v) => {
|
||||
o._horizontal_alignment = v;
|
||||
o._glyph_run = null;
|
||||
},
|
||||
HorizontalAlignment.Left);
|
||||
|
||||
public SizeCell() {
|
||||
_background = Background;
|
||||
@@ -53,23 +63,6 @@ namespace mbts.ui.controls {
|
||||
public Brush Foreground { get => (Brush)GetValue(ForegroundProperty); set => SetValue(ForegroundProperty, value); }
|
||||
#endregion
|
||||
|
||||
#region FontWeight
|
||||
public static readonly DependencyProperty FontWeightProperty =
|
||||
TextElement.FontWeightProperty.AddOwner(
|
||||
typeof(SizeCell),
|
||||
new FrameworkPropertyMetadata(
|
||||
FontWeights.Normal,
|
||||
FrameworkPropertyMetadataOptions.AffectsMeasure |
|
||||
FrameworkPropertyMetadataOptions.AffectsRender,
|
||||
WPFHelper.prop_changed_callback<FontWeight, SizeCell>(
|
||||
(p, v) => {
|
||||
p._glyph_context = p._glyph_context.with(v);
|
||||
p._set_glyph_text();
|
||||
})));
|
||||
|
||||
public FontWeight FontWeight { get => (FontWeight)GetValue(FontWeightProperty); set => SetValue(FontWeightProperty, value); }
|
||||
#endregion
|
||||
|
||||
#region FontFamily
|
||||
public static readonly DependencyProperty FontFamilyProperty =
|
||||
TextElement.FontFamilyProperty.AddOwner(
|
||||
@@ -81,12 +74,29 @@ namespace mbts.ui.controls {
|
||||
WPFHelper.prop_changed_callback<FontFamily, SizeCell>(
|
||||
(p, v) => {
|
||||
p._glyph_context = p._glyph_context.with(v);
|
||||
p._set_glyph_text();
|
||||
p._glyph_run = null;
|
||||
})));
|
||||
|
||||
public FontFamily FontFamily { get => GetValue(FontFamilyProperty) as FontFamily; set => SetValue(FontFamilyProperty, value); }
|
||||
#endregion
|
||||
|
||||
|
||||
#region FontWeight
|
||||
public static readonly DependencyProperty FontWeightProperty =
|
||||
TextElement.FontWeightProperty.AddOwner(
|
||||
typeof(SizeCell),
|
||||
new FrameworkPropertyMetadata(
|
||||
FontWeights.Normal,
|
||||
FrameworkPropertyMetadataOptions.AffectsMeasure |
|
||||
FrameworkPropertyMetadataOptions.AffectsRender,
|
||||
WPFHelper.prop_changed_callback<FontWeight, SizeCell>(
|
||||
(p, v) => {
|
||||
p._glyph_context = p._glyph_context.with(v);
|
||||
p._glyph_run = null;
|
||||
})));
|
||||
|
||||
public FontWeight FontWeight { get => (FontWeight)GetValue(FontWeightProperty); set => SetValue(FontWeightProperty, value); }
|
||||
#endregion
|
||||
|
||||
#region FontSize
|
||||
public static readonly DependencyProperty FontSizeProperty =
|
||||
TextElement.FontSizeProperty.AddOwner(
|
||||
@@ -99,7 +109,7 @@ namespace mbts.ui.controls {
|
||||
WPFHelper.prop_changed_callback<double, SizeCell>(
|
||||
(p, v) => {
|
||||
p._font_size = v;
|
||||
p._set_glyph_text();
|
||||
p._glyph_run = null;
|
||||
})));
|
||||
|
||||
public double FontSize { get => (double)GetValue(FontSizeProperty); set => SetValue(FontSizeProperty, value); }
|
||||
@@ -113,37 +123,49 @@ namespace mbts.ui.controls {
|
||||
FrameworkPropertyMetadataOptions.AffectsRender,
|
||||
(p, v) => {
|
||||
p._padding = v;
|
||||
p._set_glyph_text();
|
||||
p._glyph_run = null;
|
||||
}, DefaultCellPadding);
|
||||
|
||||
public Thickness Padding { get => (Thickness)GetValue(PaddingProperty); set => SetValue(PaddingProperty, value); }
|
||||
#endregion
|
||||
|
||||
#region Value
|
||||
#region Size
|
||||
public static readonly DependencyProperty ValueProperty =
|
||||
WPFHelper.create_dp<ushort, SizeCell>(
|
||||
nameof(Value),
|
||||
FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender,
|
||||
FrameworkPropertyMetadataOptions.AffectsMeasure |
|
||||
FrameworkPropertyMetadataOptions.AffectsRender,
|
||||
(p, v) => {
|
||||
p._value = v;
|
||||
p._set_glyph_text();
|
||||
});
|
||||
p._glyph_run = null;
|
||||
}, 0);
|
||||
|
||||
public ushort Value { get => (ushort)GetValue(ValueProperty); set => SetValue(ValueProperty, value); }
|
||||
#endregion
|
||||
|
||||
void _set_glyph_text() =>
|
||||
_glyph_text = _glyph_context.get_glyph_text(_value.ToString(), _font_size, DesiredSize, _horizontal_alignment, VerticalAlignment.Center, _padding);
|
||||
protected override Size ArrangeOverride(Size finalSize) {
|
||||
if (_glyph_run == null)
|
||||
_set_glyph(finalSize);
|
||||
return finalSize;
|
||||
}
|
||||
|
||||
protected override Size ArrangeOverride(Size finalSize) => finalSize;
|
||||
protected override Size MeasureOverride(Size availableSize) =>
|
||||
CellRender.measure_text_cell(this, _glyph_text, _padding, availableSize);
|
||||
protected override Size MeasureOverride(Size availableSize) {
|
||||
if (_glyph_run == null)
|
||||
_set_glyph(availableSize);
|
||||
return new Size(Math.Max(availableSize.Width, _padding.Left + _glyph_width + _padding.Right),
|
||||
Math.Max(availableSize.Height, _padding.Top + _font_size + _padding.Bottom));
|
||||
}
|
||||
|
||||
void _set_glyph(Size size) {
|
||||
_glyph_run = _glyph_context.get_glyph_run(_value.ToString(), _font_size, size, _horizontal_alignment, VerticalAlignment.Center, _padding);
|
||||
_glyph_width = _glyph_run == null ? 0 : _glyph_run.AdvanceWidths.Sum();
|
||||
}
|
||||
|
||||
protected override void OnRender(DrawingContext drawingContext) {
|
||||
if (_background != null)
|
||||
drawingContext.DrawRectangle(_background, null, new Rect(RenderSize));
|
||||
if (_glyph_text != null)
|
||||
drawingContext.draw_glyph_run_anti_alias(_foreground, _glyph_text);
|
||||
if (_glyph_run != null)
|
||||
drawingContext.DrawGlyphRun(_foreground, _glyph_run);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using mbts.ui.utility.text;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
@@ -13,14 +15,21 @@ namespace mbts.ui.controls {
|
||||
Thickness _padding;
|
||||
HorizontalAlignment _horizontal_alignment;
|
||||
Brush _background, _foreground;
|
||||
double _font_size;
|
||||
double _glyph_width, _font_size;
|
||||
string _text;
|
||||
GlyphRun _glyph_run;
|
||||
GlyphContext _glyph_context;
|
||||
GlyphText _glyph_text;
|
||||
|
||||
static TextCell() =>
|
||||
WPFHelper.override_metadata<HorizontalAlignment, TextCell>(
|
||||
HorizontalAlignmentProperty, FrameworkPropertyMetadataOptions.AffectsRender, (o, v) => o._horizontal_alignment = v, HorizontalAlignment.Left);
|
||||
HorizontalAlignmentProperty,
|
||||
FrameworkPropertyMetadataOptions.AffectsArrange |
|
||||
FrameworkPropertyMetadataOptions.AffectsRender,
|
||||
(o, v) => {
|
||||
o._horizontal_alignment = v;
|
||||
o._glyph_run = null;
|
||||
},
|
||||
HorizontalAlignment.Left);
|
||||
|
||||
public TextCell() {
|
||||
_background = Background;
|
||||
@@ -65,7 +74,7 @@ namespace mbts.ui.controls {
|
||||
WPFHelper.prop_changed_callback<FontFamily, TextCell>(
|
||||
(p, v) => {
|
||||
p._glyph_context = p._glyph_context.with(v);
|
||||
p._set_glyph_text();
|
||||
p._glyph_run = null;
|
||||
})));
|
||||
|
||||
public FontFamily FontFamily { get => GetValue(FontFamilyProperty) as FontFamily; set => SetValue(FontFamilyProperty, value); }
|
||||
@@ -82,7 +91,7 @@ namespace mbts.ui.controls {
|
||||
WPFHelper.prop_changed_callback<FontWeight, TextCell>(
|
||||
(p, v) => {
|
||||
p._glyph_context = p._glyph_context.with(v);
|
||||
p._set_glyph_text();
|
||||
p._glyph_run = null;
|
||||
})));
|
||||
|
||||
public FontWeight FontWeight { get => (FontWeight)GetValue(FontWeightProperty); set => SetValue(FontWeightProperty, value); }
|
||||
@@ -100,7 +109,7 @@ namespace mbts.ui.controls {
|
||||
WPFHelper.prop_changed_callback<double, TextCell>(
|
||||
(p, v) => {
|
||||
p._font_size = v;
|
||||
p._set_glyph_text();
|
||||
p._glyph_run = null;
|
||||
})));
|
||||
|
||||
public double FontSize { get => (double)GetValue(FontSizeProperty); set => SetValue(FontSizeProperty, value); }
|
||||
@@ -114,7 +123,7 @@ namespace mbts.ui.controls {
|
||||
FrameworkPropertyMetadataOptions.AffectsRender,
|
||||
(p, v) => {
|
||||
p._padding = v;
|
||||
p._set_glyph_text();
|
||||
p._glyph_run = null;
|
||||
}, DefaultCellPadding);
|
||||
|
||||
public Thickness Padding { get => (Thickness)GetValue(PaddingProperty); set => SetValue(PaddingProperty, value); }
|
||||
@@ -124,27 +133,39 @@ namespace mbts.ui.controls {
|
||||
public static readonly DependencyProperty TextProperty =
|
||||
WPFHelper.create_dp<string, TextCell>(
|
||||
nameof(Text),
|
||||
FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender,
|
||||
FrameworkPropertyMetadataOptions.AffectsMeasure |
|
||||
FrameworkPropertyMetadataOptions.AffectsRender,
|
||||
(p, v) => {
|
||||
p._text = v;
|
||||
p._set_glyph_text();
|
||||
p._glyph_run = null;
|
||||
});
|
||||
|
||||
public string Text { get => GetValue(TextProperty) as string; set => SetValue(TextProperty, value); }
|
||||
#endregion
|
||||
|
||||
void _set_glyph_text() =>
|
||||
_glyph_text = _glyph_context.get_glyph_text(_text, _font_size, DesiredSize, _horizontal_alignment, VerticalAlignment.Center, _padding);
|
||||
|
||||
protected override Size ArrangeOverride(Size finalSize) => finalSize;
|
||||
protected override Size MeasureOverride(Size availableSize) =>
|
||||
CellRender.measure_text_cell(this, _glyph_text, _padding, availableSize);
|
||||
protected override Size ArrangeOverride(Size finalSize) {
|
||||
if (_glyph_run == null)
|
||||
_set_glyph(finalSize);
|
||||
return finalSize;
|
||||
}
|
||||
|
||||
protected override Size MeasureOverride(Size availableSize) {
|
||||
if (_glyph_run == null)
|
||||
_set_glyph(availableSize);
|
||||
return new Size(Math.Max(availableSize.Width, _padding.Left + _glyph_width + _padding.Right),
|
||||
Math.Max(availableSize.Height, _padding.Top + _font_size + _padding.Bottom));
|
||||
}
|
||||
|
||||
void _set_glyph(Size size) {
|
||||
_glyph_run = _glyph_context.get_glyph_run(_text, _font_size, size, _horizontal_alignment, VerticalAlignment.Center, _padding);
|
||||
_glyph_width = _glyph_run == null ? 0 : _glyph_run.AdvanceWidths.Sum();
|
||||
}
|
||||
|
||||
protected override void OnRender(DrawingContext drawingContext) {
|
||||
if (_background != null)
|
||||
drawingContext.DrawRectangle(_background, null, new Rect(RenderSize));
|
||||
if (_glyph_text != null)
|
||||
drawingContext.draw_glyph_run_anti_alias(_foreground, _glyph_text);
|
||||
if (_glyph_run != null)
|
||||
drawingContext.DrawGlyphRun(_foreground, _glyph_run);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
static RenderUtils() => _working_order_brush.Freeze();
|
||||
|
||||
public static GlyphContext get_glyph_context(OrderBookRowVM r) => r.is_child ? _child_glyph_context : TextUtils.StandardGlyphContext;
|
||||
public static Brush get_side_brush(OrderBookRowVM r) => r.side == Side.Buy ? BTSColors.MarketData.bid : BTSColors.MarketData.ask;
|
||||
public static BindingBase get_font_weight_binding() => new Binding(nameof(OrderBookRowVM.is_child)) { Converter = _font_weight_converter };
|
||||
@@ -92,7 +93,7 @@ namespace mbts.spark {
|
||||
: base(Columns.Filled, "Filled Qty", nameof(OrderBookRowVM.filled_quantity), DefaultColumnWidths.Size, filter, DataGridFilterKnownTemplates.UIntMinMax) { }
|
||||
|
||||
public void draw(OrderBookRowVM row, DrawingContext dc, ColumnGeometry position, double row_height) =>
|
||||
CellRender.draw_text(dc, RenderUtils.get_glyph_context(row), RenderUtils.font_size, row.quantity.ToString(), position, RowHeight,
|
||||
CellRender.draw_text(dc, RenderUtils.get_glyph_context(row), RenderUtils.font_size, row.filled_quantity.ToString(), position, RowHeight,
|
||||
RenderUtils.get_side_brush(row), null, HorizontalAlignment.Right, VerticalAlignment.Center, DefaultCellPadding);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
xmlns:order="clr-namespace:bts.api.orderman;assembly=spark_api"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="600" d:DesignWidth="1080"
|
||||
FocusManager.IsFocusScope="True">
|
||||
FocusManager.IsFocusScope="True"
|
||||
Background="{StaticResource CommonBackground}">
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
@@ -54,19 +55,20 @@
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<!-- Table -->
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
<AdornerDecorator>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<!-- Table -->
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
|
||||
<GridSplitter Width="2" Grid.Row="2" Grid.Column="0" />
|
||||
<GridSplitter Width="2" Grid.Row="2" Grid.Column="0" />
|
||||
|
||||
<!--<c:DataGridEx Grid.Row="2" Grid.Column="1" x:Name="_grid" IsReadOnly="True" BorderThickness="0" GridLinesVisibility="None" CanUserSortColumns="true" SelectionUnit="FullRow" Sorting="data_grid_sorting"
|
||||
<!--<c:DataGridEx Grid.Row="2" Grid.Column="1" x:Name="_grid" IsReadOnly="True" BorderThickness="0" GridLinesVisibility="None" CanUserSortColumns="true" SelectionUnit="FullRow" Sorting="data_grid_sorting"
|
||||
RowHeight="{Binding row_height}" ItemsSource="{Binding visible_orders}" CurrentItem="{Binding current_row, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" uc:DataGridBehavior.NotifyColumnsOfSorting="True">
|
||||
<DataGrid.Resources>
|
||||
<ResourceDictionary>
|
||||
@@ -325,7 +327,7 @@
|
||||
|
||||
</c:DataGridEx>-->
|
||||
|
||||
<c:DIYGrid
|
||||
<c:DIYGrid
|
||||
x:Name="_grid"
|
||||
Grid.Row="2"
|
||||
Columns="{Binding columns}"
|
||||
@@ -334,101 +336,102 @@
|
||||
RowHeight="{x:Static sp:OrderBookView.RowHeight}"
|
||||
Sorting="data_grid_sorting"
|
||||
>
|
||||
<c:DIYGrid.Resources>
|
||||
<ResourceDictionary>
|
||||
<SolidColorBrush x:Key="TreeViewItem.TreeArrow.Static.Checked.Fill" Color="#FF595959"/>
|
||||
<SolidColorBrush x:Key="TreeViewItem.TreeArrow.Static.Checked.Stroke" Color="#FF262626"/>
|
||||
<SolidColorBrush x:Key="TreeViewItem.TreeArrow.MouseOver.Stroke" Color="#FF27C7F7"/>
|
||||
<SolidColorBrush x:Key="TreeViewItem.TreeArrow.MouseOver.Fill" Color="#FFCCEEFB"/>
|
||||
<SolidColorBrush x:Key="TreeViewItem.TreeArrow.MouseOver.Checked.Stroke" Color="#FF1CC4F7"/>
|
||||
<SolidColorBrush x:Key="TreeViewItem.TreeArrow.MouseOver.Checked.Fill" Color="#FF82DFFB"/>
|
||||
<PathGeometry x:Key="TreeArrow" Figures="M0,0 L0,6 L6,0 z"/>
|
||||
<SolidColorBrush x:Key="TreeViewItem.TreeArrow.Static.Fill" Color="#FFFFFFFF"/>
|
||||
<SolidColorBrush x:Key="TreeViewItem.TreeArrow.Static.Stroke" Color="#FF818181"/>
|
||||
<Style x:Key="{x:Static sp:OrderBookView.ExpandCollapseToggleStyleKey}" TargetType="{x:Type ToggleButton}">
|
||||
<Setter Property="Focusable" Value="False"/>
|
||||
<Setter Property="Width" Value="16"/>
|
||||
<Setter Property="Height" Value="16"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type ToggleButton}">
|
||||
<Border Background="Transparent" Height="16" Padding="0,5,5,5" Width="16">
|
||||
<Path x:Name="ExpandPath" Data="{StaticResource TreeArrow}" Fill="{StaticResource TreeViewItem.TreeArrow.Static.Fill}" Stroke="{StaticResource TreeViewItem.TreeArrow.Static.Stroke}">
|
||||
<Path.RenderTransform>
|
||||
<RotateTransform Angle="135" CenterY="3" CenterX="3"/>
|
||||
</Path.RenderTransform>
|
||||
</Path>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsChecked" Value="True">
|
||||
<Setter Property="RenderTransform" TargetName="ExpandPath">
|
||||
<Setter.Value>
|
||||
<RotateTransform Angle="180" CenterY="3" CenterX="3"/>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Setter Property="Fill" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.Static.Checked.Fill}"/>
|
||||
<Setter Property="Stroke" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.Static.Checked.Stroke}"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Stroke" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.MouseOver.Stroke}"/>
|
||||
<Setter Property="Fill" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.MouseOver.Fill}"/>
|
||||
</Trigger>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="IsMouseOver" Value="True"/>
|
||||
<Condition Property="IsChecked" Value="True"/>
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property="Stroke" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.MouseOver.Checked.Stroke}"/>
|
||||
<Setter Property="Fill" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.MouseOver.Checked.Fill}"/>
|
||||
</MultiTrigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
<Style TargetType="{x:Type ToolTip}">
|
||||
<Style.Triggers>
|
||||
<Trigger Property="Content" Value="{x:Static sys:String.Empty}">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
</Trigger>
|
||||
<Trigger Property="Content" Value="{x:Null}">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
</c:DIYGrid.Resources>
|
||||
<c:DIYGrid.InputBindings>
|
||||
<MouseBinding MouseAction="LeftDoubleClick" Command="{x:Static c:DIYGrid.DefaultRowCommand}"/>
|
||||
<KeyBinding Key="Return" Command="{x:Static c:DIYGrid.DefaultRowCommand}"/>
|
||||
</c:DIYGrid.InputBindings>
|
||||
<c:DIYGrid.CommandBindings>
|
||||
<CommandBinding
|
||||
<c:DIYGrid.Resources>
|
||||
<ResourceDictionary>
|
||||
<SolidColorBrush x:Key="TreeViewItem.TreeArrow.Static.Checked.Fill" Color="#FF595959"/>
|
||||
<SolidColorBrush x:Key="TreeViewItem.TreeArrow.Static.Checked.Stroke" Color="#FF262626"/>
|
||||
<SolidColorBrush x:Key="TreeViewItem.TreeArrow.MouseOver.Stroke" Color="#FF27C7F7"/>
|
||||
<SolidColorBrush x:Key="TreeViewItem.TreeArrow.MouseOver.Fill" Color="#FFCCEEFB"/>
|
||||
<SolidColorBrush x:Key="TreeViewItem.TreeArrow.MouseOver.Checked.Stroke" Color="#FF1CC4F7"/>
|
||||
<SolidColorBrush x:Key="TreeViewItem.TreeArrow.MouseOver.Checked.Fill" Color="#FF82DFFB"/>
|
||||
<PathGeometry x:Key="TreeArrow" Figures="M0,0 L0,6 L6,0 z"/>
|
||||
<SolidColorBrush x:Key="TreeViewItem.TreeArrow.Static.Fill" Color="#FFFFFFFF"/>
|
||||
<SolidColorBrush x:Key="TreeViewItem.TreeArrow.Static.Stroke" Color="#FF818181"/>
|
||||
<Style x:Key="{x:Static sp:OrderBookView.ExpandCollapseToggleStyleKey}" TargetType="{x:Type ToggleButton}">
|
||||
<Setter Property="Focusable" Value="False"/>
|
||||
<Setter Property="Width" Value="16"/>
|
||||
<Setter Property="Height" Value="16"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type ToggleButton}">
|
||||
<Border Background="Transparent" Height="16" Padding="0,5,5,5" Width="16">
|
||||
<Path x:Name="ExpandPath" Data="{StaticResource TreeArrow}" Fill="{StaticResource TreeViewItem.TreeArrow.Static.Fill}" Stroke="{StaticResource TreeViewItem.TreeArrow.Static.Stroke}">
|
||||
<Path.RenderTransform>
|
||||
<RotateTransform Angle="135" CenterY="3" CenterX="3"/>
|
||||
</Path.RenderTransform>
|
||||
</Path>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsChecked" Value="True">
|
||||
<Setter Property="RenderTransform" TargetName="ExpandPath">
|
||||
<Setter.Value>
|
||||
<RotateTransform Angle="180" CenterY="3" CenterX="3"/>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Setter Property="Fill" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.Static.Checked.Fill}"/>
|
||||
<Setter Property="Stroke" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.Static.Checked.Stroke}"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Stroke" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.MouseOver.Stroke}"/>
|
||||
<Setter Property="Fill" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.MouseOver.Fill}"/>
|
||||
</Trigger>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="IsMouseOver" Value="True"/>
|
||||
<Condition Property="IsChecked" Value="True"/>
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property="Stroke" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.MouseOver.Checked.Stroke}"/>
|
||||
<Setter Property="Fill" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.MouseOver.Checked.Fill}"/>
|
||||
</MultiTrigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
<Style TargetType="{x:Type ToolTip}">
|
||||
<Style.Triggers>
|
||||
<Trigger Property="Content" Value="{x:Static sys:String.Empty}">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
</Trigger>
|
||||
<Trigger Property="Content" Value="{x:Null}">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
</c:DIYGrid.Resources>
|
||||
<c:DIYGrid.InputBindings>
|
||||
<MouseBinding MouseAction="LeftDoubleClick" Command="{x:Static c:DIYGrid.DefaultRowCommand}"/>
|
||||
<KeyBinding Key="Return" Command="{x:Static c:DIYGrid.DefaultRowCommand}"/>
|
||||
</c:DIYGrid.InputBindings>
|
||||
<c:DIYGrid.CommandBindings>
|
||||
<CommandBinding
|
||||
Command="{x:Static c:DIYGrid.DefaultRowCommand}"
|
||||
Executed="{x:Static c:DIYGrid.DefaultRowActionExecuted}"
|
||||
CanExecute="{x:Static c:DIYGrid.DefaultRowActionCanExecute}"
|
||||
/>
|
||||
</c:DIYGrid.CommandBindings>
|
||||
<c:DIYGrid.RowStyle>
|
||||
<Style TargetType="ListBoxItem" BasedOn="{StaticResource DIYGridRowStyle}">
|
||||
<Style.Triggers>
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
<Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="False"/>
|
||||
<Condition Binding="{Binding status}" Value="{uc:Enum Working, Type=order:OrderStatus}"/>
|
||||
</MultiDataTrigger.Conditions>
|
||||
<MultiDataTrigger.Setters>
|
||||
<Setter Property="Background" Value="{x:Static Member=working_order_background_brush, MemberType={uc:Nested uc:BTSColors.Orders}}"/>
|
||||
</MultiDataTrigger.Setters>
|
||||
</MultiDataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</c:DIYGrid.RowStyle>
|
||||
<c:DIYGrid.RowTemplate>
|
||||
<DataTemplate>
|
||||
<sp:OrderBookRowView/>
|
||||
</DataTemplate>
|
||||
</c:DIYGrid.RowTemplate>
|
||||
</c:DIYGrid>
|
||||
</Grid>
|
||||
</c:DIYGrid.CommandBindings>
|
||||
<c:DIYGrid.RowStyle>
|
||||
<Style TargetType="ListBoxItem" BasedOn="{StaticResource DIYGridRowStyle}">
|
||||
<Style.Triggers>
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
<Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="False"/>
|
||||
<Condition Binding="{Binding status}" Value="{uc:Enum Working, Type=order:OrderStatus}"/>
|
||||
</MultiDataTrigger.Conditions>
|
||||
<MultiDataTrigger.Setters>
|
||||
<Setter Property="Background" Value="{x:Static Member=working_order_background_brush, MemberType={uc:Nested uc:BTSColors.Orders}}"/>
|
||||
</MultiDataTrigger.Setters>
|
||||
</MultiDataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</c:DIYGrid.RowStyle>
|
||||
<c:DIYGrid.RowTemplate>
|
||||
<DataTemplate>
|
||||
<sp:OrderBookRowView/>
|
||||
</DataTemplate>
|
||||
</c:DIYGrid.RowTemplate>
|
||||
</c:DIYGrid>
|
||||
</Grid>
|
||||
</AdornerDecorator>
|
||||
</UserControl>
|
||||
@@ -8,11 +8,10 @@ namespace mbts.spark {
|
||||
public const string
|
||||
SubTypeFilterTemplateKey = "SubTypeFilterTemplate",
|
||||
ExpandCollapseToggleStyleKey = "ExpandCollapseToggleStyle";
|
||||
public const double RowHeight = 18;
|
||||
public const double RowHeight = 17;
|
||||
OrderBookVM _vm;
|
||||
//DataGridEx _grid;
|
||||
public OrderBookView(OrderBookVM vm) {
|
||||
UseLayoutRounding = true;
|
||||
InitializeComponent();
|
||||
_vm = vm;
|
||||
DataContext = vm;
|
||||
|
||||
@@ -10,7 +10,7 @@ using System.Windows;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace mbts.spark {
|
||||
internal class OrderBookWindow : SparkWindow<OrderBookWindowFactory.OrderBookStartupData> {
|
||||
internal class OrderBookWindow : SparkWindow<OrderBookWindowFactory.OrderBookStartupData>, ISharedWindow {
|
||||
|
||||
const string _window_type = "OrderBook", ORDERBOOK_THREAD_ID = "OrderBook";
|
||||
OrderBookWindowFactory.OrderBookStartupData _state;
|
||||
@@ -32,7 +32,6 @@ namespace mbts.spark {
|
||||
_model = model;
|
||||
_factory = factory;
|
||||
_state = state;
|
||||
thread_init();
|
||||
}
|
||||
|
||||
public override OrderBookWindowFactory.OrderBookStartupData SaveState => _state =
|
||||
|
||||
@@ -8,21 +8,6 @@ using System.Windows;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace mbts.ui.utility.text {
|
||||
// thin wrapper around a GlyphRun that stores useful size/alignment info
|
||||
class GlyphText {
|
||||
public readonly GlyphRun run;
|
||||
public readonly double width, height, font_size;
|
||||
public readonly Rect alignment_box;
|
||||
|
||||
public GlyphText(GlyphRun run, double width, double font_size) {
|
||||
this.run = run;
|
||||
this.width = width;
|
||||
this.font_size = font_size;
|
||||
height = font_size;
|
||||
alignment_box = new Rect(0, 0, width, height);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Reduces the performance overhead of creating GlyphRuns of a particular GlyphTypeface by mapping all chars to glyph indices/widths upon construction.
|
||||
/// <para/>Note: Useful in situations where Glyphtypeface will never or rarely change. The overhead, in this case, is spent creating the map in the constructor.
|
||||
/// </summary>
|
||||
@@ -80,31 +65,13 @@ namespace mbts.ui.utility.text {
|
||||
return new GlyphRun(_glyph_typeface, 0, false, font_size, HighDpiExtensions.fdpi_ratio, glyph_indices, origin, advance_widths, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
public GlyphText get_glyph_text(string text, double font_size, Size available_size, HorizontalAlignment x_alignment, VerticalAlignment y_alignment, Thickness padding) =>
|
||||
get_glyph_text(text, font_size, available_size.Width, available_size.Height, x_alignment, y_alignment, padding);
|
||||
public GlyphRun get_glyph_run(string text, double font_size, Size available_size, HorizontalAlignment x_alignment, VerticalAlignment y_alignment, Thickness padding) =>
|
||||
get_glyph_run(text, font_size, available_size.Width, available_size.Height, x_alignment, y_alignment, padding);
|
||||
|
||||
public GlyphText get_glyph_text(string text, double font_size, double available_width, double available_height, HorizontalAlignment x_alignment, VerticalAlignment y_alignment, Thickness padding) =>
|
||||
get_glyph_text(text, font_size, 0, 0, available_width, available_height, x_alignment, y_alignment, padding);
|
||||
public GlyphRun get_glyph_run(string text, double font_size, double available_width, double available_height, HorizontalAlignment x_alignment, VerticalAlignment y_alignment, Thickness padding) =>
|
||||
get_glyph_run(text, font_size, 0, 0, available_width, available_height, x_alignment, y_alignment, padding);
|
||||
|
||||
public GlyphText get_glyph_text(
|
||||
string text, double font_size, double available_width, double available_height,
|
||||
HorizontalAlignment x_alignment, double x_offset, VerticalAlignment y_alignment, double y_offset) {
|
||||
//
|
||||
if (string.IsNullOrEmpty(text))
|
||||
return null;
|
||||
var glyph_indices = new ushort[text.Length];
|
||||
var advance_widths = new double[text.Length];
|
||||
if (!_try_get_glyph_params(text, font_size, ref glyph_indices, ref advance_widths, out double glyph_width))
|
||||
return null;
|
||||
var origin = _calculate_glyph_run_origin(font_size, available_width, available_height, glyph_width, x_alignment, x_offset, y_alignment, y_offset);
|
||||
return new GlyphText(
|
||||
new GlyphRun(_glyph_typeface, 0, false, font_size, HighDpiExtensions.fdpi_ratio, glyph_indices, origin, advance_widths, null, null, null, null, null, null),
|
||||
glyph_width, font_size);
|
||||
}
|
||||
|
||||
// since no clipping/resizinig is done at this level, the appropriate padding property with respect to x_alignment is translated into a x_offset.
|
||||
// y_alignment will be treated in the same manner (see the switch-cases code for details).
|
||||
public GlyphText get_glyph_text(
|
||||
public GlyphRun get_glyph_run(
|
||||
string text, double font_size, double left, double top, double right, double bottom,
|
||||
HorizontalAlignment x_alignment, VerticalAlignment y_alignment, Thickness padding) {
|
||||
//
|
||||
@@ -115,49 +82,9 @@ namespace mbts.ui.utility.text {
|
||||
if (!_try_get_glyph_params(text, font_size, ref glyph_indices, ref advance_widths, out double glyph_width))
|
||||
return null;
|
||||
var origin = _calculate_glyph_run_origin(font_size, left, top, right, bottom, glyph_width, x_alignment, y_alignment, padding);
|
||||
return new GlyphText(
|
||||
new GlyphRun(_glyph_typeface, 0, false, font_size, HighDpiExtensions.fdpi_ratio, glyph_indices, origin, advance_widths, null, null, null, null, null, null),
|
||||
glyph_width, font_size);
|
||||
return new GlyphRun(_glyph_typeface, 0, false, font_size, HighDpiExtensions.fdpi_ratio, glyph_indices, origin, advance_widths, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
public IEnumerable<GlyphText> get_glyph_text_lines(IReadOnlyList<string> lines,
|
||||
double font_size, double line_spacing, double available_width, double available_height,
|
||||
HorizontalAlignment x_alignment, double x_offset, VerticalAlignment v_alignment, double y_offset) {
|
||||
// ultimately, each line with will be formatted with "Top" alignment,
|
||||
// if v_alignment is Center/Bottom, measure text height and adjust y_offset to effectively align the text accordingly.
|
||||
switch (v_alignment) {
|
||||
case VerticalAlignment.Center: {
|
||||
double text_height = get_text_height();
|
||||
double adjustment = 0.5 * (available_height - text_height);
|
||||
y_offset += adjustment;
|
||||
}
|
||||
break;
|
||||
case VerticalAlignment.Bottom: {
|
||||
double text_height = get_text_height();
|
||||
double adjustment = available_height - text_height;
|
||||
y_offset += adjustment;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
foreach (string l in lines) {
|
||||
yield return get_glyph_text(l, font_size, available_width, available_height, x_alignment, x_offset, VerticalAlignment.Top, y_offset);
|
||||
y_offset += line_spacing + font_size;
|
||||
}
|
||||
double get_text_height() =>
|
||||
lines.Count * font_size + (lines.Count - 1) * line_spacing;
|
||||
}
|
||||
|
||||
public double measure_width(string text, double font_size) {
|
||||
double glyph_width = 0;
|
||||
foreach (char c in text) {
|
||||
if (!_char_map.TryGetValue(c, out (ushort index, double width) gc))
|
||||
return double.NaN;
|
||||
glyph_width += gc.width * font_size;
|
||||
}
|
||||
return glyph_width;
|
||||
}
|
||||
|
||||
static Point _calculate_glyph_run_origin(
|
||||
double font_size, double available_width, double available_height, double glyph_width,
|
||||
HorizontalAlignment x_alignment, double x_offset, VerticalAlignment y_alignment, double y_offset ) {
|
||||
|
||||
@@ -73,28 +73,6 @@ namespace mbts.ui.utility.text {
|
||||
public static FontWeight from_open_type_weight_safe(int weight_value) =>
|
||||
FontWeight.FromOpenTypeWeight(MathUtils.within_range(1, 999, weight_value));
|
||||
|
||||
// https://stackoverflow.com/questions/4095750/wpf-4-0-drawing-aliased-formattedtext-glyphrun
|
||||
public static GuidelineSet get_anti_alias_guidelines(Rect alignment_box) {
|
||||
double half_stroke_thickness = 0.5;
|
||||
// Create a guidelines set
|
||||
GuidelineSet guidelines = new GuidelineSet();
|
||||
guidelines.GuidelinesX.Add(alignment_box.Left + half_stroke_thickness);
|
||||
guidelines.GuidelinesX.Add(alignment_box.Right + half_stroke_thickness);
|
||||
guidelines.GuidelinesY.Add(alignment_box.Top + half_stroke_thickness);
|
||||
guidelines.GuidelinesY.Add(alignment_box.Bottom + half_stroke_thickness);
|
||||
return guidelines;
|
||||
}
|
||||
|
||||
public static void draw_glyph_run_anti_alias(this DrawingContext dc, Brush foreground, GlyphText glyph_text) =>
|
||||
_draw_glyph_run_anti_alias(dc, foreground, glyph_text.run, glyph_text.alignment_box);
|
||||
|
||||
static void _draw_glyph_run_anti_alias(DrawingContext dc, Brush foreground, GlyphRun glyph_run, Rect alignment_box) {
|
||||
//var anti_alias_guidelines = get_anti_alias_guidelines(alignment_box);
|
||||
//dc.PushGuidelineSet(anti_alias_guidelines);
|
||||
dc.DrawGlyphRun(foreground, glyph_run);
|
||||
//dc.Pop();
|
||||
}
|
||||
|
||||
public static string InsertText(string current_text, string insertion_text, int insertion_index, int selection_start, int selection_length) {
|
||||
if (selection_length > 0)
|
||||
current_text = current_text.Remove(selection_start, selection_length);
|
||||
|
||||
Reference in new issue
Block a user