#!/usr/bin/env python3 """Generic gamepad diagrams for the Charge Kid controller menu (CC0, made for fredygames.com). The game ships three line drawings of console-specific controllers (their own button symbols and names). The build replaces them with these: same sizes, only generic labels (L1, L2, Up, Top, Bottom, Select, Start...). python3 -I gen-controller-diagrams.py """ import sys from PIL import Image, ImageDraw, ImageFont CREAM = (238, 238, 204, 255) SIZES = {'microsoft': (352, 224), 'nintendo': (256, 224), 'sony': (384, 224)} LEFT = ['L2', 'L1', 'Up', 'Right', 'Left', 'Down', 'Select'] RIGHT = ['R2', 'R1', 'Top', 'Left', 'Right', 'Bottom', 'Start'] def main(font_path, out_dir): big = ImageFont.truetype(font_path, 16) small = ImageFont.truetype(font_path, 8) for name, (w, h) in SIZES.items(): im = Image.new('RGBA', (w, h), (0, 0, 0, 0)) d = ImageDraw.Draw(im) d.fontmode = '1' # no anti-aliasing: crisp pixels for i in range(7): y = 11 + 32 * i for side, labels in ((0, LEFT), (1, RIGHT)): text = labels[i] font = big if i < 2 else small tw = d.textlength(text, font=font) th = 16 if i < 2 else 8 if side == 0: d.line([(0, y), (44, y)], fill=CREAM, width=2) d.text((52, y - th // 2), text, font=font, fill=CREAM) else: d.line([(w - 45, y), (w - 1, y)], fill=CREAM, width=2) d.text((w - 52 - tw, y - th // 2), text, font=font, fill=CREAM) im.save('%s/controller-%s.png' % (out_dir, name), optimize=False) if __name__ == '__main__': main(sys.argv[1], sys.argv[2])