//Recursively find the last child and separate it public void Unpin() { ShapeGraphic tempChild = childShapeGraphic; ShapeGraphic tempParent = parentShapeGraphic; childShapeGraphic = new ShapeGraphic(); parentShapeGraphic = new ShapeGraphic(); childShapeGraphic = null; parentShapeGraphic = null; if (tempChild != null) { if (tempParent == null) { tempChild.removeParent(); } else { tempChild.giveParent(tempParent); } } if (tempParent != null) { if (tempChild == null) { tempParent.removeChild(); } else { tempParent.giveChild(tempChild); } } }
public ShapeGraphic(Color selectedColour, Point selectedPosition) { shapeColour = selectedColour; canvasPosition = selectedPosition; childShapeGraphic = null; parentShapeGraphic = null; copyId = -1; }
//Recursively find the child who doesn't have a child yet public void Pin(ShapeGraphic childToPin) { if (childShapeGraphic == null) { //Find the highest parent in the child graphic while (true) { if (childToPin.hasParent()) { childToPin = childToPin.getParent(); } else { break; } } childShapeGraphic = childToPin; childToPin.giveParent(this); } else { childShapeGraphic.Pin(childToPin); } }
public void removeChild() { childShapeGraphic = null; }
public void removeParent() { parentShapeGraphic = null; }
public void giveChild(ShapeGraphic child) { childShapeGraphic = child; }
public void giveParent(ShapeGraphic parent) { parentShapeGraphic = parent; }
//Returns true if a passed shape is pinned to the shape in any way public bool checkIfAlreadyPinned(ShapeGraphic childToPin) { bool result = false; if (childToPin == this) { return(true); } if (childShapeGraphic != null) { result = childShapeGraphic.checkIfAlreadyPinned(childToPin); if (result == true) { return(true); } } if (parentShapeGraphic != null) { result = parentShapeGraphic.checkIfAlreadyPinned(childToPin); if (result == true) { return(true); } } //CHeck all the childToPin's children and parents if (childToPin.hasChild()) { if (childShapeGraphic != null) { result = childShapeGraphic.checkIfAlreadyPinned(childToPin.getChild()); if (result == true) { return(true); } } if (parentShapeGraphic != null) { result = parentShapeGraphic.checkIfAlreadyPinned(childToPin.getChild()); if (result == true) { return(true); } } } if (childToPin.hasParent()) { if (childShapeGraphic != null) { result = childShapeGraphic.checkIfAlreadyPinned(childToPin.getParent()); if (result == true) { return(true); } } if (parentShapeGraphic != null) { result = parentShapeGraphic.checkIfAlreadyPinned(childToPin.getParent()); if (result == true) { return(true); } } } return(false); }
public ShapeGraphic() { childShapeGraphic = null; parentShapeGraphic = null; copyId = -1; }
//Check is two shapes in a pin mass are connected at any points private bool checkIfPinned(ShapeGraphic pinnee, ShapeGraphic pinner) { return(false); }