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. | |
void | lineTo(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. | |
void | moveTo(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). | |
bool | render(uint8_t customAlpha =255) |
Render the graphical shape drawn using moveTo() and lineTo() with the given Painter. | |
FORCE_INLINE_FUNCTION bool | wasOutlineTooComplex() |
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.
_widget | a pointer to the CanvasWidget using this Canvas. Used for getting the canvas dimensions. |
invalidatedArea | the are which should be updated. |
Note
Locks the framebuffer.
lineTo
void lineTo | ( | 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.
As for moveTo, lineTo commands completely outside the drawing are are discarded.
x | The x coordinate for the pen position in CWRUtil::Q5 format. |
y | The y coordinate for the pen position in CWRUtil::Q5 format. |
lineTo
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.
As for moveTo, lineTo commands completely outside the drawing are are discarded.
T | either int or float. |
x | The x coordinate for the pen position. |
y | The y coordinate for the pen position. |
moveTo
void moveTo | ( | CWRUtil::Q5 | x , | ||
CWRUtil::Q5 | y | ||||
) |
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.
x | The x coordinate for the pen position in CWRUtil::Q5 format. |
y | The y coordinate for the pen position in CWRUtil::Q5 format. |
moveTo
void moveTo | ( | T | x , | ||
T | y | ||||
) |
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.
T | Either int or float. |
x | The x coordinate for the pen position. |
y | The y coordinate for the pen position. |
render
bool render | ( | uint8_t | customAlpha =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.
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. |
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.
True if it was too complex, false if not.