Page Index Toggle Pages: 1 2 [3] 4 5  Send TopicPrint
Very Hot Topic (More than 25 Replies) Operations in the diagram (Read 18678 times)
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Operations in the diagram
Reply #30 - Mar 23rd, 2020 at 9:04am
Print Post  
Added:
How can I achieve the effect in the picture. The starting position of the ShapeNode in the figure is on the right. How can I control the starting position of the ShapeNode to be left or right? Then control the size of the entire ShapeNode according to TextBox: Length and TextBox: Width, but it will not affect the size of the image. Does the figure use two ShapeNodes or just one ShapeNode and has special settings? What can I do to achieve the effect in the picture? Is there any sample code? Smiley
  

3_23_9.png ( 994 KB | 120 Downloads )
3_23_9.png
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: Operations in the diagram
Reply #31 - Mar 23rd, 2020 at 2:45pm
Print Post  
Hi,

All aspects of the ShapeNode size and location are controlled by its Bounds property. If you want to modfiy the size, but keep the node anchored to the right, you need to change not only the width, but set a new location too - the new location will be offset by the difference between the new and the old size. For example, if you increase the width by 10, you need to move the location with 10 to the left to keep the node right anchored.

Code
Select All
var offset = newWidth - node.Bounds.Width;
var newBounds = new Rect(node.Bounds.X - offset, node.Bounds.Y, newWidth, node.Bounds.Height);
node.SetBounds(newBounds, true, true);
 



For the image, I already explained how to maintain its size in my previous post. If you can modify the size of your image to be what you need to be seen inside the node - the effect from your screen shot can be achieved just by setting node.ImageAlign to ImageAlign.BottomRight. If you can't modify the size of the image, set node.ImageAlign to ImageAlign.Fit and use node.ImagePadding to restrict the image to your needed bounds. For example, if your node has a size of 50 by 50 and you need your image to have size 40 by 40 - set node.ImagePadding = new Thickness(10, 10, 0, 0);. That will have the same effect.

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


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Operations in the diagram
Reply #32 - Mar 24th, 2020 at 2:41am
Print Post  
Thanks a lot Smiley
How can the effect in this picture be achieved? The ShapeNode's Image is displayed outside the ShapeNode, and the right and bottom edges of the Image and ShapeNode coincide. Is there any sample code?
  

3_24.png ( 1132 KB | 143 Downloads )
3_24.png
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: Operations in the diagram
Reply #33 - Mar 24th, 2020 at 11:12am
Print Post  
Hi,

You can achieve an effect similar to that in the picture by using two nodes - one attached to the other, and some custom drawing with clipping regions to achieve the transparency effect. Below is a code sample of that approach:
Code
Select All
ShapeNode imageNode = diagram.Factory.CreateShapeNode(0, 0, 250, 250);
imageNode.Shape = Shapes.Rectangle;
imageNode.CustomDraw = CustomDraw.Additional;
imageNode.Image = myImage;
imageNode.ImageAlign = ImageAlign.Fit;

ShapeNode overlayNode = diagram.Factory.CreateShapeNode(150, 150, 100, 100);
overlayNode.Shape = Shapes.Rectangle;
overlayNode.Brush = Brushes.Transparent;
overlayNode.Locked = true;
overlayNode.AttachTo(imageNode, AttachToNode.BottomRight);

diagram.DrawNode += (sender, args) =>
{
	if (args.Node != imageNode)
		return;

	var graphics = args.Graphics;
	var clip = new CombinedGeometry(
		GeometryCombineMode.Exclude,
		new RectangleGeometry(imageNode.Bounds),
		new RectangleGeometry(overlayNode.Bounds));
	var translate = new TranslateTransform(-imageNode.Bounds.X, -imageNode.Bounds.Y);
	graphics.PushTransform(translate);
	graphics.PushClip(clip);
	graphics.DrawRectangle(new SolidColorBrush(Color.FromArgb(120, 0, 0, 0)), null, imageNode.Bounds);
	graphics.Pop();
	graphics.Pop();
}; 



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


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Operations in the diagram
Reply #34 - Mar 24th, 2020 at 12:45pm
Print Post  
Thanks a lot Smiley
I have two questions:
1. I want to overlap the bottom and right edges of the overlayNode with the bottom and right edges of the image. How can I achieve this?
2. How to get the length and width of the image to create the imageNode?
Is there any sample code?
  

3_24_2.png ( 104 KB | 124 Downloads )
3_24_2.png
3_24_1.png ( 242 KB | 133 Downloads )
3_24_1.png
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Operations in the diagram
Reply #35 - Mar 25th, 2020 at 8:01am
Print Post  
1. something like -
Rect toAlign, alignTarget;
toAlign.X = alignTarget.Right - toAlign.Width;
toAlign.Y = alignTarget.Bottom - toAlign.Height;

