Graphics
Circle provides several options for implementing graphical user interfaces (GUI) and for generating pixel and vector graphics on an attached HDMI, composite TV display or external displays with SPI/I2C interface. These options are described in this section.
C2DGraphics
The class C2DGraphics is part of the Circle base library and can be used to generate pixel graphics on a dot-matrix display, which is provided by the class CDisplay.
#include <circle/2dgraphics.h>
-
class C2DGraphics
This class is a software graphics library with VSync and hardware-accelerated double buffering.
Note
The double buffering does not work on the Raspberry Pi 5 and on displays with SPI/I2C interface.
-
type T2DColor
Same as
CDisplay::TColor.
-
COLOR2D(red, green, blue)
Same as
DISPLAY_COLOR.
-
C2DGraphics::C2DGraphics(CDisplay *pDisplay)
Creates on instance of this class.
pDisplayis a pointer to the display driver.
Note
There is no VSync support with this constructor.
-
C2DGraphics::C2DGraphics(unsigned nWidth, unsigned nHeight, boolean bVSync = TRUE, unsigned nDisplay = 0)
Creates on instance of this class and uses the class
CBcmFrameBufferas display driver.nWidthis the screen width in pixels (0 to detect).nHeightis the screen height in pixels (0 to detect). SetbVSynctoTRUEto enable VSync and HW double buffering.nDisplayis the zero-based display number (for Raspberry Pi 4).
-
boolean C2DGraphics::Initialize(void)
Initializes the screen. Returns
TRUEon success.
-
boolean C2DGraphics::Resize(unsigned nWidth, unsigned nHeight)
Initializes the screen again with a new size.
nWidthis the new screen width andnHeightthe new screen height in number of pixels. ReturnsTRUEon success. WhenFALSEis returned, the width and/or height are not supported. The object is in an uninitialized state then and must not be used, butResize()can be called again with other parameters.
-
unsigned C2DGraphics::GetWidth(void) const
Returns the screen width in pixels.
-
unsigned C2DGraphics::GetHeight(void) const
Returns the screen height in pixels.
-
void C2DGraphics::ClearScreen(T2DColor Color)
Clears the screen.
Coloris the color used to clear the screen.
-
void C2DGraphics::DrawRect(unsigned nX, unsigned nY, unsigned nWidth, unsigned nHeight, T2DColor Color)
Draws a filled rectangle.
nXis the start X coordinate.nYis the start Y coordinate.nWidthis the rectangle width.nHeightis the rectangle height.Coloris the rectangle color.
-
void C2DGraphics::DrawRectOutline(unsigned nX, unsigned nY, unsigned nWidth, unsigned nHeight, T2DColor Color)
Draws an unfilled rectangle (inner outline).
nXis the start X coordinate.nYis the start Y coordinate.nWidthis the rectangle width.nHeightis the rectangle height.Coloris the rectangle color.
-
void C2DGraphics::DrawLine(unsigned nX1, unsigned nY1, unsigned nX2, unsigned nY2, T2DColor Color)
Draws a line.
nX1is the start position X coordinate.nY1is the start position Y coordinate.nX2is the end position X coordinate.nY2is the end position Y coordinate.Coloris the line color.
-
void C2DGraphics::DrawCircle(unsigned nX, unsigned nY, unsigned nRadius, T2DColor Color)
Draws a filled circle.
nXis the circle X coordinate.nYis the circle Y coordinate.nRadiusis the circle radius.Coloris the circle color.
-
void C2DGraphics::DrawCircleOutline(unsigned nX, unsigned nY, unsigned nRadius, T2DColor Color)
Draws an unfilled circle (inner outline).
nXis the circle X coordinate.nYis the circle Y coordinate.nRadiusis the circle radius.Coloris the circle color.
-
void C2DGraphics::DrawImage(unsigned nX, unsigned nY, unsigned nWidth, unsigned nHeight, const void *PixelBuffer)
Draws an image from a pixel buffer.
nXis the image X coordinate.nYis the image Y coordinate.nWidthis the image width.nHeightis the image height.PixelBufferis a pointer to the pixels.
-
void C2DGraphics::DrawImageTransparent(unsigned nX, unsigned nY, unsigned nWidth, unsigned nHeight, const void *PixelBuffer, T2DColor TransparentColor)
Draws an image from a pixel buffer with transparent color.
nXis the image X coordinate.nYis the image Y coordinate.nWidthis the image width.nHeightis the image height.PixelBufferis a pointer to the pixels.TransparentColoris the color to use for transparency.
-
void C2DGraphics::DrawImageRect(unsigned nX, unsigned nY, unsigned nWidth, unsigned nHeight, unsigned nSourceX, unsigned nSourceY, const void *PixelBuffer)
Draws an area of an image from a pixel buffer.
nXis the image X coordinate.nYis the image Y coordinate.nWidthis the image width.nHeightis the image height.nSourceXis the source X coordinate in the pixel buffer.nSourceYis the source Y coordinate in the pixel buffer.PixelBufferis a pointer to the pixels.
-
void C2DGraphics::DrawImageRectTransparent(unsigned nX, unsigned nY, unsigned nWidth, unsigned nHeight, unsigned nSourceX, unsigned nSourceY, unsigned nSourceWidth, unsigned nSourceHeight, const void *PixelBuffer, T2DColor TransparentColor)
Draws an area of an image from a pixel buffer with transparent color.
nXis the image X coordinate.nYis the image Y coordinate.nWidthis the image width.nHeightis the image height.nSourceXis the source X coordinate in the pixel buffer.nSourceYis the source Y coordinate in the pixel buffer.nSourceWidthis the source image width.nSourceHeightis the source image height.PixelBufferis a pointer to the pixels.TransparentColoris the color to use for transparency.
-
void C2DGraphics::DrawPixel(unsigned nX, unsigned nY, T2DColor Color)
Draws a single pixel.
nXis the pixel X coordinate.nYis the pixel Y coordinate.Coloris the pixel color.
Note
If you need to draw a lot of pixels, consider using C2DGraphics::GetBuffer() for better speed.
-
void C2DGraphics::DrawText(unsigned nX, unsigned nY, T2DColor Color, const char *pText, TTextAlign Align = AlignLeft, const TFont &rFont = DEFAULT_FONT, CCharGenerator::TFontFlags FontFlags = CCharGenerator::FontFlagsNone)
Draws a horizontal ISO8859-1 text string, using the font
rFontwith the flagsFontFlags.nXis the text X coordinate.nYis the text Y coordinate.Coloris the text color. The background is transparent.pTextis a zero-terminated C-string.Alignspecifies the horizontal text alignment, with these possible values:
-
enum C2DGraphics::TTextAlign
AlignLeft
AlignRight
AlignCenter
-
void *C2DGraphics::GetBuffer(void)
Gets raw access to the drawing buffer. Returns a pointer to the buffer, which contains the pixels in the physical color format (depends on the display).
-
CDisplay *C2DGraphics::GetDisplay(void)
Returns a pointer to the display, we are working on.
-
void C2DGraphics::UpdateDisplay(void)
Once everything has been drawn, updates the display to show the contents on screen. If VSync is enabled, this method is blocking until the screen refresh signal is received (every 16ms for 60 FPS refresh rate).
-
class C2DImage
This is a sprite image to be displayed on a
C2DGraphicsinstance.
-
C2DImage::C2DImage(C2DGraphics *p2DGraphics)
Creates an instance of
C2DImage.p2DGraphicsis theC2DGraphicsinstance to be used.
LVGL
The Light and Versatile Graphics Library (LVGL) v9.4.0 can be used with Circle. This library provides an API, which is based on the C language. See the LVGL documentation for details.
#include <lvgl/lvgl.h>
-
class CLVGL
This class is a wrapper for LVGL and has to be instantiated to use this graphics library. The wrapper class supports USB mouse or touchscreen input.
-
CLVGL::CLVGL(CScreenDevice *pScreen)
-
CLVGL::CLVGL(CDisplay *pDisplay)
Create an instance of this class.
pScreenorpDisplayreference the display to be used.
-
void CLVGL::Update(boolean bPlugAndPlayUpdated = FALSE)
Updates the display. This has to be called continuously from the application main loop at
TASK_LEVEL.bPlugAndPlayUpdatedmust be set toTRUE, if the application supports USB plug-and-play andCUSBHostController::UpdatePlugAndPlay()returnedTRUEtoo.
µGUI
The µGUI library can be used with Circle. This library provides an API, which is based on the C language. Download the Reference Guide for details.
Note
This library is currently not supported on the Raspberry Pi 5.
#include <ugui/uguicpp.h>
-
class CUGUI
This class is a wrapper for µGUI and has to be instantiated to use this graphics library. The wrapper class supports USB mouse or touchscreen input.
-
CUGUI::CUGUI(CScreenDevice *pScreen)
Creates an instance of this class.
pScreenreferences the display to be used.
-
void CUGUI::Update(boolean bPlugAndPlayUpdated = FALSE)
Updates the display. This has to be called continuously from the application main loop at
TASK_LEVEL.bPlugAndPlayUpdatedmust be set toTRUE, if the application supports USB plug-and-play andCUSBHostController::UpdatePlugAndPlay()returnedTRUEtoo.
Accelerated graphics
The accelerated graphics support is described in the VC4 subsystem section.