Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Hosing a RenderWindow in a WPF window?  (Read 3676 times)

0 Members and 2 Guests are viewing this topic.

econobeing

  • Newbie
  • *
  • Posts: 1
    • View Profile
Hosing a RenderWindow in a WPF window?
« on: February 25, 2016, 09:09:17 pm »
Hi everybody. I'm trying work on a project that is going to require a good amount of buttons and text boxes so I'd like to host the RenderWindow inside of a WPF window.

Through a some Google searching I found how how to host a RenderWindow inside of a Winforms application (http://en.sfml-dev.org/forums/index.php?topic=9141.msg61848#msg61848). Luckily there's also a way to host a Winforms control inside a WPF application (https://msdn.microsoft.com/library/ms751761(v=vs.100).aspx)

I had to make a change from the sample code though, my drawing surface has to inherit from System.Windows.Forms.Panel instead of Control, otherwise drawing shapes doesn't work.

Another big issue was that it appeared that the RenderWindow was setting its size to the size of the containing drawing surface only once upon construction, and stretching itself to fill the container the rest of the time. Which turned circles into ellipses, things couldn't be positioned under the mouse, etc. I resolved that by recreating the Renderwindow every time the SizeChanged event fires on the customer drawing surface. That's probably not ideal, but it works.

MouseButtonPressed events on the RenderWindow fire, but unfortunately KeyPressed events don't. I'm not even sure what the issue causing that might be causing that. Maybe the WPF window is "higher up the chain" or something? They KeyPressed event thing seems to be the last piece of the puzzle. I haven't tried audio yet but I can't imagine it would be an issue.

The only thing I could think of now is maybe trying to put a KeyPressed event handler on the WPF Window itself and somehow converting that into a SFML KeyPressed event. But that seems like a lot of work for something that might be able to be fixed by just changing a setting.

I have the code available in a gist here: https://gist.github.com/trlewis/73e20cdf49082823c1c5

Any help would be appreciated. I haven't found anything about using SFML with a WPF window specifically, just Winforms.