diff --git a/ST.Library.UI/ST.Library.UI.csproj b/ST.Library.UI/ST.Library.UI.csproj index e915560..f847233 100755 --- a/ST.Library.UI/ST.Library.UI.csproj +++ b/ST.Library.UI/ST.Library.UI.csproj @@ -23,13 +23,14 @@ 4 - none + pdbonly true bin\Release\ TRACE prompt 4 bin\Release\ST.Library.UI.XML + true diff --git a/ST.Library.UI/STNodeEditor/STNode.cs b/ST.Library.UI/STNodeEditor/STNode.cs index 5119534..c9598a7 100755 --- a/ST.Library.UI/STNodeEditor/STNode.cs +++ b/ST.Library.UI/STNodeEditor/STNode.cs @@ -48,10 +48,11 @@ namespace ST.Library.UI internal set { if (value == _Owner) return; if (_Owner != null) { - foreach (STNodeOption op in this._InputOptions) op.DisConnectionAll(); - foreach (STNodeOption op in this._OutputOptions) op.DisConnectionAll(); + foreach (STNodeOption op in this._InputOptions.ToArray()) op.DisConnectionAll(); + foreach (STNodeOption op in this._OutputOptions.ToArray()) op.DisConnectionAll(); } _Owner = value; + this.BuildSize(true, true, false); this.OnOwnerChanged(); } } @@ -368,8 +369,14 @@ namespace ST.Library.UI set { _Tag = value; } } - private bool m_isBuildNodeSize; - private bool m_isBuildMarkSize; + private Guid _Guid; + /// + /// 获取全局唯一标识 + /// + public Guid Guid { + get { return _Guid; } + } + private static Point m_static_pt_init = new Point(10, 10); public STNode(/*string strTitle, int x, int y*/) { @@ -395,6 +402,7 @@ namespace ST.Library.UI m_sf.SetTabStops(0, new float[] { 40 }); m_static_pt_init.X += 10; m_static_pt_init.Y += 10; + this._Guid = Guid.NewGuid(); this.OnCreate(); } @@ -409,30 +417,34 @@ namespace ST.Library.UI /// protected STNodeControl m_ctrl_hover; - public void BuildSize(bool bBuildNode, bool bBuildMark, bool bRedraw) { - m_isBuildNodeSize = bBuildNode; - m_isBuildMarkSize = bBuildMark; - if (bRedraw) { - if (this._Owner != null) this._Owner.Invalidate(); - } - } - - internal void CheckSize(DrawingTools dt) { - if (m_isBuildNodeSize) { - Size sz = this.OnBuildNodeSize(dt); - this._Width = sz.Width; - this._Height = sz.Height; - m_isBuildNodeSize = false; - } - if (m_isBuildMarkSize) { - m_isBuildMarkSize = true; - if (string.IsNullOrEmpty(this._Mark)) return; - this._MarkRectangle = this.OnBuildMarkRectangle(dt); + protected internal void BuildSize(bool bBuildNode, bool bBuildMark, bool bRedraw) { + if (this._Owner == null) return; + Pen p = new Pen(this._BackColor); + SolidBrush sb = new SolidBrush(this._BackColor); + using (Graphics g = this._Owner.CreateGraphics()) { + DrawingTools dt = new DrawingTools() { + Graphics = g, + Pen = p, + SolidBrush = sb + }; + if (bBuildNode) { + Size sz = this.OnBuildNodeSize(dt); + this._Width = sz.Width; + this._Height = sz.Height; + this.SetOptionLocation(); + this.OnResize(new EventArgs()); + } + if (bBuildMark) { + if (string.IsNullOrEmpty(this._Mark)) return; + this._MarkRectangle = this.OnBuildMarkRectangle(dt); + } } + if (bRedraw) this._Owner.Invalidate(); } internal Dictionary OnSaveNode() { Dictionary dic = new Dictionary(); + dic.Add("Guid", this._Guid.ToByteArray()); dic.Add("Left", BitConverter.GetBytes(this._Left)); dic.Add("Top", BitConverter.GetBytes(this._Top)); dic.Add("Mark", string.IsNullOrEmpty(this._Mark) ? new byte[] { 0 } : Encoding.UTF8.GetBytes(this._Mark)); @@ -444,7 +456,11 @@ namespace ST.Library.UI internal virtual byte[] GetSaveData() { List lst = new List(); - byte[] byData = Encoding.UTF8.GetBytes(this.GetType().GUID.ToString()); + Type t = this.GetType(); + byte[] byData = Encoding.UTF8.GetBytes(t.Module.Name); + lst.Add((byte)byData.Length); + lst.AddRange(byData); + byData = Encoding.UTF8.GetBytes(t.GUID.ToString()); lst.Add((byte)byData.Length); lst.AddRange(byData); @@ -552,31 +568,13 @@ namespace ST.Library.UI /// 绘制工具 protected virtual void OnDrawBody(DrawingTools dt) { SolidBrush brush = dt.SolidBrush; - Rectangle rect = new Rectangle(this.Left + 10, this._Top + this._TitleHeight, this._Width - 20, m_nItemHeight); - m_sf.Alignment = StringAlignment.Near; foreach (STNodeOption op in this._InputOptions) { - brush.Color = op.TextColor;// this._ForeColor; - dt.Graphics.DrawString(op.Text, this._Font, brush, rect, m_sf); - op.DotLeft = this.Left - 5; - op.DotTop = rect.Y + 5; - Point pt = this.OnSetOptionLocation(op); - op.DotLeft = pt.X; - op.DotTop = pt.Y; this.OnDrawOptionDot(dt, op); - rect.Y += m_nItemHeight; + this.OnDrawOptionText(dt, op); } - rect.Y = this._Top + this._TitleHeight; - m_sf.Alignment = StringAlignment.Far; foreach (STNodeOption op in this._OutputOptions) { - brush.Color = op.TextColor;// this._ForeColor; - dt.Graphics.DrawString(op.Text, this._Font, brush, rect, m_sf); - op.DotLeft = this.Left + this.Width - 5; - op.DotTop = rect.Y + 5; - Point pt = this.OnSetOptionLocation(op); - op.DotLeft = pt.X; - op.DotTop = pt.Y; this.OnDrawOptionDot(dt, op); - rect.Y += m_nItemHeight; + this.OnDrawOptionText(dt, op); } if (this._Controls.Count != 0) { //绘制子控件 //将坐标原点与节点对齐 @@ -655,12 +653,38 @@ namespace ST.Library.UI } } /// - /// 当计算Option位置时候发生 + /// 绘制选项的文本 + /// + /// 绘制工具 + /// 指定的选项 + protected virtual void OnDrawOptionText(DrawingTools dt, STNodeOption op) { + Graphics g = dt.Graphics; + SolidBrush brush = dt.SolidBrush; + if (op.IsInput) { + m_sf.Alignment = StringAlignment.Near; + } else { + m_sf.Alignment = StringAlignment.Far; + } + brush.Color = op.TextColor; + g.DrawString(op.Text, this.Font, brush, op.TextRectangle, m_sf); + } + /// + /// 当计算Option连线点位置时候发生 /// /// 需要计算的Option + /// 自动计算出的位置 /// 新的位置 - protected virtual Point OnSetOptionLocation(STNodeOption op) { - return new Point(op.DotLeft, op.DotTop); + protected virtual Point OnSetOptionDotLocation(STNodeOption op, Point pt) { + return pt; + } + /// + /// 当计算Option文本区域时候发生 + /// + /// 需要计算的Option + /// 自动计算出的区域 + /// 新的区域 + protected virtual Rectangle OnSetOptionTextRectangle(STNodeOption op, Rectangle rect) { + return rect; } /// /// 计算当前Node所需要的矩形区域 @@ -712,6 +736,7 @@ namespace ST.Library.UI /// /// 保存时候的数据 protected internal virtual void OnLoadNode(Dictionary dic) { + if (dic.ContainsKey("Guid")) this._Guid = new Guid(dic["Guid"]); if (dic.ContainsKey("Left")) this._Left = BitConverter.ToInt32(dic["Left"], 0); if (dic.ContainsKey("Top")) this._Top = BitConverter.ToInt32(dic["Top"], 0); if (dic.ContainsKey("Mark")) { @@ -721,6 +746,12 @@ namespace ST.Library.UI if (dic.ContainsKey("LockOption")) this._LockOption = dic["LockOption"][0] == 1; if (dic.ContainsKey("LockLocation")) this._LockLocation = dic["LockLocation"][0] == 1; } + /// + /// 当编辑器加载完成所有的节点时候发生 + /// + protected internal virtual void OnEditorLoadCompleted() { + + } //[event]===========================[event]==============================[event]============================[event] @@ -821,8 +852,8 @@ namespace ST.Library.UI if (m_ctrl_active != null) m_ctrl_active.OnKeyPress(e); } - protected internal virtual void OnMove(EventArgs e) { } - protected internal virtual void OnResize(EventArgs e) { } + protected internal virtual void OnMove(EventArgs e) { this.SetOptionLocation(); } + protected internal virtual void OnResize(EventArgs e) { this.SetOptionLocation(); } /// @@ -840,6 +871,26 @@ namespace ST.Library.UI #endregion protected + private void SetOptionLocation() { + Rectangle rect = new Rectangle(this.Left + 10, this._Top + this._TitleHeight, this._Width - 20, m_nItemHeight); + foreach (STNodeOption op in this._InputOptions) { + Point pt = this.OnSetOptionDotLocation(op, new Point(this.Left - 5, rect.Y + 5)); + op.TextRectangle = this.OnSetOptionTextRectangle(op, rect); + op.DotLeft = pt.X; + op.DotTop = pt.Y; + rect.Y += m_nItemHeight; + } + rect.Y = this._Top + this._TitleHeight; + m_sf.Alignment = StringAlignment.Far; + foreach (STNodeOption op in this._OutputOptions) { + Point pt = this.OnSetOptionDotLocation(op, new Point(this._Left + this._Width - 5, rect.Y + 5)); + op.TextRectangle = this.OnSetOptionTextRectangle(op, rect); + op.DotLeft = pt.X; + op.DotTop = pt.Y; + rect.Y += m_nItemHeight; + } + } + /// /// 重绘Node /// diff --git a/ST.Library.UI/STNodeEditor/STNodeCollection.cs b/ST.Library.UI/STNodeEditor/STNodeCollection.cs index 18eac67..6d23e01 100755 --- a/ST.Library.UI/STNodeEditor/STNodeCollection.cs +++ b/ST.Library.UI/STNodeEditor/STNodeCollection.cs @@ -27,7 +27,7 @@ namespace ST.Library.UI if (-1 == nIndex) { nIndex = this._Count; node.Owner = m_owner; - node.BuildSize(true, true, false); + //node.BuildSize(true, true, false); m_nodes[this._Count++] = node; m_owner.BuildBounds(); m_owner.OnNodeAdded(new STNodeEditorEventArgs(node)); @@ -87,7 +87,7 @@ namespace ST.Library.UI node.Owner = m_owner; m_nodes[nIndex] = node; this._Count++; - node.BuildSize(true, true,false); + //node.BuildSize(true, true,false); m_owner.Invalidate(); m_owner.BuildBounds(); } @@ -225,5 +225,12 @@ namespace ST.Library.UI IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } + + public STNode[] ToArray() { + STNode[] nodes = new STNode[this._Count]; + for (int i = 0; i < nodes.Length; i++) + nodes[i] = m_nodes[i]; + return nodes; + } } } diff --git a/ST.Library.UI/STNodeEditor/STNodeEditor.cs b/ST.Library.UI/STNodeEditor/STNodeEditor.cs index b8b0597..aaed817 100755 --- a/ST.Library.UI/STNodeEditor/STNodeEditor.cs +++ b/ST.Library.UI/STNodeEditor/STNodeEditor.cs @@ -10,6 +10,7 @@ using System.Drawing.Drawing2D; using System.Threading; using System.ComponentModel; using System.Reflection; +using System.IO.Compression; /* MIT License @@ -632,11 +633,12 @@ namespace ST.Library.UI g.TranslateTransform(this._CanvasOffsetX, this._CanvasOffsetY); //移动坐标系 g.ScaleTransform(this._CanvasScale, this._CanvasScale); //缩放绘图表面 - this.OnDrawNode(m_drawing_tools, this.ControlToCanvas(this.ClientRectangle)); this.OnDrawConnectedLine(m_drawing_tools); + this.OnDrawNode(m_drawing_tools, this.ControlToCanvas(this.ClientRectangle)); if (m_ca == CanvasAction.ConnectOption) { //如果正在连线 m_drawing_tools.Pen.Color = this._HighLineColor; + g.SmoothingMode = SmoothingMode.HighQuality; if (m_option_down.IsInput) this.DrawBezier(g, m_drawing_tools.Pen, m_pt_in_canvas, m_pt_dot_down, this._Curvature); else @@ -777,21 +779,23 @@ namespace ST.Library.UI this.OnHoverChanged(new EventArgs()); bRedraw = true; } - if (this._HoverNode != null) + if (this._HoverNode != null) { this._HoverNode.OnMouseMove(new MouseEventArgs(e.Button, e.Clicks, (int)m_pt_in_canvas.X - this._HoverNode.Left, (int)m_pt_in_canvas.Y - this._HoverNode.Top, e.Delta)); - - GraphicsPath gp = null; - foreach (var v in m_dic_gp_info) { //判断鼠标是否悬停到连线路径上 - if (v.Key.IsOutlineVisible(m_pt_in_canvas, m_p_line_hover)) { - gp = v.Key; - break; + m_gp_hover = null; + } else { + GraphicsPath gp = null; + foreach (var v in m_dic_gp_info) { //判断鼠标是否悬停到连线路径上 + if (v.Key.IsOutlineVisible(m_pt_in_canvas, m_p_line_hover)) { + gp = v.Key; + break; + } + } + if (m_gp_hover != gp) { + m_gp_hover = gp; + bRedraw = true; } - } - if (m_gp_hover != gp) { - m_gp_hover = gp; - bRedraw = true; } if (bRedraw) this.Invalidate(); } @@ -942,7 +946,7 @@ namespace ST.Library.UI //var rect_canvas_display = this.ControlToCanvas(rect); Image img_border = null; foreach (STNode n in this._Nodes) { - n.CheckSize(dt); + //n.CheckSize(dt); img_border = m_img_border; if (this._ShowBorder) { //如果绘制边框 判断状态 if (this._ActiveNode == n) img_border = m_img_border_active; @@ -1701,24 +1705,26 @@ namespace ST.Library.UI Dictionary dic = new Dictionary(); s.Write(new byte[] { (byte)'S', (byte)'T', (byte)'N', (byte)'D' }, 0, 4); //file head s.WriteByte(1); //ver - s.Write(BitConverter.GetBytes(this._CanvasOffsetX), 0, 4); - s.Write(BitConverter.GetBytes(this._CanvasOffsetY), 0, 4); - s.Write(BitConverter.GetBytes(this._CanvasScale), 0, 4); - s.Write(BitConverter.GetBytes(this._Nodes.Count), 0, 4); - foreach (STNode node in this._Nodes) { - try { - byte[] byNode = node.GetSaveData(); - s.Write(BitConverter.GetBytes(byNode.Length), 0, 4); - s.Write(byNode, 0, byNode.Length); - foreach (STNodeOption op in node.InputOptions) dic.Add(op, dic.Count); - foreach (STNodeOption op in node.OutputOptions) dic.Add(op, dic.Count); - } catch (Exception ex) { - throw new Exception("获取节点数据出错-" + node.Title, ex); + using (GZipStream gs = new GZipStream(s, CompressionMode.Compress)) { + gs.Write(BitConverter.GetBytes(this._CanvasOffsetX), 0, 4); + gs.Write(BitConverter.GetBytes(this._CanvasOffsetY), 0, 4); + gs.Write(BitConverter.GetBytes(this._CanvasScale), 0, 4); + gs.Write(BitConverter.GetBytes(this._Nodes.Count), 0, 4); + foreach (STNode node in this._Nodes) { + try { + byte[] byNode = node.GetSaveData(); + gs.Write(BitConverter.GetBytes(byNode.Length), 0, 4); + gs.Write(byNode, 0, byNode.Length); + foreach (STNodeOption op in node.InputOptions) dic.Add(op, dic.Count); + foreach (STNodeOption op in node.OutputOptions) dic.Add(op, dic.Count); + } catch (Exception ex) { + throw new Exception("获取节点数据出错-" + node.Title, ex); + } } + gs.Write(BitConverter.GetBytes(m_dic_gp_info.Count), 0, 4); + foreach (var v in m_dic_gp_info.Values) + gs.Write(BitConverter.GetBytes(((dic[v.Output] << 32) | dic[v.Input])), 0, 8); } - s.Write(BitConverter.GetBytes(m_dic_gp_info.Count), 0, 4); - foreach (var v in m_dic_gp_info.Values) - s.Write(BitConverter.GetBytes(((dic[v.Output] << 32) | dic[v.Input])), 0, 8); } /// /// 获取画布中内容二进制数据 @@ -1800,42 +1806,53 @@ namespace ST.Library.UI if (BitConverter.ToInt32(byLen, 0) != BitConverter.ToInt32(new byte[] { (byte)'S', (byte)'T', (byte)'N', (byte)'D' }, 0)) throw new InvalidDataException("无法识别的文件类型"); if (s.ReadByte() != 1) throw new InvalidDataException("无法识别的文件版本号"); - s.Read(byLen, 0, 4); - float x = BitConverter.ToSingle(byLen, 0); - s.Read(byLen, 0, 4); - float y = BitConverter.ToSingle(byLen, 0); - s.Read(byLen, 0, 4); - float scale = BitConverter.ToSingle(byLen, 0); - s.Read(byLen, 0, 4); - int nCount = BitConverter.ToInt32(byLen, 0); - Dictionary dic = new Dictionary(); - byte[] byData = null; - for (int i = 0; i < nCount; i++) { - s.Read(byLen, 0, byLen.Length); - nLen = BitConverter.ToInt32(byLen, 0); - byData = new byte[nLen]; - s.Read(byData, 0, byData.Length); - STNode node = this.GetNodeFromData(byData); - try { this._Nodes.Add(node); } catch (Exception ex) { throw new Exception("加载节点出错-" + node.Title, ex); } - foreach (STNodeOption op in node.InputOptions) dic.Add(dic.Count, op); - foreach (STNodeOption op in node.OutputOptions) dic.Add(dic.Count, op); + using (GZipStream gs = new GZipStream(s, CompressionMode.Decompress)) { + gs.Read(byLen, 0, 4); + float x = BitConverter.ToSingle(byLen, 0); + gs.Read(byLen, 0, 4); + float y = BitConverter.ToSingle(byLen, 0); + gs.Read(byLen, 0, 4); + float scale = BitConverter.ToSingle(byLen, 0); + gs.Read(byLen, 0, 4); + int nCount = BitConverter.ToInt32(byLen, 0); + Dictionary dic = new Dictionary(); + byte[] byData = null; + for (int i = 0; i < nCount; i++) { + gs.Read(byLen, 0, byLen.Length); + nLen = BitConverter.ToInt32(byLen, 0); + byData = new byte[nLen]; + gs.Read(byData, 0, byData.Length); + STNode node = null; + try { node = this.GetNodeFromData(byData); } catch (Exception ex) { + throw new Exception("加载节点时发生错误可能数据已损坏\r\n" + ex.Message, ex); + } + try { this._Nodes.Add(node); } catch (Exception ex) { + throw new Exception("加载节点出错-" + node.Title, ex); + } + foreach (STNodeOption op in node.InputOptions) dic.Add(dic.Count, op); + foreach (STNodeOption op in node.OutputOptions) dic.Add(dic.Count, op); + } + gs.Read(byLen, 0, 4); + nCount = BitConverter.ToInt32(byLen, 0); + byData = new byte[8]; + for (int i = 0; i < nCount; i++) { + gs.Read(byData, 0, byData.Length); + long id = BitConverter.ToInt64(byData, 0); + long op_out = id >> 32; + long op_in = (int)id; + dic[op_out].ConnectOption(dic[op_in]); + } + this.ScaleCanvas(scale, 0, 0); + this.MoveCanvas(x, y, false, CanvasMoveArgs.All); } - s.Read(byLen, 0, 4); - nCount = BitConverter.ToInt32(byLen, 0); - byData = new byte[8]; - for (int i = 0; i < nCount; i++) { - s.Read(byData, 0, byData.Length); - long id = BitConverter.ToInt64(byData, 0); - long op_out = id >> 32; - long op_in = (int)id; - dic[op_out].ConnectOption(dic[op_in]); - } - this.ScaleCanvas(scale, 0, 0); - this.MoveCanvas(x, y, false, CanvasMoveArgs.All); this.BuildBounds(); + foreach (STNode node in this._Nodes) node.OnEditorLoadCompleted(); } + private STNode GetNodeFromData(byte[] byData) { int nIndex = 0; + string strModel = Encoding.UTF8.GetString(byData, nIndex + 1, byData[nIndex]); + nIndex += byData[nIndex] + 1; string strGUID = Encoding.UTF8.GetString(byData, nIndex + 1, byData[nIndex]); nIndex += byData[nIndex] + 1; @@ -1854,7 +1871,7 @@ namespace ST.Library.UI nIndex += nLen; dic.Add(strKey, byValue); } - if (!m_dic_type.ContainsKey(strGUID)) throw new TypeLoadException("无法找到类型 {" + strGUID + "} 所在程序集 确保所需程序集已被编辑器正确加载 可通过调用LoadAssembly()加载程序集"); + if (!m_dic_type.ContainsKey(strGUID)) throw new TypeLoadException("无法找到类型 {" + strGUID + "} 所在程序集 确保程序集{" + strModel + "}已被编辑器正确加载 可通过调用LoadAssembly()加载程序集"); Type t = m_dic_type[strGUID]; ; STNode node = (STNode)Activator.CreateInstance(t); node.OnLoadNode(dic); diff --git a/ST.Library.UI/STNodeEditor/STNodeOption.cs b/ST.Library.UI/STNodeEditor/STNodeOption.cs index 8b96550..db11c63 100755 --- a/ST.Library.UI/STNodeEditor/STNodeOption.cs +++ b/ST.Library.UI/STNodeEditor/STNodeOption.cs @@ -103,7 +103,16 @@ namespace ST.Library.UI /// public int DotSize { get { return _DotSize; } - protected internal set { _DotSize = value; } + protected set { _DotSize = value; } + } + + private Rectangle _TextRectangle; + /// + /// 获取当前 Option 文本区域 + /// + public Rectangle TextRectangle { + get { return _TextRectangle; } + internal set { _TextRectangle = value; } } private object _Data; diff --git a/ST.Library.UI/STNodeEditor/STNodeOptionCollection.cs b/ST.Library.UI/STNodeEditor/STNodeOptionCollection.cs index 762a98d..e0902f5 100755 --- a/ST.Library.UI/STNodeEditor/STNodeOptionCollection.cs +++ b/ST.Library.UI/STNodeEditor/STNodeOptionCollection.cs @@ -220,5 +220,12 @@ namespace ST.Library.UI IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } + + public STNodeOption[] ToArray() { + STNodeOption[] ops = new STNodeOption[this._Count]; + for (int i = 0; i < ops.Length; i++) + ops[i] = m_options[i]; + return ops; + } } } \ No newline at end of file diff --git a/WinNodeEditerTest.suo b/WinNodeEditerTest.suo index a85da7b..732b6f1 100755 Binary files a/WinNodeEditerTest.suo and b/WinNodeEditerTest.suo differ diff --git a/WinNodeEditerTest/Demo_Image/STNodeImageInput.cs b/WinNodeEditerTest/Demo_Image/STNodeImageInput.cs index ec54ade..940e237 100755 --- a/WinNodeEditerTest/Demo_Image/STNodeImageInput.cs +++ b/WinNodeEditerTest/Demo_Image/STNodeImageInput.cs @@ -41,8 +41,8 @@ namespace ST.Library.UI.Demo_Image return m_sz; } - protected override Point OnSetOptionLocation(STNodeOption op) { - return new Point(op.DotLeft, this.Top + 35); + protected override Point OnSetOptionDotLocation(STNodeOption op, Point pt) { + return new Point(pt.X, pt.Y + 10); //return base.OnSetOptionLocation(op); } diff --git a/WinNodeEditerTest/Form1.cs b/WinNodeEditerTest/Form1.cs index 7102db6..2bdce0f 100755 --- a/WinNodeEditerTest/Form1.cs +++ b/WinNodeEditerTest/Form1.cs @@ -80,8 +80,8 @@ namespace ST.Library.UI OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "*.stn|*.stn"; if (ofd.ShowDialog() != DialogResult.OK) return; - stNodeEditor1.LoadCanvas(ofd.FileName); stNodeEditor1.Nodes.Clear(); + stNodeEditor1.LoadCanvas(ofd.FileName); } } } diff --git a/WinNodeEditerTest/Form2.Designer.cs b/WinNodeEditerTest/Form2.Designer.cs new file mode 100755 index 0000000..5392566 --- /dev/null +++ b/WinNodeEditerTest/Form2.Designer.cs @@ -0,0 +1,96 @@ +namespace ST.Library.UI +{ + partial class Form2 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) { + if (disposing && (components != null)) { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() { + this.button1 = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.button3 = new System.Windows.Forms.Button(); + this.button4 = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // button1 + // + this.button1.Location = new System.Drawing.Point(0, 0); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 23); + this.button1.TabIndex = 0; + this.button1.Text = "button1"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // button2 + // + this.button2.Location = new System.Drawing.Point(0, 29); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(75, 23); + this.button2.TabIndex = 1; + this.button2.Text = "button2"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); + // + // button3 + // + this.button3.Location = new System.Drawing.Point(0, 58); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(75, 23); + this.button3.TabIndex = 2; + this.button3.Text = "button3"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.button3_Click); + // + // button4 + // + this.button4.Location = new System.Drawing.Point(0, 87); + this.button4.Name = "button4"; + this.button4.Size = new System.Drawing.Size(75, 23); + this.button4.TabIndex = 3; + this.button4.Text = "button4"; + this.button4.UseVisualStyleBackColor = true; + this.button4.Click += new System.EventHandler(this.button4_Click); + // + // Form2 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(292, 273); + this.Controls.Add(this.button4); + this.Controls.Add(this.button3); + this.Controls.Add(this.button2); + this.Controls.Add(this.button1); + this.Name = "Form2"; + this.Text = "Form2"; + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.Button button3; + private System.Windows.Forms.Button button4; + } +} \ No newline at end of file diff --git a/WinNodeEditerTest/Form2.cs b/WinNodeEditerTest/Form2.cs new file mode 100755 index 0000000..c8457af --- /dev/null +++ b/WinNodeEditerTest/Form2.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +namespace ST.Library.UI +{ + public partial class Form2 : Form + { + public Form2() { + InitializeComponent(); + } + + Graphics m_g; + + private void button1_Click(object sender, EventArgs e) { + m_g = this.CreateGraphics(); + } + + private void button2_Click(object sender, EventArgs e) { + m_g.DrawRectangle(Pens.Red, 10, 10, 30, 30); + } + + private void button3_Click(object sender, EventArgs e) { + m_g.DrawRectangle(Pens.Yellow, 45, 45, 20, 20); + } + + private void button4_Click(object sender, EventArgs e) { + this.CreateGraphics().FillRectangle(Brushes.Black, 20, 20, 20, 20); + } + } +} diff --git a/WinNodeEditerTest/Form2.resx b/WinNodeEditerTest/Form2.resx new file mode 100755 index 0000000..29dcb1b --- /dev/null +++ b/WinNodeEditerTest/Form2.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/WinNodeEditerTest/NodeNumberAdd.cs b/WinNodeEditerTest/NodeNumberAdd.cs index d2c12e4..7d30aa9 100755 --- a/WinNodeEditerTest/NodeNumberAdd.cs +++ b/WinNodeEditerTest/NodeNumberAdd.cs @@ -28,7 +28,7 @@ namespace ST.Library.UI //当有数据传入时 void m_in_num_DataTransfer(object sender, STNodeOptionEventArgs e) { //判断连线是否是连接状态(建立连线 断开连线 都会触发该事件) - if (e.Status == ConnectionStatus.Connected) { + if (e.Status == ConnectionStatus.Connected && e.TargetOption.Data != null) { if (sender == m_in_num1) m_nNum1 = (int)e.TargetOption.Data;//TargetOption为触发此事件的Option else diff --git a/WinNodeEditerTest/WinNodeEditerTest.csproj b/WinNodeEditerTest/WinNodeEditerTest.csproj index 67964b8..b13a2df 100755 --- a/WinNodeEditerTest/WinNodeEditerTest.csproj +++ b/WinNodeEditerTest/WinNodeEditerTest.csproj @@ -64,6 +64,12 @@ Form1.cs + + Form + + + Form2.cs + @@ -73,6 +79,9 @@ Form1.cs + + Form2.cs + ResXFileCodeGenerator Resources.Designer.cs diff --git a/docs/doc.html b/docs/doc.html index acc910b..ab585a2 100755 --- a/docs/doc.html +++ b/docs/doc.html @@ -88,7 +88,7 @@ - 最后编辑时间 2020-12-30 + 最后编辑时间 2021-01-21

