Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zoom for the editor (Feature-84) #201

Merged
merged 26 commits into from May 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
38739ce
Merge pull request #2 from greenshot/release/1.3
KillyMXI Apr 25, 2020
8b45489
Zoom feature for the editor
KillyMXI Apr 26, 2020
136953a
Fixes for some identified issues
KillyMXI Apr 26, 2020
79742d1
Code review nitpicks
KillyMXI Apr 26, 2020
41082c2
Image size in OneNoteExporter
KillyMXI Apr 26, 2020
95c759e
Changed shortcuts - Ctrl+0, Ctrl+9
KillyMXI Apr 26, 2020
ec2c46d
GetOptimalWindowSize - bound by available screen space
KillyMXI Apr 26, 2020
3d39241
More fixes for Surface.Image size
KillyMXI Apr 27, 2020
169dbdc
Rework for paste from clipboard
KillyMXI Apr 27, 2020
195b5c3
Fix NPE
KillyMXI Apr 27, 2020
2be1898
Width and Height shouldn't be exposed through ISurface anymore
KillyMXI Apr 27, 2020
5fe700b
Fix GetAvailableScreenSpace on secondary screens
KillyMXI Apr 27, 2020
d47271e
Fix rendering quality at small zoom levels when redrawing small parts
KillyMXI Apr 28, 2020
4c0277b
Robust clip region resize
KillyMXI Apr 28, 2020
e6e2ed5
Keep center of visible area static on zoom when possible
KillyMXI Apr 28, 2020
1ef2df9
Unneeded using
KillyMXI Apr 28, 2020
99742ad
Fix for Best Fit on images bigger than 4 times the available space
KillyMXI Apr 29, 2020
464e5e8
Fix weird scroll position when going from no scroll zoom value
KillyMXI Apr 30, 2020
dcf75fd
Use Fractions to represent zoom factor
KillyMXI Apr 30, 2020
bac1ff4
Fix for pixel jerk
KillyMXI Apr 30, 2020
f494385
Naming consistency - not a percentage value anymore
KillyMXI Apr 30, 2020
d93c9d6
TextContainer's TextBox on zoom - fix for position, update font size
KillyMXI Apr 30, 2020
ef5b5de
Smarter zoom - keep selected elements in sight
KillyMXI May 1, 2020
0fce434
Fix: prevent image blurring at 100% zoom
KillyMXI May 1, 2020
b2a6fc8
No ScaleTransform is needed at 100% zoom
KillyMXI May 1, 2020
79ea558
Fix: zoom-in when selection is out of sight
KillyMXI May 1, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions Greenshot/Drawing/Adorners/AbstractAdorner.cs
Expand Up @@ -116,6 +116,18 @@ public virtual Rectangle Bounds
}
}

/// <summary>
/// Return the bounds of the Adorner as displayed on the parent Surface
/// </summary>
protected virtual Rectangle 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);
}
}

/// <summary>
/// The adorner is active if the edit status is not idle or undrawn
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Greenshot/Drawing/Adorners/MoveAdorner.cs
Expand Up @@ -142,7 +142,7 @@ public override void Paint(PaintEventArgs paintEventArgs)
{
Graphics targetGraphics = paintEventArgs.Graphics;

var bounds = Bounds;
var bounds = BoundsOnSurface;
GraphicsState state = targetGraphics.Save();

targetGraphics.SmoothingMode = SmoothingMode.None;
Expand Down
2 changes: 1 addition & 1 deletion Greenshot/Drawing/Adorners/ResizeAdorner.cs
Expand Up @@ -169,7 +169,7 @@ public override void Paint(PaintEventArgs paintEventArgs)
{
Graphics targetGraphics = paintEventArgs.Graphics;

var bounds = Bounds;
var bounds = BoundsOnSurface;
GraphicsState state = targetGraphics.Save();

targetGraphics.SmoothingMode = SmoothingMode.None;
Expand Down
22 changes: 11 additions & 11 deletions Greenshot/Drawing/Adorners/TargetAdorner.cs
Expand Up @@ -61,26 +61,26 @@ public override void MouseMove(object sender, MouseEventArgs mouseEventArgs)

Owner.Invalidate();
Point newGripperLocation = new Point(mouseEventArgs.X, mouseEventArgs.Y);
Rectangle surfaceBounds = new Rectangle(0, 0, Owner.Parent.Width, Owner.Parent.Height);
Rectangle imageBounds = new Rectangle(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 (!surfaceBounds.Contains(newGripperLocation))
if (!imageBounds.Contains(newGripperLocation))
{
if (newGripperLocation.X > surfaceBounds.Right)
if (newGripperLocation.X > imageBounds.Right)
{
newGripperLocation.X = surfaceBounds.Right - 5;
newGripperLocation.X = imageBounds.Right - 5;
}
if (newGripperLocation.X < surfaceBounds.Left)
if (newGripperLocation.X < imageBounds.Left)
{
newGripperLocation.X = surfaceBounds.Left;
newGripperLocation.X = imageBounds.Left;
}
if (newGripperLocation.Y > surfaceBounds.Bottom)
if (newGripperLocation.Y > imageBounds.Bottom)
{
newGripperLocation.Y = surfaceBounds.Bottom - 5;
newGripperLocation.Y = imageBounds.Bottom - 5;
}
if (newGripperLocation.Y < surfaceBounds.Top)
if (newGripperLocation.Y < imageBounds.Top)
{
newGripperLocation.Y = surfaceBounds.Top;
newGripperLocation.Y = imageBounds.Top;
}
}

Expand All @@ -96,7 +96,7 @@ public override void Paint(PaintEventArgs paintEventArgs)
{
Graphics targetGraphics = paintEventArgs.Graphics;

var bounds = Bounds;
var bounds = BoundsOnSurface;
targetGraphics.FillRectangle(Brushes.Green, bounds.X, bounds.Y, bounds.Width, bounds.Height);
}

Expand Down
17 changes: 13 additions & 4 deletions Greenshot/Drawing/CropContainer.cs
Expand Up @@ -56,7 +56,15 @@ private void Init()
/// We need to override the DrawingBound, return a rectangle in the size of the image, to make sure this element is always draw
/// (we create a transparent brown over the complete picture)
/// </summary>
public override Rectangle DrawingBounds => new Rectangle(0,0,_parent?.Width??0, _parent?.Height ?? 0);
public override Rectangle DrawingBounds {
get {
if (_parent?.Image is Image image) {
return new Rectangle(0, 0, image.Width, image.Height);
} else {
return Rectangle.Empty;
}
}
}

public override void Draw(Graphics g, RenderMode rm) {
if (_parent == null)
Expand All @@ -67,17 +75,18 @@ private void Init()
using Brush cropBrush = new SolidBrush(Color.FromArgb(100, 150, 150, 100));
Rectangle cropRectangle = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
Rectangle selectionRect = new Rectangle(cropRectangle.Left - 1, cropRectangle.Top - 1, cropRectangle.Width + 1, cropRectangle.Height + 1);
Size imageSize = _parent.Image.Size;

DrawSelectionBorder(g, selectionRect);

// top
g.FillRectangle(cropBrush, new Rectangle(0, 0, _parent.Width, cropRectangle.Top));
g.FillRectangle(cropBrush, new Rectangle(0, 0, imageSize.Width, cropRectangle.Top));
// left
g.FillRectangle(cropBrush, new Rectangle(0, cropRectangle.Top, cropRectangle.Left, cropRectangle.Height));
// right
g.FillRectangle(cropBrush, new Rectangle(cropRectangle.Left + cropRectangle.Width, cropRectangle.Top, _parent.Width - (cropRectangle.Left + cropRectangle.Width), cropRectangle.Height));
g.FillRectangle(cropBrush, new Rectangle(cropRectangle.Left + cropRectangle.Width, cropRectangle.Top, imageSize.Width - (cropRectangle.Left + cropRectangle.Width), cropRectangle.Height));
// bottom
g.FillRectangle(cropBrush, new Rectangle(0, cropRectangle.Top + cropRectangle.Height, _parent.Width, _parent.Height - (cropRectangle.Top + cropRectangle.Height)));
g.FillRectangle(cropBrush, new Rectangle(0, cropRectangle.Top + cropRectangle.Height, imageSize.Width, imageSize.Height - (cropRectangle.Top + cropRectangle.Height)));
}

public override bool HasContextMenu {
Expand Down
30 changes: 1 addition & 29 deletions Greenshot/Drawing/DrawableContainer.cs
Expand Up @@ -33,7 +33,6 @@
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Runtime.Serialization;
using System.Windows.Forms;
using GreenshotPlugin.IniFile;
using GreenshotPlugin.Interfaces;
using GreenshotPlugin.Interfaces.Drawing.Adorners;
Expand Down Expand Up @@ -298,34 +297,7 @@ public IList<IAdorner> Adorners

public virtual void Invalidate() {
if (Status != EditStatus.UNDRAWN) {
_parent?.Invalidate(DrawingBounds);
}
}

public void AlignToParent(HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment) {
if (_parent == null)
{
return;
}
int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS);
if (horizontalAlignment == HorizontalAlignment.Left) {
Left = lineThickness/2;
}
if (horizontalAlignment == HorizontalAlignment.Right) {
Left = _parent.Width - Width - lineThickness/2;
}
if (horizontalAlignment == HorizontalAlignment.Center) {
Left = (_parent.Width / 2) - (Width / 2) - lineThickness/2;
}

if (verticalAlignment == VerticalAlignment.TOP) {
Top = lineThickness/2;
}
if (verticalAlignment == VerticalAlignment.BOTTOM) {
Top = _parent.Height - Height - lineThickness/2;
}
if (verticalAlignment == VerticalAlignment.CENTER) {
Top = (_parent.Height / 2) - (Height / 2) - lineThickness/2;
_parent?.InvalidateElements(DrawingBounds);
}
}

Expand Down
33 changes: 28 additions & 5 deletions Greenshot/Drawing/DrawableContainerList.cs
Expand Up @@ -235,6 +235,30 @@ public class DrawableContainerList : List<IDrawableContainer>, IDrawableContaine
return false;
}

/// <summary>
/// A rectangle containing DrawingBounds of all drawableContainers in this list,
/// or empty rectangle if nothing is there.
/// </summary>
public Rectangle DrawingBounds
{
get
{
if (Count == 0)
{
return Rectangle.Empty;
}
else
{
var result = this[0].DrawingBounds;
for (int i = 1; i < Count; i++)
{
result = Rectangle.Union(result, this[i].DrawingBounds);
}
return result;
}
}
}

/// <summary>
/// Triggers all elements in the list ot be redrawn.
/// </summary>
Expand Down Expand Up @@ -286,7 +310,7 @@ public class DrawableContainerList : List<IDrawableContainer>, IDrawableContaine
{
region = Rectangle.Union(region, dc.DrawingBounds);
}
Parent.Invalidate(region);
Parent.InvalidateElements(region);
}
/// <summary>
/// Indicates whether the given list of elements can be pulled up,
Expand Down Expand Up @@ -523,9 +547,9 @@ public void PullElementsToTop(IDrawableContainerList elements)
}
}

public virtual void ShowContextMenu(MouseEventArgs e, ISurface surface)
public virtual void ShowContextMenu(MouseEventArgs e, ISurface iSurface)
{
if (!(surface is Surface))
if (!(iSurface is Surface surface))
KillyMXI marked this conversation as resolved.
Show resolved Hide resolved
{
return;
}
Expand All @@ -542,8 +566,7 @@ public virtual void ShowContextMenu(MouseEventArgs e, ISurface surface)
ContextMenuStrip menu = new ContextMenuStrip();
AddContextMenuItems(menu, surface);
if (menu.Items.Count > 0) {
// TODO: cast should be somehow avoided
menu.Show((Surface)surface, e.Location);
menu.Show(surface, surface.ToSurfaceCoordinates(e.Location));
while (true) {
if (menu.Visible) {
Application.DoEvents();
Expand Down
13 changes: 10 additions & 3 deletions Greenshot/Drawing/FreehandContainer.cs
Expand Up @@ -47,8 +47,8 @@ public class FreehandContainer : DrawableContainer {
/// Constructor
/// </summary>
public FreehandContainer(Surface parent) : base(parent) {
Width = parent.Width;
Height = parent.Height;
Width = parent.Image.Width;
Height = parent.Image.Height;
Top = 0;
Left = 0;
}
Expand Down Expand Up @@ -236,7 +236,14 @@ protected static void DrawSelectionBorder(Graphics graphics, Pen linePen, Graphi
int safetymargin = 10;
return new Rectangle(myBounds.Left + Left - (safetymargin+lineThickness), myBounds.Top + Top - (safetymargin+lineThickness), myBounds.Width + 2*(lineThickness+safetymargin), myBounds.Height + 2*(lineThickness+safetymargin));
}
return new Rectangle(0, 0, _parent?.Width??0, _parent?.Height?? 0);
if (_parent?.Image is Image image)
{
return new Rectangle(0, 0, image.Width, image.Height);
}
else
{
return Rectangle.Empty;
}
}
}

Expand Down