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

How to use the Current chart color pallet within RenderTarget.DrawTextLayout()

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

    How to use the Current chart color pallet within RenderTarget.DrawTextLayout()

    Please assist,

    I'm trying to re-use the chart color pallet in my, so I don't have to bother about whenever I use a white or a black chart the number will always be visible as I use the colors of the chart axis..

    Getting the color brush I found the "ChartControl.Properties.ChartText"
    ​Now I want to use this color in my "RenderTarget.DrawTextLayout()" and here I struggle...

    Code:
    // Snippet
    
    // Get the color of the Chart Text
    SharpDX.Direct2D1.Brush aapBrush = chartPanel.ChartControl.Properties.ChartText.ToDxBrush(RenderTarget);
    
    // Can't convert from Direct2D1 to SharpDX
    SharpDX.Direct2D1.SolidColorBrush customDXBrush = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, aapBrush);
    ​
    RenderTarget.DrawTextLayout(new SharpDX.Vector2((float)drawAtX, (float)(y - textFormat.FontSize / 2)), textLayout, customDXBrush, SharpDX.Direct2D1.DrawTextOptions.NoSnap);

    Now I'm hitting the wall of the conversion of the brush.. how to approach this? Or is there a much simpler way to use the current chart pallet in the DrawTextLayout function?

    UPDATE:
    The brutal version that is working is forcing in a cast but I hope it can be more elegant than this.
    Code:
    SharpDX.Direct2D1.SolidColorBrush customDXBrush = (SharpDX.Direct2D1.SolidColorBrush)ChartControl.Properties.ChartText.ToDxBrush(RenderTarget);
    Kind Regards,
    Wes​
    Last edited by Wessel; 03-24-2024, 08:06 AM.

    #2
    Hello Wessel,

    Do you absolutely need a sharpdx solidcolorbrush?

    Below is a link to User App Share script that uses DrawTextLayout but doesn't use a solid color brush.
    Simple script that adds a background watermark of the instrument symbol (and expiry if a future) to the chart. (Updated July 10th, 2018 ‐ The opacity needed to be casted as a double and divided by 100 to be between 0 and 1) (Update: August 24th, 2021 – Subtracted the ChartPanel.Y so indicator can be […]


    Just using the sharpdx brush should be sufficient.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you!

      Comment


        #4
        Instead of creating a new SolidColorBrush, you can directly use the brush returned by ToDxBrush(RenderTarget) as it should already be a SharpDX.Direct2D1.Brush, which is what DrawTextLayout() expects. Here's how you can modify your code: // Get the color of the Chart Text SharpDX.Direct2D1.Brush chartTextBrush = chartPanel.ChartControl.Properties.ChartText.ToDxB rush(RenderTarget); // Use the chart text color brush directly in DrawTextLayout RenderTarget.DrawTextLayout(new SharpDX.Vector2((float)drawAtX, (float)(y - textFormat.FontSize / 2)), textLayout, chartTextBrush, SharpDX.Direct2D1.DrawTextOptions.NoSnap);

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by fx.practic, 10-15-2013, 12:53 AM
        5 responses
        5,404 views
        0 likes
        Last Post Bidder
        by Bidder
         
        Started by Shai Samuel, 07-02-2022, 02:46 PM
        4 responses
        95 views
        0 likes
        Last Post Bidder
        by Bidder
         
        Started by DJ888, Yesterday, 10:57 PM
        0 responses
        7 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by MacDad, 02-25-2024, 11:48 PM
        7 responses
        159 views
        0 likes
        Last Post loganjarosz123  
        Started by Belfortbucks, Yesterday, 09:29 PM
        0 responses
        8 views
        0 likes
        Last Post Belfortbucks  
        Working...
        X