public NodeGraphPanel() : base(new GraphicsMode(new ColorFormat(32), 24, 8, 8), 4, 5, GraphicsContextFlags.ForwardCompatible) { InitializeComponent(); this.MouseWheel += NodeGraphPanel_MouseWheel; //this.label1.Parent = this; this.graph = new Graph("Default"); this.view = new View(graph); this.Dock = DockStyle.Fill; //this.DoubleBuffered = true; this.scroll_Margins = 32; this.scroll_Margins_Value = 10; this.editMode = NodeGraphEditMode.Idle; this.mouse_position_wrld = Vector3.Zero; this.mouse_position_ctrl = Vector3.Zero; this.key_down_alt = false; this.key_down_ctrl = false; this.scroll_last = Vector3.Zero; this.selectionBox_Origin = Vector3.Zero; this.selectionBox_Current = Vector3.Zero; this.link_input = null; this.link_output = null; this.enable_debug = true; this.enable_shadow = true; this.enable_smooth = false; }
/// <summary> /// Creates a UserControl component that displays NodeGraphViews and let interact with NodeGraphNodes & NodeGraphLinks /// </summary> public NodeGraphPanel() { InitializeComponent(); this.m_oView = new NodeGraphView(this); this.m_oDebugFont = new Font("Tahoma", 8.0f); this.m_ScrollMargins = 32; this.m_ScrollMarginsValue = 10; this.m_eEditMode = NodeGraphEditMode.Idle; this.m_ViewSpaceCursorLocation = new Point(); this.m_bAltPressed = false; this.m_bCtrlPressed = false; this.m_NodeText = new SolidBrush(Color.White); this.m_NodeTextShadow = new SolidBrush(Color.Black); this.NodeTitleZoomThreshold = 0.5f; this.NodeConnectorTextZoomTreshold = 0.8f; this.NodeHeaderSize = 24; this.NodeTextColor = Color.FromArgb(255, 255, 255, 255); this.NodeTextShadowColor = Color.FromArgb(128, 0, 0, 0); this.NodeFillColor = Color.FromArgb(255, 128, 128, 128); this.NodeFillSelectedColor = Color.FromArgb(255, 160, 128, 100); this.NodeOutlineColor = Color.FromArgb(255, 180, 180, 180); this.NodeOutlineSelectedColor = Color.FromArgb(255, 192, 160, 128); this.ConnectorTextColor = Color.FromArgb(255, 64, 64, 64); this.ConnectorFillColor = Color.FromArgb(255, 0, 0, 0); this.ConnectorFillSelectedColor = Color.FromArgb(255, 32, 32, 32); this.ConnectorOutlineColor = Color.FromArgb(255, 32, 32, 32); this.ConnectorOutlineSelectedColor = Color.FromArgb(255, 64, 64, 64); this.SelectionFillColor = Color.FromArgb(64, 128, 90, 30); this.SelectionOutlineColor = Color.FromArgb(192, 255, 180, 60); this.NodeHeaderColor = Color.FromArgb(128, 0, 0, 0); this.LinkColor = Color.FromArgb(255, 180, 180, 180); this.LinkEditableColor = Color.FromArgb(255, 64, 255, 0); this.NodeSignalValidColor = Color.FromArgb(255, 0, 255, 0); this.NodeSignalInvalidColor = Color.FromArgb(255, 255, 0, 0); this.m_NodeTitleFont = new Font("Tahoma", 8.0f); this.m_NodeConnectorFont = new Font("Tahoma", 7.0f); this.m_NodeScaledTitleFont = new Font(m_NodeTitleFont.Name, m_NodeTitleFont.Size); this.m_NodeScaledConnectorFont = new Font(m_NodeConnectorFont.Name, m_NodeConnectorFont.Size); this.m_LinkVisualStyle = LinkVisualStyle.Curve; this.ConnectorHitZoneBleed = 2; this.m_SelectBoxOrigin = new Point(); this.m_SelectBoxCurrent = new Point(); this.LinkHardness = 2.0f; this.m_iScrollLastX = 0; this.m_iScrollLastY = 0; this.EnableDrawDebug = true; this.Dock = DockStyle.Fill; this.DoubleBuffered = true; this.m_InputLink = null; this.m_OutputLink = null; this.m_bShowGrid = false; this.m_iGridPadding = 256; this.m_iGridAlpha = 32; this.m_bDrawShadow = true; this.m_bSmoothBehavior = false; }
/// <summary> /// Behavior when Mouse Click is released /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void NodeGraphPanel_MouseUp(object sender, MouseEventArgs e) { switch (this.m_eEditMode) { case NodeGraphEditMode.Scrolling: if (e.Button == MouseButtons.Middle) this.m_eEditMode = NodeGraphEditMode.Idle; break; case NodeGraphEditMode.Selecting: case NodeGraphEditMode.SelectingBox: if (e.Button == MouseButtons.Left) { this.CreateSelection(); this.m_eEditMode = NodeGraphEditMode.Idle; } break; case NodeGraphEditMode.MovingSelection: if (e.Button == MouseButtons.Left) { this.m_eEditMode = NodeGraphEditMode.Idle; } break; case NodeGraphEditMode.Linking: this.m_OutputLink = GetHitConnector(e.Location); ValidateLink(); this.m_eEditMode = NodeGraphEditMode.Idle; break; default: break; } }
/// <summary> /// Behavior when mouse is moved /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void NodeGraphPanel_MouseMove(object sender, MouseEventArgs e) { this.m_ViewSpaceCursorLocation = this.ControlToView(new Point(e.X, e.Y)); switch (this.m_eEditMode) { case NodeGraphEditMode.Scrolling: this.View.ViewX += (int)((e.Location.X - m_iScrollLastX) / this.View.ViewZoom); this.View.ViewY += (int)((e.Location.Y - m_iScrollLastY) / this.View.ViewZoom); this.m_iScrollLastX = e.Location.X; this.m_iScrollLastY = e.Location.Y; this.Refresh(); break; case NodeGraphEditMode.Selecting: this.m_eEditMode = NodeGraphEditMode.SelectingBox; this.m_SelectBoxCurrent = this.ControlToView(new Point(e.X, e.Y)); this.UpdateHighlights(); this.Refresh(); break; case NodeGraphEditMode.SelectingBox: if (this.IsInScrollArea(e.Location)) { this.UpdateScroll(e.Location); } this.m_SelectBoxCurrent = this.ControlToView(new Point(e.X, e.Y)); this.UpdateHighlights(); this.Refresh(); break; case NodeGraphEditMode.MovingSelection: if (this.IsInScrollArea(e.Location)) { this.UpdateScroll(e.Location); } Point currentCursorLoc = this.ControlToView(e.Location); int deltaX = this.m_MoveLastPosition.X - currentCursorLoc.X; int deltaY = this.m_MoveLastPosition.Y - currentCursorLoc.Y; this.MoveSelection(new Point(deltaX, deltaY)); this.Refresh(); this.m_MoveLastPosition = currentCursorLoc; break; case NodeGraphEditMode.Linking: if (this.IsInScrollArea(e.Location)) { this.UpdateScroll(e.Location); } this.Refresh(); break; default: this.Refresh(); break; } }
/// <summary> /// Behavior when Mouse is Clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void NodeGraphPanel_MouseDown(object sender, MouseEventArgs e) { switch(this.m_eEditMode) { case NodeGraphEditMode.Idle: switch (e.Button) { case MouseButtons.Middle: this.m_eEditMode = NodeGraphEditMode.Scrolling; this.m_iScrollLastX = e.Location.X; this.m_iScrollLastY = e.Location.Y; break; case MouseButtons.Left: if (this.HitAll(e.Location) == HitType.Connector) { if (!m_bAltPressed) { this.m_eEditMode = NodeGraphEditMode.Linking; this.m_InputLink = GetHitConnector(e.Location); this.m_OutputLink = null; } else { NodeGraphConnector v_Connector = GetHitConnector(e.Location); this.DeleteLinkConnectors(v_Connector); } } else if (this.View.SelectedItems.Count > 0 && this.HitSelected(e.Location)== HitType.Node) { this.m_eEditMode = NodeGraphEditMode.MovingSelection; this.m_MoveLastPosition = this.ControlToView(e.Location); } else { this.m_eEditMode = NodeGraphEditMode.Selecting; this.m_SelectBoxCurrent = this.ControlToView(new Point(e.X, e.Y)); this.m_SelectBoxOrigin = this.ControlToView(new Point(e.X, e.Y)); this.UpdateHighlights(); this.CreateSelection(); if (this.View.SelectedItems.Count > 0) { this.m_eEditMode = NodeGraphEditMode.MovingSelection; this.m_MoveLastPosition = this.ControlToView(e.Location); } } break; default: break; } break; default: break; } this.Refresh(); }