1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * geometry.h: Geometry classes
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.
14 #ifndef __GEOMETRY_H__
15 #define __GEOMETRY_H__
22 #include "transform.h"
23 #include "moon-path.h"
28 /* @Namespace=System.Windows.Media */
29 class Geometry
: public DependencyObject
{
33 GEOMETRY_NORMAL
= 0x01, // normal drawing
34 GEOMETRY_DEGENERATE
= 0x02, // degenerate drawing, use the Stroke brush for filling
35 GEOMETRY_NEEDS_FILL
= 0x04, // filling, if specified, is needed (e.g. LineGeometry doesn't need it)
36 GEOMETRY_NEEDS_CAPS
= 0x08, // Stroke[Start|End]LineCap
37 GEOMETRY_NEEDS_JOIN
= 0x10, // StrokeLineJoin, StrokeMiterLimit
38 GEOMETRY_MASK
= GEOMETRY_NORMAL
| GEOMETRY_DEGENERATE
| GEOMETRY_NEEDS_FILL
| GEOMETRY_NEEDS_CAPS
| GEOMETRY_NEEDS_JOIN
41 bool IsDegenerate () { return (flags
& Geometry::GEOMETRY_DEGENERATE
); }
42 void SetGeometryFlags (GeometryFlags sf
) { flags
&= ~Geometry::GEOMETRY_MASK
; flags
|= sf
; }
51 virtual Rect
ComputePathBounds ();
54 /* @PropertyType=Transform,GenerateAccessors */
55 const static int TransformProperty
;
57 /* @GenerateCBinding,GeneratePInvoke,ManagedAccess=Internal */
60 virtual void OnPropertyChanged (PropertyChangedEventArgs
*args
, MoonError
*error
);
61 virtual void OnSubPropertyChanged (DependencyProperty
*prop
, DependencyObject
*obj
, PropertyChangedEventArgs
*subprop_args
);
63 virtual void Draw (cairo_t
*cr
);
65 /* @GenerateCBinding,GeneratePInvoke */
67 void InvalidateCache ();
69 //virtual Point GetOriginPoint (Path *path);
71 virtual bool IsFilled () { return true; }
73 virtual void Build () {}
74 virtual bool IsBuilt () { return path
&& path
->cairo
.num_data
!= 0; }
75 virtual cairo_path_t
*GetCairoPath () { return (path
) ? &path
->cairo
: NULL
; }
80 virtual FillRule
GetFillRule () { return FillRuleNonzero
; };
82 void SetTransform (Transform
*transform
);
83 Transform
*GetTransform ();
90 /* @Namespace=System.Windows.Media */
91 class GeometryCollection
: public DependencyObjectCollection
{
93 virtual ~GeometryCollection ();
96 /* @GenerateCBinding,GeneratePInvoke */
97 GeometryCollection ();
99 virtual Type::Kind
GetElementType () { return Type::GEOMETRY
; }
106 /* @ContentProperty="Children" */
107 /* @Namespace=System.Windows.Media */
108 class GeometryGroup
: public Geometry
{
110 virtual ~GeometryGroup ();
111 virtual Rect
ComputePathBounds ();
114 /* @PropertyType=FillRule,DefaultValue=FillRuleEvenOdd,GenerateAccessors */
115 const static int FillRuleProperty
;
116 /* @PropertyType=GeometryCollection,AutoCreateValue,GenerateAccessors */
117 const static int ChildrenProperty
;
119 /* @GenerateCBinding,GeneratePInvoke */
122 virtual void OnCollectionItemChanged (Collection
*col
, DependencyObject
*obj
, PropertyChangedEventArgs
*args
);
123 virtual void OnCollectionChanged (Collection
*col
, CollectionChangedEventArgs
*args
);
125 virtual void Draw (cairo_t
*cr
);
128 // Property Accessors
130 void SetFillRule (FillRule rule
);
131 virtual FillRule
GetFillRule ();
133 void SetChildren (GeometryCollection
*children
);
134 GeometryCollection
*GetChildren ();
141 /* @Namespace=System.Windows.Media */
142 class EllipseGeometry
: public Geometry
{
144 virtual void Build ();
146 virtual ~EllipseGeometry ();
147 virtual Rect
ComputePathBounds ();
150 /* @PropertyType=Point,GenerateAccessors */
151 const static int CenterProperty
;
152 /* @PropertyType=double,DefaultValue=0.0,GenerateAccessors */
153 const static int RadiusXProperty
;
154 /* @PropertyType=double,DefaultValue=0.0,GenerateAccessors */
155 const static int RadiusYProperty
;
157 /* @GenerateCBinding,GeneratePInvoke */
161 // Property Accessors
163 void SetCenter (Point
*center
);
166 void SetRadiusX (double radius
);
167 double GetRadiusX ();
169 void SetRadiusY (double radius
);
170 double GetRadiusY ();
177 /* @Namespace=System.Windows.Media */
178 class LineGeometry
: public Geometry
{
180 virtual void Build ();
182 virtual ~LineGeometry ();
183 virtual Rect
ComputePathBounds ();
186 /* @PropertyType=Point,GenerateAccessors */
187 const static int EndPointProperty
;
188 /* @PropertyType=Point,GenerateAccessors */
189 const static int StartPointProperty
;
191 /* @GenerateCBinding,GeneratePInvoke */
195 // Property Accessors
197 void SetEndPoint (Point
*point
);
198 Point
*GetEndPoint ();
200 void SetStartPoint (Point
*point
);
201 Point
*GetStartPoint ();
206 // PathFigureCollection
208 /* @Namespace=System.Windows.Media */
209 class PathFigureCollection
: public DependencyObjectCollection
{
211 virtual ~PathFigureCollection ();
214 /* @GenerateCBinding,GeneratePInvoke */
215 PathFigureCollection ();
217 virtual Type::Kind
GetElementType () { return Type::PATHFIGURE
; }
224 /* @ContentProperty="Figures" */
225 /* @Namespace=System.Windows.Media */
226 class PathGeometry
: public Geometry
{
228 virtual void Build ();
230 virtual ~PathGeometry ();
231 virtual Rect
ComputePathBounds ();
234 /* @PropertyType=FillRule,DefaultValue=FillRuleEvenOdd,GenerateAccessors */
235 const static int FillRuleProperty
;
236 /* @PropertyType=PathFigureCollection,AutoCreateValue,GenerateAccessors */
237 const static int FiguresProperty
;
239 /* @GenerateCBinding,GeneratePInvoke */
241 PathGeometry (moon_path
*pml_path
);
243 virtual void OnCollectionItemChanged (Collection
*col
, DependencyObject
*obj
, PropertyChangedEventArgs
*args
);
244 virtual void OnCollectionChanged (Collection
*col
, CollectionChangedEventArgs
*args
);
246 // this is an element-by-element decision
247 virtual bool IsFilled () { return true; }
250 // Property Accessors
252 void SetFillRule (FillRule rule
);
253 virtual FillRule
GetFillRule ();
255 void SetFigures (PathFigureCollection
*figures
);
256 PathFigureCollection
*GetFigures ();
263 /* @Namespace=System.Windows.Media */
264 class RectangleGeometry
: public Geometry
{
266 virtual void Build ();
268 virtual ~RectangleGeometry ();
269 virtual Rect
ComputePathBounds ();
272 /* @PropertyType=double,DefaultValue=0.0,GenerateAccessors */
273 const static int RadiusXProperty
;
274 /* @PropertyType=double,DefaultValue=0.0,GenerateAccessors */
275 const static int RadiusYProperty
;
276 /* @PropertyType=Rect,GenerateAccessors */
277 const static int RectProperty
;
279 /* @GenerateCBinding,GeneratePInvoke */
280 RectangleGeometry ();
285 void SetRadiusX (double radius
);
286 double GetRadiusX ();
288 void SetRadiusY (double radius
);
289 double GetRadiusY ();
291 void SetRect (Rect
*rect
);
297 // PathSegmentCollection
299 /* @Namespace=System.Windows.Media */
300 class PathSegmentCollection
: public DependencyObjectCollection
{
302 virtual ~PathSegmentCollection ();
305 /* @GenerateCBinding,GeneratePInvoke */
306 PathSegmentCollection ();
308 virtual Type::Kind
GetElementType () { return Type::PATHSEGMENT
; }
315 /* @ContentProperty="Segments" */
316 /* @Namespace=System.Windows.Media */
317 class PathFigure
: public DependencyObject
{
319 virtual ~PathFigure ();
322 /* @PropertyType=bool,DefaultValue=false,GenerateAccessors */
323 const static int IsClosedProperty
;
324 /* @PropertyType=PathSegmentCollection,AutoCreateValue,GenerateAccessors */
325 const static int SegmentsProperty
;
326 /* @PropertyType=Point,GenerateAccessors */
327 const static int StartPointProperty
;
328 /* @PropertyType=bool,DefaultValue=true,Version=2,GenerateAccessors */
329 const static int IsFilledProperty
;
333 /* @GenerateCBinding,GeneratePInvoke */
336 virtual void OnPropertyChanged (PropertyChangedEventArgs
*args
, MoonError
*error
);
337 virtual void OnCollectionItemChanged (Collection
*col
, DependencyObject
*obj
, PropertyChangedEventArgs
*args
);
338 virtual void OnCollectionChanged (Collection
*col
, CollectionChangedEventArgs
*args
);
339 virtual void Build ();
341 virtual bool IsBuilt () { return path
&& path
->cairo
.num_data
!= 0; }
342 virtual cairo_path_t
*GetCairoPath () { return (path
) ? &path
->cairo
: NULL
; }
345 // Property Accessors
347 void SetIsClosed (bool closed
);
350 void SetIsFilled (bool value
);
353 void SetSegments (PathSegmentCollection
*segments
);
354 PathSegmentCollection
*GetSegments ();
356 void SetStartPoint (Point
*point
);
357 Point
*GetStartPoint ();
364 /* @Namespace=System.Windows.Media */
365 class PathSegment
: public DependencyObject
{
367 virtual void Build ();
369 virtual ~PathSegment ();
372 /* @GenerateCBinding,GeneratePInvoke,ManagedAccess=Internal */
375 virtual void Append (moon_path
*path
);
376 virtual int GetPathSize () { return 0; }
383 /* @Namespace=System.Windows.Media */
384 class ArcSegment
: public PathSegment
{
386 virtual ~ArcSegment ();
389 /* @PropertyType=bool,DefaultValue=false,GenerateAccessors */
390 const static int IsLargeArcProperty
;
391 /* @PropertyType=Point,GenerateAccessors */
392 const static int PointProperty
;
393 /* @PropertyType=double,DefaultValue=0.0,GenerateAccessors */
394 const static int RotationAngleProperty
;
395 /* @PropertyType=Size,GenerateAccessors */
396 const static int SizeProperty
;
397 /* @PropertyType=SweepDirection,DefaultValue=SweepDirectionCounterclockwise,GenerateAccessors */
398 const static int SweepDirectionProperty
;
400 /* @GenerateCBinding,GeneratePInvoke */
403 virtual int GetPathSize () { return 4 * MOON_PATH_CURVE_TO_LENGTH
; } // non-optimal size, depends on angle
405 virtual void Append (moon_path
*path
);
408 // Property Accessors
410 void SetIsLargeArc (bool large
);
411 bool GetIsLargeArc ();
413 void SetPoint (Point
*point
);
416 void SetRotationAngle (double angle
);
417 double GetRotationAngle ();
419 void SetSize (Size
*size
);
422 void SetSweepDirection (SweepDirection direction
);
423 SweepDirection
GetSweepDirection ();
430 /* @Namespace=System.Windows.Media */
431 class BezierSegment
: public PathSegment
{
433 virtual ~BezierSegment ();
436 /* @PropertyType=Point,GenerateAccessors */
437 const static int Point1Property
;
438 /* @PropertyType=Point,GenerateAccessors */
439 const static int Point2Property
;
440 /* @PropertyType=Point,GenerateAccessors */
441 const static int Point3Property
;
443 /* @GenerateCBinding,GeneratePInvoke */
446 virtual int GetPathSize () { return MOON_PATH_CURVE_TO_LENGTH
; }
448 virtual void Append (moon_path
*path
);
451 // Property Accessors
453 void SetPoint1 (Point
*point
);
456 void SetPoint2 (Point
*point
);
459 void SetPoint3 (Point
*point
);
467 /* @Namespace=System.Windows.Media */
468 class LineSegment
: public PathSegment
{
470 virtual ~LineSegment ();
473 /* @PropertyType=Point,GenerateAccessors */
474 const static int PointProperty
;
476 /* @GenerateCBinding,GeneratePInvoke */
479 virtual int GetPathSize () { return MOON_PATH_LINE_TO_LENGTH
; }
481 virtual void Append (moon_path
*path
);
484 // Property Accessors
486 void SetPoint (Point
*point
);
494 /* @Namespace=System.Windows.Media */
495 class PolyBezierSegment
: public PathSegment
{
497 virtual ~PolyBezierSegment ();
499 PointCollection
*GetPoints ();
502 /* @PropertyType=PointCollection,AutoCreateValue,GenerateAccessors */
503 const static int PointsProperty
;
505 /* @GenerateCBinding,GeneratePInvoke */
506 PolyBezierSegment ();
508 virtual int GetPathSize ();
510 virtual void Append (moon_path
*path
);
513 // Property Accessors
515 /* @GenerateCBinding */
516 void SetPoints (PointCollection
*points
);
523 /* @Namespace=System.Windows.Media */
524 class PolyLineSegment
: public PathSegment
{
526 virtual ~PolyLineSegment ();
528 PointCollection
*GetPoints ();
531 /* @PropertyType=PointCollection,AutoCreateValue,GenerateAccessors */
532 const static int PointsProperty
;
534 /* @GenerateCBinding,GeneratePInvoke */
537 virtual int GetPathSize ();
539 virtual void Append (moon_path
*path
);
542 // Property Accessors
544 void SetPoints (PointCollection
*points
);
549 // PolyQuadraticBezierSegment
551 /* @Namespace=System.Windows.Media */
552 class PolyQuadraticBezierSegment
: public PathSegment
{
554 virtual ~PolyQuadraticBezierSegment ();
556 PointCollection
*GetPoints ();
559 /* @PropertyType=PointCollection,AutoCreateValue,GenerateAccessors */
560 const static int PointsProperty
;
562 /* @GenerateCBinding,GeneratePInvoke */
563 PolyQuadraticBezierSegment ();
565 virtual int GetPathSize ();
567 virtual void Append (moon_path
*path
);
570 // Property Accessors
572 void SetPoints (PointCollection
*points
);
577 // QuadraticBezierSegment
579 /* @Namespace=System.Windows.Media */
580 class QuadraticBezierSegment
: public PathSegment
{
582 virtual ~QuadraticBezierSegment ();
585 /* @PropertyType=Point,GenerateAccessors */
586 const static int Point1Property
;
587 /* @PropertyType=Point,GenerateAccessors */
588 const static int Point2Property
;
590 /* @GenerateCBinding,GeneratePInvoke */
591 QuadraticBezierSegment ();
593 virtual int GetPathSize () { return MOON_PATH_CURVE_TO_LENGTH
; }
595 virtual void Append (moon_path
*path
);
598 // Property Accessors
600 void SetPoint1 (Point
*point
);
603 void SetPoint2 (Point
*point
);