LCDGFX LCD display driver  1.2.0
Lightweight graphics library for SSD1306, SSD1325, SSD1327, SSD1331, SSD1351, SH1106, SH1107, IL9163, ST7735, ST7789, ILI9341, PCD8544 displays over I2C/SPI
NanoCanvasOps< BPP > Class Template Reference

NanoCanvasOps provides operations for drawing in memory buffer. More...

#include <canvas.h>

Inheritance diagram for NanoCanvasOps< BPP >:
Collaboration diagram for NanoCanvasOps< BPP >:

Public Types

typedef NanoCanvasOps< BPP > T
 Base type for canvas class specific operations.
 

Public Member Functions

 NanoCanvasOps ()
 Creates new empty canvas object. More...
 
 NanoCanvasOps (lcdint_t w, lcdint_t h, uint8_t *bytes)
 Creates new canvas object. More...
 
void begin (lcdint_t w, lcdint_t h, uint8_t *bytes)
 Initializes canvas object. More...
 
void setOffset (lcdint_t ox, lcdint_t oy)
 Sets offset. More...
 
const NanoPoint offsetEnd () const
 Returns right-bottom point of the canvas in offset terms. More...
 
const NanoRect rect () const
 Returns rectangle area, covered by canvas in offset terms. More...
 
void putPixel (lcdint_t x, lcdint_t y)
 Draws pixel on specified position. More...
 
void putPixel (const NanoPoint &p)
 Draws pixel on specified position. More...
 
void drawVLine (lcdint_t x1, lcdint_t y1, lcdint_t y2)
 Draws vertical line from (x1,y1) to (x1,y2). More...
 
void drawHLine (lcdint_t x1, lcdint_t y1, lcdint_t x2)
 Draws horizontal line from (x1,y1) to (x2,y1). More...
 
void drawLine (lcdint_t x1, lcdint_t y1, lcdint_t x2, lcdint_t y2)
 Draws a line between two points using Bresenham's algorithm. More...
 
void drawLine (const NanoRect &rect)
 Draws line. More...
 
void drawRect (lcdint_t x1, lcdint_t y1, lcdint_t x2, lcdint_t y2) __attribute__((noinline))
 Draws rectangle outline. More...
 
void drawRect (const NanoRect &rect)
 Draws rectangle outline using NanoRect structure. More...
 
void fillRect (lcdint_t x1, lcdint_t y1, lcdint_t x2, lcdint_t y2) __attribute__((noinline))
 Fills a rectangular area with the current color. More...
 
void fillRect (const NanoRect &rect)
 Fills a rectangular area with the current color. More...
 
void drawCircle (lcdint_t x, lcdint_t y, lcdint_t r, uint8_t options=0x0F) __attribute__((noinline))
 Draws circle outline. More...
 
void drawBitmap1 (lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap) __attribute__((noinline))
 Draws monochrome bitmap in color buffer using color, specified via setColor() method Draws monochrome bitmap in color buffer using color, specified via setColor() method. More...
 
void drawBitmap8 (lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap) __attribute__((noinline))
 Draws 8-bit color bitmap in color buffer. More...
 
void drawBitmap16 (lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap) __attribute__((noinline))
 Draws 16-bit color bitmap in color buffer. More...
 
void clear () __attribute__((noinline))
 Clears canvas.
 
size_t write (uint8_t c)
 Writes single character to canvas. More...
 
uint8_t printChar (uint8_t c)
 Draws single character to canvas. More...
 
void printFixed (lcdint_t xpos, lcdint_t y, const char *ch, EFontStyle style=STYLE_NORMAL) __attribute__((noinline))
 Print text at specified position to canvas. More...
 
void printFixedPgm (lcdint_t xpos, lcdint_t y, const char *ch, EFontStyle style=STYLE_NORMAL)
 Print text at specified position to canvas. More...
 
void setMode (uint8_t modeFlags)
 Sets canvas drawing mode Sets canvas drawing mode. More...
 
void setColor (uint16_t color)
 Sets color for monochrome operations. More...
 
uint16_t getColor ()
 Returns currently set foreground color. More...
 
void invertColors ()
 Swaps foreground and background colors. More...
 
void setBackground (uint16_t color)
 Sets background color. More...
 
void setFont (NanoFont &font)
 Sets new font to use with print functions. More...
 
NanoFontgetFont ()
 Returns reference to NanoFont object currently in use. More...
 
void setFontSpacing (uint8_t spacing)
 Sets font spacing for currently active font. More...
 
void setFixedFont (const uint8_t *progmemFont)
 Sets new font to use with print functions. More...
 
void setFreeFont (const uint8_t *progmemFont, const uint8_t *secondaryFont=nullptr)
 Sets new font to use with print functions. More...
 
