Public feed #894115

Miscellany

public text v1 · immutable
Raw Edit
·published 2008-02-06 18:12 UTC
rendered paste body
Index: uielement.h
===================================================================
--- uielement.h	(revision 95027)
+++ uielement.h	(working copy)
@@ -69,7 +69,8 @@
 		SHAPE_EMPTY      = 0x20,	// there's is nothing to draw, the cached path may be NULL
 		SHAPE_NORMAL     = 0x40,	// normal drawing
 		SHAPE_DEGENERATE = 0x80,	// degenerate drawing, use the Stroke brush for filling
-		SHAPE_MASK       = (SHAPE_EMPTY | SHAPE_NORMAL | SHAPE_DEGENERATE)
+		SHAPE_RADII      = 0x100,
+		SHAPE_MASK       = (SHAPE_EMPTY | SHAPE_NORMAL | SHAPE_DEGENERATE | SHAPE_RADII)
 	};
 	
 	int flags;
Index: shape.cpp
===================================================================
--- shape.cpp	(revision 95027)
+++ shape.cpp	(working copy)
@@ -501,6 +501,12 @@
 	}
 }
 
+Rect
+Shape::ComputeLargestRectangle ()
+{
+	return Rect ();
+}
+
 Brush *
 shape_get_fill (Shape *shape)
 {
@@ -765,6 +771,15 @@
 	// note: both moon_rounded_rectangle and moon_ellipse close the path
 }
 
+Rect
+Ellipse::ComputeLargestRectangle ()
+{
+	double t = GetValue (Shape::StrokeThicknessProperty)->AsDouble ();
+	double x = (GetValue (FrameworkElement::WidthProperty)->AsDouble () - t) * cos (M_PI_2);
+	double y = (GetValue (FrameworkElement::HeightProperty)->AsDouble () - t) * sin (M_PI_2);
+	return bounds.GrowBy (-x, -y).RoundIn ();
+}
+
 void
 Ellipse::OnPropertyChanged (DependencyProperty *prop)
 {
@@ -811,8 +826,8 @@
 	if (!SetupLine (cr))
 		return drawn;
 
-	// FIXME: is it worth checking for round-corners ?
-	SetupLineJoinMiter (cr);
+	if (!HasRadii ())
+		SetupLineJoinMiter (cr);
 
 	// Draw if the path wasn't drawn by the Fill call
 	if (!drawn)
@@ -961,6 +976,7 @@
 shape:
 	// rounded-corner rectangle ?
 	if (round) {
+		AddShapeFlags (UIElement::SHAPE_RADII);
 		path = moon_path_renew (path, MOON_PATH_ROUNDED_RECTANGLE_LENGTH);
 		moon_rounded_rectangle (path, x, y, w, h, radius_x, radius_y);
 	} else {
@@ -1006,10 +1022,22 @@
 	return ((*rx != 0.0) && (*ry != 0.0));
 }
 
+Rect
+Rectangle::ComputeLargestRectangle ()
+{
+	double x = GetValue (Shape::StrokeThicknessProperty)->AsDouble ();
+	double y = x;
+	if (HasRadii ()) {
+		x += GetValue (Rectangle::RadiusXProperty)->AsDouble ();
+		y += GetValue (Rectangle::RadiusYProperty)->AsDouble ();
+	}
+	return bounds.GrowBy (-x, -y).RoundIn ();
+}
+
 double
 rectangle_get_radius_x (Rectangle *rectangle)
 {
-	return rectangle->GetValue (Rectangle::RadiusXProperty)->AsDouble();
+	return rectangle->GetValue (Rectangle::RadiusXProperty)->AsDouble ();
 }
 
 void
Index: shape.h
===================================================================
--- shape.h	(revision 95027)
+++ shape.h	(working copy)
@@ -72,6 +72,7 @@
 	virtual void Render (cairo_t *cr, int x, int y, int width, int height);
 	virtual void GetSizeForBrush (cairo_t *cr, double *width, double *height);
 	virtual void ComputeBounds ();
+	virtual Rect ComputeLargestRectangle ();
 	virtual bool InsideObject (cairo_t *cr, double x, double y);
 	virtual Point GetTransformOrigin ();
 	virtual Point GetOriginPoint () {
@@ -107,7 +108,9 @@
 	bool IsEmpty () { return (flags & UIElement::SHAPE_EMPTY); };
 	bool IsNormal () { return (flags & UIElement::SHAPE_NORMAL); };
 	bool IsDegenerate () { return (flags & UIElement::SHAPE_DEGENERATE); };
+	bool HasRadii () { return (flags & UIElement::SHAPE_RADII); };
 	void SetShapeFlags (UIElementFlags sf) { flags &= ~UIElement::SHAPE_MASK; flags |= sf; };
+	void AddShapeFlags (UIElementFlags sf) { flags |= sf; };
 };
 
 Brush	       *shape_get_fill			(Shape *shape);
@@ -145,6 +148,7 @@
 	virtual Type::Kind GetObjectType () { return Type::ELLIPSE; };
 
 	virtual void BuildPath ();
+	virtual Rect ComputeLargestRectangle ();
 	virtual bool CanFill () { return true; }
 
 	virtual void OnPropertyChanged (DependencyProperty *prop);
@@ -167,6 +171,7 @@
 	virtual Type::Kind GetObjectType () { return Type::RECTANGLE; };
 
 	virtual void BuildPath ();
+	virtual Rect ComputeLargestRectangle ();
 
 	virtual void OnPropertyChanged (DependencyProperty *prop);