示例#1
0
func (c *ColorWheel) Draw(self Widget, ctx *nanovgo.Context) {
	c.WidgetImplement.Draw(self, ctx)

	if !c.visible {
		return
	}
	x := float32(c.x)
	y := float32(c.y)
	w := float32(c.w)
	h := float32(c.h)

	ctx.Save()
	defer ctx.Restore()

	cx := x + w*0.5
	cy := y + h*0.5
	r1 := toF(w < h, w, h)*0.5 - 5.0
	r0 := r1 * 0.75

	aeps := 0.7 / r1 // half a pixel arc length in radians (2pi cancels out).
	for i := 0; i < 6; i++ {
		a0 := float32(i)/6.0*nanovgo.PI*2.0 - aeps
		a1 := float32(i+1)/6.0*nanovgo.PI*2.0 + aeps
		ctx.BeginPath()
		ctx.Arc(cx, cy, r0, a0, a1, nanovgo.Clockwise)
		ctx.Arc(cx, cy, r1, a1, a0, nanovgo.CounterClockwise)
		ctx.ClosePath()

		sin1, cos1 := sinCosF(a0)
		sin2, cos2 := sinCosF(a1)
		ax := cx + cos1*(r0+r1)*0.5
		ay := cy + sin1*(r0+r1)*0.5
		bx := cx + cos2*(r0+r1)*0.5
		by := cy + sin2*(r0+r1)*0.5
		color1 := nanovgo.HSLA(a0/(nanovgo.PI*2), 1.0, 0.55, 255)
		color2 := nanovgo.HSLA(a1/(nanovgo.PI*2), 1.0, 0.55, 255)
		paint := nanovgo.LinearGradient(ax, ay, bx, by, color1, color2)
		ctx.SetFillPaint(paint)
		ctx.Fill()
	}

	ctx.BeginPath()
	ctx.Circle(cx, cy, r0-0.5)
	ctx.Circle(cx, cy, r1+0.5)
	ctx.SetStrokeColor(nanovgo.MONO(0, 64))
	ctx.Stroke()

	// Selector
	ctx.Save()
	defer ctx.Restore()
	ctx.Translate(cx, cy)
	ctx.Rotate(c.hue * nanovgo.PI * 2)

	// Marker on
	u := clampF(r1/50, 1.5, 4.0)
	ctx.SetStrokeWidth(u)
	ctx.BeginPath()
	ctx.Rect(r0-1, -2*u, r1-r0+2, 4*u)
	ctx.SetStrokeColor(nanovgo.MONO(255, 192))
	ctx.Stroke()

	paint := nanovgo.BoxGradient(r0-3, -5, r1-r0+6, 10, 2, 4, nanovgo.MONO(0, 128), nanovgo.MONO(0, 0))
	ctx.BeginPath()
	ctx.Rect(r0-2-10, -4-10, r1-r0+4+20, 8+20)
	ctx.Rect(r0-2, -4, r1-r0+4, 8)
	ctx.PathWinding(nanovgo.Hole)
	ctx.SetFillPaint(paint)
	ctx.Fill()

	// Center triangle
	r := r0 - 6
	sin1, cos1 := sinCosF(120.0 / 180.0 * nanovgo.PI)
	sin2, cos2 := sinCosF(-120.0 / 180.0 * nanovgo.PI)
	ax := cos1 * r
	ay := sin1 * r
	bx := cos2 * r
	by := sin2 * r
	ctx.BeginPath()
	ctx.MoveTo(r, 0)
	ctx.LineTo(ax, ay)
	ctx.LineTo(bx, by)
	ctx.ClosePath()
	triPaint1 := nanovgo.LinearGradient(r, 0, ax, ay, nanovgo.HSL(c.hue, 1.0, 0.5), nanovgo.MONO(255, 255))
	ctx.SetFillPaint(triPaint1)
	ctx.Fill()
	triPaint2 := nanovgo.LinearGradient((r+ax)*0.5, ay*0.5, bx, by, nanovgo.MONO(0, 0), nanovgo.MONO(0, 255))
	ctx.SetFillPaint(triPaint2)
	ctx.Fill()

	// selector circle on triangle
	px, py := c.calculatePosition()
	ctx.SetStrokeWidth(u)
	ctx.BeginPath()
	ctx.Circle(px, py, 2*u)
	ctx.SetStrokeColor(nanovgo.MONO(255, 192))
	ctx.Stroke()
}
示例#2
0
func (c *ColorWheel) Color() nanovgo.Color {
	return nanovgo.HSL(c.hue, c.saturation, c.lightness)
}