2020-06-13 07:29:32 +00:00
|
|
|
package icons
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
2020-12-30 06:30:41 +00:00
|
|
|
"github.com/gotk3/gotk3/cairo"
|
2020-06-13 07:29:32 +00:00
|
|
|
"github.com/gotk3/gotk3/gdk"
|
|
|
|
)
|
|
|
|
|
|
|
|
// static assets
|
2020-12-30 06:30:41 +00:00
|
|
|
// var assets = map[string]*gdk.Pixbuf{}
|
2020-07-16 05:41:21 +00:00
|
|
|
|
2020-12-30 06:30:41 +00:00
|
|
|
func Logo256Variant2(sz, scale int) *cairo.Surface {
|
|
|
|
return mustSurface(loadPixbuf(__cchat_variant2_256, sz, scale), scale)
|
2020-07-16 05:41:21 +00:00
|
|
|
}
|
2020-06-13 07:29:32 +00:00
|
|
|
|
2020-12-30 06:30:41 +00:00
|
|
|
func Logo256(sz, scale int) *cairo.Surface {
|
|
|
|
return mustSurface(loadPixbuf(__cchat_256, sz, scale), scale)
|
2020-06-13 07:29:32 +00:00
|
|
|
}
|
|
|
|
|
2020-12-30 06:30:41 +00:00
|
|
|
func Logo256Pixbuf() *gdk.Pixbuf {
|
|
|
|
return loadPixbuf(__cchat_256, 256, 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
func mustSurface(p *gdk.Pixbuf, scale int) *cairo.Surface {
|
|
|
|
surface, err := gdk.CairoSurfaceCreateFromPixbuf(p, scale, nil)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln("Failed to create surface from pixbuf:", err)
|
|
|
|
}
|
|
|
|
return surface
|
|
|
|
}
|
|
|
|
|
|
|
|
func loadPixbuf(data []byte, sz, scale int) *gdk.Pixbuf {
|
2020-06-13 07:29:32 +00:00
|
|
|
l, err := gdk.PixbufLoaderNew()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln("Failed to create a pixbuf loader for icons:", err)
|
|
|
|
}
|
|
|
|
|
2020-07-17 00:21:14 +00:00
|
|
|
if sz > 0 {
|
2020-12-30 06:30:41 +00:00
|
|
|
l.Connect("size-prepared", func(l *gdk.PixbufLoader) {
|
|
|
|
l.SetSize(sz*scale, sz*scale)
|
|
|
|
})
|
2020-07-17 00:21:14 +00:00
|
|
|
}
|
|
|
|
|
2020-07-16 05:41:21 +00:00
|
|
|
p, err := l.WriteAndReturnPixbuf(data)
|
2020-06-13 07:29:32 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln("Failed to write and return pixbuf:", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return p
|
|
|
|
}
|