diff --git a/branding/resources/emi/textures/gui/buttons.png b/branding/resources/emi/textures/gui/buttons.png index 6590850..c8c3c9e 100644 Binary files a/branding/resources/emi/textures/gui/buttons.png and b/branding/resources/emi/textures/gui/buttons.png differ diff --git a/tools/branding/build.py b/tools/branding/build.py index 20d74e7..f4a1010 100644 --- a/tools/branding/build.py +++ b/tools/branding/build.py @@ -474,51 +474,65 @@ def casingify(sheet: Image.Image, wood: np.ndarray, frame, face=None) -> Image.I return Image.fromarray(np.clip(out, 0, 255).astype(np.uint8), 'RGBA') -def casing_buttons(sheet: Image.Image, wood: np.ndarray, brass_wood: np.ndarray, frame, tiles, cell: int = 12) -> Image.Image: - """EMI's buttons: a grid of 12 x 12 cells, each a black ring, a one-pixel bevel and a flat face with a symbol. - The ring stays (a white ring — the highlighted state — turns brass), the bevel becomes the casing's metal frame, - a grey face becomes wood (brass casing's darker wood when highlighted, dimmed when disabled); a coloured face (EMI's - green "switched on") keeps its colour. Symbols are kept, grey ones in cream.""" +# EMI's buttons.png (EMI 1.1): where each button is, as (x, y, width, height). EMI draws them from these rectangles, +# so each one is rebuilt inside its own bounds — a grid over the whole sheet cut the bigger ones apart. +EMI_BUTTON_CELLS = ( + [(x, y, 12, 12) for y in range(0, 84, 12) for x in range(0, 84, 12)] # small buttons, 3 states each + + [(x, y, 20, 20) for x in (164, 184, 204) for y in (0, 20)] # config, tree, "EMI" + + [(164, 40, 20, 20), (164, 60, 20, 20)] # the globe button + + [(x, y, 16, 16) for x in (224, 240) for y in (0, 16, 32)] # page arrows + + [(x, y, 12, 10) for x in (232, 244) for y in (48, 58)] # small up / down +) + + +def casing_buttons(sheet: Image.Image, wood: np.ndarray, brass_wood: np.ndarray, frame, tiles, cells=EMI_BUTTON_CELLS) -> Image.Image: + """EMI's buttons rebuilt like ours. Each cell is a 1 px ring, a 1 px bevel and a flat face with a symbol. The ring + stays (a white ring — the highlighted state — turns brass), the bevel takes the casing's metal from the block's own + edge, a grey face becomes wood (brass casing's wood when highlighted, dimmed when disabled), a coloured face (EMI's + green "on") keeps its colour; symbols are kept, grey ones in cream, their dark shadows in dark wood.""" px = np.asarray(sheet.convert('RGBA')).astype(np.float32) out = px.copy() - for cy in range(0, px.shape[0], cell): - for cx in range(0, px.shape[1], cell): - c = px[cy:cy + cell, cx:cx + cell] - if c.shape[:2] != (cell, cell) or (c[..., 3] > 0).sum() < cell * cell * 0.9: - continue - lum = c[..., :3].mean(axis=2) - ring = np.zeros((cell, cell), bool) - ring[0, :] = ring[-1, :] = ring[:, 0] = ring[:, -1] = True - bevel = np.zeros((cell, cell), bool) - bevel[1, 1:-1] = bevel[-2, 1:-1] = bevel[1:-1, 1] = bevel[1:-1, -2] = True - inside = ~ring & ~bevel - if lum[ring].mean() > 90 and lum[ring].mean() < 200: - continue # not a button cell - hot = lum[ring].mean() >= 200 - face = np.median(c[inside][:, :3], axis=0) # the face is textured; the symbol covers less of it - face_lum = face.mean() - coloured = face.max() - face.min() > 30 - dim = face_lum < 70 and not coloured - light, dark = (BRASS[3], BRASS[0]) if hot else frame - o = out[cy:cy + cell, cx:cx + cell] - if hot: - o[ring, :3] = BRASS[1] - for y in range(cell): - for x in range(cell): - if bevel[y, x]: # the casing's metal, from the block's own edge - tile = tiles[1] if hot else tiles[0] - o[y, x, :3] = (tile[1, 3 + x % 10] if y == 1 else tile[14, 3 + x % 10] if y == cell - 2 - else tile[3 + y % 10, 1] if x == 1 else tile[3 + y % 10, 14]) - elif inside[y, x]: - p = c[y, x, :3] - if abs(p.mean() - face_lum) <= 28: # the face - if not coloured: - grain = (brass_wood if hot else wood)[(cy + y) % 16, (cx + x) % 16] - o[y, x, :3] = grain * (0.5 if dim else 1.0) - elif p.mean() < face_lum: # the symbol's shadow - o[y, x, :3] = (brass_wood if hot else wood)[(cy + y) % 16, (cx + x) % 16] * 0.4 - elif p.max() - p.min() < 24: # a grey symbol - o[y, x, :3] = np.array(CREAM, np.float32) * (0.55 if dim else 1.0) + for cx, cy, w, h in cells: + c = px[cy:cy + h, cx:cx + w] + if c.shape[:2] != (h, w) or (c[..., 3] > 0).sum() < w * h * 0.9: + continue # an empty place in the grid + lum = c[..., :3].mean(axis=2) + ring = np.zeros((h, w), bool) + ring[0, :] = ring[-1, :] = ring[:, 0] = ring[:, -1] = True + bevel = np.zeros((h, w), bool) + bevel[1, 1:-1] = bevel[-2, 1:-1] = bevel[1:-1, 1] = bevel[1:-1, -2] = True + inside = ~ring & ~bevel + ring_lum = lum[ring].mean() + if 90 < ring_lum < 200: + continue # not a button + hot = ring_lum >= 200 + band = inside.copy() # the face just inside the bevel: no symbol reaches there + band[3:-3, 3:-3] = False # inside is [2:-2]; keep only its outermost pixels + face = np.median(c[band][:, :3], axis=0) + face_lum = face.mean() + coloured = face.max() - face.min() > 30 + dim = face_lum < 70 and not coloured + tile = tiles[1] if hot else tiles[0] + grain = brass_wood if hot else wood + o = out[cy:cy + h, cx:cx + w] + if hot: + o[ring, :3] = BRASS[1] + for y in range(h): + for x in range(w): + if bevel[y, x]: # the casing's metal, from the block's own edge + o[y, x, :3] = (tile[1, 3 + x % 10] if y == 1 else tile[14, 3 + x % 10] if y == h - 2 + else tile[3 + y % 10, 1] if x == 1 else tile[3 + y % 10, 14]) + elif inside[y, x]: + p = c[y, x, :3] + if np.abs(p - face).max() <= 28: # the face (by colour: a blue globe is as bright as grey) + if not coloured: + o[y, x, :3] = grain[(cy + y) % 16, (cx + x) % 16] * (0.5 if dim else 1.0) + elif p.max() - p.min() >= 24: # a coloured symbol (the globe, EMI's letters): as it is + continue + elif p.mean() < face_lum: # a symbol's shadow + o[y, x, :3] = grain[(cy + y) % 16, (cx + x) % 16] * 0.4 + else: # a grey symbol + o[y, x, :3] = np.array(CREAM, np.float32) * (0.55 if dim else 1.0) return Image.fromarray(np.clip(out, 0, 255).astype(np.uint8), 'RGBA')