本文整理汇总了Golang中github.com/BurntSushi/wingo/render.Color类的典型用法代码示例。如果您正苦于以下问题:Golang Color类的具体用法?Golang Color怎么用?Golang Color使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Color类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: DrawText
// DrawText is a convenience function that will create a new image, render
// the provided text to it, paint the image to the provided window, and resize
// the window to fit the text snugly.
//
// An error can occur when rendering the text to an image.
func DrawText(win *xwindow.Window, font *truetype.Font, size float64,
fontClr, bgClr render.Color, text string) error {
// Over estimate the extents.
ew, eh := xgraphics.TextMaxExtents(font, size, text)
eh += misc.TextBreathe // <-- this is the bug
// Create an image using the over estimated extents.
img := xgraphics.New(win.X, image.Rect(0, 0, ew, eh))
xgraphics.BlendBgColor(img, bgClr.ImageColor())
// Now draw the text, grab the (x, y) position advanced by the text, and
// check for an error in rendering.
x, y, err := img.Text(0, 0, fontClr.ImageColor(), size, font, text)
if err != nil {
return err
}
// Resize the window to the geometry determined by (x, y).
w, h := x, y+misc.TextBreathe // <-- also part of the bug
win.Resize(w, h)
// Now draw the image to the window and destroy it.
img.XSurfaceSet(win.Id)
subimg := img.SubImage(image.Rect(0, 0, w, h))
subimg.XDraw()
subimg.XPaint(win.Id)
img.Destroy()
return nil
}
开发者ID:Pursuit92,项目名称:wingo,代码行数:36,代码来源:render.go
示例2: DrawText
// DrawText is a convenience function that will create a new image, render
// the provided text to it, paint the image to the provided window, and resize
// the window to fit the text snugly.
//
// An error can occur when rendering the text to an image.
func DrawText(win *xwindow.Window, font *truetype.Font, size float64,
fontClr, bgClr render.Color, text string) error {
// BUG(burntsushi): If `text` is zero-length, very bad things happen.
if len(text) == 0 {
text = " "
}
// Over estimate the extents.
ew, eh := xgraphics.Extents(font, size, text)
// Create an image using the over estimated extents.
img := xgraphics.New(win.X, image.Rect(0, 0, ew, eh))
xgraphics.BlendBgColor(img, bgClr.ImageColor())
// Now draw the text, grab the (x, y) position advanced by the text, and
// check for an error in rendering.
_, _, err := img.Text(0, 0, fontClr.ImageColor(), size, font, text)
if err != nil {
return err
}
// Resize the window to the geometry determined by (x, y).
win.Resize(ew, eh)
// Now draw the image to the window and destroy it.
img.XSurfaceSet(win.Id)
// subimg := img.SubImage(image.Rect(0, 0, ew, eh))
img.XDraw()
img.XPaint(win.Id)
img.Destroy()
return nil
}
开发者ID:flying99999,项目名称:wingo,代码行数:39,代码来源:render.go
示例3: setGradient
func setGradient(k wini.Key, clr *render.Color) {
// Check to make sure we have a value for this key
vals := k.Strings()
if len(vals) == 0 {
logger.Warning.Println(k.Err("No values found."))
return
}
// Use the last value
val := vals[len(vals)-1]
// If there are no spaces, it can't be a gradient.
if strings.Index(val, " ") == -1 {
if start, ok := getLastInt(k); ok {
clr.ColorSet(start)
}
return
}
// Okay, now we have to do things manually.
// Split up the value into two pieces separated by whitespace and parse
// each piece as an int.
splitted := strings.Split(val, " ")
if len(splitted) != 2 {
logger.Warning.Println(k.Err("Expected a gradient value (two colors "+
"separated by a space), but found '%s' "+
"instead.", val))
return
}
start, err := strconv.ParseInt(strings.TrimSpace(splitted[0]), 0, 0)
if err != nil {
logger.Warning.Println(k.Err("'%s' is not an integer. (%s)",
splitted[0], err))
return
}
end, err := strconv.ParseInt(strings.TrimSpace(splitted[1]), 0, 0)
if err != nil {
logger.Warning.Println(k.Err("'%s' is not an integer. (%s)",
splitted[1], err))
return
}
// finally...
clr.GradientSet(int(start), int(end))
}
开发者ID:Pursuit92,项目名称:wingo,代码行数:47,代码来源:config_theme_setters.go
示例4: setNoGradient
func setNoGradient(k wini.Key, clr *render.Color) {
// Check to make sure we have a value for this key
vals := k.Strings()
if len(vals) == 0 {
logger.Warning.Println(k.Err("No values found."))
return
}
// Use the last value
val := vals[len(vals)-1]
// If there are no spaces, it can't be a gradient.
if strings.Index(val, " ") == -1 {
if start, ok := getLastInt(k); ok {
clr.ColorSet(start)
}
return
}
logger.Warning.Println(
k.Err("Gradients are not supported for this theme option."))
}
开发者ID:Pursuit92,项目名称:wingo,代码行数:22,代码来源:config_theme_setters.go
注:本文中的github.com/BurntSushi/wingo/render.Color类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论