using Hi.Disp; using System; using System.Collections.Concurrent; using System.Threading; using System.Windows.Forms; using System.ComponentModel; namespace Hi.WinForm.Disp { /// /// A contains . /// This class is usually used for debug due to its simplicity. /// public partial class RenderingForm : Form, IGetDispEngine { static readonly Form seedForm = new Form(); private static readonly ConcurrentDictionary displayerMap = new ConcurrentDictionary(4, 4); /// /// See to get the information. /// public static ConcurrentDictionary DisplayerMap { get => displayerMap; } /// /// Ctor. /// /// displayees internal RenderingForm(params IDisplayee[] displayees) { InitializeComponent(); RenderingCanvas = new RenderingCanvas(displayees); this.Controls.Add(RenderingCanvas); //Displayer.DispEngine.Start(); } /// /// The contained . /// public RenderingCanvas RenderingCanvas { get; } [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public IDisplayee Displayee { get => GetDispEngine().Displayee; set { var preDisplayee = GetDispEngine().Displayee; GetDispEngine().Displayee = value; if (preDisplayee == null) RenderingCanvas.DispEngine.SetViewToHomeView(); } } /// /// Create and obtain a if the key has not existed; Otherwise, the old one is obtained. /// are set to the obtained . /// The dictionary of this function is . /// /// key /// The displayees set to the obtained . /// A obtained by the key. public static RenderingForm Call(string key, params IDisplayee[] displayees) { if (displayerMap.TryGetValue(key, out RenderingForm f)) { f.RenderingCanvas.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; } } /// /// Clean up any resources being used. /// /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { if (disposing && (components != null)) { RenderingCanvas.Dispose(); components.Dispose(); } base.Dispose(disposing); } /// public DispEngine GetDispEngine() { return RenderingCanvas.DispEngine; } } }