Added OneClickMode to rectangle region to be able to get handle of selected control

This commit is contained in:
Jaex 2015-09-25 09:39:08 +03:00
parent 918e254673
commit 2e59b2ee83
11 changed files with 348 additions and 25 deletions

View File

@ -0,0 +1,20 @@
This license governs use of the accompanying software. If you use the software, you
accept this license. If you do not accept the license, do not use the software.
1. Definitions
The terms "reproduce," "reproduction," "derivative works," and "distribution" have the
same meaning here as under U.S. copyright law.
A "contribution" is the original software, or any additions or changes to the software.
A "contributor" is any person that distributes its contribution under this license.
"Licensed patents" are a contributor's patent claims that read directly on its contribution.
2. Grant of Rights
(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
3. Conditions and Limitations
(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically.
(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software.
(D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license.
(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.

View File

@ -68,6 +68,9 @@ namespace ShareX.ScreenCaptureLib
#endregion Screen ruler
public bool OneClickMode { get; set; }
public SimpleWindowInfo SelectedWindow { get; set; }
private ColorBlinkAnimation colorBlinkAnimation = new ColorBlinkAnimation();
public RectangleRegion()
@ -81,9 +84,15 @@ namespace ShareX.ScreenCaptureLib
private void RectangleRegion_MouseDown(object sender, MouseEventArgs e)
{
if (ScreenColorPickerMode && e.Button == MouseButtons.Left)
if ((OneClickMode || ScreenColorPickerMode) && e.Button == MouseButtons.Left)
{
CurrentPosition = InputManager.MousePosition;
if (OneClickMode)
{
SelectedWindow = AreaManager.FindSelectedWindow();
}
Close(SurfaceResult.Region);
}
}
@ -162,7 +171,7 @@ namespace ShareX.ScreenCaptureLib
AreaManager.WindowCaptureMode |= Config.ForceWindowCapture;
AreaManager.IncludeControls |= Config.IncludeControls;
if (AreaManager.WindowCaptureMode)
if (OneClickMode || AreaManager.WindowCaptureMode)
{
IntPtr handle = Handle;

View File

@ -0,0 +1,59 @@
namespace ShareX.ScreenCaptureLib
{
partial class ScrollingCaptureForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnSelectHandle = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// btnSelectHandle
//
this.btnSelectHandle.Location = new System.Drawing.Point(8, 8);
this.btnSelectHandle.Name = "btnSelectHandle";
this.btnSelectHandle.Size = new System.Drawing.Size(304, 23);
this.btnSelectHandle.TabIndex = 0;
this.btnSelectHandle.Text = "Select window or control to scroll";
this.btnSelectHandle.UseVisualStyleBackColor = true;
//
// ScrollingCaptureForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(567, 427);
this.Controls.Add(this.btnSelectHandle);
this.Name = "ScrollingCaptureForm";
this.Text = "ScrollingCaptureForm";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button btnSelectHandle;
}
}

View File

@ -0,0 +1,45 @@
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
Copyright (c) 2007-2015 ShareX Team
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)
using ShareX.HelpersLib;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ShareX.ScreenCaptureLib
{
public partial class ScrollingCaptureForm : BaseForm
{
public ScrollingCaptureForm()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -119,7 +119,7 @@ namespace ShareX.ScreenCaptureLib
public bool IsProportionalResizing { get; private set; }
public bool IsSnapResizing { get; private set; }
public List<Rectangle> Windows { get; set; }
public List<SimpleWindowInfo> Windows { get; set; }
public bool WindowCaptureMode { get; set; }
public bool IncludeControls { get; set; }
public int MinimumSize { get; set; }
@ -319,19 +319,29 @@ namespace ShareX.ScreenCaptureLib
{
CurrentHoverArea = hoverArea;
}
else if (WindowCaptureMode && Windows != null)
else
{
hoverArea = Windows.FirstOrDefault(x => x.Contains(InputManager.MousePosition));
SimpleWindowInfo window = FindSelectedWindow();
if (!hoverArea.IsEmpty)
if (window != null && !window.Rectangle.IsEmpty)
{
hoverArea = CaptureHelpers.ScreenToClient(hoverArea);
hoverArea = CaptureHelpers.ScreenToClient(window.Rectangle);
CurrentHoverArea = Rectangle.Intersect(surface.ScreenRectangle0Based, hoverArea);
}
}
}
}
public SimpleWindowInfo FindSelectedWindow()
{
if (Windows != null)
{
return Windows.FirstOrDefault(x => x.Rectangle.Contains(InputManager.MousePosition));
}
return null;
}
private void surface_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)

View File

@ -66,6 +66,12 @@
<Compile Include="Forms\RectangleTransparent.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\ScrollingCaptureForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\ScrollingCaptureForm.Designer.cs">
<DependentUpon>ScrollingCaptureForm.cs</DependentUpon>
</Compile>
<Compile Include="MonitorRegion.cs" />
<Compile Include="MonitorRegionDefaultCreator.cs" />
<Compile Include="RectangleAnnotateOptions.cs" />
@ -109,6 +115,7 @@
<Compile Include="RegionHelpers\NodeObject.cs" />
<Compile Include="RegionHelpers\ResizeManager.cs" />
<Compile Include="RegionHelpers\ShapeCaptureHelpers.cs" />
<Compile Include="SimpleWindowInfo.cs" />
<Compile Include="SnapSize.cs" />
<Compile Include="SurfaceOptions.cs" />
<Compile Include="Screencast\ScreenRecorder.cs" />
@ -131,6 +138,9 @@
<Content Include="Resources\Crosshair.cur" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Forms\ScrollingCaptureForm.resx">
<DependentUpon>ScrollingCaptureForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.de.resx">
<SubType>Designer</SubType>
</EmbeddedResource>

View File

@ -0,0 +1,50 @@
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
Copyright (c) 2007-2015 ShareX Team
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)
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
namespace ShareX.ScreenCaptureLib
{
public class SimpleWindowInfo
{
public IntPtr Handle { get; set; }
public Rectangle Rectangle { get; set; }
public SimpleWindowInfo(IntPtr handle)
{
Handle = handle;
}
public SimpleWindowInfo(IntPtr handle, Rectangle rect)
{
Handle = handle;
Rectangle = rect;
}
}
}

View File

@ -35,23 +35,23 @@ namespace ShareX.ScreenCaptureLib
public IntPtr IgnoreHandle { get; set; }
public bool IncludeChildWindows { get; set; }
private List<Rectangle> rectangles;
private List<SimpleWindowInfo> windows;
public List<Rectangle> GetWindowsRectangleList()
public List<SimpleWindowInfo> GetWindowsRectangleList()
{
rectangles = new List<Rectangle>();
windows = new List<SimpleWindowInfo>();
NativeMethods.EnumWindowsProc ewp = EvalWindow;
NativeMethods.EnumWindows(ewp, IntPtr.Zero);
List<Rectangle> result = new List<Rectangle>();
List<SimpleWindowInfo> result = new List<SimpleWindowInfo>();
foreach (Rectangle rect in rectangles)
foreach (SimpleWindowInfo window in windows)
{
bool rectVisible = true;
foreach (Rectangle rect2 in result)
foreach (SimpleWindowInfo window2 in result)
{
if (rect2.Contains(rect))
if (window2.Rectangle.Contains(window.Rectangle))
{
rectVisible = false;
break;
@ -60,7 +60,7 @@ namespace ShareX.ScreenCaptureLib
if (rectVisible)
{
result.Add(rect);
result.Add(window);
}
}
@ -84,18 +84,18 @@ namespace ShareX.ScreenCaptureLib
return true;
}
Rectangle rect;
SimpleWindowInfo windowInfo = new SimpleWindowInfo(handle);
if (isWindow)
{
rect = CaptureHelpers.GetWindowRectangle(handle);
windowInfo.Rectangle = CaptureHelpers.GetWindowRectangle(handle);
}
else
{
rect = NativeMethods.GetWindowRect(handle);
windowInfo.Rectangle = NativeMethods.GetWindowRect(handle);
}
if (!rect.IsValid())
if (!windowInfo.Rectangle.IsValid())
{
return true;
}
@ -112,11 +112,11 @@ namespace ShareX.ScreenCaptureLib
if (clientRect.IsValid())
{
rectangles.Add(clientRect);
windows.Add(new SimpleWindowInfo(handle, clientRect));
}
}
rectangles.Add(rect);
windows.Add(windowInfo);
return true;
}

View File

@ -352,7 +352,7 @@
<value>191, 22</value>
</data>
<data name="tsmiWindowRectangle.Text" xml:space="preserve">
<value>Region (Objects)</value>
<value>Region (Windows &amp; controls)</value>
</data>
<data name="tsmiRectangleAnnotate.Size" type="System.Drawing.Size, System.Drawing">
<value>191, 22</value>
@ -1159,7 +1159,7 @@
<value>191, 22</value>
</data>
<data name="tsmiTrayWindowRectangle.Text" xml:space="preserve">
<value>Region (Objects)</value>
<value>Region (Windows &amp; controls)</value>
</data>
<data name="tsmiTrayRectangleAnnotate.Size" type="System.Drawing.Size, System.Drawing">
<value>191, 22</value>

View File

@ -151,7 +151,7 @@
<value>Bölge</value>
</data>
<data name="tsmiWindowRectangle.Text" xml:space="preserve">
<value>Bölge (Objeler)</value>
<value>Bölge (Pencereler ve kontroller)</value>
</data>
<data name="tsmiRectangleAnnotate.Text" xml:space="preserve">
<value>Bölge (Dipnot)</value>
@ -445,7 +445,7 @@
<value>Bölge</value>
</data>
<data name="tsmiTrayWindowRectangle.Text" xml:space="preserve">
<value>Bölge (Objeler)</value>
<value>Bölge (Pencereler ve kontroller)</value>
</data>
<data name="tsmiTrayRectangleAnnotate.Text" xml:space="preserve">
<value>Bölge (Dipnot)</value>