Author: miguel
Date: 2007-05-25 19:05:50 -0400 (Fri, 25 May 2007)
New Revision: 77981
Modified:
trunk/moon/src/demo.c
trunk/moon/src/runtime.c
trunk/moon/src/runtime.h
trunk/moon/src/video.c
Log:
Updated vtables, we will probably move to C++
Modified: trunk/moon/src/demo.c
===================================================================
--- trunk/moon/src/demo.c 2007-05-25 22:19:59 UTC (rev 77980)
+++ trunk/moon/src/demo.c 2007-05-25 23:05:50 UTC (rev 77981)
@@ -63,6 +63,7 @@
gtk_init (&argc, &argv);
g_thread_init (NULL);
gdk_threads_init ();
+ runtime_init ();
w = gtk_window_new (GTK_WINDOW_TOPLEVEL);
da = gtk_drawing_area_new ();
Modified: trunk/moon/src/runtime.c
===================================================================
--- trunk/moon/src/runtime.c 2007-05-25 22:19:59 UTC (rev 77980)
+++ trunk/moon/src/runtime.c 2007-05-25 23:05:50 UTC (rev 77981)
@@ -31,8 +31,20 @@
};
#endif
-Surface *item_surface_get (Item *item);
+ObjectVtable object_vtable = { NULL } ;
+void
+object_init (Object *obj)
+{
+ obj->vtable = &object_vtable;
+}
+
+void
+object_class_init ()
+{
+ // Nothing.
+}
+
static void
vt_item_render (Item *item, Surface *s, double *affine, int x, int y, int
width, int height)
{
@@ -45,8 +57,15 @@
fprintf (stderr, "vt_item_getbounds called, you must implement this
method");
}
-static ItemVtable item_vtable = { &vt_item_render, &vt_item_getbounds };
+ItemVtable item_vtable;
+item_class_init ()
+{
+ item_vtable.object_vtable = object_vtable;
+ item_vtable.render = vt_item_render;
+ item_vtable.getbounds = vt_item_getbounds;
+}
+
/**
* item_getbounds:
* @item: the item to update the bounds of
@@ -61,7 +80,7 @@
double cx2 = item->x2;
double cy2 = item->y2;
- ItemVtable *vt = (ItemVtable *) item->vtable;
+ ItemVtable *vt = (ItemVtable *) item->object.vtable;
vt->getbounds (item);
//
@@ -76,7 +95,8 @@
void
item_init (Item *item)
{
- item->vtable = &item_vtable;
+ object_init (&item->object);
+ item->object.vtable = &item_vtable;
}
/*
@@ -190,13 +210,13 @@
item->xform = d;
}
- ItemVtable *vt = (ItemVtable *) item->vtable;
+ ItemVtable *vt = (ItemVtable *) item->object.vtable;
vt->getbounds (item);
item_invalidate (item);
}
static void
-group_render (Item *item, Surface *s, double *affine, int x, int y, int width,
int height)
+vt_group_render (Item *item, Surface *s, double *affine, int x, int y, int
width, int height)
{
Group *group = (Group *) item;
GSList *il;
@@ -205,25 +225,33 @@
for (il = group->items; il != NULL; il = il->next){
Item *item = (Item *) il->data;
- ItemVtable *vt = (ItemVtable *) item->vtable;
+ ItemVtable *vt = (ItemVtable *) item->object.vtable;
vt->render (item, s, use_affine, x, y, width, height);
}
}
static void
-group_getbounds (Item *item)
+vt_group_getbounds (Item *item)
{
}
-static ItemVtable group_vtable = { &group_render, &group_getbounds };
+static ItemVtable group_vtable;
+static void
+group_class_init ()
+{
+ group_vtable.object_vtable = object_vtable;
+ group_vtable.render = vt_group_render;
+ group_vtable.getbounds = vt_group_getbounds;
+}
+
void
group_init (Group *group)
{
item_init (&group->item);
- group->item.vtable = &group_vtable;
+ group->item.object.vtable = &group_vtable;
}
void
@@ -232,10 +260,16 @@
group->items = g_slist_append (group->items, item);
item->parent = (Item *) group;
- ItemVtable *vt = (ItemVtable *) item->vtable;
+ ItemVtable *vt = (ItemVtable *) item->object.vtable;
vt->getbounds (item);
}
+void
+shape_class_init ()
+{
+ // Nothing, this is pure abstract
+}
+
void
shape_init (Shape *shape)
{
@@ -257,12 +291,18 @@
cairo_restore (s->cairo);
}
-static ItemVtable surface_vtable = { &group_render, &group_getbounds };
+static ItemVtable surface_vtable;
+static void
+surface_class_init ()
+{
+ surface_vtable = group_vtable;
+}
+
Surface *
item_surface_get (Item *item)
{
- if (item->vtable == &surface_vtable)
+ if (item->object.vtable == &surface_vtable)
return (Surface *) item;
if (item->parent != NULL)
return item_surface_get (item->parent);
@@ -271,7 +311,7 @@
}
static void
-rectangle_render (Item *item, Surface *s, double *affine, int x, int y, int
width, int height)
+vt_rectangle_render (Item *item, Surface *s, double *affine, int x, int y, int
width, int height)
{
#if CAIRO
rectangle_draw (item, s, affine);
@@ -297,7 +337,7 @@
}
static void
-rectangle_getbounds (Item *item)
+vt_rectangle_getbounds (Item *item)
{
double res [6];
double *affine = item_affine_get_absolute (item, res);
@@ -315,14 +355,22 @@
#endif
}
-static ItemVtable rectangle_vtable = { &rectangle_render, rectangle_getbounds
};
+static ItemVtable rectangle_vtable;
void
+rectangle_class_init ()
+{
+ rectangle_vtable.object_vtable = object_vtable;
+ rectangle_vtable.render = vt_rectangle_render;
+ rectangle_vtable.getbounds = vt_rectangle_getbounds;
+}
+
+void
rectangle_init (Rectangle *rectangle)
{
shape_init (&rectangle->shape);
Item *i = &rectangle->shape.item;
- i->vtable = &rectangle_vtable;
+ i->object.vtable = &rectangle_vtable;
}
Item *
@@ -410,7 +458,7 @@
surface_init (Surface *s, int width, int height)
{
group_init (&s->group);
- s->group.item.vtable = &surface_vtable;
+ s->group.item.object.vtable = &surface_vtable;
s->width = width;
s->height = height;
surface_realloc (s);
@@ -437,6 +485,17 @@
surface_repaint (Surface *s, int x, int y, int width, int height)
{
surface_clear (s, x, y, width, height);
- group_render ((Item *) s, s, NULL, x, y, width, height);
+ vt_group_render ((Item *) s, s, NULL, x, y, width, height);
}
+void
+runtime_init ()
+{
+ object_class_init ();
+ item_class_init ();
+ group_class_init ();
+ shape_class_init ();
+ rectangle_class_init ();
+ surface_class_init ();
+ video_class_init ();
+}
Modified: trunk/moon/src/runtime.h
===================================================================
--- trunk/moon/src/runtime.h 2007-05-25 22:19:59 UTC (rev 77980)
+++ trunk/moon/src/runtime.h 2007-05-25 23:05:50 UTC (rev 77981)
@@ -8,6 +8,26 @@
typedef struct _Surface Surface;
typedef struct {
+ void (*nothing) ();
+} ObjectVtable;
+
+typedef struct {
+ void *vtable;
+} Object;
+
+void object_init (Object *object);
+
+typedef struct {
+ double opacity;
+ double *relative_transform;
+ double *transform;
+
+ GList *listeners;
+} Brush;
+
+typedef struct {
+ ObjectVtable object_vtable;
+
//
// render:
// Renders the given @item on the @surface. The parent affine
transformation is in
@@ -30,7 +50,7 @@
} ItemVtable;
struct _Item {
- void *vtable;
+ Object object;
// OpacityProperty;
// ClipProperty;
@@ -129,6 +149,12 @@
void surface_destroy (Surface *s);
void surface_repaint (Surface *s, int x, int y, int width, int height);
+// Vtables
+extern ItemVtable item_vtable;
+
+// External class init
+void video_class_init ();
+
#ifdef __cplusplus
};
#endif
Modified: trunk/moon/src/video.c
===================================================================
--- trunk/moon/src/video.c 2007-05-25 22:19:59 UTC (rev 77980)
+++ trunk/moon/src/video.c 2007-05-25 23:05:50 UTC (rev 77981)
@@ -83,7 +83,7 @@
static GMutex *video_lock;
static void
-video_getbounds (Item *item)
+vt_video_getbounds (Item *item)
{
Video *video = (Video *) item;
double res [6];
@@ -114,16 +114,17 @@
cairo_restore (s->cairo);
}
-static void video_render (Item *item, Surface *s, double *affine, int x, int
y, int width, int height);
+static void vt_video_render (Item *item, Surface *s, double *affine, int x,
int y, int width, int height);
static int video_inited;
-static ItemVtable video_vtable = { &video_render, &video_getbounds };
+ItemVtable video_vtable;
+
void
video_init (Video *video)
{
Item *item = &video->item;
item_init (item);
- item->vtable = &video_vtable;
+ item->object.vtable = &video_vtable;
if (!video_inited){
video_lock = g_mutex_new ();
@@ -326,7 +327,7 @@
}
static void
-video_render (Item *item, Surface *s, double *affine, int x, int y, int width,
int height)
+vt_video_render (Item *item, Surface *s, double *affine, int x, int y, int
width, int height)
{
Video *video = (Video *) item;
double actual [6];
@@ -395,4 +396,11 @@
g_free (video);
}
+void
+video_class_init ()
+{
+ video_vtable = item_vtable;
+ video_vtable.render = &vt_video_render;
+ video_vtable.getbounds = &vt_video_getbounds;
+}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches