summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Wey2011-10-16 19:18:55 +0200
committerMike Wey2011-10-16 19:18:55 +0200
commit20aceb391b4ba13d9f670cefa62066ab2ab5b90a (patch)
treeb375fbc59239cbd6c81c7be201d272447fcec834
parentc9bc467b818f77e52a1302a01c8178d446755d77 (diff)
Add a drawing example.
-rw-r--r--dmagick/DrawingContext.d4
-rw-r--r--examples/draw.d80
2 files changed, 82 insertions, 2 deletions
diff --git a/dmagick/DrawingContext.d b/dmagick/DrawingContext.d
index 64da7dc..a4daa59 100644
--- a/dmagick/DrawingContext.d
+++ b/dmagick/DrawingContext.d
@@ -1033,13 +1033,13 @@ struct Gradient
* Define a linear gradient.
*
* Params:
- * size = The height or with of the gradient.
* startColor = The starting Color.
* endColor = The end Color.
+ * size = The height or with of the gradient.
* Direction = Determines is the gradient fades from top to bottom
* or from left to right.
*/
- this(size_t size, Color startColor, Color endColor, GradientDirection direction = GradientDirection.Vertical)
+ this(Color startColor, Color endColor, size_t size, GradientDirection direction = GradientDirection.Vertical)
{
currentCount = count++;
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();
+}