A simple yet powerful library for controlling graphical displays. Multiple display controllers are supported using inheritance.

Dependents:   mbed_rifletool Hexi_Bubble_Game Hexi_Catch-the-dot_Game Hexi_Acceleromagnetic_Synth

Embed: (wiki syntax)

« Back to documentation index

Canvas Class Reference

Canvas Class Reference

Canvas abstract class. More...

#include <Canvas.h>

Inherited by Display.

Public Member Functions

 Canvas (int w, int h)
 Create a Canvas object with the specified width and height.
virtual void drawPixel (int x, int y, unsigned int c)=0
 Draw a single pixel at the specified coordinates.
virtual void clear (unsigned int c=0xFF000000)
 Fill the entire canvas with the specified color using a filled rectangle.
virtual void drawLine (int x0, int y0, int x1, int y1, unsigned int c)
 Draw a line between the specified coordinates using Bresenham's line algorithm.
virtual void drawHLine (int x, int y, int w, unsigned int c)
 Draw a fast horizontal line of the specified width, at the specified coordinates.
virtual void drawVLine (int x, int y, int h, unsigned int c)
 Draw a fast vertical line of the specified height, at the specified coordinates.
virtual void drawRect (int x, int y, int w, int h, unsigned int c)
 Draw an unfilled rectangle of the specified width and height, at the specified coordinates using fast lines.
virtual void fillRect (int x, int y, int w, int h, unsigned int c)
 Draw a filled rectangle of the specified width and height, at the specified coordinates using fast lines.
void drawTriangle (int x0, int y0, int x1, int y1, int x2, int y2, unsigned int c)
 Draw an unfilled triangle with the specified vertices using lines.
void fillTriangle (int x0, int y0, int x1, int y1, int x2, int y2, unsigned int c)
 Draw a filled triangle with the specified vertices using Adafruit's algorithm.
void drawCircle (int x, int y, int r, unsigned int c)
 Draw an unfilled circle of the specified radius, at the specified coordinates using the midpoint circle algorithm.
void fillCircle (int x, int y, int r, unsigned int c)
 Draw a filled circle of the specified radius, at the specified coordinates using Adafruit's modified midpoint circle algorithm.
void drawRoundRect (int x, int y, int w, int h, int r, unsigned int c)
 Draw an unfilled rounded rectangle of the specified width, height, and corner radius, at the specified coordinates using Adafruit's algorithm.
void fillRoundRect (int x, int y, int w, int h, int r, unsigned int c)
 Draw a filled rounded rectangle of the specified width, height, and corner radius, at the specified coordinates using Adafruit's algorithm.
void drawImage (Image *img, int x, int y)
 Draw an Image object at the specified coordinates.
int drawChar (char c, Font *fnt, int x, int y)
 Draw a character at the specified coordinates without wrapping.
void drawString (const char *str, Font *fnt, int x, int y)
 Draw a string at the specified coordinates without wrapping.
void drawString (const char *str, Font *fnt, int x, int y, int w, int h)
 Draw a string within the specified rectangle with wrapping.
int width ()
 Get the width of the canvas.
int height ()
 Get the height of the canvas.

Detailed Description

Canvas abstract class.

Used as a base class for objects that provide 2D drawing capabilities.

Definition at line 27 of file Canvas.h.


Constructor & Destructor Documentation

Canvas ( int  w,
int  h 
)

Create a Canvas object with the specified width and height.

Parameters:
wThe canvas width.
hThe canvas height.

Definition at line 19 of file Canvas.cpp.


Member Function Documentation

void clear ( unsigned int  c = 0xFF000000 ) [virtual]

Fill the entire canvas with the specified color using a filled rectangle.

Parameters:
cThe color to fill with as a 32-bit ARGB value (black by default).

Definition at line 25 of file Canvas.cpp.

int drawChar ( char  c,
Font fnt,
int  x,
int  y 
)

Draw a character at the specified coordinates without wrapping.

Parameters:
cThe character to draw.
fntPointer to the font to draw with.
xThe starting X coordinate.
yThe starting Y coordinate.
Returns:
The width of the drawn character.

Definition at line 288 of file Canvas.cpp.

void drawCircle ( int  x,
int  y,
int  r,
unsigned int  c 
)

Draw an unfilled circle of the specified radius, at the specified coordinates using the midpoint circle algorithm.

Parameters:
xThe center X coordinate.
yThe center Y coordinate.
rThe radius of the circle.
cThe color of the circle as a 32-bit ARGB value.

Definition at line 215 of file Canvas.cpp.

void drawHLine ( int  x,
int  y,
int  w,
unsigned int  c 
) [virtual]

Draw a fast horizontal line of the specified width, at the specified coordinates.

Parameters:
xThe starting X coordinate.
yThe starting Y coordinate.
wThe width of the line.
cThe color of the line as a 32-bit ARGB value.

Definition at line 80 of file Canvas.cpp.

void drawImage ( Image img,
int  x,
int  y 
)

Draw an Image object at the specified coordinates.

Parameters:
imgPointer to the image to draw.
xThe starting X coordinate.
yThe starting Y coordinate.

Definition at line 279 of file Canvas.cpp.

void drawLine ( int  x0,
int  y0,
int  x1,
int  y1,
unsigned int  c 
) [virtual]

Draw a line between the specified coordinates using Bresenham's line algorithm.

Parameters:
x0The starting X coordinate.
y0The starting Y coordinate.
x1The ending X coordinate.
y1The ending Y coordinate.
cThe color of the line as a 32-bit ARGB value.

Definition at line 30 of file Canvas.cpp.

virtual void drawPixel ( int  x,
int  y,
unsigned int  c 
) [pure virtual]

Draw a single pixel at the specified coordinates.

Parameters:
xThe X coordinate.
yThe Y coordinate.
cThe color of the pixel as a 32-bit ARGB value.

Implemented in ILI9341, SSD1306_I2C, SSD1306_SPI, and SSD1351_SPI.

void drawRect ( int  x,
int  y,
int  w,
int  h,
unsigned int  c 
) [virtual]

Draw an unfilled rectangle of the specified width and height, at the specified coordinates using fast lines.

Parameters:
xThe starting X coordinate.
yThe starting Y coordinate.
wThe width of the rectangle.
hThe height of the rectangle.
cThe color of the rectangle as a 32-bit ARGB value.

Definition at line 90 of file Canvas.cpp.

void drawRoundRect ( int  x,
int  y,
int  w,
int  h,
int  r,
unsigned int  c 
)

Draw an unfilled rounded rectangle of the specified width, height, and corner radius, at the specified coordinates using Adafruit's algorithm.

Parameters:
xThe starting X coordinate.
yThe starting Y coordinate.
wThe width of the rectangle.
hThe height of the rectangle.
rThe radius of the corners.
cThe color of the rectangle as a 32-bit ARGB value.

Definition at line 254 of file Canvas.cpp.

void drawString ( const char *  str,
Font fnt,
int  x,
int  y 
)

Draw a string at the specified coordinates without wrapping.

Parameters:
strPointer to the string to draw.
fntPointer to the font to draw with.
xThe starting X coordinate.
yThe starting Y coordinate.

Definition at line 300 of file Canvas.cpp.

void drawString ( const char *  str,
Font fnt,
int  x,
int  y,
int  w,
int  h 
)

Draw a string within the specified rectangle with wrapping.

Parameters:
strPointer to the string to draw.
fntPointer to the font to draw with.
xThe starting X coordinate.
yThe starting Y coordinate.
wThe width of the bounding rectangle.
hThe height of the bounding rectangle.

Definition at line 329 of file Canvas.cpp.

void drawTriangle ( int  x0,
int  y0,
int  x1,
int  y1,
int  x2,
int  y2,
unsigned int  c 
)

Draw an unfilled triangle with the specified vertices using lines.

Parameters:
x0The first vertex X coordinate.
y0The first vertex Y coordinate.
x1The second vertex X coordinate.
y1The second vertex Y coordinate.
x2The third vertex X coordinate.
y2The third vertex Y coordinate.
cThe color of the triangle as a 32-bit ARGB value.

Definition at line 105 of file Canvas.cpp.

void drawVLine ( int  x,
int  y,
int  h,
unsigned int  c 
) [virtual]

Draw a fast vertical line of the specified height, at the specified coordinates.

Parameters:
xThe starting X coordinate.
yThe starting Y coordinate.
hThe height of the line.
cThe color of the line as a 32-bit ARGB value.

Definition at line 85 of file Canvas.cpp.

void fillCircle ( int  x,
int  y,
int  r,
unsigned int  c 
)

Draw a filled circle of the specified radius, at the specified coordinates using Adafruit's modified midpoint circle algorithm.

Parameters:
xThe center X coordinate.
yThe center Y coordinate.
rThe radius of the circle.
cThe color of the circle as a 32-bit ARGB value.

Definition at line 248 of file Canvas.cpp.

void fillRect ( int  x,
int  y,
int  w,
int  h,
unsigned int  c 
) [virtual]

Draw a filled rectangle of the specified width and height, at the specified coordinates using fast lines.

Parameters:
xThe starting X coordinate.
yThe starting Y coordinate.
wThe width of the rectangle.
hThe height of the rectangle.
cThe color of the rectangle as a 32-bit ARGB value.

Definition at line 98 of file Canvas.cpp.

void fillRoundRect ( int  x,
int  y,
int  w,
int  h,
int  r,
unsigned int  c 
)

Draw a filled rounded rectangle of the specified width, height, and corner radius, at the specified coordinates using Adafruit's algorithm.

Parameters:
xThe starting X coordinate.
yThe starting Y coordinate.
wThe width of the rectangle.
hThe height of the rectangle.
rThe radius of the corners.
cThe color of the rectangle as a 32-bit ARGB value.

Definition at line 269 of file Canvas.cpp.

void fillTriangle ( int  x0,
int  y0,
int  x1,
int  y1,
int  x2,
int  y2,
unsigned int  c 
)

Draw a filled triangle with the specified vertices using Adafruit's algorithm.

Parameters:
x0The first vertex X coordinate.
y0The first vertex Y coordinate.
x1The second vertex X coordinate.
y1The second vertex Y coordinate.
x2The third vertex X coordinate.
y2The third vertex Y coordinate.
cThe color of the triangle as a 32-bit ARGB value.

Definition at line 112 of file Canvas.cpp.

int height (  )

Get the height of the canvas.

Returns:
The height of the canvas.

Definition at line 427 of file Canvas.cpp.

int width (  )

Get the width of the canvas.

Returns:
The width of the canvas.

Definition at line 422 of file Canvas.cpp.