Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) problem with reversing double animation (Read 5488 times)
ayushneema
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 37
Joined: Sep 23rd, 2009
problem with reversing double animation
Oct 5th, 2009 at 2:27pm
Print Post  
Hi,
i have created a diagram in which when i hover a mouse on my node it come out at become slitly bigger in size.  I am using following code to produce the effect.
Code
Select All
 Transform originalTransform;
		    DiagramNode sourceNode = cloudNode;
		    ScaleTransform scale = new ScaleTransform();
		    scale.CenterX = originBounds.X + originBounds.Width / 2;
		    scale.CenterY = originBounds.Y + originBounds.Height / 2;
		    originalTransform = sourceNode.RenderTransform;
		    TransformGroup tg = new TransformGroup();
		    tg.Children.Add(originalTransform);
		    tg.Children.Add(scale);
		    sourceNode.RenderTransform = tg;

		    var xa = new DoubleAnimation(1, multiplyFactor, new Duration(new TimeSpan(0, 0, 0, 0, 200)));

		    var ya = new DoubleAnimation(1, multiplyFactor, new Duration(new TimeSpan(0, 0, 0, 0, 200)));
		    if (diagram.FindName("mouseEnter") != null)
			  diagram.UnregisterName("mouseEnter");
		    diagram.RegisterName("mouseEnter", scale);
		    Storyboard.SetTargetName(xa, "mouseEnter");
		    Storyboard.SetTargetProperty(xa, new PropertyPath("ScaleX"));
		    Storyboard.SetTargetName(ya, "mouseEnter");
		    Storyboard.SetTargetProperty(ya, new PropertyPath("ScaleY"));

		    var sb = new Storyboard();
		    sb.Children.Add(xa);
		    sb.Children.Add(ya);
		    sb.Begin(diagram);
		    sb.Stop(); 


but my problem is that when mouse left the node, node doesn't become it is original size in a proper way. In other word i am unable to produce the reverse of double animation. for this i am using following code:
Code
Select All
Transform originalTransform;
		    DiagramNode sourceNode = cloudNode;
		    ScaleTransform scale = new ScaleTransform();
		    scale.CenterX = originBounds.X - originBounds.Width / 2;
		    scale.CenterY = originBounds.Y - originBounds.Height / 2;
		    originalTransform = sourceNode.RenderTransform;
		    TransformGroup tg = new TransformGroup();
		    tg.Children.Add(originalTransform);
		    tg.Children.Add(scale);
		    sourceNode.RenderTransform = tg;

		    var xa = new DoubleAnimation(1, multiplyFactor, new Duration(new TimeSpan(0, 0, 0, 0, 200)));

		    var ya = new DoubleAnimation(1, multiplyFactor, new Duration(new TimeSpan(0, 0, 0, 0, 200)));
		    if (diagram.FindName("mouseEnter") != null)
			  diagram.UnregisterName("mouseEnter");
		    diagram.RegisterName("mouseEnter", scale);
		    Storyboard.SetTargetName(xa, "mouseEnter");
		    Storyboard.SetTargetProperty(xa, new PropertyPath("ScaleX"));
		    Storyboard.SetTargetName(ya, "mouseEnter");
		    Storyboard.SetTargetProperty(ya, new PropertyPath("ScaleY"));

		    var sb = new Storyboard();
		    sb.Children.Add(xa);
		    sb.Children.Add(ya);
		    sb.Begin(diagram);
		    sb.Stop();
 



please suggest me how can i do that.
Thanks
Ayush Neema.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: problem with reversing double animation
Reply #1 - Oct 6th, 2009 at 12:41pm
Print Post  
With each animation you are setting the node's RenderTransform to deeper-and-deeper nested TransformGroup that contains the previous transform and an additional ScaleTransform. You should probably restore node.Transform to its original value from before the MouseEnter animation after each animation completes.
  
Back to top
 
IP Logged
 
Anshul
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 316
Joined: Apr 3rd, 2009
Re: problem with reversing double animation
Reply #2 - Oct 16th, 2009 at 11:23am
Print Post  
Hi Stoyan,

I also want this reverse animation for my application. I am agree that we are not removing the previous animation and doing deeper and deeper animation on the node but how can we remove previous render transform?

What will the reverse code for the reverse animation. Is that very much different from the code given above for reverse animation?

Regards,
Anshul
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: problem with reversing double animation
Reply #3 - Oct 19th, 2009 at 10:03am
Print Post  
Hi Anshul,

You could keep a reference to the original RenderTransform in the form class, and restore it in response to the animation's Completed event. I suppose the reverse animation should only change the positions of the 1 and multiplyFactor arguments.

Stoyan
  
Back to top
 
IP Logged
 
Anshul
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 316
Joined: Apr 3rd, 2009
Re: problem with reversing double animation
Reply #4 - Oct 20th, 2009 at 12:52pm
Print Post  
Hi Stoyan,

I tried to restore it in response to animation's completed event.

But its not working as expected.

I am sending sample application for this.

Please suggest for this.


Regards,
Anshul
  
Back to top
 
IP Logged
 
Anshul
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 316
Joined: Apr 3rd, 2009
Re: problem with reversing double animation
Reply #5 - Oct 21st, 2009 at 9:58am
Print Post  
Hi Stoyan,

Any updates on this.

