Пример #1
0
        public ImageData GetCopy()
        {
            ImageData imageData = new ImageData();
            imageData.Center = Center;
            imageData.Width = Width;
            imageData.Rotation = Rotation;

            return imageData;
        }
        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;
        }
Пример #3
0
 public void SetDefaultData()
 {
     data = new ImageData();
     data.Center = new Vector2(0.5f);
     data.Width = 0.2f;
     data.Rotation = 0f;
 }
Пример #4
0
        public List<object> CalculateAutoPosition()
        {
            int amount = editData.Collage.Images.Count;
            List<Image> order = new List<Image>();
            List<ImageData> imageDataList = new List<ImageData>();

            int lines = (int)Math.Min(Math.Max(1, Math.Floor(Math.Sqrt(amount / editData.Collage.AspectRatio))), amount);
            int needToAddAmount = amount % Math.Max(1, lines);

            for (int i = 0; i < lines; i++)
            {
                // calculates how many images will go in this line
                int imagesInLine = amount / lines;
                if (needToAddAmount > 0)
                {
                    if (dataAccess.Random.NextDouble() < 1 / (float)lines || needToAddAmount == lines - i)
                    {
                        imagesInLine++;
                        needToAddAmount--;
                    }
                }

                // calculates an ImageData object for every Image in this line
                for (int j = 0; j < imagesInLine; j++)
                {
                    ImageData data = new ImageData();

                    // position
                    Vector2 newCenter = new Vector2();
                    newCenter.X = 1 / (float)imagesInLine * (j + 0.5f);
                    newCenter.Y = (1 / (float)(lines + 1) * (i + 1) - 0.5f) * MathHelper.Clamp(200 / (float)amount, 1.02f, 1.15f) + 0.5f;
                    newCenter.X += (float)(dataAccess.Random.NextDouble() * 2 - 1) / imagesInLine / 2f;  // randomize X direction
                    newCenter.Y += (float)(dataAccess.Random.NextDouble() * 2 - 1) / lines / 2f;         // randomize Y direction
                    data.Center = newCenter;

                    // rotation
                    data.Rotation = (float)(dataAccess.Random.NextDouble() * 2 - 1) / 10;   // random amount of rotation

                    // scale
                    float newWidth = newWidth = 1 / (float)imagesInLine * 1.7f;
                    newWidth += (float)(dataAccess.Random.NextDouble() * 2 - 1) * newWidth / 2; // randomize scale
                    data.Width = newWidth;

                    imageDataList.Add(data);
                }
            }

            // change order
            List<Image> orderBuffer = new List<Image>(editData.Collage.Images);
            List<ImageData> dataBuffer = new List<ImageData>(imageDataList);
            imageDataList.Clear();
            for (int i = 0; i < amount; i++)
            {
                int index = dataAccess.Random.Next(orderBuffer.Count);
                // order
                order.Add(orderBuffer[index]);
                orderBuffer.Remove(orderBuffer[index]);
                // image data
                imageDataList.Add(dataBuffer[index]);
                dataBuffer.Remove(dataBuffer[index]);
            }

            List<object> calculationData = new List<object>() { order, imageDataList };
            return calculationData;
        }