Author: toshok
Date: 2007-06-25 15:53:14 -0400 (Mon, 25 Jun 2007)
New Revision: 80725
Modified:
trunk/moon/src/ChangeLog
trunk/moon/src/collection.cpp
trunk/moon/src/collection.h
trunk/moon/src/runtime.cpp
trunk/moon/src/runtime.h
Log:
2007-06-25 Chris Toshok <[EMAIL PROTECTED]>
* runtime.h: add decl for Panel::OnSubPropertyChanged.
* runtime.cpp (UIElement::OnPropertyChanged): handle changes to
zIndex by invalidating the item's rectangle.
(UIElement::OnSubPropertyChanged): add braces around all the if
blocks for consistency.
(Panel::OnSubPropertyChanged): if a child changes its z index we
need to resort our visual collection.
(Canvas::render): loop over the z sorted list of children instead
of the default collection list.
(item_init): just to be anal, cast the Zindex default value to
gint32.
x2007-06-25 Chris Toshok <[EMAIL PROTECTED]>
* collection.cpp: keep a z-sorted list in VisualCollection,
adding/removing elements from it when needed, and clearing it when
the collection is cleared.
* collection.h: add a virtual clear method so VisualCollection can
override it. Also, add a z_sorted_list member to
VisualCollection, so we can deal with the ZIndices of children.
Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog 2007-06-25 19:47:10 UTC (rev 80724)
+++ trunk/moon/src/ChangeLog 2007-06-25 19:53:14 UTC (rev 80725)
@@ -1,3 +1,28 @@
+2007-06-25 Chris Toshok <[EMAIL PROTECTED]>
+
+ * runtime.h: add decl for Panel::OnSubPropertyChanged.
+
+ * runtime.cpp (UIElement::OnPropertyChanged): handle changes to
+ zIndex by invalidating the item's rectangle.
+ (UIElement::OnSubPropertyChanged): add braces around all the if
+ blocks for consistency.
+ (Panel::OnSubPropertyChanged): if a child changes its z index we
+ need to resort our visual collection.
+ (Canvas::render): loop over the z sorted list of children instead
+ of the default collection list.
+ (item_init): just to be anal, cast the Zindex default value to
+ gint32.
+
+x2007-06-25 Chris Toshok <[EMAIL PROTECTED]>
+
+ * collection.cpp: keep a z-sorted list in VisualCollection,
+ adding/removing elements from it when needed, and clearing it when
+ the collection is cleared.
+
+ * collection.h: add a virtual clear method so VisualCollection can
+ override it. Also, add a z_sorted_list member to
+ VisualCollection, so we can deal with the ZIndices of children.
+
2007-06-24 Alan McGovern <[EMAIL PROTECTED]>
* runtime.(cpp|h): Implemented UIElement.ZIndexPropery
Modified: trunk/moon/src/collection.cpp
===================================================================
--- trunk/moon/src/collection.cpp 2007-06-25 19:47:10 UTC (rev 80724)
+++ trunk/moon/src/collection.cpp 2007-06-25 19:53:14 UTC (rev 80725)
@@ -167,8 +167,61 @@
}
+VisualCollection::VisualCollection ()
+{
+ z_sorted_list = new List ();
+}
+VisualCollection::~VisualCollection ()
+{
+ z_sorted_list->Clear (true);
+ delete z_sorted_list;
+}
+
+class UIElementNode : public List::Node {
+public:
+ UIElement *item;
+
+ UIElementNode (UIElement *v) : item (v) { }
+};
+
+static bool
+UIElementNodeFinder (List::Node *uin, void *data)
+{
+ return ((UIElementNode *) uin)->item == (UIElement *) data;
+}
+
+static int
+UIElementNodeComparer (List::Node *ui1, List::Node *ui2)
+{
+ int z1 =
((UIElementNode*)ui1)->item->GetValue(UIElement::ZIndexProperty)->AsInt32();
+ int z2 =
((UIElementNode*)ui2)->item->GetValue(UIElement::ZIndexProperty)->AsInt32();
+ int zdiff = z1 - z2;
+
+ if (zdiff == 0)
+ return 0;
+ else if (zdiff < 0)
+ return -1;
+ else
+ return 1;
+}
+
void
+VisualCollection::ResortByZIndex ()
+{
+ printf ("ResortByZIndex\n");
+ z_sorted_list->Clear (true);
+
+ UIElementNode* n = (UIElementNode *) list->First ();
+ while (n != NULL) {
+ z_sorted_list->InsertSorted (new UIElementNode ((UIElement *)
n->item), UIElementNodeComparer, true);
+
+ n = (UIElementNode *) n->Next ();
+ }
+}
+
+
+void
VisualCollection::VisualUpdate (DependencyObject *data)
{
Panel *panel = (Panel *) closure;
@@ -187,11 +240,13 @@
UIElement *item = (UIElement *) data;
Collection::Add (item);
+ z_sorted_list->InsertSorted (new UIElementNode (item),
UIElementNodeComparer, true);
if (((UIElement*)closure)->flags & UIElement::IS_LOADED) {
/* emit loaded events on the new item if the tree
we're adding it to has already been "loaded" */
item->OnLoaded ();
}
+
VisualUpdate (data);
}
@@ -201,6 +256,7 @@
UIElement *item = (UIElement *) data;
Collection::Insert (index, item);
+ z_sorted_list->InsertSorted (new UIElementNode (item),
UIElementNodeComparer, true);
if (((UIElement*)closure)->flags & UIElement::IS_LOADED) {
/* emit loaded events on the new item if the tree
@@ -219,10 +275,19 @@
item_invalidate (item);
Collection::Remove (item);
+ z_sorted_list->Remove (UIElementNodeFinder, item);
item_update_bounds (panel);
}
void
+VisualCollection::Clear ()
+{
+ z_sorted_list->Clear (true);
+ Collection::Clear ();
+}
+
+
+void
TriggerCollection::Add (DependencyObject *data)
{
FrameworkElement *fwe = (FrameworkElement *) closure;
Modified: trunk/moon/src/collection.h
===================================================================
--- trunk/moon/src/collection.h 2007-06-25 19:47:10 UTC (rev 80724)
+++ trunk/moon/src/collection.h 2007-06-25 19:53:14 UTC (rev 80725)
@@ -62,14 +62,19 @@
class VisualCollection : public Collection {
public:
- VisualCollection () {}
+ VisualCollection ();
+ virtual ~VisualCollection ();
virtual Type::Kind GetObjectType () { return Type::VISUAL_COLLECTION; }
virtual Type::Kind GetElementType () { return Type::VISUAL; }
virtual void Add (DependencyObject *data);
virtual void Remove (DependencyObject *data);
virtual void Insert (int index, DependencyObject *data);
+ virtual void Clear ();
+ void ResortByZIndex ();
+ List *z_sorted_list;
+
private:
void VisualUpdate (DependencyObject *data);
};
Modified: trunk/moon/src/runtime.cpp
===================================================================
--- trunk/moon/src/runtime.cpp 2007-06-25 19:47:10 UTC (rev 80724)
+++ trunk/moon/src/runtime.cpp 2007-06-25 19:53:14 UTC (rev 80725)
@@ -216,7 +216,8 @@
void
UIElement::OnPropertyChanged (DependencyProperty *prop)
{
- if (prop == UIElement::OpacityProperty) {
+ if (prop == UIElement::OpacityProperty ||
+ prop == UIElement::ZIndexProperty) {
item_invalidate (this);
} else if (prop == UIElement::VisibilityProperty) {
// XXX we need a FullInvalidate if this is changing
@@ -311,16 +312,16 @@
UIElement::OnSubPropertyChanged (DependencyProperty *prop, DependencyProperty
*subprop)
{
if (prop == UIElement::RenderTransformProperty ||
- prop == UIElement::RenderTransformOriginProperty)
+ prop == UIElement::RenderTransformOriginProperty) {
FullInvalidate (true);
- else if (prop == UIElement::ClipProperty ||
- prop == UIElement::OpacityMaskProperty) {
+ } else if (prop == UIElement::ClipProperty ||
+ prop == UIElement::OpacityMaskProperty) {
// Maybe this could also be just item_invalidate?
FullInvalidate (false);
- } else if (prop == UIElement::OpacityProperty) {
+ } else if (prop == UIElement::OpacityProperty) {
item_invalidate (this);
- } else if (prop == UIElement::VisibilityProperty){
+ } else if (prop == UIElement::VisibilityProperty) {
// XXX we need a FullInvalidate if this is changing
// from or to Collapsed, but as there's no way to tell that...
FullInvalidate (true);
@@ -654,6 +655,19 @@
}
void
+Panel::OnSubPropertyChanged (DependencyProperty *prop, DependencyProperty
*subprop)
+{
+ // if a child changes its ZIndex property we need to resort our Children
+ if (prop == UIElement::ZIndexProperty) {
+ GetChildren()->ResortByZIndex ();
+ return;
+ }
+
+ FrameworkElement::OnSubPropertyChanged (prop, subprop);
+}
+
+
+void
Panel::OnLoaded ()
{
VisualCollection *children = GetChildren ();
@@ -1181,7 +1195,7 @@
// path for the children
//
cairo_identity_matrix (s->cairo);
- cn = (Collection::Node *) children->list->First ();
+ cn = (Collection::Node *) children->z_sorted_list->First ();
for ( ; cn != NULL; cn = (Collection::Node *) cn->Next ()) {
UIElement *item = (UIElement *) cn->obj;
@@ -2381,7 +2395,7 @@
UIElement::IsHitTestVisibleProperty = DependencyObject::Register
(Type::UIELEMENT, "IsHitTestVisible", Type::BOOL);
UIElement::VisibilityProperty = DependencyObject::Register
(Type::UIELEMENT, "Visibility", new Value ((gint32)VisibilityVisible));
UIElement::ResourcesProperty = DependencyObject::Register
(Type::UIELEMENT, "Resources", Type::RESOURCE_COLLECTION);
- UIElement::ZIndexProperty = DependencyObject::Register
(Type::UIELEMENT, "ZIndex", new Value(0));
+ UIElement::ZIndexProperty = DependencyObject::Register
(Type::UIELEMENT, "ZIndex", new Value ((gint32)0));;
}
//
Modified: trunk/moon/src/runtime.h
===================================================================
--- trunk/moon/src/runtime.h 2007-06-25 19:47:10 UTC (rev 80724)
+++ trunk/moon/src/runtime.h 2007-06-25 19:53:14 UTC (rev 80725)
@@ -643,6 +643,7 @@
static DependencyProperty* BackgroundProperty;
virtual void OnPropertyChanged (DependencyProperty *prop);
+ virtual void OnSubPropertyChanged (DependencyProperty *prop,
DependencyProperty *subprop);
virtual void OnLoaded ();
};
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches