MSAGL samples 节点为 图片NodesWithImage
来源:互联网 发布:类似易企秀的软件免费 编辑:程序博客网 时间:2024/06/14 08:05
It is strange. .csproj should be in the MSAGL samples. Anyway, below is the code of the form of the sample.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.Msagl.GraphViewerGdi;
using Microsoft.Msagl.Drawing;
using Microsoft.Msagl;
using CurveFactory = Microsoft.Msagl.Splines.CurveFactory;
using P2 = Microsoft.Msagl.Point;
using GeomNode = Microsoft.Msagl.Node;
using GeomEdge = Microsoft.Msagl.Edge;
using DrawingEdge = Microsoft.Msagl.Drawing.Edge;
using DrawingNode = Microsoft.Msagl.Drawing.Node;
namespace NodesWithImages {
public partial class Form1 : Form {
Image creek;
Image leaves;
Image tree;
Image waterfall;
GViewer viewer = new GViewer();
public Form1() {
InitializeComponent();
creek = Image.FromFile("../../Creek.jpg");
leaves = Image.FromFile("../../Autumn Leaves.jpg");
tree = Image.FromFile("../../tree.jpg");
waterfall = Image.FromFile("../../waterfall.jpg");
SuspendLayout();
this.Controls.Add(viewer);
viewer.Dock = DockStyle.Fill;
ResumeLayout();
viewer.LayoutAlgorithmSettingsButtonVisible = false;
InitGraph();
}
bool DrawNode(DrawingNode node, object graphics) {
Graphics g = (Graphics)graphics;
Image image;
if (node.Id == leavesId)
image = leaves;
else if (node.Id == creekId)
image = creek;
else if (node.Id == wId)
image = waterfall;
else
image = tree;
//flip the image around its center
using (System.Drawing.Drawing2D.Matrix m = g.Transform) {
using (System.Drawing.Drawing2D.Matrix saveM = m.Clone()) {
float c = (float)node.Attr.GeometryNode.Center.Y;
using (System.Drawing.Drawing2D.Matrix m2 = new System.Drawing.Drawing2D.Matrix(1, 0, 0, -1, 0, 2 * c))
m.Multiply(m2);
g.Transform = m;
g.SetClip(FillTheGraphicsPath(node.Attr.GeometryNode.BoundaryCurve));
g.DrawImage(image, new PointF((float)(node.Attr.GeometryNode.Center.X - node.Attr.GeometryNode.Width / 2), (float)(node.Attr.GeometryNode.Center.Y - node.Attr.GeometryNode.Height / 2)));
g.Transform = saveM;
}
}
return true;//returning false would enable the default rendering
}
static System.Drawing.Drawing2D.GraphicsPath FillTheGraphicsPath(Microsoft.Msagl.Splines.ICurve iCurve) {
Microsoft.Msagl.Splines.Curve curve = iCurve as Microsoft.Msagl.Splines.Curve;
System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
foreach (Microsoft.Msagl.Splines.ICurve seg in curve.Segments)
AddSegmentToPath(seg, ref path);
return path;
}
private static void AddSegmentToPath(Microsoft.Msagl.Splines.ICurve seg, ref System.Drawing.Drawing2D.GraphicsPath p) {
const float radiansToDegrees = (float)(180.0 / Math.PI);
Microsoft.Msagl.Splines.LineSegment line = seg as Microsoft.Msagl.Splines.LineSegment;
if (line != null)
p.AddLine(PointF(line.Start), PointF(line.End));
else {
Microsoft.Msagl.Splines.CubicBezierSegment cb = seg as Microsoft.Msagl.Splines.CubicBezierSegment;
if (cb != null)
p.AddBezier(PointF(cb.B(0)), PointF(cb.B(1)), PointF(cb.B(2)), PointF(cb.B(3)));
else {
Microsoft.Msagl.Splines.Ellipse ellipse = seg as Microsoft.Msagl.Splines.Ellipse;
if (ellipse != null)
p.AddArc((float)(ellipse.Center.X - ellipse.AxisA.Length), (float)(ellipse.Center.Y - ellipse.AxisB.Length),
(float)(2 * ellipse.AxisA.Length), (float)(2 * ellipse.AxisB.Length), (float)(ellipse.ParStart * radiansToDegrees),
(float)((ellipse.ParEnd - ellipse.ParStart) * radiansToDegrees));
}
}
}
static internal PointF PointF(P2 p) { return new PointF((float)p.X, (float)p.Y); }
float radiusRatio = 0.3f;
string leavesId = "leaves";
string creekId = "creek";
string treeId = "tree";
string wId = "waterfall";
private void InitGraph() {
Graph drawingGraph = new Graph();
DrawingEdge lc=drawingGraph.AddEdge(leavesId, creekId);
DrawingEdge lt=drawingGraph.AddEdge(leavesId, treeId);
DrawingEdge lw = drawingGraph.AddEdge(leavesId, wId);
drawingGraph.FindNode(leavesId).Attr.Shape = Shape.DrawFromGeometry;
drawingGraph.FindNode(creekId).Attr.Shape = Shape.DrawFromGeometry;
drawingGraph.FindNode(treeId).Attr.Shape = Shape.DrawFromGeometry;
drawingGraph.FindNode(wId).Attr.Shape = Shape.DrawFromGeometry;
drawingGraph.FindNode(leavesId).DrawNodeDelegate = new DelegateToOverrideNodeRendering(this.DrawNode);
drawingGraph.FindNode(creekId).DrawNodeDelegate = new DelegateToOverrideNodeRendering(this.DrawNode);
drawingGraph.FindNode(treeId).DrawNodeDelegate = new DelegateToOverrideNodeRendering(this.DrawNode);
drawingGraph.FindNode(wId).DrawNodeDelegate = new DelegateToOverrideNodeRendering(this.DrawNode);
//create the geom graph
GeometryGraph geomGraph = new GeometryGraph();
double width = creek.Width;
double height = creek.Height;
GeomNode geomCreek = new Microsoft.Msagl.Node(creekId, CurveFactory.CreateBox(width, height, width*radiusRatio, height*radiusRatio, new P2()));
geomGraph.AddNode(geomCreek);
width = leaves.Width;
height = leaves.Height;
double arrowHeadLenght = width / 10;
geomGraph.LayerSeparation = height / 2;
geomGraph.NodeSeparation = width / 2;
GeomNode geomLeaves = new Microsoft.Msagl.Node(leavesId, CurveFactory.CreateBox(width, height, width* radiusRatio, height* radiusRatio, new P2()));
geomGraph.AddNode(geomLeaves);
width = tree.Width;
height = tree.Height;
GeomNode geomTree = new Microsoft.Msagl.Node(treeId, CurveFactory.CreateBox(width, height, width* radiusRatio, height *radiusRatio, new P2()));
geomGraph.AddNode(geomTree);
width = waterfall.Width;
height = waterfall.Height;
GeomNode geomW = new Microsoft.Msagl.Node(wId, CurveFactory.CreateBox(width, height, width * radiusRatio, height * radiusRatio, new P2()));
geomGraph.AddNode(geomW);
GeomEdge geomLc = new Microsoft.Msagl.Edge(geomLeaves, geomCreek);
geomLc.ArrowheadLength = arrowHeadLenght;
geomGraph.AddEdge(geomLc);
GeomEdge geomLt = new Microsoft.Msagl.Edge(geomLeaves, geomTree);
geomLt.ArrowheadLength = arrowHeadLenght;
geomGraph.AddEdge(geomLt);
GeomEdge geomLw = new Microsoft.Msagl.Edge(geomLeaves, geomW);
geomLw.ArrowheadLength = arrowHeadLenght;
geomGraph.AddEdge(geomLw);
geomGraph.CalculateLayout();
//bind the geometry graph with the drawing graph
//nodes first
foreach (DrawingNode drawingNode in drawingGraph.NodeMap.Values)
drawingNode.Attr.GeometryNode = geomGraph.FindNode(drawingNode.Id);
//bind edges
lc.Attr.GeometryEdge = geomLc;
lt.Attr.GeometryEdge = geomLt;
lw.Attr.GeometryEdge = geomLw;
//bind graphs
drawingGraph.GeometryGraph = geomGraph;
viewer.NeedToCalculateLayout = false;
viewer.Graph = drawingGraph;
}
}
}
- MSAGL samples 节点为 图片NodesWithImage
- Samples
- zedGraph后台保存图片,并设置节点为原点
- tree节点图片
- XtraTreelist添加节点图片
- Jit设置节点图片
- 判断节点为元素节点 HTML XML
- 手动为treeview添加节点
- 为GameObject添加子节点
- 世界转换为节点坐标
- 为集群增加新节点
- javascript为节点设置样式
- AutoComplete Samples
- lhgdialog - samples
- Ajaxcontroltoolkit/Samples
- CUDA Samples
- Opencv samples
- ios samples
- A LNK2005 error occurs when the CRT library and MFC libraries are linked in the wrong order in Visual C++
- vs设计页面卡死
- GetMessage与Peekmessage区别
- linux下的串口终端图形工具
- 大教堂和市集(The Cathedral and the Bazaar)
- MSAGL samples 节点为 图片NodesWithImage
- Win7快速启动栏设置及防止消失方法
- PCI配置空间和PCI存储空间
- BW中暴力激活的函数或程序
- iPhone SDK开发之 objective C property属性详解
- Android 动态更改布局
- ASP.NET(C#)-利用递归遍历文件夹和文件存入TreeView---转自360个人图书馆
- 谨以此文送给踏出校门正在求职的DDMM和刚刚踏上岗位的小菜
- eclipse关键字自动不全的设置方法!