• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Use of LineMetrics

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

    Use of LineMetrics

    Hi, I'm trying to place lines of 'random' length text next to each other horizontally. Each piece of text is a different color so (I assume) it can't be one text object. So I'm trying to work out the width of each piece of text so that I can place the next text without overlapping the previous one. I'm assuming I need to use 'LineMetrics' but I can't find any examples. I'd appreciate an example. So in my example code below, how do I set textOffset1, 2 and 3 automatically? Thanks

    Code:
            protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
            {
                base.OnRender(chartControl, chartScale);
    
                // define the point for the text to render
                SharpDX.Vector2 startPoint = new SharpDX.Vector2(ChartPanel.X, ChartPanel.Y + 20);
    
                // construct the text format with desired font family and size
                SharpDX.DirectWrite.TextFormat textFormat = new SharpDX.DirectWrite.TextFormat(Core.Globals.DirectWriteFactory, "Arial", 12);
    
                int textOffset1 = 5;
                int textOffset2 = 25;
                int textOffset3 = 45;
    
                // construct the rectangleF struct to describe the position and size the text
                SharpDX.RectangleF rectangleF1 = new SharpDX.RectangleF(startPoint.X + textOffset1, startPoint.Y, ChartPanel.W, ChartPanel.H);
                SharpDX.RectangleF rectangleF2 = new SharpDX.RectangleF(startPoint.X + textOffset2, startPoint.Y, ChartPanel.W, ChartPanel.H);
                SharpDX.RectangleF rectangleF3 = new SharpDX.RectangleF(startPoint.X + textOffset3, startPoint.Y, ChartPanel.W, ChartPanel.H);
    
    
                // define the brush used for the text
                //SharpDX.Direct2D1.SolidColorBrush customDXBrush1 = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.Blue);
                //SharpDX.Direct2D1.SolidColorBrush customDXBrush2 = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.Red);
                //SharpDX.Direct2D1.SolidColorBrush customDXBrush3 = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.Yellow);
    
                // execute the render target text command with desired values
                RenderTarget.DrawText(myText1, textFormat, rectangleF1, customDXBrush1);
                RenderTarget.DrawText(myText2, textFormat, rectangleF2, customDXBrush1);
                RenderTarget.DrawText(myText3, textFormat, rectangleF3, customDXBrush1);
    
    
                // always dispose of textFormat when finished
                textFormat.Dispose();
    
                // always dipose of brush when finished
                customDXBrush1.Dispose();
                customDXBrush2.Dispose();
                customDXBrush3.Dispose();
            }

    #2
    Hello bubblegum,

    Thank you for your post.

    You could use TextLayout and TextLayout.Metrics. This section of the help guide should point you in the correct direction:

    https://ninjatrader.com/support/help...XTextRendering

    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 ct_fx, Today, 05:14 AM
    0 responses
    4 views
    0 likes
    Last Post ct_fx
    by ct_fx
     
    Started by Beauregard, Today, 04:36 AM
    0 responses
    5 views
    0 likes
    Last Post Beauregard  
    Started by fx.practic, Today, 04:34 AM
    0 responses
    5 views
    0 likes
    Last Post fx.practic  
    Started by thomaspartyof10, Today, 02:33 AM
    0 responses
    7 views
    0 likes
    Last Post thomaspartyof10  
    Started by ArmKnuckle, Today, 01:59 AM
    0 responses
    12 views
    0 likes
    Last Post ArmKnuckle  
    Working...
    X