diff --git a/src/Greenshot.Base/Controls/ThumbnailForm.cs b/src/Greenshot.Base/Controls/ThumbnailForm.cs index b316b8720..d5b8c50e8 100644 --- a/src/Greenshot.Base/Controls/ThumbnailForm.cs +++ b/src/Greenshot.Base/Controls/ThumbnailForm.cs @@ -146,7 +146,7 @@ namespace Greenshot.Base.Controls public void AlignToControl(Control alignTo) { - var screenBounds = WindowCapture.GetScreenBounds(); + var screenBounds = DisplayInfo.ScreenBounds; if (screenBounds.Contains(alignTo.Left, alignTo.Top - Height)) { Location = new Point(alignTo.Left + (alignTo.Width / 2) - (Width / 2), alignTo.Top - Height); diff --git a/src/Greenshot.Base/Core/AbstractDestination.cs b/src/Greenshot.Base/Core/AbstractDestination.cs index 7cf1ee0d2..e462ba171 100644 --- a/src/Greenshot.Base/Core/AbstractDestination.cs +++ b/src/Greenshot.Base/Core/AbstractDestination.cs @@ -316,9 +316,9 @@ namespace Greenshot.Base.Core { // find a suitable location NativePoint location = Cursor.Position; - NativeRect menuRectangle = new NativeRect(location, menu.Size); + var menuRectangle = new NativeRect(location, menu.Size); - menuRectangle = menuRectangle.Intersect(WindowCapture.GetScreenBounds()); + menuRectangle = menuRectangle.Intersect(DisplayInfo.ScreenBounds); if (menuRectangle.Height < menu.Height) { location = location.Offset(-40, -(menuRectangle.Height - menu.Height)); diff --git a/src/Greenshot.Base/Core/Capture.cs b/src/Greenshot.Base/Core/Capture.cs index 82a5eb85b..0be688727 100644 --- a/src/Greenshot.Base/Core/Capture.cs +++ b/src/Greenshot.Base/Core/Capture.cs @@ -24,6 +24,7 @@ using System.Drawing; using System.Drawing.Imaging; using Dapplo.Windows.Common.Extensions; using Dapplo.Windows.Common.Structs; +using Dapplo.Windows.User32; using Greenshot.Base.Interfaces; using Greenshot.Base.Interfaces.Ocr; using log4net; @@ -49,7 +50,7 @@ namespace Greenshot.Base.Core { if (_screenBounds.IsEmpty) { - _screenBounds = WindowCapture.GetScreenBounds(); + _screenBounds = DisplayInfo.ScreenBounds; } return _screenBounds; @@ -164,7 +165,7 @@ namespace Greenshot.Base.Core /// public Capture() { - _screenBounds = WindowCapture.GetScreenBounds(); + _screenBounds = DisplayInfo.ScreenBounds; _captureDetails = new CaptureDetails(); } @@ -263,7 +264,7 @@ namespace Greenshot.Base.Core //private void MoveElements(List listOfElements, int x, int y) { // foreach(ICaptureElement childElement in listOfElements) { - // Rectangle bounds = childElement.Bounds; + // NativeRect bounds = childElement.Bounds; // bounds.Offset(x, y); // childElement.Bounds = bounds; // MoveElements(childElement.Children, x, y); diff --git a/src/Greenshot.Base/Core/CaptureHandler.cs b/src/Greenshot.Base/Core/CaptureHandler.cs index f807666c7..74f58b555 100644 --- a/src/Greenshot.Base/Core/CaptureHandler.cs +++ b/src/Greenshot.Base/Core/CaptureHandler.cs @@ -20,15 +20,16 @@ */ using System.Drawing; +using Dapplo.Windows.Common.Structs; namespace Greenshot.Base.Core { /// /// This is the method signature which is used to capture a rectangle from the screen. /// - /// + /// NativeRect /// Captured Bitmap - public delegate Bitmap CaptureScreenRectangleHandler(Rectangle captureBounds); + public delegate Bitmap CaptureScreenRectangleHandler(NativeRect captureBounds); /// /// This is a hack to experiment with different screen capture routines diff --git a/src/Greenshot.Base/Core/ClipboardHelper.cs b/src/Greenshot.Base/Core/ClipboardHelper.cs index 8996b7ce5..4878b3d0d 100644 --- a/src/Greenshot.Base/Core/ClipboardHelper.cs +++ b/src/Greenshot.Base/Core/ClipboardHelper.cs @@ -31,6 +31,7 @@ using System.Text; using System.Threading; using System.Windows.Forms; using Dapplo.Windows.Clipboard; +using Dapplo.Windows.Common.Structs; using Dapplo.Windows.Gdi32.Enums; using Dapplo.Windows.Gdi32.Structs; using Dapplo.Windows.User32; @@ -1121,7 +1122,7 @@ EndSelection:<<<<<<<4 private static byte[] BitmapToByteArray(Bitmap bitmap) { // Lock the bitmap's bits. - Rectangle rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height); + var rect = new NativeRect(0, 0, bitmap.Width, bitmap.Height); BitmapData bmpData = bitmap.LockBits(rect, ImageLockMode.ReadOnly, bitmap.PixelFormat); int absStride = Math.Abs(bmpData.Stride); diff --git a/src/Greenshot.Base/Core/CoreConfiguration.cs b/src/Greenshot.Base/Core/CoreConfiguration.cs index b20e1d246..580af8918 100644 --- a/src/Greenshot.Base/Core/CoreConfiguration.cs +++ b/src/Greenshot.Base/Core/CoreConfiguration.cs @@ -322,7 +322,7 @@ namespace Greenshot.Base.Core public bool ProcessEXIFOrientation { get; set; } [IniProperty("LastCapturedRegion", Description = "The last used region, for reuse in the capture last region")] - public Rectangle LastCapturedRegion { get; set; } + public NativeRect LastCapturedRegion { get; set; } [IniProperty("Win10BorderCrop", Description = "The capture is cropped with these settings, e.g. when you don't want to color around it -1,-1"), DefaultValue("0,0")] public NativeSize Win10BorderCrop { get; set; } diff --git a/src/Greenshot.Base/Core/FastBitmap.cs b/src/Greenshot.Base/Core/FastBitmap.cs index 3875e6203..96aa36da6 100644 --- a/src/Greenshot.Base/Core/FastBitmap.cs +++ b/src/Greenshot.Base/Core/FastBitmap.cs @@ -23,6 +23,8 @@ using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; +using Dapplo.Windows.Common.Extensions; +using Dapplo.Windows.Common.Structs; namespace Greenshot.Base.Core { @@ -84,7 +86,7 @@ namespace Greenshot.Base.Core /// /// Size of the underlying image /// - Size Size { get; } + NativeSize Size { get; } /// /// Height of the image area that this fastbitmap covers @@ -127,19 +129,19 @@ namespace Greenshot.Base.Core bool HasAlphaChannel { get; } /// - /// Draw the stored bitmap to the destionation bitmap at the supplied point + /// Draw the stored bitmap to the destination bitmap at the supplied point /// /// Graphics - /// Point with location - void DrawTo(Graphics graphics, Point destination); + /// NativePoint with location + void DrawTo(Graphics graphics, NativePoint destination); /// /// Draw the stored Bitmap on the Destination bitmap with the specified rectangle /// Be aware that the stored bitmap will be resized to the specified rectangle!! /// /// Graphics - /// Rectangle with destination - void DrawTo(Graphics graphics, Rectangle destinationRect); + /// NativeRect with destination + void DrawTo(Graphics graphics, NativeRect destinationRect); /// /// Return true if the coordinates are inside the FastBitmap @@ -214,7 +216,7 @@ namespace Greenshot.Base.Core /// public interface IFastBitmapWithClip : IFastBitmap { - Rectangle Clip { get; set; } + NativeRect Clip { get; set; } bool InvertClip { get; set; } @@ -267,14 +269,14 @@ namespace Greenshot.Base.Core public const int ColorIndexB = 2; public const int ColorIndexA = 3; - protected Rectangle Area; + protected NativeRect Area; /// /// If this is set to true, the bitmap will be disposed when disposing the IFastBitmap /// public bool NeedsDispose { get; set; } - public Rectangle Clip { get; set; } + public NativeRect Clip { get; set; } public bool InvertClip { get; set; } @@ -290,7 +292,7 @@ namespace Greenshot.Base.Core public static IFastBitmap Create(Bitmap source) { - return Create(source, Rectangle.Empty); + return Create(source, NativeRect.Empty); } public void SetResolution(float horizontal, float vertical) @@ -303,44 +305,37 @@ namespace Greenshot.Base.Core /// The supplied rectangle specifies the area for which the FastBitmap does its thing /// /// Bitmap to access - /// Rectangle which specifies the area to have access to, can be Rectangle.Empty for the whole image + /// NativeRect which specifies the area to have access to, can be NativeRect.Empty for the whole image /// IFastBitmap - public static IFastBitmap Create(Bitmap source, Rectangle area) - { - switch (source.PixelFormat) + public static IFastBitmap Create(Bitmap source, NativeRect area) => + source.PixelFormat switch { - case PixelFormat.Format8bppIndexed: - return new FastChunkyBitmap(source, area); - case PixelFormat.Format24bppRgb: - return new Fast24RgbBitmap(source, area); - case PixelFormat.Format32bppRgb: - return new Fast32RgbBitmap(source, area); - case PixelFormat.Format32bppArgb: - case PixelFormat.Format32bppPArgb: - return new Fast32ArgbBitmap(source, area); - default: - throw new NotSupportedException($"Not supported Pixelformat {source.PixelFormat}"); - } - } + PixelFormat.Format8bppIndexed => new FastChunkyBitmap(source, area), + PixelFormat.Format24bppRgb => new Fast24RgbBitmap(source, area), + PixelFormat.Format32bppRgb => new Fast32RgbBitmap(source, area), + PixelFormat.Format32bppArgb => new Fast32ArgbBitmap(source, area), + PixelFormat.Format32bppPArgb => new Fast32ArgbBitmap(source, area), + _ => throw new NotSupportedException($"Not supported PixelFormat {source.PixelFormat}") + }; /// /// Factory for creating a FastBitmap as a destination for the source /// /// Bitmap to clone - /// new Pixelformat + /// new PixelFormat /// IFastBitmap public static IFastBitmap CreateCloneOf(Image source, PixelFormat pixelFormat) { - return CreateCloneOf(source, pixelFormat, Rectangle.Empty); + return CreateCloneOf(source, pixelFormat, NativeRect.Empty); } /// /// Factory for creating a FastBitmap as a destination for the source /// /// Bitmap to clone - /// Area of the bitmap to access, can be Rectangle.Empty for the whole + /// Area of the bitmap to access, can be NativeRect.Empty for the whole /// IFastBitmap - public static IFastBitmap CreateCloneOf(Image source, Rectangle area) + public static IFastBitmap CreateCloneOf(Image source, NativeRect area) { return CreateCloneOf(source, PixelFormat.DontCare, area); } @@ -350,9 +345,9 @@ namespace Greenshot.Base.Core /// /// Bitmap to clone /// Pixelformat of the cloned bitmap - /// Area of the bitmap to access, can be Rectangle.Empty for the whole + /// Area of the bitmap to access, can be NativeRect.Empty for the whole /// IFastBitmap - public static IFastBitmap CreateCloneOf(Image source, PixelFormat pixelFormat, Rectangle area) + public static IFastBitmap CreateCloneOf(Image source, PixelFormat pixelFormat, NativeRect area) { Bitmap destination = ImageHelper.CloneArea(source, area, pixelFormat); FastBitmap fastBitmap = Create(destination) as FastBitmap; @@ -369,11 +364,11 @@ namespace Greenshot.Base.Core /// /// Factory for creating a FastBitmap as a destination /// - /// - /// - /// + /// NativeSize + /// PixelFormat + /// Color /// IFastBitmap - public static IFastBitmap CreateEmpty(Size newSize, PixelFormat pixelFormat, Color backgroundColor) + public static IFastBitmap CreateEmpty(NativeSize newSize, PixelFormat pixelFormat, Color backgroundColor) { Bitmap destination = ImageHelper.CreateEmpty(newSize.Width, newSize.Height, pixelFormat, backgroundColor, 96f, 96f); IFastBitmap fastBitmap = Create(destination); @@ -385,14 +380,14 @@ namespace Greenshot.Base.Core /// Constructor which stores the image and locks it when called /// /// Bitmap - /// Rectangle - protected FastBitmap(Bitmap bitmap, Rectangle area) + /// NativeRect + protected FastBitmap(Bitmap bitmap, NativeRect area) { Bitmap = bitmap; - Rectangle bitmapArea = new Rectangle(Point.Empty, bitmap.Size); - if (area != Rectangle.Empty) + var bitmapArea = new NativeRect(Point.Empty, bitmap.Size); + if (area != NativeRect.Empty) { - area.Intersect(bitmapArea); + area = area.Intersect(bitmapArea); Area = area; } else @@ -413,11 +408,11 @@ namespace Greenshot.Base.Core /// /// Return the size of the image /// - public Size Size + public NativeSize Size { get { - if (Area == Rectangle.Empty) + if (Area == NativeRect.Empty) { return Bitmap.Size; } @@ -433,7 +428,7 @@ namespace Greenshot.Base.Core { get { - if (Area == Rectangle.Empty) + if (Area == NativeRect.Empty) { return Bitmap.Width; } @@ -449,7 +444,7 @@ namespace Greenshot.Base.Core { get { - if (Area == Rectangle.Empty) + if (Area == NativeRect.Empty) { return Bitmap.Height; } @@ -596,13 +591,13 @@ namespace Greenshot.Base.Core } /// - /// Draw the stored bitmap to the destionation bitmap at the supplied point + /// Draw the stored bitmap to the destination bitmap at the supplied point /// /// /// - public void DrawTo(Graphics graphics, Point destination) + public void DrawTo(Graphics graphics, NativePoint destination) { - DrawTo(graphics, new Rectangle(destination, Area.Size)); + DrawTo(graphics, new NativeRect(destination, Area.Size)); } /// @@ -610,8 +605,8 @@ namespace Greenshot.Base.Core /// Be aware that the stored bitmap will be resized to the specified rectangle!! /// /// - /// - public void DrawTo(Graphics graphics, Rectangle destinationRect) + /// NativeRect + public void DrawTo(Graphics graphics, NativeRect destinationRect) { // Make sure this.bitmap is unlocked, if it was locked bool isLocked = BitsLocked; @@ -715,7 +710,7 @@ namespace Greenshot.Base.Core } /// - /// This is the implementation of the FastBitmat for the 8BPP pixelformat + /// This is the implementation of the FastBitmap for the 8BPP pixelformat /// public unsafe class FastChunkyBitmap : FastBitmap { @@ -723,7 +718,7 @@ namespace Greenshot.Base.Core private readonly Color[] _colorEntries; private readonly Dictionary _colorCache = new Dictionary(); - public FastChunkyBitmap(Bitmap source, Rectangle area) : base(source, area) + public FastChunkyBitmap(Bitmap source, NativeRect area) : base(source, area) { _colorEntries = Bitmap.Palette.Entries; } @@ -825,7 +820,7 @@ namespace Greenshot.Base.Core /// public unsafe class Fast24RgbBitmap : FastBitmap { - public Fast24RgbBitmap(Bitmap source, Rectangle area) : base(source, area) + public Fast24RgbBitmap(Bitmap source, NativeRect area) : base(source, area) { } @@ -891,7 +886,7 @@ namespace Greenshot.Base.Core /// public unsafe class Fast32RgbBitmap : FastBitmap { - public Fast32RgbBitmap(Bitmap source, Rectangle area) : base(source, area) + public Fast32RgbBitmap(Bitmap source, NativeRect area) : base(source, area) { } @@ -961,7 +956,7 @@ namespace Greenshot.Base.Core public Color BackgroundBlendColor { get; set; } - public Fast32ArgbBitmap(Bitmap source, Rectangle area) : base(source, area) + public Fast32ArgbBitmap(Bitmap source, NativeRect area) : base(source, area) { BackgroundBlendColor = Color.White; } diff --git a/src/Greenshot.Base/Core/ImageHelper.cs b/src/Greenshot.Base/Core/ImageHelper.cs index 306986c4e..e817b79f0 100644 --- a/src/Greenshot.Base/Core/ImageHelper.cs +++ b/src/Greenshot.Base/Core/ImageHelper.cs @@ -173,7 +173,7 @@ namespace Greenshot.Base.Core { if (image is Bitmap && (image.Width * image.Height > 0)) { - cropNativeRect.Intersect(new NativeRect(0, 0, image.Width, image.Height)); + cropNativeRect = cropNativeRect.Intersect(new NativeRect(0, 0, image.Width, image.Height)); if (cropNativeRect.Width != 0 || cropNativeRect.Height != 0) { Image returnImage = CloneArea(image, cropNativeRect, PixelFormat.DontCare); @@ -769,7 +769,7 @@ namespace Greenshot.Base.Core /// /// /// - /// + /// NativeRect public static NativeRect CreateIntersectRectangle(NativeSize applySize, NativeRect rect, bool invert) { NativeRect myRect; diff --git a/src/Greenshot.Base/Core/ImageIO.cs b/src/Greenshot.Base/Core/ImageIO.cs index f1416a827..f2e4ba4cd 100644 --- a/src/Greenshot.Base/Core/ImageIO.cs +++ b/src/Greenshot.Base/Core/ImageIO.cs @@ -598,54 +598,7 @@ namespace Greenshot.Base.Core return bmpPngExtracted; } - - /// - /// See: https://msdn.microsoft.com/en-us/library/windows/desktop/ms648069%28v=vs.85%29.aspx - /// - /// The file (EXE or DLL) to get the icon from - /// Index of the icon - /// true if the large icon is wanted - /// Icon - public static Icon ExtractAssociatedIcon(string location, int index, bool takeLarge) - { - NativeIconMethods.ExtractIconEx(location, index, out var large, out var small, 1); - Icon returnIcon = null; - bool isLarge = false; - bool isSmall = false; - try - { - if (takeLarge && !IntPtr.Zero.Equals(large)) - { - returnIcon = Icon.FromHandle(large); - isLarge = true; - } - else if (!IntPtr.Zero.Equals(small)) - { - returnIcon = Icon.FromHandle(small); - isSmall = true; - } - else if (!IntPtr.Zero.Equals(large)) - { - returnIcon = Icon.FromHandle(large); - isLarge = true; - } - } - finally - { - if (isLarge && !IntPtr.Zero.Equals(small)) - { - NativeIconMethods.DestroyIcon(small); - } - - if (isSmall && !IntPtr.Zero.Equals(large)) - { - NativeIconMethods.DestroyIcon(large); - } - } - - return returnIcon; - } - + /// /// Create an image from a stream, if an extension is supplied more formats are supported. /// diff --git a/src/Greenshot.Base/Core/PluginUtils.cs b/src/Greenshot.Base/Core/PluginUtils.cs index 12a874216..ca7895840 100644 --- a/src/Greenshot.Base/Core/PluginUtils.cs +++ b/src/Greenshot.Base/Core/PluginUtils.cs @@ -22,11 +22,11 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.Diagnostics; using System.Drawing; using System.IO; using System.Windows.Forms; using Dapplo.Windows.Icons; -using Dapplo.Windows.Icons.Enums; using Greenshot.Base.IniFile; using log4net; using Microsoft.Win32; @@ -159,21 +159,10 @@ namespace Greenshot.Base.Core try { - using (Icon appIcon = IconHelper.ExtractAssociatedIcon(path, index, CoreConfig.UseLargeIcons)) - { - if (appIcon != null) - { - return appIcon.ToBitmap(); - } - } - - using (Icon appIcon = IconHelper.GetFileExtensionIcon(path, CoreConfig.UseLargeIcons ? IconSize.Large : IconSize.Small, false)) - { - if (appIcon != null) - { - return appIcon.ToBitmap(); - } - } + var appIcon = IconHelper.ExtractAssociatedIcon(path, index, CoreConfig.UseLargeIcons); + Debug.Assert(appIcon != null && (appIcon.Width*appIcon.Height > 0), "Invalid icon"); + Log.DebugFormat("Loaded icon for {0}, with dimensions {1}x{2}", path, appIcon.Width, appIcon.Height); + return appIcon; } catch (Exception exIcon) { @@ -196,27 +185,25 @@ namespace Greenshot.Base.Core // Try to find a separator, so we insert ourselves after it for (int i = 0; i < contextMenu.Items.Count; i++) { - if (contextMenu.Items[i].GetType() == typeof(ToolStripSeparator)) + if (contextMenu.Items[i].GetType() != typeof(ToolStripSeparator)) continue; + // Check if we need to add a new separator, which is done if the first found has a Tag with the value "PluginsAreAddedBefore" + if ("PluginsAreAddedBefore".Equals(contextMenu.Items[i].Tag)) { - // Check if we need to add a new separator, which is done if the first found has a Tag with the value "PluginsAreAddedBefore" - if ("PluginsAreAddedBefore".Equals(contextMenu.Items[i].Tag)) + var separator = new ToolStripSeparator { - var separator = new ToolStripSeparator - { - Tag = "PluginsAreAddedAfter", - Size = new Size(305, 6) - }; - contextMenu.Items.Insert(i, separator); - } - else if (!"PluginsAreAddedAfter".Equals(contextMenu.Items[i].Tag)) - { - continue; - } - - contextMenu.Items.Insert(i + 1, item); - addedItem = true; - break; + Tag = "PluginsAreAddedAfter", + Size = new Size(305, 6) + }; + contextMenu.Items.Insert(i, separator); } + else if (!"PluginsAreAddedAfter".Equals(contextMenu.Items[i].Tag)) + { + continue; + } + + contextMenu.Items.Insert(i + 1, item); + addedItem = true; + break; } // If we didn't insert the item, we just add it... diff --git a/src/Greenshot.Base/Core/WindowCapture.cs b/src/Greenshot.Base/Core/WindowCapture.cs index 98c2048f8..0b4bf4e3f 100644 --- a/src/Greenshot.Base/Core/WindowCapture.cs +++ b/src/Greenshot.Base/Core/WindowCapture.cs @@ -52,26 +52,6 @@ namespace Greenshot.Base.Core private static readonly ILog Log = LogManager.GetLogger(typeof(WindowCapture)); private static readonly CoreConfiguration Configuration = IniConfig.GetIniSection(); - /// - /// Get the bounds of all screens combined. - /// - /// A Rectangle of the bounds of the entire display area. - public static NativeRect GetScreenBounds() - { - int left = 0, top = 0, bottom = 0, right = 0; - foreach (Screen screen in Screen.AllScreens) - { - left = Math.Min(left, screen.Bounds.X); - top = Math.Min(top, screen.Bounds.Y); - int screenAbsRight = screen.Bounds.X + screen.Bounds.Width; - int screenAbsBottom = screen.Bounds.Y + screen.Bounds.Height; - right = Math.Max(right, screenAbsRight); - bottom = Math.Max(bottom, screenAbsBottom); - } - - return new Rectangle(left, top, (right + Math.Abs(left)), (bottom + Math.Abs(top))); - } - /// /// Retrieves the cursor location safely, accounting for DPI settings in Vista/Windows 7. This implementation /// can conveniently be used when the cursor location is needed to deal with a fullscreen bitmap. @@ -93,10 +73,8 @@ namespace Greenshot.Base.Core /// Point public static NativePoint GetLocationRelativeToScreenBounds(NativePoint locationRelativeToScreenOrigin) { - NativePoint ret = locationRelativeToScreenOrigin; - NativeRect bounds = GetScreenBounds(); - ret.Offset(-bounds.X, -bounds.Y); - return ret; + NativeRect bounds = DisplayInfo.ScreenBounds; + return locationRelativeToScreenOrigin.Offset(-bounds.X, -bounds.Y); } /// @@ -152,9 +130,9 @@ namespace Greenshot.Base.Core /// Helper method to create an exception that might explain what is wrong while capturing /// /// string with current method - /// Rectangle of what we want to capture + /// NativeRect of what we want to capture /// - private static Exception CreateCaptureException(string method, Rectangle captureBounds) + private static Exception CreateCaptureException(string method, NativeRect captureBounds) { Exception exceptionToThrow = User32Api.CreateWin32Exception(method); if (!captureBounds.IsEmpty) @@ -224,9 +202,9 @@ namespace Greenshot.Base.Core /// This method will use User32 code to capture the specified captureBounds from the screen /// /// ICapture where the captured Bitmap will be stored - /// Rectangle with the bounds to capture + /// NativeRect with the bounds to capture /// A Capture Object with a part of the Screen as an Image - public static ICapture CaptureRectangle(ICapture capture, Rectangle captureBounds) + public static ICapture CaptureRectangle(ICapture capture, NativeRect captureBounds) { if (capture == null) { @@ -262,9 +240,9 @@ namespace Greenshot.Base.Core /// This method will use User32 code to capture the specified captureBounds from the screen /// /// ICapture where the captured Bitmap will be stored - /// Rectangle with the bounds to capture + /// NativeRect with the bounds to capture /// A Capture Object with a part of the Screen as an Image - public static ICapture CaptureRectangleFromDesktopScreen(ICapture capture, Rectangle captureBounds) + public static ICapture CaptureRectangleFromDesktopScreen(ICapture capture, NativeRect captureBounds) { if (capture == null) { @@ -279,9 +257,9 @@ namespace Greenshot.Base.Core /// /// This method will use User32 code to capture the specified captureBounds from the screen /// - /// Rectangle with the bounds to capture + /// NativeRect with the bounds to capture /// Bitmap which is captured from the screen at the location specified by the captureBounds - public static Bitmap CaptureRectangle(Rectangle captureBounds) + public static Bitmap CaptureRectangle(NativeRect captureBounds) { Bitmap returnBitmap = null; if (captureBounds.Height <= 0 || captureBounds.Width <= 0) @@ -388,17 +366,16 @@ namespace Greenshot.Base.Core { using Bitmap tmpBitmap = Image.FromHbitmap(safeDibSectionHandle.DangerousGetHandle()); // Create a new bitmap which has a transparent background - returnBitmap = ImageHelper.CreateEmpty(tmpBitmap.Width, tmpBitmap.Height, PixelFormat.Format32bppArgb, Color.Transparent, - tmpBitmap.HorizontalResolution, tmpBitmap.VerticalResolution); + returnBitmap = ImageHelper.CreateEmpty(tmpBitmap.Width, tmpBitmap.Height, PixelFormat.Format32bppArgb, Color.Transparent, tmpBitmap.HorizontalResolution, tmpBitmap.VerticalResolution); // Content will be copied here using Graphics graphics = Graphics.FromImage(returnBitmap); // For all screens copy the content to the new bitmap - foreach (Screen screen in Screen.AllScreens) + + foreach (var displayInfo in DisplayInfo.AllDisplayInfos) { - Rectangle screenBounds = screen.Bounds; - // Make sure the bounds are offsetted to the capture bounds - screenBounds.Offset(-captureBounds.X, -captureBounds.Y); - graphics.DrawImage(tmpBitmap, screenBounds, screenBounds.X, screenBounds.Y, screenBounds.Width, screenBounds.Height, GraphicsUnit.Pixel); + // Make sure the bounds are offset to the capture bounds + var displayBounds = displayInfo.Bounds.Offset(-captureBounds.X, -captureBounds.Y); + graphics.DrawImage(tmpBitmap, displayBounds, displayBounds.X, displayBounds.Y, displayBounds.Width, displayBounds.Height, GraphicsUnit.Pixel); } } else diff --git a/src/Greenshot.Base/Core/WindowDetails.cs b/src/Greenshot.Base/Core/WindowDetails.cs index a9c3a747a..4c0b38f4e 100644 --- a/src/Greenshot.Base/Core/WindowDetails.cs +++ b/src/Greenshot.Base/Core/WindowDetails.cs @@ -498,15 +498,11 @@ namespace Greenshot.Base.Core { if (Visible) { - Rectangle windowRectangle = WindowRectangle; - foreach (var screen in Screen.AllScreens) + foreach (var displayInfo in DisplayInfo.AllDisplayInfos) { - if (screen.Bounds.Contains(windowRectangle)) + if (WindowRectangle.Equals(displayInfo.Bounds)) { - if (windowRectangle.Equals(screen.Bounds)) - { - return true; - } + return true; } } } @@ -552,32 +548,31 @@ namespace Greenshot.Base.Core if (IsApp) { - Rectangle windowRectangle = WindowRectangle; - foreach (Screen screen in Screen.AllScreens) + var windowRectangle = WindowRectangle; + + foreach (var displayInfo in DisplayInfo.AllDisplayInfos) { - if (screen.Bounds.Contains(windowRectangle)) + if (!displayInfo.Bounds.Contains(windowRectangle)) continue; + if (windowRectangle.Equals(displayInfo.Bounds)) { - if (windowRectangle.Equals(screen.Bounds)) + // Fullscreen, it's "visible" when AppVisibilityOnMonitor says yes + // Although it might be the other App, this is not "very" important + NativeRect rect = displayInfo.Bounds; + IntPtr monitor = User32Api.MonitorFromRect(ref rect, MonitorFrom.DefaultToNull); + if (monitor != IntPtr.Zero) { - // Fullscreen, it's "visible" when AppVisibilityOnMonitor says yes - // Although it might be the other App, this is not "very" important - NativeRect rect = screen.Bounds; - IntPtr monitor = User32Api.MonitorFromRect(ref rect, MonitorFrom.DefaultToNull); - if (monitor != IntPtr.Zero) + MONITOR_APP_VISIBILITY? monitorAppVisibility = AppVisibility?.GetAppVisibilityOnMonitor(monitor); + //LOG.DebugFormat("App {0} visible: {1} on {2}", Text, monitorAppVisibility, screen.Bounds); + if (monitorAppVisibility == MONITOR_APP_VISIBILITY.MAV_APP_VISIBLE) { - MONITOR_APP_VISIBILITY? monitorAppVisibility = AppVisibility?.GetAppVisibilityOnMonitor(monitor); - //LOG.DebugFormat("App {0} visible: {1} on {2}", Text, monitorAppVisibility, screen.Bounds); - if (monitorAppVisibility == MONITOR_APP_VISIBILITY.MAV_APP_VISIBLE) - { - return true; - } + return true; } } - else - { - // Is only partly on the screen, when this happens the app is always visible! - return true; - } + } + else + { + // Is only partly on the screen, when this happens the app is always visible! + return true; } } @@ -635,7 +630,7 @@ namespace Greenshot.Base.Core } } - private Rectangle _previousWindowRectangle = Rectangle.Empty; + private NativeRect _previousWindowRectangle = NativeRect.Empty; private long _lastWindowRectangleRetrieveTime; private const long CacheTime = TimeSpan.TicksPerSecond * 2; @@ -694,13 +689,13 @@ namespace Greenshot.Base.Core // Only if the border size can be retrieved if (GetBorderSize(out var size)) { - windowRect = new Rectangle(windowRect.X + size.Width, windowRect.Y + size.Height, windowRect.Width - (2 * size.Width), + windowRect = new NativeRect(windowRect.X + size.Width, windowRect.Y + size.Height, windowRect.Width - (2 * size.Width), windowRect.Height - (2 * size.Height)); } } _lastWindowRectangleRetrieveTime = now; - // Try to return something valid, by getting returning the previous size if the window doesn't have a Rectangle anymore + // Try to return something valid, by getting returning the previous size if the window doesn't have a NativeRect anymore if (windowRect.IsEmpty) { return _previousWindowRectangle; @@ -717,31 +712,23 @@ namespace Greenshot.Base.Core /// /// Gets the location of the window relative to the screen. /// - public Point Location + public NativePoint Location { - get - { - Rectangle tmpRectangle = WindowRectangle; - return new Point(tmpRectangle.Left, tmpRectangle.Top); - } + get => WindowRectangle.Location; } /// /// Gets the size of the window. /// - public Size Size + public NativeSize Size { - get - { - Rectangle tmpRectangle = WindowRectangle; - return new Size(tmpRectangle.Right - tmpRectangle.Left, tmpRectangle.Bottom - tmpRectangle.Top); - } + get => WindowRectangle.Size; } /// /// Get the client rectangle, this is the part of the window inside the borders (drawable area) /// - public Rectangle ClientRectangle + public NativeRect ClientRectangle { get { @@ -760,7 +747,7 @@ namespace Greenshot.Base.Core /// /// Point with the coordinates to check /// true if the point lies within - public bool Contains(Point p) + public bool Contains(NativePoint p) { return WindowRectangle.Contains(p); } @@ -891,12 +878,13 @@ namespace Greenshot.Base.Core if (!workingArea.AreRectangleCornersVisisble(windowRectangle)) { // If none found we find the biggest screen - foreach (Screen screen in Screen.AllScreens) + + foreach (var displayInfo in DisplayInfo.AllDisplayInfos) { - Rectangle newWindowRectangle = new Rectangle(screen.WorkingArea.Location, windowRectangle.Size); + var newWindowRectangle = new NativeRect(displayInfo.WorkingArea.Location, windowRectangle.Size); if (workingArea.AreRectangleCornersVisisble(newWindowRectangle)) { - formLocation = screen.Bounds.Location; + formLocation = displayInfo.Bounds.Location; doesCaptureFit = true; break; } @@ -1169,7 +1157,7 @@ namespace Greenshot.Base.Core /// /// Helper method to get the window size for DWM Windows /// - /// out Rectangle + /// out NativeRect /// bool true if it worked private bool GetExtendedFrameBounds(out NativeRect rectangle) { @@ -1180,7 +1168,7 @@ namespace Greenshot.Base.Core return true; } - rectangle = Rectangle.Empty; + rectangle = NativeRect.Empty; return false; } @@ -1194,7 +1182,7 @@ namespace Greenshot.Base.Core var windowInfo = new WindowInfo(); // Get the Window Info for this window bool result = User32Api.GetWindowInfo(Handle, ref windowInfo); - rectangle = result ? windowInfo.ClientBounds : Rectangle.Empty; + rectangle = result ? windowInfo.ClientBounds : NativeRect.Empty; return result; } @@ -1208,7 +1196,7 @@ namespace Greenshot.Base.Core var windowInfo = new WindowInfo(); // Get the Window Info for this window bool result = User32Api.GetWindowInfo(Handle, ref windowInfo); - rectangle = result ? windowInfo.Bounds : Rectangle.Empty; + rectangle = result ? windowInfo.Bounds : NativeRect.Empty; return result; } @@ -1222,7 +1210,7 @@ namespace Greenshot.Base.Core var windowInfo = new WindowInfo(); // Get the Window Info for this window bool result = User32Api.GetWindowInfo(Handle, ref windowInfo); - size = result ? windowInfo.BorderSize : Size.Empty; + size = result ? windowInfo.BorderSize : NativeSize.Empty; return result; } @@ -1403,7 +1391,7 @@ namespace Greenshot.Base.Core /// public Image PrintWindow() { - Rectangle windowRect = WindowRectangle; + NativeRect windowRect = WindowRectangle; // Start the capture Exception exceptionOccurred = null; Image returnImage; @@ -1561,7 +1549,7 @@ namespace Greenshot.Base.Core /// /// /// - private static bool IsVisible(WindowDetails window, Rectangle screenBounds) + private static bool IsVisible(WindowDetails window, NativeRect screenBounds) { // Ignore invisible if (!window.Visible) @@ -1603,7 +1591,7 @@ namespace Greenshot.Base.Core /// List WindowDetails with all the visible top level windows public static IEnumerable GetVisibleWindows() { - Rectangle screenBounds = WindowCapture.GetScreenBounds(); + var screenBounds = DisplayInfo.ScreenBounds; foreach (var window in GetAppWindows()) { if (IsVisible(window, screenBounds)) diff --git a/src/Greenshot.Base/Greenshot.Base.csproj b/src/Greenshot.Base/Greenshot.Base.csproj index 9d8a64589..169bd9395 100644 --- a/src/Greenshot.Base/Greenshot.Base.csproj +++ b/src/Greenshot.Base/Greenshot.Base.csproj @@ -6,12 +6,12 @@ - - - - - - + + + + + + diff --git a/src/Greenshot.Base/Interfaces/Drawing/IDrawableContainer.cs b/src/Greenshot.Base/Interfaces/Drawing/IDrawableContainer.cs index 3fe786508..1733b9e31 100644 --- a/src/Greenshot.Base/Interfaces/Drawing/IDrawableContainer.cs +++ b/src/Greenshot.Base/Interfaces/Drawing/IDrawableContainer.cs @@ -58,7 +58,7 @@ namespace Greenshot.Base.Interfaces.Drawing NativeRect DrawingBounds { get; } - void ApplyBounds(RectangleF newBounds); + void ApplyBounds(NativeRectFloat newBounds); bool HasFilters { get; } diff --git a/src/Greenshot.Base/Interfaces/ICapture.cs b/src/Greenshot.Base/Interfaces/ICapture.cs index 740cdb75b..d1c8881a8 100644 --- a/src/Greenshot.Base/Interfaces/ICapture.cs +++ b/src/Greenshot.Base/Interfaces/ICapture.cs @@ -73,7 +73,7 @@ namespace Greenshot.Base.Interfaces /// /// Crops the capture to the specified rectangle (with Bitmap coordinates!) /// - /// Rectangle with bitmap coordinates + /// NativeRect with bitmap coordinates bool Crop(NativeRect cropRectangle); /// diff --git a/src/Greenshot.Base/Interfaces/Ocr/Line.cs b/src/Greenshot.Base/Interfaces/Ocr/Line.cs index 916c6ee21..aa37564c0 100644 --- a/src/Greenshot.Base/Interfaces/Ocr/Line.cs +++ b/src/Greenshot.Base/Interfaces/Ocr/Line.cs @@ -58,12 +58,12 @@ namespace Greenshot.Base.Interfaces.Ocr /// /// Calculate the bounds of the words /// - /// Rectangle + /// NativeRect private NativeRect CalculateBounds() { if (Words.Length == 0) { - return Rectangle.Empty; + return NativeRect.Empty; } var result = Words[0].Bounds; @@ -92,9 +92,7 @@ namespace Greenshot.Base.Interfaces.Ocr { foreach (var word in Words) { - var location = word.Bounds; - location.Offset(x, y); - word.Bounds = location; + word.Bounds = word.Bounds.Offset(x, y); } _calculatedBounds = null; diff --git a/src/Greenshot.Editor/Configuration/EditorConfiguration.cs b/src/Greenshot.Editor/Configuration/EditorConfiguration.cs index 74864d15e..3a516797c 100644 --- a/src/Greenshot.Editor/Configuration/EditorConfiguration.cs +++ b/src/Greenshot.Editor/Configuration/EditorConfiguration.cs @@ -152,9 +152,9 @@ namespace Greenshot.Editor.Configuration public void ResetEditorPlacement() { - WindowNormalPosition = new Rectangle(100, 100, 400, 400); - WindowMaxPosition = new Point(-1, -1); - WindowMinPosition = new Point(-1, -1); + WindowNormalPosition = new NativeRect(100, 100, 400, 400); + WindowMaxPosition = new NativePoint(-1, -1); + WindowMinPosition = new NativePoint(-1, -1); WindowPlacementFlags = 0; ShowWindowCommand = ShowWindowCommands.Normal; } diff --git a/src/Greenshot.Editor/Controls/ColorButton.cs b/src/Greenshot.Editor/Controls/ColorButton.cs index 849395330..9e968afbc 100644 --- a/src/Greenshot.Editor/Controls/ColorButton.cs +++ b/src/Greenshot.Editor/Controls/ColorButton.cs @@ -24,6 +24,7 @@ using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; +using Dapplo.Windows.Common.Structs; using Greenshot.Base.Controls; using ColorDialog = Greenshot.Editor.Forms.ColorDialog; @@ -65,7 +66,7 @@ namespace Greenshot.Editor.Controls if (Image != null) { using Graphics graphics = Graphics.FromImage(Image); - graphics.FillRectangle(brush, new Rectangle(4, 17, 16, 3)); + graphics.FillRectangle(brush, new NativeRect(4, 17, 16, 3)); } // cleanup GDI Object diff --git a/src/Greenshot.Editor/Controls/FontFamilyComboBox.cs b/src/Greenshot.Editor/Controls/FontFamilyComboBox.cs index b57d52e75..cabb40e49 100644 --- a/src/Greenshot.Editor/Controls/FontFamilyComboBox.cs +++ b/src/Greenshot.Editor/Controls/FontFamilyComboBox.cs @@ -23,6 +23,7 @@ using System; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; +using Dapplo.Windows.Common.Structs; namespace Greenshot.Editor.Controls { @@ -113,12 +114,12 @@ namespace Greenshot.Editor.Controls /// /// Helper method to draw the string /// - /// - /// - /// - /// - /// - private void DrawText(Graphics graphics, FontFamily fontFamily, FontStyle fontStyle, Rectangle bounds, string text) + /// Graphics + /// FontFamily + /// FontStyle + /// NativeRect + /// string + private void DrawText(Graphics graphics, FontFamily fontFamily, FontStyle fontStyle, NativeRect bounds, string text) { using Font font = new Font(fontFamily, Font.Size + 5, fontStyle, GraphicsUnit.Pixel); // Make sure the text is visible by centering it in the line diff --git a/src/Greenshot.Editor/Controls/ToolStripColorButton.cs b/src/Greenshot.Editor/Controls/ToolStripColorButton.cs index 91386b4f4..eb05a0fcc 100644 --- a/src/Greenshot.Editor/Controls/ToolStripColorButton.cs +++ b/src/Greenshot.Editor/Controls/ToolStripColorButton.cs @@ -24,6 +24,7 @@ using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; +using Dapplo.Windows.Common.Structs; using Greenshot.Base.Controls; using ColorDialog = Greenshot.Editor.Forms.ColorDialog; @@ -63,7 +64,7 @@ namespace Greenshot.Editor.Controls if (Image != null) { using Graphics graphics = Graphics.FromImage(Image); - graphics.FillRectangle(brush, new Rectangle(0, 13, 16, 3)); + graphics.FillRectangle(brush, new NativeRect(0, 13, 16, 3)); } // cleanup GDI Object diff --git a/src/Greenshot.Editor/Drawing/Adorners/AbstractAdorner.cs b/src/Greenshot.Editor/Drawing/Adorners/AbstractAdorner.cs index 2bf1baa00..aa023b19c 100644 --- a/src/Greenshot.Editor/Drawing/Adorners/AbstractAdorner.cs +++ b/src/Greenshot.Editor/Drawing/Adorners/AbstractAdorner.cs @@ -34,8 +34,8 @@ namespace Greenshot.Editor.Drawing.Adorners { public virtual EditStatus EditStatus { get; protected set; } = EditStatus.IDLE; - private static readonly Size DefaultSize = new Size(6, 6); - protected Size _size; + private static readonly NativeSize DefaultSize = new NativeSize(6, 6); + protected NativeSize _size; public AbstractAdorner(IDrawableContainer owner) { @@ -95,7 +95,7 @@ namespace Greenshot.Editor.Drawing.Adorners /// /// Return the location of the adorner /// - public virtual Point Location { get; set; } + public virtual NativePoint Location { get; set; } /// /// Return the bounds of the Adorner @@ -112,12 +112,12 @@ namespace Greenshot.Editor.Drawing.Adorners /// /// Return the bounds of the Adorner as displayed on the parent Surface /// - protected virtual Rectangle BoundsOnSurface + protected virtual NativeRect BoundsOnSurface { get { - Point displayLocation = Owner.Parent.ToSurfaceCoordinates(Location); - return new Rectangle(displayLocation.X - _size.Width / 2, displayLocation.Y - _size.Height / 2, _size.Width, _size.Height); + NativePoint displayLocation = Owner.Parent.ToSurfaceCoordinates(Location); + return new NativeRect(displayLocation.X - _size.Width / 2, displayLocation.Y - _size.Height / 2, _size.Width, _size.Height); } } diff --git a/src/Greenshot.Editor/Drawing/Adorners/MoveAdorner.cs b/src/Greenshot.Editor/Drawing/Adorners/MoveAdorner.cs index 228ac9746..46fcdb1b0 100644 --- a/src/Greenshot.Editor/Drawing/Adorners/MoveAdorner.cs +++ b/src/Greenshot.Editor/Drawing/Adorners/MoveAdorner.cs @@ -21,6 +21,7 @@ using System.Drawing; using System.Windows.Forms; +using Dapplo.Windows.Common.Structs; using Greenshot.Base.Interfaces.Drawing; using Greenshot.Editor.Helpers; @@ -31,8 +32,8 @@ namespace Greenshot.Editor.Drawing.Adorners /// public class MoveAdorner : AbstractAdorner { - private Rectangle _boundsBeforeResize = Rectangle.Empty; - private RectangleF _boundsAfterResize = RectangleF.Empty; + private NativeRect _boundsBeforeResize = NativeRect.Empty; + private NativeRectFloat _boundsAfterResize = NativeRectFloat.Empty; public Positions Position { get; private set; } @@ -54,7 +55,7 @@ namespace Greenshot.Editor.Drawing.Adorners public override void MouseDown(object sender, MouseEventArgs mouseEventArgs) { EditStatus = EditStatus.RESIZING; - _boundsBeforeResize = new Rectangle(Owner.Left, Owner.Top, Owner.Width, Owner.Height); + _boundsBeforeResize = new NativeRect(Owner.Left, Owner.Top, Owner.Width, Owner.Height); _boundsAfterResize = _boundsBeforeResize; } @@ -74,10 +75,7 @@ namespace Greenshot.Editor.Drawing.Adorners Owner.MakeBoundsChangeUndoable(false); // reset "workbench" rectangle to current bounds - _boundsAfterResize.X = _boundsBeforeResize.X; - _boundsAfterResize.Y = _boundsBeforeResize.Y; - _boundsAfterResize.Width = _boundsBeforeResize.Width; - _boundsAfterResize.Height = _boundsBeforeResize.Height; + _boundsAfterResize = _boundsBeforeResize; // calculate scaled rectangle ScaleHelper.Scale(ref _boundsAfterResize, Position, new PointF(mouseEventArgs.X, mouseEventArgs.Y), ScaleHelper.GetScaleOptions()); @@ -91,7 +89,7 @@ namespace Greenshot.Editor.Drawing.Adorners /// /// Return the location of the adorner /// - public override Point Location + public override NativePoint Location { get { @@ -132,7 +130,7 @@ namespace Greenshot.Editor.Drawing.Adorners break; } - return new Point(x, y); + return new NativePoint(x, y); } } } diff --git a/src/Greenshot.Editor/Drawing/Adorners/ResizeAdorner.cs b/src/Greenshot.Editor/Drawing/Adorners/ResizeAdorner.cs index 772885b21..296cc4ef8 100644 --- a/src/Greenshot.Editor/Drawing/Adorners/ResizeAdorner.cs +++ b/src/Greenshot.Editor/Drawing/Adorners/ResizeAdorner.cs @@ -21,6 +21,7 @@ using System.Drawing; using System.Windows.Forms; +using Dapplo.Windows.Common.Structs; using Greenshot.Base.Interfaces.Drawing; using Greenshot.Editor.Helpers; @@ -31,8 +32,8 @@ namespace Greenshot.Editor.Drawing.Adorners /// public class ResizeAdorner : AbstractAdorner { - private Rectangle _boundsBeforeResize = Rectangle.Empty; - private RectangleF _boundsAfterResize = RectangleF.Empty; + private NativeRect _boundsBeforeResize = NativeRect.Empty; + private NativeRectFloat _boundsAfterResize = NativeRectFloat.Empty; public Positions Position { get; private set; } @@ -82,7 +83,7 @@ namespace Greenshot.Editor.Drawing.Adorners public override void MouseDown(object sender, MouseEventArgs mouseEventArgs) { EditStatus = EditStatus.RESIZING; - _boundsBeforeResize = new Rectangle(Owner.Left, Owner.Top, Owner.Width, Owner.Height); + _boundsBeforeResize = new NativeRect(Owner.Left, Owner.Top, Owner.Width, Owner.Height); _boundsAfterResize = _boundsBeforeResize; } @@ -102,10 +103,7 @@ namespace Greenshot.Editor.Drawing.Adorners Owner.MakeBoundsChangeUndoable(false); // reset "workbench" rectangle to current bounds - _boundsAfterResize.X = _boundsBeforeResize.X; - _boundsAfterResize.Y = _boundsBeforeResize.Y; - _boundsAfterResize.Width = _boundsBeforeResize.Width; - _boundsAfterResize.Height = _boundsBeforeResize.Height; + _boundsAfterResize = _boundsBeforeResize; // calculate scaled rectangle ScaleHelper.Scale(ref _boundsAfterResize, Position, new PointF(mouseEventArgs.X, mouseEventArgs.Y), ScaleHelper.GetScaleOptions()); @@ -119,7 +117,7 @@ namespace Greenshot.Editor.Drawing.Adorners /// /// Return the location of the adorner /// - public override Point Location + public override NativePoint Location { get { diff --git a/src/Greenshot.Editor/Drawing/Adorners/TargetAdorner.cs b/src/Greenshot.Editor/Drawing/Adorners/TargetAdorner.cs index c59fc43ef..864ff28c5 100644 --- a/src/Greenshot.Editor/Drawing/Adorners/TargetAdorner.cs +++ b/src/Greenshot.Editor/Drawing/Adorners/TargetAdorner.cs @@ -22,6 +22,8 @@ using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; +using Dapplo.Windows.Common.Extensions; +using Dapplo.Windows.Common.Structs; using Greenshot.Base.Interfaces.Drawing; namespace Greenshot.Editor.Drawing.Adorners @@ -61,30 +63,30 @@ namespace Greenshot.Editor.Drawing.Adorners } Owner.Invalidate(); - Point newGripperLocation = new Point(mouseEventArgs.X, mouseEventArgs.Y); - Rectangle imageBounds = new Rectangle(0, 0, Owner.Parent.Image.Width, Owner.Parent.Image.Height); + NativePoint newGripperLocation = new NativePoint(mouseEventArgs.X, mouseEventArgs.Y); + NativeRect imageBounds = new NativeRect(0, 0, Owner.Parent.Image.Width, Owner.Parent.Image.Height); // Check if gripper inside the parent (surface), if not we need to move it inside // This was made for BUG-1682 if (!imageBounds.Contains(newGripperLocation)) { if (newGripperLocation.X > imageBounds.Right) { - newGripperLocation.X = imageBounds.Right - 5; + newGripperLocation = newGripperLocation.ChangeX(imageBounds.Right - 5); } if (newGripperLocation.X < imageBounds.Left) { - newGripperLocation.X = imageBounds.Left; + newGripperLocation = newGripperLocation.ChangeX(imageBounds.Left); } if (newGripperLocation.Y > imageBounds.Bottom) { - newGripperLocation.Y = imageBounds.Bottom - 5; + newGripperLocation = newGripperLocation.ChangeY(imageBounds.Bottom - 5); } if (newGripperLocation.Y < imageBounds.Top) { - newGripperLocation.Y = imageBounds.Top; + newGripperLocation = newGripperLocation.ChangeY(imageBounds.Top); } } @@ -103,7 +105,7 @@ namespace Greenshot.Editor.Drawing.Adorners return; } - Point[] points = new[] + Point[] points = new Point[] { Location }; diff --git a/src/Greenshot.Editor/Drawing/CropContainer.cs b/src/Greenshot.Editor/Drawing/CropContainer.cs index 1fb3bbc61..d99d4622d 100644 --- a/src/Greenshot.Editor/Drawing/CropContainer.cs +++ b/src/Greenshot.Editor/Drawing/CropContainer.cs @@ -227,10 +227,7 @@ namespace Greenshot.Editor.Drawing //allow only horizontal changes if (_parent?.Image is { } image) { - _boundsAfterResize.X = 0; - _boundsAfterResize.Y = _boundsBeforeResize.Top; - _boundsAfterResize.Width = image.Width; - _boundsAfterResize.Height = y - _boundsAfterResize.Top; + _boundsAfterResize = new NativeRectFloat(0, _boundsBeforeResize.Top, image.Width, y - _boundsAfterResize.Top); } break; } @@ -240,23 +237,18 @@ namespace Greenshot.Editor.Drawing //allow only vertical changes if (_parent?.Image is { } image) { - _boundsAfterResize.X = _boundsBeforeResize.Left; - _boundsAfterResize.Y = 0; - _boundsAfterResize.Width = x - _boundsAfterResize.Left; - _boundsAfterResize.Height = image.Height; + _boundsAfterResize = new NativeRectFloat(_boundsBeforeResize.Left, 0, x - _boundsAfterResize.Left, image.Height); } break; } default: { // reset "workbench" rectangle to current bounds - _boundsAfterResize.X = _boundsBeforeResize.Left; - _boundsAfterResize.Y = _boundsBeforeResize.Top; - _boundsAfterResize.Width = x - _boundsAfterResize.Left; - _boundsAfterResize.Height = y - _boundsAfterResize.Top; + _boundsAfterResize = new NativeRectFloat( + _boundsBeforeResize.Left, _boundsBeforeResize.Top, + x - _boundsAfterResize.Left, y - _boundsAfterResize.Top); break; } - } ScaleHelper.Scale(_boundsBeforeResize, x, y, ref _boundsAfterResize, GetAngleRoundProcessor()); diff --git a/src/Greenshot.Editor/Drawing/CursorContainer.cs b/src/Greenshot.Editor/Drawing/CursorContainer.cs index 0eda46085..e8914eb75 100644 --- a/src/Greenshot.Editor/Drawing/CursorContainer.cs +++ b/src/Greenshot.Editor/Drawing/CursorContainer.cs @@ -25,6 +25,7 @@ using System.Drawing.Drawing2D; using System.IO; using System.Runtime.Serialization; using System.Windows.Forms; +using Dapplo.Windows.Common.Structs; using Greenshot.Base.Interfaces; using Greenshot.Base.Interfaces.Drawing; using log4net; @@ -124,6 +125,6 @@ namespace Greenshot.Editor.Drawing cursor.DrawStretched(graphics, Bounds); } - public override Size DefaultSize => cursor?.Size ?? new Size(16, 16); + public override NativeSize DefaultSize => cursor?.Size ?? new NativeSize(16, 16); } } \ No newline at end of file diff --git a/src/Greenshot.Editor/Drawing/DrawableContainer.cs b/src/Greenshot.Editor/Drawing/DrawableContainer.cs index 92a9664f3..4a170f8dd 100644 --- a/src/Greenshot.Editor/Drawing/DrawableContainer.cs +++ b/src/Greenshot.Editor/Drawing/DrawableContainer.cs @@ -263,7 +263,7 @@ namespace Greenshot.Editor.Drawing [NonSerialized] // "workbench" rectangle - used for calculating bounds during resizing (to be applied to this DrawableContainer afterwards) - protected RectangleF _boundsAfterResize = RectangleF.Empty; + protected NativeRectFloat _boundsAfterResize = NativeRectFloat.Empty; public NativeRect Bounds { @@ -277,7 +277,7 @@ namespace Greenshot.Editor.Drawing } } - public virtual void ApplyBounds(RectangleF newBounds) + public virtual void ApplyBounds(NativeRectFloat newBounds) { Left = Round(newBounds.Left); Top = Round(newBounds.Top); @@ -528,10 +528,7 @@ namespace Greenshot.Editor.Drawing Invalidate(); // reset "workbench" rectangle to current bounds - _boundsAfterResize.X = _boundsBeforeResize.Left; - _boundsAfterResize.Y = _boundsBeforeResize.Top; - _boundsAfterResize.Width = x - _boundsAfterResize.Left; - _boundsAfterResize.Height = y - _boundsAfterResize.Top; + _boundsAfterResize = _boundsBeforeResize; ScaleHelper.Scale(_boundsBeforeResize, x, y, ref _boundsAfterResize, GetAngleRoundProcessor()); @@ -675,7 +672,7 @@ namespace Greenshot.Editor.Drawing public virtual bool HasDefaultSize => false; - public virtual Size DefaultSize => throw new NotSupportedException("Object doesn't have a default size"); + public virtual NativeSize DefaultSize => throw new NotSupportedException("Object doesn't have a default size"); /// /// Allows to override the initializing of the fields, so we can actually have our own defaults diff --git a/src/Greenshot.Editor/Drawing/EllipseContainer.cs b/src/Greenshot.Editor/Drawing/EllipseContainer.cs index 31feb104f..c421515d9 100644 --- a/src/Greenshot.Editor/Drawing/EllipseContainer.cs +++ b/src/Greenshot.Editor/Drawing/EllipseContainer.cs @@ -87,7 +87,7 @@ namespace Greenshot.Editor.Drawing /// /// /// - public static void DrawEllipse(Rectangle rect, Graphics graphics, RenderMode renderMode, int lineThickness, Color lineColor, Color fillColor, bool shadow) + public static void DrawEllipse(NativeRect rect, Graphics graphics, RenderMode renderMode, int lineThickness, Color lineColor, Color fillColor, bool shadow) { bool lineVisible = lineThickness > 0 && Colors.IsVisible(lineColor); // draw shadow before anything else @@ -152,7 +152,7 @@ namespace Greenshot.Editor.Drawing return EllipseClickableAt(rect, lineThickness, fillColor, x, y); } - public static bool EllipseClickableAt(Rectangle rect, int lineThickness, Color fillColor, int x, int y) + public static bool EllipseClickableAt(NativeRect rect, int lineThickness, Color fillColor, int x, int y) { // If we clicked inside the rectangle and it's visible we are clickable at. if (!Color.Transparent.Equals(fillColor)) diff --git a/src/Greenshot.Editor/Drawing/Filters/AbstractFilter.cs b/src/Greenshot.Editor/Drawing/Filters/AbstractFilter.cs index 17517b971..c972ed77d 100644 --- a/src/Greenshot.Editor/Drawing/Filters/AbstractFilter.cs +++ b/src/Greenshot.Editor/Drawing/Filters/AbstractFilter.cs @@ -22,6 +22,7 @@ using System; using System.ComponentModel; using System.Drawing; +using Dapplo.Windows.Common.Structs; using Greenshot.Base.Interfaces.Drawing; using Greenshot.Editor.Drawing.Fields; @@ -73,7 +74,7 @@ namespace Greenshot.Editor.Drawing.Filters return parent; } - public abstract void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode); + public abstract void Apply(Graphics graphics, Bitmap applyBitmap, NativeRect rect, RenderMode renderMode); protected void OnPropertyChanged(string propertyName) { diff --git a/src/Greenshot.Editor/Drawing/Filters/BlurFilter.cs b/src/Greenshot.Editor/Drawing/Filters/BlurFilter.cs index 08a6831d5..010cfd2cb 100644 --- a/src/Greenshot.Editor/Drawing/Filters/BlurFilter.cs +++ b/src/Greenshot.Editor/Drawing/Filters/BlurFilter.cs @@ -22,6 +22,7 @@ using System; using System.Drawing; using System.Drawing.Drawing2D; +using Dapplo.Windows.Common.Structs; using Dapplo.Windows.Gdi32; using Greenshot.Base.Core; using Greenshot.Base.Interfaces.Drawing; @@ -50,10 +51,10 @@ namespace Greenshot.Editor.Drawing.Filters AddField(GetType(), FieldType.PREVIEW_QUALITY, 1.0d); } - public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) + public override void Apply(Graphics graphics, Bitmap applyBitmap, NativeRect rect, RenderMode renderMode) { int blurRadius = GetFieldValueAsInt(FieldType.BLUR_RADIUS); - Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert); + var applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert); if (applyRect.Width == 0 || applyRect.Height == 0) { return; diff --git a/src/Greenshot.Editor/Drawing/Filters/BrightnessFilter.cs b/src/Greenshot.Editor/Drawing/Filters/BrightnessFilter.cs index cfdf7b025..639b0e5ac 100644 --- a/src/Greenshot.Editor/Drawing/Filters/BrightnessFilter.cs +++ b/src/Greenshot.Editor/Drawing/Filters/BrightnessFilter.cs @@ -23,6 +23,7 @@ using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; +using Dapplo.Windows.Common.Structs; using Greenshot.Base.Core; using Greenshot.Base.Interfaces.Drawing; using Greenshot.Editor.Drawing.Fields; @@ -42,11 +43,11 @@ namespace Greenshot.Editor.Drawing.Filters /// /// /// - /// + /// NativeRect /// - public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) + public override void Apply(Graphics graphics, Bitmap applyBitmap, NativeRect rect, RenderMode renderMode) { - Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert); + var applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert); if (applyRect.Width == 0 || applyRect.Height == 0) { diff --git a/src/Greenshot.Editor/Drawing/Filters/GrayscaleFilter.cs b/src/Greenshot.Editor/Drawing/Filters/GrayscaleFilter.cs index 5ed195fc7..441102980 100644 --- a/src/Greenshot.Editor/Drawing/Filters/GrayscaleFilter.cs +++ b/src/Greenshot.Editor/Drawing/Filters/GrayscaleFilter.cs @@ -23,13 +23,14 @@ using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; +using Dapplo.Windows.Common.Structs; using Greenshot.Base.Core; using Greenshot.Base.Interfaces.Drawing; namespace Greenshot.Editor.Drawing.Filters { /// - /// Description of GrayscaleFilter. + /// GrayscaleFilter makes the image grey /// [Serializable()] public class GrayscaleFilter : AbstractFilter @@ -38,9 +39,9 @@ namespace Greenshot.Editor.Drawing.Filters { } - public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) + public override void Apply(Graphics graphics, Bitmap applyBitmap, NativeRect rect, RenderMode renderMode) { - Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert); + var applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert); if (applyRect.Width == 0 || applyRect.Height == 0) { diff --git a/src/Greenshot.Editor/Drawing/Filters/HighlightFilter.cs b/src/Greenshot.Editor/Drawing/Filters/HighlightFilter.cs index 32337fb98..24624d193 100644 --- a/src/Greenshot.Editor/Drawing/Filters/HighlightFilter.cs +++ b/src/Greenshot.Editor/Drawing/Filters/HighlightFilter.cs @@ -22,12 +22,16 @@ using System; using System.Drawing; using System.Drawing.Drawing2D; +using Dapplo.Windows.Common.Structs; using Greenshot.Base.Core; using Greenshot.Base.Interfaces.Drawing; using Greenshot.Editor.Drawing.Fields; namespace Greenshot.Editor.Drawing.Filters { + /// + /// This filter highlights an area + /// [Serializable()] public class HighlightFilter : AbstractFilter { @@ -41,11 +45,11 @@ namespace Greenshot.Editor.Drawing.Filters /// /// /// - /// + /// NativeRect /// - public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) + public override void Apply(Graphics graphics, Bitmap applyBitmap, NativeRect rect, RenderMode renderMode) { - Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert); + var applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert); if (applyRect.Width == 0 || applyRect.Height == 0) { diff --git a/src/Greenshot.Editor/Drawing/Filters/IFilter.cs b/src/Greenshot.Editor/Drawing/Filters/IFilter.cs index 144732761..8c6d3d21d 100644 --- a/src/Greenshot.Editor/Drawing/Filters/IFilter.cs +++ b/src/Greenshot.Editor/Drawing/Filters/IFilter.cs @@ -21,6 +21,7 @@ using System.ComponentModel; using System.Drawing; +using Dapplo.Windows.Common.Structs; using Greenshot.Base.Interfaces.Drawing; namespace Greenshot.Editor.Drawing.Filters @@ -28,7 +29,7 @@ namespace Greenshot.Editor.Drawing.Filters public interface IFilter : INotifyPropertyChanged, IFieldHolder { DrawableContainer Parent { get; set; } - void Apply(Graphics graphics, Bitmap bmp, Rectangle rect, RenderMode renderMode); + void Apply(Graphics graphics, Bitmap bmp, NativeRect rect, RenderMode renderMode); DrawableContainer GetParent(); bool Invert { get; set; } } diff --git a/src/Greenshot.Editor/Drawing/Filters/MagnifierFilter.cs b/src/Greenshot.Editor/Drawing/Filters/MagnifierFilter.cs index f76640820..70d829a2e 100644 --- a/src/Greenshot.Editor/Drawing/Filters/MagnifierFilter.cs +++ b/src/Greenshot.Editor/Drawing/Filters/MagnifierFilter.cs @@ -22,12 +22,16 @@ using System; using System.Drawing; using System.Drawing.Drawing2D; +using Dapplo.Windows.Common.Structs; using Greenshot.Base.Core; using Greenshot.Base.Interfaces.Drawing; using Greenshot.Editor.Drawing.Fields; namespace Greenshot.Editor.Drawing.Filters { + /// + /// Magnify an area + /// [Serializable] public class MagnifierFilter : AbstractFilter { @@ -36,9 +40,9 @@ namespace Greenshot.Editor.Drawing.Filters AddField(GetType(), FieldType.MAGNIFICATION_FACTOR, 2); } - public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) + public override void Apply(Graphics graphics, Bitmap applyBitmap, NativeRect rect, RenderMode renderMode) { - Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert); + var applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert); if (applyRect.Width == 0 || applyRect.Height == 0) { @@ -62,7 +66,7 @@ namespace Greenshot.Editor.Drawing.Filters int halfHeight = rect.Height / 2; int newWidth = rect.Width / magnificationFactor; int newHeight = rect.Height / magnificationFactor; - Rectangle source = new Rectangle(rect.X + halfWidth - newWidth / 2, rect.Y + halfHeight - newHeight / 2, newWidth, newHeight); + var source = new NativeRect(rect.X + halfWidth - newWidth / 2, rect.Y + halfHeight - newHeight / 2, newWidth, newHeight); graphics.DrawImage(applyBitmap, rect, source, GraphicsUnit.Pixel); graphics.Restore(state); } diff --git a/src/Greenshot.Editor/Drawing/Filters/PixelizationFilter.cs b/src/Greenshot.Editor/Drawing/Filters/PixelizationFilter.cs index d0b88d4f7..fa677b128 100644 --- a/src/Greenshot.Editor/Drawing/Filters/PixelizationFilter.cs +++ b/src/Greenshot.Editor/Drawing/Filters/PixelizationFilter.cs @@ -22,6 +22,7 @@ using System; using System.Collections.Generic; using System.Drawing; +using Dapplo.Windows.Common.Structs; using Greenshot.Base.Core; using Greenshot.Base.Interfaces.Drawing; using Greenshot.Editor.Drawing.Fields; @@ -29,6 +30,9 @@ using Greenshot.Editor.Helpers; namespace Greenshot.Editor.Drawing.Filters { + /// + /// Pixelate an area + /// [Serializable()] public class PixelizationFilter : AbstractFilter { @@ -37,7 +41,7 @@ namespace Greenshot.Editor.Drawing.Filters AddField(GetType(), FieldType.PIXEL_SIZE, 5); } - public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) + public override void Apply(Graphics graphics, Bitmap applyBitmap, NativeRect rect, RenderMode renderMode) { int pixelSize = GetFieldValueAsInt(FieldType.PIXEL_SIZE); ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert); diff --git a/src/Greenshot.Editor/Drawing/FreehandContainer.cs b/src/Greenshot.Editor/Drawing/FreehandContainer.cs index a12c7b523..b8a66be4e 100644 --- a/src/Greenshot.Editor/Drawing/FreehandContainer.cs +++ b/src/Greenshot.Editor/Drawing/FreehandContainer.cs @@ -44,8 +44,8 @@ namespace Greenshot.Editor.Drawing }; [NonSerialized] private GraphicsPath freehandPath = new GraphicsPath(); - private Rectangle myBounds = Rectangle.Empty; - private Point lastMouse = Point.Empty; + private NativeRect myBounds = NativeRect.Empty; + private NativePoint lastMouse = NativePoint.Empty; private readonly List capturePoints = new List(); private bool isRecalculated; diff --git a/src/Greenshot.Editor/Drawing/IconContainer.cs b/src/Greenshot.Editor/Drawing/IconContainer.cs index dd6668ce9..185c17cd2 100644 --- a/src/Greenshot.Editor/Drawing/IconContainer.cs +++ b/src/Greenshot.Editor/Drawing/IconContainer.cs @@ -24,6 +24,7 @@ using System.Drawing; using System.Drawing.Drawing2D; using System.IO; using System.Runtime.Serialization; +using Dapplo.Windows.Common.Structs; using Greenshot.Base.Interfaces; using Greenshot.Base.Interfaces.Drawing; using log4net; @@ -133,6 +134,6 @@ namespace Greenshot.Editor.Drawing public override bool HasDefaultSize => true; - public override Size DefaultSize => icon?.Size ?? new Size(16, 16); + public override NativeSize DefaultSize => icon?.Size ?? new NativeSize(16, 16); } } \ No newline at end of file diff --git a/src/Greenshot.Editor/Drawing/ImageContainer.cs b/src/Greenshot.Editor/Drawing/ImageContainer.cs index 5def5578b..b3317d7bc 100644 --- a/src/Greenshot.Editor/Drawing/ImageContainer.cs +++ b/src/Greenshot.Editor/Drawing/ImageContainer.cs @@ -24,6 +24,7 @@ using System.Drawing; using System.Drawing.Drawing2D; using System.IO; using System.Runtime.Serialization; +using Dapplo.Windows.Common.Structs; using Greenshot.Base.Core; using Greenshot.Base.Effects; using Greenshot.Base.Interfaces; @@ -264,6 +265,6 @@ namespace Greenshot.Editor.Drawing public override bool HasDefaultSize => true; - public override Size DefaultSize => _image?.Size ?? new Size(32, 32); + public override NativeSize DefaultSize => _image?.Size ?? new NativeSize(32, 32); } } \ No newline at end of file diff --git a/src/Greenshot.Editor/Drawing/MetafileContainer.cs b/src/Greenshot.Editor/Drawing/MetafileContainer.cs index 04140bfe8..3225c4700 100644 --- a/src/Greenshot.Editor/Drawing/MetafileContainer.cs +++ b/src/Greenshot.Editor/Drawing/MetafileContainer.cs @@ -23,6 +23,7 @@ using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; +using Dapplo.Windows.Common.Structs; using Greenshot.Base.Core; using Greenshot.Base.Interfaces; @@ -39,14 +40,14 @@ namespace Greenshot.Editor.Drawing public MetafileContainer(Metafile metafile, ISurface parent) : base(parent) { _metafile = metafile; - Size = new Size(metafile.Width/4, metafile.Height/4); + Size = new NativeSize(metafile.Width/4, metafile.Height/4); } protected override Image ComputeBitmap() { var image = ImageHelper.CreateEmpty(Width, Height, PixelFormat.Format32bppArgb, Color.Transparent); - var dstRect = new Rectangle(0, 0, Width, Height); + var dstRect = new NativeRect(0, 0, Width, Height); using (Graphics graphics = Graphics.FromImage(image)) { graphics.SmoothingMode = SmoothingMode.HighQuality; @@ -75,6 +76,6 @@ namespace Greenshot.Editor.Drawing public override bool HasDefaultSize => true; - public override Size DefaultSize => new Size(_metafile.Width, _metafile.Height); + public override NativeSize DefaultSize => new NativeSize(_metafile.Width, _metafile.Height); } } \ No newline at end of file diff --git a/src/Greenshot.Editor/Drawing/RectangleContainer.cs b/src/Greenshot.Editor/Drawing/RectangleContainer.cs index 2ab60eaab..717e1a593 100644 --- a/src/Greenshot.Editor/Drawing/RectangleContainer.cs +++ b/src/Greenshot.Editor/Drawing/RectangleContainer.cs @@ -80,14 +80,14 @@ namespace Greenshot.Editor.Drawing /// /// This method can also be used from other containers, if the right values are passed! /// - /// + /// NativeRect /// /// /// /// /// /// - public static void DrawRectangle(Rectangle rect, Graphics graphics, RenderMode rm, int lineThickness, Color lineColor, Color fillColor, bool shadow) + public static void DrawRectangle(NativeRect rect, Graphics graphics, RenderMode rm, int lineThickness, Color lineColor, Color fillColor, bool shadow) { graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; @@ -143,7 +143,7 @@ namespace Greenshot.Editor.Drawing return RectangleClickableAt(rect, lineThickness, fillColor, x, y); } - public static bool RectangleClickableAt(Rectangle rect, int lineThickness, Color fillColor, int x, int y) + public static bool RectangleClickableAt(NativeRect rect, int lineThickness, Color fillColor, int x, int y) { // If we clicked inside the rectangle and it's visible we are clickable at. if (!Color.Transparent.Equals(fillColor)) diff --git a/src/Greenshot.Editor/Drawing/SpeechbubbleContainer.cs b/src/Greenshot.Editor/Drawing/SpeechbubbleContainer.cs index 1db69ea0d..795c7c768 100644 --- a/src/Greenshot.Editor/Drawing/SpeechbubbleContainer.cs +++ b/src/Greenshot.Editor/Drawing/SpeechbubbleContainer.cs @@ -39,7 +39,7 @@ namespace Greenshot.Editor.Drawing [Serializable] public class SpeechbubbleContainer : TextContainer { - private Point _initialGripperPoint; + private NativePoint _initialGripperPoint; // Only used for serializing the TargetGripper location private Point _storedTargetGripperLocation; @@ -120,8 +120,7 @@ namespace Greenshot.Editor.Drawing int xOffset = leftAligned ? -20 : 20; int yOffset = topAligned ? -20 : 20; - Point newGripperLocation = _initialGripperPoint; - newGripperLocation.Offset(xOffset, yOffset); + NativePoint newGripperLocation = _initialGripperPoint.Offset(xOffset, yOffset); if (TargetAdorner.Location != newGripperLocation) { diff --git a/src/Greenshot.Editor/Drawing/StepLabelContainer.cs b/src/Greenshot.Editor/Drawing/StepLabelContainer.cs index d6f089b1e..e5d93e514 100644 --- a/src/Greenshot.Editor/Drawing/StepLabelContainer.cs +++ b/src/Greenshot.Editor/Drawing/StepLabelContainer.cs @@ -117,7 +117,7 @@ namespace Greenshot.Editor.Drawing newParentSurface.AddStepLabel(this); } - public override Size DefaultSize => new Size(30, 30); + public override NativeSize DefaultSize => new NativeSize(30, 30); public override bool InitContent() { diff --git a/src/Greenshot.Editor/Drawing/Surface.cs b/src/Greenshot.Editor/Drawing/Surface.cs index c16066071..447c89a59 100644 --- a/src/Greenshot.Editor/Drawing/Surface.cs +++ b/src/Greenshot.Editor/Drawing/Surface.cs @@ -530,8 +530,8 @@ namespace Greenshot.Editor.Drawing // check if cursor is captured, and visible if (capture.Cursor != null && capture.CursorVisible) { - Rectangle cursorRect = new Rectangle(capture.CursorLocation, capture.Cursor.Size); - Rectangle captureRect = new Rectangle(Point.Empty, capture.Image.Size); + var cursorRect = new NativeRect(capture.CursorLocation, capture.Cursor.Size); + var captureRect = new NativeRect(NativePoint.Empty, capture.Image.Size); // check if cursor is on the capture, otherwise we leave it out. if (cursorRect.IntersectsWith(captureRect)) { @@ -940,7 +940,7 @@ namespace Greenshot.Editor.Drawing /// private void OnDragDrop(object sender, DragEventArgs e) { - Point mouse = PointToClient(new Point(e.X, e.Y)); + NativePoint mouse = PointToClient(new NativePoint(e.X, e.Y)); if (e.Data.GetDataPresent("Text")) { string possibleUrl = ClipboardHelper.GetText(e.Data); @@ -965,7 +965,7 @@ namespace Greenshot.Editor.Drawing drawableContainer.Top = mouse.Y; FitContainer(drawableContainer); AddElement(drawableContainer); - mouse.Offset(10, 10); + mouse = mouse.Offset(10, 10); } } @@ -974,11 +974,11 @@ namespace Greenshot.Editor.Drawing /// /// Auto crop the image /// - /// Rectangle with optional area to find a crop region + /// NativeRect with optional area to find a crop region /// true if cropped - public bool AutoCrop(Rectangle? cropArea = null) + public bool AutoCrop(NativeRect? cropArea = null) { - Rectangle cropRectangle; + NativeRect cropRectangle; using (Image tmpImage = GetImageForExport()) { cropRectangle = ImageHelper.FindAutoCropRectangle(tmpImage, conf.AutoCropDifference, cropArea); @@ -1031,7 +1031,7 @@ namespace Greenshot.Editor.Drawing Application.DoEvents(); try { - Rectangle imageRectangle = new Rectangle(Point.Empty, Image.Size); + var imageRectangle = new NativeRect(NativePoint.Empty, Image.Size); Matrix matrix = new Matrix(); Image newImage = ImageHelper.ApplyEffect(Image, effect, matrix); if (newImage != null) @@ -1042,7 +1042,7 @@ namespace Greenshot.Editor.Drawing MakeUndoable(new SurfaceBackgroundChangeMemento(this, matrix), false); SetImage(newImage, false); Invalidate(); - if (_surfaceSizeChanged != null && !imageRectangle.Equals(new Rectangle(Point.Empty, newImage.Size))) + if (_surfaceSizeChanged != null && !imageRectangle.Equals(new NativeRect(NativePoint.Empty, newImage.Size))) { _surfaceSizeChanged(this, null); } @@ -1066,7 +1066,7 @@ namespace Greenshot.Editor.Drawing /// Rectangle adapted to the dimensions of the image /// CropModes /// true if this is possible - public bool IsCropPossible(ref Rectangle cropRectangle, CropContainer.CropModes cropMode) + public bool IsCropPossible(ref NativeRect cropRectangle, CropContainer.CropModes cropMode) { cropRectangle = new NativeRect(cropRectangle.Left, cropRectangle.Top, cropRectangle.Width, cropRectangle.Height).Normalize(); //Fitting the rectangle to the dimensions of the image @@ -1199,13 +1199,13 @@ namespace Greenshot.Editor.Drawing /// /// Crop the surface /// - /// rectangle that remains + /// NativeRect that remains /// bool - public bool ApplyCrop(Rectangle cropRectangle) + public bool ApplyCrop(NativeRect cropRectangle) { if (!IsCropPossible(ref cropRectangle, CropContainer.CropModes.Default)) return false; - Rectangle imageRectangle = new Rectangle(Point.Empty, Image.Size); + var imageRectangle = new NativeRect(NativePoint.Empty, Image.Size); Bitmap tmpImage; // Make sure we have information, this this fails try @@ -1229,7 +1229,7 @@ namespace Greenshot.Editor.Drawing // Do not dispose otherwise we can't undo the image! SetImage(tmpImage, false); _elements.Transform(matrix); - if (_surfaceSizeChanged != null && !imageRectangle.Equals(new Rectangle(Point.Empty, tmpImage.Size))) + if (_surfaceSizeChanged != null && !imageRectangle.Equals(new NativeRect(NativePoint.Empty, tmpImage.Size))) { _surfaceSizeChanged(this, null); } @@ -1242,15 +1242,15 @@ namespace Greenshot.Editor.Drawing /// Crop out the surface /// Splits the image in 3 parts(top, middle, bottom). Crop out the middle and joins top and bottom. /// - /// rectangle of the middle part + /// NativeRect of the middle part /// bool - private bool ApplyHorizontalCrop(Rectangle cropRectangle) + private bool ApplyHorizontalCrop(NativeRect cropRectangle) { if (!IsCropPossible(ref cropRectangle, CropContainer.CropModes.Horizontal)) return false; - var imageRectangle = new Rectangle(Point.Empty, Image.Size); - var topRectangle = new Rectangle(0, 0, Image.Size.Width, cropRectangle.Top); - var bottomRectangle = new Rectangle(0, cropRectangle.Top + cropRectangle.Height, Image.Size.Width, Image.Size.Height - cropRectangle.Top - cropRectangle.Height); + var imageRectangle = new NativeRect(NativePoint.Empty, Image.Size); + var topRectangle = new NativeRect(0, 0, Image.Size.Width, cropRectangle.Top); + var bottomRectangle = new NativeRect(0, cropRectangle.Top + cropRectangle.Height, Image.Size.Width, Image.Size.Height - cropRectangle.Top - cropRectangle.Height); Bitmap newImage; try @@ -1262,12 +1262,12 @@ namespace Greenshot.Editor.Drawing var insertPositionTop = 0; if (topRectangle.Height > 0) { - graphics.DrawImage(Image, new Rectangle(0, insertPositionTop, topRectangle.Width, topRectangle.Height), topRectangle, GraphicsUnit.Pixel); + graphics.DrawImage(Image, new NativeRect(0, insertPositionTop, topRectangle.Width, topRectangle.Height), topRectangle, GraphicsUnit.Pixel); insertPositionTop += topRectangle.Height; } if (bottomRectangle.Height > 0) { - graphics.DrawImage(Image, new Rectangle(0, insertPositionTop, bottomRectangle.Width, bottomRectangle.Height), bottomRectangle, GraphicsUnit.Pixel); + graphics.DrawImage(Image, new NativeRect(0, insertPositionTop, bottomRectangle.Width, bottomRectangle.Height), bottomRectangle, GraphicsUnit.Pixel); } } catch (Exception ex) @@ -1287,7 +1287,7 @@ namespace Greenshot.Editor.Drawing SetImage(newImage, false); _elements.Transform(matrix); - if (_surfaceSizeChanged != null && !imageRectangle.Equals(new Rectangle(Point.Empty, newImage.Size))) + if (_surfaceSizeChanged != null && !imageRectangle.Equals(new NativeRect(NativePoint.Empty, newImage.Size))) { _surfaceSizeChanged(this, null); } @@ -1300,15 +1300,15 @@ namespace Greenshot.Editor.Drawing /// Crop out the surface /// Splits the image in 3 parts(left, middle, right). Crop out the middle and joins top and bottom. /// - /// rectangle of the middle part + /// NativeRect of the middle part /// bool - private bool ApplyVerticalCrop(Rectangle cropRectangle) + private bool ApplyVerticalCrop(NativeRect cropRectangle) { if (!IsCropPossible(ref cropRectangle, CropContainer.CropModes.Vertical)) return false; - var imageRectangle = new Rectangle(Point.Empty, Image.Size); - var leftRectangle = new Rectangle(0, 0, cropRectangle.Left, Image.Size.Height); - var rightRectangle = new Rectangle(cropRectangle.Left + cropRectangle.Width, 0, Image.Size.Width - cropRectangle.Width - cropRectangle.Left, Image.Size.Height); + var imageRectangle = new NativeRect(NativePoint.Empty, Image.Size); + var leftRectangle = new NativeRect(0, 0, cropRectangle.Left, Image.Size.Height); + var rightRectangle = new NativeRect(cropRectangle.Left + cropRectangle.Width, 0, Image.Size.Width - cropRectangle.Width - cropRectangle.Left, Image.Size.Height); Bitmap newImage; try { @@ -1319,13 +1319,13 @@ namespace Greenshot.Editor.Drawing var insertPositionLeft = 0; if (leftRectangle.Width > 0) { - graphics.DrawImage(Image, new Rectangle(insertPositionLeft, 0, leftRectangle.Width, leftRectangle.Height), leftRectangle , GraphicsUnit.Pixel); + graphics.DrawImage(Image, new NativeRect(insertPositionLeft, 0, leftRectangle.Width, leftRectangle.Height), leftRectangle , GraphicsUnit.Pixel); insertPositionLeft += leftRectangle.Width; } if (rightRectangle.Width > 0) { - graphics.DrawImage(Image, new Rectangle(insertPositionLeft, 0, rightRectangle.Width, rightRectangle.Height), rightRectangle, GraphicsUnit.Pixel); + graphics.DrawImage(Image, new NativeRect(insertPositionLeft, 0, rightRectangle.Width, rightRectangle.Height), rightRectangle, GraphicsUnit.Pixel); } } catch (Exception ex) @@ -1345,7 +1345,7 @@ namespace Greenshot.Editor.Drawing SetImage(newImage, false); _elements.Transform(matrix); - if (_surfaceSizeChanged != null && !imageRectangle.Equals(new Rectangle(Point.Empty, newImage.Size))) + if (_surfaceSizeChanged != null && !imageRectangle.Equals(new NativeRect(NativePoint.Empty, newImage.Size))) { _surfaceSizeChanged(this, null); } @@ -1735,8 +1735,8 @@ namespace Greenshot.Editor.Drawing private void SurfacePaint(object sender, PaintEventArgs paintEventArgs) { Graphics targetGraphics = paintEventArgs.Graphics; - Rectangle targetClipRectangle = paintEventArgs.ClipRectangle; - if (Rectangle.Empty.Equals(targetClipRectangle)) + NativeRect targetClipRectangle = paintEventArgs.ClipRectangle; + if (targetClipRectangle.IsEmpty) { LOG.Debug("Empty cliprectangle??"); return; @@ -1750,18 +1750,16 @@ namespace Greenshot.Editor.Drawing int verticalCorrection = targetClipRectangle.Top % (int) _zoomFactor.Numerator; if (horizontalCorrection != 0) { - targetClipRectangle.X -= horizontalCorrection; - targetClipRectangle.Width += horizontalCorrection; + targetClipRectangle = targetClipRectangle.ChangeX(-horizontalCorrection).ChangeWidth(horizontalCorrection); } if (verticalCorrection != 0) { - targetClipRectangle.Y -= verticalCorrection; - targetClipRectangle.Height += verticalCorrection; + targetClipRectangle = targetClipRectangle.ChangeY(-verticalCorrection).ChangeHeight(verticalCorrection); } } - Rectangle imageClipRectangle = ZoomClipRectangle(targetClipRectangle, _zoomFactor.Inverse(), 2); + NativeRect imageClipRectangle = ZoomClipRectangle(targetClipRectangle, _zoomFactor.Inverse(), 2); if (_elements.HasIntersectingFilters(imageClipRectangle) || _zoomFactor > Fraction.Identity) { @@ -1842,7 +1840,7 @@ namespace Greenshot.Editor.Drawing } } - private void DrawSmoothImage(Graphics targetGraphics, Image image, Rectangle imageClipRectangle) + private void DrawSmoothImage(Graphics targetGraphics, Image image, NativeRect imageClipRectangle) { var state = targetGraphics.Save(); targetGraphics.SmoothingMode = SmoothingMode.HighQuality; @@ -1855,7 +1853,7 @@ namespace Greenshot.Editor.Drawing targetGraphics.Restore(state); } - private void DrawSharpImage(Graphics targetGraphics, Image image, Rectangle imageClipRectangle) + private void DrawSharpImage(Graphics targetGraphics, Image image, NativeRect imageClipRectangle) { var state = targetGraphics.Save(); targetGraphics.SmoothingMode = SmoothingMode.None; @@ -1868,7 +1866,7 @@ namespace Greenshot.Editor.Drawing targetGraphics.Restore(state); } - private void DrawBackground(Graphics targetGraphics, Rectangle clipRectangle) + private void DrawBackground(Graphics targetGraphics, NativeRect clipRectangle) { // check if we need to draw the checkerboard if (Image.IsAlphaPixelFormat(Image.PixelFormat) && _transparencyBackgroundBrush != null) @@ -2199,32 +2197,31 @@ namespace Greenshot.Editor.Drawing dcs.Parent = this; var moveOffset = isSameSurface ? new Point(10, 10) : Point.Empty; // Here a fix for bug #1475, first calculate the bounds of the complete IDrawableContainerList - Rectangle drawableContainerListBounds = Rectangle.Empty; + NativeRect drawableContainerListBounds = NativeRect.Empty; foreach (var element in dcs) { - drawableContainerListBounds = drawableContainerListBounds == Rectangle.Empty + drawableContainerListBounds = drawableContainerListBounds == NativeRect.Empty ? element.DrawingBounds - : Rectangle.Union(drawableContainerListBounds, element.DrawingBounds); + : drawableContainerListBounds.Union(element.DrawingBounds); } // And find a location inside the target surface to paste to bool containersCanFit = drawableContainerListBounds.Width < Bounds.Width && drawableContainerListBounds.Height < Bounds.Height; if (!containersCanFit) { - Point containersLocation = drawableContainerListBounds.Location; + NativePoint containersLocation = drawableContainerListBounds.Location; containersLocation.Offset(moveOffset); if (!Bounds.Contains(containersLocation)) { // Easy fix for same surface moveOffset = isSameSurface - ? new Point(-10, -10) - : new Point(-drawableContainerListBounds.Location.X + 10, -drawableContainerListBounds.Location.Y + 10); + ? new NativePoint(-10, -10) + : new NativePoint(-drawableContainerListBounds.Location.X + 10, -drawableContainerListBounds.Location.Y + 10); } } else { - Rectangle moveContainerListBounds = drawableContainerListBounds; - moveContainerListBounds.Offset(moveOffset); + NativeRect moveContainerListBounds = drawableContainerListBounds.Offset(moveOffset); // check if the element is inside if (!Bounds.Contains(moveContainerListBounds)) { @@ -2272,7 +2269,7 @@ namespace Greenshot.Editor.Drawing } else if (ClipboardHelper.ContainsImage(clipboard)) { - Point pasteLocation = GetPasteLocation(0.1f, 0.1f); + NativePoint pasteLocation = GetPasteLocation(0.1f, 0.1f); foreach (var drawableContainer in ClipboardHelper.GetDrawables(clipboard)) { @@ -2282,13 +2279,12 @@ namespace Greenshot.Editor.Drawing drawableContainer.Top = pasteLocation.Y; AddElement(drawableContainer); SelectElement(drawableContainer); - pasteLocation.X += 10; - pasteLocation.Y += 10; + pasteLocation = pasteLocation.Offset(10, 10); } } else if (ClipboardHelper.ContainsText(clipboard)) { - Point pasteLocation = GetPasteLocation(0.4f, 0.4f); + NativePoint pasteLocation = GetPasteLocation(0.4f, 0.4f); string text = ClipboardHelper.GetText(clipboard); if (text != null) @@ -2308,13 +2304,13 @@ namespace Greenshot.Editor.Drawing /// /// 0.0f for the left edge of visible area, 1.0f for the right edge of visible area. /// 0.0f for the top edge of visible area, 1.0f for the bottom edge of visible area. - private Point GetPasteLocation(float horizontalRatio = 0.5f, float verticalRatio = 0.5f) + private NativePoint GetPasteLocation(float horizontalRatio = 0.5f, float verticalRatio = 0.5f) { var point = PointToClient(MousePosition); var rc = GetVisibleRectangle(); if (!rc.Contains(point)) { - point = new Point( + point = new NativePoint( rc.Left + (int) (rc.Width * horizontalRatio), rc.Top + (int) (rc.Height * verticalRatio) ); diff --git a/src/Greenshot.Editor/Drawing/SvgContainer.cs b/src/Greenshot.Editor/Drawing/SvgContainer.cs index f98f03a32..45847825f 100644 --- a/src/Greenshot.Editor/Drawing/SvgContainer.cs +++ b/src/Greenshot.Editor/Drawing/SvgContainer.cs @@ -21,6 +21,7 @@ using System; using System.Drawing; +using Dapplo.Windows.Common.Structs; using Greenshot.Base.Core; using Greenshot.Base.Interfaces; using Svg; @@ -56,6 +57,6 @@ namespace Greenshot.Editor.Drawing public override bool HasDefaultSize => true; - public override Size DefaultSize => new Size((int)_svgDocument.Width, (int)_svgDocument.Height); + public override NativeSize DefaultSize => new NativeSize((int)_svgDocument.Width, (int)_svgDocument.Height); } } \ No newline at end of file diff --git a/src/Greenshot.Editor/Drawing/TextContainer.cs b/src/Greenshot.Editor/Drawing/TextContainer.cs index 664b83b42..d69c1d321 100644 --- a/src/Greenshot.Editor/Drawing/TextContainer.cs +++ b/src/Greenshot.Editor/Drawing/TextContainer.cs @@ -176,7 +176,7 @@ namespace Greenshot.Editor.Drawing UpdateTextBoxFont(); } - public override void ApplyBounds(RectangleF newBounds) + public override void ApplyBounds(NativeRectFloat newBounds) { base.ApplyBounds(newBounds); UpdateTextBoxPosition(); @@ -509,8 +509,8 @@ namespace Greenshot.Editor.Drawing correction = -1; } - Rectangle absRectangle = new NativeRect(Left, Top, Width, Height).Normalize(); - Rectangle displayRectangle = Parent.ToSurfaceCoordinates(absRectangle); + var absRectangle = new NativeRect(Left, Top, Width, Height).Normalize(); + var displayRectangle = Parent.ToSurfaceCoordinates(absRectangle); _textBox.Left = displayRectangle.X + lineWidth; _textBox.Top = displayRectangle.Y + lineWidth; if (lineThickness <= 1) @@ -602,7 +602,7 @@ namespace Greenshot.Editor.Drawing graphics.PixelOffsetMode = PixelOffsetMode.None; graphics.TextRenderingHint = TextRenderingHint.SystemDefault; - Rectangle rect = new NativeRect(Left, Top, Width, Height).Normalize(); + var rect = new NativeRect(Left, Top, Width, Height).Normalize(); if (Selected && rm == RenderMode.EDIT) { DrawSelectionBorder(graphics, rect); diff --git a/src/Greenshot.Editor/FileFormatHandlers/DibFileFormatHandler.cs b/src/Greenshot.Editor/FileFormatHandlers/DibFileFormatHandler.cs index f4296f45e..d3c83d115 100644 --- a/src/Greenshot.Editor/FileFormatHandlers/DibFileFormatHandler.cs +++ b/src/Greenshot.Editor/FileFormatHandlers/DibFileFormatHandler.cs @@ -25,6 +25,8 @@ using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Runtime.InteropServices; +using Dapplo.Windows.Common.Structs; +using Dapplo.Windows.Common.TypeConverters; using Dapplo.Windows.Gdi32.Enums; using Dapplo.Windows.Gdi32.Structs; using Greenshot.Base.Core; @@ -128,7 +130,7 @@ namespace Greenshot.Editor.FileFormatHandlers { if (sourceBitmap == null) throw new ArgumentNullException(nameof(sourceBitmap)); - var area = new Rectangle(0, 0, sourceBitmap.Width, sourceBitmap.Height); + var area = new NativeRect(0, 0, sourceBitmap.Width, sourceBitmap.Height); // If the supplied format doesn't match 32bpp, we need to convert it first, and dispose the new bitmap afterwards bool needsDisposal = false; diff --git a/src/Greenshot.Editor/Forms/ColorPickerToolStripButton.cs b/src/Greenshot.Editor/Forms/ColorPickerToolStripButton.cs index 7a5123893..78f436e0e 100644 --- a/src/Greenshot.Editor/Forms/ColorPickerToolStripButton.cs +++ b/src/Greenshot.Editor/Forms/ColorPickerToolStripButton.cs @@ -24,6 +24,8 @@ using System.Diagnostics; using System.Drawing; using System.Drawing.Imaging; using System.Windows.Forms; +using Dapplo.Windows.Common.Extensions; +using Dapplo.Windows.Common.Structs; namespace Greenshot.Editor.Forms { @@ -32,7 +34,7 @@ namespace Greenshot.Editor.Forms public class ColorPickerToolStripButton : ToolStripButton { private Color _color; - public Point Offset = new Point(0, 0); + public NativePoint Offset = new NativePoint(0, 0); public event ColorPickerEventHandler ColorPicked; private readonly ColorDialog _cd; @@ -56,29 +58,24 @@ namespace Greenshot.Editor.Forms protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); - if (_color != null) + if (_color == null) return; + // replace transparent color with selected color + Graphics g = e.Graphics; + ColorMap[] colorMap = new ColorMap[1]; + colorMap[0] = new ColorMap { - // replace transparent color with selected color - Graphics g = e.Graphics; - //Graphics g = Graphics.FromImage(Image); - ColorMap[] colorMap = new ColorMap[1]; - colorMap[0] = new ColorMap - { - OldColor = Color.Magenta, //this.ImageTransparentColor; - NewColor = _color - }; - ImageAttributes attr = new ImageAttributes(); - attr.SetRemapTable(colorMap); - Rectangle rect = new Rectangle(0, 0, Image.Width, Image.Height); - // todo find a way to retrieve transparency offset automatically - // for now, we use the public variable Offset to define this manually - rect.Offset(Offset.X, Offset.Y); - //Image. - Debug.WriteLine("paint!" + Text + ": " + _color); - //ssif(color.Equals(Color.Transparent)) ((Bitmap)Image).MakeTransparent(Color.Magenta); - g.DrawImage(Image, rect, 0, 0, rect.Width, rect.Height, GraphicsUnit.Pixel, attr); - //this.Image.In - } + OldColor = Color.Magenta, //this.ImageTransparentColor; + NewColor = _color + }; + ImageAttributes attr = new ImageAttributes(); + attr.SetRemapTable(colorMap); + var rect = new NativeRect(0, 0, Image.Width, Image.Height); + // todo find a way to retrieve transparency offset automatically + // for now, we use the public variable Offset to define this manually + rect = rect.Offset(Offset.X, Offset.Y); + //ssif(color.Equals(Color.Transparent)) ((Bitmap)Image).MakeTransparent(Color.Magenta); + g.DrawImage(Image, rect, 0, 0, rect.Width, rect.Height, GraphicsUnit.Pixel, attr); + //this.Image.In } void ToolStripButton1Click(object sender, EventArgs e) diff --git a/src/Greenshot.Editor/Forms/ImageEditorForm.cs b/src/Greenshot.Editor/Forms/ImageEditorForm.cs index d6606665b..9c627accc 100644 --- a/src/Greenshot.Editor/Forms/ImageEditorForm.cs +++ b/src/Greenshot.Editor/Forms/ImageEditorForm.cs @@ -32,6 +32,7 @@ using Dapplo.Windows.Common.Extensions; using Dapplo.Windows.Common.Structs; using Dapplo.Windows.Dpi; using Dapplo.Windows.Kernel32; +using Dapplo.Windows.User32; using Dapplo.Windows.User32.Structs; using Greenshot.Base; using Greenshot.Base.Controls; @@ -53,7 +54,7 @@ using log4net; namespace Greenshot.Editor.Forms { /// - /// Description of ImageEditorForm. + /// The ImageEditorForm is the editor for Greenshot /// public partial class ImageEditorForm : EditorForm, IImageEditor { @@ -156,14 +157,12 @@ namespace Greenshot.Editor.Forms Name = "add destinations" }; thread.Start(); - - DpiChangedHandler(96, DeviceDpi); }; // Make sure the editor is placed on the same location as the last editor was on close // But only if this still exists, else it will be reset (BUG-1812) WindowPlacement editorWindowPlacement = EditorConfiguration.GetEditorPlacement(); - Rectangle screenBounds = WindowCapture.GetScreenBounds(); + NativeRect screenBounds = DisplayInfo.ScreenBounds; if (!screenBounds.Contains(editorWindowPlacement.NormalPosition)) { EditorConfiguration.ResetEditorPlacement(); @@ -322,7 +321,7 @@ namespace Greenshot.Editor.Forms if (cb.ComboBox == null) continue; // Calculate the rectangle - Rectangle r = new Rectangle(cb.ComboBox.Location.X - 1, cb.ComboBox.Location.Y - 1, cb.ComboBox.Size.Width + 1, cb.ComboBox.Size.Height + 1); + var r = new NativeRect(cb.ComboBox.Location.X - 1, cb.ComboBox.Location.Y - 1, cb.ComboBox.Size.Width + 1, cb.ComboBox.Size.Height + 1); // Draw the rectangle e.Graphics.DrawRectangle(cbBorderPen, r); @@ -1700,7 +1699,7 @@ namespace Greenshot.Editor.Forms /// private void ShrinkCanvasToolStripMenuItemClick(object sender, EventArgs e) { - Rectangle cropRectangle; + NativeRect cropRectangle; using (Image tmpImage = GetImageForExport()) { cropRectangle = ImageHelper.FindAutoCropRectangle(tmpImage, coreConfiguration.AutoCropDifference); diff --git a/src/Greenshot.Editor/Forms/MovableShowColorForm.cs b/src/Greenshot.Editor/Forms/MovableShowColorForm.cs index 65711e659..9a54ce6b6 100644 --- a/src/Greenshot.Editor/Forms/MovableShowColorForm.cs +++ b/src/Greenshot.Editor/Forms/MovableShowColorForm.cs @@ -22,8 +22,11 @@ using System; using System.Drawing; using System.Windows.Forms; +using Dapplo.Windows.Common.Extensions; +using Dapplo.Windows.Common.Structs; using Dapplo.Windows.Gdi32; using Dapplo.Windows.Gdi32.SafeHandles; +using Dapplo.Windows.User32; namespace Greenshot.Editor.Forms { @@ -46,8 +49,8 @@ namespace Greenshot.Editor.Forms /// /// Move the MovableShowColorForm to the specified location and display the color under the (current mouse) coordinates /// - /// Coordinates - public void MoveTo(Point screenCoordinates) + /// NativePoint with Coordinates + public void MoveTo(NativePoint screenCoordinates) { Color c = GetPixelColor(screenCoordinates); preview.BackColor = c; @@ -57,38 +60,36 @@ namespace Greenshot.Editor.Forms green.Text = string.Empty + c.G; alpha.Text = string.Empty + c.A; - Size cursorSize = Cursor.Current.Size; - Point hotspot = Cursor.Current.HotSpot; + NativeSize cursorSize = Cursor.Current.Size; + NativePoint hotspot = Cursor.Current.HotSpot; - Point zoomerLocation = new Point(screenCoordinates.X, screenCoordinates.Y); - zoomerLocation.X += cursorSize.Width + 5 - hotspot.X; - zoomerLocation.Y += cursorSize.Height + 5 - hotspot.Y; + var zoomerLocation = new NativePoint(screenCoordinates.X, screenCoordinates.Y) + .Offset(cursorSize.Width + 5 - hotspot.X, cursorSize.Height + 5 - hotspot.Y); - foreach (Screen screen in Screen.AllScreens) + foreach (var displayInfo in DisplayInfo.AllDisplayInfos) { - Rectangle screenRectangle = screen.Bounds; - if (screen.Bounds.Contains(screenCoordinates)) + NativeRect screenRectangle = displayInfo.Bounds; + if (!displayInfo.Bounds.Contains(screenCoordinates)) continue; + + if (zoomerLocation.X < screenRectangle.X) { - if (zoomerLocation.X < screenRectangle.X) - { - zoomerLocation.X = screenRectangle.X; - } - else if (zoomerLocation.X + Width > screenRectangle.X + screenRectangle.Width) - { - zoomerLocation.X = screenCoordinates.X - Width - 5 - hotspot.X; - } - - if (zoomerLocation.Y < screenRectangle.Y) - { - zoomerLocation.Y = screenRectangle.Y; - } - else if (zoomerLocation.Y + Height > screenRectangle.Y + screenRectangle.Height) - { - zoomerLocation.Y = screenCoordinates.Y - Height - 5 - hotspot.Y; - } - - break; + zoomerLocation = zoomerLocation.ChangeX(screenRectangle.X); } + else if (zoomerLocation.X + Width > screenRectangle.X + screenRectangle.Width) + { + zoomerLocation = zoomerLocation.ChangeX(screenCoordinates.X - Width - 5 - hotspot.X); + } + + if (zoomerLocation.Y < screenRectangle.Y) + { + zoomerLocation = zoomerLocation.ChangeY(screenRectangle.Y); + } + else if (zoomerLocation.Y + Height > screenRectangle.Y + screenRectangle.Height) + { + zoomerLocation = zoomerLocation.ChangeY(screenCoordinates.Y - Height - 5 - hotspot.Y); + } + + break; } Location = zoomerLocation; @@ -102,10 +103,10 @@ namespace Greenshot.Editor.Forms /// Color at the specified screenCoordinates private static Color GetPixelColor(Point screenCoordinates) { - using SafeWindowDcHandle screenDC = SafeWindowDcHandle.FromDesktop(); + using SafeWindowDcHandle safeWindowDcHandle = SafeWindowDcHandle.FromDesktop(); try { - uint pixel = Gdi32Api.GetPixel(screenDC, screenCoordinates.X, screenCoordinates.Y); + uint pixel = Gdi32Api.GetPixel(safeWindowDcHandle, screenCoordinates.X, screenCoordinates.Y); Color color = Color.FromArgb(255, (int) (pixel & 0xFF), (int) (pixel & 0xFF00) >> 8, (int) (pixel & 0xFF0000) >> 16); return color; } diff --git a/src/Greenshot.Editor/Helpers/ScaleHelper.cs b/src/Greenshot.Editor/Helpers/ScaleHelper.cs index 423fdf075..b75e8caad 100644 --- a/src/Greenshot.Editor/Helpers/ScaleHelper.cs +++ b/src/Greenshot.Editor/Helpers/ScaleHelper.cs @@ -22,6 +22,8 @@ using System; using System.Drawing; using System.Windows.Forms; +using Dapplo.Windows.Common.Extensions; +using Dapplo.Windows.Common.Structs; using Greenshot.Editor.Drawing; namespace Greenshot.Editor.Helpers @@ -118,7 +120,7 @@ namespace Greenshot.Editor.Helpers /// position of the handle/gripper being used for resized, see constants in Gripper.cs, e.g. Gripper.POSITION_TOP_LEFT /// coordinates of the used handle/gripper /// ScaleOptions to use when scaling - public static void Scale(ref RectangleF originalRectangle, Positions resizeHandlePosition, PointF resizeHandleCoords, ScaleOptions? options) + public static void Scale(ref NativeRectFloat originalRectangle, Positions resizeHandlePosition, NativePointFloat resizeHandleCoords, ScaleOptions? options) { options ??= GetScaleOptions(); @@ -135,8 +137,7 @@ namespace Greenshot.Editor.Helpers // scale rectangle using handle coordinates Scale(ref originalRectangle, resizeHandlePosition, resizeHandleCoords); // mirror handle coordinates via rectangle center coordinates - resizeHandleCoords.X -= 2 * (resizeHandleCoords.X - rectCenterX); - resizeHandleCoords.Y -= 2 * (resizeHandleCoords.Y - rectCenterY); + resizeHandleCoords = resizeHandleCoords.Offset(-2 * (resizeHandleCoords.X - rectCenterX), -2 * (resizeHandleCoords.Y - rectCenterY)); // scale again with opposing handle and mirrored coordinates resizeHandlePosition = (Positions) ((((int) resizeHandlePosition) + 4) % 8); Scale(ref originalRectangle, resizeHandlePosition, resizeHandleCoords); @@ -153,50 +154,72 @@ namespace Greenshot.Editor.Helpers /// bounds of the current rectangle, scaled values will be written to this reference /// position of the handle/gripper being used for resized, see constants in Gripper.cs, e.g. Gripper.POSITION_TOP_LEFT /// coordinates of the used handle/gripper - private static void Scale(ref RectangleF originalRectangle, Positions resizeHandlePosition, PointF resizeHandleCoords) + private static void Scale(ref NativeRectFloat originalRectangle, Positions resizeHandlePosition, NativePointFloat resizeHandleCoords) { switch (resizeHandlePosition) { case Positions.TopLeft: - originalRectangle.Width = originalRectangle.Left + originalRectangle.Width - resizeHandleCoords.X; - originalRectangle.Height = originalRectangle.Top + originalRectangle.Height - resizeHandleCoords.Y; - originalRectangle.X = resizeHandleCoords.X; - originalRectangle.Y = resizeHandleCoords.Y; + originalRectangle = new NativeRectFloat( + resizeHandleCoords.X, + resizeHandleCoords.Y, + originalRectangle.Left + originalRectangle.Width - resizeHandleCoords.X, + originalRectangle.Top + originalRectangle.Height - resizeHandleCoords.Y); break; case Positions.TopCenter: - originalRectangle.Height = originalRectangle.Top + originalRectangle.Height - resizeHandleCoords.Y; - originalRectangle.Y = resizeHandleCoords.Y; + originalRectangle = new NativeRectFloat( + originalRectangle.X, + resizeHandleCoords.Y, + originalRectangle.Width, + originalRectangle.Top + originalRectangle.Height - resizeHandleCoords.Y); break; case Positions.TopRight: - originalRectangle.Width = resizeHandleCoords.X - originalRectangle.Left; - originalRectangle.Height = originalRectangle.Top + originalRectangle.Height - resizeHandleCoords.Y; - originalRectangle.Y = resizeHandleCoords.Y; + originalRectangle = new NativeRectFloat( + originalRectangle.X, + resizeHandleCoords.Y, + resizeHandleCoords.X - originalRectangle.Left, + originalRectangle.Top + originalRectangle.Height - resizeHandleCoords.Y); break; case Positions.MiddleLeft: - originalRectangle.Width = originalRectangle.Left + originalRectangle.Width - resizeHandleCoords.X; - originalRectangle.X = resizeHandleCoords.X; + originalRectangle = new NativeRectFloat( + resizeHandleCoords.X, + originalRectangle.Y, + originalRectangle.Left + originalRectangle.Width - resizeHandleCoords.X, + originalRectangle.Height); break; case Positions.MiddleRight: - originalRectangle.Width = resizeHandleCoords.X - originalRectangle.Left; + originalRectangle = new NativeRectFloat( + originalRectangle.X, + originalRectangle.Y, + resizeHandleCoords.X - originalRectangle.Left, + originalRectangle.Height); break; case Positions.BottomLeft: - originalRectangle.Width = originalRectangle.Left + originalRectangle.Width - resizeHandleCoords.X; - originalRectangle.Height = resizeHandleCoords.Y - originalRectangle.Top; - originalRectangle.X = resizeHandleCoords.X; + originalRectangle = new NativeRectFloat( + resizeHandleCoords.X, + originalRectangle.Y, + originalRectangle.Left + originalRectangle.Width - resizeHandleCoords.X, + resizeHandleCoords.Y - originalRectangle.Top); break; case Positions.BottomCenter: - originalRectangle.Height = resizeHandleCoords.Y - originalRectangle.Top; + originalRectangle = new NativeRectFloat( + originalRectangle.X, + originalRectangle.Y, + originalRectangle.Width, + resizeHandleCoords.Y - originalRectangle.Top); break; case Positions.BottomRight: - originalRectangle.Width = resizeHandleCoords.X - originalRectangle.Left; - originalRectangle.Height = resizeHandleCoords.Y - originalRectangle.Top; + originalRectangle = new NativeRectFloat( + originalRectangle.X, + originalRectangle.Y, + resizeHandleCoords.X - originalRectangle.Left, + resizeHandleCoords.Y - originalRectangle.Top); break; default: @@ -213,7 +236,7 @@ namespace Greenshot.Editor.Helpers /// bounds of the current rectangle /// position of the handle/gripper being used for resized, see Position /// coordinates of the used handle/gripper, adjusted coordinates will be written to this reference - private static void AdjustCoordsForRationalScale(RectangleF originalRectangle, Positions resizeHandlePosition, ref PointF resizeHandleCoords) + private static void AdjustCoordsForRationalScale(NativeRectFloat originalRectangle, Positions resizeHandlePosition, ref NativePointFloat resizeHandleCoords) { SizeF selectedRectangle, newSize; @@ -222,29 +245,25 @@ namespace Greenshot.Editor.Helpers case Positions.TopLeft: selectedRectangle = new SizeF(originalRectangle.Right - resizeHandleCoords.X, originalRectangle.Bottom - resizeHandleCoords.Y); newSize = GetNewSizeForRationalScale(originalRectangle.Size, selectedRectangle); - resizeHandleCoords.X = originalRectangle.Right - newSize.Width; - resizeHandleCoords.Y = originalRectangle.Bottom - newSize.Height; + resizeHandleCoords = new NativePointFloat(originalRectangle.Right - newSize.Width, originalRectangle.Bottom - newSize.Height); break; case Positions.TopRight: selectedRectangle = new SizeF(resizeHandleCoords.X - originalRectangle.Left, originalRectangle.Bottom - resizeHandleCoords.Y); newSize = GetNewSizeForRationalScale(originalRectangle.Size, selectedRectangle); - resizeHandleCoords.X = originalRectangle.Left + newSize.Width; - resizeHandleCoords.Y = originalRectangle.Bottom - newSize.Height; + resizeHandleCoords = new NativePointFloat(originalRectangle.Left + newSize.Width, originalRectangle.Bottom - newSize.Height); break; case Positions.BottomLeft: selectedRectangle = new SizeF(originalRectangle.Right - resizeHandleCoords.X, resizeHandleCoords.Y - originalRectangle.Top); newSize = GetNewSizeForRationalScale(originalRectangle.Size, selectedRectangle); - resizeHandleCoords.X = originalRectangle.Right - newSize.Width; - resizeHandleCoords.Y = originalRectangle.Top + newSize.Height; + resizeHandleCoords = new NativePointFloat(originalRectangle.Right - newSize.Width, originalRectangle.Top + newSize.Height); break; case Positions.BottomRight: selectedRectangle = new SizeF(resizeHandleCoords.X - originalRectangle.Left, resizeHandleCoords.Y - originalRectangle.Top); newSize = GetNewSizeForRationalScale(originalRectangle.Size, selectedRectangle); - resizeHandleCoords.X = originalRectangle.Left + newSize.Width; - resizeHandleCoords.Y = originalRectangle.Top + newSize.Height; + resizeHandleCoords = new NativePointFloat(originalRectangle.Left + newSize.Width, originalRectangle.Top + newSize.Height); break; } } @@ -254,12 +273,12 @@ namespace Greenshot.Editor.Helpers /// * has the same aspect ratio as the original /// * fits into selected size /// - /// size to be considered for keeping aspect ratio - /// selection size (i.e. the size we'd produce if we wouldn't keep aspect ratio) + /// NativeSizeFloat to be considered for keeping aspect ratio + /// NativeSizeFloat selection size (i.e. the size we'd produce if we wouldn't keep aspect ratio) /// - private static SizeF GetNewSizeForRationalScale(SizeF originalSize, SizeF selectedSize) + private static NativeSizeFloat GetNewSizeForRationalScale(NativeSizeFloat originalSize, NativeSizeFloat selectedSize) { - SizeF newSize = selectedSize; + NativeSizeFloat newSize = selectedSize; float originalRatio = originalSize.Width / originalSize.Height; float selectedRatio = selectedSize.Width / selectedSize.Height; // will fix orientation if the scaling causes size to be flipped in any direction @@ -268,29 +287,29 @@ namespace Greenshot.Editor.Helpers { // scaled rectangle (ratio) would be wider than original // keep height and tweak width to maintain aspect ratio - newSize.Width = selectedSize.Height * originalRatio * flippedRatioSign; + newSize = newSize.ChangeWidth(selectedSize.Height * originalRatio * flippedRatioSign); } else if (Math.Abs(selectedRatio) < Math.Abs(originalRatio)) { // scaled rectangle (ratio) would be taller than original // keep width and tweak height to maintain aspect ratio - newSize.Height = selectedSize.Width / originalRatio * flippedRatioSign; + newSize = newSize.ChangeWidth(selectedSize.Width / originalRatio * flippedRatioSign); } return newSize; } - public static void Scale(Rectangle boundsBeforeResize, int cursorX, int cursorY, ref RectangleF boundsAfterResize) + public static void Scale(NativeRect boundsBeforeResize, int cursorX, int cursorY, ref NativeRectFloat boundsAfterResize) { Scale(boundsBeforeResize, cursorX, cursorY, ref boundsAfterResize, null); } - public static void Scale(Rectangle boundsBeforeResize, int cursorX, int cursorY, ref RectangleF boundsAfterResize, IDoubleProcessor angleRoundBehavior) + public static void Scale(NativeRect boundsBeforeResize, int cursorX, int cursorY, ref NativeRectFloat boundsAfterResize, IDoubleProcessor angleRoundBehavior) { Scale(boundsBeforeResize, Positions.TopLeft, cursorX, cursorY, ref boundsAfterResize, angleRoundBehavior); } - public static void Scale(Rectangle boundsBeforeResize, Positions gripperPosition, int cursorX, int cursorY, ref RectangleF boundsAfterResize, + public static void Scale(NativeRect boundsBeforeResize, Positions gripperPosition, int cursorX, int cursorY, ref NativeRectFloat boundsAfterResize, IDoubleProcessor angleRoundBehavior) { ScaleOptions opts = GetScaleOptions(); @@ -309,18 +328,16 @@ namespace Greenshot.Editor.Helpers int dist = GeometryHelper.Distance2D(boundsBeforeResize.X, boundsBeforeResize.Y, cursorX, cursorY); - boundsAfterResize.Width = (int) Math.Round(dist * Math.Cos(angle / 180 * Math.PI)); - boundsAfterResize.Height = (int) Math.Round(dist * Math.Sin(angle / 180 * Math.PI)); + boundsAfterResize = boundsAfterResize + .ChangeWidth((int)Math.Round(dist * Math.Cos(angle / 180 * Math.PI))) + .ChangeHeight((int) Math.Round(dist * Math.Sin(angle / 180 * Math.PI))); } if (centeredScale) { float wdiff = boundsAfterResize.Width - boundsBeforeResize.Width; float hdiff = boundsAfterResize.Height - boundsBeforeResize.Height; - boundsAfterResize.Width += wdiff; - boundsAfterResize.Height += hdiff; - boundsAfterResize.X -= wdiff; - boundsAfterResize.Y -= hdiff; + boundsAfterResize = boundsAfterResize.Inflate(wdiff, hdiff); } } diff --git a/src/Greenshot.Plugin.Win10/Win10OcrProvider.cs b/src/Greenshot.Plugin.Win10/Win10OcrProvider.cs index fdc0c07fa..e33909581 100644 --- a/src/Greenshot.Plugin.Win10/Win10OcrProvider.cs +++ b/src/Greenshot.Plugin.Win10/Win10OcrProvider.cs @@ -26,6 +26,7 @@ using System.Threading.Tasks; using Windows.Graphics.Imaging; using Windows.Media.Ocr; using Windows.Storage.Streams; +using Dapplo.Windows.Common.Structs; using Greenshot.Base.Core; using Greenshot.Base.Core.Enums; using Greenshot.Base.Effects; @@ -169,7 +170,7 @@ namespace Greenshot.Plugin.Win10 for (var index = 0; index < ocrLine.Words.Count; index++) { var ocrWord = ocrLine.Words[index]; - var location = new Rectangle((int) ocrWord.BoundingRect.X, (int) ocrWord.BoundingRect.Y, + var location = new NativeRect((int) ocrWord.BoundingRect.X, (int) ocrWord.BoundingRect.Y, (int) ocrWord.BoundingRect.Width, (int) ocrWord.BoundingRect.Height); var word = line.Words[index]; diff --git a/src/Greenshot/Forms/AboutForm.cs b/src/Greenshot/Forms/AboutForm.cs index 744d87e04..484a16b42 100644 --- a/src/Greenshot/Forms/AboutForm.cs +++ b/src/Greenshot/Forms/AboutForm.cs @@ -73,40 +73,40 @@ namespace Greenshot.Forms private readonly List _gSpots = new List { // Top row - new NativePoint(P2, P1), // 0 - new NativePoint(P3, P1), // 1 - new NativePoint(P4, P1), // 2 - new NativePoint(P5, P1), // 3 - new NativePoint(P6, P1), // 4 + new(P2, P1), // 0 + new(P3, P1), // 1 + new(P4, P1), // 2 + new(P5, P1), // 3 + new(P6, P1), // 4 // Second row - new NativePoint(P1, P2), // 5 - new NativePoint(P2, P2), // 6 + new(P1, P2), // 5 + new(P2, P2), // 6 // Third row - new NativePoint(P1, P3), // 7 - new NativePoint(P2, P3), // 8 + new(P1, P3), // 7 + new(P2, P3), // 8 // Fourth row - new NativePoint(P1, P4), // 9 - new NativePoint(P2, P4), // 10 - new NativePoint(P5, P4), // 11 - new NativePoint(P6, P4), // 12 - new NativePoint(P7, P4), // 13 + new(P1, P4), // 9 + new(P2, P4), // 10 + new(P5, P4), // 11 + new(P6, P4), // 12 + new(P7, P4), // 13 // Fifth row - new NativePoint(P1, P5), // 14 - new NativePoint(P2, P5), // 15 - new NativePoint(P6, P5), // 16 - new NativePoint(P7, P5), // 17 + new(P1, P5), // 14 + new(P2, P5), // 15 + new(P6, P5), // 16 + new(P7, P5), // 17 // Sixth row - new NativePoint(P1, P6), // 18 - new NativePoint(P2, P6), // 19 - new NativePoint(P3, P6), // 20 - new NativePoint(P4, P6), // 21 - new NativePoint(P5, P6), // 22 - new NativePoint(P6, P6) // 23 + new(P1, P6), // 18 + new(P2, P6), // 19 + new(P3, P6), // 20 + new(P4, P6), // 21 + new(P5, P6), // 22 + new(P6, P6) // 23 }; // 0 1 2 3 4 @@ -166,7 +166,7 @@ namespace Greenshot.Forms for (int index = 0; index < _gSpots.Count; index++) { // Read the pixels in the order of the flow - Point gSpot = _gSpots[_flowOrder[index]]; + NativePoint gSpot = _gSpots[_flowOrder[index]]; // Create the animation, first we do nothing (on the final destination) RectangleAnimator pixelAnimation; diff --git a/src/Greenshot/Forms/CaptureForm.cs b/src/Greenshot/Forms/CaptureForm.cs index 575195bd7..6844c8b1c 100644 --- a/src/Greenshot/Forms/CaptureForm.cs +++ b/src/Greenshot/Forms/CaptureForm.cs @@ -92,7 +92,7 @@ namespace Greenshot.Forms /// /// Property to access the selected capture rectangle /// - public Rectangle CaptureRectangle => _captureRect; + public NativeRect CaptureRectangle => _captureRect; /// /// Property to access the used capture mode @@ -182,7 +182,7 @@ namespace Greenshot.Forms // Initialize the animations, the window capture zooms out from the cursor to the window under the cursor if (_captureMode == CaptureMode.Window) { - _windowAnimator = new RectangleAnimator(new Rectangle(_cursorPos, Size.Empty), _captureRect, FramesForMillis(700), EasingType.Quintic, EasingMode.EaseOut); + _windowAnimator = new RectangleAnimator(new NativeRect(_cursorPos, Size.Empty), _captureRect, FramesForMillis(700), EasingType.Quintic, EasingMode.EaseOut); } // Set the zoomer animation @@ -321,7 +321,7 @@ namespace Greenshot.Forms InitializeZoomer(false); // "Fade in" window _windowAnimator = new RectangleAnimator(new NativeRect(_cursorPos, NativeSize.Empty), _captureRect, FramesForMillis(700), EasingType.Quintic, EasingMode.EaseOut); - _captureRect = Rectangle.Empty; + _captureRect = NativeRect.Empty; Invalidate(); break; case CaptureMode.Text: @@ -436,7 +436,7 @@ namespace Greenshot.Forms else if (_captureMode == CaptureMode.Text && IsWordUnderCursor(_mouseMovePos)) { // Handle a click on a single word - _captureRect = new Rectangle(_mouseMovePos, new Size(1, 1)); + _captureRect = new NativeRect(_mouseMovePos, new NativeSize(1, 1)); // Go and process the capture DialogResult = DialogResult.OK; } @@ -605,7 +605,7 @@ namespace Greenshot.Forms // Here we want to capture the window which is under the mouse _captureRect = _selectedCaptureWindow.WindowRectangle; // As the ClientRectangle is not in Bitmap coordinates, we need to correct. - _captureRect.Offset(-_capture.ScreenBounds.Location.X, -_capture.ScreenBounds.Location.Y); + _captureRect = _captureRect.Offset(-_capture.ScreenBounds.Location.X, -_capture.ScreenBounds.Location.Y); } } @@ -647,7 +647,7 @@ namespace Greenshot.Forms { if (!IsTerminalServerSession) { - NativeRect allScreenBounds = WindowCapture.GetScreenBounds(); + var allScreenBounds = DisplayInfo.ScreenBounds; allScreenBounds = allScreenBounds.MoveTo(WindowCapture.GetLocationRelativeToScreenBounds(allScreenBounds.Location)); if (verticalMove) { @@ -791,50 +791,49 @@ namespace Greenshot.Forms /// false to try to find a location which is neither out of screen bounds nor intersects with the selected rectangle private void VerifyZoomAnimation(Point pos, bool allowZoomOverCaptureRect) { - Rectangle screenBounds = Screen.GetBounds(MousePosition); + NativeRect screenBounds = DisplayInfo.GetBounds(MousePosition); // convert to be relative to top left corner of all screen bounds - screenBounds.Location = WindowCapture.GetLocationRelativeToScreenBounds(screenBounds.Location); + screenBounds = screenBounds.MoveTo(WindowCapture.GetLocationRelativeToScreenBounds(screenBounds.Location)); int relativeZoomSize = Math.Min(screenBounds.Width, screenBounds.Height) / 5; // Make sure the final size is a plural of 4, this makes it look better relativeZoomSize -= relativeZoomSize % 4; - Size zoomSize = new Size(relativeZoomSize, relativeZoomSize); - Point zoomOffset = new Point(20, 20); + var zoomSize = new NativeSize(relativeZoomSize, relativeZoomSize); + var zoomOffset = new NativePoint(20, 20); - Rectangle targetRectangle = _zoomAnimator.Final; - targetRectangle.Offset(pos); + NativeRect targetRectangle = _zoomAnimator.Final.Offset(pos); if (screenBounds.Contains(targetRectangle) && (allowZoomOverCaptureRect || !_captureRect.IntersectsWith(targetRectangle))) { return; } - Point destinationLocation = Point.Empty; - Rectangle tl = new Rectangle(pos.X - (zoomOffset.X + zoomSize.Width), pos.Y - (zoomOffset.Y + zoomSize.Height), zoomSize.Width, zoomSize.Height); - Rectangle tr = new Rectangle(pos.X + zoomOffset.X, pos.Y - (zoomOffset.Y + zoomSize.Height), zoomSize.Width, zoomSize.Height); - Rectangle bl = new Rectangle(pos.X - (zoomOffset.X + zoomSize.Width), pos.Y + zoomOffset.Y, zoomSize.Width, zoomSize.Height); - Rectangle br = new Rectangle(pos.X + zoomOffset.X, pos.Y + zoomOffset.Y, zoomSize.Width, zoomSize.Height); + var destinationLocation = NativePoint.Empty; + var tl = new NativeRect(pos.X - (zoomOffset.X + zoomSize.Width), pos.Y - (zoomOffset.Y + zoomSize.Height), zoomSize.Width, zoomSize.Height); + var tr = new NativeRect(pos.X + zoomOffset.X, pos.Y - (zoomOffset.Y + zoomSize.Height), zoomSize.Width, zoomSize.Height); + var bl = new NativeRect(pos.X - (zoomOffset.X + zoomSize.Width), pos.Y + zoomOffset.Y, zoomSize.Width, zoomSize.Height); + var br = new NativeRect(pos.X + zoomOffset.X, pos.Y + zoomOffset.Y, zoomSize.Width, zoomSize.Height); if (screenBounds.Contains(br) && (allowZoomOverCaptureRect || !_captureRect.IntersectsWith(br))) { - destinationLocation = new Point(zoomOffset.X, zoomOffset.Y); + destinationLocation = new NativePoint(zoomOffset.X, zoomOffset.Y); } else if (screenBounds.Contains(bl) && (allowZoomOverCaptureRect || !_captureRect.IntersectsWith(bl))) { - destinationLocation = new Point(-zoomOffset.X - zoomSize.Width, zoomOffset.Y); + destinationLocation = new NativePoint(-zoomOffset.X - zoomSize.Width, zoomOffset.Y); } else if (screenBounds.Contains(tr) && (allowZoomOverCaptureRect || !_captureRect.IntersectsWith(tr))) { - destinationLocation = new Point(zoomOffset.X, -zoomOffset.Y - zoomSize.Width); + destinationLocation = new NativePoint(zoomOffset.X, -zoomOffset.Y - zoomSize.Width); } else if (screenBounds.Contains(tl) && (allowZoomOverCaptureRect || !_captureRect.IntersectsWith(tl))) { - destinationLocation = new Point(-zoomOffset.X - zoomSize.Width, -zoomOffset.Y - zoomSize.Width); + destinationLocation = new NativePoint(-zoomOffset.X - zoomSize.Width, -zoomOffset.Y - zoomSize.Width); } - if (destinationLocation == Point.Empty && !allowZoomOverCaptureRect) + if (destinationLocation == NativePoint.Empty && !allowZoomOverCaptureRect) { VerifyZoomAnimation(pos, true); } else { - _zoomAnimator.ChangeDestination(new Rectangle(destinationLocation, zoomSize)); + _zoomAnimator.ChangeDestination(new NativeRect(destinationLocation, zoomSize)); } } @@ -844,7 +843,7 @@ namespace Greenshot.Forms /// /// /// - private void DrawZoom(Graphics graphics, Rectangle sourceRectangle, Rectangle destinationRectangle) + private void DrawZoom(Graphics graphics, NativeRect sourceRectangle, NativeRect destinationRectangle) { if (_capture.Image == null) { @@ -957,7 +956,7 @@ namespace Greenshot.Forms private void OnPaint(object sender, PaintEventArgs e) { Graphics graphics = e.Graphics; - Rectangle clipRectangle = e.ClipRectangle; + NativeRect clipRectangle = e.ClipRectangle; //graphics.BitBlt((Bitmap)buffer, Point.Empty); graphics.DrawImageUnscaled(_capture.Image, Point.Empty); @@ -1005,7 +1004,7 @@ namespace Greenshot.Forms } // Only draw Cursor if it's (partly) visible - if (_capture.Cursor != null && _capture.CursorVisible && clipRectangle.IntersectsWith(new Rectangle(_capture.CursorLocation, _capture.Cursor.Size))) + if (_capture.Cursor != null && _capture.CursorVisible && clipRectangle.IntersectsWith(new NativeRect(_capture.CursorLocation, _capture.Cursor.Size))) { graphics.DrawIcon(_capture.Cursor, _capture.CursorLocation.X, _capture.CursorLocation.Y); } @@ -1141,7 +1140,7 @@ namespace Greenshot.Forms using (Pen pen = new Pen(Color.LightSeaGreen)) { pen.DashStyle = DashStyle.Dot; - Rectangle screenBounds = _capture.ScreenBounds; + NativeRect screenBounds = _capture.ScreenBounds; graphics.DrawLine(pen, _cursorPos.X, screenBounds.Y, _cursorPos.X, screenBounds.Height); graphics.DrawLine(pen, screenBounds.X, _cursorPos.Y, screenBounds.Width, _cursorPos.Y); } @@ -1170,10 +1169,10 @@ namespace Greenshot.Forms const int zoomSourceWidth = 25; const int zoomSourceHeight = 25; - Rectangle sourceRectangle = new Rectangle(_cursorPos.X - zoomSourceWidth / 2, _cursorPos.Y - zoomSourceHeight / 2, zoomSourceWidth, zoomSourceHeight); + var sourceRectangle = new NativeRect(_cursorPos.X - zoomSourceWidth / 2, _cursorPos.Y - zoomSourceHeight / 2, zoomSourceWidth, zoomSourceHeight); - Rectangle destinationRectangle = _zoomAnimator.Current; - destinationRectangle.Offset(_cursorPos); + var destinationRectangle = _zoomAnimator.Current; + destinationRectangle = destinationRectangle.Offset(_cursorPos); DrawZoom(graphics, sourceRectangle, destinationRectangle); } } diff --git a/src/Greenshot/Forms/MainForm.cs b/src/Greenshot/Forms/MainForm.cs index 78044981a..081084d0b 100644 --- a/src/Greenshot/Forms/MainForm.cs +++ b/src/Greenshot/Forms/MainForm.cs @@ -32,9 +32,11 @@ using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using System.Windows.Forms.Integration; +using Dapplo.Windows.Common.Structs; using Dapplo.Windows.DesktopWindowsManager; using Dapplo.Windows.Dpi; using Dapplo.Windows.Kernel32; +using Dapplo.Windows.User32; using Greenshot.Base; using Greenshot.Base.Controls; using Greenshot.Base.Core; @@ -1003,7 +1005,7 @@ namespace Greenshot.Forms var factor = DeviceDpi / 96f; contextMenu.Scale(new SizeF(factor, factor)); contextmenu_captureclipboard.Enabled = ClipboardHelper.ContainsImage(); - contextmenu_capturelastregion.Enabled = coreConfiguration.LastCapturedRegion != Rectangle.Empty; + contextmenu_capturelastregion.Enabled = coreConfiguration.LastCapturedRegion != NativeRect.Empty; // IE context menu code try @@ -1125,51 +1127,50 @@ namespace Greenshot.Forms { ToolStripMenuItem captureScreenMenuItem = (ToolStripMenuItem) sender; captureScreenMenuItem.DropDownItems.Clear(); - if (Screen.AllScreens.Length > 1) - { - Rectangle allScreensBounds = WindowCapture.GetScreenBounds(); + if (DisplayInfo.AllDisplayInfos.Length <= 1) return; - var captureScreenItem = new ToolStripMenuItem(Language.GetString(LangKey.contextmenu_capturefullscreen_all)); - captureScreenItem.Click += delegate { - BeginInvoke((MethodInvoker) delegate { - CaptureHelper.CaptureFullscreen(false, ScreenCaptureMode.FullScreen); + var allScreensBounds = DisplayInfo.ScreenBounds; + + var captureScreenItem = new ToolStripMenuItem(Language.GetString(LangKey.contextmenu_capturefullscreen_all)); + captureScreenItem.Click += delegate { + BeginInvoke((MethodInvoker) delegate { + CaptureHelper.CaptureFullscreen(false, ScreenCaptureMode.FullScreen); + }); + }; + + captureScreenMenuItem.DropDownItems.Add(captureScreenItem); + foreach (var displayInfo in DisplayInfo.AllDisplayInfos) + { + var displayToCapture = displayInfo; + string deviceAlignment = displayToCapture.DeviceName; + + if (displayInfo.Bounds.Top == allScreensBounds.Top && displayInfo.Bounds.Bottom != allScreensBounds.Bottom) + { + deviceAlignment += " " + Language.GetString(LangKey.contextmenu_capturefullscreen_top); + } + else if (displayInfo.Bounds.Top != allScreensBounds.Top && displayInfo.Bounds.Bottom == allScreensBounds.Bottom) + { + deviceAlignment += " " + Language.GetString(LangKey.contextmenu_capturefullscreen_bottom); + } + + if (displayInfo.Bounds.Left == allScreensBounds.Left && displayInfo.Bounds.Right != allScreensBounds.Right) + { + deviceAlignment += " " + Language.GetString(LangKey.contextmenu_capturefullscreen_left); + } + else if (displayInfo.Bounds.Left != allScreensBounds.Left && displayInfo.Bounds.Right == allScreensBounds.Right) + { + deviceAlignment += " " + Language.GetString(LangKey.contextmenu_capturefullscreen_right); + } + + captureScreenItem = new ToolStripMenuItem(deviceAlignment); + captureScreenItem.Click += delegate + { + BeginInvoke((MethodInvoker) delegate + { + CaptureHelper.CaptureRegion(false, displayToCapture.Bounds); }); }; - captureScreenMenuItem.DropDownItems.Add(captureScreenItem); - foreach (Screen screen in Screen.AllScreens) - { - Screen screenToCapture = screen; - string deviceAlignment = screenToCapture.DeviceName; - - if (screen.Bounds.Top == allScreensBounds.Top && screen.Bounds.Bottom != allScreensBounds.Bottom) - { - deviceAlignment += " " + Language.GetString(LangKey.contextmenu_capturefullscreen_top); - } - else if (screen.Bounds.Top != allScreensBounds.Top && screen.Bounds.Bottom == allScreensBounds.Bottom) - { - deviceAlignment += " " + Language.GetString(LangKey.contextmenu_capturefullscreen_bottom); - } - - if (screen.Bounds.Left == allScreensBounds.Left && screen.Bounds.Right != allScreensBounds.Right) - { - deviceAlignment += " " + Language.GetString(LangKey.contextmenu_capturefullscreen_left); - } - else if (screen.Bounds.Left != allScreensBounds.Left && screen.Bounds.Right == allScreensBounds.Right) - { - deviceAlignment += " " + Language.GetString(LangKey.contextmenu_capturefullscreen_right); - } - - captureScreenItem = new ToolStripMenuItem(deviceAlignment); - captureScreenItem.Click += delegate - { - BeginInvoke((MethodInvoker) delegate - { - CaptureHelper.CaptureRegion(false, screenToCapture.Bounds); - }); - }; - captureScreenMenuItem.DropDownItems.Add(captureScreenItem); - } } } diff --git a/src/Greenshot/Helpers/CaptureHelper.cs b/src/Greenshot/Helpers/CaptureHelper.cs index c59b94fb7..46c3e7892 100644 --- a/src/Greenshot/Helpers/CaptureHelper.cs +++ b/src/Greenshot/Helpers/CaptureHelper.cs @@ -363,8 +363,7 @@ namespace Greenshot.Helpers _capture = WindowCapture.CaptureRectangle(_capture, screen.Bounds); captureTaken = true; // As the screen shot might be on a different monitor we need to correct the mouse location - var correctedCursorLocation = _capture.CursorLocation; - correctedCursorLocation.Offset(-screen.Bounds.Location.X, -screen.Bounds.Location.Y); + var correctedCursorLocation = _capture.CursorLocation.Offset(-screen.Bounds.Location.X, -screen.Bounds.Location.Y); _capture.CursorLocation = correctedCursorLocation; break; } @@ -877,7 +876,7 @@ namespace Greenshot.Helpers /// WindowDetails with the target Window OR a replacement public static WindowDetails SelectCaptureWindow(WindowDetails windowToCapture) { - Rectangle windowRectangle = windowToCapture.WindowRectangle; + NativeRect windowRectangle = windowToCapture.WindowRectangle; if (windowRectangle.Width == 0 || windowRectangle.Height == 0) { Log.WarnFormat("Window {0} has nothing to capture, using workaround to find other window of same process.", windowToCapture.Text); @@ -1220,8 +1219,7 @@ namespace Greenshot.Helpers // save for re-capturing later and show recapture context menu option // Important here is that the location needs to be offsetted back to screen coordinates! - Rectangle tmpRectangle = _captureRect; - tmpRectangle.Offset(_capture.ScreenBounds.Location.X, _capture.ScreenBounds.Location.Y); + NativeRect tmpRectangle = _captureRect.Offset(_capture.ScreenBounds.Location.X, _capture.ScreenBounds.Location.Y); CoreConfig.LastCapturedRegion = tmpRectangle; } diff --git a/src/Greenshot/Helpers/IECaptureHelper.cs b/src/Greenshot/Helpers/IECaptureHelper.cs index 464034ecd..baf35e16a 100644 --- a/src/Greenshot/Helpers/IECaptureHelper.cs +++ b/src/Greenshot/Helpers/IECaptureHelper.cs @@ -25,6 +25,7 @@ using System.Drawing; using System.Drawing.Imaging; using System.Linq; using System.Runtime.InteropServices; +using Dapplo.Windows.Common.Extensions; using Dapplo.Windows.Common.Structs; using Dapplo.Windows.Messages; using Dapplo.Windows.User32; @@ -760,9 +761,9 @@ namespace Greenshot.Helpers // Crop to clientRectangle if (ImageHelper.Crop(ref fragment, ref clientRectangle)) { - Point targetLocation = new Point(documentContainer.DestinationLocation.X, documentContainer.DestinationLocation.Y); + NativePoint targetLocation = new NativePoint(documentContainer.DestinationLocation.X, documentContainer.DestinationLocation.Y); Log.DebugFormat("Fragment targetLocation is {0}", targetLocation); - targetLocation.Offset(targetOffset); + targetLocation = targetLocation.Offset(targetOffset); Log.DebugFormat("After offsetting the fragment targetLocation is {0}", targetLocation); Log.DebugFormat("Drawing fragment of size {0} to {1}", fragment.Size, targetLocation); graphicsTarget.DrawImage(fragment, targetLocation); diff --git a/src/Greenshot/Helpers/IEInterop/IEContainer.cs b/src/Greenshot/Helpers/IEInterop/IEContainer.cs index ff433d9d5..7d741a992 100644 --- a/src/Greenshot/Helpers/IEInterop/IEContainer.cs +++ b/src/Greenshot/Helpers/IEInterop/IEContainer.cs @@ -150,7 +150,7 @@ namespace Greenshot.Helpers.IEInterop // Do not release IHTMLDocument5 com object, as this also gives problems with the document2! //Marshal.ReleaseComObject(document5); - Rectangle clientRectangle = contentWindow.WindowRectangle; + NativeRect clientRectangle = contentWindow.WindowRectangle; try { IHTMLWindow2 window2 = document2.parentWindow; @@ -184,9 +184,9 @@ namespace Greenshot.Helpers.IEInterop // If there is a border AND a scrollbar the diff == 20 if ((diffX == 4 || diffX >= 20) && (diffY == 4 || diffY >= 20)) { - Point viewportOffset = new Point(2, 2); - Size viewportSize = new Size(ClientWidth, ClientHeight); - _viewportRectangle = new Rectangle(viewportOffset, viewportSize); + var viewportOffset = new NativePoint(2, 2); + var viewportSize = new NativeSize(ClientWidth, ClientHeight); + _viewportRectangle = new NativeRect(viewportOffset, viewportSize); LOG.DebugFormat("viewportRect {0}", _viewportRectangle); } } @@ -517,15 +517,15 @@ namespace Greenshot.Helpers.IEInterop public int ScrollHeight => ScaleY(GetAttributeAsInt("scrollHeight")); - public Point SourceLocation + public NativePoint SourceLocation { get { return _sourceLocation; } set { _sourceLocation = value; } } - public Size SourceSize => new Size(ClientWidth, ClientHeight); + public NativeSize SourceSize => new NativeSize(ClientWidth, ClientHeight); - public Rectangle SourceRectangle => new Rectangle(SourceLocation, SourceSize); + public NativeRect SourceRectangle => new NativeRect(SourceLocation, SourceSize); public int SourceLeft => _sourceLocation.X; @@ -535,15 +535,15 @@ namespace Greenshot.Helpers.IEInterop public int SourceBottom => _sourceLocation.Y + ClientHeight; - public Point DestinationLocation + public NativePoint DestinationLocation { get { return _destinationLocation; } set { _destinationLocation = value; } } - public Size DestinationSize => new Size(ScrollWidth, ScrollHeight); + public NativeSize DestinationSize => new NativeSize(ScrollWidth, ScrollHeight); - public Rectangle DestinationRectangle => new Rectangle(DestinationLocation, DestinationSize); + public NativeRect DestinationRectangle => new NativeRect(DestinationLocation, DestinationSize); public int DestinationLeft {