Skip to content

Commit 7eaf984

Browse files
committed
Added STNodeEditor and translated to english
1 parent 8207da8 commit 7eaf984

17 files changed

+8026
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Data;
5+
using System.Drawing;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Windows.Forms;
9+
using System.Runtime.InteropServices;
10+
11+
namespace ST.Library.UI.NodeEditor
12+
{
13+
internal class FrmNodePreviewPanel : Form
14+
{
15+
public Color BorderColor { get; set; }
16+
public bool AutoBorderColor { get; set; }
17+
18+
private bool m_bRight;
19+
private Point m_ptHandle;
20+
private int m_nHandleSize;
21+
private Rectangle m_rect_handle;
22+
private Rectangle m_rect_panel;
23+
private Rectangle m_rect_exclude;
24+
private Region m_region;
25+
private Type m_type;
26+
private STNode m_node;
27+
private STNodeEditor m_editor;
28+
private STNodePropertyGrid m_property;
29+
30+
private Pen m_pen = new Pen(Color.Black);
31+
private SolidBrush m_brush = new SolidBrush(Color.Black);
32+
private static FrmNodePreviewPanel m_last_frm;
33+
34+
[DllImport("user32.dll")]
35+
private static extern int SetWindowRgn(IntPtr hWnd, IntPtr hRgn, bool bRedraw);
36+
37+
public FrmNodePreviewPanel(Type stNodeType, Point ptHandle, int nHandleSize, bool bRight, STNodeEditor editor, STNodePropertyGrid propertyGrid) {
38+
this.SetStyle(ControlStyles.UserPaint, true);
39+
this.SetStyle(ControlStyles.ResizeRedraw, true);
40+
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
41+
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
42+
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
43+
44+
if (m_last_frm != null) m_last_frm.Close();
45+
m_last_frm = this;
46+
47+
m_editor = editor;
48+
m_property = propertyGrid;
49+
m_editor.Size = new Size(200, 200);
50+
m_property.Size = new Size(200, 200);
51+
m_editor.Location = new Point(1 + (bRight ? nHandleSize : 0), 1);
52+
m_property.Location = new Point(m_editor.Right, 1);
53+
m_property.InfoFirstOnDraw = true;
54+
this.Controls.Add(m_editor);
55+
this.Controls.Add(m_property);
56+
this.ShowInTaskbar = false;
57+
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
58+
this.Size = new Size(402 + nHandleSize, 202);
59+
60+
m_type = stNodeType;
61+
m_ptHandle = ptHandle;
62+
m_nHandleSize = nHandleSize;
63+
m_bRight = bRight;
64+
65+
this.AutoBorderColor = true;
66+
this.BorderColor = Color.DodgerBlue;
67+
}
68+
69+
protected override void OnLoad(EventArgs e) {
70+
base.OnLoad(e);
71+
m_node = (STNode)Activator.CreateInstance(m_type);
72+
m_node.Left = 20; m_node.Top = 20;
73+
m_editor.Nodes.Add(m_node);
74+
m_property.SetNode(m_node);
75+
76+
m_rect_panel = new Rectangle(0, 0, 402, 202);
77+
m_rect_handle = new Rectangle(m_ptHandle.X, m_ptHandle.Y, m_nHandleSize, m_nHandleSize);
78+
m_rect_exclude = new Rectangle(0, m_nHandleSize, m_nHandleSize, this.Height - m_nHandleSize);
79+
if (m_bRight) {
80+
this.Left = m_ptHandle.X;
81+
m_rect_panel.X = m_ptHandle.X + m_nHandleSize;
82+
} else {
83+
this.Left = m_ptHandle.X - this.Width + m_nHandleSize;
84+
m_rect_exclude.X = this.Width - m_nHandleSize;
85+
m_rect_panel.X = this.Left;
86+
}
87+
if (m_ptHandle.Y + this.Height > Screen.GetWorkingArea(this).Bottom) {
88+
this.Top = m_ptHandle.Y - this.Height + m_nHandleSize;
89+
m_rect_exclude.Y -= m_nHandleSize;
90+
} else this.Top = m_ptHandle.Y;
91+
m_rect_panel.Y = this.Top;
92+
m_region = new Region(new Rectangle(Point.Empty, this.Size));
93+
m_region.Exclude(m_rect_exclude);
94+
using (Graphics g = this.CreateGraphics()) {
95+
IntPtr h = m_region.GetHrgn(g);
96+
FrmNodePreviewPanel.SetWindowRgn(this.Handle, h, false);
97+
m_region.ReleaseHrgn(h);
98+
}
99+
100+
this.MouseLeave += Event_MouseLeave;
101+
m_editor.MouseLeave += Event_MouseLeave;
102+
m_property.MouseLeave += Event_MouseLeave;
103+
this.BeginInvoke(new MethodInvoker(() => {
104+
m_property.Focus();
105+
}));
106+
}
107+
108+
protected override void OnClosing(CancelEventArgs e) {
109+
base.OnClosing(e);
110+
this.Controls.Clear();
111+
m_editor.Nodes.Clear();
112+
m_editor.MouseLeave -= Event_MouseLeave;
113+
m_property.MouseLeave -= Event_MouseLeave;
114+
m_last_frm = null;
115+
}
116+
117+
void Event_MouseLeave(object sender, EventArgs e) {
118+
Point pt = Control.MousePosition;
119+
if (m_rect_panel.Contains(pt) || m_rect_handle.Contains(pt)) return;
120+
this.Close();
121+
}
122+
123+
protected override void OnPaint(PaintEventArgs e) {
124+
base.OnPaint(e);
125+
Graphics g = e.Graphics;
126+
m_pen.Color = this.AutoBorderColor ? m_node.TitleColor : this.BorderColor;
127+
m_brush.Color = m_pen.Color;
128+
g.DrawRectangle(m_pen, 0, 0, this.Width - 1, this.Height - 1);
129+
g.FillRectangle(m_brush, m_rect_exclude.X - 1, m_rect_exclude.Y - 1, m_rect_exclude.Width + 2, m_rect_exclude.Height + 2);
130+
131+
Rectangle rect = this.RectangleToClient(m_rect_handle);
132+
rect.Y = (m_nHandleSize - 14) / 2;
133+
rect.X += rect.Y + 1;
134+
rect.Width = rect.Height = 14;
135+
m_pen.Width = 2;
136+
g.DrawLine(m_pen, rect.X + 4, rect.Y + 3, rect.X + 10, rect.Y + 3);
137+
g.DrawLine(m_pen, rect.X + 4, rect.Y + 6, rect.X + 10, rect.Y + 6);
138+
g.DrawLine(m_pen, rect.X + 4, rect.Y + 11, rect.X + 10, rect.Y + 11);
139+
g.DrawLine(m_pen, rect.X + 7, rect.Y + 7, rect.X + 7, rect.Y + 10);
140+
m_pen.Width = 1;
141+
g.DrawRectangle(m_pen, rect.X, rect.Y, rect.Width - 1, rect.Height - 1);
142+
}
143+
}
144+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
using System.Windows.Forms;
7+
using System.Drawing;
8+
using ST.Library.UI.NodeEditor;
9+
10+
namespace ST.Library.UI
11+
{
12+
internal class FrmSTNodePropertyInput : Form
13+
{
14+
private STNodePropertyDescriptor m_descriptor;
15+
private Rectangle m_rect;
16+
private Pen m_pen;
17+
private SolidBrush m_brush;
18+
private TextBox m_tbx;
19+
20+
public FrmSTNodePropertyInput(STNodePropertyDescriptor descriptor) {
21+
this.SetStyle(ControlStyles.UserPaint, true);
22+
this.SetStyle(ControlStyles.ResizeRedraw, true);
23+
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
24+
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
25+
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
26+
27+
m_rect = descriptor.RectangleR;
28+
m_descriptor = descriptor;
29+
this.ShowInTaskbar = false;
30+
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
31+
this.BackColor = descriptor.Control.AutoColor ? descriptor.Node.TitleColor : descriptor.Control.ItemSelectedColor;
32+
m_pen = new Pen(descriptor.Control.ForeColor, 1);
33+
m_brush = new SolidBrush(this.BackColor);
34+
}
35+
36+
protected override void OnLoad(EventArgs e) {
37+
base.OnLoad(e);
38+
Point pt = m_descriptor.Control.PointToScreen(m_rect.Location);
39+
pt.Y += m_descriptor.Control.ScrollOffset;
40+
this.Location = pt;
41+
this.Size = new System.Drawing.Size(m_rect.Width + m_rect.Height, m_rect.Height);
42+
43+
m_tbx = new TextBox();
44+
m_tbx.Font = m_descriptor.Control.Font;
45+
m_tbx.ForeColor = m_descriptor.Control.ForeColor;
46+
m_tbx.BackColor = Color.FromArgb(255, m_descriptor.Control.ItemValueBackColor);
47+
m_tbx.BorderStyle = BorderStyle.None;
48+
49+
m_tbx.Size = new Size(this.Width - 4 - m_rect.Height, this.Height - 2);
50+
m_tbx.Text = m_descriptor.GetStringFromValue();
51+
this.Controls.Add(m_tbx);
52+
m_tbx.Location = new Point(2, (this.Height - m_tbx.Height) / 2);
53+
m_tbx.SelectAll();
54+
m_tbx.LostFocus += (s, ea) => this.Close();
55+
m_tbx.KeyDown += new KeyEventHandler(tbx_KeyDown);
56+
}
57+
58+
protected override void OnPaint(PaintEventArgs e) {
59+
base.OnPaint(e);
60+
Graphics g = e.Graphics;
61+
m_brush.Color = m_tbx.BackColor;
62+
g.FillRectangle(m_brush, 1, 1, this.Width - 2 - m_rect.Height, this.Height - 2);
63+
m_brush.Color = m_descriptor.Control.ForeColor;
64+
//Enter
65+
g.FillPolygon(m_brush, new Point[]{
66+
new Point(this.Width - 21, this.Height - 2),
67+
new Point(this.Width - 14, this.Height - 2),
68+
new Point(this.Width - 14, this.Height - 8)
69+
});
70+
g.DrawLine(m_pen, this.Width - 14, this.Height - 3, this.Width - 4, this.Height - 3);
71+
g.DrawLine(m_pen, this.Width - 4, this.Height - 3, this.Width - 4, 14);
72+
g.DrawLine(m_pen, this.Width - 8, 13, this.Width - 4, 13);
73+
//----
74+
g.DrawLine(m_pen, this.Width - 19, 11, this.Width - 4, 11);
75+
//E
76+
g.DrawLine(m_pen, this.Width - 19, 3, this.Width - 16, 3);
77+
g.DrawLine(m_pen, this.Width - 19, 6, this.Width - 16, 6);
78+
g.DrawLine(m_pen, this.Width - 19, 9, this.Width - 16, 9);
79+
g.DrawLine(m_pen, this.Width - 19, 3, this.Width - 19, 9);
80+
//S
81+
g.DrawLine(m_pen, this.Width - 13, 3, this.Width - 10, 3);
82+
g.DrawLine(m_pen, this.Width - 13, 6, this.Width - 10, 6);
83+
g.DrawLine(m_pen, this.Width - 13, 9, this.Width - 10, 9);
84+
g.DrawLine(m_pen, this.Width - 13, 3, this.Width - 13, 6);
85+
g.DrawLine(m_pen, this.Width - 10, 6, this.Width - 10, 9);
86+
//C
87+
g.DrawLine(m_pen, this.Width - 7, 3, this.Width - 4, 3);
88+
g.DrawLine(m_pen, this.Width - 7, 9, this.Width - 4, 9);
89+
g.DrawLine(m_pen, this.Width - 7, 3, this.Width - 7, 9);
90+
}
91+
92+
void tbx_KeyDown(object sender, KeyEventArgs e) {
93+
if (e.KeyCode == Keys.Escape) this.Close();
94+
if (e.KeyCode != Keys.Enter) return;
95+
try {
96+
m_descriptor.SetValue(((TextBox)sender).Text, null);
97+
m_descriptor.Control.Invalidate();//add rect;
98+
} catch (Exception ex) {
99+
m_descriptor.OnSetValueError(ex);
100+
}
101+
this.Close();
102+
}
103+
104+
private void InitializeComponent() {
105+
this.SuspendLayout();
106+
//
107+
// FrmSTNodePropertyInput
108+
//
109+
this.ClientSize = new System.Drawing.Size(292, 273);
110+
this.Name = "FrmSTNodePropertyInput";
111+
this.ResumeLayout(false);
112+
}
113+
}
114+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
using System.Windows.Forms;
7+
using System.Drawing;
8+
9+
namespace ST.Library.UI.NodeEditor
10+
{
11+
internal class FrmSTNodePropertySelect : Form
12+
{
13+
private STNodePropertyDescriptor m_descriptor;
14+
private int m_nItemHeight = 25;
15+
16+
private static Type m_t_bool = typeof(bool);
17+
private Pen m_pen;
18+
private SolidBrush m_brush;
19+
private StringFormat m_sf;
20+
private Color m_clr_item_1 = Color.FromArgb(10, 0, 0, 0);// Color.FromArgb(255, 40, 40, 40);
21+
private Color m_clr_item_2 = Color.FromArgb(10, 255, 255, 255);// Color.FromArgb(255, 50, 50, 50);
22+
private object m_item_hover;
23+
24+
public FrmSTNodePropertySelect(STNodePropertyDescriptor descriptor) {
25+
this.SetStyle(ControlStyles.UserPaint, true);
26+
this.SetStyle(ControlStyles.ResizeRedraw, true);
27+
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
28+
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
29+
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
30+
31+
m_descriptor = descriptor;
32+
this.Size = descriptor.RectangleR.Size;
33+
this.ShowInTaskbar = false;
34+
this.BackColor = descriptor.Control.BackColor;
35+
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
36+
m_pen = new Pen(descriptor.Control.AutoColor ? descriptor.Node.TitleColor : descriptor.Control.ItemSelectedColor, 1);
37+
m_brush = new SolidBrush(this.BackColor);
38+
m_sf = new StringFormat();
39+
m_sf.LineAlignment = StringAlignment.Center;
40+
m_sf.FormatFlags = StringFormatFlags.NoWrap;
41+
}
42+
43+
private List<object> m_lst_item = new List<object>();
44+
45+
protected override void OnLoad(EventArgs e) {
46+
base.OnLoad(e);
47+
Point pt = m_descriptor.Control.PointToScreen(m_descriptor.RectangleR.Location);
48+
pt.Y += m_descriptor.Control.ScrollOffset;
49+
this.Location = pt;
50+
if (m_descriptor.PropertyInfo.PropertyType.IsEnum) {
51+
foreach (var v in Enum.GetValues(m_descriptor.PropertyInfo.PropertyType)) m_lst_item.Add(v);
52+
} else if (m_descriptor.PropertyInfo.PropertyType == m_t_bool) {
53+
m_lst_item.Add(true);
54+
m_lst_item.Add(false);
55+
} else {
56+
this.Close();
57+
return;
58+
}
59+
this.Height = m_lst_item.Count * m_nItemHeight;
60+
Rectangle rect = Screen.GetWorkingArea(this);
61+
if (this.Bottom > rect.Bottom) this.Top -= (this.Bottom - rect.Bottom);
62+
this.MouseLeave += (s, ea) => this.Close();
63+
this.LostFocus += (s, ea) => this.Close();
64+
}
65+
66+
protected override void OnPaint(PaintEventArgs e) {
67+
base.OnPaint(e);
68+
Graphics g = e.Graphics;
69+
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
70+
Rectangle rect_back = new Rectangle(0, 0, this.Width, m_nItemHeight);
71+
Rectangle rect_font = new Rectangle(10, 0, this.Width - 13, m_nItemHeight);
72+
int nIndex = 0;
73+
string strVal = m_descriptor.GetStringFromValue();
74+
foreach (var v in m_lst_item) {
75+
m_brush.Color = nIndex++ % 2 == 0 ? m_clr_item_1 : m_clr_item_2;
76+
g.FillRectangle(m_brush, rect_back);
77+
if (v == m_item_hover) {
78+
m_brush.Color = m_descriptor.Control.ItemHoverColor;
79+
g.FillRectangle(m_brush, rect_back);
80+
}
81+
if (v.ToString() == strVal) {
82+
m_brush.Color = m_descriptor.Control.ItemSelectedColor;
83+
g.FillRectangle(m_brush, 4, rect_back.Top + 10, 5, 5);
84+
}
85+
m_brush.Color = m_descriptor.Control.ForeColor;
86+
g.DrawString(v.ToString(), m_descriptor.Control.Font, m_brush, rect_font, m_sf);
87+
rect_back.Y += m_nItemHeight;
88+
rect_font.Y += m_nItemHeight;
89+
}
90+
g.DrawRectangle(m_pen, 0, 0, this.Width - 1, this.Height - 1);
91+
}
92+
93+
protected override void OnMouseMove(MouseEventArgs e) {
94+
base.OnMouseMove(e);
95+
int nIndex = e.Y / m_nItemHeight;
96+
if (nIndex < 0 || nIndex >= m_lst_item.Count) return;
97+
var item = m_lst_item[e.Y / m_nItemHeight];
98+
if (m_item_hover == item) return;
99+
m_item_hover = item;
100+
this.Invalidate();
101+
}
102+
103+
protected override void OnMouseClick(MouseEventArgs e) {
104+
base.OnMouseClick(e);
105+
this.Close();
106+
int nIndex = e.Y / m_nItemHeight;
107+
if (nIndex < 0) return;
108+
if (nIndex > m_lst_item.Count) return;
109+
try {
110+
m_descriptor.SetValue(m_lst_item[nIndex], null);
111+
} catch (Exception ex) {
112+
m_descriptor.OnSetValueError(ex);
113+
}
114+
}
115+
}
116+
}

0 commit comments

Comments
 (0)