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]
|
||||
// will store current bounds of this DrawableContainer before starting a resize
|
||||
private Rectangle _boundsBeforeResize = Rectangle.Empty;
|
||||
protected Rectangle _boundsBeforeResize = Rectangle.Empty;
|
||||
|
||||
[NonSerialized]
|
||||
// "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 {
|
||||
get { return GuiRectangle.GetGuiRectangle(Left, Top, Width, Height); }
|
||||
|
@ -449,6 +449,7 @@ namespace Greenshot.Drawing {
|
|||
}
|
||||
|
||||
private void GripperMouseMove(object sender, MouseEventArgs e) {
|
||||
Invalidate();
|
||||
Gripper originatingGripper = (Gripper)sender;
|
||||
int absX = originatingGripper.Left + e.X;
|
||||
int absY = originatingGripper.Top + e.Y;
|
||||
|
@ -463,7 +464,6 @@ namespace Greenshot.Drawing {
|
|||
MakeBoundsChangeUndoable(false);
|
||||
}
|
||||
|
||||
Invalidate();
|
||||
SuspendLayout();
|
||||
|
||||
// reset "workbench" rectangle to current bounds
|
||||
|
@ -479,8 +479,8 @@ namespace Greenshot.Drawing {
|
|||
ApplyBounds(_boundsAfterResize);
|
||||
|
||||
ResumeLayout();
|
||||
Invalidate();
|
||||
}
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
public bool hasFilters {
|
||||
|
|
|
@ -22,10 +22,9 @@
|
|||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Greenshot.Drawing
|
||||
{
|
||||
namespace Greenshot.Drawing {
|
||||
/// <summary>
|
||||
/// Description of Gripper.
|
||||
/// Grippers are the dragable edges of our containers
|
||||
/// </summary>
|
||||
public class Gripper : Label {
|
||||
/// <summary>
|
||||
|
@ -43,29 +42,15 @@ namespace Greenshot.Drawing
|
|||
public const int POSITION_BOTTOM_LEFT = 6;
|
||||
public const int POSITION_MIDDLE_LEFT = 7;
|
||||
|
||||
public int Position;
|
||||
public int Position {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public Gripper() {
|
||||
Width = 5;
|
||||
Height = 5;
|
||||
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
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using Greenshot.Drawing.Fields;
|
||||
using Greenshot.Helpers;
|
||||
using Greenshot.Plugin.Drawing;
|
||||
using log4net;
|
||||
|
||||
namespace Greenshot.Drawing {
|
||||
/// <summary>
|
||||
|
@ -32,7 +32,6 @@ namespace Greenshot.Drawing {
|
|||
/// </summary>
|
||||
[Serializable]
|
||||
public class RectangleContainer : DrawableContainer {
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(RectangleContainer));
|
||||
|
||||
public RectangleContainer(Surface parent) : base(parent) {
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@ using System.Drawing.Drawing2D;
|
|||
using System.Drawing.Text;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Windows.Forms;
|
||||
using GreenshotPlugin.UnmanagedHelpers;
|
||||
using log4net;
|
||||
|
||||
namespace Greenshot.Drawing {
|
||||
/// <summary>
|
||||
|
@ -36,6 +38,9 @@ namespace Greenshot.Drawing {
|
|||
/// </summary>
|
||||
[Serializable]
|
||||
public class SpeechbubbleContainer : TextContainer {
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(RectangleContainer));
|
||||
|
||||
private Point _initialGripperPoint;
|
||||
|
||||
#region TargetGripper serializing code
|
||||
// Only used for serializing the TargetGripper location
|
||||
|
@ -93,18 +98,117 @@ namespace Greenshot.Drawing {
|
|||
/// <returns>true if the surface doesn't need to handle the event</returns>
|
||||
public override bool HandleMouseDown(int mouseX, int mouseY) {
|
||||
if (TargetGripper == null) {
|
||||
_initialGripperPoint = new Point(mouseX, mouseY);
|
||||
InitTargetGripper(Color.Green, new Point(mouseX, mouseY));
|
||||
}
|
||||
return base.HandleMouseDown(mouseX + 20, mouseY + 20);
|
||||
return base.HandleMouseDown(mouseX, mouseY);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overriding the HandleMouseMove will help us to make sure the tail is always visible.
|
||||
/// Should fix BUG-1682
|
||||
/// </summary>
|
||||
/// <param name="x"></param>
|
||||
/// <param name="y"></param>
|
||||
/// <returns></returns>
|
||||
public override bool HandleMouseMove(int x, int y) {
|
||||
bool returnValue = base.HandleMouseMove(x, y);
|
||||
Point newGripperLocation = _initialGripperPoint;
|
||||
if (_boundsAfterResize.Right - _boundsAfterResize.Left >= 0) {
|
||||
newGripperLocation.Offset(-20, 0);
|
||||
} else {
|
||||
newGripperLocation.Offset(20, 0);
|
||||
}
|
||||
if (_boundsAfterResize.Bottom - _boundsAfterResize.Top >= 0) {
|
||||
newGripperLocation.Offset(0, -20);
|
||||
} else {
|
||||
newGripperLocation.Offset(0, 20);
|
||||
}
|
||||
if (TargetGripper.Location != newGripperLocation) {
|
||||
TargetGripperMove(newGripperLocation.X, newGripperLocation.Y);
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The DrawingBound should be so close as possible to the shape, so we don't invalidate to much.
|
||||
/// </summary>
|
||||
public override Rectangle DrawingBounds {
|
||||
get {
|
||||
// TODO: Use the normal bounds and extend with the TargetGripper
|
||||
return new Rectangle(0, 0, _parent.Width, _parent.Height);
|
||||
int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS);
|
||||
Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR);
|
||||
using (Pen pen = new Pen(lineColor, lineThickness)) {
|
||||
using (GraphicsPath tailPath = CreateTail()) {
|
||||
return Rectangle.Inflate(Rectangle.Union(Rectangle.Round(tailPath.GetBounds(new Matrix(), pen)),GuiRectangle.GetGuiRectangle(Left, Top, Width, Height)), lineThickness+2, lineThickness+2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper method to create the bubble GraphicsPath, so we can also calculate the bounds
|
||||
/// </summary>
|
||||
/// <param name="lineThickness"></param>
|
||||
/// <returns></returns>
|
||||
private GraphicsPath CreateBubble(int lineThickness) {
|
||||
GraphicsPath bubble = new GraphicsPath();
|
||||
Rectangle rect = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
|
||||
|
||||
Rectangle bubbleRect = GuiRectangle.GetGuiRectangle(0, 0, rect.Width, rect.Height);
|
||||
// adapt corner radius to small rectangle dimensions
|
||||
int smallerSideLength = Math.Min(bubbleRect.Width, bubbleRect.Height);
|
||||
int cornerRadius = Math.Min(30, smallerSideLength / 2 - lineThickness);
|
||||
if (cornerRadius > 0) {
|
||||
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);
|
||||
bubble.AddArc(bubbleRect.X, bubbleRect.Y + bubbleRect.Height - cornerRadius, cornerRadius, cornerRadius, 90, 90);
|
||||
} else {
|
||||
bubble.AddRectangle(bubbleRect);
|
||||
}
|
||||
bubble.CloseAllFigures();
|
||||
using (Matrix bubbleMatrix = new Matrix()) {
|
||||
bubbleMatrix.Translate(rect.Left, rect.Top);
|
||||
bubble.Transform(bubbleMatrix);
|
||||
}
|
||||
return bubble;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper method to create the tail of the bubble, so we can also calculate the bounds
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private GraphicsPath CreateTail() {
|
||||
Rectangle rect = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
|
||||
|
||||
int tailLength = GeometryHelper.Distance2D(rect.Left + (rect.Width / 2), rect.Top + (rect.Height / 2), TargetGripper.Left, TargetGripper.Top);
|
||||
int tailWidth = (Math.Abs(rect.Width) + Math.Abs(rect.Height)) / 20;
|
||||
|
||||
// This should fix a problem with the tail being to wide
|
||||
tailWidth = Math.Min(Math.Abs(rect.Width) / 2, tailWidth);
|
||||
tailWidth = Math.Min(Math.Abs(rect.Height) / 2, tailWidth);
|
||||
|
||||
GraphicsPath tail = new GraphicsPath();
|
||||
tail.AddLine(-tailWidth, 0, tailWidth, 0);
|
||||
tail.AddLine(tailWidth, 0, 0, -tailLength);
|
||||
tail.CloseFigure();
|
||||
|
||||
int tailAngle = 90 + (int)GeometryHelper.Angle2D(rect.Left + (rect.Width / 2), rect.Top + (rect.Height / 2), TargetGripper.Left, TargetGripper.Top);
|
||||
|
||||
using (Matrix tailMatrix = new Matrix()) {
|
||||
tailMatrix.Translate(rect.Left + (rect.Width / 2), rect.Top + (rect.Height / 2));
|
||||
tailMatrix.Rotate(tailAngle);
|
||||
tail.Transform(tailMatrix);
|
||||
}
|
||||
|
||||
return tail;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is to draw the actual container
|
||||
/// </summary>
|
||||
/// <param name="graphics"></param>
|
||||
/// <param name="renderMode"></param>
|
||||
public override void Draw(Graphics graphics, RenderMode renderMode) {
|
||||
if (TargetGripper == null) {
|
||||
return;
|
||||
|
@ -126,49 +230,22 @@ namespace Greenshot.Drawing {
|
|||
DrawSelectionBorder(graphics, rect);
|
||||
}
|
||||
|
||||
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);
|
||||
int tailWidth = (Math.Abs(rect.Width) + Math.Abs(rect.Height)) / 20;
|
||||
|
||||
GraphicsPath bubble = new GraphicsPath();
|
||||
|
||||
Rectangle bubbleRect = GuiRectangle.GetGuiRectangle(0, 0, rect.Width, rect.Height);
|
||||
// adapt corner radius to small rectangle dimensions
|
||||
int smallerSideLength = Math.Min(bubbleRect.Width, bubbleRect.Height);
|
||||
int cornerRadius = Math.Min(30, smallerSideLength / 2 - lineThickness);
|
||||
if (cornerRadius > 0) {
|
||||
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);
|
||||
bubble.AddArc(bubbleRect.X, bubbleRect.Y + bubbleRect.Height - cornerRadius, cornerRadius, cornerRadius, 90, 90);
|
||||
} else {
|
||||
bubble.AddRectangle(bubbleRect);
|
||||
}
|
||||
bubble.CloseAllFigures();
|
||||
|
||||
GraphicsPath tail = new GraphicsPath();
|
||||
tail.AddLine(-tailWidth, 0, tailWidth, 0);
|
||||
tail.AddLine(tailWidth, 0, 0, -tailLength);
|
||||
tail.CloseFigure();
|
||||
GraphicsPath bubble = CreateBubble(lineThickness);
|
||||
|
||||
GraphicsPath tail = CreateTail();
|
||||
GraphicsState state = graphics.Save();
|
||||
// draw the tail border where the bubble is not visible
|
||||
using (Region clipRegion = new Region(bubble)) {
|
||||
clipRegion.Translate(rect.Left, rect.Top);
|
||||
graphics.SetClip(clipRegion, CombineMode.Exclude);
|
||||
graphics.TranslateTransform(rect.Left + (rect.Width / 2), rect.Top + (rect.Height / 2));
|
||||
graphics.RotateTransform(tailAngle);
|
||||
using (Pen pen = new Pen(lineColor, lineThickness)) {
|
||||
graphics.DrawPath(pen, tail);
|
||||
}
|
||||
}
|
||||
graphics.Restore(state);
|
||||
|
||||
|
||||
if (Colors.IsVisible(fillColor)) {
|
||||
//draw the bubbleshape
|
||||
state = graphics.Save();
|
||||
graphics.TranslateTransform(rect.Left, rect.Top);
|
||||
using (Brush brush = new SolidBrush(fillColor)) {
|
||||
graphics.FillPath(brush, bubble);
|
||||
}
|
||||
|
@ -180,13 +257,7 @@ namespace Greenshot.Drawing {
|
|||
state = graphics.Save();
|
||||
// Draw bubble where the Tail is not visible.
|
||||
using (Region clipRegion = new Region(tail)) {
|
||||
using (Matrix transformMatrix = new Matrix()) {
|
||||
transformMatrix.Rotate(tailAngle);
|
||||
clipRegion.Transform(transformMatrix);
|
||||
}
|
||||
clipRegion.Translate(rect.Left + (rect.Width / 2), rect.Top + (rect.Height / 2));
|
||||
graphics.SetClip(clipRegion, CombineMode.Exclude);
|
||||
graphics.TranslateTransform(rect.Left, rect.Top);
|
||||
using (Pen pen = new Pen(lineColor, lineThickness)) {
|
||||
//pen.EndCap = pen.StartCap = LineCap.Round;
|
||||
graphics.DrawPath(pen, bubble);
|
||||
|
@ -198,8 +269,6 @@ namespace Greenshot.Drawing {
|
|||
if (Colors.IsVisible(fillColor)) {
|
||||
// Draw the tail border
|
||||
state = graphics.Save();
|
||||
graphics.TranslateTransform(rect.Left + (rect.Width / 2), rect.Top + (rect.Height / 2));
|
||||
graphics.RotateTransform(tailAngle);
|
||||
using (Brush brush = new SolidBrush(fillColor)) {
|
||||
graphics.FillPath(brush, tail);
|
||||
}
|
||||
|
@ -243,9 +312,8 @@ namespace Greenshot.Drawing {
|
|||
return path.IsOutlineVisible(x, y, pen);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ using System.Runtime.Serialization;
|
|||
|
||||
namespace Greenshot.Drawing {
|
||||
/// <summary>
|
||||
/// Description of StepLabelContainer.
|
||||
/// 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.
|
||||
/// </summary>
|
||||
|
|
|
@ -71,7 +71,7 @@ namespace GreenshotBoxPlugin {
|
|||
/// <param name="postMessage"></param>
|
||||
/// <returns>string with the file content</returns>
|
||||
public static string PostAndReturn(Uri url, string postMessage) {
|
||||
HttpWebRequest webRequest = (HttpWebRequest)NetworkHelper.CreateWebRequest(url);
|
||||
HttpWebRequest webRequest = NetworkHelper.CreateWebRequest(url);
|
||||
webRequest.Method = "POST";
|
||||
webRequest.KeepAlive = true;
|
||||
webRequest.Credentials = CredentialCache.DefaultCredentials;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue