FabGL
ESP32 Display Controller and Graphics Library
Canvas Class Reference

A class with a set of drawing methods. More...

#include <canvas.h>

Public Member Functions

void beginUpdate ()
 Suspends drawings. More...
 
void clear ()
 Fills the entire canvas with the brush color. More...
 
void copyRect (int sourceX, int sourceY, int destX, int destY, int width, int height)
 Copies a screen rectangle to the specified position. More...
 
void drawBitmap (int X, int Y, Bitmap const *bitmap)
 Draws a bitmap at specified position. More...
 
void drawChar (int X, int Y, char c)
 Draws a character at specified position. More...
 
void drawEllipse (int X, int Y, int width, int height)
 Draws an ellipse specifying center and size, using current pen color. More...
 
void drawGlyph (int X, int Y, int width, int height, uint8_t const *data, int index=0)
 Draws a glyph at specified position. More...
 
void drawLine (int X1, int Y1, int X2, int Y2)
 Draws a line specifying initial and ending coordinates. More...
 
void drawPath (Point const *points, int pointsCount)
 Draws a sequence of lines. More...
 
void drawRectangle (int X1, int Y1, int X2, int Y2)
 Draws a rectangle using the current pen color. More...
 
void drawRectangle (Rect const &rect)
 Draws a rectangle using the current pen color. More...
 
void drawText (int X, int Y, char const *text, bool wrap=false)
 Draws a string at specified position. More...
 
void drawText (FontInfo const *fontInfo, int X, int Y, char const *text, bool wrap=false)
 Draws a string at specified position. More...
 
void drawTextFmt (int X, int Y, const char *format,...)
 Draws formatted text at specified position. More...
 
void drawTextWithEllipsis (FontInfo const *fontInfo, int X, int Y, char const *text, int maxX)
 Draws a string at specified position. Add ellipses before truncation. More...
 
void endUpdate ()
 Resumes drawings after beginUpdate(). More...
 
void fillEllipse (int X, int Y, int width, int height)
 Fills an ellipse specifying center and size, using current brush color. More...
 
void fillPath (Point const *points, int pointsCount)
 Fills the polygon enclosed in a sequence of lines. More...
 
void fillRectangle (int X1, int Y1, int X2, int Y2)
 Fills a rectangle using the current brush color. More...
 
void fillRectangle (Rect const &rect)
 Fills a rectangle using the current brush color. More...
 
Rect getClippingRect ()
 Gets last clipping rectangle set using setClippingRect(). More...
 
FontInfo const * getFontInfo ()
 Gets info about currently selected font. More...
 
int getHeight ()
 Determines the canvas height in pixels. More...
 
Point getOrigin ()
 Gets last origin set using setOrigin(). More...
 
RGB888 getPixel (int X, int Y)
 Reads the pixel at specified position. More...
 
int getWidth ()
 Determines the canvas width in pixels. More...
 
void invertRectangle (int X1, int Y1, int X2, int Y2)
 Inverts a rectangle. More...
 
void invertRectangle (Rect const &rect)
 Inverts a rectangle. More...
 
void lineTo (int X, int Y)
 Draws a line starting from current pen position. More...
 
void moveTo (int X, int Y)
 Moves current pen position to the spcified coordinates. More...
 
void reset ()
 Resets paint state and other display controller settings. More...
 
void resetGlyphOptions ()
 Resets glyph options. More...
 
void resetPaintOptions ()
 Resets paint options. More...
 
void scroll (int offsetX, int offsetY)
 Scrolls pixels horizontally and/or vertically. More...
 
void selectFont (FontInfo const *fontInfo)
 Selects a font to use for the next text drawings. More...
 
void setBrushColor (uint8_t red, uint8_t green, uint8_t blue)
 Sets brush (background) color specifying color components. More...
 
void setBrushColor (Color color)
 Sets brush (background) color using a color name. More...
 
void setBrushColor (RGB888 const &color)
 Sets brush (background) color specifying color components. More...
 
void setClippingRect (Rect const &rect)
 Sets clipping rectangle relative to the origin. More...
 
void setGlyphOptions (GlyphOptions options)
 Sets drawing options for the next glyphs. More...
 
void setLineEnds (LineEnds value)
 Sets line ends shape. More...
 
void setOrigin (int X, int Y)
 Sets the axes origin. More...
 
void setOrigin (Point const &origin)
 Sets the axes origin. More...
 
void setPaintOptions (PaintOptions options)
 Sets paint options. More...
 
void setPenColor (uint8_t red, uint8_t green, uint8_t blue)
 Sets pen (foreground) color specifying color components. More...
 
void setPenColor (Color color)
 Sets pen (foreground) color using a color name. More...
 
void setPenColor (RGB888 const &color)
 Sets pen (foreground) color specifying color components. More...
 
void setPenWidth (int value)
 Sets pen width for lines, rectangles and paths. More...
 
void setPixel (int X, int Y)
 Fills a single pixel with the pen color. More...
 
void setPixel (int X, int Y, RGB888 const &color)
 Fills a single pixel with the specified color. More...
 
void setPixel (Point const &pos, RGB888 const &color)
 Fills a single pixel with the specified color. More...
 
void setScrollingRegion (int X1, int Y1, int X2, int Y2)
 Defines the scrolling region. More...
 
void swapBuffers ()
 Swaps screen buffer when double buffering is enabled. More...
 
void swapRectangle (int X1, int Y1, int X2, int Y2)
 Swaps pen and brush colors of the specified rectangle. More...
 
int textExtent (FontInfo const *fontInfo, char const *text)
 Calculates text extension in pixels. More...
 
int textExtent (char const *text)
 Calculates text extension in pixels. More...
 
void waitCompletion (bool waitVSync=true)
 Waits for drawing queue to become empty. More...
 

Detailed Description

A class with a set of drawing methods.

This class interfaces directly to the display controller and provides a set of primitives to paint lines, circles, etc. and to scroll regions, copy rectangles and draw glyphs.
For default origin is at the top left, starting from (0, 0) up to (Canvas Width - 1, Canvas Height - 1).

Example:

// Setup pins and resolution (5 GPIOs hence we have up to 8 colors)
VGAController.begin(GPIO_NUM_22, GPIO_NUM_21, GPIO_NUM_19, GPIO_NUM_18, GPIO_NUM_5);
VGAController.setResolution(VGA_640x350_70Hz);

// Paint a green rectangle with red border
fabgl::Canvas cv(&VGAController);
cv.setPenColor(Color::BrightRed);
cv.setBrushColor(Color::BrightGreen);
cv.fillRectangle(0, 0, cv.getWidth() - 1, cv.getHeight() - 1);
cv.drawRectangle(0, 0, cv.getWidth() - 1, cv.getHeight() - 1);
Examples:
ST7789_TFT/240x240/DoubleBuffer/DoubleBuffer.ino, VGA/ClassicRacer/ClassicRacer.ino, VGA/DoubleBuffer/DoubleBuffer.ino, VGA/MouseOnScreen/MouseOnScreen.ino, VGA/Songs/Songs.ino, and VGA/SpaceInvaders/SpaceInvaders.ino.

Definition at line 70 of file canvas.h.


The documentation for this class was generated from the following files: