Jazz2::UI::Canvas class

Canvas.

Base drawing surface for on-screen UI rendering. It collects textured and solid rectangle draw calls as render commands and submits them to the render queue, also providing alignment helpers and palette-based recoloring.

Base classes

class nCine::SceneNode
Base node of the scene graph transformation hierarchy.

Derived classes

class Jazz2::Editor::EditorSceneCanvas
Canvas in the level, drawn among its layers in pixels of the level.
class Jazz2::Editor::PlayTestDebugOverlay
Draws debug information of a play-test over the level.
class Jazz2::Scripting::Legacy::ScriptLayerCanvas
Where onDrawLayer1() to onDrawLayer8() of a level script draw.
class Jazz2::Scripting::Legacy::ScriptWorldCanvas
Sprites and rectangles a level script draws in the level (jjDrawSprite() and the like).
class HUD
Player HUD.
class InGameConsole
In-game console.
class MpInGameCanvasLayer
In-game canvas on sprite layer for multiplayer.
class MpInGameLobby
In-game lobby screen for multiplayer.
class Surface
Shows the interface and passes input to it.

Public static variables

static float AnimTimeMultiplier constexpr
Multiplier of game time for canvas rendering, AnimTime grows by it a frame.

Public static functions

static auto ApplyAlignment(Alignment align, Vector2f vec, Vector2f size) -> Vector2f
Applies alignment settings to a given position vector.

Constructors, destructors, conversion operators

Canvas()
Creates a new instance.

Public functions

void OnUpdate(float timeMult) override
Called every frame to update the node state.
auto OnDraw(RenderQueue& renderQueue) -> bool override
Called when the node needs to be drawn, returning true if a command was added.
void DrawTexture(const Texture& texture, Vector2f pos, std::uint16_t z, Vector2f size, const Vector4f& texCoords, const Colorf& color, BlendMode blending = BlendMode::Normal, float angle = 0.0f, std::int32_t paletteOffset = -1, Shader* shader = nullptr)
Draws a textured rectangle.
void DrawTextureBatched(const Texture& texture, Vector2f pos, std::uint16_t z, Vector2f size, const Vector4f& texCoords, const Colorf& color)
Draws a textured rectangle into one batch with the rectangles drawn right before it on the same layer.
void DrawTextureWithPalette(const Texture& texture, const Texture& palette, Vector2f pos, std::uint16_t z, Vector2f size, const Vector4f& texCoords, const Colorf& color, float paletteOffset = 0.0f)
Draws an indexed textured rectangle recolored through a palette texture (PaletteRemap shader).
void DrawSolid(Vector2f pos, std::uint16_t z, Vector2f size, const Colorf& color, BlendMode blending = BlendMode::Normal, float angle = 0.0f)
Draws a solid rectangle, turned by angle in radians about its center.
auto RentRenderCommand() -> RenderCommand*
Rents a render command for rendering on the canvas.
void DrawRenderCommand(RenderCommand* command)
Draws a raw render command.
auto ClipQuad(Vector2f& pos, Vector2f& size, Vector4f* texCoords) const -> bool
Clips a rectangle to ClipRect, returns false if nothing of it is left.

Public variables

Vector2i ViewSize
View size of the canvas.
float AnimTime
Animation time of the canvas.
Vector2f LayerOffset
Translation added to every drawn primitive in screen-space.
float LayerScale
Uniform scale applied to every drawn primitive.
float PixelScale
Pixels of the target for a unit drawn, 1 by default.
Colorf LayerColor
Tint multiplied into the color of every drawn primitive.
Rectf ClipRect
Rectangle in screen-space every drawn primitive is clipped to, one without area clips nothing.
bool OrderedDraws
Whether primitives of the same layer are drawn in the order they were drawn in.
bool AdditiveText
Whether text drawn through Font is added to what's behind it instead of drawn over it, off by default.

Function documentation

void Jazz2::UI::Canvas::DrawTexture(const Texture& texture, Vector2f pos, std::uint16_t z, Vector2f size, const Vector4f& texCoords, const Colorf& color, BlendMode blending = BlendMode::Normal, float angle = 0.0f, std::int32_t paletteOffset = -1, Shader* shader = nullptr)

Draws a textured rectangle.

paletteOffset >= 0 marks the texture as indexed (palette index in the red channel), recolored at draw time through the shared palette texture at that offset; -1 = plain RGBA. A shader draws it in place of the sprite shaders, it has to be the palette variant for an indexed texture. Only BlendMode::Normal, BlendMode::Additive and BlendMode::Difference are supported for textures, with BlendMode::Difference the color of a transparent texel must be black.

void Jazz2::UI::Canvas::DrawTextureBatched(const Texture& texture, Vector2f pos, std::uint16_t z, Vector2f size, const Vector4f& texCoords, const Colorf& color)

Draws a textured rectangle into one batch with the rectangles drawn right before it on the same layer.

Draws the same as DrawTexture() without rotation, palette and additive blending, but rectangles drawn one after another on a layer with the same texture share a single command, written straight into its batch, as the glyphs of Font are. Anything else drawn on the layer in between — by DrawTexture(), DrawSolid(), DrawRenderCommand() or a text — ends the batch, the next rectangle starts another one, so everything is drawn in the order it was drawn in as before. Meant for an interface of many small shapes.

void Jazz2::UI::Canvas::DrawTextureWithPalette(const Texture& texture, const Texture& palette, Vector2f pos, std::uint16_t z, Vector2f size, const Vector4f& texCoords, const Colorf& color, float paletteOffset = 0.0f)

Draws an indexed textured rectangle recolored through a palette texture (PaletteRemap shader).

The palette offset is the flat index of the first color in the palette texture (0 = the first row/palette).

bool Jazz2::UI::Canvas::ClipQuad(Vector2f& pos, Vector2f& size, Vector4f* texCoords) const

Clips a rectangle to ClipRect, returns false if nothing of it is left.

The position and size are in screen-space, after the layer transform. Texture coordinates in the layout the sprite shaders take (horizontal scale and offset, then vertical) are cut down along with the rectangle.

Variable documentation

Vector2f Jazz2::UI::Canvas::LayerOffset

Translation added to every drawn primitive in screen-space.

Together with LayerScale and LayerColor forms an optional draw transform applied to all primitives, including text drawn through Font. Used by the menu section transition system to slide, scale and fade an entire section without per-section cooperation. Identity by default, so non-menu canvases (HUD, cinematics, …) are unaffected. A final screen position is worldPos * LayerScale + LayerOffset.

float Jazz2::UI::Canvas::PixelScale

Pixels of the target for a unit drawn, 1 by default.

Glyphs are put on whole pixels of the target, a canvas drawn into a target larger than the units it's drawn in — by its camera — puts them on its pixels with it.

Rectf Jazz2::UI::Canvas::ClipRect

Rectangle in screen-space every drawn primitive is clipped to, one without area clips nothing.

Applied after the layer transform, on the CPU, so it doesn't stop primitives from being batched — one outside of it is left out, one across its edge is cut down together with its texture coordinates. Text drawn through Font is clipped glyph by glyph. A rotated primitive is only left out when all of it is outside, it's never cut. Nothing is clipped by default.

bool Jazz2::UI::Canvas::OrderedDraws

Whether primitives of the same layer are drawn in the order they were drawn in.

Otherwise their order is unspecified, so overlapping primitives have to be on different layers. Off by default, as only the level editor and what level scripts draw need it.