PrevNextUpHome SophiaFramework UNIVERSE 5.3

12.2. Grid and Pixel

Table 12.1. Grid and Pixel Classes

Class Nme Shape Type Description
SFXGrid Point (Grid) Class which represents the grid coordinates.
SFXPixel Image element (Pixel) Class which represents a pixel coordinate.

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.

Figure 12.3. Grid and Pixel

Grid and Pixel

12.2.1. Grid

Example 12.3. Define the grid

// grid at (10, 20)
SFXGrid grid(10, 20);

Example 12.4. Get the coordinate of grid

SInt32 x = grid.GetX();     // x = 10
SInt32 y = grid.GetY();     // y = 20

Example 12.5. Set the grid

grid.Set(15, 25);
grid.SetX(15);
grid.SetY(25);

Example 12.6. 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.7. 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));

12.2.2. Pixel

Example 12.8. Define the pixel

// pixel at (10, 20)
SFXPixel pixel(10, 20);

Example 12.9. 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.10. Set the pixel

pixel.Set(15, 25);
pixel.SetX(15);
pixel.SetY(25);

Example 12.11. 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);
}

Figure 12.4. Execution Result

Execution Result