Page Index Toggle Pages: 1 2 [3]  Send TopicPrint
Very Hot Topic (More than 25 Replies) Don't let the scroll bar restrict mouse drag of ShapeNode in Diagram (Read 13689 times)
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Don't let the scroll bar restrict mouse drag of ShapeNode in Diagram
Reply #30 - Apr 3rd, 2020 at 2:57pm
Print Post  
In addition to the above four questions, I have another question: What I want is that no matter if I scroll the mouse wheel at any point of the imageNode or overlayNode to zoom in, the maximum zoom will be the effect of the following screenshot. How to achieve this? What changes should be made to this code?
        private void diagram_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            var imageBounds = imageNode.Bounds;
            var zoomRect = diagram.Viewport;
            var zoomStep = 10;

            if (e.Delta < 0)
            {
                zoomRect = new Rect
                (
                    Math.Max(imageBounds.X, zoomRect.X - zoomStep / 2),
                    Math.Max(imageBounds.Y, zoomRect.Y - zoomStep / 2),
                    Math.Min(imageBounds.Width, zoomRect.Width + zoomStep),
                    Math.Min(imageBounds.Height, zoomRect.Height + zoomStep)
                );
            }
            else
            {
                zoomRect = new Rect
                (
                    Math.Min(overlayNode.Bounds.X, zoomRect.X + zoomStep / 2),
                    Math.Min(overlayNode.Bounds.Y, zoomRect.Y + zoomStep / 2),
                    Math.Max(overlayNode.Bounds.Width, zoomRect.Width - zoomStep),
                    Math.Max(overlayNode.Bounds.Height, zoomRect.Height - zoomStep)
                );
            }

            diagram.ZoomToRect(zoomRect, true);

            // stop the scrollviewer from scrolling
            e.Handled = true;

        }
  

4_3_1_001.png ( 1357 KB | 164 Downloads )
4_3_1_001.png
Back to top
 
IP Logged
 
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Don't let the scroll bar restrict mouse drag of ShapeNode in Diagram
Reply #31 - Apr 3rd, 2020 at 3:02pm
Print Post  
Added:

After the picture is enlarged to the maximum extent, if you roll the mouse wheel again to zoom in, the diagram cannot be moved.
  

4_3_2_001.png ( 1364 KB | 159 Downloads )
4_3_2_001.png
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: Don't let the scroll bar restrict mouse drag of ShapeNode in Diagram
Reply #32 - Apr 6th, 2020 at 6:28am
Print Post  
Hi,

As already suggested, the code provided above lets you limit both your zooming in and zooming out operations to whatever values you have in your requirements. Just replace the imageBounds variable with the bounding rectangle of your outer limits and the redRect variable with the bounding rectangle of your inner limits.

If that approach doesn't work for you, you can use the diagram ZoomFactor property to limit the level of magnification.

Regards,
Lyubo
MindFusion
  
Back to top
 
IP Logged
 
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Don't let the scroll bar restrict mouse drag of ShapeNode in Diagram
Reply #33 - Apr 6th, 2020 at 6:58am
Print Post  
I have set the ZoomFactor value,
but it failed to zoom in to the two screenshots above. How can I solve it?
  

4_6.png ( 1510 KB | 139 Downloads )
4_6.png
4_6_1.png ( 251 KB | 135 Downloads )
4_6_1.png
Back to top
 
IP Logged
 
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Don't let the scroll bar restrict mouse drag of ShapeNode in Diagram
Reply #34 - Apr 6th, 2020 at 7:01am
Print Post  
Thanks a lot, Luybo. Smiley
It's strange, zoom in to the maximum extent, if you still use the wheel to scroll, it will move the imageNode, I don't want this. When I want to zoom in to the maximum, if I still use the wheel to scroll, the imageNode cannot move, which is equivalent to not responding to the wheel message. How can I solve it?
  

4_6_5.png ( 251 KB | 130 Downloads )
4_6_5.png
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: Don't let the scroll bar restrict mouse drag of ShapeNode in Diagram
Reply #35 - Apr 6th, 2020 at 11:10am
Print Post  
Hi,

Can download a zoom example application from this link: https://mindfusion.eu/_samples/ZoomExample.zip

Regards,
Lyubo
MindFusion
  
Back to top
 
IP Logged
 
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Don't let the scroll bar restrict mouse drag of ShapeNode in Diagram
Reply #36 - Apr 6th, 2020 at 1:37pm
Print Post  
Thank you, Lyubo. Smiley I have carefully read the example you gave me. Many of the contents are what I want and I have learned a lot. But the example does not contain the content of my problem above. Please guide me to complete this content: When I zoom in to the maximum, if I still use the mouse wheel to zoom in, the ShapeNode should not move, which is equivalent to not responding to the wheel message. How can I achieve it?
« Last Edit: Apr 7th, 2020 at 12:52pm by D »  
Back to top
 
IP Logged
 
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Don't let the scroll bar restrict mouse drag of ShapeNode in Diagram
Reply #37 - Apr 7th, 2020 at 1:11pm
Print Post  
Hello, I have been waiting for your answers. Smiley
  
Back to top
 
IP Logged
 
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Don't let the scroll bar restrict mouse drag of ShapeNode in Diagram
Reply #38 - Apr 8th, 2020 at 1:29am
Print Post  
I tried the following method and it still doesn't work. When zooming in is no longer possible, if the scroll wheel is still zoomed in, the ShapeNode still moves. I would like to ask how to prohibit this ShapeNode movement.

        private void diagram_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
        {
            var imageBounds = imageNode.Bounds;
            var zoomRect = diagram.Viewport;
            var zoomStep = 10;

            if (e.Delta < 0)
            {
                zoomRect = new Rect
                (
                    Math.Max(imageBounds.X, zoomRect.X - zoomStep / 2),
                    Math.Max(imageBounds.Y, zoomRect.Y - zoomStep / 2),
                    Math.Min(imageBounds.Width, zoomRect.Width + zoomStep),
                    Math.Min(imageBounds.Height, zoomRect.Height + zoomStep)
                );
            }
            else
            {
                zoomRect = new Rect
                (
                    Math.Min(overlayNode.Bounds.X, zoomRect.X + zoomStep / 2),
                    Math.Min(overlayNode.Bounds.Y, zoomRect.Y + zoomStep / 2),
                    Math.Max(10, zoomRect.Width - zoomStep),
                    Math.Max(10, zoomRect.Height - zoomStep)
                );
            }

            if (!zoomRect.Contains(diagram.Factory.CreateShapeNode(overlayNode.Bounds.X, overlayNode.Bounds.Y, 10, 10).Bounds))
            {
                diagram.ZoomToRect(zoomRect, true);
            }


            // stop the scrollviewer from scrolling
            e.Handled = true;
        }
  
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: Don't let the scroll bar restrict mouse drag of ShapeNode in Diagram
Reply #39 - Apr 8th, 2020 at 5:14am
Print Post  
Hi,

The node doesn't move. It's always fixed at the 0,0 position. What happens is that the view scrolls to the smaller rectangle that is defined by overlayNode.Bounds. If you want to remain fixed on the viewport's center point, use the Rect.Inflate method we showed you before and when checking for constraints for inbound and outbound zooming compare only width and height and make sure the center point of the resulting bounding rectangle remains fixed.

Regards,
Lyubo
MindFusion
  
Back to top
 
IP Logged
 
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Don't let the scroll bar restrict mouse drag of ShapeNode in Diagram
Reply #40 - Apr 8th, 2020 at 5:53am
Print Post  
Hey, Lyubo. Smiley

I don't quite understand your answer above. Is there any sample code for my reference?
I desperately need it.
« Last Edit: Apr 9th, 2020 at 8:45am by D »  
Back to top
 
IP Logged
 
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Don't let the scroll bar restrict mouse drag of ShapeNode in Diagram
Reply #41 - Apr 9th, 2020 at 9:07am
Print Post  
In addition to the above question, I ask another question. At present, we have limited the minimum scope of the diagram to the size of the imageNode, but on this basis, an optimization is needed: I do n’t want the entire diagram to be equal to the length of the imageNode, it should be the same as in your screenshot 4_9_2.png, the diagram contains the imageNode the size of. Summary: Without affecting the minimum size of the diagram to be limited to the size of the imageNode, it has the same effect as in your screenshot 4_9_2.png: the diagram contains the size of the imageNode. How do I change it? Is there any sample code?
  

4_9_1.png ( 1509 KB | 151 Downloads )
4_9_1.png
4_9_2.png ( 323 KB | 122 Downloads )
4_9_2.png
Back to top
 
IP Logged
 
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Don't let the scroll bar restrict mouse drag of ShapeNode in Diagram
Reply #42 - Apr 9th, 2020 at 9:07am
Print Post  
Added:
  

4_9_1.png ( 1509 KB | 151 Downloads )
4_9_1.png
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: Don't let the scroll bar restrict mouse drag of ShapeNode in Diagram
Reply #43 - Apr 9th, 2020 at 9:33am
Print Post  
The size of the diagram is controlled by the Diagram.Bounds property. You can set it to any Rect instance. The actual value is up to you to calculate and assign according to your specifications.
  
Back to top
 
IP Logged
 
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Don't let the scroll bar restrict mouse drag of ShapeNode in Diagram
Reply #44 - Apr 9th, 2020 at 9:58am
Print Post  
Hey, Lyubo. There is no need to tell me this answer, because you told me before, please give me a detailed answer to my question, because every question I think about how to ask you seriously, and hope you answer my questions one by one Every question. After completing this project or at the end of this month, I will purchase the right to use MindFusion. I hope you can guide me. Can you take a closer look at my problem?
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1 2 [3] 
Send TopicPrint