mirror of
https://github.com/greenshot/greenshot
synced 2025-08-22 06:23:24 -07:00
Merge 39f13c91d9
into 7e005f741a
This commit is contained in:
commit
a77dcc525a
7 changed files with 111 additions and 12 deletions
|
@ -24,6 +24,7 @@ namespace Greenshot.Base.Interfaces
|
|||
public enum DrawingModes
|
||||
{
|
||||
None,
|
||||
ColorPicker,
|
||||
Rect,
|
||||
Ellipse,
|
||||
Text,
|
||||
|
|
|
@ -65,7 +65,7 @@ namespace Greenshot.Editor.Controls
|
|||
/// <param name="hotspotX">Hotspot X coordinate</param>
|
||||
/// <param name="hotspotY">Hotspot Y coordinate</param>
|
||||
/// <returns>Cursor</returns>
|
||||
private static Cursor CreateCursor(Bitmap bitmap, int hotspotX, int hotspotY)
|
||||
public static Cursor CreateCursor(Bitmap bitmap, int hotspotX, int hotspotY)
|
||||
{
|
||||
using SafeIconHandle iconHandle = new SafeIconHandle(bitmap.GetHicon());
|
||||
NativeIconMethods.GetIconInfo(iconHandle, out var iconInfo);
|
||||
|
|
|
@ -39,7 +39,9 @@ using Greenshot.Base.Interfaces;
|
|||
using Greenshot.Base.Interfaces.Drawing;
|
||||
using Greenshot.Base.Interfaces.Drawing.Adorners;
|
||||
using Greenshot.Editor.Configuration;
|
||||
using Greenshot.Editor.Controls;
|
||||
using Greenshot.Editor.Drawing.Fields;
|
||||
using Greenshot.Editor.Forms;
|
||||
using Greenshot.Editor.Memento;
|
||||
using log4net;
|
||||
|
||||
|
@ -61,6 +63,16 @@ namespace Greenshot.Editor.Drawing
|
|||
/// </summary>
|
||||
private int _counterStart = 1;
|
||||
|
||||
/// <summary>
|
||||
/// The image used for the color picker cursor initialized once form has loaded
|
||||
/// </summary>
|
||||
private Cursor colorPickerCursor = null;
|
||||
|
||||
/// <summary>
|
||||
/// The image used for the color picker cursor initialized once form has loaded
|
||||
/// </summary>
|
||||
private MovableShowColorForm _movableShowColorForm = new MovableShowColorForm();
|
||||
|
||||
/// <summary>
|
||||
/// The GUID of the surface
|
||||
/// </summary>
|
||||
|
@ -483,6 +495,8 @@ namespace Greenshot.Editor.Drawing
|
|||
_elements = new DrawableContainerList(_uniqueId);
|
||||
selectedElements = new DrawableContainerList(_uniqueId);
|
||||
LOG.Debug("Creating surface!");
|
||||
MouseEnter += SurfaceMouseEnter;
|
||||
MouseLeave += SurfaceMouseLeave;
|
||||
MouseDown += SurfaceMouseDown;
|
||||
MouseUp += SurfaceMouseUp;
|
||||
MouseMove += SurfaceMouseMove;
|
||||
|
@ -502,6 +516,7 @@ namespace Greenshot.Editor.Drawing
|
|||
SetStyle(
|
||||
ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.ContainerControl | ControlStyles.OptimizedDoubleBuffer |
|
||||
ControlStyles.SupportsTransparentBackColor, true);
|
||||
colorPickerCursor = Pipette.CreateCursor((Bitmap)new ComponentResourceManager(typeof(ImageEditorForm)).GetObject("colorPicker.Image"), 1, 14);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -788,6 +803,7 @@ namespace Greenshot.Editor.Drawing
|
|||
case DrawingModes.Path:
|
||||
_undrawnElement = new FreehandContainer(this);
|
||||
break;
|
||||
case DrawingModes.ColorPicker:
|
||||
case DrawingModes.None:
|
||||
_undrawnElement = null;
|
||||
break;
|
||||
|
@ -1415,6 +1431,7 @@ namespace Greenshot.Editor.Drawing
|
|||
private MouseEventArgs InverseZoomMouseCoordinates(MouseEventArgs e)
|
||||
=> new MouseEventArgs(e.Button, e.Clicks, (int) (e.X / _zoomFactor), (int) (e.Y / _zoomFactor), e.Delta);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// This event handler is called when someone presses the mouse on a surface.
|
||||
/// </summary>
|
||||
|
@ -1473,7 +1490,14 @@ namespace Greenshot.Editor.Drawing
|
|||
_drawingElement = null;
|
||||
}
|
||||
|
||||
if (_drawingElement == null && DrawingMode != DrawingModes.None)
|
||||
if (DrawingMode == DrawingModes.ColorPicker)
|
||||
{
|
||||
var color = _movableShowColorForm.Color;
|
||||
var colorString = "#" + color.R.ToString("X2") + color.G.ToString("X2") + color.B.ToString("X2");
|
||||
ClipboardHelper.SetClipboardData(colorString);
|
||||
SendMessageEvent(this, SurfaceMessageTyp.Info, colorString);
|
||||
}
|
||||
else if (_drawingElement == null && DrawingMode != DrawingModes.None)
|
||||
{
|
||||
if (_undrawnElement == null)
|
||||
{
|
||||
|
@ -1612,6 +1636,32 @@ namespace Greenshot.Editor.Drawing
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// This event handler is called when the mouse enters the surface
|
||||
/// </summary>
|
||||
/// <param name="e"></param>
|
||||
private void SurfaceMouseEnter(object sender, EventArgs e)
|
||||
{
|
||||
if (DrawingMode == DrawingModes.ColorPicker)
|
||||
{
|
||||
_movableShowColorForm.Visible = true;
|
||||
Focus(); // steal back focus after the movable form takes it
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This event handler is called when the mouse leaves the surface
|
||||
/// </summary>
|
||||
/// <param name="e"></param>
|
||||
private void SurfaceMouseLeave(object sender, EventArgs e)
|
||||
{
|
||||
if (DrawingMode == DrawingModes.ColorPicker)
|
||||
{
|
||||
_movableShowColorForm.Visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This event handler is called when the mouse moves over the surface
|
||||
/// </summary>
|
||||
|
@ -1619,6 +1669,11 @@ namespace Greenshot.Editor.Drawing
|
|||
/// <param name="e"></param>
|
||||
private void SurfaceMouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (DrawingMode == DrawingModes.ColorPicker)
|
||||
{
|
||||
_movableShowColorForm.MoveTo(PointToScreen(new Point(e.X, e.Y)));
|
||||
}
|
||||
|
||||
e = InverseZoomMouseCoordinates(e);
|
||||
|
||||
// Handle Adorners
|
||||
|
@ -1631,7 +1686,18 @@ namespace Greenshot.Editor.Drawing
|
|||
|
||||
Point currentMouse = e.Location;
|
||||
|
||||
Cursor = DrawingMode != DrawingModes.None ? Cursors.Cross : Cursors.Default;
|
||||
switch (DrawingMode)
|
||||
{
|
||||
case DrawingModes.None:
|
||||
Cursor = Cursors.Default;
|
||||
break;
|
||||
case DrawingModes.ColorPicker:
|
||||
Cursor = colorPickerCursor;
|
||||
break;
|
||||
default:
|
||||
Cursor = Cursors.Cross;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!_mouseDown) return;
|
||||
|
||||
|
@ -2101,6 +2167,11 @@ namespace Greenshot.Editor.Drawing
|
|||
{
|
||||
ConfirmCrop(confirm);
|
||||
}
|
||||
else if (DrawingMode == DrawingModes.ColorPicker && !confirm)
|
||||
{
|
||||
Cursor = Cursors.Default;
|
||||
_movableShowColorForm.Visible = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
ConfirmSelectedConfirmableElements(confirm);
|
||||
|
|
|
@ -60,6 +60,7 @@ namespace Greenshot.Editor.Forms {
|
|||
this.panel1 = new NonJumpingPanel();
|
||||
this.toolsToolStrip = new ToolStripEx();
|
||||
this.btnCursor = new GreenshotToolStripButton();
|
||||
this.btnColorPicker = new GreenshotToolStripButton();
|
||||
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
|
||||
this.btnRect = new GreenshotToolStripButton();
|
||||
this.btnEllipse = new GreenshotToolStripButton();
|
||||
|
@ -327,6 +328,7 @@ namespace Greenshot.Editor.Forms {
|
|||
this.toolsToolStrip.Renderer = new CustomToolStripProfessionalRenderer();
|
||||
this.toolsToolStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.btnCursor,
|
||||
this.btnColorPicker,
|
||||
this.toolStripSeparator1,
|
||||
this.btnRect,
|
||||
this.btnEllipse,
|
||||
|
@ -363,6 +365,16 @@ namespace Greenshot.Editor.Forms {
|
|||
this.btnCursor.Name = "btnCursor";
|
||||
this.btnCursor.Click += new System.EventHandler(this.BtnCursorClick);
|
||||
//
|
||||
// btnColorPicker
|
||||
//
|
||||
this.btnColorPicker.CheckOnClick = true;
|
||||
this.btnColorPicker.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
|
||||
this.btnColorPicker.Image = ((System.Drawing.Image)(resources.GetObject("colorPicker.Image")));
|
||||
this.btnColorPicker.ImageTransparentColor = System.Drawing.Color.Magenta;
|
||||
this.btnColorPicker.LanguageKey = "colorpicker_title";
|
||||
this.btnColorPicker.Name = "btnColorPicker";
|
||||
this.btnColorPicker.Click += new System.EventHandler(this.BtnColorPickerClick);
|
||||
//
|
||||
// toolStripSeparator1
|
||||
//
|
||||
this.toolStripSeparator1.Name = "toolStripSeparator1";
|
||||
|
@ -1969,6 +1981,7 @@ namespace Greenshot.Editor.Forms {
|
|||
private GreenshotToolStripMenuItem upOneLevelToolStripMenuItem;
|
||||
private GreenshotToolStripMenuItem arrangeToolStripMenuItem;
|
||||
private GreenshotToolStripButton btnCursor;
|
||||
private GreenshotToolStripButton btnColorPicker;
|
||||
private ToolStripEx toolsToolStrip;
|
||||
private GreenshotToolStripButton btnArrow;
|
||||
private GreenshotToolStripMenuItem drawArrowToolStripMenuItem;
|
||||
|
|
|
@ -285,7 +285,7 @@ namespace Greenshot.Editor.Forms
|
|||
|
||||
_toolbarButtons = new[]
|
||||
{
|
||||
btnCursor, btnRect, btnEllipse, btnText, btnLine, btnArrow, btnFreehand, btnHighlight, btnObfuscate, btnCrop, btnStepLabel, btnSpeechBubble
|
||||
btnCursor, btnColorPicker, btnRect, btnEllipse, btnText, btnLine, btnArrow, btnFreehand, btnHighlight, btnObfuscate, btnCrop, btnStepLabel, btnSpeechBubble
|
||||
};
|
||||
//toolbarDropDownButtons = new ToolStripDropDownButton[]{btnBlur, btnPixeliate, btnTextHighlighter, btnAreaHighlighter, btnMagnifier};
|
||||
|
||||
|
@ -598,6 +598,9 @@ namespace Greenshot.Editor.Forms
|
|||
case DrawingModes.None:
|
||||
SetButtonChecked(btnCursor);
|
||||
break;
|
||||
case DrawingModes.ColorPicker:
|
||||
SetButtonChecked(btnColorPicker);
|
||||
break;
|
||||
case DrawingModes.Ellipse:
|
||||
SetButtonChecked(btnEllipse);
|
||||
break;
|
||||
|
@ -683,6 +686,12 @@ namespace Greenshot.Editor.Forms
|
|||
RefreshFieldControls();
|
||||
}
|
||||
|
||||
private void BtnColorPickerClick(object sender, EventArgs e)
|
||||
{
|
||||
_surface.DrawingMode = DrawingModes.ColorPicker;
|
||||
RefreshFieldControls();
|
||||
}
|
||||
|
||||
private void BtnRectClick(object sender, EventArgs e)
|
||||
{
|
||||
_surface.DrawingMode = DrawingModes.Rect;
|
||||
|
@ -1295,7 +1304,7 @@ namespace Greenshot.Editor.Forms
|
|||
private void RefreshFieldControls()
|
||||
{
|
||||
propertiesToolStrip.SuspendLayout();
|
||||
if (_surface.HasSelectedElements || _surface.DrawingMode != DrawingModes.None)
|
||||
if (_surface.HasSelectedElements || (_surface.DrawingMode != DrawingModes.None && _surface.DrawingMode != DrawingModes.ColorPicker))
|
||||
{
|
||||
var props = (FieldAggregator)_surface.FieldAggregator;
|
||||
btnFillColor.Visible = props.HasFieldValue(FieldType.FILL_COLOR);
|
||||
|
|
|
@ -1086,6 +1086,9 @@
|
|||
<data name="btnResize.Image" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\icons\resize.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="colorPicker.Image" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\..\Greenshot\icons\pipette.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>551, 17</value>
|
||||
</metadata>
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
using System.Windows.Forms;
|
||||
|
||||
namespace Greenshot.Editor.Forms
|
||||
{
|
||||
partial class MovableShowColorForm
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue