5. The Canvas
The canvas is an abstraction of the bitmap buffer. Regions get drawn to the buffer via a canvas.
<<typedefs>>=
typedef struct btprnt_canvas btprnt_canvas;
It can be created with btprnt_canvas_new
, and freed with
btprnt_canvas_del
.
<<funcdefs>>=
btprnt_canvas * btprnt_canvas_new(btprnt_buf *buf);
<<funcs>>=
btprnt_canvas * btprnt_canvas_new(btprnt_buf *buf)
{
btprnt_canvas *c;
c = calloc(1, sizeof(btprnt_canvas));
if (c == NULL) return NULL;
c->buf = buf;
btprnt_canvas_offx_set(c, 0);
btprnt_canvas_offy_set(c, 0);
return c;
}
<<funcdefs>>=
void btprnt_canvas_offx_set(btprnt_canvas *c, int x);
void btprnt_canvas_offy_set(btprnt_canvas *c, int y);
<<funcs>>=
void btprnt_canvas_offx_set(btprnt_canvas *c, int x)
{
c->offx = x;
}
void btprnt_canvas_offy_set(btprnt_canvas *c, int y)
{
c->offy = y;
}
<<funcdefs>>=
void btprnt_canvas_del(btprnt_canvas **c);
<<funcs>>=
void btprnt_canvas_del(btprnt_canvas **c)
{
if (*c == NULL) return;
free(*c);
*c = NULL;
}
The main point of canvas abstraction is to provide an infinite for regions to lie on. Any pixels out of range of the buffer will be clipped by the canvas. Regions can be resized and moved around without having to worry about accessing bad memory.
<<structs>>=
struct btprnt_canvas {
btprnt_buf *buf;
int offx, offy;
};
The canvas has a global offset value. A canvas can be moved around to make regions or less visible.
prev | home | next