在ObjectARX Developer's
Guide 里找到了
Example
3: Obtaining the Window Coordinates
This example shows the use of AcGiViewportDraw::polylineDc() and AcGiViewport::getViewportDcCorners() to obtain the display
coordinates of the viewport. This function is convenient when you are drawing
graphics that depend on the physical layout of the viewport, such as icons
and markers that vary with the size or borders of the viewport. The graphics
drawn will change with panning and zooming.
The example draws a box in the upper-right corner of the viewport. The box's width
and height are always one-tenth of the viewport's shortest dimension, and the
box is centered one-tenth of the viewport's shortest dimension down and to the
left of the upper-right-hand corner of the viewport:
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.x = xcenter; verts.y = ycenter; verts.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); } |