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 rbeckmann05, Today, 05:50 AM
          0 responses
          2 views
          0 likes
          Last Post rbeckmann05  
          Started by doihaveto13, Today, 05:45 AM
          0 responses
          2 views
          0 likes
          Last Post doihaveto13  
          Started by giulyko00, 04-24-2024, 12:03 PM
          9 responses
          43 views
          0 likes
          Last Post giulyko00  
          Started by memonic, Yesterday, 01:23 PM
          2 responses
          25 views
          0 likes
          Last Post memonic
          by memonic
           
          Started by merc410, Today, 03:41 AM
          2 responses
          17 views
          0 likes
          Last Post merc410
          by merc410
           
          Working...
          X