summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorMike Wey2011-10-16 19:18:55 +0200
committerMike Wey2011-10-16 19:18:55 +0200
commit20aceb391b4ba13d9f670cefa62066ab2ab5b90a (patch)
treeb375fbc59239cbd6c81c7be201d272447fcec834 /examples
parentc9bc467b818f77e52a1302a01c8178d446755d77 (diff)
Add a drawing example.
Diffstat (limited to 'examples')
-rw-r--r--examples/draw.d80
1 files changed, 80 insertions, 0 deletions
diff --git a/examples/draw.d b/examples/draw.d
new file mode 100644
index 0000000..d3635c5
--- /dev/null
+++ b/examples/draw.d
@@ -0,0 +1,80 @@
+/**
+ * Copyright: Mike Wey 2011
+ * License: zlib (See accompanying LICENSE file)
+ * Authors: Mike Wey
+ */
+
+module examples.draw;
+
+import std.conv;
+
+import dmagick.Color;
+import dmagick.ColorRGB;
+import dmagick.DrawingContext;
+import dmagick.Geometry;
+import dmagick.Image;
+
+//TODO: Easier way to import symbols from the headers used by DMagick.
+import dmagick.c.geometry;
+
+void main()
+{
+ int percentage = 95;
+
+ int imageWidth = 320;
+ int imageHeight = 200;
+
+ //Define the colors to use
+ Color borderColor = new Color("snow4");
+ Color cylinderTop = new ColorRGB(1, 1, 1, 0.4);
+ Color textColor = new Color("red");
+ Color textShadow = new Color("firebrick3");
+
+ //Define the Gradients to use;
+ Gradient cylinderEmptyColor = Gradient(new Color("white"), new Color("gray"), imageHeight/2);
+ Gradient cylinderinsideColor = Gradient(new Color("white"), new Color("darkgray"), imageHeight/2);
+ Gradient cylinderFullColor = Gradient(new Color("green2"), new Color("darkgreen"), imageHeight/2);
+ Gradient cylinderOutColor = Gradient(new Color("lime"), new Color("green4"), imageHeight/2);
+
+ int progressYmax = (imageHeight * 95) / 100;
+ int progressYmin = (imageHeight * 55) / 100;
+ int progressXmin = (imageWidth * 5) / 100;
+ int progressXmax = imageWidth - progressXmin;
+ int max = ((percentage * (progressXmax - progressXmin)) / 100) + progressXmin;
+ int wc = (progressYmax - progressYmin) / 4;
+ int hc = (progressYmax - progressYmin) / 2;
+ int fontsize = (imageHeight * 2) / 5;
+
+ //Minimum progress width.
+ if ( max < progressXmin + (2 * wc))
+ max = progressXmin + (2 * wc);
+
+ Image cylinder = new Image(Geometry(imageWidth, imageHeight), new Color("white"));
+ DrawingContext dc = new DrawingContext();
+
+ dc.stroke(borderColor);
+
+ dc.push();
+ dc.fill(cylinderEmptyColor);
+ dc.roundRectangle(progressXmin, progressYmin, progressXmax, progressYmax, wc, hc);
+
+ dc.fill(cylinderFullColor);
+ dc.roundRectangle(progressXmin, progressYmin, max, progressYmax, wc, hc);
+
+ dc.fill(cylinderOutColor);
+ dc.roundRectangle(max - (2 * wc), progressYmin, max, progressYmax, wc, hc);
+ dc.pop();
+
+ dc.fill(cylinderTop);
+ dc.roundRectangle(progressXmax - (2 * wc), progressYmin, progressXmax, progressYmax, wc, hc);
+
+ dc.font("Helvetica");
+ dc.fontSize(fontsize);
+ dc.stroke(textShadow);
+ dc.fill(textColor);
+ dc.gravity(GravityType.NorthGravity);
+ dc.text(0,(imageHeight * 10) / 100, to!(string)(percentage)~" %");
+
+ dc.draw(cylinder);
+ cylinder.display();
+}