我应该如何使用 X11、motif、绘图区域和 c++ 来设置绘图区域 (X,Y) 坐标 (0,0)
How should I use X11, motif, DrawingArea, and c++ to set the DrawingArea (X,Y) coordinate (0,0)
我正在尝试使用绘图区域,但事情没有按照我预期的方式工作。
#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
相关文章:
- 将QGraphicsItem的移动区域限制在多边形区域内
- 有没有一种优雅而快速的方法来测试整数中的 1 位是否位于连续区域
- 在 Linux 中存储区域设置名称的缓冲区大小应该是多少?
- 两个连续的 OpenMP 并行区域会相互减慢速度
- 提升区域设置规范化带状字符,但不规范化重音
- 我的主窗口在创建时或单击更新区域时是否会收到编辑控件?
- 我可以将新的 std::tuple 放入内存映射区域,并在以后读回吗?
- 英特尔将指令存储在重叠的内存区域
- 如何给主窗口区域DKGRAY_BRUSH?
- 矢量擦除多个区域,2 x 擦除与单个分配?
- 错误:创建对象后无法分配区域
- 是否有任何区域设置会影响宽字符编码?
- GTKMM:拍摄绘图区域的屏幕截图?
- GTKMM:如何将键盘事件附加到绘图区域?
- 在 mmap'ed 区域上使用 memcpy 崩溃,for 循环不会
- 在绘制信号上保留绘图区域"图像"
- 我应该如何使用 X11、motif、绘图区域和 c++ 来设置绘图区域 (X,Y) 坐标 (0,0)
- 在gtk绘图区域中单击时选择绘制的线
- GTKMM::在GTk::绘图区域使用单个Gdk::PixBuf绘制多个图像
- 没有实现GTK绘图区域