Added ScottPlot to the ImGui.
This commit is contained in:
parent
ee13de9594
commit
e091c3469d
51
GUIs/skyscraper8.UI.ImGui/Forms/SdlScottPlotWindow.cs
Normal file
51
GUIs/skyscraper8.UI.ImGui/Forms/SdlScottPlotWindow.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Echo.UserInterface.Backend;
|
||||
using ScottPlot;
|
||||
using SDL2;
|
||||
using SkiaSharp;
|
||||
using skyscraper8.UI.ImGuiForms;
|
||||
using testdrid.SdlWrapper;
|
||||
|
||||
namespace skyscraper8.UI.ImGui.Forms
|
||||
{
|
||||
internal class SdlScottPlotWindow : SdlWindow
|
||||
{
|
||||
private readonly Plot _plot;
|
||||
private readonly SKBitmap _skBitmap;
|
||||
private readonly SKCanvas _skCanvas;
|
||||
|
||||
public SdlScottPlotWindow(ImGuiDevice imGuiDevice, Plot plot, int width, int height, string title)
|
||||
: base(imGuiDevice, width, height, title)
|
||||
{
|
||||
this._plot = plot;
|
||||
this._skBitmap = new SKBitmap(new SKImageInfo(width, height, SKColorType.Bgra8888));
|
||||
this._skCanvas = new SKCanvas(_skBitmap);
|
||||
}
|
||||
|
||||
private byte[] tempBuffer;
|
||||
private int dataLength;
|
||||
protected override void RenderInternal(Texture surface)
|
||||
{
|
||||
_plot.Render(_skCanvas, (int)this._size.X, (int)this._size.Y);
|
||||
|
||||
nint data0 = surface.GetData0();
|
||||
nint pixels = _skBitmap.GetPixels();
|
||||
|
||||
if (dataLength == 0)
|
||||
{
|
||||
dataLength = _skBitmap.ByteCount;
|
||||
tempBuffer = new byte[dataLength];
|
||||
}
|
||||
|
||||
Marshal.Copy(pixels, tempBuffer, 0, dataLength);
|
||||
Marshal.Copy(tempBuffer, 0, data0, dataLength);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
30
GUIs/skyscraper8.UI.ImGui/Forms/SdlTestWindow.cs
Normal file
30
GUIs/skyscraper8.UI.ImGui/Forms/SdlTestWindow.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Echo.UserInterface.Backend;
|
||||
using SDL2;
|
||||
using skyscraper8.UI.ImGuiForms;
|
||||
using testdrid;
|
||||
using testdrid.SdlWrapper;
|
||||
|
||||
namespace skyscraper8.UI.ImGui.Forms
|
||||
{
|
||||
internal class SdlTestWindow : SdlWindow
|
||||
{
|
||||
private Random rng;
|
||||
public SdlTestWindow(ImGuiDevice imGuiDevice) : base(imGuiDevice, 320, 240)
|
||||
{
|
||||
rng = new Random();
|
||||
}
|
||||
|
||||
protected override void RenderInternal(Texture surface)
|
||||
{
|
||||
byte[] buffer = new byte[3];
|
||||
rng.NextBytes(buffer);
|
||||
|
||||
surface.SetPixel(rng.Next(320), rng.Next(240), 255, buffer[0], buffer[1], buffer[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
49
GUIs/skyscraper8.UI.ImGui/Forms/SdlWindow.cs
Normal file
49
GUIs/skyscraper8.UI.ImGui/Forms/SdlWindow.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using Echo.Core.Common.Packed;
|
||||
using Echo.UserInterface.Backend;
|
||||
using ImGuiNET;
|
||||
using SDL2;
|
||||
using SDL2Demo;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using skyscraper8.Skyscraper.Drawing;
|
||||
using testdrid.SdlWrapper;
|
||||
|
||||
namespace skyscraper8.UI.ImGuiForms
|
||||
{
|
||||
internal abstract class SdlWindow : IRenderable
|
||||
{
|
||||
protected readonly Vector2 _size;
|
||||
protected readonly Texture _texture;
|
||||
protected readonly string title;
|
||||
|
||||
protected SdlWindow(ImGuiDevice imGuiDevice, int width, int height, string title = "SDL Window")
|
||||
{
|
||||
|
||||
IntPtr textureIntPtr = imGuiDevice.CreateTexture(new Int2(width, height), true, !BitConverter.IsLittleEndian);
|
||||
_texture = Texture.FromIntPointer(textureIntPtr);
|
||||
|
||||
_size = new Vector2(_texture.GetWidth(), _texture.GetHeight());
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public void Render()
|
||||
{
|
||||
_texture.Lock();
|
||||
RenderInternal(_texture);
|
||||
_texture.Unlock();
|
||||
|
||||
|
||||
ImGuiNET.ImGui.PushStyleVar(ImGuiStyleVar.WindowMinSize, new Vector2(_texture.GetWidth() + 16, _texture.GetHeight() + 16));
|
||||
ImGuiNET.ImGui.Begin(title);
|
||||
ImGuiNET.ImGui.Image(_texture.Pointer, _size);
|
||||
ImGuiNET.ImGui.End();
|
||||
ImGuiNET.ImGui.PopStyleVar();
|
||||
}
|
||||
|
||||
protected abstract void RenderInternal(Texture surface);
|
||||
}
|
||||
}
|
||||
@ -4,6 +4,8 @@ using System.Net.NetworkInformation;
|
||||
using System.Reflection;
|
||||
using Echo.UserInterface.Backend;
|
||||
using ImGuiNET;
|
||||
using ScottPlot;
|
||||
using ScottPlot.Plottables;
|
||||
using SDL2;
|
||||
using SDL2Demo.SdlWrapper;
|
||||
using testdrid.SdlWrapper;
|
||||
@ -23,7 +25,10 @@ using skyscraper5.Skyscraper.Scraper.Storage.InMemory;
|
||||
using skyscraper5.src.Skyscraper;
|
||||
using skyscraper8.Skyscraper.Plugins;
|
||||
using skyscraper8.Skyscraper.Scraper.Storage;
|
||||
using skyscraper8.UI.ImGui.Forms;
|
||||
using Color = ScottPlot.Color;
|
||||
using Exception = System.Exception;
|
||||
using Version = System.Version;
|
||||
|
||||
|
||||
namespace SkyscraperUI
|
||||
@ -767,7 +772,7 @@ namespace SkyscraperUI
|
||||
{
|
||||
uiBlockingWindow.Render();
|
||||
}
|
||||
|
||||
|
||||
ImGui.EndFrame();
|
||||
ImGui.Render();
|
||||
|
||||
|
||||
@ -75,6 +75,7 @@ namespace testdrid
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns n unique random numbers in the range [1, n], inclusive.
|
||||
/// This is equivalent to getting the first n numbers of some random permutation of the sequential numbers from 1 to max.
|
||||
|
||||
@ -137,6 +137,14 @@ namespace testdrid.SdlWrapper
|
||||
Marshal.WriteByte(locked, offset + 3, a);
|
||||
}
|
||||
|
||||
public IntPtr GetData0()
|
||||
{
|
||||
if (locked == IntPtr.Zero)
|
||||
throw new InvalidOperationException("Texture not locked");
|
||||
|
||||
return locked;
|
||||
}
|
||||
|
||||
public void Unlock()
|
||||
{
|
||||
if (locked == IntPtr.Zero)
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ImGui.NET" Version="1.88.0" />
|
||||
<PackageReference Include="OpenRA-SDL2-CS" Version="1.0.33" />
|
||||
<PackageReference Include="ScottPlot" Version="5.0.55" />
|
||||
<PackageReference Include="sdl2_image.nuget" Version="2.6.1" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user