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

Author Topic: No Window.Create method in SFML.NET?  (Read 4138 times)

0 Members and 1 Guest are viewing this topic.

Joe_Howse

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • http://nummist.com/ncc
No Window.Create method in SFML.NET?
« 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!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
No Window.Create method in SFML.NET?
« Reply #1 on: August 22, 2010, 09:29:36 pm »
Quote
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.

Quote
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 :)
Laurent Gomila - SFML developer

ferretallica

  • Newbie
  • *
  • Posts: 4
    • View Profile
No Window.Create method in SFML.NET?
« Reply #2 on: September 20, 2010, 03:25:50 am »
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:

Code: [Select]

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:

Code: [Select]

    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

ferretallica

  • Newbie
  • *
  • Posts: 4
    • View Profile
No Window.Create method in SFML.NET?
« Reply #3 on: September 22, 2010, 01:38:55 am »
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.