Home 
Class Peg2DPolygon HMI (HumanMachine Interface) Classes 
Class Peg2DPolygonPeg2DPolygon is an advanced drawing class which extends and encapsulates the functionality implemented in the PegScreen's Polygon method into a true sprite oriented 2 dimensional polygon. To draw a polygon, one would usually allocate any number of PegPoint structures, assign values to the x and y members, create a PegColor structure and assign its color properties accordingly. One would then call the PegScreen::Polygon method and pass it over the list of PegPoints and the PegColor structure. This would effectively draw the given polygon at the coordinates designated in the PegPoint array. Peg2DPolygon takes care of this work for you, and provides easy ways to move the polygon as well as rotate the polygon within its bounding rectangle. Peg2DPolygon simplifies the process of drawing 2D wireframes and filled polygons. Instead of having to normal the desired polygon coordinates to screen coordinates, one can describe a polygon it relation to origin 0 x and 0 y being in the topleft corner of the bounding rectangle of the polygon. Once these coordinates are given to the Peg2DPolygon object, the object will translate these coordinates from their 0,0 base to the left and top of its bounding rectangle as it is located on the screen. And, throughout the lifetime of the object, it updates this translation every time it is moved or resized. Another feature is the ability to rotate the polygon to any given angle without have to translate the points explicitly. The following is a discussion of how the current angle value is used in determining the translation of the points of the polygon. It is important to understand how the angle value works in the Peg2DPolygon object. Consider an x,y coordinate system (Figures 1 and 2, below). A point P in the x,y plane has coordinates (x,y) where x is considered positive along X and negative along X' while y is positive along Y and negative along Y'. The angle A described counterclockwise from X is considered positive. If it is described clockwise from X it is considered negative. The various quadrants are denoted by I,II,III and IV called the first, second, third and fourth quadrants, respectively. In Figure 1, for example, angle A is in the second quadrant while in Figure 2, angle A is in the third quadrant. When working with angles with the Peg2DPolygon class, 0 degrees is always on line X with greater angle values going counterclockwise. Therefore, line Y is at 90 degrees, line X' is at 180 degrees and line Y' is at 270 degrees. It is also important to note that the polygon is rotated relative to its bounding rectangle. In other words, if you were to have a polygon that was bounded by a rectangle that was 48 pixels high and 48 pixels wide, the center of rotation for the polygon would be at relative 23 x and 23 y (24 pixels from the top left corner of the bounding rectangle). This can provide some very interesting rotational effects. The one aspect that you do have to be careful with in rotating the polygon is the distance the point is from the center of the bouding rectangle. If a point lies outside of the radius of the largest concentric circle that would fit within the perimeter of the bounding rectangle, then the point may become clipped as the polygon is rotated. class Peg2DPolygon : public PegThing { public: Peg2DPolygon(const PegRect & tRect, PegPoint * pPoints, PEGUINT wNumPoints, PEGUINT wId = 0, PEGUINT wStyle = FF_NONE); // Overrides void Draw(void); void ParentShift(PEGINT iXOffset, PEGINT iYOffset); void Resize(PegRect tRect); // Accessors PEGUINT GetNumPoints(void) const; BOOL GetFill(void) const; PEGINT GetCurAngle(void) const; PEGINT GetLineWidth(void) const; // Mutators void SetFill(BOOL bFill); void SetCurAngle(PEGINT iTheta); void SetLineWidth(PEGINT iLineWidth); } Style FlagsFF_NONE, FF_THIN, FF_THICK, FF_RAISED, FF_RECESSED ConstructorThe constructor takes a reference to a PegRect that describes the bounding rectangle for the polygon, a pointer to a PegPoint structure, the number of points that describe the polygon, a PEGUINT for the Id of the object and a PEGUINT for the style flags. Method DrawPeg2DPolygon overrides the PegThing::Draw method in order to correctly draw the polygon. Method ParentShiftPeg2DPolygon overrides the PegThing::ParentShift method in order to correctly map the polygon coordinates to the new location on the screen. This member is called internally by the library and should not be called from a user application. Method ResizePeg2DPolygon overrides the PegThing::Resize method in order to correctly shift the polygon to the new location described by the new bounding rectangle. Method GetFillThis method retrieves the fill flag used to determine if the polygon should fill its interior or only draw its outline. Method SetFillThis method sets the fill flag used to determine if the polygon should fill its interior or only draw its outline. Method GetCurAngleThis method retrieves the current angle used to rotate the polygon. Method SetAngleThis method sets the current angle used to rotate the polygon. Method GetLineWidthRetrieves the line width used when drawing the polygon. Method SetLineWidthSets the line width used when drawing the polygon. Method GetNumPoints>Returns the number of points in the polygon. Example:The following is a code snippet that creates the Peg2DPolygon displayed in Figure 1. You'll notice that since we globally allocated the PegPoints that described the polygon, we don't set the TT_COPY flag in the constructor to the Peg2DPolygon object. // Global 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, 400, 300); InitClient(); SetColor(PCI_NORMAL, BLUE); Add(new PegTitle("Peg2DPolygon Example")); PegRect tRect; tRect.Set(mClient.wLeft + 10, mClient.wTop + 10, mClient.wLeft + 57, mClient.wTop + 57); mpPolygon = new Peg2DPolygon(tRect, >PolyPoints[0], 8, 101, FF_NONE); mpPolygon>SetColor(PCI_NORMAL, BLUE); mpPolygon>SetColor(PCI_NTEXT, WHITE); Add(mpPolygon); }
