2013-11-03 23:53:49 +13:00
|
|
|
|
#region License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
2016-01-04 04:16:01 +13:00
|
|
|
|
Copyright (c) 2007-2016 ShareX Team
|
2013-11-03 23:53:49 +13: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;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Drawing.Drawing2D;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2014-12-11 09:25:20 +13:00
|
|
|
|
namespace ShareX.ScreenCaptureLib
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-05-15 19:12:53 +12:00
|
|
|
|
public abstract class BaseRegionForm : Form
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-05-15 18:49:24 +12:00
|
|
|
|
public static GraphicsPath LastRegionFillPath { get; protected set; }
|
|
|
|
|
|
2016-06-22 19:51:57 +12:00
|
|
|
|
public RegionCaptureOptions Config { get; set; }
|
2013-11-03 23:53:49 +13:00
|
|
|
|
public int FPS { get; private set; }
|
|
|
|
|
public Rectangle ScreenRectangle { get; private set; }
|
|
|
|
|
public Rectangle ScreenRectangle0Based { get; private set; }
|
2016-05-15 19:12:53 +12:00
|
|
|
|
public RegionResult Result { get; private set; }
|
2016-05-04 21:32:09 +12:00
|
|
|
|
public int MonitorIndex { get; set; }
|
2016-08-17 20:35:06 +12:00
|
|
|
|
|
|
|
|
|
internal List<DrawableObject> DrawableObjects { get; private set; }
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2016-05-15 18:49:24 +12:00
|
|
|
|
protected Image backgroundImage;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
protected TextureBrush darkBackgroundBrush, lightBackgroundBrush;
|
|
|
|
|
protected GraphicsPath regionFillPath, regionDrawPath;
|
2015-08-23 01:13:38 +12:00
|
|
|
|
protected Pen borderPen, borderDotPen, textBackgroundPenWhite, textBackgroundPenBlack, markerPen;
|
2015-05-08 11:31:08 +12:00
|
|
|
|
protected Brush nodeBackgroundBrush, textBackgroundBrush;
|
2016-05-09 07:23:47 +12:00
|
|
|
|
protected Font infoFont, infoFontMedium, infoFontBig;
|
2015-05-17 14:32:02 +12:00
|
|
|
|
protected Stopwatch timerStart, timerFPS;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
protected int frameCount;
|
2016-05-15 18:49:24 +12:00
|
|
|
|
protected bool pause, isKeyAllowed;
|
2016-05-04 02:29:37 +12:00
|
|
|
|
|
2016-05-15 19:12:53 +12:00
|
|
|
|
public BaseRegionForm()
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
ScreenRectangle = CaptureHelpers.GetScreenBounds();
|
|
|
|
|
ScreenRectangle0Based = CaptureHelpers.ScreenToClient(ScreenRectangle);
|
|
|
|
|
|
|
|
|
|
InitializeComponent();
|
2016-02-26 09:55:54 +13:00
|
|
|
|
Icon = ShareXResources.Icon;
|
2016-07-04 22:27:31 +12:00
|
|
|
|
Cursor = Helpers.CreateCursor(Resources.Crosshair);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2016-08-17 18:35:38 +12:00
|
|
|
|
DrawableObjects = new List<DrawableObject>();
|
2016-06-22 19:51:57 +12:00
|
|
|
|
Config = new RegionCaptureOptions();
|
2015-05-17 14:32:02 +12:00
|
|
|
|
timerStart = new Stopwatch();
|
|
|
|
|
timerFPS = new Stopwatch();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
|
|
|
|
borderPen = new Pen(Color.Black);
|
2014-07-25 17:54:24 +12:00
|
|
|
|
borderDotPen = new Pen(Color.White);
|
|
|
|
|
borderDotPen.DashPattern = new float[] { 5, 5 };
|
2013-11-03 23:53:49 +13:00
|
|
|
|
nodeBackgroundBrush = new SolidBrush(Color.White);
|
2015-05-08 11:31:08 +12:00
|
|
|
|
infoFont = new Font("Verdana", 9);
|
2016-05-09 07:23:47 +12:00
|
|
|
|
infoFontMedium = new Font("Verdana", 12);
|
|
|
|
|
infoFontBig = new Font("Verdana", 16, FontStyle.Bold);
|
2015-05-08 11:31:08 +12:00
|
|
|
|
textBackgroundBrush = new SolidBrush(Color.FromArgb(75, Color.Black));
|
|
|
|
|
textBackgroundPenWhite = new Pen(Color.FromArgb(50, Color.White));
|
|
|
|
|
textBackgroundPenBlack = new Pen(Color.FromArgb(150, Color.Black));
|
2016-06-11 22:54:19 +12:00
|
|
|
|
markerPen = new Pen(Color.FromArgb(200, Color.Red));
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitializeComponent()
|
|
|
|
|
{
|
2016-05-08 08:31:43 +12:00
|
|
|
|
components = new Container();
|
|
|
|
|
|
2013-11-03 23:53:49 +13:00
|
|
|
|
SuspendLayout();
|
|
|
|
|
AutoScaleDimensions = new SizeF(6F, 13F);
|
|
|
|
|
AutoScaleMode = AutoScaleMode.Font;
|
|
|
|
|
StartPosition = FormStartPosition.Manual;
|
|
|
|
|
FormBorderStyle = FormBorderStyle.None;
|
2015-09-11 12:45:40 +12:00
|
|
|
|
Bounds = ScreenRectangle;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
|
2016-06-22 22:15:50 +12:00
|
|
|
|
Text = "ShareX - " + Resources.BaseRegionForm_InitializeComponent_Region_capture;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
ShowInTaskbar = false;
|
2016-05-06 05:03:57 +12:00
|
|
|
|
#if !DEBUG
|
2013-11-03 23:53:49 +13:00
|
|
|
|
TopMost = true;
|
2016-05-06 05:03:57 +12:00
|
|
|
|
#endif
|
2016-05-15 19:12:53 +12:00
|
|
|
|
Shown += BaseRegionForm_Shown;
|
|
|
|
|
KeyUp += BaseRegionForm_KeyUp;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
ResumeLayout(false);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-22 02:23:45 +12:00
|
|
|
|
public void Prepare()
|
|
|
|
|
{
|
|
|
|
|
Prepare(new Screenshot());
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-17 18:35:38 +12:00
|
|
|
|
// Must be called before show form
|
2016-07-22 02:23:45 +12:00
|
|
|
|
public virtual void Prepare(Screenshot screenshot)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-07-22 02:23:45 +12:00
|
|
|
|
backgroundImage = screenshot.CaptureFullscreen();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2014-11-18 01:55:20 +13:00
|
|
|
|
if (Config.UseDimming)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-05-15 18:49:24 +12:00
|
|
|
|
using (Bitmap darkBackground = (Bitmap)backgroundImage.Clone())
|
2015-05-11 02:44:48 +12:00
|
|
|
|
using (Graphics g = Graphics.FromImage(darkBackground))
|
|
|
|
|
{
|
2016-05-10 07:41:04 +12:00
|
|
|
|
using (Brush brush = new SolidBrush(Color.FromArgb(30, Color.Black)))
|
2015-05-11 02:44:48 +12:00
|
|
|
|
{
|
|
|
|
|
g.FillRectangle(brush, 0, 0, darkBackground.Width, darkBackground.Height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
darkBackgroundBrush = new TextureBrush(darkBackground) { WrapMode = WrapMode.Clamp };
|
2016-05-15 18:49:24 +12:00
|
|
|
|
lightBackgroundBrush = new TextureBrush(backgroundImage) { WrapMode = WrapMode.Clamp };
|
2015-05-11 02:44:48 +12:00
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
2014-11-18 01:55:20 +13:00
|
|
|
|
else
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-05-15 18:49:24 +12:00
|
|
|
|
darkBackgroundBrush = new TextureBrush(backgroundImage) { WrapMode = WrapMode.Clamp };
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-15 19:12:53 +12:00
|
|
|
|
private void BaseRegionForm_Shown(object sender, EventArgs e)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-03-10 05:37:54 +13:00
|
|
|
|
this.ForceActivate();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-15 19:12:53 +12:00
|
|
|
|
private void BaseRegionForm_KeyUp(object sender, KeyEventArgs e)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-08-26 01:32:45 +12:00
|
|
|
|
if (e.KeyData == Keys.Escape)
|
|
|
|
|
{
|
|
|
|
|
Close(RegionResult.Close);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-17 14:32:02 +12:00
|
|
|
|
if (!isKeyAllowed && timerStart.ElapsedMilliseconds < 1000)
|
2015-05-06 09:33:19 +12:00
|
|
|
|
{
|
2015-05-07 01:56:42 +12:00
|
|
|
|
return;
|
|
|
|
|
}
|
2015-05-06 09:33:19 +12:00
|
|
|
|
|
2015-05-17 14:32:02 +12:00
|
|
|
|
isKeyAllowed = true;
|
|
|
|
|
|
|
|
|
|
if (e.KeyData >= Keys.D0 && e.KeyData <= Keys.D9)
|
2015-05-07 01:56:42 +12:00
|
|
|
|
{
|
2015-05-17 14:32:02 +12:00
|
|
|
|
MonitorKey(e.KeyData - Keys.D0);
|
2015-05-06 09:33:19 +12:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-17 14:32:02 +12:00
|
|
|
|
switch (e.KeyData)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-05-05 00:35:34 +12:00
|
|
|
|
case Keys.Space:
|
2016-05-15 19:12:53 +12:00
|
|
|
|
Close(RegionResult.Fullscreen);
|
2016-05-05 00:35:34 +12:00
|
|
|
|
break;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
case Keys.Enter:
|
2016-05-15 19:12:53 +12:00
|
|
|
|
Close(RegionResult.Region);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
break;
|
2015-05-07 04:42:13 +12:00
|
|
|
|
case Keys.Oemtilde:
|
2016-05-15 19:12:53 +12:00
|
|
|
|
Close(RegionResult.ActiveMonitor);
|
2015-05-07 04:42:13 +12:00
|
|
|
|
break;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-07 01:56:42 +12:00
|
|
|
|
private void MonitorKey(int index)
|
|
|
|
|
{
|
|
|
|
|
if (index == 0)
|
|
|
|
|
{
|
|
|
|
|
index = 10;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
index--;
|
|
|
|
|
|
|
|
|
|
MonitorIndex = index;
|
|
|
|
|
|
2016-05-15 19:12:53 +12:00
|
|
|
|
Close(RegionResult.Monitor);
|
2015-05-07 01:56:42 +12:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-04 02:29:37 +12:00
|
|
|
|
public void Pause()
|
|
|
|
|
{
|
|
|
|
|
pause = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Resume()
|
|
|
|
|
{
|
|
|
|
|
pause = false;
|
2016-08-17 18:35:38 +12:00
|
|
|
|
|
2016-05-04 02:29:37 +12:00
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-03 23:53:49 +13:00
|
|
|
|
protected override void OnPaintBackground(PaintEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
//base.OnPaintBackground(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnPaint(PaintEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Update();
|
|
|
|
|
|
|
|
|
|
Graphics g = e.Graphics;
|
2014-07-28 12:40:50 +12:00
|
|
|
|
g.CompositingMode = CompositingMode.SourceCopy;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
g.FillRectangle(darkBackgroundBrush, ScreenRectangle0Based);
|
2014-07-28 12:40:50 +12:00
|
|
|
|
g.CompositingMode = CompositingMode.SourceOver;
|
2014-07-25 17:54:24 +12:00
|
|
|
|
|
2013-11-03 23:53:49 +13:00
|
|
|
|
Draw(g);
|
|
|
|
|
|
|
|
|
|
if (Config.ShowFPS)
|
|
|
|
|
{
|
|
|
|
|
CheckFPS();
|
2016-05-09 07:23:47 +12:00
|
|
|
|
DrawFPS(g);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-04 02:29:37 +12:00
|
|
|
|
if (!pause)
|
|
|
|
|
{
|
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-03 23:54:02 +12:00
|
|
|
|
public virtual Image GetResultImage()
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-05-15 19:12:53 +12:00
|
|
|
|
if (Result == RegionResult.Region)
|
2016-05-09 06:32:53 +12:00
|
|
|
|
{
|
|
|
|
|
using (Image img = GetOutputImage())
|
|
|
|
|
{
|
2016-08-02 20:29:17 +12:00
|
|
|
|
return RegionCaptureHelpers.ApplyRegionPathToImage(img, regionFillPath);
|
2016-05-09 06:32:53 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-05-15 19:12:53 +12:00
|
|
|
|
else if (Result == RegionResult.Fullscreen)
|
2016-05-09 06:32:53 +12:00
|
|
|
|
{
|
|
|
|
|
return GetOutputImage();
|
|
|
|
|
}
|
2016-05-15 19:12:53 +12:00
|
|
|
|
else if (Result == RegionResult.Monitor)
|
2016-05-09 06:32:53 +12:00
|
|
|
|
{
|
|
|
|
|
Screen[] screens = Screen.AllScreens;
|
|
|
|
|
|
|
|
|
|
if (MonitorIndex < screens.Length)
|
|
|
|
|
{
|
|
|
|
|
Screen screen = screens[MonitorIndex];
|
|
|
|
|
Rectangle screenRect = CaptureHelpers.ScreenToClient(screen.Bounds);
|
|
|
|
|
|
|
|
|
|
using (Image img = GetOutputImage())
|
|
|
|
|
{
|
|
|
|
|
return ImageHelpers.CropImage(img, screenRect);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-05-15 19:12:53 +12:00
|
|
|
|
else if (Result == RegionResult.ActiveMonitor)
|
2016-05-09 06:32:53 +12:00
|
|
|
|
{
|
|
|
|
|
Rectangle activeScreenRect = CaptureHelpers.GetActiveScreenBounds0Based();
|
|
|
|
|
|
|
|
|
|
using (Image img = GetOutputImage())
|
|
|
|
|
{
|
|
|
|
|
return ImageHelpers.CropImage(img, activeScreenRect);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual Image GetOutputImage()
|
|
|
|
|
{
|
2016-05-15 18:49:24 +12:00
|
|
|
|
return (Image)backgroundImage.Clone();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-18 01:00:20 +13:00
|
|
|
|
public virtual WindowInfo GetWindowInfo()
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-15 19:12:53 +12:00
|
|
|
|
public void Close(RegionResult result)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
Result = result;
|
2016-08-17 18:35:38 +12:00
|
|
|
|
|
2013-11-03 23:53:49 +13:00
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected new virtual void Update()
|
|
|
|
|
{
|
2015-05-17 14:32:02 +12:00
|
|
|
|
if (!timerStart.IsRunning)
|
|
|
|
|
{
|
|
|
|
|
timerStart.Start();
|
|
|
|
|
timerFPS.Start();
|
|
|
|
|
}
|
2014-07-28 12:40:50 +12:00
|
|
|
|
|
2013-11-03 23:53:49 +13:00
|
|
|
|
InputManager.Update();
|
|
|
|
|
|
2016-08-17 18:35:38 +12:00
|
|
|
|
DrawableObject[] objects = DrawableObjects.OrderByDescending(x => x.Order).ToArray();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2016-05-06 10:52:16 +12:00
|
|
|
|
if (objects.All(x => !x.IsDragging))
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < objects.Count(); i++)
|
|
|
|
|
{
|
|
|
|
|
DrawableObject obj = objects[i];
|
|
|
|
|
|
2016-05-06 10:52:16 +12:00
|
|
|
|
if (obj.Visible)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-05-25 05:31:40 +12:00
|
|
|
|
obj.IsCursorHover = obj.Rectangle.Contains(InputManager.MousePosition0Based);
|
2016-05-06 10:52:16 +12:00
|
|
|
|
|
2016-05-25 05:31:40 +12:00
|
|
|
|
if (obj.IsCursorHover)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-05-06 10:52:16 +12:00
|
|
|
|
if (InputManager.IsMousePressed(MouseButtons.Left))
|
|
|
|
|
{
|
|
|
|
|
obj.IsDragging = true;
|
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2016-05-06 10:52:16 +12:00
|
|
|
|
for (int y = i + 1; y < objects.Count(); y++)
|
|
|
|
|
{
|
2016-05-25 05:31:40 +12:00
|
|
|
|
objects[y].IsCursorHover = false;
|
2016-05-06 10:52:16 +12:00
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2016-05-06 10:52:16 +12:00
|
|
|
|
break;
|
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (InputManager.IsMouseReleased(MouseButtons.Left))
|
|
|
|
|
{
|
|
|
|
|
foreach (DrawableObject obj in objects)
|
|
|
|
|
{
|
|
|
|
|
obj.IsDragging = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-07-28 12:40:50 +12:00
|
|
|
|
|
2015-11-29 02:58:58 +13:00
|
|
|
|
borderDotPen.DashOffset = (float)timerStart.Elapsed.TotalSeconds * -15;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual void Draw(Graphics g)
|
|
|
|
|
{
|
|
|
|
|
DrawObjects(g);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void DrawObjects(Graphics g)
|
|
|
|
|
{
|
2016-08-17 18:35:38 +12:00
|
|
|
|
foreach (DrawableObject drawObject in DrawableObjects)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
if (drawObject.Visible)
|
|
|
|
|
{
|
|
|
|
|
drawObject.Draw(g);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CheckFPS()
|
|
|
|
|
{
|
|
|
|
|
frameCount++;
|
|
|
|
|
|
2015-05-17 14:32:02 +12:00
|
|
|
|
if (timerFPS.ElapsedMilliseconds >= 1000)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2015-05-17 14:32:02 +12:00
|
|
|
|
FPS = (int)(frameCount / timerFPS.Elapsed.TotalSeconds);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
frameCount = 0;
|
2015-05-17 14:32:02 +12:00
|
|
|
|
timerFPS.Reset();
|
|
|
|
|
timerFPS.Start();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-09 07:23:47 +12:00
|
|
|
|
private void DrawFPS(Graphics g)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
string text = "FPS: " + FPS;
|
|
|
|
|
|
2016-05-09 07:23:47 +12:00
|
|
|
|
SizeF textSize = g.MeasureString(text, infoFontBig);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2016-05-09 07:23:47 +12:00
|
|
|
|
int offset = 10;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2014-07-28 12:40:50 +12:00
|
|
|
|
Rectangle primaryScreenBounds = CaptureHelpers.GetPrimaryScreenBounds0Based();
|
|
|
|
|
Rectangle textRectangle = new Rectangle(primaryScreenBounds.X + offset, primaryScreenBounds.Y + offset, (int)textSize.Width, (int)textSize.Height);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2014-08-28 12:53:38 +12:00
|
|
|
|
if (textRectangle.Offset(10).Contains(InputManager.MousePosition0Based))
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2014-07-28 12:40:50 +12:00
|
|
|
|
textRectangle.Y = primaryScreenBounds.Height - textRectangle.Height - offset;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-09 07:23:47 +12:00
|
|
|
|
ImageHelpers.DrawTextWithOutline(g, text, textRectangle.Location, infoFontBig, Color.White, Color.Black);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-08 08:31:43 +12:00
|
|
|
|
public IContainer components = null;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
if (disposing && (components != null))
|
|
|
|
|
{
|
|
|
|
|
components.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (darkBackgroundBrush != null) darkBackgroundBrush.Dispose();
|
|
|
|
|
if (lightBackgroundBrush != null) lightBackgroundBrush.Dispose();
|
|
|
|
|
if (borderPen != null) borderPen.Dispose();
|
|
|
|
|
if (borderDotPen != null) borderDotPen.Dispose();
|
|
|
|
|
if (nodeBackgroundBrush != null) nodeBackgroundBrush.Dispose();
|
2015-05-08 11:31:08 +12:00
|
|
|
|
if (infoFont != null) infoFont.Dispose();
|
2016-05-09 07:23:47 +12:00
|
|
|
|
if (infoFontMedium != null) infoFontMedium.Dispose();
|
|
|
|
|
if (infoFontBig != null) infoFontBig.Dispose();
|
2015-05-08 11:31:08 +12:00
|
|
|
|
if (textBackgroundBrush != null) textBackgroundBrush.Dispose();
|
|
|
|
|
if (textBackgroundPenWhite != null) textBackgroundPenWhite.Dispose();
|
|
|
|
|
if (textBackgroundPenBlack != null) textBackgroundPenBlack.Dispose();
|
2015-08-23 01:13:38 +12:00
|
|
|
|
if (markerPen != null) markerPen.Dispose();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
|
|
|
|
if (regionFillPath != null)
|
|
|
|
|
{
|
|
|
|
|
if (LastRegionFillPath != null) LastRegionFillPath.Dispose();
|
|
|
|
|
LastRegionFillPath = regionFillPath;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (regionFillPath != null) regionFillPath.Dispose();
|
|
|
|
|
if (regionDrawPath != null) regionDrawPath.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-15 18:49:24 +12:00
|
|
|
|
if (backgroundImage != null) backgroundImage.Dispose();
|
|
|
|
|
|
2013-11-03 23:53:49 +13:00
|
|
|
|
base.Dispose(disposing);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|