protected override void filterForConnection(CanvasNode node, connectionRule rule) { foreach (CanvasNode gn in mNodes) { Type gnType = gn.GetType(); if (!rule.isValidType(gnType)) { if (!(gn is ConnectionPoint)) { gn.IsVisible = true; } else { gn.IsVisible = false; } gn.IsEnabled = false; } else { ConnectionPoint cp = node as ConnectionPoint; ConnectionPoint cpg = gn as ConnectionPoint; if (cp.OwnerNode == cpg.OwnerNode || cp.ParamType.Type != cpg.ParamType.Type) { gn.IsVisible = false; gn.IsEnabled = false; } } } }
protected CanvasNode intersectNodeMouseLoc(Point mousePoint, int targetDepth) { Point currPt = transformPoint(mousePoint, mTransformMatInv); CanvasNode selectedNode = null; foreach (CanvasNode gn in mNodes) { if (gn.isMouseOver(currPt)) { if (targetDepth != -1) { if (gn.mDepthLayer != targetDepth) { continue; } } if (selectedNode != null) { if (gn.mDepthLayer > selectedNode.mDepthLayer) { selectedNode = gn; } } else { selectedNode = gn; } } } return(selectedNode); }
void populateCanvasFromLoad(MaskDAGXML xmldat) { cleanCanvas(); newCanvas(); for (int i = 0; i < xmldat.mNodes.Count; i++) { Type t = xmldat.mNodes[i].GetType(); MaskDAGGraphNode val = null; try { System.Reflection.ConstructorInfo ci = t.GetConstructor(new Type[] { typeof(GraphCanvas) }); val = ((MaskDAGGraphNode)ci.Invoke(new object[] { this })); } catch (Exception e) { e.ToString(); return; } val.load(xmldat.mNodes[i]); addCanvasNode(val); } //load our connections now for (int i = 0; i < xmldat.mConnections.Count; i++) { CanvasNode start = findConnectionNode(xmldat.mConnections[i].mOwnerDeviceID, xmldat.mConnections[i].mConnectionName); CanvasNode end = findConnectionNode(xmldat.mConnections[i].mNeighborDeviceID, xmldat.mConnections[i].mNeighborConnectionName); if (start == null || end == null) continue; addConnection(start, end); } }
public virtual void onMouseUp(Point mousePoint, MouseEventArgs mouseEvent) { mMouseIsDown = false; //if we're dragging if (mDragging) { mCurrentPoint = mouseEvent.Location; //if we wern't dragging an object, then we were in selection if (!mClickedOnGraphObject) { selectNodesInDragRect(); } mDragging = false; return; //don't continue from here. } //if we DIDN'T click on an object if (!mClickedOnGraphObject) { if (mouseEvent.Button == MouseButtons.Right) { if (mPanning) { mPanning = false; } else { //clear all nodes and show context menu mClickedPoint = mouseEvent.Location; deselectAllNodes(); contextMenuStrip1.Show(mousePoint); } } if (mouseEvent.Button == MouseButtons.Left) { //just clear all nodes deselectAllNodes(); } } else { CanvasNode selectedNode = intersectNodeMouseLoc(mouseEvent.Location); if (selectedNode != null) { selectedNode.onMouseUp(mouseEvent.Location, mouseEvent); } } }
protected virtual void filterForConnection(CanvasNode node, connectionRule rule) { foreach (CanvasNode gn in mNodes) { if (rule.isInvalidType(gn.GetType())) { gn.IsVisible = false; gn.IsEnabled = false; } } }
public override void onDoubleClick(Point mousePoint, MouseEventArgs mouseEvent) { CanvasNode selectedNode = intersectNodeMouseLoc(mouseEvent.Location); if (selectedNode != null) { MaskDAGGraphNode gn = selectedNode as MaskDAGGraphNode; if (gn == null) return; if (mouseEvent.Button == MouseButtons.Left) { gn.displayPropertiesDlg(); } } }
public void generatePreview(CanvasNode cn) { OutputGenerationParams ogp = new OutputGenerationParams(); ogp.Width = 128; ogp.Height = 128; MaskDAGGraphNode gn = (MaskDAGGraphNode)cn; MaskParam mp = new MaskParam(); InputConnectionPoint icp = new InputConnectionPoint(mp,true,"Preview",gn,this); gn.computeOutput(icp,ogp); if (onUpdateCallback != null) { DAGMask m = mp.Value; onUpdateCallback(ref m); } }
protected void removeConnections(CanvasNode n) { if (n != null && n.Neighbors != null) { for (int i = 0; i < n.Neighbors.Count; i++) { CanvasNode cn = n.Neighbors[i]; if (cn == null || cn.Neighbors == null) { continue; } cn.Neighbors.Remove(n); } n.Neighbors.Clear(); } }
void drawTempConnectionLine(Graphics g) { Point currPt = transformPoint(mCurrentPoint, mTransformMatInv); Point clickedPt = transformPoint(mClickedPoint, mTransformMatInv); //snapping CanvasNode selectedNode = intersectNodeMouseLoc(mCurrentPoint); if (selectedNode != null) { currPt = selectedNode.Location; currPt.X += selectedNode.Size.Width >> 1; currPt.Y += selectedNode.Size.Height >> 1; } //draw connection line.. mTempConnectionLineAngled.setStartPoint(clickedPt.X, clickedPt.Y); mTempConnectionLineAngled.setEndPoint(currPt.X, currPt.Y); mTempConnectionLineAngled.render(g); }
public virtual void onMouseMove(Point mousePoint, MouseEventArgs mouseEvent) { if (mMode == eMode.eModeNone) { if (mMouseIsDown) { if (mouseEvent.Button == MouseButtons.Left) { mDragging = true; if (mClickedOnGraphObject) { foreach (CanvasNode gn in mNodes) { if (gn.mDepthLayer == 0 && gn.IsSelected) { gn.draggedByMouse(mCurrentPoint, mouseEvent.Location); } } } } else if (mouseEvent.Button == MouseButtons.Middle) { mPanning = true; //we're panning translateCanvas(mCurrentPoint, mouseEvent.Location); } } else { CanvasNode selectedNode = intersectNodeMouseLoc(mouseEvent.Location); if (selectedNode != null) { selectedNode.onMouseOver(mousePoint, mouseEvent); } } } mCurrentPoint = mouseEvent.Location; }
public virtual void onMouseDown(Point mousePoint, MouseEventArgs mouseEvent) { mMouseIsDown = true; mDragging = false; mClickedPoint = mouseEvent.Location; mCurrentPoint = mouseEvent.Location; mClickedOnGraphObject = false; //find the node intersecting with the mouse CanvasNode selectedNode = intersectNodeMouseLoc(mClickedPoint); if (mMode == eMode.eModeNone) { if (selectedNode != null) { mClickedOnGraphObject = true; if (mouseEvent.Button == MouseButtons.Left) { //if this node isn't select it, then clear, and select it if (!selectedNode.IsSelected) { deselectAllNodes(); selectedNode.IsSelected = true; //is this a connection type node? if so, put us in connection mode! int connectionIndex = connectionTypeIndex(selectedNode); if (connectionIndex != -1) { removeConnections(selectedNode); mMode = eMode.eModeConnection; filterForConnection(selectedNode, mConnectionRules[connectionIndex]); selectedNode.IsEnabled = true; selectedNode.IsVisible = true; mPrevSelectedNode = selectedNode; } } } else { //per node context menu plz.. } selectedNode.onMouseDown(mCurrentPoint, mouseEvent); } else { if (mouseEvent.Button == MouseButtons.Right) { } } } else { if (selectedNode == null) { mMode = eMode.eModeNone; unfilterForConnection(); } else { mClickedOnGraphObject = true; if (mouseEvent.Button == MouseButtons.Left) { removeConnections(selectedNode); //connect us addConnection(mPrevSelectedNode, selectedNode); mPrevSelectedNode = null; deselectAllNodes(); } mMode = eMode.eModeNone; unfilterForConnection(); } } selectedNode = null; }
protected void addConnection(CanvasNode a, CanvasNode b) { a.Neighbors.Add(b); b.Neighbors.Add(a); }
public void removeCanvasNode(CanvasNode cn) { cn.OnRemovedFromCanvas(); removeConnections(cn); mNodes.Remove(cn); }
public void addCanvasNode(CanvasNode cn) { mNodes.Add(cn); }