Jazz2::Scripting::Legacy::jjCANVAS struct

Drawing surface passed to the HUD and layer drawing hooks.

The HUD hooks (onDraw*) receive a canvas covering one player's view, the onDrawLayer# hooks one that draws into the level at the depth of that layer. A canvas is only valid while the hook runs. Its methods draw pixels, rectangles, tiles, sprites and text immediately; whatever is drawn later in the frame covers what was drawn before. Most methods take a SPRITE::Mode and its parameter, which control how the colors are rendered. Nothing drawn this way interacts with the level.

Public static functions

static void jjDrawString(float xPixel, float yPixel, const String& text, const jjANIMATION& animation, std::uint32_t mode, std::uint8_t param, std::int8_t layerZ, std::uint8_t layerXY, std::int8_t playerID) partially supported
Draws text into the level using the frames of an animation as the font.
static void jjDrawStringEx(float xPixel, float yPixel, const String& text, const jjANIMATION& animation, const jjTEXTAPPEARANCE& appearance, std::uint8_t param1, std::uint32_t spriteMode, std::uint8_t param2, std::int8_t layerZ, std::uint8_t layerXY, std::int8_t playerID) partially supported
Draws text into the level using the frames of an animation as the font, with a custom appearance.
static auto jjGetStringWidth(const String& text, const jjANIMATION& animation, const jjTEXTAPPEARANCE& style) -> int
Returns the width of text drawn with an animation as the font.

Constructors, destructors, conversion operators

jjCANVAS(UI::Canvas* target, Vector2f offset, float width, std::uint16_t* drawCount, std::uint16_t firstLayer, std::uint16_t lastLayer)
Creates a new instance bound to a canvas, drawCount is shared by the canvases of the frame.

Public functions

auto NextLayer() -> std::uint16_t
Returns the layer of the next draw, above every draw before it.
auto GetTextX(std::int32_t xPixel, float textWidth) const -> float
Returns where text of a width starts, as JJ2 places it.
void DrawPixel(std::int32_t xPixel, std::int32_t yPixel, std::uint8_t color, std::uint32_t mode, std::uint8_t param)
Draws a single pixel.
void DrawRectangle(std::int32_t xPixel, std::int32_t yPixel, std::int32_t width, std::int32_t height, std::uint8_t color, std::uint32_t mode, std::uint8_t param)
Draws a filled rectangle.
void DrawSprite(std::int32_t xPixel, std::int32_t yPixel, std::int32_t setID, std::uint8_t animation, std::uint8_t frame, int8_t direction, std::uint32_t mode, std::uint8_t param)
Draws a frame of an animation set.
void DrawCurFrameSprite(std::int32_t xPixel, std::int32_t yPixel, std::uint32_t sprite, int8_t direction, std::uint32_t mode, std::uint8_t param)
Draws a frame given by its index in jjAnimFrames.
void DrawResizedSprite(std::int32_t xPixel, std::int32_t yPixel, std::int32_t setID, std::uint8_t animation, std::uint8_t frame, float xScale, float yScale, std::uint32_t mode, std::uint8_t param)
Draws a scaled frame of an animation set.
void DrawResizedCurFrameSprite(std::int32_t xPixel, std::int32_t yPixel, std::uint32_t sprite, float xScale, float yScale, std::uint32_t mode, std::uint8_t param)
Draws a scaled frame given by its index in jjAnimFrames.
void DrawTransformedSprite(std::int32_t xPixel, std::int32_t yPixel, std::int32_t setID, std::uint8_t animation, std::uint8_t frame, std::int32_t angle, float xScale, float yScale, std::uint32_t mode, std::uint8_t param)
Draws a rotated and scaled frame of an animation set.
void DrawTransformedCurFrameSprite(std::int32_t xPixel, std::int32_t yPixel, std::uint32_t sprite, std::int32_t angle, float xScale, float yScale, std::uint32_t mode, std::uint8_t param)
Draws a rotated and scaled frame given by its index in jjAnimFrames.
void DrawSwingingVine(std::int32_t xPixel, std::int32_t yPixel, std::uint32_t sprite, std::int32_t length, std::int32_t curvature, std::uint32_t mode, std::uint8_t param)
Draws a frame bent like a swinging vine.
void ExternalDrawTile(std::int32_t xPixel, std::int32_t yPixel, std::uint16_t tile, std::uint32_t tileQuadrant)
Draws a tile of the tile set.
void DrawTextBasicSize(std::int32_t xPixel, std::int32_t yPixel, const String& text, std::uint32_t size, std::uint32_t mode, std::uint8_t param) partially supported
Draws text in one of the built-in font sizes.
void DrawTextExtSize(std::int32_t xPixel, std::int32_t yPixel, const String& text, std::uint32_t size, const jjTEXTAPPEARANCE& appearance, std::uint8_t param1, std::uint32_t mode, std::uint8_t param) partially supported
Draws text in one of the built-in font sizes with a custom appearance.
void DrawScriptText(std::int32_t xPixel, std::int32_t yPixel, const String& text, std::uint32_t size, std::uint32_t stringMode, std::uint32_t spriteMode, std::uint8_t param, bool newLines = false, std::int32_t spacing = 1, jjTEXTAPPEARANCE::align_ align = jjTEXTAPPEARANCE::align_DEFAULT)
Draws text in a built-in font size, moving as STRING::Mode says (BOUNCE, SPIN), in a sprite mode.
auto DrawMissingFontCharacter(std::int32_t xPixel, std::int32_t yPixel, std::int32_t setID, std::uint8_t animation, std::uint8_t frame, std::uint32_t mode, std::uint8_t param) -> bool
Draws a frame of the font of the original that has no image as the character in the font of the game, returns false for any other frame.
void drawString(std::int32_t xPixel, std::int32_t yPixel, const String& text, const jjANIMATION& animation, std::uint32_t mode, std::uint8_t param) partially supported
Draws text using the frames of an animation as the font.
void drawStringEx(std::int32_t xPixel, std::int32_t yPixel, const String& text, const jjANIMATION& animation, const jjTEXTAPPEARANCE& appearance, std::uint8_t param1, std::uint32_t spriteMode, std::uint8_t param2) partially supported
Draws text using the frames of an animation as the font, with a custom appearance.

Public variables

UI::Canvas* Target
The canvas this one draws onto.
Vector2f Offset
Added to every position.
float Width
Width of the area, text is aligned in it.
std::uint16_t* DrawCount
Counts the draws in this frame, each is drawn over the ones before it, as in JJ2+.
std::uint16_t FirstLayer
Layers of the draws, the draws after the last one stay on it.
std::uint16_t LastLayer

Function documentation

static void Jazz2::Scripting::Legacy::jjCANVAS::jjDrawString(float xPixel, float yPixel, const String& text, const jjANIMATION& animation, std::uint32_t mode, std::uint8_t param, std::int8_t layerZ, std::uint8_t layerXY, std::int8_t playerID)

Draws text into the level using the frames of an animation as the font.

static void Jazz2::Scripting::Legacy::jjCANVAS::jjDrawStringEx(float xPixel, float yPixel, const String& text, const jjANIMATION& animation, const jjTEXTAPPEARANCE& appearance, std::uint8_t param1, std::uint32_t spriteMode, std::uint8_t param2, std::int8_t layerZ, std::uint8_t layerXY, std::int8_t playerID)

Draws text into the level using the frames of an animation as the font, with a custom appearance.

static int Jazz2::Scripting::Legacy::jjCANVAS::jjGetStringWidth(const String& text, const jjANIMATION& animation, const jjTEXTAPPEARANCE& style)

Returns the width of text drawn with an animation as the font.

Measured in pixels as jjCANVAS::drawString() would lay the text out with the appearance; for text of several lines, the width of the widest one.

float Jazz2::Scripting::Legacy::jjCANVAS::GetTextX(std::int32_t xPixel, float textWidth) const

