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!
See more
See less

Partner 728x90

Collapse

Can't set the reading direction of textLayout

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Can't set the reading direction of textLayout

    Can't set the reading direction of textLayout as no sample is provided.

    Code:
                // 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

    #2
    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;
    Please let me know if I can be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      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


        #4
        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


          #5
          Are you saying then that there's currently no way of rendering text vertically to the chart window?

          Comment


            #6
            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 Files
            JimNinjaTrader Customer Service

            Comment


              #7
              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


                #8
                Ok. I understand this now. The vector statements need to be synchronized then the positioning is controllable.

                Comment


                  #9
                  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 xiinteractive, 04-09-2024, 08:08 AM
                  5 responses
                  13 views
                  0 likes
                  Last Post NinjaTrader_Erick  
                  Started by swestendorf, Today, 11:14 AM
                  2 responses
                  5 views
                  0 likes
                  Last Post NinjaTrader_Kimberly  
                  Started by Mupulen, Today, 11:26 AM
                  0 responses
                  2 views
                  0 likes
                  Last Post Mupulen
                  by Mupulen
                   
                  Started by Sparkyboy, Today, 10:57 AM
                  1 response
                  6 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by TheMarlin801, 10-13-2020, 01:40 AM
                  21 responses
                  3,918 views
                  0 likes
                  Last Post Bidder
                  by Bidder
                   
                  Working...
                  X