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

The SFML form embedded in Avalonia cannot receive any events #288

Open
PulpFiction98 opened this issue Mar 5, 2025 · 2 comments
Open

The SFML form embedded in Avalonia cannot receive any events #288

PulpFiction98 opened this issue Mar 5, 2025 · 2 comments
Labels

Comments

@PulpFiction98
Copy link

PulpFiction98 commented Mar 5, 2025

System: windows。
I used. net to create a win32 handle in Avalonia, then created a window using SFML and embedded it into the Avalonia form. The rendering and drawing are all normal, but the SFML form cannot receive any events. Is there anything that needs to be set?

Image

Image

public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
          
            this.Loaded += MainWindow_Loaded;   
        }

        private void MainWindow_Loaded(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
        {
          
            var window = [new](http://www.google.com/search?q=new+msdn.microsoft.com) SFML.Graphics.RenderWindow(windowBox.Handle);
            // window.KeyPressed += Window_KeyPressed;
            window.MouseMoved += Window_MouseMoved; ;
             var circle = [new](http://www.google.com/search?q=new+msdn.microsoft.com) SFML.Graphics.CircleShape(100f)
            {
                FillColor = SFML.Graphics.Color.Blue,
                Position=[new](http://www.google.com/search?q=new+msdn.microsoft.com) Vector2f(500,500)
            };
            window.Draw(circle);

            // Finally, display the rendered frame on screen
            window.Display();
       
        }

        private void Window_MouseMoved(object? sender, SFML.Window.MouseMoveEventArgs e)
        {
           //Can In it
        }
    }
    public class NativeEmbeddingControl : NativeControlHost
    {
        public IntPtr Handle { get; private set; }

        protected override IPlatformHandle CreateNativeControlCore(IPlatformHandle parent)
        {

            var handle = base.CreateNativeControlCore(parent);
            Handle = handle.Handle;
            Console.WriteLine($"Handle : {Handle}");
            return handle;
        }
    }
@eXpl0it3r eXpl0it3r transferred this issue from SFML/CSFML Mar 5, 2025
@eXpl0it3r
Copy link
Member

Moved the issue from CSFML to SFML.Net.

Also there's a cross post on the forum, just in case someone posts an answer there: https://en.sfml-dev.org/forums/index.php?topic=29833.0

@eXpl0it3r eXpl0it3r added the Bug label Mar 5, 2025
@PulpFiction98
Copy link
Author

PulpFiction98 commented Mar 6, 2025

将问题从 CSFML 移至 SFML.Net。

论坛上还有一个交叉帖子,以防有人在那里发布答案:https://en.sfml-dev.org/forums/index.php?topic=29833.0

将问题从 CSFML 移至 SFML.Net。

论坛上还有一个交叉帖子,以防有人在那里发布答案:https://en.sfml-dev.org/forums/index.php?topic=29833.0

Thank you, I suspect that this issue is related to creating windows from existing native handles, and it may not be just a problem with C # binding usage. Perhaps using Qt to embed SFML window also has this issue.

And this issue has also appeared to some extent in another multimedia library (SDL).

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

No branches or pull requests

2 participants