diff --git a/ShareX.HelpersLib/NameParser/CodeMenuEntryPixelInfo.cs b/ShareX.HelpersLib/NameParser/CodeMenuEntryPixelInfo.cs index 0eb5d7df9..0e05d0296 100644 --- a/ShareX.HelpersLib/NameParser/CodeMenuEntryPixelInfo.cs +++ b/ShareX.HelpersLib/NameParser/CodeMenuEntryPixelInfo.cs @@ -23,22 +23,38 @@ You should have received a copy of the GNU General Public License #endregion License Information (GPL v3) +using System; +using System.Drawing; + namespace ShareX.HelpersLib { public class CodeMenuEntryPixelInfo : CodeMenuEntry { protected override string Prefix { get; } = "$"; - public static readonly CodeMenuEntryPixelInfo x = new CodeMenuEntryPixelInfo("x", "X position"); - public static readonly CodeMenuEntryPixelInfo y = new CodeMenuEntryPixelInfo("y", "Y position"); public static readonly CodeMenuEntryPixelInfo r = new CodeMenuEntryPixelInfo("r", "Red color (0-255)"); public static readonly CodeMenuEntryPixelInfo g = new CodeMenuEntryPixelInfo("g", "Green color (0-255)"); public static readonly CodeMenuEntryPixelInfo b = new CodeMenuEntryPixelInfo("b", "Blue color (0-255)"); - public static readonly CodeMenuEntryPixelInfo hex = new CodeMenuEntryPixelInfo("hex", "Hex color value"); + public static readonly CodeMenuEntryPixelInfo hex = new CodeMenuEntryPixelInfo("hex", "Hex color value (Lowercase)"); + public static readonly CodeMenuEntryPixelInfo HEX = new CodeMenuEntryPixelInfo("HEX", "Hex color value (Uppercase)"); + public static readonly CodeMenuEntryPixelInfo x = new CodeMenuEntryPixelInfo("x", "X position"); + public static readonly CodeMenuEntryPixelInfo y = new CodeMenuEntryPixelInfo("y", "Y position"); public static readonly CodeMenuEntryPixelInfo n = new CodeMenuEntryPixelInfo("n", "New line"); public CodeMenuEntryPixelInfo(string value, string description) : base(value, description) { } + + public static string Parse(string input, Color color, Point position) + { + return input.Replace(r.ToPrefixString(), color.R.ToString(), StringComparison.InvariantCultureIgnoreCase). + Replace(g.ToPrefixString(), color.G.ToString(), StringComparison.InvariantCultureIgnoreCase). + Replace(b.ToPrefixString(), color.B.ToString(), StringComparison.InvariantCultureIgnoreCase). + Replace(HEX.ToPrefixString(), ColorHelpers.ColorToHex(color), StringComparison.InvariantCulture). + Replace(hex.ToPrefixString(), ColorHelpers.ColorToHex(color).ToLowerInvariant(), StringComparison.InvariantCultureIgnoreCase). + Replace(x.ToPrefixString(), position.X.ToString(), StringComparison.InvariantCultureIgnoreCase). + Replace(y.ToPrefixString(), position.Y.ToString(), StringComparison.InvariantCultureIgnoreCase). + Replace(n.ToPrefixString(), Environment.NewLine, StringComparison.InvariantCultureIgnoreCase); + } } } \ No newline at end of file diff --git a/ShareX.ScreenCaptureLib/Forms/RectangleRegionForm.cs b/ShareX.ScreenCaptureLib/Forms/RectangleRegionForm.cs index be1904c44..e8c43790e 100644 --- a/ShareX.ScreenCaptureLib/Forms/RectangleRegionForm.cs +++ b/ShareX.ScreenCaptureLib/Forms/RectangleRegionForm.cs @@ -544,13 +544,7 @@ private string GetInfoText() if (Mode != RectangleRegionMode.ScreenColorPicker && !string.IsNullOrEmpty(Config.CustomInfoText)) { - return Config.CustomInfoText.Replace("$r", color.R.ToString(), StringComparison.InvariantCultureIgnoreCase). - Replace("$g", color.G.ToString(), StringComparison.InvariantCultureIgnoreCase). - Replace("$b", color.B.ToString(), StringComparison.InvariantCultureIgnoreCase). - Replace("$hex", ColorHelpers.ColorToHex(color), StringComparison.InvariantCultureIgnoreCase). - Replace("$x", CurrentPosition.X.ToString(), StringComparison.InvariantCultureIgnoreCase). - Replace("$y", CurrentPosition.Y.ToString(), StringComparison.InvariantCultureIgnoreCase). - Replace("$n", Environment.NewLine, StringComparison.InvariantCultureIgnoreCase); + return CodeMenuEntryPixelInfo.Parse(Config.CustomInfoText, color, CurrentPosition); } return string.Format(Resources.RectangleRegion_GetColorPickerText, color.R, color.G, color.B, ColorHelpers.ColorToHex(color), CurrentPosition.X, CurrentPosition.Y); diff --git a/ShareX/TaskHelpers.cs b/ShareX/TaskHelpers.cs index f69c3ad41..8ff3bda7a 100644 --- a/ShareX/TaskHelpers.cs +++ b/ShareX/TaskHelpers.cs @@ -486,15 +486,7 @@ public static void OpenScreenColorPicker(TaskSettings taskSettings = null) if (pointInfo != null) { - string text = taskSettings.ToolsSettings.ScreenColorPickerFormat; - - text = text.Replace("$r", pointInfo.Color.R.ToString(), StringComparison.InvariantCultureIgnoreCase). - Replace("$g", pointInfo.Color.G.ToString(), StringComparison.InvariantCultureIgnoreCase). - Replace("$b", pointInfo.Color.B.ToString(), StringComparison.InvariantCultureIgnoreCase). - Replace("$HEX", ColorHelpers.ColorToHex(pointInfo.Color), StringComparison.InvariantCulture). - Replace("$hex", ColorHelpers.ColorToHex(pointInfo.Color).ToLowerInvariant(), StringComparison.InvariantCultureIgnoreCase). - Replace("$x", pointInfo.Position.X.ToString(), StringComparison.InvariantCultureIgnoreCase). - Replace("$y", pointInfo.Position.Y.ToString(), StringComparison.InvariantCultureIgnoreCase); + string text = CodeMenuEntryPixelInfo.Parse(taskSettings.ToolsSettings.ScreenColorPickerFormat, pointInfo.Color, pointInfo.Position); ClipboardHelpers.CopyText(text);