Author: miguel
Date: 2007-06-06 21:25:39 -0400 (Wed, 06 Jun 2007)
New Revision: 78806

Modified:
   trunk/moon/src/ChangeLog
   trunk/moon/src/demo.cpp
   trunk/moon/src/runtime.cpp
   trunk/moon/src/runtime.h
Log:
2007-06-06  Miguel de Icaza  <[EMAIL PROTECTED]>

        * runtime.h, runtime.cpp: Surface is no longer derived from
        Canvas, it now instead hosts a canvas, should avoid having two
        nested canvases for loading XAML files.

        demo.cpp: update.



Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog    2007-06-07 01:09:04 UTC (rev 78805)
+++ trunk/moon/src/ChangeLog    2007-06-07 01:25:39 UTC (rev 78806)
@@ -1,5 +1,11 @@
 2007-06-06  Miguel de Icaza  <[EMAIL PROTECTED]>
 
+       * runtime.h, runtime.cpp: Surface is no longer derived from
+       Canvas, it now instead hosts a canvas, should avoid having two
+       nested canvases for loading XAML files.
+
+       demo.cpp: update.
+
        Correct computation of the bounding box for shapes and videos.
 
        * shape.cpp: Do not pop the cairo state after draw and then call

Modified: trunk/moon/src/demo.cpp
===================================================================
--- trunk/moon/src/demo.cpp     2007-06-07 01:09:04 UTC (rev 78805)
+++ trunk/moon/src/demo.cpp     2007-06-07 01:25:39 UTC (rev 78806)
@@ -75,9 +75,12 @@
                        printf ("Was not able to load the file\n");
                }
 
-               panel_child_add (t, e);
+               surface_attach (t, e);
                
        } else {
+               Canvas *canvas = new Canvas ();
+               surface_attach (t, canvas);
+
                // Create our objects
                r_trans = new RotateTransform ();
                v_trans = new RotateTransform ();
@@ -111,10 +114,10 @@
                r2->SetValue (Canvas::TopProperty, Value (50.0));
                item_set_render_transform (r2, r_trans);
                shape_set_stroke (r2, scb);
-               panel_child_add (t, r2);
+               panel_child_add (canvas, r2);
                
 #ifdef XAML_DEMO
-               panel_child_add (t, xaml_create_from_str ("<Line Stroke='Blue' 
X1='10' Y1='10' X2='10' Y2='300' />"));
+               panel_child_add (canvas, xaml_create_from_str ("<Line 
Stroke='Blue' X1='10' Y1='10' X2='10' Y2='300' />"));
 #endif
                
 #ifdef VIDEO_DEMO
@@ -122,10 +125,10 @@
                item_set_render_transform (v, v_trans);
                item_set_transform_origin (v, Point (1, 1));
                printf ("Got %d\n", v);
-               panel_child_add (t, v);
+               panel_child_add (canvas, v);
 #endif
                
-               panel_child_add (t, r);
+               panel_child_add (canvas, r);
                
 #ifdef VIDEO_DEMO
                //UIElement *v2 = video_new 
("file:///tmp/Countdown-Colbert-BestNailings.wmv", 100, 100);
@@ -134,7 +137,7 @@
                v2->SetValue (Canvas::LeftProperty, Value (100.0));
                v2->SetValue (Canvas::TopProperty, Value (100.0));
                item_set_render_transform (v2, s_trans);
-               panel_child_add (t, v2);
+               panel_child_add (canvas, v2);
 #endif
                gtk_timeout_add (60, animate, NULL);
        }               

Modified: trunk/moon/src/runtime.cpp
===================================================================
--- trunk/moon/src/runtime.cpp  2007-06-07 01:09:04 UTC (rev 78805)
+++ trunk/moon/src/runtime.cpp  2007-06-07 01:25:39 UTC (rev 78806)
@@ -229,8 +229,11 @@
 Surface *
 item_get_surface (UIElement *item)
 {
-       if (item->flags & Video::IS_SURFACE)
-               return (Surface *) item;
+       if (item->flags & Video::IS_CANVAS){
+               Canvas *canvas = (Canvas *) item;
+               if (canvas->surface)
+                       return canvas->surface;
+       }
 
        if (item->parent != NULL)
                return item_get_surface (item->parent);
@@ -270,6 +273,11 @@
        children.Setup (panel_child_add, panel_child_remove, this);
 }
 
+Canvas::Canvas ()
+{
+       flags |= IS_CANVAS;
+}
+
 void
 Canvas::get_xform_for (UIElement *item, cairo_matrix_t *result)
 {
@@ -494,9 +502,10 @@
 
        gtk_widget_set_usize (s->drawing_area, width, height);
        s->buffer = NULL;
-       s->flags |= UIElement::IS_SURFACE;
        s->width = width;
        s->height = height;
+       s->toplevel = NULL;
+
        surface_realloc (s);
 
        gtk_signal_connect (GTK_OBJECT (s->drawing_area), "expose_event",
@@ -512,10 +521,26 @@
 }
 
 void
+surface_attach (Surface *surface, UIElement *toplevel)
+{
+       if (!(toplevel->flags & UIElement::IS_CANVAS)){
+               printf ("Unsupported toplevel\n");
+               return;
+       }
+       if (surface->toplevel)
+               base_unref (surface->toplevel);
+
+       Canvas *canvas = (Canvas *) toplevel;
+       base_ref (canvas);
+       canvas->surface = surface;
+       surface->toplevel = canvas;
+}
+
+void
 surface_repaint (Surface *s, int x, int y, int width, int height)
 {
        surface_clear (s, x, y, width, height);
-       s->render (s, x, y, width, height);
+       s->toplevel->render (s, x, y, width, height);
 }
 
 void *

Modified: trunk/moon/src/runtime.h
===================================================================
--- trunk/moon/src/runtime.h    2007-06-07 01:09:04 UTC (rev 78805)
+++ trunk/moon/src/runtime.h    2007-06-07 01:25:39 UTC (rev 78806)
@@ -522,7 +522,7 @@
        UIElement *parent;
 
        enum UIElementFlags {
-               IS_SURFACE = 1
+               IS_CANVAS = 1
        };
        
        int flags;
@@ -614,6 +614,9 @@
 //
 class Canvas : public Panel {
  public:
+       Canvas ();
+       Surface *surface;
+       
        virtual Point getxformorigin () { return Point (0, 0); }
 
        virtual void render (Surface *s, int x, int y, int width, int height);
@@ -627,7 +630,7 @@
        static DependencyProperty* LeftProperty;
 };
 
-Canvas * canvas_new ();
+Canvas *canvas_new ();
 
 
 //
@@ -668,7 +671,7 @@
 // We probably should make the Surface not derive from Canvas, but for now
 // it will do.
 //
-class Surface : public Canvas {
+class Surface {
  public:
        Surface () : width (0), height (0), buffer (0), 
                cairo_buffer_surface (NULL), cairo_buffer(NULL),
@@ -697,14 +700,13 @@
 
        // The widget where we draw.
        GtkWidget *drawing_area;
-                                       
-       //
-       // Consumer-defined data, we use it to pass the handle to invalidate
-       //
-//     void *data;
+
+       // This currently can only be a canvas.
+       UIElement *toplevel;
 };
 
 Surface *surface_new       (int width, int height);
+void     surface_attach    (Surface *s, UIElement *element);
 void     surface_init      (Surface *s, int width, int height);
 void     surface_clear     (Surface *s, int x, int y, int width, int height);
 void     surface_clear_all (Surface *s);

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

Reply via email to