CartoType C++ API 7.8.2, 2022-03-25
for Windows, Linux, Qt and other platforms supporting C++ development
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
CartoType::CGraphicsContext Class Referenceabstract

#include <cartotype_graphics_context.h>

Public Member Functions

 CGraphicsContext (std::shared_ptr< CEngine > aEngine, const TRect &aBounds, std::unique_ptr< CBitmap > aBitmap)
 
virtual TDrawResult DrawBitmap (const TBitmap &aBitmap, const TPoint &aTopLeft)=0
 
virtual TDrawResult DrawShape (const MPath &aPath)=0
 
virtual TDrawResult DrawTexture (const CTexture &aTexture, const TPointFP &aTopLeft, const TTransform &aTransform)=0
 
virtual void Clear ()=0
 
virtual TBitmap * Bitmap ()
 
virtual TDrawResult DrawRect (const TRect &aRect)
 
virtual bool TransformsPoints ()
 
virtual TDrawResult Transform2D (TPointFP &aPoint, int32_t aFractionalBits)
 
virtual TDrawResult Transform3D (TPoint3FP &aPoint)
 
virtual void InverseTransform2D (TPointFP &aPoint, int32_t aFractionalBits)
 
virtual bool EnableTransform (bool aEnable)
 
virtual TRect UntransformedBounds ()
 
virtual TDrawResult DrawStroke (const MPath &aPath, const TTransform *aTransform=nullptr, bool aClip=false)
 
virtual void SetGlow (TColor aColor, double aWidth, const TPointFP &aOffset)
 
virtual void GetGlow (TColor &aColor, double &aWidth, TPointFP &aOffset)
 
virtual TDrawResult DrawBitmapMonochrome (const TBitmap &aBitmap, const TPoint &aTopLeft)
 
TDrawResult DrawShapeAndStroke (const MPath &aPath, const TPaint &aStrokePaint, const TTransform *aTransform=nullptr)
 
void SetClip (const TRect &aClip)
 
void SetColor (TColor aColor)
 
void SetPaintServer (std::shared_ptr< CPaintServer > aPaintServer)
 
void SetPaint (const TPaint &aPaint)
 
void SetAlpha (int32_t aAlpha)
 
void SetTextureMask (TColor aColor)
 
void SetParam (TGraphicsParam &aParam)
 
void SetPen (const TCircularPen &aPen)
 
TDrawResult Transform (TPoint &aPoint, int32_t aFractionalBits)
 
void SwapBitmap (std::unique_ptr< CBitmap > &aBitmap)
 
std::shared_ptr< CEngine > Engine ()
 
const TRect & Clip () const
 
const TPaint & Paint () const
 
TColor Color () const
 
int32_t Alpha () const
 
const TRect & Bounds () const
 
const TCircularPen & Pen () const
 
void SetDashArray (std::shared_ptr< CDashArray > aDashArray)
 
std::shared_ptr< CDashArray > DashArray () const
 
const TGraphicsParam & Param () const
 

Static Public Member Functions

static uint8_t MultiplyIntensities (int aIntensity1, int aIntensity2)
 
static uint8_t AlphaBlend (int aForeground, int aBackground, int aAlpha)
 

Protected Member Functions

TDrawResult DrawDashedStroke (const MPath &aPath, const TTransform *aTransform)
 

Protected Attributes

std::shared_ptr< CEngine > iEngine
 
TGraphicsParam iParam
 
TRect iBounds
 
int32_t iChangeFlags = KAllChanged
 
std::unique_ptr< CBitmap > iBitmap
 

Static Protected Attributes

static constexpr int32_t KClipChanged = 1
 
static constexpr int32_t KPaintChanged = 2
 
static constexpr int32_t KGlowColorChanged = 4
 
static constexpr int32_t KTextureMaskChanged = 8
 
static constexpr int32_t KAllChanged = -1
 

Detailed Description

