示例#1
0
        private void CreateLayer(Vector2 canvasStartingPoint, Vector2 canvasPoint)
        {
            //History
            LayeragesArrangeHistory history = new LayeragesArrangeHistory("Add layer", this.ViewModel.LayerageCollection);

            this.ViewModel.HistoryPush(history);


            //Transformer
            Transformer transformer = new Transformer(canvasPoint, canvasStartingPoint);

            //Layer
            CurveLayer curveLayer = new CurveLayer(this.ViewModel.CanvasDevice, canvasStartingPoint, canvasPoint)
            {
                IsSelected = true,
                Transform  = new Transform(transformer),
                Style      = this.SelectionViewModel.StandCurveStyle,
            };
            Layerage curveLayerage = curveLayer.ToLayerage();

            LayerBase.Instances.Add(curveLayer);

            //Mezzanine
            LayerageCollection.Mezzanine(this.ViewModel.LayerageCollection, curveLayerage);


            this.SelectionViewModel.SetModeSingle(curveLayerage);//Selection
            LayerageCollection.ArrangeLayers(this.ViewModel.LayerageCollection);
            LayerageCollection.ArrangeLayersBackground(this.ViewModel.LayerageCollection);
            this.ViewModel.Invalidate(InvalidateMode.HD);//Invalidate
        }
示例#2
0
        /// <summary>
        /// Load from a project.
        /// </summary>
        /// <param name="project"> The project. </param>
        public void LoadFromProject(Project project)
        {
            if (project == null)
            {
                return;
            }

            //Name
            this.Name = project.Name;

            //Width Height
            this.CanvasTransformer.Width  = project.Width;
            this.CanvasTransformer.Height = project.Height;

            //Layers
            this.LayerageCollection.RootLayerages.Clear();
            if (project.Layerages != null)
            {
                foreach (Layerage layerage in project.Layerages)
                {
                    if (layerage != null)
                    {
                        this.LayerageCollection.RootLayerages.Add(layerage);
                    }
                }
            }

            //Arrange
            LayerageCollection.ArrangeLayers(this.LayerageCollection);
            LayerageCollection.ArrangeLayersBackground(this.LayerageCollection);
        }
示例#3
0
        //@Construct
        /// <summary>
        /// Initializes a LayersControl.
        /// </summary>
        public LayersControl()
        {
            this.InitializeComponent();
            //LayerageCollection
            this.ConstructLayerageCollection();
            this.ItemsControl.ItemsSource = this.ViewModel.LayerageCollection.RootControls;


            this.Tapped      += (s, e) => this.MethodViewModel.MethodSelectedNone();//Method
            this.RightTapped += (s, e) => this.ShowLayerMenu();
            this.Holding     += (s, e) => this.ShowLayerMenu();


            Retouch_Photo2.PhotosPage.AddImageCallBack += (photo) =>
            {
                if (photo == null)
                {
                    return;
                }

                //History
                LayeragesArrangeHistory history = new LayeragesArrangeHistory("Add layer", this.ViewModel.LayerageCollection);
                this.ViewModel.HistoryPush(history);

                //Transformer
                Transformer transformerSource = new Transformer(photo.Width, photo.Height, Vector2.Zero);

                //Layer
                Photocopier photocopier = photo.ToPhotocopier();
                ImageLayer  imageLayer  = new ImageLayer(this.ViewModel.CanvasDevice)
                {
                    Photocopier = photocopier,
                    IsSelected  = true,
                    Transform   = new Transform(transformerSource)
                };
                Layerage imageLayerage = imageLayer.ToLayerage();
                LayerBase.Instances.Add(imageLayer);

                //Selection
                this.SelectionViewModel.SetValue((layerage) =>
                {
                    ILayer layer = layerage.Self;

                    layer.IsSelected = false;
                });

                //Mezzanine
                LayerageCollection.Mezzanine(this.ViewModel.LayerageCollection, imageLayerage);

                this.SelectionViewModel.SetMode(this.ViewModel.LayerageCollection);//Selection
                LayerageCollection.ArrangeLayers(this.ViewModel.LayerageCollection);
                LayerageCollection.ArrangeLayersBackground(this.ViewModel.LayerageCollection);
                this.ViewModel.Invalidate();//Invalidate
            };
        }
