Author: miguel
Date: 2007-06-03 14:01:18 -0400 (Sun, 03 Jun 2007)
New Revision: 78509
Modified:
trunk/moon/src/ChangeLog
trunk/moon/src/demo.cpp
trunk/moon/src/runtime.cpp
trunk/moon/src/runtime.h
Log:
2007-06-03 Miguel de Icaza <[EMAIL PROTECTED]>
* runtime.cpp (Collection, Panel): The beginning of an API to
encapsulate collections that we will expose to the unmanaged
world.
This should be the backend for the base collection class in agclr
for the strongly typed types.
The idea is to have the MS.Internal.Collection<T> be a proxy that
contains an IntPtr pointer to the C++ Collection instance and map
the various add/remove methods to it.
The immediate goal is to be able to do from C#:
Rectangle r = new Rectangle ();
r.Brush = new SolidColorBrush (new Color (1, 0, 0));
Canvas.Children.Add (r);
Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog 2007-06-03 17:49:04 UTC (rev 78508)
+++ trunk/moon/src/ChangeLog 2007-06-03 18:01:18 UTC (rev 78509)
@@ -1,3 +1,22 @@
+2007-06-03 Miguel de Icaza <[EMAIL PROTECTED]>
+
+ * runtime.cpp (Collection, Panel): The beginning of an API to
+ encapsulate collections that we will expose to the unmanaged
+ world.
+
+ This should be the backend for the base collection class in agclr
+ for the strongly typed types.
+
+ The idea is to have the MS.Internal.Collection<T> be a proxy that
+ contains an IntPtr pointer to the C++ Collection instance and map
+ the various add/remove methods to it.
+
+ The immediate goal is to be able to do from C#:
+
+ Rectangle r = new Rectangle ();
+ r.Brush = new SolidColorBrush (new Color (1, 0, 0));
+ Canvas.Children.Add (r);
+
2007-06-02 Miguel de Icaza <[EMAIL PROTECTED]>
Implement support for the render origin.
Modified: trunk/moon/src/demo.cpp
===================================================================
--- trunk/moon/src/demo.cpp 2007-06-03 17:49:04 UTC (rev 78508)
+++ trunk/moon/src/demo.cpp 2007-06-03 18:01:18 UTC (rev 78509)
@@ -58,7 +58,7 @@
panel_child_add (t, r2);
#ifdef VIDEO_DEMO
- v = video_new ("BoxerSmacksdownInhoffe.wmv", 0, 0);
+ v = video_new ("file:///tmp/BoxerSmacksdownInhoffe.wmv", 0, 0);
item_set_transform_origin (v, Point (1, 1));
printf ("Got %d\n", v);
panel_child_add (t, v);
Modified: trunk/moon/src/runtime.cpp
===================================================================
--- trunk/moon/src/runtime.cpp 2007-06-03 17:49:04 UTC (rev 78508)
+++ trunk/moon/src/runtime.cpp 2007-06-03 18:01:18 UTC (rev 78509)
@@ -49,6 +49,23 @@
base->refcount--;
}
+void
+collection_add (Collection *collection, void *data)
+{
+ if (collection->add_fn)
+ collection->add_fn (collection, data);
+ collection->list = g_slist_append (collection->list, data);
+}
+
+void
+collection_remove (Collection *collection, void *data)
+{
+ if (collection->remove_fn)
+ collection->remove_fn (collection, data);
+
+ collection->list = g_slist_remove (collection->list, data);
+}
+
/**
* item_getbounds:
* @item: the item to update the bounds of
@@ -197,13 +214,38 @@
return NULL;
}
+static void
+panel_child_add (Collection *col, void *datum)
+{
+ Panel *panel = (Panel *) col->closure;
+ UIElement *item = (UIElement *) datum;
+
+ item->parent = panel;
+ panel->getbounds ();
+ item_invalidate (panel);
+}
+
+static void
+panel_child_remove (Collection *col, void *datum)
+{
+ Panel *panel = (Panel *) col->closure;
+
+ item_invalidate (panel);
+ panel->getbounds ();
+}
+
+Panel::Panel ()
+{
+ children.Setup (panel_child_add, panel_child_remove, this);
+}
+
void
Panel::render (Surface *s, int x, int y, int width, int height)
{
GSList *il;
double actual [6];
- for (il = children; il != NULL; il = il->next){
+ for (il = children.list; il != NULL; il = il->next){
UIElement *item = (UIElement *) il->data;
item->render (s, x, y, width, height);
@@ -216,7 +258,7 @@
UIElement::update_xform ();
GSList *il;
- for (il = children; il != NULL; il = il->next){
+ for (il = children.list; il != NULL; il = il->next){
UIElement *item = (UIElement *) il->data;
item->update_xform ();
@@ -229,7 +271,7 @@
bool first = TRUE;
GSList *il;
- for (il = children; il != NULL; il = il->next){
+ for (il = children.list; il != NULL; il = il->next){
UIElement *item = (UIElement *) il->data;
item->getbounds ();
@@ -259,12 +301,9 @@
}
void
-panel_child_add (Panel *group, UIElement *item)
+panel_child_add (Panel *panel, UIElement *item)
{
- group->children = g_slist_append (group->children, item);
- item->parent = (UIElement *) group;
-
- item->getbounds ();
+ collection_add (&panel->children, item);
}
void
Modified: trunk/moon/src/runtime.h
===================================================================
--- trunk/moon/src/runtime.h 2007-06-03 17:49:04 UTC (rev 78508)
+++ trunk/moon/src/runtime.h 2007-06-03 18:01:18 UTC (rev 78509)
@@ -36,6 +36,44 @@
};
//
+// Collection: provides a collection that we can monitor for
+// changes. We expose this collection in a few classes to
+// the managed world, and when a change happens we get a
+// chance to reflect the changes
+//
+class Collection;
+
+typedef void (*collection_item_add) (Collection *col, void *datum);
+typedef void (*collection_item_remove) (Collection *col, void *datum);
+
+class Collection {
+ public:
+ collection_item_add add_fn;
+ collection_item_remove remove_fn;
+
+ GSList *list;
+ void *closure;
+
+ Collection () { Setup (NULL, NULL, NULL); }
+
+ Collection (collection_item_add add, collection_item_remove remove,
void *data)
+ {
+ Setup (add, remove, data);
+ }
+
+ void Setup (collection_item_add add, collection_item_remove remove,
void *data)
+ {
+ list = NULL;
+ add_fn = add;
+ remove_fn = remove;
+ closure = data;
+ }
+};
+
+void collection_add (Collection *collection, void *data);
+void collection_remove (Collection *collection, void *data);
+
+//
// This guy provide reference counting
//
#define BASE_FLOATS 0x80000000
@@ -150,27 +188,31 @@
};
Surface *item_get_surface (UIElement *item);
-void item_destroy (UIElement *item);
void item_invalidate (UIElement *item);
void item_update_bounds (UIElement *item);
void item_set_transform (UIElement *item, double *transform);
void item_set_transform_origin (UIElement *item, Point p);
+
//
// Panel Class
//
class Panel : public UIElement {
public:
- GSList *children;
+ Collection children;
- Panel () : children (NULL) {}
-
+ Panel ();
+
virtual void render (Surface *s, int x, int y, int width, int height);
virtual void getbounds ();
virtual void update_xform ();
};
-void panel_child_add (Panel *group, UIElement *item);
+// panel_get_collection, exposed to the managed world so it can manipulate the
collection
+void *panel_get_collection (Panel *panel);
+// For C API usage.
+void panel_child_add (Panel *panel, UIElement *item);
+
//
// Canvas Class, the only purpose is to have the Left/Top properties that
// children can use
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches