![]() |
Display_Lib_RPI 2.3.0
A C++ Library to connect electronic displays to Linux single board computers.
|
Graphics class to hold graphic related functions for 1-bit displays. More...
#include <bicolor_graphics_RDL.hpp>
Public Types | |
enum | displayBC_rotate_e : uint8_t { BC_Degrees_0 = 0 , BC_Degrees_90 = 1 , BC_Degrees_180 = 2 , BC_Degrees_270 = 3 } |
enum | pixel_color_e : uint8_t { WHITE = 0 , BLACK = 1 , INVERSE = 2 } |
![]() | |
enum | BaseNum : uint8_t { RDL_DEC = 10 , RDL_HEX = 16 , RDL_OCT = 8 , RDL_BIN = 2 } |
Public Member Functions | |
bicolor_graphics (int16_t w, int16_t h) | |
init the Display Graphics class object | |
virtual void | drawPixel (int16_t x, int16_t y, uint8_t color)=0 |
define in the sub class | |
rdlib::Return_Codes_e | drawDotGrid (int16_t x, int16_t y, int16_t w, int16_t h, uint8_t DotGridGap, uint8_t color) |
Draws a grid of dots on the screen starting from the given coordinates. This function draws a grid of pixels with a specified gap between them. It checks that the provided coordinates and dimensions are within the screen bounds and adjusts them if necessary. It also validates The grid of dots gap value and defaults it to 2 if invalid. | |
void | drawLine (int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint8_t color) |
draws a line from (x0,y0) to (x1,y1). | |
rdlib::Return_Codes_e | drawFastVLine (int16_t x, int16_t y, int16_t h, uint8_t color) |
Draws a vertical line starting at (x,y) with height h. | |
rdlib::Return_Codes_e | drawFastHLine (int16_t x, int16_t y, int16_t w, uint8_t color) |
Draws a horizontal line starting at (x,y) with width w. | |
void | drawLineAngle (int16_t x, int16_t y, int angle, uint8_t start, uint8_t length, int offset, uint8_t color) |
Draws a line using an angle and length as parameters. This function draws a line starting from (x, y) , extending in the direction specified by angle , with a given length . The function also allows applying an offset to the angle before computing the line’s end coordinates. | |
void | drawRect (int16_t x, int16_t y, int16_t w, int16_t h, uint8_t color) |
draws rectangle at (x,y) where h is height and w is width of the rectangle. | |
void | fillRect (int16_t x, int16_t y, int16_t w, int16_t h, uint8_t color) |
fills a rectangle starting from coordinates (x,y) with width of w and height of h. | |
void | fillScreen (uint8_t color) |
Fills the whole screen with a given color. | |
void | drawCircle (int16_t x0, int16_t y0, int16_t r, uint8_t color) |
draws a circle where (x0,y0) are center coordinates an r is circle radius. | |
void | fillCircle (int16_t x0, int16_t y0, int16_t r, uint8_t color) |
fills a circle where (x0,y0) are center coordinates an r is circle radius. | |
void | drawEllipse (int16_t cx, int16_t cy, int16_t semiMajorAxis, int16_t semiMinorAxis, bool fill, uint8_t color) |
Draw an ellipse on the display. This function uses the midpoint ellipse algorithm to efficiently draw an ellipse centered at (cx, cy) with the given semi-major (horizontal) and semi-minor (vertical) axes. | |
void | drawTriangle (int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color) |
draws a triangle of coordinates (x0,y0), (x1,y1) and (x2,y2). | |
void | fillTriangle (int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color) |
Fills a triangle of coordinates (x0,y0), (x1,y1) and (x2,y2). | |
void | drawRoundRect (int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint8_t color) |
draws a rectangle with rounded edges | |
void | fillRoundRect (int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint8_t color) |
Fills a rectangle with rounded edges. | |
void | drawQuadrilateral (int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, uint8_t color) |
Draws a quadrilateral (four-sided polygon) by connecting four points with lines. This function draws a quadrilateral by drawing four lines between the given vertices. The lines are drawn in the order: (x0, y0) to (x1, y1), (x1, y1) to (x2, y2), (x2, y2) to (x3, y3), and finally (x3, y3) back to (x0, y0). | |
void | fillQuadrilateral (int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, uint8_t color, bool useTriangleSplit=true) |
Fills a quadrilateral with the specified color using triangles. This function fills a quadrilateral by dividing it into triangles and filling them individually. The quadrilateral is filled by calling the fillTriangle function three times with appropriate vertex coordinates. The useTriangleSplit parameter determines whether the quadrilateral is divided into two triangles or if only one triangle is used. | |
rdlib::Return_Codes_e | drawPolygon (int16_t x, int16_t y, uint8_t sides, int16_t diameter, float rotation, bool fill, uint8_t color) |
Draws a polygon with a specified number of sides, diameter, rotation, and color. This function draws a regular polygon by connecting points equally spaced around a circle, with each point having a distance defined by the diameter. The polygon is rotated by the given angle (in degrees) before being drawn. The number of sides is enforced to be at least 3. | |
void | drawArc (uint16_t cx, uint16_t cy, uint16_t radius, uint16_t thickness, float startAngle, float endAngle, uint8_t color) |
Draw an arc on the TFT display. This function draws an arc between two angles (start and end) on a circle with a given radius. | |
void | drawSimpleArc (int16_t cx, int16_t cy, int16_t radius, float startAngle, float endAngle, uint8_t color) |
Draw a simple arc of one pixel on the display( no offsets , thickness or maximum arc calculations) This function draws an arc between two angles (start and end) on a circle with a given radius. | |
float | getArcAngleMax () const |
Get the current maximum angle of the arc. | |
void | setArcAngleMax (float arcAngleMax) |
Set a new maximum angle for the arc. | |
int | getArcAngleOffset () const |
Get the current angle offset. | |
void | setArcAngleOffset (int arcAngleOffset) |
Set a new angle offset. | |
void | setCursor (int16_t x, int16_t y) |
set the cursor position | |
void | setRotation (displayBC_rotate_e m) |
Sets the _rotation of the display. | |
displayBC_rotate_e | getRotation () |
Gets the _rotation of the display. | |
int16_t | height (void) const |
Gets the height of the display (per current _rotation) | |
int16_t | width (void) const |
Gets the width of the display (per current _rotation) | |
virtual size_t | write (uint8_t) override |
write method used in the print class when user calls print | |
rdlib::Return_Codes_e | writeChar (int16_t x, int16_t y, char value) |
Write 1 character on display. | |
rdlib::Return_Codes_e | writeCharString (int16_t x, int16_t y, char *text) |
Write Text character array on Display. | |
void | setTextWrap (bool w) |
turn on or off screen wrap of the text | |
void | setDrawBitmapAddr (bool mode) |
sets the data addressing mode in drawBitmap function. | |
rdlib::Return_Codes_e | drawBitmap (int16_t x, int16_t y, const std::span< const uint8_t > bitmap, int16_t w, int16_t h, uint8_t color, uint8_t bg) |
Draw a 1-bit color bitmap. | |
![]() | |
display_Fonts () | |
init the OLED font class object constructor | |
rdlib::Return_Codes_e | setFont (display_Font_name_e) |
SetFont. | |
void | setInvertFont (bool invertStatus) |
setInvertFont | |
bool | getInvertFont (void) |
getInvertFont | |
![]() | |
int | getWriteError () |
gets the error flag status, zero no error | |
void | clearWriteError () |
clears the error flag by setting it to zero | |
virtual size_t | write (const uint8_t *buffer, size_t size) |
define in the sub class | |
size_t | write (const char *str) |
Writes a string to the output. | |
size_t | write (const char *buffer, size_t size) |
Writes a buffer of a specified size to the output. | |
virtual int | availableForWrite () |
define in the sub class | |
size_t | print (const char[]) |
print an array | |
size_t | print (char) |
print an character | |
size_t | print (int, int=RDL_DEC) |
print an integer of base number system | |
size_t | print (unsigned int, int=RDL_DEC) |
print an unsigned integer of base number system | |
size_t | print (long, int=RDL_DEC) |
print an long integer of base number system | |
size_t | print (unsigned long, int=RDL_DEC) |
print an unsigned long integer of base number system | |
size_t | print (double, int=2) |
print an double | |
size_t | print (const std::string &) |
print an C++ string object | |
size_t | println (const char[]) |
Prints a character array followed by a newline. | |
size_t | println (char) |
print an character followed by new line | |
size_t | println (int, int=RDL_DEC) |
print an integer of base number system followed by new line | |
size_t | println (unsigned int, int=RDL_DEC) |
print an unsigned integer of base number system followed by new line | |
size_t | println (long, int=RDL_DEC) |
print an long integer of base number system followed by new line | |
size_t | println (unsigned long, int=RDL_DEC) |
print an unsigned long integer of base number system followed by new line | |
size_t | println (double, int=2) |
print an double | |
size_t | println (void) |
Goto to new line. | |
size_t | println (const std::string &s) |
print an C++ string object followed by new line | |
template<typename T > | |
size_t | print (const std::vector< T > &v, int format=defaultFormat< T >()) |
Print a vector of any type. | |
template<typename T > | |
size_t | println (const std::vector< T > &vec, int format=defaultFormat< T >()) |
Print a vector of elements followed by a newline. | |
template<typename T , size_t N> | |
size_t | print (const std::array< T, N > &arr, int format=defaultFormat< T >()) |
Print a std::array of any type. | |
template<typename T , size_t N> | |
size_t | println (const std::array< T, N > &arr, int format=defaultFormat< T >()) |
Print a std::array of elements followed by a newline. | |
Protected Attributes | |
displayBC_rotate_e | _display_rotate = BC_Degrees_0 |
const int16_t | WIDTH |
const int16_t | HEIGHT |
int16_t | _width |
int16_t | _height |
int16_t | _cursor_x |
int16_t | _cursor_y |
float | _arcAngleMax = 360.0f |
int | _arcAngleOffset = 0 |
bool | _textwrap = true |
![]() | |
std::span< const uint8_t > | _FontSelect = pFontDefault |
uint8_t | _Font_X_Size = 0x08 |
uint8_t | _Font_Y_Size = 0x08 |
uint8_t | _FontOffset = 0x20 |
uint8_t | _FontNumChars = 0x5F |
Private Attributes | |
bool | _drawBitmapAddr |
Additional Inherited Members | |
![]() | |
void | setWriteError (int err=0) |
Graphics class to hold graphic related functions for 1-bit displays.
init the Display Graphics class object
w | width defined in sub-class |
h | height defined in sub-class |
void bicolor_graphics::drawArc | ( | uint16_t | cx, |
uint16_t | cy, | ||
uint16_t | radius, | ||
uint16_t | thickness, | ||
float | startAngle, | ||
float | endAngle, | ||
uint8_t | color | ||
) |
Draw an arc on the TFT display. This function draws an arc between two angles (start and end) on a circle with a given radius.
cx | X-coordinate of the center of the circle. |
cy | Y-coordinate of the center of the circle. |
radius | The radius of the circle. |
thickness | the thickness of the arc |
startAngle | The starting angle of the arc (in degrees). |
endAngle | The ending angle of the arc (in degrees). |
color | The color of the arc. |
rdlib::Return_Codes_e bicolor_graphics::drawBitmap | ( | int16_t | x, |
int16_t | y, | ||
const std::span< const uint8_t > | bitmap, | ||
int16_t | w, | ||
int16_t | h, | ||
uint8_t | color, | ||
uint8_t | bg | ||
) |
Draw a 1-bit color bitmap.
x | x co-ord position |
y | y co-ord posiiton a |
bitmap | span to bitmap data |
w | width of the bitmap |
h | height of the bitmap |
color | foreground colour |
bg | background colour. |
draws a circle where (x0,y0) are center coordinates an r is circle radius.
x0 | circle center x position |
y0 | circle center y position |
r | radius of circle |
color | The color of the circle |
rdlib::Return_Codes_e bicolor_graphics::drawDotGrid | ( | int16_t | x, |
int16_t | y, | ||
int16_t | w, | ||
int16_t | h, | ||
uint8_t | DotGridGap, | ||
uint8_t | color | ||
) |
Draws a grid of dots on the screen starting from the given coordinates. This function draws a grid of pixels with a specified gap between them. It checks that the provided coordinates and dimensions are within the screen bounds and adjusts them if necessary. It also validates The grid of dots gap value and defaults it to 2 if invalid.
x | The x-coordinate of the top-left corner where The grid of dots will start. |
y | The y-coordinate of the top-left corner where The grid of dots will start. |
w | The width of the area to draw The grid of dots, from the starting x-coordinate. |
h | The height of the area to draw The grid of dots, from the starting y-coordinate. |
DotGridGap | The gap between each dot gap line, controlling the spacing between drawn pixels. |
color | The color of the pixels to draw in The grid of dots. |
void bicolor_graphics::drawEllipse | ( | int16_t | cx, |
int16_t | cy, | ||
int16_t | semiMajorAxis, | ||
int16_t | semiMinorAxis, | ||
bool | fill, | ||
uint8_t | color | ||
) |
Draw an ellipse on the display. This function uses the midpoint ellipse algorithm to efficiently draw an ellipse centered at (cx, cy) with the given semi-major (horizontal) and semi-minor (vertical) axes.
cx | X-coordinate of the ellipse center. |
cy | Y-coordinate of the ellipse center. |
semiMajorAxis | Length of the semi-major axis (horizontal radius). |
semiMinorAxis | Length of the semi-minor axis (vertical radius). |
fill | if false draw Ellipse , if true fill it! |
color | color value for the ellipse. |
rdlib::Return_Codes_e bicolor_graphics::drawFastHLine | ( | int16_t | x, |
int16_t | y, | ||
int16_t | w, | ||
uint8_t | color | ||
) |
Draws a horizontal line starting at (x,y) with width w.
x | The starting x coordinate |
y | The starting y coordinate |
w | The width of the line |
color | The color of the line |
rdlib::Return_Codes_e bicolor_graphics::drawFastVLine | ( | int16_t | x, |
int16_t | y, | ||
int16_t | h, | ||
uint8_t | color | ||
) |
Draws a vertical line starting at (x,y) with height h.
x | The starting x coordinate |
y | The starting y coordinate |
h | The height of the line |
color | The color of the line |
draws a line from (x0,y0) to (x1,y1).
x0 | x start coordinate |
y0 | y start coordinate |
x1 | x end coordinate |
y1 | y end coordinate |
color | color to draw line |
void bicolor_graphics::drawLineAngle | ( | int16_t | x, |
int16_t | y, | ||
int | angle, | ||
uint8_t | start, | ||
uint8_t | length, | ||
int | offset, | ||
uint8_t | color | ||
) |
Draws a line using an angle and length as parameters. This function draws a line starting from (x, y)
, extending in the direction specified by angle
, with a given length
. The function also allows applying an offset
to the angle before computing the line’s end coordinates.
x | The starting x-coordinate (horizontal position). |
y | The starting y-coordinate (vertical position). |
angle | The angle (in degrees) at which the line is drawn. |
start | calculates a new starting position by moving start units along the given angle. |
length | The length of the line. |
offset | An additional offset applied to the angle before calculating the endpoint. |
color | The color of the line |
define in the sub class
Implemented in NOKIA_5110_RPI, SH110X_RDL, SSD1306_RDL, ERMCH1115, and ERM19264_UC1609.
rdlib::Return_Codes_e bicolor_graphics::drawPolygon | ( | int16_t | x, |
int16_t | y, | ||
uint8_t | sides, | ||
int16_t | diameter, | ||
float | rotation, | ||
bool | fill, | ||
uint8_t | color | ||
) |
Draws a polygon with a specified number of sides, diameter, rotation, and color. This function draws a regular polygon by connecting points equally spaced around a circle, with each point having a distance defined by the diameter. The polygon is rotated by the given angle (in degrees) before being drawn. The number of sides is enforced to be at least 3.
x | The x-coordinate of the center of the polygon. |
y | The y-coordinate of the center of the polygon. |
sides | The number of sides the polygon will have. Must be at least 3. |
diameter | The diameter of the circle inscribed by the polygon. |
rotation | The angle (in degrees) by which to rotate the polygon. |
fill | if false draw ,if true fill |
color | The color of the polygon edges. |
void bicolor_graphics::drawQuadrilateral | ( | int16_t | x0, |
int16_t | y0, | ||
int16_t | x1, | ||
int16_t | y1, | ||
int16_t | x2, | ||
int16_t | y2, | ||
int16_t | x3, | ||
int16_t | y3, | ||
uint8_t | color | ||
) |
Draws a quadrilateral (four-sided polygon) by connecting four points with lines. This function draws a quadrilateral by drawing four lines between the given vertices. The lines are drawn in the order: (x0, y0) to (x1, y1), (x1, y1) to (x2, y2), (x2, y2) to (x3, y3), and finally (x3, y3) back to (x0, y0).
x0 | The x-coordinate of the first vertex. |
y0 | The y-coordinate of the first vertex. |
x1 | The x-coordinate of the second vertex. |
y1 | The y-coordinate of the second vertex. |
x2 | The x-coordinate of the third vertex. |
y2 | The y-coordinate of the third vertex. |
x3 | The x-coordinate of the fourth vertex. |
y3 | The y-coordinate of the fourth vertex. |
color | The 565 color used to draw the lines of the quadrilateral. |
draws rectangle at (x,y) where h is height and w is width of the rectangle.
x | x start coordinate |
y | y start coordinate |
w | width of the rectangle |
h | height of the rectangle |
color | color to draw rect |
void bicolor_graphics::drawRoundRect | ( | int16_t | x, |
int16_t | y, | ||
int16_t | w, | ||
int16_t | h, | ||
int16_t | r, | ||
uint8_t | color | ||
) |
draws a rectangle with rounded edges
x | x start coordinate |
y | y start coordinate |
w | width of the rectangle |
h | height of the rectangle |
r | radius of the rounded edges |
color | color to draw rounded rectangle |
void bicolor_graphics::drawSimpleArc | ( | int16_t | cx, |
int16_t | cy, | ||
int16_t | radius, | ||
float | startAngle, | ||
float | endAngle, | ||
uint8_t | color | ||
) |
Draw a simple arc of one pixel on the display( no offsets , thickness or maximum arc calculations) This function draws an arc between two angles (start and end) on a circle with a given radius.
cx | X-coordinate of the center of the circle. |
cy | Y-coordinate of the center of the circle. |
radius | The radius of the circle. |
startAngle | The starting angle of the arc (in degrees). |
endAngle | The ending angle of the arc (in degrees). |
color | The color of the arc. |
0 degree is positive X axis , arc is drawn counterclockwise
void bicolor_graphics::drawTriangle | ( | int16_t | x0, |
int16_t | y0, | ||
int16_t | x1, | ||
int16_t | y1, | ||
int16_t | x2, | ||
int16_t | y2, | ||
uint8_t | color | ||
) |
draws a triangle of coordinates (x0,y0), (x1,y1) and (x2,y2).
x0 | x start coordinate point 1 |
y0 | y start coordinate point 1 |
x1 | x start coordinate point 2 |
y1 | y start coordinate point 2 |
x2 | x start coordinate point 3 |
y2 | y start coordinate point 3 |
color | color to draw triangle |
fills a circle where (x0,y0) are center coordinates an r is circle radius.
x0 | circle center x position |
y0 | circle center y position |
r | radius of circle |
color | color of the filled circle |
void bicolor_graphics::fillQuadrilateral | ( | int16_t | x0, |
int16_t | y0, | ||
int16_t | x1, | ||
int16_t | y1, | ||
int16_t | x2, | ||
int16_t | y2, | ||
int16_t | x3, | ||
int16_t | y3, | ||
uint8_t | color, | ||
bool | useTriangleSplit = true |
||
) |
Fills a quadrilateral with the specified color using triangles. This function fills a quadrilateral by dividing it into triangles and filling them individually. The quadrilateral is filled by calling the fillTriangle
function three times with appropriate vertex coordinates. The useTriangleSplit
parameter determines whether the quadrilateral is divided into two triangles or if only one triangle is used.
x0 | The x-coordinate of the first vertex. |
y0 | The y-coordinate of the first vertex. |
x1 | The x-coordinate of the second vertex. |
y1 | The y-coordinate of the second vertex. |
x2 | The x-coordinate of the third vertex. |
y2 | The y-coordinate of the third vertex. |
x3 | The x-coordinate of the fourth vertex. |
y3 | The y-coordinate of the fourth vertex. |
color | The color used to fill the quadrilateral. |
useTriangleSplit | A boolean flag that determines whether the quadrilateral should be divided into two or three triangles. |
fills a rectangle starting from coordinates (x,y) with width of w and height of h.
x | x coordinate |
y | y coordinate |
w | width of the rectangle |
h | height of the rectangle |
color | color to fill rectangle |
void bicolor_graphics::fillRoundRect | ( | int16_t | x, |
int16_t | y, | ||
int16_t | w, | ||
int16_t | h, | ||
int16_t | r, | ||
uint8_t | color | ||
) |
Fills a rectangle with rounded edges.
x | x start coordinate |
y | y start coordinate |
w | width of the rectangle |
h | height of the rectangle |
r | radius of the rounded edges |
color | color to fill round rectangle |
Fills the whole screen with a given color.
color | color to fill screen |
void bicolor_graphics::fillTriangle | ( | int16_t | x0, |
int16_t | y0, | ||
int16_t | x1, | ||
int16_t | y1, | ||
int16_t | x2, | ||
int16_t | y2, | ||
uint8_t | color | ||
) |
Fills a triangle of coordinates (x0,y0), (x1,y1) and (x2,y2).
x0 | x start coordinate point 1 |
y0 | y start coordinate point 1 |
x1 | x start coordinate point 2 |
y1 | y start coordinate point 2 |
x2 | x start coordinate point 3 |
y2 | y start coordinate point 3 |
color | color to fill triangle |
float bicolor_graphics::getArcAngleMax | ( | ) | const |
Get the current maximum angle of the arc.
int bicolor_graphics::getArcAngleOffset | ( | ) | const |
Get the current angle offset.
bicolor_graphics::displayBC_rotate_e bicolor_graphics::getRotation | ( | void | ) |
Gets the _rotation of the display.
Gets the height of the display (per current _rotation)
Set a new maximum angle for the arc.
arcAngleMax | The new maximum angle in degrees (should be positive). |
Set a new angle offset.
arcAngleOffset | The new angle offset in degrees. |
set the cursor position
x | X co-ord position |
y | Y co-ord position |
sets the data addressing mode in drawBitmap function.
mode | boolean mode , true default
|
void bicolor_graphics::setRotation | ( | displayBC_rotate_e | CurrentRotation | ) |
Sets the _rotation of the display.
CurrentRotation | value enum |
turn on or off screen wrap of the text
w | TRUE on |
Gets the width of the display (per current _rotation)
write method used in the print class when user calls print
character | the character to print |
Implements Print.
rdlib::Return_Codes_e bicolor_graphics::writeChar | ( | int16_t | x, |
int16_t | y, | ||
char | value | ||
) |
Write 1 character on display.
x | character starting position on x-axis. |
y | character starting position on x-axis. |
value | Character to be written. |
rdlib::Return_Codes_e bicolor_graphics::writeCharString | ( | int16_t | x, |
int16_t | y, | ||
char * | pText | ||
) |
Write Text character array on Display.
x | character starting position on x-axis. |
y | character starting position on y-axis. |
pText | Pointer to the array of the text to be written. |
|
protected |
Maximum angle of Arc , used by drawArc
|
protected |
used by drawArc, offset for adjusting the starting angle of arc. default positive X-axis (0°)
|
protected |
Current X co-ord cursor position
|
protected |
Current Y co-ord cursor position
|
protected |
Enum to hold rotation
|
private |
data addressing mode for method drawBitmap, True-vertical , false-horizontal
|
protected |
Display h as modified by current _rotation
If set, text at right edge of display will wrap, print method
|
protected |
Display w as modified by current _rotation