From 5bd0ccce2e8edf7a3798b34ea1639649a70d7a75 Mon Sep 17 00:00:00 2001 From: Thomas Friedel Date: Mon, 30 Apr 2018 16:30:19 +0200 Subject: [PATCH] updated docs --- canvas.go | 2 ++ gradients.go | 20 ++++++++++++++++++++ images.go | 2 +- text.go | 9 +++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/canvas.go b/canvas.go index 6463f52..62b8fba 100644 --- a/canvas.go +++ b/canvas.go @@ -68,6 +68,7 @@ type scissor struct { type lineJoin uint8 type lineEnd uint8 +// Line join and end constants for SetLineJoin and SetLineEnd const ( Miter = iota Bevel @@ -78,6 +79,7 @@ const ( type textAlign uint8 +// Text alignment constants for SetTextAlign const ( Left = iota Center diff --git a/gradients.go b/gradients.go index 641e00c..146a128 100644 --- a/gradients.go +++ b/gradients.go @@ -5,10 +5,18 @@ import ( "runtime" ) +// LinearGradient is a gradient with any number of +// stops and any number of colors. The gradient will +// be drawn such that each point on the gradient +// will correspond to a straight line type LinearGradient struct { gradient } +// RadialGradient is a gradient with any number of +// stops and any number of colors. The gradient will +// be drawn such that each point on the gradient +// will correspond to a circle type RadialGradient struct { gradient radFrom, radTo float64 @@ -27,6 +35,9 @@ type gradientStop struct { color glColor } +// NewLinearGradient creates a new linear gradient with +// the coordinates from where to where the gradient +// will apply on the canvas func NewLinearGradient(x0, y0, x1, y1 float64) *LinearGradient { lg := &LinearGradient{gradient: gradient{from: vec{x0, y0}, to: vec{x1, y1}}} gli.GenTextures(1, &lg.tex) @@ -43,6 +54,10 @@ func NewLinearGradient(x0, y0, x1, y1 float64) *LinearGradient { return lg } +// NewRadialGradient creates a new linear gradient with +// the coordinates and the radii for two circles. The +// gradient will apply from the first to the second +// circle func NewRadialGradient(x0, y0, r0, x1, y1, r1 float64) *RadialGradient { rg := &RadialGradient{gradient: gradient{from: vec{x0, y0}, to: vec{x1, y1}}, radFrom: r0, radTo: r1} gli.GenTextures(1, &rg.tex) @@ -59,8 +74,10 @@ func NewRadialGradient(x0, y0, r0, x1, y1, r1 float64) *RadialGradient { return rg } +// Delete explicitly deletes the gradient func (g *gradient) Delete() { gli.DeleteTextures(1, &g.tex) + g.deleted = true } func (g *gradient) load() { @@ -113,6 +130,9 @@ func (g *gradient) colorAt(pos float64) glColor { return c } +// AddColorStop adds a color stop to the gradient. The stops +// don't have to be added in order, they are sorted into the +// right place func (g *gradient) AddColorStop(pos float64, color ...interface{}) { c, _ := parseColor(color...) insert := len(g.stops) diff --git a/images.go b/images.go index 620490e..be76c59 100644 --- a/images.go +++ b/images.go @@ -200,7 +200,7 @@ func (img *Image) Delete() { img.deleted = true } -// Draw image draws the given image to the given coordinates. The image +// DrawImage draws the given image to the given coordinates. The image // parameter can be an Image loaded by LoadImage, a file name string that will // be loaded and cached, or a name string that corresponds to a previously // loaded image with the same name parameter. diff --git a/text.go b/text.go index d34dae1..41a1cf5 100644 --- a/text.go +++ b/text.go @@ -15,6 +15,8 @@ import ( var fontRenderingContext = newFRContext() +// Font is a loaded font that can be passed to the +// SetFont method type Font struct { font *truetype.Font } @@ -25,6 +27,8 @@ var textImage *image.Alpha var defaultFont *Font +// LoadFont loads a font and returns the result. The font +// can be a file name or a byte slice in TTF format func LoadFont(src interface{}) (*Font, error) { var f *Font switch v := src.(type) { @@ -55,6 +59,8 @@ func LoadFont(src interface{}) (*Font, error) { return f, nil } +// FillText draws the given string at the given coordinates +// using the currently set font and font height func (cv *Canvas) FillText(str string, x, y float64) { cv.activate() @@ -225,10 +231,13 @@ func (cv *Canvas) FillText(str string, x, y float64) { gli.StencilFunc(gl_ALWAYS, 0, 0xFF) } +// TextMetrics is the result of a MeasureText call type TextMetrics struct { Width float64 } +// MeasureText measures the given string using the +// current font and font height func (cv *Canvas) MeasureText(str string) TextMetrics { if cv.state.font == nil { return TextMetrics{}