Author: miguel
Date: 2007-05-31 20:20:55 -0400 (Thu, 31 May 2007)
New Revision: 78387
Modified:
trunk/moon/README
trunk/moon/src/brush.cpp
trunk/moon/src/demo.cpp
trunk/moon/src/runtime.cpp
trunk/moon/src/runtime.h
trunk/moon/src/shape.cpp
Log:
More stuff, rectangles paint, but we got a
situation with the outline being shown for the
other videos.
Modified: trunk/moon/README
===================================================================
--- trunk/moon/README 2007-05-31 23:47:47 UTC (rev 78386)
+++ trunk/moon/README 2007-06-01 00:20:55 UTC (rev 78387)
@@ -25,6 +25,19 @@
This is done so that our public API can be easily P/Invoked
from the managed side.
+* Base and Reference Counting
+
+ Base objects use a system similar to Gtk's object reference
+ counting. Objets are born in "floating" mode, which when
+ first refed turn into "refcount = 1".
+
+ This allows code like this:
+
+ shape_set_brush (rect, new SolidBrush ());
+
+ Without having to manually decrement the reference count for
+ the SolidBrush immediately following it.
+
* Items
Items for the base class for all the objects that are rendered,
@@ -185,6 +198,9 @@
I have not yet been able to find out what it is, so sometimes
the engine will not display anything, restart it in those cases.
+ You will notice some rectangles painting, thats where the
+ video should be, it is also not clear why those move
+
* Debugging
It is recommended that for now you do not `make install' as there
Modified: trunk/moon/src/brush.cpp
===================================================================
--- trunk/moon/src/brush.cpp 2007-05-31 23:47:47 UTC (rev 78386)
+++ trunk/moon/src/brush.cpp 2007-06-01 00:20:55 UTC (rev 78387)
@@ -21,20 +21,6 @@
#include <errno.h>
#include "runtime.h"
-Brush *
-brush_ref (Brush *brush)
-{
- brush->refcount++;
- return brush;
-}
-
-void
-brush_unref (Brush *brush)
-{
- if (--brush->refcount == 0)
- delete brush;
-}
-
struct Consumer {
BrushChangedNotify notify;
void *data;
Modified: trunk/moon/src/demo.cpp
===================================================================
--- trunk/moon/src/demo.cpp 2007-05-31 23:47:47 UTC (rev 78386)
+++ trunk/moon/src/demo.cpp 2007-06-01 00:20:55 UTC (rev 78387)
@@ -34,7 +34,7 @@
int
main (int argc, char *argv [])
{
- GtkWidget *w;
+ GtkWidget *w, *box, *button;
cairo_matrix_t trans;
gtk_init (&argc, &argv);
@@ -43,13 +43,20 @@
w = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ box = gtk_hbox_new (FALSE, 0);
+ button = gtk_button_new_with_label ("dingus");
+ gtk_container_add (GTK_CONTAINER (box), button);
+ gtk_widget_show_all (box);
+ //gtk_container_add (GTK_CONTAINER (w), box);
// Create our objects
Surface *t = surface_new (600, 600);
- gtk_container_add (GTK_CONTAINER (w), t->drawing_area);
- t->data = w;
+ gtk_widget_set_usize (t->drawing_area, 400, 400);
+ gtk_container_add (GTK_CONTAINER(w), t->drawing_area);
+
r = rectangle_new (100, 100, 100, 100);
- shape_set_stroke (r, new SolidColorBrush (Color (1.0, 0.0, 0.5, 0.5)));
+ Color c = Color (1.0, 0.0, 0.5, 0.5);
+ shape_set_stroke (r, new SolidColorBrush (c));
cairo_matrix_init_rotate (&trans, 0.4);
item_transform_set (r, (double *) (&trans));
surface_repaint (t, 0, 0, 300, 300);
@@ -58,20 +65,24 @@
v = video_new ("file:///tmp/BoxerSmacksdownInhoffe.wmv", 0, 0);
//printf ("Got %d\n", v);
item_transform_set (v, (double *) (&trans));
- group_item_add ((Group *) t, v);
+ panel_child_add (t, v);
#endif
- group_item_add ((Group *) t, r);
+ panel_child_add (t, r);
#ifdef VIDEO_DEMO
Item *v2 = video_new ("file:///tmp/Countdown-Colbert-BestNailings.wmv",
100, 100);
//Item *v2 = video_new ("file:///tmp/BoxerSmacksdownInhoffe.wmv", 100,
100);
- group_item_add ((Group *) t, v2);
+ panel_child_add (t, v2);
#endif
- gtk_widget_set_usize (w, 400, 400);
- gtk_widget_show (w);
+ printf ("set usize\n");
+ gtk_widget_set_usize (w, 600, 400);
+ printf ("show\n");
+ gtk_widget_show_all (w);
gtk_timeout_add (60, repaint, w);
+ printf ("timeout set\n");
//g_idle_add (repaint, w);
+ printf ("entering main\n");
gtk_main ();
}
Modified: trunk/moon/src/runtime.cpp
===================================================================
--- trunk/moon/src/runtime.cpp 2007-05-31 23:47:47 UTC (rev 78386)
+++ trunk/moon/src/runtime.cpp 2007-06-01 00:20:55 UTC (rev 78387)
@@ -31,6 +31,24 @@
};
#endif
+void
+base_ref (Base *base)
+{
+ if (base->refcount & BASE_FLOATS)
+ base->refcount = 1;
+ else
+ base->refcount++;
+}
+
+void
+base_unref (Base *base)
+{
+ if (base->refcount == BASE_FLOATS || base->refcount == 1){
+ delete base;
+ } else
+ base->refcount--;
+}
+
/**
* item_getbounds:
* @item: the item to update the bounds of
@@ -188,13 +206,13 @@
}
void
-Group::render (Surface *s, double *affine, int x, int y, int width, int height)
+Panel::render (Surface *s, double *affine, int x, int y, int width, int height)
{
GSList *il;
double actual [6];
double *use_affine = item_get_affine (affine, xform, actual);
- for (il = items; il != NULL; il = il->next){
+ for (il = children; il != NULL; il = il->next){
Item *item = (Item *) il->data;
item->render (s, use_affine, x, y, width, height);
@@ -202,12 +220,12 @@
}
void
-Group::getbounds ()
+Panel::getbounds ()
{
bool first = TRUE;
GSList *il;
- for (il = items; il != NULL; il = il->next){
+ for (il = children; il != NULL; il = il->next){
Item *item = (Item *) il->data;
item->getbounds ();
@@ -237,9 +255,9 @@
}
void
-group_item_add (Group *group, Item *item)
+panel_child_add (Panel *group, Item *item)
{
- group->items = g_slist_append (group->items, item);
+ group->children = g_slist_append (group->children, item);
item->parent = (Item *) group;
item->getbounds ();
Modified: trunk/moon/src/runtime.h
===================================================================
--- trunk/moon/src/runtime.h 2007-05-31 23:47:47 UTC (rev 78386)
+++ trunk/moon/src/runtime.h 2007-06-01 00:20:55 UTC (rev 78387)
@@ -1,5 +1,6 @@
G_BEGIN_DECLS
-
+
+#include <stdint.h>
#include <cairo.h>
class Surface;
@@ -10,7 +11,7 @@
struct Color {
double r, g, b, a;
public:
- Color () : r(0), g(0), b(0), a(0) {}
+ Color () {}
Color (double r, double g, double b, double a)
{
@@ -21,11 +22,24 @@
};
};
-class Brush {
+//
+// This guy provide reference counting
+//
+#define BASE_FLOATS 0x80000000
+
+class Base {
+ public:
+ uint32_t refcount;
+ Base () : refcount(BASE_FLOATS) {}
+};
+
+void base_ref (Base *base);
+void base_unref (Base *base);
+
+class Brush : public Base {
GSList *listeners;
public:
- int refcount;
- Brush () : opacity(0), relative_transform(NULL), transform(NULL),
listeners(NULL), refcount(1) {}
+ Brush () : opacity(0), relative_transform(NULL), transform(NULL),
listeners(NULL) {}
double opacity;
double *relative_transform;
@@ -37,13 +51,10 @@
virtual void SetupBrush (cairo_t *cairo) = 0;
};
-Brush *brush_ref (Brush *brush);
-void brush_unref (Brush *brush);
-
class SolidColorBrush : public Brush {
Color color;
public:
- SolidColorBrush (Color c) { color; }
+ SolidColorBrush (Color c) { color = c; }
virtual void SetupBrush (cairo_t *cairo);
};
@@ -107,24 +118,25 @@
double *item_affine_get_absolute (Item *item, double *result);
//
-// Group Class
+// Panel Class
//
-class Group : public Item {
+class Panel : public Item {
public:
- GSList *items;
+ GSList *children;
- Group () : items (NULL) {}
+ Panel () : children (NULL) {}
virtual void render (Surface *s, double *affine, int x, int y, int
width, int height);
virtual void getbounds ();
};
-void group_item_add (Group *group, Item *item);
+void panel_child_add (Panel *group, Item *item);
+
//
// Shape class
//
class Shape : public Item {
- void DoDraw (Surface *s, bool do_op);
+ void DoDraw (Surface *s, double *affine, bool do_op);
public:
Brush *fill, *stroke;
@@ -200,7 +212,7 @@
typedef struct _SurfacePrivate SurfacePrivate;
-class Surface : public Group {
+class Surface : public Panel {
public:
Surface () : width (0), height (0), buffer (0), pixbuf (NULL),
cairo_surface (NULL), cairo (NULL), data(NULL) {}
Modified: trunk/moon/src/shape.cpp
===================================================================
--- trunk/moon/src/shape.cpp 2007-05-31 23:47:47 UTC (rev 78386)
+++ trunk/moon/src/shape.cpp 2007-06-01 00:20:55 UTC (rev 78387)
@@ -18,8 +18,15 @@
#include "runtime.h"
void
-Shape::DoDraw (Surface *s, bool do_op)
+Shape::DoDraw (Surface *s, double *affine, bool do_op)
{
+ double result [6];
+ double *matrix = item_get_affine (affine, xform, result);
+
+ cairo_save (s->cairo);
+ if (matrix != NULL)
+ //cairo_set_matrix (s->cairo, (cairo_matrix_t *) matrix);
+
if (fill){
fill->SetupBrush (s->cairo);
Draw (s);
@@ -33,22 +40,13 @@
if (do_op)
cairo_stroke (s->cairo);
}
-
+ cairo_restore (s->cairo);
}
void
Shape::render (Surface *s, double *affine, int x, int y, int width, int height)
{
- double result [6];
- double *matrix = item_get_affine (affine, xform, result);
-
- cairo_save (s->cairo);
- if (matrix != NULL)
- cairo_set_matrix (s->cairo, (cairo_matrix_t *) matrix);
-
- DoDraw (s, TRUE);
-
- cairo_restore (s->cairo);
+ DoDraw (s, affine, TRUE);
}
void
@@ -58,12 +56,12 @@
double *affine = item_affine_get_absolute (this, res);
Surface *s = item_surface_get (this);
- if (s == NULL){
- // not yet attached
+
+ // not yet attached
+ if (s == NULL)
return;
- }
- DoDraw (s, FALSE);
+ DoDraw (s, affine, FALSE);
cairo_stroke_extents (s->cairo, &x1, &y1, &x2, &y2);
cairo_new_path (s->cairo);
}
@@ -72,23 +70,27 @@
shape_set_fill (Shape *shape, Brush *fill)
{
if (shape->fill != NULL)
- brush_unref (shape->fill);
+ base_unref (shape->fill);
- shape->fill = brush_ref (fill);
+ base_ref (fill);
+ shape->fill = fill;
}
void
shape_set_stroke (Shape *shape, Brush *stroke)
{
if (shape->stroke != NULL)
- brush_unref (shape->stroke);
+ base_unref (shape->stroke);
- shape->stroke = brush_ref (stroke);
+ base_ref (stroke);
+ shape->stroke = stroke;
}
void
Rectangle::Draw (Surface *s)
{
+ static int n;
+
cairo_rectangle (s->cairo, x, y, w, h);
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches