From aeb7e5d78e5ec9eb8e12b0968b376a0dc6cb3452 Mon Sep 17 00:00:00 2001 From: RKrom Date: Mon, 27 Feb 2012 06:29:32 +0000 Subject: [PATCH] Added initial code for rotating git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1676 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4 --- Greenshot/Drawing/DrawableContainerList.cs | 8 ++++++ Greenshot/Drawing/Surface.cs | 30 ++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/Greenshot/Drawing/DrawableContainerList.cs b/Greenshot/Drawing/DrawableContainerList.cs index 0010e2497..3f6ff2b27 100644 --- a/Greenshot/Drawing/DrawableContainerList.cs +++ b/Greenshot/Drawing/DrawableContainerList.cs @@ -52,6 +52,14 @@ namespace Greenshot.Drawing { } } + public List AsIDrawableContainerList() { + List interfaceList = new List(); + foreach(IDrawableContainer container in this) { + interfaceList.Add(container); + } + return interfaceList; + } + /// /// Gets or sets the selection status of the elements. /// If several elements are in the list, true is only returned when all elements are selected. diff --git a/Greenshot/Drawing/Surface.cs b/Greenshot/Drawing/Surface.cs index 531ba84dc..ea9c2afce 100644 --- a/Greenshot/Drawing/Surface.cs +++ b/Greenshot/Drawing/Surface.cs @@ -571,6 +571,36 @@ namespace Greenshot.Drawing { case Effects.Grayscale: newImage = ImageHelper.CreateGrayscale((Bitmap)Image); break; + case Effects.Rotate270: + MakeUndoable(new DrawableContainerBoundsChangeMemento(elements.AsIDrawableContainerList()), false); + foreach(DrawableContainer drawableContainer in elements) { + int x1 = drawableContainer.Bounds.X - (Width >> 1); + int y1 = (-drawableContainer.Bounds.Y) + (Height >> 1); + int rotatedX1 = y1; + int rotatedY1 = -x1; + int newX1 = y1 + (Height >> 1); + int newY1 = -x1 - (Width >> 1); + + int x2 = (drawableContainer.Bounds.X+drawableContainer.Bounds.Width) - (Width >> 1); + int y2 = (-(drawableContainer.Bounds.Y+drawableContainer.Bounds.Height)) + (Height >> 1); + int rotatedX2 = y2; + int rotatedY2 = -x2; + int newX2 = y2 + (Height >> 1); + int newY2 = -x2 - (Width >> 1); + int newWidth = newX2 - newX1; + int newHeight = newY2 - newY1; + + RectangleF newRectangle = new RectangleF( + newX1, + newY1, + newWidth, + newHeight + ); + LOG.DebugFormat("Bounds before {0}, bounds after {1}", drawableContainer.Bounds, newRectangle); + drawableContainer.ApplyBounds(newRectangle); + } + newImage = ImageHelper.RotateFlip((Bitmap)Image, RotateFlipType.Rotate270FlipNone); + break; } if (newImage != null) {