From 1d5854dfa75bad6b1da93613d198a4cdf3c6b8e1 Mon Sep 17 00:00:00 2001 From: everyx Date: Sun, 13 Mar 2016 23:50:19 +0800 Subject: [PATCH 1/4] feature #490 --- shadowsocks-csharp/View/MenuViewController.cs | 46 +++++++++++++------ 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index 0c087ef6..6e543115 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 = getTrayIconColorByState(icon, enabled, global); _notifyIcon.Icon = Icon.FromHandle(icon.GetHicon()); string serverInfo = null; @@ -156,6 +144,38 @@ namespace Shadowsocks.View _notifyIcon.Text = text.Substring(0, Math.Min(63, text.Length)); } + private Bitmap getTrayIconColorByState(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(color.A, 234, 67, 53)); + } + else if (global) + { + iconCopy.SetPixel(x, y, Color.FromArgb(color.A, 52, 168, 83)); + } + else + { + iconCopy.SetPixel(x, y, Color.FromArgb(color.A, 251, 188, 5)); + } + } + 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); From 45aaaa6ed99f6a099729578de692e4ce51a16b7d Mon Sep 17 00:00:00 2001 From: everyx Date: Sun, 13 Mar 2016 23:54:56 +0800 Subject: [PATCH 2/4] update function name --- shadowsocks-csharp/View/MenuViewController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index 6e543115..9097cd90 100755 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -123,7 +123,7 @@ namespace Shadowsocks.View Configuration config = controller.GetConfigurationCopy(); bool enabled = config.enabled; bool global = config.global; - icon = getTrayIconColorByState(icon, enabled, global); + icon = getTrayIconByState(icon, enabled, global); _notifyIcon.Icon = Icon.FromHandle(icon.GetHicon()); string serverInfo = null; @@ -144,7 +144,7 @@ namespace Shadowsocks.View _notifyIcon.Text = text.Substring(0, Math.Min(63, text.Length)); } - private Bitmap getTrayIconColorByState(Bitmap originIcon, bool enabled, bool global) + private Bitmap getTrayIconByState(Bitmap originIcon, bool enabled, bool global) { Bitmap iconCopy = new Bitmap(originIcon); for (int x = 0; x < iconCopy.Width; x++) From 22d081f72e2107a1c377bf44450771b4b014dd44 Mon Sep 17 00:00:00 2001 From: everyx Date: Mon, 14 Mar 2016 22:04:16 +0800 Subject: [PATCH 3/4] improve tray icon color --- shadowsocks-csharp/View/MenuViewController.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index 9097cd90..8b3c6fe4 100755 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -156,15 +156,15 @@ namespace Shadowsocks.View { if (!enabled) { - iconCopy.SetPixel(x, y, Color.FromArgb(color.A, 234, 67, 53)); + iconCopy.SetPixel(x, y, Color.FromArgb(color.A, color.R, 0, 0)); } else if (global) { - iconCopy.SetPixel(x, y, Color.FromArgb(color.A, 52, 168, 83)); + iconCopy.SetPixel(x, y, Color.FromArgb(color.A, 0, color.G, 0)); } else { - iconCopy.SetPixel(x, y, Color.FromArgb(color.A, 251, 188, 5)); + iconCopy.SetPixel(x, y, Color.FromArgb(color.A, color.R, color.G, 0)); } } else From c1fd3f30350b2ba5cc2f62c9374588242e79e733 Mon Sep 17 00:00:00 2001 From: everyx Date: Tue, 15 Mar 2016 21:06:44 +0800 Subject: [PATCH 4/4] take @laincat's advice --- shadowsocks-csharp/View/MenuViewController.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index 8b3c6fe4..fab3d729 100755 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -156,15 +156,16 @@ namespace Shadowsocks.View { if (!enabled) { - iconCopy.SetPixel(x, y, Color.FromArgb(color.A, color.R, 0, 0)); + iconCopy.SetPixel(x, y, Color.FromArgb((byte)(color.A / 1.25), color.R, color.G, color.B)); } else if (global) { - iconCopy.SetPixel(x, y, Color.FromArgb(color.A, 0, color.G, 0)); - } - else - { - iconCopy.SetPixel(x, y, Color.FromArgb(color.A, color.R, color.G, 0)); + 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