Exemplo n.º 1
0
        /// <summary>Initializes a new instance of the <see cref="ExtractParameters"/> class.</summary>
        /// <param name="settings">The plug in settings.</param>
        /// <param name="data">The data structure that will hold the information used to extract sprites.</param>
        /// <param name="textureFile">The file used as the texture.</param>
        /// <param name="extractor">The extractor used to build the sprites.</param>
        /// <param name="colorPicker">The color picker service.</param>
        /// <param name="folderBrowser">The project file system folder browser service.</param>
        /// <param name="commonServices">The common services.</param>
        /// <exception cref="ArgumentNullException">Thrown when the any parameters are <b>null</b>.</exception>
        /// <exception cref="ArgumentMissingException">Thrown when the <see cref="SpriteExtractionData.Texture"/> property of the <paramref name="data"/> parameter is <b>null</b>.</exception>
        public ExtractParameters(ExtractSpriteToolSettings settings, SpriteExtractionData data, IContentFile textureFile, IExtractorService extractor, IColorPickerService colorPicker, IFileSystemFolderBrowseService folderBrowser, IViewModelInjection commonServices)
            : base(commonServices)
        {
            Settings      = settings ?? throw new ArgumentNullException(nameof(settings));
            Data          = data ?? throw new ArgumentNullException(nameof(data));
            Extractor     = extractor ?? throw new ArgumentNullException(nameof(extractor));
            ColorPicker   = colorPicker ?? throw new ArgumentNullException(nameof(colorPicker));
            FolderBrowser = folderBrowser ?? throw new ArgumentNullException(nameof(folderBrowser));
            TextureFile   = textureFile ?? throw new ArgumentNullException(nameof(textureFile));

            if (data.Texture == null)
            {
                throw new ArgumentMissingException(nameof(data.Texture), nameof(data));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Function to show the tool form.
        /// </summary>
        private void ShowForm()
        {
            FormExtract         _form   = null;
            GorgonTexture2DView texture = null;
            Stream fileStream           = null;
            ExtractSpriteToolSettings settings;
            IGorgonImage image = null;
            IContentFile textureFile;

            CommonServices.BusyService.SetBusy();

            try
            {
                settings = ToolPlugInService.ReadContentSettings <ExtractSpriteToolSettings>(typeof(ExtractSpriteToolPlugIn).FullName);

                if (settings == null)
                {
                    settings = new ExtractSpriteToolSettings();
                }

                textureFile = _fileManager.SelectedFile;
                fileStream  = textureFile.OpenRead();

                texture = GorgonTexture2DView.FromStream(GraphicsContext.Graphics, fileStream, _defaultImageCodec, options: new GorgonTexture2DLoadOptions
                {
                    Name          = "Extractor Texture Atlas",
                    Binding       = TextureBinding.ShaderResource,
                    Usage         = ResourceUsage.Default,
                    IsTextureCube = false
                });

                image = texture.Texture.ToImage();

                fileStream.Dispose();

                if (string.IsNullOrWhiteSpace(settings.LastOutputDir))
                {
                    settings.LastOutputDir = Path.GetDirectoryName(textureFile.Path).FormatDirectory('/');
                }
                else
                {
                    if (!_fileManager.DirectoryExists(settings.LastOutputDir.FormatDirectory('/')))
                    {
                        settings.LastOutputDir = Path.GetDirectoryName(textureFile.Path).FormatDirectory('/');
                    }
                }

                _extractData.Value.Texture   = texture;
                _extractData.Value.SkipEmpty = settings.AllowEmptySpriteSkip;
                _extractData.Value.SkipColor = new GorgonColor(settings.SkipColor);

                var extractViewModel = new Extract();
                extractViewModel.Initialize(new ExtractParameters(settings,
                                                                  _extractData.Value,
                                                                  textureFile,
                                                                  new ExtractorService(GraphicsContext.Renderer2D, _fileManager,
                                                                                       new GorgonV3SpriteBinaryCodec(GraphicsContext.Renderer2D)),
                                                                  new ColorPickerService(),
                                                                  FolderBrowser,
                                                                  CommonServices));

                _form = new FormExtract();
                _form.SetupGraphics(GraphicsContext);
                _form.SetDataContext(extractViewModel);
                _form.ShowDialog(GorgonApplication.MainForm);

                ToolPlugInService.WriteContentSettings(typeof(ExtractSpriteToolPlugIn).FullName, settings);
            }
            catch (Exception ex)
            {
                CommonServices.MessageDisplay.ShowError(ex, Resources.GOREST_ERR_LAUNCH);
            }
            finally
            {
                _form?.Dispose();
                fileStream?.Dispose();
                image?.Dispose();
                texture?.Dispose();
                CommonServices.BusyService.SetIdle();
            }
        }