• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang screen.Buffer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中golang.org/x/exp/shiny/screen.Buffer的典型用法代码示例。如果您正苦于以下问题:Golang Buffer类的具体用法?Golang Buffer怎么用?Golang Buffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Buffer类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: Upload

func (t *textureImpl) Upload(dp image.Point, src screen.Buffer, sr image.Rectangle, sender screen.Sender) {
	// TODO: adjust if dp is outside dst bounds, or sr is outside src bounds.
	gl.BindTexture(gl.TEXTURE_2D, t.id)
	m := src.RGBA().SubImage(sr).(*image.RGBA)
	b := m.Bounds()
	// TODO check m bounds smaller than t.size
	gl.TexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, b.Dx(), b.Dy(), gl.RGBA, gl.UNSIGNED_BYTE, m.Pix)
	// TODO: send a screen.UploadedEvent.
}
开发者ID:kleopatra999,项目名称:exp,代码行数:9,代码来源:texture.go


示例2: Upload

func (t *textureImpl) Upload(dp image.Point, src screen.Buffer, sr image.Rectangle) {
	t.w.glctxMu.Lock()
	defer t.w.glctxMu.Unlock()

	// TODO: adjust if dp is outside dst bounds, or r is outside src bounds.
	t.w.glctx.BindTexture(gl.TEXTURE_2D, t.id)
	m := src.RGBA().SubImage(sr).(*image.RGBA)
	b := m.Bounds()
	// TODO check m bounds smaller than t.size
	t.w.glctx.TexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, b.Dx(), b.Dy(), gl.RGBA, gl.UNSIGNED_BYTE, m.Pix)
}
开发者ID:dylanpoe,项目名称:golang.org,代码行数:11,代码来源:texture.go


示例3: Upload

func (w *windowImpl) Upload(dp image.Point, src screen.Buffer, sr image.Rectangle) {
	originalSRMin := sr.Min
	sr = sr.Intersect(src.Bounds())
	if sr.Empty() {
		return
	}
	dp = dp.Add(sr.Min.Sub(originalSRMin))
	// TODO: keep a texture around for this purpose?
	t, err := w.s.NewTexture(sr.Size())
	if err != nil {
		panic(err)
	}
	t.Upload(image.Point{}, src, sr)
	w.Draw(f64.Aff3{
		1, 0, float64(dp.X),
		0, 1, float64(dp.Y),
	}, t, t.Bounds(), draw.Src, nil)
	t.Release()
}
开发者ID:kardianos,项目名称:garage,代码行数:19,代码来源:window.go


示例4: main

func main() {
	flag.Parse()

	rand.Seed(int64(time.Now().Nanosecond()))
	board := NewBoard(9, *scale)

	driver.Main(func(s screen.Screen) {
		w, err := s.NewWindow(nil)
		if err != nil {
			log.Fatal(err)
		}
		defer w.Release()

		var b screen.Buffer
		defer func() {
			if b != nil {
				b.Release()
			}
		}()

		for e := range w.Events() {
			switch e := e.(type) {
			case mouse.Event:
				if e.Direction == mouse.DirRelease && e.Button != 0 {
					board.click(b.RGBA(), int(e.X), int(e.Y), int(e.Button))
					w.Send(paint.Event{})
				}

			case key.Event:
				if e.Code == key.CodeEscape {
					return
				}

			case paint.Event:
				w.Upload(image.Point{}, b, b.Bounds())
				w.Publish()

			case size.Event:
				// TODO: Set board size.
				if b != nil {
					b.Release()
				}
				b, err = s.NewBuffer(e.Size())
				if err != nil {
					log.Fatal(err)
				}
				render(b.RGBA(), board)

			case error:
				log.Print(e)
			}
		}
	})
}
开发者ID:dylanpoe,项目名称:golang.org,代码行数:54,代码来源:main.go


示例5: main

func main() {
	log.SetFlags(0)
	log.SetPrefix("preview: ")
	flag.Usage = func() {
		log.Print("Usage: preview [options] file")
		flag.PrintDefaults()
	}
	flag.Parse()
	if flag.NArg() != 1 {
		flag.Usage()
		os.Exit(1)
	}

	if *prof != "" {
		log.Print("profile mode: will write out CPU profile after 5 seconds")
		f, err := os.Create(*prof)
		if err != nil {
			log.Fatal(err)
		}
		err = pprof.StartCPUProfile(f)
		if err != nil {
			log.Fatal(err)
		}
		go func() {
			time.Sleep(5 * time.Second)
			pprof.StopCPUProfile()
			log.Print("done writing CPU profile")
		}()
	}

	f, err := os.Open(flag.Arg(0))
	if err != nil {
		log.Fatal(err)
	}

	log.Print("parsing STL...")
	t := time.Now()
	stl, err := slice.Parse(f)
	if err != nil {
		log.Fatal(err)
	}
	f.Close()
	log.Printf("parsing took %v", time.Now().Sub(t))

	if err := sliceSTL(stl); err != nil {
		log.Fatal(err)
	}
	imgs, err := drawLayers(stl)
	if err != nil {
		log.Fatal(err)
	}
	r := imgs[0].Bounds()

	log.Print("Launching UI...")
	driver.Main(func(s screen.Screen) {
		w, err := s.NewWindow(&screen.NewWindowOptions{
			Width:  r.Dx(),
			Height: r.Dy(),
		})
		if err != nil {
			log.Fatal(err)
		}
		defer w.Release()

		r := image.Rect(int(stl.Min.X), int(stl.Min.Y), int(stl.Max.X)+1, int(stl.Max.Y)+1)
		winSize := r.Size()
		var b screen.Buffer
		defer func() {
			if b != nil {
				b.Release()
			}
		}()

		var sz size.Event
		var lastClick mouse.Event

		var layer int
		redraw := func() {
			draw.Draw(b.RGBA(), b.RGBA().Bounds(), imgs[layer], imgs[layer].Bounds().Min, draw.Src)
			drawLayerNumber(b.RGBA(), layer)
			w.Send(paint.Event{})
		}

		for e := range w.Events() {
			switch e := e.(type) {
			default:

			case mouse.Event:
				if e.Button == mouse.ButtonLeft {
					if e.Y > lastClick.Y && layer < len(imgs)-1 {
						layer++
						redraw()
					} else if e.Y < lastClick.Y && layer > 0 {
						layer--
						redraw()
					}
					lastClick = e
				}

			case key.Event:
//.........这里部分代码省略.........
开发者ID:jnjackins,项目名称:slice,代码行数:101,代码来源:main.go


示例6: main

func main() {
	flag.Parse()

	rand.Seed(int64(time.Now().Nanosecond()))
	board := NewBoard(9, *scale)

	driver.Main(func(s screen.Screen) {
		w, err := s.NewWindow(nil)
		if err != nil {
			log.Fatal(err)
		}
		defer w.Release()

		var b screen.Buffer
		defer func() {
			if b != nil {
				b.Release()
			}
		}()

		for e := range w.Events() {
			switch e := e.(type) {
			case mouse.Event:
				if e.Direction == mouse.DirRelease && e.Button != 0 {
					board.click(b.RGBA(), int(e.X), int(e.Y), int(e.Button))
					dirty = true
				}

			case key.Event:
				if e.Code == key.CodeEscape {
					return
				}

			case paint.Event:
				// TODO: we shouldn't rely on the library sending us a constant
				// stream of paint events. If we're dirty, we should just draw
				// on the window and then call w.Publish.
				//
				// TODO: This check should save CPU time but causes flicker on Darwin.
				//if dirty && !uploading {
				w.Upload(image.Point{}, b, b.Bounds(), w) // TODO: On Darwin always writes to 0,0, ignoring first arg.
				dirty = false
				uploading = true
				//}
				w.Publish()

			case screen.UploadedEvent:
				// No-op.
				uploading = false

			case size.Event:
				// TODO: Set board size.
				if b != nil {
					b.Release()
				}
				b, err = s.NewBuffer(e.Size())
				if err != nil {
					log.Fatal(err)
				}
				render(b.RGBA(), board)

			case error:
				log.Print(e)
			}
		}
	})
}
开发者ID:rdterner,项目名称:exp,代码行数:67,代码来源:main.go



注:本文中的golang.org/x/exp/shiny/screen.Buffer类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang font.Face类代码示例发布时间:2022-05-28
下一篇:
Golang inotify.Watcher类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap