DISTRHO Plugin Framework
 All Classes Functions Variables Modules Pages
NanoVG.hpp
1 /*
2  * DISTRHO Plugin Framework (DPF)
3  * Copyright (C) 2012-2014 Filipe Coelho <falktx@falktx.com>
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any purpose with
6  * or without fee is hereby granted, provided that the above copyright notice and this
7  * permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
10  * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
11  * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
12  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
13  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #ifndef DGL_NANO_WIDGET_HPP_INCLUDED
18 #define DGL_NANO_WIDGET_HPP_INCLUDED
19 
20 #include "Color.hpp"
21 #include "Widget.hpp"
22 
23 struct NVGcontext;
24 struct NVGpaint;
25 
26 START_NAMESPACE_DGL
27 
28 // -----------------------------------------------------------------------
29 // NanoImage
30 
31 /**
32  NanoVG Image class.
33 
34  This implements NanoVG images as a C++ class where deletion is handled automatically.
35  Images need to be created within a NanoVG or NanoWidget class.
36  */
37 class NanoImage
38 {
39 public:
40  /**
41  Destructor.
42  */
43  ~NanoImage();
44 
45  /**
46  Get size.
47  */
48  Size<uint> getSize() const noexcept;
49 
50  /**
51  Update image data.
52  */
53  void updateImage(const uchar* const data);
54 
55 protected:
56  /**
57  Constructors are protected.
58  NanoImages must be created within a NanoVG or NanoWidget class.
59  */
60  NanoImage(NVGcontext* const context, const int imageId) noexcept;
61 
62 private:
63  NVGcontext* fContext;
64  int fImageId;
65  Size<uint> fSize;
66  friend class NanoVG;
67 
68  void _updateSize();
69 
70  DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(NanoImage)
71 };
72 
73 // -----------------------------------------------------------------------
74 // NanoVG
75 
76 /**
77  NanoVG class.
78 
79  This class exposes the NanoVG drawing API.
80  All calls should be wrapped in beginFrame() and endFrame().
81 
82  @section State Handling
83  NanoVG contains state which represents how paths will be rendered.
84  The state contains transform, fill and stroke styles, text and font styles, and scissor clipping.
85 
86  @section Render styles
87  Fill and stroke render style can be either a solid color or a paint which is a gradient or a pattern.
88  Solid color is simply defined as a color value, different kinds of paints can be created
89  using linearGradient(), boxGradient(), radialGradient() and imagePattern().
90 
91  Current render style can be saved and restored using save() and restore().
92 
93  @section Transforms
94  The paths, gradients, patterns and scissor region are transformed by an transformation
95  matrix at the time when they are passed to the API.
96  The current transformation matrix is a affine matrix:
97  [sx kx tx]
98  [ky sy ty]
99  [ 0 0 1]
100  Where: sx,sy define scaling, kx,ky skewing, and tx,ty translation.
101  The last row is assumed to be 0,0,1 and is not stored.
102 
103  Apart from resetTransform(), each transformation function first creates
104  specific transformation matrix and pre-multiplies the current transformation by it.
105 
106  Current coordinate system (transformation) can be saved and restored using save() and restore().
107 
108  @section Images
109  NanoVG allows you to load jpg, png, psd, tga, pic and gif files to be used for rendering.
110  In addition you can upload your own image. The image loading is provided by stb_image.
111 
112  @section Paints
113  NanoVG supports four types of paints: linear gradient, box gradient, radial gradient and image pattern.
114  These can be used as paints for strokes and fills.
115 
116  @section Scissoring
117  Scissoring allows you to clip the rendering into a rectangle. This is useful for varius
118  user interface cases like rendering a text edit or a timeline.
119 
120  @section Paths
121  Drawing a new shape starts with beginPath(), it clears all the currently defined paths.
122  Then you define one or more paths and sub-paths which describe the shape. The are functions
123  to draw common shapes like rectangles and circles, and lower level step-by-step functions,
124  which allow to define a path curve by curve.
125 
126  NanoVG uses even-odd fill rule to draw the shapes. Solid shapes should have counter clockwise
127  winding and holes should have counter clockwise order. To specify winding of a path you can
128  call pathWinding(). This is useful especially for the common shapes, which are drawn CCW.
129 
130  Finally you can fill the path using current fill style by calling fill(), and stroke it
131  with current stroke style by calling stroke().
132 
133  The curve segments and sub-paths are transformed by the current transform.
134 
135  @section Text
136  NanoVG allows you to load .ttf files and use the font to render text.
137 
138  The appearance of the text can be defined by setting the current text style
139  and by specifying the fill color. Common text and font settings such as
140  font size, letter spacing and text align are supported. Font blur allows you
141  to create simple text effects such as drop shadows.
142 
143  At render time the font face can be set based on the font handles or name.
144 
145  Font measure functions return values in local space, the calculations are
146  carried in the same resolution as the final rendering. This is done because
147  the text glyph positions are snapped to the nearest pixels sharp rendering.
148 
149  The local space means that values are not rotated or scale as per the current
150  transformation. For example if you set font size to 12, which would mean that
151  line height is 16, then regardless of the current scaling and rotation, the
152  returned line height is always 16. Some measures may vary because of the scaling
153  since aforementioned pixel snapping.
154 
155  While this may sound a little odd, the setup allows you to always render the
156  same way regardless of scaling. i.e. following works regardless of scaling:
157 
158  @code
159  const char* txt = "Text me up.";
160  textBounds(vg, x,y, txt, NULL, bounds);
161  beginPath(vg);
162  roundedRect(vg, bounds[0], bounds[1], bounds[2]-bounds[0], bounds[3]-bounds[1]);
163  fill(vg);
164  @endcode
165 
166  Note: currently only solid color fill is supported for text.
167  */
168 class NanoVG
169 {
170 public:
171  enum Align {
172  // Horizontal align
173  ALIGN_LEFT = 1 << 0, // Align horizontally to left (default).
174  ALIGN_CENTER = 1 << 1, // Align horizontally to center.
175  ALIGN_RIGHT = 1 << 2, // Align horizontally to right.
176  // Vertical align
177  ALIGN_TOP = 1 << 3, // Align vertically to top.
178  ALIGN_MIDDLE = 1 << 4, // Align vertically to middle.
179  ALIGN_BOTTOM = 1 << 5, // Align vertically to bottom.
180  ALIGN_BASELINE = 1 << 6 // Align vertically to baseline (default).
181  };
182 
183  enum Alpha {
184  STRAIGHT_ALPHA,
185  PREMULTIPLIED_ALPHA
186  };
187 
188  enum LineCap {
189  BUTT,
190  ROUND,
191  SQUARE,
192  BEVEL,
193  MITER
194  };
195 
196  enum PatternRepeat {
197  REPEAT_NONE = 0x0, // No repeat
198  REPEAT_X = 0x1, // Repeat in X direction
199  REPEAT_Y = 0x2 // Repeat in Y direction
200  };
201 
202  enum Solidity {
203  SOLID = 1, // CCW
204  HOLE = 2 // CW
205  };
206 
207  enum Winding {
208  CCW = 1, // Winding for solid shapes
209  CW = 2 // Winding for holes
210  };
211 
212  struct Paint {
213  float xform[6];
214  float extent[2];
215  float radius;
216  float feather;
217  Color innerColor;
218  Color outerColor;
219  int imageId;
220  PatternRepeat repeat;
221 
222  Paint() noexcept;
223 
224  /**
225  @internal
226  */
227  Paint(const NVGpaint&) noexcept;
228  operator NVGpaint() const noexcept;
229  };
230 
231  struct GlyphPosition {
232  const char* str; // Position of the glyph in the input string.
233  float x; // The x-coordinate of the logical glyph position.
234  float minx, maxx; // The bounds of the glyph shape.
235  };
236 
237  struct TextRow {
238  const char* start; // Pointer to the input text where the row starts.
239  const char* end; // Pointer to the input text where the row ends (one past the last character).
240  const char* next; // Pointer to the beginning of the next row.
241  float width; // Logical width of the row.
242  float minx, maxx; // Actual bounds of the row. Logical with and bounds can differ because of kerning and some parts over extending.
243  };
244 
245  typedef int FontId;
246 
247  /**
248  Constructor.
249  Uses 512x512 as default atlas size.
250  */
251  NanoVG();
252 
253  /**
254  Constructor using custom text atlas size.
255  */
256  NanoVG(const int textAtlasWidth, const int textAtlasHeight);
257 
258  /**
259  Destructor.
260  */
261  virtual ~NanoVG();
262 
263  /**
264  Get the NanoVG context.
265  You should not need this under normal circumstances.
266  */
267  NVGcontext* getContext() const noexcept
268  {
269  return fContext;
270  }
271 
272  /**
273  Begin drawing a new frame.
274  @param withAlha Controls if drawing the shapes to the render target should be done using straight or pre-multiplied alpha.
275  */
276  void beginFrame(const uint width, const uint height, const float scaleFactor = 1.0f, const Alpha alpha = PREMULTIPLIED_ALPHA);
277 
278  /**
279  Begin drawing a new frame inside a widget.
280  */
281  void beginFrame(Widget* const widget);
282 
283  /**
284  Ends drawing flushing remaining render state.
285  */
286  void endFrame();
287 
288  /* --------------------------------------------------------------------
289  * State Handling */
290 
291  /**
292  Pushes and saves the current render state into a state stack.
293  A matching restore() must be used to restore the state.
294  */
295  void save();
296 
297  /**
298  Pops and restores current render state.
299  */
300  void restore();
301 
302  /**
303  Resets current render state to default values. Does not affect the render state stack.
304  */
305  void reset();
306 
307  /* --------------------------------------------------------------------
308  * Render styles */
309 
310  /**
311  Sets current stroke style to a solid color.
312  */
313  void strokeColor(const Color& color);
314 
315  /**
316  Sets current stroke style to a solid color, made from red, green, blue and alpha numeric values.
317  Values must be in [0..255] range.
318  */
319  void strokeColor(const int red, const int green, const int blue, const int alpha = 255);
320 
321  /**
322  Sets current stroke style to a solid color, made from red, green, blue and alpha numeric values.
323  Values must in [0..1] range.
324  */
325  void strokeColor(const float red, const float green, const float blue, const float alpha = 1.0f);
326 
327  /**
328  Sets current stroke style to a paint, which can be a one of the gradients or a pattern.
329  */
330  void strokePaint(const Paint& paint);
331 
332  /**
333  Sets current fill style to a solid color.
334  */
335  void fillColor(const Color& color);
336 
337  /**
338  Sets current fill style to a solid color, made from red, green, blue and alpha numeric values.
339  Values must be in [0..255] range.
340  */
341  void fillColor(const int red, const int green, const int blue, const int alpha = 255);
342 
343  /**
344  Sets current fill style to a solid color, made from red, green, blue and alpha numeric values.
345  Values must in [0..1] range.
346  */
347  void fillColor(const float red, const float green, const float blue, const float alpha = 1.0f);
348 
349  /**
350  Sets current fill style to a paint, which can be a one of the gradients or a pattern.
351  */
352  void fillPaint(const Paint& paint);
353 
354  /**
355  Sets the miter limit of the stroke style.
356  Miter limit controls when a sharp corner is beveled.
357  */
358  void miterLimit(float limit);
359 
360  /**
361  Sets the stroke width of the stroke style.
362  */
363  void strokeWidth(float size);
364 
365  /**
366  Sets how the end of the line (cap) is drawn,
367  Can be one of: BUTT, ROUND, SQUARE.
368  */
369  void lineCap(LineCap cap = BUTT);
370 
371  /**
372  Sets how sharp path corners are drawn.
373  Can be one of MITER, ROUND, BEVEL.
374  */
375  void lineJoin(LineCap join = MITER);
376 
377  /* --------------------------------------------------------------------
378  * Transforms */
379 
380  /**
381  Resets current transform to a identity matrix.
382  */
383  void resetTransform();
384 
385  /**
386  Pre-multiplies current coordinate system by specified matrix.
387  The parameters are interpreted as matrix as follows:
388  [a c e]
389  [b d f]
390  [0 0 1]
391  */
392  void transform(float a, float b, float c, float d, float e, float f);
393 
394  /**
395  Translates current coordinate system.
396  */
397  void translate(float x, float y);
398 
399  /**
400  Rotates current coordinate system. Angle is specified in radians.
401  */
402  void rotate(float angle);
403 
404  /**
405  Skews the current coordinate system along X axis. Angle is specified in radians.
406  */
407  void skewX(float angle);
408 
409  /**
410  Skews the current coordinate system along Y axis. Angle is specified in radians.
411  */
412  void skewY(float angle);
413 
414  /**
415  Scales the current coordinate system.
416  */
417  void scale(float x, float y);
418 
419  /**
420  Stores the top part (a-f) of the current transformation matrix in to the specified buffer.
421  [a c e]
422  [b d f]
423  [0 0 1]
424  */
425  void currentTransform(float xform[6]);
426 
427  /**
428  The following functions can be used to make calculations on 2x3 transformation matrices.
429  A 2x3 matrix is represented as float[6]. */
430 
431  /**
432  Sets the transform to identity matrix.
433  */
434  static void transformIdentity(float dst[6]);
435 
436  /**
437  Sets the transform to translation matrix
438  */
439  static void transformTranslate(float dst[6], float tx, float ty);
440 
441  /**
442  Sets the transform to scale matrix.
443  */
444  static void transformScale(float dst[6], float sx, float sy);
445 
446  /**
447  Sets the transform to rotate matrix. Angle is specified in radians.
448  */
449  static void transformRotate(float dst[6], float a);
450 
451  /**
452  Sets the transform to skew-x matrix. Angle is specified in radians.
453  */
454  static void transformSkewX(float dst[6], float a);
455 
456  /**
457  Sets the transform to skew-y matrix. Angle is specified in radians.
458  */
459  static void transformSkewY(float dst[6], float a);
460 
461  /**
462  Sets the transform to the result of multiplication of two transforms, of A = A*B.
463  */
464  static void transformMultiply(float dst[6], const float src[6]);
465 
466  /**
467  Sets the transform to the result of multiplication of two transforms, of A = B*A.
468  */
469  static void transformPremultiply(float dst[6], const float src[6]);
470 
471  /**
472  Sets the destination to inverse of specified transform.
473  Returns 1 if the inverse could be calculated, else 0.
474  */
475  static int transformInverse(float dst[6], const float src[6]);
476 
477  /**
478  Transform a point by given transform.
479  */
480  static void transformPoint(float& dstx, float& dsty, const float xform[6], float srcx, float srcy);
481 
482  /**
483  Convert degrees to radians.
484  */
485  static float degToRad(float deg);
486 
487  /**
488  Convert radians to degrees.
489  */
490  static float radToDeg(float rad);
491 
492  /* --------------------------------------------------------------------
493  * Images */
494 
495  /**
496  Creates image by loading it from the disk from specified file name.
497  */
498  NanoImage* createImage(const char* filename);
499 
500  /**
501  Creates image by loading it from the specified chunk of memory.
502  */
503  NanoImage* createImageMem(uchar* data, int ndata);
504 
505  /**
506  Creates image from specified image data.
507  */
508  NanoImage* createImageRGBA(uint w, uint h, const uchar* data);
509 
510  /* --------------------------------------------------------------------
511  * Paints */
512 
513  /**
514  Creates and returns a linear gradient. Parameters (sx,sy)-(ex,ey) specify the start and end coordinates
515  of the linear gradient, icol specifies the start color and ocol the end color.
516  The gradient is transformed by the current transform when it is passed to fillPaint() or strokePaint().
517  */
518  Paint linearGradient(float sx, float sy, float ex, float ey, const Color& icol, const Color& ocol);
519 
520  /**
521  Creates and returns a box gradient. Box gradient is a feathered rounded rectangle, it is useful for rendering
522  drop shadows or highlights for boxes. Parameters (x,y) define the top-left corner of the rectangle,
523  (w,h) define the size of the rectangle, r defines the corner radius, and f feather. Feather defines how blurry
524  the border of the rectangle is. Parameter icol specifies the inner color and ocol the outer color of the gradient.
525  The gradient is transformed by the current transform when it is passed to fillPaint() or strokePaint().
526  */
527  Paint boxGradient(float x, float y, float w, float h, float r, float f, const Color& icol, const Color& ocol);
528 
529  /**
530  Creates and returns a radial gradient. Parameters (cx,cy) specify the center, inr and outr specify
531  the inner and outer radius of the gradient, icol specifies the start color and ocol the end color.
532  The gradient is transformed by the current transform when it is passed to fillPaint() or strokePaint().
533  */
534  Paint radialGradient(float cx, float cy, float inr, float outr, const Color& icol, const Color& ocol);
535 
536  /**
537  Creates and returns an image pattern. Parameters (ox,oy) specify the left-top location of the image pattern,
538  (ex,ey) the size of one image, angle rotation around the top-left corner, image is handle to the image to render,
539  and repeat tells if the image should be repeated across x or y.
540  The gradient is transformed by the current transform when it is passed to fillPaint() or strokePaint().
541  */
542  Paint imagePattern(float ox, float oy, float ex, float ey, float angle, const NanoImage* image, PatternRepeat repeat);
543 
544  /* --------------------------------------------------------------------
545  * Scissoring */
546 
547  /**
548  Sets the current
549  The scissor rectangle is transformed by the current transform.
550  */
551  void scissor(float x, float y, float w, float h);
552 
553  /**
554  Reset and disables scissoring.
555  */
556  void resetScissor();
557 
558  /* --------------------------------------------------------------------
559  * Paths */
560 
561  /**
562  Clears the current path and sub-paths.
563  */
564  void beginPath();
565 
566  /**
567  Starts new sub-path with specified point as first point.
568  */
569  void moveTo(float x, float y);
570 
571  /**
572  Adds line segment from the last point in the path to the specified point.
573  */
574  void lineTo(float x, float y);
575 
576  /**
577  Adds bezier segment from last point in the path via two control points to the specified point.
578  */
579  void bezierTo(float c1x, float c1y, float c2x, float c2y, float x, float y);
580 
581  /**
582  Adds an arc segment at the corner defined by the last path point, and two specified points.
583  */
584  void arcTo(float x1, float y1, float x2, float y2, float radius);
585 
586  /**
587  Closes current sub-path with a line segment.
588  */
589  void closePath();
590 
591  /**
592  Sets the current sub-path winding.
593  */
594  void pathWinding(Winding dir);
595 
596  /**
597  Creates new arc shaped sub-path.
598  */
599  void arc(float cx, float cy, float r, float a0, float a1, Winding dir);
600 
601  /**
602  Creates new rectangle shaped sub-path.
603  */
604  void rect(float x, float y, float w, float h);
605 
606  /**
607  Creates new rounded rectangle shaped sub-path.
608  */
609  void roundedRect(float x, float y, float w, float h, float r);
610 
611  /**
612  Creates new ellipse shaped sub-path.
613  */
614  void ellipse(float cx, float cy, float rx, float ry);
615 
616  /**
617  Creates new circle shaped sub-path.
618  */
619  void circle(float cx, float cy, float r);
620 
621  /**
622  Fills the current path with current fill style.
623  */
624  void fill();
625 
626  /**
627  Fills the current path with current stroke style.
628  */
629  void stroke();
630 
631  /* --------------------------------------------------------------------
632  * Text */
633 
634  /**
635  Creates font by loading it from the disk from specified file name.
636  Returns handle to the font.
637  */
638  FontId createFont(const char* name, const char* filename);
639 
640  /**
641  Creates font by loading it from the specified memory chunk.
642  Returns handle to the font.
643  */
644  FontId createFontMem(const char* name, const uchar* data, int ndata, bool freeData);
645 
646  /**
647  Finds a loaded font of specified name, and returns handle to it, or -1 if the font is not found.
648  */
649  FontId findFont(const char* name);
650 
651  /**
652  Sets the font size of current text style.
653  */
654  void fontSize(float size);
655 
656  /**
657  Sets the blur of current text style.
658  */
659  void fontBlur(float blur);
660 
661  /**
662  Sets the letter spacing of current text style.
663  */
664  void textLetterSpacing(float spacing);
665 
666  /**
667  Sets the proportional line height of current text style. The line height is specified as multiple of font size.
668  */
669  void textLineHeight(float lineHeight);
670 
671  /**
672  Sets the text align of current text style.
673  */
674  void textAlign(Align align);
675 
676  /**
677  Sets the text align of current text style.
678  Overloaded function for convenience.
679  @see Align
680  */
681  void textAlign(int align);
682 
683  /**
684  Sets the font face based on specified id of current text style.
685  */
686  void fontFaceId(FontId font);
687 
688  /**
689  Sets the font face based on specified name of current text style.
690  */
691  void fontFace(const char* font);
692 
693  /**
694  Draws text string at specified location. If end is specified only the sub-string up to the end is drawn.
695  */
696  float text(float x, float y, const char* string, const char* end);
697 
698  /**
699  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.
700  White space is stripped at the beginning of the rows, the text is split at word boundaries or when new-line characters are encountered.
701  Words longer than the max width are slit at nearest character (i.e. no hyphenation).
702  */
703  void textBox(float x, float y, float breakRowWidth, const char* string, const char* end);
704 
705  /**
706  Measures the specified text string. The bounds value are [xmin,ymin, xmax,ymax].
707  Returns the horizontal advance of the measured text (i.e. where the next character should drawn).
708  Measured values are returned in local coordinate space.
709  */
710  float textBounds(float x, float y, const char* string, const char* end, Rectangle<float>& bounds);
711 
712  /**
713  Measures the specified multi-text string. Parameter bounds should be a pointer to float[4],
714  if the bounding box of the text should be returned. The bounds value are [xmin,ymin, xmax,ymax]
715  Measured values are returned in local coordinate space.
716  */
717  void textBoxBounds(float x, float y, float breakRowWidth, const char* string, const char* end, float* bounds);
718 
719  /**
720  Calculates the glyph x positions of the specified text. If end is specified only the sub-string will be used.
721  Measured values are returned in local coordinate space.
722  */
723  int textGlyphPositions(float x, float y, const char* string, const char* end, GlyphPosition* positions, int maxPositions);
724 
725  /**
726  Returns the vertical metrics based on the current text style.
727  Measured values are returned in local coordinate space.
728  */
729  void textMetrics(float* ascender, float* descender, float* lineh);
730 
731  /**
732  Breaks the specified text into lines. If end is specified only the sub-string will be used.
733  White space is stripped at the beginning of the rows, the text is split at word boundaries or when new-line characters are encountered.
734  Words longer than the max width are slit at nearest character (i.e. no hyphenation).
735  */
736  int textBreakLines(const char* string, const char* end, float breakRowWidth, TextRow* rows, int maxRows);
737 
738 private:
739  NVGcontext* const fContext;
740  bool fInFrame;
741 
742  DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(NanoVG)
743 };
744 
745 // -----------------------------------------------------------------------
746 // NanoWidget
747 
748 /**
749  NanoVG Widget class.
750 
751  This class implements the NanoVG drawing API inside a DGL Widget.
752  The drawing function onDisplay() is implemented internally but a
753  new onNanoDisplay() needs to be overridden instead.
754  */
755 class NanoWidget : public Widget,
756  public NanoVG
757 {
758 public:
759  /**
760  Constructor.
761  */
763  : Widget(parent),
764  NanoVG(),
765  leakDetector_NanoWidget()
766  {
767  setNeedsScaling(true);
768  }
769 
770 protected:
771  /**
772  New virtual onDisplay function.
773  @see onDisplay
774  */
775  virtual void onNanoDisplay() = 0;
776 
777 private:
778  /**
779  Widget display function.
780  Implemented internally to wrap begin/endFrame() automatically.
781  */
782  void onDisplay() override
783  {
784  //glPushAttrib(GL_PIXEL_MODE_BIT|GL_STENCIL_BUFFER_BIT|GL_ENABLE_BIT);
786  onNanoDisplay();
787  endFrame();
788  //glPopAttrib();
789  glDisable(GL_CULL_FACE);
790  }
791 
792  DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(NanoWidget)
793 };
794 
795 // -----------------------------------------------------------------------
796 
797 END_NAMESPACE_DGL
798 
799 #endif // DGL_NANO_WIDGET_HPP_INCLUDED
static void transformPoint(float &dstx, float &dsty, const float xform[6], float srcx, float srcy)
NVGcontext * getContext() const noexcept
Definition: NanoVG.hpp:267
void textAlign(Align align)
Definition: NanoVG.hpp:237
void beginPath()
Definition: NanoVG.hpp:37
void lineTo(float x, float y)
int textGlyphPositions(float x, float y, const char *string, const char *end, GlyphPosition *positions, int maxPositions)
Paint imagePattern(float ox, float oy, float ex, float ey, float angle, const NanoImage *image, PatternRepeat repeat)
static void transformScale(float dst[6], float sx, float sy)
void stroke()
void currentTransform(float xform[6])
void circle(float cx, float cy, float r)
static void transformMultiply(float dst[6], const float src[6])
void fontSize(float size)
Definition: NanoVG.hpp:755
void miterLimit(float limit)
Definition: Window.hpp:30
void strokeWidth(float size)
virtual void onNanoDisplay()=0
void textBoxBounds(float x, float y, float breakRowWidth, const char *string, const char *end, float *bounds)
Paint linearGradient(float sx, float sy, float ex, float ey, const Color &icol, const Color &ocol)
void translate(float x, float y)
static void transformPremultiply(float dst[6], const float src[6])
void arcTo(float x1, float y1, float x2, float y2, float radius)
void scale(float x, float y)
Definition: Color.hpp:33
uint getWidth() const noexcept
static void transformSkewX(float dst[6], float a)
void beginFrame(const uint width, const uint height, const float scaleFactor=1.0f, const Alpha alpha=PREMULTIPLIED_ALPHA)
void rect(float x, float y, float w, float h)
Paint radialGradient(float cx, float cy, float inr, float outr, const Color &icol, const Color &ocol)
void fontBlur(float blur)
void strokePaint(const Paint &paint)
void reset()
NanoWidget(Window &parent)
Definition: NanoVG.hpp:762
void save()
void fontFaceId(FontId font)
void moveTo(float x, float y)
void transform(float a, float b, float c, float d, float e, float f)
void ellipse(float cx, float cy, float rx, float ry)
void bezierTo(float c1x, float c1y, float c2x, float c2y, float x, float y)
void fontFace(const char *font)
NanoImage * createImageMem(uchar *data, int ndata)
FontId createFontMem(const char *name, const uchar *data, int ndata, bool freeData)
void restore()
void skewY(float angle)
void updateImage(const uchar *const data)
void endFrame()
FontId findFont(const char *name)
void rotate(float angle)
virtual ~NanoVG()
NanoImage * createImage(const char *filename)
Definition: NanoVG.hpp:212
void pathWinding(Winding dir)
Definition: NanoVG.hpp:168
void textLineHeight(float lineHeight)
void closePath()
static void transformIdentity(float dst[6])
void skewX(float angle)
Size< uint > getSize() const noexcept
float textBounds(float x, float y, const char *string, const char *end, Rectangle< float > &bounds)
static float radToDeg(float rad)
Definition: NanoVG.hpp:231
FontId createFont(const char *name, const char *filename)
static void transformSkewY(float dst[6], float a)
static int transformInverse(float dst[6], const float src[6])
void roundedRect(float x, float y, float w, float h, float r)
static float degToRad(float deg)
void textBox(float x, float y, float breakRowWidth, const char *string, const char *end)
static void transformTranslate(float dst[6], float tx, float ty)
void arc(float cx, float cy, float r, float a0, float a1, Winding dir)
Definition: Widget.hpp:51
void lineCap(LineCap cap=BUTT)
Definition: Geometry.hpp:30
void resetTransform()
float text(float x, float y, const char *string, const char *end)
void lineJoin(LineCap join=MITER)
NanoImage(NVGcontext *const context, const int imageId) noexcept
void fillColor(const Color &color)
void scissor(float x, float y, float w, float h)
void strokeColor(const Color &color)
void textMetrics(float *ascender, float *descender, float *lineh)
uint getHeight() const noexcept
void setNeedsScaling(bool yesNo) noexcept
void fillPaint(const Paint &paint)
static void transformRotate(float dst[6], float a)
Paint boxGradient(float x, float y, float w, float h, float r, float f, const Color &icol, const Color &ocol)
NanoImage * createImageRGBA(uint w, uint h, const uchar *data)
void textLetterSpacing(float spacing)
void fill()
int textBreakLines(const char *string, const char *end, float breakRowWidth, TextRow *rows, int maxRows)
void resetScissor()