Author: toshok
Date: 2007-06-14 12:20:20 -0400 (Thu, 14 Jun 2007)
New Revision: 79563

Modified:
   trunk/moon/src/ChangeLog
   trunk/moon/src/demo.cpp
   trunk/moon/src/media.cpp
   trunk/moon/src/media.h
   trunk/moon/src/runtime.cpp
   trunk/moon/src/runtime.h
   trunk/moon/src/type.cpp
   trunk/moon/src/value.cpp
   trunk/moon/src/value.h
Log:
2007-06-14  Chris Toshok  <[EMAIL PROTECTED]>

        * demo.cpp: make one of the videos an image instead.

        * type.cpp, value.h, type.h: resync these.

        * media.h, media.cpp: add naive Image class.

        * runtime.h, runtime.cpp: add some Downloader methods, and
        subclass Downloader with a *very* hackish UnmanagedDownloader
        class that just loads from files.  Also add a "write_func"
        callback that the downloader can call when it has new data to hand
        off.

2007-06-14  Chris Toshok  <[EMAIL PROTECTED]>



Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog    2007-06-14 16:18:24 UTC (rev 79562)
+++ trunk/moon/src/ChangeLog    2007-06-14 16:20:20 UTC (rev 79563)
@@ -1,3 +1,7 @@
+2007-06-14  Chris Toshok  <[EMAIL PROTECTED]>
+
+       * demo.cpp: make one of the videos an image instead.
+
 2007-06-14  Jeffrey Stedfast  <[EMAIL PROTECTED]>
 
        * xaml.cpp: Fixed the font_widths and font_stretches maps to
@@ -18,6 +22,18 @@
 
 2007-06-14  Chris Toshok  <[EMAIL PROTECTED]>
 
+       * type.cpp, value.h, type.h: resync these.
+
+       * media.h, media.cpp: add naive Image class.
+
+       * runtime.h, runtime.cpp: add some Downloader methods, and
+       subclass Downloader with a *very* hackish UnmanagedDownloader
+       class that just loads from files.  Also add a "write_func"
+       callback that the downloader can call when it has new data to hand
+       off.
+
+2007-06-14  Chris Toshok  <[EMAIL PROTECTED]>
+
        * animation.cpp: import an arc length calculator I found on the
        net (at http://steve.hollasch.net/cgindex/curves/cbezarclen.html)
        and use that for KeySpline::GetSplineProgress.  The results don't

Modified: trunk/moon/src/demo.cpp
===================================================================
--- trunk/moon/src/demo.cpp     2007-06-14 16:18:24 UTC (rev 79562)
+++ trunk/moon/src/demo.cpp     2007-06-14 16:20:20 UTC (rev 79563)
@@ -11,6 +11,7 @@
 #include "transform.h"
 #include "animation.h"
 #include "shape.h"
+#include "media.h"
 
 static UIElement *v;
 static Rectangle *r;
@@ -210,15 +211,13 @@
                
                panel_child_add (canvas, r);
                
-#ifdef VIDEO_DEMO
-               UIElement *v2 = (UIElement *) video_new 
("file:///tmp/Countdown-Colbert-BestNailings.wmv");
-               //UIElement *v2 = video_new ("file:///tmp/red.wmv", 100, 100);
-               //UIElement *v2 = (UIElement *) video_new 
("file:///tmp/BoxerSmacksdownInhoffe.wmv");
-               v2->SetValue (Canvas::LeftProperty, Value (100.0));
-               v2->SetValue (Canvas::TopProperty, Value (100.0));
-               item_set_render_transform (v2, s_trans);
-               panel_child_add (canvas, v2);
-#endif
+               UnmanagedDownloader *dl = new UnmanagedDownloader ();
+               Image *i = image_new ();
+               i->SetSource (dl, "/tmp/mono.png");
+               i->SetValue (Canvas::LeftProperty, Value (100.0));
+               i->SetValue (Canvas::TopProperty, Value (100.0));
+               item_set_render_transform (i, s_trans);
+               panel_child_add (canvas, i);
 
 
                sb = new Storyboard ();

Modified: trunk/moon/src/media.cpp
===================================================================
--- trunk/moon/src/media.cpp    2007-06-14 16:18:24 UTC (rev 79562)
+++ trunk/moon/src/media.cpp    2007-06-14 16:20:20 UTC (rev 79563)
@@ -14,6 +14,11 @@
 
 #include <gtk/gtk.h>
 
+#define Visual _XVisual
+#include <gdk/gdkx.h>
+#include <cairo-xlib.h>
+#undef Visual
+
 #include "media.h"
 
 // MediaBase
@@ -245,6 +250,134 @@
 }
 
 //
