Remember color picker color palette mode selection

This commit is contained in:
Jaex 2021-10-03 01:48:03 +03:00
parent bc336f5b72
commit eb2d90c0c9
11 changed files with 72 additions and 11 deletions

View file

@ -0,0 +1,32 @@
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
Copyright (c) 2007-2021 ShareX Team
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
*/
#endregion License Information (GPL v3)
namespace ShareX.HelpersLib
{
public class ColorPickerOptions
{
public bool RecentColorsSelected { get; set; } = true;
}
}

View file

@ -66,6 +66,8 @@ public Color Color
[DefaultValue(false)]
public bool ManualButtonClick { get; set; }
public ColorPickerOptions ColorPickerOptions { get; set; }
private bool isMouseHover;
protected void OnColorChanged(Color color)
@ -85,7 +87,7 @@ protected override void OnMouseClick(MouseEventArgs mevent)
public void ShowColorDialog()
{
if (ColorPickerForm.PickColor(Color, out Color newColor, FindForm()))
if (ColorPickerForm.PickColor(Color, out Color newColor, FindForm(), null, ColorPickerOptions))
{
Color = newColor;
}

View file

@ -37,18 +37,34 @@ public partial class ColorPickerForm : Form
public MyColor NewColor { get; private set; }
public MyColor OldColor { get; private set; }
public bool IsScreenColorPickerMode { get; private set; }
public ColorPickerOptions Options { get; private set; }
private bool oldColorExist;
private bool controlChangingColor;
private ControlHider clipboardStatusHider;
public ColorPickerForm(Color currentColor, bool isScreenColorPickerMode = false, bool checkClipboard = true)
public ColorPickerForm(Color currentColor, bool isScreenColorPickerMode = false, bool checkClipboard = true, ColorPickerOptions options = null)
{
InitializeComponent();
ShareXResources.ApplyTheme(this);
clipboardStatusHider = new ControlHider(btnClipboardStatus, 2000);
IsScreenColorPickerMode = isScreenColorPickerMode;
Options = options;
if (Options == null)
{
Options = new ColorPickerOptions();
}
if (Options.RecentColorsSelected)
{
rbRecentColors.Checked = true;
}
else
{
rbStandardColors.Checked = true;
}
PrepareColorPalette();
SetCurrentColor(currentColor, !IsScreenColorPickerMode);
@ -90,9 +106,9 @@ public bool CheckClipboard()
return false;
}
public static bool PickColor(Color currentColor, out Color newColor, Form owner = null, Func<PointInfo> openScreenColorPicker = null)
public static bool PickColor(Color currentColor, out Color newColor, Form owner = null, Func<PointInfo> openScreenColorPicker = null, ColorPickerOptions options = null)
{
using (ColorPickerForm dialog = new ColorPickerForm(currentColor))
using (ColorPickerForm dialog = new ColorPickerForm(currentColor, options: options))
{
if (openScreenColorPicker != null)
{
@ -116,7 +132,7 @@ private void PrepareColorPalette()
Color[] colors;
if (rbRecentColors.Checked)
if (Options.RecentColorsSelected)
{
colors = HelpersOptions.RecentColors.ToArray();
}
@ -296,6 +312,8 @@ private void colorPicker_ColorChanged(object sender, ColorEventArgs e)
private void rbRecentColors_CheckedChanged(object sender, EventArgs e)
{
Options.RecentColorsSelected = rbRecentColors.Checked;
PrepareColorPalette();
}

View file

@ -104,6 +104,7 @@
<Compile Include="..\SharedAssemblyInfo.cs">
<Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile>
<Compile Include="ColorPickerOptions.cs" />
<Compile Include="ControlHider.cs" />
<Compile Include="Controls\ObjectListView.cs">
<SubType>Component</SubType>

View file

@ -47,6 +47,7 @@ public NewImageForm(RegionCaptureOptions options)
nudWidth.Value = Options.EditorNewImageSize.Width;
nudHeight.Value = Options.EditorNewImageSize.Height;
cbTransparent.Checked = Options.EditorNewImageTransparent;
btnChangeColor.ColorPickerOptions = options.ColorPickerOptions;
btnChangeColor.Color = options.EditorNewImageBackgroundColor;
}

View file

@ -37,16 +37,18 @@ internal partial class TextDrawingInputBox : Form
{
public string InputText { get; private set; }
public TextDrawingOptions Options { get; private set; }
public ColorPickerOptions ColorPickerOptions { get; private set; }
private int processKeyCount;
public TextDrawingInputBox(string text, TextDrawingOptions options, bool supportGradient)
public TextDrawingInputBox(string text, TextDrawingOptions options, bool supportGradient, ColorPickerOptions colorPickerOptions)
{
InitializeComponent();
ShareXResources.ApplyTheme(this);
InputText = text;
Options = options;
ColorPickerOptions = colorPickerOptions;
if (InputText != null)
{
@ -67,6 +69,8 @@ public TextDrawingInputBox(string text, TextDrawingOptions options, bool support
}
nudTextSize.SetValue(Options.Size);
btnTextColor.ColorPickerOptions = ColorPickerOptions;
btnTextColor.Color = Options.Color;
btnGradient.Visible = supportGradient;
@ -163,7 +167,7 @@ private void tsmiEnableGradient_Click(object sender, EventArgs e)
private void tsmiSecondColor_Click(object sender, EventArgs e)
{
ColorPickerForm.PickColor(Options.Color2, out Color newColor, this);
ColorPickerForm.PickColor(Options.Color2, out Color newColor, this, null, ColorPickerOptions);
Options.Color2 = newColor;
if (tsmiSecondColor.Image != null) tsmiSecondColor.Image.Dispose();
tsmiSecondColor.Image = ImageHelpers.CreateColorPickerIcon(Options.Color2, new Rectangle(0, 0, 16, 16));

View file

@ -100,6 +100,9 @@ public class RegionCaptureOptions
public List<ImageEffectPreset> ImageEffectPresets = new List<ImageEffectPreset>();
public int SelectedImageEffectPreset = 0;
// Color picker
public ColorPickerOptions ColorPickerOptions = new ColorPickerOptions();
// Screen color picker
public string ScreenColorPickerInfoText = "";
}

View file

@ -146,7 +146,7 @@ public static SimpleWindowInfo GetWindowInfo(RegionCaptureOptions options)
public static void ShowScreenColorPickerDialog(RegionCaptureOptions options)
{
Color color = Color.Red;
ColorPickerForm colorPickerForm = new ColorPickerForm(color, true);
ColorPickerForm colorPickerForm = new ColorPickerForm(color, true, true, options.ColorPickerOptions);
colorPickerForm.EnableScreenColorPickerButton(() => GetPointInfo(options));
colorPickerForm.Show();
}

View file

@ -131,7 +131,7 @@ private bool ShowTextInputBox()
Manager.Form.Pause();
using (TextDrawingInputBox inputBox = new TextDrawingInputBox(Text, TextOptions, SupportGradient))
using (TextDrawingInputBox inputBox = new TextDrawingInputBox(Text, TextOptions, SupportGradient, Manager.Options.ColorPickerOptions))
{
result = inputBox.ShowDialog(Manager.Form) == DialogResult.OK;
Text = inputBox.InputText;

View file

@ -2098,7 +2098,7 @@ private bool PickColor(Color currentColor, out Color newColor)
openScreenColorPicker = () => RegionCaptureTasks.GetPointInfo(Options);
}
return ColorPickerForm.PickColor(currentColor, out newColor, Form, openScreenColorPicker);
return ColorPickerForm.PickColor(currentColor, out newColor, Form, openScreenColorPicker, Options.ColorPickerOptions);
}
private void OnCurrentShapeChanged(BaseShape shape)

View file

@ -690,7 +690,7 @@ public static void ShowScreenColorPickerDialog(TaskSettings taskSettings = null)
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
taskSettings.CaptureSettings.SurfaceOptions.ScreenColorPickerInfoText = taskSettings.ToolsSettings.ScreenColorPickerInfoText;
RegionCaptureTasks.ShowScreenColorPickerDialog(taskSettings.CaptureSettings.SurfaceOptions);
RegionCaptureTasks.ShowScreenColorPickerDialog(taskSettings.CaptureSettingsReference.SurfaceOptions);
}
public static void OpenScreenColorPicker(TaskSettings taskSettings = null)