LMMS
Loading...
Searching...
No Matches
nanovg.h
Go to the documentation of this file.
1//
2// Copyright (c) 2013 Mikko Mononen memon@inside.org
3//
4// This software is provided 'as-is', without any express or implied
5// warranty. In no event will the authors be held liable for any damages
6// arising from the use of this software.
7// Permission is granted to anyone to use this software for any purpose,
8// including commercial applications, and to alter it and redistribute it
9// freely, subject to the following restrictions:
10// 1. The origin of this software must not be misrepresented; you must not
11// claim that you wrote the original software. If you use this software
12// in a product, an acknowledgment in the product documentation would be
13// appreciated but is not required.
14// 2. Altered source versions must be plainly marked as such, and must not be
15// misrepresented as being the original software.
16// 3. This notice may not be removed or altered from any source distribution.
17//
18
19#ifndef NANOVG_H
20#define NANOVG_H
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26#define NVG_PI 3.14159265358979323846264338327f
27
28#ifdef _MSC_VER
29#pragma warning(push)
30#pragma warning(disable: 4201) // nonstandard extension used : nameless struct/union
31#endif
32
33typedef struct NVGcontext NVGcontext;
34
35struct NVGcolor {
36 union {
37 float rgba[4];
38 struct {
39 float r,g,b,a;
40 };
41 };
42};
43typedef struct NVGcolor NVGcolor;
44
45struct NVGpaint {
46 float xform[6];
47 float extent[2];
48 float radius;
49 float feather;
52 int image;
53};
54typedef struct NVGpaint NVGpaint;
55
57 NVG_CCW = 1, // Winding for solid shapes
58 NVG_CW = 2, // Winding for holes
59};
60
62 NVG_SOLID = 1, // CCW
63 NVG_HOLE = 2, // CW
64};
65
73
75 // Horizontal align
76 NVG_ALIGN_LEFT = 1<<0, // Default, align text horizontally to left.
77 NVG_ALIGN_CENTER = 1<<1, // Align text horizontally to center.
78 NVG_ALIGN_RIGHT = 1<<2, // Align text horizontally to right.
79 // Vertical align
80 NVG_ALIGN_TOP = 1<<3, // Align text vertically to top.
81 NVG_ALIGN_MIDDLE = 1<<4, // Align text vertically to middle.
82 NVG_ALIGN_BOTTOM = 1<<5, // Align text vertically to bottom.
83 NVG_ALIGN_BASELINE = 1<<6, // Default, align text vertically to baseline.
84};
85
99
113
121
123 const char* str; // Position of the glyph in the input string.
124 float x; // The x-coordinate of the logical glyph position.
125 float minx, maxx; // The bounds of the glyph shape.
126};
128
130 const char* start; // Pointer to the input text where the row starts.
131 const char* end; // Pointer to the input text where the row ends (one past the last character).
132 const char* next; // Pointer to the beginning of the next row.
133 float width; // Logical width of the row.
134 float minx, maxx; // Actual bounds of the row. Logical with and bounds can differ because of kerning and some parts over extending.
135};
136typedef struct NVGtextRow NVGtextRow;
137
139 NVG_IMAGE_GENERATE_MIPMAPS = 1<<0, // Generate mipmaps during creation of the image.
140 NVG_IMAGE_REPEATX = 1<<1, // Repeat image in X direction.
141 NVG_IMAGE_REPEATY = 1<<2, // Repeat image in Y direction.
142 NVG_IMAGE_FLIPY = 1<<3, // Flips (inverses) image in Y direction when rendered.
143 NVG_IMAGE_PREMULTIPLIED = 1<<4, // Image data has premultiplied alpha.
144 NVG_IMAGE_NEAREST = 1<<5, // Image interpolation is Nearest instead Linear
145};
146
154
155// Begin drawing a new frame
156// Calls to nanovg drawing API should be wrapped in nvgBeginFrame() & nvgEndFrame()
157// nvgBeginFrame() defines the size of the window to render to in relation currently
158// set viewport (i.e. glViewport on GL backends). Device pixel ration allows to
159// control the rendering on Hi-DPI devices.
160// For example, GLFW returns two dimension for an opened window: window size and
161// frame buffer size. In that case you would set windowWidth/Height to the window size
162// devicePixelRatio to: frameBufferWidth / windowWidth.
163void nvgBeginFrame(NVGcontext* ctx, float windowWidth, float windowHeight, float devicePixelRatio);
164
165// Cancels drawing the current frame.
166void nvgCancelFrame(NVGcontext* ctx);
167
168// Ends drawing flushing remaining render state.
169void nvgEndFrame(NVGcontext* ctx);
170
171//
172// Composite operation
173//
174// The composite operations in NanoVG are modeled after HTML Canvas API, and
175// the blend func is based on OpenGL (see corresponding manuals for more info).
176// The colors in the blending state have premultiplied alpha.
177
178// Sets the composite operation. The op parameter should be one of NVGcompositeOperation.
179void nvgGlobalCompositeOperation(NVGcontext* ctx, int op);
180
181// Sets the composite operation with custom pixel arithmetic. The parameters should be one of NVGblendFactor.
182void nvgGlobalCompositeBlendFunc(NVGcontext* ctx, int sfactor, int dfactor);
183
184// Sets the composite operation with custom pixel arithmetic for RGB and alpha components separately. The parameters should be one of NVGblendFactor.
185void nvgGlobalCompositeBlendFuncSeparate(NVGcontext* ctx, int srcRGB, int dstRGB, int srcAlpha, int dstAlpha);
186
187//
188// Color utils
189//
190// Colors in NanoVG are stored as unsigned ints in ABGR format.
191
192// Returns a color value from red, green, blue values. Alpha will be set to 255 (1.0f).
193NVGcolor nvgRGB(unsigned char r, unsigned char g, unsigned char b);
194
195// Returns a color value from red, green, blue values. Alpha will be set to 1.0f.
196NVGcolor nvgRGBf(float r, float g, float b);
197
198
199// Returns a color value from red, green, blue and alpha values.
200NVGcolor nvgRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
201
202// Returns a color value from red, green, blue and alpha values.
203NVGcolor nvgRGBAf(float r, float g, float b, float a);
204
205
206// Linearly interpolates from color c0 to c1, and returns resulting color value.
207NVGcolor nvgLerpRGBA(NVGcolor c0, NVGcolor c1, float u);
208
209// Sets transparency of a color value.
210NVGcolor nvgTransRGBA(NVGcolor c0, unsigned char a);
211
212// Sets transparency of a color value.
214
215// Returns color value specified by hue, saturation and lightness.
216// HSL values are all in range [0..1], alpha will be set to 255.
217NVGcolor nvgHSL(float h, float s, float l);
218
219// Returns color value specified by hue, saturation and lightness and alpha.
220// HSL values are all in range [0..1], alpha in range [0..255]
221NVGcolor nvgHSLA(float h, float s, float l, unsigned char a);
222
223//
224// State Handling
225//
226// NanoVG contains state which represents how paths will be rendered.
227// The state contains transform, fill and stroke styles, text and font styles,
228// and scissor clipping.
229
230// Pushes and saves the current render state into a state stack.
231// A matching nvgRestore() must be used to restore the state.
232void nvgSave(NVGcontext* ctx);
233
234// Pops and restores current render state.
235void nvgRestore(NVGcontext* ctx);
236
237// Resets current render state to default values. Does not affect the render state stack.
238void nvgReset(NVGcontext* ctx);
239
240//
241// Render styles
242//
243// Fill and stroke render style can be either a solid color or a paint which is a gradient or a pattern.
244// Solid color is simply defined as a color value, different kinds of paints can be created
245// using nvgLinearGradient(), nvgBoxGradient(), nvgRadialGradient() and nvgImagePattern().
246//
247// Current render style can be saved and restored using nvgSave() and nvgRestore().
248
249// Sets whether to draw antialias for nvgStroke() and nvgFill(). It's enabled by default.
250void nvgShapeAntiAlias(NVGcontext* ctx, int enabled);
251
252// Sets current stroke style to a solid color.
253void nvgStrokeColor(NVGcontext* ctx, NVGcolor color);
254
255// Sets current stroke style to a paint, which can be a one of the gradients or a pattern.
256void nvgStrokePaint(NVGcontext* ctx, NVGpaint paint);
257
258// Sets current fill style to a solid color.
259void nvgFillColor(NVGcontext* ctx, NVGcolor color);
260
261// Sets current fill style to a paint, which can be a one of the gradients or a pattern.
262void nvgFillPaint(NVGcontext* ctx, NVGpaint paint);
263
264// Sets the miter limit of the stroke style.
265// Miter limit controls when a sharp corner is beveled.
266void nvgMiterLimit(NVGcontext* ctx, float limit);
267
268// Sets the stroke width of the stroke style.
269void nvgStrokeWidth(NVGcontext* ctx, float size);
270
271// Sets how the end of the line (cap) is drawn,
272// Can be one of: NVG_BUTT (default), NVG_ROUND, NVG_SQUARE.
273void nvgLineCap(NVGcontext* ctx, int cap);
274
275// Sets how sharp path corners are drawn.
276// Can be one of NVG_MITER (default), NVG_ROUND, NVG_BEVEL.
277void nvgLineJoin(NVGcontext* ctx, int join);
278
279// Sets the transparency applied to all rendered shapes.
280// Already transparent paths will get proportionally more transparent as well.
281void nvgGlobalAlpha(NVGcontext* ctx, float alpha);
282void nvgGlobalTint(NVGcontext* ctx, NVGcolor tint);
284void nvgAlpha(NVGcontext* ctx, float alpha);
285void nvgTint(NVGcontext* ctx, NVGcolor tint);
286
287//
288// Transforms
289//
290// The paths, gradients, patterns and scissor region are transformed by an transformation
291// matrix at the time when they are passed to the API.
292// The current transformation matrix is a affine matrix:
293// [sx kx tx]
294// [ky sy ty]
295// [ 0 0 1]
296// Where: sx,sy define scaling, kx,ky skewing, and tx,ty translation.
297// The last row is assumed to be 0,0,1 and is not stored.
298//
299// Apart from nvgResetTransform(), each transformation function first creates
300// specific transformation matrix and pre-multiplies the current transformation by it.
301//
302// Current coordinate system (transformation) can be saved and restored using nvgSave() and nvgRestore().
303
304// Resets current transform to a identity matrix.
306
307// Premultiplies current coordinate system by specified matrix.
308// The parameters are interpreted as matrix as follows:
309// [a c e]
310// [b d f]
311// [0 0 1]
312void nvgTransform(NVGcontext* ctx, float a, float b, float c, float d, float e, float f);
313
314// Translates current coordinate system.
315void nvgTranslate(NVGcontext* ctx, float x, float y);
316
317// Rotates current coordinate system. Angle is specified in radians.
318void nvgRotate(NVGcontext* ctx, float angle);
319
320// Skews the current coordinate system along X axis. Angle is specified in radians.
321void nvgSkewX(NVGcontext* ctx, float angle);
322
323// Skews the current coordinate system along Y axis. Angle is specified in radians.
324void nvgSkewY(NVGcontext* ctx, float angle);
325
326// Scales the current coordinate system.
327void nvgScale(NVGcontext* ctx, float x, float y);
328
329// Stores the top part (a-f) of the current transformation matrix in to the specified buffer.
330// [a c e]
331// [b d f]
332// [0 0 1]
333// There should be space for 6 floats in the return buffer for the values a-f.
334void nvgCurrentTransform(NVGcontext* ctx, float* xform);
335
336
337// The following functions can be used to make calculations on 2x3 transformation matrices.
338// A 2x3 matrix is represented as float[6].
339
340// Sets the transform to identity matrix.
341void nvgTransformIdentity(float* dst);
342
343// Sets the transform to translation matrix matrix.
344void nvgTransformTranslate(float* dst, float tx, float ty);
345
346// Sets the transform to scale matrix.
347void nvgTransformScale(float* dst, float sx, float sy);
348
349// Sets the transform to rotate matrix. Angle is specified in radians.
350void nvgTransformRotate(float* dst, float a);
351
352// Sets the transform to skew-x matrix. Angle is specified in radians.
353void nvgTransformSkewX(float* dst, float a);
354
355// Sets the transform to skew-y matrix. Angle is specified in radians.
356void nvgTransformSkewY(float* dst, float a);
357
358// Sets the transform to the result of multiplication of two transforms, of A = A*B.
359void nvgTransformMultiply(float* dst, const float* src);
360
361// Sets the transform to the result of multiplication of two transforms, of A = B*A.
362void nvgTransformPremultiply(float* dst, const float* src);
363
364// Sets the destination to inverse of specified transform.
365// Returns 1 if the inverse could be calculated, else 0.
366int nvgTransformInverse(float* dst, const float* src);
367
368// Transform a point by given transform.
369void nvgTransformPoint(float* dstx, float* dsty, const float* xform, float srcx, float srcy);
370
371// Converts degrees to radians and vice versa.
372float nvgDegToRad(float deg);
373float nvgRadToDeg(float rad);
374
375//
376// Images
377//
378// NanoVG allows you to load jpg, png, psd, tga, pic and gif files to be used for rendering.
379// In addition you can upload your own image. The image loading is provided by stb_image.
380// The parameter imageFlags is combination of flags defined in NVGimageFlags.
381
382// Creates image by loading it from the disk from specified file name.
383// Returns handle to the image.
384int nvgCreateImage(NVGcontext* ctx, const char* filename, int imageFlags);
385
386// Creates image by loading it from the specified chunk of memory.
387// Returns handle to the image.
388int nvgCreateImageMem(NVGcontext* ctx, int imageFlags, unsigned char* data, int ndata);
389
390// Creates image from specified image data and texture format.
391// Returns handle to the image.
392int nvgCreateImageRaw(NVGcontext* ctx, int w, int h, int imageFlags, enum NVGtexture format, const unsigned char* data);
393
394// Creates image from specified image data.
395// Returns handle to the image.
396int nvgCreateImageRGBA(NVGcontext* ctx, int w, int h, int imageFlags, const unsigned char* data);
397
398// Updates image data specified by image handle.
399void nvgUpdateImage(NVGcontext* ctx, int image, const unsigned char* data);
400
401// Returns the dimensions of a created image.
402void nvgImageSize(NVGcontext* ctx, int image, int* w, int* h);
403
404// Deletes created image.
405void nvgDeleteImage(NVGcontext* ctx, int image);
406
407//
408// Paints
409//
410// NanoVG supports four types of paints: linear gradient, box gradient, radial gradient and image pattern.
411// These can be used as paints for strokes and fills.
412
413// Creates and returns a linear gradient. Parameters (sx,sy)-(ex,ey) specify the start and end coordinates
414// of the linear gradient, icol specifies the start color and ocol the end color.
415// The gradient is transformed by the current transform when it is passed to nvgFillPaint() or nvgStrokePaint().
416NVGpaint nvgLinearGradient(NVGcontext* ctx, float sx, float sy, float ex, float ey,
417 NVGcolor icol, NVGcolor ocol);
418
419// Creates and returns a box gradient. Box gradient is a feathered rounded rectangle, it is useful for rendering
420// drop shadows or highlights for boxes. Parameters (x,y) define the top-left corner of the rectangle,
421// (w,h) define the size of the rectangle, r defines the corner radius, and f feather. Feather defines how blurry
422// the border of the rectangle is. Parameter icol specifies the inner color and ocol the outer color of the gradient.
423// The gradient is transformed by the current transform when it is passed to nvgFillPaint() or nvgStrokePaint().
424NVGpaint nvgBoxGradient(NVGcontext* ctx, float x, float y, float w, float h,
425 float r, float f, NVGcolor icol, NVGcolor ocol);
426
427// Creates and returns a radial gradient. Parameters (cx,cy) specify the center, inr and outr specify
428// the inner and outer radius of the gradient, icol specifies the start color and ocol the end color.
429// The gradient is transformed by the current transform when it is passed to nvgFillPaint() or nvgStrokePaint().
430NVGpaint nvgRadialGradient(NVGcontext* ctx, float cx, float cy, float inr, float outr,
431 NVGcolor icol, NVGcolor ocol);
432
433// Creates and returns an image pattern. Parameters (ox,oy) specify the left-top location of the image pattern,
434// (ex,ey) the size of one image, angle rotation around the top-left corner, image is handle to the image to render.
435// The gradient is transformed by the current transform when it is passed to nvgFillPaint() or nvgStrokePaint().
436NVGpaint nvgImagePattern(NVGcontext* ctx, float ox, float oy, float ex, float ey,
437 float angle, int image, float alpha);
438
439//
440// Scissoring
441//
442// Scissoring allows you to clip the rendering into a rectangle. This is useful for various
443// user interface cases like rendering a text edit or a timeline.
444
445// Sets the current scissor rectangle.
446// The scissor rectangle is transformed by the current transform.
447void nvgScissor(NVGcontext* ctx, float x, float y, float w, float h);
448
449// Intersects current scissor rectangle with the specified rectangle.
450// The scissor rectangle is transformed by the current transform.
451// Note: in case the rotation of previous scissor rect differs from
452// the current one, the intersection will be done between the specified
453// rectangle and the previous scissor rectangle transformed in the current
454// transform space. The resulting shape is always rectangle.
455void nvgIntersectScissor(NVGcontext* ctx, float x, float y, float w, float h);
456
457// Reset and disables scissoring.
458void nvgResetScissor(NVGcontext* ctx);
459
460//
461// Paths
462//
463// Drawing a new shape starts with nvgBeginPath(), it clears all the currently defined paths.
464// Then you define one or more paths and sub-paths which describe the shape. The are functions
465// to draw common shapes like rectangles and circles, and lower level step-by-step functions,
466// which allow to define a path curve by curve.
467//
468// NanoVG uses even-odd fill rule to draw the shapes. Solid shapes should have counter clockwise
469// winding and holes should have counter clockwise order. To specify winding of a path you can
470// call nvgPathWinding(). This is useful especially for the common shapes, which are drawn CCW.
471//
472// Finally you can fill the path using current fill style by calling nvgFill(), and stroke it
473// with current stroke style by calling nvgStroke().
474//
475// The curve segments and sub-paths are transformed by the current transform.
476
477// Clears the current path and sub-paths.
478void nvgBeginPath(NVGcontext* ctx);
479
480// Starts new sub-path with specified point as first point.
481void nvgMoveTo(NVGcontext* ctx, float x, float y);
482
483// Adds line segment from the last point in the path to the specified point.
484void nvgLineTo(NVGcontext* ctx, float x, float y);
485
486// Adds cubic bezier segment from last point in the path via two control points to the specified point.
487void nvgBezierTo(NVGcontext* ctx, float c1x, float c1y, float c2x, float c2y, float x, float y);
488
489// Adds quadratic bezier segment from last point in the path via a control point to the specified point.
490void nvgQuadTo(NVGcontext* ctx, float cx, float cy, float x, float y);
491
492// Adds an arc segment at the corner defined by the last path point, and two specified points.
493void nvgArcTo(NVGcontext* ctx, float x1, float y1, float x2, float y2, float radius);
494
495// Closes current sub-path with a line segment.
496void nvgClosePath(NVGcontext* ctx);
497
498// Sets the current sub-path winding, see NVGwinding and NVGsolidity.
499void nvgPathWinding(NVGcontext* ctx, int dir);
500
501// Creates new circle arc shaped sub-path. The arc center is at cx,cy, the arc radius is r,
502// and the arc is drawn from angle a0 to a1, and swept in direction dir (NVG_CCW, or NVG_CW).
503// Angles are specified in radians.
504void nvgArc(NVGcontext* ctx, float cx, float cy, float r, float a0, float a1, int dir);
505
506// Creates new rectangle shaped sub-path.
507void nvgRect(NVGcontext* ctx, float x, float y, float w, float h);
508
509// Creates new rounded rectangle shaped sub-path.
510void nvgRoundedRect(NVGcontext* ctx, float x, float y, float w, float h, float r);
511
512// Creates new rounded rectangle shaped sub-path with varying radii for each corner.
513void nvgRoundedRectVarying(NVGcontext* ctx, float x, float y, float w, float h, float radTopLeft, float radTopRight, float radBottomRight, float radBottomLeft);
514
515// Creates new ellipse shaped sub-path.
516void nvgEllipse(NVGcontext* ctx, float cx, float cy, float rx, float ry);
517
518// Creates new circle shaped sub-path.
519void nvgCircle(NVGcontext* ctx, float cx, float cy, float r);
520
521// Fills the current path with current fill style.
522void nvgFill(NVGcontext* ctx);
523
524// Fills the current path with current stroke style.
525void nvgStroke(NVGcontext* ctx);
526
527
528//
529// Text
530//
531// NanoVG allows you to load .ttf files and use the font to render text.
532//
533// The appearance of the text can be defined by setting the current text style
534// and by specifying the fill color. Common text and font settings such as
535// font size, letter spacing and text align are supported. Font blur allows you
536// to create simple text effects such as drop shadows.
537//
538// At render time the font face can be set based on the font handles or name.
539//
540// Font measure functions return values in local space, the calculations are
541// carried in the same resolution as the final rendering. This is done because
542// the text glyph positions are snapped to the nearest pixels sharp rendering.
543//
544// The local space means that values are not rotated or scale as per the current
545// transformation. For example if you set font size to 12, which would mean that
546// line height is 16, then regardless of the current scaling and rotation, the
547// returned line height is always 16. Some measures may vary because of the scaling
548// since aforementioned pixel snapping.
549//
550// While this may sound a little odd, the setup allows you to always render the
551// same way regardless of scaling. I.e. following works regardless of scaling:
552//
553// const char* txt = "Text me up.";
554// nvgTextBounds(vg, x,y, txt, NULL, bounds);
555// nvgBeginPath(vg);
556// nvgRoundedRect(vg, bounds[0],bounds[1], bounds[2]-bounds[0], bounds[3]-bounds[1]);
557// nvgFill(vg);
558//
559// Note: currently only solid color fill is supported for text.
560
561// Creates font by loading it from the disk from specified file name.
562// Returns handle to the font.
563int nvgCreateFont(NVGcontext* ctx, const char* name, const char* filename);
564
565// fontIndex specifies which font face to load from a .ttf/.ttc file.
566int nvgCreateFontAtIndex(NVGcontext* ctx, const char* name, const char* filename, const int fontIndex);
567
568// Creates font by loading it from the specified memory chunk.
569// Returns handle to the font.
570int nvgCreateFontMem(NVGcontext* ctx, const char* name, unsigned char* data, int ndata, int freeData);
571
572// fontIndex specifies which font face to load from a .ttf/.ttc file.
573int nvgCreateFontMemAtIndex(NVGcontext* ctx, const char* name, unsigned char* data, int ndata, int freeData, const int fontIndex);
574
575// Finds a loaded font of specified name, and returns handle to it, or -1 if the font is not found.
576int nvgFindFont(NVGcontext* ctx, const char* name);
577
578// Adds a fallback font by handle.
579int nvgAddFallbackFontId(NVGcontext* ctx, int baseFont, int fallbackFont);
580
581// Adds a fallback font by name.
582int nvgAddFallbackFont(NVGcontext* ctx, const char* baseFont, const char* fallbackFont);
583
584// Resets fallback fonts by handle.
585void nvgResetFallbackFontsId(NVGcontext* ctx, int baseFont);
586
587// Resets fallback fonts by name.
588void nvgResetFallbackFonts(NVGcontext* ctx, const char* baseFont);
589
590// Sets the font size of current text style.
591void nvgFontSize(NVGcontext* ctx, float size);
592
593// Sets the blur of current text style.
594void nvgFontBlur(NVGcontext* ctx, float blur);
595
596// Sets the letter spacing of current text style.
597void nvgTextLetterSpacing(NVGcontext* ctx, float spacing);
598
599// Sets the proportional line height of current text style. The line height is specified as multiple of font size.
600void nvgTextLineHeight(NVGcontext* ctx, float lineHeight);
601
602// Sets the text align of current text style, see NVGalign for options.
603void nvgTextAlign(NVGcontext* ctx, int align);
604
605// Sets the font face based on specified id of current text style.
606void nvgFontFaceId(NVGcontext* ctx, int font);
607
608// Sets the font face based on specified name of current text style.
609void nvgFontFace(NVGcontext* ctx, const char* font);
610
611// Draws text string at specified location. If end is specified only the sub-string up to the end is drawn.
612float nvgText(NVGcontext* ctx, float x, float y, const char* string, const char* end);
613
614// 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.
615// White space is stripped at the beginning of the rows, the text is split at word boundaries or when new-line characters are encountered.
616// Words longer than the max width are slit at nearest character (i.e. no hyphenation).
617void nvgTextBox(NVGcontext* ctx, float x, float y, float breakRowWidth, const char* string, const char* end);
618
619// Measures the specified text string. Parameter bounds should be a pointer to float[4],
620// if the bounding box of the text should be returned. The bounds value are [xmin,ymin, xmax,ymax]
621// Returns the horizontal advance of the measured text (i.e. where the next character should drawn).
622// Measured values are returned in local coordinate space.
623float nvgTextBounds(NVGcontext* ctx, float x, float y, const char* string, const char* end, float* bounds);
624
625// Measures the specified multi-text string. Parameter bounds should be a pointer to float[4],
626// if the bounding box of the text should be returned. The bounds value are [xmin,ymin, xmax,ymax]
627// Measured values are returned in local coordinate space.
628void nvgTextBoxBounds(NVGcontext* ctx, float x, float y, float breakRowWidth, const char* string, const char* end, float* bounds);
629
630// Calculates the glyph x positions of the specified text. If end is specified only the sub-string will be used.
631// Measured values are returned in local coordinate space.
632int nvgTextGlyphPositions(NVGcontext* ctx, float x, float y, const char* string, const char* end, NVGglyphPosition* positions, int maxPositions);
633
634// Returns the vertical metrics based on the current text style.
635// Measured values are returned in local coordinate space.
636void nvgTextMetrics(NVGcontext* ctx, float* ascender, float* descender, float* lineh);
637
638// Breaks the specified text into lines. If end is specified only the sub-string will be used.
639// White space is stripped at the beginning of the rows, the text is split at word boundaries or when new-line characters are encountered.
640// Words longer than the max width are slit at nearest character (i.e. no hyphenation).
641int nvgTextBreakLines(NVGcontext* ctx, const char* string, const char* end, float breakRowWidth, NVGtextRow* rows, int maxRows);
642
643//
644// Internal Render API
645//
647 float xform[6];
648 float extent[2];
649};
650typedef struct NVGscissor NVGscissor;
651
652struct NVGvertex {
653 float x,y,u,v;
654};
655typedef struct NVGvertex NVGvertex;
656
669typedef struct NVGpath NVGpath;
670
671struct NVGparams {
672 void* userPtr;
674 int (*renderCreate)(void* uptr, void* otherUptr);
675 int (*renderCreateTexture)(void* uptr, int type, int w, int h, int imageFlags, const unsigned char* data);
676 int (*renderDeleteTexture)(void* uptr, int image);
677 int (*renderUpdateTexture)(void* uptr, int image, int x, int y, int w, int h, const unsigned char* data);
678 int (*renderGetTextureSize)(void* uptr, int image, int* w, int* h);
679 void (*renderViewport)(void* uptr, float width, float height, float devicePixelRatio);
680 void (*renderCancel)(void* uptr);
681 void (*renderFlush)(void* uptr);
682 void (*renderFill)(void* uptr, NVGpaint* paint, NVGcompositeOperationState compositeOperation, NVGscissor* scissor, float fringe, const float* bounds, const NVGpath* paths, int npaths);
683 void (*renderStroke)(void* uptr, NVGpaint* paint, NVGcompositeOperationState compositeOperation, NVGscissor* scissor, float fringe, float strokeWidth, const NVGpath* paths, int npaths);
684 void (*renderTriangles)(void* uptr, NVGpaint* paint, NVGcompositeOperationState compositeOperation, NVGscissor* scissor, const NVGvertex* verts, int nverts, float fringe);
685 void (*renderDelete)(void* uptr);
686};
687typedef struct NVGparams NVGparams;
688
689// Constructor and destructor, called by the render back-end.
692
694
695// Debug function to dump cached path data.
697
698#ifdef _MSC_VER
699#pragma warning(pop)
700#endif
701
702#define NVG_NOTUSED(v) for (;;) { (void)(1 ? (void)0 : ( (void)(v) ) ); break; }
703
704#ifdef __cplusplus
705}
706#endif
707
708#endif // NANOVG_H
uint8_t a
Definition Spc_Cpu.h:141
T limit(T val, T min, T max)
Definition Util.h:78
CAdPlugDatabase::CRecord::RecordType type
Definition adplugdb.cpp:93
* e
Definition inflate.c:1404
UINT_D64 w
Definition inflate.c:942
int * l
Definition inflate.c:1579
int y
Definition inflate.c:1588
unsigned d
Definition inflate.c:940
int g
Definition inflate.c:1573
struct huft * u[BMAX]
Definition inflate.c:1583
unsigned s
Definition inflate.c:1555
unsigned x[BMAX+1]
Definition inflate.c:1586
unsigned f
Definition inflate.c:1572
static char filename[]
Definition features.c:5
static const char * name
Definition pugl.h:1582
static int int height
Definition pugl.h:1594
static int width
Definition pugl.h:1593
JSAMPIMAGE data
Definition jpeglib.h:945
void nvgRoundedRect(NVGcontext *ctx, float x, float y, float w, float h, float r)
Definition nanovg.c:2217
void nvgRotate(NVGcontext *ctx, float angle)
Definition nanovg.c:790
NVGimageFlags
Definition nanovg.h:138
@ NVG_IMAGE_REPEATX
Definition nanovg.h:140
@ NVG_IMAGE_NEAREST
Definition nanovg.h:144
@ NVG_IMAGE_PREMULTIPLIED
Definition nanovg.h:143
@ NVG_IMAGE_REPEATY
Definition nanovg.h:141
@ NVG_IMAGE_FLIPY
Definition nanovg.h:142
@ NVG_IMAGE_GENERATE_MIPMAPS
Definition nanovg.h:139
NVGcolor nvgTransRGBA(NVGcolor c0, unsigned char a)
Definition nanovg.c:491
void nvgTextBox(NVGcontext *ctx, float x, float y, float breakRowWidth, const char *string, const char *end)
Definition nanovg.c:2612
void nvgTint(NVGcontext *ctx, NVGcolor tint)
Definition nanovg.c:761
NVGpaint nvgRadialGradient(NVGcontext *ctx, float cx, float cy, float inr, float outr, NVGcolor icol, NVGcolor ocol)
Definition nanovg.c:952
void nvgBeginFrame(NVGcontext *ctx, float windowWidth, float windowHeight, float devicePixelRatio)
Definition nanovg.c:404
int nvgCreateImageRGBA(NVGcontext *ctx, int w, int h, int imageFlags, const unsigned char *data)
Definition nanovg.c:891
int nvgCreateFontAtIndex(NVGcontext *ctx, const char *name, const char *filename, const int fontIndex)
Definition nanovg.c:2370
void nvgAlpha(NVGcontext *ctx, float alpha)
Definition nanovg.c:755
void nvgArcTo(NVGcontext *ctx, float x1, float y1, float x2, float y2, float radius)
Definition nanovg.c:2072
void nvgShapeAntiAlias(NVGcontext *ctx, int enabled)
Definition nanovg.c:707
void nvgGlobalCompositeOperation(NVGcontext *ctx, int op)
Definition nanovg.c:1096
int nvgCreateFont(NVGcontext *ctx, const char *name, const char *filename)
Definition nanovg.c:2365
void nvgEllipse(NVGcontext *ctx, float cx, float cy, float rx, float ry)
Definition nanovg.c:2250
void nvgGlobalAlpha(NVGcontext *ctx, float alpha)
Definition nanovg.c:737
float nvgTextBounds(NVGcontext *ctx, float x, float y, const char *string, const char *end, float *bounds)
Definition nanovg.c:2901
void nvgScissor(NVGcontext *ctx, float x, float y, float w, float h)
Definition nanovg.c:1028
void nvgQuadTo(NVGcontext *ctx, float cx, float cy, float x, float y)
Definition nanovg.c:2061
void nvgGlobalCompositeBlendFuncSeparate(NVGcontext *ctx, int srcRGB, int dstRGB, int srcAlpha, int dstAlpha)
Definition nanovg.c:1107
int nvgFindFont(NVGcontext *ctx, const char *name)
Definition nanovg.c:2385
void nvgResetFallbackFonts(NVGcontext *ctx, const char *baseFont)
Definition nanovg.c:2408
NVGpaint nvgLinearGradient(NVGcontext *ctx, float sx, float sy, float ex, float ey, NVGcolor icol, NVGcolor ocol)
Definition nanovg.c:913
NVGcolor nvgRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
Definition nanovg.c:469
void nvgResetScissor(NVGcontext *ctx)
Definition nanovg.c:1087
NVGcolor nvgRGBAf(float r, float g, float b, float a)
Definition nanovg.c:480
int nvgTextGlyphPositions(NVGcontext *ctx, float x, float y, const char *string, const char *end, NVGglyphPosition *positions, int maxPositions)
Definition nanovg.c:2645
void nvgTransformRotate(float *dst, float a)
Definition nanovg.c:575
void nvgCurrentTransform(NVGcontext *ctx, float *xform)
Definition nanovg.c:822
NVGcontext * nvgCreateInternal(NVGparams *params, NVGcontext *other)
Definition nanovg.c:305
void nvgTransformPremultiply(float *dst, const float *src)
Definition nanovg.c:610
void nvgTransformScale(float *dst, float sx, float sy)
Definition nanovg.c:568
int nvgCreateImage(NVGcontext *ctx, const char *filename, int imageFlags)
Definition nanovg.c:856
void nvgMiterLimit(NVGcontext *ctx, float limit)
Definition nanovg.c:719
float nvgText(NVGcontext *ctx, float x, float y, const char *string, const char *end)
Definition nanovg.c:2538
int nvgCreateFontMem(NVGcontext *ctx, const char *name, unsigned char *data, int ndata, int freeData)
Definition nanovg.c:2375
NVGalign
Definition nanovg.h:74
@ NVG_ALIGN_MIDDLE
Definition nanovg.h:81
@ NVG_ALIGN_CENTER
Definition nanovg.h:77
@ NVG_ALIGN_LEFT
Definition nanovg.h:76
@ NVG_ALIGN_BOTTOM
Definition nanovg.h:82
@ NVG_ALIGN_BASELINE
Definition nanovg.h:83
@ NVG_ALIGN_TOP
Definition nanovg.h:80
@ NVG_ALIGN_RIGHT
Definition nanovg.h:78
void nvgRect(NVGcontext *ctx, float x, float y, float w, float h)
Definition nanovg.c:2205
void nvgImageSize(NVGcontext *ctx, int image, int *w, int *h)
Definition nanovg.c:903
void nvgBeginPath(NVGcontext *ctx)
Definition nanovg.c:2037
void nvgFill(NVGcontext *ctx)
Definition nanovg.c:2290
void nvgTransformSkewX(float *dst, float a)
Definition nanovg.c:583
NVGcolor nvgRGB(unsigned char r, unsigned char g, unsigned char b)
Definition nanovg.c:459
int nvgAddFallbackFontId(NVGcontext *ctx, int baseFont, int fallbackFont)
Definition nanovg.c:2392
void nvgTransformIdentity(float *dst)
Definition nanovg.c:554
void nvgFontSize(NVGcontext *ctx, float size)
Definition nanovg.c:2414
int nvgTransformInverse(float *dst, const float *src)
Definition nanovg.c:618
int nvgCreateImageRaw(NVGcontext *ctx, int w, int h, int imageFlags, enum NVGtexture format, const unsigned char *data)
Definition nanovg.c:886
void nvgClosePath(NVGcontext *ctx)
Definition nanovg.c:2128
void nvgCircle(NVGcontext *ctx, float cx, float cy, float r)
Definition nanovg.c:2263
void nvgTextAlign(NVGcontext *ctx, int align)
Definition nanovg.c:2438
NVGcompositeOperation
Definition nanovg.h:100
@ NVG_ATOP
Definition nanovg.h:104
@ NVG_SOURCE_OVER
Definition nanovg.h:101
@ NVG_SOURCE_IN
Definition nanovg.h:102
@ NVG_DESTINATION_ATOP
Definition nanovg.h:108
@ NVG_DESTINATION_IN
Definition nanovg.h:106
@ NVG_SOURCE_OUT
Definition nanovg.h:103
@ NVG_XOR
Definition nanovg.h:111
@ NVG_DESTINATION_OVER
Definition nanovg.h:105
@ NVG_LIGHTER
Definition nanovg.h:109
@ NVG_COPY
Definition nanovg.h:110
@ NVG_DESTINATION_OUT
Definition nanovg.h:107
void nvgPathWinding(NVGcontext *ctx, int dir)
Definition nanovg.c:2134
void nvgStrokeWidth(NVGcontext *ctx, float size)
Definition nanovg.c:713
void nvgTextLineHeight(NVGcontext *ctx, float lineHeight)
Definition nanovg.c:2432
int nvgTextBreakLines(NVGcontext *ctx, const char *string, const char *end, float breakRowWidth, NVGtextRow *rows, int maxRows)
Definition nanovg.c:2695
void nvgSkewY(NVGcontext *ctx, float angle)
Definition nanovg.c:806
void nvgEndFrame(NVGcontext *ctx)
Definition nanovg.c:429
NVGcolor nvgRGBf(float r, float g, float b)
Definition nanovg.c:464
void nvgLineTo(NVGcontext *ctx, float x, float y)
Definition nanovg.c:2049
void nvgFontFaceId(NVGcontext *ctx, int font)
Definition nanovg.c:2444
void nvgTextLetterSpacing(NVGcontext *ctx, float spacing)
Definition nanovg.c:2426
NVGpaint nvgImagePattern(NVGcontext *ctx, float ox, float oy, float ex, float ey, float angle, int image, float alpha)
Definition nanovg.c:1005
void nvgDeleteImage(NVGcontext *ctx, int image)
Definition nanovg.c:908
NVGsolidity
Definition nanovg.h:61
@ NVG_SOLID
Definition nanovg.h:62
@ NVG_HOLE
Definition nanovg.h:63
void nvgBezierTo(NVGcontext *ctx, float c1x, float c1y, float c2x, float c2y, float x, float y)
Definition nanovg.c:2055
int nvgAddFallbackFont(NVGcontext *ctx, const char *baseFont, const char *fallbackFont)
Definition nanovg.c:2398
void nvgTextBoxBounds(NVGcontext *ctx, float x, float y, float breakRowWidth, const char *string, const char *end, float *bounds)
Definition nanovg.c:2928
void nvgLineJoin(NVGcontext *ctx, int join)
Definition nanovg.c:731
void nvgTransformPoint(float *dstx, float *dsty, const float *xform, float srcx, float srcy)
Definition nanovg.c:635
void nvgStrokePaint(NVGcontext *ctx, NVGpaint paint)
Definition nanovg.c:835
void nvgTranslate(NVGcontext *ctx, float x, float y)
Definition nanovg.c:782
float nvgDegToRad(float deg)
Definition nanovg.c:641
int nvgCreateImageMem(NVGcontext *ctx, int imageFlags, unsigned char *data, int ndata)
Definition nanovg.c:872
int nvgCreateFontMemAtIndex(NVGcontext *ctx, const char *name, unsigned char *data, int ndata, int freeData, const int fontIndex)
Definition nanovg.c:2380
float nvgRadToDeg(float rad)
Definition nanovg.c:646
NVGcolor nvgTransRGBAf(NVGcolor c0, float a)
Definition nanovg.c:497
void nvgDeleteInternal(NVGcontext *ctx)
Definition nanovg.c:377
void nvgStroke(NVGcontext *ctx)
Definition nanovg.c:2321
NVGblendFactor
Definition nanovg.h:86
@ NVG_ONE_MINUS_SRC_COLOR
Definition nanovg.h:90
@ NVG_SRC_COLOR
Definition nanovg.h:89
@ NVG_SRC_ALPHA
Definition nanovg.h:93
@ NVG_ONE_MINUS_SRC_ALPHA
Definition nanovg.h:94
@ NVG_ONE
Definition nanovg.h:88
@ NVG_SRC_ALPHA_SATURATE
Definition nanovg.h:97
@ NVG_ZERO
Definition nanovg.h:87
@ NVG_DST_ALPHA
Definition nanovg.h:95
@ NVG_ONE_MINUS_DST_COLOR
Definition nanovg.h:92
@ NVG_DST_COLOR
Definition nanovg.h:91
@ NVG_ONE_MINUS_DST_ALPHA
Definition nanovg.h:96
void nvgGlobalCompositeBlendFunc(NVGcontext *ctx, int sfactor, int dfactor)
Definition nanovg.c:1102
void nvgIntersectScissor(NVGcontext *ctx, float x, float y, float w, float h)
Definition nanovg.c:1058
void nvgTransform(NVGcontext *ctx, float a, float b, float c, float d, float e, float f)
Definition nanovg.c:769
NVGwinding
Definition nanovg.h:56
@ NVG_CW
Definition nanovg.h:58
@ NVG_CCW
Definition nanovg.h:57
void nvgFontFace(NVGcontext *ctx, const char *font)
Definition nanovg.c:2450
void nvgLineCap(NVGcontext *ctx, int cap)
Definition nanovg.c:725
void nvgScale(NVGcontext *ctx, float x, float y)
Definition nanovg.c:814
void nvgTransformMultiply(float *dst, const float *src)
Definition nanovg.c:597
void nvgStrokeColor(NVGcontext *ctx, NVGcolor color)
Definition nanovg.c:829
void nvgGlobalTint(NVGcontext *ctx, NVGcolor tint)
Definition nanovg.c:743
void nvgRoundedRectVarying(NVGcontext *ctx, float x, float y, float w, float h, float radTopLeft, float radTopRight, float radBottomRight, float radBottomLeft)
Definition nanovg.c:2222
void nvgCancelFrame(NVGcontext *ctx)
Definition nanovg.c:424
NVGparams * nvgInternalParams(NVGcontext *ctx)
Definition nanovg.c:372
NVGcolor nvgLerpRGBA(NVGcolor c0, NVGcolor c1, float u)
Definition nanovg.c:503
void nvgUpdateImage(NVGcontext *ctx, int image, const unsigned char *data)
Definition nanovg.c:896
void nvgSkewX(NVGcontext *ctx, float angle)
Definition nanovg.c:798
void nvgFontBlur(NVGcontext *ctx, float blur)
Definition nanovg.c:2420
void nvgMoveTo(NVGcontext *ctx, float x, float y)
Definition nanovg.c:2043
void nvgTextMetrics(NVGcontext *ctx, float *ascender, float *descender, float *lineh)
Definition nanovg.c:2997
NVGcolor nvgGetGlobalTint(NVGcontext *ctx)
Definition nanovg.c:749
NVGpaint nvgBoxGradient(NVGcontext *ctx, float x, float y, float w, float h, float r, float f, NVGcolor icol, NVGcolor ocol)
Definition nanovg.c:979
void nvgArc(NVGcontext *ctx, float cx, float cy, float r, float a0, float a1, int dir)
Definition nanovg.c:2140
NVGcolor nvgHSLA(float h, float s, float l, unsigned char a)
Definition nanovg.c:537
void nvgReset(NVGcontext *ctx)
Definition nanovg.c:679
void nvgResetFallbackFontsId(NVGcontext *ctx, int baseFont)
Definition nanovg.c:2403
NVGlineCap
Definition nanovg.h:66
@ NVG_SQUARE
Definition nanovg.h:69
@ NVG_BUTT
Definition nanovg.h:67
@ NVG_MITER
Definition nanovg.h:71
@ NVG_BEVEL
Definition nanovg.h:70
@ NVG_ROUND
Definition nanovg.h:68
void nvgSave(NVGcontext *ctx)
Definition nanovg.c:663
NVGcolor nvgHSL(float h, float s, float l)
Definition nanovg.c:519
void nvgFillPaint(NVGcontext *ctx, NVGpaint paint)
Definition nanovg.c:848
void nvgResetTransform(NVGcontext *ctx)
Definition nanovg.c:776
void nvgRestore(NVGcontext *ctx)
Definition nanovg.c:672
void nvgTransformSkewY(float *dst, float a)
Definition nanovg.c:590
NVGtexture
Definition nanovg.h:147
@ NVG_TEXTURE_BGR
Definition nanovg.h:149
@ NVG_TEXTURE_RGB
Definition nanovg.h:151
@ NVG_TEXTURE_ALPHA
Definition nanovg.h:148
@ NVG_TEXTURE_RGBA
Definition nanovg.h:152
@ NVG_TEXTURE_BGRA
Definition nanovg.h:150
void nvgFillColor(NVGcontext *ctx, NVGcolor color)
Definition nanovg.c:842
void nvgDebugDumpPathCache(NVGcontext *ctx)
Definition nanovg.c:2268
void nvgTransformTranslate(float *dst, float tx, float ty)
Definition nanovg.c:561
Definition nanovg.h:35
float g
Definition nanovg.h:39
float a
Definition nanovg.h:39
float r
Definition nanovg.h:39
float b
Definition nanovg.h:39
float rgba[4]
Definition nanovg.h:37
Definition nanovg.h:114
int srcAlpha
Definition nanovg.h:117
int dstRGB
Definition nanovg.h:116
int srcRGB
Definition nanovg.h:115
int dstAlpha
Definition nanovg.h:118
Definition nanovg.c:133
Definition nanovg.h:122
float minx
Definition nanovg.h:125
float x
Definition nanovg.h:124
const char * str
Definition nanovg.h:123
float maxx
Definition nanovg.h:125
Definition nanovg.h:45
float xform[6]
Definition nanovg.h:46
float radius
Definition nanovg.h:48
NVGcolor innerColor
Definition nanovg.h:50
int image
Definition nanovg.h:52
float feather
Definition nanovg.h:49
float extent[2]
Definition nanovg.h:47
NVGcolor outerColor
Definition nanovg.h:51
Definition nanovg.h:671
int(* renderUpdateTexture)(void *uptr, int image, int x, int y, int w, int h, const unsigned char *data)
Definition nanovg.h:677
int(* renderGetTextureSize)(void *uptr, int image, int *w, int *h)
Definition nanovg.h:678
int edgeAntiAlias
Definition nanovg.h:673
void(* renderFlush)(void *uptr)
Definition nanovg.h:681
int(* renderCreate)(void *uptr, void *otherUptr)
Definition nanovg.h:674
int(* renderCreateTexture)(void *uptr, int type, int w, int h, int imageFlags, const unsigned char *data)
Definition nanovg.h:675
void * userPtr
Definition nanovg.h:672
void(* renderTriangles)(void *uptr, NVGpaint *paint, NVGcompositeOperationState compositeOperation, NVGscissor *scissor, const NVGvertex *verts, int nverts, float fringe)
Definition nanovg.h:684
void(* renderDelete)(void *uptr)
Definition nanovg.h:685
void(* renderStroke)(void *uptr, NVGpaint *paint, NVGcompositeOperationState compositeOperation, NVGscissor *scissor, float fringe, float strokeWidth, const NVGpath *paths, int npaths)
Definition nanovg.h:683
int(* renderDeleteTexture)(void *uptr, int image)
Definition nanovg.h:676
void(* renderFill)(void *uptr, NVGpaint *paint, NVGcompositeOperationState compositeOperation, NVGscissor *scissor, float fringe, const float *bounds, const NVGpath *paths, int npaths)
Definition nanovg.h:682
void(* renderCancel)(void *uptr)
Definition nanovg.h:680
void(* renderViewport)(void *uptr, float width, float height, float devicePixelRatio)
Definition nanovg.h:679
Definition nanovg.h:657
int nfill
Definition nanovg.h:663
NVGvertex * stroke
Definition nanovg.h:664
int count
Definition nanovg.h:659
int first
Definition nanovg.h:658
int convex
Definition nanovg.h:667
unsigned char closed
Definition nanovg.h:660
NVGvertex * fill
Definition nanovg.h:662
int nstroke
Definition nanovg.h:665
int nbevel
Definition nanovg.h:661
int winding
Definition nanovg.h:666
Definition nanovg.h:646
float xform[6]
Definition nanovg.h:647
float extent[2]
Definition nanovg.h:648
Definition nanovg.h:129
float maxx
Definition nanovg.h:134
const char * end
Definition nanovg.h:131
const char * next
Definition nanovg.h:132
float width
Definition nanovg.h:133
float minx
Definition nanovg.h:134
const char * start
Definition nanovg.h:130
Definition nanovg.h:652
float u
Definition nanovg.h:653
float y
Definition nanovg.h:653
float v
Definition nanovg.h:653
float x
Definition nanovg.h:653
return c
Definition crypt.c:175
int r
Definition crypt.c:458
uch h[RAND_HEAD_LEN]
Definition crypt.c:459
b
Definition crypt.c:628
ulg size
Definition extract.c:2350
typedef int(UZ_EXP MsgFn)()
#define void
Definition unzip.h:396
_WDL_CSTRING_PREFIX void INT_PTR const char * format
Definition wdlcstring.h:263