Author: spouliot
Date: 2007-08-28 14:04:13 -0400 (Tue, 28 Aug 2007)
New Revision: 84968
Modified:
trunk/moon/src/ChangeLog
trunk/moon/src/geometry.cpp
trunk/moon/src/geometry.h
trunk/moon/src/panel.cpp
trunk/moon/src/shape.cpp
trunk/moon/src/shape.h
trunk/moon/src/uielement.cpp
trunk/moon/src/uielement.h
Log:
2007-08-28 Sebastien Pouliot <[EMAIL PROTECTED]>
* geometry.h: Add a Path* parameter to Draw as we need to know some
stuff (e.g. stroke thickness) in order to detect degenerate cases.
* geometry.cpp: Handle degenerate case for RectangleGeometry.
* panel.cpp, uielementy.cpp: Adjust Draw calls for optional Path
element (NULL in the case of clipping).
* shape.cpp|h: Move cairo_path_t caching logic from Path to Shape
class. Add GetFillRule method. Handle most cases where a large stroke
thickness change the SL drawing behaviour (wrt Cairo behaviour)
* uielement.h: Add flags for empty/normal/degenerate shapes
Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog 2007-08-28 17:52:22 UTC (rev 84967)
+++ trunk/moon/src/ChangeLog 2007-08-28 18:04:13 UTC (rev 84968)
@@ -1,3 +1,15 @@
+2007-08-28 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * geometry.h: Add a Path* parameter to Draw as we need to know some
+ stuff (e.g. stroke thickness) in order to detect degenerate cases.
+ * geometry.cpp: Handle degenerate case for RectangleGeometry.
+ * panel.cpp, uielementy.cpp: Adjust Draw calls for optional Path
+ element (NULL in the case of clipping).
+ * shape.cpp|h: Move cairo_path_t caching logic from Path to Shape
+ class. Add GetFillRule method. Handle most cases where a large stroke
+ thickness change the SL drawing behaviour (wrt Cairo behaviour)
+ * uielement.h: Add flags for empty/normal/degenerate shapes
+
2007-08-28 Rolf Bjarne Kvinge <[EMAIL PROTECTED]>
* panel.cpp: InsideObject: The point is only inside us if we have a
Modified: trunk/moon/src/geometry.cpp
===================================================================
--- trunk/moon/src/geometry.cpp 2007-08-28 17:52:22 UTC (rev 84967)
+++ trunk/moon/src/geometry.cpp 2007-08-28 18:04:13 UTC (rev 84968)
@@ -58,7 +58,7 @@
}
void
-Geometry::Draw (cairo_t *cr)
+Geometry::Draw (Path *path, cairo_t *cr)
{
cairo_set_fill_rule (cr, convert_fill_rule (geometry_get_fill_rule
(this)));
Transform* transform = geometry_get_transform (this);
@@ -92,10 +92,6 @@
this->SetValue (GeometryGroup::ChildrenProperty, Value (new
GeometryCollection ()));
}
-GeometryGroup::~GeometryGroup ()
-{
-}
-
void
GeometryGroup::OnPropertyChanged (DependencyProperty *prop)
{
@@ -132,17 +128,17 @@
}
void
-GeometryGroup::Draw (cairo_t *cr)
+GeometryGroup::Draw (Path *path, cairo_t *cr)
{
GeometryCollection *children = geometry_group_get_children (this);
Collection::Node *node;
- Geometry::Draw (cr);
+ Geometry::Draw (path, cr);
node = (Collection::Node *) children->list->First ();
for ( ; node != NULL; node = (Collection::Node *) node->Next ()) {
Geometry *geometry = (Geometry *) node->obj;
- geometry->Draw (cr);
+ geometry->Draw (path, cr);
}
}
@@ -241,9 +237,9 @@
}
void
-EllipseGeometry::Draw (cairo_t *cr)
+EllipseGeometry::Draw (Path *path, cairo_t *cr)
{
- Geometry::Draw (cr);
+ Geometry::Draw (path, cr);
Point *pt = ellipse_geometry_get_center (this);
double rx = ellipse_geometry_get_radius_x (this);
@@ -292,9 +288,9 @@
}
void
-LineGeometry::Draw (cairo_t *cr)
+LineGeometry::Draw (Path *path, cairo_t *cr)
{
- Geometry::Draw (cr);
+ Geometry::Draw (path, cr);
Point *p1 = line_geometry_get_start_point (this);
Point *p2 = line_geometry_get_end_point (this);
@@ -320,10 +316,6 @@
this->SetValue (PathGeometry::FiguresProperty, Value (new
PathFigureCollection ()));
}
-PathGeometry::~PathGeometry ()
-{
-}
-
void
PathGeometry::OnPropertyChanged (DependencyProperty *prop)
{
@@ -354,17 +346,17 @@
}
void
-PathGeometry::Draw (cairo_t *cr)
+PathGeometry::Draw (Path *path, cairo_t *cr)
{
PathFigureCollection *children = GetValue
(PathGeometry::FiguresProperty)->AsPathFigureCollection();
Collection::Node *node;
- Geometry::Draw (cr);
+ Geometry::Draw (path, cr);
node = (Collection::Node *) children->list->First ();
for ( ; node != NULL; node = (Collection::Node *) node->Next ()) {
PathFigure *pf = (PathFigure *) node->obj;
- pf->Draw (cr);
+ pf->Draw (path, cr);
}
}
@@ -433,26 +425,55 @@
}
void
-RectangleGeometry::Draw (cairo_t *cr)
+RectangleGeometry::Draw (Path *path, cairo_t *cr)
{
- Geometry::Draw (cr);
+ Geometry::Draw (path, cr);
Rect *rect = rectangle_geometry_get_rect (this);
if (!rect)
return;
- double radius_x = rectangle_geometry_get_radius_x (this);
- if (radius_x != 0) {
- double radius_y = rectangle_geometry_get_radius_y (this);
- if (radius_y != 0) {
- moon_rounded_rectangle (cr, rect->x, rect->y, rect->w,
rect->h, radius_x, radius_y);
- return;
+ double half_thick = 0.0;
+ // path is optional (e.g. not available for clipping)
+ if (path) {
+ double thick = shape_get_stroke_thickness (path);
+ if ((thick > rect->w) || (thick > rect->h)) {
+ half_thick = thick / 2.0;
+ rect->x -= half_thick;
+ rect->y -= half_thick;
+ rect->w += thick;
+ rect->h += thick;
+/* FIXME
+ * - this doesn't match MS-SL if mixed with some "normal" (non-degenerated)
geometry
+ */
+ path->SetShapeFlags (UIElement::SHAPE_DEGENERATE);
}
}
- // normal rectangle
- cairo_rectangle (cr, rect->x, rect->y, rect->w, rect->h);
+
+ double radius_x, radius_y;
+ if (GetRadius (&radius_x, &radius_y)) {
+ moon_rounded_rectangle (cr, rect->x, rect->y, rect->w, rect->h,
radius_x + half_thick, radius_y + half_thick);
+ } else {
+ cairo_rectangle (cr, rect->x, rect->y, rect->w, rect->h);
+ }
}
+bool
+RectangleGeometry::GetRadius (double *rx, double *ry)
+{
+ Value *value = GetValueNoDefault (RectangleGeometry::RadiusXProperty);
+ if (!value)
+ return false;
+ *rx = value->AsDouble ();
+
+ value = GetValueNoDefault (RectangleGeometry::RadiusYProperty);
+ if (!value)
+ return false;
+ *ry = value->AsDouble ();
+
+ return ((*rx != 0.0) && (*ry != 0.0));
+}
+
//
// PathFigure
//
@@ -506,7 +527,7 @@
}
void
-PathFigure::Draw (cairo_t *cr)
+PathFigure::Draw (Path *path, cairo_t *cr)
{
PathSegmentCollection *children = GetValue
(PathFigure::SegmentsProperty)->AsPathSegmentCollection ();
Point *start = path_figure_get_start_point (this);
Modified: trunk/moon/src/geometry.h
===================================================================
--- trunk/moon/src/geometry.h 2007-08-28 17:52:22 UTC (rev 84967)
+++ trunk/moon/src/geometry.h 2007-08-28 18:04:13 UTC (rev 84968)
@@ -33,7 +33,7 @@
virtual void OnPropertyChanged (DependencyProperty *prop);
- virtual void Draw (cairo_t *cr);
+ virtual void Draw (Path *path, cairo_t *cr);
virtual bool IsFilled () { return true; };
};
@@ -61,14 +61,13 @@
static DependencyProperty* ChildrenProperty;
GeometryGroup ();
- ~GeometryGroup ();
virtual Type::Kind GetObjectType () { return Type::GEOMETRYGROUP; };
virtual void OnPropertyChanged (DependencyProperty *prop);
virtual void OnSubPropertyChanged (DependencyProperty *prop,
DependencyProperty *subprop);
virtual void OnCollectionChanged (Collection *col, CollectionChangeType
type, DependencyObject *obj, DependencyProperty *prop);
- virtual void Draw (cairo_t *cr);
+ virtual void Draw (Path *path, cairo_t *cr);
};
GeometryGroup *geometry_group_new ();
GeometryCollection *geometry_group_get_children (GeometryGroup
*geometry_group);
@@ -86,7 +85,7 @@
EllipseGeometry () { };
virtual Type::Kind GetObjectType () { return Type::ELLIPSEGEOMETRY; };
- virtual void Draw (cairo_t *cr);
+ virtual void Draw (Path *path, cairo_t *cr);
};
EllipseGeometry* ellipse_geometry_new ();
Point* ellipse_geometry_get_center (EllipseGeometry *ellipse_geometry);
@@ -107,7 +106,7 @@
LineGeometry () { };
virtual Type::Kind GetObjectType () { return Type::LINEGEOMETRY; };
- virtual void Draw (cairo_t *cr);
+ virtual void Draw (Path *path, cairo_t *cr);
};
LineGeometry* line_geometry_new ();
Point* line_geometry_get_end_point (LineGeometry* line_geometry);
@@ -134,12 +133,11 @@
static DependencyProperty* FiguresProperty;
PathGeometry ();
- ~PathGeometry ();
virtual Type::Kind GetObjectType () { return Type::PATHGEOMETRY; };
virtual void OnPropertyChanged (DependencyProperty *prop);
virtual void OnCollectionChanged (Collection *col, CollectionChangeType
type, DependencyObject *obj, DependencyProperty *prop);
- virtual void Draw (cairo_t *cr);
+ virtual void Draw (Path *path, cairo_t *cr);
// this is an element-by-element decision
virtual bool IsFilled () { return true; }
@@ -160,7 +158,9 @@
RectangleGeometry () { };
virtual Type::Kind GetObjectType () { return Type::RECTANGLEGEOMETRY; };
- virtual void Draw (cairo_t *cr);
+ virtual void Draw (Path *path, cairo_t *cr);
+
+ bool GetRadius (double *rx, double *ry);
};
RectangleGeometry* rectangle_geometry_new ();
double rectangle_geometry_get_radius_x (RectangleGeometry *rectangle_geometry);
@@ -197,7 +197,7 @@
virtual void OnPropertyChanged (DependencyProperty *prop);
virtual void OnCollectionChanged (Collection *col, CollectionChangeType
type, DependencyObject *obj, DependencyProperty *prop);
- virtual void Draw (cairo_t *cr);
+ virtual void Draw (Path *path, cairo_t *cr);
};
PathFigure* path_figure_new ();
bool path_figure_get_is_closed (PathFigure *path_figure);
Modified: trunk/moon/src/panel.cpp
===================================================================
--- trunk/moon/src/panel.cpp 2007-08-28 17:52:22 UTC (rev 84967)
+++ trunk/moon/src/panel.cpp 2007-08-28 18:04:13 UTC (rev 84968)
@@ -216,7 +216,7 @@
Value *value = GetValue (UIElement::ClipProperty);
if (value) {
Geometry *geometry = value->AsGeometry ();
- geometry->Draw (cr);
+ geometry->Draw (NULL, cr);
cairo_clip (cr);
}
Modified: trunk/moon/src/shape.cpp
===================================================================
--- trunk/moon/src/shape.cpp 2007-08-28 17:52:22 UTC (rev 84967)
+++ trunk/moon/src/shape.cpp 2007-08-28 18:04:13 UTC (rev 84968)
@@ -82,6 +82,7 @@
double cx = x + rx;
double cy = y + ry;
+ // cairo_new_sub_path (cr); unrequired with the cairo_move_to call
cairo_move_to (cr, cx + rx, cy);
/* an approximate of the ellipse by drawing a curve in each
@@ -122,6 +123,7 @@
double c1 = ARC_TO_BEZIER * radius_x;
double c2 = ARC_TO_BEZIER * radius_y;
+ // cairo_new_sub_path (cr); unrequired with the cairo_move_to call
cairo_move_to (cr, x + radius_x, y);
cairo_rel_line_to (cr, w - 2 * radius_x, 0.0);
cairo_rel_curve_to (cr, c1, 0.0, radius_x, c2, radius_x, radius_y);
@@ -154,6 +156,8 @@
{
stroke = NULL;
fill = NULL;
+ path = NULL;
+ SetShapeFlags (UIElement::SHAPE_NORMAL);
}
Shape::~Shape ()
@@ -167,8 +171,27 @@
fill->Detach (NULL, this);
fill->unref ();
}
+ if (path) {
+ cairo_path_destroy (path);
+ }
}
+void
+Shape::Draw (cairo_t *cr)
+{
+#if FALSE
+ // yes that leaks but it's for debugging purpose only
+ BuildPath (cr);
+#else
+ if (path) {
+ cairo_new_path (cr);
+ cairo_append_path (cr, path);
+ } else {
+ BuildPath (cr);
+ }
+#endif
+}
+
bool
Shape::IsFilled ()
{
@@ -184,6 +207,11 @@
{
cairo_set_matrix (cr, &absolute_xform);
+ if (IsEmpty ()) {
+ cairo_new_path (cr);
+ return;
+ }
+
//printf ("Draw, xform: %g %g %g %g %g %g\n",
// absolute_xform.xy,
// absolute_xform.xx,
@@ -193,15 +221,17 @@
// absolute_xform.y0);
bool drawn = false;
+
// getting bounds, using cairo_stroke_extents, doesn't requires us to
fill (consider_fill)
// unless there is no stroke brush assigned, which requires us to fill
and use cairo_fill_extents
// also not every shapes can be filled, e.g. polylines, CallFill
- if ((consider_fill || !stroke) && IsFilled ()) {
+ if (!IsDegenerate () && (consider_fill || !stroke) && IsFilled ()) {
if (fill) {
Draw (cr);
drawn = true;
if (do_op) {
fill->SetupBrush (cr, this);
+ cairo_set_fill_rule (cr, convert_fill_rule
(GetFillRule ()));
cairo_fill_preserve (cr);
}
}
@@ -215,7 +245,10 @@
return;
}
- cairo_set_line_width (cr, thickness);
+ if (IsDegenerate ())
+ cairo_set_line_width (cr, 1.0);
+ else
+ cairo_set_line_width (cr, thickness);
int count = 0;
double offset = 0.0;
@@ -243,6 +276,8 @@
Draw (cr);
if (do_op) {
stroke->SetupBrush (cr, this);
+ if (IsDegenerate ())
+ cairo_fill_preserve (cr);
cairo_stroke (cr);
}
}
@@ -278,7 +313,6 @@
else
cairo_fill_extents (cr, &x1, &y1, &x2, &y2);
- cairo_new_path (cr);
cairo_restore (cr);
bounds = Rect (x1-1, y1-1, x2-x1 + 2, y2-y1 + 2);
@@ -326,11 +360,15 @@
Shape::OnPropertyChanged (DependencyProperty *prop)
{
if (prop->type != Type::SHAPE) {
+ if ((prop == FrameworkElement::HeightProperty) || (prop ==
FrameworkElement::WidthProperty))
+ InvalidatePathCache ();
+
FrameworkElement::OnPropertyChanged (prop);
return;
}
if (prop == Shape::StretchProperty) {
+ InvalidatePathCache ();
UpdateBounds ();
}
else if (prop == Shape::StrokeProperty) {
@@ -357,12 +395,14 @@
}
UpdateBounds ();
+ } else if (prop == Shape::StrokeThicknessProperty) {
+ InvalidatePathCache ();
+ UpdateBounds ();
} else if (prop == Shape::StrokeDashCapProperty
|| prop == Shape::StrokeEndLineCapProperty
|| prop == Shape::StrokeLineJoinProperty
|| prop == Shape::StrokeMiterLimitProperty
- || prop == Shape::StrokeStartLineCapProperty
- || prop == Shape::StrokeThicknessProperty) {
+ || prop == Shape::StrokeStartLineCapProperty) {
UpdateBounds ();
}
@@ -391,6 +431,16 @@
}
+void
+Shape::InvalidatePathCache ()
+{
+ SetShapeFlags (UIElement::SHAPE_NORMAL);
+ if (path) {
+ cairo_path_destroy (path);
+ path = NULL;
+ }
+}
+
Brush *
shape_get_fill (Shape *shape)
{
@@ -548,15 +598,36 @@
}
void
-Ellipse::Draw (cairo_t *cr)
+Ellipse::BuildPath (cairo_t *cr)
{
Stretch stretch = shape_get_stretch (this);
- if (stretch == StretchNone)
+ if (stretch == StretchNone) {
+ SetShapeFlags (UIElement::SHAPE_EMPTY);
return;
+ }
+ double x = 0.0;
+ double y = 0.0;
double w = framework_element_get_width (this);
double h = framework_element_get_height (this);
+ double t = shape_get_stroke_thickness (this);
+ double t2 = t * 2.0;
+
+ if ((t2 > w) || (t2 > h)) {
+ if (w < t)
+ w = t;
+ if (h < t)
+ h = t;
+ SetShapeFlags (UIElement::SHAPE_DEGENERATE);
+ } else {
+ double half = t / 2;
+ x = y = half;
+ w -= t;
+ h -= t;
+ SetShapeFlags (UIElement::SHAPE_NORMAL);
+ }
+
switch (stretch) {
case StretchUniform:
w = h = (w < h) ? w : h;
@@ -577,7 +648,15 @@
break;
}
- moon_ellipse (cr, 0, 0, w, h);
+ cairo_new_path (cr);
+ if (IsDegenerate ()) {
+ double radius = t / 2;
+ moon_rounded_rectangle (cr, x, y, w, h, radius, radius);
+ } else {
+ moon_ellipse (cr, x, y, w, h);
+ }
+ // note: both moon_rounded_rectangle and moon_ellipse calls
cairo_close_path
+ path = cairo_copy_path (cr);
}
Ellipse *
@@ -598,54 +677,145 @@
SetValue (Shape::StretchProperty, Value (StretchFill));
}
+/*
+ * rendering notes:
+ * - a Width="0" or a Height="0" can be rendered differently from not
specifying Width or Height
+ * - if a rectangle has only a Width or only a Height it is NEVER rendered
+ */
void
-Rectangle::Draw (cairo_t *cr)
+Rectangle::BuildPath (cairo_t *cr)
{
+ Value *width = GetValueNoDefault (FrameworkElement::WidthProperty);
+ Value *height = GetValueNoDefault (FrameworkElement::HeightProperty);
+
+ // nothing is drawn if only the width or only the height is specified
+ if ((!width && height) || (width && !height)) {
+ SetShapeFlags (UIElement::SHAPE_EMPTY);
+ return;
+ }
+
Stretch stretch = shape_get_stretch (this);
+ double t = shape_get_stroke_thickness (this);
+
+ // nothing is drawn (nor filled) if no StrokeThickness="0"
+ // unless both Width and Height are specified or when no streching is
required
+ if ((t == 0.0) && (!width || !height || (stretch == StretchNone))) {
+ SetShapeFlags (UIElement::SHAPE_EMPTY);
+ return;
+ }
+
+ double x = 0.5, y = 0.5;
double w, h;
-
- if (stretch == StretchNone) {
- // this gets us a single colored point at X,Y
- w = 0.5;
- h = 0.5;
- } else {
- w = framework_element_get_width (this);
- h = framework_element_get_height (this);
+ double radius_x, radius_y;
+ bool compute_origin = false;
+ // degenerate cases are handled differently for round-corner rectangles
+ bool round = GetRadius (&radius_x, &radius_y);
- switch (stretch) {
- case StretchUniform:
- w = h = (w < h) ? w : h;
- break;
- case StretchUniformToFill:
- // this gets an ellipse larger than it's dimension,
relative
- // scaling is ok but we need to clip to it's original
size
- cairo_rectangle (cr, 0, 0, w, h);
- cairo_clip (cr);
- w = h = (w > h) ? w : h;
- break;
- case StretchFill:
- /* nothing needed here. the assignment of w/h above
- is correct for this case. */
- break;
- case StretchNone:
- /* not reached */
- break;
+ cairo_new_path (cr);
+
+ // if both width and height are missing then the width and height are
equal (on screen) to the thickness
+ if ((!width && !height) || (stretch == StretchNone)) {
+ // don't make invisible points
+ x = 0.5;
+ if (t <= 1.0) {
+ if (t > 0.0)
+ y = 0.0;
+ w = h = 0.5;
+ } else {
+ w = h = (t - 1.0);
}
- double radius_x = rectangle_get_radius_x (this);
- if (radius_x != 0) {
- double radius_y = rectangle_get_radius_y (this);
- if (radius_y != 0) {
- moon_rounded_rectangle (cr, 0, 0, w, h,
radius_x, radius_y);
- return;
+ SetShapeFlags (UIElement::SHAPE_DEGENERATE);
+ goto shape;
+ }
+
+ w = width->AsDouble ();
+ h = height->AsDouble ();
+
+ // there are two kinds of degenerations
+ // (a) the thickness is larger (or equal) to the width or height
+ if ((t > w) || (t > h)) {
+ // in this case we must adjust the values to make a (much)
larger rectangle
+ x -= t / 2.0;
+ y -= t / 2.0 - 1.0;
+ if (stretch == StretchUniform) {
+ w = h = ((w < h) ? w : h) + t;
+ } else {
+ w += (t - 1.0);
+ h += (t - 1.0);
+ if (round)
+ radius_x = radius_y = t / 2;
+ }
+ SetShapeFlags (UIElement::SHAPE_DEGENERATE);
+ goto shape;
+ } else {
+ // (b) the thickness is larger (or equal) to half the width or
half the height
+ double t2 = t * 2.0;
+ if ((t2 >= w) || (t2 >= h)) {
+ x = 0.5;
+ if (stretch == StretchUniform) {
+ w = h = (w < h) ? w : h;
+ } else {
+ w -= 1.0;
+ h -= 1.0;
+ if (round) {
+ radius_x = w;
+ radius_y = h;
+ }
}
+ SetShapeFlags (UIElement::SHAPE_DEGENERATE);
+ goto shape;
}
}
-
- // normal rectangle
- cairo_new_path (cr);
- cairo_rectangle (cr, 0, 0, w, h);
- cairo_close_path (cr);
+
+ // both Width and Height are specified
+ if (stretch != StretchNone) {
+ compute_origin = true;
+ if (t > w - t) {
+ t = w / 2.0;
+ }
+ w -= t;
+ if (t > h - t) {
+ t = h / 2.0;
+ }
+ h -= t;
+ }
+
+ switch (stretch) {
+ case StretchNone:
+ break;
+ case StretchUniform:
+ w = h = (w < h) ? w : h;
+ break;
+ case StretchUniformToFill:
+ // this gets an ellipse larger than it's dimension, relative
+ // scaling is ok but we need to clip to it's original size
+ cairo_rectangle (cr, 0, 0, w + t, h + t);
+ cairo_clip (cr);
+ w = h = (w > h) ? w : h;
+ break;
+ case StretchFill:
+ /* nothing needed here. the assignment of w/h above
+ is correct for this case. */
+ break;
+ }
+
+ if ((t != 0.0) && compute_origin) {
+ x = t / 2.0;
+ y = x - 0.5;
+ }
+ SetShapeFlags (UIElement::SHAPE_NORMAL);
+
+shape:
+ // rounded-corner rectangle ?
+ if (round) {
+ moon_rounded_rectangle (cr, x, y, w, h, radius_x, radius_y);
+ } else {
+ cairo_rectangle (cr, x, y, w, h);
+ }
+
+ // no need to call cairo_close_path (cr) since both
mono_rounded_rectangle and cairo_rectangle calls it
+ path = cairo_copy_path (cr);
}
void
@@ -655,12 +825,31 @@
Shape::OnPropertyChanged (prop);
return;
}
+
+ if ((prop == Rectangle::RadiusXProperty) || (prop ==
Rectangle::RadiusYProperty))
+ InvalidatePathCache ();
Invalidate ();
NotifyAttacheesOfPropertyChange (prop);
}
+bool
+Rectangle::GetRadius (double *rx, double *ry)
+{
+ Value *value = GetValueNoDefault (Rectangle::RadiusXProperty);
+ if (!value)
+ return false;
+ *rx = value->AsDouble ();
+
+ value = GetValueNoDefault (Rectangle::RadiusYProperty);
+ if (!value)
+ return false;
+ *ry = value->AsDouble ();
+
+ return ((*rx != 0.0) && (*ry != 0.0));
+}
+
double
rectangle_get_radius_x (Rectangle *rectangle)
{
@@ -784,17 +973,25 @@
DependencyProperty* Polygon::FillRuleProperty;
DependencyProperty* Polygon::PointsProperty;
+FillRule
+Polygon::GetFillRule ()
+{
+ return polygon_get_fill_rule (this);
+}
+
void
-Polygon::Draw (cairo_t *cr)
+Polygon::BuildPath (cairo_t *cr)
{
int i, count = 0;
Point *points = polygon_get_points (this, &count);
- if (!points || (count < 1))
+ if (!points || (count < 1)) {
+ SetShapeFlags (UIElement::SHAPE_EMPTY);
return;
+ }
+ SetShapeFlags (UIElement::SHAPE_NORMAL);
cairo_new_path (cr);
- cairo_set_fill_rule (cr, convert_fill_rule (polygon_get_fill_rule
(this)));
Stretch stretch = shape_get_stretch (this);
switch (stretch) {
@@ -813,6 +1010,7 @@
}
cairo_close_path (cr);
+ path = cairo_copy_path (cr);
}
void
@@ -823,15 +1021,12 @@
return;
}
- if (prop->type == Type::POLYGON) {
- if (prop == Polygon::PointsProperty) {
- UpdateBounds (true /* force one here, even if the
bounds don't change */);
- }
- else {
- Invalidate ();
- }
+ if (prop == Polygon::PointsProperty) {
+ InvalidatePathCache ();
+ UpdateBounds (true /* force one here, even if the bounds don't
change */);
}
+ Invalidate ();
NotifyAttacheesOfPropertyChange (prop);
}
@@ -891,16 +1086,24 @@
DependencyProperty* Polyline::FillRuleProperty;
DependencyProperty* Polyline::PointsProperty;
+FillRule
+Polyline::GetFillRule ()
+{
+ return polyline_get_fill_rule (this);
+}
+
void
-Polyline::Draw (cairo_t *cr)
+Polyline::BuildPath (cairo_t *cr)
{
int i, count = 0;
Point *points = polyline_get_points (this, &count);
- if (!points || (count < 1))
+ if (!points || (count < 1)) {
+ SetShapeFlags (UIElement::SHAPE_EMPTY);
return;
+ }
- cairo_set_fill_rule (cr, convert_fill_rule (polyline_get_fill_rule
(this)));
+ SetShapeFlags (UIElement::SHAPE_NORMAL);
cairo_new_path (cr);
Stretch stretch = shape_get_stretch (this);
@@ -929,13 +1132,11 @@
}
if (prop == Polyline::PointsProperty) {
+ InvalidatePathCache ();
UpdateBounds (true /* force one here, even if the bounds don't
change */);
- Invalidate ();
}
- else {
- Invalidate ();
- }
+ Invalidate ();
NotifyAttacheesOfPropertyChange (prop);
}
@@ -995,32 +1196,25 @@
DependencyProperty* Path::DataProperty;
-Path::~Path ()
+FillRule
+Path::GetFillRule ()
{
- CleanupCache ();
+ Geometry* geometry = path_get_data (this);
+ return geometry ? geometry_get_fill_rule (geometry) :
Shape::GetFillRule ();
}
void
-Path::Draw (cairo_t *cr)
+Path::BuildPath (cairo_t *cr)
{
- Geometry* data = path_get_data (this);
- if (!data)
+ Geometry* geometry = path_get_data (this);
+ if (!geometry) {
+ SetShapeFlags (UIElement::SHAPE_EMPTY);
return;
+ }
- // compute and cache the path as some options, like stretch, can be
very expansive
- // to compute multiple times (e.g. fill, stroke and getbounds)
- if (!path)
- BuildPath (cr, data);
+ SetShapeFlags (UIElement::SHAPE_NORMAL);
+ geometry->Draw (this, cr);
- cairo_new_path (cr);
- cairo_append_path (cr, path);
-}
-
-void
-Path::BuildPath (cairo_t *cr, Geometry* geometry)
-{
- geometry->Draw (cr);
-
path = cairo_copy_path (cr);
Stretch stretch = shape_get_stretch (this);
@@ -1092,9 +1286,6 @@
break;
case StretchUniform:
sw = sh = (sw < sh) ? sw : sh;
- if (sw < sh) {
- } else {
- }
break;
case StretchUniformToFill:
cairo_new_path (cr);
@@ -1139,20 +1330,10 @@
break;
case CAIRO_PATH_CLOSE_PATH:
break;
- break;
}
}
}
-void
-Path::CleanupCache ()
-{
- if (path) {
- cairo_path_destroy (path);
- path = NULL;
- }
-}
-
bool
Path::IsFilled ()
{
@@ -1163,18 +1344,12 @@
void
Path::OnPropertyChanged (DependencyProperty *prop)
{
- /* base class property we have special code to handle */
- if (prop == Shape::StretchProperty) {
- CleanupCache ();
- }
-
if (prop->type != Type::PATH) {
Shape::OnPropertyChanged (prop);
return;
}
-
- CleanupCache ();
+ InvalidatePathCache ();
FullInvalidate (false);
NotifyAttacheesOfPropertyChange (prop);
@@ -1184,7 +1359,7 @@
Path::OnSubPropertyChanged (DependencyProperty *prop, DependencyProperty
*subprop)
{
if (prop == Path::DataProperty) {
- CleanupCache ();
+ InvalidatePathCache ();
FullInvalidate (false);
}
else
Modified: trunk/moon/src/shape.h
===================================================================
--- trunk/moon/src/shape.h 2007-08-28 17:52:22 UTC (rev 84967)
+++ trunk/moon/src/shape.h 2007-08-28 18:04:13 UTC (rev 84968)
@@ -39,6 +39,9 @@
class Shape : public FrameworkElement {
void DoDraw (cairo_t *cr, bool do_op, bool consider_fill);
Brush *stroke, *fill;
+ protected:
+ cairo_path_t *path;
+ void InvalidatePathCache ();
public:
static DependencyProperty* FillProperty;
static DependencyProperty* StretchProperty;
@@ -70,6 +73,7 @@
//
virtual bool IsFilled ();
+ virtual FillRule GetFillRule () { return FillRuleNonzero; }
//
// Draw: draws the Shape in the cairo context (affine transforms are
set before this
@@ -78,10 +82,17 @@
// This is called multiple times: one for fills, one for strokes
// if they are both set. It will also be called to compute the
bounding box.
//
- virtual void Draw (cairo_t *cr) = 0;
+ virtual void Draw (cairo_t *cr);
+ virtual void BuildPath (cairo_t *cr) {};
virtual void OnPropertyChanged (DependencyProperty *prop);
virtual void OnSubPropertyChanged (DependencyProperty *prop,
DependencyProperty *subprop);
+
+ //
+ bool IsEmpty () { return (flags & UIElement::SHAPE_EMPTY); };
+ bool IsNormal () { return (flags & UIElement::SHAPE_NORMAL); };
+ bool IsDegenerate () { return (flags & UIElement::SHAPE_DEGENERATE); };
+ void SetShapeFlags (UIElementFlags sf) { flags &=
~UIElement::SHAPE_MASK; flags |= sf; };
};
Brush *shape_get_fill (Shape *shape);
@@ -116,7 +127,7 @@
Ellipse ();
virtual Type::Kind GetObjectType () { return Type::ELLIPSE; };
- void Draw (cairo_t *cr);
+ virtual void BuildPath (cairo_t *cr);
};
Ellipse *ellipse_new (void);
@@ -133,9 +144,11 @@
Rectangle ();
virtual Type::Kind GetObjectType () { return Type::RECTANGLE; };
- void Draw (cairo_t *cr);
+ virtual void BuildPath (cairo_t *cr);
virtual void OnPropertyChanged (DependencyProperty *prop);
+
+ bool GetRadius (double *rx, double *ry);
};
Rectangle *rectangle_new (void);
@@ -192,7 +205,10 @@
// Polygon has no center to compute, it's always 0,0 because it
provides it's own start and end
// virtual Point GetTransformOrigin ();
- void Draw (cairo_t *cr);
+ virtual void BuildPath (cairo_t *cr);
+
+ virtual FillRule GetFillRule ();
+
virtual void OnPropertyChanged (DependencyProperty *prop);
virtual void OnCollectionChanged (Collection *col, CollectionChangeType
type, DependencyObject *obj, DependencyProperty *prop);
};
@@ -218,8 +234,10 @@
// Polyline has no center to compute, it's always 0,0 because it
provides it's own start and end
// virtual Point GetTransformOrigin ();
- void Draw (cairo_t *cr);
+ virtual void BuildPath (cairo_t *cr);
+ virtual FillRule GetFillRule ();
+
virtual void OnPropertyChanged (DependencyProperty *prop);
virtual void OnCollectionChanged (Collection *col, CollectionChangeType
type, DependencyObject *obj, DependencyProperty *prop);
};
@@ -235,24 +253,21 @@
// Path
//
class Path : public Shape {
- cairo_path_t *path;
-
- void BuildPath (cairo_t *cr, Geometry* geometry);
- void CleanupCache ();
public:
static DependencyProperty* DataProperty;
- Path () : path (NULL) {};
- ~Path ();
+ Path () {};
virtual Type::Kind GetObjectType () { return Type::PATH; };
// Path has no center to compute, it's always 0,0 because it provides
it's own start and end
// virtual Point GetTransformOrigin ();
- void Draw (cairo_t *cr);
+ virtual void BuildPath (cairo_t *cr);
virtual bool IsFilled ();
+ virtual FillRule GetFillRule ();
+
virtual void OnPropertyChanged (DependencyProperty *prop);
virtual void OnSubPropertyChanged (DependencyProperty *prop,
DependencyProperty *subprop);
};
Modified: trunk/moon/src/uielement.cpp
===================================================================
--- trunk/moon/src/uielement.cpp 2007-08-28 17:52:22 UTC (rev 84967)
+++ trunk/moon/src/uielement.cpp 2007-08-28 18:04:13 UTC (rev 84968)
@@ -254,7 +254,7 @@
cairo_save (cr);
- clip->Draw (cr);
+ clip->Draw (NULL, cr);
cairo_matrix_t inverse = absolute_xform;
cairo_matrix_invert (&inverse);
Modified: trunk/moon/src/uielement.h
===================================================================
--- trunk/moon/src/uielement.h 2007-08-28 17:52:22 UTC (rev 84967)
+++ trunk/moon/src/uielement.h 2007-08-28 18:04:13 UTC (rev 84968)
@@ -51,7 +51,12 @@
RENDER_VISIBLE = 0x02,
// the HitTestVisible property
- HIT_TEST_VISIBLE = 0x04
+ HIT_TEST_VISIBLE = 0x04,
+
+ SHAPE_EMPTY = 0x10, // there's is nothing to draw,
the cached path may be NULL
+ SHAPE_NORMAL = 0x20, // normal drawing
+ SHAPE_DEGENERATE = 0x40, // degenerate drawing, use the
Stroke brush for filling
+ SHAPE_MASK = 0x70
};
int flags;
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches