class documentation
class Draw(lcd.LCD):
Constructor: Draw(foreground, background, scale_x, scale_y, ...)
Class for drawing shapes and text on the display.
Methods
char(position,char, color=None, font_size=-1)- Draw a single character
circle(position,radius, color=None)- Draw a circle outline
clear(position=Vector(0, 0), size=Vector(320, 320), color=None)- Fill a rectangular area with a color
- `erase`()
- Clear the entire display
fill_circle(position,radius, color=None)- Draw a filled circle
fill_rectangle(position,size, color=None)- Draw a filled rectangle
fill_round_rectangle(position,size,radius, color=None)- Draw a filled rounded rectangle
fill_screen(color=None)- Fill the entire screen with a color
fill_triangle(point1,point2,point3, color=None)- Draw a filled triangle
fill_triangle_alpha(point1,point2,point3, color=None, alpha=255)- Draw a filled triangle with alpha blending
get_font(font_size=0)- Get the FontSize object for a given font size
image(position,img)- Draw an image object to the back buffer
image_bmp(position,path, storage=None)- Draw a 24-bit BMP image from a file path
image_jpeg(position,path, storage=None)- Draw a JPEG image from a file path
image_jpeg_buffer(position,buf)- Draw a JPEG image from bytes data in a buffer
image_bytearray(position,size,byte_data, invert=False)- Draw an image from 8-bit byte data (bytes or bytearray)
image_bytearray_1bit(position,size,byte_data)- Draw a 1-bit bitmap from packed byte_data (8 pixels per byte, row-aligned)
image_bytearray_path(position,size,path, storage=None, seek=0, chunk_size=0, mount_vfs=True)- Draw an image from an 8-bit bytearray file stored on disk
len(text, font_size=0)- Calculate the pixel width of a text string for a given font size
line(position,size, color=None)- Draw a horizontal line
line_custom(point_1,point_2, color=None)- Draw a line between two points
pixel(position, color=None)- Draw a single pixel
psram(position,size,addr)- Draw pixel data directly from PSRAM at the specified address and length
rect(position,size, color=None)- Draw a rectangle outline
screenshot(file_path)- Take a screenshot of the current display and save it to the specified file path (.bmp)
set_brightness(level)- Set the display brightness (0-100)
set_mode(mode)- Set the LCD mode (PSRAM or HEAP)
set_scaling(scale_x,scale_y, scale_position=False)- Set the LCD scaling parameters
- `swap`()
- Update the display with the current framebuffer contents
text(position,text, color=None, font_size=-1)- Draw text on the display
triangle(point1,point2,point3, color=None)- Draw a triangle outline
| Method | __del__ |
Destructor to ensure cleanup on object deletion |
| Method | __init__ |
Initialize the drawing context with colors and scaling. |
| Method | background |
Set the current background color. |
| Method | char |
Draw a single character on the display. |
| Method | circle |
Draw a circle outline. |
| Method | clear |
Fill a rectangular area with a color. |
| Method | erase |
Erase the display by filling with background color |
| Method | fill |
Draw a filled circle. |
| Method | fill |
Draw a filled rectangle. |
| Method | fill |
Draw a filled rounded rectangle on the display. |
| Method | fill |
Fill the entire screen with a color. |
| Method | fill |
Draw a filled triangle. |
| Method | fill |
Draw a filled triangle with alpha blending. |
| Method | font |
Set the default font size. |
| Method | foreground |
Set the current foreground color. |
| Method | get |
Get the FontSize object for the specified font size. |
| Method | image |
Draw an image object to the back buffer. |
| Method | image |
Draw a 24-bit BMP image. |
| Method | image |
Draw an image from 8-bit byte data (bytes or bytearray). |
| Method | image |
Draw a 1-bit bitmap from packed byte_data (8 pixels per byte, row-aligned). |
| Method | image |
Draw an image from an 8-bit bytearray file stored on disk. |
| Method | image |
Draw a JPEG image from a file path. |
| Method | image |
Draw a JPEG image from bytes data into a BytesIO buffer. |
| Method | len |
Calculate the pixel width of a text string for a given font size. |
| Method | line |
Draw horizontal line. |
| Method | line |
Draw line between two points. |
| Method | pixel |
Draw a pixel. |
| Method | psram |
Draw pixel data directly from PSRAM at the specified address and length. |
| Method | rect |
Draw a rectangle outline on the display. |
| Method | text |
Draw text on the display. |
| Method | triangle |
Draw a triangle outline. |
| Method | use |
Set whether to use LVGL mode for drawing. |
| Property | background |
Get the current background color |
| Property | font |
Get the default font size |
| Property | font |
Get the font size |
| Property | foreground |
Get the current foreground color |
| Property | size |
Get the size of the display |
| Property | use |
Get whether LVGL mode is enabled |
| Instance Variable | _background |
Undocumented |
| Instance Variable | _font |
Undocumented |
| Instance Variable | _font |
Undocumented |
| Instance Variable | _foreground |
Undocumented |
| Instance Variable | _size |
Undocumented |
| Instance Variable | _use |
Undocumented |
def __init__(self, foreground:
int = 65535, background: int = 0, scale_x: float = 1.0, scale_y: float = 1.0, scale_position: bool = False):
¶
Initialize the drawing context with colors and scaling.
| Parameters | |
foreground:int | The default color for drawing. Defaults to 0xFFFF. |
background:int | The default color for clearing. Defaults to 0x0000. |
scalefloat | Horizontal scaling factor for drawing operations. Defaults to 1.0. |
scalefloat | Vertical scaling factor for drawing operations. Defaults to 1.0. |
scalebool | Whether to scale drawn element positions. Defaults to False. |
Draw a single character on the display.
| Parameters | |
position:Vector | The position to draw the character. |
char:str | The character to draw. |
color:int | The color to use. Defaults to None (foreground). |
fontint | The font size to use. Defaults to -1 (default font). |
Draw a circle outline.
| Parameters | |
position:Vector | The center position of the circle. |
radius:int | The radius of the circle. |
color:int | The color to use. Defaults to None (foreground). |
Draw a filled circle.
| Parameters | |
position:Vector | The center position of the circle. |
radius:int | The radius of the circle. |
color:int | The fill color. Defaults to None (foreground). |
Fill the entire screen with a color.
| Parameters | |
color:int | The fill color. Defaults to None (background). |
Get the FontSize object for the specified font size.
| Parameters | |
fontint | The font size to look up. Defaults to 0. |
| Returns | |
FontSize | The FontSize object for the given size. |
Draw a 24-bit BMP image.
| Parameters | |
position:Vector | The top-left position to draw the image. |
path:str | The path to the BMP file. |
def image_bytearray_path(self, position:
Vector, size: Vector, path: str, storage=None, seek=0, chunk_size=0, invert=False):
¶
Draw an image from an 8-bit bytearray file stored on disk.
| Parameters | |
position:Vector | The top-left position to draw the image. |
size:Vector | The size of the image. |
path:str | The path to the bytearray file. |
| storage | Storage instance for file access. Defaults to None. |
seek:int | Byte offset to start reading from. Defaults to 0. |
chunkint | Number of bytes to read per chunk. Defaults to 0 (read all). |
invert:bool | Whether to invert the pixel values. Defaults to False. |
Draw a JPEG image from a file path.
| Parameters | |
position:Vector | The top-left position to draw the image. |
path:str | The path to the JPEG file. |
| storage | Storage instance for file access. Defaults to None. |
| Returns | |
bool | True on success, False on failure. |
Draw a JPEG image from bytes data into a BytesIO buffer.
| Parameters | |
position:Vector | The top-left position to draw the image. |
| buf | Bytes data containing the JPEG image. |
| Returns | |
bool | True on success, False on failure. |
Calculate the pixel width of a text string for a given font size.
| Parameters | |
text:str | The text to measure. |
fontint | The font size to use. Defaults to 0. |
| Returns | |
int | The pixel width of the text. |
Draw a pixel.
| Parameters | |
position:Vector | The position of the pixel. |
color:int | The pixel color. Defaults to None (foreground). |
Draw text on the display.
| Parameters | |
position:Vector | The position to draw the text. |
text:str | The text to draw. |
color:int | The text color. Defaults to None (foreground). |
fontint | The font size to use. Defaults to -1 (default font). |