Ejemplo n.º 1
0
        /// <summary>
        /// Draws everything inside canvas.
        /// </summary>
        private void DisplayInControl()
        {
            int factor = FullSize ? Settings.LargeFactor : Settings.SmallFactor;
            int max    = Settings.MaxSize;
            int size   = factor * max;

            MainCanvas.Children.Clear();

            Border border = new Border
            {
                Width           = max * factor + 2,
                Height          = size,
                BorderThickness = new Thickness(0, 0, 2, 0),
                BorderBrush     = Brushes.Black
            };

            MainCanvas.Children.Add(border);

            DisplayCuboids(Cuboids);
            DisplayCuboids(CuboidsSelection);

            DisplaySelectionCuboidsDimensions();
            DisplayTheGrid(factor, max, size);

            CuboidsHelper.ResetIsOnTop(Cuboids);
            CuboidsHelper.ResetZIndexes(MainCanvas, ViewDirection);
        }
Ejemplo n.º 2
0
        private void CuboidControl_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (!FullSize || IsGridVisible)
            {
                return;
            }

            CuboidControl cc     = sender as CuboidControl;
            Canvas        canvas = cc.Parent as Canvas;

            if (!cc.Cuboid.IsOnTop)
            {
                return;
            }

            MainWindowViewModel vm = DataContext as MainWindowViewModel;

            if (cc.Cuboid.FromSelection)
            {
                switch (ViewDirection)
                {
                case ViewDirection.TopView:
                    cc.Cuboid.Z = CuboidsHelper.FindLastCoordinateForTopView(vm.Cuboids, cc.Cuboid.X, cc.Cuboid.Y);
                    break;

                case ViewDirection.FrontView:
                    cc.Cuboid.Y = CuboidsHelper.FindLastCoordinateForFrontView(vm.Cuboids, cc.Cuboid.X, cc.Cuboid.Z) - cc.Cuboid.Depth;
                    break;

                case ViewDirection.BackView:
                    cc.Cuboid.Y = CuboidsHelper.FindLastCoordinateForBackView(vm.Cuboids, cc.Cuboid.X, cc.Cuboid.Z);
                    break;

                case ViewDirection.LeftView:
                    cc.Cuboid.X = CuboidsHelper.FindLastCoordinateForLeftView(vm.Cuboids, cc.Cuboid.Y, cc.Cuboid.Z) - cc.Cuboid.Width;
                    break;

                case ViewDirection.RightView:
                    cc.Cuboid.X = CuboidsHelper.FindLastCoordinateForRightView(vm.Cuboids, cc.Cuboid.Y, cc.Cuboid.Z);
                    break;
                }

                Cuboid newCuboid = new Cuboid(cc.Cuboid);
                if (cc.Cuboid.IsDragged && CuboidsHelper.CheckIfCanBeAdded(vm.Cuboids, newCuboid))
                {
                    ObservableCollection <Cuboid> tmp = new ObservableCollection <Cuboid>(vm.Cuboids);
                    tmp.Add(newCuboid);
                    vm.Cuboids = new ObservableCollection <Cuboid>(tmp);
                    vm.Actions.Add(new List <ActionObject>()
                    {
                        new ActionObject(newCuboid, ActionType.Add)
                    });
                }
                cc.Cuboid.IsDragged = false;
            }
            else
            {
                if (ViewDirection == ViewDirection.TopView)
                {
                    cc.Cuboid.Z = CuboidsHelper.FindLastCoordinateForTopView(vm.Cuboids, cc.Cuboid);
                }
                if (CuboidsHelper.CheckIfCanBeAdded(vm.Cuboids, cc.Cuboid))
                {
                    Cuboid startCuboid = new Cuboid(cc.Cuboid);
                    startCuboid.X = startX;
                    startCuboid.Y = startY;
                    startCuboid.Z = startZ;
                    List <ActionObject> actions = new List <ActionObject>()
                    {
                        new ActionObject(startCuboid, ActionType.Remove),
                        new ActionObject(new Cuboid(cc.Cuboid), ActionType.Add)
                    };
                    vm.Actions.Add(actions);
                }
                else
                {
                    cc.Cuboid.X = startX;
                    cc.Cuboid.Y = startY;
                    cc.Cuboid.Z = startZ;
                }
            }

            CuboidsHelper.ResetIsOnTop(vm.Cuboids);
            CuboidsHelper.ResetZIndexes(canvas, ViewDirection);
            movingObject = null;
            Mouse.Capture(null);
        }