Simple Game Graphics Library 1.1
|
Functions | |
void | drawRect (float center_x, float center_y, float width, float height, const Brush &brush) |
void | drawBezier (float *ep1, float *cp1, float *cp2, float *ep2, const Brush &brush) |
void | drawLine (float x1, float y1, float x2, float y2, const Brush &brush) |
void | drawDisk (float cx, float cy, float radius, const Brush &brush) |
void | drawSector (float cx, float cy, float radius1, float radius2, float start_angle, float end_angle, const Brush &brush) |
bool | setFont (std::string fontname) |
void | drawText (float pos_x, float pos_y, float size, const std::string &text, const Brush &brush) |
void | setOrientation (float angle) |
void | setScale (float sx, float sy) |
void | resetPose () |
void drawBezier | ( | float * | ep1, |
float * | cp1, | ||
float * | cp2, | ||
float * | ep2, | ||
const Brush & | brush ) |
Draws a bezier segment.
Draws a 3rd order bezier segment between two end-points on the canvas, using two intermediate control points to distort the curve. The outline attributes are specified in the brush parameter.
ep1 | is an array containing the x and y coordinates of the first end point, in canvas units. |
cp1 | is an array containing the x and y coordinates of the first control point, in canvas units. |
cp2 | is an array containing the x and y coordinates of the second control point, in canvas units. |
ep2 | is an array containing the x and y coordinates of the second end point, in canvas units. |
brush | specifies the drawing attributes to use for the outline and fill of the shape. |
void drawDisk | ( | float | cx, |
float | cy, | ||
float | radius, | ||
const Brush & | brush ) |
Draws a disk.
Draws a disk (or circle, if fill opacity is set to 0) of certain radius and centered at (cx, cy). The outline and fill attributes are specified in the brush parameter.
cx | is the x coordinate of the center of the disk in canvas units. |
cy | is the y coordinate of the center of the disk in canvas units. |
radius | is the radius of the disk in canvas units. |
brush | specifies the drawing attributes to use for the outline and fill of the shape. |
void drawLine | ( | float | x1, |
float | y1, | ||
float | x2, | ||
float | y2, | ||
const Brush & | brush ) |
Draws a line segment.
Draws a linear segment between two points on the canvas. The outline attributes are specified in the brush parameter.
x1 | is the x coordinate of the first point in canvas units. |
y1 | is the y coordinate of the first point in canvas units. |
x2 | is the x coordinate of the second point in canvas units. |
y2 | is the y coordinate of the second point in canvas units. |
brush | specifies the drawing attributes to use for the outline and fill of the shape. |
void drawRect | ( | float | center_x, |
float | center_y, | ||
float | width, | ||
float | height, | ||
const Brush & | brush ) |
Draws a rectangle.
Draws a rectangle of size width X height, centered at (center_x, center_y). The shape outline and fill attributes are provided in the brush parameter.
center_x | is the x coordinate of the rectangle center in canvas units. |
center_y | is the y coordinate of the rectangle center in canvas units. |
width | is the horizontal size of the rectangle center in canvas units. |
height | is the vertical size of the rectangle center in canvas units. |
brush | specifies the drawing attributes to use for the outline and fill of the shape. |
void drawSector | ( | float | cx, |
float | cy, | ||
float | radius1, | ||
float | radius2, | ||
float | start_angle, | ||
float | end_angle, | ||
const Brush & | brush ) |
Draws a sector of a disk.
Draws a sector of a disk between an inner and outer radius and two angles. The outline and fill attributes are specified in the brush parameter.
cx | is the x coordinate of the center of the disk sector in canvas units. |
cy | is the y coordinate of the center of the disk sector in canvas units. |
radius1 | is the inner radius of the disk sector in canvas units. |
radius2 | is the outer radius of the disk sector in canvas units. |
void drawText | ( | float | pos_x, |
float | pos_y, | ||
float | size, | ||
const std::string & | text, | ||
const Brush & | brush ) |
Draws a string of text at a user-provided location on the canvas, using the current font.
The function displays the glyphs for the text provided, in a left-aligned manner. The coordinates passed to the function correspond to the lower left corner of the text box and the height of the glyphs is indicated by the size parameter. If there is no active font (or the setFont function failed), no text is drawn.
pos_x | is the horizontal coordinate of the lower left corner of the text in canvas units. |
pos_y | is the vertical coordinate of the lower left corner of the text in canvas units. |
size | is the glyph height of the text to be drawn. |
text | is the string of text to display. |
brush | contains the drawing attributes. Only the fill parameters of the provided brush are used for drawing, including any gradient. |
void resetPose | ( | ) |
Restores both the orientation and scaling to their default values for subsequent draw calls.
bool setFont | ( | std::string | fontname | ) |
Sets the current font for text rendering.
Notifies the SGG engine to prepare and make current the font typeface in the filename supplied as argument. If the font is not already loaded into SGG, it loads the SGG and builds all necessary information for it. If the font name supplied does not correspond to a valid path to a TrueType typeface, the operation is silently aborted and no font is loaded or made active for text rendering. After loading the font, it is made current and all subsequent text drawing calls use this font for text rendering. If the font is already loaded into SGG, it is just made active for rendering. This operation does not incur any measurable overhead, as all resource allocation and convesion processes occur once, during the first call to load a specific font.
fontname | is a valid path to the filename of the TrueType font (.ttf extension) to use. |
void setOrientation | ( | float | angle | ) |
Sets the current orientation that all subsequent draw calls will use for the displayed shapes.
SGG maintains a current orientation (default value 0.0f - no rotation) according to which it displays the shape of draw calls. Once set, the orientation is respected by all subsequent draw calls, until set to a new value or reset via a call to resetPose(). The rotation of the drawn shape in accordance with the orientation value occurs using a pivot point specific to the drawn shape. For rectangles, disks and sections, the pivot point is their center. For text, it is the lower left corner of the text bounds. Line segments are not rotated, since it is simpler to redefine their end-points.
angle | is the angle of rotation for the shapes to draw in degrees. Positive angles correspond to counter-clockwise rotations. |
void setScale | ( | float | sx, |
float | sy ) |
Sets the current scale that all subsequent draw calls will use for the displayed shapes.
SGG maintains a current scale (default value 1.0f - no scaling) according to which it displays the shape of draw calls. Once set, the scale is respected by all subsequent draw calls, until set to a new value or reset via a call to resetPose().
The scaling is defined by two scaling factors, one for each dimension of the shape. Setting an equal value for both parameters corresponds to a uniform scale (no distortion). Scaling factors greater than 1 mean shape magnification, while values less than 1 result in shrinking. Never set the scaling factor to 0.
The change of scale of the drawn shape along its X and Y dimension is performed prior to the rotation, using a pivot point specific to the drawn shape. For rectangles, disks and sections, the pivot point is their center. For text, it is the lower left corner of the text bounds. Line segments are not scaled, since it is simpler to redefine their end-points.
sx | is the scale factor along the local X axis of the shape. 1 means no scaling. |
sy | is the scale factor along the local Y axis of the shape. 1 means no scaling. |