示例#1
0
        /// <summary>
        /// Function to retrieve the ribbon button for the tool.
        /// </summary>
        /// <param name="project">The project data.</param>
        /// <param name="fileManager">The project file manager.</param>
        /// <returns>A new tool ribbon button instance.</returns>
        /// <exception cref="ArgumentNullException">Thrown when the <paramref name="project"/>, or the <paramref name="fileManager"/> parameter is <b>null</b>.</exception>
        /// <remarks>
        /// <para>
        /// This will return data to describe a new button for the tool in the plug in. If the return value is <b>null</b>, then the tool will not be available on the ribbon.
        /// </para>
        /// </remarks>
        public IToolPlugInRibbonButton GetToolButton(IProject project, IContentFileManager fileManager)
        {
            if (project == null)
            {
                throw new ArgumentNullException(nameof(project));
            }

            if (fileManager == null)
            {
                throw new ArgumentNullException(nameof(fileManager));
            }

            IGorgonFileSystemWriter <Stream> scratchWriter = GetScratchArea(project.TempDirectory);

            return(OnGetToolButton(fileManager, scratchWriter));
        }
示例#2
0
 /// <summary>Initializes a new instance of the <see cref="T:Gorgon.Editor.ImageEditor.ImageIO"/> class.</summary>
 /// <param name="defaultCodec">The default codec used by the plug in.</param>
 /// <param name="installedCodecs">The list of installed codecs.</param>
 /// <param name="importDialog">The dialog service used to export an image.</param>
 /// <param name="busyService">The busy state service.</param>
 /// <param name="scratchArea">The file system writer used to write to the temporary area.</param>
 /// <param name="bcCompressor">The block compressor used to block (de)compress image data.</param>
 /// <param name="log">The logging interface to use.</param>
 public ImageIOService(IGorgonImageCodec defaultCodec,
                       ICodecRegistry installedCodecs,
                       IExportImageDialogService exportDialog,
                       IImportImageDialogService importDialog,
                       IBusyStateService busyService,
                       IGorgonFileSystemWriter <Stream> scratchArea,
                       TexConvCompressor bcCompressor,
                       IGorgonLog log)
 {
     _exportDialog   = exportDialog;
     _importDialog   = importDialog;
     DefaultCodec    = defaultCodec;
     InstalledCodecs = installedCodecs;
     ScratchArea     = scratchArea;
     _compressor     = bcCompressor;
     _busyState      = busyService;
     _log            = log ?? GorgonLog.NullLog;
 }
 /// <summary>Initializes a new instance of the <see cref="T:Gorgon.Editor.SpriteEditor.SpriteContentParameters"/> class.</summary>
 /// <param name="factory">The factory for building sprite content data.</param>
 /// <param name="spriteFile">The sprite file.</param>
 /// <param name="spriteTextureFile">The sprite texture file.</param>
 /// <param name="fileManager">The file manager used to access external content.</param>
 /// <param name="textureService">The texture service to use when reading sprite texture data.</param>
 /// <param name="sprite">The sprite being edited.</param>
 /// <param name="codec">The codec to use when reading/writing sprite data.</param>
 /// <param name="manualRectEdit">The manual rectangle editor view model.</param>
 /// <param name="manualVertexEdit">The manual vertex editor view model.</param>
 /// <param name="spritePickMaskEditor">The sprite picker mask color editor.</param>
 /// <param name="colorEditor">The color editor for the sprite.</param>
 /// <param name="anchorEditor">The anchor editor for the sprite.</param>
 /// <param name="wrapEditor">The texture wrapping state editor for the sprite.</param>
 /// <param name="settings">The plug in settings view model.</param>
 /// <param name="undoService">The undo service.</param>
 /// <param name="scratchArea">The file system used to write out temporary working data.</param>
 /// <param name="commonServices">Common application services.</param>
 public SpriteContentParameters(
     ISpriteContentFactory factory,
     IContentFile spriteFile,
     IContentFile spriteTextureFile,
     IContentFileManager fileManager,
     ISpriteTextureService textureService,
     GorgonSprite sprite,
     IGorgonSpriteCodec codec,
     IManualRectangleEditor manualRectEdit,
     IManualVertexEditor manualVertexEdit,
     ISpritePickMaskEditor spritePickMaskEditor,
     ISpriteColorEdit colorEditor,
     ISpriteAnchorEdit anchorEditor,
     ISpriteWrappingEditor wrapEditor,
     ISamplerBuildService samplerBuilder,
     IEditorPlugInSettings settings,
     IUndoService undoService,
     IGorgonFileSystemWriter <Stream> scratchArea,
     IViewModelInjection commonServices)
     : base(spriteFile, commonServices)
 {
     Factory               = factory ?? throw new ArgumentNullException(nameof(factory));
     Sprite                = sprite ?? throw new ArgumentNullException(nameof(sprite));
     UndoService           = undoService ?? throw new ArgumentNullException(nameof(undoService));
     ContentFileManager    = fileManager ?? throw new ArgumentNullException(nameof(fileManager));
     ScratchArea           = scratchArea ?? throw new ArgumentNullException(nameof(scratchArea));
     TextureService        = textureService ?? throw new ArgumentNullException(nameof(textureService));
     SpriteCodec           = codec ?? throw new ArgumentNullException(nameof(codec));
     ManualRectangleEditor = manualRectEdit ?? throw new ArgumentNullException(nameof(manualRectEdit));
     ManualVertexEditor    = manualVertexEdit ?? throw new ArgumentNullException(nameof(manualVertexEdit));
     SpritePickMaskEditor  = spritePickMaskEditor ?? throw new ArgumentNullException(nameof(spritePickMaskEditor));
     Settings              = settings ?? throw new ArgumentNullException(nameof(settings));
     ColorEditor           = colorEditor ?? throw new ArgumentNullException(nameof(colorEditor));
     AnchorEditor          = anchorEditor ?? throw new ArgumentNullException(nameof(anchorEditor));
     SpriteWrappingEditor  = wrapEditor ?? throw new ArgumentNullException(nameof(wrapEditor));
     SamplerBuilder        = samplerBuilder ?? throw new ArgumentNullException(nameof(samplerBuilder));
     SpriteTextureFile     = spriteTextureFile;
 }
