Announcement

Collapse
No announcement yet.

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 DannyP96, 05-18-2026, 02:38 PM
        1 response
        85 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        143 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        83 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        256 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        334 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X