touchgfx::Canvas class
@class Canvas Canvas.hpp 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 above and below the currently invalidated rectangle. This was chosen because CanvasWidgetRenderer works with horizontal scan lines, and eliminating unnecessary lines on the left and right does result in as good optimizations, and in some cases (as e.g. Circle) work against the desired (and expected) optimization.
class Canvas
{
public:
Canvas(const CanvasWidget* _widget, const Rect& invalidatedArea);
virtual ~Canvas();
void moveTo(CWRUtil::Q5 x, CWRUtil::Q5 y);
void lineTo(CWRUtil::Q5 x, CWRUtil::Q5 y);
template <typename T>
void moveTo(T x, T y)
{
moveTo(CWRUtil::toQ5<T>(x), CWRUtil::toQ5<T>(y));
}
template <typename T>
void lineTo(T x, T y)
{
lineTo(CWRUtil::toQ5<T>(x), CWRUtil::toQ5<T>(y));
}
bool render();
private:
const CanvasWidget* widget;
CWRUtil::Q5 invalidatedAreaX;
CWRUtil::Q5 invalidatedAreaY;
CWRUtil::Q5 invalidatedAreaWidth;
CWRUtil::Q5 invalidatedAreaHeight;
RenderingBuffer rbuf;
Rasterizer ras;
int16_t offsetX, offsetY;
bool enoughMemory;
bool penUp, penHasBeenDown;
CWRUtil::Q5 previousX, previousY;
uint8_t previousOutside;
uint8_t penDownOutside;
CWRUtil::Q5 initialX, initialY;
enum
{
POINT_IS_ABOVE = 1 << 0,
POINT_IS_BELOW = 1 << 1,
POINT_IS_LEFT = 1 << 2,
POINT_IS_RIGHT = 1 << 3
};
uint8_t isOutside(const CWRUtil::Q5& x, const CWRUtil::Q5& y, const CWRUtil::Q5& width, const CWRUtil::Q5& height) const;
void transformFrameBufferToDisplay(CWRUtil::Q5& x, CWRUtil::Q5& y) const;
void close();
};
invalidatedAreaX
invalidatedAreaY
invalidatedAreaWidth
invalidatedAreaHeight
rbuf
ras
offsetX
offsetY
enoughMemory
penUp
penHasBeenDown
previousX
previousY
previousOutside
penDownOutside
initialX
initialY
Methods
moveTo()
lineTo()
moveTo()
lineTo()
render()
@fn bool Canvas::render(); Render the drawn shape. Render the graphical shape drawn (using moveTo() and lineTo()) using the widgets 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 previous moveTo() command.
Read more...
isOutside() const
@fn void Canvas::transformFrameBufferToDisplay(CWRUtil::Q5& x, CWRUtil::Q5& y) const; Transform frame buffer coordinates to display coordinates. Transform frame buffer coordinates to display coordinates for Q5 coordinates. @see DisplayTransformation::transformFrameBufferToDisplay().
Read more...
close()
@fn void Canvas::close() Closes the path being drawn. Closes the path being drawn using moveTo and lineTo.
Read more...
Examples
touchgfx::Canvas is referenced by
3 libraries and example projects.
Variables of touchgfx::Canvas type
touchgfx::Canvas