DISTRHO Plugin Framework
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
NanoVG Class Reference

#include <NanoVG.hpp>

Inheritance diagram for NanoVG:
NanoBaseWidget< BaseWidget >

Classes

struct  GlyphPosition
 
struct  Paint
 
struct  TextRow
 

Public Types

enum  CreateFlags { CREATE_ANTIALIAS = 1 << 0 , CREATE_STENCIL_STROKES = 1 << 1 , CREATE_DEBUG = 1 << 2 }
 
enum  ImageFlags {
  IMAGE_GENERATE_MIPMAPS = 1 << 0 , IMAGE_REPEAT_X = 1 << 1 , IMAGE_REPEAT_Y = 1 << 2 , IMAGE_FLIP_Y = 1 << 3 ,
  IMAGE_PREMULTIPLIED = 1 << 4
}
 
enum  Align {
  ALIGN_LEFT = 1 << 0 , ALIGN_CENTER = 1 << 1 , ALIGN_RIGHT = 1 << 2 , ALIGN_TOP = 1 << 3 ,
  ALIGN_MIDDLE = 1 << 4 , ALIGN_BOTTOM = 1 << 5 , ALIGN_BASELINE = 1 << 6
}
 
enum  LineCap {
  BUTT , ROUND , SQUARE , BEVEL ,
  MITER
}
 
enum  Solidity { SOLID = 1 , HOLE = 2 }
 
enum  Winding { CCW = 1 , CW = 2 }
 
typedef int FontId
 

Public Member Functions

 NanoVG (int flags=CREATE_ANTIALIAS)
 
 NanoVG (NVGcontext *context)
 
virtual ~NanoVG ()
 
NVGcontext * getContext () const noexcept
 
void beginFrame (const uint width, const uint height, const float scaleFactor=1.0f)
 
void beginFrame (Widget *const widget)
 
void cancelFrame ()
 
void endFrame ()
 
void save ()
 
void restore ()
 
void reset ()
 
void strokeColor (const Color &color)
 
void strokeColor (const int red, const int green, const int blue, const int alpha=255)
 
void strokeColor (const float red, const float green, const float blue, const float alpha=1.0f)
 
void strokePaint (const Paint &paint)
 
void fillColor (const Color &color)
 
void fillColor (const int red, const int green, const int blue, const int alpha=255)
 
void fillColor (const float red, const float green, const float blue, const float alpha=1.0f)
 
void fillPaint (const Paint &paint)
 
void miterLimit (float limit)
 
void strokeWidth (float size)
 
void lineCap (LineCap cap=BUTT)
 
void lineJoin (LineCap join=MITER)
 
void globalAlpha (float alpha)
 
void globalTint (Color tint)
 
void resetTransform ()
 
void transform (float a, float b, float c, float d, float e, float f)
 
void translate (float x, float y)
 
void rotate (float angle)
 
void skewX (float angle)
 
void skewY (float angle)
 
void scale (float x, float y)
 
void currentTransform (float xform[6])
 
NanoImage::Handle createImageFromFile (const char *filename, ImageFlags imageFlags)
 
NanoImage::Handle createImageFromFile (const char *filename, int imageFlags)
 
NanoImage::Handle createImageFromMemory (const uchar *data, uint dataSize, ImageFlags imageFlags)
 
NanoImage::Handle createImageFromMemory (const uchar *data, uint dataSize, int imageFlags)
 
NanoImage::Handle createImageFromRawMemory (uint w, uint h, const uchar *data, ImageFlags imageFlags, ImageFormat format)
 
NanoImage::Handle createImageFromRawMemory (uint w, uint h, const uchar *data, int imageFlags, ImageFormat format)
 
NanoImage::Handle createImageFromRGBA (uint w, uint h, const uchar *data, ImageFlags imageFlags)
 
NanoImage::Handle createImageFromRGBA (uint w, uint h, const uchar *data, int imageFlags)
 
NanoImage::Handle createImageFromTextureHandle (GLuint textureId, uint w, uint h, ImageFlags imageFlags, bool deleteTexture=false)
 
NanoImage::Handle createImageFromTextureHandle (GLuint textureId, uint w, uint h, int imageFlags, bool deleteTexture=false)
 
Paint linearGradient (float sx, float sy, float ex, float ey, const Color &icol, const Color &ocol)
 
Paint boxGradient (float x, float y, float w, float h, float r, float f, const Color &icol, const Color &ocol)
 
Paint radialGradient (float cx, float cy, float inr, float outr, const Color &icol, const Color &ocol)
 
Paint imagePattern (float ox, float oy, float ex, float ey, float angle, const NanoImage &image, float alpha)
 
void scissor (float x, float y, float w, float h)
 
void intersectScissor (float x, float y, float w, float h)
 
void resetScissor ()
 
void beginPath ()
 
void moveTo (float x, float y)
 
void lineTo (float x, float y)
 
void bezierTo (float c1x, float c1y, float c2x, float c2y, float x, float y)
 
void quadTo (float cx, float cy, float x, float y)
 
void arcTo (float x1, float y1, float x2, float y2, float radius)
 
void closePath ()
 
void pathWinding (Winding dir)
 
void arc (float cx, float cy, float r, float a0, float a1, Winding dir)
 
void rect (float x, float y, float w, float h)
 
void roundedRect (float x, float y, float w, float h, float r)
 
void ellipse (float cx, float cy, float rx, float ry)
 
void circle (float cx, float cy, float r)
 
void fill ()
 
void stroke ()
 
FontId createFontFromFile (const char *name, const char *filename)
 
FontId createFontFromMemory (const char *name, const uchar *data, uint dataSize, bool freeData)
 
FontId findFont (const char *name)
 
void fontSize (float size)
 
void fontBlur (float blur)
 
void textLetterSpacing (float spacing)
 
void textLineHeight (float lineHeight)
 
void textAlign (Align align)
 
void textAlign (int align)
 
void fontFaceId (FontId font)
 
void fontFace (const char *font)
 
float text (float x, float y, const char *string, const char *end)
 
void textBox (float x, float y, float breakRowWidth, const char *string, const char *end=nullptr)
 
float textBounds (float x, float y, const char *string, const char *end, Rectangle< float > &bounds)
 
void textBoxBounds (float x, float y, float breakRowWidth, const char *string, const char *end, float bounds[4])
 
int textGlyphPositions (float x, float y, const char *string, const char *end, GlyphPosition &positions, int maxPositions)
 
void textMetrics (float *ascender, float *descender, float *lineh)
 
int textBreakLines (const char *string, const char *end, float breakRowWidth, TextRow &rows, int maxRows)
 
virtual bool loadSharedResources ()
 

Static Public Member Functions

static void transformIdentity (float dst[6])
 
static void transformTranslate (float dst[6], float tx, float ty)
 
static void transformScale (float dst[6], float sx, float sy)
 
static void transformRotate (float dst[6], float a)
 
static void transformSkewX (float dst[6], float a)
 
static void transformSkewY (float dst[6], float a)
 
static void transformMultiply (float dst[6], const float src[6])
 
static void transformPremultiply (float dst[6], const float src[6])
 
static int transformInverse (float dst[6], const float src[6])
 
static void transformPoint (float &dstx, float &dsty, const float xform[6], float srcx, float srcy)
 
static float degToRad (float deg)
 
static float radToDeg (float rad)
 

Detailed Description

NanoVG class.

This class exposes the NanoVG drawing API. All calls should be wrapped in beginFrame() and endFrame().

Handling

NanoVG contains state which represents how paths will be rendered. The state contains transform, fill and stroke styles, text and font styles, and scissor clipping.

styles

Fill and stroke render style can be either a solid color or a paint which is a gradient or a pattern. Solid color is simply defined as a color value, different kinds of paints can be created using linearGradient(), boxGradient(), radialGradient() and imagePattern().

Current render style can be saved and restored using save() and restore().

Transforms

The paths, gradients, patterns and scissor region are transformed by an transformation matrix at the time when they are passed to the API. The current transformation matrix is a affine matrix: [sx kx tx] [ky sy ty] [ 0 0 1] Where: sx,sy define scaling, kx,ky skewing, and tx,ty translation. The last row is assumed to be 0,0,1 and is not stored.

Apart from resetTransform(), each transformation function first creates specific transformation matrix and pre-multiplies the current transformation by it.

Current coordinate system (transformation) can be saved and restored using save() and restore().

Images

NanoVG allows you to load jpg, png, psd, tga, pic and gif files to be used for rendering. In addition you can upload your own image. The image loading is provided by stb_image.

