shithub: wildlife

Download patch

ref: 50c527fe9f81010d304f49ce51dfc39a16cdec6c
parent: eca59fe0c9f2e78eca5246e626950ee5b408ca12
author: Philip Silva <philip.silva@protonmail.com>
date: Wed Mar 30 06:58:23 EDT 2022

add animals

--- a/main.go
+++ b/main.go
@@ -23,9 +23,32 @@
 var (
 	dui *duit.DUI
 	scale int
+
+	history []*Item
+	lastM draw.Mouse
 )
 
+type Category int
+
+const (
+	About Category = iota
+	Animal
+)
+
+func (c Category) path() string {
+	switch c {
+	case About:
+		return "about"
+	case Animal:
+		return "animal"
+	}
+	log.Fatalf("%v unknown", c)
+	return ""
+}
+
 type Folder struct {
+	Category
+
 	Pre string
 	Suf string
 	Name string
@@ -74,7 +97,7 @@
 	for key, it := range f.Items {
 		if key == k {
 			if it.Image == nil {
-				fn := fmt.Sprintf("./data/about/%v%v/%v%v.dib", f.Pre, f.Suf, f.Pre, k)
+				fn := fmt.Sprintf("./data/%v/%v%v/%v%v.dib", f.Category.path(), f.Pre, f.Suf, f.Pre, k)
 				it.Image = &duit.Image{
 					Image: readImagePath(fn),
 				}
@@ -85,11 +108,6 @@
 	return nil
 }
 
-/*func (f Folder) getItem(k string) string {
-	fnSuf := k
-	return fmt.Sprintf("./data/about/%v%v/%v%v.dib", f.Pre, f.Suf, f.Pre, fnSuf)
-}*/
-
 type Item struct {
 	*duit.Image
 
@@ -99,10 +117,14 @@
 }
 
 func (it *Item) Mouse(dui *duit.DUI, self *duit.Kid, m draw.Mouse, origM draw.Mouse, orig image.Point) (r duit.Result) {
-	if m.Buttons&1 == 1 {
-		//log.Printf("m=%+v, origM=%+v", m, origM)
+	defer func() {
+		lastM = m
+	}()
+	if m.Buttons&1 == 1 && lastM.Buttons&1 == 0 {
+		//log.Printf("m= %v,%v", m.Point.X*2/scale, m.Point.Y*2/scale)
 		for k, t := range it.Targets {
 			if t.has(m.Point) {
+				history = append(history, it)
 				fName, itName := it.f.Decode(k)
 				_=fName
 				tf := getFolder(it.f.Pre, k)
@@ -120,8 +142,13 @@
 			Consumed: true,
 		}
 	} else if m.Buttons&4 == 4 {
-		tf := getFolder("", "cont")
-		it := tf.Main()
+		var it *Item
+		if l := len(history); l > 0 {
+			it, history = history[l-1], history[:l-1]
+		} else {
+			tf := getFolder("", "cont")
+			it = tf.Main()
+		}
 		dui.Top.UI = it
 		dui.MarkLayout(dui.Top.UI)
 		dui.MarkDraw(dui.Top.UI)
@@ -168,6 +195,7 @@
 }
 
 var folders = []*Folder{
+	/* about */
 	&Folder{
 		Pre: "afri",
 		Suf: "00aa",
@@ -205,6 +233,24 @@
 			},
 			"01pu": &Item{
 				name: "Africa",
+				Targets: map[string]Target{
+					"leop": C(114,610,80),
+					"babn": C(348,568,55),
+					"cock": C(474,716,40),
+					"01p2": C(200,292,100),
+					"01p1": C(680,539,100),
+					"lion": C(468,360,60),
+					"rats": C(391,74,60),
+					"mosq": C(218,147,40),
+					"aant": C(575,124,50),
+					"chee": C(814,256,70),
+					"vult": C(849,72, 90),
+					"hyen": C(906,666,60),
+					"cdog": C(1104,642,80),
+					"fsal": C(1074,428,100),
+					"kbee": C(1130,252,60),
+					"afri": C(1150,68,50),
+				},
 			},
 			"02pu": &Item{
 				name: "Asia",
@@ -214,6 +260,20 @@
 			},
 			"04pu": &Item{
 				name: "Europe",
+				Targets: map[string]Target{
+					"addr": C(852,367,60),
+					"cent": C(714,699, 100),
+					"cock": C(69,256, 100),
+					"crab": C(1013,175, 65),
+					"fsal": C(670,497,80),
+					"gsqu": C(411,95,75),
+					"mosq": C(728,59,50),
+					"rats": C(288,325, 100),
+					"scor": C(160,593, 90),
+					"vult": C(418,610, 70),
+					"wlvr": C(609,193, 70),
+					"wolf": C(1101, 546, 100),
+				},
 			},
 			"05pu": &Item{
 				name: "North America",
@@ -389,6 +449,723 @@
 			"01fb": &Item{},
 		},
 	},
+
+	/* animal */
+	&Folder{
+		Category: Animal,
+		Pre: "addr",
+		Suf: "00aa",
+		Name: "European Adder",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "European Adder",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "aant",
+		Suf: "00aa",
+		Name: "Army Ant",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Army Ant",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "alig",
+		Suf: "00aa",
+		Name: "Aligator",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Aligator",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "arow",
+		Suf: "00aa",
+		Name: "Poison Arrow Frog",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Poison Arrow Frog",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "babn",
+		Suf: "00aa",
+		Name: "Baboon",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Baboon",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "bara",
+		Suf: "00aa",
+		Name: "Baracuda",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Baracuda",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "boac",
+		Suf: "00aa",
+		Name: "Boa",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Boa",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "boct",
+		Suf: "00aa",
+		Name: "Blue-ringed Octopus",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Blue-ringed Octopus",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "bwid",
+		Suf: "00aa",
+		Name: "Black Widow Spider",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Black Widow Spider",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "cane",
+		Suf: "00aa",
+		Name: "Cane Toad",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Cane Toad",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "cbuf",
+		Suf: "00aa",
+		Name: "Cape Buffalo",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Cape Buffalo",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "cdog",
+		Suf: "00aa",
+		Name: "Cape Hunting Dog",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Cape Hunting Dog",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "cent",
+		Suf: "00aa",
+		Name: "Centipede",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Centipede",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "chee",
+		Suf: "00aa",
+		Name: "Cheetah",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Cheetah",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "cobr",
+		Suf: "00aa",
+		Name: "Cobra",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Cobra",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "cock",
+		Suf: "00aa",
+		Name: "Cockroach",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Cockroach",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "coug",
+		Suf: "00aa",
+		Name: "Cougar",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Cougar",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "crab",
+		Suf: "00aa",
+		Name: "Crab",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Crab",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "croc",
+		Suf: "00aa",
+		Name: "Crocodile",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Crocodile",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "eeel",
+		Suf: "00aa",
+		Name: "Electric Eel",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Electric Eel",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "elef",
+		Suf: "00aa",
+		Name: "Elefant",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Elefant",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "fsal",
+		Suf: "00aa",
+		Name: "Fire Salamander",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Fire Salamander",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "funl",
+		Suf: "00aa",
+		Name: "Funnel-web Spider",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Funnel-web Spider",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "gila",
+		Suf: "00aa",
+		Name: "Gila Monster",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Gila Monster",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "griz",
+		Suf: "00aa",
+		Name: "Grizzly Bear",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Grizzly Bear",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "gsqu",
+		Suf: "00aa",
+		Name: "Giant Squid",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Giant Squid",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "gwsh",
+		Suf: "00aa",
+		Name: "Great White Shark",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Great White Shark",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "gwsh",
+		Suf: "00aa",
+		Name: "Hammerhead Shark",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Hammerhead Shark",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "harp",
+		Suf: "00aa",
+		Name: "Harpy Eagle",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Harpy Eagle",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "hipp",
+		Suf: "00aa",
+		Name: "Hippopotamus",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Hippopotamus",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "hyen",
+		Suf: "00aa",
+		Name: "Hyena",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Hyena",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "jagu",
+		Suf: "00aa",
+		Name: "Jaguar",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Jaguar",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "kbee",
+		Suf: "00aa",
+		Name: "Killer Bee",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Killer Bee",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "komd",
+		Suf: "00aa",
+		Name: "Komodo Dragon",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Komodo Dragon",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "leop",
+		Suf: "00aa",
+		Name: "Leopard",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Leopard",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "lfsh",
+		Suf: "00aa",
+		Name: "Lionfish",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Lionfish",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "lion",
+		Suf: "00aa",
+		Name: "Lion",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Lion",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "mamb",
+		Suf: "00aa",
+		Name: "Black Mamba",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Black Mamba",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "mang",
+		Suf: "00aa",
+		Name: "Mangrove Snake",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Mangrove Snake",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "meel",
+		Suf: "00aa",
+		Name: "Moray Eel",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Moray Eel",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "mosq",
+		Suf: "00aa",
+		Name: "Mosquito",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Mosquito",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "mwar",
+		Suf: "00aa",
+		Name: "Portuguese Man-of-War",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Portuguese Man-of-War",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "orca",
+		Suf: "00aa",
+		Name: "Killer Whale",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Killer Whale",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "pbea",
+		Suf: "00aa",
+		Name: "Polar Bear",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Polar Bear",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "pira",
+		Suf: "00aa",
+		Name: "Piranha",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Piranha",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "plat",
+		Suf: "00aa",
+		Name: "Platypus",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Platypus",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "porc",
+		Suf: "00aa",
+		Name: "Porcupine Fish",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Porcupine Fish",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "post",
+		Suf: "00aa",
+		Name: "Passion-vine Caterpillar",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Passion-vine Caterpillar",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "pyth",
+		Suf: "00aa",
+		Name: "Python",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Python",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "rats",
+		Suf: "00aa",
+		Name: "Rats",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Rats",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "rhin",
+		Suf: "00aa",
+		Name: "Rhinoceros",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Rhinoceros",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "rttl",
+		Suf: "00aa",
+		Name: "Rattlesnake",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Rattlesnake",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "scor",
+		Suf: "00aa",
+		Name: "Scorpion",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Scorpion",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "seas",
+		Suf: "00aa",
+		Name: "Sea Snake",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Sea Snake",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "snap",
+		Suf: "00aa",
+		Name: "Snapping Turtle",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Snapping Turtle",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "sray",
+		Suf: "00aa",
+		Name: "Stingray",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Stingray",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "swsp",
+		Suf: "00aa",
+		Name: "Australian Sea Wasp",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Australian Sea Wasp",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "tasm",
+		Suf: "00aa",
+		Name: "Tasmanian Devil",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Tasmanian Devil",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "tigr",
+		Suf: "00aa",
+		Name: "Tiger",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Tiger",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "vamp",
+		Suf: "00aa",
+		Name: "Vampire Bat",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Vampire Bat",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "vult",
+		Suf: "00aa",
+		Name: "Vulture",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Vulture",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "wart",
+		Suf: "00aa",
+		Name: "Warthog",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Warthog",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "wasp",
+		Suf: "00aa",
+		Name: "Wasp",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Wasp",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "wlvr",
+		Suf: "00aa",
+		Name: "Wolverine",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Wolverine",
+			},
+		},
+	},
+	&Folder{
+		Category: Animal,
+		Pre: "wolf",
+		Suf: "00aa",
+		Name: "Wolf",
+		Items: map[string]*Item{
+			"00aa": &Item{
+				name: "Wolf",
+			},
+		},
+	},
 }
 
 func init() {
@@ -462,8 +1239,9 @@
 	}
 
 	f := getFolder("", "cont")
-
-	dui.Top.UI = f.Main()
+	it := f.Main()
+	history = append(history, it)
+	dui.Top.UI = it
 	dui.Render()
 
 	for {