Author: toshok
Date: 2008-01-17 15:17:40 -0500 (Thu, 17 Jan 2008)
New Revision: 93196

Modified:
   trunk/moon/src/ChangeLog
   trunk/moon/src/rect.h
   trunk/moon/src/stylus.cpp
   trunk/moon/src/stylus.h
Log:
2008-01-17  Chris Toshok  <[EMAIL PROTECTED]>

        * rect.h (Rect::Transform): new method, allows for transforming a
        rectangle by a cairo_matrix_t, used with transforming the stroke
        bounds back to screen space using the InkPresenter's
        absolute_xform.

        * stylus.cpp, stylus.h: deal with collection changed notifications
        on Stroke::StylusPointsProperty and on
        InkPresenter::StrokesProperty, and correctly invalidate a stroke's
        bounds.  The bounds of a stroke needs to be looked at - right now
        it's in the coordinate space of the InkPresenter, and so it needs
        to be transformed back to screen space before invalidating.  Need
        to check if MS uses screen space for a stroke's bounds (seems
        likely they do, but this was easier to code.)



Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog    2008-01-17 20:16:19 UTC (rev 93195)
+++ trunk/moon/src/ChangeLog    2008-01-17 20:17:40 UTC (rev 93196)
@@ -1,3 +1,19 @@
+2008-01-17  Chris Toshok  <[EMAIL PROTECTED]>
+
+       * rect.h (Rect::Transform): new method, allows for transforming a
+       rectangle by a cairo_matrix_t, used with transforming the stroke
+       bounds back to screen space using the InkPresenter's
+       absolute_xform.
+
+       * stylus.cpp, stylus.h: deal with collection changed notifications
+       on Stroke::StylusPointsProperty and on
+       InkPresenter::StrokesProperty, and correctly invalidate a stroke's
+       bounds.  The bounds of a stroke needs to be looked at - right now
+       it's in the coordinate space of the InkPresenter, and so it needs
+       to be transformed back to screen space before invalidating.  Need
+       to check if MS uses screen space for a stroke's bounds (seems
+       likely they do, but this was easier to code.)
+
 2008-01-17  Jeffrey Stedfast  <[EMAIL PROTECTED]>
 
        * list.cpp (Wait): Added.

Modified: trunk/moon/src/rect.h
===================================================================
--- trunk/moon/src/rect.h       2008-01-17 20:16:19 UTC (rev 93195)
+++ trunk/moon/src/rect.h       2008-01-17 20:17:40 UTC (rev 93196)
@@ -111,6 +111,32 @@
                return gdk;
        }
 
+       Rect Transform (cairo_matrix_t *xform)
+       {
+               double p1x, p1y;
+               double p2x, p2y;
+
+               p1x = x;
+               p1y = y;
+
+               p2x = x + w;
+               p2y = y + h;
+
+               cairo_matrix_transform_point (xform, &p1x, &p1y);
+               cairo_matrix_transform_point (xform, &p2y, &p2y);
+
+               double left, right;
+               double top, bottom;
+
+               left = p1x > p2x ? p2x : p1x;
+               right = p1x > p2x ? p1x : p2x;
+
+               top = p1y > p2y ? p2y : p1y;
+               bottom = p1y > p2y ? p1y : p2y;
+
+               return Rect (left, top, right - left, bottom - top);
+       }
+
        bool operator == (const Rect &rect)
        {
                return x == rect.x && y == rect.y && w == rect.w && h == rect.h;

Modified: trunk/moon/src/stylus.cpp
===================================================================
--- trunk/moon/src/stylus.cpp   2008-01-17 20:16:19 UTC (rev 93195)
+++ trunk/moon/src/stylus.cpp   2008-01-17 20:17:40 UTC (rev 93196)
@@ -110,11 +110,10 @@
        if (!stylusPointCollection)
                return 1.0; // documented as such, needs testing
 
-       int count = collection_count (stylusPointCollection);
-       for (int i=0; i < count; i++) {
-               collection_add (this, collection_get_value_at 
(stylusPointCollection, i));
-       }
-       return collection_count (this) - 1;
+       for (Collection::Node *n = (Collection::Node *) 
stylusPointCollection->list->First (); n; n = (Collection::Node *) n->next)
+               Add (n->obj);
+
+       return list->Length () - 1;
 }
 
 
@@ -122,18 +121,21 @@
 {
        this->SetValue (Stroke::StylusPointsProperty, Value::CreateUnref (new 
StylusPointCollection ()));
        this->SetValue (Stroke::DrawingAttributesProperty, Value::CreateUnref 
(new DrawingAttributes ()));
+
+       bounds = Rect (0,0,0,0);
+       old_bounds = Rect (0,0,0,0);
 }
 
 Rect
 Stroke::GetBounds ()
 {
-       DrawingAttributes *da = stroke_get_drawing_attributes (this);
-       StylusPointCollection *spc = stroke_get_stylus_points (this);
+       return bounds;
+}
 
-       if (da)
-               return da->ComputeBounds (spc);
-       else
-               return DrawingAttributes::ComputeBoundsWithoutDrawingAttributes 
(spc);
+Rect
+Stroke::GetOldBounds ()
+{
+       return old_bounds;
 }
 
 bool
@@ -150,6 +152,83 @@
        return false;
 }
 
+void
+Stroke::AddStylusPointToBounds (StylusPoint *stylus_point)
+{
+       DrawingAttributes *da = stroke_get_drawing_attributes (this);
+       double height, width;
+
+       if (da) {
+               height = drawing_attributes_get_height (da) + 4.0;
+               width = drawing_attributes_get_width (da) + 4.0;
+       }
+       else {
+               height = width = 6.0;
+
+       }
+       printf ("stylus point at %g %g\n",
+               stylus_point_get_x (stylus_point),
+               stylus_point_get_y (stylus_point));
+
+       bounds = bounds.Union (Rect (stylus_point_get_x (stylus_point) - width 
/ 2,
+                                    stylus_point_get_y (stylus_point) - height 
/ 2,
+                                    width, height));
+}
+
+void
+Stroke::ComputeBounds ()
+{
+       bounds = Rect (0,0,0,0);
+
+       StylusPointCollection *spc = stroke_get_stylus_points (this);
+       if (!spc)
+               return;
+
+       Collection::Node *cnp;
+       for (cnp = (Collection::Node *) spc->list->First (); cnp != NULL; cnp = 
(Collection::Node *) cnp->next)
+               AddStylusPointToBounds ((StylusPoint*)cnp->obj);
+}
+
+void
+Stroke::OnCollectionChanged (Collection *col, CollectionChangeType type, 
DependencyObject *obj, DependencyProperty *prop)
+{
+       old_bounds = bounds;
+
+       switch (type) {
+       case CollectionChangeTypeItemAdded:
+               AddStylusPointToBounds ((StylusPoint*)obj);
+               break;
+       case CollectionChangeTypeItemRemoved:
+       case CollectionChangeTypeItemChanged:
+       case CollectionChangeTypeChanged:
+               ComputeBounds ();
+               break;
+       }
+
+       NotifyAttachersOfPropertyChange (Stroke::StylusPointsProperty);
+}
+
+void
+Stroke::OnPropertyChanged (DependencyProperty *prop)
+{
+       if (prop->type != Type::STROKE) {
+               DependencyObject::OnPropertyChanged (prop);
+               return;
+       }
+
+       if (prop == Stroke::StylusPointsProperty) {
+               Collection *newcol = GetValue (prop)->AsCollection();
+               
+               if (newcol) {
+                       if (newcol->closure)
+                               printf ("Warning we attached a property that 
was already attached\n");
+                       newcol->closure = this;
+               }
+       }
+
+       NotifyAttachersOfPropertyChange (prop);
+}
+
 Stroke*
 stroke_new ()
 {
@@ -371,20 +450,6 @@
        drawing_attributes_quick_render (cr, 2.0, NULL, collection);
 }
 
-Rect
-DrawingAttributes::ComputeBounds (StylusPointCollection *stylusPointCollection)
-{
-       // XXX
-       return Rect (0,0,0,0);
-}
-
-Rect
-DrawingAttributes::ComputeBoundsWithoutDrawingAttributes 
(StylusPointCollection *stylusPointCollection)
-{
-       // XXX
-       return Rect (0,0,0,0);
-}
-
 InkPresenter::InkPresenter ()
 {
        this->SetValue (InkPresenter::StrokesProperty, Value::CreateUnref (new 
StrokeCollection ()));
@@ -427,15 +492,47 @@
        }
 }
 