Paints

NanoVG supports four types of paints: linear gradient, box gradient, radial gradient and image pattern. These can be used as paints for strokes and fills.

Scissoring

Scissoring allows you to clip the rendering into a rectangle. This is useful for various user interface cases like rendering a text edit or a timeline.

Paths

Drawing a new shape starts with beginPath(), it clears all the currently defined paths. Then you define one or more paths and sub-paths which describe the shape. The are functions to draw common shapes like rectangles and circles, and lower level step-by-step functions, which allow to define a path curve by curve.

NanoVG uses even-odd fill rule to draw the shapes. Solid shapes should have counter clockwise winding and holes should have counter clockwise order. To specify winding of a path you can call pathWinding(). This is useful especially for the common shapes, which are drawn CCW.

Finally you can fill the path using current fill style by calling fill(), and stroke it with current stroke style by calling stroke().

The curve segments and sub-paths are transformed by the current transform.

Text

NanoVG allows you to load .ttf files and use the font to render text.

The appearance of the text can be defined by setting the current text style and by specifying the fill color. Common text and font settings such as font size, letter spacing and text align are supported. Font blur allows you to create simple text effects such as drop shadows.

At render time the font face can be set based on the font handles or name.

Font measure functions return values in local space, the calculations are carried in the same resolution as the final rendering. This is done because the text glyph positions are snapped to the nearest pixels sharp rendering.

The local space means that values are not rotated or scale as per the current transformation. For example if you set font size to 12, which would mean that line height is 16, then regardless of the current scaling and rotation, the returned line height is always 16. Some measures may vary because of the scaling since aforementioned pixel snapping.

While this may sound a little odd, the setup allows you to always render the same way regardless of scaling. i.e. following works regardless of scaling:

const char* txt = "Text me up.";
vg.textBounds(x,y, txt, NULL, bounds);
vg.beginPath();
vg.roundedRect(bounds[0], bounds[1], bounds[2]-bounds[0], bounds[3]-bounds[1]);
vg.fill();

Note: currently only solid color fill is supported for text.

Member Enumeration Documentation

◆ CreateFlags

Enumerator
CREATE_ANTIALIAS 

Flag indicating if geometry based anti-aliasing is used (may not be needed when using MSAA).

CREATE_STENCIL_STROKES 

Flag indicating if strokes should be drawn using stencil buffer. The rendering will be a little slower, but path overlaps (i.e. self-intersecting or sharp turns) will be drawn just once.

CREATE_DEBUG 

Flag indicating that additional debug checks are done.

Constructor & Destructor Documentation

◆ NanoVG() [1/2]

NanoVG::NanoVG ( int  flags = CREATE_ANTIALIAS)

Constructor.

See also
CreateFlags

◆ NanoVG() [2/2]

NanoVG::NanoVG ( NVGcontext *  context)
explicit

Constructor reusing a NanoVG context, used for subwidgets. Context will not be deleted on class destructor.

◆ ~NanoVG()

virtual NanoVG::~NanoVG ( )
virtual

Destructor.

Member Function Documentation

◆ getContext()

NVGcontext* NanoVG::getContext ( ) const
inlinenoexcept

Get the NanoVG context. You should not need this under normal circumstances.

◆ beginFrame() [1/2]

void NanoVG::beginFrame ( const uint  width,
const uint  height,
const float  scaleFactor = 1.0f 
)

Begin drawing a new frame.

◆ beginFrame() [2/2]

void NanoVG::beginFrame ( Widget *const  widget)

Begin drawing a new frame inside a widget.

◆ cancelFrame()

void NanoVG::cancelFrame ( )

Cancels drawing the current frame.

◆ endFrame()

void NanoVG::endFrame ( )

Ends drawing flushing remaining render state.

◆ save()

void NanoVG::save ( )

Pushes and saves the current render state into a state stack. A matching restore() must be used to restore the state.

◆ restore()

void NanoVG::restore ( )

Pops and restores current render state.

◆ reset()

void NanoVG::reset ( )

Resets current render state to default values. Does not affect the render state stack.

◆ strokeColor() [1/3]

void NanoVG::strokeColor ( const Color color)

Sets current stroke style to a solid color.

◆ strokeColor() [2/3]

void NanoVG::strokeColor ( const int  red,
const int  green,
const int  blue,
const int  alpha = 255 
)

