public Scope Group(string name, Colour32 colour, m4x4 transform) { return(Scope.Create( () => GroupOpen(name, colour), () => GroupClose(transform) )); }
// Notes: // - Given a colour, returns a brush suitable for text written over that colour public object?Convert(object value, Type targetType, object parameter, CultureInfo culture) { var colour = Colour32.White; switch (value) { case Color col: colour = col.ToColour32(); break; case Colour32 col32: colour = col32; break; case uint u32: colour = new Colour32(u32); break; case int i32: colour = new Colour32((uint)i32); break; } return(colour.Intensity > 0.5 ? Brushes.Black : Brushes.White); }
public static string LineStrip(string name, Colour32 colour, int width, IEnumerable <v4> points, m4x4?o2w = null, v4?pos = null) { var w = Width(width); var pts = points.Select(x => " " + Vec3(x)); return($"*LineStrip {name} {colour} {{{w} {pts} {Transform(o2w, pos)}}}"); }
public LdrBuilder Line(string name, Colour32 colour, float width, bool smooth, IEnumerable <v4> points) { if (!points.Any()) { return(this); } return(Append("*LineStrip ", name, " ", colour, " {", Ldr.Width(width), Ldr.Smooth(smooth), points.Select(x => Ldr.Vec3(x)), "}\n")); }
public LdrBuilder Arrow(string name, Colour32 colour, Ldr.EArrowType type, float width, bool smooth, IEnumerable <v4> points) { if (!points.Any()) { return(this); } return(Append("*Arrow ", name, " ", colour, " {", type.ToString(), points.Select(x => Ldr.Vec3(x)), Ldr.Width(width), Ldr.Smooth(smooth), "}\n")); }
public object?Convert(object value, Type targetType, object parameter, CultureInfo culture) { // Allow 'value' to be non-boolean, where not-null == true if (!(value is bool b)) { b = value != null; } if (!(parameter is string s)) { return(null); } try { var c = s.Split('|'); if (c.Length != 2) { throw new Exception($"{nameof(BoolSelect)} parameter has the incorrect format. Expected '<true_value>|<false_value>'"); } var val = b ? c[0] : c[1]; // Special case conversions not handled by 'ConvertTo' if (targetType == typeof(Colour32)) { return(Colour32.Parse(val)); } if (targetType == typeof(Color)) { return(Colour32.Parse(val).ToMediaColor()); } if (targetType == typeof(Brush)) { return(Colour32.Parse(val).ToMediaBrush()); } if (targetType == typeof(Thickness)) { var i = (int?)Util.ConvertTo(val, typeof(int)) ?? 0; return(new Thickness(i)); } if (targetType == typeof(ImageSource)) { // Use: ConverterParameter='image_key1|image_key2' // Image keys should be static resource keys. // Only works if the resources are in App.xml. var res = Application.Current.TryFindResource(val); res ??= Application.Current.MainWindow.TryFindResource(val); res ??= Application.Current.Windows.Cast <Window>().Select(x => x.TryFindResource(val)).FirstOrDefault(x => x != null); return(res); } return(Util.ConvertTo(val, targetType)); } catch { // Handle this silently so that runtime editing XML works return(null); } }
public void Line(string name, Colour32 colour, int width, bool smooth, IEnumerable <v4> points) { if (!points.Any()) { return; } var w = width != 0 ? $"*Width {{{width}}}" : string.Empty; var s = smooth ? "*Smooth " : string.Empty; Append("*LineStrip ", name, " ", colour, " {", w, s, points.Select(x => Ldr.Vec3(x)), "}\n"); }
public LdrBuilder Line(string name, Colour32 colour, float width, bool smooth, Func <int, v4?> points) { int idx = 0; Append("*LineStrip ", name, " ", colour, " {", Ldr.Width(width), Ldr.Smooth(smooth)); for (v4?pt; (pt = points(idx++)) != null;) { Append(Ldr.Vec3(pt.Value)); } Append("}\n"); return(this); }
public LdrBuilder Arrow(string name, Colour32 colour, Ldr.EArrowType type, float width, bool smooth, Func <int, v4?> points) { int idx = 0; Append("*Arrow ", name, " ", colour, " {"); for (v4?pt; (pt = points(idx++)) != null;) { Append(Ldr.Vec3(pt.Value)); } Append(Ldr.Width(width), Ldr.Smooth(smooth), type.ToString(), "}\n"); return(this); }
public void Line(string name, Colour32 colour, int width, bool smooth, Func <int, v4?> points) { int idx = 0; var w = width != 0 ? $"*Width {{{width}}}" : string.Empty; var s = smooth ? "*Smooth " : string.Empty; Append("*LineStrip ", name, " ", colour, " {", w, s); for (v4?pt; (pt = points(idx++)) != null;) { Append(Ldr.Vec3(pt.Value)); } Append("}\n"); }
public ChartSettings() { Q2BColour = new Colour32(0xff22b14c); // Green B2QColour = new Colour32(0xffed1c24); // Red NettWorthColour = new Colour32(0xffbbd2eb); // Blueish ShowOpenOrders = EShowItems.Disabled; ShowCompletedOrders = EShowItems.Disabled; ShowVolume = false; ShowMarketDepth = false; XAxisLabelMode = EXAxisLabelMode.LocalTime; ConfettiLabelSize = 10.0; ConfettiLabelTransparency = 1.0; ConfettiDescriptionsVisible = true; ConfettiLabelsToTheLeft = true; SelectionDistance = 5.0; }
public object?Convert(object value, Type targetType, object parameter, CultureInfo culture) { // Convert all colour types to Colour32 var colour = Colour32.Black; switch (value) { case Color col: { colour = col.ToColour32(); break; } case Colour32 col32: { colour = col32; break; } case uint u32: { colour = new Colour32(u32); break; } case int i32: { colour = new Colour32((uint)i32); break; } } if (parameter is string op) { var m = Regex.Match(op, @"lerp:\s*([0-9a-fA-F]{8})\s+(\d\.?\d*)"); if (m.Success && Colour32.TryParse(m.Groups[1].Value) is Colour32 target && double_.TryParse(m.Groups[2].Value) is double frac) { colour = Colour32.Lerp(colour, target, frac); } } return(new SolidColorBrush(colour.ToMediaColor())); }
public LdrBuilder Mesh(string name, Colour32 colour, IList <v4>?verts, IList <v4>?normals = null, IList <Colour32>?colours = null, IList <v2>?tex = null, IList <ushort>?faces = null, IList <ushort>?lines = null, IList <ushort>?tetra = null, bool generate_normals = false, v4?position = null) { Append("*Mesh ", name, " ", colour, " {\n"); if (verts != null) { Append("*Verts {").Append(verts.Select(x => Ldr.Vec3(x))).Append("}\n"); } if (normals != null) { Append("*Normals {").Append(normals.Select(x => Ldr.Vec3(x))).Append("}\n"); } if (colours != null) { Append("*Colours {").Append(colours.Select(x => Ldr.Colour(x))).Append("}\n"); } if (tex != null) { Append("*TexCoords {").Append(tex.Select(x => Ldr.Vec2(x))).Append("}\n"); } if (verts != null && faces != null) { Debug.Assert(faces.All(i => i >= 0 && i < verts.Count)); Append("*Faces {").Append(faces).Append("}\n"); } if (verts != null && lines != null) { Debug.Assert(lines.All(i => i >= 0 && i < verts.Count)); Append("*Lines {").Append(lines).Append("}\n"); } if (verts != null && tetra != null) { Debug.Assert(tetra.All(i => i >= 0 && i < verts.Count)); Append("*Tetra {").Append(tetra).Append("}\n"); } if (generate_normals) { Append("*GenerateNormals\n"); } if (position != null) { Append(Ldr.Position(position.Value)); } Append("}\n"); return(this); }
public object?Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (!(value is bool b)) { return(null); } if (!(parameter is string s)) { return(null); } var c = s.Split('|'); if (c.Length != 2 || !Colour32.TryParse(c[0], out var true_colour) || !Colour32.TryParse(c[1], out var false_colour)) { throw new Exception($"{nameof(BoolToBrush)} parameter has the incorrect format. Expected '<true_colour>|<false_colour>'"); } var colour = b ? true_colour : false_colour; return(new SolidColorBrush(colour.ToMediaColor())); }
public object?ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { if (!(value is string str)) { return(null); } if (targetType.Equals(typeof(Color))) { return(Colour32.TryParse(str)?.ToMediaColor()); } if (targetType.Equals(typeof(Colour32))) { return(Colour32.TryParse(str)); } if (targetType.Equals(typeof(uint))) { return(Colour32.TryParse(str)?.ARGB); } if (targetType.Equals(typeof(int))) { return((int?)Colour32.TryParse(str)?.ARGB); } return(null); }
public LdrBuilder Axis(string name, Colour32 colour, m4x4 basis, float scale) { return(Append("*Matrix3x3 ", name, " ", colour, " {", basis.x * scale, " ", basis.y * scale, " ", basis.z * scale, " ", Ldr.Position(basis.pos), "}\n")); }
public LdrBuilder Axis(string name, Colour32 colour, m3x4 basis, float scale) { return(Axis(name, colour, new m4x4(basis, v4.Origin), scale)); }
public LdrBuilder Axis(string name, Colour32 colour, m4x4 basis) { return(Axis(name, colour, basis, 0.1f)); }
public LdrBuilder Quad(string name, Colour32 colour, AxisId axis_id, float w, float h, v4 position) { return(Rect(name, colour, axis_id, w, h, true, position)); }
public LdrBuilder Quad(string name, Colour32 colour, v4 tl, v4 tr, v4 br, v4 bl, v4 position) { return(Append("*Quad ", name, " ", colour, " {", bl, " ", br, " ", tr, " ", tl, " ", Ldr.Position(position), "}\n")); }
public LdrBuilder Quad(string name, Colour32 colour, v4 tl, v4 tr, v4 br, v4 bl) { return(Quad(name, colour, tl, tr, br, bl, v4.Origin)); }
public LdrBuilder Pie(string name, Colour32 colour, AxisId axis_id, bool solid, float ang0, float ang1, float rad0, float rad1, v4 position) { return(Pie(name, colour, axis_id, solid, ang0, ang1, rad0, rad1, 1f, 1f, 40, position)); }
public LdrBuilder Quad(Colour32 colour, v4 tl, v4 tr, v4 br, v4 bl) { return(Quad(string.Empty, colour, tl, tr, br, bl)); }
public LdrBuilder Quad(Colour32 colour) { return(Quad(string.Empty, colour)); }
public LdrBuilder Triangle(string name, Colour32 colour, IEnumerable <v4> pts, m4x4?o2w = null) { return(Append("*Triangle ", name, " ", colour, " {", pts, Ldr.Transform(o2w), "}")); }
public LdrBuilder Triangle(string name, Colour32 colour, v4 a, v4 b, v4 c, m4x4?o2w = null) { return(Append("*Triangle ", name, " ", colour, " {", a, " ", b, " ", c, " ", Ldr.Transform(o2w), "}")); }
public LdrBuilder Rect(string name, Colour32 colour, AxisId axis_id, float width, float height, bool solid, float corner_radius, v4 position) { return(Append("*Rect ", name, " ", colour, " {", width, " ", height, " ", axis_id, " ", Ldr.Solid(solid), " ", Ldr.CornerRadius(corner_radius), " ", Ldr.Position(position), "}\n")); }
public LdrBuilder Ribbon(string name, Colour32 colour, IEnumerable <v4> points, AxisId axis_id, float width, bool smooth, m4x4?o2w = null) { return(Append("*Ribbon ", name, " ", colour, " {", points, " ", axis_id, Ldr.Width(width), Ldr.Smooth(smooth), Ldr.Transform(o2w), "}\n")); }
public LdrBuilder Pie(string name, Colour32 colour, AxisId axis_id, bool solid, float ang0, float ang1, float rad0, float rad1, float sx, float sy, int facets, v4 position) { return(Append("*Pie ", name, " ", colour, " {", ang0, " ", ang1, " ", rad0, " ", rad1, " ", axis_id, " ", Ldr.Solid(solid), " ", Ldr.Facets(facets), " *Scale ", sx, " ", sy, " ", Ldr.Position(position), "}\n")); }
public LdrBuilder Quad(string name, Colour32 colour) { return(Quad(name, colour, new v4(0, 1, 0, 1), new v4(1, 1, 0, 1), new v4(1, 0, 0, 1), new v4(0, 0, 0, 1))); }