Documentation
¶
Overview ¶
Package nanovgo is a Go binding for NanoVG (https://github.com/memononen/nanovg), a small antialiased vector graphics rendering library for OpenGL.
Index ¶
- func DegToRad(deg float32) float32
- func RadToDeg(rad float32) float32
- func TransformIdentity(dst *[6]float32)
- func TransformInverse(dst *[6]float32, src [6]float32) (succeeded bool)
- func TransformMultiply(dst *[6]float32, src [6]float32)
- func TransformPoint(xform [6]float32, srcX, srcY float32) (dstX, dstY float32)
- func TransformPremultiply(dst *[6]float32, src [6]float32)
- func TransformRotate(dst *[6]float32, angle float32)
- func TransformScale(dst *[6]float32, sx, sy float32)
- func TransformSkewX(dst *[6]float32, angle float32)
- func TransformSkewY(dst *[6]float32, angle float32)
- func TransformTranslate(dst *[6]float32, tx, ty float32)
- type Align
- type BlendFactor
- type CompositeOperation
- type CompositeOperationState
- type Context
- func (ctx *Context) AddFallbackFont(baseFont, fallbackFont string)
- func (ctx *Context) AddFallbackFontID(baseFont, fallbackFont *Font)
- func (ctx *Context) Arc(x, y, radius, angle0, angle1 float32, direction Winding)
- func (ctx *Context) ArcTo(x1, y1, x2, y2, radius float32)
- func (ctx *Context) BeginFrame(windowWidth, windowHeight, devicePixelRatio float32)
- func (ctx *Context) BeginPath()
- func (ctx *Context) BezierTo(c1X, c1Y, c2X, c2Y, x, y float32)
- func (ctx *Context) BoxGradient(x, y, width, height, radius, feather float32, ...) Paint
- func (ctx *Context) CancelFrame()
- func (ctx *Context) Circle(x, y, radius float32)
- func (ctx *Context) ClosePath()
- func (ctx *Context) CreateFont(name, filename string) *Font
- func (ctx *Context) CreateFontMem(name string, data []uint8, freeData int) *Font
- func (ctx *Context) CreateImage(filename string, imageFlags ImageFlag) *Image
- func (ctx *Context) CreateImageMem(imageFlags ImageFlag, data []uint8) *Image
- func (ctx *Context) CreateImageRGBA(width, height int, imageFlags ImageFlag, data []uint8) *Image
- func (ctx *Context) CurrentTransform() [6]float32
- func (ctx *Context) Delete()
- func (ctx *Context) Ellipse(x, y, radiusX, radiusY float32)
- func (ctx *Context) EndFrame()
- func (ctx *Context) Fill()
- func (ctx *Context) FillColor(color color.Color)
- func (ctx *Context) FillPaint(paint Paint)
- func (ctx *Context) FindFont(name string) *Font
- func (ctx *Context) FontBlur(blur float32)
- func (ctx *Context) FontFace(font string)
- func (ctx *Context) FontFaceID(font *Font)
- func (ctx *Context) FontSize(size float32)
- func (ctx *Context) GlobalAlpha(alpha float32)
- func (ctx *Context) GlobalCompositeBlendFunc(sFactor, dFactor BlendFactor)
- func (ctx *Context) GlobalCompositeBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha BlendFactor)
- func (ctx *Context) GlobalCompositeOperation(op CompositeOperation)
- func (ctx *Context) ImagePattern(x, y, imageWidth, imageHeight, angle float32, image *Image, alpha float32) Paint
- func (ctx *Context) IntersectScissor(x, y, width, height float32)
- func (ctx *Context) LineCap(cap LineCap)
- func (ctx *Context) LineJoin(join LineJoin)
- func (ctx *Context) LineTo(x, y float32)
- func (ctx *Context) LinearGradient(startX, startY, endX, endY float32, startColor, endColor color.Color) Paint
- func (ctx *Context) MiterLimit(limit float32)
- func (ctx *Context) MoveTo(x, y float32)
- func (ctx *Context) PathWinding(direction Winding)
- func (ctx *Context) QuadTo(cX, cY, x, y float32)
- func (ctx *Context) RadialGradient(centerX, centerY, innerRadius, outerRadius float32, ...) Paint
- func (ctx *Context) Rect(x, y, width, height float32)
- func (ctx *Context) Reset()
- func (ctx *Context) ResetScissor()
- func (ctx *Context) ResetTransform()
- func (ctx *Context) Restore()
- func (ctx *Context) Rotate(angle float32)
- func (ctx *Context) RoundedRect(x, y, width, height, radius float32)
- func (ctx *Context) RoundedRectVarying(...)
- func (ctx *Context) Save()
- func (ctx *Context) Scale(x, y float32)
- func (ctx *Context) Scissor(x, y, width, height float32)
- func (ctx *Context) ShapeAntialias(enabled bool)
- func (ctx *Context) SkewX(angle float32)
- func (ctx *Context) SkewY(angle float32)
- func (ctx *Context) Stroke()
- func (ctx *Context) StrokeColor(color color.Color)
- func (ctx *Context) StrokePaint(paint Paint)
- func (ctx *Context) StrokeWidth(size float32)
- func (ctx *Context) Text(x, y float32, text string)
- func (ctx *Context) TextAlign(align Align)
- func (ctx *Context) TextBounds(x, y float32, text string) (float32, [4]float32)
- func (ctx *Context) TextBox(x, y, breakRowWidth float32, text string)
- func (ctx *Context) TextBoxBounds(x, y, breakRowWidth float32, text string) [4]float32
- func (ctx *Context) TextBreakLines(text string, breakRowWidth float32, maxRows int) []TextRow
- func (ctx *Context) TextGlyphPositions(x, y float32, text string, maxPositions int) []GlyphPosition
- func (ctx *Context) TextLetterSpacing(spacing float32)
- func (ctx *Context) TextLineHeight(lineHeight float32)
- func (ctx *Context) TextMetrics() (ascender, descender, lineh float32)
- func (ctx *Context) Transform(a, b, c, d, e, f float32)
- func (ctx *Context) Translate(x, y float32)
- type CreateFlag
- type Font
- type GlyphPosition
- type Image
- type ImageFlag
- type LineCap
- type LineJoin
- type Paint
- type TextRow
- type Winding
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TransformIdentity ¶
func TransformIdentity(dst *[6]float32)
TransformIdentity sets the transform to an identity matrix.
func TransformInverse ¶
TransformInverse sets dst to the inverse of src. Returns true if the inverse could be calculated, else false.
func TransformMultiply ¶
TransformMultiply sets the transform to the result of multiplication of the two transforms, of A = A*B.
func TransformPoint ¶
TransformPoint transforms a point (srcX,srcY) by xform.
func TransformPremultiply ¶
TransformPremultiply sets the transform to the result of multiplication of the two transforms, of A = B*A.
func TransformRotate ¶
TransformRotate sets the transform to a rotate matrix. angle is specified in radians.
func TransformScale ¶
TransformScale sets the transform to a scale matrix.
func TransformSkewX ¶
TransformSkewX sets the transform to a skew-x matrix. angle is specified in radians.
func TransformSkewY ¶
TransformSkewY sets the transform to a skew-y matrix. angle is specified in radians.
func TransformTranslate ¶
TransformTranslate sets the transform to a translation matrix.
Types ¶
type Align ¶
type Align int
Align indicates how text should be aligned horizontally or vertically.
const ( // Horizontal aligns. AlignLeft Align = C.NVG_ALIGN_LEFT AlignCenter Align = C.NVG_ALIGN_CENTER AlignRight Align = C.NVG_ALIGN_RIGHT // Vertical align. AlignTop Align = C.NVG_ALIGN_TOP AlignMiddle Align = C.NVG_ALIGN_MIDDLE AlignBottom Align = C.NVG_ALIGN_BOTTOM AlignBaseline Align = C.NVG_ALIGN_BASELINE )
Align styles.
type BlendFactor ¶
type BlendFactor int
BlendFactor indicates how blending should work.
const ( Zero BlendFactor = C.NVG_ZERO One BlendFactor = C.NVG_ONE SrcColor BlendFactor = C.NVG_SRC_COLOR OneMinusSrcColor BlendFactor = C.NVG_ONE_MINUS_SRC_COLOR DstColor BlendFactor = C.NVG_DST_COLOR OneMinusDstColor BlendFactor = C.NVG_ONE_MINUS_DST_COLOR SrcAlpha BlendFactor = C.NVG_SRC_ALPHA OneMinusSrcAlpha BlendFactor = C.NVG_ONE_MINUS_SRC_ALPHA DstAlpha BlendFactor = C.NVG_DST_ALPHA OneMinusDstAlpha BlendFactor = C.NVG_ONE_MINUS_DST_ALPHA SrcAlphaSaturate BlendFactor = C.NVG_SRC_ALPHA_SATURATE )
Blend factors.
type CompositeOperation ¶
type CompositeOperation int
CompositeOperation specify the operation for composition.
const ( SourceOver CompositeOperation = C.NVG_SOURCE_OVER SourceIn CompositeOperation = C.NVG_SOURCE_IN SourceOut CompositeOperation = C.NVG_SOURCE_OUT Atop CompositeOperation = C.NVG_ATOP DestinationOver CompositeOperation = C.NVG_DESTINATION_OVER DestinationIn CompositeOperation = C.NVG_DESTINATION_IN DestinationOut CompositeOperation = C.NVG_DESTINATION_OUT DestinationAtop CompositeOperation = C.NVG_DESTINATION_ATOP Lighter CompositeOperation = C.NVG_LIGHTER Copy CompositeOperation = C.NVG_COPY Xor CompositeOperation = C.NVG_XOR )
Composite operations.
type CompositeOperationState ¶
type CompositeOperationState C.NVGcompositeOperationState
CompositeOperationState records the state of a composition operation.
type Context ¶
type Context C.NVGcontext
Context is a NanoVGo context for vector graphics rendering.
func CreateContext ¶
func CreateContext(flags CreateFlag) *Context
CreateContext creates a NanoVGo context for OpenGL 3. flags should be a combination of Antialias, StencilStrokes and Debug.
func (*Context) AddFallbackFont ¶
AddFallbackFont adds a fallback font by its name.
func (*Context) AddFallbackFontID ¶
AddFallbackFontID adds a fallback font by its handle.
func (*Context) Arc ¶
Arc creates a new circle arc shaped sub-path. The arc center is at (x,y), the arc radius is radius, and the arc is drawn from angle angle0 to angle1, and swept in direction direction (CCW or CW).
Angles are specified in radians.
func (*Context) ArcTo ¶
ArcTo adds an arc segment at the corner defined by the last path point, and two points (x1,y1) and (x2,y2).
func (*Context) BeginFrame ¶
BeginFrame begins drawing a new frame.
Calls to NanoVGo drawing API should be wrapped in Context.BeginFrame() and Context.EndFrame(). Context.BeginFrame() defines the size of the window to render to in relation to currently set viewport (i.e. glViewport on GL backends). Device pixel ratio allows to control the rendering on Hi-DPI devices.
For example, GLFW returns two dimensions for an opened window: window size and framebuffer size. In that case you would set windowWidth/Height to the window size, deivcePixelRatio to frameBufferWidth / windowWidth.
func (*Context) BeginPath ¶
func (ctx *Context) BeginPath()
BeginPath clears the current path and sub-paths.
func (*Context) BezierTo ¶
BezierTo adds a cubic bezier segment from the last point in the path via two control points ((c1X,c1Y) and (c2X,c2Y)) to point (x,y).
func (*Context) BoxGradient ¶
func (ctx *Context) BoxGradient(x, y, width, height, radius, feather float32, innerColor, outerColor color.Color) Paint
BoxGradient creates and returns a box gradient. A box gradient is a feathered rounded rectangle, it is useful for rendering drop shadows or highlights for boxes. Parameters (x,y) define the top-left corner of the rectangle, (width,height) define the size of the rectangle, radius defines the corner radius, and feather defines how blurry the border of the rectangle is. innerColor specifies the inner color and outerColor the outer color of the gradient.
The gradient is transformed by the current transform when it is passed to Context.FillPaint() or Context.StrokePaint().
func (*Context) CancelFrame ¶
func (ctx *Context) CancelFrame()
CancelFrame cancels drawing the current frame.
func (*Context) ClosePath ¶
func (ctx *Context) ClosePath()
ClosePath closes current sub-path with a line segment.
func (*Context) CreateFont ¶
CreateFont creates a font by loading it from the disk from filename. Returns a handle to the font.
func (*Context) CreateFontMem ¶
CreateFontMem creates a font by loading it from data, a memory chunk. Returns a handle to the font.
func (*Context) CreateImage ¶
CreateImage creates an image by loading it from the disk from filename. Returns a handle to the image.
func (*Context) CreateImageMem ¶
CreateImageMem creates an image by loading it from data, a chunk of memory. Returns a handle to the image.
func (*Context) CreateImageRGBA ¶
CreateImageRGBA creates an image from data. Returns a handle to the image.
func (*Context) CurrentTransform ¶
CurrentTransform returns the top part (a-f) of the current transformation matrix.
[a c e] [b d f] [0 0 1]
func (*Context) EndFrame ¶
func (ctx *Context) EndFrame()
EndFrame ends drawing and flushes remaining render state.
func (*Context) Fill ¶
func (ctx *Context) Fill()
Fill fills the current path with the current fill style.
func (*Context) FillPaint ¶
FillPaint sets the current fill style to a pint, which can be one of the gradients or a pattern.
func (*Context) FindFont ¶
FindFont finds a loaded font with name, and returns a handle to it, or nil if the font is not found.
func (*Context) FontFaceID ¶
FontFaceID sets the font face of the current text style with a font handle.
func (*Context) GlobalAlpha ¶
GlobalAlpha sets the transparency applied to all rendered shapes.
Already transparent paths will get proportionally more transparent as well.
func (*Context) GlobalCompositeBlendFunc ¶
func (ctx *Context) GlobalCompositeBlendFunc(sFactor, dFactor BlendFactor)
GlobalCompositeBlendFunc sets the composite operation with custom pixel arithmetic. sFactor and dFactor should be one of BlendFactor.
func (*Context) GlobalCompositeBlendFuncSeparate ¶
func (ctx *Context) GlobalCompositeBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha BlendFactor)
GlobalCompositeBlendFuncSeparate sets the composite operation with custom pixel arithmetic for RGB and alpha components separately. The parameters should be one of BlendFactor.
func (*Context) GlobalCompositeOperation ¶
func (ctx *Context) GlobalCompositeOperation(op CompositeOperation)
GlobalCompositeOperation sets the composite operation. op should be one of CompositeOperation.
func (*Context) ImagePattern ¶
func (ctx *Context) ImagePattern(x, y, imageWidth, imageHeight, angle float32, image *Image, alpha float32) Paint
ImagePattern creates and returns an image pattern. Parameters (x,y) specify the left-top location of the image pattern, (imageWidth,imageHeight) the size of one image, angle rotation around the top-left corner, image is handle to the image to render.
The gradient is transformed by the current transform when it is passed to Context.FillPaint() or Context.StrokePaint().
func (*Context) IntersectScissor ¶
IntersectScissor intersects the current scissor rectangle with the specified rectangle. The scissor rectangle is transformed by the current transform.
Note: in case the rotation of previous scissor rect differs from the current one, the intersection will be done between the specified rectangle and the previous scissor rectangle transformed in the current transform space. The resulting shape is always rectangle.
func (*Context) LineCap ¶
LineCap sets how the end of the line (cap) is drawn. cap can be one of Butt (default), RoundCap and Square.
func (*Context) LineJoin ¶
LineJoin sets how sharp path corners are drawn. join can be one of Miter (default), RoundJoin and Bevel.
func (*Context) LinearGradient ¶
func (ctx *Context) LinearGradient(startX, startY, endX, endY float32, startColor, endColor color.Color) Paint
LinearGradient creates and returns a linear gradient. Parameters (startX,startY)-(endX,endY) specify the start and end coordinates of the linear gradient, startColor specifies the start color and endColor the end color.
The gradient is transformed by the current transform when it is passed to Context.FillPaint() or Context.StrokePaint().
func (*Context) MiterLimit ¶
MiterLimit sets the miter limit of the stroke style.
Miter limit controls when a sharp corner is beveled.
func (*Context) PathWinding ¶
PathWinding sets the current sub-path winding, see Winding.
func (*Context) QuadTo ¶
QuadTo adds a quadratic bezier segment from the last point in the path via a control point (cX,cY) to point (x,y).
func (*Context) RadialGradient ¶
func (ctx *Context) RadialGradient(centerX, centerY, innerRadius, outerRadius float32, startColor, endColor color.Color) Paint
RadialGradient creates and returns a radian gradient. Parameters (centerX,centerY) specify the center, innerRadius and outerRadius specify the inner and outer radius of the gradient, startColor specifies the start color and endColor the end color.
The gradient is transformed by the current transform when it is passed to Context.FillPaint() or Context.StrokePaint().
func (*Context) Reset ¶
func (ctx *Context) Reset()
Reset resets current render state to default values. This does not affect the render state stack.
func (*Context) ResetScissor ¶
func (ctx *Context) ResetScissor()
ResetScissor resets and disables scissoring.
func (*Context) ResetTransform ¶
func (ctx *Context) ResetTransform()
ResetTransform resets the current transform to an indentity matrix.
func (*Context) Restore ¶
func (ctx *Context) Restore()
Restore pops and restores the current render state.
func (*Context) Rotate ¶
Rotate rotates the current coordinate system. angle is specified in radians.
func (*Context) RoundedRect ¶
RoundedRect creates a new rounded rectangle shaped sub-path.
func (*Context) RoundedRectVarying ¶
func (ctx *Context) RoundedRectVarying(x, y, width, height, radiusTopLeft, radiusTopRight, radiusBottomRight, radiusBottomLeft float32)
RoundedRectVarying creates a new rounded rectangle shaped sub-path with varying radii for each corner.
func (*Context) Save ¶
func (ctx *Context) Save()
Save pushes and saves the current render state into a state stack.
A matching Context.Restore() must be used to restore the state.
func (*Context) Scissor ¶
Scissor sets the current scissor rectangle. The scissor rectangle is transformed by the current transform.
func (*Context) ShapeAntialias ¶
ShapeAntialias sets whether to draw antialias for Context.Stroke() and Context.Fill(). It's enabled by default.
func (*Context) SkewX ¶
SkewX skews the current coordinate system along the X axis. angle is specified in radians.
func (*Context) SkewY ¶
SkewY skews the current coordinate system along the Y axis. angle is specified in radians.
func (*Context) Stroke ¶
func (ctx *Context) Stroke()
Stroke strokes the current path with the current stroke style.
func (*Context) StrokeColor ¶
StrokeColor sets the current stroke style to a solid color.
func (*Context) StrokePaint ¶
StrokePaint sets the current stroke style to a paint, which can be one of the gradients or a pattern.
func (*Context) StrokeWidth ¶
StrokeWidth sets the stroke width of the stroke style.
func (*Context) TextAlign ¶
TextAlign sets the text align of the current text style, see Align for options.
func (*Context) TextBounds ¶
TextBounds measures the specified text. Returns the horizontal advance of the measured text (i.e. where the next character should be drawn), and the bounding box of the text. The bounds values are [xmin, ymin, xmax, ymax].
Measured values are returned in local coordinate space.
func (*Context) TextBox ¶
TextBox draws multi-line text at location (x,y) wrapped at the width breakRowWidth.
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 split at the nearest character (i.e. no hyphenation).
func (*Context) TextBoxBounds ¶
TextBoxBounds measures the specified multi-line text. Returns the bounding box of the text. The bounds values are [xmin, ymin, xmax, ymax].
Measured values are returned in local coordinate space.
func (*Context) TextBreakLines ¶
TextBreakLines breaks the text into lines.
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 split at the nearest character (i.e. no hyphenation).
func (*Context) TextGlyphPositions ¶
func (ctx *Context) TextGlyphPositions(x, y float32, text string, maxPositions int) []GlyphPosition
TextGlyphPositions calculates the glyph x position of text.
Measured values are returned in local coordinate space.
func (*Context) TextLetterSpacing ¶
TextLetterSpacing sets the letter spacing of the current text style.
func (*Context) TextLineHeight ¶
TextLineHeight sets the proportional line height of the current text style. The line height is specified as multiple of font size.
func (*Context) TextMetrics ¶
TextMetrics returns the vertical metrics based on the current text style.
Measured values are returned in local coordinate space.
type CreateFlag ¶
type CreateFlag int
CreateFlag is a flag for creating NanoVGo contexts.
const ( // Antialias indicates if geometry based anti-aliasing is used (may not be // needed when using MSAA). Antialias CreateFlag = C.NVG_ANTIALIAS // StencilStrokes indicates if strokes should be drawn using stencil buffer. // The rendering will be a little slower, but path overlaps (i.e. // self-intersecting or sharp turns) will be drawn just once. StencilStrokes CreateFlag = C.NVG_STENCIL_STROKES // Debug indicates that additional debug checks are done. Debug CreateFlag = C.NVG_DEBUG )
Create flags.
type Font ¶
type Font struct {
// contains filtered or unexported fields
}
Font is a handle to a created font.
type GlyphPosition ¶
type GlyphPosition C.NVGglyphPosition
GlyphPosition is the position of a glyph from an input string.
func (GlyphPosition) MaxX ¶
func (pos GlyphPosition) MaxX() float32
MaxX returns the bounds of the glyph shape.
func (GlyphPosition) MinX ¶
func (pos GlyphPosition) MinX() float32
MinX returns the bounds of the glyph shape.
func (GlyphPosition) X ¶
func (pos GlyphPosition) X() float32
X returns the x-coordinate of the logical glyph position.
type Image ¶
type Image struct {
// contains filtered or unexported fields
}
Image is a handle to an loaded image.
func (*Image) UpdateImage ¶
UpdateImage updates image data.
type ImageFlag ¶
type ImageFlag int
ImageFlag indicates how images should be processed.
const ( ImageGenerateMipmaps ImageFlag = C.NVG_IMAGE_GENERATE_MIPMAPS ImageRepeatX ImageFlag = C.NVG_IMAGE_REPEATX ImageRepeatY ImageFlag = C.NVG_IMAGE_REPEATY ImageFlipy ImageFlag = C.NVG_IMAGE_FLIPY ImagePremultiplied ImageFlag = C.NVG_IMAGE_PREMULTIPLIED ImageNearest ImageFlag = C.NVG_IMAGE_NEAREST )
Image flags.
type TextRow ¶
type TextRow C.NVGtextRow
TextRow stores the range, width and position of a row of text.
func (TextRow) MaxX ¶
MaxX returns the actual bounds of row. Logical width and bounds can differ because of kerning and some parts over extending.