Code formatting (indents etc.) to get it consistent, simplify it for contributors.

This commit is contained in:
Robin Krom 2021-03-28 19:24:26 +02:00
parent 726644de99
commit e8c0b307ee
No known key found for this signature in database
GPG key ID: BCC01364F1371490
435 changed files with 46647 additions and 39014 deletions

View file

@ -18,6 +18,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Windows.Forms;
using GreenshotPlugin.Core;
@ -28,39 +29,44 @@ using GreenshotPlugin.UnmanagedHelpers;
using GreenshotPlugin.UnmanagedHelpers.Enums;
using GreenshotPlugin.UnmanagedHelpers.Structs;
namespace GreenshotPlugin.Controls {
/// <summary>
/// This form allows us to show a Thumbnail preview of a window near the context menu when selecting a window to capture.
/// Didn't make it completely "generic" yet, but at least most logic is in here so we don't have it in the mainform.
/// </summary>
public sealed class ThumbnailForm : FormWithoutActivation {
private static readonly CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
namespace GreenshotPlugin.Controls
{
/// <summary>
/// This form allows us to show a Thumbnail preview of a window near the context menu when selecting a window to capture.
/// Didn't make it completely "generic" yet, but at least most logic is in here so we don't have it in the mainform.
/// </summary>
public sealed class ThumbnailForm : FormWithoutActivation
{
private static readonly CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
private IntPtr _thumbnailHandle = IntPtr.Zero;
private IntPtr _thumbnailHandle = IntPtr.Zero;
public ThumbnailForm() {
ShowInTaskbar = false;
FormBorderStyle = FormBorderStyle.None;
TopMost = false;
Enabled = false;
if (conf.WindowCaptureMode == WindowCaptureMode.Auto || conf.WindowCaptureMode == WindowCaptureMode.Aero) {
BackColor = Color.FromArgb(255, conf.DWMBackgroundColor.R, conf.DWMBackgroundColor.G, conf.DWMBackgroundColor.B);
} else {
BackColor = Color.White;
}
public ThumbnailForm()
{
ShowInTaskbar = false;
FormBorderStyle = FormBorderStyle.None;
TopMost = false;
Enabled = false;
if (conf.WindowCaptureMode == WindowCaptureMode.Auto || conf.WindowCaptureMode == WindowCaptureMode.Aero)
{
BackColor = Color.FromArgb(255, conf.DWMBackgroundColor.R, conf.DWMBackgroundColor.G, conf.DWMBackgroundColor.B);
}
else
{
BackColor = Color.White;
}
// cleanup at close
FormClosing += delegate {
UnregisterThumbnail();
};
}
// cleanup at close
FormClosing += delegate { UnregisterThumbnail(); };
}
public new void Hide() {
UnregisterThumbnail();
base.Hide();
}
public new void Hide()
{
UnregisterThumbnail();
base.Hide();
}
private void UnregisterThumbnail()
private void UnregisterThumbnail()
{
if (_thumbnailHandle == IntPtr.Zero) return;
@ -68,15 +74,16 @@ namespace GreenshotPlugin.Controls {
_thumbnailHandle = IntPtr.Zero;
}
/// <summary>
/// Show the thumbnail of the supplied window above (or under) the parent Control
/// </summary>
/// <param name="window">WindowDetails</param>
/// <param name="parentControl">Control</param>
public void ShowThumbnail(WindowDetails window, Control parentControl) {
UnregisterThumbnail();
/// <summary>
/// Show the thumbnail of the supplied window above (or under) the parent Control
/// </summary>
/// <param name="window">WindowDetails</param>
/// <param name="parentControl">Control</param>
public void ShowThumbnail(WindowDetails window, Control parentControl)
{
UnregisterThumbnail();
DWM.DwmRegisterThumbnail(Handle, window.Handle, out _thumbnailHandle);
DWM.DwmRegisterThumbnail(Handle, window.Handle, out _thumbnailHandle);
if (_thumbnailHandle == IntPtr.Zero) return;
var result = DWM.DwmQueryThumbnailSourceSize(_thumbnailHandle, out var sourceSize);
@ -93,12 +100,13 @@ namespace GreenshotPlugin.Controls {
}
int thumbnailHeight = 200;
int thumbnailWidth = (int)(thumbnailHeight * (sourceSize.Width / (float)sourceSize.Height));
int thumbnailWidth = (int) (thumbnailHeight * (sourceSize.Width / (float) sourceSize.Height));
if (parentControl != null && thumbnailWidth > parentControl.Width)
{
thumbnailWidth = parentControl.Width;
thumbnailHeight = (int)(thumbnailWidth * (sourceSize.Height / (float)sourceSize.Width));
thumbnailHeight = (int) (thumbnailWidth * (sourceSize.Height / (float) sourceSize.Width));
}
Width = thumbnailWidth;
Height = thumbnailHeight;
// Prepare the displaying of the Thumbnail
@ -116,26 +124,34 @@ namespace GreenshotPlugin.Controls {
return;
}
if (parentControl != null) {
if (parentControl != null)
{
AlignToControl(parentControl);
}
if (!Visible) {
if (!Visible)
{
Show();
}
// Make sure it's on "top"!
if (parentControl != null) {
if (parentControl != null)
{
User32.SetWindowPos(Handle, parentControl.Handle, 0, 0, 0, 0, WindowPos.SWP_NOMOVE | WindowPos.SWP_NOSIZE | WindowPos.SWP_NOACTIVATE);
}
}
public void AlignToControl(Control alignTo) {
var screenBounds = WindowCapture.GetScreenBounds();
if (screenBounds.Contains(alignTo.Left, alignTo.Top - Height)) {
Location = new Point(alignTo.Left + (alignTo.Width / 2) - (Width / 2), alignTo.Top - Height);
} else {
Location = new Point(alignTo.Left + (alignTo.Width / 2) - (Width / 2), alignTo.Bottom);
}
}
}
}
public void AlignToControl(Control alignTo)
{
var screenBounds = WindowCapture.GetScreenBounds();
if (screenBounds.Contains(alignTo.Left, alignTo.Top - Height))
{
Location = new Point(alignTo.Left + (alignTo.Width / 2) - (Width / 2), alignTo.Top - Height);
}
else
{
Location = new Point(alignTo.Left + (alignTo.Width / 2) - (Width / 2), alignTo.Bottom);
}
}
}
}