Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
Loading...
Searching...
No Matches
wsgCanvas.h File Reference

Detailed Description

Provides a canvas to paint with low memory requirements.

Author
Jeremy Stintzcum (jerem.nosp@m.y.st.nosp@m.intzc.nosp@m.um@g.nosp@m.mail..nosp@m.com)
Version
1.0
Date
2025-09-02

Overview

The WSG Canvas system is a simple way of combining wsgs together to create a single sprite. Why is this useful? Well, it was initially designed for the swadgesonas, which would require loading a lot of individual WSGs and leaving them loaded, which would be pretty memory intensive. Instead, this canvas system allows for a WSG to be created once, and all the other WSGs applied over it are only loaded when the data is needed, and then immediately discarded. This is a much more efficient way to store swadgesonas, and will allow many of them to be on-screen at once.

Usage

Step one is to load up a canvas. Use canvasBlankInit() to create a blank canvas on which to paint, or load a normal WSG. Just note that any changes you make cannot be revered without re-initializing the WSG.

Next, use canvasDraw() to put WSGs onto the canvas. You can rotate, flip in both x and y, and position the WSG however you like on the canvas. Pixels outside of the boundaries of the canvas will be discarded, and transparent pixels will leave the color underneath to show through, allowing for complex layering.

Palettes are also supported, so things like custom hair colors can be applied without having to rely on a drawing function further down the line.

Two additional "simple" versions have been provided for when rotation and flipping aren't required.

Lastly, call freeWsg() when done with the canvas, just like any other WSG.

The canvas can be used like any WSG, so all wsg drawing functions work on it once it has been created.

// Create structs
wsg_t canvas;
// Initialize canvas
canvasBlankInit(&canvas, 280, 240, c444, true);
// Draw to the canvas normally
canvasDrawSimple(&canvas, KID_0_WSG, 40, 48);
// Draw to the canvas with a palette
wsgPalette_t palette;
wsgPaletteReset(&palette);
canvasDrawPal(&canvas, KID_1_WSG, 160, 48, true, false, 15, palette);
// Clean up
freeWsg(&canvas);
void freeWsg(wsg_t *wsg)
Free the memory for a loaded WSG.
Definition fs_wsg.c:196
@ c444
r = 4, g = 4, b = 4
Definition palette.h:196
void canvasBlankInit(wsg_t *canvas, int width, int height, paletteColor_t startColor, bool spiRam)
Initializes a blank canvas to the dimensions and color provided.
Definition wsgCanvas.c:50
void canvasDrawSimple(wsg_t *canvas, cnfsFileIdx_t image, int startX, int startY)
Draws a image to the canvas at the specified coordinates relative to the canvas.
Definition wsgCanvas.c:59
void canvasDrawPal(wsg_t *canvas, cnfsFileIdx_t image, int startX, int startY, bool flipX, bool flipY, int32_t rotateDeg, wsgPalette_t *pal)
Draws an image to the canvas at a specified angle.
Definition wsgCanvas.c:74
void wsgPaletteReset(wsgPalette_t *palette)
Resets the palette to initial state.
Definition wsgPalette.c:375
Definition wsgPalette.h:74
A sprite using paletteColor_t colors that can be drawn to the display.
Definition wsg.h:57

Go to the source code of this file.

Functions

void canvasBlankInit (wsg_t *canvas, int width, int height, paletteColor_t startColor, bool spiRam)
 Initializes a blank canvas to the dimensions and color provided.
 
void canvasDrawSimple (wsg_t *canvas, cnfsFileIdx_t image, int startX, int startY)
 Draws a image to the canvas at the specified coordinates relative to the canvas.
 
void canvasDrawSimplePal (wsg_t *canvas, cnfsFileIdx_t image, int startX, int startY, wsgPalette_t *pal)
 Draws a image to the canvas at the specified coordinates relative to the canvas and applies a palette.
 
void canvasDraw (wsg_t *canvas, cnfsFileIdx_t image, int startX, int startY, bool flipX, bool flipY, int32_t rotateDeg)
 Draws an image to the canvas at a specified angle.
 
void canvasDrawPal (wsg_t *canvas, cnfsFileIdx_t image, int startX, int startY, bool flipX, bool flipY, int32_t rotateDeg, wsgPalette_t *pal)
 Draws an image to the canvas at a specified angle.
 

Function Documentation

◆ canvasBlankInit()

void canvasBlankInit ( wsg_t * canvas,
int width,
int height,
paletteColor_t startColor,
bool spiRam )

Initializes a blank canvas to the dimensions and color provided.

Parameters
canvasWSG to save the canvas too. Use a standard wsg_t and provide the pointer
widthWidth in pixels of the desired canvas
heightHeight in pixels of the desired canvas
startColorThe initial color. Can be any paletteColor_t including cTransparent
spiRamWhether or not to load the pixel data into SPIRAM.

◆ canvasDrawSimple()

void canvasDrawSimple ( wsg_t * canvas,
cnfsFileIdx_t image,
int startX,
int startY )

Draws a image to the canvas at the specified coordinates relative to the canvas.

Parameters
canvasWSG to save changes to. Will work with any WSG, cannot be reverted
imageNew cnfsFileIdx_t to apply to the canvas
startXX position on canvas. Negative moves left, positive moves right. Pixels not on canvas are cropped.
startYY position on canvas. Negative moves left, positive moves right. Pixels not on canvas are cropped.

◆ canvasDrawSimplePal()

void canvasDrawSimplePal ( wsg_t * canvas,
cnfsFileIdx_t image,
int startX,
int startY,
wsgPalette_t * pal )

Draws a image to the canvas at the specified coordinates relative to the canvas and applies a palette.

Parameters
canvasWSG to save changes to. Will work with any WSG, cannot be reverted
imageNew cnfsFileIdx_t to apply to the canvas
startXX position on canvas. Negative moves left, positive moves right. Pixels not on canvas are cropped.
startYY position on canvas. Negative moves left, positive moves right. Pixels not on canvas are cropped.
palPalette data to use to transform the image

◆ canvasDraw()

void canvasDraw ( wsg_t * canvas,
cnfsFileIdx_t image,
int startX,
int startY,
bool flipX,
bool flipY,
int32_t rotateDeg )

Draws an image to the canvas at a specified angle.

Parameters
canvasWSG to save changes to. Will work with any WSG, cannot be reverted
imageNew cnfsFileIdx_t to apply to the canvas
startXX position on canvas. Negative moves left, positive moves right. Pixels not on canvas are cropped.
startYY position on canvas. Negative moves left, positive moves right. Pixels not on canvas are cropped.
flipXFlips applied image in the x direction
flipYFlips applied image in the Y direction
rotateDegAngle to draw the image at

◆ canvasDrawPal()

void canvasDrawPal ( wsg_t * canvas,
cnfsFileIdx_t image,
int startX,
int startY,
bool flipX,
bool flipY,
int32_t rotateDeg,
wsgPalette_t * pal )

Draws an image to the canvas at a specified angle.

Parameters
canvasWSG to save changes to. Will work with any WSG, cannot be reverted
imageNew cnfsFileIdx_t to apply to the canvas
startXX position on canvas. Negative moves left, positive moves right. Pixels not on canvas are cropped.
startYY position on canvas. Negative moves left, positive moves right. Pixels not on canvas are cropped.
flipXFlips applied image in the x direction
flipYFlips applied image in the Y direction
rotateDegAngle to draw the image at
palPalette data to use to transform the image