Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SharpDX Object Auto Clipping

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

    SharpDX Object Auto Clipping

    Hi,

    If I draw a partially off the screen object using SharpDX, will NT8 automatically clip the unseen parts for me? or will they just be leaved unhandled outside of the viewable region which will introduce performance issues for later?

    Code:
    protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
    {
        base.OnRender(chartControl, chartScale);
        
        // Create brush for the line
        SharpDX.Direct2D1.SolidColorBrush customDXBrush = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.DodgerBlue);
        
        // Purposely crate an partially off the screen line
        SharpDX.Vector2 startPoint = new SharpDX.Vector2(ChartPanel.X - 20, ChartPanel.Y - 20);
        SharpDX.Vector2 endPoint = new SharpDX.Vector2(ChartPanel.X + ChartPanel.W + 20, ChartPanel.Y + ChartPanel.H + 20);
        RenderTarget.DrawLine(startPoint, endPoint, customDXBrush, 2);  
        
        // Dispose
        customDXBrush.Dispose();
    }​
    Last edited by Curerious; 04-18-2025, 08:57 AM.

    #2
    Hello Curerious,

    That will be clipped as its outside the rendered area but it would be best to try and render within the panel for performance. If you need to extend a line to the edge of the panel you can reference the panel coordinates and its with and height to know the rendering area.

    Comment


      #3
      Hey Jesse

      Thanks for answering. However, coming from the below post and here's a quote from one of your Vendor's, QuantKey_Bruce which is also an knowledgeable technician, claimed the following:

      I would recommend you let the library handle it, rather than calculating the intercepts at the edges of the screen and just drawing on the screen, because the library already has this code in it, and for you to recreate it is a waste of your time (and even CPU time, because the library has to check anyway after you've checked). For that matter, you could elect to skip the checks above also, but they're so easy to check for, I tend to go ahead and rule those out before they hit the library.

      So I am wondering, which way is more resource efficient? Or it really depends on my coding skills? (So if I really sucks at coding algorithms then don't even bother to clip it on my own)
      Last edited by Curerious; 04-18-2025, 11:37 AM.

      Comment


        #4
        Hello Curerious,

        It is not a waste of time to calculate your own specific endpoints. For example the ray tool which extends to the edge of the screen has specific logic in it to calculate the line value to the edge of the screen as a projection which is the best way to approach that task.

        If you have to have some value off screen you should likely limit it to the panel edge because that value is known.You can use C# method Math.Max to constrain a value. There is no reason to let the platform handle it when its a out of range value, if you can make sure its in range that is the better way to approach a programming goal to avoid any errors down the line.

        Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.


        You can reference the properties on this page to know the X/Y and Width/Height so you can know the exact edges of the panel in any direction.

        Comment


          #5
          If you have to have some value off screen you should likely limit it to the panel edge because that value is known.You can use C# method Math.Max to constrain a value.
          I don't think is that easy, I think in that case I would have to do the following (unless you have some better algorithms) :
          1. calculate the line first (y=mx+b and all its x,y coordinates)
          2. determine which part is out of screen
          3. use min,max to manually clip out the "out of bound" x,y coordinates
          4. find out the "at bound" x,y coordinates, input it into SharpDX and let it recalculate the line and paint it.

          I don't know how the platform will handle it, but I think they will write a better algorithm than I do? But you are correct, it is something for me to think about.
          Last edited by Curerious; 04-18-2025, 12:46 PM.

          Comment


            #6
            Hello Curerious,

            If the line is out of the screen you can just use the screens bounds like the X + W to get the right side edge if that was the right side. You would extend the line to the X point of X + W and then use whatever your calculated y value is. That would just require checking if your calculated X is greater than the panel edge X, if so just use the panel edge X in place of it. If you are trying to do a projection like the ray tool you could look at the logic used for that which handles pointing at any edge of the screen depending on the 2 anchors locations.

            Comment


              #7
              Thank you Jesse! I will look into the ray tool for reference.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              557 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              324 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              101 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              545 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              547 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X