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

Added option to add a parent reference for SDL window #2111

Merged
merged 1 commit into from
Jan 26, 2024

Conversation

Doprez
Copy link
Contributor

@Doprez Doprez commented Jan 19, 2024

PR Details

I wanted an easy way to embed Stride into other UI frameworks so I decided to make a simple breakdown of #1474 without the built in demos.

Description

This PR allows for SDL to take in a parent handle and use that for rendering.

WinForms example:
image

In the future I would like to use this for experimenting with Avalonia as the parent host using the NativeControlHost.

Related Issue

#1474

Motivation and Context

Some people have asked for an easy way to embed Stride into UI frameworks in the Discord this will allow an easy constructor to pass in a parent handle.

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)

Checklist

  • My change requires a change to the documentation.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have built and run the editor to try this change out.

@Kryptos-FR Kryptos-FR changed the title added option to ad a parent reference for SDL window added option to add a parent reference for SDL window Jan 19, 2024
@Kryptos-FR
Copy link
Member

Thanks for the contribution. A couple of questions:

What's causing the inputs to not work?

Can this is be used already to adapt the GameForm used in the GameStudio? And in that way validate that it might work later with Avalonia.

@Doprez
Copy link
Contributor Author

Doprez commented Jan 19, 2024

What's causing the inputs to not work?

Im not 100% sure honestly. The Winforms inputs seem to be registered but the the results are not consistant. When you use the mouse to look around in the particle scene for example, it will slowly rotate and on release of the mouse it will flick the view in the direction it was moving.

A couple thoughts I have had are:

  • wondering if it is using 2 seperate inputs, one for the SDL for and one for the main form?
  • Do we need to take over the message loop manually?

but I havent found a solution or specific answer.

Can this is be used already to adapt the GameForm used in the GameStudio? And in that way validate that it might work later with Avalonia.

Your Avalonia branch was actually the main inspiration for me wanting this. Its why I wanted to test with Avalonia in the future when I have more time.

@Doprez
Copy link
Contributor Author

Doprez commented Jan 19, 2024

it will slowly rotate and on release of the mouse it will flick the view in the direction it was moving

Forget what I said here, this is apparently normal behaviour for this demo...

@Doprez
Copy link
Contributor Author

Doprez commented Jan 19, 2024

@Kryptos-FR so I went back and tested all of the templates apart from the VR one and I had zero issues with using inputs.

the problems I faced:

  • the mouse cursor is not hidden but it can be locked in place.
  • framerate needs to be changed for the minimized window for some reason. When using SDL as a child control it seems to think it is minimized until fullscreened so it will run at a lower FPS unless you set MinimizedMinimumUpdateRate.MinimumElapsedTime

tested the following with Winforms:

  • FPS template works fine
  • Third person template works fine
  • Top down template works fine
  • Particle demo works fine

@Kryptos-FR
Copy link
Member

Kryptos-FR commented Jan 19, 2024

Do you have public branch somewhere I could use to test those samples on my side or just the code snippet you used?

@Doprez
Copy link
Contributor Author

Doprez commented Jan 19, 2024

https://github.com/Doprez/test-parent-sdl-branch/tree/main this should be all you need, essentially the .WinForms project can be attached to any Stride game the same way you would use the .Windows projects.

@Kryptos-FR Kryptos-FR self-requested a review January 19, 2024 16:56
@Doprez
Copy link
Contributor Author

Doprez commented Jan 19, 2024

image

https://github.com/Doprez/stride-in-avalonia

Decided to mess with Avalonia since everyone at work is just waiting on the weekend lol. And a black screen is better than no screen I think?

Edit: It is not better, default behvaiour when it cant use a handle is black so this isnt running at all.

@Doprez
Copy link
Contributor Author

Doprez commented Jan 20, 2024

Took a step back to try and get the WPF dexample working from the previous PR because Avalonia is being weird to set up.

it works with WPF and Ill add it to the my repo along with my attempts to get Avalonia running:
image

@Eideren
Copy link
Collaborator

Eideren commented Jan 26, 2024

Is this one ready for merge or do you want to figure out the issue you're having with Avalonia first ? I'm guessing if there are changes required to make avalonia work it'll likely be on the client side rather than the engine one but just in case.

@Kryptos-FR
Copy link
Member

@Eideren if there is any change needed for Avalonia it will be done at that time. I think it's ok to merge this PR as long as WPF is still working.

@Doprez
Copy link
Contributor Author

Doprez commented Jan 26, 2024

Yep, these issues are mostly with understanding avalonia itself, the pr should be good.

@Eideren Eideren merged commit 022296f into stride3d:master Jan 26, 2024
2 checks passed
@Eideren
Copy link
Collaborator

Eideren commented Jan 26, 2024

Thanks !

@VaclavElias VaclavElias changed the title added option to add a parent reference for SDL window Added option to add a parent reference for SDL window Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants