Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Use OnRender with percentage and not with pixels

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

    Use OnRender with percentage and not with pixels

    Hi,

    I am wondering If it is possible use the draws that I make with OnRender in percentage of the chart? Because If I move the dimensions of the chart, it doesnt adapt it

    I use like a base code the SampleCustomRender, I cut what I wont use and the code look like this:

    Code:
    protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
        {
            // Define the initial and final coordinates of the panel
            SharpDX.Vector2 startPoint = new SharpDX.Vector2(ChartPanel.X, ChartPanel.Y);
            SharpDX.Vector2 endPoint = new SharpDX.Vector2(ChartPanel.X + ChartPanel.W, ChartPanel.Y + ChartPanel.H);
    
            // Width, height, and center of the chart
            float width = endPoint.X - startPoint.X;
            float height = endPoint.Y - startPoint.Y;
            SharpDX.Vector2 center = (startPoint + endPoint) / 2;
    
            if (!IsInHitTest)
            {
                // Convert WPF brushes to SharpDX resources
                SharpDX.Direct2D1.Brush smallAreaBrushDx = smallAreaBrush.ToDxBrush(RenderTarget);
                SharpDX.Direct2D1.Brush textBrushDx = textBrush.ToDxBrush(RenderTarget);
    
                #region Rendering of the draws
    
                // Define the format and layout of the text
                SharpDX.DirectWrite.TextFormat textFormat2 = new SharpDX.DirectWrite.TextFormat(
                    NinjaTrader.Core.Globals.DirectWriteFactory,
                    "Century Gothic",
                    FontWeight.Bold,
                    FontStyle.Italic,
                    32f
                );
                SharpDX.DirectWrite.TextLayout textLayout2 = new SharpDX.DirectWrite.TextLayout(
                    NinjaTrader.Core.Globals.DirectWriteFactory,
                    NinjaTrader.Custom.Resource.SampleCustomPlotLowerRightCorner,
                    textFormat2,
                    400,
                    textFormat2.FontSize
                );
    
                // Define the coordinates for the text in the lower-right corner
                SharpDX.Vector2 lowerTextPoint = new SharpDX.Vector2(
                    ChartPanel.W - textLayout2.Metrics.Width - 5,
                    ChartPanel.Y + (ChartPanel.H - textLayout2.Metrics.Height)
                );
    
                // Define the rectangle for the text
                SharpDX.RectangleF rect1 = new SharpDX.RectangleF(
                    lowerTextPoint.X,
                    lowerTextPoint.Y,
                    textLayout2.Metrics.Width,
                    textLayout2.Metrics.Height
                );
    
                // Render the rectangle and text
                RenderTarget.FillRectangle(rect1, smallAreaBrushDx);
                RenderTarget.DrawRectangle(rect1, smallAreaBrushDx, 2);
                RenderTarget.DrawTextLayout(lowerTextPoint, textLayout2, textBrushDx, SharpDX.Direct2D1.DrawTextOptions.NoSnap);
    
                #endregion
    
                // Release SharpDX resources
                smallAreaBrushDx.Dispose();
                textBrushDx.Dispose();
                textFormat2.Dispose();
                textLayout2.Dispose();
            }
        }
    ​
    For example when I use the Draw.Text Fixed this can adapt it, something like this I am trying to use but also I want to be avaible to see like this image

    Click image for larger version

Name:	image.png
Views:	148
Size:	24.8 KB
ID:	1327284
    they are 3 blocks. I am thinking that I should adapt no just the rectangule of the onrender... also the text, is it okay? is it possible? how?

    Thanks!

    #2
    Hello FaaZer,

    You would have to use math to find the percents of those sections by using the panels width. For example if you divide the panel width by 3 you would get the maximum width of 1/3 of the panel.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    558 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