Page Index Toggle Pages: [1] 2  Send TopicPrint
Hot Topic (More than 10 Replies) Operations between two nodes (Read 5566 times)
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Operations between two nodes
Apr 6th, 2020 at 7:54am
Print Post  
Set the area of ​​the overlayNode beyond the imageNode to black. How to achieve it?
  

11.jpg ( 21 KB | 120 Downloads )
11.jpg
22.jpg ( 23 KB | 126 Downloads )
22.jpg
33.jpg ( 21 KB | 124 Downloads )
33.jpg
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: Operations between two nodes
Reply #1 - Apr 6th, 2020 at 10:09am
Print Post  
Hi,

Set Diagram.BackBrush to Black brush and apply a semi-transparency mask from a DrawForeground event hander. Same principle as demonstrated here: https://mindfusion.eu/Forum/YaBB.pl?num=1584493773/33#33.

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


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Operations between two nodes
Reply #2 - Apr 6th, 2020 at 10:52am
Print Post  
Thank you very much for your answer, Lyubo.
I tried applying the following code, but it throws an exception. How to solve this?
xaml:
                    <diag:Diagram x:Name="diagram"
AllowDrop="True"
VerticalAlignment="Top"
HorizontalAlignment="Left"
DefaultShape="RoundRect"
Behavior="Pan"
PreviewMouseWheel="diagram_PreviewMouseWheel" GridSizeX="15" GridSizeY="15" RestrictItemsToBounds="InsideOnly" RightButtonActions="None"
Bounds="-60,-60,2000,2000" MouseWheel="diagram_MouseWheel" NodeDoubleClicked="diagram_NodeDoubleClicked" DrawNode="diagram_DrawNode"
BackBrush="Black" DrawForeground="diagram_DrawForeground"
>
</diag:Diagram>
cs:
        private void diagram_DrawForeground(object sender, DiagramEventArgs e)
        {
            if (e.Node != diagram)
                return;
            var graphics = e.Graphics;
            var clip = new CombinedGeometry(
                GeometryCombineMode.Exclude,
                new RectangleGeometry(diagram.Bounds),
                new RectangleGeometry(overlayNode.Bounds));

            var translate = new TranslateTransform(-diagram.Bounds.X, -diagram.Bounds.Y);
            graphics.PushTransform(translate);
            graphics.PushClip(clip);
            graphics.DrawRectangle(new SolidColorBrush(Color.FromArgb(120, 0, 0, 0)), null, diagram.Bounds);
            graphics.Pop();
            graphics.Pop();
        }
  

4_6_12.png ( 323 KB | 121 Downloads )
4_6_12.png
4_6_11.png ( 286 KB | 155 Downloads )
4_6_11.png
Back to top
 
IP Logged
 
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Operations between two nodes
Reply #3 - Apr 8th, 2020 at 6:00am
Print Post  
Lyubo, I'm waiting for your answer to this question. Smiley
  
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: Operations between two nodes
Reply #4 - Apr 8th, 2020 at 7:06am
Print Post  
Hi,

Your IDE is clear why there are exceptions. In the first screenshot the error happens becaue the DiagramEventArgs class doesn't have a Node property, nor is a Node a Diagram. In the second, apparently you haven't created your overlayNode yet at the time the event handler is called, so the compiler throws and exception there. Make sure that overlayNode is not null before executing the drawing code.

In the above code replace if ( e.Node != diagram ) return; with if (overlayNode == null ) return;

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


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Operations between two nodes
Reply #5 - Apr 8th, 2020 at 7:20am
Print Post  
Yes, you are right. I have changed it. Now the code is as follows. But it failed to achieve the effect of screenshot 11.jpg, screenshot 22.jpg and screenshot 33.jpg above. What changes do I need to make?
xaml:
<diag:Diagram x:Name="diagram"
AllowDrop="True"
VerticalAlignment="Top"
HorizontalAlignment="Left"
DefaultShape="RoundRect"
Behavior="Pan"
PreviewMouseWheel="diagram_PreviewMouseWheel" GridSizeX="15" GridSizeY="15" RestrictItemsToBounds="InsideOnly" RightButtonActions="None"
Bounds="-600,-600,1500,1500" MouseWheel="diagram_MouseWheel" NodeDoubleClicked="diagram_NodeDoubleClicked" DrawNode="diagram_DrawNode"
BackBrush="Black" DrawForeground="diagram_DrawForeground"
>
</diag:Diagram>

