Fixed it myself:
#include <SFML/Graphics.hpp>
#include <wx/wx.h>
#ifdef __WXGTK__
#include <gdk/gdkx.h>
#include <gtk/gtk.h>
#endif
class wxSFMLCanvas : public wxControl, public sf::RenderWindow
{
public :
wxSFMLCanvas(wxWindow* Parent = NULL, wxWindowID Id = -1, const wxPoint& Position = wxDefaultPosition,
const wxSize& Size = wxDefaultSize, long Style = 0);
virtual ~wxSFMLCanvas() {};
private :
DECLARE_EVENT_TABLE()
virtual void OnUpdate() {};
void OnIdle(wxIdleEvent&);
void OnPaint(wxPaintEvent&);
void OnEraseBackground(wxEraseEvent&);
};
BEGIN_EVENT_TABLE( wxSFMLCanvas, wxControl )
EVT_IDLE( wxSFMLCanvas::OnIdle )
EVT_PAINT( wxSFMLCanvas::OnPaint )
EVT_ERASE_BACKGROUND( wxSFMLCanvas::OnEraseBackground )
END_EVENT_TABLE()
void wxSFMLCanvas::OnIdle(wxIdleEvent&)
{
// Send a paint message when the control is idle, to ensure maximum framerate
Refresh();
}
void wxSFMLCanvas::OnEraseBackground(wxEraseEvent&)
{
}
void wxSFMLCanvas::OnPaint(wxPaintEvent&)
{
// Prepare the control to be repainted
wxPaintDC Dc(this);
// Let the derived class do its specific stuff
OnUpdate();
// Display on screen
display();
}
wxSFMLCanvas::wxSFMLCanvas(wxWindow* Parent, wxWindowID Id, const wxPoint& Position, const wxSize& Size, long Style) :
wxControl(Parent, Id, Position, Size, Style)
{
#ifdef __WXGTK__
// GTK implementation requires to go deeper to find the
// low-level X11 identifier of the widget
gtk_widget_realize(m_wxwindow);
gtk_widget_set_double_buffered(m_wxwindow, false);
GdkWindow* Win = gtk_widget_get_window( (GtkWidget *) GetHandle() );
XFlush(GDK_WINDOW_XDISPLAY(Win));
sf::RenderWindow::create(GDK_WINDOW_XWINDOW(Win));
#else
// Tested under Windows XP only (should work with X11
// and other Windows versions - no idea about MacOS)
sf::RenderWindow::Create(GetHandle());
#endif
}
class MyCanvas : public wxSFMLCanvas
{
public :
MyCanvas(wxWindow* Parent,
wxWindowID Id,
wxPoint Position,
wxSize Size,
long Style = 0) :
wxSFMLCanvas(Parent, Id, Position, Size, Style)
{
// Load an image and assign it to our sprite
//myImage.LoadFromFile("sprite.png");
//mySprite.SetImage(myImage);
}
private :
virtual void OnUpdate()
{
// Clear the view
clear(sf::Color::Blue);
// Display the sprite in the view
//Draw(mySprite);
}
//sf::Image myImage;
//sf::Sprite mySprite;
};
class MyFrame : public wxFrame
{
public :
MyFrame() :
wxFrame(NULL, wxID_ANY, "SFML wxWidgets", wxDefaultPosition, wxSize(800, 600))
{
new MyCanvas(this, wxID_ANY, wxPoint(50, 50), wxSize(700, 500));
}
};
class MyApplication : public wxApp
{
private :
virtual bool OnInit()
{
// Create the main window
MyFrame* MainFrame = new MyFrame;
MainFrame->Show();
return true;
}
};
IMPLEMENT_APP(MyApplication);