uint8_t * getData ()
 Return pointer to canvas pixels data.
 
lcduint_t width ()
 Returns canvas width in pixels.
 
lcduint_t height ()
 Returns canvas height in pixels.
 
void rotateCW (T &out)
 Rotates the canvas clock-wise.
 

Public Attributes

NanoPoint offset
 Fixed offset for all operation of NanoCanvasOps in pixels.
 

Static Public Attributes

static const uint8_t BITS_PER_PIXEL = BPP
 number of bits per single pixel in buffer
 

Protected Attributes

lcduint_t m_w
 width of NanoCanvas area in pixels
 
lcduint_t m_h
 height of NanoCanvas area in pixels
 
lcdint_t m_cursorX
 current X cursor position for text output
 
lcdint_t m_cursorY
 current Y cursor position for text output
 
uint8_t m_textMode
 Flags for current NanoCanvas mode.
 
EFontStyle m_fontStyle
 currently active font style
 
uint8_t * m_buf
 Canvas data.
 
uint16_t m_color
 current color
 
uint16_t m_bgColor
 current background color
 
NanoFontm_font = nullptr
 current set font to use with NanoCanvas
 

Detailed Description

template<uint8_t BPP>
class NanoCanvasOps< BPP >

NanoCanvasOps provides operations for drawing in memory buffer.

Depending on the BPP template argument, this class can work with 1-bit (monochrome), 8-bit, or 16-bit canvas areas. All drawing operations write to an off-screen buffer that can later be flushed to a display.

Template Parameters
BPPbits per pixel (1, 8, or 16)
See also
NanoCanvas1, NanoCanvas8, NanoCanvas16

Definition at line 53 of file canvas.h.

Constructor & Destructor Documentation

◆ NanoCanvasOps() [1/2]

template<uint8_t BPP>
NanoCanvasOps< BPP >::NanoCanvasOps ( )
inline

Creates new empty canvas object.

If you this constructor is used, you must call begin() method before working with canvas.

Definition at line 70 of file canvas.h.

◆ NanoCanvasOps() [2/2]

template<uint8_t BPP>
NanoCanvasOps< BPP >::NanoCanvasOps ( lcdint_t  w,
lcdint_t  h,
uint8_t *  bytes 
)
inline

Creates new canvas object.

Width can be of any value. Height should be divided by 8. Memory buffer must be not less than w * h.

Parameters
w- width
h- height
bytes- pointer to memory buffer to use

Definition at line 84 of file canvas.h.

Member Function Documentation

◆ begin()

template<uint8_t BPP>
void NanoCanvasOps< BPP >::begin ( lcdint_t  w,
lcdint_t  h,
uint8_t *  bytes 
)

Initializes canvas object.

Width can be of any value. Height should be divided by 8. Memory buffer must be not less than w * h.

Parameters
w- width
h- height
bytes- pointer to memory buffer to use

◆ drawBitmap1()

template<uint8_t BPP>
void NanoCanvasOps< BPP >::drawBitmap1 ( lcdint_t  x,
lcdint_t  y,
lcduint_t  w,
lcduint_t  h,
const uint8_t *  bitmap 
)

Draws monochrome bitmap in color buffer using color, specified via setColor() method Draws monochrome bitmap in color buffer using color, specified via setColor() method.

Parameters
x- position X in pixels
y- position Y in pixels
w- width in pixels
h- height in pixels
bitmap- monochrome bitmap data, located in flash
Note
There are 2 modes: transparent and non-transparent mode, - and 2 colors available: black and white. In non-transparent mode, when black color is selected, the monochrome image just inverted. In transparent mode, those pixels of source monochrome image, which are black, do not overwrite pixels in the screen buffer.

◆ drawBitmap16()

template<uint8_t BPP>
void NanoCanvasOps< BPP >::drawBitmap16 ( lcdint_t  x,
lcdint_t  y,
lcduint_t  w,
lcduint_t  h,
const uint8_t *  bitmap 
)

Draws 16-bit color bitmap in color buffer.

Draws 16-bit color bitmap in color buffer.

Parameters
x- position X in pixels
y- position Y in pixels
w- width in pixels
h- height in pixels
bitmap- 16-bit color bitmap data, located in flash

◆ drawBitmap8()

template<uint8_t BPP>
void NanoCanvasOps< BPP >::drawBitmap8 ( lcdint_t  x,
lcdint_t  y,
lcduint_t  w,
lcduint_t  h,
const uint8_t *  bitmap 
)

Draws 8-bit color bitmap in color buffer.

Draws 8-bit color bitmap in color buffer.

Parameters
x- position X in pixels
y- position Y in pixels
w- width in pixels
h- height in pixels
bitmap- 8-bit color bitmap data, located in flash

◆ drawCircle()

