• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Setting SharpDX colors from the UI

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

    Setting SharpDX colors from the UI

    I have added the following to an OnRender() block to set a color:
    Code:
    SharpDX.Direct2D1.SolidColorBrush customDXBrush = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.DodgerBlue);
    This works fine but how can I set the color from the UI? This page does not explain it and I would think it would but I cannot locate the answer.

    #2
    Hello swcooke,

    Thank you for the post.

    To make this into an input, you would need to replace the SharpDX.Color.DodgerBlue with a user Input so that it is variable.

    For this question, I would suggest reviewing the indicator "SampleCustomRender" that comes with NinjaTrader. That indicator has a few color inputs already which you could just copy and paste into your script if needed. This also explains how to use those inputs with rendering so it would be a good sample for this concept specifically.


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

    Comment


      #3
      In the Sample Custom Render the comments advise against using ToDxBrush() but the code still seems to demonstrate drawing using it. Since the comments and the doc's advise against using ToDxBrush() but the examples do, can you give me an example of replacing the SharpDX.Color.DodgerBlue with a user Input so that it is variable as you have suggested?

      Comment


        #4
        You misunderstand. Of course you can use the DX extensions to convert your brushes. The issue really is: where is the most efficient place to do this? The answer is: in OnRenderTargetChanged().

        Comment


          #5
          Hello swcooke,

          I had only used your syntax as a description of what needs to be modified, I would suggest using the syntax the sample shows.

          The helpguide just suggests against using this when it is not needed, the examples show static colors which do not change so recreating the brush over and over would not be useful there. For a variable input, you would need to create the brush so I would suggest using the same syntax as the sample shows.

          You can also use the OnRenderTargetChanged override to create brushes efficiently if you have a lot that needs to be created.
          https://ninjatrader.com/support/help...rTargetChanged

          Please let me know if I may be of further assistance.
          JesseNinjaTrader Customer Service

          Comment


            #6
            Not sure what it is you are doing but here is a snippet you can use to set up your user input brushes:

            In you global variables:
            Code:
                    private Brush areaBrush;
                    private SharpDX.Direct2D1.Brush areaBrushDx;
                    private int areaOpacity;
            In State == State.Defaults
            Code:
                    AreaColor = Brushes.Blue;
                    AreaOpacity = 50;
            In OnRenderTargetChanged():
            Code:
                    public override void OnRenderTargetChanged()
                    {
                        if (areaBrushDx != null)
                            areaBrushDx.Dispose();
            
                        if (RenderTarget != null)
                        {
                            try
                            {
                                areaBrushDx = areaBrush.ToDxBrush(RenderTarget);
                            }
                            catch (Exception e) { }
                        }
                    }
            In Properties:
            Code:
                    [XmlIgnore]
                    [Display(Name = "NinjaScript Text Brush", GroupName = "NinjaScriptGeneral", Order = 0)]
                    public Brush AreaColor
                    {
                        get { return areaBrush; }
                        set
                        {
                            areaBrush = value;
                            if (areaBrush != null)
                            {
                                if (areaBrush.IsFrozen)
                                    areaBrush = areaBrush.Clone();
                                areaBrush.Opacity = areaOpacity / 100d;
                                areaBrush.Freeze();
                            }
                        }
                    }
            
                    [Browsable(false)]
                    public string AreaColorSerialize
                    {
                        get { return Serialize.BrushToString(AreaColor); }
                        set { AreaColor = Serialize.StringToBrush(value); }
                    }
            
                    [Range(0, 100)]
                    [Display(Name = "NinjaScriptDrawingToolAreaOpacity", GroupName = "NinjaScriptGeneral", Order = 1)]
                    public int AreaOpacity
                    {
                        get { return areaOpacity; }
                        set
                        {
                            areaOpacity = Math.Max(0, Math.Min(100, value));
                            if (areaBrush != null)
                            {
                                if (areaBrush.IsFrozen)
                                    areaBrush = areaBrush.Clone();
                                areaBrush.Opacity = areaOpacity / 100d;
                                areaBrush.Freeze();
                            }
                        }
                    }
            Hope this helps.

            Comment


              #7
              Thank you so much. That explains a lot. One follow up question, in the case of this line:
              Code:
              [Display(Name = "CoolName", GroupName = "NinjaScriptGeneral", Order = 1)]
              How can I get the label to display in the UI as "Cool Name" instead of "CoolName?"

              Comment


                #8
                Originally posted by swcooke View Post
                Thank you so much. That explains a lot. One follow up question, in the case of this line:
                Code:
                [Display(Name = "CoolName", GroupName = "NinjaScriptGeneral", Order = 1)]
                How can I get the label to display in the UI as "Cool Name" instead of "CoolName?"
                Did you try this?

                Code:
                [Display(Name = "Cool Name", GroupName = "NinjaScriptGeneral", Order = 1)]

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by E-Viper87, Today, 02:50 PM
                1 response
                4 views
                0 likes
                Last Post NinjaTrader_PatrickG  
                Started by diddyp1990, Today, 01:28 PM
                1 response
                11 views
                0 likes
                Last Post NinjaTrader_Paul  
                Started by dariuszszyc, Today, 09:08 AM
                8 responses
                32 views
                0 likes
                Last Post Nicolas
                by Nicolas
                 
                Started by pman777, Today, 12:08 PM
                2 responses
                6 views
                0 likes
                Last Post pman777
                by pman777
                 
                Started by Sadat, Today, 09:09 AM
                5 responses
                22 views
                0 likes
                Last Post NinjaTrader_JoshG  
                Working...
                X