Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 144 additions & 0 deletions ST.Library.UI/NodeEditor/FrmNodePreviewPanel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
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;
using System.Runtime.InteropServices;

namespace ST.Library.UI.NodeEditor
{
internal class FrmNodePreviewPanel : Form
{
public Color BorderColor { get; set; }
public bool AutoBorderColor { get; set; }

private bool m_bRight;
private Point m_ptHandle;
private int m_nHandleSize;
private Rectangle m_rect_handle;
private Rectangle m_rect_panel;
private Rectangle m_rect_exclude;
private Region m_region;
private Type m_type;
private STNode m_node;
private STNodeEditor m_editor;
private STNodePropertyGrid m_property;

private Pen m_pen = new Pen(Color.Black);
private SolidBrush m_brush = new SolidBrush(Color.Black);
private static FrmNodePreviewPanel m_last_frm;

[DllImport("user32.dll")]
private static extern int SetWindowRgn(IntPtr hWnd, IntPtr hRgn, bool bRedraw);

public FrmNodePreviewPanel(Type stNodeType, Point ptHandle, int nHandleSize, bool bRight, STNodeEditor editor, STNodePropertyGrid propertyGrid) {
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);

if (m_last_frm != null) m_last_frm.Close();
m_last_frm = this;

m_editor = editor;
m_property = propertyGrid;
m_editor.Size = new Size(200, 200);
m_property.Size = new Size(200, 200);
m_editor.Location = new Point(1 + (bRight ? nHandleSize : 0), 1);
m_property.Location = new Point(m_editor.Right, 1);
m_property.InfoFirstOnDraw = true;
this.Controls.Add(m_editor);
this.Controls.Add(m_property);
this.ShowInTaskbar = false;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Size = new Size(402 + nHandleSize, 202);

m_type = stNodeType;
m_ptHandle = ptHandle;
m_nHandleSize = nHandleSize;
m_bRight = bRight;

this.AutoBorderColor = true;
this.BorderColor = Color.DodgerBlue;
}

protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
m_node = (STNode)Activator.CreateInstance(m_type);
m_node.Left = 20; m_node.Top = 20;
m_editor.Nodes.Add(m_node);
m_property.SetNode(m_node);

m_rect_panel = new Rectangle(0, 0, 402, 202);
m_rect_handle = new Rectangle(m_ptHandle.X, m_ptHandle.Y, m_nHandleSize, m_nHandleSize);
m_rect_exclude = new Rectangle(0, m_nHandleSize, m_nHandleSize, this.Height - m_nHandleSize);
if (m_bRight) {
this.Left = m_ptHandle.X;
m_rect_panel.X = m_ptHandle.X + m_nHandleSize;
} else {
this.Left = m_ptHandle.X - this.Width + m_nHandleSize;
m_rect_exclude.X = this.Width - m_nHandleSize;
m_rect_panel.X = this.Left;
}
if (m_ptHandle.Y + this.Height > Screen.GetWorkingArea(this).Bottom) {
this.Top = m_ptHandle.Y - this.Height + m_nHandleSize;
m_rect_exclude.Y -= m_nHandleSize;
} else this.Top = m_ptHandle.Y;
m_rect_panel.Y = this.Top;
m_region = new Region(new Rectangle(Point.Empty, this.Size));
m_region.Exclude(m_rect_exclude);
using (Graphics g = this.CreateGraphics()) {
IntPtr h = m_region.GetHrgn(g);
FrmNodePreviewPanel.SetWindowRgn(this.Handle, h, false);
m_region.ReleaseHrgn(h);
}

this.MouseLeave += Event_MouseLeave;
m_editor.MouseLeave += Event_MouseLeave;
m_property.MouseLeave += Event_MouseLeave;
this.BeginInvoke(new MethodInvoker(() => {
m_property.Focus();
}));
}

protected override void OnClosing(CancelEventArgs e) {
base.OnClosing(e);
this.Controls.Clear();
m_editor.Nodes.Clear();
m_editor.MouseLeave -= Event_MouseLeave;
m_property.MouseLeave -= Event_MouseLeave;
m_last_frm = null;
}

void Event_MouseLeave(object sender, EventArgs e) {
Point pt = Control.MousePosition;
if (m_rect_panel.Contains(pt) || m_rect_handle.Contains(pt)) return;
this.Close();
}

protected override void OnPaint(PaintEventArgs e) {
base.OnPaint(e);
Graphics g = e.Graphics;
m_pen.Color = this.AutoBorderColor ? m_node.TitleColor : this.BorderColor;
m_brush.Color = m_pen.Color;
g.DrawRectangle(m_pen, 0, 0, this.Width - 1, this.Height - 1);
g.FillRectangle(m_brush, m_rect_exclude.X - 1, m_rect_exclude.Y - 1, m_rect_exclude.Width + 2, m_rect_exclude.Height + 2);

Rectangle rect = this.RectangleToClient(m_rect_handle);
rect.Y = (m_nHandleSize - 14) / 2;
rect.X += rect.Y + 1;
rect.Width = rect.Height = 14;
m_pen.Width = 2;
g.DrawLine(m_pen, rect.X + 4, rect.Y + 3, rect.X + 10, rect.Y + 3);
g.DrawLine(m_pen, rect.X + 4, rect.Y + 6, rect.X + 10, rect.Y + 6);
g.DrawLine(m_pen, rect.X + 4, rect.Y + 11, rect.X + 10, rect.Y + 11);
g.DrawLine(m_pen, rect.X + 7, rect.Y + 7, rect.X + 7, rect.Y + 10);
m_pen.Width = 1;
g.DrawRectangle(m_pen, rect.X, rect.Y, rect.Width - 1, rect.Height - 1);
}
}
}
114 changes: 114 additions & 0 deletions ST.Library.UI/NodeEditor/FrmSTNodePropertyInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Windows.Forms;
using System.Drawing;
using ST.Library.UI.NodeEditor;

namespace ST.Library.UI
{
internal class FrmSTNodePropertyInput : Form
{
private STNodePropertyDescriptor m_descriptor;
private Rectangle m_rect;
private Pen m_pen;
private SolidBrush m_brush;
private TextBox m_tbx;

public FrmSTNodePropertyInput(STNodePropertyDescriptor descriptor) {
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);

m_rect = descriptor.RectangleR;
m_descriptor = descriptor;
this.ShowInTaskbar = false;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.BackColor = descriptor.Control.AutoColor ? descriptor.Node.TitleColor : descriptor.Control.ItemSelectedColor;
m_pen = new Pen(descriptor.Control.ForeColor, 1);
m_brush = new SolidBrush(this.BackColor);
}

protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
Point pt = m_descriptor.Control.PointToScreen(m_rect.Location);
pt.Y += m_descriptor.Control.ScrollOffset;
this.Location = pt;
this.Size = new System.Drawing.Size(m_rect.Width + m_rect.Height, m_rect.Height);

m_tbx = new TextBox();
m_tbx.Font = m_descriptor.Control.Font;
m_tbx.ForeColor = m_descriptor.Control.ForeColor;
m_tbx.BackColor = Color.FromArgb(255, m_descriptor.Control.ItemValueBackColor);
m_tbx.BorderStyle = BorderStyle.None;

m_tbx.Size = new Size(this.Width - 4 - m_rect.Height, this.Height - 2);
m_tbx.Text = m_descriptor.GetStringFromValue();
this.Controls.Add(m_tbx);
m_tbx.Location = new Point(2, (this.Height - m_tbx.Height) / 2);
m_tbx.SelectAll();
m_tbx.LostFocus += (s, ea) => this.Close();
m_tbx.KeyDown += new KeyEventHandler(tbx_KeyDown);
}

protected override void OnPaint(PaintEventArgs e) {
base.OnPaint(e);
Graphics g = e.Graphics;
m_brush.Color = m_tbx.BackColor;
g.FillRectangle(m_brush, 1, 1, this.Width - 2 - m_rect.Height, this.Height - 2);
m_brush.Color = m_descriptor.Control.ForeColor;
//Enter
g.FillPolygon(m_brush, new Point[]{
new Point(this.Width - 21, this.Height - 2),
new Point(this.Width - 14, this.Height - 2),
new Point(this.Width - 14, this.Height - 8)
});
g.DrawLine(m_pen, this.Width - 14, this.Height - 3, this.Width - 4, this.Height - 3);
g.DrawLine(m_pen, this.Width - 4, this.Height - 3, this.Width - 4, 14);
g.DrawLine(m_pen, this.Width - 8, 13, this.Width - 4, 13);
//----
g.DrawLine(m_pen, this.Width - 19, 11, this.Width - 4, 11);
//E
g.DrawLine(m_pen, this.Width - 19, 3, this.Width - 16, 3);
g.DrawLine(m_pen, this.Width - 19, 6, this.Width - 16, 6);
g.DrawLine(m_pen, this.Width - 19, 9, this.Width - 16, 9);
g.DrawLine(m_pen, this.Width - 19, 3, this.Width - 19, 9);
//S
g.DrawLine(m_pen, this.Width - 13, 3, this.Width - 10, 3);
g.DrawLine(m_pen, this.Width - 13, 6, this.Width - 10, 6);
g.DrawLine(m_pen, this.Width - 13, 9, this.Width - 10, 9);
g.DrawLine(m_pen, this.Width - 13, 3, this.Width - 13, 6);
g.DrawLine(m_pen, this.Width - 10, 6, this.Width - 10, 9);
//C
g.DrawLine(m_pen, this.Width - 7, 3, this.Width - 4, 3);
g.DrawLine(m_pen, this.Width - 7, 9, this.Width - 4, 9);
g.DrawLine(m_pen, this.Width - 7, 3, this.Width - 7, 9);
}

void tbx_KeyDown(object sender, KeyEventArgs e) {
if (e.KeyCode == Keys.Escape) this.Close();
if (e.KeyCode != Keys.Enter) return;
try {
m_descriptor.SetValue(((TextBox)sender).Text, null);
m_descriptor.Control.Invalidate();//add rect;
} catch (Exception ex) {
m_descriptor.OnSetValueError(ex);
}
this.Close();
}

private void InitializeComponent() {
this.SuspendLayout();
//
// FrmSTNodePropertyInput
//
this.ClientSize = new System.Drawing.Size(292, 273);
this.Name = "FrmSTNodePropertyInput";
this.ResumeLayout(false);
}
}
}
116 changes: 116 additions & 0 deletions ST.Library.UI/NodeEditor/FrmSTNodePropertySelect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Windows.Forms;
using System.Drawing;

namespace ST.Library.UI.NodeEditor
{
internal class FrmSTNodePropertySelect : Form
{
private STNodePropertyDescriptor m_descriptor;
private int m_nItemHeight = 25;

private static Type m_t_bool = typeof(bool);
private Pen m_pen;
private SolidBrush m_brush;
private StringFormat m_sf;
private Color m_clr_item_1 = Color.FromArgb(10, 0, 0, 0);// Color.FromArgb(255, 40, 40, 40);
private Color m_clr_item_2 = Color.FromArgb(10, 255, 255, 255);// Color.FromArgb(255, 50, 50, 50);
private object m_item_hover;

public FrmSTNodePropertySelect(STNodePropertyDescriptor descriptor) {
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);

m_descriptor = descriptor;
this.Size = descriptor.RectangleR.Size;
this.ShowInTaskbar = false;
this.BackColor = descriptor.Control.BackColor;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
m_pen = new Pen(descriptor.Control.AutoColor ? descriptor.Node.TitleColor : descriptor.Control.ItemSelectedColor, 1);
m_brush = new SolidBrush(this.BackColor);
m_sf = new StringFormat();
m_sf.LineAlignment = StringAlignment.Center;
m_sf.FormatFlags = StringFormatFlags.NoWrap;
}

private List<object> m_lst_item = new List<object>();

protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
Point pt = m_descriptor.Control.PointToScreen(m_descriptor.RectangleR.Location);
pt.Y += m_descriptor.Control.ScrollOffset;
this.Location = pt;
if (m_descriptor.PropertyInfo.PropertyType.IsEnum) {
foreach (var v in Enum.GetValues(m_descriptor.PropertyInfo.PropertyType)) m_lst_item.Add(v);
} else if (m_descriptor.PropertyInfo.PropertyType == m_t_bool) {
m_lst_item.Add(true);
m_lst_item.Add(false);
} else {
this.Close();
return;
}
this.Height = m_lst_item.Count * m_nItemHeight;
Rectangle rect = Screen.GetWorkingArea(this);
if (this.Bottom > rect.Bottom) this.Top -= (this.Bottom - rect.Bottom);
this.MouseLeave += (s, ea) => this.Close();
this.LostFocus += (s, ea) => this.Close();
}

protected override void OnPaint(PaintEventArgs e) {
base.OnPaint(e);
Graphics g = e.Graphics;
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
Rectangle rect_back = new Rectangle(0, 0, this.Width, m_nItemHeight);
Rectangle rect_font = new Rectangle(10, 0, this.Width - 13, m_nItemHeight);
int nIndex = 0;
string strVal = m_descriptor.GetStringFromValue();
foreach (var v in m_lst_item) {
m_brush.Color = nIndex++ % 2 == 0 ? m_clr_item_1 : m_clr_item_2;
g.FillRectangle(m_brush, rect_back);
if (v == m_item_hover) {
m_brush.Color = m_descriptor.Control.ItemHoverColor;
g.FillRectangle(m_brush, rect_back);
}
if (v.ToString() == strVal) {
m_brush.Color = m_descriptor.Control.ItemSelectedColor;
g.FillRectangle(m_brush, 4, rect_back.Top + 10, 5, 5);
}
m_brush.Color = m_descriptor.Control.ForeColor;
g.DrawString(v.ToString(), m_descriptor.Control.Font, m_brush, rect_font, m_sf);
rect_back.Y += m_nItemHeight;
rect_font.Y += m_nItemHeight;
}
g.DrawRectangle(m_pen, 0, 0, this.Width - 1, this.Height - 1);
}

protected override void OnMouseMove(MouseEventArgs e) {
base.OnMouseMove(e);
int nIndex = e.Y / m_nItemHeight;
if (nIndex < 0 || nIndex >= m_lst_item.Count) return;
var item = m_lst_item[e.Y / m_nItemHeight];
if (m_item_hover == item) return;
m_item_hover = item;
this.Invalidate();
}

protected override void OnMouseClick(MouseEventArgs e) {
base.OnMouseClick(e);
this.Close();
int nIndex = e.Y / m_nItemHeight;
if (nIndex < 0) return;
if (nIndex > m_lst_item.Count) return;
try {
m_descriptor.SetValue(m_lst_item[nIndex], null);
} catch (Exception ex) {
m_descriptor.OnSetValueError(ex);
}
}
}
}
Loading