[comp.windows.x] graphics and widgets

sbuck@GATEWAY.MITRE.ORG (Steve Buck) (08/16/89)

I'm trying to create a window with two main areas.  One area contains several
command widgets and the other I would like to be able to display graphics in.
Right now I've set up my root widget and then created two form widgets, one
for the command widgets and one to display graphics in.  Could someone please
tell me how I go about drawing things in the widget like I did for the window
 (i.e. XDrawRectangle, but for the widget)
          Thanks,
-- 
			-- Steve Buck

The MITRE Corporation, Networking Center
McLean, Virginia
phone:	(703) 883-5574
email:	sbuck@gateway.mitre.org

sbuck@GATEWAY.MITRE.ORG (Steve Buck) (08/16/89)

> out in the manuals, sigh.   Anyway all you need to display graphics
> is the Display and Window id of the widget you want to draw into
> (plus of course a suitable graphics context).   To retrieve the Display

Ok,
   here is a section of code that I use to create the GC and when I try
to run it it gives me 'X Protocol error: BadDrawable, invalid Pixmap or Window
			parameter'
	Widget dispwin;
	Window displaywin;
             .
	     .
	     .
	/* get window from widget */
	displaywin = XtWindow (dispwin);
	
        /* create GC for text and drawing */
	get_GC(displaywin, &gc, font_info);

	/* Ask parents to manage children */
	XtManageChild (dispwin);

	/* Realize widget tree */
	XtRealizeWidget (win);

	/* Start event processing loop */
	XtAppMainLoop (app_context);
}

void get_GC (displaywin, gc, font_info)
Window displaywin;
GC *gc;
XFontStruct *font_info;
{
	/* create default graphics context */
	*gc = XCreateGC (display, displaywin, 0, NULL);

	/* specify font */
	XSetFont (display, *gc, font_info->fid);

	/* specify black foreground since default may be white on white */
	XSetForeground (display, *gc, BlackPixel(display, screen));
}

> and Window id from a widget use ... XtDisplay(w) and XtWindow(w).  Nothing
> could be simpler! eg:
> 
> 	XDrawLine(XtDisplay(w), XtWindow(w), gc, 0, 0, 10, 20);
> 
> However ... a word of warning this will not work until the window has been
> realized and mapped and has received the first ConfigureNotify event.
> ie. The Server will ignore these requests as it has no real window to draw
> into.  So what you need to do is to capture the first ConfigureNotify event
> either using a translation string "<ConfigureNotify>: turn_on_graphics()"
> or using XtAddEventHandler(w, ... ), the choice is yours,  plus you
> need to capture resize and expose events for redrawing, so a suitable
> XtNtranslations string for your drawing widget might be...
> 
> 	"<ConfigureNotify>: turn_on_graphics() resize()\n\
> 	 <Expose>: redraw()"
> 

Ok,
   I also have the problem that when I try to add the procedure draw_graphics
to the translation table it comes back with the error 'X Toolkit Warning:
		Actions not found: draw_graphics.  Here is how I'm changing
the translation table:

	XtTranslations  DisplayTrans;
	static char	DisplayTransTable[]=
				"<ConfigureNotify>: draw_graphics() \n\
				 <Expose>: draw_graphics()";
		.
		.
		.
	/* create display window */
	i = 0;
	XtSetArg(args[i], XtNx, 2); i++;
	XtSetArg(args[i], XtNy, 152); i++;
	XtSetArg(args[i], XtNwidth, 600); i++;
	XtSetArg(args[i], XtNheight, 600); i++;
	XtSetArg(args[i], XtNborderWidth, border_width); i++;
	dispwin = XtCreateWidget ("window", formWidgetClass, win, args, i); 

	/* modify translation table */
	DisplayTrans = XtParseTranslationTable(DisplayTransTable);
	XtAugmentTranslations (dispwin, DisplayTrans);


Any ideas as to what is wrong would be appreciated.
             Thanks,
-- 
			-- Steve Buck

The MITRE Corporation, Networking Center
McLean, Virginia
phone:	(703) 883-5574
email:	sbuck@gateway.mitre.org