The base graphics context class. A graphics context draws to a raster drawing surface with square pixels.

Constructor & Destructor Documentation

◆ CGraphicsContext()

CartoType::CGraphicsContext::CGraphicsContext ( std::shared_ptr< CEngine >  aEngine,
const TRect &  aBounds,
std::unique_ptr< CBitmap >  aBitmap 
)

Constructs a graphics context to draw into aBounds.

Member Function Documentation

◆ Alpha()

int32_t CartoType::CGraphicsContext::Alpha ( ) const
inline

Returns the current alpha (opacity) level as a number in the range 0 ... 255.

◆ AlphaBlend()

static uint8_t CartoType::CGraphicsContext::AlphaBlend ( int  aForeground,
int  aBackground,
int  aAlpha 
)
inlinestatic

Blends aForeground and aBackground in the proportion aAlpha. All three numbers are intensities in the range 0...255.

◆ Bitmap()

TBitmap * CartoType::CGraphicsContext::Bitmap ( )
virtual

Returns a pointer to the bitmap, if any.

Returns the bitmap drawn to by the graphics context, if any. If the graphics context does not draw to a bitmap, this function returns nullptr.

◆ Bounds()

const TRect & CartoType::CGraphicsContext::Bounds ( ) const
inline

Return the rectangle that the graphics context draws to if no clipping is done.

◆ Clear()

virtual void CartoType::CGraphicsContext::Clear ( )
pure virtual

Clears the drawing area to transparent black. If colors are not stored sets all pixels to zero intensity. If transparency levels are not stored sets all pixels to black.

◆ Clip()

const TRect & CartoType::CGraphicsContext::Clip ( ) const
inline

Returns the clipping rectangle.

◆ Color()

TColor CartoType::CGraphicsContext::Color ( ) const
inline

Returns the current color as an RGBA value including the alpha channel.

◆ DashArray()

std::shared_ptr< CDashArray > CartoType::CGraphicsContext::DashArray ( ) const
inline

Returns the current dash array.

◆ DrawBitmap()

virtual TDrawResult CartoType::CGraphicsContext::DrawBitmap ( const TBitmap &  aBitmap,
const TPoint &  aTopLeft 
)
pure virtual

Draws a bitmap. If the bitmap has no color information, uses the current color. Combines any alpha information from the bitmap with the current alpha level. The coordinates are whole pixels.

◆ DrawBitmapMonochrome()

TDrawResult CartoType::CGraphicsContext::DrawBitmapMonochrome ( const TBitmap &  aBitmap,
const TPoint &  aTopLeft 
)
virtual

Draws a colored bitmap in monochrome using the current color to colorise it. The default implementation draws the bitmap normally.

◆ DrawDashedStroke()

TDrawResult CartoType::CGraphicsContext::DrawDashedStroke ( const MPath &  aPath,
const TTransform *  aTransform 
)
protected

Draws a dashed stroke using the current dash array, optionally transforming it by aTransform.

◆ DrawRect()

TDrawResult CartoType::CGraphicsContext::DrawRect ( const TRect &  aRect)
virtual

Draws a filled rectangle in the current color. The coordinates are whole pixels.

◆ DrawShape()

virtual TDrawResult CartoType::CGraphicsContext::DrawShape ( const MPath &  aPath)
pure virtual

Draws a filled shape in the current color. The coordinates are in 64ths of pixels.

◆ DrawShapeAndStroke()

TDrawResult CartoType::CGraphicsContext::DrawShapeAndStroke ( const MPath &  aPath,
const TPaint &  aStrokePaint,
const TTransform *  aTransform = nullptr 
)

Fills and outlines a shape. The path coordinates are 64ths of pixels. The shape is filled if the current paint is non-null, and outlined if aStrokePaint is non-null. Optionally apply a transform to the shape and the stroke envelope. The offsets in aTransform are whole pixels.

◆ DrawStroke()

TDrawResult CartoType::CGraphicsContext::DrawStroke ( const MPath &  aPath,
const TTransform *  aTransform = nullptr,
bool  aClip = false 
)
virtual

Draws a stroke using the current circular pen.

The path coordinates are 64ths of pixels.

Optionally applies a transform to the stroke envelope before drawing it. The offsets in aTransform are whole pixels.

◆ DrawTexture()

TDrawResult CartoType::CGraphicsContext::DrawTexture ( const CTexture &  aTexture,
const TPointFP &  aTopLeft,
const TTransform &  aTransform 
)
pure virtual

Draws a texture at aTopLeft, transforming it by aTransform.

Draws a texture at aTopLeft, transforming it by aTransform. The base implementation throws KErrorUnimplemented.

◆ EnableTransform()

bool CartoType::CGraphicsContext::EnableTransform ( bool  aEnable)
virtual

Enables or disables any transformation applied by the graphics context. Returns the previous state. The base implementation does nothing and returns false.

◆ Engine()

std::shared_ptr< CEngine > CartoType::CGraphicsContext::Engine ( )
inline

Returns a pointer to the graphics engine.

◆ GetGlow()

void CartoType::CGraphicsContext::GetGlow ( TColor &  aColor,
double &  aWidth,
TPointFP &  aOffset 
)
virtual

Gets the current glow parameters.

◆ InverseTransform2D()

void CartoType::CGraphicsContext::InverseTransform2D ( TPointFP &  aPoint,
int32_t  aFractionalBits 
)
virtual

Applies the inverse of the graphics context's current transformation to a point. See CGraphicsContext::Transform function for details.

◆ MultiplyIntensities()

static uint8_t CartoType::CGraphicsContext::MultiplyIntensities ( int  aIntensity1,
int  aIntensity2 
)
inlinestatic

Multiplies two intensities, treated as fractions in the range 0...255.

◆ Paint()

const TPaint & CartoType::CGraphicsContext::Paint ( ) const
inline

Returns the current paint.

◆ Param()

const TGraphicsParam & CartoType::CGraphicsContext::Param ( ) const
inline

Returns the current graphics parameters.

◆ Pen()

const TCircularPen & CartoType::CGraphicsContext::Pen ( ) const
inline

Returns the pen used for drawing strokes.

◆ SetAlpha()

void CartoType::CGraphicsContext::SetAlpha ( int32_t  aAlpha)

Sets the alpha (transparency) level, where 0 = transparent and 255 = opaque.

◆ SetClip()

void CartoType::CGraphicsContext::SetClip ( const TRect &  aClip)

Sets the clip rectangle.

◆ SetColor()

void CartoType::CGraphicsContext::SetColor ( TColor  aColor)

Sets the color used for painting and sets the paint server to null.

◆ SetDashArray()

void CartoType::CGraphicsContext::SetDashArray ( std::shared_ptr< CDashArray >  aDashArray)
inline

Sets the array of dash and gap sizes used for dashed strokes.

◆ SetGlow()

void CartoType::CGraphicsContext::SetGlow ( TColor  aColor,
double  aWidth,
const TPointFP &  aOffset 
)
virtual

Sets the current glow parameters. Bitmaps are drawn with a glowing border if the glow color is not fully transparent and the glow width is greater than zero. The default implementation does nothing.

◆ SetPaint()

void CartoType::CGraphicsContext::SetPaint ( const TPaint &  aPaint)

Sets the color and the paint server.

◆ SetPaintServer()

void CartoType::CGraphicsContext::SetPaintServer ( std::shared_ptr< CPaintServer >  aPaintServer)

Sets the paint server. A value of null tells the graphics context not to use a paint server but to use the current color.

◆ SetParam()

void CartoType::CGraphicsContext::SetParam ( TGraphicsParam &  aParam)

Sets the graphics parameters to the values in aParam.

◆ SetPen()

void CartoType::CGraphicsContext::SetPen ( const TCircularPen &  aPen)

