ESP32VGA
ESP32 VGA Controller and Graphics Library
|
A class with a set of drawing methods. More...
#include <canvas.h>
Public Member Functions | |
uint16_t | getWidth () |
Return the canvas width in pixels. This is equivalent to VGA Controller viewport width. | |
uint16_t | getHeight () |
Return the canvas height in pixels. This is equivalent to VGA Controller viewport height. | |
void | clear () |
Fill the entire canvas with the brush color. | |
void | setScrollingRegion (int16_t X1, int16_t Y1, int16_t X2, int16_t Y2) |
Define the scrolling region. More... | |
void | scroll (int16_t offsetX, int16_t offsetY) |
Scroll pixels horizontally and/or vertically. More... | |
void | moveTo (int16_t X, int16_t Y) |
Move current pen position to the spcified coordinates. More... | |
void | setPenColor (uint8_t red, uint8_t green, uint8_t blue) |
Set pen (foreground) color specifying color components. More... | |
void | setPenColor (Color color) |
Set pen (foreground) color using a color name. More... | |
void | setBrushColor (uint8_t red, uint8_t green, uint8_t blue) |
Set brush (background) color specifying color components. More... | |
void | setBrushColor (Color color) |
Set brush (background) color using a color name. More... | |
void | setPixel (int16_t X, int16_t Y) |
Fill a single pixel with the pen color. More... | |
void | lineTo (int16_t X, int16_t Y) |
Draw a line starting from current pen position. More... | |
void | drawLine (int16_t X1, int16_t Y1, int16_t X2, int16_t Y2) |
Draw a line specifying initial and ending coordinates. More... | |
void | drawRectangle (int16_t X1, int16_t Y1, int16_t X2, int16_t Y2) |
Draw a rectangle using the current pen color. More... | |
void | fillRectangle (int16_t X1, int16_t Y1, int16_t X2, int16_t Y2) |
Fill a rectangle using the current brush color. More... | |
void | swapRectangle (int16_t X1, int16_t Y1, int16_t X2, int16_t Y2) |
Swap pen and brush colors of the specified rectangle. More... | |
void | drawEllipse (int16_t X, int16_t Y, uint16_t width, uint16_t height) |
Draw an ellipse specifying center and size, using current pen color. More... | |
void | fillEllipse (int16_t X, int16_t Y, uint16_t width, uint16_t height) |
Fill an ellipse specifying center and size, using current brush color. More... | |
void | waitCompletion (bool waitVSync=true) |
Wait for drawing queue to become empty. More... | |
void | drawGlyph (int16_t X, int16_t Y, uint16_t width, uint16_t height, uint8_t const *data, uint16_t index=0) |
Draw a glyph at specified position. More... | |
void | setGlyphOptions (GlyphOptions options) |
Set drawing options for the next glyphs. More... | |
Static Public Member Functions | |
static FontInfo const * | getPresetFontInfo (int columns, int rows) |
Get the font info that best fits the specified number of columns and rows. More... | |
A class with a set of drawing methods.
This class interfaces directly to the VGA controller and provides a set of primitives to paint lines, circles, etc. and to scroll regions, copy rectangles and draw glyphs. Origins are at 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 Canvas.setPenColor(Color::BrightRed); Canvas.setBrushColor(Color::BrightGreen); Canvas.fillRectangle(0, 0, Canvas.getWidth() - 1, Canvas.getHeight() - 1); Canvas.drawRectangle(0, 0, Canvas.getWidth() - 1, Canvas.getHeight() - 1);
void FabGL::CanvasClass::drawEllipse | ( | int16_t | X, |
int16_t | Y, | ||
uint16_t | width, | ||
uint16_t | height | ||
) |
Draw an ellipse specifying center and size, using current pen color.
X | Horizontal coordinate of the ellipse center. |
Y | Vertical coordinate of the ellipse center. |
width | Ellipse width. |
height | Ellipse height. |
Example:
// Paint a yellow ellipse Canvas.setPenColor(Color::BrightYellow); Canvas.drawEllipse(100, 100, 40, 40);
void FabGL::CanvasClass::drawGlyph | ( | int16_t | X, |
int16_t | Y, | ||
uint16_t | width, | ||
uint16_t | height, | ||
uint8_t const * | data, | ||
uint16_t | index = 0 |
||
) |
Draw a glyph at specified position.
Glyph is a bitmap (1 bit per pixel) that can be painted using pen (foreground) and brush (background) colors. Various drawing options can be set using CanvasClass.setGlyphOptions() method. Glyphs are used by TerminalClass to render characters.
X | Horizontal coordinate where to draw the glyph. |
Y | Vertical coordinate where to draw the glyph. |
width | Horizontal size of the glyph. |
height | Vertical size of the glyph. |
data | Memory buffer containing the glyph. Each line is byte aligned. The size must be "(width + 7) / 8 * height" (integer division!). |
index | Optional index inside data. Use when the buffer contains multiple glyphs. |
Example:
// draw an 'A' using the predefined font to fit 80x25 screen text Canvas.setPenColor(Color::BrightGreen); const FabGL::FontInfo * f = Canvas.getPresetFontInfo(80, 25); Canvas.drawGlyph(0, 0, f->width, f->height, f->data, 0x41); // draw a 12x8 sprite const uint8_t enemy[] = { 0x0f, 0x00, 0x7f, 0xe0, 0xff, 0xf0, 0xe6, 0x70, 0xff, 0xf0, 0x39, 0xc0, 0x66, 0x60, 0x30, 0xc0, }; Canvas.setPenColor(Color::BrightYellow); Canvas.drawGlyph(50, 80, 12, 8, enemy);
void FabGL::CanvasClass::drawLine | ( | int16_t | X1, |
int16_t | Y1, | ||
int16_t | X2, | ||
int16_t | Y2 | ||
) |
Draw a line specifying initial and ending coordinates.
The line has the current pen color.
X1 | Starting horizontal coordinate. |
Y1 | Starting vertical coordinate. |
X2 | Ending horizontal coordinate. |
Y2 | Ending vertical coordinate. |
Example:
// Paint a blue X over the whole canvas Canvas.setPenColor(Color::BrightBlue); Canvas.drawLine(0, 0, Canvas.getWidth() - 1, Canvas.getHeight() - 1); Canvas.drawLine(Canvas.getWidth() - 1, 0, 0, Canvas.getHeight() - 1);
void FabGL::CanvasClass::drawRectangle | ( | int16_t | X1, |
int16_t | Y1, | ||
int16_t | X2, | ||
int16_t | Y2 | ||
) |
Draw a rectangle using the current pen color.
X1 | Top left horizontal coordinate. |
Y1 | Top left vertical coordiante. |
X2 | Bottom right horizontal coordinate. |
Y2 | Bottom right vertical coordiante. |
Example:
// Paint a yellow rectangle Canvas.setPenColor(Color::BrightYellow); Canvas.drawRectangle(10, 10, 100, 100);
void FabGL::CanvasClass::fillEllipse | ( | int16_t | X, |
int16_t | Y, | ||
uint16_t | width, | ||
uint16_t | height | ||
) |
Fill an ellipse specifying center and size, using current brush color.
X | Horizontal coordinate of the ellipse center. |
Y | Vertical coordinate of the ellipse center. |
width | Ellipse width. |
height | Ellipse height. |
Example:
// Paint a filled yellow ellipse Canvas.setBrushColor(Color::BrightYellow); Canvas.fillEllipse(100, 100, 40, 40); // Paint a yellow ellipse with blue border Canvas.setPenColor(Color::BrightBlue); Canvas.setBrushColor(Color::BrightYellow); Canvas.fillEllipse(100, 100, 40, 40); Canvas.drawEllipse(100, 100, 40, 40);
void FabGL::CanvasClass::fillRectangle | ( | int16_t | X1, |
int16_t | Y1, | ||
int16_t | X2, | ||
int16_t | Y2 | ||
) |
Fill a rectangle using the current brush color.
X1 | Top left horizontal coordinate. |
Y1 | Top left vertical coordiante. |
X2 | Bottom right horizontal coordinate. |
Y2 | Bottom right vertical coordiante. |
Example:
// Paint a filled yellow rectangle Canvas.setBrushColor(Color::BrightYellow); Canvas.fillRectangle(10, 10, 100, 100); // Paint a yellow rectangle with blue border Canvas.setPenColor(Color::BrightBlue); Canvas.setBrushColor(Color::BrightYellow); Canvas.fillRectangle(10, 10, 100, 100); Canvas.drawRectangle(10, 10, 100, 100);
|
static |
Get the font info that best fits the specified number of columns and rows.
columns | Minimum number of required columns. |
rows | Minimum number of required rows. |
void FabGL::CanvasClass::lineTo | ( | int16_t | X, |
int16_t | Y | ||
) |
Draw a line starting from current pen position.
Starting pen position is specified using CanvasClass.moveTo() method or from ending position of the last call to CanvasClass.lineTo(). The line has the current pen color.
X | Horizontal ending line position. |
Y | Vertical ending line position. |
Example:
// Paint white a triangle Canvas.setPenColor(Color::BrightWhite); Canvas.moveTo(10, 12); Canvas.lineTo(30, 40); Canvas.lineTo(10, 12);
void FabGL::CanvasClass::moveTo | ( | int16_t | X, |
int16_t | Y | ||
) |
Move current pen position to the spcified coordinates.
Some methods expect initial pen position to be specified, like Canvas.lineTo().
X | Horizontal pen position. |
Y | Vertical pen position. |
Example:
// Paint a triangle Canvas.moveTo(10, 12); Canvas.lineTo(30, 40); Canvas.lineTo(10, 12);
void FabGL::CanvasClass::scroll | ( | int16_t | offsetX, |
int16_t | offsetY | ||
) |
Scroll pixels horizontally and/or vertically.
Scrolling occurs inside the scrolling region defined by CanvasClass.setScrollingRegion(). Vertical scroll is done moving line pointers, so it is very fast to perform. Horizontal scroll is done moving pixel by pixel (CPU intensive task).
offsetX | Number of pixels to scroll left (offsetX < 0) or right (offsetX > 0). |
offsetY | Number of pixels to scroll up (offsetY < 0) or down (offsetY > 0). |
void FabGL::CanvasClass::setBrushColor | ( | uint8_t | red, |
uint8_t | green, | ||
uint8_t | blue | ||
) |
Set brush (background) color specifying color components.
red | Red color component. Minimum value is 0, maximum value is 1 with 8 colors and 3 with 64 colors. |
green | Green color component. Minimum value is 0, maximum value is 1 with 8 colors and 3 with 64 colors. |
blue | Blue color component. Minimum value is 0, maximum value is 1 with 8 colors and 3 with 64 colors. |
Example:
// Set blue brush with 8 colors setup Canvas.setBrushColor(0, 0, 1); // Set blue brush with 64 colors setup Canvas.setBrushColor(0, 0, 3);
void FabGL::CanvasClass::setBrushColor | ( | Color | color | ) |
Set brush (background) color using a color name.
color | The color name. |
Example:
// Set blue brush Canvas.setBrushColor(Color::BrightBlue);
void FabGL::CanvasClass::setGlyphOptions | ( | GlyphOptions | options | ) |
Set drawing options for the next glyphs.
Setting glyph options allows to slightly change how a glyph is rendered, applying effects like Bold, Italic, Inversion, double width or height and so on. Because FabGL::CanvasClass draws text using glyphs these options affects also how text is rendered.
options | A bit field to specify multiple options |
Example:
// Draw "Hello World!" Canvas.setGlyphOptions(GlyphOptions().FillBackground(true).DoubleWidth(1)); Canvas.drawText(20, 20, "Hello World!");
void FabGL::CanvasClass::setPenColor | ( | uint8_t | red, |
uint8_t | green, | ||
uint8_t | blue | ||
) |
Set pen (foreground) color specifying color components.
red | Red color component. Minimum value is 0, maximum value is 1 with 8 colors and 3 with 64 colors. |
green | Green color component. Minimum value is 0, maximum value is 1 with 8 colors and 3 with 64 colors. |
blue | Blue color component. Minimum value is 0, maximum value is 1 with 8 colors and 3 with 64 colors. |
Example:
// Set white pen with 8 colors setup Canvas.setPenColor(1, 1, 1); // Set white pen with 64 colors setup Canvas.setPenColor(3, 3, 3);
void FabGL::CanvasClass::setPenColor | ( | Color | color | ) |
Set pen (foreground) color using a color name.
color | Color name. |
Example:
// Set white pen Canvas.setPenColor(Color::BrightWhite);
void FabGL::CanvasClass::setPixel | ( | int16_t | X, |
int16_t | Y | ||
) |
Fill a single pixel with the pen color.
X | Horizontal pixel position. |
Y | Vertical pixel position. |
void FabGL::CanvasClass::setScrollingRegion | ( | int16_t | X1, |
int16_t | Y1, | ||
int16_t | X2, | ||
int16_t | Y2 | ||
) |
Define the scrolling region.
A scrolling region is the rectangle area where CanvasClass.scroll() method can operate.
X1 | Top left horizontal coordinate. |
Y1 | Top left vertical coordiante. |
X2 | Bottom right horizontal coordinate. |
Y2 | Bottom right vertical coordiante. |
void FabGL::CanvasClass::swapRectangle | ( | int16_t | X1, |
int16_t | Y1, | ||
int16_t | X2, | ||
int16_t | Y2 | ||
) |
Swap pen and brush colors of the specified rectangle.
X1 | Top left horizontal coordinate. |
Y1 | Top left vertical coordiante. |
X2 | Bottom right horizontal coordinate. |
Y2 | Bottom right vertical coordiante. |
void FabGL::CanvasClass::waitCompletion | ( | bool | waitVSync = true | ) |
Wait for drawing queue to become empty.
waitVSync | If true drawings are done on vertical retracing (slow), if false drawings are perfomed immediately (fast with flickering). |