本文整理汇总了Golang中github.com/shibukawa/nanovgo.Context.BeginPath方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.BeginPath方法的具体用法?Golang Context.BeginPath怎么用?Golang Context.BeginPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/shibukawa/nanovgo.Context
的用法示例。
在下文中一共展示了Context.BeginPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: drawDropDown
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))
}
示例2: drawSearchBox
func drawSearchBox(ctx *nanovgo.Context, text string, x, y, w, h float32) {
cornerRadius := h/2 - 1
// Edit
bg := nanovgo.BoxGradient(x, y+1.5, w, h, h/2, 5, nanovgo.RGBA(0, 0, 0, 16), nanovgo.RGBA(0, 0, 0, 92))
ctx.BeginPath()
ctx.RoundedRect(x, y, w, h, cornerRadius)
ctx.SetFillPaint(bg)
ctx.Fill()
/* ctx.BeginPath();
ctx.RoundedRect(x+0.5f,y+0.5f, w-1,h-1, cornerRadius-0.5f);
ctx.StrokeColor(ctx.RGBA(0,0,0,48));
ctx.Stroke();*/
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+h*0.55, y+h*0.55, cpToUTF8(IconSEARCH))
ctx.SetFontSize(20.0)
ctx.SetFontFace("sans")
ctx.SetFillColor(nanovgo.RGBA(255, 255, 255, 32))
ctx.SetTextAlign(nanovgo.AlignLeft | nanovgo.AlignMiddle)
ctx.Text(x+h*1.05, y+h*0.5, text)
ctx.SetFontSize(h * 1.3)
ctx.SetFontFace("icons")
ctx.SetFillColor(nanovgo.RGBA(255, 255, 255, 32))
ctx.SetTextAlign(nanovgo.AlignCenter | nanovgo.AlignMiddle)
ctx.Text(x+w-h*0.55, y+h*0.55, cpToUTF8(IconCIRCLEDCROSS))
}
示例3: Draw
func (sf *SpinnerFilter) Draw(self nanogui.Widget, ctx *nanovgo.Context) {
if sf.isActive() {
var py int
fw, fh := sf.Parent().Size()
if window, ok := sf.Parent().(*nanogui.Window); ok {
hh := window.Theme().WindowHeaderHeight
py += hh
fh -= hh
}
sf.SetPosition(0, py)
sf.SetSize(fw, fh)
currentTime := nanogui.GetTime() - sf.startTime
var alpha float32
var showSpinner bool
if sf.state == SpinnerFadeIn {
if currentTime > 1 {
alpha = 0.7
showSpinner = true
} else {
alpha = currentTime * 0.7
}
} else {
if currentTime > 1 {
alpha = 0.7
} else {
alpha = (1.0 - currentTime) * 0.7
}
}
ctx.Save()
ctx.BeginPath()
ctx.SetFillColor(nanovgo.MONOf(0, alpha))
ctx.Rect(0, float32(py), float32(fw), float32(fh))
ctx.Fill()
if showSpinner {
cx := float32(fw / 2)
cy := float32(py + fh/2)
rotation := 2 * math.Pi * float64(currentTime*float32(sf.speed)*float32(sf.num)) / float64(sf.num)
dr := float64(2 * math.Pi / float64(sf.num))
ctx.SetStrokeWidth(sf.lineWidth)
for i := 0; i < sf.num; i++ {
ctx.BeginPath()
ctx.MoveTo(cx+float32(math.Cos(rotation))*sf.c1, cy+float32(math.Sin(rotation))*sf.c1)
ctx.LineTo(cx+float32(math.Cos(rotation))*sf.c2, cy+float32(math.Sin(rotation))*sf.c2)
ctx.SetStrokeColor(nanovgo.MONOf(1.0, float32(i)/float32(sf.num)))
ctx.Stroke()
rotation += dr
}
}
ctx.Restore()
} else {
sf.SetSize(0, 0)
sf.SetVisible(false)
return
}
}
示例4: drawEditBoxBase
func drawEditBoxBase(ctx *nanovgo.Context, x, y, w, h float32) {
// Edit
bg := nanovgo.BoxGradient(x+1, y+1+1.5, w-2, h-2, 3, 4, nanovgo.RGBA(255, 255, 255, 32), nanovgo.RGBA(32, 32, 32, 32))
ctx.BeginPath()
ctx.RoundedRect(x+1, y+1, w-2, h-2, 4-1)
ctx.SetFillPaint(bg)
ctx.Fill()
ctx.BeginPath()
ctx.RoundedRect(x+0.5, y+0.5, w-1, h-1, 4-0.5)
ctx.SetStrokeColor(nanovgo.RGBA(0, 0, 0, 48))
ctx.Stroke()
}
示例5: drawLines
func drawLines(ctx *nanovgo.Context, x, y, w, h, t float32) {
var pad float32 = 5.0
s := w/9.0 - pad*2
joins := []nanovgo.LineCap{nanovgo.Miter, nanovgo.Round, nanovgo.Bevel}
caps := []nanovgo.LineCap{nanovgo.Butt, nanovgo.Round, nanovgo.Square}
ctx.Save()
defer ctx.Restore()
pts := []float32{
-s*0.25 + cosF(t*0.3)*s*0.5,
sinF(t*0.3) * s * 0.5,
-s * 0.25,
0,
s * 0.25,
0,
s*0.25 + cosF(-t*0.3)*s*0.5,
sinF(-t*0.3) * s * 0.5,
}
for i, cap := range caps {
for j, join := range joins {
fx := x + s*0.5 + float32(i*3+j)/9.0*w + pad
fy := y - s*0.5 + pad
ctx.SetLineCap(cap)
ctx.SetLineJoin(join)
ctx.SetStrokeWidth(s * 0.3)
ctx.SetStrokeColor(nanovgo.RGBA(0, 0, 0, 160))
ctx.BeginPath()
ctx.MoveTo(fx+pts[0], fy+pts[1])
ctx.LineTo(fx+pts[2], fy+pts[3])
ctx.LineTo(fx+pts[4], fy+pts[5])
ctx.LineTo(fx+pts[6], fy+pts[7])
ctx.Stroke()
ctx.SetLineCap(nanovgo.Butt)
ctx.SetLineJoin(nanovgo.Bevel)
ctx.SetStrokeWidth(1.0)
ctx.SetStrokeColor(nanovgo.RGBA(0, 192, 255, 255))
ctx.BeginPath()
ctx.MoveTo(fx+pts[0], fy+pts[1])
ctx.LineTo(fx+pts[2], fy+pts[3])
ctx.LineTo(fx+pts[4], fy+pts[5])
ctx.LineTo(fx+pts[6], fy+pts[7])
ctx.Stroke()
}
}
}
示例6: drawWidths
func drawWidths(ctx *nanovgo.Context, x, y, width float32) {
ctx.Save()
defer ctx.Restore()
ctx.SetStrokeColor(nanovgo.RGBA(0, 0, 0, 255))
for i := 0; i < 20; i++ {
w := (float32(i) + 0.5) * 0.1
ctx.SetStrokeWidth(w)
ctx.BeginPath()
ctx.MoveTo(x, y)
ctx.LineTo(x+width, y+width*0.3)
ctx.Stroke()
y += 10
}
}
示例7: drawButton
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)
}
示例8: RenderGraph
// RenderGraph shows graph
func (pg *PerfGraph) RenderGraph(ctx *nanovgo.Context, x, y float32) {
avg := pg.GetGraphAverage()
var w float32 = 200
var h float32 = 35
ctx.BeginPath()
ctx.Rect(x, y, w, h)
ctx.SetFillColor(backgroundColor)
ctx.Fill()
ctx.BeginPath()
ctx.MoveTo(x, y+h)
for i := 0; i < nvgGraphHistoryCount; i++ {
v := float32(1.0) / float32(0.00001+pg.values[(pg.head+i)%nvgGraphHistoryCount])
if v > 80.0 {
v = 80.0
}
vx := x + float32(i)/float32(nvgGraphHistoryCount-1)*w
vy := y + h - ((v / 80.0) * h)
ctx.LineTo(vx, vy)
}
ctx.LineTo(x+w, y+h)
ctx.SetFillColor(graphColor)
ctx.Fill()
ctx.SetFontFace(pg.fontFace)
if len(pg.name) > 0 {
ctx.SetFontSize(14.0)
ctx.SetTextAlign(nanovgo.AlignLeft | nanovgo.AlignTop)
ctx.SetFillColor(titleTextColor)
ctx.Text(x+3, y+1, pg.name)
}
ctx.SetFontSize(18.0)
ctx.SetTextAlign(nanovgo.AlignRight | nanovgo.AlignTop)
ctx.SetFillColor(fpsTextColor)
ctx.Text(x+w-3, y+1, fmt.Sprintf("%.2f FPS", 1.0/avg))
ctx.SetFontSize(15.0)
ctx.SetTextAlign(nanovgo.AlignRight | nanovgo.AlignBottom)
ctx.SetFillColor(averageTextColor)
ctx.Text(x+w-3, y+h+1, fmt.Sprintf("%.2f ms", avg*1000.0))
}
示例9: Draw
func (i *ImageView) Draw(self Widget, ctx *nanovgo.Context) {
if i.image == 0 {
return
}
x := float32(i.x)
y := float32(i.y)
ow := float32(i.w)
oh := float32(i.h)
var w, h float32
{
iw, ih, _ := ctx.ImageSize(i.image)
w = float32(iw)
h = float32(ih)
}
if i.policy == ImageSizePolicyFixed {
if ow < w {
h = float32(int(h * ow / w))
w = ow
}
if oh < h {
w = float32(int(w * oh / h))
h = oh
}
} else { // mPolicy == Expand
// expand to width
h = float32(int(h * ow / w))
w = ow
// shrink to height, if necessary
if oh < h {
w = float32(int(w * oh / h))
h = oh
}
}
imgPaint := nanovgo.ImagePattern(x, y, w, h, 0, i.image, 1.0)
ctx.BeginPath()
ctx.Rect(x, y, w, h)
ctx.SetFillPaint(imgPaint)
ctx.Fill()
}
示例10: Draw
func (p *ProgressBar) Draw(self Widget, ctx *nanovgo.Context) {
px := float32(p.x)
py := float32(p.y)
pw := float32(p.w)
ph := float32(p.h)
p.WidgetImplement.Draw(self, ctx)
paint := nanovgo.BoxGradient(px+1, py+1, pw-2, ph, 3, 4, nanovgo.MONO(0, 32), nanovgo.MONO(0, 92))
ctx.BeginPath()
ctx.RoundedRect(px, py, pw, ph, 3)
ctx.SetFillPaint(paint)
ctx.Fill()
value := clampF(p.value, 0.0, 1.0)
barPos := (pw - 2) * value
barPaint := nanovgo.BoxGradient(px, py, barPos+1.5, ph-1, 3, 4, nanovgo.MONO(220, 100), nanovgo.MONO(128, 100))
ctx.BeginPath()
ctx.RoundedRect(px+1, py+1, barPos, ph-2, 3)
ctx.SetFillPaint(barPaint)
ctx.Fill()
}
示例11: Draw
func (v *VScrollPanel) Draw(self Widget, ctx *nanovgo.Context) {
if len(v.children) == 0 {
return
}
x := float32(v.x)
y := float32(v.y)
w := float32(v.w)
h := float32(v.h)
child := v.children[0]
layout := self.Layout()
if layout != nil {
_, v.childPreferredHeight = layout.PreferredSize(self, ctx)
} else {
_, v.childPreferredHeight = child.PreferredSize(child, ctx)
}
ctx.Save()
ctx.Translate(x, y)
ctx.Scissor(0, 0, w, h)
ctx.Translate(0, -v.scroll*(float32(v.childPreferredHeight)-h))
if child.Visible() {
child.Draw(child, ctx)
}
ctx.Restore()
if v.childPreferredHeight > v.h {
scrollH := h * minF(1.0, h/float32(v.childPreferredHeight))
scrollH = minF(maxF(20.0, scrollH), h)
paint := nanovgo.BoxGradient(x+w-12+1, y+4+1, 8, h-8, 3, 4, nanovgo.MONO(0, 32), nanovgo.MONO(0, 92))
ctx.BeginPath()
ctx.RoundedRect(x+w-12, y+4, 8, h-8, 3)
ctx.SetFillPaint(paint)
ctx.Fill()
barPaint := nanovgo.BoxGradient(x+y-12-1, y+4+1+(h-8-scrollH)*v.scroll-1, 8, scrollH, 3, 4, nanovgo.MONO(220, 100), nanovgo.MONO(128, 100))
ctx.BeginPath()
ctx.RoundedRect(x+w-12+1, y+4+1+(h-8-scrollH)*v.scroll, 8-2, scrollH-2, 2)
ctx.SetFillPaint(barPaint)
ctx.Fill()
}
}
示例12: drawSpinner
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()
}
示例13: drawCheckBox
func drawCheckBox(ctx *nanovgo.Context, text string, x, y, w, h float32) {
ctx.SetFontSize(18.0)
ctx.SetFontFace("sans")
ctx.SetFillColor(nanovgo.RGBA(255, 255, 255, 160))
ctx.SetTextAlign(nanovgo.AlignLeft | nanovgo.AlignMiddle)
ctx.Text(x+28, y+h*0.5, text)
bg := nanovgo.BoxGradient(x+1, y+float32(int(h*0.5))-9+1, 18, 18, 3, 3, nanovgo.RGBA(0, 0, 0, 32), nanovgo.RGBA(0, 0, 0, 92))
ctx.BeginPath()
ctx.RoundedRect(x+1, y+float32(int(h*0.5))-9, 18, 18, 3)
ctx.SetFillPaint(bg)
ctx.Fill()
ctx.SetFontSize(40)
ctx.SetFontFace("icons")
ctx.SetFillColor(nanovgo.RGBA(255, 255, 255, 128))
ctx.SetTextAlign(nanovgo.AlignCenter | nanovgo.AlignMiddle)
ctx.Text(x+9+2, y+h*0.5, cpToUTF8(IconCHECK))
}
示例14: drawCaps
func drawCaps(ctx *nanovgo.Context, x, y, width float32) {
caps := []nanovgo.LineCap{nanovgo.Butt, nanovgo.Round, nanovgo.Square}
var lineWidth float32 = 8.0
ctx.Save()
defer ctx.Restore()
ctx.BeginPath()
ctx.Rect(x-lineWidth/2, y, width+lineWidth, 40)
ctx.SetFillColor(nanovgo.RGBA(255, 255, 255, 32))
ctx.Fill()
ctx.BeginPath()
ctx.Rect(x, y, width, 40)
ctx.SetFillColor(nanovgo.RGBA(255, 255, 255, 32))
ctx.Fill()
ctx.SetStrokeWidth(lineWidth)
for i, cap := range caps {
ctx.SetLineCap(cap)
ctx.SetStrokeColor(nanovgo.RGBA(0, 0, 0, 255))
ctx.BeginPath()
ctx.MoveTo(x, y+float32(i)*10+5)
ctx.LineTo(x+width, y+float32(i)*10+5)
ctx.Stroke()
}
}
示例15: Draw
// Draw() draws the widget (and all child widgets)
func (w *WidgetImplement) Draw(self Widget, ctx *nanovgo.Context) {
if debugFlag {
ctx.SetStrokeWidth(1.0)
ctx.BeginPath()
ctx.Rect(float32(w.x)-0.5, float32(w.y)-0.5, float32(w.w)+1.0, float32(w.h)+1.0)
ctx.SetStrokeColor(nanovgo.RGBA(255, 0, 0, 255))
ctx.Stroke()
}
if len(w.children) == 0 {
return
}
ctx.Translate(float32(w.x), float32(w.y))
// draw depth 0 items
var drawLater widgetsAsc = make([]Widget, 0, len(w.children))
for _, child := range w.children {
if child.Visible() {
depth := child.Depth()
if depth == 0 {
cx, cy := child.Position()
cw, ch := child.Size()
if !self.IsClipped(cx, cy, cw, ch) {
child.Draw(child, ctx)
}
} else {
drawLater = append(drawLater, child)
}
}
}
// draw by depth order
sort.Sort(drawLater)
for _, child := range drawLater {
cx, cy := child.Position()
cw, ch := child.Size()
if !self.IsClipped(cx, cy, cw, ch) {
child.Draw(child, ctx)
}
}
ctx.Translate(-float32(w.x), -float32(w.y))
}