コード例 #1
0
ファイル: ExampleForm.cs プロジェクト: ldh9451/XLE
 void OnShowElementMenu(object sender, AcceptElementLocationEventArgs e)
 {
     if (e.Element is Node && ((Node)e.Element).Tag is ShaderProcedureNodeTag)
     {
         var tag = (ShaderProcedureNodeTag)((Node)e.Element).Tag;
         nodeMenu.Tag = tag.Id;
         nodeMenu.Show(e.Position);
         e.Cancel = false;
     }
     if (e.Element is Node && ((Node)e.Element).Tag is ShaderParameterNodeTag)
     {
         var tag = (ShaderParameterNodeTag)((Node)e.Element).Tag;
         parameterBoxMenu.Tag = tag.Id;
         parameterBoxMenu.Show(e.Position);
         e.Cancel = false;
     }
     else if (e.Element is ShaderFragmentNodeItem)
     {
         var tag = (ShaderFragmentNodeItem)e.Element;
         if (tag.ArchiveName != null)
         {
             ShaderParameterUtil.EditParameter(graphControl, tag.ArchiveName);
             e.Cancel = false;
         }
     }
     else if (e.Element is NodeConnector && ((NodeConnector)e.Element).Item is ShaderFragmentNodeItem)
     {
         var tag = (ShaderFragmentNodeItem)((NodeConnector)e.Element).Item;
         if (tag.ArchiveName != null)
         {
             ShaderParameterUtil.EditParameter(graphControl, tag.ArchiveName);
             e.Cancel = false;
         }
     }
     else
     {
         // if you don't want to show a menu for this item (but perhaps show a menu for something more higher up)
         // then you can cancel the event
         e.Cancel = true;
     }
 }
コード例 #2
0
ファイル: GraphControl.cs プロジェクト: coreafive/XLE
        void OnShowElementMenu(object sender, AcceptElementLocationEventArgs e)
        {
            if (e.Element == null)
            {
                _emptySpaceMenu.Tag = ClientToModel(new System.Drawing.PointF(e.Position.X, e.Position.Y));
                _emptySpaceMenu.Show(e.Position);
                e.Cancel = false;
            }
            else
            if (e.Element is Node && ((Node)e.Element).Tag is ShaderProcedureNodeTag)
            {
                var tag = (ShaderProcedureNodeTag)((Node)e.Element).Tag;
                _nodeMenu.Tag = tag.Id;
                _nodeMenu.Show(e.Position);
                e.Cancel = false;
            }
            // if (e.Element is Node && ((Node)e.Element).Tag is ShaderParameterNodeTag)
            // {
            //     var tag = (ShaderParameterNodeTag)((Node)e.Element).Tag;
            //     parameterBoxMenu.Tag = tag.Id;
            //     parameterBoxMenu.Show(e.Position);
            //     e.Cancel = false;
            // }
            // else 
            // if (e.Element is ShaderFragmentNodeItem)
            // {
            //     var tag = (ShaderFragmentNodeItem)e.Element;
            //     if (tag.ArchiveName != null)
            //     {
            //         ShaderParameterUtil.EditParameter(GetGraphModel(), tag.ArchiveName);
            //         e.Cancel = false;
            //     }
            // }
            else if (e.Element is NodeConnector && ((NodeConnector)e.Element).Item is ShaderFragmentNodeItem)
            {
                NodeConnector conn = (NodeConnector)e.Element;
                var tag = (ShaderFragmentNodeItem)conn.Item;
                if (tag.ArchiveName != null)
                {
                    // pop up a context menu for this connector
                    var menu = new ContextMenuStrip();

                    var param = conn.Item as ShaderFragmentInterfaceParameterItem;
                    if (param != null)
                    {
                        var editItem = new ToolStripMenuItem() { Text = "Edit parameter" };
                        editItem.Click += (object o, EventArgs a) => { EditInterfaceParameter(param); };
                        menu.Items.Add(editItem);
                    }

                    if (conn == conn.Item.Input)
                    {
                        var existing = GetSimpleConnection(conn);
                        if (!string.IsNullOrEmpty(existing))
                        {
                            var editItem = new ToolStripMenuItem() { Text = "Edit simple connection" };
                            editItem.Click += (object o, EventArgs a) => { EditSimpleConnection(conn); };
                            menu.Items.Add(editItem);
                        }
                        else
                        {
                            var addItem = new ToolStripMenuItem() { Text = "Add simple connection" };
                            addItem.Click += (object o, EventArgs a) => { EditSimpleConnection(conn); };
                            menu.Items.Add(addItem);
                        }
                    }

                    if (conn.Node.Connections.Where(x=>x.To==conn||x.From==conn).Any())
                    {
                        var removeItem = new ToolStripMenuItem() { Text = "Disconnect" };
                        removeItem.Click += (object o, EventArgs a) => { DisconnectAll(conn); };
                        menu.Items.Add(removeItem);
                    }

                    if (menu.Items.Count > 0)
                    {
                        menu.Show(e.Position);
                        e.Cancel = false;
                    }
                }
            }
            else
            {
                // if you don't want to show a menu for this item (but perhaps show a menu for something more higher up) 
                // then you can cancel the event
                e.Cancel = true;
            }
        }
コード例 #3
0
ファイル: GraphControl.cs プロジェクト: ldh9451/XLE
        protected override void OnMouseClick(MouseEventArgs e)
        {
            try
            {
                ignoreDoubleClick = false;
                if (mouseMoved)
                    return;

                var points = new Point[] { lastLocation };
                inverse_transformation.TransformPoints(points);
                var transformed_location = points[0];

                if (e.Button == MouseButtons.Right)
                {
                    if (null != ShowElementMenu)
                    {
                        // See if we clicked on an element and give our owner the chance to show a menu
                        var result = FindElementAt(transformed_location, delegate(IElement el)
                        {
                            // Fire the event and see if someone cancels it.
                            var eventArgs = new AcceptElementLocationEventArgs(el, this.PointToScreen(lastLocation));
                            // Give our owner the chance to show a menu for this element ...
                            ShowElementMenu(this, eventArgs);
                            // If the owner declines (cancel == true) then we'll continue looking up the hierarchy ..
                            return !eventArgs.Cancel;
                        });
                        // If we haven't found anything to click on we'll just return the event with a null pointer ..
                        //	allowing our owner to show a generic menu
                        if (result == null)
                        {
                            var eventArgs = new AcceptElementLocationEventArgs(null, this.PointToScreen(lastLocation));
                            ShowElementMenu(this, eventArgs);
                        }
                        return;
                    }
                }

                var element = FindElementAt(transformed_location);
                if (element == null)
                {
                    ignoreDoubleClick = true; // to avoid double-click from firing
                    if (ModifierKeys == Keys.None)
                        FocusElement = null;
                    return;
                }

                switch (element.ElementType)
                {
                    case ElementType.NodeItem:
                    {
                        if (ModifierKeys != Keys.None)
                            return;

                        var item = element as NodeItem;
                        if (item.OnClick())
                        {
                            ignoreDoubleClick = true; // to avoid double-click from firing
                            this.Refresh();
                            return;
                        }
                        break;
                    }
                }
            }
            finally
            {
                base.OnMouseClick(e);
            }
        }