Skip to main content

Circle

Simple widget capable of drawing a circle, or part of a circle (an arc). The Circle can be filled or be drawn as a simple line along the circumference of the circle. Several parameters of the circle can be changed: Center, radius, line width, line cap, start angle and end angle.

Note:

  • Since the underlying CanwasWidgetRenderer only supports straight lines, the circle is drawn using many small straight lines segments. The granularity can be adjusted to match the requirements - large circles need more line segments, small circles need fewer line segments, to look smooth and round.
  • All circle parameters are internally handled as CWRUtil::Q5 which means that floating point values are rounded down to a fixed number of binary digits, for example:
Circle circle;
circle.setCircle(1.1f, 1.1f, 0.9); // Will use (35/32, 35/32, 28/32) = (1.09375f, 1.09375f, 0.875f)
int x, y, r;
circle.getCenter(&x, &y); // Will return (1, 1)
circle.getRadius(&r); // Will return 0

.

Inherits from: CanvasWidget, Widget, Drawable

Public Functions

Circle()
virtual booldrawCanvasWidget(const Rect & invalidatedArea) const
Draw canvas widget for the given invalidated area.
template \<typename T \>
void
getArc(T & startAngle, T & endAngle) const
Gets the start and end angles in degrees for the circle arc.
int16_tgetArcEnd() const
Gets the end angle in degrees for the arc.
template \<typename T \>
void
getArcEnd(T & angle) const
Gets the end angle in degrees for the arc.
int16_tgetArcStart() const
Gets the start angle in degrees for the arc.
template \<typename T \>
void
getArcStart(T & angle) const
Gets the start angle in degrees for the arc.
intgetCapPrecision() const
Gets the precision of the ends of the Circle arc.
template \<typename T \>
void
getCenter(T & x, T & y) const
Gets the center coordinates of the Circle.
template \<typename T \>
void
getLineWidth(T & width) const
Gets line width.
virtual RectgetMinimalRect() const
Gets minimal rectangle containing the shape drawn by this widget.
RectgetMinimalRect(CWRUtil::Q5 arcStart, CWRUtil::Q5 arcEnd) const
Gets minimal rectangle containing a given circle arc using the set line width.
RectgetMinimalRect(int16_t arcStart, int16_t arcEnd) const
Gets minimal rectangle containing a given circle arc using the set line width.
intgetPrecision() const
Gets the precision of the circle drawing function.
template \<typename T \>
void
getRadius(T & r) const
Gets the radius of the Circle.
voidsetArc(const int16_t startAngle, const int16_t endAngle)
Sets the start and end angles in degrees of the Circle arc.
template \<typename T \>
void
setArc(const T startAngle, const T endAngle)
Sets the start and end angles in degrees of the Circle arc.
voidsetCapPrecision(const int precision)
Sets the precision of the ends of the Circle arc.
voidsetCenter(const int16_t x, const int16_t y)
Sets the center of the Circle.
template \<typename T \>
void
setCenter(const T x, const T y)
Sets the center of the Circle.
voidsetCircle(const int16_t x, const int16_t y, const int16_t r)
Sets the center and radius of the Circle.
template \<typename T \>
void
setCircle(const T x, const T y, const T r)
Sets the center and radius of the Circle.
template \<typename T \>
void
setLineWidth(const T width)
Sets the line width for this Circle.
voidsetPixelCenter(int x, int y)
Sets the center of the circle / arc in the middle of a pixel.
voidsetPrecision(const int precision)
Sets precision of the Circle drawing function.
template \<typename T \>
void
setRadius(const T r)
Sets the radius of the Circle.
template \<typename T \>
void
updateArc(const T startAngle, const T endAngle)
Updates the start and end angle in degrees for this Circle arc.
template \<typename T \>
void
updateArcEnd(const T endAngle)
Updates the end angle in degrees for this Circle arc.
template \<typename T \>
void
updateArcStart(const T startAngle)
Updates the start angle in degrees for this Circle arc.

Protected Functions

voidupdateArc(const CWRUtil::Q5 setStartAngleQ5, const CWRUtil::Q5 setEndAngleQ5)
Updates the start and end angle in degrees for this Circle arc.

Additional inherited members

Public Functions inherited from CanvasWidget

