繁体   English   中英

我应该如何使用X11,motif,DrawingArea和c ++来设置DrawingArea(X,Y)坐标(0,0)

[英]How should I use X11, motif, DrawingArea, and c++ to set the DrawingArea (X,Y) coordinate (0,0)

我正在尝试使用DrawingAreas,事情并没有按照我的预期运作。

#include <Xm/Xm.h>
#include <Xm/DrawingA.h>

main(int argc, char *argv[])
{
  Widget shell, workArea, box1;
  XtAppContext app;
  shell = XtVaAppInitialize(&app, "gp", NULL, 0, &argc, argv, NULL, XmNwidth, 500, XmNheight, 500, NULL);
  XtRealizeWidget(shell);

  workArea = XtCreateWidget("wa",xmDrawingAreaWidgetClass, shell, NULL, 0);
  XtVaSetValues(workArea, XmNbackground, 30000, NULL);

  box1 = XtCreateWidget("b1", xmDrawingAreaWidgetClass, workArea, NULL, 0);
  XtVaSetValues(box1, XmNx, 0, XmNy, 0, XmNwidth, 400, XmNheight, 400, NULL);

  XtManageChild(workArea);
  XtManageChild(box1);
  //XtAppMainLoop(app);
  XEvent event;
  Dimension x,y,w,h;
  while(1)
  {
    XtAppNextEvent(app, &event);
    if (event.type == EnterNotify)
    {
      XtVaGetValues(box1, XmNx, &x, XmNy, &y, XmNwidth, &w, XmNheight, &h, NULL);
      printf("(x,y,w,h) == (%d,%d,%d,%d)\n", x, y, w, h);
    }
    if (event.type == LeaveNotify)
    {
      XtVaSetValues(box1, XmNx, 0, XmNy, 0, XmNwidth, 400, XmNheight, 400, NULL);
      printf("tried to set (x,y,w,h) = (0,0,400,400)\n");
    }
    XtDispatchEvent(&event);
  }
}

当我进入窗口并使用指针离开窗口时,我得到输出:

(x,y,w,h) == (10,10,400,400)
(x,y,w,h) == (10,10,400,400)
tried to set (x,y,w,h) = (0,0,400,400)
tried to set (x,y,w,h) = (0,0,400,400)
(x,y,w,h) == (10,10,400,400)
(x,y,w,h) == (10,10,400,400)
tried to set (x,y,w,h) = (0,0,400,400)
tried to set (x,y,w,h) = (0,0,400,400)

为什么XtVaSetValues没有将box1设置为(X,Y)=(0,0)? 如何在窗口内的(0,0)处完成绘图区域的放置?

我找到了答案,但没有提供它的声誉:

XtManageChild(box1);
XtUnmanageChild(box1);
XtVaSetValues(box1, XmNx, 0, XmNy, 0, XmNwidth, 400, XmNheight, 400, NULL);
XtMapWidget(box1);

看起来对XtManageChild()的调用正在调用父级的change_managed过程:

xtmanpage

为了将(x,y)设置为(0,0),我必须确保不管理小部件:

XtManageChild(box1); // must be called once
XtUnmanageChild(box1); // unmanage to allow (0,0)
XtVaSetValues(box1, NmNx, 0, XmNy, 0, XmNwidth, 400, XmNheight, 400, NULL);
XtMapWidget(box1); // show the widget

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM