Author: miguel
Date: 2007-06-04 20:38:55 -0400 (Mon, 04 Jun 2007)
New Revision: 78603

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

        * ffvideo.cpp: Set audio initialization to zero for now, so we can
        continue debugging.

        * runtime.cpp (Canvas): override render, in preparation for using
        attached properties.   I get the feeling am going to regret not
        keeping the top/left attached properties somewhere else.

        (Value): introduce the discriminating union for values as
        discussed on irc.
        
        (DependencyObject): use lower case name for properties.
        Take Value * instead of void *, this is so we can represent NULL
        values (is this a good idea Chris, or do we want to have a
        Value.Type.NULL enumeration value?

        Update hash table creation to g_free the result on hash table
        update and removal.

        (Event): Update indentation to be Linux-like instead of GNU like.



Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog    2007-06-04 23:29:59 UTC (rev 78602)
+++ trunk/moon/src/ChangeLog    2007-06-05 00:38:55 UTC (rev 78603)
@@ -1,3 +1,25 @@
+2007-06-04  Miguel de Icaza  <[EMAIL PROTECTED]>
+
+       * ffvideo.cpp: Set audio initialization to zero for now, so we can
+       continue debugging.
+
+       * runtime.cpp (Canvas): override render, in preparation for using
+       attached properties.   I get the feeling am going to regret not
+       keeping the top/left attached properties somewhere else.
+
+       (Value): introduce the discriminating union for values as
+       discussed on irc.
+       
+       (DependencyObject): use lower case name for properties.
+       Take Value * instead of void *, this is so we can represent NULL
+       values (is this a good idea Chris, or do we want to have a
+       Value.Type.NULL enumeration value?
+
+       Update hash table creation to g_free the result on hash table
+       update and removal.
+
+       (Event): Update indentation to be Linux-like instead of GNU like.
+
 2007-06-04  Sebastien Pouliot  <[EMAIL PROTECTED]>
 
        * shape.cpp|h: Add Poly[line|gon] drawing code and C helper functions 

Modified: trunk/moon/src/ffvideo.cpp
===================================================================
--- trunk/moon/src/ffvideo.cpp  2007-06-04 23:29:59 UTC (rev 78602)
+++ trunk/moon/src/ffvideo.cpp  2007-06-05 00:38:55 UTC (rev 78603)
@@ -235,6 +235,10 @@
 
                        cc = video->audio_stream->codec;
                        n = snd_pcm_open (&video->pcm, "default", 
SND_PCM_STREAM_PLAYBACK, 0 /*SND_PCM_NONBLOCK*/);
+
+                       // Set this to NULL to disable audio for now.
+                       video->pcm = NULL;
+                       n = -1;
                        if (n < 0)
                                printf ("Error, can not initialize audio %d\n", 
video->pcm);
                        else {

Modified: trunk/moon/src/runtime.cpp
===================================================================
--- trunk/moon/src/runtime.cpp  2007-06-04 23:29:59 UTC (rev 78602)
+++ trunk/moon/src/runtime.cpp  2007-06-05 00:38:55 UTC (rev 78603)
@@ -413,7 +413,27 @@
 {
 
 }
+
+void
+Canvas::render (Surface *s, int x, int y, int width, int height)
+{
+       GSList *il;
+       double actual [6];
        
+       for (il = children.list; il != NULL; il = il->next){
+               UIElement *item = (UIElement *) il->data;
+
+               
+               item->render (s, x, y, width, height);
+       }
+}
+
+void 
+Canvas::getbounds ()
+{
+       Panel::getbounds ();
+}
+
 Surface *
 surface_new (int width, int height)
 {
@@ -454,38 +474,41 @@
 GHashTable *DependencyObject::default_values = NULL;
 
 void
-DependencyObject::SetValue (DependencyProperty *Property, void *Value)
+DependencyObject::SetValue (DependencyProperty *property, Value value)
 {
-       g_hash_table_insert (current_values, Property->Name, Value);
+       Value *copy = g_new (Value, 1);
+       *copy = value;
+
+       g_hash_table_insert (current_values, property->name, copy);
 }
 
-void *
-DependencyObject::GetValue (DependencyProperty *Property)
+Value *
+DependencyObject::GetValue (DependencyProperty *property)
 {
-       void *value = NULL;
+       Value *value = NULL;
        GHashTable * table = NULL;
 
-       value = g_hash_table_lookup (current_values, Property->Name);
+       value = (Value *) g_hash_table_lookup (current_values, property->name);
 
-       if (NULL != value)
+       if (value != NULL)
                return value;
 
-       if (NULL == default_values)
+       if (default_values != NULL)
                return NULL;
 
-       table = (GHashTable*) g_hash_table_lookup (default_values, 
&Property->Type);
+       table = (GHashTable*) g_hash_table_lookup (default_values, 
&property->type);
        
-       if (NULL == table)
+       if (table == NULL)
                return NULL;
 
-       value = g_hash_table_lookup (table, Property->Name);
+       value = (Value *) g_hash_table_lookup (table, property->name);
 
        return value;
 }
 
 DependencyObject::DependencyObject ()
 {
-       current_values = g_hash_table_new (g_str_hash, g_str_equal);
+       current_values = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, 
g_free);
 }
 
 DependencyObject::~DependencyObject ()
@@ -493,25 +516,28 @@
        g_hash_table_destroy (current_values);
 }
 
+//
+// DependencyObject takes ownership of the Value * for default_value
+//
 DependencyProperty *
-DependencyObject::Register (int type, char *name, void *default_value)
+DependencyObject::Register (DependencyObject::Type type, char *name, Value 
*default_value)
 {
        if (NULL == default_values)
                default_values = g_hash_table_new (g_int_hash, g_int_equal);
 
        DependencyProperty *property = new DependencyProperty (name, 
default_value);
-       property->Type = type;
+       property->type = type;
        
        GHashTable *table;
 
-       table = (GHashTable*) g_hash_table_lookup (default_values, 
&property->Type);
+       table = (GHashTable*) g_hash_table_lookup (default_values, 
&property->type);
 
-       if (NULL == table) {
+       if (table == NULL) {
                table = g_hash_table_new (g_str_hash, g_str_equal);
-               g_hash_table_insert (default_values, &property->Type, table);
+               g_hash_table_insert (default_values, &property->type, table);
        }
 
-       g_hash_table_insert (table, property->Name, property->DefaultValue);
+       g_hash_table_insert (table, property->name, property->default_value);
 
        return property;
 }
@@ -519,22 +545,23 @@
 /*
        DependencyProperty
 */
-DependencyProperty::DependencyProperty (char *name, void *default_value)
+DependencyProperty::DependencyProperty (char *name, Value *default_value)
 {
-       this->Name = g_strdup (name);
-       this->DefaultValue = default_value;
+       this->name = g_strdup (name);
+       this->default_value = default_value;
 }
 
 DependencyProperty::~DependencyProperty ()
 {
-       g_free (Name);
+       g_free (name);
+       if (default_value != NULL)
+               g_free (default_value);
 }
 
-
 // event handlers for c++
 typedef struct {
-  EventHandler func;
-  gpointer data;
+       EventHandler func;
+       gpointer data;
 } EventClosure;
 
 EventObject::EventObject ()
@@ -557,62 +584,75 @@
 void
 EventObject::AddEventHandler (char *event_name, EventHandler handler, gpointer 
data)
 {
-  GList *events = (GList*)g_hash_table_lookup (event_hash, event_name);
+       GList *events = (GList*)g_hash_table_lookup (event_hash, event_name);
 
-  EventClosure *closure = new EventClosure ();
-  closure->func = handler;
-  closure->data = data;
+       EventClosure *closure = new EventClosure ();
+       closure->func = handler;
+       closure->data = data;
 
-  if (events == NULL) {
-    g_hash_table_insert (event_hash, g_strdup (event_name), g_list_prepend 
(NULL, closure));
-  }
-  else {
-    g_list_append (events, closure); // not prepending means we don't need to 
g_hash_table_replace
-  }
+       if (events == NULL) {
+               g_hash_table_insert (event_hash, g_strdup (event_name), 
g_list_prepend (NULL, closure));
+       }
+       else {
+               g_list_append (events, closure); // not prepending means we 
don't need to g_hash_table_replace
+       }
 }
 
 void
 EventObject::RemoveEventHandler (char *event_name, EventHandler handler, 
gpointer data)
 {
-  GList *events = (GList*)g_hash_table_lookup (event_hash, event_name);
+       GList *events = (GList*)g_hash_table_lookup (event_hash, event_name);
 
-  if (events == NULL)
-    return;
+       if (events == NULL)
+               return;
 
-  GList *l;
-  for (l = events; l; l = l->next) {
-    EventClosure *closure = (EventClosure*)l->data;
-    if (closure->func == handler && closure->data == data)
-      break;
-  }
+       GList *l;
+       for (l = events; l; l = l->next) {
+               EventClosure *closure = (EventClosure*)l->data;
+               if (closure->func == handler && closure->data == data)
+                       break;
+       }
 
-  if (l == NULL) /* we didn't find it */
-    return;
+       if (l == NULL) /* we didn't find it */
+               return;
 
-  g_free (l->data);
-  events = g_list_delete_link (events, l);
+       g_free (l->data);
+       events = g_list_delete_link (events, l);
 
-  if (events == NULL) {
-    /* delete the event */
-    gpointer key, value;
-    g_hash_table_lookup_extended (event_hash, event_name, &key, &value);
-    g_free (key);
-  }
-  else {
-    g_hash_table_replace (event_hash, event_name, events);
-  }
+       if (events == NULL) {
+               /* delete the event */
+               gpointer key, value;
+               g_hash_table_lookup_extended (event_hash, event_name, &key, 
&value);
+               g_free (key);
+       }
+       else {
+               g_hash_table_replace (event_hash, event_name, events);
+       }
 }
 
 void
 EventObject::EmitEvent (char *event_name)
 {
-  GList *events = (GList*)g_hash_table_lookup (event_hash, event_name);
+       GList *events = (GList*)g_hash_table_lookup (event_hash, event_name);
 
-  if (events == NULL)
-    return;
+       if (events == NULL)
+               return;
+       
+       for (GList *l = events; l; l = l->next) {
+               EventClosure *closure = (EventClosure*)l->data;
+               closure->func (closure->data);
+       }
+}
 
-  for (GList *l = events; l; l = l->next) {
-    EventClosure *closure = (EventClosure*)l->data;
-    closure->func (closure->data);
-  }
+void 
+canvas_init ()
+{
+       DependencyObject::Register (DependencyObject::CANVAS, "Top", new Value 
(0.0));
+       DependencyObject::Register (DependencyObject::CANVAS, "Left", new Value 
(0.0));
 }
+
+void
+runtime_init ()
+{
+       canvas_init ();
+}

Modified: trunk/moon/src/runtime.h
===================================================================
--- trunk/moon/src/runtime.h    2007-06-04 23:29:59 UTC (rev 78602)
+++ trunk/moon/src/runtime.h    2007-06-05 00:38:55 UTC (rev 78603)
@@ -10,15 +10,15 @@
 
 class EventObject {
  public:
-  EventObject ();
-  ~EventObject ();
-
-  void AddEventHandler (char *event_name, EventHandler handler, gpointer data);
-  void RemoveEventHandler (char *event_name, EventHandler handler, gpointer 
data);
-
-  void EmitEvent (char *event_name);
+       EventObject ();
+       ~EventObject ();
+       
+       void AddEventHandler (char *event_name, EventHandler handler, gpointer 
data);
+       void RemoveEventHandler (char *event_name, EventHandler handler, 
gpointer data);
+       
+       void EmitEvent (char *event_name);
  private:
-  GHashTable *event_hash;
+       GHashTable *event_hash;
 };
 
 class Surface;
@@ -93,17 +93,43 @@
 void collection_add    (Collection *collection, void *data);
 void collection_remove (Collection *collection, void *data);
 
+struct Value {
+public:
+       enum Kind {
+               INVALID = 0,
+               DOUBLE = 1
+       };
+
+       Kind k;
+       union {
+               double d;
+       } u;
+
+       Value () : k (INVALID) {}
+       
+       Value (double d)
+       {
+               k = DOUBLE;
+               u.d = d;
+       }
+};
+
 //
 // DependencyObject
 // 
 
 class DependencyObject {
  public:
+       enum Type {
+               INVALID = 0,
+               CANVAS,
+       };
+       
        DependencyObject ();
        ~DependencyObject ();
-       static DependencyProperty* Register (int type, char *name, void 
*default_value);
-       void SetValue (DependencyProperty *property, void *value);
-       void* GetValue (DependencyProperty *property);
+       static DependencyProperty* Register (Type type, char *name, Value 
*default_value);
+       void SetValue (DependencyProperty *property, Value value);
+       Value *GetValue (DependencyProperty *property);
 
  private:
        static GHashTable *default_values;
@@ -117,10 +143,11 @@
  public:
        DependencyProperty () {} ;
        ~DependencyProperty ();
-       DependencyProperty (char *name, void *default_value);
-       char *Name;
-       void *DefaultValue;
-       int Type;
+       DependencyProperty (char *name, Value *default_value);
+
+       char *name;
+       Value *default_value;
+       DependencyObject::Type type;
 };
 
 //
@@ -305,7 +332,10 @@
  public:
        virtual Point getxformorigin () { return Point (0, 0); }
 
-       virtual void set_prop_from_str (const char *pname, const char *vname);  
+       virtual void set_prop_from_str (const char *pname, const char *vname);
+
+       virtual void render (Surface *s, int x, int y, int width, int height);
+       virtual void getbounds ();
 };
 
 //
@@ -316,7 +346,7 @@
        double x, y;            // Canvas.TopProperty, Canvas.LeftProperty
        double w, h;
 
-       FrameworkElement () : x(0), y(0), w(0), h(0) {} 
+       FrameworkElement () : w(0), h(0) {} 
 
        virtual void set_prop_from_str (const char *prop, const char *value);
 };
@@ -381,8 +411,10 @@
 
 void    *surface_get_drawing_area (Surface *s);
 
+//
+// XAML
+//
 
-
 UIElement  *xaml_create_from_file     (const char *filename);
 UIElement  *xaml_create_from_str      (const char *xaml);
 

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

Reply via email to