+// Image
+//
+DependencyProperty* Image::DownloadProgressProperty;
+
+Image::Image ()
+  : pixbuf_width (0),
+    pixbuf_height (0),
+    loader (NULL),
+    xlib_surface (NULL)
+{
+}
+
+void
+Image::SetSource (DependencyObject *downloader, char* PartName)
+{
+       loader = gdk_pixbuf_loader_new ();
+
+       g_signal_connect (loader, "size_prepared", 
G_CALLBACK(loader_size_prepared), this);
+
+       this->downloader = downloader;
+       ((Downloader*)downloader)->SetWriteFunc (pixbuf_write, this);
+       ((Downloader*)downloader)->Open ("GET", PartName, true);
+}
+
+void
+Image::pixbuf_write (guchar *buf, gsize count, gpointer data)
+{
+       ((Image*)data)->PixbufWrite (buf, count);
+}
+
+void
+Image::PixbufWrite (guchar *buf, gsize count)
+{
+       gdk_pixbuf_loader_write (loader, buf, count, NULL);
+}
+
+void
+Image::loader_size_prepared (GdkPixbufLoader *loader, int width, int height, 
gpointer data)
+{
+       ((Image*)data)->LoaderSizePrepared (width, height);
+}
+
+void
+Image::LoaderSizePrepared (int width, int height)
+{
+       printf ("image has size %dx%d\n", width, height);
+       pixbuf_width = width;
+       pixbuf_height = height;
+
+       item_update_bounds (this);
+}
+
+void
+Image::render (Surface *s, int x, int y, int width, int height)
+{
+       cairo_save (s->cairo);
+
+       GdkPixbuf *pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
+       if (pixbuf) {
+               if (!xlib_surface) {
+                       pixmap = gdk_pixmap_new (GDK_DRAWABLE 
(s->drawing_area->window),
+                                                gdk_pixbuf_get_width (pixbuf),
+                                                gdk_pixbuf_get_height (pixbuf),
+                                                gdk_drawable_get_depth 
(GDK_DRAWABLE (s->drawing_area->window)));
+                       GdkGC *gc = gdk_gc_new (GDK_DRAWABLE (pixmap));
+                       gdk_draw_pixbuf (GDK_DRAWABLE (pixmap),
+                                        gc,
+                                        pixbuf,
+                                        0, 0,
+                                        0, 0,
+                                        gdk_pixbuf_get_width (pixbuf),
+                                        gdk_pixbuf_get_height (pixbuf),
+                                        GDK_RGB_DITHER_NONE,
+                                        0,0);
+                       g_object_unref (G_OBJECT (gc));
+                       
+
+                       xlib_surface = cairo_xlib_surface_create 
(GDK_PIXMAP_XDISPLAY (pixmap),
+                                                                 
GDK_PIXMAP_XID (pixmap),
+                                                                 
GDK_VISUAL_XVISUAL (gdk_drawable_get_visual (GDK_DRAWABLE (pixmap))),
+                                                                 
gdk_pixbuf_get_width (pixbuf),
+                                                                 
gdk_pixbuf_get_height (pixbuf));
+               }
+
+               cairo_set_matrix (s->cairo, &absolute_xform);
+       
+               cairo_set_source_surface (s->cairo, xlib_surface, 0, 0);
+
+               cairo_rectangle (s->cairo, 0, 0, this->pixbuf_width, 
this->pixbuf_height);
+
+               cairo_fill (s->cairo);
+       }
+       cairo_restore (s->cairo);
+}
+
+void
+Image::getbounds ()
+{
+       x1 = y1 = 0;
+       x2 = pixbuf_width;
+       y2 = pixbuf_height;
+}
+
+Image*
+image_new ()
+{
+       return new Image ();
+}
+
+void
+image_set_download_progress (Image *img, double progress)
+{
+       img->SetValue (Image::DownloadProgressProperty, Value(progress));
+}
+
+double
+image_get_download_progress (Image *img)
+{
+       return img->GetValue (Image::DownloadProgressProperty)->AsDouble();
+}
+
+void
+image_set_source (Image *img, DependencyObject *Downloader, char *PartName)
+{
+       img->SetSource (Downloader, PartName);
+}
+
+//
 // MediaAttribute
 //
 
@@ -261,4 +394,8 @@
 {
        /* MediaAttribute */
        MediaAttribute::ValueProperty = DependencyObject::Register 
(Value::MEDIAATTRIBUTE, "Value", new Value (""));
+
+       /* Image */
+       Image::DownloadProgressProperty = DependencyObject::Register 
(Value::IMAGE, "DownloadProgress", new Value(0.0));
+
 }

Modified: trunk/moon/src/media.h
===================================================================
--- trunk/moon/src/media.h      2007-06-14 16:18:24 UTC (rev 79562)
+++ trunk/moon/src/media.h      2007-06-14 16:20:20 UTC (rev 79563)
@@ -35,7 +35,37 @@
 void    media_base_set_stretch (MediaBase *media, Stretch value);
 
 
+class Image : public MediaBase {
+ public:
+       Image ();
+       virtual Value::Kind GetObjectType () { return Value::IMAGE; };
 
+       virtual void render (Surface *surface, int x, int y, int width, int 
height);
+       virtual void getbounds ();
+
+       void SetSource (DependencyObject *Downloader, char* PartName);
+
+       static DependencyProperty *DownloadProgressProperty;
+ private:
+       void PixbufWrite (guchar *bug, gsize count);
+       void LoaderSizePrepared (int width, int height);
+       static void pixbuf_write (guchar *buf, gsize count, gpointer data);
+       static void loader_size_prepared (GdkPixbufLoader *loader, int width, 
int height, gpointer data);
+       GdkPixbufLoader *loader;
+       DependencyObject *downloader;
+       cairo_surface_t *xlib_surface;
+       GdkPixmap *pixmap;
+       int pixbuf_width;
+       int pixbuf_height;
+};
+
+Image* image_new ();
+void   image_set_download_progress (Image *img, double progress);
+double image_get_download_progress (Image *img);
+void   image_set_source (DependencyObject *Downloader, char *PartName);
+
+
+
 class MediaElement : public MediaBase {
 public:
        static DependencyProperty *AutoPlayProperty;

Modified: trunk/moon/src/runtime.cpp
===================================================================
--- trunk/moon/src/runtime.cpp  2007-06-14 16:18:24 UTC (rev 79562)
+++ trunk/moon/src/runtime.cpp  2007-06-14 16:20:20 UTC (rev 79563)
@@ -15,6 +15,8 @@
 #include <malloc.h>
 #include <glib.h>
 #include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
 #define Visual _XVisual
 #include <gdk/gdkx.h>
 #if AGG
@@ -2029,6 +2031,106 @@
 }
 
 //
+// Downloader
+//
+
+void
+Downloader::Abort ()
+{
+}
+
+char*
+Downloader::GetResponseText (char* PartName)
+{
+       return NULL;
+}
+
+void
+Downloader::Open (char *verb, char *URI, bool Async)
+{
+}
+
+void
+Downloader::Send ()
+{
+}
+
+void
+Downloader::SetWriteFunc (downloader_write_func write,
+                         gpointer data)
+{
+       this->write = write;
+       this->write_data = data;
+}
+
+//
+// UnmanagedDownloader hack
+//
+
+
+UnmanagedDownloader::UnmanagedDownloader ()
+  : fd (-1),
+    async_idle (-1)
+{
+}
+
+UnmanagedDownloader::~UnmanagedDownloader ()
+{
+       Close ();
+}
+
+gboolean
+UnmanagedDownloader::async_fill_buffer (gpointer cb_data)
+{
+       return ((UnmanagedDownloader*)cb_data)->AsyncFillBuffer ();
+}
+
+gboolean
+UnmanagedDownloader::AsyncFillBuffer ()
+{
+       guchar buf[1024];
+
+       int n = read (fd, buf, sizeof (buf));
+
+       this->write (buf, n, write_data);
+}
+
+void
+UnmanagedDownloader::Open (char *verb, char *uri, bool async)
+{
+       fd = open (uri, O_RDONLY);
+       if (fd == -1) {
+               printf ("failed open\n");
+               return;
+       }
+
+       if (async)
+               async_idle = g_idle_add (async_fill_buffer, this);
+}
+
+void
+UnmanagedDownloader::Send ()
+{
+}
+
+void
+UnmanagedDownloader::Abort ()
+{
+       Close ();
+}
+
+void
+UnmanagedDownloader::Close ()
+{
+       if (fd != -1)
+               close (fd);
+       if (async_idle != -1)
+               g_source_remove (async_idle);
+}
+
+
+
+//
 // UIElement
 //
 DependencyProperty* UIElement::RenderTransformProperty;

Modified: trunk/moon/src/runtime.h
===================================================================
--- trunk/moon/src/runtime.h    2007-06-14 16:18:24 UTC (rev 79562)
+++ trunk/moon/src/runtime.h    2007-06-14 16:20:20 UTC (rev 79563)
@@ -299,19 +299,52 @@
        GHashTable *names;
 };
 
+typedef void (*downloader_write_func)(guchar *buf, gsize n, gpointer cb_data);
+
 class Downloader : public DependencyObject {
  public:
        Downloader () {};
        virtual Value::Kind GetObjectType () { return Value::DOWNLOADER; };     
 
+       virtual void Abort ();
+       virtual char* GetResponseText (char* PartName);
+       virtual void Open (char *verb, char *URI, bool Async);
+       virtual void Send ();
+
+       void SetWriteFunc (downloader_write_func write,
+                          gpointer data);
+
        static DependencyProperty *DownloadProgressProperty;
        static DependencyProperty *ResponseTextProperty;
        static DependencyProperty *StatusProperty;
        static DependencyProperty *StatusTextProperty;
        static DependencyProperty *UriProperty;
+
+ protected:
+       downloader_write_func write;
+       gpointer write_data;
 };
 Downloader* downloader_new ();
 
+class UnmanagedDownloader : public Downloader {
+ public:
+       UnmanagedDownloader ();
+       virtual ~UnmanagedDownloader ();
+       Value::Kind GetObjectType () { return Value::UNMANAGEDDOWNLOADER; };
+
+       virtual void Abort ();
+       //virtual char* GetResponseText (char* PartName);
+       virtual void Open (char *verb, char *URI, bool Async);
+       virtual void Send ();
+
+       void Close ();
+ private:
+       gboolean AsyncFillBuffer ();
+       static gboolean async_fill_buffer (gpointer cb_data);
+       int fd;
+       int async_idle;
+};
+
 class Visual : public DependencyObject {
  public:
        Visual () {};

Modified: trunk/moon/src/type.cpp
===================================================================
--- trunk/moon/src/type.cpp     2007-06-14 16:18:24 UTC (rev 79562)
+++ trunk/moon/src/type.cpp     2007-06-14 16:20:20 UTC (rev 79563)
@@ -99,6 +99,7 @@
        Type::RegisterType ("GradientBrush", Value::GRADIENTBRUSH, 
Value::BRUSH);
        Type::RegisterType ("GradientStop", Value::GRADIENTSTOP, 
Value::DEPENDENCY_OBJECT);
        Type::RegisterType ("GradientStopCollection", 
Value::GRADIENTSTOP_COLLECTION, Value::COLLECTION);
+       Type::RegisterType ("Image", Value::IMAGE, Value::MEDIABASE);
        Type::RegisterType ("ImageBrush", Value::IMAGEBRUSH, Value::TILEBRUSH);
        Type::RegisterType ("Inline", Value::INLINE, Value::DEPENDENCY_OBJECT);
        Type::RegisterType ("Inlines", Value::INLINES, Value::COLLECTION);
@@ -161,6 +162,7 @@
        Type::RegisterType ("TriggerActionCollection", 
Value::TRIGGERACTION_COLLECTION, Value::COLLECTION);
        Type::RegisterType ("TriggerCollection", Value::TRIGGER_COLLECTION, 
Value::COLLECTION);
        Type::RegisterType ("UIElement", Value::UIELEMENT, Value::VISUAL);
+       Type::RegisterType ("UnmanagedDownloader", Value::UNMANAGEDDOWNLOADER, 
Value::DOWNLOADER);
        Type::RegisterType ("VideoBrush", Value::VIDEOBRUSH, Value::TILEBRUSH);
        Type::RegisterType ("Visual", Value::VISUAL, Value::DEPENDENCY_OBJECT);
        Type::RegisterType ("VisualCollection", Value::VISUAL_COLLECTION, 
Value::COLLECTION);

Modified: trunk/moon/src/value.cpp
===================================================================
--- trunk/moon/src/value.cpp    2007-06-14 16:18:24 UTC (rev 79562)
+++ trunk/moon/src/value.cpp    2007-06-14 16:20:20 UTC (rev 79563)
@@ -218,6 +218,12 @@
        checked_get_subclass (GRADIENTSTOP_COLLECTION, GradientStopCollection);
 }
 
+Image*
+Value::AsImage ()
+{
+       checked_get_subclass (IMAGE, Image);
+}
+
 ImageBrush*
 Value::AsImageBrush ()
 {
@@ -590,6 +596,12 @@
        checked_get_subclass (UIELEMENT, UIElement);
 }
 
+UnmanagedDownloader*
+Value::AsUnmanagedDownloader ()
+{
+       checked_get_subclass (UNMANAGEDDOWNLOADER, UnmanagedDownloader);
+}
+
 VideoBrush*
 Value::AsVideoBrush ()
 {

Modified: trunk/moon/src/value.h
===================================================================
--- trunk/moon/src/value.h      2007-06-14 16:18:24 UTC (rev 79562)
+++ trunk/moon/src/value.h      2007-06-14 16:20:20 UTC (rev 79563)
@@ -58,6 +58,7 @@
 class GradientBrush;
 class GradientStop;
 class GradientStopCollection;
+class Image;
 class ImageBrush;
 class Inline;
 class Inlines;
@@ -120,6 +121,7 @@
 class TriggerActionCollection;
 class TriggerCollection;
 class UIElement;
+class UnmanagedDownloader;
 class VideoBrush;
 class Visual;
 class VisualCollection;
@@ -182,6 +184,7 @@
                GRADIENTBRUSH,
                GRADIENTSTOP,
                GRADIENTSTOP_COLLECTION,
+               IMAGE,
                IMAGEBRUSH,
                INLINE,
                INLINES,
@@ -244,6 +247,7 @@
                TRIGGERACTION_COLLECTION,
                TRIGGER_COLLECTION,
                UIELEMENT,
+               UNMANAGEDDOWNLOADER,
                VIDEOBRUSH,
                VISUAL,
                VISUAL_COLLECTION,
@@ -353,6 +357,7 @@
        GradientBrush*                 AsGradientBrush ();
        GradientStop*                  AsGradientStop ();
        GradientStopCollection*        AsGradientStopCollection ();
+       Image*                         AsImage ();
        ImageBrush*                    AsImageBrush ();
        Inline*                        AsInline ();
        Inlines*                       AsInlines ();
@@ -415,6 +420,7 @@
        TriggerActionCollection*       AsTriggerActionCollection ();
        TriggerCollection*             AsTriggerCollection ();
        UIElement*                     AsUIElement ();
+       UnmanagedDownloader*           AsUnmanagedDownloader ();
        VideoBrush*                    AsVideoBrush ();
        Visual*                        AsVisual ();
        VisualCollection*              AsVisualCollection ();

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

Reply via email to