You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

621 lines
25KB

  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. #ifndef NANOVG_H
  19. #define NANOVG_H
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. #define NVG_PI 3.14159265358979323846264338327f
  24. #ifdef _MSC_VER
  25. #pragma warning(push)
  26. #pragma warning(disable: 4201) // nonstandard extension used : nameless struct/union
  27. #endif
  28. typedef struct NVGcontext NVGcontext;
  29. struct NVGcolor {
  30. union {
  31. float rgba[4];
  32. struct {
  33. float r,g,b,a;
  34. };
  35. };
  36. };
  37. typedef struct NVGcolor NVGcolor;
  38. struct NVGpaint {
  39. float xform[6];
  40. float extent[2];
  41. float radius;
  42. float feather;
  43. NVGcolor innerColor;
  44. NVGcolor outerColor;
  45. int image;
  46. };
  47. typedef struct NVGpaint NVGpaint;
  48. enum NVGwinding {
  49. NVG_CCW = 1, // Winding for solid shapes
  50. NVG_CW = 2, // Winding for holes
  51. };
  52. enum NVGsolidity {
  53. NVG_SOLID = 1, // CCW
  54. NVG_HOLE = 2, // CW
  55. };
  56. enum NVGlineCap {
  57. NVG_BUTT,
  58. NVG_ROUND,
  59. NVG_SQUARE,
  60. NVG_BEVEL,
  61. NVG_MITER,
  62. };
  63. enum NVGalign {
  64. // Horizontal align
  65. NVG_ALIGN_LEFT = 1<<0, // Default, align text horizontally to left.
  66. NVG_ALIGN_CENTER = 1<<1, // Align text horizontally to center.
  67. NVG_ALIGN_RIGHT = 1<<2, // Align text horizontally to right.
  68. // Vertical align
  69. NVG_ALIGN_TOP = 1<<3, // Align text vertically to top.
  70. NVG_ALIGN_MIDDLE = 1<<4, // Align text vertically to middle.
  71. NVG_ALIGN_BOTTOM = 1<<5, // Align text vertically to bottom.
  72. NVG_ALIGN_BASELINE = 1<<6, // Default, align text vertically to baseline.
  73. };
  74. struct NVGglyphPosition {
  75. const char* str; // Position of the glyph in the input string.
  76. float x; // The x-coordinate of the logical glyph position.
  77. float minx, maxx; // The bounds of the glyph shape.
  78. };
  79. typedef struct NVGglyphPosition NVGglyphPosition;
  80. struct NVGtextRow {
  81. const char* start; // Pointer to the input text where the row starts.
  82. const char* end; // Pointer to the input text where the row ends (one past the last character).
  83. const char* next; // Pointer to the beginning of the next row.
  84. float width; // Logical width of the row.
  85. float minx, maxx; // Actual bounds of the row. Logical with and bounds can differ because of kerning and some parts over extending.
  86. };
  87. typedef struct NVGtextRow NVGtextRow;
  88. enum NVGimageFlags {
  89. NVG_IMAGE_GENERATE_MIPMAPS = 1<<0, // Generate mipmaps during creation of the image.
  90. NVG_IMAGE_REPEATX = 1<<1, // Repeat image in X direction.
  91. NVG_IMAGE_REPEATY = 1<<2, // Repeat image in Y direction.
  92. NVG_IMAGE_FLIPY = 1<<3, // Flips (inverses) image in Y direction when rendered.
  93. NVG_IMAGE_PREMULTIPLIED = 1<<4, // Image data has premultiplied alpha.
  94. };
  95. // Begin drawing a new frame
  96. // Calls to nanovg drawing API should be wrapped in nvgBeginFrame() & nvgEndFrame()
  97. // nvgBeginFrame() defines the size of the window to render to in relation currently
  98. // set viewport (i.e. glViewport on GL backends). Device pixel ration allows to
  99. // control the rendering on Hi-DPI devices.
  100. // For example, GLFW returns two dimension for an opened window: window size and
  101. // frame buffer size. In that case you would set windowWidth/Height to the window size
  102. // devicePixelRatio to: frameBufferWidth / windowWidth.
  103. void nvgBeginFrame(NVGcontext* ctx, int windowWidth, int windowHeight, float devicePixelRatio);
  104. // Cancels drawing the current frame.
  105. void nvgCancelFrame(NVGcontext* ctx);
  106. // Ends drawing flushing remaining render state.
  107. void nvgEndFrame(NVGcontext* ctx);
  108. //
  109. // Color utils
  110. //
  111. // Colors in NanoVG are stored as unsigned ints in ABGR format.
  112. // Returns a color value from red, green, blue values. Alpha will be set to 255 (1.0f).
  113. NVGcolor nvgRGB(unsigned char r, unsigned char g, unsigned char b);
  114. // Returns a color value from red, green, blue values. Alpha will be set to 1.0f.
  115. NVGcolor nvgRGBf(float r, float g, float b);
  116. // Returns a color value from red, green, blue and alpha values.
  117. NVGcolor nvgRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
  118. // Returns a color value from red, green, blue and alpha values.
  119. NVGcolor nvgRGBAf(float r, float g, float b, float a);
  120. // Linearly interpolates from color c0 to c1, and returns resulting color value.
  121. NVGcolor nvgLerpRGBA(NVGcolor c0, NVGcolor c1, float u);
  122. // Sets transparency of a color value.
  123. NVGcolor nvgTransRGBA(NVGcolor c0, unsigned char a);
  124. // Sets transparency of a color value.
  125. NVGcolor nvgTransRGBAf(NVGcolor c0, float a);
  126. // Returns color value specified by hue, saturation and lightness.
  127. // HSL values are all in range [0..1], alpha will be set to 255.
  128. NVGcolor nvgHSL(float h, float s, float l);
  129. // Returns color value specified by hue, saturation and lightness and alpha.
  130. // HSL values are all in range [0..1], alpha in range [0..255]
  131. NVGcolor nvgHSLA(float h, float s, float l, unsigned char a);
  132. //
  133. // State Handling
  134. //
  135. // NanoVG contains state which represents how paths will be rendered.
  136. // The state contains transform, fill and stroke styles, text and font styles,
  137. // and scissor clipping.
  138. // Pushes and saves the current render state into a state stack.
  139. // A matching nvgRestore() must be used to restore the state.
  140. void nvgSave(NVGcontext* ctx);
  141. // Pops and restores current render state.
  142. void nvgRestore(NVGcontext* ctx);
  143. // Resets current render state to default values. Does not affect the render state stack.
  144. void nvgReset(NVGcontext* ctx);
  145. //
  146. // Render styles
  147. //
  148. // Fill and stroke render style can be either a solid color or a paint which is a gradient or a pattern.
  149. // Solid color is simply defined as a color value, different kinds of paints can be created
  150. // using nvgLinearGradient(), nvgBoxGradient(), nvgRadialGradient() and nvgImagePattern().
  151. //
  152. // Current render style can be saved and restored using nvgSave() and nvgRestore().
  153. // Sets current stroke style to a solid color.
  154. void nvgStrokeColor(NVGcontext* ctx, NVGcolor color);
  155. // Sets current stroke style to a paint, which can be a one of the gradients or a pattern.
  156. void nvgStrokePaint(NVGcontext* ctx, NVGpaint paint);
  157. // Sets current fill style to a solid color.
  158. void nvgFillColor(NVGcontext* ctx, NVGcolor color);
  159. // Sets current fill style to a paint, which can be a one of the gradients or a pattern.
  160. void nvgFillPaint(NVGcontext* ctx, NVGpaint paint);
  161. // Sets the miter limit of the stroke style.
  162. // Miter limit controls when a sharp corner is beveled.
  163. void nvgMiterLimit(NVGcontext* ctx, float limit);
  164. // Sets the stroke width of the stroke style.
  165. void nvgStrokeWidth(NVGcontext* ctx, float size);
  166. // Sets how the end of the line (cap) is drawn,
  167. // Can be one of: NVG_BUTT (default), NVG_ROUND, NVG_SQUARE.
  168. void nvgLineCap(NVGcontext* ctx, int cap);
  169. // Sets how sharp path corners are drawn.
  170. // Can be one of NVG_MITER (default), NVG_ROUND, NVG_BEVEL.
  171. void nvgLineJoin(NVGcontext* ctx, int join);
  172. // Sets the transparency applied to all rendered shapes.
  173. // Already transparent paths will get proportionally more transparent as well.
  174. void nvgGlobalAlpha(NVGcontext* ctx, float alpha);
  175. //
  176. // Transforms
  177. //
  178. // The paths, gradients, patterns and scissor region are transformed by an transformation
  179. // matrix at the time when they are passed to the API.
  180. // The current transformation matrix is a affine matrix:
  181. // [sx kx tx]
  182. // [ky sy ty]
  183. // [ 0 0 1]
  184. // Where: sx,sy define scaling, kx,ky skewing, and tx,ty translation.
  185. // The last row is assumed to be 0,0,1 and is not stored.
  186. //
  187. // Apart from nvgResetTransform(), each transformation function first creates
  188. // specific transformation matrix and pre-multiplies the current transformation by it.
  189. //
  190. // Current coordinate system (transformation) can be saved and restored using nvgSave() and nvgRestore().
  191. // Resets current transform to a identity matrix.
  192. void nvgResetTransform(NVGcontext* ctx);
  193. // Premultiplies current coordinate system by specified matrix.
  194. // The parameters are interpreted as matrix as follows:
  195. // [a c e]
  196. // [b d f]
  197. // [0 0 1]
  198. void nvgTransform(NVGcontext* ctx, float a, float b, float c, float d, float e, float f);
  199. // Translates current coordinate system.
  200. void nvgTranslate(NVGcontext* ctx, float x, float y);
  201. // Rotates current coordinate system. Angle is specified in radians.
  202. void nvgRotate(NVGcontext* ctx, float angle);
  203. // Skews the current coordinate system along X axis. Angle is specified in radians.
  204. void nvgSkewX(NVGcontext* ctx, float angle);
  205. // Skews the current coordinate system along Y axis. Angle is specified in radians.
  206. void nvgSkewY(NVGcontext* ctx, float angle);
  207. // Scales the current coordinate system.
  208. void nvgScale(NVGcontext* ctx, float x, float y);
  209. // Stores the top part (a-f) of the current transformation matrix in to the specified buffer.
  210. // [a c e]
  211. // [b d f]
  212. // [0 0 1]
  213. // There should be space for 6 floats in the return buffer for the values a-f.
  214. void nvgCurrentTransform(NVGcontext* ctx, float* xform);
  215. // The following functions can be used to make calculations on 2x3 transformation matrices.
  216. // A 2x3 matrix is represented as float[6].
  217. // Sets the transform to identity matrix.
  218. void nvgTransformIdentity(float* dst);
  219. // Sets the transform to translation matrix matrix.
  220. void nvgTransformTranslate(float* dst, float tx, float ty);
  221. // Sets the transform to scale matrix.
  222. void nvgTransformScale(float* dst, float sx, float sy);
  223. // Sets the transform to rotate matrix. Angle is specified in radians.
  224. void nvgTransformRotate(float* dst, float a);
  225. // Sets the transform to skew-x matrix. Angle is specified in radians.
  226. void nvgTransformSkewX(float* dst, float a);
  227. // Sets the transform to skew-y matrix. Angle is specified in radians.
  228. void nvgTransformSkewY(float* dst, float a);
  229. // Sets the transform to the result of multiplication of two transforms, of A = A*B.
  230. void nvgTransformMultiply(float* dst, const float* src);
  231. // Sets the transform to the result of multiplication of two transforms, of A = B*A.
  232. void nvgTransformPremultiply(float* dst, const float* src);
  233. // Sets the destination to inverse of specified transform.
  234. // Returns 1 if the inverse could be calculated, else 0.
  235. int nvgTransformInverse(float* dst, const float* src);
  236. // Transform a point by given transform.
  237. void nvgTransformPoint(float* dstx, float* dsty, const float* xform, float srcx, float srcy);
  238. // Converts degrees to radians and vice versa.
  239. float nvgDegToRad(float deg);
  240. float nvgRadToDeg(float rad);
  241. //
  242. // Images
  243. //
  244. // NanoVG allows you to load jpg, png, psd, tga, pic and gif files to be used for rendering.
  245. // In addition you can upload your own image. The image loading is provided by stb_image.
  246. // The parameter imageFlags is combination of flags defined in NVGimageFlags.
  247. // Creates image by loading it from the disk from specified file name.
  248. // Returns handle to the image.
  249. int nvgCreateImage(NVGcontext* ctx, const char* filename, int imageFlags);
  250. // Creates image by loading it from the specified chunk of memory.
  251. // Returns handle to the image.
  252. int nvgCreateImageMem(NVGcontext* ctx, int imageFlags, unsigned char* data, int ndata);
  253. // Creates image from specified image data.
  254. // Returns handle to the image.
  255. int nvgCreateImageRGBA(NVGcontext* ctx, int w, int h, int imageFlags, const unsigned char* data);
  256. // Updates image data specified by image handle.
  257. void nvgUpdateImage(NVGcontext* ctx, int image, const unsigned char* data);
  258. // Returns the dimensions of a created image.
  259. void nvgImageSize(NVGcontext* ctx, int image, int* w, int* h);
  260. // Deletes created image.
  261. void nvgDeleteImage(NVGcontext* ctx, int image);
  262. //
  263. // Paints
  264. //
  265. // NanoVG supports four types of paints: linear gradient, box gradient, radial gradient and image pattern.
  266. // These can be used as paints for strokes and fills.
  267. // Creates and returns a linear gradient. Parameters (sx,sy)-(ex,ey) specify the start and end coordinates
  268. // of the linear gradient, icol specifies the start color and ocol the end color.
  269. // The gradient is transformed by the current transform when it is passed to nvgFillPaint() or nvgStrokePaint().
  270. NVGpaint nvgLinearGradient(NVGcontext* ctx, float sx, float sy, float ex, float ey,
  271. NVGcolor icol, NVGcolor ocol);
  272. // Creates and returns a box gradient. Box gradient is a feathered rounded rectangle, it is useful for rendering
  273. // drop shadows or highlights for boxes. Parameters (x,y) define the top-left corner of the rectangle,
  274. // (w,h) define the size of the rectangle, r defines the corner radius, and f feather. Feather defines how blurry
  275. // the border of the rectangle is. Parameter icol specifies the inner color and ocol the outer color of the gradient.
  276. // The gradient is transformed by the current transform when it is passed to nvgFillPaint() or nvgStrokePaint().
  277. NVGpaint nvgBoxGradient(NVGcontext* ctx, float x, float y, float w, float h,
  278. float r, float f, NVGcolor icol, NVGcolor ocol);
  279. // Creates and returns a radial gradient. Parameters (cx,cy) specify the center, inr and outr specify
  280. // the inner and outer radius of the gradient, icol specifies the start color and ocol the end color.
  281. // The gradient is transformed by the current transform when it is passed to nvgFillPaint() or nvgStrokePaint().
  282. NVGpaint nvgRadialGradient(NVGcontext* ctx, float cx, float cy, float inr, float outr,
  283. NVGcolor icol, NVGcolor ocol);
  284. // Creates and returns an image patter. Parameters (ox,oy) specify the left-top location of the image pattern,
  285. // (ex,ey) the size of one image, angle rotation around the top-left corner, image is handle to the image to render.
  286. // The gradient is transformed by the current transform when it is passed to nvgFillPaint() or nvgStrokePaint().
  287. NVGpaint nvgImagePattern(NVGcontext* ctx, float ox, float oy, float ex, float ey,
  288. float angle, int image, float alpha);
  289. //
  290. // Scissoring
  291. //
  292. // Scissoring allows you to clip the rendering into a rectangle. This is useful for various
  293. // user interface cases like rendering a text edit or a timeline.
  294. // Sets the current scissor rectangle.
  295. // The scissor rectangle is transformed by the current transform.
  296. void nvgScissor(NVGcontext* ctx, float x, float y, float w, float h);
  297. // Intersects current scissor rectangle with the specified rectangle.
  298. // The scissor rectangle is transformed by the current transform.
  299. // Note: in case the rotation of previous scissor rect differs from
  300. // the current one, the intersection will be done between the specified
  301. // rectangle and the previous scissor rectangle transformed in the current
  302. // transform space. The resulting shape is always rectangle.
  303. void nvgIntersectScissor(NVGcontext* ctx, float x, float y, float w, float h);
  304. // Reset and disables scissoring.
  305. void nvgResetScissor(NVGcontext* ctx);
  306. //
  307. // Paths
  308. //
  309. // Drawing a new shape starts with nvgBeginPath(), it clears all the currently defined paths.
  310. // Then you define one or more paths and sub-paths which describe the shape. The are functions
  311. // to draw common shapes like rectangles and circles, and lower level step-by-step functions,
  312. // which allow to define a path curve by curve.
  313. //
  314. // NanoVG uses even-odd fill rule to draw the shapes. Solid shapes should have counter clockwise
  315. // winding and holes should have counter clockwise order. To specify winding of a path you can
  316. // call nvgPathWinding(). This is useful especially for the common shapes, which are drawn CCW.
  317. //
  318. // Finally you can fill the path using current fill style by calling nvgFill(), and stroke it
  319. // with current stroke style by calling nvgStroke().
  320. //
  321. // The curve segments and sub-paths are transformed by the current transform.
  322. // Clears the current path and sub-paths.
  323. void nvgBeginPath(NVGcontext* ctx);
  324. // Starts new sub-path with specified point as first point.
  325. void nvgMoveTo(NVGcontext* ctx, float x, float y);
  326. // Adds line segment from the last point in the path to the specified point.
  327. void nvgLineTo(NVGcontext* ctx, float x, float y);
  328. // Adds cubic bezier segment from last point in the path via two control points to the specified point.
  329. void nvgBezierTo(NVGcontext* ctx, float c1x, float c1y, float c2x, float c2y, float x, float y);
  330. // Adds quadratic bezier segment from last point in the path via a control point to the specified point.
  331. void nvgQuadTo(NVGcontext* ctx, float cx, float cy, float x, float y);
  332. // Adds an arc segment at the corner defined by the last path point, and two specified points.
  333. void nvgArcTo(NVGcontext* ctx, float x1, float y1, float x2, float y2, float radius);
  334. // Closes current sub-path with a line segment.
  335. void nvgClosePath(NVGcontext* ctx);
  336. // Sets the current sub-path winding, see NVGwinding and NVGsolidity.
  337. void nvgPathWinding(NVGcontext* ctx, int dir);
  338. // Creates new circle arc shaped sub-path. The arc center is at cx,cy, the arc radius is r,
  339. // and the arc is drawn from angle a0 to a1, and swept in direction dir (NVG_CCW, or NVG_CW).
  340. // Angles are specified in radians.
  341. void nvgArc(NVGcontext* ctx, float cx, float cy, float r, float a0, float a1, int dir);
  342. // Creates new rectangle shaped sub-path.
  343. void nvgRect(NVGcontext* ctx, float x, float y, float w, float h);
  344. // Creates new rounded rectangle shaped sub-path.
  345. void nvgRoundedRect(NVGcontext* ctx, float x, float y, float w, float h, float r);
  346. // Creates new ellipse shaped sub-path.
  347. void nvgEllipse(NVGcontext* ctx, float cx, float cy, float rx, float ry);
  348. // Creates new circle shaped sub-path.
  349. void nvgCircle(NVGcontext* ctx, float cx, float cy, float r);
  350. // Fills the current path with current fill style.
  351. void nvgFill(NVGcontext* ctx);
  352. // Fills the current path with current stroke style.
  353. void nvgStroke(NVGcontext* ctx);
  354. //
  355. // Text
  356. //
  357. // NanoVG allows you to load .ttf files and use the font to render text.
  358. //
  359. // The appearance of the text can be defined by setting the current text style
  360. // and by specifying the fill color. Common text and font settings such as
  361. // font size, letter spacing and text align are supported. Font blur allows you
  362. // to create simple text effects such as drop shadows.
  363. //
  364. // At render time the font face can be set based on the font handles or name.
  365. //
  366. // Font measure functions return values in local space, the calculations are
  367. // carried in the same resolution as the final rendering. This is done because
  368. // the text glyph positions are snapped to the nearest pixels sharp rendering.
  369. //
  370. // The local space means that values are not rotated or scale as per the current
  371. // transformation. For example if you set font size to 12, which would mean that
  372. // line height is 16, then regardless of the current scaling and rotation, the
  373. // returned line height is always 16. Some measures may vary because of the scaling
  374. // since aforementioned pixel snapping.
  375. //
  376. // While this may sound a little odd, the setup allows you to always render the
  377. // same way regardless of scaling. I.e. following works regardless of scaling:
  378. //
  379. // const char* txt = "Text me up.";
  380. // nvgTextBounds(vg, x,y, txt, NULL, bounds);
  381. // nvgBeginPath(vg);
  382. // nvgRoundedRect(vg, bounds[0],bounds[1], bounds[2]-bounds[0], bounds[3]-bounds[1]);
  383. // nvgFill(vg);
  384. //
  385. // Note: currently only solid color fill is supported for text.
  386. // Creates font by loading it from the disk from specified file name.
  387. // Returns handle to the font.
  388. int nvgCreateFont(NVGcontext* ctx, const char* name, const char* filename);
  389. // Creates font by loading it from the specified memory chunk.
  390. // Returns handle to the font.
  391. int nvgCreateFontMem(NVGcontext* ctx, const char* name, unsigned char* data, int ndata, int freeData);
  392. // Finds a loaded font of specified name, and returns handle to it, or -1 if the font is not found.
  393. int nvgFindFont(NVGcontext* ctx, const char* name);
  394. // Sets the font size of current text style.
  395. void nvgFontSize(NVGcontext* ctx, float size);
  396. // Sets the blur of current text style.
  397. void nvgFontBlur(NVGcontext* ctx, float blur);
  398. // Sets the letter spacing of current text style.
  399. void nvgTextLetterSpacing(NVGcontext* ctx, float spacing);
  400. // Sets the proportional line height of current text style. The line height is specified as multiple of font size.
  401. void nvgTextLineHeight(NVGcontext* ctx, float lineHeight);
  402. // Sets the text align of current text style, see NVGalign for options.
  403. void nvgTextAlign(NVGcontext* ctx, int align);
  404. // Sets the font face based on specified id of current text style.
  405. void nvgFontFaceId(NVGcontext* ctx, int font);
  406. // Sets the font face based on specified name of current text style.
  407. void nvgFontFace(NVGcontext* ctx, const char* font);
  408. // Draws text string at specified location. If end is specified only the sub-string up to the end is drawn.
  409. float nvgText(NVGcontext* ctx, float x, float y, const char* string, const char* end);
  410. // 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.
  411. // White space is stripped at the beginning of the rows, the text is split at word boundaries or when new-line characters are encountered.
  412. // Words longer than the max width are slit at nearest character (i.e. no hyphenation).
  413. void nvgTextBox(NVGcontext* ctx, float x, float y, float breakRowWidth, const char* string, const char* end);
  414. // Measures the specified text string. Parameter bounds should be a pointer to float[4],
  415. // if the bounding box of the text should be returned. The bounds value are [xmin,ymin, xmax,ymax]
  416. // Returns the horizontal advance of the measured text (i.e. where the next character should drawn).
  417. // Measured values are returned in local coordinate space.
  418. float nvgTextBounds(NVGcontext* ctx, float x, float y, const char* string, const char* end, float* bounds);
  419. // Measures the specified multi-text string. Parameter bounds should be a pointer to float[4],
  420. // if the bounding box of the text should be returned. The bounds value are [xmin,ymin, xmax,ymax]
  421. // Measured values are returned in local coordinate space.
  422. void nvgTextBoxBounds(NVGcontext* ctx, float x, float y, float breakRowWidth, const char* string, const char* end, float* bounds);
  423. // Calculates the glyph x positions of the specified text. If end is specified only the sub-string will be used.
  424. // Measured values are returned in local coordinate space.
  425. int nvgTextGlyphPositions(NVGcontext* ctx, float x, float y, const char* string, const char* end, NVGglyphPosition* positions, int maxPositions);
  426. // Returns the vertical metrics based on the current text style.
  427. // Measured values are returned in local coordinate space.
  428. void nvgTextMetrics(NVGcontext* ctx, float* ascender, float* descender, float* lineh);
  429. // Breaks the specified text into lines. If end is specified only the sub-string will be used.
  430. // White space is stripped at the beginning of the rows, the text is split at word boundaries or when new-line characters are encountered.
  431. // Words longer than the max width are slit at nearest character (i.e. no hyphenation).
  432. int nvgTextBreakLines(NVGcontext* ctx, const char* string, const char* end, float breakRowWidth, NVGtextRow* rows, int maxRows);
  433. //
  434. // Internal Render API
  435. //
  436. enum NVGtexture {
  437. NVG_TEXTURE_ALPHA = 0x01,
  438. NVG_TEXTURE_RGBA = 0x02,
  439. };
  440. struct NVGscissor {
  441. float xform[6];
  442. float extent[2];
  443. };
  444. typedef struct NVGscissor NVGscissor;
  445. struct NVGvertex {
  446. float x,y,u,v;
  447. };
  448. typedef struct NVGvertex NVGvertex;
  449. struct NVGpath {
  450. int first;
  451. int count;
  452. unsigned char closed;
  453. int nbevel;
  454. NVGvertex* fill;
  455. int nfill;
  456. NVGvertex* stroke;
  457. int nstroke;
  458. int winding;
  459. int convex;
  460. };
  461. typedef struct NVGpath NVGpath;
  462. struct NVGparams {
  463. void* userPtr;
  464. int edgeAntiAlias;
  465. int (*renderCreate)(void* uptr);
  466. int (*renderCreateTexture)(void* uptr, int type, int w, int h, int imageFlags, const unsigned char* data);
  467. int (*renderDeleteTexture)(void* uptr, int image);
  468. int (*renderUpdateTexture)(void* uptr, int image, int x, int y, int w, int h, const unsigned char* data);
  469. int (*renderGetTextureSize)(void* uptr, int image, int* w, int* h);
  470. void (*renderViewport)(void* uptr, int width, int height, float devicePixelRatio);
  471. void (*renderCancel)(void* uptr);
  472. void (*renderFlush)(void* uptr);
  473. void (*renderFill)(void* uptr, NVGpaint* paint, NVGscissor* scissor, float fringe, const float* bounds, const NVGpath* paths, int npaths);
  474. void (*renderStroke)(void* uptr, NVGpaint* paint, NVGscissor* scissor, float fringe, float strokeWidth, const NVGpath* paths, int npaths);
  475. void (*renderTriangles)(void* uptr, NVGpaint* paint, NVGscissor* scissor, const NVGvertex* verts, int nverts);
  476. void (*renderDelete)(void* uptr);
  477. };
  478. typedef struct NVGparams NVGparams;
  479. // Constructor and destructor, called by the render back-end.
  480. NVGcontext* nvgCreateInternal(NVGparams* params);
  481. void nvgDeleteInternal(NVGcontext* ctx);
  482. NVGparams* nvgInternalParams(NVGcontext* ctx);
  483. // Debug function to dump cached path data.
  484. void nvgDebugDumpPathCache(NVGcontext* ctx);
  485. #ifdef _MSC_VER
  486. #pragma warning(pop)
  487. #endif
  488. #define NVG_NOTUSED(v) for (;;) { (void)(1 ? (void)0 : ( (void)(v) ) ); break; }
  489. #ifdef __cplusplus
  490. }
  491. #endif
  492. #endif // NANOVG_H