cs:
private void diagram_DrawForeground(object sender, DiagramEventArgs e)
{
if (overlayNode == null)
return;
var graphics = e.Graphics;
var clip = new CombinedGeometry(
GeometryCombineMode.Exclude,
new RectangleGeometry(diagram.Bounds),
new RectangleGeometry(overlayNode.Bounds));

var translate = new TranslateTransform(-diagram.Bounds.X, -diagram.Bounds.Y);
graphics.PushTransform(translate);
graphics.PushClip(clip);
graphics.DrawRectangle(new SolidColorBrush(Color.FromArgb(120, 0, 0, 0)), null, diagram.Bounds);
graphics.Pop();
graphics.Pop();
}
  

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


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: Operations between two nodes
Reply #6 - Apr 8th, 2020 at 7:32am
Print Post  
Call diagram.InvalidateForeground(); from a NodeModifying handler and after creating your node.
  
Back to top
 
IP Logged
 
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Operations between two nodes
Reply #7 - Apr 8th, 2020 at 7:41am
Print Post  
Yes, I tried it, but it still fails. I know it is my problem, please guide me.
private void diagram_DrawForeground(object sender, DiagramEventArgs e)
{
if (overlayNode == null)
return;
var graphics = e.Graphics;
var clip = new CombinedGeometry(
GeometryCombineMode.Exclude,
new RectangleGeometry(diagram.Bounds),
new RectangleGeometry(overlayNode.Bounds));

var translate = new TranslateTransform(-diagram.Bounds.X, -diagram.Bounds.Y);
graphics.PushTransform(translate);
graphics.PushClip(clip);
graphics.DrawRectangle(new SolidColorBrush(Color.FromArgb(120, 0, 0, 0)), null, diagram.Bounds);
graphics.Pop();
graphics.Pop();
}

private void diagram_NodeModifying(object sender, NodeValidationEventArgs e)
{
diagram.InvalidateForeground();
}
  
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: Operations between two nodes
Reply #8 - Apr 8th, 2020 at 8:26am
Print Post  
Hi,

Remove the translate transfrom. Namely these lines
Code
Select All
//var translate = new TranslateTransform(-diagram.Bounds.X, -diagram.Bounds.Y);
//graphics.PushTransform(translate); 

. Remove one call to graphics.Pop(); too. And make sure you're not applying another opacity mask in a DrawNode handler.

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


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Operations between two nodes
Reply #9 - Apr 8th, 2020 at 8:40am
Print Post  
I tried it, it still doesn't work
xaml:
<diag:Diagram x:Name="diagram"
AllowDrop="True"
VerticalAlignment="Top"
HorizontalAlignment="Left"
DefaultShape="RoundRect"
Behavior="Pan"
PreviewMouseWheel="diagram_PreviewMouseWheel" GridSizeX="15" GridSizeY="15" RestrictItemsToBounds="InsideOnly" RightButtonActions="None"
Bounds="-600,-600,1500,1500" MouseWheel="diagram_MouseWheel" NodeDoubleClicked="diagram_NodeDoubleClicked" DrawNode="diagram_DrawNode"
BackBrush="Black" DrawForeground="diagram_DrawForeground" NodeModifying="diagram_NodeModifying"
>
</diag:Diagram>
cs:
private void diagram_DrawNode(object sender, DrawNodeEventArgs e)
{
if (e.Node != imageNode)
return;

var graphics = e.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();
}

private void diagram_DrawForeground(object sender, DiagramEventArgs e)
{
if (overlayNode == null)
return;
var graphics = e.Graphics;
var clip = new CombinedGeometry(
GeometryCombineMode.Exclude,
new RectangleGeometry(diagram.Bounds),
new RectangleGeometry(overlayNode.Bounds));

// var translate = new TranslateTransform(-diagram.Bounds.X, -diagram.Bounds.Y);
// graphics.PushTransform(translate);
graphics.PushClip(clip);
graphics.DrawRectangle(new SolidColorBrush(Color.FromArgb(120, 0, 0, 0)), null, diagram.Bounds);
//graphics.Pop();
graphics.Pop();
}

private void diagram_NodeModifying(object sender, NodeValidationEventArgs e)
{
diagram.InvalidateForeground();
}

I even commented out the method DrawNode, but it doesn't work either.
private void diagram_DrawNode(object sender, DrawNodeEventArgs e)
{
//if (e.Node != imageNode)
// return;

//var graphics = e.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();
}

Is there something wrong?
  
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: Operations between two nodes
Reply #10 - Apr 8th, 2020 at 8:59am
Print Post  
Hi,

It works in my test - see attached image. Try debugging your code to see what's wrong on your end.

Regards,
Lyubo
MindFusion
  

opacity.png ( 522 KB | 124 Downloads )
opacity.png
Back to top
 
IP Logged
 
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Operations between two nodes
Reply #11 - Apr 8th, 2020 at 9:09am
Print Post  
Hi, Lyubo. Smiley

What I want is the effect of these screenshots. The area where overlayNode and diagram intersect is displayed in black. Areas where overlayNode does not intersect diagram are displayed transparently. But does not affect the interaction between imageNode and overlayNode. I used the above code, the program runs normally, but it does not achieve the effect I want: the diagram is not transparent. May I ask what changes need to be made?
  

11_001.jpg ( 21 KB | 125 Downloads )
11_001.jpg
22_001.jpg ( 23 KB | 127 Downloads )
22_001.jpg
33_001.jpg ( 21 KB | 120 Downloads )
33_001.jpg
Back to top
 
IP Logged
 
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Operations between two nodes
Reply #12 - Apr 9th, 2020 at 5:59am
Print Post  
Hello, I have been waiting for your answers. Smiley
  
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: Operations between two nodes
Reply #13 - Apr 9th, 2020 at 7:59am
Print Post  
Hi,

I'm not entirely sure why you were expecting an answer as a solution to the above case was already provided. There is an opacity mask over the whole diagram and to achieve the exact effect in the above picture, all you needed to do was change the color of the semi-transparent layer. In my test, changing the color to that in the following snippet produces the effect in the attached screenshot:

Code
Select All
Color.FromArgb(120, 200, 200, 200) 



Additionally, as pointed out, you need to make sure that the diagram foreground is redrawn after changes that would affect the transparency layer.

The code sample we provided uses overlayNode as bounds for the non-transparent portion of the mask, but it can be any other rectangle that is defined in your requirements. It's meant as a guide on how to achieve a particular effect, not to be the actual source code of your application.

Regards,
Lyubo
MindFusion
  

opacity_001.png ( 227 KB | 121 Downloads )
opacity_001.png
Back to top
 
IP Logged
 
D
Full Member
***
Offline


I Love MindFusion!

Posts: 158
Joined: Mar 16th, 2020
Re: Operations between two nodes
Reply #14 - Apr 9th, 2020 at 8:32am
Print Post  
I understand that overlayNode is only used as the border of the non-transparent part of the mask. I also changed the color to the color in the following snippet, but as a result, the diagram failed to achieve transparency. May I ask what went wrong? Please tell what changes are made in the following code?
xaml:
<diag:Diagram x:Name="diagram"
AllowDrop="True"
VerticalAlignment="Top"
HorizontalAlignment="Left"
DefaultShape="RoundRect"
Behavior="Pan"
PreviewMouseWheel="diagram_PreviewMouseWheel" GridSizeX="15" GridSizeY="15" RestrictItemsToBounds="InsideOnly" RightButtonActions="None"
Bounds="-600,-600,1500,1500" MouseWheel="diagram_MouseWheel" NodeDoubleClicked="diagram_NodeDoubleClicked" DrawNode="diagram_DrawNode"
BackBrush="Black" DrawForeground="diagram_DrawForeground" NodeModifying="diagram_NodeModifying"
>
</diag:Diagram>

cs:
private void diagram_DrawNode(object sender, DrawNodeEventArgs e)
{
if (e.Node != imageNode)
return;

var graphics = e.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();
}

private void diagram_DrawForeground(object sender, DiagramEventArgs e)
{
if (overlayNode == null)
return;
var graphics = e.Graphics;
var clip = new CombinedGeometry(
GeometryCombineMode.Exclude,
new RectangleGeometry(diagram.Bounds),
new RectangleGeometry(overlayNode.Bounds));

// var translate = new TranslateTransform(-diagram.Bounds.X, -diagram.Bounds.Y);
// graphics.PushTransform(translate);
graphics.PushClip(clip);
graphics.DrawRectangle(new SolidColorBrush(Color.FromArgb(120, 200, 200, 200)), null, diagram.Bounds);
//graphics.Pop();
graphics.Pop();
}

private void diagram_NodeModifying(object sender, NodeValidationEventArgs e)
{
diagram.InvalidateForeground();
}
  

4_9.png ( 875 KB | 129 Downloads )
4_9.png
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint