zntg/ui/draw.go
Sander Schobers 239c24533d Some changes to UI elements.
- Added colors to palette and renamed white/black to lightest/darkest.
- Extracted drawing code.
- Restyled checkbox, spinner and scrollbar.
2018-08-07 10:13:05 +02:00

39 lines
936 B
Go

package ui
import (
"image"
"image/color"
"math"
"github.com/llgcode/draw2d/draw2dimg"
"opslag.de/schobers/galleg/allegro5"
)
func drawBitmap(w, h int, draw func(*draw2dimg.GraphicContext)) *allegro5.Bitmap {
dest := image.NewRGBA(image.Rect(0, 0, w, h))
gc := draw2dimg.NewGraphicContext(dest)
gc.SetFillColor(color.Transparent)
gc.Clear()
draw(gc)
bmp, err := allegro5.NewBitmapFromImage(dest, false)
if nil != err {
return nil
}
return bmp
}
func drawCircle(r, w int, startAngle, a float64, c color.Color) *allegro5.Bitmap {
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()
})
}