Stroke Class

View as Markdown

Definition

Objects derived from the Stroke class are used to characterize how a plot is visually displayed (plotted) on a chart.

Syntax

Stroke(Stroke stroke)

Stroke(Brush brush)

Stroke(Brush brush, float width)

Stroke(Brush brush, DashStyle dashStyleHelper, float width)

Parameters

ParameterDescription
brushThe brush used to draw the plot (reference)
dashStyleHelperPossible values:
• DashStyleHelper.Dash
• DashStyleHelper.DashDot
• DashStyleHelper.DashDotDot
• DashStyleHelper.Dot
• DashStyleHelper.Solid
strokeThe stroke object
widthThe width of the stroke

Properties

PropertyDescription
BrushThe System.Windows.Media.Brush used to construct the stroke (reference)
BrushDXA SharpDX.Direct2D1.Brush used to actually render the stroke Note: To avoid and resolve access violation exceptions, please see Warning and examples remarked below
DashStyleDXA SharpDX.Direct2D1.DashStyle used to render the stroke style Note: To avoid and resolve access violation exceptions, please see Warning and examples remarked below
DashStyleHelperA dashstyle used to construct the stroke. Possible values are:
• DashStyleHelper.Dash
• DashStyleHelper.DashDot
• DashStyleHelper.DashDotDot
• DashStyleHelper.Dot
• DashStyleHelper.Solid
RenderTargetThe RenderTarget drawing context used for the stroke.

Note: This property must be set before accessing a stroke’s BrushDX property. Please see Warning and examples remarked below

PropertyDescription
StrokeStyleA SharpDX.Direct2D1.StrokeStyle
WidthA float representing the width in pixels

There may be situations where a RenderTarget has not been set, and to prevent access violation exception before accessing the BrushDX or DashStyleDX properties, you should explicitly set the RenderTarget before attempting to access that property. Please see the example below.

Examples

See the AddPlot() method for additional examples.

Using a Stroke SharpDX Brush for Custom Rendering

1protected override void OnStateChange()
2{
3 if (State == State.SetDefaults)
4 {
5 IsOverlay = true;
6 // set the Stroke default to red brush
7 MyStroke = new Stroke(Brushes.Red);
8 }
9 else if (State == State.Configure)
10 {
11 }
12}
13
14public override void OnRenderTargetChanged()
15{
16 // Explicitly set the Stroke RenderTarget
17 if (RenderTarget != null)
18 MyStroke.RenderTarget = RenderTarget;
19}
20
21protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
22{
23 // create two points from the top left corner
24 SharpDX.Vector2 pointA = new SharpDX.Vector2(0, 0);
25 // to 300 pixels offset X and Y to create a diagonal line
26 SharpDX.Vector2 pointB = new SharpDX.Vector2(300, 300);
27
28 // Draw the line using the Stroke SharpDX brush
29 RenderTarget.DrawLine(pointA, pointB, MyStroke.BrushDX, MyStroke.Width, MyStroke.StrokeStyle);
30
31}
32
33[NinjaScriptProperty]
34[Description("My Stroke")]
35public Stroke MyStroke { get; set; }
1protected override void OnStateChange()
2{
3 if (State == State.SetDefaults)
4 {
5 IsOverlay = true;
6 // set stroke default to blue brush
7 MyStroke = new Stroke(Brushes.Blue);
8 }
9 else if (State == State.Configure)
10 {
11 }
12}
13
14protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
15{
16 // create two points from the top left corner
17 SharpDX.Vector2 pointA = new SharpDX.Vector2(0, 0);
18 // to 300 pixels offset X and Y to create a diagonal line
19 SharpDX.Vector2 pointB = new SharpDX.Vector2(300, 300);
20
21 NinjaTrader.Gui.Stroke MyStroke = new Stroke(Brushes.Blue);
22
23 // if BrushDX is null, convert the constructed brush to a DX brush
24 SharpDX.Direct2D1.Brush myBrush = MyStroke.BrushDX ?? MyStroke.Brush.ToDxBrush(RenderTarget);
25 RenderTarget.DrawLine(pointA, pointB, myBrush, MyStroke.Width, MyStroke.StrokeStyle);
26
27 myBrush.Dispose();
28}
29
30[NinjaScriptProperty]
31[Description("My Stroke")]
32public Stroke MyStroke { get; set; }