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
Type | Name | Description |
---|---|---|
CanvasElement::DrawCallback | func | Function 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.
Name | Value |
---|---|
TypeUnknown | 0 |
TypeText | 1 |
TypeMesh | 2 |
TypeRect | 3 |
TypeTriangle | 4 |
TypeEllipse | 5 |
TypeShape | 6 |
TypeStrip | 7 |
NumTypes | 8 |
Mode
Element modes.
Name | Value | Description |
---|---|---|
ModeSolid | 0 | Solid color mode. |
ModeTexture | 1 | Sample based on texture coordinates. |
ModeTextureFetch | 2 | Sample based on fragment coordinates. |
ModeTextureClamp | 3 | Discard when texture coordinates out of [0-1] range. |
ModeTextureCubic | 4 | Cubic texture filter mode. |
ModeTextureCubic3x3 | 5 | Cubic texture filter with 3x3 prefiltered area mode. |
ModeTextureCubic5x5 | 6 | Cubic texture filter with 5x5 prefiltered area mode. |
ModeTextureRed | 7 | Red texture channel mode. |
ModeTextureGreen | 8 | Green texture channel mode. |
ModeTextureBlue | 9 | Blue texture channel mode. |
ModeTextureAlpha | 10 | Alpha texture channel mode. |
ModeGradient | 11 | Gradient mode. |
NumModes | 12 |
Align
Element alignments.
Name | Value |
---|---|
AlignNone | 0 |
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) |
NumAligns | 6 |
Stack
Element stack operations.
Name | Value | Description |
---|---|---|
StackNone | 0 | |
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. |