示例#4
0
        /// <summary>Function to open a content object from this plugin.</summary>
        /// <param name="file">The file that contains the content.</param>
        /// <param name = "fileManager" > The file manager used to access other content files.</param>
        /// <param name="scratchArea">The file system for the scratch area used to write transitory information.</param>
        /// <param name="undoService">The undo service for the plug in.</param>
        /// <returns>A new IEditorContent object.</returns>
        /// <remarks>
        /// The <paramref name="scratchArea" /> parameter is the file system where temporary files to store transitory information for the plug in is stored. This file system is destroyed when the
        /// application or plug in is shut down, and is not stored with the project.
        /// </remarks>
        protected async override Task <IEditorContent> OnOpenContentAsync(IContentFile file, IContentFileManager fileManager, IGorgonFileSystemWriter <Stream> scratchArea, IUndoService undoService)
        {
            var content = new SpriteContent();
            GorgonTexture2DView   spriteImage = null;
            IContentFile          imageFile;
            GorgonSprite          sprite;
            ISpriteTextureService textureService;
            Stream stream = null;

            try
            {
                textureService = new SpriteTextureService(GraphicsContext, fileManager, _ddsCodec);

                // Load the sprite image.
                (spriteImage, imageFile) = await textureService.LoadFromSpriteContentAsync(file);

                // Load the sprite now.
                stream = file.OpenRead();
                sprite = _defaultCodec.FromStream(stream, spriteImage);

                var settings = new EditorPlugInSettings();
                ISpritePickMaskEditor spritePickMaskEditor = settings;
                settings.Initialize(new SettingsParameters(_settings, CommonServices));

                var manualRectEdit = new ManualRectangleEditor();
                manualRectEdit.Initialize(new ManualInputParameters(settings, CommonServices));

                var manualVertexEdit = new ManualVertexEditor();
                manualVertexEdit.Initialize(new ManualInputParameters(settings, CommonServices));

                var colorEditor = new SpriteColorEdit();
                colorEditor.Initialize(CommonServices);

                var anchorEditor = new SpriteAnchorEdit();
                anchorEditor.Initialize(CommonServices);

                var samplerBuilder = new SamplerBuildService(new GorgonSamplerStateBuilder(GraphicsContext.Graphics));

                var wrapEditor = new SpriteWrappingEditor();
                wrapEditor.Initialize(new SpriteWrappingEditorParameters(samplerBuilder, CommonServices));

                content.Initialize(new SpriteContentParameters(this,
                                                               file,
                                                               imageFile,
                                                               fileManager,
                                                               textureService,
                                                               sprite,
                                                               _defaultCodec,
                                                               manualRectEdit,
                                                               manualVertexEdit,
                                                               spritePickMaskEditor,
                                                               colorEditor,
                                                               anchorEditor,
                                                               wrapEditor,
                                                               samplerBuilder,
                                                               settings,
                                                               undoService,
                                                               scratchArea,
                                                               CommonServices));

                // If we have a texture, then read its data into RAM.
                if (sprite.Texture != null)
                {
                    await content.ExtractImageDataAsync();
                }

                return(content);
            }
            catch
            {
                spriteImage?.Dispose();
                throw;
            }
            finally
            {
                stream?.Dispose();
            }
        }
示例#5
0
        /// <summary>Function to open a content object from this plugin.</summary>
        /// <param name="file">The file that contains the content.</param>
        /// <param name = "fileManager" > The file manager used to access other content files.</param>
        /// <param name="injector">Parameters for injecting dependency objects.</param>
        /// <param name="scratchArea">The file system for the scratch area used to write transitory information.</param>
        /// <param name="undoService">The undo service for the plug in.</param>
        /// <returns>A new IEditorContent object.</returns>
        /// <remarks>
        /// The <paramref name="scratchArea" /> parameter is the file system where temporary files to store transitory information for the plug in is stored. This file system is destroyed when the
        /// application or plug in is shut down, and is not stored with the project.
        /// </remarks>
        protected async override Task <IEditorContent> OnOpenContentAsync(IContentFile file, IContentFileManager fileManager, IGorgonFileSystemWriter <Stream> scratchArea, IUndoService undoService)
        {
            FileInfo          texConvExe = GetTexConvExe();
            TexConvCompressor compressor = null;

            if (texConvExe.Exists)
            {
                compressor = new TexConvCompressor(texConvExe, scratchArea, _ddsCodec);
            }

            var imageIO = new ImageIOService(_ddsCodec,
                                             _codecs,
                                             new ExportImageDialogService(_settings),
                                             new ImportImageDialogService(_settings, _codecs),
                                             CommonServices.BusyService,
                                             scratchArea,
                                             compressor,
                                             CommonServices.Log);

            (IGorgonImage image, IGorgonVirtualFile workingFile, BufferFormat originalFormat)imageData = await Task.Run(() =>
            {
                using (Stream inStream = file.OpenRead())
                {
                    return(imageIO.LoadImageFile(inStream, file.Name));
                }
            });

            var services = new ImageEditorServices
            {
                CommonServices        = CommonServices,
                ImageIO               = imageIO,
                UndoService           = undoService,
                ImageUpdater          = new ImageUpdaterService(),
                ExternalEditorService = new ImageExternalEditService(CommonServices.Log)
            };

            var cropResizeSettings = new CropResizeSettings();
            var dimensionSettings  = new DimensionSettings();
            var mipSettings        = new MipMapSettings();
            var alphaSettings      = new AlphaSettings
            {
                AlphaValue  = _settings.LastAlphaValue,
                UpdateRange = _settings.LastAlphaRange
            };

            cropResizeSettings.Initialize(CommonServices);
            dimensionSettings.Initialize(new DimensionSettingsParameters(GraphicsContext.Graphics.VideoAdapter, CommonServices));
            mipSettings.Initialize(CommonServices);


            var content = new ImageContent();

            content.Initialize(new ImageContentParameters(file,
                                                          _settings,
                                                          cropResizeSettings,
                                                          dimensionSettings,
                                                          mipSettings,
                                                          alphaSettings,
                                                          imageData,
                                                          GraphicsContext.Graphics.VideoAdapter,
                                                          GraphicsContext.Graphics.FormatSupport,
                                                          services));

            return(content);
        }
 /// <summary>Initializes a new instance of the TexConvCompressor class.</summary>
 /// <param name="texConvFile">The tex conv file.</param>
 /// <param name="scratchWriter">The scratch writer.</param>
 /// <param name="codec">The codec used to read/write the file.</param>
 public TexConvCompressor(FileInfo texConvFile, IGorgonFileSystemWriter <Stream> scratchWriter, IGorgonImageCodec codec)
 {
     _codec   = codec;
     _writer  = scratchWriter;
     _texConv = texConvFile;
 }
示例#7
0
 /// <summary>
 /// Function to retrieve the ribbon button for the tool.
 /// </summary>
 /// <param name="fileManager">The project file manager.</param>
 /// <param name="scratchArea">The scratch area for writing temporary data.</param>
 /// <returns>A new tool ribbon button instance.</returns>
 /// <remarks>
 /// <para>
 /// Tool plug in developers must override this method to return the button which is inserted on the application ribbon, under the "Tools" tab. If the method returns <b>null</b>, then the tool is
 /// ignored.
 /// </para>
 /// <para>
 /// The resulting data structure will contain the means to handle the click event for the tool, and as such, is the only means of communication between the main UI and the plug in.
 /// </para>
 /// <para>
 /// The <paramref name="fileManager"/> will allow plug ins to enumerate files in the project file system, create files/directories, and delete files/directories. This allows the plug in a means
 /// to persist any data generated.
 /// </para>
 /// <para>
 /// The <paramref name="scratchArea"/> is used to write temporary data to the project temporary area, which is useful for handling transitory states. Because this is <b>temporary</b>, any data
 /// written to this area will be deleted on application shut down. So do not rely on this data being there on the next start up.
 /// </para>
 /// </remarks>
 protected abstract IToolPlugInRibbonButton OnGetToolButton(IContentFileManager fileManager, IGorgonFileSystemWriter <Stream> scratchArea);
示例#8
0
        /// <summary>Function to retrieve the ribbon button for the tool.</summary>
        /// <param name="fileManager">The project file manager.</param>
        /// <param name="scratchArea">The scratch area for writing temporary data.</param>
        /// <returns>A new tool ribbon button instance.</returns>
        /// <remarks>
        ///   <para>
        /// Tool plug in developers must override this method to return the button which is inserted on the application ribbon, under the "Tools" tab. If the method returns <b>null</b>, then the tool is
        /// ignored.
        /// </para>
        ///   <para>
        /// The resulting data structure will contain the means to handle the click event for the tool, and as such, is the only means of communication between the main UI and the plug in.
        /// </para>
        ///   <para>
        /// The <paramref name="fileManager" /> will allow plug ins to enumerate files in the project file system, create files/directories, and delete files/directories. This allows the plug in a means
        /// to persist any data generated.
        /// </para>
        ///   <para>
        /// The <paramref name="scratchArea" /> is used to write temporary data to the project temporary area, which is useful for handling transitory states. Because this is <b>temporary</b>, any data
        /// written to this area will be deleted on application shut down. So do not rely on this data being there on the next start up.
        /// </para>
        /// </remarks>
        protected override IToolPlugInRibbonButton OnGetToolButton(IContentFileManager fileManager, IGorgonFileSystemWriter <Stream> scratchArea)
        {
            _fileManager = fileManager;

            if (_button.ClickCallback == null)
            {
                _button.ClickCallback = ShowForm;
            }

            if (_button.CanExecute == null)
            {
                _button.CanExecute = CanShowForm;
            }

            return(_button);
        }
示例#9
0
 /// <summary>
 /// Function to open a content object from this plugin.
 /// </summary>
 /// <param name="file">The file that contains the content.</param>
 /// <param name="fileManager">The file manager used to access other content files.</param>
 /// <param name="scratchArea">The file system for the scratch area used to write transitory information.</param>
 /// <param name="undoService">The undo service for the plug in.</param>
 /// <returns>A new <see cref="IEditorContent"/> object.</returns>
 /// <remarks>
 /// <para>
 /// The <paramref name="scratchArea"/> parameter is the file system where temporary files to store transitory information for the plug in is stored. This file system is destroyed when the
 /// application or plug in is shut down, and is not stored with the project.
 /// </para>
 /// </remarks>
 protected abstract Task <IEditorContent> OnOpenContentAsync(IContentFile file, IContentFileManager fileManager, IGorgonFileSystemWriter <Stream> scratchArea, IUndoService undoService);