async Task GenerateCxCodeAsync(LottieVisualDiagnostics diagnostics, string suggestedClassName, IStorageFile cppFile) { // Ask the user to pick a name for the .h file. var filePicker = new FileSavePicker { SuggestedStartLocation = PickerLocationId.DocumentsLibrary, SuggestedFileName = suggestedClassName, }; // Dropdown of file types the user can save the file as filePicker.FileTypeChoices.Add("C++ CX header", new[] { ".h" }); var hFile = await filePicker.PickSaveFileAsync(); if (hFile == null) { // No header file chosen - give up. return; } // Generate the .cpp and the .h text. diagnostics.GenerateCxCode(hFile.Name, out var cppText, out var hText); // Write the .cpp file. await FileIO.WriteTextAsync(cppFile, cppText); // Write the .h file if the user specified one. if (hFile != null) { await FileIO.WriteTextAsync(hFile, hText); } }
IEnumerable <Tuple <string, string> > DiagnosticsToProperties(LottieVisualDiagnostics diagnostics) { yield return(Tuple.Create("File name", diagnostics.FileName)); yield return(Tuple.Create("Duration", $"{diagnostics.Duration.TotalSeconds.ToString("#,##0.0##")} secs")); var aspectRatio = FloatToRatio(diagnostics.LottieWidth / diagnostics.LottieHeight); yield return(Tuple.Create("Aspect ratio", $"{aspectRatio.Item1.ToString("0.###")}:{aspectRatio.Item2.ToString("0.###")}")); yield return(Tuple.Create("Size", $"{diagnostics.LottieWidth} x {diagnostics.LottieHeight}")); foreach (var marker in diagnostics.Markers) { yield return(Tuple.Create("Marker", $"{marker.Key}: {marker.Value.ToString("0.0###")}")); } }
async Task GenerateCxCodeAsync(LottieVisualDiagnostics diagnostics, string suggestedClassName, IStorageFile cppFile) { // Ask the user to pick a name for the .h file. var filePicker = new FileSavePicker { SuggestedStartLocation = PickerLocationId.DocumentsLibrary, SuggestedFileName = suggestedClassName, }; // Dropdown of file types the user can save the file as filePicker.FileTypeChoices.Add("C++ CX header", new[] { ".h" }); var hFile = await filePicker.PickSaveFileAsync(); if (hFile == null) { // No header file chosen - give up. return; } // Ask the user to pick a name for the ICompositionSource.h file. var iCompositionSourceFilePicker = new FileSavePicker { SuggestedStartLocation = PickerLocationId.DocumentsLibrary, SuggestedFileName = "ICompositionSource.h", }; // Dropdown of file types the user can save the file as iCompositionSourceFilePicker.FileTypeChoices.Add("ICompositionSource header", new[] { ".h" }); var iCompositionSourceHeader = await iCompositionSourceFilePicker.PickSaveFileAsync(); // Generate the .cpp and the .h text. diagnostics.GenerateCxCode(hFile.Name, out var cppText, out var hText); // Write the .cpp file. await FileIO.WriteTextAsync(cppFile, cppText); // Write the .h file if the user specified one. if (hFile != null) { await FileIO.WriteTextAsync(hFile, hText); } // Write the ICompositionSource.h file if the user specified it. if (iCompositionSourceHeader != null) { await FileIO.WriteLinesAsync(iCompositionSourceHeader, new[] { "#pragma once", "namespace Compositions", "{", " public interface class ICompositionSource", " {", " virtual bool TryCreateAnimatedVisual(", " Windows::UI::Composition::Compositor^ compositor,", " Windows::UI::Composition::Visual^* rootVisual,", " Windows::Foundation::Numerics::float2* size,", " Windows::Foundation::TimeSpan* duration,", " Platform::Object^* diagnostics);", " };", "}", string.Empty, }); } }