added MouseWheel event support for Silverlight 3.0
[moon.git] / src / geometry.h
blob48d291fa3f51bd3c2a793fb446c583be456066ca
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * geometry.h: Geometry classes
5 * Contact:
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__
17 #include <glib.h>
19 #include <cairo.h>
20 #include "enums.h"
21 #include "rect.h"
22 #include "transform.h"
23 #include "moon-path.h"
26 // Geometry
28 /* @Namespace=System.Windows.Media */
29 class Geometry : public DependencyObject {
30 protected:
31 #if 0
32 enum GeometryFlags {
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; }
44 int flags;
45 #endif
46 moon_path *path;
48 Rect local_bounds;
50 virtual ~Geometry ();
51 virtual Rect ComputePathBounds ();
53 public:
54 /* @PropertyType=Transform,GenerateAccessors */
55 const static int TransformProperty;
57 /* @GenerateCBinding,GeneratePInvoke,ManagedAccess=Internal */
58 Geometry ();
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 */
66 Rect GetBounds ();
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; }
78 // Property Accessors
80 virtual FillRule GetFillRule () { return FillRuleNonzero; };
82 void SetTransform (Transform *transform);
83 Transform *GetTransform ();
88 // GeometryCollection
90 /* @Namespace=System.Windows.Media */
91 class GeometryCollection : public DependencyObjectCollection {
92 protected:
93 virtual ~GeometryCollection ();
95 public:
96 /* @GenerateCBinding,GeneratePInvoke */
97 GeometryCollection ();
99 virtual Type::Kind GetElementType () { return Type::GEOMETRY; }
104 // GeometryGroup
106 /* @ContentProperty="Children" */
107 /* @Namespace=System.Windows.Media */
108 class GeometryGroup : public Geometry {
109 protected:
110 virtual ~GeometryGroup ();
111 virtual Rect ComputePathBounds ();
113 public:
114 /* @PropertyType=FillRule,DefaultValue=FillRuleEvenOdd,GenerateAccessors */
115 const static int FillRuleProperty;
116 /* @PropertyType=GeometryCollection,AutoCreateValue,GenerateAccessors */
117 const static int ChildrenProperty;
119 /* @GenerateCBinding,GeneratePInvoke */
120 GeometryGroup ();
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 ();
139 // EllipseGeometry
141 /* @Namespace=System.Windows.Media */
142 class EllipseGeometry : public Geometry {
143 protected:
144 virtual void Build ();
146 virtual ~EllipseGeometry ();
147 virtual Rect ComputePathBounds ();
149 public:
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 */
158 EllipseGeometry ();
161 // Property Accessors
163 void SetCenter (Point *center);
164 Point *GetCenter ();
166 void SetRadiusX (double radius);
167 double GetRadiusX ();
169 void SetRadiusY (double radius);
170 double GetRadiusY ();
175 // LineGeometry
177 /* @Namespace=System.Windows.Media */
178 class LineGeometry : public Geometry {
179 protected:
180 virtual void Build ();
182 virtual ~LineGeometry ();
183 virtual Rect ComputePathBounds ();
185 public:
186 /* @PropertyType=Point,GenerateAccessors */
187 const static int EndPointProperty;
188 /* @PropertyType=Point,GenerateAccessors */
189 const static int StartPointProperty;
191 /* @GenerateCBinding,GeneratePInvoke */
192 LineGeometry ();
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 {
210 protected:
211 virtual ~PathFigureCollection ();
213 public:
214 /* @GenerateCBinding,GeneratePInvoke */
215 PathFigureCollection ();
217 virtual Type::Kind GetElementType () { return Type::PATHFIGURE; }
222 // PathGeometry
224 /* @ContentProperty="Figures" */
225 /* @Namespace=System.Windows.Media */
226 class PathGeometry : public Geometry {
227 protected:
228 virtual void Build ();
230 virtual ~PathGeometry ();
231 virtual Rect ComputePathBounds ();
233 public:
234 /* @PropertyType=FillRule,DefaultValue=FillRuleEvenOdd,GenerateAccessors */
235 const static int FillRuleProperty;
236 /* @PropertyType=PathFigureCollection,AutoCreateValue,GenerateAccessors */
237 const static int FiguresProperty;
239 /* @GenerateCBinding,GeneratePInvoke */
240 PathGeometry ();
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 ();
261 // RectangleGeometry
263 /* @Namespace=System.Windows.Media */
264 class RectangleGeometry : public Geometry {
265 protected:
266 virtual void Build ();
268 virtual ~RectangleGeometry ();
269 virtual Rect ComputePathBounds ();
271 public:
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 ();
283 // Property Accesors
285 void SetRadiusX (double radius);
286 double GetRadiusX ();
288 void SetRadiusY (double radius);
289 double GetRadiusY ();
291 void SetRect (Rect *rect);
292 Rect *GetRect ();
297 // PathSegmentCollection
299 /* @Namespace=System.Windows.Media */
300 class PathSegmentCollection : public DependencyObjectCollection {
301 protected:
302 virtual ~PathSegmentCollection ();
304 public:
305 /* @GenerateCBinding,GeneratePInvoke */
306 PathSegmentCollection ();
308 virtual Type::Kind GetElementType () { return Type::PATHSEGMENT; }
313 // PathFigure
315 /* @ContentProperty="Segments" */
316 /* @Namespace=System.Windows.Media */
317 class PathFigure : public DependencyObject {
318 protected:
319 virtual ~PathFigure ();
321 public:
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;
331 moon_path *path;
333 /* @GenerateCBinding,GeneratePInvoke */
334 PathFigure ();
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);
348 bool GetIsClosed ();
350 void SetIsFilled (bool value);
351 bool GetIsFilled ();
353 void SetSegments (PathSegmentCollection *segments);
354 PathSegmentCollection *GetSegments ();
356 void SetStartPoint (Point *point);
357 Point *GetStartPoint ();
362 // PathSegment
364 /* @Namespace=System.Windows.Media */
365 class PathSegment : public DependencyObject {
366 protected:
367 virtual void Build ();
369 virtual ~PathSegment ();
371 public:
372 /* @GenerateCBinding,GeneratePInvoke,ManagedAccess=Internal */
373 PathSegment ();
375 virtual void Append (moon_path *path);
376 virtual int GetPathSize () { return 0; }
381 // ArcSegment
383 /* @Namespace=System.Windows.Media */
384 class ArcSegment : public PathSegment {
385 protected:
386 virtual ~ArcSegment ();
388 public:
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 */
401 ArcSegment ();
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);
414 Point *GetPoint ();
416 void SetRotationAngle (double angle);
417 double GetRotationAngle ();
419 void SetSize (Size *size);
420 Size *GetSize ();
422 void SetSweepDirection (SweepDirection direction);
423 SweepDirection GetSweepDirection ();
428 // BezierSegment
430 /* @Namespace=System.Windows.Media */
431 class BezierSegment : public PathSegment {
432 protected:
433 virtual ~BezierSegment ();
435 public:
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 */
444 BezierSegment ();
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);
454 Point *GetPoint1 ();
456 void SetPoint2 (Point *point);
457 Point *GetPoint2 ();
459 void SetPoint3 (Point *point);
460 Point *GetPoint3 ();
465 // LineSegment
467 /* @Namespace=System.Windows.Media */
468 class LineSegment : public PathSegment {
469 protected:
470 virtual ~LineSegment ();
472 public:
473 /* @PropertyType=Point,GenerateAccessors */
474 const static int PointProperty;
476 /* @GenerateCBinding,GeneratePInvoke */
477 LineSegment ();
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);
487 Point *GetPoint ();
492 // PolyBezierSegment
494 /* @Namespace=System.Windows.Media */
495 class PolyBezierSegment : public PathSegment {
496 protected:
497 virtual ~PolyBezierSegment ();
499 PointCollection *GetPoints ();
501 public:
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);
521 // PolyLineSegment
523 /* @Namespace=System.Windows.Media */
524 class PolyLineSegment : public PathSegment {
525 protected:
526 virtual ~PolyLineSegment ();
528 PointCollection *GetPoints ();
530 public:
531 /* @PropertyType=PointCollection,AutoCreateValue,GenerateAccessors */
532 const static int PointsProperty;
534 /* @GenerateCBinding,GeneratePInvoke */
535 PolyLineSegment ();
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 {
553 protected:
554 virtual ~PolyQuadraticBezierSegment ();
556 PointCollection *GetPoints ();
558 public:
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 {
581 protected:
582 virtual ~QuadraticBezierSegment ();
584 public:
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);
601 Point *GetPoint1 ();
603 void SetPoint2 (Point *point);
604 Point *GetPoint2 ();
607 #endif