Mercurial > projects > doodle
annotate doodle/gtk/cairo_renderer.d @ 84:cdd4fc728d94
Renamed Drawable to Renderer
author | daveb |
---|---|
date | Mon, 16 Aug 2010 17:23:09 +0930 |
parents | doodle/gtk/cairo.d@d92b9f04b1e8 |
children | 467febed7367 |
rev | line source |
---|---|
84 | 1 module doodle.gtk.cairo_renderer; |
73 | 2 |
3 public { | |
84 | 4 import doodle.tk.renderer; |
79 | 5 import cairo.Context; |
73 | 6 } |
7 | |
84 | 8 final class CairoRenderer : Renderer { |
73 | 9 this(Context cr) { |
10 assert(cr); | |
11 _cr = cr; | |
12 } | |
13 | |
14 // Drawing overrides: | |
15 | |
79 | 16 void setLineStyle(LineStyle style) { |
17 switch (style) { | |
18 case LineStyle.SOLID: | |
81 | 19 _cr.setDash([ ], 0.0); |
79 | 20 break; |
21 case LineStyle.DASHED: | |
22 _cr.setDash([ 4.0, 4.0 ], 0.0); | |
23 break; | |
24 case LineStyle.DOTTED: | |
81 | 25 _cr.setDash([ 1.0, 4.0 ], 0.0); |
79 | 26 break; |
27 default: | |
28 assert(0); | |
29 } | |
30 } | |
31 | |
32 void setLineWidth(in double width) { _cr.setLineWidth(width); } | |
33 | |
34 void setColor(in Color color) { _cr.setSourceRgba(color.r, color.g, color.b, color.a); } | |
35 | |
36 void translate(in Point p) { _cr.translate(p.x, p.y); } | |
37 void scale(in double s) { _cr.scale(s, s); } | |
38 | |
76 | 39 void pushState() { _cr.save; } |
40 void popState() { _cr.restore; } | |
73 | 41 |
81 | 42 void drawRectangle(in Rectangle rectangle, bool fill = false) { |
79 | 43 _cr.rectangle(rectangle.position.x, rectangle.position.y, |
44 rectangle.size.x, rectangle.size.y); | |
80
b759414d2b72
Switched from cairo to Drawable abstraction
"David Bryant <bagnose@gmail.com>"
parents:
79
diff
changeset
|
45 if (fill) { _cr.fill; } else { _cr.stroke; } |
79 | 46 } |
47 | |
81 | 48 void drawEllipse(in Rectangle rectangle, bool fill = false) { |
79 | 49 // NYI |
50 } | |
51 | |
52 void drawSegment(in Segment segment) { | |
53 _cr.moveTo(segment.begin.x, segment.begin.y); | |
54 _cr.lineTo(segment.end.x, segment.end.y); | |
55 _cr.stroke; | |
56 } | |
57 | |
58 void drawHLine(in double y, in double x0, in double x1) { | |
59 _cr.moveTo(x0, y); | |
60 _cr.lineTo(x1, y); | |
61 _cr.stroke; | |
62 } | |
63 | |
64 void drawVLine(in double x, in double y0, in double y1) { | |
65 _cr.moveTo(x, y0); | |
66 _cr.lineTo(x, y1); | |
67 } | |
68 | |
81 | 69 void drawPoly(in Point[] points, bool fill = false) { |
79 | 70 assert(points.length >= 2); |
71 foreach(i, p; points) { | |
72 if (i == 0) { _cr.moveTo(p.x, p.y); } | |
73 else { _cr.lineTo(p.x, p.y); } | |
74 } | |
75 if (fill) { _cr.fill; } else { _cr.stroke; } | |
76 } | |
77 | |
78 void setFontFace(in FontFace face) { | |
79 // NYI | |
80 } | |
81 | |
82 void setFontSize(in double size) { | |
83 // NYI | |
84 } | |
85 | |
86 void drawText(in string text) { | |
87 // NYI | |
88 } | |
89 | |
90 void measureText(in string text, out Rectangle logicalBounds, out Rectangle totalBounds) const { | |
91 // NYI | |
92 } | |
93 | |
73 | 94 private { |
95 Context _cr; | |
96 } | |
97 } |