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

Golang xgraphics.ParseFont函数代码示例

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

本文整理汇总了Golang中github.com/BurntSushi/xgbutil/xgraphics.ParseFont函数的典型用法代码示例。如果您正苦于以下问题:Golang ParseFont函数的具体用法?Golang ParseFont怎么用?Golang ParseFont使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: DefaultFullTheme

func DefaultFullTheme(X *xgbutil.XUtil) *FullTheme {
	return &FullTheme{
		Font: xgraphics.MustFont(xgraphics.ParseFont(
			bytes.NewBuffer(misc.DejavusansTtf))),
		FontSize:   15,
		AFontColor: render.NewColor(0xffffff),
		IFontColor: render.NewColor(0x000000),

		TitleSize:   25,
		ATitleColor: render.NewColor(0x3366ff),
		ITitleColor: render.NewColor(0xdfdcdf),

		ACloseButton: builtInButton(X, misc.ClosePng),
		ICloseButton: builtInButton(X, misc.ClosePng),

		AMaximizeButton: builtInButton(X, misc.MaximizePng),
		IMaximizeButton: builtInButton(X, misc.MaximizePng),

		AMinimizeButton: builtInButton(X, misc.MinimizePng),
		IMinimizeButton: builtInButton(X, misc.MinimizePng),

		BorderSize:   10,
		ABorderColor: render.NewColor(0x3366ff),
		IBorderColor: render.NewColor(0xdfdcdf),
	}
}
开发者ID:mkrull,项目名称:wingo,代码行数:26,代码来源:full.go


示例2: main

func main() {
	X, err := xgbutil.NewConn()
	if err != nil {
		log.Fatal(err)
	}

	// Load some font. You may need to change the path depending upon your
	// system configuration.
	fontReader, err := os.Open(fontPath)
	if err != nil {
		log.Fatal(err)
	}

	// Now parse the font.
	font, err := xgraphics.ParseFont(fontReader)
	if err != nil {
		log.Fatal(err)
	}

	// Create some canvas.
	ximg := xgraphics.New(X, image.Rect(0, 0, canvasWidth, canvasHeight))
	ximg.For(func(x, y int) xgraphics.BGRA {
		return bg
	})

	// Now write the text.
	_, _, err = ximg.Text(10, 10, fg, size, font, msg)
	if err != nil {
		log.Fatal(err)
	}

	// Compute extents of first line of text.
	_, firsth := xgraphics.Extents(font, size, msg)

	// Now show the image in its own window.
	win := ximg.XShowExtra("Drawing text using xgraphics", true)

	// Now draw some more text below the above and demonstrate how to update
	// only the region we've updated.
	_, _, err = ximg.Text(10, 10+firsth, fg, size, font, "Some more text.")
	if err != nil {
		log.Fatal(err)
	}

	// Now compute extents of the second line of text, so we know which region
	// to update.
	secw, sech := xgraphics.Extents(font, size, "Some more text.")

	// Now repaint on the region that we drew text on. Then update the screen.
	bounds := image.Rect(10, 10+firsth, 10+secw, 10+firsth+sech)
	ximg.SubImage(bounds).XDraw()
	ximg.XPaint(win.Id)

	// All we really need to do is block, which could be achieved using
	// 'select{}'. Invoking the main event loop however, will emit error
	// message if anything went seriously wrong above.
	xevent.Main(X)
}
开发者ID:sbinet,项目名称:xgbutil,代码行数:58,代码来源:main.go


示例3: loadFont

func loadFont(name string) *Font {
	fontReader, err := os.Open(name)
	if err != nil {
		log.Fatal(err)
	}

	font, err := xgraphics.ParseFont(fontReader)
	if err != nil {
		log.Fatal(err)
	}
	return &Font{Size: 12.0, TrueType: font}
}
开发者ID:pointlander,项目名称:csm,代码行数:12,代码来源:csm.go


示例4: OpenFont

func OpenFont(fileName string) *truetype.Font {
	f, err := os.Open(fileName)

	FailMeMaybe(err)

	defer f.Close()

	fnt, err := xgraphics.ParseFont(f)

	FailMeMaybe(err)

	return fnt
}
开发者ID:AmandaCameron,项目名称:gobar,代码行数:13,代码来源:util.go


示例5:

	ActiveFontColor render.Color

	GroupBgColor   render.Color
	GroupFont      *truetype.Font
	GroupFontSize  float64
	GroupFontColor render.Color
	GroupSpacing   int
}

var DefaultSelectTheme = &SelectTheme{
	BorderSize:  10,
	BgColor:     render.NewImageColor(color.RGBA{0xff, 0xff, 0xff, 0xff}),
	BorderColor: render.NewImageColor(color.RGBA{0x0, 0x0, 0x0, 0xff}),
	Padding:     20,

	Font: xgraphics.MustFont(xgraphics.ParseFont(
		bytes.NewBuffer(misc.DataFile("DejaVuSans.ttf")))),
	FontSize:  20.0,
	FontColor: render.NewImageColor(color.RGBA{0x0, 0x0, 0x0, 0xff}),

	ActiveBgColor:   render.NewImageColor(color.RGBA{0x0, 0x0, 0x0, 0xff}),
	ActiveFontColor: render.NewImageColor(color.RGBA{0xff, 0xff, 0xff, 0xff}),

	GroupBgColor: render.NewImageColor(color.RGBA{0xff, 0xff, 0xff, 0xff}),
	GroupFont: xgraphics.MustFont(xgraphics.ParseFont(
		bytes.NewBuffer(misc.DataFile("DejaVuSans.ttf")))),
	GroupFontSize:  25.0,
	GroupFontColor: render.NewImageColor(color.RGBA{0x33, 0x66, 0xff, 0xff}),
	GroupSpacing:   15,
}

type SelectConfig struct {
开发者ID:cshapeshifter,项目名称:wingo,代码行数:32,代码来源:select.go


示例6:

	ActiveFontColor render.Color

	GroupBgColor   render.Color
	GroupFont      *truetype.Font
	GroupFontSize  float64
	GroupFontColor render.Color
	GroupSpacing   int
}

var DefaultSelectTheme = &SelectTheme{
	BorderSize:  10,
	BgColor:     render.NewImageColor(color.RGBA{0xff, 0xff, 0xff, 0xff}),
	BorderColor: render.NewImageColor(color.RGBA{0x0, 0x0, 0x0, 0xff}),
	Padding:     20,

	Font: xgraphics.MustFont(xgraphics.ParseFont(
		bytes.NewBuffer(bindata.DejavusansTtf()))),
	FontSize:  20.0,
	FontColor: render.NewImageColor(color.RGBA{0x0, 0x0, 0x0, 0xff}),

	ActiveBgColor:   render.NewImageColor(color.RGBA{0x0, 0x0, 0x0, 0xff}),
	ActiveFontColor: render.NewImageColor(color.RGBA{0xff, 0xff, 0xff, 0xff}),

	GroupBgColor: render.NewImageColor(color.RGBA{0xff, 0xff, 0xff, 0xff}),
	GroupFont: xgraphics.MustFont(xgraphics.ParseFont(
		bytes.NewBuffer(bindata.DejavusansTtf()))),
	GroupFontSize:  25.0,
	GroupFontColor: render.NewImageColor(color.RGBA{0x33, 0x66, 0xff, 0xff}),
	GroupSpacing:   15,
}

type SelectConfig struct {
开发者ID:yannicklm,项目名称:wingo,代码行数:32,代码来源:select.go


示例7: SetupDisplay

func SetupDisplay() (ctrlChan chan interface{}) {
	ctrlChan = make(chan interface{})
	X, err := xgbutil.NewConn()
	if err != nil {
		log.Fatal(err)
	}

	fontReader, err := os.Open(fontPath)
	if err != nil {
		log.Fatal(err)
	}

	// Now parse the font.
	font, err := xgraphics.ParseFont(fontReader)
	if err != nil {
		log.Fatal(err)
	}

	img, gc := initGc(width+border*2, height+heading+border*2)
	ximg := xgraphics.NewConvert(X, img)
	wid := ximg.XShowExtra("Regiment", true)

	circle := new(draw2d.PathStorage)

	ctr := 0
	fps := 0
	go func() {
		for {
			c := <-ctrlChan
			switch c := c.(type) {
			case *generals.Regiment:
				c.Step()
				rp := c.Position()
				gc.SetFillColor(image.Black)
				gc.SetStrokeColor(image.Black)

				for i := 0; i < len(rp.RowPath); i++ {
					x, y := rp.RowPath[i].X, rp.RowPath[i].Y
					circle = new(draw2d.PathStorage)
					circle.ArcTo(x+border, y+border+heading, 1, 1, 0, 2*math.Pi)
					gc.FillStroke(circle)
				}

				for i := 0; i < len(rp.ColPath); i++ {
					x, y := rp.ColPath[i].X, rp.ColPath[i].Y
					circle = new(draw2d.PathStorage)
					circle.ArcTo(x+border, y+border+heading, 1, 1, 0, 2*math.Pi)
					gc.FillStroke(circle)
				}

			case *Frame:
				for xp := border; xp < (width + border); xp++ {
					for yp := border; yp < (height + border + heading); yp++ {
						ximg.Set(xp, yp, img.At(xp, yp))
					}
				}
				_, _, err = ximg.Text(10, 0, fg, size, font, fmt.Sprintf("FPS: %v", fps))
				if err != nil {
					log.Fatal(err)
				}
				ximg.XDraw()
				ximg.XPaint(wid.Id)
				ctr++

				gc.SetFillColor(image.White)
				// fill the background
				gc.Clear()
			case *Timing:
				fps = ctr
				_, _, err = ximg.Text(10, 0, fg, size, font, fmt.Sprintf("FPS: %v", fps))
				ctr = 0
			default:
				fmt.Println(reflect.TypeOf(c))
			}
		}
	}()

	go func() {
		xevent.Main(X)
	}()
	return ctrlChan
}
开发者ID:stanim,项目名称:generals,代码行数:82,代码来源:display.go


示例8: fatal

	"github.com/BurntSushi/xgb/xproto"

	"github.com/BurntSushi/xgbutil"
	"github.com/BurntSushi/xgbutil/keybind"
	"github.com/BurntSushi/xgbutil/xevent"
	"github.com/BurntSushi/xgbutil/xgraphics"
	"github.com/BurntSushi/xgbutil/xwindow"

	"github.com/BurntSushi/wingo/bindata"
	"github.com/BurntSushi/wingo/render"
	"github.com/BurntSushi/wingo/text"
)

var (
	// A near guaranteed font. If parsing fails, MustFont wll panic.
	font = xgraphics.MustFont(xgraphics.ParseFont(
		bytes.NewBuffer(bindata.FreemonoTtf())))
	fontSize  = 30.0
	fontColor = render.NewImageColor(color.RGBA{0x0, 0x0, 0x0, 0xff})
	bgColor   = render.NewImageColor(color.RGBA{0xff, 0xff, 0xff, 0xff})
	width     = 800
	padding   = 10
)

func fatal(err error) {
	if err != nil {
		log.Fatal(err)
	}
}

func main() {
	X, err := xgbutil.NewConn()
开发者ID:yannicklm,项目名称:wingo,代码行数:32,代码来源:main.go



注:本文中的github.com/BurntSushi/xgbutil/xgraphics.ParseFont函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang xgraphics.Image类代码示例发布时间:2022-05-24
下一篇:
Golang xgraphics.New函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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