示例 3:获取窗口坐标
此示例演示如何使用 和 获取视口的显示坐标。当您绘制依赖于视口的物理布局的图形时,此功能非常方便,例如随视口的大小或边框而变化的图标和标记。绘制的图形将随着平移和缩放而变化。AcGiViewportDraw::polylineDc()AcGiViewport::getViewportDcCorners() 该示例在视口的右上角绘制一个框。框的宽度和高度始终是视口最短尺寸的十分之一,并且框位于视口右上角左侧的视口最短尺寸的十分之一的中心: void AsdkIconSamp::subViewportDraw(AcGiViewportDraw* pV) { // Get the current viewport's display coordinates. // AcGePoint2d lower_left, upper_right; pV->viewport ().getViewportDcCorners(lower_left, upper_right); double xsize = upper_right.x - lower_left.x; double ysize = upper_right.y - lower_left.y; xsize /= 10.0; ysize /= 10.0; double xcenter = upper_right.x - xsize; double ycenter = upper_right.y - ysize; double half_xsize = xsize / 2.0; double half_ysize = ysize / 2.0; // Create a unit square. // const int num_verts = 5; AcGePoint3d verts[num_verts]; for (int i = 0; i < num_verts; i++) { verts[i].x = xcenter; verts[i].y = ycenter; verts[i].z = 0.0; } verts[0].x -= half_xsize; verts[0].y += half_ysize; verts[1].x += half_xsize; verts[1].y += half_ysize; verts[2].x += half_xsize; verts[2].y -= half_ysize; verts[3].x -= half_xsize; verts[3].y -= half_ysize; verts[4] = verts[0]; pV- >subEntityTraits().setColor(kRed); pV->geometry ().polylineDc(num_verts, verts); } void AsdkIconSamp::viewportDraw(AcGiViewportDraw* pV) { // Get the current viewport's display coordinates. // AcGePoint2d lower_left, upper_right; pV->viewport().getViewportDcCorners(lower_left, upper_right); double xsize = upper_right.x - lower_left.x; double ysize = upper_right.y - lower_left.y; xsize /= 10.0; ysize /= 10.0; double xcenter = upper_right.x - xsize; double ycenter = upper_right.y - ysize; double half_xsize = xsize / 2.0; double half_ysize = ysize / 2.0; // Create a unit square. // const int num_verts = 5; AcGePoint3d verts[num_verts]; for (int i = 0; i < num_verts; i++) { verts[i].x = xcenter; verts[i].y = ycenter; verts[i].z = 0.0; } verts[0].x -= half_xsize; verts[0].y += half_ysize; verts[1].x += half_xsize; verts[1].y += half_ysize; verts[2].x += half_xsize; verts[2].y -= half_ysize; verts[3].x -= half_xsize; verts[3].y -= half_ysize; verts[4] = verts[0]; pV->subEntityTraits().setColor(kRed); pV->geometry().polylineDc(num_verts, verts); } 父主题: |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2024-12-15 22:03
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.