init
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
using Hi.Disp;
|
||||
using Hi.Disp.Flag;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Hi.WinForm.Disp
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="Form"/> contains <see cref="RenderingCanvas"/>.
|
||||
/// This class is usually used for debug due to its simplicity.
|
||||
/// </summary>
|
||||
public partial class RenderingForm : Form,IGetDispEngine
|
||||
{
|
||||
static readonly Form seedForm = new Form();
|
||||
private static readonly ConcurrentDictionary<string, RenderingForm> displayerMap
|
||||
= new ConcurrentDictionary<string, RenderingForm>(4, 4);
|
||||
/// <summary>
|
||||
/// See <see cref="Call(string, IDisplayee[])"/> to get the information.
|
||||
/// </summary>
|
||||
public static ConcurrentDictionary<string, RenderingForm> DisplayerMap { get => displayerMap; }
|
||||
/// <summary>
|
||||
/// Ctor.
|
||||
/// </summary>
|
||||
/// <param name="displayees">displayees</param>
|
||||
internal RenderingForm(params IDisplayee[] displayees)
|
||||
{
|
||||
InitializeComponent();
|
||||
Displayer = new RenderingCanvas(displayees);
|
||||
this.Controls.Add(Displayer);
|
||||
//Displayer.DispEngine.Start();
|
||||
}
|
||||
/// <summary>
|
||||
/// The contained <see cref="RenderingCanvas"/>.
|
||||
/// </summary>
|
||||
public RenderingCanvas Displayer { get; }
|
||||
/// <summary>
|
||||
/// Create and obtain a <see cref="RenderingForm"/> if the key has not existed; Otherwise, the old one is obtained.
|
||||
/// <paramref name="displayees"/> are set to the obtained <see cref="RenderingForm"/>.
|
||||
/// The dictionary of this function is <see cref="DisplayerMap"/>.
|
||||
/// </summary>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="displayees">The displayees set to the obtained <see cref="RenderingForm"/>.</param>
|
||||
/// <returns>A <see cref="RenderingForm"/> obtained by the key.</returns>
|
||||
public static RenderingForm Call(string key, params IDisplayee[] displayees)
|
||||
{
|
||||
if (displayerMap.TryGetValue(key, out RenderingForm f))
|
||||
{
|
||||
f.Displayer.DispEngine.Displayee = new DispList(displayees);
|
||||
return f;
|
||||
}
|
||||
else
|
||||
{
|
||||
_ = seedForm.Handle;
|
||||
seedForm.Invoke(new Action(() =>
|
||||
{
|
||||
RenderingForm ff = new RenderingForm(displayees)
|
||||
{
|
||||
Text = key,
|
||||
Visible = true
|
||||
};
|
||||
displayerMap.TryAdd(key, ff);
|
||||
}));
|
||||
|
||||
RenderingForm fff = null;
|
||||
while (!displayerMap.TryGetValue(key, out fff))
|
||||
Thread.Sleep(1);
|
||||
return fff;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
Displayer.Dispose();
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
/// <inheritdoc/>
|
||||
public DispEngine GetDispEngine()
|
||||
{
|
||||
return Displayer.DispEngine;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user