Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

fillrectangle gradient

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

    fillrectangle gradient

    hi,

    i am trying to fill a rectangle in onrender with a lineargradientbrush, how whould I do that?

    thanks in advance

    #2
    Hello,

    Thank you for the question.

    Below is an example using LinearGradientBrush:

    Code:
    SharpDX.Direct2D1.LinearGradientBrush      linearGradientBrush = new SharpDX.Direct2D1.LinearGradientBrush(RenderTarget, new SharpDX.Direct2D1.LinearGradientBrushProperties()
    {
    	StartPoint = new SharpDX.Vector2(50, 0),
    	EndPoint = new SharpDX. Vector2(450, 0),
    },
    new 	SharpDX.Direct2D1.GradientStopCollection(RenderTarget, new SharpDX.Direct2D1.GradientStop[]
    {
    	new	SharpDX.Direct2D1. GradientStop()
    	{
    		Color = SharpDX.Color.Blue,
    		Position = 0,
    	},
    	new 	SharpDX.Direct2D1. GradientStop()
    	{
    		Color = SharpDX.Color.Green,
    		Position = 1,
    	}
    }));
    
    RenderTarget.FillRectangle(new SharpDX.RectangleF(100, 100, 450, 150), linearGradientBrush);
    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks, Jesse

      thats what I was looking for, one additional question, do I have to "freeze" the brush, when I use this?
      P.S. What do the values in the Brackets in the vector2 definition exactly stand for?
      Last edited by keepsimple; 03-02-2016, 09:53 AM.

      Comment


        #4
        Hello,

        In this case I do not believe there is a need or way to do so. This is a SharpDX.Direct2D1.LinearGradientBrush opposed to a System.Windows.Media.LinearGradientBrush

        It is always good practice to freeze/dispose of objects you create explicitly to ensure they are marked for removal correctly. SharpDX.Direct2D1.LinearGradientBrush specifically has no Freeze() method.

        Regarding the second question, if you are asking about: Vector2(50, 0), or the (50,0). A Vector2 contains a 2 dimension coordinate or X and Y so this would be 50 X and 0 Y.

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

        Comment


          #5
          thanks jesse,

          will work with that, asking about the vector2 I knew it stands for coordinates, perhaps I formulated my question a little confusing, I wanted to know, for what those coordinates are needed, I played a little with it and i think they determine the start and endpoint for the coloring. hope thats right.

          thanks again for your help.

          regards

          Comment


            #6
            Hello,

            Thank you for clairifing.

            Yes those coordinates go along with the coords you see in the RenderTarget command regarding the colors position:

            Code:
            StartPoint = new SharpDX.Vector2(50, 0),
            EndPoint = new SharpDX. Vector2(450, 0),
            
            FillRectangle(new SharpDX.RectangleF(100, 100, 450, 150)
            This would be a Horizontal gradient as the Start is 50 X and end is 450 X with 0 Y on both.

            For a Vertical you could use something like:

            Code:
            StartPoint = new SharpDX.Vector2(0, 150),
            EndPoint = new SharpDX. Vector2(0, 250),
            It appears that this may be the RenderTarget coordinates in these Vectors, as 0Y through 150 Y would produce a solid color where 150 through 250 produces a gradient as the Rectangle starts at 100 Y.

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

            Comment


              #7
              Jesse,
              On the code below, how do you transform Color11 so that it can be accepted by Color (inside GradientStop). The objective is to change Color based on opacity.
              SharpDX.ColorBGRA Color11 = new SharpDX.ColorBGRA(0f, 1f, 0f, 0.5f);

              new SharpDX.Direct2D1. GradientStop()
              {
              Color = SharpDX.Color.Blue,
              Position = 0,
              },

              Comment


                #8
                Hello,

                They Type of color this takes as an input is a Color4, 4 meaning it has 4 overloads for values it can take (R G B A)

                Here is a simple example of constructing a new Color4 object:

                Code:
                SharpDX.Color4 color = new SharpDX.Color4(100,100,100,255);
                
                Color = SharpDX.Color.Blue,
                
                would instead be
                
                Color = color,
                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Thank you very much. SharpDX.Color4 is accepted by Color (inside GradientStop).

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Jon17, Today, 04:33 PM
                  0 responses
                  1 view
                  0 likes
                  Last Post Jon17
                  by Jon17
                   
                  Started by Javierw.ok, Today, 04:12 PM
                  0 responses
                  4 views
                  0 likes
                  Last Post Javierw.ok  
                  Started by timmbbo, Today, 08:59 AM
                  2 responses
                  10 views
                  0 likes
                  Last Post bltdavid  
                  Started by alifarahani, Today, 09:40 AM
                  6 responses
                  41 views
                  0 likes
                  Last Post alifarahani  
                  Started by Waxavi, Today, 02:10 AM
                  1 response
                  20 views
                  0 likes
                  Last Post NinjaTrader_LuisH  
                  Working...
                  X