2. there are the Width and Height properties of ImageSource.
  
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: Operations in the diagram
Reply #36 - Mar 25th, 2020 at 8:49am
Print Post  
In addition to the above, if you want to convert the image size (which is in pixels) to diagram's MeasureUnit, use the following code:
Code
Select All
var imageWidthPx = myImage.PixelWidth * 96 / myImage.DpiX;
var imageHeightPx = myImage.PixelHeight * 96 / myImage.DpiY;

var imageWidth = GraphicsUnit.Pixel.Convert(imageWidthPx, diagram.MeasureUnit);
var imageHeight = GraphicsUnit.Pixel.Convert(imageHeightPx, diagram.MeasureUnit); 



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


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Operations in the diagram
Reply #37 - Mar 25th, 2020 at 8:52am
Print Post  
SmileyHi Mr. Slavcho, thank you and Mr. Lyubo for your answers. The answer you said is not very clear to me. My first question is that I created two nodes in the diagram, imageNode and overlayNode. I currently implement the effect in the picture according to the method you taught, but some optimization is needed, that is, the bottom and right sides of the overlayNode node should coincide with the bottom and right sides of the image in the imageNode node, not the bottom and right sides of the imageNode How can I achieve this? My second problem is that I want to get the Width and Height of the image in the imageNode before I create the imageNode. Use these two to create the imageNode {imageNode = diagram.Factory.CreateShapeNode (0, 0, Width, Height);} How can I achieve this?
  

3_24_001.png ( 1132 KB | 111 Downloads )
3_24_001.png
3_24_2_001.png ( 104 KB | 119 Downloads )
3_24_2_001.png
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: Operations in the diagram
Reply #38 - Mar 25th, 2020 at 11:58am
Print Post  
Hi,

For your first question, as already stated above use ImageAlign.BottomRight. Regarding image size, there is a code example just above your post.

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


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Operations in the diagram
Reply #39 - Mar 25th, 2020 at 1:15pm
Print Post  
Hello Mr. Lyubo, thank you for your answer. After I applied the sample code, I got an error, why can't imageNode.Image and ImageAlign.BottomRight be used. Please give me guidance. At present, I have only achieved the effect of Figure 2, but I want to achieve the effect of Figure 1: The bottom and right sides of the image of the imageNode overlap with the bottom and right sides of the overlayNode respectively. In addition, how can we make the size of image in imageNode and imageNode consistent? I think this can also achieve the effect of Figure 1. Please give me sample code. Smiley
  

3_24_002.png ( 1132 KB | 130 Downloads )
3_24_002.png
3_24_2_002.png ( 104 KB | 121 Downloads )
3_24_2_002.png
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: Operations in the diagram
Reply #40 - Mar 25th, 2020 at 2:02pm
Print Post  
You need to assign ImageAlign.BottomRight to the node's ImageAlign property, not to the image:
Code
Select All
using MindFusion.Diagramming.Wpf;

//...

imageNode.ImageAlign = ImageAlign.BottomRight; 



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


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Operations in the diagram
Reply #41 - Mar 25th, 2020 at 3:09pm
Print Post  
Hello Mr. Lyubo, thank you for your answer. After I changed the imageNode property ImageAlign from the original ImageAlign.Fit to ImageAlign.BottomRight, the image in imageNode is not displayed completely, and this function: when zooming in and out, change the mouse wheel to the center point in the view, instead of Using the current coordinate position of the mouse as the base point is also affected and does not work properly. Smiley
  

3_25_3.png ( 86 KB | 120 Downloads )
3_25_3.png
3_25_4.png ( 259 KB | 117 Downloads )
3_25_4.png
Back to top
 
IP Logged
 
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Operations in the diagram
Reply #42 - Mar 25th, 2020 at 3:28pm
Print Post  
SmileyAdded:
I want the image in imageNode to show its own size, and the size of imageNode is the same as the size of imageNode.Image. I tried this method: imageNode.SetBounds (new Rect (0, 0, imageNode.Image.Width, imageNode.Image.Height), true, true); but the effect is not working: the overlayNode is not displayed, and the picture cannot be dragged, and the mouse wheel event is also affected. How can I solve it. The only solution I thought of was to get the length and width of the image before creating the imageNode, and then use the length and width of the image to create the imageNode: imageNode = diagram.Factory.CreateShapeNode (0, 0, the_length, the_width); please tell me what How to do? In order to achieve the effect of Figure 3 I want.
  

3_25_5.png ( 256 KB | 127 Downloads )
3_25_5.png
3_25_6.png ( 218 KB | 125 Downloads )
3_25_6.png
Back to top
 
IP Logged
 
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Operations in the diagram
Reply #43 - Mar 25th, 2020 at 3:34pm
Print Post  
SmileyThe effect I want:
  

3_24_003.png ( 1132 KB | 110 Downloads )
3_24_003.png
Back to top
 
IP Logged
 
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Operations in the diagram
Reply #44 - Mar 26th, 2020 at 2:24pm
Print Post  
Hello, I have been waiting for you to answer my above question.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1 2 [3] 4 5 
Send TopicPrint