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

Brush to SharpDx.color

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

    Brush to SharpDx.color

    Hi

    I have a brush property and I need to find a way to convert it to a SharpDx.Color.
    Below is the brush property and below that is the code from OnRender. Right now the color is hardcoded as Yellow.
    The object is to replace the hard coded color with the brush color.
    Hopefully this makes sense.

    Code:
    [Display(Name="speed color", Order=1, GroupName="Parameters")]
    public Brush TapeSpeedLowColor
    { get; set; }

    Code:
    SharpDX.Color dxColor = SharpDX.Color.Yellow;
    SharpDX.Direct2D1.SolidColorBrush solidDXBrush = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, dxColor);
    RenderTarget.FillRectangle(rect2, solidDXBrush);

    #2
    Hello Bidder,

    Thanks for your post.

    You would need to create a SharpDX.Direct2D1.Brush and assign the user-defined brush to that SharpDX brush. For example, if we have a user-defined brush called TextBrush, we would need to assign that to our SharpDX.Direct2D1.Brush. See below.

    Code:
    //In OnRender()
    SharpDX.Direct2D1.Brush textBrushDx;
    
    textBrushDx = TextBrush.ToDxBrush(RenderTarget);
    Please see the attached example script which demonstrates using a user-defined brush property for SharpDX rendering.

    Also, see the help guide documentation linked below for more information.
    SharpDX Brush Resources: https://ninjatrader.com/support/help...BrushResources
    Working with Advanced Brush Types (SharpDX): https://ninjatrader.com/support/help...shTypesSharpDX

    Let us know if we may assist further.
    Attached Files
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Hi Brandon, Thank you for this information, working smoothly thanks to your help.

      Mr. SharpDX and I have had brief, one-sided conversations on many occasions. Brief, primarily because all the words contain only 4 letters. : )

      Comment


        #4
        Just for anyone that still looking at this solution, beware - the ToDxBrush() extension is not thread-safe and it will throw an exception if trying to access the system brush inside of a OnRender() method.

        Comment


          #5
          Hello TuffWeasel,

          Welcome to the NinjaTrader forums!

          The ToDxBrush() is dependent on the RenderTarget. You will not be able to use .ToDxBrush() outside of OnRender() or OnRenderTargetChanged().

          Below is a link to the help guide.


          Included with NinjaTrader is the SampleCustomRender indicator that demonstrates on line 127 using .ToDxBrush() in OnRender().

          Also, below is a link to another example.
          Chelsea B.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by alifarahani, Today, 09:40 AM
          3 responses
          15 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by RookieTrader, Today, 09:37 AM
          4 responses
          17 views
          0 likes
          Last Post RookieTrader  
          Started by PaulMohn, Today, 12:36 PM
          0 responses
          2 views
          0 likes
          Last Post PaulMohn  
          Started by love2code2trade, 04-17-2024, 01:45 PM
          4 responses
          38 views
          0 likes
          Last Post love2code2trade  
          Started by junkone, Today, 11:37 AM
          3 responses
          22 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X