Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/VL.ImGui.Stride #667

Merged
merged 25 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f63a489
Add VL.Core.Commands to Solution, was missing
kopffarben Feb 9, 2024
e35671d
VL.Imgui.Stride
kopffarben Feb 9, 2024
5e35f47
Helppatch shows MEMORYLEAK in BuildImFontAtlas() in VL.Imgui.Skia and…
kopffarben Feb 9, 2024
20a6db4
atlas.AddFontFromFileTTF caused the Memoryleak
kopffarben Feb 9, 2024
52b433a
Merge remote-tracking branch 'remotes/origin/main' into feature/VL.Im…
kopffarben Feb 13, 2024
f4b05f1
Move out some Functions from ToSkiaLayer to VL,ImGui.Renderhelper tha…
kopffarben Feb 13, 2024
28e4a1b
some CleanUp
kopffarben Feb 13, 2024
e8a1a00
remove ColorSpace Transformation from shaders/ImGuiShader_DrawFX.sdsl
kopffarben Feb 14, 2024
0b4bf91
ColorConversion in Shader
kopffarben Feb 21, 2024
0a4a2d3
WIP
kopffarben Feb 22, 2024
06aa334
WIP
kopffarben Feb 22, 2024
3871f97
WIP
kopffarben Feb 22, 2024
8e67d8f
get rid off unsafe ... use GCHandle instead
kopffarben Feb 23, 2024
966ab06
REWORK ToSkiaLayer.cs and SkiaWidget.cs and SkiaContext.cs
kopffarben Feb 23, 2024
94dd520
SkiaWidget is now working
kopffarben Feb 23, 2024
9425eba
Merge remote-tracking branch 'remotes/origin/main' into feature/VL.Im…
kopffarben Feb 23, 2024
c1ed36b
WIP InputHandeling
kopffarben Feb 23, 2024
400a08a
Throw Error when ImGuiRenderer is used inside ImGuiRenderer
kopffarben Feb 24, 2024
8205359
Skia Input Handling
kopffarben Feb 28, 2024
4082f68
CleanUP and working Skia Notification ... skiaRenderer don't push Tra…
kopffarben Mar 5, 2024
b491503
more CleanUP
kopffarben Mar 5, 2024
af909f9
Merge remote-tracking branch 'remotes/origin/main' into feature/VL.Im…
kopffarben Mar 5, 2024
2ee41af
WIP and CleanUP
kopffarben Mar 5, 2024
e700d86
WIP SceneWidget
kopffarben Mar 5, 2024
a44e84c
WIP SceneWidget
kopffarben Mar 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 31 additions & 30 deletions VL.ImGui.Skia/src/SkiaContext.cs
Original file line number Diff line number Diff line change
@@ -1,47 +1,48 @@
using ImGuiNET;
using Stride.Core.Mathematics;
using System.Runtime.CompilerServices;
using VL.Lib.IO.Notifications;
using VL.Skia;
using VL.ImGui.Widgets;


namespace VL.ImGui
{
using ImGui = ImGuiNET.ImGui;

class EmptyLayer : ILayer
public interface IContextWithSkia
{
public static EmptyLayer Instance = new EmptyLayer();
public IntPtr AddLayer(SkiaWidget layer, System.Numerics.Vector2 pos, System.Numerics.Vector2 size);

public RectangleF? Bounds => default;
public void RemoveLayer(SkiaWidget layer);
}

public bool Notify(INotification notification, CallerInfo caller)
{
return false;
}
public sealed class SkiaContext : Context, IContextWithSkia
{
public readonly List<SkiaWidget> Layers = new List<SkiaWidget>();

public void Render(CallerInfo caller)
public IntPtr AddLayer(SkiaWidget layer, System.Numerics.Vector2 pos, System.Numerics.Vector2 size)
{
if (Layers.Contains(layer))
{
return Layers.IndexOf(layer) + 1;
}
else
{
Layers.Add(layer);
return Layers.Count;
}
}
}

internal sealed class SkiaContext : Context
{
public readonly List<ILayer> Layers = new List<ILayer>();

public override void NewFrame()
public void RemoveLayer(SkiaWidget layer)
{
Layers.Clear();
Layers.Add(EmptyLayer.Instance);
base.NewFrame();
if (Layers.Contains(layer))
{
Layers.Remove(layer);
}
}

internal void AddLayer(Vector2 size, ILayer layer)
public SkiaWidget? GetLayer(IntPtr index)
{
var id = Layers.Count;
Layers.Add(layer);
DrawListPtr.AddImage(new IntPtr(id), default, Unsafe.As<Vector2, System.Numerics.Vector2>(ref size));
if (DrawList == DrawList.AtCursor)
ImGui.Image(new IntPtr(0), Unsafe.As<Vector2, System.Numerics.Vector2>(ref size));
if (Layers.Count >= index)
return Layers.ElementAt((int)index - 1);
else
return null;
}


}
}
37 changes: 26 additions & 11 deletions VL.ImGui.Skia/src/SkiaWidget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public sealed partial class SkiaWidget : PrimitiveWidget, IDisposable, ILayer
private bool _disposed;
private bool _itemHasFocus;
private bool _windowHasFocus;
private IContextWithSkia? _skiaContext;

public ILayer? Layer { private get; set; }

Expand All @@ -27,29 +28,38 @@ public sealed partial class SkiaWidget : PrimitiveWidget, IDisposable, ILayer

protected override void Draw(Context context, in ImDrawListPtr drawList, in System.Numerics.Vector2 offset)
{
if (Layer is null)
return;

if (context is SkiaContext skiaContext)
if (context is IContextWithSkia skiaContext)
{
var _ = Size.FromHectoToImGui();
var position = ImGui.GetCursorPos();
ImGui.InvisibleButton($"{GetHashCode()}", _, ImGuiButtonFlags.None);
this._skiaContext = skiaContext;

if (Layer is null)
{
skiaContext.RemoveLayer(this);
return;
}

var pos = ImGui.GetCursorPos();
var size = Size.FromHectoToImGui();
ImGui.InvisibleButton($"{GetHashCode()}", size, ImGuiButtonFlags.None);
_itemHasFocus = ImGui.IsItemFocused();
_windowHasFocus = ImGui.IsWindowFocused();
ImGui.SetCursorPos(position);
skiaContext.AddLayer(new Vector2(_.X, _.Y), this);
ImGui.SetCursorPos(pos);

// Use Callback instead of Texture to pass Layer ID ... first Layer has ID 1
drawList.AddCallback(skiaContext.AddLayer(this, pos, size), IntPtr.Zero);
}
}

[Pin(Ignore = true)]
public RectangleF? Bounds => !_disposed ? Layer?.Bounds : default;

SKMatrix? trans;

public void Render(CallerInfo caller)
{
if (_disposed || Layer is null)
return;

trans = caller.Transformation;
Layer.Render(caller);
}

Expand All @@ -65,11 +75,16 @@ public bool Notify(INotification notification, CallerInfo caller)
if (EventFilter == EventFilter.WindowHasFocus && !_windowHasFocus)
return false;

return Layer.Notify(notification, caller);

if (trans != null)
return Layer.Notify(notification, caller.WithTransformation((SKMatrix)trans));
else
return Layer.Notify(notification, caller); ;
}

public void Dispose()
{
_skiaContext?.RemoveLayer(this);
_disposed = true;
}
}
Expand Down
Loading