Graphics
Circle provides several options for implementing graphical user interfaces (GUI) and for generating pixel and vector graphics on an attached HDMI or composite TV display. 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 frame buffer, which is provided by the class CBcmFrameBuffer.
#include <circle/2dgraphics.h>
-
class C2DGraphics
This class is a software graphics library with VSync and hardware-accelerated double buffering.
-
C2DGraphics::C2DGraphics(unsigned nWidth, unsigned nHeight, boolean bVSync = TRUE, unsigned nDisplay = 0)
Creates on instance of this class.
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.
-
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(TScreenColor Color)
Clears the screen.
Coloris the color used to clear the screen (seeCScreenDevice::SetPixel()).
-
void C2DGraphics::DrawRect(unsigned nX, unsigned nY, unsigned nWidth, unsigned nHeight, TScreenColor 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, TScreenColor 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, TScreenColor 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, TScreenColor 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, TScreenColor 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, TScreenColor *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, TScreenColor *PixelBuffer, TScreenColor 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, TScreenColor *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, TScreenColor *PixelBuffer, TScreenColor 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, TScreenColor 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.
-
TScreenColor *C2DGraphics::GetBuffer(void)
Gets raw access to the drawing buffer. Returns a pointer to the buffer.
-
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).
LVGL
The Light and Versatile Graphics Library (LVGL) v7.11.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, CInterruptSystem *pInterrupt)
-
CLVGL::CLVGL(CBcmFrameBuffer *pFrameBuffer, CInterruptSystem *pInterrupt)
Create an instance of this class.
pScreenorpFrameBufferreference the display to be used.pInterruptis a pointer to the system interrupt object.
-
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.
#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.