added checks that LoadGL is called before anything else is done
This commit is contained in:
parent
caaba150e8
commit
34c01f47d4
4 changed files with 16 additions and 1 deletions
|
@ -102,6 +102,9 @@ const (
|
||||||
// the origin, since GL uses the bottom left coordinate, the
|
// the origin, since GL uses the bottom left coordinate, the
|
||||||
// coordinates given here also use the bottom left as origin
|
// coordinates given here also use the bottom left as origin
|
||||||
func New(x, y, w, h int) *Canvas {
|
func New(x, y, w, h int) *Canvas {
|
||||||
|
if gli == nil {
|
||||||
|
panic("LoadGL must be called before a canvas can be created")
|
||||||
|
}
|
||||||
cv := &Canvas{stateStack: make([]drawState, 0, 20)}
|
cv := &Canvas{stateStack: make([]drawState, 0, 20)}
|
||||||
cv.SetBounds(x, y, w, h)
|
cv.SetBounds(x, y, w, h)
|
||||||
cv.state.lineWidth = 1
|
cv.state.lineWidth = 1
|
||||||
|
|
|
@ -40,6 +40,9 @@ type gradientStop struct {
|
||||||
// the coordinates from where to where the gradient
|
// the coordinates from where to where the gradient
|
||||||
// will apply on the canvas
|
// will apply on the canvas
|
||||||
func NewLinearGradient(x0, y0, x1, y1 float64) *LinearGradient {
|
func NewLinearGradient(x0, y0, x1, y1 float64) *LinearGradient {
|
||||||
|
if gli == nil {
|
||||||
|
panic("LoadGL must be called before gradients can be created")
|
||||||
|
}
|
||||||
lg := &LinearGradient{gradient: gradient{from: vec{x0, y0}, to: vec{x1, y1}, opaque: true}}
|
lg := &LinearGradient{gradient: gradient{from: vec{x0, y0}, to: vec{x1, y1}, opaque: true}}
|
||||||
gli.GenTextures(1, &lg.tex)
|
gli.GenTextures(1, &lg.tex)
|
||||||
gli.ActiveTexture(gl_TEXTURE0)
|
gli.ActiveTexture(gl_TEXTURE0)
|
||||||
|
@ -61,6 +64,9 @@ func NewLinearGradient(x0, y0, x1, y1 float64) *LinearGradient {
|
||||||
// gradient will apply from the first to the second
|
// gradient will apply from the first to the second
|
||||||
// circle
|
// circle
|
||||||
func NewRadialGradient(x0, y0, r0, x1, y1, r1 float64) *RadialGradient {
|
func NewRadialGradient(x0, y0, r0, x1, y1, r1 float64) *RadialGradient {
|
||||||
|
if gli == nil {
|
||||||
|
panic("LoadGL must be called before gradients can be created")
|
||||||
|
}
|
||||||
rg := &RadialGradient{gradient: gradient{from: vec{x0, y0}, to: vec{x1, y1}, opaque: true}, radFrom: r0, radTo: r1}
|
rg := &RadialGradient{gradient: gradient{from: vec{x0, y0}, to: vec{x1, y1}, opaque: true}, radFrom: r0, radTo: r1}
|
||||||
gli.GenTextures(1, &rg.tex)
|
gli.GenTextures(1, &rg.tex)
|
||||||
gli.ActiveTexture(gl_TEXTURE0)
|
gli.ActiveTexture(gl_TEXTURE0)
|
||||||
|
|
|
@ -24,6 +24,9 @@ var images = make(map[string]*Image)
|
||||||
// string. If you want the canvas package to load the image, make sure you
|
// string. If you want the canvas package to load the image, make sure you
|
||||||
// import the required format packages
|
// import the required format packages
|
||||||
func LoadImage(src interface{}) (*Image, error) {
|
func LoadImage(src interface{}) (*Image, error) {
|
||||||
|
if gli == nil {
|
||||||
|
panic("LoadGL must be called before images can be loaded")
|
||||||
|
}
|
||||||
var img *Image
|
var img *Image
|
||||||
var err error
|
var err error
|
||||||
switch v := src.(type) {
|
switch v := src.(type) {
|
||||||
|
|
5
text.go
5
text.go
|
@ -30,6 +30,9 @@ var defaultFont *Font
|
||||||
// LoadFont loads a font and returns the result. The font
|
// LoadFont loads a font and returns the result. The font
|
||||||
// can be a file name or a byte slice in TTF format
|
// can be a file name or a byte slice in TTF format
|
||||||
func LoadFont(src interface{}) (*Font, error) {
|
func LoadFont(src interface{}) (*Font, error) {
|
||||||
|
if gli == nil {
|
||||||
|
panic("LoadGL must be called before fonts can be loaded")
|
||||||
|
}
|
||||||
var f *Font
|
var f *Font
|
||||||
switch v := src.(type) {
|
switch v := src.(type) {
|
||||||
case *truetype.Font:
|
case *truetype.Font:
|
||||||
|
@ -392,7 +395,7 @@ func (cv *Canvas) MeasureText(str string) TextMetrics {
|
||||||
}
|
}
|
||||||
|
|
||||||
return TextMetrics{
|
return TextMetrics{
|
||||||
Width: x,
|
Width: x,
|
||||||
ActualBoundingBoxAscent: -minY,
|
ActualBoundingBoxAscent: -minY,
|
||||||
ActualBoundingBoxDescent: +maxY,
|
ActualBoundingBoxDescent: +maxY,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue