void SetNodePositions(FaultTreeNode node) { FaultTreeNode temp = node.Child; int childNumber = 0; while (temp != null) { childNumber++; temp = temp.Sibling; } temp = node.Child; int shift = childNumber / 2; while (temp != null) { DrawLocation newDrawLocation = _listOfDrawLocations.Find(item => item.Node == temp); DrawLocation drawLocationOfCurrentNode = _listOfDrawLocations.Find(item => item.Node == node); int nodeDepth = temp.Depth; // Node distance 2^depth distance from max depth, node draw size is 3/2 to add a small distance // between nodes at the same depth, the value is divided by 2 (for each side of the tree) // bit-shifting is a more optimal solution for powers of 2 int spacing = ((int)(_nodeDrawSize.Width * 1f) * (1 << (2 * (_maxNodeDepth - nodeDepth)))) / childNumber; newDrawLocation.DrawPosition.X = drawLocationOfCurrentNode.DrawPosition.X - shift * spacing; shift--; // Increase the Y distance by a base distance plus 10 for each level // newDrawLocation.DrawPosition.Y = drawLocationOfCurrentNode.DrawPosition.Y + ((_nodeDrawSize.Height * nodeDepth) * 1.1f); newDrawLocation.DrawPosition.Y = drawLocationOfCurrentNode.DrawPosition.Y + 2f * _nodeDrawSize.Height; SetNodePositions(temp); temp = temp.Sibling; } }
void EstablishNodeLines() { _listOfNodeLines.Clear(); for (int i = 0; i < _binaryTree.NumOfNodes - 1; ++i) { if (_listOfDrawLocations[i].Node.Left != null) { NodeLine newLine = new NodeLine(); DrawLocation currentDrawLocation = _listOfDrawLocations.Find(item => (item.Node == _listOfDrawLocations[i].Node.Left)); // Line start and end positions are translated to the center of each node newLine.Start.X = _listOfDrawLocations[i].DrawPosition.X + (_nodeDrawSize.Width / 2.0f); newLine.Start.Y = _listOfDrawLocations[i].DrawPosition.Y + (_nodeDrawSize.Height / 2.0f); newLine.End.X = currentDrawLocation.DrawPosition.X + (_nodeDrawSize.Width / 2.0f); newLine.End.Y = currentDrawLocation.DrawPosition.Y + (_nodeDrawSize.Height / 2.0f); _listOfNodeLines.Add(newLine); } if (_listOfDrawLocations[i].Node.Right != null) { NodeLine newLine = new NodeLine(); DrawLocation currentDrawLocation = _listOfDrawLocations.Find(item => (item.Node == _listOfDrawLocations[i].Node.Right)); newLine.Start.X = _listOfDrawLocations[i].DrawPosition.X + (_nodeDrawSize.Width / 2.0f); newLine.Start.Y = _listOfDrawLocations[i].DrawPosition.Y + (_nodeDrawSize.Height / 2.0f); newLine.End.X = currentDrawLocation.DrawPosition.X + (_nodeDrawSize.Width / 2.0f); newLine.End.Y = currentDrawLocation.DrawPosition.Y + (_nodeDrawSize.Height / 2.0f); _listOfNodeLines.Add(newLine); } } }
public override void Draw() { if (BodyLibrary == null) { return; } BodyLibrary.Draw(DrawFrame, DrawLocation, DrawColour, true); if (QuestIcon == QuestIcon.None) { return; } var offSet = BodyLibrary.GetOffSet(BaseIndex); var size = BodyLibrary.GetSize(BaseIndex); int imageIndex = 981 + ((int)QuestIcon * 2) + QuestIndex; //Libraries.Prguse.Draw(981 + ((int)QuestIcon * 2) + QuestIndex, DrawLocation.Add(offSet).Add(0, -40), Color.White, false); Libraries.Prguse.Draw(imageIndex, DrawLocation.Add(offSet).Add(size.Width / 2 - 28, -40), Color.White, false); }
void SetNodePositions(BinaryTreeNode node) { if (node.Left != null) { // Set the distances between nodes at the same depth DrawLocation newDrawLocation = _listOfDrawLocations.Find(item => item.Node == node.Left); DrawLocation drawLocationOfCurrentNode = _listOfDrawLocations.Find(item => item.Node == node); int nodeDepth = node.Left.Depth; // Node distance 2^depth distance from max depth, node draw size is 3/2 to add a small distance // between nodes at the same depth, the value is divided by 2 (for each side of the tree) // bit-shifting is a more optimal solution for powers of 2 int spacing = ((int)(_nodeDrawSize.Width * 1f) * (1 << (int)((_maxNodeDepth - nodeDepth) / 1.5))) / 2; newDrawLocation.DrawPosition.X = drawLocationOfCurrentNode.DrawPosition.X - spacing; // Increase the Y distance by a base distance plus 10 for each level newDrawLocation.DrawPosition.Y = drawLocationOfCurrentNode.DrawPosition.Y + ((_nodeDrawSize.Height * nodeDepth) * 1f); SetNodePositions(node.Left); } if (node.Right != null) { DrawLocation newDrawLocation = _listOfDrawLocations.Find(item => item.Node == node.Right); DrawLocation drawLocationOfCurrentNode = _listOfDrawLocations.Find(item => item.Node == node); int nodeDepth = node.Right.Depth; int spacing = ((int)(_nodeDrawSize.Width * 1f) * (1 << (int)((_maxNodeDepth - nodeDepth) / 1.5))) / 2; newDrawLocation.DrawPosition.X = drawLocationOfCurrentNode.DrawPosition.X + spacing; newDrawLocation.DrawPosition.Y = drawLocationOfCurrentNode.DrawPosition.Y + ((_nodeDrawSize.Height * nodeDepth) * 1f); SetNodePositions(node.Right); } }
void EstablishNodeLines() { _listOfNodeLines.Clear(); for (int i = 0; i < _faultTree.NumOfNodes - 1; ++i) { FaultTreeNode child = _listOfDrawLocations[i].Node.Child; while (child != null) { NodeLine newLine = new NodeLine(); DrawLocation currentDrawLocation = _listOfDrawLocations.Find(item => (item.Node == child)); // DrawLocation currentDrawLocation = _listOfDrawLocations.Find(item => (item.Node == _listOfDrawLocations[i].Node.Child)); // Line start and end positions are translated to the center of each node newLine.Start.X = _listOfDrawLocations[i].DrawPosition.X + (_nodeDrawSize.Width / 2.0f); newLine.Start.Y = _listOfDrawLocations[i].DrawPosition.Y + (_nodeDrawSize.Height / 2.0f); newLine.End.X = currentDrawLocation.DrawPosition.X + (_nodeDrawSize.Width / 2.0f); newLine.End.Y = currentDrawLocation.DrawPosition.Y + (_nodeDrawSize.Height / 2.0f); _listOfNodeLines.Add(newLine); child = child.Sibling; } } }