CanvasWidget()
virtual voiddraw(const Rect & invalidatedArea) const
Draws the given invalidated area.
virtual uint8_tgetAlpha() const
Gets the current alpha value of the 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.

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

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.
virtual voiddraw(const Rect & invalidatedArea) const =0
Draw this drawable.
Drawable()
Initializes a new instance of the Drawable class.
voiddrawToDynamicBitmap(BitmapId id)
Render the Drawable object into a dynamic bitmap.
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 RectgetSolidRect() const =0
Get (the largest possible) rectangle that is guaranteed to be solid (opaque).
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 voidinvalidate() const
Tell the framework that this entire Drawable needs to be redrawn.
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

Circle

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:

Reimplements: touchgfx::CanvasWidget::drawCanvasWidget

getArc

void getArc(T &startAngle ,const
T &endAngleconst
)const

Gets the start and end angles in degrees for the circle arc.

Template Parameters:
TGeneric type parameter, either int or float.
Parameters:
startAngleThe start angle rounded down to the precision of T.
endAngleThe end angle rounded down to the precision of T.
See also:

getArcEnd

int16_t getArcEnd()const

Gets the end angle in degrees for the arc.

Returns:

The end angle for the arc rounded down to an integer.

See also:

getArcEnd

void getArcEnd(T &angle)

Gets the end angle in degrees for the arc.

Template Parameters:
TGeneric type parameter, either int or float.
Parameters:
angleThe end angle rounded down to the precision of T.

getArcStart

int16_t getArcStart()const

Gets the start angle in degrees for the arc.

Returns:

The starting angle for the arc rounded down to an integer.

See also:

getArcStart

void getArcStart(T &angle)

Gets the start angle in degrees for the arc.

Template Parameters:
TGeneric type parameter, either int or float.
Parameters:
angleThe starting angle rounded down to the precision of T.
See also:

getCapPrecision

int getCapPrecision()const

Gets the precision of the ends of the Circle arc.

Returns:

The cap precision in degrees.

See also:

getCenter

void getCenter(T &x ,const
T &yconst
)const

Gets the center coordinates of the Circle.

Template Parameters:
TGeneric type parameter, either int or float.
Parameters:
xThe x coordinate of the center rounded down to the precision of T.
yThe y coordinate of the center rounded down to the precision of T.
See also:

getLineWidth

void getLineWidth(T &width)

Gets line width.

Template Parameters:
TGeneric type parameter, either int or float.
Parameters:
widthThe line width rounded down to the precision of T.
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.

Reimplements: touchgfx::CanvasWidget::getMinimalRect

getMinimalRect

Rect getMinimalRect(CWRUtil::Q5arcStart ,const
CWRUtil::Q5arcEndconst
)const

Gets minimal rectangle containing a given circle arc using the set line width.

Parameters:
arcStartThe arc start.
arcEndThe arc end.
Returns:

The minimal rectangle.

getMinimalRect

Rect getMinimalRect(int16_tarcStart ,const
int16_tarcEndconst
)const

Gets minimal rectangle containing a given circle arc using the set line width.

Parameters:
arcStartThe arc start.
arcEndThe arc end.
Returns:

The minimal rectangle.

getPrecision

int getPrecision()const

Gets the precision of the circle drawing function.

The precision is the number of degrees used as step counter when drawing smaller line fragments around the circumference of the circle, the default being 5.

Returns:

The precision.

See also:

getRadius

void getRadius(T &r)

Gets the radius of the Circle.

Template Parameters:
TGeneric type parameter, either int or float.
Parameters:
rThe radius rounded down to the precision of T.

setArc

void setArc(const int16_tstartAngle ,
const int16_tendAngle
)

Sets the start and end angles in degrees of the Circle arc.

0 degrees is straight up (12 o'clock) and 90 degrees is to the left (3 o'clock). Any positive or negative degrees can be used to specify the part of the Circle to draw.

Parameters:
startAngleThe start degrees.
endAngleThe end degrees.
Note

The area containing the Circle is not invalidated.

See also:

setArc

void setArc(const TstartAngle ,
const TendAngle
)

Sets the start and end angles in degrees of the Circle arc.

0 degrees is straight up (12 o'clock) and 90 degrees is to the left (3 o'clock). Any positive or negative degrees can be used to specify the part of the Circle to draw.

Template Parameters:
TGeneric type parameter, either int or float.
Parameters:
startAngleThe start degrees.
endAngleThe end degrees.
Note

The area containing the Circle is not invalidated.

See also:

setCapPrecision

void setCapPrecision(const intprecision)

Sets the precision of the ends of the Circle arc.

The precision is given in degrees where 180 is the default which results in a square ended arc (aka "butt cap"). 90 will draw "an arrow head" and smaller values gives a round cap. Larger values of precision results in faster rendering of the circle.

Parameters:
precisionThe new cap precision.
Note

The circle is not invalidated. The cap precision is not used if the circle is filled (if line width is zero) or when a full circle is drawn.

setCenter

void setCenter(const int16_tx ,
const int16_ty
)

Sets the center of the Circle.

Parameters:
xThe x coordinate of center.
yThe y coordinate of center.
Note

The area containing the Circle is not invalidated.

See also:

setCenter

void setCenter(const Tx ,
const Ty
)

Sets the center of the Circle.

Template Parameters:
TGeneric type parameter, either int or float.
Parameters:
xThe x coordinate of center.
yThe y coordinate of center.
Note

The area containing the Circle is not invalidated.

See also:

setCircle

void setCircle(const int16_tx ,
const int16_ty ,
const int16_tr
)

Sets the center and radius of the Circle.

Parameters:
xThe x coordinate of center.
yThe y coordinate of center.
rThe radius.
Note

The area containing the Circle is not invalidated.

See also:

setCircle

void setCircle(const Tx ,
const Ty ,
const Tr
)

Sets the center and radius of the Circle.

Template Parameters:
TGeneric type parameter, either int or float.
Parameters:
xThe x coordinate of center.
yThe y coordinate of center.
rThe radius.
Note

The area containing the Circle is not invalidated.

See also:

setLineWidth

void setLineWidth(const Twidth)

Sets the line width for this Circle.

If the line width is set to zero, the circle will be filled.

Template Parameters:
TGeneric type parameter, either int or float.
Parameters:
widthThe width of the line measured in pixels.
Note

The area containing the Circle is not invalidated. if the new line with is smaller than the old width, the circle should be invalidated before updating the width to ensure that the old circle is completely erased.

setPixelCenter

void setPixelCenter(intx ,
inty
)

Sets the center of the circle / arc in the middle of a pixel.

Normally the coordinate is between pixel number x and x+1 horizontally and between pixel y and y+1 vertically. This function will set the center in the middle of the pixel by adding 0.5 to both x and y.

Parameters:
xThe x coordinate of the center of the circle.
yThe y coordinate of the center of the circle.

setPrecision

void setPrecision(const intprecision)

Sets precision of the Circle drawing function.

The number given as precision is the number of degrees used as step counter when drawing the line fragments around the circumference of the circle, five being a reasonable value. Higher values results in less nice circles but faster rendering and possibly sufficient for very small circles. Large circles might require a precision smaller than five to make the edge of the circle look nice and smooth.

Parameters:
precisionThe precision measured in degrees.
Note

The circle is not invalidated.

setRadius

void setRadius(const Tr)

Sets the radius of the Circle.

Template Parameters:
TGeneric type parameter, either int or float.
Parameters:
rThe radius.
Note

The area containing the Circle is not invalidated.

See also:

updateArc

void updateArc(const TstartAngle ,
const TendAngle
)

Updates the start and end angle in degrees for this Circle arc.

Template Parameters:
TGeneric type parameter, either int or float.
Parameters:
startAngleThe new start angle in degrees.
endAngleThe new end angle in degrees.
Note

The areas containing the updated Circle arcs are invalidated. As little as possible will be invalidated for best performance.

See also:

updateArcEnd

void updateArcEnd(const TendAngle)

Updates the end angle in degrees for this Circle arc.

Template Parameters:
TGeneric type parameter, either int or float.
Parameters:
endAngleThe end angle in degrees.
Note

The area containing the updated Circle arc is invalidated.

See also:

updateArcStart

void updateArcStart(const TstartAngle)

Updates the start angle in degrees for this Circle arc.

Template Parameters:
TGeneric type parameter, either int or float.
Parameters:
startAngleThe start angle in degrees.
Note

The area containing the updated Circle arc is invalidated.

See also:

Protected Functions Documentation

updateArc

void updateArc(const CWRUtil::Q5setStartAngleQ5 ,
const CWRUtil::Q5setEndAngleQ5
)

Updates the start and end angle in degrees for this Circle arc.

Parameters:
setStartAngleQ5The new start angle in degrees.
setEndAngleQ5The new end angle in degrees.
Note

The areas containing the updated Circle arcs are invalidated. As little as possible will be invalidated for best performance.

See also: