Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Changing colors of a ID2D1Linear/RadialGradientBrush at runtime


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 AvengerDr   Members   -  Reputation: 751

Like
0Likes
Like

Posted 14 August 2014 - 03:57 AM

Hi all,

if you had a look at my devjournal, I'm trying to build an animatable UI framework. I'm going to use C# terminology because I'm using D2D from SharpDX but it shoud apply to C++ just the same. So, every property that can be written to such as the Opacity of a gradient or its RadiusX/Y (in the case of a Radial gradient) can be animated just fine. 

 

I'd like to implement the possibility of animating the colors of a Gradient Brush. Once you create a gradient brush, it seems you can only get a copy of the GradientStops you used returned to you through the GetGradientStops method. Since a GradientStop is a structure, if I were to change their colors, it would have no effect on the actual brush being used.

 

This seems to be a big limitation, so before going any further I'd like to know if someone has attempted to do anything similar. Is there really no other way? The Color property of a SolidColorBrush can be written to, so that could be animated over time. How to do the same with a GradientBrush? Is the only way to do it to create intermediate gradients so that instead of animating the colors I change the whole brush? For a decent animation, you could need to create dozens of slightly different brushes and that seems terribly inefficient.

 

I have two alternative approaches in mind:

  1. Have the source and target gradient one on top of the other and then animate their opacity so that one goes from 0 to 1 and the other from 1 to 0 in the same interval of time. Though I'm not sure the effect would be the same.
  2. Have a greyscale gradient and animate a blended solidcolorbrush on top of it.

But these seem more like hacks, so I was wondering if there was a better way to do this.


Edited by AvengerDr, 14 August 2014 - 03:58 AM.

--Avengers UTD Chronicles - My game development blog

Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS