WidgetCanvas Class
This class creates a canvas on which lines, polygons and a text can be drawn.
WidgetCanvas Class
This class inherits from WidgetMembers
WidgetCanvas (Gui gui)
Constructor. Creates a new canvas widget.Arguments
- Gui gui - GUI, to which the canvas will belong.
int addLinePoint (int line, vec3 point)
Adds a new segment to the line in the canvas widget.Arguments
- int line - Canvas element ID of the line.
- vec3 point - Segment point coordinates.
Return value
Index number of the added line segment point.int addLine (int order = 0)
Adds a new line to the canvas widget. By default, it is rendered in white color.Arguments
- int order = 0 - Rendering order (the higher the value, the later the line will be rendered atop other elements).
Return value
Canvas element ID for the added line.int addPolygonPoint (int polygon, vec3 point)
Adds a new vertex to the polygon in the canvas widget.Arguments
- int polygon - Canvas element ID of the polygon.
- vec3 point - Polygon vertex coordinates.
Return value
Index number of the added polygon vertex.int addPolygon (int order = 0)
Adds a new polygon to the canvas widget. By default, it is rendered in white color. The blending mode for:- The source screen buffer color is GUI_BLEND_SRC_ALPHA.
- The destination polygon color is GUI_BLEND_ONE_MINUS_SRC_ALPHA.
Arguments
- int order = 0 - Rendering order (the higher the value, the later the polygon will be rendered atop other elements).
Return value
Canvas element ID for the added polygon.int addText (int order = 0)
Adds a new text string to the canvas widget. By default, it is rendered in white color. If a font size is not set for the canvas widget, a default one is used. No shadow is cast from a text. Text width and height on the canvas widget are equal to 0.Arguments
- int order = 0 - Rendering order (the higher the value, the later the text will be rendered atop other elements).
Return value
Canvas element ID of the added text string.void clearLinePoints (int line)
Deletes all points that make up a given line.Arguments
- int line - Canvas element ID of the line.
void clearPolygonPoints (int polygon)
Deletes all points that make up a given polygon.Arguments
- int polygon - Canvas element ID of the polygon.
void clear ()
Clears the canvas widget: deletes all drawn lines, polygons and text.vec4 getColor ()
Returns the background color for the widget.Return value
Background color.Image getImage ()
Returns the current texture image set for the canvas widget.Return value
Texture image.vec4 getLineColor (int line)
Returns the current color of the specified line.Arguments
- int line - Canvas element ID of the line.
Return value
Line color.int getLineIntersection (int x, int y, float distance)
Checks whether the specified point (e.g. the mouse cursor) intersects with lines drawn in the canvas widget.Arguments
- int x - X coordinate of the point.
- int y - Y coordinate of the point.
- float distance - Point radius acceptable for detecting intersection.
Return value
Index number of intersected lines array; otherwise, -1 is returned if no intersections are found.int getLineOrder (int line)
Returns the rendering order of the given line (the higher the value, the later the line is rendered atop other elements).Arguments
- int line - Canvas element ID of the line.
Return value
Rendering order.vec3 getLinePoint (int line, int point)
Returns the coordinates of the specified line segment point.Arguments
- int line - Canvas element ID of the line.
- int point - Index number of the line segment point.
Return value
Segment point coordinates.mat4 getLineTransform (int line)
Returns the current transformation matrix of the specified line.Arguments
- int line - Canvas element ID of the line.
Return value
Transformation matrix.int getLine (int num)
Returns the canvas element ID of the line by its index.Arguments
- int num - Line index number.
Return value
Canvas element ID of the line.int getNumLinePoints (int line)
Returns the number of the points that create line segments.Arguments
- int line - Canvas element ID of the line.
Return value
The number of line segment points.int getNumLines ()
Returns the number of lines drawn in the canvas widget.Return value
The number of lines.int getNumPolygonPoints (int polygon)
Returns the number of vertices for the specified polygon.Arguments
- int polygon - Canvas element ID of the polygon.
Return value
The number of polygon vertices.int getNumPolygons ()
Returns the number of polygons drawn in the canvas widget.Return value
The number of polygons.int getNumTexts ()
Returns the number of text strings drawn in the canvas widget.Return value
The number of text strings.int getPolygonBlendDestFunc (int polygon)
Returns the blending mode of the destination color for the specified polygon.Arguments
- int polygon - Canvas element ID of the polygon.
Return value
Blending mode (one of the GUI_BLEND_* variables):- GUI_BLEND_NONE = 0
- GUI_BLEND_ZERO
- GUI_BLEND_ONE
- GUI_BLEND_SRC_COLOR
- GUI_BLEND_ONE_MINUS_SRC_COLOR
- GUI_BLEND_SRC_ALPHA
- GUI_BLEND_ONE_MINUS_SRC_ALPHA
- GUI_BLEND_DEST_COLOR
- GUI_BLEND_ONE_MINUS_DEST_COLOR
- GUI_BLEND_DEST_ALPHA
- GUI_BLEND_ONE_MINUS_DEST_ALPHA
int getPolygonBlendSrcFunc (int polygon)
Returns the blending mode of the source screen buffer color for the specified polygon.Arguments
- int polygon - Canvas element ID of the polygon.
Return value
Blending mode (one of the GUI_BLEND_* variables):- GUI_BLEND_NONE = 0
- GUI_BLEND_ZERO
- GUI_BLEND_ONE
- GUI_BLEND_SRC_COLOR
- GUI_BLEND_ONE_MINUS_SRC_COLOR
- GUI_BLEND_SRC_ALPHA
- GUI_BLEND_ONE_MINUS_SRC_ALPHA
- GUI_BLEND_DEST_COLOR
- GUI_BLEND_ONE_MINUS_DEST_COLOR
- GUI_BLEND_DEST_ALPHA
- GUI_BLEND_ONE_MINUS_DEST_ALPHA
vec4 getPolygonColor (int polygon)
Returns the current color of the specified polygon.Arguments
- int polygon - Canvas element ID of the polygon.
Return value
Polygon color.Image getPolygonImage (int polygon)
Returns the current image set for a given polygon.Arguments
- int polygon - Canvas element ID of the polygon.
Return value
Current image.int getPolygonIntersection (int x, int y)
Checks whether the specified point (e.g. the mouse cursor) intersects with widget polygons.Arguments
- int x - X coordinate of the point.
- int y - Y coordinate of the point.
Return value
ID of intersected polygons array; if no intersections are found, -1 is returned.int getPolygonOrder (int polygon)
Returns the rendering order of the given polygon (the higher the value, the later the polygon is rendered atop other elements).Arguments
- int polygon - Canvas element ID of the polygon.
Return value
Rendering order.vec3 getPolygonPoint (int polygon, int point)
Returns the coordinates of the specified polygon vertex.Arguments
- int polygon - Canvas element ID of the polygon.
- int point - Index number of the polygon vertex.
Return value
Polygon vertex coordinates.vec2 getPolygonTexCoord (int polygon, int point)
Returns the texture coordinates of the specified point of the polygon.Arguments
- int polygon - Canvas element ID of the polygon.
- int point - Index of the polygon point.
Return value
Texture coordinates of the point.string getPolygonTexture (int polygon)
Returns the current texture set for a given polygon.Arguments
- int polygon - Canvas element ID of the polygon.
Return value
Path to the texture.mat4 getPolygonTransform (int polygon)
Returns the current transformation matrix of the specified polygon.Arguments
- int polygon - Canvas element ID of the polygon.
Return value
Transformation matrix.int getPolygonWrapRepeat (int polygon)
Returns a value indicating if texture tiling is enabled for the given polygon.Arguments
- int polygon - Canvas element ID of the polygon.
Return value
1 if texture tiling is enabled; 0 if disabled.int getPolygon (int num)
Returns the canvas element ID of the polygon by its index.Arguments
- int num - Polygon index number.
Return value
Canvas element ID of the polygon.vec4 getTextColor (int text)
Returns the current color of the specified text.Arguments
- int text - Canvas element ID of the text string.
Return value
Font color.int getTextHeight (int text)
Returns the height of the given text element on the canvas widget.Arguments
- int text - Canvas element ID of the text string.
Return value
Text height in pixels.int getTextIntersection (int x, int y)
Checks whether the specified point (e.g. the mouse cursor) intersects with a bounding box of widget text.Arguments
- int x - X coordinate of the point.
- int y - Y coordinate of the point.
Return value
ID of intersected text lines array; otherwise, -1 is returned if no intersections are found.int getTextOrder (int text)
Returns the rendering order of the given text element (the higher the value, the later the text is rendered atop other elements).Arguments
- int text - Canvas element ID of the text string.
Return value
Rendering order.int getTextOutline (int text)
Returns a value indicating if the text is rendered casting a shadow. Positive or negative values determine the distance in pixels used to offset the outline.Arguments
- int text - Canvas element ID of the text string.
Return value
Positive value if the outline is offset in the bottom-right corner direction. Negative value if the outline is offset in the top-left corner direction. 0 if font is not outlined.vec3 getTextPosition (int text)
Returns the current position of the specified text.Arguments
- int text - Canvas element ID of the text string.
Return value
Text position coordinates.int getTextSize (int text)
Returns the current font size of the specified text.Arguments
- int text - Canvas element ID of the text string.
Return value
Font size.string getTextText (int text)
Returns the current text drawn in the given text element on the canvas widget.Arguments
- int text - Canvas element ID of the text string.
Return value
Text string.mat4 getTextTransform (int text)
Returns the current transformation matrix of the specified text.Arguments
- int text - Canvas element ID of the text string.
Return value
Transformation matrix.int getTextWidth (int text)
Returns the width of the given text element on the canvas widget.Arguments
- int text - Canvas element ID of the text string.
Return value
Text width in pixels.int getText (int num)
Returns the canvas element ID of the text string by its index.Arguments
- int num - Text element index number.
Return value
Canvas element ID of the text string.string getTexture ()
Returns the name of the current texture set for the canvas widget.Return value
Texture name.mat4 getTransform ()
Returns a transformation matrix applied to all primitives on the canvas widget.Return value
Transformation matrix.void removeLinePoint (int line, int point)
Removes the segment of the line from the canvas widget.Arguments
- int line - Canvas element ID of the line.
- int point - Index number of the point.
void removeLine (int line)
Removes the line from the canvas widget.Arguments
- int line - Canvas element ID of the line.
void removePolygonPoint (int polygon, vec3 point)
Removes the vertex of the polygon from the canvas widget.Arguments
- int polygon - Canvas element ID of the polygon.
- vec3 point - Polygon vertex coordinates.
void removePolygon (int polygon)
Removes the polygon from the canvas widget.Arguments
- int polygon - Canvas element ID of the polygon.
void removeText (int text)
Removes the text from the canvas widget.Arguments
- int text - Canvas element ID of the text string.
void setColor (vec4 color)
Sets the background color for the widget.Arguments
- vec4 color - Background color.
void setImage (Image image)
Updates the texture image for the canvas widget.Arguments
- Image image - Texture image.
void setLineColor (int line, vec4 color)
Updates the color of the specified line.Arguments
- int line - Canvas element ID of the line.
- vec4 color - Line color.
void setLineOrder (int line, int order)
Updates the rendering order of the given line (the higher the value, the later the line will be rendered atop other elements).Arguments
- int line - Canvas element ID of the line.
- int order - Rendering order.
void setLineTransform (int line, mat4 transform)
Updates the transformation matrix of the specified line.Arguments
- int line - Canvas element ID of the line.
- mat4 transform - Transformation matrix.
void setPolygonBlendFunc (int polygon, int src, int dest)
Updates the blending coefficients for specified polygon.Arguments
- int polygon - Canvas element ID of the polygon.
- int src - Blending mode for the source screen buffer color (one of the GUI_BLEND_* variables).
- int dest - Blending mode for the destination polygon color (one of the GUI_BLEND_* variables).
void setPolygonColor (int polygon, vec4 color)
Updates the color of the specified polygon.Arguments
- int polygon - Canvas element ID of the polygon.
- vec4 color - Polygon color.
void setPolygonImage (int polygon, Image image)
Sets an image for a given polygon.Arguments
- int polygon - Canvas element ID of the polygon.
- Image image - Image to set.
void setPolygonOrder (int polygon, int order)
Updates the rendering order of the given polygon (the higher the value, the later the polygon will be rendered atop other elements).Arguments
- int polygon - Canvas element ID of the polygon.
- int order - Rendering order.
void setPolygonTexCoord (int polygon, vec2 texcoord)
Updates the texture coordinates for the last added point of the polygon. Before calling this function, the point should be added with addPolygonPoint().Arguments
- int polygon - Canvas element ID of the polygon.
- vec2 texcoord - Texture coordinates for the point.
void setPolygonTexture (int polygon, string texture)
Sets a texture from a file for the given polygon.Arguments
- int polygon - Canvas element ID of the polygon.
- string texture - Path to the texture.
void setPolygonTransform (int polygon, mat4 transform)
Updates the transformation matrix of the specified polygon.Arguments
- int polygon - Canvas element ID of the polygon.
- mat4 transform - Transformation matrix.
void setPolygonWrapRepeat (int polygon, int repeat)
Sets texture tiling for a given polygon.Arguments
- int polygon - Canvas element ID of the polygon.
- int repeat - Positive number to enable texture tiling; 0 to disable it.
void setTextColor (int text, vec4 color)
Updates the color of the specified text.Arguments
- int text - Canvas element ID of the text string.
- vec4 color - Font color.
void setTextOrder (int text, int order)
Updates the rendering order of the given text element (the higher the value, the later the text will be rendered atop other elements).Arguments
- int text - Canvas element ID of the text string.
- int order - Rendering order.
void setTextOutline (int text, int outline)
Sets a value indicating if the text should be rendered casting a shadow. Positive or negative values set the distance in pixels to offset the outline. The default is 0 (no outlining).Arguments
- int text - Canvas element ID of the text string.
- int outline - Outline offset:
- Positive values set offset in the bottom-right corner direction.
- Negative values set offset in the top-left corner direction (the outline will overlap widget text).
- 0 is not to use outlining.
void setTextPosition (int text, vec3 position)
Updates the position of the specified text.Arguments
- int text - Canvas element ID of the text string.
- vec3 position - Text position coordinates.
void setTextSize (int text, int size)
Updates the font size of the specified text.Arguments
- int text - Canvas element ID of the text string.
- int size - Font size.
void setTextText (int text, string str)
Updates the text to be drawn in the given text element on the canvas widget.Arguments
- int text - Canvas element ID of the text string.
- string str - Text string.
void setTextTransform (int text, mat4 transform)
Updates the transformation matrix of the specified text.Arguments
- int text - Canvas element ID of the text string.
- mat4 transform - Transformation matrix.
void setTexture (string name)
Updates the name of the texture for the canvas widget.Arguments
- string name - Texture name.
void setTransform (mat4 transform)
Sets a transformation matrix applied to all primitives on the canvas widget.Arguments
- mat4 transform - Transformation matrix.
Last update: 2017-07-03
Help improve this article
Was this article helpful?
(or select a word/phrase and press Ctrl+Enter)