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

Display Class Reference

Display Class Reference

Display abstract class. More...

#include <Display.h>

Inherits Canvas.

Inherited by ILI9341, SSD1306_I2C, SSD1306_SPI, and SSD1351_SPI.

Public Types

enum  State { NOT_INITIALIZED, DISPLAY_OFF, DISPLAY_ON }
 

Represents the state of the Display.

More...

Public Member Functions

 Display (int w, int h)
 Create a Display object with the specified width and height.
virtual bool open ()=0
 Probe for the display controller and initialize it if present.
virtual void flush ()
 flush any writes to the Display
virtual Display::State state ()
 Get the current state of the Display.
virtual void state (State s)
 Set the state of the Display.
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

Display abstract class.

Used as a base class for Display objects with 2D drawing capabilites.

Definition at line 26 of file Display.h.


Member Enumeration Documentation

enum State

Represents the state of the Display.

Enumerator:
NOT_INITIALIZED 

Display has not been initialized yet.

DISPLAY_OFF 

Display is initialized and turned off.

DISPLAY_ON 

Display is initialized and turned on.

Definition at line 31 of file Display.h.


Constructor & Destructor Documentation

Display ( int  w,
int  h 
)

Create a Display object with the specified width and height.

Parameters:
wThe display width.
hThe display height.

Definition at line 19 of file Display.cpp.


Member Function Documentation

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

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 
) [inherited]

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 
) [inherited]

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, inherited]

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 
) [inherited]

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, inherited]

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, inherited]

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, inherited]

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 
) [inherited]

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,
int  w,
int  h 
) [inherited]

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 drawString ( const char *  str,
Font fnt,
int  x,
int  y 
) [inherited]

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 drawTriangle ( int  x0,
int  y0,
int  x1,
int  y1,
int  x2,
int  y2,
unsigned int  c 
) [inherited]

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, inherited]

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 
) [inherited]

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, inherited]

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 
) [inherited]

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 
) [inherited]

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.

void flush (  ) [virtual]

flush any writes to the Display

Reimplemented in ILI9341, SSD1306_I2C, SSD1306_SPI, and SSD1351_SPI.

Definition at line 24 of file Display.cpp.

int height (  ) [inherited]

Get the height of the canvas.

Returns:
The height of the canvas.

Definition at line 427 of file Canvas.cpp.

virtual bool open (  ) [pure virtual]

Probe for the display controller and initialize it if present.

Returns:
'true' if the device exists on the bus, 'false' if the device doesn't exist on the bus.

Implemented in ILI9341, SSD1306_I2C, SSD1306_SPI, and SSD1351_SPI.

void state ( State  s ) [virtual]

Set the state of the Display.

Parameters:
modeThe new state as a State enum.

Reimplemented in ILI9341, SSD1306_I2C, SSD1306_SPI, and SSD1351_SPI.

Definition at line 35 of file Display.cpp.

Display::State state (  ) [virtual]

Get the current state of the Display.

Returns:
The current state as a State enum.

Reimplemented in ILI9341, SSD1306_I2C, SSD1306_SPI, and SSD1351_SPI.

Definition at line 29 of file Display.cpp.

int width (  ) [inherited]

Get the width of the canvas.

Returns:
The width of the canvas.

Definition at line 422 of file Canvas.cpp.