fixed #675: Added optional custom info text setting for region capture so it can show color info and allows to copy it

This commit is contained in:
Jaex 2015-07-21 14:55:53 +03:00
parent e80383968d
commit 585da60da7
4 changed files with 45 additions and 13 deletions

View file

@ -26,6 +26,7 @@ You should have received a copy of the GNU General Public License
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
@ -34,6 +35,7 @@ namespace ShareX.HelpersLib
[DefaultEvent("MouseClick")]
public class BlackStyleButton : Control
{
[Editor("System.ComponentModel.Design.MultilineStringEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
public override string Text
{
get

View file

@ -115,12 +115,11 @@ private void CopyAreaInfo()
if (AreaManager.IsCurrentAreaValid)
{
clipboardText = GetAreaText(AreaManager.CurrentArea);
ClipboardHelpers.CopyText(clipboardText);
}
else
{
CurrentPosition = InputManager.MousePosition;
clipboardText = string.Format("X: {0} Y: {1}", CurrentPosition.X, CurrentPosition.Y);
clipboardText = GetInfoText();
}
ClipboardHelpers.CopyText(clipboardText);
@ -175,7 +174,7 @@ public override void Prepare()
}
}
if (ScreenColorPickerMode)
if (Config.UseCustomInfoText || ScreenColorPickerMode)
{
bmpSurfaceImage = new Bitmap(SurfaceImage);
}
@ -384,6 +383,14 @@ protected virtual void WriteTips(StringBuilder sb)
{
sb.AppendLine("[Ctrl + C] Copy position and size");
}
else if (Config.UseCustomInfoText)
{
sb.AppendLine("[Ctrl + C] Copy info");
}
else
{
sb.AppendLine("[Ctrl + C] Copy position");
}
sb.AppendLine();
@ -444,6 +451,28 @@ private string GetAreaText(Rectangle area)
return string.Format(Resources.RectangleRegion_GetAreaText_Area, area.X, area.Y, area.Width, area.Height);
}
private string GetInfoText()
{
if (ScreenColorPickerMode || Config.UseCustomInfoText)
{
Color color = CurrentColor;
if (!ScreenColorPickerMode && !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);
}
return string.Format(Resources.RectangleRegion_GetColorPickerText, color.R, color.G, color.B, ColorHelpers.ColorToHex(color), CurrentPosition.X, CurrentPosition.Y);
}
return string.Format("X: {0} Y: {1}", CurrentPosition.X, CurrentPosition.Y);
}
private void DrawCrosshair(Graphics g)
{
int offset = 5;
@ -492,16 +521,7 @@ private void DrawMagnifier(Graphics g)
CurrentPosition = InputManager.MousePosition;
if (ScreenColorPickerMode)
{
Color color = CurrentColor;
infoText = string.Format(Resources.RectangleRegion_GetColorPickerText, color.R, color.G, color.B, ColorHelpers.ColorToHex(color), CurrentPosition.X, CurrentPosition.Y);
}
else
{
infoText = string.Format("X: {0} Y: {1}", CurrentPosition.X, CurrentPosition.Y);
}
infoText = GetInfoText();
Size textSize = g.MeasureString(infoText, infoFont).ToSize();
infoTextRect.Size = new Size(textSize.Width + infoTextPadding * 2, textSize.Height + infoTextPadding * 2);
}

View file

@ -43,6 +43,7 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Design" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />

View file

@ -25,7 +25,9 @@ You should have received a copy of the GNU General Public License
using ShareX.HelpersLib;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Design;
namespace ShareX.ScreenCaptureLib
{
@ -37,6 +39,13 @@ public class SurfaceOptions
[DefaultValue(true), Description("Show coordinate and size information.")]
public bool ShowInfo { get; set; }
[DefaultValue(false), Description("Allows to show your custom info text near cursor. This way you can show color info too.")]
public bool UseCustomInfoText { get; set; }
[DefaultValue("X: $x, Y: $y\r\nR: $r, G: $g, B: $b\r\nHex: $hex"), Description("Show this custom info when color info setting is enabled. Formats: $x, $y, $r, $g, $b, $hex"),
Editor(typeof(MultilineStringEditor), typeof(UITypeEditor))]
public string CustomInfoText { get; set; }
[DefaultValue(true), Description("Show hotkeys/tips.")]
public bool ShowTips { get; set; }