X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5fd11f09718445c5795526c393f2b2a1875f6870..fe8aa971c4c66cc68ba6b64c61fae8149477bb5f:/utils/glcanvas/gtk/glcanvas.cpp?ds=sidebyside diff --git a/utils/glcanvas/gtk/glcanvas.cpp b/utils/glcanvas/gtk/glcanvas.cpp index a4b55c539e..bbc4c0dfdd 100644 --- a/utils/glcanvas/gtk/glcanvas.cpp +++ b/utils/glcanvas/gtk/glcanvas.cpp @@ -128,6 +128,18 @@ wxPalette wxGLContext::CreateDefaultPalette() return wxNullPalette; } +//----------------------------------------------------------------------------- +// "realize" from m_wxwindow +//----------------------------------------------------------------------------- + +static gint +gtk_glwindow_realized_callback( GtkWidget * WXUNUSED(widget), wxGLCanvas *win ) +{ + win->m_glContext = new wxGLContext( TRUE, win, wxNullPalette, win->m_glContext ); + + return FALSE; +} + //--------------------------------------------------------------------------- // wxGlCanvas //--------------------------------------------------------------------------- @@ -166,21 +178,13 @@ bool wxGLCanvas::Create( wxWindow *parent, int *attribList, const wxPalette& palette) { - m_needParent = TRUE; - m_acceptsFocus = TRUE; - - if (!PreCreation( parent, pos, size ) || - !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) - { - wxFAIL_MSG( _T("wxGLCanvas creation failed") ); - return FALSE; - } - + m_glContext = (wxGLContext*)shared; // const_cast + if (!attribList) { int data[] = { GLX_RGBA, GLX_DOUBLEBUFFER, - GLX_DEPTH_SIZE, 1, /* use largest available depth buffer */ + GLX_DEPTH_SIZE, 1, // use largest available depth buffer GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, @@ -220,42 +224,35 @@ bool wxGLCanvas::Create( wxWindow *parent, g_vi = glXChooseVisual( dpy, DefaultScreen(dpy), attribList ); + wxCHECK_MSG( g_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 ); gtk_widget_push_colormap( colormap ); gtk_widget_push_visual( visual ); + + wxScrolledWindow::Create( parent, id, pos, size, style, name ); + + m_glWidget = m_wxwindow; - m_glWidget = gtk_myfixed_new(); - m_widget = m_glWidget; - + gtk_signal_connect( GTK_OBJECT(m_glWidget), "realize", + GTK_SIGNAL_FUNC(gtk_glwindow_realized_callback), (gpointer) this ); gtk_widget_pop_visual(); gtk_widget_pop_colormap(); - m_parent->DoAddChild( this ); - /* must be realized for OpenGl output */ gtk_widget_realize( m_glWidget ); - m_glContext = new wxGLContext( TRUE, this, palette, shared ); - XFree( g_vi ); g_vi = (XVisualInfo*) NULL; - /* we pretend to have a m_wxwindow so that PostCreation hooks - up the events for expose and draw */ - m_wxwindow = m_glWidget; - PostCreation(); - - Show( TRUE ); - return TRUE; } wxGLCanvas::~wxGLCanvas() { if (m_glContext) delete m_glContext; - m_wxwindow = (GtkWidget*) NULL; } void wxGLCanvas::SwapBuffers() @@ -292,10 +289,10 @@ void wxGLCanvas::SetColour( const char *colour ) GtkWidget *wxGLCanvas::GetConnectWidget() { - return m_glWidget; + return m_wxwindow; } bool wxGLCanvas::IsOwnGtkWindow( GdkWindow *window ) { - return (window == m_glWidget->window); + return (window == m_wxwindow->window); }