1 /**
2  * Copyright: Mike Wey 2011
3  * License:   zlib (See accompanying LICENSE file)
4  * Authors:   Mike Wey
5  */
6 
7 module examples.draw;
8 
9 import std.conv;
10 
11 import dmagick.Color;
12 import dmagick.ColorRGB;
13 import dmagick.DrawingContext;
14 import dmagick.Geometry;
15 import dmagick.Image;
16 
17 void main()
18 {
19 	int percentage = 95;
20 
21 	int imageWidth = 320;
22 	int imageHeight = 200;
23 
24 	//Define the colors to use
25 	Color borderColor = new Color("snow4");
26 	Color cylinderTop = new ColorRGB(1, 1, 1, 0.4);
27 	Color textColor   = new Color("red");
28 	Color textShadow  = new Color("firebrick3");
29 
30 	//Define the Gradients to use;
31 	Gradient cylinderEmptyColor  = Gradient(new Color("white"),  new Color("gray"),      imageHeight/2);
32 	Gradient cylinderFullColor   = Gradient(new Color("green2"), new Color("darkgreen"), imageHeight/2);
33 	Gradient cylinderOutColor    = Gradient(new Color("lime"),   new Color("green4"),    imageHeight/2);
34 
35 	int progressYmax = (imageHeight * 95) / 100; 
36 	int progressYmin = (imageHeight * 55) / 100;
37 	int progressXmin = (imageWidth * 5) / 100;
38 	int progressXmax = imageWidth - progressXmin;
39 	int max = ((percentage * (progressXmax - progressXmin)) / 100) + progressXmin;
40 	int wc = (progressYmax - progressYmin) / 4;
41 	int hc = (progressYmax - progressYmin) / 2;
42 	int fontsize = (imageHeight * 2) / 5;
43 
44 	//Minimum progress width.
45 	if ( max < progressXmin + (2 * wc))
46 		max = progressXmin + (2 * wc);
47 
48 	Image cylinder = new Image(Geometry(imageWidth, imageHeight), new Color("white"));
49 	DrawingContext dc = new DrawingContext();
50 
51 	dc.stroke(borderColor);
52 
53 	dc.push();
54 	dc.fill(cylinderEmptyColor);
55 	dc.roundRectangle(progressXmin, progressYmin, progressXmax, progressYmax, wc, hc);
56 
57 	dc.fill(cylinderFullColor);
58 	dc.roundRectangle(progressXmin, progressYmin, max, progressYmax, wc, hc);
59 
60 	dc.fill(cylinderOutColor);
61 	dc.roundRectangle(max - (2 * wc), progressYmin, max, progressYmax, wc, hc);
62 	dc.pop();
63 
64 	dc.fill(cylinderTop);
65 	dc.roundRectangle(progressXmax - (2 * wc), progressYmin, progressXmax, progressYmax, wc, hc);
66 
67 	dc.fontFamily("Sans");
68 	dc.fontSize(fontsize);
69 	dc.stroke(textShadow);
70 	dc.fill(textColor);
71 	dc.gravity(GravityType.NorthGravity);
72 	dc.text(0,(imageHeight * 10) / 100, to!(string)(percentage)~" %");
73 
74 	dc.draw(cylinder);
75 	cylinder.display();
76 }