get width&height from drawingarea ?

This forum is read only. No new submissions are accepted.

Questions about motif? Contact us

4 posts / 0 new
Last post
get width&height from drawingarea ?

After some experiments i am back to motif.
now i have some strange results. it would be nice if someone could tell me what is going on.
I have a drawing area widget and for testing i draw a line from upper right to lower left,
When i resize the window are the first reported coordinates are as expected. all other are rubbish.
void exposeCB(Widget w, XtPointer clientdata,XtPointer calldata)
{
puts(__func__);
XGCValues values;
int width,height,depth; /* Dimension */
GC gc;
XtVaGetValues(w,
XmNforeground,&values.foreground,
XmNbackground,&values.background,
NULL);
gc=XtGetGC(w, GCForeground|GCBackground,&values);
width=0;height=0;
XtVaGetValues(w,
XmNwidth,&width,
XmNheight,&height,
XmNdepth,&depth,
NULL);
XDrawLine(XtDisplay(w),
XtWindow(w) , /* drawable */
gc,
0,0,
width,height);
printf("%d %d\n",height,width);
}

 

 

Hi i figured out what went wrong,
XmNwidth XmNheight do not represent the "true" size of the drawingarea.

To find the lower right you need the expose event structure
and pick the x,y and width,height parameter from there.

    Also, the width and height

    Also, the width and height must be of Dimension type, not int.
    Otherwise your reading XtVaGetValues(w, XmNwidth,&width, XmNheight,&height,
    will be bogus.
    This is one of the old X Window (design) problems which does not handle windows bigger than signed short. Normally not a problem, but if you need big images with automatic scrollbars on drawing area, and you need to zoom in, you can quickly blow the precision.

     

     

     

    actualy when i was debugging i tried this but it changed nothing but you are right a correct code should use Dimension (unsigned short).