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

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.


          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 = "[COLOR=Red]Cool Name[/COLOR]", GroupName = "NinjaScriptGeneral", Order = 1)]

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Sparkyboy, Today, 10:57 AM
                0 responses
                1 view
                0 likes
                Last Post Sparkyboy  
                Started by TheMarlin801, 10-13-2020, 01:40 AM
                21 responses
                3,916 views
                0 likes
                Last Post Bidder
                by Bidder
                 
                Started by timmbbo, 07-05-2023, 10:21 PM
                3 responses
                152 views
                0 likes
                Last Post grayfrog  
                Started by Lumbeezl, 01-11-2022, 06:50 PM
                30 responses
                809 views
                1 like
                Last Post grayfrog  
                Started by xiinteractive, 04-09-2024, 08:08 AM
                3 responses
                11 views
                0 likes
                Last Post NinjaTrader_Erick  
                Working...
                X