canvas/examples/ios/ios.go
2018-05-17 15:16:50 +02:00

41 lines
765 B
Go

package example
import (
"math"
"time"
"github.com/tfriedel6/canvas"
"github.com/tfriedel6/canvas/glimpl/ios"
)
var cv *canvas.Canvas
var mx, my float64
func TouchEvent(typ string, x, y int) {
mx, my = float64(x), float64(y)
}
func LoadGL(w, h int) {
err := canvas.LoadGL(glimplios.GLImpl{})
if err != nil {
time.Sleep(100 * time.Millisecond)
panic(err)
}
cv = canvas.New(0, 0, w, h)
}
func DrawFrame() {
if cv == nil {
return
}
w, h := float64(cv.Width()), float64(cv.Height())
cv.SetFillStyle("#000")
cv.FillRect(0, 0, w, h)
cv.SetFillStyle("#0F0")
cv.FillRect(w*0.25, h*0.25, w*0.5, h*0.5)
cv.SetLineWidth(6)
sqrSize := math.Min(w, h) * 0.1
cv.SetStrokeStyle("#F00")
cv.StrokeRect(mx-sqrSize/2, my-sqrSize/2, sqrSize, sqrSize)
}