예제 #1
0
 private async void editorWrapper_Drop(object sender, DragEventArgs e)
 {
     if (e.Data.GetDataPresent(DataFormats.FileDrop))
     {
         string[] paths;
         try
         {
             paths = (e.Data.GetData(DataFormats.FileDrop) as string[]).OrderBy(p => Convert.ToInt32(System.IO.Path.GetFileNameWithoutExtension(p))).ToArray();
         }
         catch
         {
             paths = (e.Data.GetData(DataFormats.FileDrop) as string[]).OrderBy(p => p).ToArray();
         }
         SpriteSheet = new SpriteSheetGenerator(paths);
         SpriteSheet.ClipTransparent = switchClip.SwitchStatus == SwitchStatus.On ? true : false;
         SpriteSheet.Reverse         = switchReverse.SwitchStatus == SwitchStatus.On ? true : false;
         SpriteSheet.OnProgress     += SpriteSheet_OnProgress;
         SpriteTask = new Task(() =>
         {
             SpriteSheet.Load();
         });
         SpriteTask.Start();
         await SpriteTask;
         Update();
         textPath.Text = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(paths[0]), "SpriteSheet.png");
     }
 }
예제 #2
0
        public async void Update()
        {
            workSpace.Visibility = Visibility.Visible;
            Columns = SpriteSheet.Columns;
            if (switchMultiRow.SwitchStatus == SardineFish.Windows.Controls.SwitchStatus.Off)
            {
                Columns = SpriteSheet.Images.Count;
            }
            Rows = (int)Math.Ceiling((double)SpriteSheet.Images.Count / Columns);

            RenderImageSize = new Vector(Columns * SpriteSheet.MaxWidth, Rows * SpriteSheet.MaxHeight);
            if (switchSnap2Pow.SwitchStatus == SwitchStatus.On)
            {
                var size = (int)Math.Pow(2, Math.Ceiling(Math.Log(RenderImageSize.X, 2)));
                RenderImageSize = new Vector(size, size);
            }
            PreviewImageSize = RenderImageSize;

            images.Children.Clear();
            double scale = 1;

            if (switchMultiRow.SwitchStatus == SwitchStatus.On)
            {
                if (PreviewImageSize.X > workSpace.ActualWidth - 64)
                {
                    scale             = (workSpace.ActualWidth - 64) / RenderImageSize.X;
                    PreviewImageSize *= scale;
                }
            }
            else
            {
                if (PreviewImageSize.Y > workSpace.ActualHeight - 128)
                {
                    scale             = (workSpace.ActualHeight - 128) / RenderImageSize.Y;
                    PreviewImageSize *= scale;
                }
            }
            images.Width  = PreviewImageSize.X;
            images.Height = PreviewImageSize.Y;

            var centerOffset = new Vector(workSpace.ActualWidth - PreviewImageSize.X, workSpace.ActualHeight - PreviewImageSize.Y);

            centerOffset /= 2;
            if (switchMultiRow.SwitchStatus == SwitchStatus.On && PreviewImageSize.Y > workSpace.ActualHeight)
            {
                centerOffset.Y += (PreviewImageSize.Y - workSpace.ActualHeight) / 2 + 32;
            }
            else if (switchMultiRow.SwitchStatus == SwitchStatus.Off && PreviewImageSize.X > workSpace.ActualWidth)
            {
                centerOffset.X += (PreviewImageSize.X - workSpace.ActualWidth) / 2 + 64;
            }
            imagesTransform.X = centerOffset.X;
            imagesTransform.Y = centerOffset.Y;

            for (var i = 0; i < SpriteSheet.Images.Count; i++)
            {
                var img = SpriteSheet.Images[i];

                var grid = new Grid();
                grid.Width  = SpriteSheet.MaxWidth * scale;
                grid.Height = SpriteSheet.MaxHeight * scale;
                var image = new Image();

                /*var task = new Task<WriteableBitmap>(() => SpriteSheetGenerator.ToWriteableBitmap(img, SpriteSheet.MaxWidth, SpriteSheet.MaxHeight));
                 * task.Start();*/
                image.Source = SpriteSheetGenerator.ToWriteableBitmap(img, SpriteSheet.MaxWidth, SpriteSheet.MaxHeight);

                image.SetValue(RenderOptions.BitmapScalingModeProperty, BitmapScalingMode.HighQuality);
                image.SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Unspecified);
                image.SnapsToDevicePixels = true;
                image.Width   = SpriteSheet.MaxWidth * scale;
                image.Height  = SpriteSheet.MaxHeight * scale;
                image.Stretch = Stretch.Fill;
                grid.Children.Add(image);
                images.Children.Add(grid);

                progressBar.Value = 100 * PreviewLoadProgress * ((double)(i + 1) / SpriteSheet.Images.Count) + 100 * (1 - PreviewLoadProgress);
            }

            await Task.Delay(500);

            progressBar.Value = 0;
        }