Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Flickering when call UpdateFromPoints method (Read 6488 times)
CanadaProgrammer
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 113
Joined: Jun 30th, 2011
Flickering when call UpdateFromPoints method
Dec 12th, 2012 at 9:12am
Print Post  
I change values of points of a link in SelectionMoving event, then
call UpdateFromPoints method. Function can be done but the link
flickers seriously. How to solve it?

Thanks.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Flickering when call UpdateFromPoints method
Reply #1 - Dec 12th, 2012 at 9:48am
Print Post  
Call DiagramView.RecreateCacheImage if modifying items during user interaction.
  
Back to top
 
IP Logged
 
CanadaProgrammer
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 113
Joined: Jun 30th, 2011
Re: Flickering when call UpdateFromPoints method
Reply #2 - Dec 12th, 2012 at 10:00pm
Print Post  
Stoyo wrote on Dec 12th, 2012 at 9:48am:
Call DiagramView.RecreateCacheImage if modifying items during user interaction.

Thanks. So I should call RecreateCacheImage after every time UpdateFromPoints is called ? or
just call it at anyplace of SelectionMoving event?

I call it like below:
...
shape.UpdateFromPoints(false, false);
this.DiagramView.RecreateCacheImage();
...

But it does not work and cause a new strange problem.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Flickering when call UpdateFromPoints method
Reply #3 - Dec 13th, 2012 at 7:15am
Print Post  
You must call it only once, and only if the link is not selected and being modified. Items that are not modified during interaction are pre-rendered in a background buffer image for faster repaint while dragging the mouse, and RecreateCacheImage lets you refresh that image.

If the link is selected, it's not in the buffer image anyway, and if you see flickering it probably happens because the control sets the link points again after you have changed them. In that case you might have to move your code to some handler called after the control sets the link points. E.g. try doing that in a custom behavior class after calling the base MouseMove method, if the behavior's current item is Selection and the selection contains the links you need to modify.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
CanadaProgrammer
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 113
Joined: Jun 30th, 2011
Re: Flickering when call UpdateFromPoints method
Reply #4 - Dec 13th, 2012 at 7:53am
Print Post  
Stoyo wrote on Dec 13th, 2012 at 7:15am:
You must call it only once, and only if the link is not selected and being modified. Items that are not modified during interaction are pre-rendered in a background buffer image for faster repaint while dragging the mouse, and RecreateCacheImage lets you refresh that image.

If the link is selected, it's not in the buffer image anyway, and if you see flickering it probably happens because the control sets the link points again after you have changed them. In that case you might have to move your code to some handler called after the control sets the link points. E.g. try doing that in a custom behavior class after calling the base MouseMove method, if the behavior's current item is Selection and the selection contains the links you need to modify.

I hope that helps,
Stoyan


Thanks for your reply.
I read the document, I still can not understand.
Looks behavior class only can work when user draw a shape.
But my case is not a operation of drawing a shape, it is
a operation of modifying a shape. Would you like tell me more ?

Thanks a lot

  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Flickering when call UpdateFromPoints method
Reply #5 - Dec 13th, 2012 at 8:57am
Print Post  
In most cases at a higher level it's enough to override StartDraw to decide what item to create or modify. Yet behavior classes receive all mouse messages, e.g. the PanBehavior responds to MouseMove by scrolling the diagram view, so you can override the respective methods in a custom class to get more control over user interaction.

From what I can understand you need non-standard modification of links, so I think BehaviorBase.OnMouseMove override should be a good place to implement it if you don't want to create a custom link class.

SelectionMoving is only a validation event where the control expects you to confirm or cancel the operation, and will set its own link points after raising it, disregarding any modifications you might have done from the handler.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
CanadaProgrammer
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 113
Joined: Jun 30th, 2011
Re: Flickering when call UpdateFromPoints method
Reply #6 - Dec 13th, 2012 at 10:24pm
Print Post  
Thanks. Your answer is helpful. But I meet a new problem so I try to show you more and hope you will give me help again.

// This is only a base class, nothing else
public class EMLinkShape : DiagramLink
{
...
}
// This is the link that I want to control
public class EMLinkMessageShape : EMLinkShape
{
...
}
// My custom behavior class
internal class EMLinkMessageShapeBehavior : DrawLinksBehavior
{
     public EMLinkMessageShapeBehavior(DiagramView diagramView)
           : base(diagramView)
     {
     }
     // I override below three methods to implement my control
     // It can work.
     protected override DiagramLink CreateLink()
     {
           return new EMLinkMessageShape(this.Diagram);
     }
     protected override void OnMouseMove(Point mousePosition)
     {
           // Here call my method to draw link
           MyMethod(...);
     }
     public override InteractionState StartDraw(PointF point)
     {
           DiagramLink link = Diagram.GetLinkAt(point, this.Diagram.LinkHitDistance);

           if (link != null)
                 return new InteractionState(link, 8, Action.Modify);
           else
                 return new InteractionState(new ShapeNode(Diagram), -1, Action.Create);
     }
     // This is my method
     protected void MyMethod(...)
     {
           ...
           link.UpdateFromPoints(); // this is last line
     }
}

It can work and can finish my feature. But there is a new problem. When I modify link by mouse slowly, feature can be done excellently. But if I
move mouse quickly the result is very ugly. Like what the below picture shows


How to solve this problem?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Flickering when call UpdateFromPoints method
Reply #7 - Dec 14th, 2012 at 6:35pm
Print Post  
Try adding the result of link.GetRepaintRect() to InteractionState.InvalidRect for both the original and changed link points.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
CanadaProgrammer
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 113
Joined: Jun 30th, 2011
Re: Flickering when call UpdateFromPoints method
Reply #8 - Dec 15th, 2012 at 9:39am
Print Post  
It is hard to understand, InvalidRect of InteractionState is a value , not a list. How to add?
Could you show me a sample? just several lines code. Thanks a lot

BTW,There is another question. When I only select a shape(type is ShapeNode), then overrided method of my custom behavior class will be called. But if I choose several shape, such as 2 ShapeNode and a DiagramLink, then overrided method of my custom behavior class can not be called. Why? Thanks a lot

One more question. Is there any other documents or materials to train developers to use this product? I tried to registry twice but did not get any mail to activate my account. If there are some other documetns then please tell me download link. Thanks
« Last Edit: Dec 16th, 2012 at 10:37pm by CanadaProgrammer »  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Flickering when call UpdateFromPoints method
Reply #9 - Dec 17th, 2012 at 11:53am
Print Post  
Add it by creating a union of the two rectangles, e.g.:

Code
Select All
protected override void OnMouseMove(Point mousePosition)
{
	...
	var ist = Diagram.Interaction;
	if (ist != null)
		ist.InvalidRect = RectangleF.Union(ist.InvalidRect, rect);
	base.OnMouseMove(mousePosition);
} 



where rect is a bounding rectangle of the additional items you need repainted (union of each item's GetRepaintRect()).

Quote:
When I only select a shape(type is ShapeNode), then overrided method of my custom behavior class will be called. But if I choose several shape, such as 2 ShapeNode and a DiagramLink, then overrided method of my custom behavior class can not be called.


There's no way Behavior.OnMouseMove not to be called. Check if there aren't any if statements not executed; for example in your first case InteractionState.CurrentItem will be a ShapeNode, in the second case it will be a Selection instance.

You can find the control's documentation is here:
http://www.mindfusion.eu/onlinehelp/flowchartnet/index.htm

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
CanadaProgrammer
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 113
Joined: Jun 30th, 2011
Re: Flickering when call UpdateFromPoints method
Reply #10 - Dec 19th, 2012 at 5:18am
Print Post  
StartDraw is not called always. Select several shapes then drag mouse starting at a empty point (no any shape under cursor), then StartDraw will be called. if a shape is under cursor and the shape is selected then StartDraw will not be called. So when user choose several shapes and try to move them then where is the best place to customize behaviour ?

Actually I found a way to do it in this situation but I am not sure it is the best way. When user choose single shape then create InteractionState object in StartDraw method then return to caller. If use select muliple shapes then I create a InteractionState obejct in OnMouseMove method and assign the object to Diagram object directly. Is it the only way ?

And I hope there are some documents to decribe how to use these classes in namespace MindFusion.Diagramming.WinForms.Behaviors.

Thanks a lot
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Flickering when call UpdateFromPoints method
Reply #11 - Dec 19th, 2012 at 10:39am
Print Post  
Yes, StartDraw is called to implement behavior-specific code, while moving the selection is considered common for all behavior classes and its InteractionState is created from base MouseMove handler.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
CanadaProgrammer
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 113
Joined: Jun 30th, 2011
Re: Flickering when call UpdateFromPoints method
Reply #12 - Dec 19th, 2012 at 10:29pm
Print Post  
Thanks very much.
I select a shape, such as a ShapeNode, then move it. I find OnMouseMove method will be called twice and the value of MouseMoved of InteractionState is false. I think only once is enough to notice developer that this is the moment to begin to move mouse. But actually it is twice, why?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Flickering when call UpdateFromPoints method
Reply #13 - Dec 21st, 2012 at 2:42pm
Print Post  
It seems InteractionState.MouseMoved is set only after the mouse moves at least a couple of pixels, to make it easier to click-select a node instead of starting modifications. You could use your own flag to detect the first move, clearing it from MouseDown override and setting it from MouseMove; or you could even immediately set InteractionState.MouseMoved if you don't need the threshold value.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint