I'm trying to nest a text to a manual hand moving line (in the center of the line), but when i'm trying to translate / move the text on code i'm getting unexpected results on screen.
What I'm doing first is getting the angle of the line and then rotate the text. After, I reset the rotation.
My actual code is:
SharpDX.Direct2D1.Brush textBrushDx;
textBrushDx = textBrush.ToDxBrush(RenderTarget);
NinjaTrader.Gui.Tools.SimpleFont simpleFont = chartControl.Properties.LabelFont ?? new NinjaTrader.Gui.Tools.SimpleFont("Arial", 16);
SharpDX.DirectWrite.TextFormat textFormat1 = simpleFont.ToDirectWriteTextFormat();
SharpDX.DirectWrite.TextFormat textFormat2 = Font.ToDirectWriteTextFormat();
SharpDX.DirectWrite.TextLayout textLayout = new SharpDX.DirectWrite.TextLayout(NinjaTrader.Core.Globals.DirectWriteFactory, text, textFormat2, 400, textFormat1.FontSize);
textFormat1.TextAlignment = SharpDX.DirectWrite.TextAlignment.Center;
textFormat2.TextAlignment = SharpDX.DirectWrite.TextAlignment.Center;
double offsetX = 0;
double offsetY = 0;
Point textPoint = new Point();
textPoint.X = ((startPointAdjusted.X + endPointAdjusted.X) / 2);
textPoint.Y = ((startPointAdjusted.Y + endPointAdjusted.Y) / 2);
// Rotate and draw the text
float anguloLineaRecta = (float)GetAngle(startPoint.X, startPoint.Y, endPoint.X, endPoint.Y);
SharpDX.Vector2 puntoTextoCentrado = new SharpDX.Vector2((float)(textPoint.X + offsetX), (float)(textPoint.Y + offsetY));
RenderTarget.Transform = Matrix3x2.Rotation((float)(Math.PI * anguloLineaRecta) / 180, puntoTextoCentrado);
RenderTarget.DrawTextLayout(puntoTextoCentrado, textLayout, textBrushDx, SharpDX.Direct2D1.DrawTextOptions.NoSnap);
RenderTarget.Transform = Matrix3x2.Identity;
RenderTarget.Transform = Matrix3x2.Rotation((float)(Math.PI * anguloLineaRecta) / 180, puntoTextoCentrado) * Matrix3x2.Translation(textLayout.Metrics.Width / 2, textLayout.Metrics.Height / 2);
I uploaded 3 images: Text without moving its position, when i tried translate and what i want.
Thanks.

Comment