Exemple #1
0
func loadImageDirectory(ctx *nanovgo.Context, dir string) []nanogui.Image {
	var images []nanogui.Image
	files, err := AssetDir("icons")
	if err != nil {
		panic(err)
	}
	for _, file := range files {
		fullPath := fmt.Sprintf("%s/%s", "icons", file)
		img := ctx.CreateImageFromMemory(0, MustAsset(fullPath))
		if img == 0 {
			panic("Could not open image data!")
		}
		images = append(images, nanogui.Image{
			ImageID: img,
			Name:    fullPath[:len(fullPath)-4],
		})
	}
	return images
}
Exemple #2
0
func LoadDemo(ctx *nanovgo.Context) *demo.DemoData {
	d := &demo.DemoData{}
	for i := 0; i < 12; i++ {
		path := fmt.Sprintf("assets/image%d.jpg", i+1)
		d.Images = append(d.Images, ctx.CreateImageFromMemory(0, demo.MustAsset(path)))
		if d.Images[i] == 0 {
			log.Fatalf("Could not load %s", path)
		}
	}

	d.FontIcons = ctx.CreateFontFromMemory("icons", demo.MustAsset("assets/entypo.ttf"), 0)
	if d.FontIcons == -1 {
		log.Fatalln("Could not add font icons.")
	}
	d.FontNormal = ctx.CreateFontFromMemory("sans", demo.MustAsset("assets/Roboto-Regular.ttf"), 0)
	if d.FontNormal == -1 {
		log.Fatalln("Could not add font italic.")
	}
	d.FontBold = ctx.CreateFontFromMemory("sans-bold", demo.MustAsset("assets/Roboto-Bold.ttf"), 0)
	if d.FontBold == -1 {
		log.Fatalln("Could not add font bold.")
	}
	return d
}