//Checks all subrectangles in a guiNode to see if any of them were also clicked private int checkRectDex(Point p, NodeMap.guiNode gn) { for (int i = 1; i < gn.rects.Length; i++) { if (isColliding(gn.rects[i], p)) { return(i); } } return(0); }
private void initRects(int x, int y, NodeMap.guiNode gn) { int needed = gn.node.getNeeded(); int opt = gn.node.getOptional(); bool isOutput = gn.node.GetType() == typeof(OutputNode); int mainHeight = Math.Max((needed + opt) * SRS, 32); int mainWidth = 4 * SRS; gn.rects[0] = new Rectangle(x, y, mainWidth, mainHeight); for (int i = 0; i < needed + opt; i++) { int inY = i * SRS; gn.rects[i + 1] = new Rectangle(x, y + inY, SRS, SRS); } gn.rects[needed + opt + 1] = new Rectangle(x + mainWidth - SRS, y + mainHeight - SRS, SRS, SRS); if (!isOutput) { gn.rects[needed + opt + 2] = new Rectangle(x + mainWidth - SRS, y, SRS, SRS); } }
private void NP_Click(object sender, EventArgs e) { Point point = this.PointToClient(Cursor.Position); //Check if user clicked a node NodeMap.guiNode colNode = this.checkCollision(point); //If so colNode would be the node they clicked //Check collision prioritizes the sub rectangles. //I have no idea why we'd want to take a click on a sub rect //as a click on the main one, but then again I'm f*****g dumb. if (colNode.node != null) { int rDex = this.checkRectDex(point, colNode); if (rDex == 0) { if (selectedNode.node == colNode.node) { colNode.node.openForm(); } else { selectedNode = colNode; } } else { //If it's an input to a node if (rDex < colNode.rects.Length - 1) { //If the edge's destination hasn't been set if (destSet == false) { nextEdge.n2 = colNode; destSet = true; //This number stores the index of the child node that will be destination nextEdge.dex = rDex - 1; } else { MessageBox.Show("Can't put an input into an input.\n...silly goose."); } } //It's an output to a node else { //If the edge's source hasn't been set if (sourceSet == false) { nextEdge.n1 = colNode; sourceSet = true; } else { MessageBox.Show("Can't put an output into an output.\n...silly goose."); } } //If, by the end of it all, we have a valid edge if (sourceSet == true && destSet == true) { if (map.isValid(nextEdge)) { nextEdge.p1 = midPoint(nextEdge.n1.rects[nextEdge.n1.rects.Length - 1]); nextEdge.p2 = midPoint(nextEdge.n2.rects[nextEdge.dex + 1]); this.map.AddEdge(nextEdge); } else { MessageBox.Show("You can't create an infinite loop. Do you normally try and break anything you get your hands on?"); } sourceSet = false; destSet = false; } } } else { if (currentNode != NONE) { addCurrentNode(point.X, point.Y); } } UpdateGraph(); }