示例#1
0
        /// <summary>
        /// Evalutaes the builder.
        /// If invalid, lissts the problems.
        /// If valid, builds a landscape and generates the output (if the layer is present)
        /// </summary>
        public async Task Run()
        {
            const string     nln = "\n";
            LandscapeBuilder landscapeBuilder = BuildLandscapeBuilder();
            await Output.SetAsync(string.Join(nln, landscapeBuilder.GetFullReport()));

            if (landscapeBuilder.IsValid())
            {
                await Output.SetAsync(Output.Value + nln + "===  VALID  ===");

                Landscape landscape = landscapeBuilder.Build();
                try {
                    HeightMapImageOutputter outputter = (HeightMapImageOutputter)landscape.GetOutputter <byte[]>("img");

                    await Output.SetAsync(Output.Value + nln + "Generating the landscape.");

                    byte[] bytes = outputter.GetObject(new Coordinate());
                    await Output.SetAsync(Output.Value + nln + "Generating the image.");

                    await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => {
                        LatestBitmap = outputter.BytesToBitmap(bytes);
                        if (LatestBitmap.BitmapPixelFormat != BitmapPixelFormat.Bgra8 || LatestBitmap.BitmapAlphaMode == BitmapAlphaMode.Straight)
                        {
                            LatestBitmap = SoftwareBitmap.Convert(LatestBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied);
                        }
                        SoftwareBitmapSource source = new SoftwareBitmapSource();
                        await source.SetBitmapAsync(LatestBitmap);
                        SoftwareBitmapSource.SetFromUIThread(source);
                    }).AsTask();

                    await Output.SetAsync(Output.Value + nln + "Preview is ready,");
                } catch (Exception err) {
                    await Output.SetAsync(Output.Value + nln + "Failed to retrieve the Bitmap Outputter."
                                          + nln + "To enable the preview add a HeightMapImageOutputterBuilder with id of \"img\"" + nln + err.Message);
                }
            }
            else
            {
                await Output.SetAsync(Output.Value + nln + "=== INVALID ===");
            }
        }
示例#2
0
        /// <summary>
        /// Creates a save dialog and saves the landscape into the file
        /// </summary>
        public async Task SaveDialog()
        {
            LandscapeBuilder landscapeBuilder = BuildLandscapeBuilder();

            if (landscapeBuilder.IsValid())
            {
                FileSavePicker savePicker = new FileSavePicker {
                    SuggestedStartLocation = PickerLocationId.DocumentsLibrary
                };
                savePicker.FileTypeChoices.Add("Landscape XML", new List <string>()
                {
                    ".xml"
                });
                savePicker.SuggestedFileName = "New Landscape";
                StorageFile file = await savePicker.PickSaveFileAsync();
                await Save(file, landscapeBuilder);
            }
            else
            {
                await Task.Run(Run);
            }
        }