概述

@@ -595,21 +595,40 @@ void OnDrawMark(DrawingTools dt) dt绘制工具 - -   - 当计算Option位置时候发生 - Point OnSetOptionLocation(STNodeOption op) - - op需要计算的Option - -   +   绘制选项连线的点 void OnDrawOptionDot(DrawingTools dt, STNodeOption op) dt绘制工具 - op指定的选项 + op需要绘制的Option +   + 绘制选项的文本 + void OnDrawOptionText(DrawingTools dt, STNodeOption op) + + dt绘制工具 + + + op需要绘制的Option + +   + 当计算Option连线点位置时候发生 + Point OnSetOptionDotLocation(STNodeOption op, Point pt) + + op需要计算的Option + + + op自动计算出的位置 + +   + 当计算Option文本区域时候发生 + Rectangle OnSetOptionTextRectangle(STNodeOption op, Rectangle rect) + + op需要计算的Option + + + op自动计算出的区域   计算当前Node所需要的矩形区域 @@ -634,13 +653,18 @@ 当需要保存时候 此Node有哪些需要额外保存的数据 void OnSaveNode(Dictionary<string, byte[]>) - 保存时并不会进行序列化 仅自动保存Mark属性 还原时候仅重新通过空参数构造器创建此Node + + dic需要保存的数据 + + 保存时并不会进行序列化 仅自动保存部分(Guid,Left,Top,Mark,LockOption,LockLocation)属性 还原时候仅重新通过空参数构造器创建此Node
然后调用OnLoadNode()将保存的数据进行还原
- void OnLoadNode(Dictionary dic) + void OnLoadNode(Dictionary<string, byte[]> dic) dic保存时候的数据   + 当编辑器加载完成所有的节点时候发生 + void OnEditorLoadCompleted()
protected override void OnSaveNode(Dictionary<string, byte[]>) {
     dic.Add("count", BitConverter.GetBytes(this.InputOptionsCount));