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

I had it working and now it doesn't!

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

    I had it working and now it doesn't!

    Code:
    SharpDX.Direct2D1.AntialiasMode oldAntialiasMode = RenderTarget.AntialiasMode;
    RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.Aliased;
    
    blockstring.Append(String.Format("({0})", "Hello"));
    
    SharpDX.Direct2D1.Brush textBrushDx;
    Brush textBrush = ChartControl.Properties.AxisPen.Brush;
    
    textBrushDx = textBrush.ToDxBrush(RenderTarget);
    
    
    SharpDX.DirectWrite.TextFormat textFormat1 = subFont.ToDirectWriteTextFormat();
    // blockstring.Clear();
    SharpDX.DirectWrite.TextLayout textLayout1 = new SharpDX.DirectWrite.TextLayout(NinjaTrader.Core.Gl obals.DirectWriteFactory,
    blockstring.ToString(), textFormat1, ChartPanel.X + ChartPanel.W,
    textFormat1.FontSize);//this binds it to the ChartPanel space ONLY
    
    SharpDX.Vector2 textPoint = new SharpDX.Vector2(ChartPanel.X-30 + (ChartPanel.W/2),ChartPanel.Y );
    
    RenderTarget.DrawTextLayout(textPoint, textLayout1, textBrushDx, SharpDX.Direct2D1.DrawTextOptions.NoSnap);
    
    
    textLayout1.Dispose();
    textBrushDx.Dispose();
    textFormat1.Dispose();
    RenderTarget.AntialiasMode = oldAntialiasMode;
    Spent 2 hours on this - had it working and now just can't get it to display - please tell me where I am going wrong.

    thanks
    Last edited by Mindset; 10-09-2020, 03:19 AM. Reason: Found the answer. I had a condition above it that was incorrect

    #2
    Hello Mindset,

    Thanks for your post.

    The script may not have a string in blockstring that would be visible, or the brush that is being used is transparent.

    You can hard code a brush and a string in your code to verify that the code is working properly when there is a definite string and brush given.

    For example, you could check your code with a hard coded brush and string as follows:

    Code:
    protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
    {
        SharpDX.Direct2D1.AntialiasMode oldAntialiasMode = RenderTarget.AntialiasMode;
        RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.Aliased;
    
        SharpDX.Direct2D1.Brush textBrushDx;
        System.Windows.Media.Brush textBrush = Brushes.Orange;
    
        textBrushDx = textBrush.ToDxBrush(RenderTarget);
    
    
        SharpDX.DirectWrite.TextFormat textFormat1 = ChartControl.Properties.LabelFont.ToDirectWriteTex tFormat();
    
        SharpDX.DirectWrite.TextLayout textLayout1 = new SharpDX.DirectWrite.TextLayout(NinjaTrader.Core.Gl obals.DirectWriteFactory,
        "Test", textFormat1, ChartPanel.X + ChartPanel.W,
        textFormat1.FontSize);//this binds it to the ChartPanel space ONLY
    
        SharpDX.Vector2 textPoint = new SharpDX.Vector2(ChartPanel.X-30 + (ChartPanel.W/2),ChartPanel.Y );
    
        RenderTarget.DrawTextLayout(textPoint, textLayout1, textBrushDx, SharpDX.Direct2D1.DrawTextOptions.NoSnap);
    
    
        textLayout1.Dispose();
        textBrushDx.Dispose();
        textFormat1.Dispose();
        RenderTarget.AntialiasMode = oldAntialiasMode;
    }
    We look forward to assisting.
    JimNinjaTrader Customer Service

    Comment


      #3
      Thanks Jim
      I am trying to get different texts with different colours.
      Where am I going wrong here - looks simple enough?

      Code:
      if (ChartBars == null)
      return;
      int txtHeight = (int)subFont.TextFormatHeight; // (int)graphics.MeasureString("X", txtFont).Heig
      
      //Anti alias lines
      //Append to stringbuilder
      // Declare BrushDx
      //place text Brush to DXBrush
      //textlayout declaration
      //Vector 2 text point
      //Dispose
      
      ChartPanel panel = chartControl.ChartPanels[chartScale.PanelIndex];
      SharpDX.Direct2D1.AntialiasMode oldAntialiasMode = RenderTarget.AntialiasMode;
      RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.Aliased;
      
      
      
      SharpDX.Direct2D1.Brush textBrushDxW;
      SharpDX.Direct2D1.Brush textBrushDxG;
      Brush textBrush = Brushes.White;//Brushes.AliceBlue;//ChartControl.Properties.AxisPen.Brush;
      Brush textBrushGreen = Brushes.Chartreuse;
      // areaBrushDx = areaBrush.ToDxBrush(RenderTarget);
      textBrushDxW = textBrush.ToDxBrush(RenderTarget);
      textBrushDxG = textBrush.ToDxBrush(RenderTarget);
      
      
      SharpDX.DirectWrite.TextFormat textFormat1 = subFont.ToDirectWriteTextFormat();
      
      ///White
      SharpDX.DirectWrite.TextLayout textLayoutwhite = new SharpDX.DirectWrite.TextLayout(NinjaTrader.Core.Gl obals.DirectWriteFactory,
      whitestring.ToString(), textFormat1, ChartPanel.X + ChartPanel.W,
      textFormat1.FontSize);//this binds it to the ChartPanel space ONLY
      
      ///Green
      SharpDX.DirectWrite.TextLayout textLayoutgreen = new SharpDX.DirectWrite.TextLayout(NinjaTrader.Core.Gl obals.DirectWriteFactory,
      greenstring.ToString(), textFormat1, ChartPanel.X + ChartPanel.W,
      textFormat1.FontSize);//this binds it to the ChartPanel space ONLY
      
      
      SharpDX.Vector2 textPoint = new SharpDX.Vector2(ChartPanel.X-30 + (ChartPanel.W/2),ChartPanel.Y );
      
      RenderTarget.DrawTextLayout(textPoint, textLayoutwhite, textBrushDxW, SharpDX.Direct2D1.DrawTextOptions.NoSnap);
      SharpDX.Vector2 textPoint2 = new SharpDX.Vector2(ChartPanel.X-30 + (ChartPanel.W/2),ChartPanel.Y+txtHeight );
      RenderTarget.DrawTextLayout(textPoint2, textLayoutgreen, textBrushDxG, SharpDX.Direct2D1.DrawTextOptions.NoSnap);
      
      
      textLayoutwhite.Dispose();
      textLayoutgreen.Dispose();
      textBrushDxW.Dispose();
      textBrushDxG.Dispose();
      
      //areaBrushDx.Dispose();
      textFormat1.Dispose();
      RenderTarget.AntialiasMode = oldAntialiasMode;

      Comment


        #4
        Oh I forgot to change the Brush - Jeez!!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CortexZenUSA, Today, 12:53 AM
        0 responses
        2 views
        0 likes
        Last Post CortexZenUSA  
        Started by CortexZenUSA, Today, 12:46 AM
        0 responses
        1 view
        0 likes
        Last Post CortexZenUSA  
        Started by usazencortex, Today, 12:43 AM
        0 responses
        5 views
        0 likes
        Last Post usazencortex  
        Started by sidlercom80, 10-28-2023, 08:49 AM
        168 responses
        2,266 views
        0 likes
        Last Post sidlercom80  
        Started by Barry Milan, Yesterday, 10:35 PM
        3 responses
        13 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X