Ejemplo n.º 1
0
        /// <summary>
        /// Function to show the tool form.
        /// </summary>
        private void ShowForm()
        {
            TextureAtlasSettings settings;
            FormAtlasGen         form = null;

            CommonServices.BusyService.SetBusy();

            try
            {
                settings = ToolPlugInService.ReadContentSettings <TextureAtlasSettings>(typeof(TextureAtlasToolPlugIn).FullName);

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

                (List <IContentFileExplorerSearchEntry> searchEntries, List <ContentFileExplorerDirectoryEntry> entries) = GetFileEntries();

                if (_fileVm == null)
                {
                    _fileVm = new SpriteFiles();
                }

                if (_textureAtlas == null)
                {
                    _textureAtlas = new TextureAtlas();
                }

                var fileIO = new FileIOService(_fileManager, _defaultImageCodec, _defaultSpriteCodec);

                _fileVm.Initialize(new SpriteFilesParameters(entries, new EditorContentSearchService(searchEntries), CommonServices));
                _textureAtlas.Initialize(new TextureAtlasParameters(settings,
                                                                    _fileVm,
                                                                    new GorgonTextureAtlasService(GraphicsContext.Renderer2D),
                                                                    fileIO,
                                                                    FolderBrowser,
                                                                    CommonServices));

                form = new FormAtlasGen();
                form.SetupGraphics(GraphicsContext);
                form.SetDataContext(_textureAtlas);

                CommonServices.BusyService.SetIdle();
                form.ShowDialog(GorgonApplication.MainForm);

                ToolPlugInService.WriteContentSettings(typeof(TextureAtlasToolPlugIn).FullName, settings);
            }
            catch (Exception ex)
            {
                CommonServices.MessageDisplay.ShowError(ex, Resources.GORTAG_ERR_LAUNCH);
            }
            finally
            {
                CommonServices.BusyService.SetIdle();
                form?.Dispose();
            }
        }
Ejemplo n.º 2
0
        /// <summary>Releases the unmanaged resources used by the <see cref="T:System.Windows.Forms.ApplicationContext" /> and optionally releases the managed resources.</summary>
        /// <param name="disposing">
        /// <see langword="true" /> to release both managed and unmanaged resources; <see langword="false" /> to release only unmanaged resources. </param>
        protected override void Dispose(bool disposing)
        {
            AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve;

            ToolPlugInService    toolPlugIns    = Interlocked.Exchange(ref _toolPlugIns, null);
            ContentPlugInService contentPlugIns = Interlocked.Exchange(ref _contentPlugIns, null);
            GraphicsContext      context        = Interlocked.Exchange(ref _graphicsContext, null);
            GorgonMefPlugInCache pluginCache    = Interlocked.Exchange(ref _pluginCache, null);
            FormMain             mainForm       = Interlocked.Exchange(ref _mainForm, null);
            FormSplash           splash         = Interlocked.Exchange(ref _splash, null);

            toolPlugIns?.Dispose();
            contentPlugIns?.Dispose();
            context?.Dispose();
            pluginCache?.Dispose();
            mainForm?.Dispose();
            splash?.Dispose();

            base.Dispose(disposing);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ViewModelFactory"/> class.
 /// </summary>
 /// <param name="settings">The settings for the application.</param>
 /// <param name="providers">The providers used to open/save files.</param>
 /// <param name="contentPlugIns">The plugins used for content.</param>
 /// <param name="toolPlugIns">The plugins used for application tools.</param>
 /// <param name="projectManager">The application project manager.</param>
 /// <param name="viewModelInjection">The common services for the application.</param>
 /// <param name="clipboardService">The application clipboard service.</param>
 /// <param name="dirLocatorService">The directory locator service.</param>
 /// <param name="fileScanService">The file scanning service used to scan content files for content plugin associations.</param>
 /// <param name="folderBrowser">The file system folder browser service.</param>
 /// <exception cref="ArgumentNullException">Thrown when any parameter is <b>null</b>.</exception>
 public ViewModelFactory(EditorSettings settings,
                         FileSystemProviders providers,
                         ContentPlugInService contentPlugIns,
                         ToolPlugInService toolPlugIns,
                         ProjectManager projectManager,
                         IViewModelInjection viewModelInjection,
                         ClipboardService clipboardService,
                         DirectoryLocateService dirLocatorService,
                         FileScanService fileScanService,
                         IEditorFileSystemFolderBrowseService folderBrowser)
 {
     Settings            = settings ?? throw new ArgumentNullException(nameof(settings));
     FileSystemProviders = providers ?? throw new ArgumentNullException(nameof(providers));
     ContentPlugIns      = contentPlugIns ?? throw new ArgumentNullException(nameof(contentPlugIns));
     ToolPlugIns         = toolPlugIns ?? throw new ArgumentNullException(nameof(toolPlugIns));
     _projectManager     = projectManager ?? throw new ArgumentNullException(nameof(projectManager));
     _viewModelInjection = viewModelInjection ?? throw new ArgumentNullException(nameof(viewModelInjection));
     _clipboard          = clipboardService ?? throw new ArgumentNullException(nameof(clipboardService));
     _dirLocator         = dirLocatorService ?? throw new ArgumentNullException(nameof(dirLocatorService));
     _fileScanService    = fileScanService ?? throw new ArgumentNullException(nameof(fileScanService));
     _folderBrowser      = folderBrowser ?? throw new ArgumentNullException(nameof(folderBrowser));
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Function to load any tool plugins.
        /// </summary>
        /// <returns>The tool plugin manager service used to manipulate the loaded tool plugins.</returns>
        private ToolPlugInService LoadToolPlugIns()
        {
            var toolPlugInsDir        = new DirectoryInfo(Path.Combine(_plugInLocation.FullName, "Tools"));
            var toolPlugInSettingsDir = new DirectoryInfo(Path.Combine(Program.ApplicationUserDirectory.FullName, "ToolPlugIns"));
            var toolPlugIns           = new ToolPlugInService(toolPlugInSettingsDir, _graphicsContext, _folderBrowser, _commonServices);

            if (!toolPlugInSettingsDir.Exists)
            {
                toolPlugInSettingsDir.Create();
                toolPlugInSettingsDir.Refresh();
            }

            if (!toolPlugInsDir.Exists)
            {
                return(toolPlugIns);
            }

            try
            {
                _splash.InfoText = Resources.GOREDIT_TEXT_LOADING_TOOL_PLUGINS;

                if (!toolPlugInsDir.Exists)
                {
                    toolPlugInsDir.Create();
                    return(toolPlugIns);
                }

                toolPlugIns.LoadToolPlugIns(_pluginCache, toolPlugInsDir);
            }
            catch (Exception ex)
            {
                Program.Log.LogException(ex);
                GorgonDialogs.ErrorBox(_splash, Resources.GOREDIT_ERR_LOADING_PLUGINS, Resources.GOREDIT_ERR_ERROR, ex);
            }

            return(toolPlugIns);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Function to perform the boot strapping operation.
        /// </summary>
        /// <returns>The main application window.</returns>
        public async void BootStrap()
        {
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;

            try
            {
                // Get our initial context.
                SynchronizationContext.SetSynchronizationContext(new WindowsFormsSynchronizationContext());

                Program.Log.Print("Booting application...", LoggingLevel.All);

                Cursor.Current = Cursors.WaitCursor;

                await ShowSplashAsync();

                // Initalize the common resources.
                EditorCommonResources.LoadResources();

                _folderBrowser   = new FileSystemFolderBrowseService();
                _commonServices  = new ViewModelInjection(Program.Log, new WaitCursorBusyState(), new MessageBoxService());
                _pluginCache     = new GorgonMefPlugInCache(Program.Log);
                _graphicsContext = GraphicsContext.Create(Program.Log);

                _plugInLocation = new DirectoryInfo(Path.Combine(GorgonApplication.StartupPath.FullName, "PlugIns"));

                if (!_plugInLocation.Exists)
                {
                    Program.Log.Print($"[ERROR] Plug in path '{_plugInLocation.FullName}' was not found.  No plug ins will be loaded.", LoggingLevel.Simple);
                    GorgonDialogs.ErrorBox(null, Resources.GOREDIT_ERR_LOADING_PLUGINS);
                }

                // Get any application settings we might have.
                _settings = LoadSettings();

                // Load our file system import/export plugins.
                FileSystemProviders fileSystemProviders = LoadFileSystemPlugIns();

                // Load our tool plug ins.
                _toolPlugIns = LoadToolPlugIns();

                // Load our content service plugins.
                _contentPlugIns = LoadContentPlugIns();

                // Create the project manager for the application
                _projectManager = new ProjectManager(fileSystemProviders);

                _mainForm = new FormMain
                {
                    Location    = new Point(_settings.WindowBounds.Value.X, _settings.WindowBounds.Value.Y),
                    Size        = new Size(_settings.WindowBounds.Value.Width, _settings.WindowBounds.Value.Height),
                    WindowState = FormWindowState.Normal
                };

                await HideSplashAsync();

                MainForm = _mainForm;

                var factory = new ViewModelFactory(_settings,
                                                   fileSystemProviders,
                                                   _contentPlugIns,
                                                   _toolPlugIns,
                                                   _projectManager,
                                                   _commonServices,
                                                   new ClipboardService(),
                                                   new DirectoryLocateService(),
                                                   new FileScanService(_contentPlugIns),
                                                   _folderBrowser);

                FormWindowState windowState;
                // Ensure the window state values fall into an acceptable range.
                if (!Enum.IsDefined(typeof(FormWindowState), _settings.WindowState))
                {
                    windowState = FormWindowState.Maximized;
                }
                else
                {
                    windowState = (FormWindowState)_settings.WindowState;
                }

                _mainForm.GraphicsContext = _graphicsContext;
                _mainForm.SetDataContext(factory.CreateMainViewModel(_graphicsContext.Graphics.VideoAdapter.Name));
                _mainForm.Show();
                _mainForm.WindowState = windowState;
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Ejemplo n.º 6
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();
            }
        }