Some more small changes from Point to NativePoint etc, also some small code changes.

This commit is contained in:
Robin Krom 2022-04-09 09:38:56 +02:00
commit f900299cc8
No known key found for this signature in database
GPG key ID: BCC01364F1371490
26 changed files with 107 additions and 161 deletions

View file

@ -396,10 +396,10 @@ namespace Greenshot.Base.Controls
protected void ApplyLanguage(Control applyTo) protected void ApplyLanguage(Control applyTo)
{ {
if (!(applyTo is IGreenshotLanguageBindable languageBindable)) if (applyTo is not IGreenshotLanguageBindable languageBindable)
{ {
// check if it's a menu! // check if it's a menu!
if (!(applyTo is ToolStrip toolStrip)) if (applyTo is not ToolStrip toolStrip)
{ {
return; return;
} }
@ -416,21 +416,15 @@ namespace Greenshot.Base.Controls
ApplyLanguage(applyTo, languageBindable.LanguageKey); ApplyLanguage(applyTo, languageBindable.LanguageKey);
// Repopulate the combox boxes // Repopulate the combox boxes
if (applyTo is IGreenshotConfigBindable configBindable && applyTo is GreenshotComboBox comboxBox) if (applyTo is not (IGreenshotConfigBindable configBindable and GreenshotComboBox comboxBox)) return;
{ if (string.IsNullOrEmpty(configBindable.SectionName) || string.IsNullOrEmpty(configBindable.PropertyName)) return;
if (!string.IsNullOrEmpty(configBindable.SectionName) && !string.IsNullOrEmpty(configBindable.PropertyName))
{
IniSection section = IniConfig.GetIniSection(configBindable.SectionName); IniSection section = IniConfig.GetIniSection(configBindable.SectionName);
if (section != null) if (section == null) return;
{
// Only update the language, so get the actual value and than repopulate // Only update the language, so get the actual value and than repopulate
Enum currentValue = comboxBox.GetSelectedEnum(); Enum currentValue = comboxBox.GetSelectedEnum();
comboxBox.Populate(section.Values[configBindable.PropertyName].ValueType); comboxBox.Populate(section.Values[configBindable.PropertyName].ValueType);
comboxBox.SetValue(currentValue); comboxBox.SetValue(currentValue);
} }
}
}
}
/// <summary> /// <summary>
/// Helper method to cache the fieldinfo values, so we don't need to reflect all the time! /// Helper method to cache the fieldinfo values, so we don't need to reflect all the time!
@ -472,10 +466,9 @@ namespace Greenshot.Base.Controls
continue; continue;
} }
if (!(controlObject is Control applyToControl)) if (controlObject is not Control applyToControl)
{ {
ToolStripItem applyToItem = controlObject as ToolStripItem; if (controlObject is not ToolStripItem applyToItem)
if (applyToItem == null)
{ {
LOG.DebugFormat("No Control or ToolStripItem: {0}", field.Name); LOG.DebugFormat("No Control or ToolStripItem: {0}", field.Name);
continue; continue;

View file

@ -44,7 +44,7 @@ namespace Greenshot.Base.Core
public virtual int CompareTo(object obj) public virtual int CompareTo(object obj)
{ {
if (!(obj is IDestination other)) if (obj is not IDestination other)
{ {
return 1; return 1;
} }

View file

@ -284,6 +284,9 @@ EndSelection:<<<<<<<4
{ {
if (dataObject == null) return false; if (dataObject == null) return false;
IList<string> formats = GetFormats(dataObject);
Log.DebugFormat("Found formats: {0}", string.Join(",", formats));
if (dataObject.GetDataPresent(DataFormats.Bitmap) if (dataObject.GetDataPresent(DataFormats.Bitmap)
|| dataObject.GetDataPresent(DataFormats.Dib) || dataObject.GetDataPresent(DataFormats.Dib)
|| dataObject.GetDataPresent(DataFormats.Tiff) || dataObject.GetDataPresent(DataFormats.Tiff)

View file

@ -3,6 +3,8 @@ using System.ComponentModel;
using System.Drawing; using System.Drawing;
using System.Globalization; using System.Globalization;
using System.Text; using System.Text;
using Dapplo.Windows.Common.Extensions;
using Dapplo.Windows.Common.Structs;
using Greenshot.Base.Effects; using Greenshot.Base.Effects;
namespace Greenshot.Base.Core namespace Greenshot.Base.Core
@ -136,16 +138,16 @@ namespace Greenshot.Base.Core
break; break;
case "ShadowOffset": case "ShadowOffset":
Point shadowOffset = new Point(); NativePoint shadowOffset = new NativePoint();
string[] coordinates = pair[1].Split(','); string[] coordinates = pair[1].Split(',');
if (int.TryParse(coordinates[0], out var shadowOffsetX)) if (int.TryParse(coordinates[0], out var shadowOffsetX))
{ {
shadowOffset.X = shadowOffsetX; shadowOffset = shadowOffset.ChangeX(shadowOffsetX);
} }
if (int.TryParse(coordinates[1], out var shadowOffsetY)) if (int.TryParse(coordinates[1], out var shadowOffsetY))
{ {
shadowOffset.Y = shadowOffsetY; shadowOffset = shadowOffset.ChangeY(shadowOffsetY);
} }
effect.ShadowOffset = shadowOffset; effect.ShadowOffset = shadowOffset;

View file

@ -384,7 +384,7 @@ namespace Greenshot.Base.Core
protected FastBitmap(Bitmap bitmap, NativeRect area) protected FastBitmap(Bitmap bitmap, NativeRect area)
{ {
Bitmap = bitmap; Bitmap = bitmap;
var bitmapArea = new NativeRect(Point.Empty, bitmap.Size); var bitmapArea = new NativeRect(NativePoint.Empty, bitmap.Size);
if (area != NativeRect.Empty) if (area != NativeRect.Empty)
{ {
area = area.Intersect(bitmapArea); area = area.Intersect(bitmapArea);

View file

@ -191,7 +191,7 @@ namespace Greenshot.Base.Core
/// Private helper method for the FindAutoCropNativeRect /// Private helper method for the FindAutoCropNativeRect
/// </summary> /// </summary>
/// <param name="fastBitmap">IFastBitmap</param> /// <param name="fastBitmap">IFastBitmap</param>
/// <param name="colorPoint">Point</param> /// <param name="colorPoint">NativePoint</param>
/// <param name="cropDifference">int</param> /// <param name="cropDifference">int</param>
/// <param name="area">NativeRect with optional area to scan in</param> /// <param name="area">NativeRect with optional area to scan in</param>
/// <returns>NativeRect</returns> /// <returns>NativeRect</returns>

View file

@ -558,46 +558,6 @@ namespace Greenshot.Base.Core
return fileImage; return fileImage;
} }
/// <summary>
/// Based on: https://www.codeproject.com/KB/cs/IconExtractor.aspx
/// And a hint from: https://www.codeproject.com/KB/cs/IconLib.aspx
/// </summary>
/// <param name="iconStream">Stream with the icon information</param>
/// <returns>Bitmap with the Vista Icon (256x256)</returns>
private static Bitmap ExtractVistaIcon(Stream iconStream)
{
const int sizeIconDir = 6;
const int sizeIconDirEntry = 16;
Bitmap bmpPngExtracted = null;
try
{
byte[] srcBuf = new byte[iconStream.Length];
iconStream.Read(srcBuf, 0, (int)iconStream.Length);
int iCount = BitConverter.ToInt16(srcBuf, 4);
for (int iIndex = 0; iIndex < iCount; iIndex++)
{
int iWidth = srcBuf[sizeIconDir + sizeIconDirEntry * iIndex];
int iHeight = srcBuf[sizeIconDir + sizeIconDirEntry * iIndex + 1];
if (iWidth == 0 && iHeight == 0)
{
int iImageSize = BitConverter.ToInt32(srcBuf, sizeIconDir + sizeIconDirEntry * iIndex + 8);
int iImageOffset = BitConverter.ToInt32(srcBuf, sizeIconDir + sizeIconDirEntry * iIndex + 12);
using MemoryStream destStream = new MemoryStream();
destStream.Write(srcBuf, iImageOffset, iImageSize);
destStream.Seek(0, SeekOrigin.Begin);
bmpPngExtracted = new Bitmap(destStream); // This is PNG! :)
break;
}
}
}
catch
{
return null;
}
return bmpPngExtracted;
}
/// <summary> /// <summary>
/// Create an image from a stream, if an extension is supplied more formats are supported. /// Create an image from a stream, if an extension is supplied more formats are supported.
/// </summary> /// </summary>

View file

@ -113,7 +113,7 @@ namespace Greenshot.Base.Core
/// </summary> /// </summary>
/// <param name="path">path to the exe or dll</param> /// <param name="path">path to the exe or dll</param>
/// <param name="index">index of the icon</param> /// <param name="index">index of the icon</param>
/// <returns>Bitmap with the icon or null if something happended</returns> /// <returns>Bitmap with the icon or null if something happened</returns>
public static Image GetCachedExeIcon(string path, int index) public static Image GetCachedExeIcon(string path, int index)
{ {
string cacheKey = $"{path}:{index}"; string cacheKey = $"{path}:{index}";
@ -148,7 +148,7 @@ namespace Greenshot.Base.Core
/// </summary> /// </summary>
/// <param name="path">path to the exe or dll</param> /// <param name="path">path to the exe or dll</param>
/// <param name="index">index of the icon</param> /// <param name="index">index of the icon</param>
/// <returns>Bitmap with the icon or null if something happended</returns> /// <returns>Bitmap with the icon or null if something happened</returns>
private static Bitmap GetExeIcon(string path, int index) private static Bitmap GetExeIcon(string path, int index)
{ {
if (!File.Exists(path)) if (!File.Exists(path))
@ -164,7 +164,6 @@ namespace Greenshot.Base.Core
Log.DebugFormat("Loaded icon for {0}, with dimensions {1}x{2}", path, appIcon.Width, appIcon.Height); Log.DebugFormat("Loaded icon for {0}, with dimensions {1}x{2}", path, appIcon.Width, appIcon.Height);
return appIcon; return appIcon;
} }
return appIcon;
} }
catch (Exception exIcon) catch (Exception exIcon)
{ {

View file

@ -96,12 +96,12 @@ namespace Greenshot.Base.Core
using SafeIconHandle safeIcon = NativeIconMethods.CopyIcon(cursorInfo.CursorHandle); using SafeIconHandle safeIcon = NativeIconMethods.CopyIcon(cursorInfo.CursorHandle);
if (!NativeIconMethods.GetIconInfo(safeIcon, out var iconInfo)) return capture; if (!NativeIconMethods.GetIconInfo(safeIcon, out var iconInfo)) return capture;
Point cursorLocation = User32Api.GetCursorLocation(); NativePoint cursorLocation = User32Api.GetCursorLocation();
// Align cursor location to Bitmap coordinates (instead of Screen coordinates) // Align cursor location to Bitmap coordinates (instead of Screen coordinates)
var x = cursorLocation.X - iconInfo.Hotspot.X - capture.ScreenBounds.X; var x = cursorLocation.X - iconInfo.Hotspot.X - capture.ScreenBounds.X;
var y = cursorLocation.Y - iconInfo.Hotspot.Y - capture.ScreenBounds.Y; var y = cursorLocation.Y - iconInfo.Hotspot.Y - capture.ScreenBounds.Y;
// Set the location // Set the location
capture.CursorLocation = new Point(x, y); capture.CursorLocation = new NativePoint(x, y);
using (Icon icon = Icon.FromHandle(safeIcon.DangerousGetHandle())) using (Icon icon = Icon.FromHandle(safeIcon.DangerousGetHandle()))
{ {

View file

@ -1515,9 +1515,9 @@ namespace Greenshot.Base.Core
/// <summary> /// <summary>
/// Recursive "find children which" /// Recursive "find children which"
/// </summary> /// </summary>
/// <param name="point">point to check for</param> /// <param name="point">NativePoint to check for</param>
/// <returns></returns> /// <returns>WindowDetails</returns>
public WindowDetails FindChildUnderPoint(Point point) public WindowDetails FindChildUnderPoint(NativePoint point)
{ {
if (!Contains(point)) if (!Contains(point))
{ {

View file

@ -23,6 +23,7 @@ using System.ComponentModel;
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using Dapplo.Windows.Common.Structs;
using Greenshot.Base.Core; using Greenshot.Base.Core;
namespace Greenshot.Base.Effects namespace Greenshot.Base.Effects
@ -42,7 +43,7 @@ namespace Greenshot.Base.Effects
public int ShadowSize { get; set; } public int ShadowSize { get; set; }
public Point ShadowOffset { get; set; } public NativePoint ShadowOffset { get; set; }
public virtual void Reset() public virtual void Reset()
{ {

View file

@ -129,7 +129,7 @@ namespace Greenshot.Editor.Controls
{ {
//Release Capture should consume MouseUp when canceled with the escape key //Release Capture should consume MouseUp when canceled with the escape key
User32Api.ReleaseCapture(); User32Api.ReleaseCapture();
PipetteUsed?.Invoke(this, new PipetteUsedArgs(_movableShowColorForm.color)); PipetteUsed?.Invoke(this, new PipetteUsedArgs(_movableShowColorForm.Color));
} }
base.OnMouseUp(e); base.OnMouseUp(e);

View file

@ -55,23 +55,18 @@ namespace Greenshot.Editor.Drawing.Adorners
isNotSwitched = !isNotSwitched; isNotSwitched = !isNotSwitched;
} }
switch (Position) return Position switch
{ {
case Positions.TopLeft: Positions.TopLeft => isNotSwitched ? Cursors.SizeNWSE : Cursors.SizeNESW,
case Positions.BottomRight: Positions.BottomRight => isNotSwitched ? Cursors.SizeNWSE : Cursors.SizeNESW,
return isNotSwitched ? Cursors.SizeNWSE : Cursors.SizeNESW; Positions.TopRight => isNotSwitched ? Cursors.SizeNESW : Cursors.SizeNWSE,
case Positions.TopRight: Positions.BottomLeft => isNotSwitched ? Cursors.SizeNESW : Cursors.SizeNWSE,
case Positions.BottomLeft: Positions.MiddleLeft => Cursors.SizeWE,
return isNotSwitched ? Cursors.SizeNESW : Cursors.SizeNWSE; Positions.MiddleRight => Cursors.SizeWE,
case Positions.MiddleLeft: Positions.TopCenter => Cursors.SizeNS,
case Positions.MiddleRight: Positions.BottomCenter => Cursors.SizeNS,
return Cursors.SizeWE; _ => Cursors.SizeAll
case Positions.TopCenter: };
case Positions.BottomCenter:
return Cursors.SizeNS;
default:
return Cursors.SizeAll;
}
} }
} }

View file

@ -54,7 +54,7 @@ namespace Greenshot.Editor.Drawing
/// This is the offset for the shadow version of the bitmap /// This is the offset for the shadow version of the bitmap
/// Do not serialize, as the offset is recreated /// Do not serialize, as the offset is recreated
/// </summary> /// </summary>
[NonSerialized] private Point _shadowOffset = new Point(-1, -1); [NonSerialized] private NativePoint _shadowOffset = new NativePoint(-1, -1);
public ImageContainer(ISurface parent, string filename) : this(parent) public ImageContainer(ISurface parent, string filename) : this(parent)
{ {

View file

@ -42,7 +42,7 @@ namespace Greenshot.Editor.Drawing
private NativePoint _initialGripperPoint; private NativePoint _initialGripperPoint;
// Only used for serializing the TargetGripper location // Only used for serializing the TargetGripper location
private Point _storedTargetGripperLocation; private NativePoint _storedTargetGripperLocation;
/// <summary> /// <summary>
/// Store the current location of the target gripper /// Store the current location of the target gripper
@ -96,8 +96,8 @@ namespace Greenshot.Editor.Drawing
{ {
if (TargetAdorner == null) if (TargetAdorner == null)
{ {
_initialGripperPoint = new Point(mouseX, mouseY); _initialGripperPoint = new NativePoint(mouseX, mouseY);
InitTargetAdorner(new Point(mouseX, mouseY)); InitTargetAdorner(_initialGripperPoint);
} }
return base.HandleMouseDown(mouseX, mouseY); return base.HandleMouseDown(mouseX, mouseY);

View file

@ -1012,7 +1012,7 @@ namespace Greenshot.Editor.Drawing
public void Clear(Color newColor) public void Clear(Color newColor)
{ {
//create a blank bitmap the same size as original //create a blank bitmap the same size as original
Bitmap newBitmap = ImageHelper.CreateEmptyLike(Image, Color.Empty); Bitmap newBitmap = ImageHelper.CreateEmptyLike(Image, newColor);
if (newBitmap == null) return; if (newBitmap == null) return;
// Make undoable // Make undoable
MakeUndoable(new SurfaceBackgroundChangeMemento(this, null), false); MakeUndoable(new SurfaceBackgroundChangeMemento(this, null), false);
@ -2112,10 +2112,7 @@ namespace Greenshot.Editor.Drawing
} }
// maybe the undo button has to be enabled // maybe the undo button has to be enabled
if (_movingElementChanged != null) _movingElementChanged?.Invoke(this, new SurfaceElementEventArgs());
{
_movingElementChanged(this, new SurfaceElementEventArgs());
}
} }
/// <summary> /// <summary>
@ -2150,10 +2147,7 @@ namespace Greenshot.Editor.Drawing
DrawingMode = DrawingModes.None; DrawingMode = DrawingModes.None;
// maybe the undo button has to be enabled // maybe the undo button has to be enabled
if (_movingElementChanged != null) _movingElementChanged?.Invoke(this, new SurfaceElementEventArgs());
{
_movingElementChanged(this, new SurfaceElementEventArgs());
}
} }
public void RemoveCropContainer() public void RemoveCropContainer()
@ -2195,7 +2189,7 @@ namespace Greenshot.Editor.Drawing
// Make element(s) only move 10,10 if the surface is the same // Make element(s) only move 10,10 if the surface is the same
bool isSameSurface = (dcs.ParentID == _uniqueId); bool isSameSurface = (dcs.ParentID == _uniqueId);
dcs.Parent = this; dcs.Parent = this;
var moveOffset = isSameSurface ? new Point(10, 10) : Point.Empty; var moveOffset = isSameSurface ? new NativePoint(10, 10) : NativePoint.Empty;
// Here a fix for bug #1475, first calculate the bounds of the complete IDrawableContainerList // Here a fix for bug #1475, first calculate the bounds of the complete IDrawableContainerList
NativeRect drawableContainerListBounds = NativeRect.Empty; NativeRect drawableContainerListBounds = NativeRect.Empty;
foreach (var element in dcs) foreach (var element in dcs)
@ -2485,24 +2479,24 @@ namespace Greenshot.Editor.Drawing
bool shiftModifier = (ModifierKeys & Keys.Shift) == Keys.Shift; bool shiftModifier = (ModifierKeys & Keys.Shift) == Keys.Shift;
int px = shiftModifier ? 10 : 1; int px = shiftModifier ? 10 : 1;
Point moveBy = Point.Empty; NativePoint moveBy = NativePoint.Empty;
switch (k) switch (k)
{ {
case Keys.Left: case Keys.Left:
case Keys.Left | Keys.Shift: case Keys.Left | Keys.Shift:
moveBy = new Point(-px, 0); moveBy = new NativePoint(-px, 0);
break; break;
case Keys.Up: case Keys.Up:
case Keys.Up | Keys.Shift: case Keys.Up | Keys.Shift:
moveBy = new Point(0, -px); moveBy = new NativePoint(0, -px);
break; break;
case Keys.Right: case Keys.Right:
case Keys.Right | Keys.Shift: case Keys.Right | Keys.Shift:
moveBy = new Point(px, 0); moveBy = new NativePoint(px, 0);
break; break;
case Keys.Down: case Keys.Down:
case Keys.Down | Keys.Shift: case Keys.Down | Keys.Shift:
moveBy = new Point(0, px); moveBy = new NativePoint(0, px);
break; break;
case Keys.PageUp: case Keys.PageUp:
PullElementsUp(); PullElementsUp();
@ -2580,7 +2574,7 @@ namespace Greenshot.Editor.Drawing
return false; return false;
} }
if (!Point.Empty.Equals(moveBy)) if (moveBy != NativePoint.Empty)
{ {
selectedElements.MakeBoundsChangeUndoable(true); selectedElements.MakeBoundsChangeUndoable(true);
selectedElements.MoveBy(moveBy.X, moveBy.Y); selectedElements.MoveBy(moveBy.X, moveBy.Y);

View file

@ -34,7 +34,7 @@ namespace Greenshot.Editor.Drawing
[Serializable] [Serializable]
public class SvgContainer : VectorGraphicsContainer public class SvgContainer : VectorGraphicsContainer
{ {
private SvgDocument _svgDocument; private readonly SvgDocument _svgDocument;
public SvgContainer(SvgDocument svgDocument, ISurface parent) : base(parent) public SvgContainer(SvgDocument svgDocument, ISurface parent) : base(parent)
{ {

View file

@ -291,7 +291,7 @@ namespace Greenshot.Editor.Drawing
}; };
_textBox.DataBindings.Add("Text", this, "Text", false, DataSourceUpdateMode.OnPropertyChanged); _textBox.DataBindings.Add("Text", this, "Text", false, DataSourceUpdateMode.OnPropertyChanged);
_textBox.LostFocus += textBox_LostFocus; _textBox.LostFocus += TextBox_LostFocus;
_textBox.KeyDown += textBox_KeyDown; _textBox.KeyDown += textBox_KeyDown;
} }
@ -585,7 +585,7 @@ namespace Greenshot.Editor.Drawing
} }
} }
private void textBox_LostFocus(object sender, EventArgs e) private void TextBox_LostFocus(object sender, EventArgs e)
{ {
// next change will be made undoable // next change will be made undoable
makeUndoable = true; makeUndoable = true;

View file

@ -22,6 +22,7 @@
using System; using System;
using System.Drawing; using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
using Dapplo.Windows.Common.Structs;
using Greenshot.Base.Effects; using Greenshot.Base.Effects;
namespace Greenshot.Editor.Forms namespace Greenshot.Editor.Forms
@ -51,7 +52,7 @@ namespace Greenshot.Editor.Forms
private void ButtonOK_Click(object sender, EventArgs e) private void ButtonOK_Click(object sender, EventArgs e)
{ {
_effect.Darkness = trackBar1.Value / (float) 40; _effect.Darkness = trackBar1.Value / (float) 40;
_effect.ShadowOffset = new Point((int) offsetX.Value, (int) offsetY.Value); _effect.ShadowOffset = new NativePoint((int) offsetX.Value, (int) offsetY.Value);
_effect.ShadowSize = (int) thickness.Value; _effect.ShadowSize = (int) thickness.Value;
DialogResult = DialogResult.OK; DialogResult = DialogResult.OK;
} }

View file

@ -36,7 +36,7 @@ namespace Greenshot.Editor.Forms
/// </summary> /// </summary>
public partial class MovableShowColorForm : Form public partial class MovableShowColorForm : Form
{ {
public Color color public Color Color
{ {
get { return preview.BackColor; } get { return preview.BackColor; }
} }
@ -99,9 +99,9 @@ namespace Greenshot.Editor.Forms
/// <summary> /// <summary>
/// Get the color from the pixel on the screen at "x,y" /// Get the color from the pixel on the screen at "x,y"
/// </summary> /// </summary>
/// <param name="screenCoordinates">Point with the coordinates</param> /// <param name="screenCoordinates">NativePoint with the coordinates</param>
/// <returns>Color at the specified screenCoordinates</returns> /// <returns>Color at the specified screenCoordinates</returns>
private static Color GetPixelColor(Point screenCoordinates) private static Color GetPixelColor(NativePoint screenCoordinates)
{ {
using SafeWindowDcHandle safeWindowDcHandle = SafeWindowDcHandle.FromDesktop(); using SafeWindowDcHandle safeWindowDcHandle = SafeWindowDcHandle.FromDesktop();
try try

View file

@ -20,8 +20,8 @@
*/ */
using System; using System;
using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
using Dapplo.Windows.Common.Structs;
using Greenshot.Base.Effects; using Greenshot.Base.Effects;
namespace Greenshot.Editor.Forms namespace Greenshot.Editor.Forms
@ -56,7 +56,7 @@ namespace Greenshot.Editor.Forms
private void ButtonOK_Click(object sender, EventArgs e) private void ButtonOK_Click(object sender, EventArgs e)
{ {
_effect.Darkness = shadowDarkness.Value / (float) 40; _effect.Darkness = shadowDarkness.Value / (float) 40;
_effect.ShadowOffset = new Point((int) offsetX.Value, (int) offsetY.Value); _effect.ShadowOffset = new NativePoint((int) offsetX.Value, (int) offsetY.Value);
_effect.ShadowSize = (int) thickness.Value; _effect.ShadowSize = (int) thickness.Value;
_effect.ToothHeight = (int) toothsize.Value; _effect.ToothHeight = (int) toothsize.Value;
_effect.VerticalToothRange = (int) verticaltoothrange.Value; _effect.VerticalToothRange = (int) verticaltoothrange.Value;

View file

@ -219,7 +219,7 @@ namespace Greenshot.Forms
/// <param name="e"></param> /// <param name="e"></param>
private void LinkLabelClicked(object sender, LinkLabelLinkClickedEventArgs e) private void LinkLabelClicked(object sender, LinkLabelLinkClickedEventArgs e)
{ {
if (!(sender is LinkLabel linkLabel)) return; if (sender is not LinkLabel linkLabel) return;
var link = linkLabel.Tag?.ToString() ?? linkLabel.Text; var link = linkLabel.Tag?.ToString() ?? linkLabel.Text;
try try
{ {

View file

@ -73,7 +73,7 @@ namespace Greenshot.Forms
private int _mX; private int _mX;
private int _mY; private int _mY;
private NativePoint _mouseMovePos = Point.Empty; private NativePoint _mouseMovePos = NativePoint.Empty;
private NativePoint _cursorPos; private NativePoint _cursorPos;
private CaptureMode _captureMode; private CaptureMode _captureMode;
private readonly List<WindowDetails> _windows; private readonly List<WindowDetails> _windows;
@ -404,7 +404,7 @@ namespace Greenshot.Forms
private void HandleMouseDown() private void HandleMouseDown()
{ {
Point tmpCursorLocation = WindowCapture.GetCursorLocationRelativeToScreenBounds(); NativePoint tmpCursorLocation = WindowCapture.GetCursorLocationRelativeToScreenBounds();
_mX = tmpCursorLocation.X; _mX = tmpCursorLocation.X;
_mY = tmpCursorLocation.Y; _mY = tmpCursorLocation.Y;
_mouseDown = true; _mouseDown = true;
@ -508,11 +508,11 @@ namespace Greenshot.Forms
} }
else if (_fixMode == FixMode.Vertical) else if (_fixMode == FixMode.Vertical)
{ {
currentMouse = new Point(currentMouse.X, _previousMousePos.Y); currentMouse = new NativePoint(currentMouse.X, _previousMousePos.Y);
} }
else if (_fixMode == FixMode.Horizontal) else if (_fixMode == FixMode.Horizontal)
{ {
currentMouse = new Point(_previousMousePos.X, currentMouse.Y); currentMouse = new NativePoint(_previousMousePos.X, currentMouse.Y);
} }
_previousMousePos = currentMouse; _previousMousePos = currentMouse;
@ -551,7 +551,7 @@ namespace Greenshot.Forms
/// </summary> /// </summary>
protected override void Animate() protected override void Animate()
{ {
Point lastPos = _cursorPos; NativePoint lastPos = _cursorPos;
_cursorPos = _mouseMovePos; _cursorPos = _mouseMovePos;
if (_selectedCaptureWindow != null && lastPos.Equals(_cursorPos) && !IsAnimating(_zoomAnimator) && !IsAnimating(_windowAnimator)) if (_selectedCaptureWindow != null && lastPos.Equals(_cursorPos) && !IsAnimating(_zoomAnimator) && !IsAnimating(_windowAnimator))
@ -579,7 +579,7 @@ namespace Greenshot.Forms
} }
// Iterate over the found windows and check if the current location is inside a window // Iterate over the found windows and check if the current location is inside a window
Point cursorPosition = Cursor.Position; NativePoint cursorPosition = Cursor.Position;
_selectedCaptureWindow = null; _selectedCaptureWindow = null;
lock (_windows) lock (_windows)
{ {
@ -789,7 +789,7 @@ namespace Greenshot.Forms
/// </summary> /// </summary>
/// <param name="pos">preferred destination location for the zoom area</param> /// <param name="pos">preferred destination location for the zoom area</param>
/// <param name="allowZoomOverCaptureRect">false to try to find a location which is neither out of screen bounds nor intersects with the selected rectangle</param> /// <param name="allowZoomOverCaptureRect">false to try to find a location which is neither out of screen bounds nor intersects with the selected rectangle</param>
private void VerifyZoomAnimation(Point pos, bool allowZoomOverCaptureRect) private void VerifyZoomAnimation(NativePoint pos, bool allowZoomOverCaptureRect)
{ {
NativeRect screenBounds = DisplayInfo.GetBounds(MousePosition); NativeRect screenBounds = DisplayInfo.GetBounds(MousePosition);
// convert to be relative to top left corner of all screen bounds // convert to be relative to top left corner of all screen bounds

View file

@ -507,15 +507,13 @@ namespace Greenshot.Helpers
// Set capture title, fixing bug #3569703 // Set capture title, fixing bug #3569703
foreach (WindowDetails window in WindowDetails.GetVisibleWindows()) foreach (WindowDetails window in WindowDetails.GetVisibleWindows())
{ {
Point estimatedLocation = new Point(CoreConfig.LastCapturedRegion.X + CoreConfig.LastCapturedRegion.Width / 2, NativePoint estimatedLocation = new NativePoint(CoreConfig.LastCapturedRegion.X + CoreConfig.LastCapturedRegion.Width / 2,
CoreConfig.LastCapturedRegion.Y + CoreConfig.LastCapturedRegion.Height / 2); CoreConfig.LastCapturedRegion.Y + CoreConfig.LastCapturedRegion.Height / 2);
if (window.Contains(estimatedLocation)) if (!window.Contains(estimatedLocation)) continue;
{
_selectedCaptureWindow = window; _selectedCaptureWindow = window;
_capture.CaptureDetails.Title = _selectedCaptureWindow.Text; _capture.CaptureDetails.Title = _selectedCaptureWindow.Text;
break; break;
} }
}
// Move cursor, fixing bug #3569703 // Move cursor, fixing bug #3569703
_capture.MoveMouseLocation(_capture.ScreenBounds.Location.X - _capture.Location.X, _capture.ScreenBounds.Location.Y - _capture.Location.Y); _capture.MoveMouseLocation(_capture.ScreenBounds.Location.X - _capture.Location.X, _capture.ScreenBounds.Location.Y - _capture.Location.Y);

View file

@ -722,14 +722,14 @@ namespace Greenshot.Helpers
int horizontalPage = 0; int horizontalPage = 0;
// The location of the browser, used as the destination into the bitmap target // The location of the browser, used as the destination into the bitmap target
Point targetOffset = new Point(); NativePoint targetOffset = NativePoint.Empty;
// Loop of the pages and make a copy of the visible viewport // Loop of the pages and make a copy of the visible viewport
while (horizontalPage * viewportWidth < pageWidth) while (horizontalPage * viewportWidth < pageWidth)
{ {
// Scroll to location // Scroll to location
documentContainer.ScrollLeft = viewportWidth * horizontalPage; documentContainer.ScrollLeft = viewportWidth * horizontalPage;
targetOffset.X = documentContainer.ScrollLeft; targetOffset = targetOffset.ChangeX(documentContainer.ScrollLeft);
// Variable used for looping vertically // Variable used for looping vertically
int verticalPage = 0; int verticalPage = 0;
@ -738,7 +738,7 @@ namespace Greenshot.Helpers
// Scroll to location // Scroll to location
documentContainer.ScrollTop = viewportHeight * verticalPage; documentContainer.ScrollTop = viewportHeight * verticalPage;
//Shoot visible window //Shoot visible window
targetOffset.Y = documentContainer.ScrollTop; targetOffset = targetOffset.ChangeY(documentContainer.ScrollTop);
// Draw the captured fragment to the target, but "crop" the scrollbars etc while capturing // Draw the captured fragment to the target, but "crop" the scrollbars etc while capturing
NativeSize viewPortSize = new NativeSize(viewportWidth, viewportHeight); NativeSize viewPortSize = new NativeSize(viewportWidth, viewportHeight);

View file

@ -40,11 +40,11 @@ namespace Greenshot.Helpers.IEInterop
private static readonly Guid IID_IWebBrowserApp = new Guid("0002DF05-0000-0000-C000-000000000046"); private static readonly Guid IID_IWebBrowserApp = new Guid("0002DF05-0000-0000-C000-000000000046");
private static readonly Guid IID_IWebBrowser2 = new Guid("D30C1661-CDAF-11D0-8A3E-00C04FC9E26E"); private static readonly Guid IID_IWebBrowser2 = new Guid("D30C1661-CDAF-11D0-8A3E-00C04FC9E26E");
private static int _counter; private static int _counter;
private readonly NativePoint _startLocation = NativePoint.Empty;
private IHTMLDocument2 _document2; private IHTMLDocument2 _document2;
private IHTMLDocument3 _document3; private IHTMLDocument3 _document3;
private NativePoint _sourceLocation; private NativePoint _sourceLocation;
private NativePoint _destinationLocation; private NativePoint _destinationLocation;
private NativePoint _startLocation = NativePoint.Empty;
private NativeRect _viewportRectangle = NativeRect.Empty; private NativeRect _viewportRectangle = NativeRect.Empty;
private bool _isDtd; private bool _isDtd;
private DocumentContainer _parent; private DocumentContainer _parent;
@ -90,15 +90,15 @@ namespace Greenshot.Helpers.IEInterop
// Calculate startLocation for the frames // Calculate startLocation for the frames
IHTMLWindow2 window2 = document2.parentWindow; IHTMLWindow2 window2 = document2.parentWindow;
IHTMLWindow3 window3 = (IHTMLWindow3) window2; IHTMLWindow3 window3 = (IHTMLWindow3) window2;
Point contentWindowLocation = contentWindow.WindowRectangle.Location; NativePoint contentWindowLocation = contentWindow.WindowRectangle.Location;
int x = window3.screenLeft - contentWindowLocation.X; int x = window3.screenLeft - contentWindowLocation.X;
int y = window3.screenTop - contentWindowLocation.Y; int y = window3.screenTop - contentWindowLocation.Y;
// Release IHTMLWindow 2+3 com objects // Release IHTMLWindow 2+3 com objects
releaseCom(window2); ReleaseCom(window2);
releaseCom(window3); ReleaseCom(window3);
_startLocation = new Point(x, y); _startLocation = new NativePoint(x, y);
Init(document2, contentWindow); Init(document2, contentWindow);
} }
@ -112,7 +112,7 @@ namespace Greenshot.Helpers.IEInterop
/// Helper method to release com objects /// Helper method to release com objects
/// </summary> /// </summary>
/// <param name="comObject"></param> /// <param name="comObject"></param>
private void releaseCom(object comObject) private void ReleaseCom(object comObject)
{ {
if (comObject != null) if (comObject != null)
{ {
@ -182,7 +182,7 @@ namespace Greenshot.Helpers.IEInterop
int diffY = clientRectangle.Height - ClientHeight; int diffY = clientRectangle.Height - ClientHeight;
// If there is a border around the inner window, the diff == 4 // If there is a border around the inner window, the diff == 4
// If there is a border AND a scrollbar the diff == 20 // If there is a border AND a scrollbar the diff == 20
if ((diffX == 4 || diffX >= 20) && (diffY == 4 || diffY >= 20)) if (diffX is 4 or >= 20 && diffY is 4 or >= 20)
{ {
var viewportOffset = new NativePoint(2, 2); var viewportOffset = new NativePoint(2, 2);
var viewportSize = new NativeSize(ClientWidth, ClientHeight); var viewportSize = new NativeSize(ClientWidth, ClientHeight);
@ -193,9 +193,9 @@ namespace Greenshot.Helpers.IEInterop
LOG.DebugFormat("Zoomlevel {0}, {1}", _zoomLevelX, _zoomLevelY); LOG.DebugFormat("Zoomlevel {0}, {1}", _zoomLevelX, _zoomLevelY);
// Release com objects // Release com objects
releaseCom(window2); ReleaseCom(window2);
releaseCom(screen); ReleaseCom(screen);
releaseCom(screen2); ReleaseCom(screen2);
} }
catch (Exception e) catch (Exception e)
{ {
@ -225,8 +225,8 @@ namespace Greenshot.Helpers.IEInterop
LOG.Warn("Problem while trying to get document url!", e); LOG.Warn("Problem while trying to get document url!", e);
} }
_sourceLocation = new Point(ScaleX(_startLocation.X), ScaleY(_startLocation.Y)); _sourceLocation = new NativePoint(ScaleX(_startLocation.X), ScaleY(_startLocation.Y));
_destinationLocation = new Point(ScaleX(_startLocation.X), ScaleY(_startLocation.Y)); _destinationLocation = new NativePoint(ScaleX(_startLocation.X), ScaleY(_startLocation.Y));
if (_parent != null) if (_parent != null)
{ {
@ -254,7 +254,7 @@ namespace Greenshot.Helpers.IEInterop
} }
// Clean up frameWindow // Clean up frameWindow
releaseCom(frameWindow); ReleaseCom(frameWindow);
} }
catch (Exception e) catch (Exception e)
{ {
@ -263,7 +263,7 @@ namespace Greenshot.Helpers.IEInterop
} }
// Clean up collection // Clean up collection
releaseCom(frameCollection); ReleaseCom(frameCollection);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -279,7 +279,7 @@ namespace Greenshot.Helpers.IEInterop
{ {
CorrectFrameLocations(frameElement); CorrectFrameLocations(frameElement);
// Clean up frameElement // Clean up frameElement
releaseCom(frameElement); ReleaseCom(frameElement);
} }
catch (Exception e) catch (Exception e)
{ {
@ -294,7 +294,7 @@ namespace Greenshot.Helpers.IEInterop
} }
/// <summary> /// <summary>
/// Corrent the frame locations with the information /// Correct the frame locations with the information
/// </summary> /// </summary>
/// <param name="frameElement"></param> /// <param name="frameElement"></param>
private void CorrectFrameLocations(IHTMLElement frameElement) private void CorrectFrameLocations(IHTMLElement frameElement)
@ -311,22 +311,22 @@ namespace Greenshot.Helpers.IEInterop
// Release element, but prevent the frameElement to be released // Release element, but prevent the frameElement to be released
if (oldElement != null) if (oldElement != null)
{ {
releaseCom(oldElement); ReleaseCom(oldElement);
} }
oldElement = element; oldElement = element;
} while (element != null); } while (element != null);
Point elementLocation = new Point((int) x, (int) y); var elementLocation = new NativePoint((int) x, (int) y);
IHTMLElement2 element2 = (IHTMLElement2) frameElement; IHTMLElement2 element2 = (IHTMLElement2) frameElement;
IHTMLRect rec = element2.getBoundingClientRect(); IHTMLRect rec = element2.getBoundingClientRect();
Point elementBoundingLocation = new Point(rec.left, rec.top); var elementBoundingLocation = new NativePoint(rec.left, rec.top);
// Release IHTMLRect // Release IHTMLRect
releaseCom(rec); ReleaseCom(rec);
LOG.DebugFormat("Looking for iframe to correct at {0}", elementBoundingLocation); LOG.DebugFormat("Looking for iframe to correct at {0}", elementBoundingLocation);
foreach (DocumentContainer foundFrame in _frames) foreach (DocumentContainer foundFrame in _frames)
{ {
Point frameLocation = foundFrame.SourceLocation; NativePoint frameLocation = foundFrame.SourceLocation;
if (frameLocation.Equals(elementBoundingLocation)) if (frameLocation.Equals(elementBoundingLocation))
{ {
// Match found, correcting location // Match found, correcting location
@ -475,7 +475,7 @@ namespace Greenshot.Helpers.IEInterop
var element = !_isDtd ? _document2.body : _document3.documentElement; var element = !_isDtd ? _document2.body : _document3.documentElement;
element.setAttribute(attribute, value, 1); element.setAttribute(attribute, value, 1);
// Release IHTMLElement com object // Release IHTMLElement com object
releaseCom(element); ReleaseCom(element);
} }
/// <summary> /// <summary>
@ -488,7 +488,7 @@ namespace Greenshot.Helpers.IEInterop
var element = !_isDtd ? _document2.body : _document3.documentElement; var element = !_isDtd ? _document2.body : _document3.documentElement;
var retVal = element.getAttribute(attribute, 1); var retVal = element.getAttribute(attribute, 1);
// Release IHTMLElement com object // Release IHTMLElement com object
releaseCom(element); ReleaseCom(element);
return retVal; return retVal;
} }