diff doodle/gtk/cairo.d @ 79:535bae7a7305

Checkpoint
author "David Bryant <bagnose@gmail.com>"
date Sun, 15 Aug 2010 23:18:05 +0930
parents 78bc2046256e
children b759414d2b72
line wrap: on
line diff
--- a/doodle/gtk/cairo.d	Sun Aug 15 15:19:14 2010 +0930
+++ b/doodle/gtk/cairo.d	Sun Aug 15 23:18:05 2010 +0930
@@ -2,9 +2,9 @@
 
 public {
     import doodle.tk.drawing;
+    import cairo.Context;
 }
 
-/*
 final class CairoDrawable : Drawable {
     this(Context cr) {
         assert(cr);
@@ -13,11 +13,84 @@
 
     // Drawing overrides:
 
+    void setLineStyle(LineStyle style) {
+        switch (style) {
+        case LineStyle.SOLID:
+            _cr.setDash([ 4.0, 4.0 ], 0.0);
+            break;
+        case LineStyle.DASHED:
+            _cr.setDash([ 4.0, 4.0 ], 0.0);
+            break;
+        case LineStyle.DOTTED:
+            _cr.setDash([ 4.0, 4.0 ], 0.0);
+            break;
+        default:
+            assert(0);
+        }
+    }
+
+    void setLineWidth(in double width) { _cr.setLineWidth(width); }
+
+    void setColor(in Color color) { _cr.setSourceRgba(color.r, color.g, color.b, color.a); }
+
+    void translate(in Point p) { _cr.translate(p.x, p.y); }
+    void scale(in double s) { _cr.scale(s, s); }
+
     void pushState() { _cr.save; }
     void popState() { _cr.restore; }
 
+    void drawRectangle(in Rectangle rectangle, bool fill) {
+        _cr.rectangle(rectangle.position.x, rectangle.position.y,
+                      rectangle.size.x, rectangle.size.y);
+    }
+
+    void drawEllipse(in Rectangle rectangle, bool fill) {
+        // NYI
+    }
+
+    void drawSegment(in Segment segment) {
+        _cr.moveTo(segment.begin.x, segment.begin.y);
+        _cr.lineTo(segment.end.x, segment.end.y);
+        _cr.stroke;
+    }
+
+    void drawHLine(in double y, in double x0, in double x1) {
+        _cr.moveTo(x0, y);
+        _cr.lineTo(x1, y);
+        _cr.stroke;
+    }
+
+    void drawVLine(in double x, in double y0, in double y1) {
+        _cr.moveTo(x, y0);
+        _cr.lineTo(x, y1);
+    }
+
+    void drawPoly(in Point[] points, bool fill) {
+        assert(points.length >= 2);
+        foreach(i, p; points) {
+            if (i == 0) { _cr.moveTo(p.x, p.y); }
+            else { _cr.lineTo(p.x, p.y); }
+        }
+        if (fill) { _cr.fill; } else { _cr.stroke; }
+    }
+
+    void setFontFace(in FontFace face) {
+        // NYI
+    }
+
+    void setFontSize(in double size) {
+        // NYI
+    }
+
+    void drawText(in string text) {
+        // NYI
+    }
+
+    void measureText(in string text, out Rectangle logicalBounds, out Rectangle totalBounds) const {
+        // NYI
+    }
+
     private {
         Context _cr;
     }
 }
-*/