Ejemplo n.º 1
0
func drawDropDown(ctx *nanovgo.Context, text string, x, y, w, h float32) {

	var cornerRadius float32 = 4.0

	bg := nanovgo.LinearGradient(x, y, x, y+h, nanovgo.RGBA(255, 255, 255, 16), nanovgo.RGBA(0, 0, 0, 16))
	ctx.BeginPath()
	ctx.RoundedRect(x+1, y+1, w-2, h-2, cornerRadius-1)
	ctx.SetFillPaint(bg)
	ctx.Fill()

	ctx.BeginPath()
	ctx.RoundedRect(x+0.5, y+0.5, w-1, h-1, cornerRadius-0.5)
	ctx.SetStrokeColor(nanovgo.RGBA(0, 0, 0, 48))
	ctx.Stroke()

	ctx.SetFontSize(20.0)
	ctx.SetFontFace("sans")
	ctx.SetFillColor(nanovgo.RGBA(255, 255, 255, 160))
	ctx.SetTextAlign(nanovgo.AlignLeft | nanovgo.AlignMiddle)
	ctx.Text(x+h*0.3, y+h*0.5, text)

	ctx.SetFontSize(h * 1.3)
	ctx.SetFontFace("icons")
	ctx.SetFillColor(nanovgo.RGBA(255, 255, 255, 64))
	ctx.SetTextAlign(nanovgo.AlignCenter | nanovgo.AlignMiddle)
	ctx.Text(x+w-h*0.5, y+h*0.5, cpToUTF8(IconCHEVRONRIGHT))
}
Ejemplo n.º 2
0
func drawButton(ctx *nanovgo.Context, preicon int, text string, x, y, w, h float32, col nanovgo.Color) {
	var cornerRadius float32 = 4.0
	var iw float32

	var alpha uint8
	if isBlack(col) {
		alpha = 16
	} else {
		alpha = 32
	}
	bg := nanovgo.LinearGradient(x, y, x, y+h, nanovgo.RGBA(255, 255, 255, alpha), nanovgo.RGBA(0, 0, 0, alpha))
	ctx.BeginPath()
	ctx.RoundedRect(x+1, y+1, w-2, h-2, cornerRadius-1)
	if !isBlack(col) {
		ctx.SetFillColor(col)
		ctx.Fill()
	}
	ctx.SetFillPaint(bg)
	ctx.Fill()

	ctx.BeginPath()
	ctx.RoundedRect(x+0.5, y+0.5, w-1, h-1, cornerRadius-0.5)
	ctx.SetStrokeColor(nanovgo.RGBA(0, 0, 0, 48))
	ctx.Stroke()

	ctx.SetFontSize(20.0)
	ctx.SetFontFace("sans-bold")
	tw, _ := ctx.TextBounds(0, 0, text)
	if preicon != 0 {
		ctx.SetFontSize(h * 1.3)
		ctx.SetFontFace("icons")
		iw, _ = ctx.TextBounds(0, 0, cpToUTF8(preicon))
		iw += h * 0.15

		ctx.SetFillColor(nanovgo.RGBA(255, 255, 255, 96))
		ctx.SetTextAlign(nanovgo.AlignLeft | nanovgo.AlignMiddle)
		ctx.Text(x+w*0.5-tw*0.5-iw*0.75, y+h*0.5, cpToUTF8(preicon))
	}

	ctx.SetFontSize(20.0)
	ctx.SetFontFace("sans-bold")
	ctx.SetTextAlign(nanovgo.AlignLeft | nanovgo.AlignMiddle)
	ctx.SetFillColor(nanovgo.RGBA(0, 0, 0, 160))
	ctx.Text(x+w*0.5-tw*0.5+iw*0.25, y+h*0.5-1, text)
	ctx.SetFillColor(nanovgo.RGBA(255, 255, 255, 160))
	ctx.Text(x+w*0.5-tw*0.5+iw*0.25, y+h*0.5, text)
}
Ejemplo n.º 3
0
func drawWindow(ctx *nanovgo.Context, title string, x, y, w, h float32) {
	var cornerRadius float32 = 3.0

	ctx.Save()
	defer ctx.Restore()
	//      ctx.Reset();

	// Window
	ctx.BeginPath()
	ctx.RoundedRect(x, y, w, h, cornerRadius)
	ctx.SetFillColor(nanovgo.RGBA(28, 30, 34, 192))
	//      ctx.FillColor(nanovgo.RGBA(0,0,0,128));
	ctx.Fill()

	// Drop shadow
	shadowPaint := nanovgo.BoxGradient(x, y+2, w, h, cornerRadius*2, 10, nanovgo.RGBA(0, 0, 0, 128), nanovgo.RGBA(0, 0, 0, 0))
	ctx.BeginPath()
	ctx.Rect(x-10, y-10, w+20, h+30)
	ctx.RoundedRect(x, y, w, h, cornerRadius)
	ctx.PathWinding(nanovgo.Hole)
	ctx.SetFillPaint(shadowPaint)
	ctx.Fill()

	// Header
	headerPaint := nanovgo.LinearGradient(x, y, x, y+15, nanovgo.RGBA(255, 255, 255, 8), nanovgo.RGBA(0, 0, 0, 16))
	ctx.BeginPath()
	ctx.RoundedRect(x+1, y+1, w-2, 30, cornerRadius-1)
	ctx.SetFillPaint(headerPaint)
	ctx.Fill()
	ctx.BeginPath()
	ctx.MoveTo(x+0.5, y+0.5+30)
	ctx.LineTo(x+0.5+w-1, y+0.5+30)
	ctx.SetStrokeColor(nanovgo.RGBA(0, 0, 0, 32))
	ctx.Stroke()

	ctx.SetFontSize(18.0)
	ctx.SetFontFace("sans-bold")
	ctx.SetTextAlign(nanovgo.AlignCenter | nanovgo.AlignMiddle)

	ctx.SetFontBlur(2)
	ctx.SetFillColor(nanovgo.RGBA(0, 0, 0, 128))
	ctx.Text(x+w/2, y+16+1, title)

	ctx.SetFontBlur(0)
	ctx.SetFillColor(nanovgo.RGBA(220, 220, 220, 160))
	ctx.Text(x+w/2, y+16, title)
}
Ejemplo n.º 4
0
func drawSpinner(ctx *nanovgo.Context, cx, cy, r, t float32) {
	a0 := 0.0 + t*6
	a1 := nanovgo.PI + t*6
	r0 := r
	r1 := r * 0.75

	ctx.Save()
	defer ctx.Restore()

	ctx.BeginPath()
	ctx.Arc(cx, cy, r0, a0, a1, nanovgo.Clockwise)
	ctx.Arc(cx, cy, r1, a1, a0, nanovgo.CounterClockwise)
	ctx.ClosePath()
	ax := cx + cosF(a0)*(r0+r1)*0.5
	ay := cy + sinF(a0)*(r0+r1)*0.5
	bx := cx + cosF(a1)*(r0+r1)*0.5
	by := cy + sinF(a1)*(r0+r1)*0.5
	paint := nanovgo.LinearGradient(ax, ay, bx, by, nanovgo.RGBA(0, 0, 0, 0), nanovgo.RGBA(0, 0, 0, 128))
	ctx.SetFillPaint(paint)
	ctx.Fill()
}
Ejemplo n.º 5
0
func drawSlider(ctx *nanovgo.Context, pos, x, y, w, h float32) {
	cy := y + float32(int(h*0.5))
	kr := float32(int(h * 0.25))

	ctx.Save()
	defer ctx.Restore()
	//      ctx.ClearState(vg);

	// Slot
	bg := nanovgo.BoxGradient(x, cy-2+1, w, 4, 2, 2, nanovgo.RGBA(0, 0, 0, 32), nanovgo.RGBA(0, 0, 0, 128))
	ctx.BeginPath()
	ctx.RoundedRect(x, cy-2, w, 4, 2)
	ctx.SetFillPaint(bg)
	ctx.Fill()

	// Knob Shadow
	bg = nanovgo.RadialGradient(x+float32(int(pos*w)), cy+1, kr-3, kr+3, nanovgo.RGBA(0, 0, 0, 64), nanovgo.RGBA(0, 0, 0, 0))
	ctx.BeginPath()
	ctx.Rect(x+float32(int(pos*w))-kr-5, cy-kr-5, kr*2+5+5, kr*2+5+5+3)
	ctx.Circle(x+float32(int(pos*w)), cy, kr)
	ctx.PathWinding(nanovgo.Hole)
	ctx.SetFillPaint(bg)
	ctx.Fill()

	// Knob
	knob := nanovgo.LinearGradient(x, cy-kr, x, cy+kr, nanovgo.RGBA(255, 255, 255, 16), nanovgo.RGBA(0, 0, 0, 16))
	ctx.BeginPath()
	ctx.Circle(x+float32(int(pos*w)), cy, kr-1)
	ctx.SetFillColor(nanovgo.RGBA(40, 43, 48, 255))
	ctx.Fill()
	ctx.SetFillPaint(knob)
	ctx.Fill()

	ctx.BeginPath()
	ctx.Circle(x+float32(int(pos*w)), cy, kr-0.5)
	ctx.SetStrokeColor(nanovgo.RGBA(0, 0, 0, 92))
	ctx.Stroke()
}
Ejemplo n.º 6
0
func (w *Window) Draw(self Widget, ctx *nanovgo.Context) {
	ds := float32(w.theme.WindowDropShadowSize)
	cr := float32(w.theme.WindowCornerRadius)
	hh := float32(w.theme.WindowHeaderHeight)

	// Draw window
	wx := float32(w.x)
	wy := float32(w.y)
	ww := float32(w.w)
	wh := float32(w.h)
	ctx.Save()
	ctx.BeginPath()
	ctx.RoundedRect(wx, wy, ww, wh, cr)
	if w.mouseFocus {
		ctx.SetFillColor(w.theme.WindowFillFocused)
	} else {
		ctx.SetFillColor(w.theme.WindowFillUnfocused)
	}
	ctx.Fill()

	// Draw a drop shadow
	shadowPaint := nanovgo.BoxGradient(wx, wy, ww, wh, cr*2, ds*2, w.theme.DropShadow, w.theme.Transparent)
	ctx.BeginPath()
	ctx.Rect(wx-ds, wy-ds, ww+ds*2, wh+ds*2)
	ctx.RoundedRect(wx, wy, ww, wh, cr)
	ctx.PathWinding(nanovgo.Hole)
	ctx.SetFillPaint(shadowPaint)
	ctx.Fill()

	if w.title != "" {
		headerPaint := nanovgo.LinearGradient(wx, wy, ww, wh+hh, w.theme.WindowHeaderGradientTop, w.theme.WindowHeaderGradientBot)

		ctx.BeginPath()
		ctx.RoundedRect(wx, wy, ww, hh, cr)
		ctx.SetFillPaint(headerPaint)
		ctx.Fill()

		ctx.BeginPath()
		ctx.RoundedRect(wx, wy, ww, wh, cr)
		ctx.SetStrokeColor(w.theme.WindowHeaderSepTop)
		ctx.Scissor(wx, wy, ww, 0.5)
		ctx.Stroke()
		ctx.ResetScissor()

		ctx.BeginPath()
		ctx.MoveTo(wx+0.5, wy+hh-1.5)
		ctx.LineTo(wx+ww-0.5, wy+hh-1.5)
		ctx.SetStrokeColor(w.theme.WindowHeaderSepTop)
		ctx.Stroke()

		ctx.SetFontSize(18.0)
		ctx.SetFontFace(w.theme.FontBold)
		ctx.SetTextAlign(nanovgo.AlignCenter | nanovgo.AlignMiddle)
		ctx.SetFontBlur(2.0)
		ctx.SetFillColor(w.theme.DropShadow)
		ctx.Text(wx+ww*0.5, wy+hh*0.5, w.title)
		ctx.SetFontBlur(0.0)
		if w.focused {
			ctx.SetFillColor(w.theme.WindowTitleFocused)
		} else {
			ctx.SetFillColor(w.theme.WindowTitleUnfocused)
		}
		ctx.Text(wx+ww*0.5, wy+hh*0.5-1, w.title)
	}
	ctx.Restore()
	w.WidgetImplement.Draw(self, ctx)
}
Ejemplo n.º 7
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()
}
Ejemplo n.º 8
0
func drawColorWheel(ctx *nanovgo.Context, x, y, w, h, t float32) {
	var r0, r1, ax, ay, bx, by, aeps, r float32
	hue := sinF(t * 0.12)

	ctx.Save()
	defer ctx.Restore()
	/*      ctx.BeginPath()
	ctx.Rect(x,y,w,h)
	ctx.FillColor(nanovgo.RGBA(255,0,0,128))
	ctx.Fill()*/

	cx := x + w*0.5
	cy := y + h*0.5
	if w < h {
		r1 = w*0.5 - 5.0
	} else {
		r1 = h*0.5 - 5.0
	}
	r0 = r1 - 20.0
	aeps = 0.5 / 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.0)/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()
		ax = cx + cosF(a0)*(r0+r1)*0.5
		ay = cy + sinF(a0)*(r0+r1)*0.5
		bx = cx + cosF(a1)*(r0+r1)*0.5
		by = cy + sinF(a1)*(r0+r1)*0.5
		paint := nanovgo.LinearGradient(ax, ay, bx, by, nanovgo.HSLA(a0/(nanovgo.PI*2), 1.0, 0.55, 255), nanovgo.HSLA(a1/(nanovgo.PI*2), 1.0, 0.55, 255))
		ctx.SetFillPaint(paint)
		ctx.Fill()
	}

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

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

	// Marker on
	ctx.SetStrokeWidth(2.0)
	ctx.BeginPath()
	ctx.Rect(r0-1, -3, r1-r0+2, 6)
	ctx.SetStrokeColor(nanovgo.RGBA(255, 255, 255, 192))
	ctx.Stroke()

	paint := nanovgo.BoxGradient(r0-3, -5, r1-r0+6, 10, 2, 4, nanovgo.RGBA(0, 0, 0, 128), nanovgo.RGBA(0, 0, 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
	ax = cosF(120.0/180.0*nanovgo.PI) * r
	ay = sinF(120.0/180.0*nanovgo.PI) * r
	bx = cosF(-120.0/180.0*nanovgo.PI) * r
	by = sinF(-120.0/180.0*nanovgo.PI) * r
	ctx.BeginPath()
	ctx.MoveTo(r, 0)
	ctx.LineTo(ax, ay)
	ctx.LineTo(bx, by)
	ctx.ClosePath()
	paint = nanovgo.LinearGradient(r, 0, ax, ay, nanovgo.HSLA(hue, 1.0, 0.5, 255), nanovgo.RGBA(255, 255, 255, 255))
	ctx.SetFillPaint(paint)
	ctx.Fill()
	paint = nanovgo.LinearGradient((r+ax)*0.5, (0+ay)*0.5, bx, by, nanovgo.RGBA(0, 0, 0, 0), nanovgo.RGBA(0, 0, 0, 255))
	ctx.SetFillPaint(paint)
	ctx.Fill()
	ctx.SetStrokeColor(nanovgo.RGBA(0, 0, 0, 64))
	ctx.Stroke()

	// Select circle on triangle
	ax = cosF(120.0/180.0*nanovgo.PI) * r * 0.3
	ay = sinF(120.0/180.0*nanovgo.PI) * r * 0.4
	ctx.SetStrokeWidth(2.0)
	ctx.BeginPath()
	ctx.Circle(ax, ay, 5)
	ctx.SetStrokeColor(nanovgo.RGBA(255, 255, 255, 192))
	ctx.Stroke()

	paint = nanovgo.RadialGradient(ax, ay, 7, 9, nanovgo.RGBA(0, 0, 0, 64), nanovgo.RGBA(0, 0, 0, 0))
	ctx.BeginPath()
	ctx.Rect(ax-20, ay-20, 40, 40)
	ctx.Circle(ax, ay, 7)
	ctx.PathWinding(nanovgo.Hole)
	ctx.SetFillPaint(paint)
	ctx.Fill()
}
Ejemplo n.º 9
0
func drawThumbnails(ctx *nanovgo.Context, x, y, w, h float32, images []int, t float32) {
	var cornerRadius float32 = 3.0

	var thumb float32 = 60.0
	var arry float32 = 30.5
	stackh := float32(len(images)/2)*(thumb+10) + 10
	u := (1 + cosF(t*0.5)) * 0.5
	u2 := (1 - cosF(t*0.2)) * 0.5

	ctx.Save()
	defer ctx.Restore()

	// Drop shadow
	shadowPaint := nanovgo.BoxGradient(x, y+4, w, h, cornerRadius*2, 20, nanovgo.RGBA(0, 0, 0, 128), nanovgo.RGBA(0, 0, 0, 0))
	ctx.BeginPath()
	ctx.Rect(x-10, y-10, w+20, h+30)
	ctx.RoundedRect(x, y, w, h, cornerRadius)
	ctx.PathWinding(nanovgo.Hole)
	ctx.SetFillPaint(shadowPaint)
	ctx.Fill()

	// Window
	ctx.BeginPath()
	ctx.RoundedRect(x, y, w, h, cornerRadius)
	ctx.MoveTo(x-10, y+arry)
	ctx.LineTo(x+1, y+arry-11)
	ctx.LineTo(x+1, y+arry+11)
	ctx.SetFillColor(nanovgo.RGBA(200, 200, 200, 255))
	ctx.Fill()

	ctx.Block(func() {
		ctx.Scissor(x, y, w, h)
		ctx.Translate(0, -(stackh-h)*u)

		dv := 1.0 / float32(len(images)-1)

		for i, imageID := range images {
			tx := x + 10.0
			ty := y + 10.0
			tx += float32(i%2) * (thumb + 10.0)
			ty += float32(i/2) * (thumb + 10.0)
			imgW, imgH, _ := ctx.ImageSize(imageID)
			var iw, ih, ix, iy float32
			if imgW < imgH {
				iw = thumb
				ih = iw * float32(imgH) / float32(imgW)
				ix = 0
				iy = -(ih - thumb) * 0.5
			} else {
				ih = thumb
				iw = ih * float32(imgW) / float32(imgH)
				ix = -(iw - thumb) * 0.5
				iy = 0
			}

			v := float32(i) * dv
			a := clampF((u2-v)/dv, 0, 1)

			if a < 1.0 {
				drawSpinner(ctx, tx+thumb/2, ty+thumb/2, thumb*0.25, t)
			}

			imgPaint := nanovgo.ImagePattern(tx+ix, ty+iy, iw, ih, 0.0/180.0*nanovgo.PI, imageID, a)
			ctx.BeginPath()
			ctx.RoundedRect(tx, ty, thumb, thumb, 5)
			ctx.SetFillPaint(imgPaint)
			ctx.Fill()

			shadowPaint := nanovgo.BoxGradient(tx-1, ty, thumb+2, thumb+2, 5, 3, nanovgo.RGBA(0, 0, 0, 128), nanovgo.RGBA(0, 0, 0, 0))
			ctx.BeginPath()
			ctx.Rect(tx-5, ty-5, thumb+10, thumb+10)
			ctx.RoundedRect(tx, ty, thumb, thumb, 6)
			ctx.PathWinding(nanovgo.Hole)
			ctx.SetFillPaint(shadowPaint)
			ctx.Fill()

			ctx.BeginPath()
			ctx.RoundedRect(tx+0.5, ty+0.5, thumb-1, thumb-1, 4-0.5)
			ctx.SetStrokeWidth(1.0)
			ctx.SetStrokeColor(nanovgo.RGBA(255, 255, 255, 192))
			ctx.Stroke()
		}
	})

	// Hide fades
	fadePaint := nanovgo.LinearGradient(x, y, x, y+6, nanovgo.RGBA(200, 200, 200, 255), nanovgo.RGBA(200, 200, 200, 0))
	ctx.BeginPath()
	ctx.Rect(x+4, y, w-8, 6)
	ctx.SetFillPaint(fadePaint)
	ctx.Fill()

	fadePaint = nanovgo.LinearGradient(x, y+h, x, y+h-6, nanovgo.RGBA(200, 200, 200, 255), nanovgo.RGBA(200, 200, 200, 0))
	ctx.BeginPath()
	ctx.Rect(x+4, y+h-6, w-8, 6)
	ctx.SetFillPaint(fadePaint)
	ctx.Fill()

	// Scroll bar
	shadowPaint = nanovgo.BoxGradient(x+w-12+1, y+4+1, 8, h-8, 3, 4, nanovgo.RGBA(0, 0, 0, 32), nanovgo.RGBA(0, 0, 0, 92))
	ctx.BeginPath()
	ctx.RoundedRect(x+w-12, y+4, 8, h-8, 3)
	ctx.SetFillPaint(shadowPaint)
	//      ctx.FillColor(ctx.RGBA(255,0,0,128));
	ctx.Fill()

	scrollH := (h / stackh) * (h - 8)
	shadowPaint = nanovgo.BoxGradient(x+w-12-1, y+4+(h-8-scrollH)*u-1, 8, scrollH, 3, 4, nanovgo.RGBA(220, 220, 220, 255), nanovgo.RGBA(128, 128, 128, 255))
	ctx.BeginPath()
	ctx.RoundedRect(x+w-12+1, y+4+1+(h-8-scrollH)*u, 8-2, scrollH-2, 2)
	ctx.SetFillPaint(shadowPaint)
	//      ctx.FillColor(ctx.RGBA(0,0,0,128));
	ctx.Fill()
}
Ejemplo n.º 10
0
func drawGraph(ctx *nanovgo.Context, x, y, w, h, t float32) {
	var sx, sy [6]float32
	dx := w / 5.0

	samples := []float32{
		(1 + sinF(t*1.2345+cosF(t*0.33457)*0.44)) * 0.5,
		(1 + sinF(t*0.68363+cosF(t*1.3)*1.55)) * 0.5,
		(1 + sinF(t*1.1642+cosF(t*0.33457)*1.24)) * 0.5,
		(1 + sinF(t*0.56345+cosF(t*1.63)*0.14)) * 0.5,
		(1 + sinF(t*1.6245+cosF(t*0.254)*0.3)) * 0.5,
		(1 + sinF(t*0.345+cosF(t*0.03)*0.6)) * 0.5,
	}

	for i := 0; i < 6; i++ {
		sx[i] = x + float32(i)*dx
		sy[i] = y + h*samples[i]*0.8
	}

	// Graph background
	bg := nanovgo.LinearGradient(x, y, x, y+h, nanovgo.RGBA(0, 160, 192, 0), nanovgo.RGBA(0, 160, 192, 64))
	ctx.BeginPath()
	ctx.MoveTo(sx[0], sy[0])
	for i := 1; i < 6; i++ {
		ctx.BezierTo(sx[i-1]+dx*0.5, sy[i-1], sx[i]-dx*0.5, sy[i], sx[i], sy[i])
	}
	ctx.LineTo(x+w, y+h)
	ctx.LineTo(x, y+h)
	ctx.SetFillPaint(bg)
	ctx.Fill()

	// Graph line
	ctx.BeginPath()
	ctx.MoveTo(sx[0], sy[0]+2)
	for i := 1; i < 6; i++ {
		ctx.BezierTo(sx[i-1]+dx*0.5, sy[i-1]+2, sx[i]-dx*0.5, sy[i]+2, sx[i], sy[i]+2)
	}
	ctx.SetStrokeColor(nanovgo.RGBA(0, 0, 0, 32))
	ctx.SetStrokeWidth(3.0)
	ctx.Stroke()

	ctx.BeginPath()
	ctx.MoveTo(sx[0], sy[0])
	for i := 1; i < 6; i++ {
		ctx.BezierTo(sx[i-1]+dx*0.5, sy[i-1], sx[i]-dx*0.5, sy[i], sx[i], sy[i])
	}
	ctx.SetStrokeColor(nanovgo.RGBA(0, 160, 192, 255))
	ctx.SetStrokeWidth(3.0)
	ctx.Stroke()

	// Graph sample pos
	for i := 0; i < 6; i++ {
		bg = nanovgo.RadialGradient(sx[i], sy[i]+2, 3.0, 8.0, nanovgo.RGBA(0, 0, 0, 32), nanovgo.RGBA(0, 0, 0, 0))
		ctx.BeginPath()
		ctx.Rect(sx[i]-10, sy[i]-10+2, 20, 20)
		ctx.SetFillPaint(bg)
		ctx.Fill()
	}

	ctx.BeginPath()
	for i := 0; i < 6; i++ {
		ctx.Circle(sx[i], sy[i], 4.0)
	}
	ctx.SetFillColor(nanovgo.RGBA(0, 160, 192, 255))
	ctx.Fill()
	ctx.BeginPath()
	for i := 0; i < 6; i++ {
		ctx.Circle(sx[i], sy[i], 2.0)
	}
	ctx.SetFillColor(nanovgo.RGBA(220, 220, 220, 255))
	ctx.Fill()

	ctx.SetStrokeWidth(1.0)
}
Ejemplo n.º 11
0
func drawEyes(ctx *nanovgo.Context, x, y, w, h, mx, my, t float32) {
	ex := w * 0.23
	ey := h * 0.5
	lx := x + ex
	ly := y + ey
	rx := x + w - ex
	ry := y + ey
	var dx, dy, d, br float32
	if ex < ey {
		br = ex * 0.5
	} else {
		br = ey * 0.5
	}
	blink := float32(1.0 - math.Pow(float64(sinF(t*0.5)), 200)*0.8)

	bg1 := nanovgo.LinearGradient(x, y+h*0.5, x+w*0.1, y+h, nanovgo.RGBA(0, 0, 0, 32), nanovgo.RGBA(0, 0, 0, 16))
	ctx.BeginPath()
	ctx.Ellipse(lx+3.0, ly+16.0, ex, ey)
	ctx.Ellipse(rx+3.0, ry+16.0, ex, ey)
	ctx.SetFillPaint(bg1)
	ctx.Fill()

	bg2 := nanovgo.LinearGradient(x, y+h*0.25, x+w*0.1, y+h, nanovgo.RGBA(220, 220, 220, 255), nanovgo.RGBA(128, 128, 128, 255))
	ctx.BeginPath()
	ctx.Ellipse(lx, ly, ex, ey)
	ctx.Ellipse(rx, ry, ex, ey)
	ctx.SetFillPaint(bg2)
	ctx.Fill()

	dx = (mx - rx) / (ex * 10)
	dy = (my - ry) / (ey * 10)
	d = sqrtF(dx*dx + dy*dy)
	if d > 1.0 {
		dx /= d
		dy /= d
	}
	dx *= ex * 0.4
	dy *= ey * 0.5
	ctx.BeginPath()
	ctx.Ellipse(lx+dx, ly+dy+ey*0.25*(1.0-blink), br, br*blink)
	ctx.SetFillColor(nanovgo.RGBA(32, 32, 32, 255))
	ctx.Fill()

	dx = (mx - rx) / (ex * 10)
	dy = (my - ry) / (ey * 10)
	d = sqrtF(dx*dx + dy*dy)
	if d > 1.0 {
		dx /= d
		dy /= d
	}
	dx *= ex * 0.4
	dy *= ey * 0.5
	ctx.BeginPath()
	ctx.Ellipse(rx+dx, ry+dy+ey*0.25*(1.0-blink), br, br*blink)
	ctx.SetFillColor(nanovgo.RGBA(32, 32, 32, 255))
	ctx.Fill()
	dx = (mx - rx) / (ex * 10)
	dy = (my - ry) / (ey * 10)
	d = sqrtF(dx*dx + dy*dy)
	if d > 1.0 {
		dx /= d
		dy /= d
	}
	dx *= ex * 0.4
	dy *= ey * 0.5
	ctx.BeginPath()
	ctx.Ellipse(rx+dx, ry+dy+ey*0.25*(1.0-blink), br, br*blink)
	ctx.SetFillColor(nanovgo.RGBA(32, 32, 32, 255))
	ctx.Fill()

	gloss1 := nanovgo.RadialGradient(lx-ex*0.25, ly-ey*0.5, ex*0.1, ex*0.75, nanovgo.RGBA(255, 255, 255, 128), nanovgo.RGBA(255, 255, 255, 0))
	ctx.BeginPath()
	ctx.Ellipse(lx, ly, ex, ey)
	ctx.SetFillPaint(gloss1)
	ctx.Fill()

	gloss2 := nanovgo.RadialGradient(rx-ex*0.25, ry-ey*0.5, ex*0.1, ex*0.75, nanovgo.RGBA(255, 255, 255, 128), nanovgo.RGBA(255, 255, 255, 0))
	ctx.BeginPath()
	ctx.Ellipse(rx, ry, ex, ey)
	ctx.SetFillPaint(gloss2)
	ctx.Fill()
}
Ejemplo n.º 12
0
func (b *Button) Draw(self Widget, ctx *nanovgo.Context) {
	b.WidgetImplement.Draw(self, ctx)

	bx := float32(b.x)
	by := float32(b.y)
	bw := float32(b.w)
	bh := float32(b.h)

	var gradTop nanovgo.Color
	var gradBot nanovgo.Color

	if b.pushed {
		gradTop = b.theme.ButtonGradientTopPushed
		gradBot = b.theme.ButtonGradientBotPushed
	} else if b.mouseFocus && b.enabled {
		gradTop = b.theme.ButtonGradientTopFocused
		gradBot = b.theme.ButtonGradientBotFocused
	} else {
		gradTop = b.theme.ButtonGradientTopUnfocused
		gradBot = b.theme.ButtonGradientBotUnfocused
	}
	ctx.BeginPath()
	ctx.RoundedRect(bx+1.0, by+1.0, bw-2.0, bh-2.0, float32(b.theme.ButtonCornerRadius-1))

	if b.backgroundColor.A != 0.0 {
		bgColor := b.backgroundColor
		bgColor.A = 1.0
		ctx.SetFillColor(bgColor)
		ctx.Fill()
		if b.pushed {
			gradTop.A = 0.8
			gradBot.A = 0.8
		} else {
			a := 1 - b.backgroundColor.A
			if !b.enabled {
				a = a*0.5 + 0.5
			}
			gradTop.A = a
			gradBot.A = a
		}
	}

	bg := nanovgo.LinearGradient(bx, by, bx, by+bh, gradTop, gradBot)
	ctx.SetFillPaint(bg)
	ctx.Fill()

	ctx.BeginPath()
	var pOff float32 = 0.0
	if b.pushed {
		pOff = 1.0
	}
	ctx.RoundedRect(bx+0.5, by+1.5-pOff, bw-1.0, bh-2+pOff, float32(b.theme.ButtonCornerRadius))
	ctx.SetStrokeColor(b.theme.BorderLight)
	ctx.Stroke()

	ctx.BeginPath()
	ctx.RoundedRect(bx+0.5, by+0.5, bw-1.0, bh-2, float32(b.theme.ButtonCornerRadius))
	ctx.SetStrokeColor(b.theme.BorderDark)
	ctx.Stroke()

	fontSize := float32(b.FontSize())
	ctx.SetFontSize(fontSize)
	ctx.SetFontFace(b.theme.FontBold)
	caption := b.caption
	tw, _ := ctx.TextBounds(0, 0, caption)

	centerX := bx + bw*0.5
	centerY := by + bh*0.5
	textPosX := centerX - tw*0.5
	textPosY := centerY - 1.0

	textColor := b.TextColor()
	if b.icon > 0 || b.imageIcon > 0 {
		var iw, ih float32
		if b.icon > 0 {
			ih = fontSize * 1.5 / 2
			ctx.SetFontSize(ih)
			ctx.SetFontFace(b.theme.FontIcons)
			iw, _ = ctx.TextBounds(0, 0, string([]rune{rune(b.icon)}))
		} else if b.imageIcon > 0 {
			ih = fontSize * 0.9
			w, h, _ := ctx.ImageSize(b.imageIcon)
			iw = float32(w) * ih / float32(h)
		}
		if b.caption != "" {
			iw += float32(b.h) * 0.15
		}
		ctx.SetFillColor(textColor)
		ctx.SetTextAlign(nanovgo.AlignLeft | nanovgo.AlignMiddle)
		iconPosX := centerX
		iconPosY := centerY - 1

		switch b.iconPosition {
		case ButtonIconLeftCentered:
			iconPosX -= (tw + iw) * 0.5
			textPosX += iw * 0.5
		case ButtonIconRightCentered:
			iconPosX -= iw * 0.5
			textPosX += tw * 0.5
		case ButtonIconLeft:
			iconPosX = bx + 8.0
		case ButtonIconRight:
			iconPosX = bx + bw - iw - 8
		}
		if b.icon > 0 {
			ctx.TextRune(iconPosX, iconPosY, []rune{rune(b.icon)})
		} else {
			var eOff float32 = 0.25
			if b.enabled {
				eOff = 0.5
			}
			imgPaint := nanovgo.ImagePattern(iconPosX, iconPosY-ih*0.5, iw, ih, 0, b.imageIcon, eOff)
			ctx.SetFillPaint(imgPaint)
			ctx.Fill()
		}
	}
	ctx.SetFontSize(fontSize)
	ctx.SetFontFace(b.theme.FontBold)
	ctx.SetTextAlign(nanovgo.AlignLeft | nanovgo.AlignMiddle)
	ctx.SetFillColor(b.theme.TextColorShadow)
	ctx.Text(textPosX, textPosY, caption)
	ctx.SetFillColor(textColor)
	ctx.Text(textPosX, textPosY+1.0, caption)
}