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

[VL.ImGui.Stride.Viewports] #673

Open
wants to merge 60 commits into
base: main
Choose a base branch
from

Conversation

kopffarben
Copy link
Contributor

PR Details

Viewports support for VL.Imgui.Stride

Description

This is an attempt to support ImGui viewports in VL.

It already works quite well, there are a few small things that do not work satisfactorily yet.

IssueTracker: https://github.com/kopffarben/VL.StandardLibs/issues

The previous features should all still work. Not 100 percent sure.

The problem with the Skia input should also be fixed.
I think Kairos is still working, but I'm not quite sure as I don't know exactly how it should behave.

In general, it could be cleaned up again, I'm also not completely satisfied with the naming of some classes ... but in principle it's good for now.
I'm also not quite sure if this is the best solution for some things.

I would be very happy about a code review.

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

compiler Error after Cloning in ImGuiEffect.sdfx.cs
VL.ImGui.Stride was not updated in VL when edit the source
problem was different TargetFramework in csproj (net8.0-windows) and vvvv\packs\VL.ImGui.Stride\lib (net8.0-windows7.0)
so vl use allways version from vvvv-folder
remove InputManager from RenderLayerWithViewPort and get resourceHandle in MappedInputSource
now inputSource works from beginning

See MappedInputSource.Dispose
// TODO ... this will lead into 'Access violation'
//inputManager.Sources.Remove(this);
CleanUp
more GC friendly (reuse PointerPoint if possible)
known issues:
InputHandling need to be checked
Didn't work after restart F9
some bugs need to be found
maybe fixed SkiaWidget
Remove unused RenderView from RenderWidget ... is now done in vl
ClenUp
remove transformation workaround ... not longer needed ... fixed with 8e87a5a
@kopffarben
Copy link
Contributor Author

the AddMousePosEvent is only set if ImGui is not in viewport mode. If ImGui is in viewport mode, the screen space mouse position is set every frame in ImGuiWindows.

private void SetPerFrameImGuiData()
{
    unsafe
    { 
        int x, y;
        uint buttons = global::Stride.Graphics.SDL.Window.SDL.GetGlobalMouseState(&x, &y);
        _strideDeviceContext.IO.MouseDown[0] = (buttons & 0b0001) != 0;
        _strideDeviceContext.IO.MouseDown[1] = (buttons & 0b0010) != 0;
        _strideDeviceContext.IO.MouseDown[2] = (buttons & 0b0100) != 0;
        _strideDeviceContext.IO.MousePos = new Vector2(x, y);
    }

    _strideDeviceContext.IO.DisplaySize = new Vector2(mainViewportWindow.Size.X, mainViewportWindow.Size.Y);
    _strideDeviceContext.IO.DisplayFramebufferScale = new Vector2(1.0f, 1.0f);
    
    
    ImGui.GetPlatformIO().Viewports[0].Pos = new Vector2(mainViewportWindow.Position.X, mainViewportWindow.Position.Y);    
    ImGui.GetPlatformIO().Viewports[0].Size = new Vector2(mainViewportWindow.Size.X, mainViewportWindow.Size.Y);
}

So it should not break the current approach

@kopffarben
Copy link
Contributor Author

SO I fixed most of it for now, merged main and the bugfix. The problem with pulling the window in and out still exists.

I lose the input source or the appropriate viewport after dragging in and out a few times. Sometimes it goes faster ... but I don't have enough time right now to investigate it more closely. But I will keep at it.

kopffarben added 17 commits May 30, 2024 16:13
use VL.ImGui.Stride/src/ImGuiRenderer.cs from kopffarben
known issue ... remove IInputSource from normal Stride Windows
…r.cs

Use this Option in WindowCore to has an UniqueName, so save WindowLayout now working

remove temp loggiong ... was for debugging
…reen was wron ... width was 0 ... bug in Stride
Refactored `ImGuiWindow` and `ImGuiWindows` classes to use `IResourceHandle<InputManager>` and handle null `Window` objects gracefully. Updated `Dispose` methods across multiple classes to follow the standard dispose pattern, including adding `Dispose(bool disposing)` methods and finalizers. Removed `InputManagerExtension` class. Improved code readability with minor formatting changes.
Introduce UniqueId field to RenderWidget for unique naming.
Add constructors to initialize UniqueId. Remove nodeContext property.
Update ImGui.BeginChild to use UniqueId for unique names.
- Added new input pins ("Bounds," "Save Bounds," "Enable Camera," "EditMode") and removed some ("Edit Mode," "Node Context") in `VL.ImGui.Stride.vl` to improve functionality.
- Modified `HowTo ImGui Windows Docking.vl`
- Added `GameWindow` property and modified constructors in `ImGuiWindow.cs` and `ImGuiWindows.cs` to accept `RectangleF bounds`.
@kopffarben
Copy link
Contributor Author

SO finally I have it ... Yeahhh

I also had to use the SourceGenerator to get the layout saving of ImGui to work. Does nothing else than bringing the NodeContext in the Window Widget into the Constructor ... so I have a UniqueID for the names of the windows that I can add to the name name##uniqueID

The InputHandling was a really difficult matter ... but now it works completely ... I always capture the correct InputSource ... and the mapping to the SubInputSources always works.

Apart from that, I also handle the commands, perfmeters and so on ... Even the EditMode works, oh yes, I also save the bounds of the main window in the InputPin ... Copy from RenderWindow

Just take a look at Helppatch ... it's almost a full-blown application ... Windows, save layout, edit layout ... , LightMode/DarkMode ... etc.

@azeno
Copy link
Member

azeno commented Jan 7, 2025

Finally found some time to have a look. Two observations:

  • Text input doesn't work. Tried in the help patch in the StyleEditor/Colors tab or Log/Filters.
  • When opening the help patch parts of the main window are initially not visible on my screen. Moving the window to the left in order to make them visible seems to trigger some render issue, content is drawn out of place. See screenshot:
    image

@kopffarben
Copy link
Contributor Author

Ahh, thought I'd found all the bugs.

The keyboard input doesn't seem to work at all, doesn't work with the LogUI helppatch either. Short debugging shows that the events from Stride arrive but are somehow not passed on to ImGui. I have relatively little time at the moment, I'm at mBox. I'll be able to take a closer look on Friday.

I can't understand the second bug at all, I haven't seen it like this before and unfortunately I can't reproduce it.

@kopffarben
Copy link
Contributor Author

kopffarben commented Jan 13, 2025

mhh don't fix it in Viewport/Docking mode, but fix it in VL.ImGui.Stride Helppatch LogView

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants