|
Peg2DPolygon |
|
|
|
| ||||||||||||||||||
|
|
See Also |
PegScreen
(Polygon() function)
Polygon Geometry |
It is important to understand the geometry which governs the operation of a KwikPeg 2D polygon.
Consider the x-y coordinate system shown in Figures 1 and 2 below. A point P in the x-y plane has coordinates (x,y). Coordinate x is considered positive along OX and negative along OX'. Coordinate y is positive along OY and negative along OY'. Line X'OXis the x; line Y'OY is the y axis.
The angle A (shown red) described counterclockwise from OX is considered positive. If the angle is described clockwise from OX, it is considered negative.
The quadrants denoted by I, II, III and IV are the first, second, third and fourth quadrants, respectively. In Figure 1, the angle shown in red is in the second quadrant. In Figure 2, the angle shown in red is in the third quadrant.

Angles used by the Peg2DPolygon class are defined as follows.
0 degrees is always along line OX.
Angle values increase in the counterclockwise direction.
Therefore, line OY is at 90 degrees, line OX' is at 180 degrees
and line OY' is at 270 degrees.
It is also important to note that the polygon is rotated relative to the center of its bounding rectangle. Hence, you can easily create some very interesting rotational effects.
When rotating the polygon, you must be aware of the distance from the center of the bounding rectangle to each polygon point. If a polygon point lies outside largest concentric circle that will fit within the bounding rectangle, then the line segments joining that point to its neighboring polygon points may be clipped as the polygon is rotated.
Styles |
The Peg2DPolygon class supports
the following style flags:
FF_NONE | No frame. |
FF_THIN | Thin frame. |
FF_THICK | Thick 3D frame. |
FF_RAISED | Raised 3D frame. |
FF_RECESSED | Recessed 3D frame. |
AF_TRANSPARENT |
If this style flag is set, the object will be drawn with a transparent
background in its client area. The object therefore floats over its parent,
assuming its parent's image as its background. This style flag is used
by the PegPrompt and PegVPrompt objects to add
text over other control objects. |
TT_COPY |
Keep separate copy of text with the object. This flag should be used when the string value used to assign text to an object is located in temporary storage such as a local variable on the stack. |
Although the Peg2DPolygon class supports the
AF_TRANSPARENT style, you must take care
when rotating or moving the polygon to ensure that
the relic polygon is properly erased.
After rotating the polygon, you should force the parent
object to redraw itself. Of course, this assumes that you
have not set the PSF_VIEWPORT status on the
Peg2DPolygon object.
The Peg2DPolygon class also supports the
TT_COPY style. When this style flag is used,
the Peg2DPolygon copies the array of
PegPoints into the Peg2DPolygon object.
Therefore, if you have statically allocated your point array
or have dynamically created your list of points, you can avoid
duplicating your array by not using the TT_COPY style.
This style flag is not used unless specified by you.
|
| |
| Top of page |
Members |
Constructors:
|
| |
|
|
Peg2DPolygon(const PegRect &Rect,
|
PegPoint *pPoints, WORD wNumPoints,
| |
WORD wId = 0, WORD wStyle = FF_NONE)
| |
This constructor creates a 2D polygon
in the rectangle specified by parameter Rect.
Parameter iNumPoints specifies the number of
PegPoints listed in the array of points referenced
by pPoints. The last point in the array will be
connected to the first point in the array when the polygon
is drawn.
The frame style and polygon characteristics will be governed
by the style flags provided by parameter wStyle.
Public Functions:
|
| |
|
|
void Draw()
|
The Peg2DPolygon class overrides the
Draw() function to draw the 2D polygon.
|
| |
|
|
SIGNED GetCurAngle() const
|
|
|
void SetCurAngle(SIGNED iTheta)
|
These inline functions get or set the current angle of rotation of the polygon. By default, the angle is set to 0 degrees.
|
| |
|
|
BOOL GetFill() const
|
|
|
void SetFill(BOOL bFill)
|
These inline functions get or set the current fill mode.
By default, the fill mode is set to FALSE.
If parameter bFill is TRUE,
the polygon will be filled with the object's select
color as specified by color flag PCI_STEXT.
If parameter bFill is FALSE,
the polygon interior will not be filled. In most cases,
the interior will be painted in the object's normal
color as specified by color flag PCI_NORMAL.
However, if style flag AF_TRANSPARENT is set,
the polygon interior will be left transparent, allowing the
underlying parent object to show through the polygon.
|
| |
|
|
SIGNED GetLineWidth() const
|
|
|
void SetLineWidth(SIGNED iWidth)
|
These inline functions get or set
the current width of the lines used to draw the polygon outline.
Parameter iWidth specifies the line width in pixels.
By default, the line width is set to one pixel.
|
| |
|
|
WORD GetNumPoints(void) const
|
This inline function returns the number of points in the array of points used to specify the polygon shape.
|
| |
|
|
void ParentShift(
|
WORD iXOffset, WORD iYOffset)
| |
The Peg2DPolygon class overrides the
ParentShift() function to map the polygon
coordinates to the correct screen location when the
polygon is moved. This function is used only by KwikPeg.
|
| |
|
|
void Resize(PegRect Rect)
|
The Peg2DPolygon class overrides the
Resize() function to redraw the polygon
within the bounding rectangle specified by tRect.
Note that the size and location of the bounding rectangle can
change but the polygon points relative to the bounding rectangle
will not change. Hence, the polygon will not change
size, shape or orientation within its bounding rectangle.
|
| |
| Top of page |
Examples |
The following example illustrates a 2D polygon derived from the
Peg2DPolygon class and drawn within a decorated
window.

The Peg2DPolygon object illustrated above was created
by the following code fragment:
// Polygon point data
static PegPoint gtPolyPoints[] =
{ {47, 24}, {12, 12}, {24, 22},
{24, 23}, {31, 19}, {31, 27},
{24, 25}, {12, 35} };
PolygonWindow::PolygonWindow() : PegDecoratedWindow()
{
mReal.Set(0, 0, 300, 160);
InitClient();
SetColor(PCI_NORMAL, LIGHTCYAN);
Add(new PegTitle("Peg2DPolygon Example"));
PegRect tRect;
tRect.Set(mClient.wLeft + 80,
mClient.wTop + 40,
mClient.wLeft + 80 + 47,
mClient.wTop + 40 + 47);
mpPolygon = new Peg2DPolygon(tRect,
>PolyPoints[0],
sizeof(gtPolyPoints)/sizeof(PegPoint),
101, FF_NONE | AF_TRANSPARENT);
mpPolygon->SetColor(PCI_STEXT, LIGHTRED);
mpPolygon->SetColor(PCI_NTEXT, WHITE);
mpPolygon->SetFill(TRUE);
Add(mpPolygon);
}
|
Top of page |
|
|
|
|
| Copyright © 2000-2003 |