X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/545176521071a4edd242a2cd4163b363e818ec56..da590c59c76028158708a0e9dea4e8e16ecceec2:/utils/glcanvas/gtk/glcanvas.cpp diff --git a/utils/glcanvas/gtk/glcanvas.cpp b/utils/glcanvas/gtk/glcanvas.cpp index a59ceaed95..71d8228192 100644 --- a/utils/glcanvas/gtk/glcanvas.cpp +++ b/utils/glcanvas/gtk/glcanvas.cpp @@ -50,11 +50,14 @@ IMPLEMENT_CLASS(wxGLContext,wxObject) wxGLContext::wxGLContext( bool WXUNUSED(isRGB), wxWindow *win, const wxPalette& WXUNUSED(palette) ) { m_window = win; - m_widget = ((wxGLCanvas*)win)->m_glWidget; - - wxCHECK_RET( g_vi, "invalid visual for OpenGl" ); + m_widget = win->m_wxwindow; + + wxGLCanvas *gc = (wxGLCanvas*) win; + XVisualInfo *vi = (XVisualInfo *) gc->m_vi; - m_glContext = glXCreateContext( GDK_DISPLAY(), g_vi, None, GL_TRUE ); + wxCHECK_RET( vi, "invalid visual for OpenGl" ); + + m_glContext = glXCreateContext( GDK_DISPLAY(), vi, None, GL_TRUE ); wxCHECK_RET( m_glContext, "Couldn't create OpenGl context" ); } @@ -66,15 +69,17 @@ wxGLContext::wxGLContext( ) { m_window = win; - m_widget = ((wxGLCanvas*)win)->m_glWidget; - - wxCHECK_RET( g_vi, "invalid visual for OpenGl" ); + m_widget = win->m_wxwindow; + + wxGLCanvas *gc = (wxGLCanvas*) win; + XVisualInfo *vi = (XVisualInfo *) gc->m_vi; + + wxCHECK_RET( vi, "invalid visual for OpenGl" ); if( other != 0 ) - m_glContext = glXCreateContext( GDK_DISPLAY(), g_vi, other->m_glContext, - GL_TRUE ); + m_glContext = glXCreateContext( GDK_DISPLAY(), vi, other->m_glContext, GL_TRUE ); else - m_glContext = glXCreateContext( GDK_DISPLAY(), g_vi, None, GL_TRUE ); + m_glContext = glXCreateContext( GDK_DISPLAY(), vi, None, GL_TRUE ); wxCHECK_RET( m_glContext, "Couldn't create OpenGl context" ); } @@ -95,7 +100,7 @@ void wxGLContext::SwapBuffers() { if (m_glContext) { - GdkWindow *window = GTK_MYFIXED(m_widget)->bin_window; + GdkWindow *window = GTK_PIZZA(m_widget)->bin_window; glXSwapBuffers( GDK_DISPLAY(), GDK_WINDOW_XWINDOW( window ) ); } } @@ -104,7 +109,7 @@ void wxGLContext::SetCurrent() { if (m_glContext) { - GdkWindow *window = GTK_MYFIXED(m_widget)->bin_window; + GdkWindow *window = GTK_PIZZA(m_widget)->bin_window; glXMakeCurrent( GDK_DISPLAY(), GDK_WINDOW_XWINDOW(window), m_glContext ); } } @@ -146,8 +151,25 @@ gtk_glwindow_realized_callback( GtkWidget * WXUNUSED(widget), wxGLCanvas *win ) { win->m_glContext = new wxGLContext( TRUE, win, wxNullPalette, win->m_sharedContext ); - XFree( g_vi ); - g_vi = (XVisualInfo*) NULL; + return FALSE; +} + +//----------------------------------------------------------------------------- +// "map" from m_wxwindow +//----------------------------------------------------------------------------- + +static gint +gtk_glwindow_map_callback( GtkWidget * WXUNUSED(widget), wxGLCanvas *win ) +{ + if (win->m_glContext/* && win->m_exposed*/) + { + wxPaintEvent event( win->GetId() ); + event.SetEventObject( win ); + win->GetEventHandler()->ProcessEvent( event ); + + win->m_exposed = FALSE; + win->GetUpdateRegion().Clear(); + } return FALSE; } @@ -186,6 +208,24 @@ gtk_glwindow_draw_callback( GtkWidget *WXUNUSED(widget), GdkRectangle *rect, wxG rect->width, rect->height ); } +//----------------------------------------------------------------------------- +// "size_allocate" of m_wxwindow +//----------------------------------------------------------------------------- + +static void +gtk_glcanvas_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxGLCanvas *win ) +{ + if (g_isIdle) + wxapp_install_idle_handler(); + + if (!win->m_hasVMT) + return; + + wxSizeEvent event( wxSize(win->m_width,win->m_height), win->GetId() ); + event.SetEventObject( win ); + win->GetEventHandler()->ProcessEvent( event ); +} + //--------------------------------------------------------------------------- // wxGlCanvas //--------------------------------------------------------------------------- @@ -225,9 +265,11 @@ bool wxGLCanvas::Create( wxWindow *parent, const wxPalette& palette) { m_sharedContext = (wxGLContext*)shared; // const_cast + m_glContext = (wxGLContext*) NULL; m_exposed = FALSE; m_noExpose = TRUE; + m_nativeSizeEvent = TRUE; if (!attribList) { @@ -271,12 +313,14 @@ bool wxGLCanvas::Create( wxWindow *parent, Display *dpy = GDK_DISPLAY(); - g_vi = glXChooseVisual( dpy, DefaultScreen(dpy), attribList ); + XVisualInfo *vi = glXChooseVisual( dpy, DefaultScreen(dpy), attribList ); + + m_vi = vi; // safe for later use - wxCHECK_MSG( g_vi, FALSE, "required visual couldn't be found" ); + wxCHECK_MSG( m_vi, FALSE, "required visual couldn't be found" ); - GdkVisual *visual = gdkx_visual_get( g_vi->visualid ); - GdkColormap *colormap = gdk_colormap_new( gdkx_visual_get(g_vi->visualid), TRUE ); + GdkVisual *visual = gdkx_visual_get( vi->visualid ); + GdkColormap *colormap = gdk_colormap_new( gdkx_visual_get(vi->visualid), TRUE ); gtk_widget_push_colormap( colormap ); gtk_widget_push_visual( visual ); @@ -285,17 +329,23 @@ bool wxGLCanvas::Create( wxWindow *parent, m_glWidget = m_wxwindow; - gtk_my_fixed_set_clear( GTK_MYFIXED(m_wxwindow), FALSE ); + gtk_pizza_set_clear( GTK_PIZZA(m_wxwindow), FALSE ); gtk_signal_connect( GTK_OBJECT(m_wxwindow), "realize", GTK_SIGNAL_FUNC(gtk_glwindow_realized_callback), (gpointer) this ); + gtk_signal_connect( GTK_OBJECT(m_wxwindow), "map", + GTK_SIGNAL_FUNC(gtk_glwindow_map_callback), (gpointer) this ); + gtk_signal_connect( GTK_OBJECT(m_wxwindow), "expose_event", GTK_SIGNAL_FUNC(gtk_glwindow_expose_callback), (gpointer)this ); gtk_signal_connect( GTK_OBJECT(m_wxwindow), "draw", GTK_SIGNAL_FUNC(gtk_glwindow_draw_callback), (gpointer)this ); + gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate", + GTK_SIGNAL_FUNC(gtk_glcanvas_size_callback), (gpointer)this ); + gtk_widget_pop_visual(); gtk_widget_pop_colormap(); @@ -304,6 +354,11 @@ bool wxGLCanvas::Create( wxWindow *parent, wxGLCanvas::~wxGLCanvas() { + XVisualInfo *vi = (XVisualInfo *) m_vi; + + if (vi) + XFree( vi ); + if (m_glContext) delete m_glContext; }