Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SharpDX.Color

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

    SharpDX.Color

    In the code:
    using(SharpDX,Direct2D1.SolidColorBrush dxBrush =
    new SharpDX.Direct2D1.SolidColorBrush(Render Target, SharpDX.Color.Blue));

    How would I set the color from a string such as "Blue" or "Systems.Window.Media.Colors Blue"

    Something like:
    SharpDX.Color = Color.Blue;

    I am having a hard time finding info on SharpDX.

    Thanks

    #2
    Hello TAJTrades,

    You could get this from a System.Windows.Media.Brush

    For example:

    SharpDX.Direct2D1.Brush myBrush = Brushes.Blue.ToDxBrush(RenderTarget);



    Also, see my example of using these efficiently.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Edit:
      I made an Indicator to simply things
      In the OnRender it is throwing errors CS1502 and CS1503 on the line using......

      I am trying to change the Help guide code from "SharpDX.Color.Blue" to "TestBrush.ToDxBrush(RenderTarget)". What am I doing wrong?

      PHP Code:
      public class TJBrushOnRenderTest Indicator
          
      {
              protected 
      override void OnStateChange()
              {
                  if (
      State == State.SetDefaults)
                  {
                      
      Description                                    = @"Enter the description for your new custom Indicator here.";
                      
      Name                                        "TJBrushOnRenderTest";
                      
      Calculate                                    Calculate.OnBarClose;
                      
      IsOverlay                                    true;
                      
      DisplayInDataBox                            true;
                      
      DrawOnPricePanel                            true;
                      
      DrawHorizontalGridLines                        true;
                      
      DrawVerticalGridLines                        true;
                      
      PaintPriceMarkers                            true;
                      
      ScaleJustification                            NinjaTrader.Gui.Chart.ScaleJustification.Right;
                      
      //Disable this property if your indicator requires custom values that cumulate with each new market data event. 
                      //See Help Guide for additional information.
                      
      IsSuspendedWhileInactive                    true;
                      
      TestBrush                    Brushes.Orange;
                  }
                  else if (
      State == State.Configure)
                  {
                  }
              }

              
              
              protected 
      override void OnRender(ChartControl chartControlChartScale chartScale)
              {
                  
                  
                  
                  
                  
      // implicitly recreate and dispose of brush on each render pass
                    
      using (SharpDX.Direct2D1.SolidColorBrush dxBrush = new SharpDX.Direct2D1.SolidColorBrush(RenderTargetTestBrush.ToDxBrush(RenderTarget)))
                    {
                      
      RenderTarget.FillRectangle(new SharpDX.RectangleF(100100100100), dxBrush);
                    }            
              }
                  
              
              
              
              protected 
      override void OnBarUpdate()
              {
                  
      //Add your custom indicator logic here.
              
      }

              
      #region Properties
              
      [NinjaScriptProperty]
              [
      XmlIgnore]
              [
      Display(Name="TestBrush"Description="TestBrush Description"Order=1GroupName="Parameters")]
              public 
      Brush TestBrush
              
      getset; }

              [
      Browsable(false)]
              public 
      string TestBrushSerializable
              
      {
                  
      get { return Serialize.BrushToString(TestBrush); }
                  
      set TestBrush Serialize.StringToBrush(value); }
              }            
              
      #endregion

          
      }

      Last edited by TAJTrades; 06-22-2017, 06:22 AM.

      Comment


        #4
        Hello TAJTrades,

        What does the error message say?

        The message is likely going to show you which line is causing the error.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          The error is on the line:
          using (SharpDX.Direct2D1.SolidColorBrush dxBrush = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, TestBrush.ToDxBrush(RenderTarget)))

          Error Messages:
          #1
          TJBrushOnRenderTest.cs,The best overloaded method match for 'SharpDX.Direct2D1.SolidColorBrush.SolidColorBrush (SharpDX.Direct2D1.RenderTarget SharpDX.Color4)' has some invalid arguments,CS1502,62,57,
          #2
          TJBrushOnRenderTest.cs,Argument 2: cannot convert from 'SharpDX.Direct2D1.Brush' to 'SharpDX.Color4',CS1503,62,109,

          So I am thinking the error happens trying to convert Brush TestBrush to ToDxBrush

          Comment


            #6
            Hello TAJTrades,

            I am not understanding what the using call is for..

            I unsure of how this will affect things.

            I am also unsure how you are trying to create a new SharpDX.Direct2D1.SolidColorBrush using a SharpDX.Direct2D1.Brush as the parameter.

            When you call TestBrush.ToDxBrush(RenderTarget) this is going to return a SharpDX.Direct2D1.Brush which is already a usable brush. (Please take a look at the example I provided you)
            You are trying to take this usable brush and supply this as a parameter to the constructor of SharpDX.Direct2D1.SolidColorBrush. A SharpDX.Direct2D1.SolidColorBrush will not accept a SharpDX.Direct2D1.Brush as a parameter. The constructor for this object will only accept a Color4 object.




            But I can say that the following would work:
            Code:
            SharpDX.Direct2D1.Brush dxBrush = TestBrush.ToDxBrush(RenderTarget);
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Wow, I never imagined this could be so difficult.

              The using statement is copied for the Help Guide. Seach Help Guide for OnRender, result #1. It is the exact code I pasted in my post #3.

              using(SharpDX.Direct2D1.SolidColorBrushdxBrush=newSharpDX.Direct2D1.SolidColorBrush(RenderTarget,Sha rpDX.Color.Blue))
              {
              RenderTarget.FillRectangle(newSharpDX.RectangleF(ChartPanel.X,ChartPanel.Y,Chart Panel.W,ChartPanel.H),dxBrush);
              }

              Now in that using statement, at the end is "SharpDX.Color.Blue"

              All I am trying to do is get a code snippet that is not hard coded for a color, in this case DodgerBlue. So I tired replacing (NOTE: Bold, Italic, Under Line area):

              using(SharpDX.Direct2D1.SolidColorBrushdxBrush=newSharpDX.Direct2D1.SolidColorBrush(RenderTarget,SharpDX.Color.Blue))

              with

              using(SharpDX.Direct2D1.SolidColorBrushdxBrush=newSharpDX.Direct2D1.SolidColorBrush(RenderTarget,TestBrush.ToDXBrush(RenderTarget))

              it throws an error. Why? How can I fix that. I prefer to use the "using" method as that is supposed to take care of the cleanup/ dispose.

              Comment


                #8
                Hello TAJTrades,

                Thank you for pointing out this error in the help guide.



                I have notified our product management of the incorrect code so that this may be corrected.

                You are getting an error because this object's constructor will not accept a SharpDX.Direct2D1.Brush as a parameter. It will only accept a SharpDX.Direct2D1.Color4 as a parameter.


                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Ok, making progress. I can accept the error in the Help Guide.

                  That creates a new question. Can I convert this TestBush to SharpDX.Direct2D1.Color4
                  HTML Code:
                  if (State == State.SetDefaults)
                              {
                                TestBrush  = Brushes.Orange;
                              }
                  
                  
                  #region Properties
                          [NinjaScriptProperty]
                          [XmlIgnore]
                          [Display(Name="TestBrush", Description="TestBrush Description", Order=1, GroupName="Parameters")]
                          public Brush TestBrush
                          { get; set; }
                  
                          [Browsable(false)]
                          public string TestBrushSerializable
                          {
                              get { return Serialize.BrushToString(TestBrush); }
                              set { TestBrush = Serialize.StringToBrush(value); }
                          }            
                          #endregion
                  If so how? Keep in mind I prefer to us the "using" method. The Color4 in the Help Guide leaves me lost. I am not sure what to do with the constructor Color4().

                  I have now found 2 issues in the Help Guide so I am a little hesitant to lean on it to hard. Thanks for your help. I am really not trying to be a PITA.
                  Last edited by TAJTrades; 06-22-2017, 11:17 AM.

                  Comment


                    #10
                    Hello TAJTrades,

                    You would need to do this from the argb of the System.Windows.Media.SolidColorBrush.Color property.

                    Color4(float red, float green, float blue, float alpha)
                    https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx
                    http://ninjatrader.com/support/helpG...pdx_color4.htm
                    Code:
                    SolidColorBrush testSolidColorBrush = (SolidColorBrush)TestBrush;
                    
                    SharpDX.Color4 color4Obj = new SharpDX.Color4(testSolidColorBrush.Color.R, testSolidColorBrush.Color.G, testSolidColorBrush.Color.B, testSolidColorBrush.Color.A);
                    Last edited by NinjaTrader_ChelseaB; 12-14-2022, 11:33 AM.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_ChelseaB View Post
                      Hello TAJTrades,

                      I am not understanding what the using call is for..

                      I unsure of how this will affect things.

                      I am also unsure how you are trying to create a new SharpDX.Direct2D1.SolidColorBrush using a SharpDX.Direct2D1.Brush as the parameter.

                      When you call TestBrush.ToDxBrush(RenderTarget) this is going to return a SharpDX.Direct2D1.Brush which is already a usable brush. (Please take a look at the example I provided you)
                      You are trying to take this usable brush and supply this as a parameter to the constructor of SharpDX.Direct2D1.SolidColorBrush. A SharpDX.Direct2D1.SolidColorBrush will not accept a SharpDX.Direct2D1.Brush as a parameter. The constructor for this object will only accept a Color4 object.




                      But I can say that the following would work:
                      Code:
                      SharpDX.Direct2D1.Brush dxBrush = TestBrush.ToDxBrush(RenderTarget);
                      Thank you ChelseaB. This was very helpful for an issue I was working on just now!

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by RubenCazorla, Today, 09:07 AM
                      2 responses
                      13 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Started by i019945nj, 12-14-2023, 06:41 AM
                      7 responses
                      82 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Started by timmbbo, 07-05-2023, 10:21 PM
                      4 responses
                      158 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Started by tkaboris, Today, 08:01 AM
                      1 response
                      7 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Started by Lumbeezl, 01-11-2022, 06:50 PM
                      31 responses
                      820 views
                      1 like
                      Last Post NinjaTrader_Adrian  
                      Working...
                      X