blob: 9799786744e80be5092d98cc08dbe310e73694cf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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);
};
}
}
|