// define the point for the text to render SharpDX.Vector2 startPoint = new SharpDX.Vector2(ChartPanel.W * 0.5f, ChartPanel.H * 0.5f); // construct the text format with desired font family and size SharpDX.DirectWrite.TextFormat textFormat = new SharpDX.DirectWrite.TextFormat(Core.Globals.DirectWriteFactory, "Arial", 20); SharpDX.DirectWrite.TextLayout textLayout = new SharpDX.DirectWrite.TextLayout (NinjaTrader.Core.Globals.DirectWriteFactory, "text to render", textFormat, ChartPanel.W, ChartPanel.H); textLayout.ReadingDirection = ReadingDirection.DWRITE_READING_DIRECTION_BOTTOM_TO_TOP; // define the brush used for the text using (SharpDX.Direct2D1.SolidColorBrush customDXBrush = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.DimGray)) { RenderTarget.DrawTextLayout(startPoint, textLayout, customDXBrush); } //RenderTarget.Transform = Matrix3x2.Rotation(0.5f * 3.14159265359f); // execute the render target text command with desired values //RenderTarget.Transform = Matrix3x2.Rotation(1.5f * 3.14159265359f); textLayout.Dispose(); // always dispose of textFormat when finished textFormat.Dispose(); // always dipose of brush when finished
Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
Can't set the reading direction of textLayout
Collapse
X
-
Can't set the reading direction of textLayout
Can't set the reading direction of textLayout as no sample is provided.
Code:Tags: None
-
Hello bkinvent,
Thanks for opening thread.
You will want to make sure the SharpDX.DirectWrite namespace is included to recognize the ReadingDirection enum. From there, you can use LeftToRight and RightToLeft as listed in the help documentation.
Code:using SharpDX.DirectWrite; ... textLayout1.ReadingDirection = ReadingDirection.LeftToRight;
JimNinjaTrader Customer Service
-
Hi,
Thank you for responding, is it possible to re-orientate the SharpDX text object so that it reads vertically? The C++ version of Directx 11.2 has this enum: DWRITE_READING_DIRECTION_BOTTOM_TO_TOP; but I am not sure if it's been ported to SharpDX?
If not, could you please show how I can use the transform matrix3x2 to first save the initial orientation then rotate just the textlayout by 90 degrees and then restore the original orientation so that rest of the chart is unaffected by the transform matrix?
Is there an easier way of outputting vertical text to the chart window?
Comment
-
Hello bkinvent,
As the requirement for NinjaTrader 8 is DirectX 10 and we still target Windows 7 PC's, DWRITE_READING_DIRECTION_TOP_TO_BOTTOM and DWRITE_READING_DIRECTION_BOTTOM_TO_TOP are unavailable.
I do not have any samples that I could share that demonstrate how you can transform matrices and rotate text in SharpDX. You may wish to view some Direct2D1 or DirectWrite samples that are shared elsewhere on the internet to get an idea on how this can be done in SharpDX.
I'm currently looking into this more on my end and will update this post with any more findings.
If there is anything else I can do to help out, please let me know.Last edited by NinjaTrader_Jim; 07-19-2017, 07:59 AM.JimNinjaTrader Customer Service
Comment
-
Hello bkinvent,
No, I wasn't stating it wasn't currently possible. At the time, I did not have any examples that could show how it could be done.
It would be possible by rotating the RenderTarget, drawing the text, and then rotating the RenderTarget back.
My colleague Jesse and I looked at this further and he came up with a sample that demonstrates how this can be done. I have added some comments and attached the script to this post.Attached FilesJimNinjaTrader Customer Service
- Likes 1
Comment
-
Hi Guys,
Cant seem to understand the positioning of this text layout on the chart.
Changing only the X value on the either of the vector statements below results in the text layout moving in both the X & Y directions.
Changing only the Y value on the either of the vector statements below results in the text layout moving in both the X & Y directions.
Docs not very helpful:
Code:// Rotate the RenderTarget by setting the Matrix3x2 Transform property // Matrix3x2.Rotation() will return a rotated Matrix3x2 based off of the angle specified, and the center point where you draw the object RenderTarget.Transform = Matrix3x2.Rotation(1.5708f, new[B] Vector2(100,100));[/B] // Draw the text on the rotated RenderTarget RenderTarget.DrawTextLayout(new [B]SharpDX.Vector2(100, 100)[/B], cachedTextLayout, tmpBrush, SharpDX.Direct2D1.DrawTextOptions.NoSnap);
Comment
-
Hello Bidder,
Thank you for your reply.
Basically the reason it moves regardless of which you modify is that you're either modifying the center point the text is being rotated around, or your're modifying the coordinate to draw the text and modifying either would cause the text to be moved to a different location.
There is the RenderTarget which we can think of as the canvas we are drawing on. When we rotate the RenderTarget by pi/2 radians, we essentially rotate the canvas 90 degrees.
Then we draw on that rotated canvas, so if we decrease the X coordinate for RenderTarget.DrawTextLayout, we are in fact moving it left on the canvas.
BUT, when we rotate back (set it to the identity matrix) that movement of the X coordinate is now moving upwards so you see it moving in both the X and Y directions.
Please let us know if we may be of further assistance to you.
Kate W.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by WHICKED, Today, 12:56 PM
|
1 response
8 views
0 likes
|
Last Post Today, 01:17 PM | ||
Started by cre8able, Today, 01:16 PM
|
0 responses
1 view
0 likes
|
Last Post
by cre8able
Today, 01:16 PM
|
||
Started by chbruno, 04-24-2024, 04:10 PM
|
2 responses
47 views
0 likes
|
Last Post
by chbruno
Today, 01:15 PM
|
||
Started by WHICKED, Today, 12:45 PM
|
1 response
11 views
0 likes
|
Last Post Today, 01:08 PM | ||
Started by samish18, Today, 01:01 PM
|
0 responses
5 views
0 likes
|
Last Post
by samish18
Today, 01:01 PM
|
Comment