SFML community forums
Bindings - other languages => DotNet => Topic started by: Joe_Howse on August 22, 2010, 04:01:54 pm
-
I have just started learning SFML and am very impressed. :)
I notice that SFML.NET does not include the Window.Create method that is present in C/C++ SFML. I was wondering, what is the recommended way of recreating the Window in SFML.NET (for example, if I want to toggle fullscreen mode)? Should I just close the existing Window and initialize another one to replace it?
Also, can you recommend any concise way to copy all event handlers (myWindow.Closed etc.) from one Window to another? I would normally want to preserve event handlers when recreating the window.
Thanks!
-
I notice that SFML.NET does not include the Window.Create method that is present in C/C++ SFML. I was wondering, what is the recommended way of recreating the Window in SFML.NET (for example, if I want to toggle fullscreen mode)? Should I just close the existing Window and initialize another one to replace it?
Yes. All "create" functions are implemented directly as constructors in SFML.Net.
Also, can you recommend any concise way to copy all event handlers (myWindow.Closed etc.) from one Window to another? I would normally want to preserve event handlers when recreating the window.
Sorry I have no idea, I'm not a .Net expert at all :)
-
If you're trying to do it for the same reasons I have, try wrapping your windows in another class and having them all raise desired events, then handle them in one place. eg:
Public Class DisplayWindow
Private WithEvents _RenderWindow As RenderWindow
Public Event InputReceived(ByVal Sender As Object,ByVal e As KeyEventArgs)
#Region "Events"
Sub App_KeyPressed(ByVal sender As Object, ByVal e As KeyEventArgs) Handles _RenderWindow.KeyPressed
RaiseEvent InputReceived(Me,e)
End Sub
'Put other events here
#End Region
End Class
Then when you want to create these windows and handle their events in one place you can do something like this:
Private _DisplayWindows As List(Of DisplayWindow)
Private Sub CreateNewWindow()
_DisplayWindows .Add(New DisplayWindow())
AddHandler _DisplayWindows.Last.InputReceived, AddressOf ProcessInput
End Sub
Private Sub ProcessInput(ByVal sender As Object, ByVal e As KeyEventArgs)
'Handle your common logic here
End Sub
-
Been looking into this further thinking it might be relevant to my particular multiple-monitor support implementation. As it turns out, it's not. Still, this might be of interest as a good starting point if you want to copy all events from one object to another:
http://stackoverflow.com/questions/660480/determine-list-of-event-handlers-bound-to-event
Basically you can adapt the accepted answer in that thread to add event handlers to the new window for each one it finds in the main foreach loop.