mirror of
https://github.com/diamondburned/cchat-gtk.git
synced 2024-11-16 03:02:45 +00:00
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package icons
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/gotk3/gotk3/cairo"
|
|
"github.com/gotk3/gotk3/gdk"
|
|
)
|
|
|
|
// static assets
|
|
// var assets = map[string]*gdk.Pixbuf{}
|
|
|
|
func Logo256Variant2(sz, scale int) *cairo.Surface {
|
|
return mustSurface(loadPixbuf(__cchat_variant2_256, sz, scale), scale)
|
|
}
|
|
|
|
func Logo256(sz, scale int) *cairo.Surface {
|
|
return mustSurface(loadPixbuf(__cchat_256, sz, scale), scale)
|
|
}
|
|
|
|
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 {
|
|
l, err := gdk.PixbufLoaderNew()
|
|
if err != nil {
|
|
log.Fatalln("Failed to create a pixbuf loader for icons:", err)
|
|
}
|
|
|
|
if sz > 0 {
|
|
l.Connect("size-prepared", func(l *gdk.PixbufLoader) {
|
|
l.SetSize(sz*scale, sz*scale)
|
|
})
|
|
}
|
|
|
|
p, err := l.WriteAndReturnPixbuf(data)
|
|
if err != nil {
|
|
log.Fatalln("Failed to write and return pixbuf:", err)
|
|
}
|
|
|
|
return p
|
|
}
|