SetClippingRectangle
From Spheriki
Sets a clipping rectangle that only allows drawing inside the given bounds.
Contents |
[edit]
Usage
SetClippingRectangle(x, y, width, height);
- x Number. The x-coordinate (left-right) to set the clipping rectangle at.
- y Number. The y-coordinate (up-down) of the clipping rectangle to set.
- width Number, non-negative. Width of the clipping rectangle.
- height Number, non-negative. Height of the clipping rectangle.
[edit]
Examples
const SILLY_STRING = "lots of text can fit in here because I feel like typing "; const REPEAT = 100; var font = GetSystemFont(); var big_string = ""; // Generate a long string for (var i = 0; i < REPEAT; ++i) big_string += SILLY_STRING; // Set the clipping rectangle SetClippingRectangle( GetScreenWidth() * 0.25, GetScreenHeight() * 0.25, GetScreenWidth() * 0.5, GetScreenHeight() * 0.5 ); // Write out the string, wordwrapped font.drawTextBox(0, 0, GetScreenWidth(), GetScreenHeight(), 0, big_string); FlipScreen(); // Wait for a key press GetKey();
The above example demonstrates the basic principle behind the clipping rectangle. A large string is prepared, and then the clipping region is set to a centred rectangle in the screen. The text is drawn to the entire screen, but is clipped by the existing rectangle, which is why only part of the screen is covered by the text.
[edit]
Notes
- All drawing functions, both for graphical primitives and image/surface blitting, are bound by the dimensions of the clipping rectangle.
- To restore drawing to the entire screen again, you can use
SetClippingRectangle(0, 0, GetScreenWidth(), GetScreenHeight());.
- A previously-set clipping rectangle can be retrieved later using GetClippingRectangle(), which returns a Rectangle object.
[edit]
See also
- GetClippingRectangle()
- Rectangle object

