Skip to content
kio edited this page Oct 5, 2026 · 2 revisions

Canvas, Pixmap and Pixmap_wAttr


class Canvas

header file: Graphics/Canvas.h

class Canvas is the virtual base class for all Pixmaps. It defines a bunch of virtual methods and provides some useful primitives by itself. These are the main functions. There are more and most come in even more variants:

	/* _______________________________________________________________________________________
	   create shared, dependent instance of the entire pixmap or a window:
		x and w must result in multiples of full byte, e.g. for bitmaps 8*N.
	*/
	virtual Canvas* cloneWindow(coord x, coord y, coord w, coord h) throws = 0;

	/* _______________________________________________________________________________________
	   set and get single pixels:
		In attribute modes the color is stored in attributes[] and the ink in pixels[].
		In direct color modes the color is stored in pixels[] and there are no attributes[]. 
			-> set_pixel() ignores `ink`, and getters always return data from pixels[].
	*/
	virtual void set_pixel(coord x, coord y, uint color, uint ink = 1) noexcept = 0;
	virtual uint get_pixel(coord x, coord y, uint* ink) const noexcept			= 0;
	virtual uint get_color(coord x, coord y) const noexcept						= 0;
	virtual uint get_ink(coord x, coord y) const noexcept						= 0;

	/* _______________________________________________________________________________________
	   draw lines:
		- draw nothing if width or height is <= 0.
		- draw_hline_to(): no clipping test!
		- draw_vline_to(): no clipping test!
		- drawHLine():  draw horizontal line
		- drawVLine():  draw vertical line
	*/
	virtual void draw_hline_to(coord x, coord y, coord x2, uint color, uint ink = 1) noexcept;
	virtual void draw_vline_to(coord x, coord y, coord y2, uint color, uint ink = 1) noexcept;

	void drawHLine(coord x, coord y, coord w, uint color, uint ink = 1) noexcept;
	void drawVLine(coord x, coord y, coord h, uint color, uint ink = 1) noexcept;
	void drawHLineTo(coord x, coord y, coord x2, uint color, uint ink = 1) noexcept;
	void drawVLineTo(coord x, coord y, coord y2, uint color, uint ink = 1) noexcept;

	/* _______________________________________________________________________________________
	   paint rectangular area:
		- fillRect(): paint rectangular area
		- xorRect():  xor all colors in the rect area with the xorColor
		              Pixmap_wAttr: xor colors of all inks in the attributes[]
		- clear():    entire pixmap, in attr modes also all inks 
	*/
	virtual void fillRect(coord x, coord y, coord w, coord h, uint color, uint ink = 1) noexcept;
	virtual void xorRect(coord x, coord y, coord w, coord h, uint color) noexcept;
	virtual void clear(uint color) noexcept;

	/* _______________________________________________________________________________________
	   copy rectangular area:
		- copy pixels inside a pixmap. Source and target area may overlap
		- copy pixels from other pixmap. Source and target must have same ColorMode
	*/
	virtual void copyRect(coord zx, coord zy, coord qx, coord qy, coord w, coord h) noexcept;
	virtual void copyRect(coord zx, coord zy, const Canvas& src, coord qx, coord qy, coord w, coord h) noexcept;

	/* _______________________________________________________________________________________
	   copy bitmaps:
	   - drawBmp():  draw rectangular area from bitmap: set `1` bits with color, skip `0` bits
	   - readBmp():  read rect area into bitmap. 
						set=0: `color` is background => clear bit in bmp for pixel == color
						set=1: `color` is foreground => set bit in bmp for pixel == color
	   - drawChar(): variant of drawBmp() which assumes: w = 8, row_offset = 1, x%8 = 0
	*/
	virtual void readBmp(coord x, coord y, uint8* bmp, int row_offs, coord w, coord h, uint color, bool set) noexcept;
	virtual void drawBmp(coord zx, coord zy, const uint8* bmp, int ro, coord w, coord h, uint color, uint = 1) noexcept;
	virtual void drawChar(coord zx, coord zy, const uint8* bmp, coord h, uint color, uint = 1) noexcept;

	/* _______________________________________________________________________________________
	   more drawing primitives:
	*/
	void drawLine(coord x1, coord y1, coord x2, coord y2, uint color, uint ink = 1) noexcept;
	void drawRect(coord x, coord y, coord w, coord h, uint color, uint ink = 1) noexcept;
	void drawCircle(coord x, coord y, coord w, coord h, uint color, uint ink = 1) noexcept;
	void fillCircle(coord x, coord y, coord w, coord h, uint color, uint ink = 1) noexcept;
	void floodFill(coord x, coord y, uint color, uint ink = 1);
	void drawPolygon(const Point*, uint cnt, uint color, uint ink = 1) noexcept;
	void drawTriangle(const Point& p1, const Point& p2, const Point& p3, uint color, uint ink = 1) noexcept;
	void fillTriangle(Point p1, Point p2, Point p3, uint color, uint ink = 1) noexcept;
	void fillPolygon(const Point*, uint cnt, uint color, uint ink = 1);
	void drawBezier_f(const Point& p1, const Point& p2, const Point& p3, const Point& p4, uint c, uint i = 1) noexcept;
	void drawBezier(const Point& p1, const Point& p2, const Point& p3, const Point& p4, uint c, uint i = 1) noexcept;

template class Pixmap

header file: Graphics/Pixmap.h


#template class Pixmap_wAttr header file: Graphics/Pixmap_wAttr.h

Clone this wiki locally