pixie/tests/megatest_icons.nim

71 lines
1.9 KiB
Nim
Raw Normal View History

2021-02-23 07:54:48 +00:00
import cligen, os, pixie, pixie/fileformats/svg, strformat
# Clone https://github.com/twbs/icons
# Check out commit f364cb14dfc0703b9e3ef10c8b490a71dfef1e9d
2021-02-23 07:54:48 +00:00
# Clone https://github.com/icons8/flat-color-icons
# Check out commit 8eccbbbd8b2af1d2c9593e7cfba5ecb0d68ee378
# Clone https://github.com/ionic-team/ionicons
# Check out commit 0d7f507677f8d317ce6882729ffecf46e215e01a
# Clone https://github.com/tabler/tabler-icons
# Check out commit ccf2784b57e42a2b2221963f92146fd7b249b5b7
# Clone https://github.com/simple-icons/simple-icons
# Check out commit 355454cb6caa02aba70638631c557d4e06205710
type IconSet = object
name: string
path: string
const
2021-02-23 07:54:48 +00:00
iconSets = [
IconSet(name: "twbs-icons", path: "../icons/icons/*"),
IconSet(name: "flat-color-icons", path: "../flat-color-icons/svg/*"),
IconSet(name: "ionicons", path: "../ionicons/src/svg/*"),
2021-02-23 23:28:18 +00:00
IconSet(name: "tabler-icons", path: "../tabler-icons/icons/*"),
2021-02-23 22:22:29 +00:00
IconSet(name: "simple-icons", path: "../simple-icons/icons/*")
2021-02-23 07:54:48 +00:00
]
width = 32
height = 32
2021-02-23 07:54:48 +00:00
proc renderIconSet(index: int) =
let iconSet = iconSets[index]
var images: seq[(string, Image)]
for filePath in walkFiles(iconSet.path):
let
(_, name, _) = splitFile(filePath)
2022-05-22 01:05:13 +00:00
image = newImage(parseSvg(readFile(filePath), width, height))
2021-02-23 07:54:48 +00:00
images.add((name, image))
let
2021-02-23 07:58:23 +00:00
columns = 40
2021-02-23 07:54:48 +00:00
rows = (images.len + columns - 1) div columns
rendered = newImage((width + 4) * columns, (height + 4) * rows)
for i in 0 ..< rows:
for j in 0 ..< max(images.len - i * columns, 0):
2021-08-12 03:54:55 +00:00
let
(_, icon) = images[i * columns + j]
pos = vec2(((width + 4) * j + 2).float32, ((height + 4) * i + 2).float32)
2021-02-23 07:54:48 +00:00
rendered.draw(
icon,
2021-08-12 03:54:55 +00:00
translate(pos),
2022-02-14 04:02:37 +00:00
OverwriteBlend
2021-02-23 07:54:48 +00:00
)
2021-10-03 22:49:21 +00:00
rendered.writeFile(&"tests/fileformats/svg/{iconSet.name}.png")
2021-02-23 07:54:48 +00:00
proc main(index = -1) =
if index >= 0:
renderIconSet(index)
else:
for i in 0 ..< iconSets.len:
renderIconSet(i)
dispatch(main)