diff --git a/Greenshot/Drawing/DrawableContainer.cs b/Greenshot/Drawing/DrawableContainer.cs
index f29bdbb5a..32d5bb923 100644
--- a/Greenshot/Drawing/DrawableContainer.cs
+++ b/Greenshot/Drawing/DrawableContainer.cs
@@ -692,10 +692,16 @@ namespace Greenshot.Drawing {
Invalidate();
}
- public virtual bool CanRotate {
- get {
- return true;
- }
+ ///
+ /// Retrieve the rotation angle from the matrix
+ ///
+ ///
+ ///
+ public static int CalculateAngle(Matrix matrix) {
+ const int M11 = 0;
+ const int M21 = 2;
+ var radians = Math.Atan2(matrix.Elements[M21], matrix.Elements[M11]);
+ return (int)-Math.Round(radians * 180 / Math.PI);
}
///
diff --git a/Greenshot/Drawing/FreehandContainer.cs b/Greenshot/Drawing/FreehandContainer.cs
index 4f3984128..72a9b8369 100644
--- a/Greenshot/Drawing/FreehandContainer.cs
+++ b/Greenshot/Drawing/FreehandContainer.cs
@@ -171,15 +171,6 @@ namespace Greenshot.Drawing {
myBounds = Rectangle.Round(freehandPath.GetBounds());
}
- ///
- /// Currently we can't rotate the freehand
- ///
- public override bool CanRotate {
- get {
- return false;
- }
- }
-
///
/// Do the drawing of the freehand "stroke"
///
@@ -267,6 +258,10 @@ namespace Greenshot.Drawing {
return freehandPath.GetHashCode();
}
+ ///
+ /// This is overriden to prevent the grippers to be modified.
+ /// Might not be the best way...
+ ///
protected override void DoLayout() {
}
diff --git a/Greenshot/Drawing/ImageContainer.cs b/Greenshot/Drawing/ImageContainer.cs
index 55533b9ad..4bb992808 100644
--- a/Greenshot/Drawing/ImageContainer.cs
+++ b/Greenshot/Drawing/ImageContainer.cs
@@ -93,7 +93,8 @@ namespace Greenshot.Drawing {
public Image Image {
set {
// Remove all current bitmaps
- DisposeImages();
+ DisposeImage();
+ DisposeShadow();
image = ImageHelper.Clone(value);
bool shadow = GetFieldValueAsBool(FieldType.SHADOW);
CheckShadow(shadow);
@@ -118,24 +119,42 @@ namespace Greenshot.Drawing {
///
protected override void Dispose(bool disposing) {
if (disposing) {
- DisposeImages();
+ DisposeImage();
+ DisposeShadow();
}
- image = null;
- _shadowBitmap = null;
base.Dispose(disposing);
}
- private void DisposeImages() {
+ private void DisposeImage() {
if (image != null) {
image.Dispose();
}
+ image = null;
+ }
+ private void DisposeShadow() {
if (_shadowBitmap != null) {
_shadowBitmap.Dispose();
}
- image = null;
_shadowBitmap = null;
}
+
+
+ ///
+ /// Make sure the content is also transformed.
+ ///
+ ///
+ public override void Transform(Matrix matrix) {
+ base.Transform(matrix);
+ LOG.DebugFormat("Rotating element with {0} degrees.", CalculateAngle(matrix));
+ DisposeShadow();
+ using (var tmpMatrix = new Matrix()) {
+ using (image) {
+ image = ImageHelper.ApplyEffect(image, new RotateEffect(CalculateAngle(matrix)), tmpMatrix);
+ }
+ }
+ }
+
///
///
///
@@ -157,7 +176,9 @@ namespace Greenshot.Drawing {
///
private void CheckShadow(bool shadow) {
if (shadow && _shadowBitmap == null) {
- _shadowBitmap = ImageHelper.ApplyEffect(image, new DropShadowEffect(), new Matrix());
+ using (var matrix = new Matrix()) {
+ _shadowBitmap = ImageHelper.ApplyEffect(image, new DropShadowEffect(), matrix);
+ }
}
}