Deluge Firmware 1.3.0
Build date: 2025.04.16
Loading...
Searching...
No Matches
Canvas Class Reference

Public Types

using ImageStore = uint8_t[kImageHeight][kImageWidth]
 

Public Member Functions

 Canvas (Canvas const &other)=delete
 
 Canvas (Canvas &&other)=delete
 
Canvasoperator= (Canvas const &other)=delete
 
Canvasoperator= (Canvas &&other)=delete
 
ImageStore & hackGetImageStore ()
 XXX: DO NOT USE THIS OUTSIDE OF THE CORE OLED CODE.
 
Rendering routines
void clear ()
 Clear the entire image.
 
void clearAreaExact (int32_t minX, int32_t minY, int32_t maxX, int32_t maxY)
 
void drawPixel (int32_t x, int32_t y)
 Set a single pixel.
 
void drawHorizontalLine (int32_t pixelY, int32_t startX, int32_t endX)
 
void drawVerticalLine (int32_t pixelX, int32_t startY, int32_t endY)
 
void drawRectangle (int32_t minX, int32_t minY, int32_t maxX, int32_t maxY)
 
void drawString (std::string_view str, int32_t pixelX, int32_t pixelY, int32_t textWidth, int32_t textHeight, int32_t scrollPos=0, int32_t endX=OLED_MAIN_WIDTH_PIXELS, bool useTextWidth=false)
 
void drawStringCentred (char const *string, int32_t pixelY, int32_t textWidth, int32_t textHeight, int32_t centrePos=OLED_MAIN_WIDTH_PIXELS/2)
 
void drawStringCentredShrinkIfNecessary (char const *string, int32_t pixelY, int32_t textWidth, int32_t textHeight)
 
void drawStringAlignRight (char const *string, int32_t pixelY, int32_t textWidth, int32_t textHeight, int32_t rightPos=OLED_MAIN_WIDTH_PIXELS)
 
void drawChar (uint8_t theChar, int32_t pixelX, int32_t pixelY, int32_t textWidth, int32_t textHeight, int32_t scrollPos=0, int32_t endX=OLED_MAIN_WIDTH_PIXELS)
 Draw a single character.
 
int32_t getCharIndex (uint8_t theChar)
 
int32_t getCharWidthInPixels (uint8_t theChar, int32_t textHeight)
 
int32_t getCharSpacingInPixels (uint8_t theChar, int32_t textHeight, bool isLastChar)
 
int32_t getStringWidthInPixels (char const *string, int32_t textHeight)
 
void drawGraphicMultiLine (uint8_t const *graphic, int32_t startX, int32_t startY, int32_t width, int32_t height=8, int32_t numBytesTall=1)
 
void drawScreenTitle (std::string_view text)
 
void invertArea (int32_t xMin, int32_t width, int32_t startY, int32_t endY)
 
void invertLeftEdgeForMenuHighlighting (int32_t xMin, int32_t width, int32_t startY, int32_t endY)
 inverts just the left edge
 

Static Public Attributes

static constexpr uint32_t kImageHeight = OLED_MAIN_HEIGHT_PIXELS >> 3
 Height of the image in bytes.
 
static constexpr uint32_t kImageWidth = OLED_MAIN_WIDTH_PIXELS
 Width of the image in pixels.
 

Private Attributes

uint8_t image_ [kImageHeight][kImageWidth]
 

Member Function Documentation

◆ clearAreaExact()

void Canvas::clearAreaExact ( int32_t minX,
int32_t minY,
int32_t maxX,
int32_t maxY )

Clear only a subset of the image

Parameters
minXminimum X coordinate, inclusive
minYminimum Y coordinate, inclusive
maxXmaximum X coordinate, inclusive
maxYmaximum Y coordinate, exclusive

◆ drawGraphicMultiLine()

void Canvas::drawGraphicMultiLine ( uint8_t const * graphic,
int32_t startX,
int32_t startY,
int32_t width,
int32_t height = 8,
int32_t numBytesTall = 1 )

Draw a "graphic".

The provided graphic array is used as a bit mask and added to the existing content.

Parameters
graphicPointer to the start of an array representing the graphic.
startXX coodinate of the left edge of the graphic
startYY coordinate of the top of the graphic
widthWidth of the graphic in pixels
heightHeight of the graphic in pixels
numBytesTallNumber of bytes in the Y direction, determines the stride in the graphic array

◆ drawHorizontalLine()

void Canvas::drawHorizontalLine ( int32_t pixelY,
int32_t startX,
int32_t endX )

Draw a horizontal line.

Parameters
pixelYY coordinate of the line to draw
startXStarting X coordinate, inclusive
endYEnding Y coordinate, inclusive

◆ drawRectangle()

void Canvas::drawRectangle ( int32_t minX,
int32_t minY,
int32_t maxX,
int32_t maxY )

Draw a 1-px wide rectangle.

Parameters
minXMinimum X coordinate, inclusive
minYMinimum Y coordinate, inclusive
maxXMaximum X coordinate, inclusive
maxYMaximum Y coordinate, inclusive

◆ drawScreenTitle()

void Canvas::drawScreenTitle ( std::string_view title)

Draw a screen title and underline it.

Parameters
textTitle text

◆ drawString()

void Canvas::drawString ( std::string_view str,
int32_t pixelX,
int32_t pixelY,
int32_t textWidth,
int32_t textHeight,
int32_t scrollPos = 0,
int32_t endX = OLED_MAIN_WIDTH_PIXELS,
bool useTextWidth = false )

Draw a string

Parameters
strThe string
pixelXX coordinate of the left side of the string
pixelYY coordinate of the top side of the string
textWidthBase width in pixels of each character
textHeightHeight in pixels of each character
scrollPosOffset in pixels representing how far the text has scrolled from the left.
endXMaximum X coordinate after which we bail out. N.B. this means the actual maximum X coordinate rendered is endX + textWidth, as the individual character rendering work can overshoot.

◆ drawStringAlignRight()

void Canvas::drawStringAlignRight ( char const * string,
int32_t pixelY,
int32_t textWidth,
int32_t textHeight,
int32_t rightPos = OLED_MAIN_WIDTH_PIXELS )

Draw a string, aligned to the right.

Parameters
stringA null-terminated C string
pixelYThe Y coordinate of the top of the string
textWidthThe width for each character in the string
textHeightThe height for each character in the string
rightPosX coordinate, exclusive, of the rightmost pixel to use for the string

◆ drawStringCentred()

void Canvas::drawStringCentred ( char const * string,
int32_t pixelY,
int32_t textWidth,
int32_t textHeight,
int32_t centrePos = OLED_MAIN_WIDTH_PIXELS / 2 )

Draw a string, centered at the provided location.

Parameters
stringA null-terminated C string
pixelYY coordinate of the top side of the string
textWidthBase width in pixels of each character
textHeightHeight in pixels of each character
scrollPosOffset in pixels representing how far the text has scrolled from the left.
endXMaximum X coordinate after which we bail out. N.B. this means the actual maximum X coordinate rendered is endX + textWidth, as the individual character rendering work can overshoot.

◆ drawStringCentredShrinkIfNecessary()

void Canvas::drawStringCentredShrinkIfNecessary ( char const * string,
int32_t pixelY,
int32_t textWidth,
int32_t textHeight )

Draw a string, reducing its height so the string fits within the specified width

Parameters
stringA null-terminated C string
pixelYThe Y coordinate of the top of the string
textWidthRequested width for each character in the string
textHeightRequested height for each character in the string

◆ drawVerticalLine()

void Canvas::drawVerticalLine ( int32_t pixelX,
int32_t startY,
int32_t endY )

Draw a vertical line.

Parameters
pixelXX coordinate of the line
startYY coordinate of the line, inclusive
endYY coordinate of the line, inclusive

◆ getCharIndex()

int32_t Canvas::getCharIndex ( uint8_t theChar)

Returns index for character so it can be looked up

Parameters
theCharA single character

◆ getCharSpacingInPixels()

int32_t Canvas::getCharSpacingInPixels ( uint8_t theChar,
int32_t textHeight,
bool isLastChar )

Returns spacing in pixels between characters drawn in a string

Parameters
theCharA single character
textHeightThe height of the character (to distinguish between non-bold and bold characters)
isLastChara boolean to specify whether any char's follow this char

◆ getCharWidthInPixels()

int32_t Canvas::getCharWidthInPixels ( uint8_t theChar,
int32_t textHeight )

Return width of a single character with a given character height

Parameters
theCharA single character
textHeightThe height of the character

◆ getStringWidthInPixels()

int32_t Canvas::getStringWidthInPixels ( char const * string,
int32_t textHeight )

Returns width of a string in pixels

Parameters
stringA null-terminated C string
textHeightThe height for each character in the string

◆ invertArea()

void Canvas::invertArea ( int32_t xMin,
int32_t width,
int32_t startY,
int32_t endY )

Invert an area of the canvas.

Parameters
xMinMinimum X coordinate, inclusive
widthWidth of the region to invert. End coordinate is excluded.
startYMinimum Y coordinate, inclusive
endYMaximum Y coordinate, inclusive

◆ invertLeftEdgeForMenuHighlighting()

void Canvas::invertLeftEdgeForMenuHighlighting ( int32_t xMin,
int32_t width,
int32_t startY,
int32_t endY )

inverts just the left edge

Invert just the left edge of the canvas.

Parameters
xMinMinimum X coordinate, inclusive
widthWidth of the region to invert. End coordinate is excluded.
startYMinimum Y coordinate, inclusive
endYMaximum Y coordinate, inclusive

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