CartoType C++ API 7.8.2, 2022-03-25
for Windows, Linux, Qt and other platforms supporting C++ development
|
#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 |
The base graphics context class. A graphics context draws to a raster drawing surface with square pixels.
CartoType::CGraphicsContext::CGraphicsContext | ( | std::shared_ptr< CEngine > | aEngine, |
const TRect & | aBounds, | ||
std::unique_ptr< CBitmap > | aBitmap | ||
) |
Constructs a graphics context to draw into aBounds.
|
inline |
Returns the current alpha (opacity) level as a number in the range 0 ... 255.
|
inlinestatic |
Blends aForeground and aBackground in the proportion aAlpha. All three numbers are intensities in the range 0...255.
|
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.
|
inline |
Return the rectangle that the graphics context draws to if no clipping is done.
|
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.
|
inline |
Returns the clipping rectangle.
|
inline |
Returns the current color as an RGBA value including the alpha channel.
|
inline |
Returns the current dash array.
|
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.
|
virtual |
Draws a colored bitmap in monochrome using the current color to colorise it. The default implementation draws the bitmap normally.
|
protected |
Draws a dashed stroke using the current dash array, optionally transforming it by aTransform.
|
virtual |
Draws a filled rectangle in the current color. The coordinates are whole pixels.
|
pure virtual |
Draws a filled shape in the current color. The coordinates are in 64ths of pixels.
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.
|
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.
|
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.
|
virtual |
Enables or disables any transformation applied by the graphics context. Returns the previous state. The base implementation does nothing and returns false.
|
inline |
Returns a pointer to the graphics engine.
|
virtual |
Gets the current glow parameters.
|
virtual |
Applies the inverse of the graphics context's current transformation to a point. See CGraphicsContext::Transform function for details.
|
inlinestatic |
Multiplies two intensities, treated as fractions in the range 0...255.
|
inline |
Returns the current paint.
|
inline |
Returns the current graphics parameters.
|
inline |
Returns the pen used for drawing strokes.
void CartoType::CGraphicsContext::SetAlpha | ( | int32_t | aAlpha | ) |
Sets the alpha (transparency) level, where 0 = transparent and 255 = opaque.
void CartoType::CGraphicsContext::SetClip | ( | const TRect & | aClip | ) |
Sets the clip rectangle.
void CartoType::CGraphicsContext::SetColor | ( | TColor | aColor | ) |
Sets the color used for painting and sets the paint server to null.
|
inline |
Sets the array of dash and gap sizes used for dashed strokes.
|
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.
void CartoType::CGraphicsContext::SetPaint | ( | const TPaint & | aPaint | ) |
Sets the color and the paint server.
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.
void CartoType::CGraphicsContext::SetParam | ( | TGraphicsParam & | aParam | ) |
Sets the graphics parameters to the values in aParam.
void CartoType::CGraphicsContext::SetPen | ( | const TCircularPen & | aPen | ) |
Sets the pen used for drawing strokes.
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.
|
inline |
Swaps the bitmap with another one.
TDrawResult CartoType::CGraphicsContext::Transform | ( | TPoint & | aPoint, |
int32_t | aFractionalBits | ||
) |
If this GC transforms points, applies the its current transformation to an integer point.
|
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.
|
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.
|
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.
|
virtual |
Returns the bounds of the display plane before any transformaton applied by it by the GC. The base implementation returns the ordinary bounds.
|
protected |
If non-null, the bitmap owned by the graphics context.
|
protected |
The bounds, in pixels, of the device drawn into.
|
protected |
Flags that are set when graphics parameters are changed, allowing derived classes to synchronize their internal states if necessary.
|
protected |
The engine object, which provides the shape rendering engines and other shared resources.
|
protected |
The drawing parameters such as the color and clip rectangle.
|
staticconstexprprotected |
A flag used in iChangeFlags: all graphics parameters have changed; the internal state must be completely initialised.
|
staticconstexprprotected |
A flag used in iChangeFlags: the clip rectangle has changed.
|
staticconstexprprotected |
A flag used in iChangeFlags: the glow color, if any, has changed.
|
staticconstexprprotected |
A flag used in iChangeFlags: the paint has changed.
|
staticconstexprprotected |
A flag used in iChangeFlags: the texture mask has changed.