summaryrefslogtreecommitdiff
path: root/dmagick/DrawingContext.d
diff options
context:
space:
mode:
Diffstat (limited to 'dmagick/DrawingContext.d')
-rw-r--r--dmagick/DrawingContext.d69
1 files changed, 69 insertions, 0 deletions
diff --git a/dmagick/DrawingContext.d b/dmagick/DrawingContext.d
new file mode 100644
index 0000000..9799786
--- /dev/null
+++ b/dmagick/DrawingContext.d
@@ -0,0 +1,69 @@
+/**
+ * Copyright: Mike Wey 2011
+ * License: zlib (See accompanying LICENSE file)
+ * Authors: Mike Wey
+ */
+
+module dmagick.DrawingContext;
+
+import dmagick.Image;
+
+import dmagick.c.geometry;
+
+class DrawingContext
+{
+ private void delegate(Image)[] actions;
+
+ //Image property changes that need undoing.
+ private void delegate(Image)[string] undo;
+
+ /**
+ * Apply the drawing context to the image.
+ */
+ void draw(Image image)
+ {
+ undo = null;
+
+ foreach ( action; actions )
+ action(image);
+
+ foreach ( u; undo )
+ u(image);
+ }
+
+ /**
+ * Specify a transformation matrix to adjust scaling, rotation, and
+ * translation (coordinate transformation) for subsequently drawn
+ * objects in the drawing context.
+ */
+ void affine(AffineMatrix affine)
+ {
+ AffineMatrix oldAffine;
+
+ actions ~= (Image image)
+ {
+ if ( "affine" !in undo )
+ {
+ oldAffine = image.options.affine;
+
+ undo["affine"] = (Image image)
+ {
+ image.options.affine = oldAffine;
+ };
+ }
+
+ image.options.affine = affine;
+ };
+ }
+
+ /**
+ * Transforms the image as specified by the affine matrix.
+ */
+ void affineTransform(AffineMatrix affine)
+ {
+ actions ~= (Image image)
+ {
+ image.affineTransform(affine);
+ };
+ }
+}