2018-08-07 05:03:52 +00:00
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"image"
|
|
|
|
"image/color"
|
|
|
|
"math"
|
|
|
|
|
|
|
|
"github.com/llgcode/draw2d/draw2dimg"
|
2018-09-22 14:23:26 +00:00
|
|
|
"opslag.de/schobers/zntg/allg5"
|
2018-08-07 05:03:52 +00:00
|
|
|
)
|
|
|
|
|
2018-09-22 14:23:26 +00:00
|
|
|
func drawBitmap(w, h int, draw func(*draw2dimg.GraphicContext)) *allg5.Bitmap {
|
2018-08-07 05:03:52 +00:00
|
|
|
dest := image.NewRGBA(image.Rect(0, 0, w, h))
|
|
|
|
gc := draw2dimg.NewGraphicContext(dest)
|
|
|
|
gc.SetFillColor(color.Transparent)
|
|
|
|
gc.Clear()
|
|
|
|
draw(gc)
|
2018-09-22 14:23:26 +00:00
|
|
|
bmp, err := allg5.NewBitmapFromImage(dest, false)
|
2018-08-07 05:03:52 +00:00
|
|
|
if nil != err {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return bmp
|
|
|
|
}
|
|
|
|
|
2018-09-22 14:23:26 +00:00
|
|
|
func drawCircle(r, w int, startAngle, a float64, c color.Color) *allg5.Bitmap {
|
2018-08-07 05:03:52 +00:00
|
|
|
var width = 2*r + w
|
|
|
|
return drawBitmap(width, width, func(gc *draw2dimg.GraphicContext) {
|
|
|
|
gc.SetFillColor(c)
|
|
|
|
gc.SetStrokeColor(c)
|
|
|
|
gc.SetLineWidth(float64(w))
|
|
|
|
var rad = float64(r)
|
|
|
|
var cnt = float64(width) * .5
|
|
|
|
var dx1, dy1 = cnt + math.Cos(startAngle)*rad, cnt + math.Sin(startAngle)*rad
|
|
|
|
gc.MoveTo(dx1, dy1)
|
|
|
|
gc.ArcTo(cnt, cnt, rad, rad, startAngle, a)
|
|
|
|
gc.Stroke()
|
|
|
|
})
|
|
|
|
}
|