當前位置: 首頁>>代碼示例>>Golang>>正文


Golang vg.Context類代碼示例

本文整理匯總了Golang中github.com/vizstra/vg.Context的典型用法代碼示例。如果您正苦於以下問題:Golang Context類的具體用法?Golang Context怎麽用?Golang Context使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Context類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Draw

func (self *Window) Draw(ctx vg.Context) {
	now := time.Now()
	_, _, w, h := self.Bounds()
	fbw, fbh := self.FramebufferSize()

	// Calculate pixel ration for hi-dpi devices.
	bg := color.Gray13

	gl.ClearColor(gl.Float(bg.R), gl.Float(bg.G), gl.Float(bg.B), gl.Float(bg.A))
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT)

	//Do OpenGL stuff
	// Iterate over scene, rendering what can be rendered
	if self.renderer != nil {
		self.renderer.Render()
	}

	// 2D Display
	// r := float64(fbw) / float64(w)
	gl.Viewport(0, 0, gl.Sizei(fbw), gl.Sizei(fbh))

	if self.child != nil {
		ctx.BeginFrame(int(w), int(h), 1.0)
		self.child.SetBounds(0.0, 0.0, float64(w), float64(h))
		self.child.Draw(ctx)
		ctx.EndFrame()
	}
	if debug {
		fmt.Println(time.Since(now))
	}
}
開發者ID:xormplus,項目名稱:ui-1,代碼行數:31,代碼來源:window.go

示例2: tokenBounds

// tokenSize retrieves the metrics from the internal cache, sizes.
// It is expensive to calculate the token sizes each frame and the
// sizes do not change often to justify the cost.  Testing revealed
// this approach yields a slower rate of growth.
//
// TODO: maybe choose to disable cpu scaling for better performance
//         > echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
//       or
//         > sudo update-rc.d ondemand disable
func (self *Text) tokenBounds(i int, ctx *vg.Context) *ui.Rectangle {
	bounds := self.bounds[i]
	if bounds == nil {
		x, y, w, h := ctx.TextBounds(self.tokens[i], 0, 0)

		bounds = &ui.Rectangle{ui.Position{x, y}, ui.Size{w, h}}
		self.bounds[i] = bounds
	}
	return bounds
}
開發者ID:xormplus,項目名稱:ui-1,代碼行數:19,代碼來源:text.go

示例3: Draw

func (self *LineChart) Draw(x, y, w, h float64, ctx vg.Context) {
	ui.DrawDefaultElement(x, y, w, h, Palette[CHART_BACKGROUND], ctx)
	// th := self.Title.draw(x, y, w, h, ctx)
	ctx.BeginPath()
	ctx.Fill()
	self.drawSeries(x, y, w, h, ctx)
	ctx.ResetScissor()
}
開發者ID:xormplus,項目名稱:ui-1,代碼行數:8,代碼來源:line.go

示例4: draw

// draw draws the title and returns the height.
func (self *Title) draw(x, y, w, h float64, ctx vg.Context) float64 {
	th := 0.0
	name := self.Model.Title()
	if len(name) > 0 {
		th = self.FontSize + 16
		// ctx.BeginPath()
		// ctx.StrokeColor(color.RGBA{0, 50, 100, 25})
		// ctx.StrokeWidth(1)
		// ctx.LineCap(vg.ROUND)
		// ctx.LineJoin(vg.ROUND)
		// ctx.MoveTo(x, y+th)
		// ctx.LineTo(x+1.5, y+th)
		// ctx.LineTo(x+w+1.5, y+th)
		// ctx.Stroke()

		ctx.FillColor(color.RGBA{255, 251, 251, 255})
		ctx.TextAlign(vg.ALIGN_LEFT | vg.ALIGN_MIDDLE)
		ctx.SetFontSize(self.FontSize + 3)
		ctx.FindFont(vg.FONT_DEFAULT)
		ctx.WrappedText(x+10, y+self.FontSize, w, name)

	}
	return th
}
開發者ID:xormplus,項目名稱:ui-1,代碼行數:25,代碼來源:title.go

示例5: DrawDefaultElement

func DrawDefaultElement(x, y, w, h float64, bg color.Color, ctx vg.Context) {

	// Shadow
	ctx.BeginPath()
	ctx.StrokeColor(color.RGBA{100, 100, 100, 100})
	ctx.RoundedRect(x, y, w, h, 30)
	ctx.StrokeWidth(1)
	ctx.Stroke()
	ctx.FillPaint(ctx.BoxGradient(x, y, w, h, h*.5, h, bg, bg))
	ctx.Fill()
}
開發者ID:xormplus,項目名稱:ui-1,代碼行數:11,代碼來源:aw-util.go

示例6: drawSeries

func (self *LineChart) drawSeries(x, y, w, h float64, ctx vg.Context) {
	// Boundries
	baseline := y + h
	_, max, count := self.Model.Limits()
	horIncr := w / (count - 1)
	vratio := (h - 1) / max
	for _, s := range self.Model.Series() {
		c1 := CloneColor(s.Color)
		c1.A = 150
		ctx.StrokeColor(c1)
		ctx.StrokeWidth(s.StrokeWidth)
		ctx.BeginPath()
		for i, f := range s.Data {
			if i == 0 {
				ctx.MoveTo(x+float64(i)*horIncr, baseline-(f*vratio))
			} else {
				ctx.LineTo(x+float64(i)*horIncr, baseline-(f*vratio))
			}
		}
		ctx.Stroke()

		if self.Fill {
			ctx.BeginPath()
			// ctx.MoveTo(x, baseline)
			c2 := CloneColor(s.Color)
			c2.A = 200
			ctx.FillColor(c2)
			for i, f := range s.Data {
				if i == 0 {
					ctx.MoveTo(x+float64(i)*horIncr, baseline-(f*vratio))
				}

				ctx.LineTo(x+float64(i)*horIncr, baseline-(f*vratio))

				if i == len(s.Data)-1 {
					ctx.LineTo(x+float64(i)*horIncr, baseline)
					ctx.LineTo(x, baseline)
					ctx.MoveTo(x, baseline-(s.Data[0]*vratio))
					break
				}
			}
			ctx.Fill()
		}
	}
}
開發者ID:xormplus,項目名稱:ui-1,代碼行數:45,代碼來源:line.go

示例7: Draw

func (self *Element) Draw(ctx vg.Context) {
	x, y, w, h := self.Bounds()
	x, y = self.Clamp(x, y)

	// draw background
	c := CloneColor(self.ActiveBackground)
	bg := ctx.BoxGradient(x, y, w, h, h, h, c, c)

	ctx.BeginPath()
	ctx.RoundedRect(x, y, w, h, self.CornerRadius)
	ctx.FillPaint(bg)
	ctx.Fill()
	ctx.StrokeWidth(self.BorderWidth)
	ctx.StrokeColor(c.Lighten(-0.5))
	ctx.Stroke()

	if self.DrawCB != nil {
		self.DrawCB(ctx)
	}
}
開發者ID:xormplus,項目名稱:ui-1,代碼行數:20,代碼來源:element.go

示例8: Draw

func (self *Text) Draw(ctx vg.Context) {
	x, y, w, h := self.Bounds()
	self.lastContext = &ctx
	ctx.Scissor(x, y, w, h)
	ctx.BeginPath()
	ctx.RoundedRect(x, y, w, h, self.CornerRadius)
	ctx.FillColor(self.Background)
	ctx.Fill()
	ctx.FillColor(self.Foreground)

	self.forEachDrawnToken(x, y, w, h,
		func(i int, x, y, lineHeight float64, bounds *ui.Rectangle, ctx *vg.Context) {
			ctx.Text(x, y, self.tokens[i])
		},
	)

	// for i := 0; i < len(self.selections); i++ {
	// 	s := self.selections[i]
	// }

	ctx.ResetScissor()
}
開發者ID:xormplus,項目名稱:ui-1,代碼行數:22,代碼來源:text.go

示例9: spaceWidth

func (self *Text) spaceWidth(ctx *vg.Context) float64 {
	xmin, _, xmax, _ := ctx.TextBounds(".", 0, 0)
	return xmax - xmin
}
開發者ID:xormplus,項目名稱:ui-1,代碼行數:4,代碼來源:text.go


注:本文中的github.com/vizstra/vg.Context類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。