Sets the pen used for drawing strokes.

◆ SetTextureMask()

void CartoType::CGraphicsContext::SetTextureMask ( TColor  aColor)

Sets the texture mask color: the color that prevents texture pixels from being drawn in unwanted areas like the sea.

◆ SwapBitmap()

void CartoType::CGraphicsContext::SwapBitmap ( std::unique_ptr< CBitmap > &  aBitmap)
inline

Swaps the bitmap with another one.

◆ Transform()

TDrawResult CartoType::CGraphicsContext::Transform ( TPoint &  aPoint,
int32_t  aFractionalBits 
)

If this GC transforms points, applies the its current transformation to an integer point.

◆ Transform2D()

TDrawResult CartoType::CGraphicsContext::Transform2D ( TPointFP &  aPoint,
int32_t  aFractionalBits 
)
virtual

Applies the graphics context's current transformation to a point. Returns false if the transformation fails because of range or other issues.

Graphics contexts that provide a non-identity overriding implementation of this function must also override TransformsPoints to return true. The base implementation is identity and thus does nothing. Although the transform does not change the point's representation, the number of fractional bits must be supplied so that the transform can use actual pixels consistently, as in a perpective transform.

◆ Transform3D()

TDrawResult CartoType::CGraphicsContext::Transform3D ( TPoint3FP &  aPoint)
virtual

Applies the graphics context's current transformation to a 3D point.

Graphics contexts, like the perspective GC, that provide a non-identity overriding implementation of this function, must also override TransformsPoints to return true. The base implementation is identity and thus does nothing. The units of aPoint are whole pixels.

◆ TransformsPoints()

bool CartoType::CGraphicsContext::TransformsPoints ( )
virtual

Returns true if the GC applies a further transformation to points before drawing them, as for example the perspective transformation. The base implementation returns false.

◆ UntransformedBounds()

TRect CartoType::CGraphicsContext::UntransformedBounds ( )
virtual

Returns the bounds of the display plane before any transformaton applied by it by the GC. The base implementation returns the ordinary bounds.

Member Data Documentation

◆ iBitmap

std::unique_ptr<CBitmap> CartoType::CGraphicsContext::iBitmap
protected

If non-null, the bitmap owned by the graphics context.

◆ iBounds

TRect CartoType::CGraphicsContext::iBounds
protected

The bounds, in pixels, of the device drawn into.

◆ iChangeFlags

int32_t CartoType::CGraphicsContext::iChangeFlags = KAllChanged
protected

Flags that are set when graphics parameters are changed, allowing derived classes to synchronize their internal states if necessary.

◆ iEngine

std::shared_ptr<CEngine> CartoType::CGraphicsContext::iEngine
protected

The engine object, which provides the shape rendering engines and other shared resources.

◆ iParam

TGraphicsParam CartoType::CGraphicsContext::iParam
protected

The drawing parameters such as the color and clip rectangle.

◆ KAllChanged

constexpr int32_t CartoType::CGraphicsContext::KAllChanged = -1
staticconstexprprotected

A flag used in iChangeFlags: all graphics parameters have changed; the internal state must be completely initialised.

◆ KClipChanged

constexpr int32_t CartoType::CGraphicsContext::KClipChanged = 1
staticconstexprprotected

A flag used in iChangeFlags: the clip rectangle has changed.

◆ KGlowColorChanged

constexpr int32_t CartoType::CGraphicsContext::KGlowColorChanged = 4
staticconstexprprotected

A flag used in iChangeFlags: the glow color, if any, has changed.

◆ KPaintChanged

constexpr int32_t CartoType::CGraphicsContext::KPaintChanged = 2
staticconstexprprotected

A flag used in iChangeFlags: the paint has changed.

◆ KTextureMaskChanged

constexpr int32_t CartoType::CGraphicsContext::KTextureMaskChanged = 8
staticconstexprprotected

A flag used in iChangeFlags: the texture mask has changed.


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