template<uint8_t BPP>
void NanoCanvasOps< BPP >::drawCircle ( lcdint_t  x,
lcdint_t  y,
lcdint_t  r,
uint8_t  options = 0x0F 
)

Draws circle outline.

Parameters
xhorizontal position of circle center in pixels
yvertical position of circle center in pixels
rcircle radius in pixels
optionsbitmask for quadrants to draw (bits 0–3 for 4 quadrants, 0x0F = full circle)

◆ drawHLine()

template<uint8_t BPP>
void NanoCanvasOps< BPP >::drawHLine ( lcdint_t  x1,
lcdint_t  y1,
lcdint_t  x2 
)

Draws horizontal line from (x1,y1) to (x2,y1).

Parameters
x1- start X position
y1- Y position
x2- end X position
Note
color can be set via setColor()
See also
drawVLine(), drawLine()

◆ drawLine() [1/2]

template<uint8_t BPP>
void NanoCanvasOps< BPP >::drawLine ( lcdint_t  x1,
lcdint_t  y1,
lcdint_t  x2,
lcdint_t  y2 
)

Draws a line between two points using Bresenham's algorithm.

Parameters
x1- start X position
y1- start Y position
x2- end X position
y2- end Y position
Note
color can be set via setColor()
See also
drawHLine(), drawVLine()

◆ drawLine() [2/2]

template<uint8_t BPP>
void NanoCanvasOps< BPP >::drawLine ( const NanoRect rect)

Draws line.

Parameters
rect- structure, describing rectangle area
Note
color can be set via setColor()

◆ drawRect() [1/2]

template<uint8_t BPP>
void NanoCanvasOps< BPP >::drawRect ( lcdint_t  x1,
lcdint_t  y1,
lcdint_t  x2,
lcdint_t  y2 
)

Draws rectangle outline.

Parameters
x1- left X
y1- top Y
x2- right X
y2- bottom Y
Note
color can be set via setColor()
See also
fillRect()

◆ drawRect() [2/2]

template<uint8_t BPP>
void NanoCanvasOps< BPP >::drawRect ( const NanoRect rect)

Draws rectangle outline using NanoRect structure.

Parameters
rect- rectangle area to draw
Note
color can be set via setColor()
See also
fillRect()

◆ drawVLine()

template<uint8_t BPP>
void NanoCanvasOps< BPP >::drawVLine ( lcdint_t  x1,
lcdint_t  y1,
lcdint_t  y2 
)

Draws vertical line from (x1,y1) to (x1,y2).

Parameters
x1- X position
y1- start Y position
y2- end Y position
Note
color can be set via setColor()
See also
drawHLine(), drawLine()

◆ fillRect() [1/2]

template<uint8_t BPP>
void NanoCanvasOps< BPP >::fillRect ( lcdint_t  x1,
lcdint_t  y1,
lcdint_t  x2,
lcdint_t  y2 
)

Fills a rectangular area with the current color.

Parameters
x1- left X
y1- top Y
x2- right X
y2- bottom Y
Note
color can be set via setColor()
See also
drawRect(), clear()

◆ fillRect() [2/2]

template<uint8_t BPP>
void NanoCanvasOps< BPP >::fillRect ( const NanoRect rect)

Fills a rectangular area with the current color.

Parameters
rect- rectangle area to fill
Note
color can be set via setColor()
See also
drawRect(), clear()

◆ getColor()

template<uint8_t BPP>
uint16_t NanoCanvasOps< BPP >::getColor ( )
inline

Returns currently set foreground color.

Returns
current color value
See also
setColor()

Definition at line 336 of file canvas.h.

◆ getFont()

template<uint8_t BPP>
NanoFont& NanoCanvasOps< BPP >::getFont ( )
inline

Returns reference to NanoFont object currently in use.

Returns
reference to current NanoFont
See also
setFont(), setFixedFont(), setFreeFont()

Definition at line 380 of file canvas.h.

◆ invertColors()

template<uint8_t BPP>
void NanoCanvasOps< BPP >::invertColors ( )
inline

Swaps foreground and background colors.

See also
setColor(), setBackground()

Definition at line 345 of file canvas.h.

◆ offsetEnd()

template<uint8_t BPP>
const NanoPoint NanoCanvasOps< BPP >::offsetEnd ( ) const
inline

Returns right-bottom point of the canvas in offset terms.

If offset is (0,0), then offsetEnd() will return (width-1,height-1).

Definition at line 116 of file canvas.h.

◆ printChar()

template<uint8_t BPP>
uint8_t NanoCanvasOps< BPP >::printChar ( uint8_t  c)

Draws single character to canvas.

Parameters
c- character code to print
Returns
0 if char is not printed

◆ printFixed()

