I am wondering If it is possible use the draws that I make with OnRender in percentage of the chart? Because If I move the dimensions of the chart, it doesnt adapt it
I use like a base code the SampleCustomRender, I cut what I wont use and the code look like this:
protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
{
// Define the initial and final coordinates of the panel
SharpDX.Vector2 startPoint = new SharpDX.Vector2(ChartPanel.X, ChartPanel.Y);
SharpDX.Vector2 endPoint = new SharpDX.Vector2(ChartPanel.X + ChartPanel.W, ChartPanel.Y + ChartPanel.H);
// Width, height, and center of the chart
float width = endPoint.X - startPoint.X;
float height = endPoint.Y - startPoint.Y;
SharpDX.Vector2 center = (startPoint + endPoint) / 2;
if (!IsInHitTest)
{
// Convert WPF brushes to SharpDX resources
SharpDX.Direct2D1.Brush smallAreaBrushDx = smallAreaBrush.ToDxBrush(RenderTarget);
SharpDX.Direct2D1.Brush textBrushDx = textBrush.ToDxBrush(RenderTarget);
#region Rendering of the draws
// Define the format and layout of the text
SharpDX.DirectWrite.TextFormat textFormat2 = new SharpDX.DirectWrite.TextFormat(
NinjaTrader.Core.Globals.DirectWriteFactory,
"Century Gothic",
FontWeight.Bold,
FontStyle.Italic,
32f
);
SharpDX.DirectWrite.TextLayout textLayout2 = new SharpDX.DirectWrite.TextLayout(
NinjaTrader.Core.Globals.DirectWriteFactory,
NinjaTrader.Custom.Resource.SampleCustomPlotLowerRightCorner,
textFormat2,
400,
textFormat2.FontSize
);
// Define the coordinates for the text in the lower-right corner
SharpDX.Vector2 lowerTextPoint = new SharpDX.Vector2(
ChartPanel.W - textLayout2.Metrics.Width - 5,
ChartPanel.Y + (ChartPanel.H - textLayout2.Metrics.Height)
);
// Define the rectangle for the text
SharpDX.RectangleF rect1 = new SharpDX.RectangleF(
lowerTextPoint.X,
lowerTextPoint.Y,
textLayout2.Metrics.Width,
textLayout2.Metrics.Height
);
// Render the rectangle and text
RenderTarget.FillRectangle(rect1, smallAreaBrushDx);
RenderTarget.DrawRectangle(rect1, smallAreaBrushDx, 2);
RenderTarget.DrawTextLayout(lowerTextPoint, textLayout2, textBrushDx, SharpDX.Direct2D1.DrawTextOptions.NoSnap);
#endregion
// Release SharpDX resources
smallAreaBrushDx.Dispose();
textBrushDx.Dispose();
textFormat2.Dispose();
textLayout2.Dispose();
}
}
they are 3 blocks. I am thinking that I should adapt no just the rectangule of the onrender... also the text, is it okay? is it possible? how?
Thanks!

Comment