Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
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:
-
w The canvas width. h The 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:
-
c The 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:
-
c The character to draw. fnt Pointer to the font to draw with. x The starting X coordinate. y The 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:
-
x The center X coordinate. y The center Y coordinate. r The radius of the circle. c The 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:
-
x The starting X coordinate. y The starting Y coordinate. w The width of the line. c The 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:
-
img Pointer to the image to draw. x The starting X coordinate. y The 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:
-
x0 The starting X coordinate. y0 The starting Y coordinate. x1 The ending X coordinate. y1 The ending Y coordinate. c The 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:
-
x The X coordinate. y The Y coordinate. c The color of the pixel as a 32-bit ARGB value.
Implemented in ILI9163, ILI9341, SEPS525_SPI, SSD1306_I2C, SSD1306_SPI, SSD1351_SPI, and SSD1353_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:
-
x The starting X coordinate. y The starting Y coordinate. w The width of the rectangle. h The height of the rectangle. c The 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:
-
x The starting X coordinate. y The starting Y coordinate. w The width of the rectangle. h The height of the rectangle. r The radius of the corners. c The 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:
-
str Pointer to the string to draw. fnt Pointer to the font to draw with. x The starting X coordinate. y The 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:
-
str Pointer to the string to draw. fnt Pointer to the font to draw with. x The starting X coordinate. y The starting Y coordinate. w The width of the bounding rectangle. h The 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:
-
x0 The first vertex X coordinate. y0 The first vertex Y coordinate. x1 The second vertex X coordinate. y1 The second vertex Y coordinate. x2 The third vertex X coordinate. y2 The third vertex Y coordinate. c The 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:
-
x The starting X coordinate. y The starting Y coordinate. h The height of the line. c The 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:
-
x The center X coordinate. y The center Y coordinate. r The radius of the circle. c The 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:
-
x The starting X coordinate. y The starting Y coordinate. w The width of the rectangle. h The height of the rectangle. c The 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:
-
x The starting X coordinate. y The starting Y coordinate. w The width of the rectangle. h The height of the rectangle. r The radius of the corners. c The 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:
-
x0 The first vertex X coordinate. y0 The first vertex Y coordinate. x1 The second vertex X coordinate. y1 The second vertex Y coordinate. x2 The third vertex X coordinate. y2 The third vertex Y coordinate. c The 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.
Generated on Tue Jul 12 2022 21:38:03 by
1.7.2