updated docs
This commit is contained in:
parent
c50447827c
commit
5bd0ccce2e
4 changed files with 32 additions and 1 deletions
|
@ -68,6 +68,7 @@ type scissor struct {
|
||||||
type lineJoin uint8
|
type lineJoin uint8
|
||||||
type lineEnd uint8
|
type lineEnd uint8
|
||||||
|
|
||||||
|
// Line join and end constants for SetLineJoin and SetLineEnd
|
||||||
const (
|
const (
|
||||||
Miter = iota
|
Miter = iota
|
||||||
Bevel
|
Bevel
|
||||||
|
@ -78,6 +79,7 @@ const (
|
||||||
|
|
||||||
type textAlign uint8
|
type textAlign uint8
|
||||||
|
|
||||||
|
// Text alignment constants for SetTextAlign
|
||||||
const (
|
const (
|
||||||
Left = iota
|
Left = iota
|
||||||
Center
|
Center
|
||||||
|
|
20
gradients.go
20
gradients.go
|
@ -5,10 +5,18 @@ import (
|
||||||
"runtime"
|
"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 {
|
type LinearGradient struct {
|
||||||
gradient
|
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 {
|
type RadialGradient struct {
|
||||||
gradient
|
gradient
|
||||||
radFrom, radTo float64
|
radFrom, radTo float64
|
||||||
|
@ -27,6 +35,9 @@ type gradientStop struct {
|
||||||
color glColor
|
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 {
|
func NewLinearGradient(x0, y0, x1, y1 float64) *LinearGradient {
|
||||||
lg := &LinearGradient{gradient: gradient{from: vec{x0, y0}, to: vec{x1, y1}}}
|
lg := &LinearGradient{gradient: gradient{from: vec{x0, y0}, to: vec{x1, y1}}}
|
||||||
gli.GenTextures(1, &lg.tex)
|
gli.GenTextures(1, &lg.tex)
|
||||||
|
@ -43,6 +54,10 @@ func NewLinearGradient(x0, y0, x1, y1 float64) *LinearGradient {
|
||||||
return lg
|
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 {
|
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}
|
rg := &RadialGradient{gradient: gradient{from: vec{x0, y0}, to: vec{x1, y1}}, radFrom: r0, radTo: r1}
|
||||||
gli.GenTextures(1, &rg.tex)
|
gli.GenTextures(1, &rg.tex)
|
||||||
|
@ -59,8 +74,10 @@ func NewRadialGradient(x0, y0, r0, x1, y1, r1 float64) *RadialGradient {
|
||||||
return rg
|
return rg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete explicitly deletes the gradient
|
||||||
func (g *gradient) Delete() {
|
func (g *gradient) Delete() {
|
||||||
gli.DeleteTextures(1, &g.tex)
|
gli.DeleteTextures(1, &g.tex)
|
||||||
|
g.deleted = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *gradient) load() {
|
func (g *gradient) load() {
|
||||||
|
@ -113,6 +130,9 @@ func (g *gradient) colorAt(pos float64) glColor {
|
||||||
return c
|
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{}) {
|
func (g *gradient) AddColorStop(pos float64, color ...interface{}) {
|
||||||
c, _ := parseColor(color...)
|
c, _ := parseColor(color...)
|
||||||
insert := len(g.stops)
|
insert := len(g.stops)
|
||||||
|
|
|
@ -200,7 +200,7 @@ func (img *Image) Delete() {
|
||||||
img.deleted = true
|
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
|
// 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
|
// be loaded and cached, or a name string that corresponds to a previously
|
||||||
// loaded image with the same name parameter.
|
// loaded image with the same name parameter.
|
||||||
|
|
9
text.go
9
text.go
|
@ -15,6 +15,8 @@ import (
|
||||||
|
|
||||||
var fontRenderingContext = newFRContext()
|
var fontRenderingContext = newFRContext()
|
||||||
|
|
||||||
|
// Font is a loaded font that can be passed to the
|
||||||
|
// SetFont method
|
||||||
type Font struct {
|
type Font struct {
|
||||||
font *truetype.Font
|
font *truetype.Font
|
||||||
}
|
}
|
||||||
|
@ -25,6 +27,8 @@ var textImage *image.Alpha
|
||||||
|
|
||||||
var defaultFont *Font
|
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) {
|
func LoadFont(src interface{}) (*Font, error) {
|
||||||
var f *Font
|
var f *Font
|
||||||
switch v := src.(type) {
|
switch v := src.(type) {
|
||||||
|
@ -55,6 +59,8 @@ func LoadFont(src interface{}) (*Font, error) {
|
||||||
return f, nil
|
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) {
|
func (cv *Canvas) FillText(str string, x, y float64) {
|
||||||
cv.activate()
|
cv.activate()
|
||||||
|
|
||||||
|
@ -225,10 +231,13 @@ func (cv *Canvas) FillText(str string, x, y float64) {
|
||||||
gli.StencilFunc(gl_ALWAYS, 0, 0xFF)
|
gli.StencilFunc(gl_ALWAYS, 0, 0xFF)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TextMetrics is the result of a MeasureText call
|
||||||
type TextMetrics struct {
|
type TextMetrics struct {
|
||||||
Width float64
|
Width float64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MeasureText measures the given string using the
|
||||||
|
// current font and font height
|
||||||
func (cv *Canvas) MeasureText(str string) TextMetrics {
|
func (cv *Canvas) MeasureText(str string) TextMetrics {
|
||||||
if cv.state.font == nil {
|
if cv.state.font == nil {
|
||||||
return TextMetrics{}
|
return TextMetrics{}
|
||||||
|
|
Loading…
Reference in a new issue