Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Semi-transparent and grayed SVG nodes (Read 3550 times)
Vladimir
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 9
Joined: Feb 2nd, 2010
Semi-transparent and grayed SVG nodes
Apr 2nd, 2012 at 11:20pm
Print Post  
Hello!

We have such diagramming tasks that require node semi-transparency and graying a node (e.g. show node as disabled).

How could I do that?
1. I have no idea how to rich transparency.
2. I think that I could gray a node with CustomDraw – just overlay a gray rectangle over the node in additional mode. Am I right or there are more elegant way to do that?

Thank you in advance!
Best wishes,
Vladimir.
  

SVGNode-triks.png (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Semi-transparent and grayed SVG nodes
Reply #1 - Apr 3rd, 2012 at 9:19am
Print Post  
Hi,

At this time there is no SvgNode property available to make the node semi-transparent. You will have to set fill-opacity attribute on your SVG shapes, and load them as separate SvgContent objects to use for transparent nodes.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Vladimir
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 9
Joined: Feb 2nd, 2010
Re: Semi-transparent and grayed SVG nodes
Reply #2 - Apr 3rd, 2012 at 12:35pm
Print Post  
OK. I see.
Thank you for your post.

What about grayed node (not transparent)?
Please look at the right node on the picture labeled "Grayed". It's not transparent.
How to do that?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Semi-transparent and grayed SVG nodes
Reply #3 - Apr 3rd, 2012 at 2:05pm
Print Post  
You could try handling the DrawNode event and filling the polygon returned by SvgContent.GetConcaveHull() with translucent gray.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Semi-transparent and grayed SVG nodes
Reply #4 - Apr 3rd, 2012 at 6:06pm
Print Post  
One addition - GetConcaveHull returns the points in SVG coordinates, which you will need to map to the node's bounding rectangle as shown below.

Code
Select All
node.CustomDraw = CustomDraw.Additional;
.....

private System.Drawing.SolidBrush grayBrush =
	new System.Drawing.SolidBrush(Color.FromArgb(100, Color.Gray));

private void diagram_DrawNode(object sender, DrawNodeEventArgs e)
{
	SvgNode svgNode = e.Node as SvgNode;
	if (svgNode != null && !e.Shadow)
	{
		PointF[] points = svgNode.Content.GetConcaveHull();

		GraphicsState gs = e.Graphics.Save();
		MapCoordinateSystem(e.Graphics,
			svgNode.Content.GetBounds(), e.Node.Bounds);
		e.Graphics.FillPolygon(grayBrush, points);
		e.Graphics.Restore(gs);
    }
}

private void MapCoordinateSystem(IGraphics graphics,
	RectangleF newBounds, RectangleF oldBounds)
{
	graphics.TranslateTransform(oldBounds.X, oldBounds.Y);
	graphics.ScaleTransform(
		oldBounds.Width / newBounds.Width,
		oldBounds.Height / newBounds.Height);
	graphics.TranslateTransform(-newBounds.X, -newBounds.Y);
} 



The code above assumes you are using ContentAlign=Stretch. Since GetConcaveHull() isn't very fast, you might want to cache the points for each SvgContent in some Dictionary.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Vladimir
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 9
Joined: Feb 2nd, 2010
Re: Semi-transparent and grayed SVG nodes
Reply #5 - Apr 3rd, 2012 at 10:15pm
Print Post  
Yes, it's not fast but exactly what I need.

Thank you!
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint