Back to index

libsfml  1.6+dfsg2
wxSFMLCanvas.cpp
Go to the documentation of this file.
00001 
00002 
00004 // Headers
00006 #include "wxSFMLCanvas.hpp"
00007 
00008 // Platform-specific includes
00009 #ifdef __WXGTK__
00010     #include <gdk/gdkx.h>
00011     #include <gtk/gtk.h>
00012     #include <wx/gtk/win_gtk.h>
00013 #endif
00014 
00015 
00017 // Event table
00019 BEGIN_EVENT_TABLE(wxSFMLCanvas, wxControl)
00020     EVT_IDLE(wxSFMLCanvas::OnIdle)
00021     EVT_PAINT(wxSFMLCanvas::OnPaint)
00022     EVT_ERASE_BACKGROUND(wxSFMLCanvas::OnEraseBackground)
00023 END_EVENT_TABLE()
00024 
00025 
00029 wxSFMLCanvas::wxSFMLCanvas(wxWindow* Parent, wxWindowID Id, const wxPoint& Position, const wxSize& Size, long Style) :
00030 wxControl(Parent, Id, Position, Size, Style)
00031 {
00032     #ifdef __WXGTK__
00033 
00034         // GTK implementation requires to go deeper to find the low-level X11 identifier of the widget
00035         gtk_widget_realize(m_wxwindow);
00036         gtk_widget_set_double_buffered(m_wxwindow, false);
00037         GdkWindow* Win = GTK_PIZZA(m_wxwindow)->bin_window;
00038         XFlush(GDK_WINDOW_XDISPLAY(Win));
00039         sf::RenderWindow::Create(GDK_WINDOW_XWINDOW(Win));
00040 
00041     #else
00042 
00043         // Tested under Windows XP only (should work with X11 and other Windows versions - no idea about MacOS)
00044         sf::RenderWindow::Create(GetHandle());
00045     
00046     #endif
00047 }
00048 
00049 
00053 wxSFMLCanvas::~wxSFMLCanvas()
00054 {
00055     // Nothing to do...
00056 }
00057 
00058 
00063 void wxSFMLCanvas::OnUpdate()
00064 {
00065     // Nothing to do by default...
00066 }
00067 
00068 
00073 void wxSFMLCanvas::OnIdle(wxIdleEvent&)
00074 {
00075     // Send a paint message when the control is idle, to ensure maximum framerate
00076     Refresh();
00077 }
00078 
00079 
00084 void wxSFMLCanvas::OnPaint(wxPaintEvent&)
00085 {
00086     // Make sure the control is able to be repainted
00087     wxPaintDC Dc(this);
00088 
00089     // Let the derived class do its specific stuff
00090     OnUpdate();
00091 
00092     // Display on screen
00093     Display();
00094 }
00095 
00096 
00100 void wxSFMLCanvas::OnEraseBackground(wxEraseEvent&)
00101 {
00102     // Don't do anything. We intercept this event in order to prevent the
00103     // parent class to draw the background before repainting the window,
00104     // which would cause some flickering
00105 }