2014-07-09 10:32:36 +12:00
|
|
|
|
#region License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
2015-08-13 13:07:38 +12:00
|
|
|
|
Copyright (c) 2007-2015 ShareX Team
|
2014-07-09 10:32:36 +12:00
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
2014-12-11 09:25:20 +13:00
|
|
|
|
using ShareX.HelpersLib;
|
|
|
|
|
using ShareX.ScreenCaptureLib.Properties;
|
2014-07-09 10:32:36 +12:00
|
|
|
|
using System;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Drawing.Drawing2D;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2014-12-11 09:25:20 +13:00
|
|
|
|
namespace ShareX.ScreenCaptureLib
|
2014-07-09 10:32:36 +12:00
|
|
|
|
{
|
2015-09-01 06:36:50 +12:00
|
|
|
|
public class RectangleAnnotate : BaseForm
|
2014-07-09 10:32:36 +12:00
|
|
|
|
{
|
2014-07-10 11:16:27 +12:00
|
|
|
|
public static Rectangle LastSelectionRectangle0Based { get; private set; }
|
2014-07-09 10:32:36 +12:00
|
|
|
|
|
|
|
|
|
public Rectangle ScreenRectangle { get; private set; }
|
|
|
|
|
|
|
|
|
|
public Rectangle ScreenRectangle0Based
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return new Rectangle(0, 0, ScreenRectangle.Width, ScreenRectangle.Height);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Rectangle SelectionRectangle { get; private set; }
|
|
|
|
|
|
|
|
|
|
public Rectangle SelectionRectangle0Based
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return new Rectangle(SelectionRectangle.X - ScreenRectangle.X, SelectionRectangle.Y - ScreenRectangle.Y, SelectionRectangle.Width, SelectionRectangle.Height);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Point CurrentMousePosition { get; private set; }
|
|
|
|
|
|
|
|
|
|
public Point CurrentMousePosition0Based
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return new Point(CurrentMousePosition.X - ScreenRectangle.X, CurrentMousePosition.Y - ScreenRectangle.Y);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Point PreviousMousePosition { get; private set; }
|
|
|
|
|
|
|
|
|
|
public Point PreviousMousePosition0Based
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return new Point(PreviousMousePosition.X - ScreenRectangle.X, PreviousMousePosition.Y - ScreenRectangle.Y);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-09 13:17:37 +12:00
|
|
|
|
private bool cursorShown = true;
|
|
|
|
|
|
|
|
|
|
public bool CursorShown
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return cursorShown;
|
|
|
|
|
}
|
2014-07-10 07:30:18 +12:00
|
|
|
|
private set
|
2014-07-09 13:17:37 +12:00
|
|
|
|
{
|
|
|
|
|
if (cursorShown == value)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
|
{
|
|
|
|
|
Cursor.Show();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Cursor.Hide();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cursorShown = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-10 15:11:30 +12:00
|
|
|
|
public RectangleAnnotateOptions Options { get; private set; }
|
2014-07-10 11:16:27 +12:00
|
|
|
|
|
2015-11-13 14:07:25 +13:00
|
|
|
|
public RegionAnnotateMode Mode { get; private set; }
|
|
|
|
|
|
|
|
|
|
public bool IsDrawingMode => Mode != RegionAnnotateMode.Capture && !isBusy;
|
|
|
|
|
|
2014-07-09 10:32:36 +12:00
|
|
|
|
private Timer timer;
|
|
|
|
|
private Image backgroundImage;
|
|
|
|
|
private Pen borderDotPen, borderDotPen2;
|
|
|
|
|
private Point positionOnClick;
|
2015-11-13 14:07:25 +13:00
|
|
|
|
private bool isMouseDown, isBusy;
|
2014-07-09 10:32:36 +12:00
|
|
|
|
private Stopwatch penTimer;
|
2015-11-13 14:07:25 +13:00
|
|
|
|
private Font infofont, tipFont;
|
2014-07-09 10:32:36 +12:00
|
|
|
|
|
2014-07-10 11:16:27 +12:00
|
|
|
|
public RectangleAnnotate(RectangleAnnotateOptions options)
|
2014-07-09 10:32:36 +12:00
|
|
|
|
{
|
2014-07-10 11:16:27 +12:00
|
|
|
|
Options = options;
|
|
|
|
|
|
2014-07-09 10:32:36 +12:00
|
|
|
|
backgroundImage = Screenshot.CaptureFullscreen();
|
|
|
|
|
borderDotPen = new Pen(Color.Black, 1);
|
|
|
|
|
borderDotPen2 = new Pen(Color.White, 1);
|
|
|
|
|
borderDotPen2.DashPattern = new float[] { 5, 5 };
|
2015-11-13 14:07:25 +13:00
|
|
|
|
infofont = new Font("Arial", 15);
|
2014-07-10 08:57:26 +12:00
|
|
|
|
tipFont = new Font("Arial", 13);
|
2014-07-09 10:32:36 +12:00
|
|
|
|
penTimer = Stopwatch.StartNew();
|
|
|
|
|
ScreenRectangle = CaptureHelpers.GetScreenBounds();
|
|
|
|
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
using (MemoryStream cursorStream = new MemoryStream(Resources.Crosshair))
|
|
|
|
|
{
|
2014-07-09 13:17:37 +12:00
|
|
|
|
Cursor = new Cursor(cursorStream);
|
2014-07-09 10:32:36 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
timer = new Timer { Interval = 10 };
|
|
|
|
|
timer.Tick += timer_Tick;
|
|
|
|
|
timer.Start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IContainer components = null;
|
|
|
|
|
|
|
|
|
|
private void InitializeComponent()
|
|
|
|
|
{
|
|
|
|
|
SuspendLayout();
|
|
|
|
|
AutoScaleDimensions = new SizeF(6F, 13F);
|
|
|
|
|
AutoScaleMode = AutoScaleMode.Font;
|
|
|
|
|
StartPosition = FormStartPosition.Manual;
|
|
|
|
|
Bounds = ScreenRectangle;
|
|
|
|
|
FormBorderStyle = FormBorderStyle.None;
|
|
|
|
|
SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
|
2014-10-18 00:08:33 +13:00
|
|
|
|
Text = "ShareX - " + Resources.RectangleAnnotate_InitializeComponent_Rectangle_capture_annotate;
|
2014-07-09 10:32:36 +12:00
|
|
|
|
ShowInTaskbar = false;
|
|
|
|
|
TopMost = true;
|
2014-07-09 13:17:37 +12:00
|
|
|
|
|
|
|
|
|
Shown += RectangleAnnotate_Shown;
|
|
|
|
|
MouseDown += RectangleAnnotate_MouseDown;
|
|
|
|
|
MouseUp += RectangleAnnotate_MouseUp;
|
|
|
|
|
MouseWheel += RectangleAnnotate_MouseWheel;
|
|
|
|
|
KeyDown += RectangleAnnotate_KeyDown;
|
|
|
|
|
KeyUp += RectangleAnnotate_KeyUp;
|
|
|
|
|
|
2014-07-09 10:32:36 +12:00
|
|
|
|
ResumeLayout(false);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-10 11:16:27 +12:00
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
if (disposing && (components != null))
|
|
|
|
|
{
|
|
|
|
|
components.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (timer != null) timer.Dispose();
|
|
|
|
|
if (backgroundImage != null) backgroundImage.Dispose();
|
|
|
|
|
if (borderDotPen != null) borderDotPen.Dispose();
|
|
|
|
|
if (borderDotPen2 != null) borderDotPen2.Dispose();
|
2015-11-13 14:07:25 +13:00
|
|
|
|
if (infofont != null) infofont.Dispose();
|
2014-07-10 11:16:27 +12:00
|
|
|
|
if (tipFont != null) tipFont.Dispose();
|
|
|
|
|
|
|
|
|
|
base.Dispose(disposing);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-09 13:17:37 +12:00
|
|
|
|
private void RectangleAnnotate_Shown(object sender, EventArgs e)
|
2014-07-09 10:32:36 +12:00
|
|
|
|
{
|
|
|
|
|
this.ShowActivate();
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-09 13:17:37 +12:00
|
|
|
|
private void RectangleAnnotate_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
|
{
|
2015-11-13 14:07:25 +13:00
|
|
|
|
if (e.KeyCode == Keys.D1)
|
2014-07-09 13:17:37 +12:00
|
|
|
|
{
|
2015-11-13 14:07:25 +13:00
|
|
|
|
Mode = RegionAnnotateMode.Capture;
|
2014-07-10 07:30:18 +12:00
|
|
|
|
}
|
2015-11-13 14:07:25 +13:00
|
|
|
|
else if (e.KeyCode == Keys.D2)
|
|
|
|
|
{
|
|
|
|
|
Mode = RegionAnnotateMode.Pen;
|
|
|
|
|
}
|
|
|
|
|
else if (e.KeyCode == Keys.D3)
|
|
|
|
|
{
|
|
|
|
|
Mode = RegionAnnotateMode.Rectangle;
|
2015-11-13 20:30:52 +13:00
|
|
|
|
}
|
|
|
|
|
else if (e.KeyCode == Keys.ControlKey)
|
|
|
|
|
{
|
|
|
|
|
switch (Mode)
|
|
|
|
|
{
|
|
|
|
|
case RegionAnnotateMode.Capture:
|
|
|
|
|
Mode = RegionAnnotateMode.Pen;
|
|
|
|
|
break;
|
|
|
|
|
case RegionAnnotateMode.Pen:
|
|
|
|
|
Mode = RegionAnnotateMode.Rectangle;
|
|
|
|
|
break;
|
|
|
|
|
case RegionAnnotateMode.Rectangle:
|
|
|
|
|
Mode = RegionAnnotateMode.Capture;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-11-13 14:07:25 +13:00
|
|
|
|
}
|
|
|
|
|
else if (e.KeyCode == Keys.ShiftKey && IsDrawingMode)
|
2014-07-10 07:30:18 +12:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2015-11-13 14:07:25 +13:00
|
|
|
|
isBusy = true;
|
2014-09-08 18:40:04 +12:00
|
|
|
|
Options.DrawingPenColor = ColorPickerForm.GetColor(Options.DrawingPenColor);
|
2014-07-10 07:30:18 +12:00
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
2015-11-13 14:07:25 +13:00
|
|
|
|
isBusy = false;
|
2014-07-10 07:30:18 +12:00
|
|
|
|
}
|
2014-07-09 13:17:37 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RectangleAnnotate_KeyUp(object sender, KeyEventArgs e)
|
2014-07-09 10:32:36 +12:00
|
|
|
|
{
|
|
|
|
|
if (e.KeyCode == Keys.Escape)
|
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
2014-07-10 08:57:26 +12:00
|
|
|
|
else if (e.KeyCode == Keys.Space)
|
|
|
|
|
{
|
|
|
|
|
DoSelection(ScreenRectangle);
|
|
|
|
|
}
|
2014-07-09 10:32:36 +12:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-09 13:17:37 +12:00
|
|
|
|
private void RectangleAnnotate_MouseDown(object sender, MouseEventArgs e)
|
2014-07-09 10:32:36 +12:00
|
|
|
|
{
|
|
|
|
|
if (e.Button == MouseButtons.Left)
|
|
|
|
|
{
|
|
|
|
|
positionOnClick = CaptureHelpers.GetCursorPosition();
|
|
|
|
|
isMouseDown = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-09 13:17:37 +12:00
|
|
|
|
private void RectangleAnnotate_MouseUp(object sender, MouseEventArgs e)
|
2014-07-09 10:32:36 +12:00
|
|
|
|
{
|
2014-07-10 07:30:18 +12:00
|
|
|
|
if (e.Button == MouseButtons.Left && isMouseDown)
|
2014-07-09 10:32:36 +12:00
|
|
|
|
{
|
2015-11-13 20:30:52 +13:00
|
|
|
|
isMouseDown = false;
|
|
|
|
|
|
|
|
|
|
switch (Mode)
|
2014-07-09 13:17:37 +12:00
|
|
|
|
{
|
2015-11-13 20:30:52 +13:00
|
|
|
|
case RegionAnnotateMode.Capture:
|
|
|
|
|
DoSelection(SelectionRectangle);
|
|
|
|
|
break;
|
|
|
|
|
case RegionAnnotateMode.Rectangle:
|
|
|
|
|
AddRectangle();
|
|
|
|
|
break;
|
2014-07-09 13:17:37 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-07-10 07:30:18 +12:00
|
|
|
|
else if (e.Button == MouseButtons.Right)
|
|
|
|
|
{
|
|
|
|
|
if (isMouseDown)
|
|
|
|
|
{
|
|
|
|
|
isMouseDown = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-07-09 13:17:37 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RectangleAnnotate_MouseWheel(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
2015-11-13 14:07:25 +13:00
|
|
|
|
if (IsDrawingMode)
|
2014-07-09 13:17:37 +12:00
|
|
|
|
{
|
2014-07-10 12:40:41 +12:00
|
|
|
|
if (e.Delta > 0)
|
|
|
|
|
{
|
|
|
|
|
Options.DrawingPenSize++;
|
|
|
|
|
}
|
|
|
|
|
else if (e.Delta < 0)
|
|
|
|
|
{
|
|
|
|
|
Options.DrawingPenSize--;
|
|
|
|
|
}
|
2014-07-09 10:32:36 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-10 08:57:26 +12:00
|
|
|
|
private void DoSelection(Rectangle rect)
|
|
|
|
|
{
|
|
|
|
|
SelectionRectangle = rect;
|
|
|
|
|
|
|
|
|
|
if (SelectionRectangle0Based.Width > 0 && SelectionRectangle0Based.Height > 0)
|
|
|
|
|
{
|
|
|
|
|
LastSelectionRectangle0Based = SelectionRectangle0Based;
|
|
|
|
|
DialogResult = DialogResult.OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-09 10:32:36 +12:00
|
|
|
|
public Image GetAreaImage()
|
|
|
|
|
{
|
|
|
|
|
Rectangle rect = SelectionRectangle0Based;
|
|
|
|
|
|
|
|
|
|
if (rect.Width > 0 && rect.Height > 0)
|
|
|
|
|
{
|
|
|
|
|
if (rect.X == 0 && rect.Y == 0 && rect.Width == backgroundImage.Width && rect.Height == backgroundImage.Height)
|
|
|
|
|
{
|
|
|
|
|
return (Image)backgroundImage.Clone();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ImageHelpers.CropImage(backgroundImage, rect);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void timer_Tick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
PreviousMousePosition = CurrentMousePosition;
|
|
|
|
|
CurrentMousePosition = CaptureHelpers.GetCursorPosition();
|
|
|
|
|
SelectionRectangle = CaptureHelpers.CreateRectangle(positionOnClick.X, positionOnClick.Y, CurrentMousePosition.X, CurrentMousePosition.Y);
|
|
|
|
|
Refresh();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnPaintBackground(PaintEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
//base.OnPaintBackground(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnPaint(PaintEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Graphics g = e.Graphics;
|
|
|
|
|
g.InterpolationMode = InterpolationMode.NearestNeighbor;
|
2014-07-10 07:30:18 +12:00
|
|
|
|
g.SmoothingMode = SmoothingMode.HighQuality;
|
2014-07-09 10:32:36 +12:00
|
|
|
|
|
2015-11-13 20:30:52 +13:00
|
|
|
|
if (Mode == RegionAnnotateMode.Pen && isMouseDown)
|
2014-07-09 10:32:36 +12:00
|
|
|
|
{
|
2014-07-10 07:30:18 +12:00
|
|
|
|
using (Graphics gImage = Graphics.FromImage(backgroundImage))
|
2014-07-09 10:32:36 +12:00
|
|
|
|
{
|
2014-07-10 07:30:18 +12:00
|
|
|
|
gImage.SmoothingMode = SmoothingMode.HighQuality;
|
2015-11-13 20:30:52 +13:00
|
|
|
|
DrawLine(gImage);
|
2014-07-09 10:32:36 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-07-09 13:17:37 +12:00
|
|
|
|
|
2014-07-28 12:40:50 +12:00
|
|
|
|
g.CompositingMode = CompositingMode.SourceCopy;
|
2014-07-09 13:17:37 +12:00
|
|
|
|
g.DrawImage(backgroundImage, ScreenRectangle0Based);
|
2014-07-28 12:40:50 +12:00
|
|
|
|
g.CompositingMode = CompositingMode.SourceOver;
|
2014-07-09 13:17:37 +12:00
|
|
|
|
|
2015-11-13 14:07:25 +13:00
|
|
|
|
if (Mode == RegionAnnotateMode.Pen)
|
2014-07-09 10:32:36 +12:00
|
|
|
|
{
|
2015-11-13 20:30:52 +13:00
|
|
|
|
DrawDot(g);
|
|
|
|
|
}
|
|
|
|
|
else if (Mode == RegionAnnotateMode.Rectangle && isMouseDown)
|
|
|
|
|
{
|
|
|
|
|
g.SmoothingMode = SmoothingMode.HighSpeed;
|
|
|
|
|
DrawRectangle(g);
|
2014-07-10 08:20:47 +12:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-10 11:16:27 +12:00
|
|
|
|
if (Options.ShowTips)
|
2014-07-10 08:20:47 +12:00
|
|
|
|
{
|
|
|
|
|
DrawTips(g);
|
2014-07-09 13:17:37 +12:00
|
|
|
|
}
|
2014-07-09 10:32:36 +12:00
|
|
|
|
|
2015-11-13 14:07:25 +13:00
|
|
|
|
if (!IsDrawingMode)
|
2014-07-09 13:17:37 +12:00
|
|
|
|
{
|
2015-11-13 14:07:25 +13:00
|
|
|
|
if (Options.ShowInfo)
|
2014-07-09 10:32:36 +12:00
|
|
|
|
{
|
2015-11-13 14:07:25 +13:00
|
|
|
|
DrawInfo(g);
|
2014-07-09 10:32:36 +12:00
|
|
|
|
}
|
2014-07-09 13:17:37 +12:00
|
|
|
|
|
2015-11-13 14:07:25 +13:00
|
|
|
|
if (isMouseDown)
|
|
|
|
|
{
|
|
|
|
|
g.DrawRectangleProper(borderDotPen, SelectionRectangle0Based);
|
|
|
|
|
borderDotPen2.DashOffset = (float)penTimer.Elapsed.TotalSeconds * -10;
|
|
|
|
|
g.DrawRectangleProper(borderDotPen2, SelectionRectangle0Based);
|
|
|
|
|
}
|
2014-07-09 10:32:36 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-07-10 07:30:18 +12:00
|
|
|
|
|
2014-07-10 08:20:47 +12:00
|
|
|
|
private void DrawTips(Graphics g)
|
|
|
|
|
{
|
|
|
|
|
int offset = 10;
|
2014-07-10 15:11:30 +12:00
|
|
|
|
int padding = 3;
|
2014-07-10 12:40:41 +12:00
|
|
|
|
|
|
|
|
|
string tipText;
|
|
|
|
|
|
2015-11-13 14:07:25 +13:00
|
|
|
|
if (IsDrawingMode)
|
2014-07-10 12:40:41 +12:00
|
|
|
|
{
|
2014-10-18 00:08:33 +13:00
|
|
|
|
tipText = Resources.RectangleAnnotate_DrawTips_Drawing_mode_on;
|
2014-07-10 12:40:41 +12:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-10-18 00:08:33 +13:00
|
|
|
|
tipText = Resources.RectangleAnnotate_DrawTips_Drawing_mode_off;
|
2014-07-10 12:40:41 +12:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-10 08:20:47 +12:00
|
|
|
|
Size textSize = g.MeasureString(tipText, tipFont).ToSize();
|
|
|
|
|
int rectWidth = textSize.Width + padding * 2;
|
|
|
|
|
int rectHeight = textSize.Height + padding * 2;
|
2014-07-27 07:38:14 +12:00
|
|
|
|
Rectangle primaryScreenBounds = CaptureHelpers.GetPrimaryScreenBounds0Based();
|
2014-07-28 12:40:50 +12:00
|
|
|
|
Rectangle textRectangle = new Rectangle(primaryScreenBounds.X + (primaryScreenBounds.Width / 2) - (rectWidth / 2), primaryScreenBounds.Y + offset, rectWidth, rectHeight);
|
2014-07-10 08:20:47 +12:00
|
|
|
|
|
2014-08-28 12:53:38 +12:00
|
|
|
|
if (textRectangle.Offset(10).Contains(CurrentMousePosition0Based))
|
2014-07-10 08:20:47 +12:00
|
|
|
|
{
|
2014-07-27 07:38:14 +12:00
|
|
|
|
textRectangle.Y = primaryScreenBounds.Height - rectHeight - offset;
|
2014-07-10 08:20:47 +12:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-10 15:11:30 +12:00
|
|
|
|
using (Brush brush = new SolidBrush(Color.FromArgb(175, Color.White)))
|
|
|
|
|
using (Pen pen = new Pen(Color.FromArgb(175, Color.Black)))
|
2014-07-10 08:20:47 +12:00
|
|
|
|
{
|
2014-07-20 08:08:45 +12:00
|
|
|
|
g.DrawRoundedRectangle(brush, pen, textRectangle, 5);
|
2014-07-10 08:20:47 +12:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-10 15:11:30 +12:00
|
|
|
|
using (StringFormat sf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center })
|
|
|
|
|
{
|
|
|
|
|
g.DrawString(tipText, tipFont, Brushes.Black, textRectangle, sf);
|
|
|
|
|
}
|
2014-07-10 08:20:47 +12:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-13 14:07:25 +13:00
|
|
|
|
private void DrawInfo(Graphics g)
|
2014-07-10 08:20:47 +12:00
|
|
|
|
{
|
2015-11-13 14:07:25 +13:00
|
|
|
|
string infoText;
|
|
|
|
|
|
|
|
|
|
if (isMouseDown)
|
|
|
|
|
{
|
|
|
|
|
infoText = string.Format("X: {0} Y: {1}\r\n{2} x {3}", SelectionRectangle.X, SelectionRectangle.Y, SelectionRectangle.Width, SelectionRectangle.Height);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
infoText = string.Format("X: {0} Y: {1}", CurrentMousePosition.X, CurrentMousePosition.Y);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-10 08:20:47 +12:00
|
|
|
|
int offset = 10;
|
|
|
|
|
Point position = new Point(CurrentMousePosition0Based.X + offset, CurrentMousePosition0Based.Y + offset);
|
|
|
|
|
|
2015-11-13 14:07:25 +13:00
|
|
|
|
ImageHelpers.DrawTextWithShadow(g, infoText, position, infofont, Color.White, Color.Black);
|
2014-07-10 08:20:47 +12:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-13 20:30:52 +13:00
|
|
|
|
private void DrawLine(Graphics g)
|
2014-07-10 07:30:18 +12:00
|
|
|
|
{
|
2015-11-13 20:30:52 +13:00
|
|
|
|
if (CurrentMousePosition0Based == PreviousMousePosition0Based)
|
2014-07-10 07:30:18 +12:00
|
|
|
|
{
|
2015-11-13 20:30:52 +13:00
|
|
|
|
DrawDot(g);
|
2014-07-10 07:30:18 +12:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-11-13 20:30:52 +13:00
|
|
|
|
using (Pen pen = new Pen(Options.DrawingPenColor, Options.DrawingPenSize) { StartCap = LineCap.Round, EndCap = LineCap.Round })
|
2014-07-10 07:30:18 +12:00
|
|
|
|
{
|
|
|
|
|
g.DrawLine(pen, PreviousMousePosition0Based, CurrentMousePosition0Based);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-13 20:30:52 +13:00
|
|
|
|
private void DrawRectangle(Graphics g)
|
2014-07-10 07:30:18 +12:00
|
|
|
|
{
|
2015-11-13 20:30:52 +13:00
|
|
|
|
using (Pen pen = new Pen(Options.DrawingPenColor, Options.DrawingPenSize) { Alignment = PenAlignment.Inset })
|
2014-07-10 07:30:18 +12:00
|
|
|
|
{
|
2015-11-13 20:30:52 +13:00
|
|
|
|
g.DrawRectangleProper(pen, SelectionRectangle.Offset(Options.DrawingPenSize - 1));
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-07-10 07:30:18 +12:00
|
|
|
|
|
2015-11-13 20:30:52 +13:00
|
|
|
|
private void AddRectangle()
|
|
|
|
|
{
|
|
|
|
|
using (Graphics g = Graphics.FromImage(backgroundImage))
|
|
|
|
|
{
|
|
|
|
|
g.SmoothingMode = SmoothingMode.HighSpeed;
|
|
|
|
|
DrawRectangle(g);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DrawDot(Graphics g)
|
|
|
|
|
{
|
|
|
|
|
Point pos = CurrentMousePosition0Based;
|
|
|
|
|
|
|
|
|
|
using (Brush brush = new SolidBrush(Options.DrawingPenColor))
|
|
|
|
|
{
|
|
|
|
|
RectangleF rect = new RectangleF(pos.X - Options.DrawingPenSize / 2f, pos.Y - Options.DrawingPenSize / 2f, Options.DrawingPenSize, Options.DrawingPenSize);
|
|
|
|
|
g.FillEllipse(brush, rect);
|
2014-07-10 07:30:18 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-07-09 10:32:36 +12:00
|
|
|
|
}
|
2014-07-27 07:38:14 +12:00
|
|
|
|
}
|