1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * shape.h: This match the classes inside System.Windows.Shapes
6 * Moonlight List (moonlight-list@lists.ximian.com)
8 * Copyright 2007-2008 Novell, Inc. (http://www.novell.com)
10 * See the LICENSE file included with the distribution for details.
21 #include "frameworkelement.h"
22 #include "moon-path.h"
32 cairo_fill_rule_t
convert_fill_rule (FillRule fill_rule
);
33 void calc_line_bounds (double x1
, double x2
, double y1
, double y2
, double thickness
, PenLineCap start_cap
, PenLineCap end_cap
, Rect
* bounds
);
41 /* @Namespace=System.Windows.Shapes */
42 class Shape
: public FrameworkElement
{
47 cairo_surface_t
*cached_surface
;
51 void DoDraw (cairo_t
*cr
, bool do_op
);
53 void SetupLineCaps (cairo_t
*cr
);
54 void SetupLineJoinMiter (cairo_t
*cr
);
55 virtual bool SetupLine (cairo_t
* cr
);
56 bool SetupDashes (cairo_t
*cr
, double thickness
);
57 bool SetupDashes (cairo_t
*cr
, double thickness
, double offset
);
58 bool Fill (cairo_t
*cr
, bool do_op
);
59 void Clip (cairo_t
*cr
);
60 virtual bool DrawShape (cairo_t
*cr
, bool do_op
) { g_warning ("%s does not implement DrawShape ().", GetTypeName ()); return false; }
61 // virtual bool DrawDegenerateShape (cairo_t *cr, bool do_op) = 0;
64 virtual void InvalidatePathCache (bool free
= false);
65 void InvalidateSurfaceCache (void);
66 void InvalidateNaturalBounds ();
67 void InvalidateFillBounds ();
68 void InvalidateStrokeBounds ();
69 void InvalidateStretch ();
71 Rect
GetStretchExtents ();
72 Rect
GetNaturalBounds ();
74 bool IsCandidateForCaching (void);
76 virtual Rect
ComputeShapeBounds (bool logical
) { return ComputeShapeBounds (logical
, NULL
); }
77 virtual Rect
ComputeShapeBounds (bool logical
, cairo_matrix_t
* matrix
);
79 virtual void ShiftPosition (Point p
);
80 virtual void TransformBounds (cairo_matrix_t
*old
, cairo_matrix_t
*current
);
82 virtual Rect
ComputeStretchBounds ();
84 DoubleCollection
*GetStrokeDashArray ();
87 cairo_matrix_t stretch_transform
;
88 /* @PropertyType=Brush,GenerateAccessors */
89 const static int FillProperty
;
90 /* @PropertyType=Stretch,AutoCreator=Shape::CreateDefaultStretch,GenerateAccessors */
91 const static int StretchProperty
;
92 /* @PropertyType=Brush,GenerateAccessors */
93 const static int StrokeProperty
;
94 /* @PropertyType=DoubleCollection,GenerateAccessors */
95 const static int StrokeDashArrayProperty
;
96 /* @PropertyType=PenLineCap,DefaultValue=PenLineCapFlat,GenerateAccessors */
97 const static int StrokeDashCapProperty
;
98 /* @PropertyType=double,DefaultValue=0.0,GenerateAccessors */
99 const static int StrokeDashOffsetProperty
;
100 /* @PropertyType=PenLineCap,DefaultValue=PenLineCapFlat,GenerateAccessors */
101 const static int StrokeEndLineCapProperty
;
102 /* @PropertyType=PenLineJoin,DefaultValue=PenLineJoinMiter,GenerateAccessors */
103 const static int StrokeLineJoinProperty
;
104 /* @PropertyType=double,DefaultValue=10.0,GenerateAccessors */
105 const static int StrokeMiterLimitProperty
;
106 /* @PropertyType=PenLineCap,DefaultValue=PenLineCapFlat,GenerateAccessors */
107 const static int StrokeStartLineCapProperty
;
108 /* @PropertyType=double,DefaultValue=1.0,GenerateAccessors */
109 const static int StrokeThicknessProperty
;
111 /* @GenerateCBinding,GeneratePInvoke,ManagedAccess=Protected */
114 /* @GenerateCBinding,GeneratePInvoke */
115 virtual Transform
*GetGeometryTransform ();
118 // Overrides from UIElement.
120 virtual Size
ComputeActualSize ();
121 virtual Size
MeasureOverride (Size Availablesize
);
122 virtual Size
ArrangeOverride (Size finalSize
);
123 virtual void Render (cairo_t
*cr
, Region
*region
, bool path_only
= false);
124 virtual void GetSizeForBrush (cairo_t
*cr
, double *width
, double *height
);
125 virtual void ComputeBounds ();
126 virtual bool InsideObject (cairo_t
*cr
, double x
, double y
);
127 virtual Point
GetOriginPoint () { return extents
.GetTopLeft (); }
130 // new virtual methods for shapes
132 virtual bool IsStroked () { return stroke
; }
133 virtual bool IsFilled () { return fill
; }
134 virtual bool CanFill () { return false; }
135 virtual bool CanFindElement () { return IsFilled () || IsStroked (); }
136 virtual FillRule
GetFillRule () { return FillRuleNonzero
; }
139 // Draw: draws the Shape in the cairo context (affine transforms are set before this
142 // This is called multiple times: one for fills, one for strokes
143 // if they are both set. It will also be called to compute the bounding box.
145 virtual void Draw (cairo_t
*cr
);
146 virtual void BuildPath () {};
147 void Stroke (cairo_t
*cr
, bool do_op
);
148 bool NeedsClipping ();
150 virtual void CacheInvalidateHint (void);
151 virtual void OnPropertyChanged (PropertyChangedEventArgs
*args
, MoonError
*error
);
152 virtual void OnSubPropertyChanged (DependencyProperty
*prop
, DependencyObject
*obj
, PropertyChangedEventArgs
*subobj_args
);
153 virtual Point
GetTransformOrigin ();
156 bool IsEmpty () { return (flags
& UIElement::SHAPE_EMPTY
); };
157 bool IsNormal () { return (flags
& UIElement::SHAPE_NORMAL
); };
158 bool IsDegenerate () { return (flags
& UIElement::SHAPE_DEGENERATE
); };
159 bool HasRadii () { return (flags
& UIElement::SHAPE_RADII
); };
160 void SetShapeFlags (UIElementFlags sf
) { flags
&= ~UIElement::SHAPE_MASK
; flags
|= sf
; };
161 void AddShapeFlags (UIElementFlags sf
) { flags
|= sf
; };
164 // Property Accessors
166 void SetFill (Brush
*fill
);
169 void SetStroke (Brush
*stroke
);
172 void SetStretch (Stretch stretch
);
173 Stretch
GetStretch ();
175 void SetStrokeDashArray (DoubleCollection
*dashes
);
177 void SetStrokeDashCap (PenLineCap cap
);
178 PenLineCap
GetStrokeDashCap ();
180 void SetStrokeDashOffset (double offset
);
181 double GetStrokeDashOffset ();
183 void SetStrokeEndLineCap (PenLineCap cap
);
184 PenLineCap
GetStrokeEndLineCap ();
186 void SetStrokeLineJoin (PenLineJoin join
);
187 PenLineJoin
GetStrokeLineJoin ();
189 void SetStrokeMiterLimit (double limit
);
190 double GetStrokeMiterLimit ();
192 void SetStrokeStartLineCap (PenLineCap cap
);
193 PenLineCap
GetStrokeStartLineCap ();
195 void SetStrokeThickness (double thickness
);
196 double GetStrokeThickness ();
198 static Value
* CreateDefaultStretch (DependencyObject
*instance
, DependencyProperty
*property
);
205 /* @Namespace=System.Windows.Shapes */
206 class Ellipse
: public Shape
{
208 virtual ~Ellipse () {}
209 virtual bool DrawShape (cairo_t
*cr
, bool do_op
);
210 virtual Rect
ComputeShapeBounds (bool logical
);
211 virtual Rect
ComputeStretchBounds ();
214 /* @GenerateCBinding,GeneratePInvoke */
217 virtual void BuildPath ();
218 virtual bool CanFill () { return true; }
220 virtual void OnPropertyChanged (PropertyChangedEventArgs
*args
, MoonError
*error
);
227 /* @Namespace=System.Windows.Shapes */
228 class Rectangle
: public Shape
{
230 virtual ~Rectangle () {}
231 virtual bool DrawShape (cairo_t
*cr
, bool do_op
);
232 virtual Rect
ComputeShapeBounds (bool logical
);
233 virtual Rect
ComputeStretchBounds ();
236 /* @PropertyType=double,DefaultValue=0.0,GenerateAccessors */
237 const static int RadiusXProperty
;
238 /* @PropertyType=double,DefaultValue=0.0,GenerateAccessors */
239 const static int RadiusYProperty
;
241 /* @GenerateCBinding,GeneratePInvoke */
244 virtual Rect
GetCoverageBounds ();
245 virtual void BuildPath ();
246 virtual bool CanFill () { return true; }
248 virtual void OnPropertyChanged (PropertyChangedEventArgs
*args
, MoonError
*error
);
251 // Property Accessors
253 void SetRadiusX (double radius
);
254 double GetRadiusX ();
256 void SetRadiusY (double radius
);
257 double GetRadiusY ();
264 /* @Namespace=System.Windows.Shapes */
265 class Line
: public Shape
{
268 virtual bool DrawShape (cairo_t
*cr
, bool do_op
);
269 virtual Rect
ComputeShapeBounds (bool logical
);
272 /* @PropertyType=double,DefaultValue=0.0,GenerateAccessors */
273 const static int X1Property
;
274 /* @PropertyType=double,DefaultValue=0.0,GenerateAccessors */
275 const static int Y1Property
;
276 /* @PropertyType=double,DefaultValue=0.0,GenerateAccessors */
277 const static int X2Property
;
278 /* @PropertyType=double,DefaultValue=0.0,GenerateAccessors */
279 const static int Y2Property
;
281 /* @GenerateCBinding,GeneratePInvoke */
282 Line () { SetObjectType (Type::LINE
); }
284 virtual void BuildPath ();
286 virtual void OnPropertyChanged (PropertyChangedEventArgs
*args
, MoonError
*error
);
288 // Line has no center to compute, it's always 0,0 because it provides it's own start and end
289 // virtual Point GetTransformOrigin ();
292 // Property Accessors
294 void SetX1 (double x1
);
297 void SetY1 (double y1
);
300 void SetX2 (double x2
);
303 void SetY2 (double y2
);
311 /* @Namespace=System.Windows.Shapes */
312 class Polygon
: public Shape
{
314 virtual ~Polygon () {}
315 virtual bool DrawShape (cairo_t
*cr
, bool do_op
);
317 PointCollection
*GetPoints ();
320 /* @PropertyType=FillRule,DefaultValue=FillRuleEvenOdd,GenerateAccessors */
321 const static int FillRuleProperty
;
322 /* @PropertyType=PointCollection,AutoCreateValue,GenerateAccessors */
323 const static int PointsProperty
;
325 /* @GenerateCBinding,GeneratePInvoke */
328 // Polygon has no center to compute, it's always 0,0 because it provides it's own start and end
329 // virtual Point GetTransformOrigin ();
331 virtual void BuildPath ();
333 virtual bool CanFill () { return true; }
335 virtual void OnPropertyChanged (PropertyChangedEventArgs
*args
, MoonError
*error
);
336 virtual void OnCollectionItemChanged (Collection
*col
, DependencyObject
*obj
, PropertyChangedEventArgs
*args
);
337 virtual void OnCollectionChanged (Collection
*col
, CollectionChangedEventArgs
*args
);
340 // Property Accessors
342 void SetFillRule (FillRule rule
);
343 virtual FillRule
GetFillRule ();
345 void SetPoints (PointCollection
*points
);
352 /* @Namespace=System.Windows.Shapes */
353 class Polyline
: public Shape
{
355 virtual ~Polyline () {}
356 virtual bool DrawShape (cairo_t
*cr
, bool do_op
);
358 PointCollection
*GetPoints ();
361 /* @PropertyType=FillRule,DefaultValue=FillRuleEvenOdd,GenerateAccessors */
362 const static int FillRuleProperty
;
363 /* @PropertyType=PointCollection,AutoCreateValue,GenerateAccessors */
364 const static int PointsProperty
;
366 /* @GenerateCBinding,GeneratePInvoke */
369 // Polyline has no center to compute, it's always 0,0 because it provides it's own start and end
370 // virtual Point GetTransformOrigin ();
372 virtual void BuildPath ();
374 virtual bool CanFill () { return true; }
376 virtual void OnPropertyChanged (PropertyChangedEventArgs
*args
, MoonError
*error
);
377 virtual void OnCollectionItemChanged (Collection
*col
, DependencyObject
*obj
, PropertyChangedEventArgs
*args
);
378 virtual void OnCollectionChanged (Collection
*col
, CollectionChangedEventArgs
*args
);
381 // Property Accessors
383 void SetFillRule (FillRule rule
);
384 virtual FillRule
GetFillRule ();
386 void SetPoints (PointCollection
*points
);
393 /* @Namespace=System.Windows.Shapes */
394 class Path
: public Shape
{
397 virtual bool SetupLine (cairo_t
*cr
);
398 virtual bool DrawShape (cairo_t
*cr
, bool do_op
);
399 virtual Rect
ComputeShapeBounds (bool logical
, cairo_matrix_t
*matrix
);
402 /* @PropertyType=Geometry,GenerateAccessors */
403 const static int DataProperty
;
405 /* @GenerateCBinding,GeneratePInvoke */
406 Path () { SetObjectType (Type::PATH
); }
408 // Path has no center to compute, it's always 0,0 because it provides it's own start and end
409 // virtual Point GetTransformOrigin ();
411 virtual void Draw (cairo_t
*cr
);
413 virtual bool CanFill () { return true; }
414 virtual FillRule
GetFillRule ();
416 virtual void OnPropertyChanged (PropertyChangedEventArgs
*args
, MoonError
*error
);
417 virtual void OnSubPropertyChanged (DependencyProperty
*prop
, DependencyObject
*obj
, PropertyChangedEventArgs
*subobj_args
);
420 // Property Accessors
422 void SetData (Geometry
*data
);
423 Geometry
*GetData ();
426 #endif /* __SHAPE_H__ */