Canvas
touchgfx/widgets/canvas/Canvas.hpp
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 AbstractPainter *const painter, const Rect & canvasAreaAbs, const Rect & invalidatedAreaRel, uint8_t globalAlpha) | |
Canvas Constructor. | |
bool | close() |
Closes the current shape so that the inside can be filled using a Painter. | |
void | cubicBezierTo(float x0, float y0, float x1, float y1, float x2, float y2, float x, float y) |
Draw a Cubic Bezier curve via x1,y1 and x2,y2 to x3,y3. | |
Rasterizer::FillingRule | getFillingRule() const |
Gets the filling rule being used when rendering the outline. | |
virtual 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). | |
void | quadraticBezierTo(float x0, float y0, const float x1, const float y1, const float x, const float y) |
Draw a Quadratic Bezier curve via x1,y1 to x2,y2. | |
bool | render(uint8_t customAlpha =255) |
Render the graphical shape drawn using moveTo() and lineTo() with the given Painter. | |
void | setFillingRule(Rasterizer::FillingRule rule) |
Sets the filling rule to be used when rendering the outline. | |
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 AbstractPainter *const | painter , | ||
const Rect & | canvasAreaAbs , | ||||
const Rect & | invalidatedAreaRel , | ||||
uint8_t | globalAlpha | ||||
) |
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.
painter | The painter used for drawing in the canvas. |
canvasAreaAbs | The canvas dimensions in absolute coordinates. |
invalidatedAreaRel | The area which should be updated in relative coordinates to the canvas area. |
globalAlpha | The alpha value to use when drawing in the canvas. |
Note
Locks the framebuffer.
close
bool close | ( | ) |
Closes the current shape so that the inside can be filled using a Painter.
True if there is enough memory to calculate the shape outline, false if there is too little memory.
cubicBezierTo
void cubicBezierTo | ( | float | x0 , | ||
float | y0 , | ||||
float | x1 , | ||||
float | y1 , | ||||
float | x2 , | ||||
float | y2 , | ||||
float | x , | ||||
float | y | ||||
) |
Draw a Cubic Bezier curve via x1,y1 and x2,y2 to x3,y3.
x0 | The start x coordinate. |
y0 | The start y coordinate. |
x1 | The first 'via' x coordinate. |
y1 | The first 'via' y coordinate. |
x2 | The second 'via' x coordinate. |
y2 | The second 'via' y coordinate. |
x | The end x coordinate. |
y | The end y coordinate. |
getFillingRule
Rasterizer::FillingRule getFillingRule | ( | ) | const |
Gets the filling rule being used when rendering the outline.
The filling rule.
lineTo
virtual 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. |
quadraticBezierTo
void quadraticBezierTo | ( | float | x0 , | ||
float | y0 , | ||||
const float | x1 , | ||||
const float | y1 , | ||||
const float | x , | ||||
const float | y | ||||
) |
Draw a Quadratic Bezier curve via x1,y1 to x2,y2.
x0 | The start x coordinate. |
y0 | The start y coordinate. |
x1 | The 'via' x coordinate. |
y1 | The 'via' y coordinate. |
x | The end x coordinate. |
y | The end y coordinate. |
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.
setFillingRule
void setFillingRule | ( | Rasterizer::FillingRule | rule | ) | |
Sets the filling rule to be used when rendering the outline.
rule | The filling rule. |
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.