Sets current stroke style to a solid color, made from red, green, blue and alpha numeric values. Values must be in [0..255] range.

◆ strokeColor() [3/3]

void NanoVG::strokeColor ( const float  red,
const float  green,
const float  blue,
const float  alpha = 1.0f 
)

Sets current stroke style to a solid color, made from red, green, blue and alpha numeric values. Values must in [0..1] range.

◆ strokePaint()

void NanoVG::strokePaint ( const Paint paint)

Sets current stroke style to a paint, which can be a one of the gradients or a pattern.

◆ fillColor() [1/3]

void NanoVG::fillColor ( const Color color)

Sets current fill style to a solid color.

◆ fillColor() [2/3]

void NanoVG::fillColor ( const int  red,
const int  green,
const int  blue,
const int  alpha = 255 
)

Sets current fill style to a solid color, made from red, green, blue and alpha numeric values. Values must be in [0..255] range.

◆ fillColor() [3/3]

void NanoVG::fillColor ( const float  red,
const float  green,
const float  blue,
const float  alpha = 1.0f 
)

Sets current fill style to a solid color, made from red, green, blue and alpha numeric values. Values must in [0..1] range.

◆ fillPaint()

void NanoVG::fillPaint ( const Paint paint)

Sets current fill style to a paint, which can be a one of the gradients or a pattern.

◆ miterLimit()

void NanoVG::miterLimit ( float  limit)

Sets the miter limit of the stroke style. Miter limit controls when a sharp corner is beveled.

◆ strokeWidth()

void NanoVG::strokeWidth ( float  size)

Sets the stroke width of the stroke style.

◆ lineCap()

void NanoVG::lineCap ( LineCap  cap = BUTT)

Sets how the end of the line (cap) is drawn, Can be one of: BUTT, ROUND, SQUARE.

◆ lineJoin()

void NanoVG::lineJoin ( LineCap  join = MITER)

Sets how sharp path corners are drawn. Can be one of MITER, ROUND, BEVEL.

◆ globalAlpha()

void NanoVG::globalAlpha ( float  alpha)

Sets the transparency applied to all rendered shapes. Already transparent paths will get proportionally more transparent as well.

◆ globalTint()

void NanoVG::globalTint ( Color  tint)

Sets the color tint applied to all rendered shapes.

◆ resetTransform()

void NanoVG::resetTransform ( )

Resets current transform to a identity matrix.

◆ transform()

void NanoVG::transform ( float  a,
float  b,
float  c,
float  d,
float  e,
float  f 
)

Pre-multiplies current coordinate system by specified matrix. The parameters are interpreted as matrix as follows: [a c e] [b d f] [0 0 1]

◆ translate()

void NanoVG::translate ( float  x,
float  y 
)

Translates current coordinate system.

◆ rotate()

void NanoVG::rotate ( float  angle)

Rotates current coordinate system. Angle is specified in radians.

◆ skewX()

void NanoVG::skewX ( float  angle)

Skews the current coordinate system along X axis. Angle is specified in radians.

◆ skewY()

void NanoVG::skewY ( float  angle)

Skews the current coordinate system along Y axis. Angle is specified in radians.

◆ scale()

void NanoVG::scale ( float  x,
float  y 
)

Scales the current coordinate system.

◆ currentTransform()

void NanoVG::currentTransform ( float  xform[6])

Stores the top part (a-f) of the current transformation matrix in to the specified buffer. [a c e] [b d f] [0 0 1]

◆ transformIdentity()

static void NanoVG::transformIdentity ( float  dst[6])
static

The following functions can be used to make calculations on 2x3 transformation matrices. A 2x3 matrix is represented as float[6]. Sets the transform to identity matrix.

◆ transformTranslate()

static void NanoVG::transformTranslate ( float  dst[6],
float  tx,
float  ty 
)
static

Sets the transform to translation matrix

◆ transformScale()

static void NanoVG::transformScale ( float  dst[6],
float  sx,
float  sy 
)
static

Sets the transform to scale matrix.

◆ transformRotate()

static void NanoVG::transformRotate ( float  dst[6],
float  a 
)
static

Sets the transform to rotate matrix. Angle is specified in radians.

◆ transformSkewX()

static void NanoVG::transformSkewX ( float  dst[6],
float  a 
)
static

