          {underscoreToCase} with prefix = "NVG_"
          deriving (Show,Read,Eq,Ord)#}
 
+-- | Begin drawing a new frame
+--
+-- Calls to nanovg drawing API should be wrapped in 'beginFrame' & 'endFrame'.
+--
+-- 'beginFrame' defines the size of the window to render to in relation currently
+-- set viewport (i.e. glViewport on GL backends). Device pixel ration allows to
+-- control the rendering on Hi-DPI devices.
+--
+-- For example, GLFW returns two dimension for an opened window: window size and
+-- frame buffer size. In that case you would set windowWidth/Height to the window size
+-- devicePixelRatio to: frameBufferWidth / windowWidth.
 {#fun unsafe nvgBeginFrame as beginFrame
         {`Context',`CInt',`CInt',`Float'} -> `()'#}
 
-{#fun unsafe nvgCancelFrame as canelFrame
-        {`Context'} -> `()'#}
-
+-- | Cancels drawing the current frame.
+{#fun unsafe nvgCancelFrame as cancelFrame
+        {`Context'} -> `()'#}
+
+-- | Ends drawing flushing remaining render state.
 {#fun unsafe nvgEndFrame as endFrame
         {`Context'} -> `()'#}
 
+-- | Returns a color value from red, green, blue values. Alpha will be set to 255 (1.0f).
 {#fun pure unsafe nvgRGB_ as rgb
         {id`CUChar',id`CUChar',id`CUChar',alloca-`Color'peek*} -> `()'#}
 
+-- | Returns a color value from red, green, blue values. Alpha will be set to 1.0f.
 {#fun pure unsafe nvgRGBf_ as rgbf
         {`CFloat',`CFloat',`CFloat',alloca-`Color'peek*} -> `()'#}
 
+-- | Returns a color value from red, green, blue and alpha values.
 {#fun pure unsafe nvgRGBA_ as rgba
         {id`CUChar',id`CUChar',id`CUChar',id`CUChar',alloca-`Color'peek*} -> `()'#}
 
+-- | Returns a color value from red, green, blue and alpha values.
 {#fun pure unsafe nvgRGBAf_ as rgbaf
         {`CFloat',`CFloat',`CFloat',`CFloat',alloca-`Color'peek*} -> `()'#}
 
+-- | Linearly interpolates from color c0 to c1, and returns resulting color value.
 {#fun pure unsafe nvgLerpRGBA_ as lerpRGBA
         {with*`Color',with*`Color',`CFloat',alloca-`Color'peek*} -> `()'#}
 
+-- | Sets transparency of a color value.
 {#fun pure unsafe nvgTransRGBA_ as transRGBA
         {with*`Color',id`CUChar',alloca-`Color'peek*} -> `()'#}
 
+-- | Sets transparency of a color value.
 {#fun pure unsafe nvgTransRGBAf_ as transRGBAf
         {with*`Color',`CFloat',alloca-`Color'peek*} -> `()'#}
 
+-- | Returns color value specified by hue, saturation and lightness.
+-- HSL values are all in range [0..1], alpha will be set to 255.
 {#fun pure unsafe nvgHSL_ as hsl
         {`CFloat',`CFloat',`CFloat',alloca-`Color'peek*} -> `()'#}
 
+-- | Returns color value specified by hue, saturation and lightness and alpha.
+-- HSL values are all in range [0..1], alpha in range [0..255]
 {#fun pure unsafe nvgHSLA_ as hsla
         {`CFloat',`CFloat',`CFloat',id`CUChar',alloca-`Color'peek*} -> `()'#}
 
+-- | Pushes and saves the current render state into a state stack.
+-- A matching 'restore' must be used to restore the state.
+
 {#fun unsafe nvgSave as save
         {`Context'} -> `()'#}
 
+-- | Pops and restores current render state.
 {#fun unsafe nvgRestore as restore
         {`Context'} -> `()'#}
 
+-- | Resets current render state to default values. Does not affect the render state stack.
 {#fun unsafe nvgReset as reset
         {`Context'} -> `()'#}
 
+-- | Sets current stroke style to a solid color.
 {#fun unsafe nvgStrokeColor_ as strokeColor
         {`Context',with*`Color'} -> `()'#}
 
+-- | Sets current stroke style to a paint, which can be a one of the gradients or a pattern.
 {#fun unsafe nvgStrokePaint_ as strokePaint
         {`Context',with*`Paint'} -> `()'#}
 
+-- | Sets current fill style to a solid color.
 {#fun unsafe nvgFillColor_ as fillColor
         {`Context',with*`Color'} -> `()'#}
 
+-- | Sets current fill style to a paint, which can be a one of the gradients or a pattern.
 {#fun unsafe nvgFillPaint_ as fillPaint
         {`Context',with*`Paint'} -> `()'#}
 
+-- | Sets the miter limit of the stroke style.
+-- Miter limit controls when a sharp corner is beveled.
 {#fun unsafe nvgMiterLimit as miterLimit
         {`Context',`CFloat'} -> `()'#}
 
+-- | Sets the stroke width of the stroke style.
 {#fun unsafe nvgStrokeWidth as strokeWidth
         {`Context',`CFloat'} -> `()'#}
 
+-- | Sets how the end of the line (cap) is drawn,
+-- Can be one of: 'Butt' (default), 'Round', 'Square'.
 {#fun unsafe nvgLineCap as lineCap
         {`Context',`LineCap'} -> `()'#}
 
+-- | Sets how sharp path corners are drawn.
+-- Can be one of 'Miter' (default), 'Round', 'Bevel.
 {#fun unsafe nvgLineJoin as lineJoin
         {`Context',`LineCap'} -> `()'#}
 
+-- | Sets the transparency applied to all rendered shapes.
+-- Already transparent paths will get proportionally more transparent as well.
 {#fun unsafe nvgGlobalAlpha as globalAlpha
         {`Context',`CFloat'} -> `()'#}
 
+-- | Resets current transform to a identity matrix.
 {#fun unsafe nvgResetTransform as resetTransform
         {`Context'} -> `()'#}
 
+-- | Premultiplies current coordinate system by specified matrix.
+-- The parameters are interpreted as matrix as follows:
+--
+-- > [a c e]
+-- > [b d f]
+-- > [0 0 1]
 {#fun unsafe nvgTransform as transform
         {`Context',`CFloat',`CFloat',`CFloat',`CFloat',`CFloat',`CFloat'} -> `()'#}
 
+-- | Translates current coordinate system.
 {#fun unsafe nvgTranslate as translate
         {`Context',`CFloat',`CFloat'} -> `()'#}
 
+-- | Rotates current coordinate system. Angle is specified in radians.
 {#fun unsafe nvgRotate as rotate
         {`Context',`CFloat'} -> `()'#}
 
+-- | Skews the current coordinate system along X axis. Angle is specified in radians.
 {#fun unsafe nvgSkewX as skewX
         {`Context',`CFloat'} -> `()'#}
 
+-- | Skews the current coordinate system along Y axis. Angle is specified in radians.
 {#fun unsafe nvgSkewY as skewY
         {`Context',`CFloat'} -> `()'#}
 
+-- | Scales the current coordinate system.
 {#fun unsafe nvgScale as scale
         {`Context',`CFloat',`CFloat'} -> `()'#}
 

  | i < 0 = Nothing
  | otherwise = Just (Image i)

{#fun unsafe nvgCreateImage as createImage
        {`Context','withCString.unwrapFileName'*`FileName',`CInt'} -> `Maybe Image'safeImage#}

{#fun unsafe nvgCreateImageMem as createImageMem
        {`Context',`ImageFlags',useAsCStringLen'*`ByteString'&} -> `Maybe Image'safeImage#}

{#fun unsafe nvgCreateImageRGBA as createImageRGBA
        {`Context',`CInt',`CInt',`ImageFlags',useAsPtr*`ByteString'} -> `Maybe Image'safeImage#}

{#fun unsafe nvgUpdateImage as updateImage
        {`Context',imageHandle`Image',useAsPtr*`ByteString'} -> `()'#}

{#fun unsafe nvgImageSize as imageSize
        {`Context',imageHandle`Image',alloca-`CInt'peek*,alloca-`CInt'peek*} -> `()'#}

{#fun unsafe nvgDeleteImage as deleteImage
        {`Context',imageHandle`Image'} -> `()'#}

{#fun unsafe nvgLinearGradient_ as linearGradient
        {`Context',`CFloat',`CFloat',`CFloat',`CFloat',with*`Color',with*`Color',alloca-`Paint'peek*} -> `()'#}

{#fun unsafe nvgBoxGradient_ as boxGradient
        {`Context',`CFloat',`CFloat',`CFloat',`CFloat',`CFloat',`CFloat',with*`Color',with*`Color',alloca-`Paint'peek*} -> `()'#}

{#fun unsafe nvgRadialGradient_ as radialGradient
        {`Context',`CFloat',`CFloat',`CFloat',`CFloat',with*`Color',with*`Color',alloca-`Paint'peek*} -> `()'#}

{#fun unsafe nvgImagePattern_ as imagePattern
        {`Context',`CFloat',`CFloat',`CFloat',`CFloat',`CFloat',imageHandle`Image',`CFloat',alloca-`Paint'peek*} -> `()'#}

{#fun unsafe nvgScissor as scissor
        {`Context',`CFloat',`CFloat',`CFloat',`CFloat'} -> `()'#}

{#fun unsafe nvgIntersectScissor as intersectScissor
        {`Context',`CFloat',`CFloat',`CFloat',`CFloat'} -> `()'#}

{#fun unsafe nvgResetScissor as resetScissor
        {`Context'} -> `()'#}

{#fun unsafe nvgBeginPath as beginPath
        {`Context'} -> `()'#}

{#fun unsafe nvgMoveTo as moveTo
        {`Context',`CFloat',`CFloat'} -> `()'#}

{#fun unsafe nvgLineTo as lineTo
        {`Context',`CFloat',`CFloat'} -> `()'#}

{#fun unsafe nvgBezierTo as bezierTo
        {`Context',`CFloat',`CFloat',`CFloat',`CFloat',`CFloat',`CFloat'} -> `()'#}

{#fun unsafe nvgQuadTo as quadTo
        {`Context',`CFloat',`CFloat',`CFloat',`CFloat'} -> `()'#}

{#fun unsafe nvgArcTo as arcTo
        {`Context',`CFloat',`CFloat',`CFloat',`CFloat',`CFloat'} -> `()'#}

{#fun unsafe nvgClosePath as closePath
        {`Context'} -> `()'#}

{#fun unsafe nvgPathWinding as pathWinding
        {`Context', `CInt'} -> `()'#}

{#fun unsafe nvgArc as arc
        {`Context',`CFloat',`CFloat', `CFloat', `CFloat', `CFloat', `Winding'} -> `()'#}

{#fun unsafe nvgRect as rect
         {`Context',`CFloat',`CFloat',`CFloat',`CFloat'} -> `()'#}

{#fun unsafe nvgRoundedRect as roundedRect
        {`Context',`CFloat',`CFloat',`CFloat',`CFloat',`CFloat'} -> `()'#}

{#fun unsafe nvgEllipse as ellipse
        {`Context',`CFloat',`CFloat',`CFloat',`CFloat'} -> `()'#}

{#fun unsafe nvgCircle as circle
        {`Context',`CFloat',`CFloat',`CFloat'} -> `()'#}

{#fun unsafe nvgFill as fill
        {`Context'} -> `()'#}

{#fun unsafe nvgStroke as stroke
        {`Context'} -> `()'#}


  | i < 0 = Nothing
  | otherwise = Just (Font i)

-- | Creates font by loading it from the disk from specified file name.
-- Returns handle to the font.
{#fun unsafe nvgCreateFont as createFont
        {`Context',withCString*`T.Text','withCString.unwrapFileName'*`FileName'} -> `Maybe Font'safeFont#}

-- | Creates image by loading it from the specified memory chunk.
-- Returns handle to the font.
{#fun unsafe nvgCreateFontMem as createFontMem
        {`Context',withCString*`T.Text',useAsCStringLen'*`ByteString'&,zero-`CInt'} -> `Maybe Font'safeFont#}

-- | Finds a loaded font of specified name, and returns handle to it, or -1 if the font is not found.
{#fun unsafe nvgFindFont as findFont
        {`Context', withCString*`T.Text'} -> `Maybe Font'safeFont#}

-- | Sets the font size of current text style.
{#fun unsafe nvgFontSize as fontSize
        {`Context',`CFloat'} -> `()'#}

-- | Sets the blur of current text style.
{#fun unsafe nvgFontBlur as fontBlur
        {`Context',`CFloat'} -> `()'#}

-- | Sets the letter spacing of current text style.
{#fun unsafe nvgTextLetterSpacing as textLetterSpacing
        {`Context',`CFloat'} -> `()'#}

-- | Sets the proportional line height of current text style. The line height is specified as multiple of font size. 
{#fun unsafe nvgTextLineHeight as textLineHeight
        {`Context',`CFloat'} -> `()'#}

-- | Sets the text align of current text style, see NVGalign for options.
{#fun unsafe nvgTextAlign as textAlign
        {`Context',bitMask`S.Set Align'} -> `()'#}

-- | Sets the font face based on specified id of current text style.
{#fun unsafe nvgFontFaceId as fontFaceId
        {`Context',fontHandle`Font'} -> `()'#}

-- | Sets the font face based on specified name of current text styl
{#fun unsafe nvgFontFace as fontFace
        {`Context',withCString*`T.Text'} -> `()'#}

-- | Draws text string at specified location. If end is specified only the sub-string up to the end is drawn.
{#fun unsafe nvgText as text
         {`Context',`CFloat',`CFloat',id`Ptr CChar',id`Ptr CChar'} -> `()'#}

-- | Draws multi-line text string at specified location wrapped at the specified width. If end is specified only the sub-string up to the end is drawn.
-- | White space is stripped at the beginning of the rows, the text is split at word boundaries or when new-line characters are encountered.
-- | Words longer than the max width are slit at nearest character (i.e. no hyphenation).
{#fun unsafe nvgTextBox as textBox
        {`Context',`CFloat',`CFloat',`CFloat',withCString*`T.Text',null-`Ptr CUChar'} -> `()'#}

