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

Multiple Brushes in OnRenderTargetChanged()

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

    Multiple Brushes in OnRenderTargetChanged()

    I am trying to understand brush concepts and I am looking at the documentation for OnRenderTargetChange() which gives this example:

    Code:
    public override void OnRenderTargetChanged()
    {
      // if dxBrush exists on first render target change, dispose of it
      if (dxBrush != null)
      {
        dxBrush.Dispose();
      }
     
      // recalculate dxBrush from value caluled in OnBarUpdated when RenderTarget is recreated
      if (RenderTarget != null)
        dxBrush = brushColor.ToDxBrush(RenderTarget);
    }
    My question is, do I reproduce this code for each brush like this:

    Code:
    public override void OnRenderTargetChanged()
    {
      //first brush
      if (dxBrush != null)  { dxBrush.Dispose(); }
      if (RenderTarget != null){dxBrush = brushColor.ToDxBrush(RenderTarget);}
    
        //second brush
      if (dxBrush2 != null)  { dxBrush2.Dispose(); }
      if (RenderTarget != null){dxBrush2 = brushColor2.ToDxBrush(RenderTarget);}
    
      //third brush
      if (dxBrush3 != null)  { dxBrush3.Dispose(); }
      if (RenderTarget != null){dxBrush3 = brushColor3.ToDxBrush(RenderTarget);}
    }
    Is this a common approach? Any pitfalls that have to do with the order of these?
    Last edited by swcooke; 06-15-2018, 09:47 AM.

    #2
    Hello swcooke,

    Thank you for the post.

    Yes, this is pretty standard and really shouldn't have any pitfalls. The problems would come when not correctly recreating brushes and you end up trying to use invalid objects. Recreating the brushes when the render target changes is needed so this type of logic is suggested to be used.

    I do see you are using the same variable for each line of syntax in your sample unless that was intended:
    Code:
    [B]brushColor[/B].ToDxBrush(RenderTarget);
    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks for pointing that out. I have edited my post and fixed that. One last question. Can you confirm that the order of each of these does not matter?

      Comment


        #4
        Hello swcooke,

        Yes, the order should not matter, mainly you want to include objects that do need to be recreated in this override. You can make the order inside of the method however it makes logical sense and looks good to you.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by kevinenergy, 02-17-2023, 12:42 PM
        115 responses
        2,699 views
        1 like
        Last Post kevinenergy  
        Started by prdecast, Today, 06:07 AM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by Christopher_R, Today, 12:29 AM
        1 response
        14 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by chartchart, 05-19-2021, 04:14 PM
        3 responses
        577 views
        1 like
        Last Post NinjaTrader_Gaby  
        Started by bsbisme, Yesterday, 02:08 PM
        1 response
        15 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Working...
        X