template<uint8_t BPP>
void NanoCanvasOps< BPP >::printFixed ( lcdint_t  xpos,
lcdint_t  y,
const char *  ch,
EFontStyle  style = STYLE_NORMAL 
)

Print text at specified position to canvas.

Parameters
xposposition in pixels
yposition in pixels
chpointer to NULL-terminated string.
stylespecific font style to use
Note
Supports only STYLE_NORMAL and STYLE_BOLD

◆ printFixedPgm()

template<uint8_t BPP>
void NanoCanvasOps< BPP >::printFixedPgm ( lcdint_t  xpos,
lcdint_t  y,
const char *  ch,
EFontStyle  style = STYLE_NORMAL 
)

Print text at specified position to canvas.

Parameters
xposposition in pixels
yposition in pixels
chpointer to NULL-terminated string, located in flash
stylespecific font style to use
Note
Supports only STYLE_NORMAL and STYLE_BOLD

◆ putPixel() [1/2]

template<uint8_t BPP>
void NanoCanvasOps< BPP >::putPixel ( lcdint_t  x,
lcdint_t  y 
)

Draws pixel on specified position.

Parameters
x- position X
y- position Y
Note
color can be set via setColor()

◆ putPixel() [2/2]

template<uint8_t BPP>
void NanoCanvasOps< BPP >::putPixel ( const NanoPoint p)

Draws pixel on specified position.

Parameters
p- NanoPoint
Note
color can be set via setColor()

◆ rect()

template<uint8_t BPP>
const NanoRect NanoCanvasOps< BPP >::rect ( ) const
inline

Returns rectangle area, covered by canvas in offset terms.

If offset is (0,0), then rect() will return ((0,0),(width-1,height-1))

Definition at line 125 of file canvas.h.

◆ setBackground()

template<uint8_t BPP>
void NanoCanvasOps< BPP >::setBackground ( uint16_t  color)
inline

Sets background color.

Parameters
colorBackground color

Definition at line 357 of file canvas.h.

◆ setColor()

template<uint8_t BPP>
void NanoCanvasOps< BPP >::setColor ( uint16_t  color)
inline

Sets color for monochrome operations.

Parameters
color- color to set (refer to RGB_COLOR8 definition)

Definition at line 326 of file canvas.h.

◆ setFixedFont()

template<uint8_t BPP>
void NanoCanvasOps< BPP >::setFixedFont ( const uint8_t *  progmemFont)
inline

Sets new font to use with print functions.

If multiple canvases are used in single application, this method can cause conflicts.

Warning
use this method only if single canvas is used in project
Parameters
progmemFontpointer to font data in flash (refer to NanoFont::loadFixedFont)

Definition at line 404 of file canvas.h.

◆ setFont()

template<uint8_t BPP>
void NanoCanvasOps< BPP >::setFont ( NanoFont font)
inline

Sets new font to use with print functions.

If multiple canvases are used in single application, this method allows to use different fonts for different canvases.

Parameters
fontreference to font object (NanoFont)

Definition at line 370 of file canvas.h.

◆ setFontSpacing()

template<uint8_t BPP>
void NanoCanvasOps< BPP >::setFontSpacing ( uint8_t  spacing)
inline

Sets font spacing for currently active font.

Parameters
spacingspacing in pixels

Definition at line 389 of file canvas.h.

◆ setFreeFont()

template<uint8_t BPP>
void NanoCanvasOps< BPP >::setFreeFont ( const uint8_t *  progmemFont,
const uint8_t *  secondaryFont = nullptr 
)
inline

Sets new font to use with print functions.

If multiple canvases are used in single application, this method can cause conflicts.

Warning
use this method only if single canvas is used in project
Parameters
progmemFontpointer to font data in flash (refer to NanoFont::loadFreeFont)
secondaryFontpointer to font data in flash (refer to NanoFont::loadSecondaryFont)

Definition at line 420 of file canvas.h.

◆ setMode()

template<uint8_t BPP>
void NanoCanvasOps< BPP >::setMode ( uint8_t  modeFlags)
inline

Sets canvas drawing mode Sets canvas drawing mode.

The set flags define transparency of output images

Parameters
modeFlags- combination of flags: CANVAS_TEXT_WRAP, CANVAS_MODE_TRANSPARENT

Definition at line 317 of file canvas.h.

◆ setOffset()

template<uint8_t BPP>
void NanoCanvasOps< BPP >::setOffset ( lcdint_t  ox,
lcdint_t  oy 
)
inline

Sets offset.

Parameters
ox- X offset in pixels
oy- Y offset in pixels

Definition at line 106 of file canvas.h.

◆ write()

template<uint8_t BPP>
size_t NanoCanvasOps< BPP >::write ( uint8_t  c)

Writes single character to canvas.

Parameters
c- character code to print

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