Example #1
0
 /// <summary>
 /// Exports the given animations into a BundleSheetExport and returns the created sheet
 /// </summary>
 /// <param name="settings">The export settings for the sheet</param>
 /// <param name="anims">The list of animations to export</param>
 /// <param name="cancellationToken">A cancelation token that is passed to the exporters and can be used to cancel the export process mid-way</param>
 /// <param name="progressHandler">Optional event handler for reporting the export progress</param>
 /// <returns>A BundleSheetExport representing the animations passed ready to be saved to disk</returns>
 public async Task <BundleSheetExport> ExportBundleSheet(AnimationExportSettings settings, Animation[] anims, CancellationToken cancellationToken = new CancellationToken(), BundleExportProgressEventHandler progressHandler = null)
 {
     using (var atlas = await GenerateAtlasFromAnimations(settings, anims, "", cancellationToken, progressHandler))
     {
         return(BundleSheetExport.FromAtlas(atlas));
     }
 }
        /// <summary>
        /// Unloads the currently displayed export sheet preview
        /// </summary>
        public void UnloadExportSheet()
        {
            _sheetExport = null;
            _frameRects  = null;

            RefreshFrameBoundsPreview();

            Invalidate();
        }
Example #3
0
        /// <summary>
        /// Removes the currently displayed preview and disposes of the image
        /// </summary>
        public void RemovePreview()
        {
            if (zpb_sheetPreview.Image != null)
            {
                zpb_sheetPreview.Image.Dispose();
                zpb_sheetPreview.Image = null;
            }

            _bundleSheetExport = null;
        }
Example #4
0
 /// <summary>
 /// Exports the given animations into a BundleSheetExport and returns the created sheet
 /// </summary>
 /// <param name="sheet">The sheet to export</param>
 /// <param name="cancellationToken">A cancelation token that is passed to the exporters and can be used to cancel the export process mid-way</param>
 /// <param name="progressHandler">Optional event handler for reporting the export progress</param>
 /// <returns>A BundleSheetExport representing the animation sheet passed ready to be saved to disk</returns>
 public async Task <BundleSheetExport> ExportBundleSheet(AnimationSheet sheet, CancellationToken cancellationToken = new CancellationToken(), BundleExportProgressEventHandler progressHandler = null)
 {
     //
     // 1. Generate texture atlas
     //
     using (var atlas = await GenerateAtlasFromAnimationSheet(sheet, cancellationToken, progressHandler))
     {
         //
         // 2. Generate an export sheet from the texture atlas
         //
         return(BundleSheetExport.FromAtlas(atlas));
     }
 }
        /// <summary>
        /// Loads a bundle sheet export preview
        /// </summary>
        /// <param name="bundleSheetExport">The bundle sheet export containing data about the exported image</param>
        public void LoadExportSheet(BundleSheetExport bundleSheetExport)
        {
            UnloadExportSheet();

            // Reset the transformations
            Image        = bundleSheetExport.Sheet;
            _sheetExport = bundleSheetExport;

            RefreshFrameBoundsPreview();

            Invalidate();

            UpdateScrollbars();
        }
Example #6
0
 public BundleSheetJson(BundleSheetExport bundleSheet, string sheetName, string exportPath)
 {
     BundleSheet = bundleSheet;
     ExportPath  = exportPath;
     SheetName   = sheetName;
 }
Example #7
0
        /// <summary>
        /// Generates a preview for the AnimationSheet currently loaded into this form
        /// </summary>
        public void GeneratePreview()
        {
            RepopulateExportSettings();
            UpdateCountLabels();

            if (_sheetToEdit.Animations.Length <= 0)
            {
                lbl_alertLabel.Text    = AnimationMessages.TextNoAnimationInSheetToGeneratePreview;
                pnl_alertPanel.Visible = true;
                return;
            }

            // Time the bundle export
            pb_exportProgress.Visible = true;

            BundleExportProgressEventHandler handler = args =>
            {
                Invoke(new Action(() =>
                {
                    pb_exportProgress.Value = args.StageProgress;
                }));
            };

            var form = FindForm();

            if (form != null)
            {
                form.Cursor = Cursors.WaitCursor;
            }

            btn_generatePreview.Enabled = false;

            var sw = Stopwatch.StartNew();

            _sheetCancellation = new CancellationTokenSource();

            // Export the bundle
            var t = _controller.GenerateBundleSheet(_exportSettings, _sheetCancellation.Token, handler, _sheetToEdit.Animations);

            t.ContinueWith(task =>
            {
                Invoke(new Action(() =>
                {
                    btn_generatePreview.Enabled = true;

                    // Dispose of current preview
                    RemovePreview();

                    if (_sheetCancellation.IsCancellationRequested)
                    {
                        _sheetCancellation = null;
                        Close();
                        return;
                    }

                    _sheetCancellation = null;

                    _bundleSheetExport = task.Result;

                    Image img = _bundleSheetExport.Sheet;

                    sw.Stop();

                    if (form != null)
                    {
                        form.Cursor = Cursors.Default;
                    }

                    zpb_sheetPreview.SetImage(img);

                    pb_exportProgress.Visible = false;

                    // Update labels
                    lbl_sheetPreview.Text = AnimationMessages.TextSheetPreviewGenerated + sw.ElapsedMilliseconds + @"ms)";

                    lbl_dimensions.Text    = img.Width + @"x" + img.Height;
                    lbl_pixelCount.Text    = (img.Width * img.Height).ToString("N0");
                    lbl_framesOnSheet.Text = (_bundleSheetExport.FrameCount - _bundleSheetExport.ReusedFrameCount) + "";
                    lbl_reusedFrames.Text  = (_bundleSheetExport.ReusedFrameCount) + "";
                    lbl_memoryUsage.Text   = Utilities.FormatByteSize(ImageUtilities.MemoryUsageOfImage(img));

                    if (pnl_alertPanel.Visible &&
                        lbl_alertLabel.Text == AnimationMessages.TextNoAnimationInSheetToGeneratePreview)
                    {
                        pnl_alertPanel.Visible = false;
                    }

                    if (cb_showFrameBounds.Checked)
                    {
                        ShowFrameBounds();
                    }
                }));
            });
        }