internal static UiParticipant ToUiParticipant(Participant participant) { var newRoot = new UiParticipant(participant.Name, null); AddChildren(newRoot, participant.Left, participant.Right); return(newRoot); }
private static void AddLine(UiParticipant node, Canvas canvas) { if (node.Left != null) { var line = new Line { Y1 = node.HorizontalAlignment * _rowDistance, X1 = node.VerticalAlignment * _columnDistance, Y2 = node.Left.HorizontalAlignment * _rowDistance + _cornerRadius, X2 = node.VerticalAlignment * _columnDistance, Stroke = _bracketColor }; canvas.Children.Add(line); } if (node.Winner != null && node.Winner.HorizontalAlignment != 0) { var line = new Line { Y1 = node.HorizontalAlignment * _rowDistance + _cornerRadius, X1 = node.Winner.VerticalAlignment * _columnDistance, Y2 = node.Winner.HorizontalAlignment * _rowDistance, X2 = node.Winner.VerticalAlignment * _columnDistance, Stroke = _bracketColor }; canvas.Children.Add(line); } }
public UiParticipant(string name, UiParticipant winner) { Name = name; Winner = winner; HorizontalAlignment = 0; VerticalAlignment = 0; }
private static void AddLinkToCanvas(ref int rowIndex, int colIndex, UiParticipant node, Canvas canvas) { if (node.Left != null) { AddLinkToCanvas(ref rowIndex, colIndex - 1, node.Left, canvas); } AddParticipantToCanvas(rowIndex, colIndex, node, canvas); rowIndex++; if (node.Right != null) { AddLinkToCanvas(ref rowIndex, colIndex - 1, node.Right, canvas); } }
private static void AddParticipantToCanvas(int rowIndex, int colIndex, UiParticipant node, Canvas canvas) { node.AddAlignment(rowIndex, colIndex); var fullNameToolTip = new ToolTip() { Content = node.Name }; var participant = new TextBlock() { Text = node.Name, TextWrapping = TextWrapping.Wrap, TextTrimming = TextTrimming.CharacterEllipsis, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, FontSize = _heightOfText, }; var border = new Border() { Width = _columnDistance, MinHeight = _rowDistance / 2, MaxHeight = _rowDistance, CornerRadius = new CornerRadius(_cornerRadius), Background = Brushes.White, BorderBrush = _bracketColor, BorderThickness = new Thickness(1), ToolTip = fullNameToolTip }; border.Child = participant; if (node.Winner?.Name == node.Name) { border.Background = Brushes.ForestGreen; participant.FontWeight = FontWeights.Bold; participant.Foreground = Brushes.White; } Canvas.SetTop(border, rowIndex * _rowDistance); Canvas.SetLeft(border, _columnDistance * colIndex); canvas.Children.Add(border); AddLine(node, canvas); }
private static void AddChildren(UiParticipant newParticipant, Participant left, Participant right) { UiParticipant leftRoot = null; UiParticipant rightRoot = null; if (left != null) { leftRoot = new UiParticipant(left.Name, newParticipant); } if (right != null) { rightRoot = new UiParticipant(right.Name, newParticipant); } newParticipant.SetChildren(leftRoot, rightRoot); if (left != null && right != null) { AddChildren(leftRoot, left.Left, left.Right); AddChildren(rightRoot, right.Left, right.Right); } }
public void SetChildren(UiParticipant left, UiParticipant right) { Left = left; Right = right; }
private static void AddParticipantToCanvas(int rowIndex, int colIndex, UiParticipant node, Canvas canvas) { node.AddAlignment(rowIndex, colIndex); var participant = new TextBlock() { Text = node.Name, HorizontalAlignment = HorizontalAlignment.Center }; var border = new Border() { Width = 70, Height = 20, CornerRadius = new CornerRadius(10, 10, 10, 10), }; border.Child = participant; if (node.Winner?.Name == node.Name) { border.Background = Brushes.ForestGreen; participant.FontWeight = FontWeights.Bold; participant.Foreground = Brushes.White; } Canvas.SetTop(border, rowIndex * _rowDistance); Canvas.SetLeft(border, _columnDistance * colIndex + 5); canvas.Children.Add(border); if (node.Left != null) { var firstLine = new Line { Y1 = node.HorizontalAlignment * _rowDistance, X1 = node.VerticalAlignment * _columnDistance, Y2 = node.Left.HorizontalAlignment * _rowDistance, X2 = node.VerticalAlignment * _columnDistance, Stroke = _bracketColor }; var secondLine = new Line { Y1 = node.Left.HorizontalAlignment * _rowDistance, X1 = node.VerticalAlignment * _columnDistance, Y2 = node.Left.HorizontalAlignment * _rowDistance, X2 = node.Left.VerticalAlignment * _columnDistance, Stroke = _bracketColor }; canvas.Children.Add(firstLine); canvas.Children.Add(secondLine); } if (node.Winner != null && node.Winner.HorizontalAlignment != 0) { var firstLine = new Line { Y1 = node.HorizontalAlignment * _rowDistance + _heightOfText, X1 = node.VerticalAlignment * _columnDistance, Y2 = node.HorizontalAlignment * _rowDistance + _heightOfText, X2 = node.Winner.VerticalAlignment * _columnDistance, Stroke = _bracketColor }; var secondLine = new Line { Y1 = node.HorizontalAlignment * _rowDistance + _heightOfText, X1 = node.Winner.VerticalAlignment * _columnDistance, Y2 = node.Winner.HorizontalAlignment * _rowDistance, X2 = node.Winner.VerticalAlignment * _columnDistance, Stroke = _bracketColor }; canvas.Children.Add(firstLine); canvas.Children.Add(secondLine); } }