Re: interface Gdk::Pixbuf with normal X Window



On Tue, 2004-11-30 at 03:46, Jan Hudec wrote:
> On Mon, Nov 29, 2004 at 23:49:50 -0500, Carl Nygard wrote:
> > What do I need to do to get Gdk::Pixbuf to render to a normal X Window,
> > say one created by normal Xlib or OpenMotif?
> 
> You can't interact directly with X Windows. You have to wrap them in Gdk
> windows. There is a function for it somewhere in the appropriate
> gdk_x11_*. I am not sure whether it is bound in C++ or whether you'll
> have to go to the C interface directly (it is an internal interface).
> 
> Once you have Gdk::Window, you can simply render the pixbuf there, since
> Gdk::Window is a drawable.
> 

Can someone glance at this code and tell me what's wrong?  I'm not
having much success, and it seems like it should be simple.  

Program received signal SIGSEGV, Segmentation fault.
0x06a1ee66 in Gdk::GC::GC(Glib::RefPtr<Gdk::Drawable> const&) ()
   from /usr/lib/libgdkmm-2.0.so.1
(gdb) where
#0  0x06a1ee66 in Gdk::GC::GC(Glib::RefPtr<Gdk::Drawable> const&) ()
   from /usr/lib/libgdkmm-2.0.so.1
#1  0x06a1f8b7 in Gdk::GC::create(Glib::RefPtr<Gdk::Drawable> const&) ()
   from /usr/lib/libgdkmm-2.0.so.1
#2  0x0804b979 in GtkInfo::GtkInfo(unsigned long) ()
#3  0x0804bc5e in main ()

#include <gdk/gdkx.h>
#include <Xm/Form.h>
#include <Xm/Frame.h>
#include <Xm/DrawingA.h>

#undef DestroyNotify
#undef Status
#include <gtkmm/main.h>
#include <gtkmm/drawingarea.h>
#include <gdkmm/colormap.h>
#include <gdkmm/window.h>

#include <math.h>
#include <unistd.h>


struct GtkInfo {
    GtkInfo(Window win);

    Glib::RefPtr<Gdk::Drawable> _win;
    Glib::RefPtr<Gdk::GC> _gc;
    Glib::RefPtr<Gdk::Colormap> _colormap;
    Gdk::Color _fg;
    Gdk::Color _bg;
    
};

GtkInfo::GtkInfo(Window win) :
    _win(Glib::wrap(gdk_window_foreign_new(win))),
    _gc(Gdk::GC::create(_win)),
    _colormap(_win->get_colormap()),
    _fg(Gdk::Color("black")),
    _bg(Gdk::Color("white"))
{
    _colormap->alloc_color(_fg);
    _colormap->alloc_color(_bg);
    _gc->set_foreground(_fg);
    _gc->set_background(_bg);
}

int main(int argc, char** argv)
{
    Gtk::Main m(argc, argv);

    // Mandated by Gtk errors pointing to this function
    g_type_init();

    XtAppContext app_context;

	Widget GtopLevel = XtVaAppInitialize(&app_context,
                                         "RasterTest",
                                         NULL,0,
                                         &argc,argv,
                                         NULL,
                                         NULL);

    Widget Gwindow = XtVaCreateManagedWidget(
        "Gwindow",
        xmFormWidgetClass,
        GtopLevel,
        NULL);
  
    Widget Ggraf = XtVaCreateManagedWidget(
        "Ggraf",
        xmDrawingAreaWidgetClass,
        Gwindow,
        XmNtopAttachment,XmATTACH_FORM,
        XmNleftAttachment,XmATTACH_FORM,
        XmNrightAttachment,XmATTACH_FORM,
        XmNbottomAttachment,XmATTACH_FORM,
        XmNwidth,500,
        XmNheight,300,
        NULL);

	XtRealizeWidget(GtopLevel);

    GtkInfo info(XtWindow(Ggraf));

    XtAppMainLoop(app_context);
    
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]