-bool
-InkPresenter::OnChildPropertyChanged (DependencyProperty *prop, 
DependencyObject *child)
+void
+InkPresenter::OnPropertyChanged (DependencyProperty *prop)
 {
-       if (prop == StrokesProperty)
-               return true;
+       if (prop->type != Type::INKPRESENTER) {
+               Canvas::OnPropertyChanged (prop);
+               return;
+       }
 
-       return Canvas::OnChildPropertyChanged (prop, child);
+       if (prop == InkPresenter::StrokesProperty) {
+               Collection *newcol = GetValue (prop)->AsCollection();
+               
+               if (newcol) {
+                       if (newcol->closure)
+                               printf ("Warning we attached a property that 
was already attached\n");
+                       newcol->closure = this;
+               }
+       }
+
+       NotifyAttachersOfPropertyChange (prop);
 }
 
+void
+InkPresenter::OnCollectionChanged (Collection *col, CollectionChangeType type, 
DependencyObject *obj, DependencyProperty *prop)
+{
+       switch (type) {
+       case CollectionChangeTypeItemAdded:
+       case CollectionChangeTypeItemRemoved:
+       case CollectionChangeTypeItemChanged: {
+               Rect ink_bounds = GetBounds();
+               Stroke *stroke = (Stroke*)obj;
+               Invalidate (stroke->GetBounds().Transform (&absolute_xform));
+               if (type == CollectionChangeTypeItemChanged)
+                       Invalidate (stroke->GetOldBounds().Transform 
(&absolute_xform));
+               break;
+       }
+       case CollectionChangeTypeChanged:
+               Invalidate ();
+               break;
+       }
+}
+
 InkPresenter*
 ink_presenter_new ()
 {

Modified: trunk/moon/src/stylus.h
===================================================================
--- trunk/moon/src/stylus.h     2008-01-17 20:16:19 UTC (rev 93195)
+++ trunk/moon/src/stylus.h     2008-01-17 20:17:40 UTC (rev 93196)
@@ -84,9 +84,6 @@
        void Render (cairo_t *cr, StylusPointCollection* collection);
        static void RenderWithoutDrawingAttributes (cairo_t *cr, 
StylusPointCollection* collection);
 
-       Rect ComputeBounds (StylusPointCollection *collection);
-       static Rect ComputeBoundsWithoutDrawingAttributes 
(StylusPointCollection* collection);
-
        static DependencyProperty* ColorProperty;
        static DependencyProperty* OutlineColorProperty;
        static DependencyProperty* HeightProperty;
@@ -111,10 +108,21 @@
        virtual Type::Kind GetObjectType () { return Type::STROKE; };
 
        Rect GetBounds ();
+       Rect GetOldBounds ();
        bool HitTest (StylusPointCollection *stylusPoints);
 
+       virtual void OnPropertyChanged (DependencyProperty *prop);
+       virtual void OnCollectionChanged (Collection *col, CollectionChangeType 
type, DependencyObject *obj, DependencyProperty *prop);
+
        static DependencyProperty* DrawingAttributesProperty;
        static DependencyProperty* StylusPointsProperty;
+
+ private:
+       Rect bounds;
+       Rect old_bounds;
+
+       void AddStylusPointToBounds (StylusPoint *stylus_point);
+       void ComputeBounds ();
 };
 
 Stroke*                stroke_new ();
@@ -148,7 +156,8 @@
        virtual Type::Kind GetObjectType () { return Type::INKPRESENTER; };
 
        virtual void RenderChildren (cairo_t *cr, Region *region);
-       virtual bool OnChildPropertyChanged (DependencyProperty *prop, 
DependencyObject *child);
+       virtual void OnPropertyChanged (DependencyProperty *prop);
+       virtual void OnCollectionChanged (Collection *col, CollectionChangeType 
type, DependencyObject *obj, DependencyProperty *prop);
 
        static DependencyProperty* StrokesProperty;
 };

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to