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 bool | drawCanvasWidget(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_t | getArcEnd() 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_t | getArcStart() 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. | |
int | getCapPrecision() 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 Rect | getMinimalRect() const |
Gets minimal rectangle containing the shape drawn by this widget. | |
Rect | getMinimalRect(CWRUtil::Q5 arcStart, CWRUtil::Q5 arcEnd) const |
Gets minimal rectangle containing a given circle arc using the set line width. | |
Rect | getMinimalRect(int16_t arcStart, int16_t arcEnd) const |
Gets minimal rectangle containing a given circle arc using the set line width. | |
int | getPrecision() const |
Gets the precision of the circle drawing function. | |
template <typename T > void | getRadius(T & r) const |
Gets the radius of the Circle. | |
void | setArc(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. | |
void | setCapPrecision(const int precision) |
Sets the precision of the ends of the Circle arc. | |
void | setCenter(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. | |
void | setCircle(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. | |
void | setPixelCenter(int x, int y) |
Sets the center of the circle / arc in the middle of a pixel. | |
void | setPrecision(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
void | updateArc(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 void | draw(const Rect & invalidatedArea) const |
Draws the given invalidated area. | |
virtual uint8_t | getAlpha() const |
Gets the current alpha value of the widget. | |
virtual AbstractPainter & | getPainter() const |
Gets the current painter for the CanvasWidget. | |
virtual Rect | getSolidRect() const |
Gets the largest solid (non-transparent) rectangle. | |
virtual void | invalidate() const |
Invalidates the area covered by this CanvasWidget. | |
void | resetMaxRenderLines() |
Resets the maximum render lines. | |
virtual void | setAlpha(uint8_t newAlpha) |
Sets the opacity (alpha value). | |
virtual void | setPainter(AbstractPainter & painter) |
Sets a painter for the CanvasWidget. | |
Protected Attributes inherited from CanvasWidget
uint8_t | alpha |
The Alpha for this CanvasWidget. | |
Public Functions inherited from Widget
virtual void | getLastChild(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
void | center() |
Centers the Drawable inside its parent. | |
void | centerX() |
Center the Drawable horizontally inside its parent. | |
void | centerY() |
Center the Drawable vertically inside its parent. | |
virtual void | childGeometryChanged() |
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 void | draw(const Rect & invalidatedArea) const =0 |
Draw this drawable. | |
Drawable() | |
Initializes a new instance of the Drawable class. | |
void | drawToDynamicBitmap(BitmapId id) |
Render the Drawable object into a dynamic bitmap. | |
void | expand(int margin =0) |
Expands the Drawable to have the same size as its parent with a given margin around the edge. | |
Rect | getAbsoluteRect() 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_t | getHeight() const |
Gets the height of this Drawable. | |
virtual void | getLastChild(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 Rect | getSolidRect() const =0 |
Get (the largest possible) rectangle that is guaranteed to be solid (opaque). | |
virtual Rect | getSolidRectAbsolute() |
Helper function for obtaining the largest solid rect (as implemented by getSolidRect()) expressed in absolute coordinates. | |
virtual void | getVisibleRect(Rect & rect) const |
Function for finding the visible part of this drawable. | |
int16_t | getWidth() const |
Gets the width of this Drawable. | |
int16_t | getX() const |
Gets the x coordinate of this Drawable, relative to its parent. | |
int16_t | getY() const |
Gets the y coordinate of this Drawable, relative to its parent. | |
virtual void | handleClickEvent(const ClickEvent & event) |
Defines the event handler interface for ClickEvents. | |
virtual void | handleDragEvent(const DragEvent & event) |
Defines the event handler interface for DragEvents. | |
virtual void | handleGestureEvent(const GestureEvent & event) |
Defines the event handler interface for GestureEvents. | |
virtual void | handleTickEvent() |
Called periodically by the framework if the Drawable instance has subscribed to timer ticks. | |
virtual void | invalidate() const |
Tell the framework that this entire Drawable needs to be redrawn. | |
virtual void | invalidateContent() const |
Tell the framework that the contents of the Drawable needs to be redrawn. | |
virtual void | invalidateRect(Rect & invalidatedArea) const |
Request that a region of this drawable is redrawn. | |
bool | isTouchable() const |
Gets whether this Drawable receives touch events or not. | |
bool | isVisible() const |
Gets whether this Drawable is visible. | |
virtual void | moveRelative(int16_t x, int16_t y) |
Moves the drawable. | |
virtual void | moveTo(int16_t x, int16_t y) |
Moves the drawable. | |
virtual void | setHeight(int16_t height) |
Sets the height of this drawable. | |
void | setPosition(const Drawable & drawable) |
Sets the position of the Drawable to the same as the given Drawable. | |
void | setPosition(int16_t x, int16_t y, int16_t width, int16_t height) |
Sets the size and position of this Drawable, relative to its parent. | |
void | setTouchable(bool touch) |
Controls whether this Drawable receives touch events or not. | |
void | setVisible(bool vis) |
Controls whether this Drawable should be visible. | |
virtual void | setWidth(int16_t width) |
Sets the width of this drawable. | |
void | setWidthHeight(const Bitmap & bitmap) |
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates). | |
void | setWidthHeight(const Drawable & drawable) |
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates). | |
void | setWidthHeight(const Rect & rect) |
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates). | |
void | setWidthHeight(int16_t width, int16_t height) |
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates). | |
virtual void | setX(int16_t x) |
Sets the x coordinate of this Drawable, relative to its parent. | |
void | setXY(const Drawable & drawable) |
Sets the x and y coordinates of this Drawable. | |
void | setXY(int16_t x, int16_t y) |
Sets the x and y coordinates of this Drawable, relative to its parent. | |
virtual void | setY(int16_t y) |
Sets the y coordinate of this Drawable, relative to its parent. | |
virtual void | translateRectToAbsolute(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. | |
Rect | rect |
The coordinates of this Drawable, relative to its parent. | |
bool | touchable |
True if this drawable should receive touch events. | |
bool | visible |
True if this drawable should be drawn. | |
Public Functions Documentation
Circle
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.
invalidatedArea | The invalidated area. |
true if the widget was drawn properly, false if not.
Reimplements: touchgfx::CanvasWidget::drawCanvasWidget
getArc
void getArc | ( | T & | startAngle , | const | |
T & | endAngle | const | |||
) | const |
Gets the start and end angles in degrees for the circle arc.
T | Generic type parameter, either int or float. |
startAngle | The start angle rounded down to the precision of T. |
endAngle | The end angle rounded down to the precision of T. |
Note
Angles are given in degrees, so a full circle is 360.
getArcEnd
int16_t getArcEnd | ( | ) | const |
getArcEnd
void getArcEnd | ( | T & | angle | ) | |
Gets the end angle in degrees for the arc.
T | Generic type parameter, either int or float. |
angle | The end angle rounded down to the precision of T. |
Note
Angles are given in degrees, so a full circle is 360.
getArcStart
int16_t getArcStart | ( | ) | const |
getArcStart
void getArcStart | ( | T & | angle | ) | |
getCapPrecision
int getCapPrecision | ( | ) | const |
getCenter
void getCenter | ( | T & | x , | const | |
T & | y | const | |||
) | const |
getLineWidth
void getLineWidth | ( | T & | width | ) | |
Gets line width.
T | Generic type parameter, either int or float. |
width | The line width rounded down to the precision of T. |
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.
The minimal rectangle containing the shape drawn.
Reimplements: touchgfx::CanvasWidget::getMinimalRect
getMinimalRect
Rect getMinimalRect | ( | CWRUtil::Q5 | arcStart , | const | |
CWRUtil::Q5 | arcEnd | const | |||
) | const |
Gets minimal rectangle containing a given circle arc using the set line width.
arcStart | The arc start. |
arcEnd | The arc end. |
The minimal rectangle.
getMinimalRect
Rect getMinimalRect | ( | int16_t | arcStart , | const | |
int16_t | arcEnd | const | |||
) | const |
Gets minimal rectangle containing a given circle arc using the set line width.
arcStart | The arc start. |
arcEnd | The arc end. |
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.
The precision.
getRadius
void getRadius | ( | T & | r | ) | |
Gets the radius of the Circle.
T | Generic type parameter, either int or float. |
r | The radius rounded down to the precision of T. |
setArc
void setArc | ( | const int16_t | startAngle , | ||
const int16_t | endAngle | ||||
) |
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.
startAngle | The start degrees. |
endAngle | The end degrees. |
Note
The area containing the Circle is not invalidated. Angles are given in degrees, so a full circle is 360.
setArc
void setArc | ( | const T | startAngle , | ||
const T | endAngle | ||||
) |
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.
T | Generic type parameter, either int or float. |
startAngle | The start degrees. |
endAngle | The end degrees. |
Note
The area containing the Circle is not invalidated. Angles are given in degrees, so a full circle is 360.
setCapPrecision
void setCapPrecision | ( | const int | precision | ) | |
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.
precision | The 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_t | x , | ||
const int16_t | y | ||||
) |
setCenter
void setCenter | ( | const T | x , | ||
const T | y | ||||
) |
setCircle
void setCircle | ( | const int16_t | x , | ||
const int16_t | y , | ||||
const int16_t | r | ||||
) |
setCircle
void setCircle | ( | const T | x , | ||
const T | y , | ||||
const T | r | ||||
) |
setLineWidth
void setLineWidth | ( | const T | width | ) | |
Sets the line width for this Circle.
If the line width is set to zero, the circle will be filled.
T | Generic type parameter, either int or float. |
width | The 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 | ( | int | x , | ||
int | y | ||||
) |
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.
x | The x coordinate of the center of the circle. |
y | The y coordinate of the center of the circle. |
setPrecision
void setPrecision | ( | const int | precision | ) | |
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.
precision | The precision measured in degrees. |
Note
The circle is not invalidated.
setRadius
void setRadius | ( | const T | r | ) | |
updateArc
void updateArc | ( | const T | startAngle , | ||
const T | endAngle | ||||
) |
Updates the start and end angle in degrees for this Circle arc.
T | Generic type parameter, either int or float. |
startAngle | The new start angle in degrees. |
endAngle | The 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. Angles are given in degrees, so a full circle is 360.
updateArcEnd
void updateArcEnd | ( | const T | endAngle | ) | |
updateArcStart
void updateArcStart | ( | const T | startAngle | ) | |
Protected Functions Documentation
updateArc
void updateArc | ( | const CWRUtil::Q5 | setStartAngleQ5 , | ||
const CWRUtil::Q5 | setEndAngleQ5 | ||||
) |
Updates the start and end angle in degrees for this Circle arc.
setStartAngleQ5 | The new start angle in degrees. |
setEndAngleQ5 | The 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.