46 lines
1.5 KiB
C#
46 lines
1.5 KiB
C#
using Hi.Disp;
|
|
using Hi.Geom;
|
|
using Hi.HiNcKits;
|
|
using Microsoft.Extensions.Logging;
|
|
using System;
|
|
|
|
namespace Sample.Disp;
|
|
|
|
/// <summary>
|
|
/// Runs a display sample to the point where its <see cref="IDisplayee"/> is ready to be rendered.
|
|
/// HiAPI ships no rendering canvas, so the samples in this project stop at the handover: they
|
|
/// compose the displayee and report it, and the application hands that same object to a canvas of
|
|
/// its own. See the Building Your Own Rendering Canvas guide for the canvas side.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// ### Source Code
|
|
/// [!code-csharp[SampleCode](~/../Hi.Sample/Disp/DemoUtil.cs)]
|
|
/// </remarks>
|
|
public static class DemoUtil
|
|
{
|
|
/// <summary>
|
|
/// Initializes the application, reports the displayee's extent, and shuts down again —
|
|
/// the headless equivalent of opening a window on it.
|
|
/// </summary>
|
|
/// <param name="title">A name for the sample, used in the console output.</param>
|
|
/// <param name="displayee">The object a rendering canvas would display.</param>
|
|
public static void Present(string title, IDisplayee displayee)
|
|
{
|
|
if (displayee is null) throw new ArgumentNullException(nameof(displayee));
|
|
|
|
using var loggerFactory = LoggerFactory.Create(b => b.AddConsole());
|
|
LocalApp.AppBegin(loggerFactory.CreateLogger("Hi.Sample"));
|
|
try
|
|
{
|
|
Box3d box = new Box3d();
|
|
displayee.ExpandToBox3d(ref box);
|
|
Console.WriteLine($"{title}: {displayee.GetType().Name} bounding {box}");
|
|
Console.WriteLine("Assign it to your canvas' DispEngine.Displayee to see it.");
|
|
}
|
|
finally
|
|
{
|
|
LocalApp.AppEnd();
|
|
}
|
|
}
|
|
}
|