示例#4
0
        //@Construct
        /// <summary>
        /// Initializes a ConvertToCurvesButton.
        /// </summary>
        public ConvertToCurvesButton()
        {
            this.InitializeComponent();
            this.Button.Click += (s, e) =>
            {
                if (this.SelectionViewModel.SelectionMode == ListViewSelectionMode.None)
                {
                    return;
                }

                //History
                LayeragesArrangeHistory history = new LayeragesArrangeHistory("Convert to curves", this.ViewModel.LayerageCollection);
                this.ViewModel.HistoryPush(history);

                this.SelectionViewModel.SetValue((layerage) =>
                {
                    ILayer layer = layerage.Self;

                    //Turn to curve layer
                    ILayer curveLayer = this.CreateCurveLayer(layerage);

                    if (curveLayer != null)
                    {
                        Layerage curveLayerage = curveLayer.ToLayerage();
                        LayerBase.Instances.Add(curveLayer);

                        //set image brush
                        if (layer.Type == LayerType.Image)
                        {
                            ImageLayer imageLayer = (ImageLayer)layer;
                            curveLayer.Style.Fill = imageLayer.ToBrush();
                        }

                        this.ReplaceLayerage(curveLayerage, layerage);
                    }
                });

                LayerageCollection.ArrangeLayers(this.ViewModel.LayerageCollection);
                LayerageCollection.ArrangeLayersBackground(this.ViewModel.LayerageCollection);
                this.SelectionViewModel.SetMode(this.ViewModel.LayerageCollection);//Selection

                //Change tools group value.
                {
                    ITool tool = this.TipViewModel.Tools.First(t => t != null && t.Type == ToolType.Node);

                    ToolBase.Instance = tool;
                    this.SelectionViewModel.ToolType = ToolType.Node;

                    this.ViewModel.TipTextBegin(tool.Button.Title);
                    this.ViewModel.Invalidate();//Invalidate
                }
            };
        }
示例#5
0
        public void Complete(Vector2 startingPoint, Vector2 point, bool isOutNodeDistance)
        {
            if (this.MezzanineLayerage == null)
            {
                return;
            }

            if (isOutNodeDistance)
            {
                if (this.MezzanineLayerage == null)
                {
                    return;
                }
                ILayer mezzanineLayer = this.MezzanineLayerage.Self;


                Transformer transformerDestination = this.CreateTransformer(startingPoint, point, this._sizeWidth, this._sizeHeight);

                this.SelectionViewModel.Transformer  = transformerDestination;//Selection
                mezzanineLayer.Transform.Transformer = transformerDestination;

                //Refactoring
                mezzanineLayer.IsRefactoringRender     = true;
                mezzanineLayer.IsRefactoringIconRender = true;
                this.MezzanineLayerage.RefactoringParentsRender();
                this.MezzanineLayerage.RefactoringParentsIconRender();


                foreach (Layerage layerage in this.ViewModel.LayerageCollection.RootLayerages)
                {
                    ILayer layer = layerage.Self;

                    layer.IsSelected = false;
                }

                mezzanineLayer.IsSelected = true;
                this.MezzanineLayerage    = null;
            }
            else
            {
                LayerageCollection.RemoveMezzanine(this.ViewModel.LayerageCollection, this.MezzanineLayerage); //Mezzanine
            }
            //         this.SelectionViewModel.SetMode(this.ViewModel.LayerageCollection);//Selection

            LayerageCollection.ArrangeLayers(this.ViewModel.LayerageCollection);
            LayerageCollection.ArrangeLayersBackground(this.ViewModel.LayerageCollection);

            this.ViewModel.Invalidate(InvalidateMode.HD);//Invalidate
        }
        private void ConstructLayerageCollection()
        {
            if (LayerageCollection.ItemClick == null)
            {
                LayerageCollection.ItemClick += (layer) =>
                {
                    Layerage layerage = this.ViewModel.LayerageCollection.FindFirstLayerage(layer);

                    this.ItemClick(layerage);
                };
            }
            if (LayerageCollection.RightTapped == null)
            {
                LayerageCollection.RightTapped += (layer) =>
                {
                    Layerage layerage = this.ViewModel.LayerageCollection.FindFirstLayerage(layer);

                    this.ShowLayerMenu(layerage);
                };
            }

            if (LayerageCollection.VisibilityChanged == null)
            {
                LayerageCollection.VisibilityChanged += (layer2) =>
                {
                    Visibility visibility = (layer2.Visibility == Visibility.Visible) ? Visibility.Collapsed : Visibility.Visible;

                    if (layer2.IsSelected)
                    {
                        this.SelectionViewModel.Visibility = visibility;

                        this.MethodViewModel.ILayerChanged <Visibility>
                        (
                            set: (layer) => layer.Visibility = visibility,

                            historyTitle: "Set visibility",
                            getHistory: (layer) => layer.Visibility,
                            setHistory: (layer, previous) => layer.Visibility = previous
                        );
                    }
                    else
                    {
                        //History
                        LayersPropertyHistory history = new LayersPropertyHistory("Set visibility");

                        //Selection
                        ILayer layer = layer2;

                        var previous = layer.Visibility;
                        history.UndoAction += () =>
                        {
                            //Refactoring
                            layer.IsRefactoringRender     = true;
                            layer.IsRefactoringIconRender = true;
                            layer.Visibility = previous;
                        };

                        //Refactoring
                        layer.IsRefactoringRender     = true;
                        layer.IsRefactoringIconRender = true;
                        //layerage.RefactoringParentsRender();
                        //layerage.RefactoringParentsIconRender();
                        layer.Visibility = visibility;

                        //History
                        this.ViewModel.HistoryPush(history);

                        this.ViewModel.Invalidate();//Invalidate
                    }
                };
            }
            if (LayerageCollection.IsExpandChanged == null)
            {
                LayerageCollection.IsExpandChanged += (layer) =>
                {
                    layer.IsExpand = !layer.IsExpand;

                    Layerage layerage = this.ViewModel.LayerageCollection.FindFirstLayerage(layer);
                    LayerageCollection.ArrangeLayersVisibility(layerage);
                };
            }
            if (LayerageCollection.IsSelectedChanged == null)
            {
                LayerageCollection.IsSelectedChanged += (layer) =>
                {
                    Layerage layerage = this.ViewModel.LayerageCollection.FindFirstLayerage(layer);
                    this.MethodViewModel.MethodSelectedNot(layerage);//Method
                };
            }

            if (LayerageCollection.DragItemsStarted == null)
            {
                LayerageCollection.DragItemsStarted += (layer, manipulationMode) =>
                {
                    Layerage layerage = this.ViewModel.LayerageCollection.FindFirstLayerage(layer);

                    this.DragSourceLayerage = layerage;

                    if (manipulationMode == ManipulationModes.TranslateY)
                    {
                        this.DragLayerIsSelected = true;
                    }
                    else if (manipulationMode == ManipulationModes.System)
                    {
                        this.DragLayerIsSelected = false;
                    }
                };
            }
            if (LayerageCollection.DragItemsDelta == null)
            {
                LayerageCollection.DragItemsDelta += (layer, overlayMode) =>
                {
                    Layerage layerage = this.ViewModel.LayerageCollection.FindFirstLayerage(layer);

                    this.DragDestinationLayerage = layerage;
                    this.DragLayerOverlayMode    = overlayMode;
                };
            }
            if (LayerageCollection.DragItemsCompleted == null)
            {
                LayerageCollection.DragItemsCompleted += () =>
                {
                    //History
                    LayeragesArrangeHistory history = new LayeragesArrangeHistory("Layers arrange", this.ViewModel.LayerageCollection);
                    this.ViewModel.HistoryPush(history);

                    LayerageCollection.DragComplete(this.ViewModel.LayerageCollection, this.DragDestinationLayerage, this.DragSourceLayerage, this.DragLayerOverlayMode, this.DragLayerIsSelected);

                    this.SelectionViewModel.SetMode(this.ViewModel.LayerageCollection);//Selection
                    LayerageCollection.ArrangeLayers(this.ViewModel.LayerageCollection);
                    LayerageCollection.ArrangeLayersBackground(this.ViewModel.LayerageCollection);
                    this.ViewModel.Invalidate();//Invalidate

                    this.DragSourceLayerage      = null;
                    this.DragDestinationLayerage = null;
                    this.DragLayerIsSelected     = false;
                    this.DragLayerOverlayMode    = OverlayMode.None;
                };
            }
        }