Skip to main content

CanvasElement

The CanvasElement class represents a drawable element within a Canvas and serves as a base for various types such as text, shapes, and meshes, offering customizable rendering modes, alignments, and transformations. It provides fine-grained control over visual attributes including color, texture, depth, and blending, and supports stack-based operations for managing transform, color, and scissor states. Each element can be linked to a dedicated rendering pipeline, sampler, and draw callback, enabling flexible and precise control over its appearance and rendering behavior.

#include <interface/TellusimCanvas.h>

Constructors

CanvasElement()

Methods

Element type.

Type getType() const
static const char *getTypeName(Type type)
const char *getTypeName() const
bool isText() const
bool isMesh() const
bool isRect() const
bool isTriangle() const
bool isEllipse() const
bool isShape() const
bool isStrip() const

Element canvas.

void setCanvas(Canvas &canvas)
const Canvas getCanvas() const
Canvas getCanvas()

Element mode.

void setMode(Mode mode)
Mode getMode() const

Element align.

void setAlign(Align align)
Align getAlign() const
bool hasAlign(Align align) const
bool hasAligns(Align aligns) const

Element order.

void setOrder(int32_t order)
int32_t getOrder() const

Element enabled flag.

void setEnabled(bool enabled)
bool isEnabled() const

Element color.

void clearColor()
void setColor(Stack op)
void setColor(Color color, Stack op = StackNone)
void setColor(float32_t r, float32_t g, float32_t b, float32_t a, Stack op = StackNone)
const Color getColor() const
Stack getColorOp() const

Element transform.

void clearTransform()
void setTransform(Stack op)
void setTransform(Matrix4x4f transform, Stack op = StackNone)
const Matrix4x4f getTransform() const
Stack getTransformOp() const

Element scissor.

void clearScissor()
void setScissor(Stack op)
void setScissor(Rect scissor, Stack op = StackNone)
const Rect getScissor() const
Stack getScissorOp() const

Element mipmap number.

void setMipmap(float32_t mipmap)
float32_t getMipmap() const

Sampler pointer.

void setSampler(Sampler &sampler)
Sampler getSampler() const

Filter mode.

void setFilter(Filter filter)
Filter getFilter() const
void setAnisotropy(uint32_t anisotropy)
uint32_t getAnisotropy() const

Wrapping mode.

void setWrapMode(WrapMode mode)
WrapMode getWrapMode() const

Texture pointer.

void setTexture(Texture &texture, bool linear = false)
Texture getTexture() const
bool getTextureLinear() const

Pipeline pointer.

void setPipeline(Pipeline pipeline)
Pipeline getPipeline() const

Rasterization parameters.

void setPrimitive(Primitive primitive)
Primitive getPrimitive() const
void setCullMode(CullMode mode)
CullMode getCullMode() const
void setFrontMode(FrontMode mode)
FrontMode getFrontMode() const

Blending parameters.

void setBlend(BlendOp op, BlendFunc src, BlendFunc dest)
BlendOp getBlendOp() const
BlendFunc getBlendSrcFunc() const
BlendFunc getBlendDestFunc() const

Color parameters.

void setColorMask(ColorMask mask)
ColorMask getColorMask() const

Depth parameters.

void setDepthMask(DepthMask mask)
DepthMask getDepthMask() const
void setDepthFunc(DepthFunc func)
DepthFunc getDepthFunc() const

Stencil parameters.

void setStencilRef(uint32_t ref)
void setStencilFunc(StencilFunc func, StencilOp fail_op, StencilOp dfail_op, StencilOp dpass_op)
uint32_t getStencilRef() const
StencilFunc getStencilFunc() const
StencilOp getStencilFailOp() const
StencilOp getStencilDepthFailOp() const
StencilOp getStencilDepthPassOp() const

Draw callback.

void setDrawCallback(const DrawCallback &func)
DrawCallback getDrawCallback() const
TypeNameDescription
CanvasElement::DrawCallbackfuncFunction that runs on Canvas::draw() call. Returning false prevents CanvasElement draw.

Element rectangle.

const Rect getRect()

Types

using DrawCallback = Function<bool(Command command, CanvasElement element)>

Enums

Type

Element types.

NameValue
TypeUnknown0
TypeText1
TypeMesh2
TypeRect3
TypeTriangle4
TypeEllipse5
TypeShape6
TypeStrip7
NumTypes8

Mode

Element modes.

NameValueDescription
ModeSolid0Solid color mode.
ModeTexture1Sample based on texture coordinates.
ModeTextureFetch2Sample based on fragment coordinates.
ModeTextureClamp3Discard when texture coordinates out of [0-1] range.
ModeTextureCubic4Cubic texture filter mode.
ModeTextureCubic3x35Cubic texture filter with 3x3 prefiltered area mode.
ModeTextureCubic5x56Cubic texture filter with 5x5 prefiltered area mode.
ModeTextureRed7Red texture channel mode.
ModeTextureGreen8Green texture channel mode.
ModeTextureBlue9Blue texture channel mode.
ModeTextureAlpha10Alpha texture channel mode.
ModeGradient11Gradient mode.
NumModes12

Align

Element alignments.

NameValue
AlignNone0
AlignLeft(1 << 0)
AlignRight(1 << 1)
AlignBottom(1 << 2)
AlignTop(1 << 3)
AlignCenterX(1 << 4)
AlignCenterY(1 << 5)
AlignLeftBottom(AlignLeft | AlignBottom)
AlignLeftTop(AlignLeft | AlignTop)
AlignRightBottom(AlignRight | AlignBottom)
AlignRightTop(AlignRight | AlignTop)
AlignCenter(AlignCenterX | AlignCenterY)
NumAligns6

Stack

Element stack operations.

NameValueDescription
StackNone0
StackPush(1 << 0)Push into the stack.
StackPop(1 << 1)Pop from the stack.
StackSet(1 << 2)Replace top of the stack.
StackMul(1 << 3)Multiply top of the stack.
StackGet(1 << 4)Get top of the stack.