-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgenerate_icon.py
More file actions
148 lines (126 loc) · 5.52 KB
/
generate_icon.py
File metadata and controls
148 lines (126 loc) · 5.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env python3
"""Generate StreaMonitor app icon (.ico + embedded C header for GLFW)."""
import struct, io, math, os
from PIL import Image, ImageDraw, ImageFont
def make_icon_image(size):
"""Create a single icon at the given size."""
img = Image.new("RGBA", (size, size), (0, 0, 0, 0))
draw = ImageDraw.Draw(img)
s = size # shorthand
pad = max(1, s // 16)
# ── Background: rounded rectangle with gradient-like dark blue ────
# Dark blue/purple gradient feel
bg_color = (22, 27, 46, 255) # deep navy
accent = (90, 140, 255, 255) # bright blue accent
rec_red = (255, 50, 60, 255) # recording red dot
text_col = (230, 235, 250, 255) # near-white text
# Rounded rect background
r = max(2, s // 6)
draw.rounded_rectangle([pad, pad, s - pad - 1, s - pad - 1],
radius=r, fill=bg_color)
# ── Monitor outline (accent blue) ────────────────────────────────
# Monitor body: top 65% of the icon area
mx1 = s * 0.12
my1 = s * 0.10
mx2 = s * 0.88
my2 = s * 0.62
mr = max(1, s // 20)
lw = max(1, s // 24)
draw.rounded_rectangle([mx1, my1, mx2, my2], radius=mr,
outline=accent, width=lw)
# Monitor stand (stem + base)
cx = s * 0.5
draw.line([(cx, my2), (cx, s * 0.72)], fill=accent, width=lw)
bw = s * 0.22
draw.line([(cx - bw, s * 0.72), (cx + bw, s * 0.72)],
fill=accent, width=lw)
# ── "SM" text inside monitor ─────────────────────────────────────
# Use a built-in font scaled to fit inside the monitor
font_size = max(8, int(s * 0.28))
try:
font = ImageFont.truetype("arialbd.ttf", font_size)
except (OSError, IOError):
try:
font = ImageFont.truetype("arial.ttf", font_size)
except (OSError, IOError):
font = ImageFont.load_default()
text = "SM"
bbox = draw.textbbox((0, 0), text, font=font)
tw, th = bbox[2] - bbox[0], bbox[3] - bbox[1]
tx = (mx1 + mx2) / 2 - tw / 2 - bbox[0]
ty = (my1 + my2) / 2 - th / 2 - bbox[1]
draw.text((tx, ty), text, fill=text_col, font=font)
# ── Recording red dot (top-right of monitor) ─────────────────────
dot_r = max(1, s // 14)
dot_cx = mx2 - dot_r - lw
dot_cy = my1 + dot_r + lw + max(1, s // 32)
draw.ellipse([dot_cx - dot_r, dot_cy - dot_r,
dot_cx + dot_r, dot_cy + dot_r], fill=rec_red)
# ── Signal waves (bottom-right, small) ───────────────────────────
if s >= 32:
wave_cx = s * 0.78
wave_cy = s * 0.86
for i in range(1, 3):
wr = s * 0.04 * i
arc_lw = max(1, s // 40)
bbox_arc = [wave_cx - wr, wave_cy - wr, wave_cx + wr, wave_cy + wr]
draw.arc(bbox_arc, start=220, end=320, fill=accent, width=arc_lw)
return img
def generate_c_header(img, path):
"""Save 32x32 RGBA image as a C header for GLFW window icon."""
pixels = list(img.getdata())
w, h = img.size
with open(path, "w") as f:
f.write("// Auto-generated by generate_icon.py - DO NOT EDIT\n")
f.write("#pragma once\n\n")
f.write(f"static const int kIconWidth = {w};\n")
f.write(f"static const int kIconHeight = {h};\n\n")
f.write(f"// {w}x{h} RGBA pixel data ({w*h*4} bytes)\n")
f.write("static const unsigned char kIconPixels[] = {\n")
line = " "
for i, (r, g, b, a) in enumerate(pixels):
line += f"0x{r:02x},0x{g:02x},0x{b:02x},0x{a:02x},"
if (i + 1) % 8 == 0:
f.write(line + "\n")
line = " "
if line.strip():
f.write(line + "\n")
f.write("};\n")
def main():
out_dir = os.path.join(os.path.dirname(__file__), "src", "resources")
os.makedirs(out_dir, exist_ok=True)
# Generate multi-size .ico
sizes = [16, 24, 32, 48, 64, 128, 256]
images = [make_icon_image(s) for s in sizes]
ico_path = os.path.join(out_dir, "app_icon.ico")
images[0].save(ico_path, format="ICO",
sizes=[(s, s) for s in sizes],
append_images=images[1:])
print(f"[OK] {ico_path}")
# Generate C header from 48x48 version (good for window title bar)
header_path = os.path.join(out_dir, "icon_data.h")
# Use 48x48 for the GLFW icon (sharp at typical title bar sizes)
img48 = make_icon_image(48)
generate_c_header(img48, header_path)
print(f"[OK] {header_path}")
# Also generate a 16x16 for small icon
with open(header_path, "a") as f:
img16 = make_icon_image(16)
pixels = list(img16.getdata())
f.write("\n// 16x16 small icon\n")
f.write(f"static const int kIconSmallWidth = 16;\n")
f.write(f"static const int kIconSmallHeight = 16;\n\n")
f.write("static const unsigned char kIconSmallPixels[] = {\n")
line = " "
for i, (r, g, b, a) in enumerate(pixels):
line += f"0x{r:02x},0x{g:02x},0x{b:02x},0x{a:02x},"
if (i + 1) % 8 == 0:
f.write(line + "\n")
line = " "
if line.strip():
f.write(line + "\n")
f.write("};\n")
print(f"[OK] {header_path} (small icon appended)")
print("\nDone! Icon files generated in src/resources/")
if __name__ == "__main__":
main()