Skip to main content

Canvas

Class for easy rendering using CanvasWidgetRenderer. The Canvas class will make implementation of a new CanvasWidget very easy. The few simple primitives allows moving a "pen" and drawing the outline of a shape which can then be rendered.

The Canvas class has been optimized to eliminate drawing unnecessary lines outside the currently invalidated rectangle.

Public Functions

Canvas(const CanvasWidget * _widget, const Rect & invalidatedArea)
Canvas Constructor.
voidlineTo(CWRUtil::Q5 x, CWRUtil::Q5 y)
Draw line from the current (x, y) to the new (x, y) as part of the shape being drawn.
template <typename T >
void
lineTo(T x, T y)
Draw line from the current (x, y) to the new (x, y) as part of the shape being drawn.
voidmoveTo(CWRUtil::Q5 x, CWRUtil::Q5 y)
Move the current pen position to (x, y).
template <typename T >
void
moveTo(T x, T y)
Move the current pen position to (x, y).
boolrender(uint8_t customAlpha =255)
Render the graphical shape drawn using moveTo() and lineTo() with the given Painter.
FORCE_INLINE_FUNCTION boolwasOutlineTooComplex()
Determines if we the outline was too complex to draw completely.
virtual ~Canvas()
Finalizes an instance of the Canvas class.

Public Functions Documentation

Canvas

Canvas(const CanvasWidget *_widget ,
const Rect &invalidatedArea
)

Canvas Constructor.

Locks the framebuffer and prepares for drawing only in the allowed area which has been invalidated. The color depth of the LCD is taken into account.

Parameters:
_widgeta pointer to the CanvasWidget using this Canvas. Used for getting the canvas dimensions.
invalidatedAreathe are which should be updated.
Note

Locks the framebuffer.

lineTo

Draw line from the current (x, y) to the new (x, y) as part of the shape being drawn.

As for moveTo, lineTo commands completely outside the drawing are are discarded.

Parameters:
xThe x coordinate for the pen position in CWRUtil::Q5 format.
yThe y coordinate for the pen position in CWRUtil::Q5 format.
See also:

lineTo

void lineTo(Tx ,
Ty
)

Draw line from the current (x, y) to the new (x, y) as part of the shape being drawn.

As for moveTo, lineTo commands completely outside the drawing are are discarded.

Template Parameters:
Teither int or float.
Parameters:
xThe x coordinate for the pen position.
yThe y coordinate for the pen position.

moveTo

Move the current pen position to (x, y).

If the pen is outside the drawing area, nothing is done, but the coordinates are saved in case the next operation is lineTo a coordinate which is inside (or on the opposite side of) the drawing area.

Parameters:
xThe x coordinate for the pen position in CWRUtil::Q5 format.
yThe y coordinate for the pen position in CWRUtil::Q5 format.

moveTo

void moveTo(Tx ,
Ty
)

Move the current pen position to (x, y).

If the pen is outside (above or below) the drawing area, nothing is done, but the coordinates are saved in case the next operation is lineTo a coordinate which is inside (or on the opposite side of) the drawing area.

Template Parameters:
TEither int or float.
Parameters:
xThe x coordinate for the pen position.
yThe y coordinate for the pen position.

render

bool render(uint8_tcustomAlpha =255)

Render the graphical shape drawn using moveTo() and lineTo() with the given Painter.

The shape is automatically closed, i.e. a lineTo() is automatically inserted connecting the current pen position with the initial pen position given in the first moveTo() command.

Parameters:
customAlpha(Optional) Alpha to apply to the entire canvas. Useful if the canvas is part of a more complex container setup that needs to be faded. Default is solid.
Returns:

true if the widget was rendered, false if insufficient memory was available to render the widget.

wasOutlineTooComplex

FORCE_INLINE_FUNCTION bool wasOutlineTooComplex()

Determines if we the outline was too complex to draw completely.

Returns:

True if it was too complex, false if not.

~Canvas

virtual ~Canvas()

Finalizes an instance of the Canvas class.

Note

Unlocks the framebuffer.