diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index 0c087ef6..fab3d729 100755 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -123,19 +123,7 @@ namespace Shadowsocks.View Configuration config = controller.GetConfigurationCopy(); bool enabled = config.enabled; bool global = config.global; - if (!enabled) - { - Bitmap iconCopy = new Bitmap(icon); - for (int x = 0; x < iconCopy.Width; x++) - { - for (int y = 0; y < iconCopy.Height; y++) - { - Color color = icon.GetPixel(x, y); - iconCopy.SetPixel(x, y, Color.FromArgb((byte)(color.A / 1.25), color.R, color.G, color.B)); - } - } - icon = iconCopy; - } + icon = getTrayIconByState(icon, enabled, global); _notifyIcon.Icon = Icon.FromHandle(icon.GetHicon()); string serverInfo = null; @@ -156,6 +144,39 @@ namespace Shadowsocks.View _notifyIcon.Text = text.Substring(0, Math.Min(63, text.Length)); } + private Bitmap getTrayIconByState(Bitmap originIcon, bool enabled, bool global) + { + Bitmap iconCopy = new Bitmap(originIcon); + for (int x = 0; x < iconCopy.Width; x++) + { + for (int y = 0; y < iconCopy.Height; y++) + { + Color color = originIcon.GetPixel(x, y); + if (color.A != 0 && color.R > 30) + { + if (!enabled) + { + iconCopy.SetPixel(x, y, Color.FromArgb((byte)(color.A / 1.25), color.R, color.G, color.B)); + } + else if (global) + { + Color flyBlue = Color.FromArgb(25, 125, 191); + // Muliply with flyBlue + int red = color.R * flyBlue.R / 255; + int green = color.G * flyBlue.G / 255; + int blue = color.B * flyBlue.B / 255; + iconCopy.SetPixel(x, y, Color.FromArgb(color.A, red, green, blue)); + } + } + else + { + iconCopy.SetPixel(x, y, Color.FromArgb(color.A, color.R, color.G, color.B)); + } + } + } + return iconCopy; + } + private MenuItem CreateMenuItem(string text, EventHandler click) { return new MenuItem(I18N.GetString(text), click);