Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Clarification on redrawing objects in NinjaTrader using SharpDX

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

    #16
    The second is that the line is partially on the screen. As an example, it starts left of the screen and ends on the screen or off the screen to the right. In this case, I would recommend you let the library handle it
    QuantKey_Bruce
    So is this how you will draw a line that’s partially off the screen using SharpDX? Or you have a better way to draw?
    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();
            }​
    The reason I am asking these is because you claimed that there a way for us to draw outside of the viewable region using SharpDX, and I don't know any of that, hence I am curious on how you will be able to accomplish such a thing. (By using negative coordinate as I demonstrated above or other methods..)

    Yes, that's the basic idea. You COULD try to deduce which pixels of the line are visible (clipping) and I'm not saying you should or shouldn't but I will say most people don't. The time it takes SharpDX to figure out which pixels are on the screen is minimal, and if you try to do it yourself there's a much higher chance of introducing bugs, so your starting stance should be to let the library handle it and only try to do this yourself if you must - for instance, if you have some special case where the library's performance is the limiting factor (this is highly unlikely).
    Last edited by Curerious; 04-18-2025, 09:52 AM.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    574 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    333 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
    553 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    551 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X