Hi all,

I wanto to create an object ClutterGrid, extending the ClutterActor main
class, but I have a problem.

I have followed this tutorial:
http://www.openismus.com/misc/clutter_tutorial/docs/tutorial/html/apa.html

The object is the same but I've a property in addition to the "color" in
example; this is the struct of private object:

struct _ClutterGridPrivate
{
    ClutterColor    color;
    gint        step;
};

I've modified the functions "clutter_grid_set_property" and
"clutter_grid_get_property", to manage the PROP_STEP enumeration,
and I don't receive any compilation problem....

.... but ....

When I try to executing the test program I receive this errors:

(./grid_actor_test:32623): GLib-GObject-CRITICAL **: g_param_spec_boxed:
assertion `G_TYPE_IS_VALUE_TYPE (boxed_type)' failed

(./grid_actor_test:32623): GLib-GObject-CRITICAL **:
g_object_class_install_property: assertion `G_IS_PARAM_SPEC (pspec)' failed

As attachment I've put the grid_actor.c file.
I think the error stay into the "clutter_grid_class_init" function.

Where I've wrong?

Sorry for my english and thanks for help!

Ciao

--
Matteo Cappadonna
   [EMAIL PROTECTED]
/* grid_actor.c   -   Clutter actor for grid
 *
 * (c) Matteo <mouser> Cappadonna, 2008
 * [EMAIL PROTECTED]
 */
 
#include "grid_actor.h"

#include <clutter/cogl.h>
#include <GL/glx.h>

G_DEFINE_TYPE (ClutterGrid, clutter_grid, CLUTTER_TYPE_ACTOR);

enum
{
	PROP_0,
	
	PROP_COLOR,
	PROP_STEP
};

#define CLUTTER_GRID_GET_PRIVATE(obj) \
  (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
  CLUTTER_TYPE_GRID, ClutterGridPrivate))
  
struct _ClutterGridPrivate
{
	ClutterColor	color;
	gint		step;
};

static void
clutter_grid_paint (ClutterActor *self)
{
	ClutterGrid		*grid = CLUTTER_GRID(self);
	ClutterGridPrivate	*priv;
	ClutterGeometry		geom;
	ClutterColor		tmp_col;
	
	gint x, y;
	
	grid = CLUTTER_GRID(self);
	priv = grid->priv;
	
	cogl_push_matrix();
	
	cogl_enable(CGL_ENABLE_BLEND);
	
	clutter_actor_get_geometry (self, &geom);
	
	/* parent paint call will have translated us into position so
	 * paint from 0, 0
	 */
	tmp_col.red	= priv->color.red;
	tmp_col.green	= priv->color.green;
	tmp_col.blue	= priv->color.blue;
	tmp_col.alpha	= clutter_actor_get_opacity(self);
	
	/* paint the grid
	 */
	glBegin(GL_LINES);
	
	/* paint vertical lines
	 */
	for (x=priv->step; x<geom.width; x+=priv->step)
	{
		glVertex2i(x, 0);
		glVertex2i(x, geom.height);			
	}
	
	/* paint horizontal lines
	 */
	for (y=priv->step; y<geom.height; y+=priv->step)
	{
		glVertex2i(0, y);
		glVertex2i(geom.width, y);
	}
	
	glEnd();
	
	cogl_pop_matrix();
}

static void
clutter_grid_set_property (GObject	*object,
			    guint	prop_id,
			    const GValue *value,
			    GParamSpec	*pspec)
{
	ClutterGrid *grid = CLUTTER_GRID(object);
	
	switch (prop_id)
	{
	case PROP_COLOR:
		clutter_grid_set_color(grid, g_value_get_boxed(value));
		break;
		
	case PROP_STEP:
		clutter_grid_set_step(grid, g_value_get_boxed(value));
		break;
		
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
		break;
	}
}

static void
clutter_grid_get_property (GObject	*object,
			    guint	prop_id,
			    GValue	*value,
			    GParamSpec	*pspec)
{
	ClutterGrid	*grid = CLUTTER_GRID(object);
	ClutterColor	color;
	
	switch (prop_id)
	{
	case PROP_COLOR:
		clutter_grid_get_color(grid, &color);
		g_value_set_boxed(value, &color);
		break;
		
	case PROP_STEP:
		g_value_set_boxed(value, &CLUTTER_GRID_GET_PRIVATE(object)->step);
		break;
		
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
		break;
	}
}

static void
clutter_grid_finalize (GObject *object)
{
	G_OBJECT_CLASS(clutter_grid_parent_class)->finalize(object);
}

static void
clutter_grid_dispose (GObject *object)
{
	G_OBJECT_CLASS(clutter_grid_parent_class)->dispose(object);
}

static void
clutter_grid_class_init (ClutterGridClass *klass)
{
	GObjectClass		*gobject_class = G_OBJECT_CLASS(klass);
	ClutterActorClass	*actor_class = CLUTTER_ACTOR_CLASS(klass);
	
	actor_class->paint = clutter_grid_paint;
	
	gobject_class->finalize		= clutter_grid_finalize;
	gobject_class->dispose		= clutter_grid_dispose;
	gobject_class->set_property	= clutter_grid_set_property;
	gobject_class->get_property	= clutter_grid_get_property;
	
	/**
	 * ClutterGrid:color:
	 *
	 * The color of the grid.
	 */
	g_object_class_install_property(gobject_class,
					PROP_COLOR,
					g_param_spec_boxed("color",
							   "Color",
							   "The color of the grid",
							   CLUTTER_TYPE_COLOR,
							   G_PARAM_READABLE | G_PARAM_WRITABLE));
							   
	/**
	 * ClutterGrid:step:
	 *
	 * The step of the grid lines.
	 */
	g_object_class_install_property(gobject_class,
					PROP_STEP,
					g_param_spec_boxed("step",
							   "Step",
							   "The step of the grid lines.",
							   G_TYPE_BOXED,
							   G_PARAM_READABLE | G_PARAM_WRITABLE));
							   
	g_type_class_add_private(gobject_class, sizeof(ClutterGridPrivate));
}

static void
clutter_grid_init (ClutterGrid *self)
{
	ClutterGridPrivate *priv;
	
	self->priv = priv = CLUTTER_GRID_GET_PRIVATE(self);
	
	priv->color.red = 0xff;
	priv->color.green = 0xff;
	priv->color.blue = 0xff;
	priv->color.alpha = 0xff;
}

/**
 * clutter_grid_new:
 *
 * Create a new #ClutterActor with a grid shape.
 *
 * Return value: a new #ClutterActor
 */
ClutterActor*
clutter_grid_new (void)
{
	return g_object_new(CLUTTER_TYPE_GRID, NULL);
}

/**
 * clutter_grid_new_with_color:
 * @color: a #ClutterColor
 *
 * Creates a new #ClutterActor with a grid shape
 * and with @color.
 *
 * Return value: a new #ClutterActor
 */
ClutterActor*
clutter_grid_new_with_color (const ClutterColor *color)
{
	return g_object_new(CLUTTER_TYPE_GRID,
			    "color", color,
			    NULL);
}

/**
 * clutter_grid_get_color:
 * @grid: a #ClutterGrid
 * @color: return location for a #ClutterColor
 *
 * Retrieves the color of a @grid.
 */
void
clutter_grid_get_color (ClutterGrid	*grid,
			 ClutterColor	*color)
{
	ClutterGridPrivate *priv;
	
	g_return_if_fail(CLUTTER_IS_GRID(grid));
	g_return_if_fail(color != NULL);
	
	priv = grid->priv;
	
	color->red = priv->color.red;
	color->green = priv->color.green;
	color->blue = priv->color.blue;
	color->alpha = priv->color.alpha;
}

/**
 * clutter_grid_set_color:
 * @grid: a #ClutterGrid
 * @color: a #ClutterColor
 *
 * Sets the color of @grid
 */
void
clutter_grid_set_color (ClutterGrid		*grid,
			 const ClutterColor	*color)
{
	ClutterGridPrivate *priv;
	
	g_return_if_fail(CLUTTER_IS_GRID(grid));
	g_return_if_fail(color != NULL);
	
	g_object_ref(grid);
	
	priv = grid->priv;
	
	priv->color.red = color->red;
	priv->color.green = color->green;
	priv->color.blue = color->blue;
	priv->color.alpha = color->alpha;
	
	clutter_actor_set_opacity(CLUTTER_ACTOR(grid), priv->color.alpha);
	
	if (CLUTTER_ACTOR_IS_VISIBLE(CLUTTER_ACTOR(grid)))
		clutter_actor_queue_redraw(CLUTTER_ACTOR(grid));
		
	g_object_notify(G_OBJECT(grid), "color");
	g_object_unref(grid);
}

/**
 * clutter_grid_get_step:
 * @grid: a #ClutterGrid
 * @step: return location for a #gint
 *
 * Retrieves the step of @grid lines.
 */
void
clutter_grid_get_step (ClutterGrid	*grid,
		 	gint		*step)
{
	ClutterGridPrivate *priv;
	
	g_return_if_fail(CLUTTER_IS_GRID(grid));
	g_return_if_fail(step != NULL);
	
	priv = grid->priv;
	
	step = &priv->step;
}

/**
 * clutter_grid_set_color:
 * @grid: a #ClutterGrid
 * @step: a @gint
 *
 * Sets the step of @grid lines
 */
void
clutter_grid_set_step (ClutterGrid	*grid,
			const gint	*step)
{
	ClutterGridPrivate *priv;
	
	g_return_if_fail(CLUTTER_IS_GRID(grid));
	g_return_if_fail(grid != NULL);
	
	g_object_ref(grid);
	
	priv = grid->priv;
	
	priv->step = *step;
	
	if (CLUTTER_ACTOR_IS_VISIBLE(CLUTTER_ACTOR(grid)))
		clutter_actor_queue_redraw(CLUTTER_ACTOR(grid));
		
	g_object_notify(G_OBJECT(grid), "step");
	g_object_unref(grid);
}

Reply via email to