123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Numerics;
- using System.Text;
- using System.Threading.Tasks;
- using Vulkan;
- using Veldrid.SPIRV;
- using System.Diagnostics;
- using System.Drawing;
- namespace Veldrid.Common
- {
- public sealed partial class VeldridContent: IDisposable
- {
- public Axis.LineAxis AddLineAxis()
- {
- Axis.LineAxis lineAxis = new Axis.LineAxis(this);
- lineAxis.CreateResources();
- renders.Add(lineAxis);
- return lineAxis;
- }
- public Vector2 WindowScale { get; set; } = Vector2.One;
- public ImagesRender AddImages(BitmapData bitmapData, SizeF cursorsize, SizeF gridsize)
- {
- ImagesRender imagesRender = new ImagesRender(this,bitmapData,cursorsize,gridsize);
- imagesRender.CreateResources();
- renders.Add(imagesRender);
- return imagesRender;
- }
- public VeldridText AddText(Boolean supportbackColor = false, Boolean supportbackTransparent = true)
- {
- VeldridText text = new VeldridText(this,supportbackColor,supportbackTransparent);
- text.CreateResources();
- renders.Add(text);
- return text;
- }
- public MutiText AddMutiText(Boolean supportbackColor = false, Boolean supportbackTransparent = true)
- {
- MutiText text = new MutiText(this, supportbackColor, supportbackTransparent);
- text.CreateResources();
- renders.Add(text);
- return text;
- }
- public Plot.LineSeries AddLineSeries()
- {
- Plot.LineSeries series = new Plot.LineSeries(this);
- series.CreateResources();
- renders.Add(series);
- return series;
- }
- public Plot.DataReViewPlot AddReviewPlot()
- {
- Plot.DataReViewPlot plot= new Plot.DataReViewPlot(this);
- plot.CreateResources();
- renders.Add(plot);
- return plot;
- }
- public Legend.Legend AddLegend()
- {
- Legend.Legend legend = new Legend.Legend(this);
- legend.CreateResources();
- renders.Add(legend);
- return legend;
- }
- private List<BaseVeldridRender> renders = new List<BaseVeldridRender>();
-
- private VeldridText text;
- internal GraphicsManger GraphicsManger { get; }
- private bool disposedValue;
- public VeldridContent(GraphicsDevice device)
- {
- GraphicsManger = new GraphicsManger(device);
-
- text = new VeldridText(this,true,false);
- text.Margin = new Padding(40, 10, 10, 20);
- text.CreateResources();
- text.FontSize = 14;
- text.Color = System.Drawing.Color.White;
- text.Local = new System.Drawing.PointF(text.Range.MinX+20, text.Range.MinY+40);
- text.VerticalAlignment = VerticalAlignment.Bottom;
- text.HorizontalAlignment = HorizontalAlignment.Left;
- }
- public RgbaFloat BackColor = RgbaFloat.Black;
- private object locker= new object();
- public void Resize(uint width,uint height)
- {
- GraphicsManger.Device.ResizeMainWindow(width,height);
- renders.ForEach(x => x.Resize());
- text?.Resize();
- }
- public uint Width => GraphicsManger.Device.SwapchainFramebuffer.Width;
- public uint Height=>GraphicsManger.Device.SwapchainFramebuffer.Height;
- public void Render(bool runtimeplot = true)
- {
- lock (locker)
- {
- Stopwatch stopwatch = new Stopwatch();
- stopwatch.Start();
- GraphicsManger.CommandList.Begin();
- GraphicsManger.CommandList.SetFramebuffer(GraphicsManger.Device.MainSwapchain.Framebuffer);
- GraphicsManger.CommandList.ClearColorTarget(0, BackColor);
- renders.ForEach(x => x?.Draw());
- text?.Draw();
- GraphicsManger.CommandList.End();
- GraphicsManger.Device.SubmitCommands(GraphicsManger.CommandList);
- GraphicsManger.Device.SwapBuffers();
- GraphicsManger.Device.WaitForIdle();
- stopwatch.Stop();
- if (text != null) text.Text = string.Format("{0:f2}FPS", 1000 / stopwatch.Elapsed.TotalMilliseconds);
- }
- }
- private void Dispose(bool disposing)
- {
- if (!disposedValue)
- {
- if (disposing)
- {
- renders.ForEach(x => x?.DisposeResources());
- GraphicsManger?.Dispose();
- // TODO: 释放托管状态(托管对象)
- }
- // TODO: 释放未托管的资源(未托管的对象)并重写终结器
- // TODO: 将大型字段设置为 null
- disposedValue = true;
- }
- }
- // // TODO: 仅当“Dispose(bool disposing)”拥有用于释放未托管资源的代码时才替代终结器
- // ~VeldridContent()
- // {
- // // 不要更改此代码。请将清理代码放入“Dispose(bool disposing)”方法中
- // Dispose(disposing: false);
- // }
- public void Dispose()
- {
- // 不要更改此代码。请将清理代码放入“Dispose(bool disposing)”方法中
- Dispose(disposing: true);
- GC.SuppressFinalize(this);
- }
- }
- }
|