PrevNextUpHome SophiaFramework UNIVERSE 5.3

12.7. Clipping

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.

12.7.1. Clipping with Rectangular

In the figure below, the string is clipped by rectangle.

Figure 12.9. Clipping the String

Clipping the String

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

12.7.2. Clipping with other than Rectangle

To do clipping by other than SFXRectangle, use the SFBGraphics instance instead of SFXGraphics.

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

Figure 12.10. Execution Result

Execution Result

The rectangle is clipped with the specified circle.