Пример #1
0
        public bool Start()
        {
            // stop if no image is selected
            if (editData.SelectedImages.Count == 0) return false;

            List<Image> newOrder = new List<Image>(editData.Collage.Images);
            Rectangle testBoundary = new Rectangle(0, 0, 1000, 600);

            foreach(Image image in editData.SelectedImages)
            {
                int index = newOrder.IndexOf(image);
                newOrder.Remove(image);
                Rectangle rec1 = image.GetRectangleInBoundary(testBoundary);

                for(int i = index; i< newOrder.Count; i++)
                {
                    index = i;
                    Rectangle rec2 = newOrder[i].GetRectangleInBoundary(testBoundary);
                    if (Utils.CouldOverlap(rec1, rec2, image.Rotation, newOrder[i].Rotation)) break;
                }
                newOrder.Insert((int)MathHelper.Clamp(index + 1, 0, newOrder.Count), image);
            }

            Command command = new Command(ExecuteOrderChange, ExecuteOrderChange, newOrder, "Set Forward");
            editData.UndoManager.ExecuteAndAddCommand(command);

            return false;
        }
        public bool Update()
        {
            if (colorChooser == null && !dataAccess.GuiThread.WaitsToInvoke) dataAccess.GuiThread.Invoke(OpenColorDialog);
            if (colorChooser != null)
            {
                editData.Collage.BackgroundColor = colorChooser.SelectedColor;
                if (colorChooser.Response != Gtk.ResponseType.None && colorChooser.Response != Gtk.ResponseType.Ok)
                {
                    editData.Collage.BackgroundColor = startColor;
                    colorChooser.Destroy();
                    colorChooser = null;
                    return false;
                }
                if (colorChooser.Response == Gtk.ResponseType.Ok)
                {
                    Command command = new Command(ExecuteColorChange, ExecuteColorChange, colorChooser.SelectedColor, "Change Background Color");
                    command.SetUndoData(startColor);
                    editData.UndoManager.AddCommand(command);

                    colorChooser.Destroy();
                    colorChooser = null;
                    return false;
                }
            }
            return true;
        }
Пример #3
0
        public bool Update()
        {
            if (dataAccess.Input.ScrollWheelDifference != 0) startTime = DateTime.Now;
            foreach (Image image in editData.SelectedImages)
            {
                image.Width *= (dataAccess.Input.ScrollWheelDifference / 2000f) + 1;
                image.Width = Math.Max(image.Width, 0.01f);
            }

            bool continueScale = (DateTime.Now - startTime).Milliseconds < 300          // stop when the time is up
                && !dataAccess.Input.IsStrg                                             // stop when the user wants to zoom instead of scale
                && !(dataAccess.Input.IsLeftButtonDown && (!editData.SelectedImages.Contains(editData.ImageUnderMouse) || editData.ImageUnderMouse == null)); // stop when the user clicks somewhere, where no selection is

            if (!continueScale)
            {
                float[] newWidth = new float[editData.SelectedImages.Count];
                for (int i = 0; i < editData.SelectedImages.Count; i++)
                {
                    newWidth[i] = editData.SelectedImages[i].Width;
                }
                Command command = new Command(ExecuteScale, ExecuteScale, newWidth, "Scale Selected Images");
                command.SetUndoData(startWidth);
                editData.UndoManager.AddCommand(command);
            }
            return continueScale;
        }
Пример #4
0
 public bool Start()
 {
     List<Image> images = new List<Image>();
     foreach(Image image in editData.SelectedImages)
     {
         images.Add(image);
     }
     Command command = new Command(ExecuteRemoveImages, ExecuteAddImages, images, "Remove images");
     editData.UndoManager.ExecuteAndAddCommand(command);
     return false;
 }
Пример #5
0
 public bool Start()
 {
     List<Image> newOrder = new List<Image>(editData.Collage.Images);
     foreach (Image image in editData.SelectedImages)
     {
         newOrder.Remove(image);
         newOrder.Add(image);
     }
     Command command = new Command(ExecuteOrderChange, ExecuteOrderChange, newOrder, "Set To Front");
     editData.UndoManager.ExecuteAndAddCommand(command);
     return false;
 }
Пример #6
0
        public bool Start()
        {
            List<Image> newSelection = new List<Image>();

            bool selectionChanged = false;
            Rectangle drawRectangle = editData.DrawRectangle.Rectangle;

            if (!dataAccess.Input.IsShift)
            {
                // single selection
                Image newSelectedImage = editData.ImageUnderMouse;
                if (!editData.SelectedImages.Contains(newSelectedImage))
                {
                    if (newSelectedImage != null)
                    {
                        newSelection.Add(newSelectedImage);
                        selectionChanged = editData.SelectedImages.Count != 1 || !editData.SelectedImages.Contains(newSelectedImage);
                    }
                    else
                    {
                        selectionChanged = editData.SelectedImages.Count != 0;
                    }
                }
            }
            else
            {
                // multiselect
                newSelection.AddRange(editData.SelectedImages);

                Image newSelectedImage = editData.ImageUnderMouse;
                if(newSelectedImage != null)
                {
                    if (editData.SelectedImages.Contains(newSelectedImage)) newSelection.Remove(newSelectedImage);
                    else newSelection.Add(newSelectedImage);
                    selectionChanged = true;
                }
            }

            if (selectionChanged)
            {
                Command command = new Command(ExecuteSelection, ExecuteSelection, newSelection, "Select Image(s)");
                editData.UndoManager.ExecuteAndAddCommand(command);
            }
            return false;
        }
Пример #7
0
 public bool Update()
 {
     bool continueMove = dataAccess.Input.IsLeftButtonDown;
     if (continueMove)
     {
         foreach (Image image in editData.SelectedImages)
         {
             image.SetCenterInBoundary(editData.DrawRectangle.Rectangle, image.GetCenterInBoundary(editData.DrawRectangle.Rectangle) + dataAccess.Input.MouseDifferenceVector);
         }
         totalMove += dataAccess.Input.MouseDifferenceVector;
     }
     else
     {
         Command command = new Command(ExecuteMove, ExecuteMove, totalMove, "Move Selected Images");
         command.SetUndoData(-totalMove);
         editData.UndoManager.AddCommand(command);
     }
     return continueMove;
 }
        public bool Start()
        {
            if (editData.SelectedImages.Count > 0)
            {
                Image newBackgroundImage = editData.SelectedImages.First();

                ImageData newImageData = new ImageData();
                newImageData.Center = new Vector2(0.5f);
                newImageData.Rotation = 0f;
                newImageData.Width = 1f;

                int oldIndex = editData.Collage.Images.IndexOf(newBackgroundImage);

                Command command = new Command(ExecuteSetAsBackground, UndoSetAsBackground, new List<object>() { oldIndex, newImageData }, "Set To Front");
                command.SetUndoData(new List<object>() { oldIndex, newBackgroundImage.Data });
                editData.UndoManager.ExecuteAndAddCommand(command);
            }
            return false;
        }
Пример #9
0
        public bool Update()
        {
            bool areFilesChoosed = !dataAccess.GuiThread.IsBlockedByDialog;

            if (areFilesChoosed)
            {
                string[] fileNames = ofw.SelectedFiles;
                ofw.Destroy();
                if (fileNames != null)
                {
                    // make a list of all new images.
                    List<Image> images = new List<Image>();
                    for (int i = 0; i < fileNames.Length; i++)
                    {
                        // check if the image needs a new Source or if another one can be reused
                        ImageSource imageSource = null;
                        foreach (Image img in editData.Collage.Images)
                        {
                            if (img.Source.FileName == fileNames[i])
                            {
                                imageSource = img.Source;
                                break;
                            }
                        }
                        Image image;
                        if (imageSource == null) image = new Image(dataAccess, fileNames[i]);
                        else image = new Image(imageSource);

                        // set a random position
                        image.Center = new Vector2((float)dataAccess.Random.NextDouble(), (float)dataAccess.Random.NextDouble());

                        images.Add(image);
                    }
                    // make a command that can load all images at once
                    Command command = new Command(ExecuteAddImages, ExecuteRemoveImages, images, "Add new images");
                    editData.UndoManager.ExecuteAndAddCommand(command);
                }
            }
            return !areFilesChoosed;
        }
Пример #10
0
        public bool Update()
        {
            foreach(Image image in editData.SelectedImages)
            {
                Vector2 difference = dataAccess.Input.MousePositionVector - image.GetCenterInBoundary(editData.DrawRectangle.Rectangle);
                image.Rotation = (float)Math.Atan2(difference.Y, difference.X) + rotationOffset[editData.SelectedImages.IndexOf(image)];
            }

            bool continueRotation = dataAccess.Input.IsRightButtonDown;
            if(!continueRotation)
            {
                float[] newRotation = new float[editData.SelectedImages.Count];
                for (int i = 0; i < editData.SelectedImages.Count; i++)
            {
                newRotation[i] = editData.SelectedImages[i].Rotation;
            }
                Command command = new Command(ExecuteScale, ExecuteScale, newRotation, "Scale Selected Images");
                command.SetUndoData(startRotation);
                editData.UndoManager.AddCommand(command);
            }
            return continueRotation;
        }
        public bool Update()
        {
            // allow to zoom and move the view
            editData.DrawRectangle.Zoom(-dataAccess.Input.ScrollWheelDifference / 10f, dataAccess.Input.MousePositionVector);
            if (dataAccess.Input.IsMiddleButtonDown) editData.DrawRectangle.Move(dataAccess.Input.MouseDifferenceVector);

            UpdateButtons();

            if(IsCanceled())
            {
                editData.DrawRectangle.AspectRatio = startAspectRatio;
                return false;
            }

            if (IsConfirmed())
            {
                Command command = new Command(ExecuteAspectRatioChange, ExecuteAspectRatioChange, editData.Collage.AspectRatio, "Change Aspect Ratio");
                command.SetUndoData(startAspectRatio);
                editData.UndoManager.AddCommand(command);
                return false;
            }
            else
            {
                Rectangle newDrawPosition = editData.DrawRectangle.Rectangle;

                // change size
                if (rightMoveButton.IsDown) newDrawPosition.Width += dataAccess.Input.MouseDifferencePoint.X;
                if (downMoveButton.IsDown) newDrawPosition.Height += dataAccess.Input.MouseDifferencePoint.Y;
                // set minimum size
                if (newDrawPosition.Width < 50) newDrawPosition.Width = 50;
                if (newDrawPosition.Height < 50) newDrawPosition.Height = 50;

                editData.DrawRectangle.SetRectangle(newDrawPosition);

                SetButtonPositions();
                return true;
            }
        }
Пример #12
0
 public bool Start()
 {
     Command command = new Command(ExecuteClearCollage, UndoClearCollage, null, "Clear Collage");
     editData.UndoManager.ExecuteAndAddCommand(command);
     return false;
 }
        public bool Update()
        {
            if(dataAccess.Input.IsKeyPressed(Keys.Escape))
            {
                editData.SelectedImages.Clear();
                editData.SelectedImages.AddRange(selectionBefore);
                return false;
            }

            if (dataAccess.Input.IsLeftButtonReleased || dataAccess.Input.AreKeysPressed(Keys.Enter))
            {
                Command command = new Command(ExecuteSelectionChange, ExecuteSelectionChange, new List<Image>(editData.SelectedImages), "Random Selection");
                command.SetUndoData(selectionBefore);
                editData.UndoManager.AddCommand(command);
                return false;
            }
            else
            {
                selectionFraction = dataAccess.Input.MousePositionVector.X / (float)dataAccess.GraphicsDevice.Viewport.Width;
                selectionFraction = MathHelper.Clamp(selectionFraction, 0, 1);

                editData.SelectedImages.Clear();
                editData.SelectedImages.AddRange(randomOrder.GetRange(0, (int)Math.Floor(randomOrder.Count * selectionFraction)));
                return true;
            }
        }
Пример #14
0
        public bool Start()
        {
            List<object> currentData = GetCurrentData();
            List<object> calculationData = CalculateAutoPosition();

            Command command = new Command(ExecuteAutoPosition, ExecuteAutoPosition, calculationData, "Auto Position");
            command.SetUndoData(currentData);
            editData.UndoManager.ExecuteAndAddCommand(command);

            return false;
        }
Пример #15
0
 public bool Start()
 {
     Command command = new Command(ExecuteSelectAll, ExecuteUndoSelectAll, null, "Select All");
     editData.UndoManager.ExecuteAndAddCommand(command);
     return false;
 }