Hello all,
Am trying to use cairo for drawing in a Motif/ViewKit setup. I;m stuck
Here's my simple tester code minus the boilerplate:
Code:
MainWindow::MainWindow(const char* name) : VkWindow(name) {
setMenuBar(mnu);
ui_root = XtVaCreateWidget (
"ui_root", xmFormWidgetClass, mainWindowWidget(),
XmNwidth, 600,
XmNheight, 400,
NULL );
ui_drawingarea = XtVaCreateWidget (
"ui_drawingarea", xmDrawingAreaWidgetClass, ui_root,
XmNtopAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
NULL );
XtManageChild(ui_drawingarea);
Display *dpy = theApplication->display();
cairo_surface_t *cs = cairo_xlib_surface_create( dpy, XtWindow(ui_drawingarea), DefaultVisual(dpy, 0), 200, 200 );
cairo_t *c = cairo_create(cs);
cairo_rectangle(c, 0.0, 0.0, 200, 200);
cairo_set_source_rgb(c, 0.0, 0.0, 0.5);
// I think cairo_fill() fails with BadWindow because the X11 drawables aren't mapped
// since VkWindow->show() hasn't been called yet :(
//
//cairo_fill(c);
//cairo_destroy(c);
addView(ui_root);
}
MainWindow::~MainWindow() { // bye, bye. }
const char* MainWindow::className() { return "MainWindow"; }
void MainWindow::mnu_file_new() {
cout << "called: mnu_file_new." << endl;
}
void MainWindow::mnu_file_new_cb(Widget w, XtPointer client_data, XtPointer call_data) {
MainWindow *obj = (MainWindow *) client_data;
obj->mnu_file_new();
}
void MainWindow::mnu_file_quit() {
theApplication->quitYourself();
}
void MainWindow::mnu_file_quit_cb(Widget w, XtPointer client_data, XtPointer call_data) {
MainWindow *obj = (MainWindow *) client_data;
obj->mnu_file_quit();
}
VkMenuDesc MainWindow::mnu[] {
{SUBMENU, "File", NULL, mnu_file},
{END}
};
VkMenuDesc MainWindow::mnu_file[] {
{ACTION, "New", &MainWindow::mnu_file_new_cb},
{SEPARATOR, "Menu separator"},
{ACTION, "Quit", &MainWindow::mnu_file_quit_cb},
{END}
};
My understanding is that cairo_fill() in the constructor gives me 'BadWindow' because the actual widgets haven't been mapped yet as VkWindow->show() hasn't been called yet. But when I move cairo_fill() to mnu_file_new() in the menubar, so I can call it when the window is mapped, I get a segmentation fault. Which I think is because of the whole C++ instance thing where things aren't actually mapped in memory like you think they are, which is why you need to define things as static for callbacks etc., which remains very confusing to me.
So my question is: how do I get a handle to the cairo drawable/surface in each of my VkWindow instances so I can draw into them at will?
thnx,
Jimmer