mirror of
https://github.com/greenshot/greenshot
synced 2025-07-14 17:13:44 -07:00
BUG-1682: This fixes the tail location while drawing, and also reduces the drawing bounds to that which it should be. (includes a few cleanups)
This commit is contained in:
parent
4fe74a240b
commit
49193644a8
6 changed files with 340 additions and 289 deletions
|
@ -222,11 +222,11 @@ namespace Greenshot.Drawing {
|
||||||
|
|
||||||
[NonSerialized]
|
[NonSerialized]
|
||||||
// will store current bounds of this DrawableContainer before starting a resize
|
// will store current bounds of this DrawableContainer before starting a resize
|
||||||
private Rectangle _boundsBeforeResize = Rectangle.Empty;
|
protected Rectangle _boundsBeforeResize = Rectangle.Empty;
|
||||||
|
|
||||||
[NonSerialized]
|
[NonSerialized]
|
||||||
// "workbench" rectangle - used for calculating bounds during resizing (to be applied to this DrawableContainer afterwards)
|
// "workbench" rectangle - used for calculating bounds during resizing (to be applied to this DrawableContainer afterwards)
|
||||||
private RectangleF _boundsAfterResize = RectangleF.Empty;
|
protected RectangleF _boundsAfterResize = RectangleF.Empty;
|
||||||
|
|
||||||
public Rectangle Bounds {
|
public Rectangle Bounds {
|
||||||
get { return GuiRectangle.GetGuiRectangle(Left, Top, Width, Height); }
|
get { return GuiRectangle.GetGuiRectangle(Left, Top, Width, Height); }
|
||||||
|
@ -449,6 +449,7 @@ namespace Greenshot.Drawing {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GripperMouseMove(object sender, MouseEventArgs e) {
|
private void GripperMouseMove(object sender, MouseEventArgs e) {
|
||||||
|
Invalidate();
|
||||||
Gripper originatingGripper = (Gripper)sender;
|
Gripper originatingGripper = (Gripper)sender;
|
||||||
int absX = originatingGripper.Left + e.X;
|
int absX = originatingGripper.Left + e.X;
|
||||||
int absY = originatingGripper.Top + e.Y;
|
int absY = originatingGripper.Top + e.Y;
|
||||||
|
@ -463,7 +464,6 @@ namespace Greenshot.Drawing {
|
||||||
MakeBoundsChangeUndoable(false);
|
MakeBoundsChangeUndoable(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
Invalidate();
|
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
|
|
||||||
// reset "workbench" rectangle to current bounds
|
// reset "workbench" rectangle to current bounds
|
||||||
|
@ -479,8 +479,8 @@ namespace Greenshot.Drawing {
|
||||||
ApplyBounds(_boundsAfterResize);
|
ApplyBounds(_boundsAfterResize);
|
||||||
|
|
||||||
ResumeLayout();
|
ResumeLayout();
|
||||||
Invalidate();
|
|
||||||
}
|
}
|
||||||
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool hasFilters {
|
public bool hasFilters {
|
||||||
|
|
|
@ -22,10 +22,9 @@
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace Greenshot.Drawing
|
namespace Greenshot.Drawing {
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Description of Gripper.
|
/// Grippers are the dragable edges of our containers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Gripper : Label {
|
public class Gripper : Label {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -34,38 +33,24 @@ namespace Greenshot.Drawing
|
||||||
/// 7 3
|
/// 7 3
|
||||||
/// 6 5 4
|
/// 6 5 4
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const int POSITION_TOP_LEFT = 0;
|
public const int POSITION_TOP_LEFT = 0;
|
||||||
public const int POSITION_TOP_CENTER = 1;
|
public const int POSITION_TOP_CENTER = 1;
|
||||||
public const int POSITION_TOP_RIGHT = 2;
|
public const int POSITION_TOP_RIGHT = 2;
|
||||||
public const int POSITION_MIDDLE_RIGHT = 3;
|
public const int POSITION_MIDDLE_RIGHT = 3;
|
||||||
public const int POSITION_BOTTOM_RIGHT = 4;
|
public const int POSITION_BOTTOM_RIGHT = 4;
|
||||||
public const int POSITION_BOTTOM_CENTER = 5;
|
public const int POSITION_BOTTOM_CENTER = 5;
|
||||||
public const int POSITION_BOTTOM_LEFT = 6;
|
public const int POSITION_BOTTOM_LEFT = 6;
|
||||||
public const int POSITION_MIDDLE_LEFT = 7;
|
public const int POSITION_MIDDLE_LEFT = 7;
|
||||||
|
|
||||||
public int Position;
|
public int Position {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
public Gripper() {
|
public Gripper() {
|
||||||
Width = 5;
|
Width = 5;
|
||||||
Height = 5;
|
Height = 5;
|
||||||
BackColor = Color.Black;
|
BackColor = Color.Black;
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsTop() {
|
|
||||||
return Position == 0 || Position == 1 || Position == 2;
|
|
||||||
}
|
|
||||||
public bool IsRight() {
|
|
||||||
return Position == 2 || Position == 3 || Position == 4;
|
|
||||||
}
|
|
||||||
public bool IsBottom() {
|
|
||||||
return Position == 4 || Position == 5 || Position == 6;
|
|
||||||
}
|
|
||||||
public bool IsLeft() {
|
|
||||||
return Position == 6 || Position == 7 || Position == 0;
|
|
||||||
}
|
|
||||||
public bool IsCorner() {
|
|
||||||
return Position == 0 || Position == 2 || Position == 4 || Position == 6;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,13 +18,13 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Drawing2D;
|
using System.Drawing.Drawing2D;
|
||||||
using Greenshot.Drawing.Fields;
|
using Greenshot.Drawing.Fields;
|
||||||
using Greenshot.Helpers;
|
using Greenshot.Helpers;
|
||||||
using Greenshot.Plugin.Drawing;
|
using Greenshot.Plugin.Drawing;
|
||||||
using log4net;
|
|
||||||
|
|
||||||
namespace Greenshot.Drawing {
|
namespace Greenshot.Drawing {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -32,7 +32,6 @@ namespace Greenshot.Drawing {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class RectangleContainer : DrawableContainer {
|
public class RectangleContainer : DrawableContainer {
|
||||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(RectangleContainer));
|
|
||||||
|
|
||||||
public RectangleContainer(Surface parent) : base(parent) {
|
public RectangleContainer(Surface parent) : base(parent) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,251 +1,319 @@
|
||||||
/*
|
/*
|
||||||
* Greenshot - a free and open source screenshot tool
|
* Greenshot - a free and open source screenshot tool
|
||||||
* Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom
|
* Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom
|
||||||
*
|
*
|
||||||
* For more information see: http://getgreenshot.org/
|
* For more information see: http://getgreenshot.org/
|
||||||
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
|
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 1 of the License, or
|
* the Free Software Foundation, either version 1 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using Greenshot.Drawing.Fields;
|
using Greenshot.Drawing.Fields;
|
||||||
using Greenshot.Helpers;
|
using Greenshot.Helpers;
|
||||||
using Greenshot.Plugin;
|
using Greenshot.Plugin;
|
||||||
using Greenshot.Plugin.Drawing;
|
using Greenshot.Plugin.Drawing;
|
||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Drawing2D;
|
using System.Drawing.Drawing2D;
|
||||||
using System.Drawing.Text;
|
using System.Drawing.Text;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using GreenshotPlugin.UnmanagedHelpers;
|
||||||
namespace Greenshot.Drawing {
|
using log4net;
|
||||||
/// <summary>
|
|
||||||
/// Description of SpeechbubbleContainer.
|
namespace Greenshot.Drawing {
|
||||||
/// </summary>
|
/// <summary>
|
||||||
[Serializable]
|
/// Description of SpeechbubbleContainer.
|
||||||
public class SpeechbubbleContainer : TextContainer {
|
/// </summary>
|
||||||
|
[Serializable]
|
||||||
#region TargetGripper serializing code
|
public class SpeechbubbleContainer : TextContainer {
|
||||||
// Only used for serializing the TargetGripper location
|
private static readonly ILog LOG = LogManager.GetLogger(typeof(RectangleContainer));
|
||||||
private Point _storedTargetGripperLocation;
|
|
||||||
|
private Point _initialGripperPoint;
|
||||||
/// <summary>
|
|
||||||
/// Store the current location of the target gripper
|
#region TargetGripper serializing code
|
||||||
/// </summary>
|
// Only used for serializing the TargetGripper location
|
||||||
/// <param name="context"></param>
|
private Point _storedTargetGripperLocation;
|
||||||
[OnSerializing]
|
|
||||||
private void SetValuesOnSerializing(StreamingContext context) {
|
/// <summary>
|
||||||
if (TargetGripper != null) {
|
/// Store the current location of the target gripper
|
||||||
_storedTargetGripperLocation = TargetGripper.Location;
|
/// </summary>
|
||||||
}
|
/// <param name="context"></param>
|
||||||
}
|
[OnSerializing]
|
||||||
|
private void SetValuesOnSerializing(StreamingContext context) {
|
||||||
/// <summary>
|
if (TargetGripper != null) {
|
||||||
/// Restore the target gripper
|
_storedTargetGripperLocation = TargetGripper.Location;
|
||||||
/// </summary>
|
}
|
||||||
/// <param name="context"></param>
|
}
|
||||||
[OnDeserialized]
|
|
||||||
private void SetValuesOnDeserialized(StreamingContext context) {
|
/// <summary>
|
||||||
InitTargetGripper(Color.Green, _storedTargetGripperLocation);
|
/// Restore the target gripper
|
||||||
}
|
/// </summary>
|
||||||
#endregion
|
/// <param name="context"></param>
|
||||||
|
[OnDeserialized]
|
||||||
public SpeechbubbleContainer(Surface parent)
|
private void SetValuesOnDeserialized(StreamingContext context) {
|
||||||
: base(parent) {
|
InitTargetGripper(Color.Green, _storedTargetGripperLocation);
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
/// <summary>
|
|
||||||
/// We set our own field values
|
public SpeechbubbleContainer(Surface parent)
|
||||||
/// </summary>
|
: base(parent) {
|
||||||
protected override void InitializeFields() {
|
}
|
||||||
AddField(GetType(), FieldType.LINE_THICKNESS, 2);
|
|
||||||
AddField(GetType(), FieldType.LINE_COLOR, Color.Blue);
|
/// <summary>
|
||||||
//AddField(GetType(), FieldType.SHADOW, false);
|
/// We set our own field values
|
||||||
AddField(GetType(), FieldType.FONT_ITALIC, false);
|
/// </summary>
|
||||||
AddField(GetType(), FieldType.FONT_BOLD, true);
|
protected override void InitializeFields() {
|
||||||
AddField(GetType(), FieldType.FILL_COLOR, Color.White);
|
AddField(GetType(), FieldType.LINE_THICKNESS, 2);
|
||||||
AddField(GetType(), FieldType.FONT_FAMILY, FontFamily.GenericSansSerif.Name);
|
AddField(GetType(), FieldType.LINE_COLOR, Color.Blue);
|
||||||
AddField(GetType(), FieldType.FONT_SIZE, 20f);
|
//AddField(GetType(), FieldType.SHADOW, false);
|
||||||
AddField(GetType(), FieldType.TEXT_HORIZONTAL_ALIGNMENT, HorizontalAlignment.Center);
|
AddField(GetType(), FieldType.FONT_ITALIC, false);
|
||||||
AddField(GetType(), FieldType.TEXT_VERTICAL_ALIGNMENT, VerticalAlignment.CENTER);
|
AddField(GetType(), FieldType.FONT_BOLD, true);
|
||||||
}
|
AddField(GetType(), FieldType.FILL_COLOR, Color.White);
|
||||||
|
AddField(GetType(), FieldType.FONT_FAMILY, FontFamily.GenericSansSerif.Name);
|
||||||
protected override void TargetGripperMove(int absX, int absY) {
|
AddField(GetType(), FieldType.FONT_SIZE, 20f);
|
||||||
base.TargetGripperMove(absX, absY);
|
AddField(GetType(), FieldType.TEXT_HORIZONTAL_ALIGNMENT, HorizontalAlignment.Center);
|
||||||
Invalidate();
|
AddField(GetType(), FieldType.TEXT_VERTICAL_ALIGNMENT, VerticalAlignment.CENTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
protected override void TargetGripperMove(int absX, int absY) {
|
||||||
/// Called from Surface (the _parent) when the drawing begins (mouse-down)
|
base.TargetGripperMove(absX, absY);
|
||||||
/// </summary>
|
Invalidate();
|
||||||
/// <returns>true if the surface doesn't need to handle the event</returns>
|
}
|
||||||
public override bool HandleMouseDown(int mouseX, int mouseY) {
|
|
||||||
if (TargetGripper == null) {
|
/// <summary>
|
||||||
InitTargetGripper(Color.Green, new Point(mouseX, mouseY));
|
/// Called from Surface (the _parent) when the drawing begins (mouse-down)
|
||||||
}
|
/// </summary>
|
||||||
return base.HandleMouseDown(mouseX + 20, mouseY + 20);
|
/// <returns>true if the surface doesn't need to handle the event</returns>
|
||||||
}
|
public override bool HandleMouseDown(int mouseX, int mouseY) {
|
||||||
|
if (TargetGripper == null) {
|
||||||
public override Rectangle DrawingBounds {
|
_initialGripperPoint = new Point(mouseX, mouseY);
|
||||||
get {
|
InitTargetGripper(Color.Green, new Point(mouseX, mouseY));
|
||||||
// TODO: Use the normal bounds and extend with the TargetGripper
|
}
|
||||||
return new Rectangle(0, 0, _parent.Width, _parent.Height);
|
return base.HandleMouseDown(mouseX, mouseY);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/// <summary>
|
||||||
public override void Draw(Graphics graphics, RenderMode renderMode) {
|
/// Overriding the HandleMouseMove will help us to make sure the tail is always visible.
|
||||||
if (TargetGripper == null) {
|
/// Should fix BUG-1682
|
||||||
return;
|
/// </summary>
|
||||||
}
|
/// <param name="x"></param>
|
||||||
graphics.SmoothingMode = SmoothingMode.HighQuality;
|
/// <param name="y"></param>
|
||||||
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
/// <returns></returns>
|
||||||
graphics.CompositingQuality = CompositingQuality.HighQuality;
|
public override bool HandleMouseMove(int x, int y) {
|
||||||
graphics.PixelOffsetMode = PixelOffsetMode.None;
|
bool returnValue = base.HandleMouseMove(x, y);
|
||||||
graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
|
Point newGripperLocation = _initialGripperPoint;
|
||||||
|
if (_boundsAfterResize.Right - _boundsAfterResize.Left >= 0) {
|
||||||
Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR);
|
newGripperLocation.Offset(-20, 0);
|
||||||
Color fillColor = GetFieldValueAsColor(FieldType.FILL_COLOR);
|
} else {
|
||||||
int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS);
|
newGripperLocation.Offset(20, 0);
|
||||||
|
}
|
||||||
bool lineVisible = (lineThickness > 0 && Colors.IsVisible(lineColor));
|
if (_boundsAfterResize.Bottom - _boundsAfterResize.Top >= 0) {
|
||||||
Rectangle rect = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
|
newGripperLocation.Offset(0, -20);
|
||||||
|
} else {
|
||||||
if (Selected && renderMode == RenderMode.EDIT) {
|
newGripperLocation.Offset(0, 20);
|
||||||
DrawSelectionBorder(graphics, rect);
|
}
|
||||||
}
|
if (TargetGripper.Location != newGripperLocation) {
|
||||||
|
TargetGripperMove(newGripperLocation.X, newGripperLocation.Y);
|
||||||
int tailAngle = 90 + (int)GeometryHelper.Angle2D(rect.Left + (rect.Width / 2), rect.Top + (rect.Height / 2), TargetGripper.Left, TargetGripper.Top);
|
}
|
||||||
int tailLength = GeometryHelper.Distance2D(rect.Left + (rect.Width / 2), rect.Top + (rect.Height / 2), TargetGripper.Left, TargetGripper.Top);
|
return returnValue;
|
||||||
int tailWidth = (Math.Abs(rect.Width) + Math.Abs(rect.Height)) / 20;
|
}
|
||||||
|
|
||||||
GraphicsPath bubble = new GraphicsPath();
|
/// <summary>
|
||||||
|
/// The DrawingBound should be so close as possible to the shape, so we don't invalidate to much.
|
||||||
Rectangle bubbleRect = GuiRectangle.GetGuiRectangle(0, 0, rect.Width, rect.Height);
|
/// </summary>
|
||||||
// adapt corner radius to small rectangle dimensions
|
public override Rectangle DrawingBounds {
|
||||||
int smallerSideLength = Math.Min(bubbleRect.Width, bubbleRect.Height);
|
get {
|
||||||
int cornerRadius = Math.Min(30, smallerSideLength / 2 - lineThickness);
|
int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS);
|
||||||
if (cornerRadius > 0) {
|
Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR);
|
||||||
bubble.AddArc(bubbleRect.X, bubbleRect.Y, cornerRadius, cornerRadius, 180, 90);
|
using (Pen pen = new Pen(lineColor, lineThickness)) {
|
||||||
bubble.AddArc(bubbleRect.X + bubbleRect.Width - cornerRadius, bubbleRect.Y, cornerRadius, cornerRadius, 270, 90);
|
using (GraphicsPath tailPath = CreateTail()) {
|
||||||
bubble.AddArc(bubbleRect.X + bubbleRect.Width - cornerRadius, bubbleRect.Y + bubbleRect.Height - cornerRadius, cornerRadius, cornerRadius, 0, 90);
|
return Rectangle.Inflate(Rectangle.Union(Rectangle.Round(tailPath.GetBounds(new Matrix(), pen)),GuiRectangle.GetGuiRectangle(Left, Top, Width, Height)), lineThickness+2, lineThickness+2);
|
||||||
bubble.AddArc(bubbleRect.X, bubbleRect.Y + bubbleRect.Height - cornerRadius, cornerRadius, cornerRadius, 90, 90);
|
}
|
||||||
} else {
|
}
|
||||||
bubble.AddRectangle(bubbleRect);
|
}
|
||||||
}
|
}
|
||||||
bubble.CloseAllFigures();
|
|
||||||
|
/// <summary>
|
||||||
GraphicsPath tail = new GraphicsPath();
|
/// Helper method to create the bubble GraphicsPath, so we can also calculate the bounds
|
||||||
tail.AddLine(-tailWidth, 0, tailWidth, 0);
|
/// </summary>
|
||||||
tail.AddLine(tailWidth, 0, 0, -tailLength);
|
/// <param name="lineThickness"></param>
|
||||||
tail.CloseFigure();
|
/// <returns></returns>
|
||||||
|
private GraphicsPath CreateBubble(int lineThickness) {
|
||||||
GraphicsState state = graphics.Save();
|
GraphicsPath bubble = new GraphicsPath();
|
||||||
// draw the tail border where the bubble is not visible
|
Rectangle rect = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
|
||||||
using (Region clipRegion = new Region(bubble)) {
|
|
||||||
clipRegion.Translate(rect.Left, rect.Top);
|
Rectangle bubbleRect = GuiRectangle.GetGuiRectangle(0, 0, rect.Width, rect.Height);
|
||||||
graphics.SetClip(clipRegion, CombineMode.Exclude);
|
// adapt corner radius to small rectangle dimensions
|
||||||
graphics.TranslateTransform(rect.Left + (rect.Width / 2), rect.Top + (rect.Height / 2));
|
int smallerSideLength = Math.Min(bubbleRect.Width, bubbleRect.Height);
|
||||||
graphics.RotateTransform(tailAngle);
|
int cornerRadius = Math.Min(30, smallerSideLength / 2 - lineThickness);
|
||||||
using (Pen pen = new Pen(lineColor, lineThickness)) {
|
if (cornerRadius > 0) {
|
||||||
graphics.DrawPath(pen, tail);
|
bubble.AddArc(bubbleRect.X, bubbleRect.Y, cornerRadius, cornerRadius, 180, 90);
|
||||||
}
|
bubble.AddArc(bubbleRect.X + bubbleRect.Width - cornerRadius, bubbleRect.Y, cornerRadius, cornerRadius, 270, 90);
|
||||||
}
|
bubble.AddArc(bubbleRect.X + bubbleRect.Width - cornerRadius, bubbleRect.Y + bubbleRect.Height - cornerRadius, cornerRadius, cornerRadius, 0, 90);
|
||||||
graphics.Restore(state);
|
bubble.AddArc(bubbleRect.X, bubbleRect.Y + bubbleRect.Height - cornerRadius, cornerRadius, cornerRadius, 90, 90);
|
||||||
|
} else {
|
||||||
|
bubble.AddRectangle(bubbleRect);
|
||||||
if (Colors.IsVisible(fillColor)) {
|
}
|
||||||
//draw the bubbleshape
|
bubble.CloseAllFigures();
|
||||||
state = graphics.Save();
|
using (Matrix bubbleMatrix = new Matrix()) {
|
||||||
graphics.TranslateTransform(rect.Left, rect.Top);
|
bubbleMatrix.Translate(rect.Left, rect.Top);
|
||||||
using (Brush brush = new SolidBrush(fillColor)) {
|
bubble.Transform(bubbleMatrix);
|
||||||
graphics.FillPath(brush, bubble);
|
}
|
||||||
}
|
return bubble;
|
||||||
graphics.Restore(state);
|
}
|
||||||
}
|
|
||||||
|
/// <summary>
|
||||||
if (lineVisible) {
|
/// Helper method to create the tail of the bubble, so we can also calculate the bounds
|
||||||
//draw the bubble border
|
/// </summary>
|
||||||
state = graphics.Save();
|
/// <returns></returns>
|
||||||
// Draw bubble where the Tail is not visible.
|
private GraphicsPath CreateTail() {
|
||||||
using (Region clipRegion = new Region(tail)) {
|
Rectangle rect = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
|
||||||
using (Matrix transformMatrix = new Matrix()) {
|
|
||||||
transformMatrix.Rotate(tailAngle);
|
int tailLength = GeometryHelper.Distance2D(rect.Left + (rect.Width / 2), rect.Top + (rect.Height / 2), TargetGripper.Left, TargetGripper.Top);
|
||||||
clipRegion.Transform(transformMatrix);
|
int tailWidth = (Math.Abs(rect.Width) + Math.Abs(rect.Height)) / 20;
|
||||||
}
|
|
||||||
clipRegion.Translate(rect.Left + (rect.Width / 2), rect.Top + (rect.Height / 2));
|
// This should fix a problem with the tail being to wide
|
||||||
graphics.SetClip(clipRegion, CombineMode.Exclude);
|
tailWidth = Math.Min(Math.Abs(rect.Width) / 2, tailWidth);
|
||||||
graphics.TranslateTransform(rect.Left, rect.Top);
|
tailWidth = Math.Min(Math.Abs(rect.Height) / 2, tailWidth);
|
||||||
using (Pen pen = new Pen(lineColor, lineThickness)) {
|
|
||||||
//pen.EndCap = pen.StartCap = LineCap.Round;
|
GraphicsPath tail = new GraphicsPath();
|
||||||
graphics.DrawPath(pen, bubble);
|
tail.AddLine(-tailWidth, 0, tailWidth, 0);
|
||||||
}
|
tail.AddLine(tailWidth, 0, 0, -tailLength);
|
||||||
}
|
tail.CloseFigure();
|
||||||
graphics.Restore(state);
|
|
||||||
}
|
int tailAngle = 90 + (int)GeometryHelper.Angle2D(rect.Left + (rect.Width / 2), rect.Top + (rect.Height / 2), TargetGripper.Left, TargetGripper.Top);
|
||||||
|
|
||||||
if (Colors.IsVisible(fillColor)) {
|
using (Matrix tailMatrix = new Matrix()) {
|
||||||
// Draw the tail border
|
tailMatrix.Translate(rect.Left + (rect.Width / 2), rect.Top + (rect.Height / 2));
|
||||||
state = graphics.Save();
|
tailMatrix.Rotate(tailAngle);
|
||||||
graphics.TranslateTransform(rect.Left + (rect.Width / 2), rect.Top + (rect.Height / 2));
|
tail.Transform(tailMatrix);
|
||||||
graphics.RotateTransform(tailAngle);
|
}
|
||||||
using (Brush brush = new SolidBrush(fillColor)) {
|
|
||||||
graphics.FillPath(brush, tail);
|
return tail;
|
||||||
}
|
}
|
||||||
graphics.Restore(state);
|
|
||||||
}
|
/// <summary>
|
||||||
|
/// This is to draw the actual container
|
||||||
// cleanup the paths
|
/// </summary>
|
||||||
bubble.Dispose();
|
/// <param name="graphics"></param>
|
||||||
tail.Dispose();
|
/// <param name="renderMode"></param>
|
||||||
|
public override void Draw(Graphics graphics, RenderMode renderMode) {
|
||||||
// Draw the text
|
if (TargetGripper == null) {
|
||||||
UpdateFormat();
|
return;
|
||||||
DrawText(graphics, rect, lineThickness, lineColor, false, StringFormat, Text, Font);
|
}
|
||||||
}
|
graphics.SmoothingMode = SmoothingMode.HighQuality;
|
||||||
|
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||||
public override bool Contains(int x, int y) {
|
graphics.CompositingQuality = CompositingQuality.HighQuality;
|
||||||
double xDistanceFromCenter = x - (Left + Width / 2);
|
graphics.PixelOffsetMode = PixelOffsetMode.None;
|
||||||
double yDistanceFromCenter = y - (Top + Height / 2);
|
graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
|
||||||
// ellipse: x^2/a^2 + y^2/b^2 = 1
|
|
||||||
return Math.Pow(xDistanceFromCenter, 2) / Math.Pow(Width / 2, 2) + Math.Pow(yDistanceFromCenter, 2) / Math.Pow(Height / 2, 2) < 1;
|
Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR);
|
||||||
}
|
Color fillColor = GetFieldValueAsColor(FieldType.FILL_COLOR);
|
||||||
|
int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS);
|
||||||
public override bool ClickableAt(int x, int y) {
|
|
||||||
Rectangle rect = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
|
bool lineVisible = (lineThickness > 0 && Colors.IsVisible(lineColor));
|
||||||
int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS);
|
Rectangle rect = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
|
||||||
int lineThicknessPlusSafety = lineThickness + 10;
|
|
||||||
|
if (Selected && renderMode == RenderMode.EDIT) {
|
||||||
// If we clicked inside the rectangle and it's visible we are clickable at.
|
DrawSelectionBorder(graphics, rect);
|
||||||
Color fillColor = GetFieldValueAsColor(FieldType.FILL_COLOR);
|
}
|
||||||
if (!Color.Transparent.Equals(fillColor)) {
|
|
||||||
if (Contains(x, y)) {
|
GraphicsPath bubble = CreateBubble(lineThickness);
|
||||||
return true;
|
|
||||||
}
|
GraphicsPath tail = CreateTail();
|
||||||
}
|
GraphicsState state = graphics.Save();
|
||||||
|
// draw the tail border where the bubble is not visible
|
||||||
// check the rest of the lines
|
using (Region clipRegion = new Region(bubble)) {
|
||||||
if (lineThicknessPlusSafety > 0) {
|
graphics.SetClip(clipRegion, CombineMode.Exclude);
|
||||||
using (Pen pen = new Pen(Color.White, lineThicknessPlusSafety)) {
|
using (Pen pen = new Pen(lineColor, lineThickness)) {
|
||||||
using (GraphicsPath path = new GraphicsPath()) {
|
graphics.DrawPath(pen, tail);
|
||||||
path.AddEllipse(rect);
|
}
|
||||||
return path.IsOutlineVisible(x, y, pen);
|
}
|
||||||
}
|
graphics.Restore(state);
|
||||||
}
|
|
||||||
} else {
|
if (Colors.IsVisible(fillColor)) {
|
||||||
return false;
|
//draw the bubbleshape
|
||||||
}
|
state = graphics.Save();
|
||||||
}
|
using (Brush brush = new SolidBrush(fillColor)) {
|
||||||
}
|
graphics.FillPath(brush, bubble);
|
||||||
}
|
}
|
||||||
|
graphics.Restore(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lineVisible) {
|
||||||
|
//draw the bubble border
|
||||||
|
state = graphics.Save();
|
||||||
|
// Draw bubble where the Tail is not visible.
|
||||||
|
using (Region clipRegion = new Region(tail)) {
|
||||||
|
graphics.SetClip(clipRegion, CombineMode.Exclude);
|
||||||
|
using (Pen pen = new Pen(lineColor, lineThickness)) {
|
||||||
|
//pen.EndCap = pen.StartCap = LineCap.Round;
|
||||||
|
graphics.DrawPath(pen, bubble);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
graphics.Restore(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Colors.IsVisible(fillColor)) {
|
||||||
|
// Draw the tail border
|
||||||
|
state = graphics.Save();
|
||||||
|
using (Brush brush = new SolidBrush(fillColor)) {
|
||||||
|
graphics.FillPath(brush, tail);
|
||||||
|
}
|
||||||
|
graphics.Restore(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
// cleanup the paths
|
||||||
|
bubble.Dispose();
|
||||||
|
tail.Dispose();
|
||||||
|
|
||||||
|
// Draw the text
|
||||||
|
UpdateFormat();
|
||||||
|
DrawText(graphics, rect, lineThickness, lineColor, false, StringFormat, Text, Font);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Contains(int x, int y) {
|
||||||
|
double xDistanceFromCenter = x - (Left + Width / 2);
|
||||||
|
double yDistanceFromCenter = y - (Top + Height / 2);
|
||||||
|
// ellipse: x^2/a^2 + y^2/b^2 = 1
|
||||||
|
return Math.Pow(xDistanceFromCenter, 2) / Math.Pow(Width / 2, 2) + Math.Pow(yDistanceFromCenter, 2) / Math.Pow(Height / 2, 2) < 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool ClickableAt(int x, int y) {
|
||||||
|
Rectangle rect = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
|
||||||
|
int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS);
|
||||||
|
int lineThicknessPlusSafety = lineThickness + 10;
|
||||||
|
|
||||||
|
// If we clicked inside the rectangle and it's visible we are clickable at.
|
||||||
|
Color fillColor = GetFieldValueAsColor(FieldType.FILL_COLOR);
|
||||||
|
if (!Color.Transparent.Equals(fillColor)) {
|
||||||
|
if (Contains(x, y)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check the rest of the lines
|
||||||
|
if (lineThicknessPlusSafety > 0) {
|
||||||
|
using (Pen pen = new Pen(Color.White, lineThicknessPlusSafety)) {
|
||||||
|
using (GraphicsPath path = new GraphicsPath()) {
|
||||||
|
path.AddEllipse(rect);
|
||||||
|
return path.IsOutlineVisible(x, y, pen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -30,7 +30,6 @@ using System.Runtime.Serialization;
|
||||||
|
|
||||||
namespace Greenshot.Drawing {
|
namespace Greenshot.Drawing {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Description of StepLabelContainer.
|
|
||||||
/// This is an enumerated label, every single StepLabelContainer shows the number of the order it was created.
|
/// This is an enumerated label, every single StepLabelContainer shows the number of the order it was created.
|
||||||
/// To make sure that deleting recalculates, we check the location before every draw.
|
/// To make sure that deleting recalculates, we check the location before every draw.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -71,7 +71,7 @@ namespace GreenshotBoxPlugin {
|
||||||
/// <param name="postMessage"></param>
|
/// <param name="postMessage"></param>
|
||||||
/// <returns>string with the file content</returns>
|
/// <returns>string with the file content</returns>
|
||||||
public static string PostAndReturn(Uri url, string postMessage) {
|
public static string PostAndReturn(Uri url, string postMessage) {
|
||||||
HttpWebRequest webRequest = (HttpWebRequest)NetworkHelper.CreateWebRequest(url);
|
HttpWebRequest webRequest = NetworkHelper.CreateWebRequest(url);
|
||||||
webRequest.Method = "POST";
|
webRequest.Method = "POST";
|
||||||
webRequest.KeepAlive = true;
|
webRequest.KeepAlive = true;
|
||||||
webRequest.Credentials = CredentialCache.DefaultCredentials;
|
webRequest.Credentials = CredentialCache.DefaultCredentials;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue