Hi,

ok it was easier than I thought.
Creating an hbox and attaching textures was the correct thing, I suppose.
The width and height would have been calculated on that hbox.

I attach the sample program, if someone would ever need that.

regards,
Massimo



On 12/13/2010 12:48 AM, Massimo Cora' wrote:
Hi,

I'm trying to subclass ClutterActor to create a composite actor.
The resulting actor would be really simple because composed by an
horizontal box with three textures loaded.
I'm a bit confused by the docs and because I don't have a clean simple
example on how to do it.
On my code I've tried to implement map, unmap, get_preferred_width,
get_preferred_height, paint, allocate, and also pick, but I wasn't able
to have it displayed.

Can you please point me to something specific?

thanks and regards,
Massimo CorĂ 
_______________________________________________
clutter-app-devel-list mailing list
[email protected]
http://lists.clutter-project.org/listinfo/clutter-app-devel-list

/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
 * 
 * Copyright (C) Massimo Cora' 2010 <[email protected]>
 * 
 */

#include "test-subclassing.h"

struct _SelectionSongPriv
{
	ClutterActor *foo_plus;
	ClutterActor *foo_minus;
	
	ClutterActor *hbox;
	ClutterLayoutManager *layout_hbox;
};

#define PLUS_TEX "./button-plus.png"
#define MINUS_TEX "./button-minus.png"	


#define SELECTION_SONG_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
	SELECTION_TYPE_SONG, SelectionSongPriv))

G_DEFINE_TYPE (SelectionSong, selection_song, CLUTTER_TYPE_ACTOR);

static void
selection_song_init (SelectionSong *object)
{
	SelectionSongPriv *priv;

	priv = SELECTION_SONG_GET_PRIVATE (object);
	

	priv->layout_hbox = clutter_box_layout_new ();
	priv->hbox = clutter_box_new (priv->layout_hbox);
	
	priv->foo_plus = clutter_texture_new_from_file (PLUS_TEX, NULL);
	priv->foo_minus = clutter_texture_new_from_file (MINUS_TEX, NULL);

	clutter_box_layout_pack (CLUTTER_BOX_LAYOUT (priv->layout_hbox), priv->foo_plus, 
	    				   FALSE,
                           FALSE, /* x-fill */
                           FALSE, /* y-fill */
                           CLUTTER_BOX_ALIGNMENT_START,
                           CLUTTER_BOX_ALIGNMENT_CENTER);
	
	clutter_box_layout_pack (CLUTTER_BOX_LAYOUT (priv->layout_hbox), priv->foo_minus, 
	    			   	   FALSE,
                           FALSE, /* x-fill */
                           FALSE, /* y-fill */
                           CLUTTER_BOX_ALIGNMENT_END,
                           CLUTTER_BOX_ALIGNMENT_CENTER);
	
	clutter_actor_set_parent (priv->hbox, CLUTTER_ACTOR (object));
}

static void
selection_song_finalize (GObject *object)
{
	/* TODO: Add deinitalization code here */

	G_OBJECT_CLASS (selection_song_parent_class)->finalize (object);
}

static void
selection_song_map (ClutterActor *object)
{
	SelectionSongPriv *priv;

	priv = SELECTION_SONG_GET_PRIVATE (object);

  	CLUTTER_ACTOR_CLASS (selection_song_parent_class)->map (object);
	
	DEBUG_PRINT ("map called");

	clutter_actor_map (priv->hbox);
}

static void
selection_song_unmap (ClutterActor *object)
{
	SelectionSongPriv *priv;

	priv = SELECTION_SONG_GET_PRIVATE (object);

  	CLUTTER_ACTOR_CLASS (selection_song_parent_class)->unmap (object);

	DEBUG_PRINT ("unmap called");

	clutter_actor_unmap (priv->hbox);
}

static void
selection_song_get_preferred_width (ClutterActor *actor,
                              gfloat        for_height,
                              gfloat       *min_width_p,
                              gfloat       *natural_width_p)
{
	SelectionSongPriv *priv;

	priv = SELECTION_SONG_GET_PRIVATE (actor);

	DEBUG_PRINT ("get_preferred_width [%f]", for_height);

	*natural_width_p = *min_width_p = clutter_actor_get_width (priv->hbox);
}

static void
selection_song_get_preferred_height (ClutterActor *actor,
                               gfloat        for_width,
                               gfloat       *min_height_p,
                               gfloat       *natural_height_p)
{
	SelectionSongPriv *priv;

	priv = SELECTION_SONG_GET_PRIVATE (actor);
	
	DEBUG_PRINT ("get_preferred_height [%f]", for_width);	

	*natural_height_p = *min_height_p = clutter_actor_get_height (priv->hbox);
}

static void
selection_song_paint (ClutterActor *actor)
{
	SelectionSongPriv *priv;

	priv = SELECTION_SONG_GET_PRIVATE (actor);
  	clutter_actor_paint (priv->hbox);
}


static void
selection_song_allocate (ClutterActor          *actor,
                   const ClutterActorBox *box,
                   ClutterAllocationFlags flags)
{
	SelectionSongPriv *priv;
  	ClutterActorClass *parent_class;

	priv = SELECTION_SONG_GET_PRIVATE (actor);
	

  	parent_class = CLUTTER_ACTOR_CLASS (selection_song_parent_class);
  	parent_class->allocate (actor, box, flags);

	clutter_actor_allocate (priv->hbox, box, flags);
}

static void
selection_song_class_init (SelectionSongClass *klass)
{
	GObjectClass* object_class = G_OBJECT_CLASS (klass);
	ClutterActorClass* actor_class = CLUTTER_ACTOR_CLASS (klass);

	object_class->finalize = selection_song_finalize;

	actor_class->map = selection_song_map;
	actor_class->unmap = selection_song_unmap;
  	actor_class->get_preferred_width = selection_song_get_preferred_width;
  	actor_class->get_preferred_height = selection_song_get_preferred_height;
	actor_class->paint = selection_song_paint;
	actor_class->allocate = selection_song_allocate;
	
	g_type_class_add_private (klass, sizeof (SelectionSongPriv));
}

SelectionSong *		
selection_song_new ()
{
	return g_object_new (SELECTION_TYPE_SONG, NULL);	
}


 

int
main (int argc, char ** argv)
{
	ClutterStage *stage;
	ClutterActor *actor;
	
  	clutter_init (&argc, &argv);
	
	actor = CLUTTER_ACTOR (selection_song_new ());	
  	stage = CLUTTER_STAGE (clutter_stage_get_default ());
	
  	clutter_container_add (CLUTTER_CONTAINER (stage), actor, NULL);
	clutter_actor_show ( CLUTTER_ACTOR (stage));
	clutter_main();

	return 0;
}
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
 * 
 * Copyright (C) Massimo Cora' 2010 <[email protected]>
 * 
 */

#ifndef _SELECTION_SONG_H_
#define _SELECTION_SONG_H_

#include <glib-object.h>
#include <glib.h>
#include <gio/gio.h>
#include <clutter/clutter.h>


#if defined (__GNUC__) && (__GNUC__ >= 3) && !defined(__STRICT_ANSI__)
	#define DEBUG_PRINT(format, ...) g_debug ("%s:%d (%s) " format, __FILE__, __LINE__, G_STRFUNC, ##__VA_ARGS__)
#else
	#define DEBUG_PRINT g_debug
#endif

G_BEGIN_DECLS

#define SELECTION_TYPE_SONG             (selection_song_get_type ())
#define SELECTION_SONG(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), SELECTION_TYPE_SONG, SelectionSong))
#define SELECTION_SONG_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), SELECTION_TYPE_SONG, SelectionSongClass))
#define SELECTION_IS_SONG(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SELECTION_TYPE_SONG))
#define SELECTION_IS_SONG_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), SELECTION_TYPE_SONG))
#define SELECTION_SONG_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), SELECTION_TYPE_SONG, SelectionSongClass))

typedef struct _SelectionSongClass SelectionSongClass;
typedef struct _SelectionSong SelectionSong;
typedef struct _SelectionSongPriv SelectionSongPriv;

struct _SelectionSongClass
{
	ClutterActorClass parent_class;
};

struct _SelectionSong
{
	ClutterActor parent_instance;

	SelectionSongPriv *priv;
};

SelectionSong *		selection_son_new 	();

GType selection_song_get_type (void) G_GNUC_CONST;

G_END_DECLS

#endif /* _SELECTION_SONG_H_ */
 
_______________________________________________
clutter-app-devel-list mailing list
[email protected]
http://lists.clutter-project.org/listinfo/clutter-app-devel-list

Reply via email to