주요 내용으로 건너뛰기

CanvasWidget

Class for drawing complex polygons on the display using CanvasWidgetRenderer. The CanvasWidget is used by passing it to a Canvas object, drawing the outline of the object and then having CanvasWidget render the outline on the display using the assigned painter.

Inherits from: Widget, Drawable

Inherited by: AbstractGraphElement, AbstractShape, Circle, Line

Public Functions

CanvasWidget()
virtual voiddraw(const Rect & invalidatedArea) const
Draws the given invalidated area.
virtual booldrawCanvasWidget(const Rect & invalidatedArea) const =0
Draw canvas widget for the given invalidated area.
virtual uint8_tgetAlpha() const
Gets the current alpha value of the widget.
virtual RectgetMinimalRect() const
Gets minimal rectangle containing the shape drawn by this widget.
virtual AbstractPainter &getPainter() const
Gets the current painter for the CanvasWidget.
virtual RectgetSolidRect() const
Gets the largest solid (non-transparent) rectangle.
virtual voidinvalidate() const
Invalidates the area covered by this CanvasWidget.
voidresetMaxRenderLines()
Resets the maximum render lines.
virtual voidsetAlpha(uint8_t newAlpha)
Sets the opacity (alpha value).
virtual voidsetPainter(AbstractPainter & painter)
Sets a painter for the CanvasWidget.

Additional inherited members

Public Functions inherited from Widget

virtual voidgetLastChild(int16_t x, int16_t y, Drawable ** last)
Since a Widget is only one Drawable, Widget::getLastChild simply yields itself as result, but only if the Widget isVisible and isTouchable.

Public Functions inherited from Drawable

voidcenter()
Centers the Drawable inside its parent.
voidcenterX()
Center the Drawable horizontally inside its parent.
voidcenterY()
Center the Drawable vertically inside its parent.
virtual voidchildGeometryChanged()
This function can be called on parent nodes to signal that the size or position of one or more of its children has changed.
Drawable()
Initializes a new instance of the Drawable class.
voiddrawToDynamicBitmap(BitmapId id)
Render the Drawable object into a dynamic bitmap.
voidexpand(int margin =0)
Expands the Drawable to have the same size as its parent with a given margin around the edge.
RectgetAbsoluteRect() const
Helper function for obtaining the rectangle this Drawable covers, expressed in absolute coordinates.
virtual Drawable *getFirstChild()
Function for obtaining the first child of this drawable if any.
int16_tgetHeight() const
Gets the height of this Drawable.
virtual voidgetLastChild(int16_t x, int16_t y, Drawable ** last) =0
Function for obtaining the the last child of this drawable that intersects with the specified point.
Drawable *getNextSibling()
Gets the next sibling node.
Drawable *getParent() const
Returns the parent node.
const Rect &getRect() const
Gets the rectangle this Drawable covers, in coordinates relative to its parent.
virtual RectgetSolidRectAbsolute()
Helper function for obtaining the largest solid rect (as implemented by getSolidRect()) expressed in absolute coordinates.
virtual voidgetVisibleRect(Rect & rect) const
Function for finding the visible part of this drawable.
int16_tgetWidth() const
Gets the width of this Drawable.
int16_tgetX() const
Gets the x coordinate of this Drawable, relative to its parent.
int16_tgetY() const
Gets the y coordinate of this Drawable, relative to its parent.
virtual voidhandleClickEvent(const ClickEvent & event)
Defines the event handler interface for ClickEvents.
virtual voidhandleDragEvent(const DragEvent & event)
Defines the event handler interface for DragEvents.
virtual voidhandleGestureEvent(const GestureEvent & event)
Defines the event handler interface for GestureEvents.
virtual voidhandleTickEvent()
Called periodically by the framework if the Drawable instance has subscribed to timer ticks.
virtual voidinvalidateRect(Rect & invalidatedArea) const
Request that a region of this drawable is redrawn.
boolisTouchable() const
Gets whether this Drawable receives touch events or not.
boolisVisible() const
Gets whether this Drawable is visible.
virtual voidmoveRelative(int16_t x, int16_t y)
Moves the drawable.
virtual voidmoveTo(int16_t x, int16_t y)
Moves the drawable.
virtual voidsetHeight(int16_t height)
Sets the height of this drawable.
voidsetPosition(const Drawable & drawable)
Sets the position of the Drawable to the same as the given Drawable.
voidsetPosition(int16_t x, int16_t y, int16_t width, int16_t height)
Sets the size and position of this Drawable, relative to its parent.
voidsetTouchable(bool touch)
Controls whether this Drawable receives touch events or not.
voidsetVisible(bool vis)
Controls whether this Drawable should be visible.
virtual voidsetWidth(int16_t width)
Sets the width of this drawable.
voidsetWidthHeight(const Bitmap & bitmap)
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates).
voidsetWidthHeight(const Drawable & drawable)
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates).
voidsetWidthHeight(const Rect & rect)
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates).
voidsetWidthHeight(int16_t width, int16_t height)
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates).
virtual voidsetX(int16_t x)
Sets the x coordinate of this Drawable, relative to its parent.
voidsetXY(const Drawable & drawable)
Sets the x and y coordinates of this Drawable.
voidsetXY(int16_t x, int16_t y)
Sets the x and y coordinates of this Drawable, relative to its parent.
virtual voidsetY(int16_t y)
Sets the y coordinate of this Drawable, relative to its parent.
virtual voidtranslateRectToAbsolute(Rect & r) const
Helper function for converting a region of this Drawable to absolute coordinates.
virtual ~Drawable()
Finalizes an instance of the Drawable class.

Protected Attributes inherited from Drawable

Drawable *nextSibling
Pointer to the next Drawable.
Drawable *parent
Pointer to this drawable's parent.
Rectrect
The coordinates of this Drawable, relative to its parent.
booltouchable
True if this drawable should receive touch events.
boolvisible
True if this drawable should be drawn.

Public Functions Documentation

CanvasWidget

draw

virtual void draw(const Rect &invalidatedArea)

Draws the given invalidated area.

If the underlying CanvasWidgetRenderer fail to render the widget (if the widget is too complex), the invalidated area is cut into smaller slices (horizontally) which are then drawn separately. If drawing a single raster line fails, that line is considered too complex and skipped (it is left blank/transparent) and drawing continues on the next raster line.

If drawing has failed at least once, which means that the number of horizontal lines draw has been reduced, the number of successfully drawn horizontal lines is remembered for the next invocation of draw(). A future call to draw() would then start off with the reduced number of horizontal lines to prevent potentially drawing the canvas widget in vain, as happened previously in draw().

Parameters:
invalidatedAreaThe invalidated area.
Note

Subclasses of CanvasWidget should implement drawCanvasWidget(), not draw(). The term "too complex" means that the size of the buffer (assigned to CanvasWidgetRenderer using CanvasWidgetRenderer::setupBuffer()) is too small.

See also:

Reimplements: touchgfx::Drawable::draw

Reimplemented by: touchgfx::GraphElementGridX::draw, touchgfx::GraphElementGridY::draw, touchgfx::GraphElementVerticalGapLine::draw, touchgfx::GraphElementHistogram::draw, touchgfx::GraphElementBoxes::draw, touchgfx::GraphLabelsX::draw, touchgfx::GraphLabelsY::draw, touchgfx::GraphTitle::draw

drawCanvasWidget

virtual bool drawCanvasWidget(const Rect &invalidatedArea)

Draw canvas widget for the given invalidated area.

Similar to draw(), but might be invoked several times with increasingly smaller areas to due to memory constraints from the underlying CanvasWidgetRenderer.

Parameters:
invalidatedAreaThe invalidated area.
Returns:

true if the widget was drawn properly, false if not.

See also:

Reimplemented by: touchgfx::AbstractShape::drawCanvasWidget, touchgfx::Circle::drawCanvasWidget, touchgfx::Line::drawCanvasWidget, touchgfx::AbstractGraphElementNoCWR::drawCanvasWidget, touchgfx::GraphElementArea::drawCanvasWidget, touchgfx::GraphElementLine::drawCanvasWidget, touchgfx::GraphElementDots::drawCanvasWidget, touchgfx::GraphElementDiamonds::drawCanvasWidget, touchgfx::GraphTitle::drawCanvasWidget

getAlpha

virtual uint8_t getAlpha()const

Gets the current alpha value of the widget.

The alpha value is in range 255 (solid) to 0 (invisible).

Returns:

The current alpha value.

See also:

getMinimalRect

virtual Rect getMinimalRect()const

Gets minimal rectangle containing the shape drawn by this widget.

Default implementation returns the size of the entire widget, but this function should be overwritten in subclasses and return the minimal rectangle containing the shape. See classes such as Circle for example implementations.

Returns:

The minimal rectangle containing the shape drawn.

Reimplemented by: touchgfx::AbstractShape::getMinimalRect, touchgfx::Circle::getMinimalRect, touchgfx::Line::getMinimalRect

getPainter

virtual AbstractPainter & getPainter()const

Gets the current painter for the CanvasWidget.

Returns:

The painter.

See also:

getSolidRect

virtual Rect getSolidRect()const

Gets the largest solid (non-transparent) rectangle.

Since canvas widgets typically do not have a solid rect, it is recommended to return an empty rectangle.

Returns:

The largest solid (non-transparent) rectangle.

Note

Function draw() might fail for some horizontal lines due to memory constraints. These lines will not be drawn and may cause strange display artifacts.

See also:

Reimplements: touchgfx::Drawable::getSolidRect

invalidate

virtual void invalidate()const

Invalidates the area covered by this CanvasWidget.

Since many widgets are a lot smaller than the actual size of the canvas widget, each widget must be able to tell the smallest rectangle completely containing the shape drawn by the widget. For example a circle arc is typically much smaller than the widget containing the circle.

See also:

Reimplements: touchgfx::Drawable::invalidate

resetMaxRenderLines

Resets the maximum render lines.

The maximum render lines is decreates if the rendering buffer is found to be too small to render a complex outline. This is done to speed up subsequent draws by not having to draw the outline in vain (as was done previously) to force the outline to be drawn in smaller blocks. The resetMaxRenderLines() will try to render the entire outline in one go on the next call to draw().

setAlpha

virtual void setAlpha(uint8_tnewAlpha)

Sets the opacity (alpha value).

This can be used to fade it away by gradually decreasing the alpha value from 255 (solid) to 0 (invisible).

Parameters:
newAlphaThe new alpha value. 255=solid, 0=invisible.
Note

The user code must call invalidate() in order to update the display.

See also:

setPainter

virtual void setPainter(AbstractPainter &painter)

Sets a painter for the CanvasWidget.

Parameters:
painterThe painter for the CanvasWidget.
Note

If setPainter() is used to change the painter to a different painter, the area containing the CanvasWidget is not automatically invalidated.

See also:

Reimplemented by: touchgfx::AbstractGraphElementNoCWR::setPainter