Sets the transform to skew-x matrix. Angle is specified in radians.

◆ transformSkewY()

static void NanoVG::transformSkewY ( float  dst[6],
float  a 
)
static

Sets the transform to skew-y matrix. Angle is specified in radians.

◆ transformMultiply()

static void NanoVG::transformMultiply ( float  dst[6],
const float  src[6] 
)
static

Sets the transform to the result of multiplication of two transforms, of A = A*B.

◆ transformPremultiply()

static void NanoVG::transformPremultiply ( float  dst[6],
const float  src[6] 
)
static

Sets the transform to the result of multiplication of two transforms, of A = B*A.

◆ transformInverse()

static int NanoVG::transformInverse ( float  dst[6],
const float  src[6] 
)
static

Sets the destination to inverse of specified transform. Returns 1 if the inverse could be calculated, else 0.

◆ transformPoint()

static void NanoVG::transformPoint ( float &  dstx,
float &  dsty,
const float  xform[6],
float  srcx,
float  srcy 
)
static

Transform a point by given transform.

◆ degToRad()

static float NanoVG::degToRad ( float  deg)
static

Convert degrees to radians.

◆ radToDeg()

static float NanoVG::radToDeg ( float  rad)
static

Convert radians to degrees.

◆ createImageFromFile() [1/2]

NanoImage::Handle NanoVG::createImageFromFile ( const char *  filename,
ImageFlags  imageFlags 
)

Creates image by loading it from the disk from specified file name.

◆ createImageFromFile() [2/2]

NanoImage::Handle NanoVG::createImageFromFile ( const char *  filename,
int  imageFlags 
)

Creates image by loading it from the disk from specified file name. Overloaded function for convenience.

See also
ImageFlags

◆ createImageFromMemory() [1/2]

NanoImage::Handle NanoVG::createImageFromMemory ( const uchar *  data,
uint  dataSize,
ImageFlags  imageFlags 
)

Creates image by loading it from the specified chunk of memory.

◆ createImageFromMemory() [2/2]

NanoImage::Handle NanoVG::createImageFromMemory ( const uchar *  data,
uint  dataSize,
int  imageFlags 
)

Creates image by loading it from the specified chunk of memory. Overloaded function for convenience.

See also
ImageFlags

◆ createImageFromRawMemory() [1/2]

NanoImage::Handle NanoVG::createImageFromRawMemory ( uint  w,
uint  h,
const uchar *  data,
ImageFlags  imageFlags,
ImageFormat  format 
)

Creates image from specified raw format image data.

◆ createImageFromRawMemory() [2/2]

NanoImage::Handle NanoVG::createImageFromRawMemory ( uint  w,
uint  h,
const uchar *  data,
int  imageFlags,
ImageFormat  format 
)

Creates image from specified raw format image data. Overloaded function for convenience.

See also
ImageFlags

◆ createImageFromRGBA() [1/2]

NanoImage::Handle NanoVG::createImageFromRGBA ( uint  w,
uint  h,
const uchar *  data,
ImageFlags  imageFlags 
)

Creates image from specified RGBA image data.

◆ createImageFromRGBA() [2/2]

NanoImage::Handle NanoVG::createImageFromRGBA ( uint  w,
uint  h,
const uchar *  data,
int  imageFlags 
)

Creates image from specified RGBA image data. Overloaded function for convenience.

See also
ImageFlags

◆ createImageFromTextureHandle() [1/2]

NanoImage::Handle NanoVG::createImageFromTextureHandle ( GLuint  textureId,
uint  w,
uint  h,
ImageFlags  imageFlags,
bool  deleteTexture = false 
)

Creates image from an OpenGL texture handle.

◆ createImageFromTextureHandle() [2/2]

NanoImage::Handle NanoVG::createImageFromTextureHandle ( GLuint  textureId,
uint  w,
uint  h,
int  imageFlags,
bool  deleteTexture = false 
)

Creates image from an OpenGL texture handle. Overloaded function for convenience.

See also
ImageFlags

◆ linearGradient()

Paint NanoVG::linearGradient ( float  sx,
float  sy,
float  ex,
float  ey,
const Color icol,
const Color ocol 
)

Creates and returns a linear gradient. Parameters (sx,sy)-(ex,ey) specify the start and end coordinates of the linear gradient, icol specifies the start color and ocol the end color. The gradient is transformed by the current transform when it is passed to fillPaint() or strokePaint().

◆ boxGradient()

Paint NanoVG::boxGradient ( float  x,
float  y,
float  w,
float  h,
float  r,
float  f,
const Color icol,
const Color ocol 
)

Creates and returns a box gradient. Box gradient is a feathered rounded rectangle, it is useful for rendering drop shadows or highlights for boxes. Parameters (x,y) define the top-left corner of the rectangle, (w,h) define the size of the rectangle, r defines the corner radius, and f feather. Feather defines how blurry the border of the rectangle is. Parameter icol specifies the inner color and ocol the outer color of the gradient. The gradient is transformed by the current transform when it is passed to fillPaint() or strokePaint().

◆ radialGradient()

Paint NanoVG::radialGradient ( float  cx,
float  cy,
float  inr,
float  outr,
const Color icol,
const Color ocol 
)

Creates and returns a radial gradient. Parameters (cx,cy) specify the center, inr and outr specify the inner and outer radius of the gradient, icol specifies the start color and ocol the end color. The gradient is transformed by the current transform when it is passed to fillPaint() or strokePaint().

◆ imagePattern()

Paint NanoVG::imagePattern ( float  ox,
float  oy,
float  ex,
float  ey,
float  angle,
const NanoImage image,
float  alpha 
)

Creates and returns an image pattern. Parameters (ox,oy) specify the left-top location of the image pattern, (ex,ey) the size of one image, angle rotation around the top-left corner, image is handle to the image to render. The gradient is transformed by the current transform when it is passed to fillPaint() or strokePaint().

◆ scissor()

void NanoVG::scissor ( float  x,
float  y,
float  w,
float  h 
)

Sets the current scissor rectangle. The scissor rectangle is transformed by the current transform.

◆ intersectScissor()

void NanoVG::intersectScissor ( float  x,
float  y,
float  w,
float  h 
)

Intersects current scissor rectangle with the specified rectangle. The scissor rectangle is transformed by the current transform. Note: in case the rotation of previous scissor rect differs from the current one, the intersection will be done between the specified rectangle and the previous scissor rectangle transformed in the current transform space. The resulting shape is always rectangle.

◆ resetScissor()

void NanoVG::resetScissor ( )

Reset and disables scissoring.

◆ beginPath()

void NanoVG::beginPath ( )

Clears the current path and sub-paths.

◆ moveTo()

void NanoVG::moveTo ( float  x,
float  y 
)

Starts new sub-path with specified point as first point.

◆ lineTo()

void NanoVG::lineTo ( float  x,
float  y 
)

Adds line segment from the last point in the path to the specified point.

◆ bezierTo()

void NanoVG::bezierTo ( float  c1x,
float  c1y,
float  c2x,
float  c2y,
float  x,
float  y 
)

Adds cubic bezier segment from last point in the path via two control points to the specified point.

◆ quadTo()

void NanoVG::quadTo ( float  cx,
float  cy,
float  x,
float  y 
)

Adds quadratic bezier segment from last point in the path via a control point to the specified point.

◆ arcTo()

void NanoVG::arcTo ( float  x1,
float  y1,
float  x2,
float  y2,
float  radius 
)

Adds an arc segment at the corner defined by the last path point, and two specified points.

◆ closePath()

void NanoVG::closePath ( )

Closes current sub-path with a line segment.

◆ pathWinding()

void NanoVG::pathWinding ( Winding  dir)

Sets the current sub-path winding.

◆ arc()

void NanoVG::arc ( float  cx,
float  cy,
float  r,
float  a0,
float  a1,
Winding  dir 
)

Creates new circle arc shaped sub-path. The arc center is at cx,cy, the arc radius is r, and the arc is drawn from angle a0 to a1, and swept in direction dir (NVG_CCW or NVG_CW). Angles are specified in radians.

◆ rect()

void NanoVG::rect ( float  x,
float  y,
float  w,
float  h 
)

Creates new rectangle shaped sub-path.

◆ roundedRect()

void NanoVG::roundedRect ( float  x,
float  y,
float  w,
float  h,
float  r 
)

Creates new rounded rectangle shaped sub-path.

◆ ellipse()

void NanoVG::ellipse ( float  cx,
float  cy,
float  rx,
float  ry 
)

Creates new ellipse shaped sub-path.

◆ circle()

void NanoVG::circle ( float  cx,
float  cy,
float  r 
)

Creates new circle shaped sub-path.

◆ fill()

void NanoVG::fill ( )

Fills the current path with current fill style.

◆ stroke()

void NanoVG::stroke ( )

Fills the current path with current stroke style.

◆ createFontFromFile()

FontId NanoVG::createFontFromFile ( const char *  name,
const char *  filename 
)

Creates font by loading it from the disk from specified file name. Returns handle to the font.

◆ createFontFromMemory()

FontId NanoVG::createFontFromMemory ( const char *  name,
const uchar *  data,
uint  dataSize,
bool  freeData 
)

Creates font by loading it from the specified memory chunk. Returns handle to the font.

◆ findFont()

FontId NanoVG::findFont ( const char *  name)

Finds a loaded font of specified name, and returns handle to it, or -1 if the font is not found.

◆ fontSize()

void NanoVG::fontSize ( float  size)

Sets the font size of current text style.

◆ fontBlur()

void NanoVG::fontBlur ( float  blur)

Sets the blur of current text style.

◆ textLetterSpacing()

void NanoVG::textLetterSpacing ( float  spacing)

Sets the letter spacing of current text style.

◆ textLineHeight()

void NanoVG::textLineHeight ( float  lineHeight)

Sets the proportional line height of current text style. The line height is specified as multiple of font size.

◆ textAlign() [1/2]

void NanoVG::textAlign ( Align  align)

Sets the text align of current text style.

◆ textAlign() [2/2]

void NanoVG::textAlign ( int  align)

Sets the text align of current text style. Overloaded function for convenience.

See also
Align

◆ fontFaceId()

void NanoVG::fontFaceId ( FontId  font)

Sets the font face based on specified id of current text style.

◆ fontFace()

void NanoVG::fontFace ( const char *  font)

Sets the font face based on specified name of current text style.

◆ text()

float NanoVG::text ( float  x,
float  y,
const char *  string,
const char *  end 
)

Draws text string at specified location. If end is specified only the sub-string up to the end is drawn.

◆ textBox()

void NanoVG::textBox ( float  x,
float  y,
float  breakRowWidth,
const char *  string,
const char *  end = nullptr 
)

Draws multi-line text string at specified location wrapped at the specified width. If end is specified only the sub-string up to the end is drawn. White space is stripped at the beginning of the rows, the text is split at word boundaries or when new-line characters are encountered. Words longer than the max width are slit at nearest character (i.e. no hyphenation).

◆ textBounds()

float NanoVG::textBounds ( float  x,
float  y,
const char *  string,
const char *  end,
Rectangle< float > &  bounds 
)

Measures the specified text string. The bounds value are [xmin,ymin, xmax,ymax]. Returns the horizontal advance of the measured text (i.e. where the next character should drawn). Measured values are returned in local coordinate space.

◆ textBoxBounds()

void NanoVG::textBoxBounds ( float  x,
float  y,
float  breakRowWidth,
const char *  string,
const char *  end,
float  bounds[4] 
)

Measures the specified multi-text string. Parameter bounds should be a pointer to float[4], if the bounding box of the text should be returned. The bounds value are [xmin,ymin, xmax,ymax] Measured values are returned in local coordinate space.

◆ textGlyphPositions()

int NanoVG::textGlyphPositions ( float  x,
float  y,
const char *  string,
const char *  end,
GlyphPosition positions,
int  maxPositions 
)

Calculates the glyph x positions of the specified text. If end is specified only the sub-string will be used. Measured values are returned in local coordinate space.

◆ textMetrics()

void NanoVG::textMetrics ( float *  ascender,
float *  descender,
float *  lineh 
)

Returns the vertical metrics based on the current text style. Measured values are returned in local coordinate space.

◆ textBreakLines()

int NanoVG::textBreakLines ( const char *  string,
const char *  end,
float  breakRowWidth,
TextRow rows,
int  maxRows 
)

Breaks the specified text into lines. If end is specified only the sub-string will be used. White space is stripped at the beginning of the rows, the text is split at word boundaries or when new-line characters are encountered. Words longer than the max width are slit at nearest character (i.e. no hyphenation).

◆ loadSharedResources()

virtual bool NanoVG::loadSharedResources ( )
virtual

Load DPF's internal shared resources for this NanoVG class.


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