From db8b2cb2c58928139d0f0f999e23415d837c3967 Mon Sep 17 00:00:00 2001 From: RKrom Date: Fri, 30 May 2014 10:11:51 +0200 Subject: [PATCH] Improved the drawing of the speechbubble, now one can resize it "the wrong way" and it is still drawn correctly. Made the counting labels to appear directly centered to the mouse, this simplifies placing them. Also removed the possibility to resize them. Fixed a bug where the tool-buttons were not being disabled, if another tool is selected or ESC is pressed. --- Greenshot/Drawing/DrawableContainer.cs | 2 +- Greenshot/Drawing/SpeechbubbleContainer.cs | 24 +++++++++++----------- Greenshot/Drawing/StepLabelContainer.cs | 19 ++++++++++++++--- Greenshot/Forms/ImageEditorForm.cs | 2 +- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/Greenshot/Drawing/DrawableContainer.cs b/Greenshot/Drawing/DrawableContainer.cs index 89747bbb7..78ba171fd 100644 --- a/Greenshot/Drawing/DrawableContainer.cs +++ b/Greenshot/Drawing/DrawableContainer.cs @@ -559,7 +559,7 @@ namespace Greenshot.Drawing { ResumeLayout(); } - public void HideGrippers() { + public virtual void HideGrippers() { SuspendLayout(); if (_grippers != null) { for (int i = 0; i < _grippers.Length; i++) { diff --git a/Greenshot/Drawing/SpeechbubbleContainer.cs b/Greenshot/Drawing/SpeechbubbleContainer.cs index 1286a44bc..33d315fc9 100644 --- a/Greenshot/Drawing/SpeechbubbleContainer.cs +++ b/Greenshot/Drawing/SpeechbubbleContainer.cs @@ -43,7 +43,7 @@ namespace Greenshot.Drawing { /// We set our own field values /// protected override void InitializeFields() { - AddField(GetType(), FieldType.LINE_THICKNESS, 0); + AddField(GetType(), FieldType.LINE_THICKNESS, 2); AddField(GetType(), FieldType.LINE_COLOR, Color.Blue); AddField(GetType(), FieldType.SHADOW, false); AddField(GetType(), FieldType.FONT_ITALIC, false); @@ -68,7 +68,7 @@ namespace Greenshot.Drawing { if (TargetGripper == null) { InitTargetGripper(Color.Green, new Point(mouseX, mouseY)); } - return base.HandleMouseDown(mouseX, mouseY); + return base.HandleMouseDown(mouseX + 20, mouseY + 20); } public override Rectangle DrawingBounds { @@ -93,9 +93,9 @@ namespace Greenshot.Drawing { bool lineVisible = (lineThickness > 0 && Colors.IsVisible(lineColor)); Rectangle rect = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height); - int tailAngle = 90 + (int)GeometryHelper.Angle2D(Left + (Width / 2), Top + (Height / 2), TargetGripper.Left, TargetGripper.Top); - int tailLength = GeometryHelper.Distance2D(Left + (Width / 2), Top + (Height / 2), TargetGripper.Left, TargetGripper.Top); - int tailWidth = (Math.Abs(Width) + Math.Abs(Height)) / 20; + 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(); int CornerRadius = 30; @@ -118,9 +118,9 @@ namespace Greenshot.Drawing { GraphicsState state = graphics.Save(); // draw the tail border where the bubble is not visible using (Region clipRegion = new Region(bubble)) { - clipRegion.Translate(Left, Top); + clipRegion.Translate(rect.Left, rect.Top); graphics.SetClip(clipRegion, CombineMode.Exclude); - graphics.TranslateTransform(Left + (Width / 2), Top + (Height / 2)); + 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); @@ -132,7 +132,7 @@ namespace Greenshot.Drawing { if (Colors.IsVisible(fillColor)) { //draw the bubbleshape state = graphics.Save(); - graphics.TranslateTransform(Left, Top); + graphics.TranslateTransform(rect.Left, rect.Top); using (Brush brush = new SolidBrush(fillColor)) { graphics.FillPath(brush, bubble); } @@ -147,11 +147,11 @@ namespace Greenshot.Drawing { Matrix transformMatrix = new Matrix(); transformMatrix.Rotate(tailAngle); clipRegion.Transform(transformMatrix); - clipRegion.Translate(Left + (Width / 2), Top + (Height / 2)); + clipRegion.Translate(rect.Left + (rect.Width / 2), rect.Top + (rect.Height / 2)); graphics.SetClip(clipRegion, CombineMode.Exclude); - graphics.TranslateTransform(Left, Top); + graphics.TranslateTransform(rect.Left, rect.Top); using (Pen pen = new Pen(lineColor, lineThickness)) { - pen.EndCap = pen.StartCap = LineCap.Round; + //pen.EndCap = pen.StartCap = LineCap.Round; graphics.DrawPath(pen, bubble); } } @@ -161,7 +161,7 @@ namespace Greenshot.Drawing { if (Colors.IsVisible(fillColor)) { // Draw the tail border state = graphics.Save(); - graphics.TranslateTransform(Left + (Width / 2), Top + (Height / 2)); + 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); diff --git a/Greenshot/Drawing/StepLabelContainer.cs b/Greenshot/Drawing/StepLabelContainer.cs index 704e4c68e..8870e877d 100644 --- a/Greenshot/Drawing/StepLabelContainer.cs +++ b/Greenshot/Drawing/StepLabelContainer.cs @@ -48,20 +48,33 @@ namespace Greenshot.Drawing { InitContent(); } + public override void ShowGrippers() { + } + + public override void HideGrippers() { + } + public override bool InitContent() { _defaultEditMode = EditStatus.IDLE; _stringFormat.Alignment = StringAlignment.Center; _stringFormat.LineAlignment = StringAlignment.Center; // Set defaults - Width = 40; - Height = 40; + Width = 30; + Height = 30; using (FontFamily fam = new FontFamily(FontFamily.GenericSansSerif.Name)) { - _font = new Font(fam, 18, FontStyle.Regular, GraphicsUnit.Pixel); + _font = new Font(fam, 14, FontStyle.Regular, GraphicsUnit.Pixel); } return true; } + /// + /// This makes it possible for the label to be placed exactly in the middle of the pointer. + /// + public override bool HandleMouseDown(int mouseX, int mouseY) { + return base.HandleMouseDown(mouseX - (Width / 2), mouseY - (Height / 2)); + } + /// /// We set our own field values /// diff --git a/Greenshot/Forms/ImageEditorForm.cs b/Greenshot/Forms/ImageEditorForm.cs index f44be74b7..f63100af3 100644 --- a/Greenshot/Forms/ImageEditorForm.cs +++ b/Greenshot/Forms/ImageEditorForm.cs @@ -176,7 +176,7 @@ namespace Greenshot { obfuscateModeButton.DropDownItemClicked += FilterPresetDropDownItemClicked; highlightModeButton.DropDownItemClicked += FilterPresetDropDownItemClicked; - toolbarButtons = new[] { btnCursor, btnRect, btnEllipse, btnText, btnLine, btnArrow, btnFreehand, btnHighlight, btnObfuscate, btnCrop }; + toolbarButtons = new[] { btnCursor, btnRect, btnEllipse, btnText, btnLine, btnArrow, btnFreehand, btnHighlight, btnObfuscate, btnCrop, btnStepLabel, btnSpeechBubble }; //toolbarDropDownButtons = new ToolStripDropDownButton[]{btnBlur, btnPixeliate, btnTextHighlighter, btnAreaHighlighter, btnMagnifier}; pluginToolStripMenuItem.Visible = pluginToolStripMenuItem.DropDownItems.Count > 0;