ESP32VGA
ESP32 VGA Controller and Graphics Library
Public Member Functions | Static Public Member Functions | List of all members
ESP32VGA::VGACanvasClass Class Reference

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

#include <VGACanvas.h>

Public Member Functions

uint16_t getWidth ()
 Returns the canvas width in pixels. This is equivalent to VGA Controller viewport width.
 
uint16_t getHeight ()
 Returns the canvas height in pixels. This is equivalent to VGA Controller viewport height.
 
void clear ()
 Fills the entire canvas with the brush color.
 
void setScrollingRegion (int16_t X1, int16_t Y1, int16_t X2, int16_t Y2)
 Defines the scrolling region. More...
 
void scroll (int16_t offsetX, int16_t offsetY)
 Scrolls pixels horizontally and/or vertically. More...
 
void moveTo (int16_t X, int16_t Y)
 Moves current pen position to the spcified coordinates. 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 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 setPixel (int16_t X, int16_t Y)
 Fills a single pixel with the pen color. More...
 
void lineTo (int16_t X, int16_t Y)
 Draws a line starting from current pen position. More...
 
void drawLine (int16_t X1, int16_t Y1, int16_t X2, int16_t Y2)
 Draws a line specifying initial and ending coordinates. More...
 
void drawRectangle (int16_t X1, int16_t Y1, int16_t X2, int16_t Y2)
 Draws a rectangle using the current pen color. More...
 
void fillRectangle (int16_t X1, int16_t Y1, int16_t X2, int16_t Y2)
 Fills a rectangle using the current brush color. More...
 
void swapRectangle (int16_t X1, int16_t Y1, int16_t X2, int16_t Y2)
 Swaps pen and brush colors of the specified rectangle. More...
 
void drawEllipse (int16_t X, int16_t Y, uint16_t width, uint16_t height)
 Draws 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)
 Fills an ellipse specifying center and size, using current brush color. More...
 
void waitCompletion (bool waitVSync=true)
 Waits 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)
 Draws a glyph at specified position. More...
 

Static Public Member Functions

static FontInfo const * getPresetFontInfo (uint8_t columns)
 Gets the font info that best fits the specified number of columns. More...
 

Detailed Description

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
VGACanvas.setPenColor(Color::BrightRed);
VGACanvas.setBrushColor(Color::BrightGreen);
VGACanvas.fillRectangle(0, 0, VGACanvas.getWidth() - 1, VGACanvas.getHeight() - 1);
VGACanvas.drawRectangle(0, 0, VGACanvas.getWidth() - 1, VGACanvas.getHeight() - 1);

Member Function Documentation

◆ drawEllipse()

void ESP32VGA::VGACanvasClass::drawEllipse ( int16_t  X,
int16_t  Y,
uint16_t  width,
uint16_t  height 
)

Draws an ellipse specifying center and size, using current pen color.

Parameters
XHorizontal coordinate of the ellipse center.
YVertical coordinate of the ellipse center.
widthEllipse width.
heightEllipse height.

Example:

// Paint a yellow ellipse
VGACanvas.setPenColor(Color::BrightYellow);
VGACanvas.drawEllipse(100, 100, 40, 40);

◆ drawGlyph()

void ESP32VGA::VGACanvasClass::drawGlyph ( int16_t  X,
int16_t  Y,
uint16_t  width,
uint16_t  height,
uint8_t const *  data,
uint16_t  index = 0 
)

Draws 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 VGACanvasClass.setGlyphOptions() method. Glyphs are used by VGATerminalClass to render characters.

Parameters
XHorizontal coordinate where to draw the glyph.
YVertical coordinate where to draw the glyph.
widthHorizontal size of the glyph.
heightVertical size of the glyph.
dataMemory buffer containing the glyph. Each line is byte aligned. The size must be "(width + 7) / 8 * height" (integer division!).
indexOptional index inside data. Use when the buffer contains multiple glyphs.

Example:

// draw an 'A' using the predefined 80 columns font
VGACanvas.setPenColor(Color::BrightGreen);
const ESP32VGA::FontInfo * f = VGACanvas.getPresetFontInfo(80);
VGACanvas.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,
};
VGACanvas.setPenColor(Color::BrightYellow);
VGACanvas.drawGlyph(50, 80, 12, 8, enemy);

◆ drawLine()

void ESP32VGA::VGACanvasClass::drawLine ( int16_t  X1,
int16_t  Y1,
int16_t  X2,
int16_t  Y2 
)

Draws a line specifying initial and ending coordinates.

The line has the current pen color.

Parameters
X1Starting horizontal coordinate.
Y1Starting vertical coordinate.
X2Ending horizontal coordinate.
Y2Ending vertical coordinate.

Example:

// Paint a blue X over the whole canvas
VGACanvas.setPenColor(Color::BrightBlue);
VGACanvas.drawLine(0, 0, VGACanvas.getWidth() - 1, VGACanvas.getHeight() - 1);
VGACanvas.drawLine(VGACanvas.getWidth() - 1, 0, 0, VGACanvas.getHeight() - 1);

◆ drawRectangle()

void ESP32VGA::VGACanvasClass::drawRectangle ( int16_t  X1,
int16_t  Y1,
int16_t  X2,
int16_t  Y2 
)

Draws a rectangle using the current pen color.

Parameters
X1Top left horizontal coordinate.
Y1Top left vertical coordiante.
X2Bottom right horizontal coordinate.
Y2Bottom right vertical coordiante.

Example:

// Paint a yellow rectangle
VGACanvas.setPenColor(Color::BrightYellow);
VGACanvas.drawRectangle(10, 10, 100, 100);

◆ fillEllipse()

void ESP32VGA::VGACanvasClass::fillEllipse ( int16_t  X,
int16_t  Y,
uint16_t  width,
uint16_t  height 
)

Fills an ellipse specifying center and size, using current brush color.

Parameters
XHorizontal coordinate of the ellipse center.
YVertical coordinate of the ellipse center.
widthEllipse width.
heightEllipse height.

Example:

// Paint a filled yellow ellipse
VGACanvas.setBrushColor(Color::BrightYellow);
VGACanvas.fillEllipse(100, 100, 40, 40);

// Paint a yellow ellipse with blue border
VGACanvas.setPenColor(Color::BrightBlue);
VGACanvas.setBrushColor(Color::BrightYellow);
VGACanvas.fillEllipse(100, 100, 40, 40);
VGACanvas.drawEllipse(100, 100, 40, 40);

◆ fillRectangle()

void ESP32VGA::VGACanvasClass::fillRectangle ( int16_t  X1,
int16_t  Y1,
int16_t  X2,
int16_t  Y2 
)

Fills a rectangle using the current brush color.

Parameters
X1Top left horizontal coordinate.
Y1Top left vertical coordiante.
X2Bottom right horizontal coordinate.
Y2Bottom right vertical coordiante.

Example:

// Paint a filled yellow rectangle
VGACanvas.setBrushColor(Color::BrightYellow);
VGACanvas.fillRectangle(10, 10, 100, 100);

// Paint a yellow rectangle with blue border
VGACanvas.setPenColor(Color::BrightBlue);
VGACanvas.setBrushColor(Color::BrightYellow);
VGACanvas.fillRectangle(10, 10, 100, 100);
VGACanvas.drawRectangle(10, 10, 100, 100);

◆ getPresetFontInfo()

FontInfo const * ESP32VGA::VGACanvasClass::getPresetFontInfo ( uint8_t  columns)
static

Gets the font info that best fits the specified number of columns.

Look at VGADEFAULT80COLUMNS_FONTPATH, VGADEFAULT80COLUMNS_FONTNAME, VGADEFAULT132COLUMNS_FONTPATH and VGADEFAULT132COLUMNS_FONTNAME in VGAConf.h to know which fonts are the preset fonts.

Parameters
columnsNumber of columns (80 or 132).
Returns
The font info of the preset font.

◆ lineTo()

void ESP32VGA::VGACanvasClass::lineTo ( int16_t  X,
int16_t  Y 
)

Draws a line starting from current pen position.

Starting pen position is specified using VGACanvasClass.moveTo() method or from ending position of the last call to VGACanvasClass.lineTo(). The line has the current pen color.

Parameters
XHorizontal ending line position.
YVertical ending line position.

Example:

// Paint white a triangle
VGACanvas.setPenColor(Color::BrightWhite);
VGACanvas.moveTo(10, 12);
VGACanvas.lineTo(30, 40);
VGACanvas.lineTo(10, 12);

◆ moveTo()

void ESP32VGA::VGACanvasClass::moveTo ( int16_t  X,
int16_t  Y 
)

Moves current pen position to the spcified coordinates.

Some methods expect initial pen position to be specified, like VGACanvas.lineTo().

Parameters
XHorizontal pen position.
YVertical pen position.

Example:

// Paint a triangle
VGACanvas.moveTo(10, 12);
VGACanvas.lineTo(30, 40);
VGACanvas.lineTo(10, 12);

◆ scroll()

void ESP32VGA::VGACanvasClass::scroll ( int16_t  offsetX,
int16_t  offsetY 
)

Scrolls pixels horizontally and/or vertically.

Scrolling occurs inside the scrolling region defined by VGACanvasClass.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).

Parameters
offsetXNumber of pixels to scroll left (offsetX < 0) or right (offsetX > 0).
offsetYNumber of pixels to scroll up (offsetY < 0) or down (offsetY > 0).

◆ setBrushColor() [1/2]

void ESP32VGA::VGACanvasClass::setBrushColor ( uint8_t  red,
uint8_t  green,
uint8_t  blue 
)

Sets brush (background) color specifying color components.

Parameters
redRed color component. Minimum value is 0, maximum value is 1 with 8 colors and 3 with 64 colors.
greenGreen color component. Minimum value is 0, maximum value is 1 with 8 colors and 3 with 64 colors.
blueBlue 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
VGACanvas.setBrushColor(0, 0, 1);

// Set blue brush with 64 colors setup
VGACanvas.setBrushColor(0, 0, 3);

◆ setBrushColor() [2/2]

void ESP32VGA::VGACanvasClass::setBrushColor ( Color  color)

Sets brush (background) color using a color name.

Parameters
colorColor name.

Example:

 // Set blue brush
 VGACanvas.setBrushColor(Color::BrightBlue);

◆ setPenColor() [1/2]

void ESP32VGA::VGACanvasClass::setPenColor ( uint8_t  red,
uint8_t  green,
uint8_t  blue 
)

Sets pen (foreground) color specifying color components.

Parameters
redRed color component. Minimum value is 0, maximum value is 1 with 8 colors and 3 with 64 colors.
greenGreen color component. Minimum value is 0, maximum value is 1 with 8 colors and 3 with 64 colors.
blueBlue 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
VGACanvas.setPenColor(1, 1, 1);

// Set white pen with 64 colors setup
VGACanvas.setPenColor(3, 3, 3);

◆ setPenColor() [2/2]

void ESP32VGA::VGACanvasClass::setPenColor ( Color  color)

Sets pen (foreground) color using a color name.

Parameters
colorColor name.

Example:

 // Set white pen
 VGACanvas.setPenColor(Color::BrightWhite);

◆ setPixel()

void ESP32VGA::VGACanvasClass::setPixel ( int16_t  X,
int16_t  Y 
)

Fills a single pixel with the pen color.

Parameters
XHorizontal pixel position.
YVertical pixel position.

◆ setScrollingRegion()

void ESP32VGA::VGACanvasClass::setScrollingRegion ( int16_t  X1,
int16_t  Y1,
int16_t  X2,
int16_t  Y2 
)

Defines the scrolling region.

A scrolling region is the rectangle area where VGACanvasClass.scroll() method can operate.

Parameters
X1Top left horizontal coordinate.
Y1Top left vertical coordiante.
X2Bottom right horizontal coordinate.
Y2Bottom right vertical coordiante.

◆ swapRectangle()

void ESP32VGA::VGACanvasClass::swapRectangle ( int16_t  X1,
int16_t  Y1,
int16_t  X2,
int16_t  Y2 
)

Swaps pen and brush colors of the specified rectangle.

Parameters
X1Top left horizontal coordinate.
Y1Top left vertical coordiante.
X2Bottom right horizontal coordinate.
Y2Bottom right vertical coordiante.

◆ waitCompletion()

void ESP32VGA::VGACanvasClass::waitCompletion ( bool  waitVSync = true)

Waits for drawing queue to become empty.

Parameters
waitVSyncIf true drawings are done on vertical retracing (slow), if false drawings are perfomed immediately (fast with flickering).

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