diff --git a/ANX.Framework.sln b/ANX.Framework.sln index c8a09e76..7a767847 100644 --- a/ANX.Framework.sln +++ b/ANX.Framework.sln @@ -1,5 +1,5 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2010 +# Visual Studio 2012 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ANX.Framework", "ANX.Framework\ANX.Framework.csproj", "{6899F0C9-70B9-4EB0-9DD3-E598D4BE3E35}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ANX.Framework.TestCenter", "ANX.Framework.TestCenter\ANX.Framework.TestCenter.csproj", "{7344BBEB-A1C7-43A8-B68E-D42B81973DA9}" @@ -248,17 +248,21 @@ Global {ECBF60CB-1CF0-4F92-8963-E73115B04B43}.Debug|Any CPU.ActiveCfg = Debug|x86 {ECBF60CB-1CF0-4F92-8963-E73115B04B43}.Debug|Any CPU.Build.0 = Debug|x86 {ECBF60CB-1CF0-4F92-8963-E73115B04B43}.Debug|ARM.ActiveCfg = Debug|x86 + {ECBF60CB-1CF0-4F92-8963-E73115B04B43}.Debug|ARM.Build.0 = Debug|x86 {ECBF60CB-1CF0-4F92-8963-E73115B04B43}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 {ECBF60CB-1CF0-4F92-8963-E73115B04B43}.Debug|Mixed Platforms.Build.0 = Debug|x86 {ECBF60CB-1CF0-4F92-8963-E73115B04B43}.Debug|x64.ActiveCfg = Debug|x86 + {ECBF60CB-1CF0-4F92-8963-E73115B04B43}.Debug|x64.Build.0 = Debug|x86 {ECBF60CB-1CF0-4F92-8963-E73115B04B43}.Debug|x86.ActiveCfg = Debug|x86 {ECBF60CB-1CF0-4F92-8963-E73115B04B43}.Debug|x86.Build.0 = Debug|x86 {ECBF60CB-1CF0-4F92-8963-E73115B04B43}.Release|Any CPU.ActiveCfg = Release|x86 {ECBF60CB-1CF0-4F92-8963-E73115B04B43}.Release|Any CPU.Build.0 = Release|x86 {ECBF60CB-1CF0-4F92-8963-E73115B04B43}.Release|ARM.ActiveCfg = Release|x86 + {ECBF60CB-1CF0-4F92-8963-E73115B04B43}.Release|ARM.Build.0 = Release|x86 {ECBF60CB-1CF0-4F92-8963-E73115B04B43}.Release|Mixed Platforms.ActiveCfg = Release|x86 {ECBF60CB-1CF0-4F92-8963-E73115B04B43}.Release|Mixed Platforms.Build.0 = Release|x86 {ECBF60CB-1CF0-4F92-8963-E73115B04B43}.Release|x64.ActiveCfg = Release|x86 + {ECBF60CB-1CF0-4F92-8963-E73115B04B43}.Release|x64.Build.0 = Release|x86 {ECBF60CB-1CF0-4F92-8963-E73115B04B43}.Release|x86.ActiveCfg = Release|x86 {ECBF60CB-1CF0-4F92-8963-E73115B04B43}.Release|x86.Build.0 = Release|x86 {9D8DC781-2E0D-4348-BAD9-745F91428A3F}.Debug|Any CPU.ActiveCfg = Debug|x86 diff --git a/Tools/ANXContentCompilerGUI/ANX.ContentCompiler.GUI.csproj b/Tools/ANXContentCompilerGUI/ANX.ContentCompiler.GUI.csproj index 5c4ff44e..a67a1e83 100644 --- a/Tools/ANXContentCompilerGUI/ANX.ContentCompiler.GUI.csproj +++ b/Tools/ANXContentCompilerGUI/ANX.ContentCompiler.GUI.csproj @@ -152,6 +152,7 @@ PreviewScreen.cs + True True @@ -191,6 +192,9 @@ + + PreviewScreen.cs + ResXFileCodeGenerator Designer diff --git a/Tools/ANXContentCompilerGUI/Dialogues/PreviewScreen.Designer.cs b/Tools/ANXContentCompilerGUI/Dialogues/PreviewScreen.Designer.cs index 969c0c9d..7098b360 100644 --- a/Tools/ANXContentCompilerGUI/Dialogues/PreviewScreen.Designer.cs +++ b/Tools/ANXContentCompilerGUI/Dialogues/PreviewScreen.Designer.cs @@ -31,6 +31,8 @@ this.buttonQuit = new System.Windows.Forms.Button(); this.labelTitle = new System.Windows.Forms.Label(); this.drawSurface = new System.Windows.Forms.Panel(); + this.labelStatus = new System.Windows.Forms.Label(); + this.drawSurface.SuspendLayout(); this.SuspendLayout(); // // buttonQuit @@ -69,11 +71,21 @@ // // drawSurface // + this.drawSurface.Controls.Add(this.labelStatus); this.drawSurface.Location = new System.Drawing.Point(12, 27); this.drawSurface.Name = "drawSurface"; this.drawSurface.Size = new System.Drawing.Size(595, 410); this.drawSurface.TabIndex = 4; // + // labelStatus + // + this.labelStatus.Location = new System.Drawing.Point(129, 166); + this.labelStatus.Name = "labelStatus"; + this.labelStatus.Size = new System.Drawing.Size(337, 78); + this.labelStatus.TabIndex = 0; + this.labelStatus.Text = "Loading Preview..."; + this.labelStatus.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // // PreviewScreen // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -90,6 +102,8 @@ this.ShowInTaskbar = false; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Preview"; + this.Load += new System.EventHandler(this.PreviewScreenLoad); + this.drawSurface.ResumeLayout(false); this.ResumeLayout(false); } @@ -99,5 +113,6 @@ private System.Windows.Forms.Button buttonQuit; private System.Windows.Forms.Label labelTitle; private System.Windows.Forms.Panel drawSurface; + private System.Windows.Forms.Label labelStatus; } } \ No newline at end of file diff --git a/Tools/ANXContentCompilerGUI/Dialogues/PreviewScreen.cs b/Tools/ANXContentCompilerGUI/Dialogues/PreviewScreen.cs index a985d4dd..5b3c49fe 100644 --- a/Tools/ANXContentCompilerGUI/Dialogues/PreviewScreen.cs +++ b/Tools/ANXContentCompilerGUI/Dialogues/PreviewScreen.cs @@ -3,9 +3,16 @@ using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; +using System.IO; using System.Linq; using System.Text; +using System.Threading; using System.Windows.Forms; +using ANX.Framework.Content; +using ANX.Framework.Content.Pipeline; +using ANX.Framework.Content.Pipeline.Tasks; +using ANX.Framework.Graphics; +using Timer = System.Windows.Forms.Timer; namespace ANX.ContentCompiler.GUI.Dialogues { @@ -14,11 +21,37 @@ namespace ANX.ContentCompiler.GUI.Dialogues #region Fields private Point _lastPos; private bool _mouseDown; + private readonly BuildItem _item; + private Thread _loaderThread; + private readonly string _outputFile; + private readonly string _outputDir; + private volatile bool _started; + private volatile bool _error; + private volatile string _errorMessage; + private string _processor; + private Timer _checkTimer; + private Timer _tickTimer; + private readonly GraphicsDevice _graphicsDevice; + private SpriteBatch _batch; #endregion - public PreviewScreen() + public PreviewScreen(BuildItem item) { InitializeComponent(); + _item = item; + _outputFile = Path.GetTempFileName(); + _outputDir = Path.GetTempPath(); + _graphicsDevice = new GraphicsDevice( + GraphicsAdapter.DefaultAdapter, + GraphicsProfile.HiDef, + new PresentationParameters + { + BackBufferWidth = drawSurface.Width, + BackBufferHeight = drawSurface.Height, + BackBufferFormat = SurfaceFormat.Color, + DeviceWindowHandle = drawSurface.Handle, + PresentationInterval = PresentInterval.Default, + }); } #region WindowMoveMethods @@ -51,5 +84,82 @@ namespace ANX.ContentCompiler.GUI.Dialogues Close(); DialogResult = DialogResult.Cancel; } + + public void CompileFile() + { + var builderTask = new BuildContent + { + BuildLogger = new FakeBuildLogger(), + OutputDirectory = _outputDir, + TargetPlatform = TargetPlatform.Windows, + TargetProfile = GraphicsProfile.HiDef, + CompressContent = false + }; + if (String.IsNullOrEmpty(_item.ImporterName)) + { + _item.ImporterName = ImporterManager.GuessImporterByFileExtension(_item.SourceFilename); + } + if (String.IsNullOrEmpty(_item.ProcessorName)) + { + _item.ProcessorName = + new ProcessorManager().GetProcessorForImporter(new ImporterManager().GetInstance(_item.ImporterName)); + } + _processor = _item.ProcessorName; + _item.OutputFilename = _outputFile; + try + { + builderTask.Execute(new[] { _item }); + } + catch (Exception ex) + { + _error = true; + _errorMessage = ex.Message; + } + } + + private void PreviewScreenLoad(object sender, EventArgs e) + { + _checkTimer = new Timer {Interval = 1000}; + _checkTimer.Tick += CheckThread; + _checkTimer.Start(); + } + + void CheckThread(object sender, EventArgs e) + { + if (!_started) + { + ((Timer) sender).Interval = 100; + _loaderThread = new Thread(CompileFile); + _loaderThread.Start(); + _started = true; + } + else + { + if (_loaderThread.IsAlive) + return; + if (_error) + { + labelStatus.Text = "Loading of Preview failed with: \n" + _errorMessage; + return; + } + labelStatus.Text = "Loading successful"; + labelStatus.Hide(); + _tickTimer = new Timer {Interval = 120}; + _tickTimer.Tick += Tick; + _batch = new SpriteBatch(_graphicsDevice); + _tickTimer.Start(); + } + } + + void Tick(object sender, EventArgs e) + { + _graphicsDevice.Clear(Framework.Color.CornflowerBlue); + if (_processor == "TextureProcessor") + { + _batch.Begin(); + + _batch.End(); + } + } } } diff --git a/Tools/ANXContentCompilerGUI/MainWindow.cs b/Tools/ANXContentCompilerGUI/MainWindow.cs index d0d95fbe..1949b8c3 100644 --- a/Tools/ANXContentCompilerGUI/MainWindow.cs +++ b/Tools/ANXContentCompilerGUI/MainWindow.cs @@ -876,7 +876,13 @@ namespace ANX.ContentCompiler.GUI #region ShowPreview internal void ShowPreview() { - using (var preview = new PreviewScreen()) + BuildItem buildItem = null; + foreach (var item in _contentProject.BuildItems.Where(item => item.AssetName == treeView.SelectedNode.Text)) + { + buildItem = item; + } + + using (var preview = new PreviewScreen(buildItem)) { if ((string)treeView.SelectedNode.Tag == "File") preview.ShowDialog();