Author: spouliot
Date: 2007-12-13 16:14:39 -0500 (Thu, 13 Dec 2007)
New Revision: 91252
Modified:
trunk/moon/src/ChangeLog
trunk/moon/src/shape.cpp
trunk/moon/src/shape.h
Log:
2007-12-13 Sebastien Pouliot <[EMAIL PROTECTED]>
* shape.cpp|h: Shortcut path bounds calculation when both Width
and Height are specified. Add same clipping rules to Line,
Polyline and Polygon classes.
Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog 2007-12-13 20:04:14 UTC (rev 91251)
+++ trunk/moon/src/ChangeLog 2007-12-13 21:14:39 UTC (rev 91252)
@@ -1,3 +1,9 @@
+2007-12-13 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * shape.cpp|h: Shortcut path bounds calculation when both Width
+ and Height are specified. Add same clipping rules to Line,
+ Polyline and Polygon classes.
+
2007-12-13 Sebastien Pouliot <[EMAIL PROTECTED]>
* geometry.cpp: Resume using cairo_stroke_extents in some cases
Modified: trunk/moon/src/shape.cpp
===================================================================
--- trunk/moon/src/shape.cpp 2007-12-13 20:04:14 UTC (rev 91251)
+++ trunk/moon/src/shape.cpp 2007-12-13 21:14:39 UTC (rev 91252)
@@ -118,9 +118,37 @@
bool
Shape::NeedsClipping ()
{
- return (!IsDegenerate () && (shape_get_stretch (this) ==
StretchUniformToFill));
+ if (!IsDegenerate () && (shape_get_stretch (this) ==
StretchUniformToFill))
+ return true;
+
+ // some shapes, like Line, Polyline, Polygon and Path, are clipped if
both Height and Width properties are present
+ if (!ClipOnHeightAndWidth ())
+ return false;
+
+ Value *vh = GetValueNoDefault (FrameworkElement::HeightProperty);
+ if (!vh)
+ return false;
+
+ return (GetValueNoDefault (FrameworkElement::WidthProperty) != NULL);
}
+bool
+Shape::MixedHeightWidth (Value **height, Value **width)
+{
+ Value *vw = GetValueNoDefault (FrameworkElement::WidthProperty);
+ Value *vh = GetValueNoDefault (FrameworkElement::HeightProperty);
+
+ // nothing is drawn if only the width or only the height is specified
+ if ((!vw && vh) || (vw && !vh)) {
+ SetShapeFlags (UIElement::SHAPE_EMPTY);
+ return true;
+ }
+
+ if (width) *width = vw;
+ if (height) *height = vh;
+ return false;
+}
+
void
Shape::Draw (cairo_t *cr)
{
@@ -607,14 +635,9 @@
void
Ellipse::BuildPath ()
{
- 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);
+ Value *height, *width;
+ if (Shape::MixedHeightWidth (&height, &width))
return;
- }
Stretch stretch = shape_get_stretch (this);
double x = 0.0;
@@ -731,14 +754,9 @@
void
Rectangle::BuildPath ()
{
- 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);
+ Value *height, *width;
+ if (Shape::MixedHeightWidth (&height, &width))
return;
- }
Stretch stretch = shape_get_stretch (this);
double t = IsStroked () ? shape_get_stroke_thickness (this) : 0.0;
@@ -989,6 +1007,9 @@
void
Line::BuildPath ()
{
+ if (Shape::MixedHeightWidth (NULL, NULL))
+ return;
+
SetShapeFlags (UIElement::SHAPE_NORMAL);
path = moon_path_renew (path, MOON_PATH_MOVE_TO_LENGTH +
MOON_PATH_LINE_TO_LENGTH);
@@ -1000,6 +1021,12 @@
void
Line::ComputeBounds ()
{
+ Value *vh, *vw;
+ if (Shape::MixedHeightWidth (&vh, &vw)) {
+ bounds = Rect (0.0, 0.0, 0.0, 0.0);
+ return;
+ }
+
double thickness = shape_get_stroke_thickness (this);
if (thickness <= 0.0) {
bounds = Rect (0.0, 0.0, 0.0, 0.0);
@@ -1008,6 +1035,13 @@
calc_line_bounds (line_get_x1 (this), line_get_x2 (this), line_get_y1
(this), line_get_y2 (this), thickness, &bounds);
+ // if Height and Width are specified (they could be both missing)
+ // then we must clip the line those values
+ if (vh && vw) {
+ bounds.w = MIN (bounds.w, vw->AsDouble ());
+ bounds.h = MIN (bounds.h, vh->AsDouble ());
+ }
+
bounds = bounding_rect_for_transformed_rect (&absolute_xform,
IntersectBoundsWithClipPath (bounds, false));
}
@@ -1228,14 +1262,20 @@
void
Polygon::ComputeBounds ()
{
- bounds = Rect (0.0, 0.0, 0.0, 0.0);
+ Value *vh, *vw;
+ if (Shape::MixedHeightWidth (&vh, &vw)) {
+ bounds = Rect (0.0, 0.0, 0.0, 0.0);
+ return;
+ }
int i, count = 0;
Point *points = polygon_get_points (this, &count);
// the first point is a move to, resulting in an empty shape
- if (!points || (count < 2))
+ if (!points || (count < 2)) {
+ bounds = Rect (0.0, 0.0, 0.0, 0.0);
return;
+ }
double thickness = shape_get_stroke_thickness (this);
if (thickness == 0.0)
@@ -1294,6 +1334,14 @@
bounds.y -= y0;
}
+ // if Height and Width are specified (they could be both missing)
+ // then we must clip the path those values, and this also defines
+ // *exactly* our bounds (whether we like them or not is another story)
+ if (vh && vw) {
+ bounds.w = vw->AsDouble ();
+ bounds.h = vh->AsDouble ();
+ }
+
bounds = bounding_rect_for_transformed_rect (&absolute_xform,
IntersectBoundsWithClipPath (bounds, false));
}
@@ -1301,6 +1349,9 @@
void
Polygon::BuildPath ()
{
+ if (Shape::MixedHeightWidth (NULL, NULL))
+ return;
+
int i, count = 0;
Point *points = polygon_get_points (this, &count);
@@ -1453,14 +1504,20 @@
void
Polyline::ComputeBounds ()
{
- bounds = Rect (0.0, 0.0, 0.0, 0.0);
+ Value *vh, *vw;
+ if (Shape::MixedHeightWidth (&vh, &vw)) {
+ bounds = Rect (0.0, 0.0, 0.0, 0.0);
+ return;
+ }
int i, count = 0;
Point *points = polyline_get_points (this, &count);
// the first point is a move to, resulting in an empty shape
- if (!points || (count < 2))
+ if (!points || (count < 2)) {
+ bounds = Rect (0.0, 0.0, 0.0, 0.0);
return;
+ }
double thickness = shape_get_stroke_thickness (this);
if (thickness == 0.0)
@@ -1498,6 +1555,14 @@
bounds.y -= points [0].y;
}
+ // if Height and Width are specified (they could be both missing)
+ // then we must clip the path those values, and this also defines
+ // *exactly* our bounds (whether we like them or not is another story)
+ if (vh && vw) {
+ bounds.w = vw->AsDouble ();
+ bounds.h = vh->AsDouble ();
+ }
+
bounds = bounding_rect_for_transformed_rect (&absolute_xform,
IntersectBoundsWithClipPath (bounds, false));
}
@@ -1505,6 +1570,9 @@
void
Polyline::BuildPath ()
{
+ if (Shape::MixedHeightWidth (NULL, NULL))
+ return;
+
int i, count = 0;
Point *points = polyline_get_points (this, &count);
@@ -1631,75 +1699,60 @@
return geometry ? geometry_get_fill_rule (geometry) :
Shape::GetFillRule ();
}
-bool
-Path::NeedsClipping ()
-{
- if (Shape::NeedsClipping ())
- return true;
-
- Value *vh = GetValueNoDefault (FrameworkElement::HeightProperty);
- if (!vh)
- return false;
-
- return (GetValueNoDefault (FrameworkElement::WidthProperty) != NULL);
-}
-
void
Path::ComputeBounds ()
{
- // paths aren't drawn unless both Height and Width are specified (or
missing)
- Value *vh = GetValueNoDefault (FrameworkElement::HeightProperty);
- Value *vw = GetValueNoDefault (FrameworkElement::WidthProperty);
- if ((vh && !vw) || (!vh && vw)) {
- bounds = Rect (0.0, 0.0, 0.0, 0.0);
+ bounds = Rect (0.0, 0.0, 0.0, 0.0);
+
+ Value *vh, *vw;
+ if (Shape::MixedHeightWidth (&vh, &vw))
return;
- }
Geometry* geometry = path_get_data (this);
- if (!geometry) {
- bounds = Rect (0.0, 0.0, 0.0, 0.0);
+ if (!geometry)
return;
- }
- bounds = geometry->ComputeBounds (this);
+ // if Height and Width are specified (they could be both missing)
+ // then we must clip the path those values, and this also defines
+ // *exactly* our bounds (whether we like them or not is another story)
+ if (vh && vw) {
+ bounds.w = vw->AsDouble ();
+ bounds.h = vh->AsDouble ();
+ } else {
+ bounds = geometry->ComputeBounds (this);
- Stretch stretch = shape_get_stretch (this);
- if (stretch != StretchNone) {
- double t = shape_get_stroke_thickness (this) * .5;
- bounds.x = -t;
- bounds.y = -t;
+ Stretch stretch = shape_get_stretch (this);
+ if (stretch != StretchNone) {
+ double t = shape_get_stroke_thickness (this) * 0.5;
- double vscale = vh ? (vh->AsDouble () / bounds.h) : 1.0;
- double hscale = vw ? (vw->AsDouble () / bounds.w) : 1.0;
- double scale;
+ bounds.x = -t;
+ bounds.y = -t;
- switch (stretch) {
- case StretchUniform:
- scale = MIN (vw ? vscale : hscale, vh ? hscale :
vscale);
- bounds.h = (int) ceil(bounds.h * scale);
- bounds.w = (int) ceil(bounds.w * scale);
- break;
- case StretchUniformToFill:
- scale = MAX (vw ? vscale : hscale, vh ? hscale :
vscale);
- bounds.h = (int) ceil(bounds.h * scale);
- bounds.w = (int) ceil(bounds.w * scale);
- break;
- default:
- // bounds are already set correctly
- bounds.h = bounds.h * vscale;
- bounds.w = bounds.w * hscale;
- break;
- }
+ double vscale = vh ? (vh->AsDouble () / bounds.h) : 1.0;
+ double hscale = vw ? (vw->AsDouble () / bounds.w) : 1.0;
+ double scale;
- bounds.w += 2 * t;
- bounds.h += 2 * t;
- }
+ switch (stretch) {
+ case StretchUniform:
+ scale = MIN (vw ? vscale : hscale, vh ? hscale
: vscale);
+ bounds.h = (int) ceil(bounds.h * scale);
+ bounds.w = (int) ceil(bounds.w * scale);
+ break;
+ case StretchUniformToFill:
+ scale = MAX (vw ? vscale : hscale, vh ? hscale
: vscale);
+ bounds.h = (int) ceil(bounds.h * scale);
+ bounds.w = (int) ceil(bounds.w * scale);
+ break;
+ default:
+ // bounds are already set correctly
+ bounds.h = bounds.h * vscale;
+ bounds.w = bounds.w * hscale;
+ break;
+ }
- // if Height and Width are specified (they could be both missing)
- // then we must clip the path those values
- if (vh && vw) {
- bounds.w = MIN (bounds.w, vw->AsDouble ());
- bounds.h = MIN (bounds.h, vh->AsDouble ());
+ bounds.w += 2 * t;
+ bounds.h += 2 * t;
+ }
}
bounds = bounding_rect_for_transformed_rect (&absolute_xform,
Modified: trunk/moon/src/shape.h
===================================================================
--- trunk/moon/src/shape.h 2007-12-13 20:04:14 UTC (rev 91251)
+++ trunk/moon/src/shape.h 2007-12-13 21:14:39 UTC (rev 91252)
@@ -82,7 +82,9 @@
//
virtual void Draw (cairo_t *cr);
virtual void BuildPath () {};
- virtual bool NeedsClipping ();
+ virtual bool ClipOnHeightAndWidth () { return false; }
+ bool NeedsClipping ();
+ bool MixedHeightWidth (Value **width, Value **height);
virtual void OnPropertyChanged (DependencyProperty *prop);
virtual void OnSubPropertyChanged (DependencyProperty *prop,
DependencyObject *obj, DependencyProperty *subprop);
@@ -175,6 +177,7 @@
virtual void BuildPath ();
virtual void ComputeBounds ();
+ virtual bool ClipOnHeightAndWidth () { return true; }
virtual void OnPropertyChanged (DependencyProperty *prop);
@@ -216,6 +219,7 @@
virtual bool CanFill () { return true; }
virtual void GetSizeForBrush (cairo_t *cr, double *width, double
*height);
virtual void ComputeBounds ();
+ virtual bool ClipOnHeightAndWidth () { return true; }
virtual void OnPropertyChanged (DependencyProperty *prop);
virtual void OnCollectionChanged (Collection *col, CollectionChangeType
type, DependencyObject *obj, DependencyProperty *prop);
@@ -247,6 +251,7 @@
virtual bool CanFill () { return true; }
virtual void GetSizeForBrush (cairo_t *cr, double *width, double
*height);
virtual void ComputeBounds ();
+ virtual bool ClipOnHeightAndWidth () { return true; }
virtual FillRule GetFillRule ();
@@ -279,7 +284,7 @@
virtual void GetSizeForBrush (cairo_t *cr, double *width, double
*height);
virtual void ComputeBounds ();
- virtual bool NeedsClipping ();
+ virtual bool ClipOnHeightAndWidth () { return true; }
virtual bool CanFill () { return true; }
virtual FillRule GetFillRule ();
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches