updated docs

This commit is contained in:
Thomas Friedel 2018-04-30 16:30:19 +02:00
parent c50447827c
commit 5bd0ccce2e
4 changed files with 32 additions and 1 deletions

View file

@ -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

View file

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

View file

@ -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.

View file

@ -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{}