diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 67f7b75..43f1b97 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -21,6 +21,7 @@ diff --git a/android/app/src/main/res/drawable/ic_launcher_foreground.xml b/android/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..7aaa34e --- /dev/null +++ b/android/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + diff --git a/android/app/src/main/res/mipmap-anydpi/ic_launcher.xml b/android/app/src/main/res/mipmap-anydpi/ic_launcher.xml new file mode 100644 index 0000000..bcdeecd --- /dev/null +++ b/android/app/src/main/res/mipmap-anydpi/ic_launcher.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/ts3-client/swing/src/main/java/com/ts3client/ui/DesktopEntry.java b/ts3-client/swing/src/main/java/com/ts3client/ui/DesktopEntry.java index 79d6f6c..a9ec5e2 100644 --- a/ts3-client/swing/src/main/java/com/ts3client/ui/DesktopEntry.java +++ b/ts3-client/swing/src/main/java/com/ts3client/ui/DesktopEntry.java @@ -35,7 +35,7 @@ public final class DesktopEntry { private DesktopEntry() { } - /** Call on the event thread once the look-and-feel is installed (the icon uses its accent). */ + /** Call on the event thread. */ public static void install() { if (!System.getProperty("os.name", "").toLowerCase(Locale.ROOT).startsWith("linux") || !Boolean.parseBoolean(System.getProperty("ts3j.desktopEntry", "true"))) { diff --git a/ts3-client/swing/src/main/java/com/ts3client/ui/IconTheme.java b/ts3-client/swing/src/main/java/com/ts3client/ui/IconTheme.java index 8150bae..283b75e 100644 --- a/ts3-client/swing/src/main/java/com/ts3client/ui/IconTheme.java +++ b/ts3-client/swing/src/main/java/com/ts3client/ui/IconTheme.java @@ -145,7 +145,7 @@ public final class IconTheme { return c != null ? c : Color.BLACK; } - private static BufferedImage rasterize(byte[] data, int size) { + static BufferedImage rasterize(byte[] data, int size) { try { SVGDocument document = new SVGLoader().load( new ByteArrayInputStream(data), null, LoaderContext.createDefault()); diff --git a/ts3-client/swing/src/main/java/com/ts3client/ui/Icons.java b/ts3-client/swing/src/main/java/com/ts3client/ui/Icons.java index b889519..1bafb4a 100644 --- a/ts3-client/swing/src/main/java/com/ts3client/ui/Icons.java +++ b/ts3-client/swing/src/main/java/com/ts3client/ui/Icons.java @@ -10,6 +10,8 @@ import java.awt.Graphics2D; import java.awt.Image; import java.awt.RenderingHints; import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.InputStream; import java.util.List; /** @@ -301,8 +303,15 @@ public final class Icons { return app(small()); } + /** Below 32 pixels a variant with a bolder headset, whose thin lines would blur away. */ public static ImageIcon app(int size) { - return make(size, Icons::paintApp); + String name = size < 32 ? "app-icon-small.svg" : "app-icon.svg"; + try (InputStream in = Icons.class.getResourceAsStream(name)) { + BufferedImage image = IconTheme.rasterize(in.readAllBytes(), size); + if (image != null) return new ImageIcon(image); + } catch (IOException | RuntimeException ignored) { + } + return new ImageIcon(new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB)); } /** The window icon at the sizes task bars and switchers pick from. */ @@ -475,14 +484,4 @@ public final class Icons { g.drawLine(x1, y1, x2, y2); } } - - private static void paintApp(Graphics2D g) { - g.setColor(Theme.accent()); - g.fillRoundRect(1, 1, 14, 14, 4, 4); - g.setColor(Color.WHITE); - g.setStroke(new BasicStroke(1.6f)); - g.drawArc(4, 5, 8, 8, 30, 120); - g.drawArc(2, 3, 12, 12, 30, 120); - g.fillOval(7, 9, 2, 2); - } } diff --git a/ts3-client/swing/src/main/java/com/ts3client/ui/MainFrame.java b/ts3-client/swing/src/main/java/com/ts3client/ui/MainFrame.java index 2d0e03a..10dbcff 100644 --- a/ts3-client/swing/src/main/java/com/ts3client/ui/MainFrame.java +++ b/ts3-client/swing/src/main/java/com/ts3client/ui/MainFrame.java @@ -43,6 +43,7 @@ import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.KeyboardFocusManager; +import java.awt.Taskbar; import java.awt.event.ActionEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; @@ -136,6 +137,10 @@ public final class MainFrame extends JFrame implements ServerTabPane.Listener { contacts.addListener(() -> SwingUtilities.invokeLater(this::contactsChanged)); setIconImages(Icons.appImages()); + // The macOS dock ignores window icons. + if (Taskbar.isTaskbarSupported() && Taskbar.getTaskbar().isSupported(Taskbar.Feature.ICON_IMAGE)) { + Taskbar.getTaskbar().setIconImage(Icons.app(256).getImage()); + } // We tear the connections down ourselves on close, so don't let Swing kill the JVM. setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { diff --git a/ts3-client/swing/src/main/resources/com/ts3client/ui/app-icon-small.svg b/ts3-client/swing/src/main/resources/com/ts3client/ui/app-icon-small.svg new file mode 100644 index 0000000..66e92a8 --- /dev/null +++ b/ts3-client/swing/src/main/resources/com/ts3client/ui/app-icon-small.svg @@ -0,0 +1 @@ + diff --git a/ts3-client/swing/src/main/resources/com/ts3client/ui/app-icon.svg b/ts3-client/swing/src/main/resources/com/ts3client/ui/app-icon.svg new file mode 100644 index 0000000..0e576f7 --- /dev/null +++ b/ts3-client/swing/src/main/resources/com/ts3client/ui/app-icon.svg @@ -0,0 +1 @@ + diff --git a/ts3-client/tools/AppIcon.java b/ts3-client/tools/AppIcon.java new file mode 100644 index 0000000..2efdfa5 --- /dev/null +++ b/ts3-client/tools/AppIcon.java @@ -0,0 +1,180 @@ +import java.awt.BasicStroke; +import java.awt.Shape; +import java.awt.geom.AffineTransform; +import java.awt.geom.Arc2D; +import java.awt.geom.Area; +import java.awt.geom.Ellipse2D; +import java.awt.geom.Path2D; +import java.awt.geom.PathIterator; +import java.awt.geom.Rectangle2D; +import java.awt.geom.RoundRectangle2D; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Locale; + +/** + * Draws the application icon: Rubin's vase, whose outline is two faces looking at each + * other, wearing one headset — the left face talks into its microphone. Writes the + * desktop's SVGs and the Android launcher's foreground. + * + *

Run from the repository root: {@code java ts3-client/tools/AppIcon.java}. + */ +public class AppIcon { + + /** The left face, top to bottom, in a 256 box; the vase is it and its mirror image. */ + static final double[][] PROFILE = { + {74, 52}, {90, 72}, {100, 94}, {102, 103}, {100, 109}, {109, 119}, {118, 129}, + {115, 135}, {106, 137}, {108, 146}, {103, 152}, {106, 160}, {100, 167}, {104, 176}, + {107, 184}, {100, 191}, {92, 197}, {89, 208}, {86, 216}, {74, 224}, {68, 226}}; + + static final String LIGHT = "4FA3FF"; + static final String DARK = "2442B8"; + + /** Headset geometry; the small icon gets a bolder one. */ + record Headset(double earX, double earY, double cupW, double cupH, double band, double bandTop, + double boom, double micX, double micY, double mic, double gap) { + } + + static final Headset LARGE = new Headset(40, 124, 30, 46, 13, 28, 9, 90, 156, 8, 6); + static final Headset SMALL = new Headset(36, 124, 40, 58, 22, 22, 15, 88, 160, 12, 8); + + public static void main(String[] args) throws IOException { + Path root = Path.of(""); + Path ui = root.resolve("ts3-client/swing/src/main/resources/com/ts3client/ui"); + Files.writeString(ui.resolve("app-icon.svg"), svg(path(icon(LARGE), 6))); + Files.writeString(ui.resolve("app-icon-small.svg"), svg(path(icon(SMALL), 0.5))); + Files.writeString(root.resolve("android/app/src/main/res/drawable/ic_launcher_foreground.xml"), + vector(path(icon(LARGE), 6))); + } + + /** The vase with the headset, which a gap keeps apart from it. */ + static Area icon(Headset h) { + Path2D outline = new Path2D.Double(); + outline.moveTo(PROFILE[0][0], PROFILE[0][1]); + spline(outline, PROFILE); + double[][] right = new double[PROFILE.length][]; + for (int i = 0; i < PROFILE.length; i++) { + double[] p = PROFILE[PROFILE.length - 1 - i]; + right[i] = new double[]{256 - p[0], p[1]}; + } + outline.lineTo(right[0][0], right[0][1]); + spline(outline, right); + outline.closePath(); + + Area set = new Area(); + set.add(new Area(cup(h.earX(), h))); + set.add(new Area(cup(256 - h.earX(), h))); + double r = 128 - h.earX(), bandBottom = h.earY() - h.cupH() / 2 + 4; + set.add(stroke(new Arc2D.Double(h.earX(), h.bandTop(), 2 * r, 2 * (bandBottom - h.bandTop()), + 0, 180, Arc2D.OPEN), h.band())); + Path2D boom = new Path2D.Double(); + boom.moveTo(h.earX() + 4, h.earY() + h.cupH() / 2 - 8); + boom.curveTo(h.earX() + 10, h.micY() + 12, h.micX() - 30, h.micY() + 8, h.micX(), h.micY()); + set.add(stroke(boom, h.boom())); + set.add(new Area(new Ellipse2D.Double(h.micX() - h.mic(), h.micY() - h.mic(), 2 * h.mic(), 2 * h.mic()))); + + Area icon = new Area(outline); + icon.subtract(stroke(set, 2 * h.gap())); + icon.add(set); + return icon; + } + + static Shape cup(double x, Headset h) { + return new RoundRectangle2D.Double(x - h.cupW() / 2, h.earY() - h.cupH() / 2, h.cupW(), h.cupH(), + h.cupW() * 0.9, h.cupW() * 0.9); + } + + /** Catmull-Rom through the points; the path is already at the first. */ + static void spline(Path2D path, double[][] pts) { + for (int i = 0; i < pts.length - 1; i++) { + double[] p0 = pts[Math.max(i - 1, 0)], p1 = pts[i], p2 = pts[i + 1], p3 = pts[Math.min(i + 2, pts.length - 1)]; + path.curveTo(p1[0] + (p2[0] - p0[0]) / 6, p1[1] + (p2[1] - p0[1]) / 6, + p2[0] - (p3[0] - p1[0]) / 6, p2[1] - (p3[1] - p1[1]) / 6, p2[0], p2[1]); + } + } + + static Area stroke(Shape shape, double width) { + return new Area(new BasicStroke((float) width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND) + .createStrokedShape(shape)); + } + + /** Path data of the shape scaled to fill the 256 box, less a margin. */ + static String path(Area shape, double margin) { + Rectangle2D b = shape.getBounds2D(); + double k = (256 - 2 * margin) / Math.max(b.getWidth(), b.getHeight()); + AffineTransform t = new AffineTransform(); + t.translate(128, 128); + t.scale(k, k); + t.translate(-b.getCenterX(), -b.getCenterY()); + StringBuilder s = new StringBuilder(); + double[] c = new double[6]; + for (PathIterator it = shape.getPathIterator(t); !it.isDone(); it.next()) { + int type = it.currentSegment(c); + switch (type) { + case PathIterator.SEG_MOVETO -> s.append('M').append(points(c, 1)); + case PathIterator.SEG_LINETO -> s.append('L').append(points(c, 1)); + case PathIterator.SEG_QUADTO -> s.append('Q').append(points(c, 2)); + case PathIterator.SEG_CUBICTO -> s.append('C').append(points(c, 3)); + case PathIterator.SEG_CLOSE -> s.append('Z'); + default -> throw new IllegalStateException(); + } + } + return s.toString(); + } + + static String points(double[] c, int n) { + StringBuilder s = new StringBuilder(); + for (int i = 0; i < n; i++) { + if (i > 0) s.append(' '); + s.append(number(c[2 * i])).append(',').append(number(c[2 * i + 1])); + } + return s.toString(); + } + + static String number(double v) { + String s = String.format(Locale.ROOT, "%.1f", v); + return s.endsWith(".0") ? s.substring(0, s.length() - 2) : s; + } + + static String svg(String path) { + return """ + \ + \ + \ + + """.formatted(LIGHT, DARK, path); + } + + static String vector(String path) { + return """ + + + + + + + + + + + + """.formatted(path, LIGHT, DARK); + } +}