Returns where text of a width starts, as JJ2 places it.

Around 0x8000 it's centered, moved by the difference, and around 0x10000 it ends that far from the right edge.

void Jazz2::Scripting::Legacy::jjCANVAS::DrawPixel(std::int32_t xPixel, std::int32_t yPixel, std::uint8_t color, std::uint32_t mode, std::uint8_t param)

Draws a single pixel.

The pixel at the given position gets the palette color with index color, rendered in the sprite mode. For many pixels, a sprite of your own is usually the better choice.

void Jazz2::Scripting::Legacy::jjCANVAS::DrawRectangle(std::int32_t xPixel, std::int32_t yPixel, std::int32_t width, std::int32_t height, std::uint8_t color, std::uint32_t mode, std::uint8_t param)

Draws a filled rectangle.

The top left corner is at the given position, the rectangle is width by height pixels in the palette color with index color. In most BLEND_ sprite modes, param acts as the opacity (255 is opaque).

void Jazz2::Scripting::Legacy::jjCANVAS::DrawSprite(std::int32_t xPixel, std::int32_t yPixel, std::int32_t setID, std::uint8_t animation, std::uint8_t frame, int8_t direction, std::uint32_t mode, std::uint8_t param)

Draws a frame of an animation set.

setID is an ANIM::Set value, animation the index of the animation in that set and frame the index of the frame in the animation, all counted from 0. The frame's hotspot lands on the given position.

direction flips the sprite: negative values flip it horizontally, values from 64 to 127 vertically and values from -128 to -65 both ways. The SPRITE::Direction constants name these cases.

void Jazz2::Scripting::Legacy::jjCANVAS::DrawCurFrameSprite(std::int32_t xPixel, std::int32_t yPixel, std::uint32_t sprite, int8_t direction, std::uint32_t mode, std::uint8_t param)

Draws a frame given by its index in jjAnimFrames.

Same as drawSprite(), but the frame is a single index, such as the curFrame of an object or a player.

void Jazz2::Scripting::Legacy::jjCANVAS::DrawResizedSprite(std::int32_t xPixel, std::int32_t yPixel, std::int32_t setID, std::uint8_t animation, std::uint8_t frame, float xScale, float yScale, std::uint32_t mode, std::uint8_t param)

Draws a scaled frame of an animation set.

Like drawSprite(), but the frame is stretched by xScale and yScale instead of taking a direction. A negative scale flips the sprite on that axis. No smoothing is applied.

void Jazz2::Scripting::Legacy::jjCANVAS::DrawResizedCurFrameSprite(std::int32_t xPixel, std::int32_t yPixel, std::uint32_t sprite, float xScale, float yScale, std::uint32_t mode, std::uint8_t param)

Draws a scaled frame given by its index in jjAnimFrames.

Same as drawResizedSprite(), but the frame is a single index.

void Jazz2::Scripting::Legacy::jjCANVAS::DrawTransformedSprite(std::int32_t xPixel, std::int32_t yPixel, std::int32_t setID, std::uint8_t animation, std::uint8_t frame, std::int32_t angle, float xScale, float yScale, std::uint32_t mode, std::uint8_t param)

Draws a rotated and scaled frame of an animation set.

angle uses 1024 units per full turn (as jjSin() does) and turns the sprite counter-clockwise about its hotspot; 0 leaves it unrotated. The sprite is scaled by xScale and yScale before it is rotated.

void Jazz2::Scripting::Legacy::jjCANVAS::DrawTransformedCurFrameSprite(std::int32_t xPixel, std::int32_t yPixel, std::uint32_t sprite, std::int32_t angle, float xScale, float yScale, std::uint32_t mode, std::uint8_t param)

Draws a rotated and scaled frame given by its index in jjAnimFrames.

Same as drawRotatedSprite(), but the frame is a single index.

void Jazz2::Scripting::Legacy::jjCANVAS::DrawSwingingVine(std::int32_t xPixel, std::int32_t yPixel, std::uint32_t sprite, std::int32_t length, std::int32_t curvature, std::uint32_t mode, std::uint8_t param)

Draws a frame bent like a swinging vine.

The frame is drawn length rows down from the given position, repeating from its top if it is shorter. Each row is shifted sideways by curvature * row * row / 4194304 pixels, and the vine gets one row shorter for every 2048 of the curvature. Pixels with palette index 128 are treated as transparent, as vine graphics expect.

void Jazz2::Scripting::Legacy::jjCANVAS::ExternalDrawTile(std::int32_t xPixel, std::int32_t yPixel, std::uint16_t tile, std::uint32_t tileQuadrant)

Draws a tile of the tile set.

The tile's top left corner is at the given position. tile may include the TILE::HFLIPPED, TILE::VFLIPPED and TILE::ANIMATED flags. With a tileQuadrant other than TILE::ALLQUADRANTS, only that quarter of the tile is drawn, at its place within the tile. This only draws; it doesn't add anything solid to the level.

void Jazz2::Scripting::Legacy::jjCANVAS::DrawTextBasicSize(std::int32_t xPixel, std::int32_t yPixel, const String& text, std::uint32_t size, std::uint32_t mode, std::uint8_t param)

Draws text in one of the built-in font sizes.

size is a STRING::Size and mode a STRING::Mode: DARK draws dimmed text, RIGHTALIGN ends the text at the given position, BOUNCE and SPIN move the letters, and PALSHIFT shifts the font colors by param palette entries. The x coordinate can also select alignment, see jjTEXTAPPEARANCE::align. Characters whose frames a script replaced in the font animations are drawn with those frames.

void Jazz2::Scripting::Legacy::jjCANVAS::DrawTextExtSize(std::int32_t xPixel, std::int32_t yPixel, const String& text, std::uint32_t size, const jjTEXTAPPEARANCE& appearance, std::uint8_t param1, std::uint32_t mode, std::uint8_t param)

Draws text in one of the built-in font sizes with a custom appearance.

Uses spacing, align and newline of the appearance, and lets the letters bounce or spin when its amplitudes are non-zero.

void Jazz2::Scripting::Legacy::jjCANVAS::DrawScriptText(std::int32_t xPixel, std::int32_t yPixel, const String& text, std::uint32_t size, std::uint32_t stringMode, std::uint32_t spriteMode, std::uint8_t param, bool newLines = false, std::int32_t spacing = 1, jjTEXTAPPEARANCE::align_ align = jjTEXTAPPEARANCE::align_DEFAULT)

Draws text in a built-in font size, moving as STRING::Mode says (BOUNCE, SPIN), in a sprite mode.

In SPIN, # colors every letter on its own as in the texts of levels, as JJ2+ draws a selected menu item. Elsewhere \n breaks the line only with newLines. spacing and align are of jjTEXTAPPEARANCE, RIGHTALIGN aligns right too.

void Jazz2::Scripting::Legacy::jjCANVAS::drawString(std::int32_t xPixel, std::int32_t yPixel, const String& text, const jjANIMATION& animation, std::uint32_t mode, std::uint8_t param)

Draws text using the frames of an animation as the font.

Frame 0 of the animation is the space and each further frame the next character code, as in the built-in font animations. A space is 7 pixels wide, other characters as wide as their frames. @ and line feeds start a new line, and |, #, ~, ^ and § are left out. mode is a STRING::Mode: RIGHTALIGN ends the text at the given position and PALSHIFT shifts the colors by param palette entries.

void Jazz2::Scripting::Legacy::jjCANVAS::drawStringEx(std::int32_t xPixel, std::int32_t yPixel, const String& text, const jjANIMATION& animation, const jjTEXTAPPEARANCE& appearance, std::uint8_t param1, std::uint32_t spriteMode, std::uint8_t param2)

Draws text using the frames of an animation as the font, with a custom appearance.

Uses spacing and align of the appearance, and draws the special characters it sets to STRING::DISPLAYSIGN as regular characters. The text is drawn in spriteMode with param2.