From 2e59b2ee835151a53de9aff09e98a0e14d5dbb7e Mon Sep 17 00:00:00 2001 From: Jaex Date: Fri, 25 Sep 2015 09:39:08 +0300 Subject: [PATCH] Added OneClickMode to rectangle region to be able to get handle of selected control --- Licenses/DirectShow_devices_license.txt | 20 +++ .../Forms/RectangleRegion.cs | 13 +- .../Forms/ScrollingCaptureForm.Designer.cs | 59 +++++++++ .../Forms/ScrollingCaptureForm.cs | 45 +++++++ .../Forms/ScrollingCaptureForm.resx | 120 ++++++++++++++++++ .../RegionHelpers/AreaManager.cs | 20 ++- .../ShareX.ScreenCaptureLib.csproj | 10 ++ ShareX.ScreenCaptureLib/SimpleWindowInfo.cs | 50 ++++++++ .../WindowsRectangleList.cs | 28 ++-- ShareX/Forms/MainForm.resx | 4 +- ShareX/Forms/MainForm.tr.resx | 4 +- 11 files changed, 348 insertions(+), 25 deletions(-) create mode 100644 Licenses/DirectShow_devices_license.txt create mode 100644 ShareX.ScreenCaptureLib/Forms/ScrollingCaptureForm.Designer.cs create mode 100644 ShareX.ScreenCaptureLib/Forms/ScrollingCaptureForm.cs create mode 100644 ShareX.ScreenCaptureLib/Forms/ScrollingCaptureForm.resx create mode 100644 ShareX.ScreenCaptureLib/SimpleWindowInfo.cs diff --git a/Licenses/DirectShow_devices_license.txt b/Licenses/DirectShow_devices_license.txt new file mode 100644 index 000000000..3f0434f36 --- /dev/null +++ b/Licenses/DirectShow_devices_license.txt @@ -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. \ No newline at end of file diff --git a/ShareX.ScreenCaptureLib/Forms/RectangleRegion.cs b/ShareX.ScreenCaptureLib/Forms/RectangleRegion.cs index ba232b5d3..912657f5f 100644 --- a/ShareX.ScreenCaptureLib/Forms/RectangleRegion.cs +++ b/ShareX.ScreenCaptureLib/Forms/RectangleRegion.cs @@ -68,6 +68,9 @@ public Color CurrentColor #endregion Screen ruler + public bool OneClickMode { get; set; } + public SimpleWindowInfo SelectedWindow { get; set; } + private ColorBlinkAnimation colorBlinkAnimation = new ColorBlinkAnimation(); public RectangleRegion() @@ -81,9 +84,15 @@ public RectangleRegion() 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 @@ public override void Prepare() AreaManager.WindowCaptureMode |= Config.ForceWindowCapture; AreaManager.IncludeControls |= Config.IncludeControls; - if (AreaManager.WindowCaptureMode) + if (OneClickMode || AreaManager.WindowCaptureMode) { IntPtr handle = Handle; diff --git a/ShareX.ScreenCaptureLib/Forms/ScrollingCaptureForm.Designer.cs b/ShareX.ScreenCaptureLib/Forms/ScrollingCaptureForm.Designer.cs new file mode 100644 index 000000000..3a97e8678 --- /dev/null +++ b/ShareX.ScreenCaptureLib/Forms/ScrollingCaptureForm.Designer.cs @@ -0,0 +1,59 @@ +namespace ShareX.ScreenCaptureLib +{ + partial class ScrollingCaptureForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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; + } +} \ No newline at end of file diff --git a/ShareX.ScreenCaptureLib/Forms/ScrollingCaptureForm.cs b/ShareX.ScreenCaptureLib/Forms/ScrollingCaptureForm.cs new file mode 100644 index 000000000..96af4e7df --- /dev/null +++ b/ShareX.ScreenCaptureLib/Forms/ScrollingCaptureForm.cs @@ -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 . +*/ + +#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(); + } + } +} \ No newline at end of file diff --git a/ShareX.ScreenCaptureLib/Forms/ScrollingCaptureForm.resx b/ShareX.ScreenCaptureLib/Forms/ScrollingCaptureForm.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/ShareX.ScreenCaptureLib/Forms/ScrollingCaptureForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ShareX.ScreenCaptureLib/RegionHelpers/AreaManager.cs b/ShareX.ScreenCaptureLib/RegionHelpers/AreaManager.cs index 889c9b9eb..38281710a 100644 --- a/ShareX.ScreenCaptureLib/RegionHelpers/AreaManager.cs +++ b/ShareX.ScreenCaptureLib/RegionHelpers/AreaManager.cs @@ -119,7 +119,7 @@ public bool IsResizing public bool IsProportionalResizing { get; private set; } public bool IsSnapResizing { get; private set; } - public List Windows { get; set; } + public List Windows { get; set; } public bool WindowCaptureMode { get; set; } public bool IncludeControls { get; set; } public int MinimumSize { get; set; } @@ -319,19 +319,29 @@ private void CheckHover() { 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) diff --git a/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj b/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj index 5f1ae6825..761675736 100644 --- a/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj +++ b/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj @@ -66,6 +66,12 @@ Form + + Form + + + ScrollingCaptureForm.cs + @@ -109,6 +115,7 @@ + @@ -131,6 +138,9 @@ + + ScrollingCaptureForm.cs + Designer diff --git a/ShareX.ScreenCaptureLib/SimpleWindowInfo.cs b/ShareX.ScreenCaptureLib/SimpleWindowInfo.cs new file mode 100644 index 000000000..558e92b08 --- /dev/null +++ b/ShareX.ScreenCaptureLib/SimpleWindowInfo.cs @@ -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 . +*/ + +#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; + } + } +} \ No newline at end of file diff --git a/ShareX.ScreenCaptureLib/WindowsRectangleList.cs b/ShareX.ScreenCaptureLib/WindowsRectangleList.cs index 86967b358..669b49843 100644 --- a/ShareX.ScreenCaptureLib/WindowsRectangleList.cs +++ b/ShareX.ScreenCaptureLib/WindowsRectangleList.cs @@ -35,23 +35,23 @@ public class WindowsRectangleList public IntPtr IgnoreHandle { get; set; } public bool IncludeChildWindows { get; set; } - private List rectangles; + private List windows; - public List GetWindowsRectangleList() + public List GetWindowsRectangleList() { - rectangles = new List(); + windows = new List(); NativeMethods.EnumWindowsProc ewp = EvalWindow; NativeMethods.EnumWindows(ewp, IntPtr.Zero); - List result = new List(); + List result = new List(); - 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 @@ public List GetWindowsRectangleList() if (rectVisible) { - result.Add(rect); + result.Add(window); } } @@ -84,18 +84,18 @@ private bool CheckHandle(IntPtr handle, bool isWindow) 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 @@ private bool CheckHandle(IntPtr handle, bool isWindow) if (clientRect.IsValid()) { - rectangles.Add(clientRect); + windows.Add(new SimpleWindowInfo(handle, clientRect)); } } - rectangles.Add(rect); + windows.Add(windowInfo); return true; } diff --git a/ShareX/Forms/MainForm.resx b/ShareX/Forms/MainForm.resx index 2baace343..4ecde9970 100644 --- a/ShareX/Forms/MainForm.resx +++ b/ShareX/Forms/MainForm.resx @@ -352,7 +352,7 @@ 191, 22 - Region (Objects) + Region (Windows & controls) 191, 22 @@ -1159,7 +1159,7 @@ 191, 22 - Region (Objects) + Region (Windows & controls) 191, 22 diff --git a/ShareX/Forms/MainForm.tr.resx b/ShareX/Forms/MainForm.tr.resx index edea5b99a..ac1c571db 100644 --- a/ShareX/Forms/MainForm.tr.resx +++ b/ShareX/Forms/MainForm.tr.resx @@ -151,7 +151,7 @@ Bölge - Bölge (Objeler) + Bölge (Pencereler ve kontroller) Bölge (Dipnot) @@ -445,7 +445,7 @@ Bölge - Bölge (Objeler) + Bölge (Pencereler ve kontroller) Bölge (Dipnot)