/// <summary> /// Adds the wall display to the box display. /// </summary> /// <param name="wall">Wall which will be added.</param> /// <param name="top">The top position.</param> /// <param name="left">The left position.</param> private void AddWall(Wall wall, int top, int left) { BoxCanvas.Children.Add(wall); Canvas.SetLeft(wall, left); Canvas.SetTop(wall, top); wall.MouseLeftButtonDown += WallMouseButtonEventHandler; }
/// <summary> /// Copy the children between canvases. The children from source canvas will be removed. /// </summary> /// <param name="destinationWall">Destination cavase.</param> /// <param name="moveSize">if set to <c>true</c> the destination canvase size will be set to source canvase size.</param> public void CopyToWall(Wall destinationWall, bool moveSize = false) { if (moveSize) { destinationWall.Height = Height; destinationWall.Width = Width; } destinationWall.Children.Clear(); foreach (FrameworkElement sourceFrameworkElement in Children) { FrameworkElement frameworkElement = null; if (sourceFrameworkElement is TextBlock) { frameworkElement = CreateTextBlock(((TextBlock)sourceFrameworkElement).Text, ((TextBlock)sourceFrameworkElement).Foreground); } if (sourceFrameworkElement is Image) { frameworkElement = CreateImage(sourceFrameworkElement.Tag.ToString()); } if (frameworkElement != null) { AddElement(frameworkElement, destinationWall); RegisterTransformsElement(frameworkElement); if (frameworkElement.RenderTransform != null && frameworkElement.RenderTransform is TransformGroup) { TransformGroup tranGroup = (TransformGroup)sourceFrameworkElement.RenderTransform; ScaleTransform scaleTransform = GetScaleTransform(tranGroup); if (scaleTransform != null) ScaleEditedElement(scaleTransform.ScaleX); RotateTransform rotateTransform = GetRotateTransform(tranGroup); if (rotateTransform != null) TurnEditedElement(rotateTransform.Angle); TranslateTransform translateTransform = GetTranslateTransform(tranGroup); if (translateTransform != null) { MoveEditedElementX(translateTransform.X); MoveEditedElementY(translateTransform.Y); } } } } destinationWall.WallColor = WallColor; if (moveSize) { double scale = GetScale((int)destinationWall.Width, (int)destinationWall.Height, CanvasWidth, CanvasHeight); destinationWall.RenderTransform = new ScaleTransform(); { ((ScaleTransform)destinationWall.RenderTransform).ScaleX = scale; ((ScaleTransform)destinationWall.RenderTransform).ScaleY = scale; } Thickness m = destinationWall.Margin; m.Left = EdgeGap + (double)(CanvasWidth - EdgeGap * 2 - GetSizeToDisplay(scale, (int)destinationWall.Width)) / 2; m.Top = EdgeGap + (double)(CanvasHeight - EdgeGap * 2 - GetSizeToDisplay(scale, (int)destinationWall.Height)) / 2; destinationWall.Margin = m; } }
/// <summary> /// Rebuilds the specified main canvas. /// </summary> /// <param name="canvasToDisplayBox">The canvas on which walls of box will be displayed.</param> /// <param name="realWidth">Width of the real box.</param> /// <param name="realLength">Length of the real.</param> /// <param name="realHeight">Height of the real.</param> /// <param name="realCoverHeight">Height of the real cover.</param> /// <param name="boxType">Type of the box.</param> public void Rebuild(Canvas canvasToDisplayBox, int realWidth, int realLength, int realHeight, int realCoverHeight, BoxType.BoxTypeEnum boxType) { BoxCanvas = canvasToDisplayBox; BoxCanvas.Children.Clear(); RealWidth = realWidth; RealLength = realLength; RealHeight = realHeight; RealCoverHeight = realCoverHeight; BoxType = boxType; Scale = GetScale(realWidth, realLength, realHeight, realCoverHeight, BoxType, MainCanvasHeight, MainCanvasWidth); UpWall = new Wall(GetSizeToDisplay(RealLength), GetSizeToDisplay(RealWidth), Colors.Yellow, WallType.WallTypeEnum.Up); BackWall = new Wall(GetSizeToDisplay(RealLength), GetSizeToDisplay(RealHeight), Colors.Fuchsia, WallType.WallTypeEnum.Back); BottomWall = new Wall(GetSizeToDisplay(RealLength), GetSizeToDisplay(RealWidth), Colors.Black, WallType.WallTypeEnum.Bottom); FrontWall = new Wall(GetSizeToDisplay(RealLength), GetSizeToDisplay(RealHeight), Colors.Green, WallType.WallTypeEnum.Front); LeftWall = new Wall(GetSizeToDisplay(RealHeight), GetSizeToDisplay(RealWidth), Colors.Lime, WallType.WallTypeEnum.Left); RightWall = new Wall(GetSizeToDisplay(RealHeight), GetSizeToDisplay(RealWidth), Colors.Maroon, WallType.WallTypeEnum.Right); CoverWall = new Wall(GetSizeToDisplay(RealLength), GetSizeToDisplay(RealWidth), Colors.Yellow, WallType.WallTypeEnum.Cover); BackCoverWall = new Wall(GetSizeToDisplay(RealLength), GetSizeToDisplay(RealCoverHeight), Colors.Teal, WallType.WallTypeEnum.BackCover); FrontCoverWall = new Wall(GetSizeToDisplay(RealLength), GetSizeToDisplay(RealCoverHeight), Colors.Teal, WallType.WallTypeEnum.FrontCover); LeftCoverWall = new Wall(GetSizeToDisplay(RealCoverHeight), GetSizeToDisplay(RealWidth), Colors.Teal, WallType.WallTypeEnum.LeftCover); RightCoverWall = new Wall(GetSizeToDisplay(RealCoverHeight), GetSizeToDisplay(RealWidth), Colors.Teal, WallType.WallTypeEnum.RightCover); //calculation for displaying on the center the canvas int lengthToDisplay = (int)(2 * EdgeGap + 2 * WallGap + GetSizeToDisplay(2 * RealHeight + RealLength)); int widthToDisplay = (int)(2 * EdgeGap + 2 * WallGap + GetSizeToDisplay(2 * RealHeight + RealWidth)); if (BoxType == BoxCreator.BoxType.BoxTypeEnum.Close) { lengthToDisplay = (int)(2 * EdgeGap + 2 * WallGap + GetSizeToDisplay(2 * RealHeight + RealLength)); widthToDisplay = (int)(2 * EdgeGap + 3 * WallGap + GetSizeToDisplay(2 * RealHeight + 2 * RealWidth)); } if (BoxType == BoxCreator.BoxType.BoxTypeEnum.WithCover) { lengthToDisplay = (int)(2 * EdgeGap + 2 * WallGap + GetSizeToDisplay(2 * RealHeight + RealLength)); widthToDisplay = (int)(4 * WallGap + 2 * EdgeGap + CoverGap + GetSizeToDisplay(2 * RealHeight + 2 * RealWidth + 2 * RealCoverHeight)); } LeftShift = (MainCanvasWidth - lengthToDisplay) / 2; TopShift = (MainCanvasHeight - widthToDisplay) / 2; IsRebuild = true; }