![]() ![]() ![]()
|
BREW C++ Class Library & GUI Framework & XML Middleware : SophiaFramework 4.1 |
Table 12.1. Line Class
| Class Name | Shape type | Description |
|---|---|---|
| SFXLine | Line | Class that represents a line that has start point (x1, y1) and end point (x2, y2). |
Example 12.3. Define the line
// line : start point (10, 40), end point (30, 20)
SFXLine line(10, 40, 30, 20);
Example 12.4. Draw the line
// get SFXGraphics instance SFXGraphicsPtr graphics = SFXGraphics::GetInstance(); graphics->DrawLine(line); // draw line
Example 12.5. 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.6. 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.7. 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 }
Table 12.2. Rectangle Class
| Class Name | Shape Type | Description |
|---|---|---|
| SFXRectangle | Rectangle | Class that represents a rectangle that has top-left point (x, y), width, and height. |
Example 12.8. Define the rectangle
// top-left point (10, 40), 60 pixels width and 35 pixels height
SFXRectangle rectangle(10, 40, 60, 35);
Example 12.9. Draw the border line of rectangle
SFXGraphicsPtr graphics = SFXGraphics::GetInstance(); graphics->DrawRectangle(rectangle);
Example 12.10. Paint the rectangle
graphics->FillRectangle(rectangle, SFXRGBColor(0x00, 0x00, 0x00, 0x00));
Reference: Color
Example 12.11. 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.12. Get the boundary
SFXLine leftLine = rectangle.GetEdgeLeft(); SFXLine rightLine = rectangle.GetEdgeRight(); SFXLine topLine = rectangle.GetEdgeTop(); SFXLine bottomLine = rectangle.GetEdgeBottom();
Example 12.13. Draw the bottom line and right line only
graphics->DrawLine(rectangle.GetEdgeBottom()); graphics->DrawLine(rectangle.GetEdgeRight());
Example 12.14. 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.15. 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));
Table 12.3. Grid and Pixel Classes
| Class Nme | Shape Type | Description |
|---|---|---|
| SFXGrid | Point (Grid) | Class that represents the grid coordinates. |
| SFXPixel | Image element (Pixel) | Class that represents the pixel coordinates. |
Comparing to the "Go" game or the Japanese Chess game, the drawing plain is like the playing board, the grid is like the place to put the "Go" stone, and the pixel is like the place to put the piece of the Japanese Chess game.
Example 12.17. Get the coordinate of grid
SInt32 x = grid.GetX(); // x = 10 SInt32 y = grid.GetY(); // y = 20
Example 12.19. Operate the grid
// move point 3 grids right grid.AddX(3); // move point 3 grids left and 3 grids down grid.Add(-3, 3);
Example 12.20. Draw the grid
SFXGraphicsPtr graphics = SFXGraphics::GetInstance(); // draw text (grid is drawing position) // DrawText function does not take SFXPixel instance as argument graphics->DrawText("drawing", grid); // draw image: at (10, 20) top-left // image: SFBImageSmp type image->Draw(SFXGrid(10, 20));
Example 12.22. Draw the pixel
SFXGraphicsPtr graphics = SFXGraphics::GetInstance();
// DrawPixel function does not take SFXGrid instance as argument
graphics->DrawPixel(pixel);
Get the coordinate of pixel
SInt32 x = pixel.GetX(); // x = 10 SInt32 y = pixel.GetY(); // y = 20
Example 12.24. Operate the pixel
SFXPixel pixel(10, 20);
SFXGraphicsPtr graphics = SFXGraphics::GetInstance();
SInt32 i;
for (i = 0; i < 50; ++i) {
// draw pixel
graphics->DrawPixel(pixel, SFXRGBColor(0x00, 0x00, 0x00, 0x00));
// move point 3 pixels right
pixel.AddX(3);
}
for (i = 0; i < 50; ++i) {
// draw point
graphics->DrawPixel(pixel, SFXRGBColor(0x00, 0x00, 0x00, 0x00));
// move point 3 pixels left and 3 pixels down
pixel.Offset(-3, 3);
}
Table 12.4. Size and Margin Classes
| Class Name | Shape Type | Description |
|---|---|---|
| SFXSize | Size | Class that represents size(height and width). |
| SFXMargin | Margin | Class that represents the top, bottom, left and right margins of rectangle. |
Example 12.25. Size
// Responder SFRResponderPtr responder; // size of 10 pixels width and 20 pixels height SFXSize size(10, 20); // scroll virtual region of responder 10 pixels right and 20 pixels down responder->Scroll(size);
Example 12.26. Width and height of rectangle (SFXRectangle)
// Rectangle SFXRectangle rectangle(10, 20, 30, 40); // size of 50 pixels width and 60 pixels height SFXSize size(50, 60); // set size of rectangle to 50 pixels width and 60 pixels height rectangle.SetSize(size); // extend size of rectangle by 15 pixels width and 25 pixels height rectangle.AddSize(SFXSize(15, 25));
Example 12.27. Margin
SFRTitleWindowPtr window1; SFXMargin margin; // get frame region of window 1 as margin margin = window1->GetFrameMargin(); SInt32 top = margin.GetTop(); // top size of frame region SInt32 bottom = margin.GetBottom(); // bottom size of frame region SInt32 left = margin.GetLeft(); // left size of frame region SInt32 right = margin.GetRight(); // right size of frame region
Related Information: Drawing Region
Table 12.5. Classes of Triangle, Circle, Pie, etc.
| Class Name | Shape Type | Description |
|---|---|---|
| SFXTriangle | Triangle | Class that represents a triangle with 3 vertices (x1, y1), (x2, y2), (x3, y3). |
| SFXCircle | Circle | Class that represents a circle with center (x, y) and radius. |
| SFXPie | Pie | Class that represents a pie with center (x, y), radius, beginning angle, extent angle. |
| SFXArc | Arc | Class that represents an arc with center (x, y), radius, beginning angle, extent angle. |
| SFXEllipse | Ellipse | Class that represents an ellipse with center (x, y), horizontal radius, vertical radius. |
Example 12.28. 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);
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 that represents a polygon |
| SFXPolyline | Polyline | Class that represents a polyline |
![]() |
Array of pixels |
|---|---|
Note that the array of pixels for the vertices should not be destroyed. | |
Example 12.29. 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);
In SFXRectangle class, there are functions for comparison, evaluation, and operation.
Example 12.30. Graphic operation
SFXRectangle rectangle1(10, 20, 30, 40); SFXRectangle rectangle2(20, 10, 30, 40); SFXRectangle rectangle3; // compare if (rectangle1 == rectangle2) { // when rectangle1 equals rectangle2 } // whether rectangle is valid or not if (rectangle1.IsEmpty()) { // when width or height is less than or equal to 0 } // inclusion relation of rectangles if (rectangle1.IsInsideOf(rectangle2)) { // when rectangle1 is included in rectangle2 } // get intersectional part of two rectangles rectangle3 = rectangle1.Intersection(rectangle2); // check whether two rectangles intersect each other or not if (rectangle1.IntersectsWith(rectangle2)) { // when intersectional part of two rectangles exists } // get rectangle including two given rectangles rectangle3 = rectangle1.Union(rectangle2); // check whether rectangle that includes two given rectangles exists or not if (rectangle1.UnifiesWith(rectangle2)) { // when exist such rectangle } // when width or height is negative, make it positive value rectangle1.Normalize();
Example 12.31. Combine the operations
// draw rectangle from origin one by adding 50 to height and moving down by 30 // original rectangle is also changed graphics->DrawRectangle(rectangle.AddHeight(50).AddY(30)); // draw line bottom edge of rectangle of which start point is moved 20 pixels right and end point is moved 40 pixels down // (rectangle is not changed) graphics->DrawLine(rectangle.GetEdgeBottom().AddStartX(20).AddEndY(40)); // get rectangle of screen size by SFXGraphics::GetDeviceRectangle() // shrink it by 40 pixels left and right, 20 pixels up and down // move it 10 pixels down // and then draw it graphics->DrawRectangle(SFXGraphics::GetDeviceRectangle().Deflate(40, 20).AddY(10)); // extend rectangle of top-left (30, 20), 40 pixels width, and 10 pixels height // by 5 pixels left and right, 10 pixels up and down // and then draw it graphics->DrawRectangle(SFXRectangle(30, 20, 40, 10).Inflate(5, 10));
When creating the constant Shape instance, the overhead that the constructor is called occurs.
Example 12.32. Const Shapes
SFXRectangleConst rectangle(10, 20, 30, 40); // since rectangle is constant, constructor is called SFXLineConst line(50, 60, 70, 80); // line is also constant, constructor is called graphics->DrawRectangle(rectangle); graphics->DrawLine(line);
If the AtomRec structure is used when creating constant objects, the constructor will not be called and there will be no overhead
Example 12.33. Draw the shapes of Const type using the AtomRec structure
// rectangle is constant (and constructor is not called) static SFXRectangle::AtomRecConst rectangle = { 10, 20, 30, 40 }; // line is also constant (constructor is not called) static SFXLine::AtomRecConst line = { 50, 60, 70, 80 }; graphics->DrawRectangle(rectangle); graphics->DrawLine(line);
Clipping is the function that the outside area of specified shape such as rectangle, circle, triangle, or polygon may not be drawn.
SFXClip is the Shape class for clipping.
In the figure below, the string is clipped by rectangle.
Example 12.34. Clip the string with rectangular
// black color SFXRGBColor black(0x00, 0x00, 0x00, 0x00); // rectangle SFXRectangle rectangle(10, 10, 150, 55); // draw border graphics->DrawRectangle(rectangle, black); // clip rectangle SFXClip clip(rectangle); // set clipping graphics->SetClip(rectangle); // get top-left of rectangle SFXGrid grid = rectangle.GetLeftTop(); // get font-height SInt32 fontHeight = graphics->GetFontHeight(); // draw string graphics->DrawText("test clipping", grid, black); // draw string (move drawing position down by fontHeight using grid.AddY(fontHeight)) graphics->DrawText("test clipping", grid.AddY(fontHeight), black); graphics->DrawText("test clipping", grid.AddY(fontHeight), black);
To do clipping by other than SFXRectangle, use the SFBGraphics instance instead of SFXGraphics.
Example 12.35. Clip the circle with other than rectangle
// get SFBGraphics interface SFBGraphicsSmp g = graphics->GetSFBGraphics(); // circle SFXCircle circle(100, 50, 40); // clip circle SFXClip clip(circle); // set clipping g->SetClip(&clip, AEE_GRAPHICS_FRAME); // set fill color g->SetFillColor(SFXRGBColor(0x99, 0x99, 0x99, 0x00)); // draw rectangle g->DrawRect(&SFXRectangle(55, 5, 60, 80));
The rectangle is clipped with the specified circle.
|
Copyright (C) 2002 - 2009 Sophia Cradle, Inc. All Rights Reserved. |
![]() ![]() ![]()
|