PrevNextUpHome SophiaFramework UNIVERSE 5.3

12.4. Kinds of the Shapes

Figure 12.5. Kinds of the Shapes

Kinds of the Shapes

12.4.1. Line

Table 12.3. Line Class

Class Name Shape type Description
SFXLine Line Class which represents a line that has start point (x1, y1) and end point (x2, y2).

Example 12.14. Define the line

// line : start point (10, 40), end point (30, 20)
SFXLine line(10, 40, 30, 20);

Example 12.15. Draw the line

// get SFXGraphics instance
SFXGraphicsPtr graphics = SFXGraphics::GetInstance();
graphics->DrawLine(line);         // draw line

Example 12.16. Get the coordinates of line

SInt32 startX = line.GetStartX(); // startX = 10
SInt32 startY = line.GetStartY(); // startY = 40
SInt32 endX = line.GetEndX();     // endX = 30
SInt32 endY = line.GetEndY();     // endY = 20

Example 12.17. Set the line

// set start point (10, 20)
line.SetStart(10, 20);

// set X-value and Y-value of start point separately
line.SetStartX(10);
line.SetStartY(20);

// set end point (80, 20)
line.SetEnd(80, 20);

//  set X-value and Y-value of end point separately
line.SetEndX(80);
line.SetEndY(20);

Example 12.18. Operate the line

// set start point (10, 20) and end point (80, 20)
line.Set(10, 20, 80, 20);

graphics->DrawLine(line);     // draw line

// move line 0 pixel right and 10 pixels down
line.Offset(0, 10);

graphics->DrawLine(line);     // draw line

// move line 10 pixels right and 2 pixels down
line.Offset(10, 2);

// move end point 20 pixels left ( the - operator is also available for moving left )
line.SubEndX(20);

graphics->DrawLine(line);     // draw line

SIntN i;
for (i = 0; i < 5; ++i) {
    // move line 0 pixel left and 10 pixels down
    line.Offset(0, 10);
    graphics->DrawLine(line); // draw line
}

12.4.2. Rectangle

Table 12.4. Rectangle Class

Class Name Shape Type Description
SFXRectangle Rectangle Class which represents a rectangle that has top-left point (x, y), width, and height.

Example 12.19. Define the rectangle

// top-left point (10, 40), 60 pixels width and 35 pixels height
SFXRectangle rectangle(10, 40, 60, 35);

Example 12.20. Draw the border line of rectangle

SFXGraphicsPtr graphics = SFXGraphics::GetInstance();
graphics->DrawRectangle(rectangle);

Example 12.21. Paint the rectangle

graphics->FillRectangle(rectangle, SFXRGBColor(0x00, 0x00, 0x00, 0x00));

Reference: Color

Example 12.22. Get the values of rectangle

SInt32 left = rectangle.GetLeft();     // left   = 10
SInt32 right = rectangle.GetRight();   // right  = 70
SInt32 top = rectangle.GetTop();       // top    = 40
SInt32 bottom = rectangle.GetBottom(); // bottom = 75
SInt32 width = rectangle.GetWidth();   // width  = 60
SInt32 height = rectangle.GetHeight(); // height = 35

Example 12.23. Get the boundary

SFXLine leftLine = rectangle.GetEdgeLeft();
SFXLine rightLine = rectangle.GetEdgeRight();
SFXLine topLine = rectangle.GetEdgeTop();
SFXLine bottomLine = rectangle.GetEdgeBottom();

Example 12.24. Draw the bottom line and right line only

graphics->DrawLine(rectangle.GetEdgeBottom());
graphics->DrawLine(rectangle.GetEdgeRight());

Example 12.25. Set the coordinates of rectangle

rectangle.Set(15, 20, 40, 35);
rectangle.SetLeft(30);
rectangle.SetRight(25);
rectangle.SetTop(45);
rectangle.SetBottom(60);
rectangle.SetWidth(25);
rectangle.SetHeight(35);

Example 12.26. Operate the rectangle

// get entire rectangular area of screen
SFXRectangle rectangle = SFXGraphics::GetDeviceRectangle();

// shrink rectangle by 5 pixels width and 10 pixels height
rectangle.Deflate(5, 10);

graphics->DrawRectangle(rectangle);

SInt32 delta = 30;

// extend rectangle by 30 pixels height
rectangle.AddTop(delta);

graphics->FillRectangle(rectangle, SFXRGBColor(0x00, 0x00, 0x00, 0x00));

12.4.3. Triangle, Circle, Pie, etc.

Table 12.5. Classes of Triangle, Circle, Pie, etc.

Class Name Shape Type Description
SFXTriangle Triangle Class which represents a triangle with 3 vertices (x1, y1), (x2, y2), (x3, y3).
SFXCircle Circle Class which represents a circle with center (x, y) and radius.
SFXPie Pie Class which represents a pie with center (x, y), radius, beginning angle, extent angle.
SFXArc Arc Class which represents an arc with center (x, y), radius, beginning angle, extent angle.
SFXEllipse Ellipse Class which represents an ellipse with center (x, y), horizontal radius, vertical radius.

Figure 12.6. Triangle, Circle, Pie, etc.

Triangle, Circle, Pie, etc.

Example 12.27. Draw the triangle, circle, pie, etc.

// Triangle
// from left x1, y1, x2, y2, x3, y3
SFXTriangle triangle(10, 40, 105, 25, 80, 95);
// draw triangle
graphics->DrawTriangle(triangle);

// Circle
// from left: center's X, Y coordinates, radius
SFXCircle circle(170, 60, 40);
// draw circle
graphics->DrawCircle(circle);

// Pie
// from left: center's X, Y coordinates, radius, beginning angle, extent angle
SFXPie pie(80, 160, 60, 120, 60);
// draw pie
graphics->DrawPie(pie);

// Arc
// from left: center's X, Y coordinates, radius, beginning angle, extent angle
SFXArc arc(190, 160, 60, 120, 60);
// draw arc
graphics->DrawArc(arc);

// Ellipse
// from left: center's X, Y coordinates, horizontal radius, vertical radius
SFXEllipse ellipse(110, 200, 100, 20);
// draw ellipse
graphics->DrawEllipse(ellipse);

12.4.4. Polygon and Polyline

In SFXPolygon, SFXPolyline classes, the array of coordinates of vertices are established before being set to the instance.

Table 12.6. Polygon and Polyline Class

Class Name Shape Type Description
SFXPolygon Polygon Class which represents a polygon.
SFXPolyline Polyline Class which represents a polyline.

Figure 12.7. Polygon

Polygon

Figure 12.8. Polyline

Polyline
[Caution] Array of pixels

Note that the array of pixels for the vertices should not be destroyed.

Example 12.28. Draw the polygon and poligon

// vertices of polygon
SFXPixel pixel[5];
pixel[0].Set(30, 80);
pixel[1].Set(35, 50);
pixel[2].Set(130, 30);
pixel[3].Set(180, 40);
pixel[4].Set(190, 90);

// define polygon (set array of vertices and its size)
SFXPolygon polygon(&pixel[0], lengthof(pixel));

// draw poligon
graphics->DrawPolygon(polygon);

// vertices of polyline
SFXPixel pixel[5];
pixel[0].Set(30, 80);
pixel[1].Set(35, 50);
pixel[2].Set(130, 30);
pixel[3].Set(180, 40);
pixel[4].Set(190, 90);

// define polygon (set array of vertices and its size)
SFXPolyline polyline(&pixel[0], lengthof(pixel));

// draw polyline
graphics->DrawPolyline(polyline);