Removed "rotate" leftovers. Also implemented transform in the ImageContainer, be aware: scaling will probably cause artefakts if we "undo"...

This commit is contained in:
RKrom 2014-06-02 10:27:58 +02:00
parent 4b8ec88aaf
commit 621cc7fd0c
3 changed files with 42 additions and 20 deletions

View file

@ -692,10 +692,16 @@ namespace Greenshot.Drawing {
Invalidate(); Invalidate();
} }
public virtual bool CanRotate { /// <summary>
get { /// Retrieve the rotation angle from the matrix
return true; /// </summary>
} /// <param name="matrix"></param>
/// <returns></returns>
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);
} }
/// <summary> /// <summary>

View file

@ -171,15 +171,6 @@ namespace Greenshot.Drawing {
myBounds = Rectangle.Round(freehandPath.GetBounds()); myBounds = Rectangle.Round(freehandPath.GetBounds());
} }
/// <summary>
/// Currently we can't rotate the freehand
/// </summary>
public override bool CanRotate {
get {
return false;
}
}
/// <summary> /// <summary>
/// Do the drawing of the freehand "stroke" /// Do the drawing of the freehand "stroke"
/// </summary> /// </summary>
@ -267,6 +258,10 @@ namespace Greenshot.Drawing {
return freehandPath.GetHashCode(); return freehandPath.GetHashCode();
} }
/// <summary>
/// This is overriden to prevent the grippers to be modified.
/// Might not be the best way...
/// </summary>
protected override void DoLayout() { protected override void DoLayout() {
} }

View file

@ -93,7 +93,8 @@ namespace Greenshot.Drawing {
public Image Image { public Image Image {
set { set {
// Remove all current bitmaps // Remove all current bitmaps
DisposeImages(); DisposeImage();
DisposeShadow();
image = ImageHelper.Clone(value); image = ImageHelper.Clone(value);
bool shadow = GetFieldValueAsBool(FieldType.SHADOW); bool shadow = GetFieldValueAsBool(FieldType.SHADOW);
CheckShadow(shadow); CheckShadow(shadow);
@ -118,24 +119,42 @@ namespace Greenshot.Drawing {
/// <param name="disposing"></param> /// <param name="disposing"></param>
protected override void Dispose(bool disposing) { protected override void Dispose(bool disposing) {
if (disposing) { if (disposing) {
DisposeImages(); DisposeImage();
DisposeShadow();
} }
image = null;
_shadowBitmap = null;
base.Dispose(disposing); base.Dispose(disposing);
} }
private void DisposeImages() { private void DisposeImage() {
if (image != null) { if (image != null) {
image.Dispose(); image.Dispose();
} }
image = null;
}
private void DisposeShadow() {
if (_shadowBitmap != null) { if (_shadowBitmap != null) {
_shadowBitmap.Dispose(); _shadowBitmap.Dispose();
} }
image = null;
_shadowBitmap = null; _shadowBitmap = null;
} }
/// <summary>
/// Make sure the content is also transformed.
/// </summary>
/// <param name="matrix"></param>
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);
}
}
}
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
@ -157,7 +176,9 @@ namespace Greenshot.Drawing {
/// <param name="shadow"></param> /// <param name="shadow"></param>
private void CheckShadow(bool shadow) { private void CheckShadow(bool shadow) {
if (shadow && _shadowBitmap == null) { if (shadow && _shadowBitmap == null) {
_shadowBitmap = ImageHelper.ApplyEffect(image, new DropShadowEffect(), new Matrix()); using (var matrix = new Matrix()) {
_shadowBitmap = ImageHelper.ApplyEffect(image, new DropShadowEffect(), matrix);
}
} }
} }