nanovgo

package module
v0.0.0-...-b800a0c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2018 License: Zlib Imports: 3 Imported by: 0

README

NanoVGo

GoDoc

NanoVGo is a Go binding for NanoVG, a small antialiased vector graphics rendering library for OpenGL.

NanoVGo is in an early stage. Frequent changes to the APIs are expected, which will become stable after the 1.0.0 version.

Please note that NanoVGo is a Go binding created with Cgo, instead of a Go port. For a Go port of the NanoVG library, please refer to shibukawa/nanovgo.

NanoVG Version

Commit cfa175a (Sep 2, 2018).

Credits

NanoVGo uses the source code of NanoVG under the zlib license.

License

zlib

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func DegToRad

func DegToRad(deg float32) float32

DegToRad converts degrees to radians.

func RadToDeg

func RadToDeg(rad float32) float32

RadToDeg converts radians to degrees.

func TransformIdentity

func TransformIdentity(dst *[6]float32)

TransformIdentity sets the transform to an identity matrix.

func TransformInverse

func TransformInverse(dst *[6]float32, src [6]float32) (succeeded bool)

TransformInverse sets dst to the inverse of src. Returns true if the inverse could be calculated, else false.

func TransformMultiply

func TransformMultiply(dst *[6]float32, src [6]float32)

TransformMultiply sets the transform to the result of multiplication of the two transforms, of A = A*B.

func TransformPoint

func TransformPoint(xform [6]float32, srcX, srcY float32) (dstX, dstY float32)

TransformPoint transforms a point (srcX,srcY) by xform.

func TransformPremultiply

func TransformPremultiply(dst *[6]float32, src [6]float32)

TransformPremultiply sets the transform to the result of multiplication of the two transforms, of A = B*A.

func TransformRotate

func TransformRotate(dst *[6]float32, angle float32)

TransformRotate sets the transform to a rotate matrix. angle is specified in radians.

func TransformScale

func TransformScale(dst *[6]float32, sx, sy float32)

TransformScale sets the transform to a scale matrix.

func TransformSkewX

func TransformSkewX(dst *[6]float32, angle float32)

TransformSkewX sets the transform to a skew-x matrix. angle is specified in radians.

func TransformSkewY

func TransformSkewY(dst *[6]float32, angle float32)

TransformSkewY sets the transform to a skew-y matrix. angle is specified in radians.

func TransformTranslate

func TransformTranslate(dst *[6]float32, tx, ty float32)

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.

Blend factors.

type CompositeOperation

type CompositeOperation int

CompositeOperation specify the operation for composition.

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

func (ctx *Context) AddFallbackFont(baseFont, fallbackFont string)

AddFallbackFont adds a fallback font by its name.

func (*Context) AddFallbackFontID

func (ctx *Context) AddFallbackFontID(baseFont, fallbackFont *Font)

AddFallbackFontID adds a fallback font by its handle.

func (*Context) Arc

func (ctx *Context) Arc(x, y, radius, angle0, angle1 float32, direction Winding)

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

func (ctx *Context) ArcTo(x1, y1, x2, y2, radius float32)

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

func (ctx *Context) BeginFrame(windowWidth, windowHeight, devicePixelRatio float32)

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

func (ctx *Context) BezierTo(c1X, c1Y, c2X, c2Y, x, y float32)

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) Circle

func (ctx *Context) Circle(x, y, radius float32)

Circle creates a new circle shaped sub-path. The center is at (x,y).

func (*Context) ClosePath

func (ctx *Context) ClosePath()

ClosePath closes current sub-path with a line segment.

func (*Context) CreateFont

func (ctx *Context) CreateFont(name, filename string) *Font

CreateFont creates a font by loading it from the disk from filename. Returns a handle to the font.

func (*Context) CreateFontMem

func (ctx *Context) CreateFontMem(name string, data []uint8, freeData int) *Font

CreateFontMem creates a font by loading it from data, a memory chunk. Returns a handle to the font.

func (*Context) CreateImage

func (ctx *Context) CreateImage(filename string, imageFlags ImageFlag) *Image

CreateImage creates an image by loading it from the disk from filename. Returns a handle to the image.

func (*Context) CreateImageMem

func (ctx *Context) CreateImageMem(imageFlags ImageFlag, data []uint8) *Image

CreateImageMem creates an image by loading it from data, a chunk of memory. Returns a handle to the image.

func (*Context) CreateImageRGBA

func (ctx *Context) CreateImageRGBA(width, height int, imageFlags ImageFlag, data []uint8) *Image

CreateImageRGBA creates an image from data. Returns a handle to the image.

func (*Context) CurrentTransform

func (ctx *Context) CurrentTransform() [6]float32

CurrentTransform returns the top part (a-f) of the current transformation matrix.

[a c e]
[b d f]
[0 0 1]

func (*Context) Delete

func (ctx *Context) Delete()

Delete deletes a NanoVGo context.

func (*Context) Ellipse

func (ctx *Context) Ellipse(x, y, radiusX, radiusY float32)

Ellipse creates a new ellipse shape sub-path. The center is at (x,y).

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) FillColor

func (ctx *Context) FillColor(color color.Color)

FillColor sets the current fill style to a solid color.

func (*Context) FillPaint

func (ctx *Context) FillPaint(paint Paint)

FillPaint sets the current fill style to a pint, which can be one of the gradients or a pattern.

func (*Context) FindFont

func (ctx *Context) FindFont(name string) *Font

FindFont finds a loaded font with name, and returns a handle to it, or nil if the font is not found.

func (*Context) FontBlur

func (ctx *Context) FontBlur(blur float32)

FontBlur sets the blur of the current text style.

func (*Context) FontFace

func (ctx *Context) FontFace(font string)

FontFace sets the font face of the current text style by the font name.

func (*Context) FontFaceID

func (ctx *Context) FontFaceID(font *Font)

FontFaceID sets the font face of the current text style with a font handle.

func (*Context) FontSize

func (ctx *Context) FontSize(size float32)

FontSize sets the font size of the current text style.

func (*Context) GlobalAlpha

func (ctx *Context) GlobalAlpha(alpha float32)

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

func (ctx *Context) IntersectScissor(x, y, width, height float32)

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

func (ctx *Context) LineCap(cap 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

func (ctx *Context) LineJoin(join LineJoin)

LineJoin sets how sharp path corners are drawn. join can be one of Miter (default), RoundJoin and Bevel.

func (*Context) LineTo

func (ctx *Context) LineTo(x, y float32)

LineTo adds a line segment from the last point in the path to point (x,y).

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

func (ctx *Context) MiterLimit(limit float32)

MiterLimit sets the miter limit of the stroke style.

Miter limit controls when a sharp corner is beveled.

func (*Context) MoveTo

func (ctx *Context) MoveTo(x, y float32)

MoveTo starts a new sub-path with point (x,y) as the first point.

func (*Context) PathWinding

func (ctx *Context) PathWinding(direction Winding)

PathWinding sets the current sub-path winding, see Winding.

func (*Context) QuadTo

func (ctx *Context) QuadTo(cX, cY, x, y float32)

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) Rect

func (ctx *Context) Rect(x, y, width, height float32)

Rect creates a new rectangle shaped sub-path.

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

func (ctx *Context) Rotate(angle float32)

Rotate rotates the current coordinate system. angle is specified in radians.

func (*Context) RoundedRect

func (ctx *Context) RoundedRect(x, y, width, height, radius float32)

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) Scale

func (ctx *Context) Scale(x, y float32)

Scale scales the current coordinate system.

func (*Context) Scissor

func (ctx *Context) Scissor(x, y, width, height float32)

Scissor sets the current scissor rectangle. The scissor rectangle is transformed by the current transform.

func (*Context) ShapeAntialias

func (ctx *Context) ShapeAntialias(enabled bool)

ShapeAntialias sets whether to draw antialias for Context.Stroke() and Context.Fill(). It's enabled by default.

func (*Context) SkewX

func (ctx *Context) SkewX(angle float32)

SkewX skews the current coordinate system along the X axis. angle is specified in radians.

func (*Context) SkewY

func (ctx *Context) SkewY(angle float32)

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

func (ctx *Context) StrokeColor(color color.Color)

StrokeColor sets the current stroke style to a solid color.

func (*Context) StrokePaint

func (ctx *Context) StrokePaint(paint Paint)

StrokePaint sets the current stroke style to a paint, which can be one of the gradients or a pattern.

func (*Context) StrokeWidth

func (ctx *Context) StrokeWidth(size float32)

StrokeWidth sets the stroke width of the stroke style.

func (*Context) Text

func (ctx *Context) Text(x, y float32, text string)

Text draws text at location (x,y).

func (*Context) TextAlign

func (ctx *Context) TextAlign(align Align)

TextAlign sets the text align of the current text style, see Align for options.

func (*Context) TextBounds

func (ctx *Context) TextBounds(x, y float32, text string) (float32, [4]float32)

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

func (ctx *Context) TextBox(x, y, breakRowWidth float32, text string)

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

func (ctx *Context) TextBoxBounds(x, y, breakRowWidth float32, text string) [4]float32

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

func (ctx *Context) TextBreakLines(text string, breakRowWidth float32, maxRows int) []TextRow

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

func (ctx *Context) TextLetterSpacing(spacing float32)

TextLetterSpacing sets the letter spacing of the current text style.

func (*Context) TextLineHeight

func (ctx *Context) TextLineHeight(lineHeight float32)

TextLineHeight sets the proportional line height of the current text style. The line height is specified as multiple of font size.

func (*Context) TextMetrics

func (ctx *Context) TextMetrics() (ascender, descender, lineh float32)

TextMetrics returns the vertical metrics based on the current text style.

Measured values are returned in local coordinate space.

func (*Context) Transform

func (ctx *Context) Transform(a, b, c, d, e, f float32)

Transform premultiplies the current coordinate system by a matrix.

The parameters are interpreted as a matrix as follows:

[a c e]
[b d f]
[0 0 1]

func (*Context) Translate

func (ctx *Context) Translate(x, y float32)

Translate translates the current coordinate system.

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) Delete

func (image *Image) Delete()

Delete deletes image.

func (*Image) Size

func (image *Image) Size() (width, height int)

Size returns the dimensions of image.

func (*Image) UpdateImage

func (image *Image) UpdateImage(data []uint8)

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 LineCap

type LineCap int

LineCap specifies the style of line caps.

const (
	Butt     LineCap = C.NVG_BUTT
	RoundCap LineCap = C.NVG_ROUND
	Square   LineCap = C.NVG_SQUARE
)

Line caps.

type LineJoin

type LineJoin int

LineJoin specifies the style of sharp path corners.

const (
	Miter     LineJoin = C.NVG_MITER
	RoundJoin LineJoin = C.NVG_ROUND
	Bevel     LineJoin = C.NVG_BEVEL
)

Line joins.

type Paint

type Paint C.NVGpaint

Paint is a paint style used for painting.

type TextRow

type TextRow C.NVGtextRow

TextRow stores the range, width and position of a row of text.

func (TextRow) MaxX

func (row TextRow) MaxX() float32

MaxX returns the actual bounds of row. Logical width and bounds can differ because of kerning and some parts over extending.

func (TextRow) MinX

func (row TextRow) MinX() float32

MinX returns the actual bounds of row. Logical width and bounds can differ because of kerning and some parts over extending.

func (TextRow) Next

func (row TextRow) Next() string

Next returns the remaining text.

func (TextRow) Text

func (row TextRow) Text() string

Text returns the text of row.

func (TextRow) Width

func (row TextRow) Width() float32

Width returns the logical width of row.

type Winding

type Winding int

Winding specifies the direction of winding.

const (
	// CCW is the winding for solid shapes.
	CCW Winding = C.NVG_CCW
	// CW is the winding for holes.
	CW Winding = C.NVG_CW
)

Windings.

const (
	// Solid is for CCW.
	Solid Winding = C.NVG_SOLID
	// Hole is for CW.
	Hole Winding = C.NVG_HOLE
)

Solidities.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL