Skip to main content

AbstractPainter

touchgfx/widgets/canvas/AbstractPainter.hpp

An abstract class for creating painter classes for drawing canvas widgets. All canvas widgets need a painter to fill the shape drawn with a CanvasWidgetRenderer. The painter must provide the color of a pixel on a given coordinate, which will the be blended into the framebuffer depending on the position of the canvas widget and the transparency of the given pixel.

The AbstractPainter also implements a function which will blend each pixel in a scanline snippet into the framebuffer, but for better performance, the function should be reimplemented in each painter.

Inherited by: AbstractPainterABGR2222, AbstractPainterARGB2222, AbstractPainterARGB8888, AbstractPainterBGRA2222, AbstractPainterBW, AbstractPainterGRAY2, AbstractPainterGRAY4, AbstractPainterLinearGradient, AbstractPainterRGB565, AbstractPainterRGB888, AbstractPainterRGBA2222

Public Functions

AbstractPainter()
Initializes a new instance of the AbstractPainter class.
voidframebufferToDisplay(int16_t & widgetX, int16_t & widgetY) const
Convert Framebuffer widget coordinates to display widget coordinates.
virtual HAL::RenderingMethodgetRenderingMethod() const
Return the applicable rendering method of the painter.
virtual voidpaint(uint8_t * destination, int16_t offset, int16_t widgetX, int16_t widgetY, int16_t count, uint8_t alpha) const =0
Paints a streak of pixels (all with the same alpha) in the framebuffer.
virtual boolsetup(const Rect & widgetRect) const
This function is called before any actual paint operation is started.
virtual voidtearDown() const
This function is called after all paint operation have finished.
virtual ~AbstractPainter()
Finalizes an instance of the AbstractPainter class.

Protected Functions

FORCE_INLINE_FUNCTION boolcompatibleFramebuffer(Bitmap::BitmapFormat format)
Helper function to check if the provided bitmap format matches the current framebuffer format.

Protected Attributes

int16_twidgetWidth
The width of the widget on screen, used by framebufferToDisplay()

Public Functions Documentation

AbstractPainter

Initializes a new instance of the AbstractPainter class.

framebufferToDisplay

void framebufferToDisplay(int16_t &widgetX ,const
int16_t &widgetYconst
)const

Convert Framebuffer widget coordinates to display widget coordinates.

This is handy when creating a custom painter and the X,Y is needed in the same coordinate system as the widget on the display.

Parameters:
widgetXThe widget x coordinate.
widgetYThe widget y coordinate.
See also:

getRenderingMethod

virtual HAL::RenderingMethod getRenderingMethod()const

Return the applicable rendering method of the painter.

HARDWARE if the painter uses hardware based drawing, SOFTWARE otherwise. Relevant on platforms using DCACHE.

Returns:

HARDWARE if painter uses hardware based drawing, SOFTWARE otherwise.

Reimplemented by: touchgfx::PainterRGB565::getRenderingMethod, touchgfx::PainterRGB565Bitmap::getRenderingMethod, touchgfx::PainterRGB565L8Bitmap::getRenderingMethod, touchgfx::PainterRGB888::getRenderingMethod, touchgfx::PainterRGB888Bitmap::getRenderingMethod, touchgfx::PainterRGB888L8Bitmap::getRenderingMethod

paint

virtual void paint(uint8_t *destination ,const =0
int16_toffset ,const =0
int16_twidgetX ,const =0
int16_twidgetY ,const =0
int16_tcount ,const =0
uint8_talphaconst =0
)const =0

Paints a streak of pixels (all with the same alpha) in the framebuffer.

The first pixel to paint is at 'offset' relative to 'destination' (to be able to support 1bpp, 2bpp and 4bpp). The first pixel to paint is at the given 'widgetX', 'widgetY' coordinate. The number of pixels to paint is 'count' and the alpha to apply is 'alpha'.

Note that the widgetX, widgetY is relative to the widget in the framebuffer, not the display. To convert the coordinate to display widget coordinates, use framebufferToDisplay().

Parameters:
destinationIf non-null, the pointer.
offsetThe offset to add to the destination.
widgetXThe widget x coordinate.
widgetYThe widget y coordinate.
countNumber of pixels.
alphaThe alpha of the pixels.
See also:

Reimplemented by: touchgfx::PainterABGR2222::paint, touchgfx::PainterABGR2222Bitmap::paint, touchgfx::PainterARGB2222::paint, touchgfx::PainterARGB2222Bitmap::paint, touchgfx::PainterARGB8888::paint, touchgfx::PainterARGB8888Bitmap::paint, touchgfx::PainterARGB8888L8Bitmap::paint, touchgfx::PainterBGRA2222::paint, touchgfx::PainterBGRA2222Bitmap::paint, touchgfx::PainterBW::paint, touchgfx::PainterBWBitmap::paint, touchgfx::PainterGRAY2::paint, touchgfx::PainterGRAY2Bitmap::paint, touchgfx::PainterGRAY4::paint, touchgfx::PainterGRAY4Bitmap::paint, touchgfx::PainterRGB565::paint, touchgfx::PainterRGB565Bitmap::paint, touchgfx::PainterRGB565L8Bitmap::paint, touchgfx::PainterRGB565LinearGradient::paint, touchgfx::PainterRGB888::paint, touchgfx::PainterRGB888Bitmap::paint, touchgfx::PainterRGB888L8Bitmap::paint, touchgfx::PainterRGB888LinearGradient::paint, touchgfx::PainterRGBA2222::paint, touchgfx::PainterRGBA2222Bitmap::paint, touchgfx::PainterXRGB8888::paint, touchgfx::PainterXRGB8888Bitmap::paint, touchgfx::PainterXRGB8888L8Bitmap::paint

setup

virtual bool setup(const Rect &widgetRect)

This function is called before any actual paint operation is started.

This allows the painter to initialize variables and optional dma queues. This happens before the first scan line segment is being drawn. If the painter is unable to draw, e.g. no bitmap assigned to a bitmap painter, 'false' should be returned.

Parameters:
widgetRectThe widget rectangle.
Returns:

True if the painter is ready to paint, false otherwise.

See also:

Reimplemented by: touchgfx::PainterABGR2222Bitmap::setup, touchgfx::PainterARGB2222Bitmap::setup, touchgfx::PainterARGB8888Bitmap::setup, touchgfx::PainterARGB8888L8Bitmap::setup, touchgfx::PainterBGRA2222Bitmap::setup, touchgfx::PainterBWBitmap::setup, touchgfx::PainterGRAY2Bitmap::setup, touchgfx::PainterGRAY4Bitmap::setup, touchgfx::PainterRGB565Bitmap::setup, touchgfx::PainterRGB565L8Bitmap::setup, touchgfx::PainterRGB888Bitmap::setup, touchgfx::PainterRGB888L8Bitmap::setup, touchgfx::PainterRGBA2222Bitmap::setup, touchgfx::PainterXRGB8888Bitmap::setup, touchgfx::PainterXRGB8888L8Bitmap::setup

tearDown

~AbstractPainter

virtual ~AbstractPainter()

Finalizes an instance of the AbstractPainter class.

Protected Functions Documentation

compatibleFramebuffer

static FORCE_INLINE_FUNCTION bool compatibleFramebuffer(Bitmap::BitmapFormatformat)

Helper function to check if the provided bitmap format matches the current framebuffer format.

Parameters:
formatA bitmap format.
Returns:

True if the format matches the framebuffer format, false otherwise.

Protected Attributes Documentation

widgetWidth

int16_t widgetWidth

The width of the widget on screen, used by framebufferToDisplay()