diff options
| author | Mike Wey | 2011-08-27 18:05:32 +0200 |
|---|---|---|
| committer | Mike Wey | 2011-08-27 18:05:32 +0200 |
| commit | 64d0db95dc33f9b00784826e37136323fdf4cfd9 (patch) | |
| tree | caec2a73187193de9ad9118e336cd5dfda53461a | |
| parent | 38b47ebbaff4326800286b2a93579298be6578c6 (diff) | |
Add a drawing context class.
| -rw-r--r-- | dmagick/DrawingContext.d | 69 |
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); + }; + } +} |
