class GUICanvas

A GUI element that allows the user to draw custom graphics.

All drawn elements relative to the canvas, to its origin in the top left corner.

Public

Methods

staticGetGuiTypeName

static const String &GetGuiTypeName()

Returns type name of the GUI element used for finding GUI element styles.

DrawLine

void DrawLine(const GUILogicalPoint &a, const GUILogicalPoint &b, const Color &color, u8 depth = 128)

Draws a line going from to .

a
Starting point of the line, relative to the canvas origin (top-left).
b
Ending point of the line, relative to the canvas origin (top-left).
color
Color of the line.
depth
Depth at which to draw the element. Elements with higher depth will be drawn before others. Additionally elements of the same type (triangle or line) will be drawn in order they are submitted if they share the same depth.

DrawPolyLine

void DrawPolyLine(const Vector<GUILogicalPoint> &vertices, const Color &color, u8 depth = 128)

Draws multiple lines following the path by the provided vertices.

First vertex connects to the second vertex, and every following vertex connects to the previous vertex.

vertices
Points to use for drawing the line. Must have at least two elements. All points are relative to the canvas origin (top-left).
color
Color of the line.
depth
Depth at which to draw the element. Elements with higher depth will be drawn before others. Additionally elements of the same type (triangle or line) will be drawn in order they are submitted if they share the same depth.

DrawImage

void DrawImage(const HSpriteImage &image, const GUILogicalArea &area, const Color &color, TextureScaleMode scaleMode = TextureScaleMode::StretchToFit, u8 depth = 128)

Draws a quad with a the provided image displayed.

image
Image to draw.
area
Position and size of the texture to draw. Position is relative to the canvas origin (top-left). If size is zero, the default texture size will be used.
color
Color to tint the drawn texture with.
scaleMode
Scale mode to use when sizing the texture. Only relevant if the provided quad size doesn't match the texture size.
depth
Depth at which to draw the element. Elements with higher depth will be drawn before others. Additionally elements of the same type (triangle or line) will be drawn in order they are submitted if they share the same depth.

DrawTriangleStrip

void DrawTriangleStrip(const Vector<GUILogicalPoint> &vertices, const Color &color, u8 depth = 128)

Draws a triangle strip.

First three vertices are used to form the initial triangle, and every next vertex will form a triangle with the previous two.

vertices
A set of points defining the triangles. Must have at least three elements. All points are relative to the canvas origin (top-left).
color
Color of the triangles.
depth
Depth at which to draw the element. Elements with higher depth will be drawn before others. Additionally elements of the same type (triangle or line) will be drawn in order they are submitted if they share the same depth.

DrawTriangleList

void DrawTriangleList(const Vector<GUILogicalPoint> &vertices, const Color &color, u8 depth = 128)

Draws a triangle list.

Every three vertices in the list represent a unique triangle.

vertices
A set of points defining the triangles. Must have at least three elements, and its size must be a multiple of three.
color
Color of the triangles.
depth
Depth at which to draw the element. Elements with higher depth will be drawn before others. Additionally elements of the same type (triangle or line) will be drawn in order they are submitted if they share the same depth.

DrawText

void DrawText(const String &text, const GUILogicalPoint &position, const HFont &font, float size, const Color &color, u8 depth = 128)

Draws a piece of text with the wanted font.

The text will be aligned to the top-left corner of the provided position, and will not be word wrapped.

text
Text to draw.
position
Position of the text to draw. This represents the top-left corner of the text. It is relative to the canvas origin (top-left).
font
Font to draw the text with.
size
Size of the font.
color
Color of the text.
depth
Depth at which to draw the element. Elements with higher depth will be drawn before others. Additionally elements of the same type (triangle or line) will be drawn in order they are submitted if they share the same depth.

Clear

void Clear()

Clears the canvas, removing any previously drawn elements.

staticCreate

static GUIElementType *Create(const String &styleClass, const TInlineArray<GUIOption, 4> &options)

Creates a new GUI element.

styleClass
Style class that will be used for determining GUI element visuals from the current style sheet. If no class is provided, default style is determined based on GUI element type.
options
Additional options that control GUI element size and position. This will override options set in the style sheet.

Internal

Constructors

GUICanvas

GUICanvas(PrivatelyConstruct, const String &styleName, const GUISizeConstraints &sizeConstraints)

Methods

CalculateUnconstrainedOptimalSize

GUILogicalSize CalculateUnconstrainedOptimalSize() const override

Calculates the optimal size for the GUI element, ignoring size constraints.

GetRenderElementDepthRange

u32 GetRenderElementDepthRange() const override

Returns the range of depths that the child elements can be rendered it.

GetStyleSheetElement

const char *GetStyleSheetElement() const override

Returns the name of the GUI element type to be used for style lookup in the style sheet.

Protected

Methods

~GUICanvas

virtual ~GUICanvas() noexcept

FillBuffer

void FillBuffer(u8 *vertices, u32 *indices, u32 vertexOffset, u32 indexOffset, const Vector2I &offset, u32 maxVertexCount, u32 maxIndexCount, u32 renderElementIdx) const override

Fill the pre-allocated vertex, uv and index buffers with the mesh data for the specified render element.

vertices
Previously allocated buffer where to store the vertices. Output is expected to match the GUIMeshType as returned by getRenderElements() for the specified element.
indices
Previously allocated buffer where to store the indices.
vertexOffset
At which vertex should the method start filling the buffer.
offset
Offset that should be applied to all output vertex positions.
indexOffset
At which index should the method start filling the buffer.
maxVertexCount
Total number of vertices the buffers were allocated for. Used only for memory safety.
maxIndexCount
Total number of indices the buffers were allocated for. Used only for memory safety.
renderElementIdx
Zero-based index of the render element.

UpdateRenderElements

void UpdateRenderElements() override

Recreates the internal render elements.

Must be called before GetRenderElementVertexAndIndexData/FillBuffer if element is dirty. Marks the element as non dirty.

BuildImageElement

void BuildImageElement(const CanvasElement &element)

Build an image sprite from the provided canvas element.

BuildTextElement

void BuildTextElement(const CanvasElement &element)

Build a text sprite from the provided canvas element.

BuildTriangleElement

void BuildTriangleElement(const CanvasElement &element, const Vector2 &offset, float scale, const Area2I &clipRect) const

Build a set of clipped triangles from the source triangles provided by the canvas element.

BuildAllTriangleElementsIfDirty

void BuildAllTriangleElementsIfDirty(const Vector2 &offset, float scale, const Area2I &clipRect) const

Rebuilds all triangle elements on the canvas, by constructing a set of clipped and offset triangles from the triangles provided by the canvas elements.

FindElement

const CanvasElement &FindElement(u32 renderElementIdx) const

Finds the canvas element that contains the render element with the specified index.

Fields

mElements

Vector<CanvasElement> mElements

mDepthRange

u8 mDepthRange

mImageData

Vector<ImageElementData> mImageData

mTextData

Vector<TextElementData> mTextData

mTriangleElementData

Vector<TriangleElementData> mTriangleElementData

mVertexData

Vector<GUILogicalPointF> mVertexData

mClippedVertices

Vector<Vector2> mClippedVertices

mClippedLineVertices

Vector<Vector2> mClippedLineVertices

mLastOffset

Vector2 mLastOffset

mLastClipRect

Area2I mLastClipRect

mForceTriangleBuild

bool mForceTriangleBuild