Regards,
Rupesh.
« Last Edit: Oct 22nd, 2009 at 7:26am by Anshul »  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: problem with reversing double animation
Reply #6 - Oct 22nd, 2009 at 4:06pm
Print Post  
It seems the Completed event never fires for the container Storyboard, but for the Animation objects it contains. So instead of

sb.Completed += new EventHandler(sb_Completed);

you could add the handler to the X animation

xa.Completed += new EventHandler(sb_Completed);

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Anshul
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 316
Joined: Apr 3rd, 2009
Re: problem with reversing double animation
Reply #7 - Oct 23rd, 2009 at 7:10am
Print Post  
Hi Stoyan,


Its not working as expected.

I tried this on sample
xa.Completed += new EventHandler(sb_Completed);

But still behaviour is same.

Please suggest for this.

Regards,
Anshul.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: problem with reversing double animation
Reply #8 - Oct 24th, 2009 at 10:02am
Print Post  
I forgot to mention you must attach the handlers before calling the storyboard.Begin method. The events are not raised otherwise. It turned out the storyboard's event also works when the handler is attached before the Begin() call:

sb.Completed += new EventHandler(sb_Completed);
sb.Begin(diagram);

I cannot understand what you are trying to achieve with these animations. Keep in mind that animation values are temporary, so if you expect the node to stay at double size after the animation completes, you must either set it from the Completed event, or otherwise double its original size and run the animation from 0.5 to 1 instead from 1 to 2.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Anshul
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 316
Joined: Apr 3rd, 2009
Re: problem with reversing double animation
Reply #9 - Nov 16th, 2009 at 8:19am
Print Post  
Hi Stoyan,

With referance to latest reply
I have attached the handlers before calling sb.begin(Daigram).
And I have also tried the animation from 0.5 to 1 instead from 1 to 2.

But still I am not getting the reverse animation as I want.

My aim is:
I am having set of nodes in the diagram.

1.When the mouse is over the perticular node , double size animation should occur.
2.And node should remain in same size until the mouse is moved over the other node.
3.When mouse is moved over the other node double animation should occur.
4.At the same time reverse animation should occur on previouse node returning back to original size.

Thanks and Regards,
Anshul
  
Back to top
 
IP Logged
 
Anshul
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 316
Joined: Apr 3rd, 2009
Re: problem with reversing double animation
Reply #10 - Nov 21st, 2009 at 12:04pm
Print Post  
Hi Stoyan,

Any update on this?

Regards,
Anshul
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: problem with reversing double animation
Reply #11 - Nov 22nd, 2009 at 10:33am
Print Post  
This seems to do what you described:

Code
Select All
DiagramNode pointedNode;

void diagram_MouseMove(object sender, MouseEventArgs e)
{
	Point mousePosition = e.GetPosition(diagram.DocumentPlane);
	DiagramNode newNode = diagram.GetNodeAt(mousePosition);

	if (newNode == pointedNode)
		return;

	if (pointedNode != null && newNode != null)
		Animate(pointedNode, normalSize);

	if (newNode != null)
	{
		Animate(newNode, doubleSize);
		pointedNode = newNode;
	}
}

void Animate(DiagramNode node, Size size)
{
	Rect r = node.Bounds;
	Size s = r.Size;
	double dx = size.Width - s.Width;
	double dy = size.Height - s.Height;
	r.Inflate(dx / 2, dy / 2);

	var animation = new RectAnimation(node.Bounds, r,
		new Duration(TimeSpan.FromSeconds(0.5)), FillBehavior.Stop);

	Storyboard.SetTarget(animation, node);
	Storyboard.SetTargetProperty(animation, new PropertyPath(DiagramNode.BoundsProperty));

	var sb = new Storyboard();
	sb.Children.Add(animation);
	sb.Begin(diagram);
}

Size normalSize = new Size(60, 35);
Size doubleSize = new Size(120, 70);
 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Anshul
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 316
Joined: Apr 3rd, 2009
Re: problem with reversing double animation
Reply #12 - Nov 23rd, 2009 at 1:55pm
Print Post  
Hi Stoyan,


In my application, I am opening Property window after the double animation.

On the mouse leave event of property window I am using following code for Fade out effect of window.

But I am getting blackish window when the window is fading out.

private void Properties_MouseLeave(object sender, MouseEventArgs e)
       {
           try
           {
               PropertyTimer.Interval = TimeSpan.FromMilliseconds(200);
               PropertyTimer.Start();
               PropertyTimer.Tick += new EventHandler(QPropertyTimer_Tick);
           }
           catch (Exception exc)
           {
           }
       }


void PropertyTimer_Tick(object sender, EventArgs e)
       {
           try
           {
               App.Qwindow.Dispatcher.BeginInvoke(DispatcherPriority.Send, (DispatcherOperationCallback)delegate(object o)
               {
                  
                   this.Opacity = this.Opacity - 0.005;
                   if (this.Opacity == 0.0)
                   {
                       this.Close();
                   }
                   return null;
               }, null);
           }
           catch (Exception exc)
           {
            }
       }



Please Suggest for this.

Regards,
Anshul
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: problem with reversing double animation
Reply #13 - Nov 25th, 2009 at 3:02pm
Print Post  
Are you using any effects with this window, e.g. DropShadowEffect? In such case you might be seeing the black shadow when the window starts to get transparent.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint