VSTGUI 4.10
Graphical User Interface Framework not only for VST plugins
COffscreenContext Class Reference

A draw context using a bitmap as it's back buffer. More...

#include <coffscreencontext.h>

+ Inheritance diagram for COffscreenContext:

Static Public Member Functions

static SharedPointer< COffscreenContextcreate (const CPoint &size, double scaleFactor=1.)
 
static SharedPointer< COffscreenContextcreate (CFrame *frame, CCoord width, CCoord height, double scaleFactor=1.)
 

COffscreenContext Methods

SharedPointer< CBitmapbitmap
 
void copyFrom (CDrawContext *pContext, CRect destRect, CPoint srcOffset=CPoint(0, 0))
 copy from offscreen to pContext More...
 
CCoord getWidth () const
 
CCoord getHeight () const
 
CBitmapgetBitmap () const
 
 COffscreenContext (const PlatformGraphicsDeviceContextPtr device, const CRect &surfaceRect, const PlatformBitmapPtr &platformBitmap)
 
 COffscreenContext (CBitmap *bitmap)
 
 COffscreenContext (const CRect &surfaceRect)
 

Additional Inherited Members

- Public Types inherited from CDrawContext
enum  PathDrawMode { kPathFilled , kPathFilledEvenOdd , kPathStroked }
 
using LinePair = VSTGUI::LinePair
 
using LineList = VSTGUI::LineList
 
using PointList = VSTGUI::PointList
 
- Public Member Functions inherited from CDrawContext
void setLineStyle (const CLineStyle &style)
 set the current line style More...
 
const CLineStylegetLineStyle () const
 get the current line style More...
 
void setLineWidth (CCoord width)
 set the current line width More...
 
CCoord getLineWidth () const
 get the current line width More...
 
void setDrawMode (CDrawMode mode)
 set the current draw mode, see CDrawMode More...
 
CDrawMode getDrawMode () const
 get the current draw mode, see CDrawMode More...
 
void setClipRect (const CRect &clip)
 set the current clip More...
 
CRectgetClipRect (CRect &clip) const
 get the current clip More...
 
void resetClipRect ()
 reset the clip to the default state More...
 
void setFillColor (const CColor &color)
 set current fill color More...
 
CColor getFillColor () const
 get current fill color More...
 
void setFrameColor (const CColor &color)
 set current stroke color More...
 
CColor getFrameColor () const
 get current stroke color More...
 
void setFontColor (const CColor &color)
 set current font color More...
 
CColor getFontColor () const
 get current font color More...
 
void setFont (const CFontRef font, const CCoord &size=0, const int32_t &style=-1)
 set current font More...
 
const CFontRef getFont () const
 get current font More...
 
CCoord getStringWidth (UTF8StringPtr pStr)
 get the width of an UTF-8 encoded string More...
 
void drawString (UTF8StringPtr string, const CRect &_rect, const CHoriTxtAlign hAlign=kCenterText, bool antialias=true)
 draw an UTF-8 encoded string More...
 
void drawString (UTF8StringPtr string, const CPoint &_point, bool antialias=true)
 draw an UTF-8 encoded string More...
 
CCoord getStringWidth (IPlatformString *pStr)
 get the width of a platform string More...
 
void drawString (IPlatformString *string, const CRect &_rect, const CHoriTxtAlign hAlign=kCenterText, bool antialias=true)
 draw a platform string More...
 
void drawString (IPlatformString *string, const CPoint &_point, bool antialias=true)
 draw a platform string More...
 
void setGlobalAlpha (float newAlpha)
 sets the global alpha value[0..1] More...
 
float getGlobalAlpha () const
 get current global alpha value More...
 
void saveGlobalState ()
 
void restoreGlobalState ()
 
const CGraphicsTransformgetCurrentTransform () const
 
const CRectgetAbsoluteClipRect () const
 
double getScaleFactor () const
 returns the backend scale factor. More...
 
CCoord getHairlineSize () const
 returns the current line size which corresponds to one pixel on screen. More...
 
CGraphicsPathcreateGraphicsPath ()
 create a graphics path object, you need to forget it after usage More...
 
CGraphicsPathcreateTextPath (const CFontRef font, UTF8StringPtr text)
 create a graphics path from a text More...
 
CGraphicsPathcreateRoundRectGraphicsPath (const CRect &size, CCoord radius)
 create a rect with round corners as graphics path, you need to forget it after usage More...
 
void drawGraphicsPath (CGraphicsPath *path, PathDrawMode mode=kPathFilled, CGraphicsTransform *transformation=nullptr)
 
void fillLinearGradient (CGraphicsPath *path, const CGradient &gradient, const CPoint &startPoint, const CPoint &endPoint, bool evenOdd=false, CGraphicsTransform *transformation=nullptr)
 
void fillRadialGradient (CGraphicsPath *path, const CGradient &gradient, const CPoint &center, CCoord radius, const CPoint &originOffset=CPoint(0, 0), bool evenOdd=false, CGraphicsTransform *transformation=nullptr)
 
void beginDraw ()
 
void endDraw ()
 
const CRectgetSurfaceRect () const
 
 CDrawContext (const PlatformGraphicsDeviceContextPtr device, const CRect &surfaceRect, double scaleFactor)
 
 ~CDrawContext () noexcept override
 
const PlatformGraphicsDeviceContextPtrgetPlatformDeviceContext () const
 
void drawLine (const CPoint &start, const CPoint &end)
 
void drawLine (const LinePair &line)
 draw a line More...
 
void drawLines (const LineList &lines)
 draw multiple lines at once More...
 
void drawPolygon (const PointList &polygonPointList, const CDrawStyle drawStyle=kDrawStroked)
 draw a polygon More...
 
void drawRect (const CRect &rect, const CDrawStyle drawStyle=kDrawStroked)
 draw a rect More...
 
void drawArc (const CRect &rect, const float startAngle1, const float endAngle2, const CDrawStyle drawStyle=kDrawStroked)
 draw an arc, angles are in degree More...
 
void drawEllipse (const CRect &rect, const CDrawStyle drawStyle=kDrawStroked)
 draw an ellipse More...
 
void drawPoint (const CPoint &point, const CColor &color)
 draw a point More...
 
void drawBitmap (CBitmap *bitmap, const CRect &dest, const CPoint &offset=CPoint(0, 0), float alpha=1.f)
 don't call directly, please use CBitmap::draw instead More...
 
void drawBitmapNinePartTiled (CBitmap *bitmap, const CRect &dest, const CNinePartTiledDescription &desc, float alpha=1.f)
 
void fillRectWithBitmap (CBitmap *bitmap, const CRect &srcRect, const CRect &dstRect, float alpha)
 
void clearRect (const CRect &rect)
 clears the rect (makes r = 0, g = 0, b = 0, a = 0) More...
 
void setBitmapInterpolationQuality (BitmapInterpolationQuality quality)
 set the current bitmap interpolation quality More...
 
BitmapInterpolationQuality getBitmapInterpolationQuality () const
 get the current bitmap interpolation quality More...
 
- Public Member Functions inherited from ReferenceCounted< T >
 ReferenceCounted ()=default
 
virtual ~ReferenceCounted () noexcept=default
 
 ReferenceCounted (const ReferenceCounted &)
 
ReferenceCountedoperator= (const ReferenceCounted &)
 
void forget () override
 decrease refcount and delete object if refcount == 0 More...
 
void remember () override
 increase refcount More...
 
virtual int32_t getNbReference () const
 get refcount More...
 
virtual void forget ()=0
 decrease refcount and delete object if refcount == 0 More...
 
virtual void remember ()=0
 increase refcount More...
 
- Protected Member Functions inherited from CDrawContext
 CDrawContext ()=delete
 
 CDrawContext (const CRect &surfaceRect)
 
void init ()
 
void pushTransform (const CGraphicsTransform &transformation)
 
void popTransform ()
 
const UTF8StringgetDrawString (UTF8StringPtr string)
 
void clearDrawString ()
 

Detailed Description

A draw context using a bitmap as it's back buffer.

There are two usage scenarios :

Drawing into a bitmap and then push the contents into another draw context

if (auto offscreen = COffscreenContext::create (frame, 100, 100))
{
offscreen->beginDraw ();
// ...
// draw into offscreen
// ...
offscreen->endDraw ();
offscreen->copyFrom (otherContext, destRect);
}
static SharedPointer< COffscreenContext > create(const CPoint &size, double scaleFactor=1.)
Definition: coffscreencontext.cpp:51

Drawing static content into a bitmap and reuse the bitmap for drawing

if (cachedBitmap == 0)
{
if (auto offscreen = COffscreenContext::create (frame, 100, 100))
{
offscreen->beginDraw ();
// ...
// draw into offscreen
// ...
offscreen->endDraw ();
cachedBitmap = offscreen->getBitmap ();
if (cachedBitmap)
cachedBitmap->remember ();
}
}
if (cachedBitmap)
{
// ...
}

Constructor & Destructor Documentation

◆ COffscreenContext() [1/3]

COffscreenContext ( const PlatformGraphicsDeviceContextPtr  device,
const CRect surfaceRect,
const PlatformBitmapPtr platformBitmap 
)

◆ COffscreenContext() [2/3]

COffscreenContext ( CBitmap bitmap)
explicitprotected

◆ COffscreenContext() [3/3]

COffscreenContext ( const CRect surfaceRect)
explicitprotected

Member Function Documentation

◆ copyFrom()

void copyFrom ( CDrawContext pContext,
CRect  destRect,
CPoint  srcOffset = CPoint (0, 0) 
)

copy from offscreen to pContext

◆ create() [1/2]

SharedPointer< COffscreenContext > create ( CFrame frame,
CCoord  width,
CCoord  height,
double  scaleFactor = 1. 
)
static

◆ create() [2/2]

SharedPointer< COffscreenContext > create ( const CPoint size,
double  scaleFactor = 1. 
)
static

◆ getBitmap()

CBitmap * getBitmap ( ) const
inline

◆ getHeight()

CCoord getHeight ( ) const

◆ getWidth()

CCoord getWidth ( ) const

Member Data Documentation

◆ bitmap

SharedPointer<CBitmap> bitmap
protected

The documentation for this class was generated from the following files: