wasm-canvas
HTMLCanvasElement Struct Reference

#include <canvas.h>

Collaboration diagram for HTMLCanvasElement:

Public Attributes

struct {
   CanvasRenderingContext2D *   ctx
 
   char *   id
 
private
 
int(* getHeight )(HTMLCanvasElement *this)
 
int(* getWidth )(HTMLCanvasElement *this)
 
void(* setHeight )(HTMLCanvasElement *this, int height)
 
void(* setWidth )(HTMLCanvasElement *this, int width)
 
CanvasRenderingContext2D *(* getContext )(HTMLCanvasElement *this, char *contextType)
 

Detailed Description

Struct containing state and OO-like behavior of an HTML canvas structured similarly to how it would be exposed in JavaScript. This struct should be instantiated using the createCanvas() function, and, when you're done using it, should be freed using the freeCanvas() function.

After freeing the canvas struct, the DOM element will still be present and active in HTML. In the future, it may be possible to reacquire the same canvas as a struct by calling createCanvas() with the same element id.

The real meat of this struct comes with the getContext() function pointer, which creates a canvas rendering context with drawing capabilities.

A typical use of this struct might look like the following:

HTMLCanvas *canvas = createCanvas("myCanvas");
canvas->setHeight(canvas, 1080);
canvas->setWidth(canvas, 1920);
CanvasRenderingContext2D *ctx = canvas->getContext(canvas, "2d"); // only 2d is supported currently
ctx->fillRect(ctx, 50, 75, 100, 200);
freeCanvas(canvas);

Member Data Documentation

◆ getContext

CanvasRenderingContext2D*(* HTMLCanvasElement::getContext) (HTMLCanvasElement *this, char *contextType)

Returns a drawing context for the canvas, or null if the context type is not supported. Use type "2d" (only this type is currently supported) to retrieve a CanvasRenderingContext2D.

The field retrieved by this getter function behaves like a singleton.

◆ getHeight

int(* HTMLCanvasElement::getHeight) (HTMLCanvasElement *this)

Returns a positive integer reflecting the height HTML attribute of the <canvas> element interpreted in CSS pixels. The canvas height defaults to 150.

◆ getWidth

int(* HTMLCanvasElement::getWidth) (HTMLCanvasElement *this)

Returns a positive integer reflecting the width HTML attribute of the <canvas> element interpreted in CSS pirxels. The canvas width defaults to 300.

◆ setHeight

void(* HTMLCanvasElement::setHeight) (HTMLCanvasElement *this, int height)

Sets the height HTML attribute of the <canvas> element. If an invalid value is specified, the default value of 150 is used.

◆ setWidth

void(* HTMLCanvasElement::setWidth) (HTMLCanvasElement *this, int width)

Sets the width HTML attribute of the <canvas> element. If an invalid value is specified, the default value of 300 is used.


The documentation for this struct was generated from the following file: