Ejemplo n.º 1
0
GnibblesBoard *
gnibbles_board_new (void)
{
  gchar *filename;
  const char *dirname;
  GValue val = {0,};

  GnibblesBoard *board = g_new (GnibblesBoard, 1);
  board->width = BOARDWIDTH;
  board->height = BOARDHEIGHT;
  board->level = NULL;
  board->surface = NULL;

  dirname = games_runtime_get_directory (GAMES_RUNTIME_GAME_PIXMAP_DIRECTORY);
  filename = g_build_filename (dirname, "wall-small-empty.svg", NULL);

  board->surface = clutter_texture_new_from_file (filename, NULL);

  clutter_actor_set_opacity (CLUTTER_ACTOR (board->surface), 100);
  g_value_init (&val, G_TYPE_BOOLEAN);
  g_value_set_boolean ( &val, TRUE);

  g_object_set_property (G_OBJECT (board->surface), "repeat-y", &val);
  g_object_set_property (G_OBJECT (board->surface), "repeat-x", &val);

  clutter_actor_set_position (CLUTTER_ACTOR (board->surface), 0, 0);
  clutter_actor_set_size (CLUTTER_ACTOR (board->surface),
                          properties->tilesize * BOARDWIDTH,
                          properties->tilesize * BOARDHEIGHT);
  clutter_container_add_actor (CLUTTER_CONTAINER (stage),
                               CLUTTER_ACTOR (board->surface));
  clutter_actor_show (CLUTTER_ACTOR (board->surface));

  return board;
}
Ejemplo n.º 2
0
void
gnome_app_actor_add_background (ClutterActor *actor, gchar *filename)
{
	ClutterActor *texture;
	ClutterActor *parent;
	GError *error;
	gfloat width, height;
	gfloat x, y;

	error = NULL;
	texture = clutter_texture_new_from_file (filename, &error);
	clutter_actor_set_opacity (texture, 128);
	if (error) {
		g_error ("Error in add background: %s\n", error->message);
		g_error_free (error);
		return;
	}
	clutter_actor_get_size (actor, &width, &height);
	clutter_actor_set_size (texture, width, height);
	if (CLUTTER_IS_CONTAINER (actor)) {
		clutter_container_add_actor (CLUTTER_CONTAINER (actor), texture);
		clutter_actor_set_position (texture, 0, 0);
	} else {
		parent = clutter_actor_get_parent (actor);
		clutter_container_add_actor (CLUTTER_CONTAINER (parent), texture);
		clutter_actor_get_position (actor, &x, &y);
		clutter_actor_set_position (texture, x, y);
	}
	/*This make it real background ...
	 * TODO: how about both par/child actor with background */
	clutter_actor_lower_bottom (texture);
}
Ejemplo n.º 3
0
ClutterActor *
make_source (void)
{
  ClutterActor *source, *actor;
  GError *error = NULL;
  gchar *file;

  ClutterColor  yellow = {0xff, 0xff, 0x00, 0xff};

  source  = clutter_group_new ();

  file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL);
  actor = clutter_texture_new_from_file (file, &error);
  if (!actor)
    g_error("pixbuf load failed: %s", error ? error->message : "Unknown");

  g_free (file);

  clutter_group_add (source, actor);

  actor = clutter_text_new_with_text ("Sans Bold 50px", "Clutter");

  clutter_text_set_color (CLUTTER_TEXT (actor), &yellow);
  clutter_actor_set_y (actor, clutter_actor_get_height(source) + 5);
  clutter_group_add (source, actor);

  return source;
}
Ejemplo n.º 4
0
ClutterActor *
mex_telepathy_channel_create_static_image (void)
{
  ClutterActor *actor;

  gchar *static_image_path;
  GError *error = NULL;

  static_image_path = g_build_filename (mex_get_data_dir (),
                                        "style",
                                        "thumb-call-pip-off.png",
                                        NULL);

  actor = clutter_texture_new_from_file (static_image_path,
                    &error);
  if (error)
  {
    g_warning ("Error loading texture %s", error->message);
    g_clear_error (&error);
  }

  if (static_image_path)
    g_free (static_image_path);

  clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE
                                         (actor), TRUE);

  return actor;
}
Ejemplo n.º 5
0
//
// redraw stack
//
void redraw_stack()
{
	if (stage == NULL) {
		fprintf(stderr, "stage cannot be drawn upon\n");
		return;
	}
	
	// clear stage
	ClutterColor stage_bg_color;
	clutter_color_parse("#fff", &stage_bg_color);
  clutter_stage_set_color(CLUTTER_STAGE(stage), &stage_bg_color);
  
  int width=256, /*height=256, */padding=5;
  
  // loop through all windows and draw an item on the grid
  WindowStack *sitem = stack;
  int i=0;
  while (sitem != NULL) {
  	printf( "drawing stack item %d\n", (i+1) );
  	int x = (i*width) + ( (i+1)*padding );
  	int y = padding;
  	ClutterActor *actor = clutter_texture_new_from_file("/home/Downloads/window.png", NULL);
  	clutter_container_add(CLUTTER_CONTAINER(stage), actor, NULL);
	  clutter_actor_set_position(actor, x, y);
	  sitem = sitem->next;
	  i++;
  }
  
  clutter_actor_show(CLUTTER_ACTOR(stage));  
  clutter_color_free(&stage_bg_color);
}
Ejemplo n.º 6
0
static void
manager_device_added_cb (ClutterDeviceManager *manager,
                         ClutterInputDevice   *device,
                         TestDevicesApp       *app)
{
  ClutterInputDeviceType device_type;
  ClutterActor *hand = NULL;

  g_print ("got a %s device '%s' with id %d\n",
           device_type_name (device),
           clutter_input_device_get_device_name (device),
           clutter_input_device_get_device_id (device));

  device_type = clutter_input_device_get_device_type (device);
  if (device_type == CLUTTER_POINTER_DEVICE ||
      device_type == CLUTTER_PEN_DEVICE ||
      device_type == CLUTTER_POINTER_DEVICE)
    {
      g_print ("*** enabling device '%s' ***\n",
               clutter_input_device_get_device_name (device));

      clutter_input_device_set_enabled (device, TRUE);

      hand = clutter_texture_new_from_file (TESTS_DATADIR
                                            G_DIR_SEPARATOR_S
                                            "redhand.png",
                                            NULL);
      g_hash_table_insert (app->devices, device, hand);

      clutter_container_add_actor (CLUTTER_CONTAINER (app->stage), hand);
    }
}
Ejemplo n.º 7
0
static void
penge_grid_view_init (PengeGridView *self)
{
  PengeGridViewPrivate *priv = GET_PRIVATE_REAL (self);

  self->priv = priv;



  priv->everything_pane = g_object_new (PENGE_TYPE_EVERYTHING_PANE,
                                        NULL);

  mx_table_add_actor (MX_TABLE (self), priv->everything_pane, 0, 0);

  mx_table_set_row_spacing (MX_TABLE (self), 6);
  mx_table_set_column_spacing (MX_TABLE (self), 6);

  /* 
   * Create a background and parent it to the grid. We paint and allocate this
   * in the overridden vfuncs
   */
  priv->background = g_object_new (PENGE_TYPE_VIEW_BACKGROUND, NULL);
  clutter_actor_set_parent (priv->background, (ClutterActor *)self);
  clutter_actor_show (priv->background);

  priv->background_fade = clutter_texture_new_from_file (FADE_BG,
                                                         NULL);
  clutter_actor_set_parent (priv->background_fade, (ClutterActor *)self);
  clutter_actor_show (priv->background_fade);

  priv->gconf_client = gconf_client_get_default ();

 _update_layout (self);
}
Ejemplo n.º 8
0
G_MODULE_EXPORT int
test_viewport_main (int argc, char *argv[])
{
  ClutterTimeline  *timeline;
  ClutterAlpha     *alpha;
  ClutterBehaviour *r_behave;
  ClutterActor     *stage;
  ClutterActor     *hand;
  ClutterColor      stage_color = { 0xcc, 0xcc, 0xcc, 0xff };
  gchar            *file;

  clutter_init (&argc, &argv);

  stage = clutter_stage_get_default ();

  clutter_stage_set_color (CLUTTER_STAGE (stage),
		           &stage_color);

  /* Make a hand */
  file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL);
  hand = clutter_texture_new_from_file (file, NULL);
  if (!hand)
    g_error("Unable to load image '%s'", file);

  g_free (file);

  clutter_actor_set_position (hand, 300, 200);
  clutter_actor_set_clip (hand, 20, 21, 132, 170);
  clutter_actor_set_anchor_point (hand, 86, 125);
  clutter_actor_show (hand);
  clutter_container_add_actor (CLUTTER_CONTAINER (stage), hand);

  /* Make a timeline */
  timeline = clutter_timeline_new (7692);
  clutter_timeline_set_loop (timeline, TRUE);

  /* Set an alpha func to power behaviour */
  alpha = clutter_alpha_new_full (timeline, CLUTTER_LINEAR);

  /* Create a behaviour for that alpha */
  r_behave = clutter_behaviour_rotate_new (alpha,
					   CLUTTER_Z_AXIS,
					   CLUTTER_ROTATE_CW,
					   0.0, 360.0); 

  /* Apply it to our actor */
  clutter_behaviour_apply (r_behave, hand);

  /* start the timeline and thus the animations */
  clutter_timeline_start (timeline);

  clutter_actor_show_all (stage);

  clutter_main();

  g_object_unref (r_behave);

  return 0;
}
Ejemplo n.º 9
0
int
main (int argc, char **argv)
{
  ClutterActor *stage, *image, *sub_image;
  CoglHandle texture, sub_texture;
  gfloat image_width, image_height;

  /* Initialize Clutter */
  if (clutter_init (NULL, NULL) != CLUTTER_INIT_SUCCESS)
    return 1;

  /* Get the default stage */
  stage = clutter_stage_get_default ();
  clutter_stage_set_title (CLUTTER_STAGE (stage), "Sub-texture");

  /* Create a new ClutterTexture that shows smiley.png */
  image = clutter_texture_new_from_file ("smiley.png", NULL);
  clutter_actor_get_size (image, &image_width, &image_height);
  clutter_actor_set_size (stage,
                          image_width * 3 / 2 + 30,
                          image_height + 20);

  /* Grab the CoglHandle of the underlying Cogl texture */
  texture = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (image));

  /* Create a new Cogl texture from the handle above. That new texture is a
   * rectangular region from image, more precisely the north ouest corner
   * of the image */
  sub_texture = cogl_texture_new_from_sub_texture (texture,
                                                   0, 0,
                                                   image_width / 2,
                                                   image_height / 2);

  /* Finally, use the newly created Cogl texture to feed a new ClutterTexture
   * and thus create a new actor that displays sub_texture */
   sub_image = clutter_texture_new ();
   clutter_texture_set_cogl_texture (CLUTTER_TEXTURE (sub_image), sub_texture);

  /*
   * You could have used the more straightforward g_object_new() function that
   * can create an object and set some properties on it at the same time:
   * sub_image = g_object_new (CLUTTER_TYPE_TEXTURE,
   *                           "cogl-texture", sub_texture,
   *                           NULL);
   */

  /* Put the original image at (10,10) and the new sub image next to it */
  clutter_actor_set_position (image, 10, 10);
  clutter_actor_set_position (sub_image, 20 + image_width, 10);

  /* Add both ClutterTexture to the stage */
  clutter_container_add (CLUTTER_CONTAINER (stage), image, sub_image, NULL);

  clutter_actor_show_all (stage);

  clutter_main ();

  return 0;
}
Ejemplo n.º 10
0
G_MODULE_EXPORT gint
test_texture_quality_main (int argc, char *argv[])
{
  ClutterTimeline  *timeline;
  ClutterAlpha     *alpha;
  ClutterBehaviour *depth_behavior;
  ClutterActor     *stage;
  ClutterActor     *image;
  ClutterColor      stage_color = { 0x12, 0x34, 0x56, 0xff };
  ClutterFog        stage_fog = { 10.0, -50.0 };
  GError           *error;

  clutter_init (&argc, &argv);

  stage = clutter_stage_get_default ();
  clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
  clutter_stage_set_use_fog (CLUTTER_STAGE (stage), TRUE);
  clutter_stage_set_fog (CLUTTER_STAGE (stage), &stage_fog);

  g_signal_connect (stage,
                    "button-press-event", G_CALLBACK (clutter_main_quit),
                    NULL);

  error = NULL;
  image = clutter_texture_new_from_file (argv[1]?argv[1]:"redhand.png", &error);
  if (error)
    g_error ("Unable to load image: %s", error->message);

  if (!argv[1])
    g_print ("Hint: the redhand.png isn't a good test image for this test.\n"
             "This test can take any clutter loadable image as an argument\n");

  /* center the image */
  clutter_actor_set_position (image, 
    (clutter_actor_get_width (stage) - clutter_actor_get_width (image))/2,
    (clutter_actor_get_height (stage) - clutter_actor_get_height (image))/2);
  clutter_container_add (CLUTTER_CONTAINER (stage), image, NULL);

  timeline = clutter_timeline_new (5000);
  g_signal_connect (timeline,
                    "completed", G_CALLBACK (timeline_completed),
                    NULL);

  alpha = clutter_alpha_new_full (timeline, CLUTTER_LINEAR);
  depth_behavior = clutter_behaviour_depth_new (alpha, -2500, 400);
  clutter_behaviour_apply (depth_behavior, image);

  clutter_actor_show (stage);
  clutter_timeline_start (timeline);

  g_timeout_add (10000, change_filter, image);

  clutter_main ();

  g_object_unref (depth_behavior);
  g_object_unref (timeline);

  return EXIT_SUCCESS;
}
Ejemplo n.º 11
0
int main(int argc,char *argv[])
{

  ClutterColor stage_color = { 0x00, 0x00, 0x00, 0xff };
  ClutterColor actor_color = { 0xff,0xff,0xff,0x98};

  /** 初始化clutter */
  clutter_init(&argc, &argv);

  /** 获取默认的场景stage */
  ClutterActor *stage = clutter_stage_get_default();
  /** 设置场景大小,注意场景也actor的一种,所以可以使用actor的api设置*/
  clutter_actor_set_size(stage,400,400);
  /** 设置场景背景*/
  clutter_stage_set_color(CLUTTER_STAGE(stage), &stage_color);



  /** 载入一个图像的actor */
  //ClutterActor * image = clutter_texture_new_from_file("demo.png",NULL);
  image = clutter_texture_new_from_file("demo.png",NULL);
  if(!image){
	  printf("load image error\n");
	  exit(-1);
  }

  /** 设置actor在场景中的位置*/
  clutter_actor_set_position(image, 100,100);
  /** 缩放图像,这里设置长宽各放大了两倍*/
  clutter_actor_set_scale(image,2.0,2.0);

  /** 设置图像旋转,以y轴旋转,角度20'c */
  clutter_actor_set_rotation(image, CLUTTER_Y_AXIS, 120,0,0,0);
  /** 把actor加入场景中*/
  clutter_container_add_actor(CLUTTER_CONTAINER(stage),image);
  clutter_actor_show(image);


  /** 打开actor的事件响应*/
  clutter_actor_set_reactive(image,TRUE);

  /** 连接actor的某事件*/
  g_signal_connect(image, "button-press-event", G_CALLBACK(on_image_button_press),NULL);

  /** 加入时间线*/
  //ClutterTimeline* timeline = clutter_timeline_new(5000);
  timeline = clutter_timeline_new(5000);
  g_signal_connect(timeline, "new-frame",G_CALLBACK(on_timeline_new_frame),NULL);
  clutter_timeline_set_loop(timeline,TRUE);
  //clutter_timeline_start(timeline);

  clutter_actor_show(stage);

  clutter_main();
  
  g_object_unref(timeline);
	printf("\n");
	return 0;
}
Ejemplo n.º 12
0
/* Setup various status icons */
static void init_icons(ClutterActor *stage)
{
	ClutterActor *rs_img;
	ClutterActor *ra_img;
	ClutterActor *shuffle_img;
	ClutterActor *play_img;
	ClutterActor *pause_img;

	rs_img = clutter_texture_new_from_file("icons/repeat-single.png", NULL);
	clutter_actor_set_name(rs_img, "rs_img");
	clutter_actor_set_size(rs_img, 20, 20);
	clutter_actor_set_position(rs_img, 430, 102);
	if (!mozart_get_repeat_single())
		clutter_actor_hide(rs_img);
	clutter_container_add_actor(CLUTTER_CONTAINER(stage), rs_img);

	ra_img = clutter_texture_new_from_file("icons/repeat-all.png", NULL);
	clutter_actor_set_name(ra_img, "ra_img");
	clutter_actor_set_size(ra_img, 20, 20);
	clutter_actor_set_position(ra_img, 430, 102);
	if (!mozart_get_repeat_all())
		clutter_actor_hide(ra_img);
	clutter_container_add_actor(CLUTTER_CONTAINER(stage), ra_img);

	shuffle_img = clutter_texture_new_from_file("icons/shuffle.png", NULL);
	clutter_actor_set_name(shuffle_img, "shuffle_img");
	clutter_actor_set_size(shuffle_img, 20, 20);
	clutter_actor_set_position(shuffle_img, 460, 102);
	if (!mozart_playlist_shuffled(NULL))
		clutter_actor_hide(shuffle_img);
	clutter_container_add_actor(CLUTTER_CONTAINER(stage), shuffle_img);

	play_img = clutter_texture_new_from_file("icons/playing.png", NULL);
	clutter_actor_set_name(play_img, "play_img");
	clutter_actor_set_size(play_img, 20, 20);
	clutter_actor_set_position(play_img, 400, 102);
	clutter_actor_hide(play_img);
	clutter_container_add_actor(CLUTTER_CONTAINER(stage), play_img);

	pause_img = clutter_texture_new_from_file("icons/paused.png", NULL);
	clutter_actor_set_name(pause_img, "pause_img");
	clutter_actor_set_size(pause_img, 20, 20);
	clutter_actor_set_position(pause_img, 400, 102);
	clutter_actor_hide(pause_img);
	clutter_container_add_actor(CLUTTER_CONTAINER(stage), pause_img);
}
Ejemplo n.º 13
0
static
gboolean
action_add_image (ClutterActor *action,
                  ClutterEvent *event,
                  gpointer      userdata)
{
  ClutterActor *group = CLUTTER_ACTOR (userdata);
  ClutterActor *actor;

  actor = clutter_texture_new_from_file (ASSETS_DIR "redhand.png", NULL);
  clutter_actor_set_position (actor, event->button.x, event->button.y);
  clutter_group_add (CLUTTER_GROUP (group), actor);
  return FALSE;
}
Ejemplo n.º 14
0
ClutterActor *
add_hand (ClutterActor *group,
          gint          x,
          gint          y)
{
  ClutterActor     *actor;

  actor = clutter_texture_new_from_file (ASSETS_DIR "redhand.png", NULL);
  clutter_group_add (CLUTTER_GROUP (group), actor);

  clutter_actor_set_opacity (actor, 1.0 * 255);
  clutter_actor_set_position (actor, x, y);

  clutter_container_child_set (CLUTTER_CONTAINER (group), actor,
                               "manipulatable", TRUE,
                               "mode", CLUTTER_BOX2D_DYNAMIC, NULL);
  return actor;
}
Ejemplo n.º 15
0
static ClutterActor *new_rect (gint r,
                               gint g,
                               gint b,
                               gint a)
{
  GError *error = NULL;
  ClutterColor *color = clutter_color_new (r, g, b, a);
  ClutterActor *rectangle = clutter_rectangle_new_with_color (color);

  gchar *file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL);
  rectangle = clutter_texture_new_from_file (file, &error);
  if (rectangle == NULL)
    g_error ("image load failed: %s", error->message);
  g_free (file);

  clutter_actor_set_size (rectangle, 128, 128);
  clutter_color_free (color);
  return rectangle;
}
Ejemplo n.º 16
0
void
gmc_button_set_icon (GmcButton *self, const gchar *filename)
{
  GmcButtonPrivate *priv;
  ClutterActor *icon;
  GError *error = NULL;

  priv = GMC_BUTTON_GET_PRIVATE (self);

  icon = clutter_texture_new_from_file (filename, &error);
  if (!icon) {
    g_critical ("%s - %s [%s] %s", G_STRFUNC, error->message, filename, clutter_text_get_text (CLUTTER_TEXT (priv->label)));
    return;
  }

  if (priv->icon) {
    g_object_unref (priv->icon);
  }

  priv->icon = icon;
  clutter_actor_set_size (priv->icon, 24, 24);
  clutter_actor_set_parent (priv->icon, CLUTTER_ACTOR (self));
}
Ejemplo n.º 17
0
static ClutterActor *new_rect (gint r,
                               gint g,
                               gint b,
                               gint a)
{
  GError *error = NULL;
  ClutterColor *color = clutter_color_new (r, g, b, a);
  ClutterActor *group = clutter_group_new ();
  ClutterActor *rectangle = clutter_rectangle_new_with_color (color);
  ClutterActor *hand = NULL;

  gchar *file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL);

  hand = clutter_texture_new_from_file (file, &error);
  if (rectangle == NULL)
    g_error ("image load failed: %s", error->message);
  g_free (file);
  clutter_actor_set_size (hand, ACTOR_WIDTH,ACTOR_HEIGHT);

  clutter_actor_set_size (rectangle, ACTOR_WIDTH,ACTOR_HEIGHT);
  clutter_color_free (color);
  clutter_container_add (CLUTTER_CONTAINER (group), rectangle, hand, NULL);
  return group;
}
Ejemplo n.º 18
0
static void
set_clear_button_size (ClutterActor *clear_button)
{

  /* TODO quick fix for MX port. */
  clutter_actor_set_size (clear_button, 22, 21);

#if 0
  GValue background_image = { 0, };

  g_value_init (&background_image, G_TYPE_STRING);
  mx_stylable_get_property (MX_STYLABLE (clear_button),
                              "background-image", &background_image);
  if (g_value_get_string (&background_image))
    {
      GError        *error = NULL;
      ClutterActor  *background_texture = clutter_texture_new_from_file (
                                            g_value_get_string (&background_image),
                                            &error);
      if (error)
        {
          g_warning ("%s", error->message);
          g_error_free (error);
        }
      else
        {
          gint width, height;
          clutter_texture_get_base_size (CLUTTER_TEXTURE (background_texture),
                                         &width, &height);
          clutter_actor_set_size (clear_button, width, height);
          g_object_unref (background_texture);
        }
      g_value_unset (&background_image);
    }
#endif
}
Ejemplo n.º 19
0
G_MODULE_EXPORT int
test_bin_layout_main (int argc, char *argv[])
{
  ClutterActor *stage, *box, *rect;
  ClutterLayoutManager *layout;
  ClutterColor stage_color = { 0xe0, 0xf2, 0xfc, 0xff };
  ClutterColor bg_color = { 0xcc, 0xcc, 0xcc, 0x99 };
  ClutterColor *color;

  clutter_init (&argc, &argv);

  stage = clutter_stage_get_default ();
  clutter_stage_set_title (CLUTTER_STAGE (stage), "Box test");
  clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
  clutter_actor_set_size (stage, 640, 480);

  layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
                                   CLUTTER_BIN_ALIGNMENT_CENTER);

  box = clutter_box_new (layout);
  clutter_container_add_actor (CLUTTER_CONTAINER (stage), box);
  clutter_actor_set_anchor_point_from_gravity (box, CLUTTER_GRAVITY_CENTER);
  clutter_actor_set_position (box, 320, 240);
  clutter_actor_set_reactive (box, TRUE);
  clutter_actor_set_name (box, "box");

  rect = make_background (&bg_color, 200, 200);

  /* first method: use clutter_box_pack() */
  clutter_box_pack (CLUTTER_BOX (box), rect,
                    "x-align", CLUTTER_BIN_ALIGNMENT_FILL,
                    "y-align", CLUTTER_BIN_ALIGNMENT_FILL,
                    NULL);

  clutter_actor_lower_bottom (rect);
  clutter_actor_set_name (rect, "background");

  {
    ClutterActor *tex;
    GError *error;
    gchar *file;

    error = NULL;
    file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL);
    tex = clutter_texture_new_from_file (file, &error);
    if (error)
      g_error ("Unable to create texture: %s", error->message);

    clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (tex), TRUE);

    /* second method: use clutter_bin_layout_add() */
    clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout), tex,
                            CLUTTER_BIN_ALIGNMENT_CENTER,
                            CLUTTER_BIN_ALIGNMENT_CENTER);

    clutter_actor_raise (tex, rect);
    clutter_actor_set_width (tex, 175);
    clutter_actor_set_name (tex, "texture");

    g_free (file);
  }

  color = clutter_color_new (g_random_int_range (0, 255),
                             g_random_int_range (0, 255),
                             g_random_int_range (0, 255),
                             224);

  rect = clutter_rectangle_new_with_color (color);

  /* third method: container_add() and set_alignment() */
  clutter_container_add_actor (CLUTTER_CONTAINER (box), rect);
  clutter_bin_layout_set_alignment (CLUTTER_BIN_LAYOUT (layout), rect,
                                    CLUTTER_BIN_ALIGNMENT_END,
                                    CLUTTER_BIN_ALIGNMENT_END);

  clutter_actor_set_size (rect, 50, 50);
  clutter_actor_set_opacity (rect, 0);
  clutter_actor_raise_top (rect);
  clutter_actor_set_name (rect, "emblem");


  g_signal_connect (box,
                    "enter-event", G_CALLBACK (on_box_enter),
                    rect);
  g_signal_connect (box,
                    "leave-event", G_CALLBACK (on_box_leave),
                    rect);

  clutter_actor_show_all (stage);

  clutter_main ();

  clutter_color_free (color);

  return EXIT_SUCCESS;
}
Ejemplo n.º 20
0
int main(int argc,char *argv[])
{

  ClutterColor stage_color = { 0x00, 0x00, 0x00, 0xff };

  clutter_init(&argc, &argv);

  ClutterActor *stage = clutter_stage_get_default ();
  clutter_actor_set_size (stage, 521, 577);
  clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);

  //ClutterActor * _group = clutter_group_new();
   _group = clutter_group_new();
  clutter_actor_set_position(_group, 0,0);
  clutter_container_add_actor(CLUTTER_CONTAINER(stage),_group);
  clutter_actor_show(_group);

  /** 加载棋盘图片*/
  ClutterActor* _board = clutter_texture_new_from_file("./wood/wood.png",NULL);

  clutter_actor_set_position(_board,0,0);
  //clutter_actor_set_rotation(_board, CLUTTER_Y_AXIS, 20,0,0,0);
  //clutter_actor_set_rotation(_board, CLUTTER_X_AXIS, 20,0,0,0);
  //clutter_actor_set_rotation(_board, CLUTTER_Z_AXIS, 20,0,0,0);


  //clutter_container_add_actor(CLUTTER_CONTAINER(stage),_board);
  clutter_container_add_actor(CLUTTER_CONTAINER(_group),_board);
  clutter_actor_show(_board);



#if 0
  load_chess();
#else 
  /** 加载棋子*/
  ClutterActor* _rking = clutter_texture_new_from_file("./wood/red_king.png",NULL);
  clutter_actor_set_position(_rking,235,8);
  clutter_container_add_actor(CLUTTER_CONTAINER(_group),_rking);
  clutter_actor_show(_rking);

  clutter_actor_set_reactive(_rking,TRUE);
  g_signal_connect(_rking, "button-press-event",G_CALLBACK(on_rking_button_press),NULL);

  timeline=clutter_timeline_new(3000);
  //g_signal_connect(timeline,"new-frame",G_CALLBACK(on_timeline_new_frame),_rking);
  clutter_timeline_set_loop(timeline,TRUE);

  ClutterAlpha* alpha_ = clutter_alpha_new_full(timeline,
         CLUTTER_EASE_IN_OUT_QUAD);//CLUTTER_EASE_IN_SINE);

  ClutterBehaviour* behaviour_ = clutter_behaviour_rotate_new(alpha_, 
		  CLUTTER_Y_AXIS,
		CLUTTER_ROTATE_CW,
		0,
		360);
  clutter_behaviour_rotate_set_center(CLUTTER_BEHAVIOUR_ROTATE(behaviour_), clutter_actor_get_width(_rking)/2,0,0);
  clutter_behaviour_apply(behaviour_, _rking);

  clutter_actor_set_rotation(_group, CLUTTER_X_AXIS, 40,2,600,0);
  //clutter_actor_set_rotation(_group, CLUTTER_Y_AXIS, 40,221,200,0);


#endif

  clutter_actor_show(stage);
  clutter_main();

  g_object_unref(timeline);

	printf("\n");
	return 0;
}
Ejemplo n.º 21
0
int main(int argc, char *argv[])
{
  ClutterColor stage_color = { 0x61, 0x64, 0x8c, 0xff };

  /* Call gtk_clutter_init() to init both clutter and gtk+ */
  if (gtk_clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
    g_error ("Unable to initialize GtkClutter");

  if (argc != 2)
    g_error ("Usage: example <image file>");
  
  /* Create a toplevel window: */
  GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_default_size (GTK_WINDOW (window), 640, 480);
  g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);

  /* Create a table to hold the scrollbars and the ClutterEmbed widget: */
  GtkWidget *table = gtk_table_new (2, 2, FALSE);
  gtk_container_add (GTK_CONTAINER (window), table);
  gtk_widget_show (table);

  /* Create ClutterEmbed widget for the stage: */
  GtkWidget *embed = gtk_clutter_embed_new ();
  gtk_table_attach (GTK_TABLE (table), embed,
    0, 1,
    0, 1,
    GTK_EXPAND | GTK_FILL,
    GTK_EXPAND | GTK_FILL,
    0, 0);
  gtk_widget_show (embed);

  /* Init the stage: */
  ClutterActor *stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (embed));
  clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
  clutter_actor_set_size (stage, 640, 480);

  /* Create a viewport actor to be able to scroll actor. By passing NULL it
   * will create new GtkAdjustments. */
  ClutterActor *viewport = gtk_clutter_viewport_new (NULL, NULL, NULL);
  clutter_container_add_actor (CLUTTER_CONTAINER (stage), viewport);

  /* Load image from first command line argument and add it to viewport: */
  ClutterActor *texture = clutter_texture_new_from_file (argv[1], NULL);
  clutter_container_add_actor (CLUTTER_CONTAINER (viewport), texture);
  clutter_actor_set_position (texture, 0, 0);
  clutter_actor_set_position (texture, 0, 0);
  clutter_actor_set_position (viewport, 0, 0);
  clutter_actor_set_size (viewport, 640, 480);

  /* Create scrollbars and connect them to viewport: */
  GtkAdjustment *h_adjustment = NULL;
  GtkAdjustment *v_adjustment = NULL;
  gtk_clutter_scrollable_get_adjustments (GTK_CLUTTER_SCROLLABLE (viewport),
    &h_adjustment, &v_adjustment);
  GtkWidget *scrollbar = gtk_vscrollbar_new (v_adjustment);
  gtk_table_attach (GTK_TABLE (table), scrollbar,
    1, 2,
    0, 1,
    0, GTK_EXPAND | GTK_FILL,
    0, 0);
  gtk_widget_show (scrollbar);
  
  scrollbar = gtk_hscrollbar_new (h_adjustment);
  gtk_table_attach (GTK_TABLE (table), scrollbar,
    0, 1,
    1, 2,
    GTK_EXPAND | GTK_FILL, 0,
    0, 0);

  gtk_widget_show (scrollbar);
  gtk_widget_show (window);

  gtk_main();

	return EXIT_SUCCESS;
}
Ejemplo n.º 22
0
static void
on_monitors_changed (MetaScreen *screen,
                     MetaPlugin *plugin)
{
  MetaDefaultPlugin *self = META_DEFAULT_PLUGIN (plugin);
  __attribute__ ((unused)) ClutterAnimation *animation;
  int i, n;
  gchar *wallpaper = NULL;
  GFile *wallpaper_file = NULL;
  gchar *filename = NULL;
  gboolean random_colour = FALSE;

  clutter_actor_destroy_all_children (self->priv->background_group);

  wallpaper = g_settings_get_string(self->priv->settings, PICTURE_KEY);
  if (!wallpaper)
      random_colour = TRUE;
  else {
      wallpaper_file = g_file_new_for_uri(wallpaper);
      filename = g_file_get_path(wallpaper_file);
  }
      

  n = meta_screen_get_n_monitors (screen);
  for (i = 0; i < n; i++)
    {
      MetaRectangle rect;
      ClutterActor *background;
      ClutterColor color;

      meta_screen_get_monitor_geometry (screen, i, &rect);

      /* Don't use rand() here, mesa calls srand() internally when
         parsing the driconf XML, but it's nice if the colors are
         reproducible.
      */
      if (random_colour) {
            background = meta_background_actor_new ();
            clutter_color_init (&color,
                          g_random_int () % 255,
                          g_random_int () % 255,
                          g_random_int () % 255,
                          255);
            clutter_actor_set_background_color (background, &color);
      } else {
            /* Set the background */
            background = clutter_texture_new_from_file(filename, NULL);
      }

      clutter_actor_set_position (background, rect.x, rect.y);
      clutter_actor_set_size (background, rect.width, rect.height);
      clutter_actor_add_child (self->priv->background_group, background);
      clutter_actor_set_scale (background, 0.0, 0.0);
      clutter_actor_show (background);
      clutter_actor_move_anchor_point_from_gravity (background,
                                                    CLUTTER_GRAVITY_CENTER);
      /* Ease in the background using a scale effect */
      animation = clutter_actor_animate (background, CLUTTER_EASE_IN_SINE,
                                         BACKGROUND_TIMEOUT,
                                         "scale-x", 1.0,
                                         "scale-y", 1.0,
                                         NULL);
    }
    if (wallpaper_file)
      g_object_unref(wallpaper_file);
    g_free(wallpaper);
    g_free(filename);
}
Ejemplo n.º 23
0
G_MODULE_EXPORT int
test_paint_wrapper_main (int argc, char *argv[])
{
    ClutterAlpha *alpha;
    ClutterActor *stage;
    ClutterColor  stage_color = { 0x61, 0x64, 0x8c, 0xff };
    SuperOH      *oh;
    gint          i;
    GError       *error;
    ClutterActor *real_hand;

    error = NULL;

#ifdef HAVE_CLUTTER_GLX
    clutter_x11_set_use_argb_visual (TRUE);
#endif

    clutter_init_with_args (&argc, &argv,
                            NULL,
                            super_oh_entries,
                            NULL,
                            &error);
    if (error)
    {
        g_warning ("Unable to initialise Clutter:\n%s",
                   error->message);
        g_error_free (error);

        return EXIT_FAILURE;
    }

    stage = clutter_stage_get_default ();
    clutter_actor_set_size (stage, 800, 600);

    if (use_alpha != 255)
    {
        clutter_stage_set_use_alpha (CLUTTER_STAGE (stage), TRUE);
        clutter_actor_set_opacity (stage, use_alpha);
    }

    clutter_stage_set_title (CLUTTER_STAGE (stage), "Paint Test");
    clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);

    oh = g_new(SuperOH, 1);
    oh->stage = stage;

    /* Create a timeline to manage animation */
    oh->timeline = clutter_timeline_new (6000);
    clutter_timeline_set_loop (oh->timeline, TRUE);

    /* fire a callback for frame change */
    g_signal_connect (oh->timeline, "new-frame", G_CALLBACK (frame_cb), oh);

    /* Set up some behaviours to handle scaling  */
    alpha = clutter_alpha_new_with_func (oh->timeline, my_sine_wave, NULL, NULL);

    oh->scaler_1 = clutter_behaviour_scale_new (alpha, 0.5, 0.5, 1.0, 1.0);
    oh->scaler_2 = clutter_behaviour_scale_new (alpha, 1.0, 1.0, 0.5, 0.5);

    real_hand = clutter_texture_new_from_file (TESTS_DATADIR
                G_DIR_SEPARATOR_S
                "redhand.png",
                &error);
    if (real_hand == NULL)
    {
        g_error ("image load failed: %s", error->message);
        return EXIT_FAILURE;
    }

    /* create a new group to hold multiple actors in a group */
    oh->group = clutter_group_new();

    oh->hand = g_new (ClutterActor*, n_hands);

    oh->stage_width = clutter_actor_get_width (stage);
    oh->stage_height = clutter_actor_get_height (stage);
    oh->radius = (oh->stage_width + oh->stage_height)
                 / n_hands;

    for (i = 0; i < n_hands; i++)
    {
        gint x, y, w, h;

        if (i == 0)
            oh->hand[i] = real_hand;
        else
            oh->hand[i] = clutter_clone_new (real_hand);

        clutter_actor_set_reactive (oh->hand[i], TRUE);

        clutter_actor_set_size (oh->hand[i], 200, 213);

        /* Place around a circle */
        w = clutter_actor_get_width (oh->hand[i]);
        h = clutter_actor_get_height (oh->hand[i]);

        x = oh->stage_width / 2
            + oh->radius
            * cos (i * G_PI / (n_hands / 2))
            - w / 2;

        y = oh->stage_height / 2
            + oh->radius
            * sin (i * G_PI / (n_hands / 2))
            - h / 2;

        clutter_actor_set_position (oh->hand[i], x, y);

        clutter_actor_move_anchor_point_from_gravity (oh->hand[i],
                CLUTTER_GRAVITY_CENTER);

        g_signal_connect (oh->hand[i], "button-press-event",
                          G_CALLBACK (on_button_press_event),
                          oh);

        /* paint something before each hand */
        g_signal_connect (oh->hand[i],
                          "paint", G_CALLBACK (hand_pre_paint),
                          oh);

        /* paint something after each hand */
        g_signal_connect_after (oh->hand[i],
                                "paint", G_CALLBACK (hand_post_paint),
                                oh);

        /* Add to our group group */
        clutter_container_add_actor (CLUTTER_CONTAINER (oh->group), oh->hand[i]);

        if (i % 2)
            clutter_behaviour_apply (oh->scaler_1, oh->hand[i]);
        else
            clutter_behaviour_apply (oh->scaler_2, oh->hand[i]);
    }

    oh->paint_guards = g_malloc0 (sizeof (gboolean) * n_hands);

    /* Add the group to the stage */
    clutter_container_add_actor (CLUTTER_CONTAINER (stage),
                                 CLUTTER_ACTOR (oh->group));

    /* Show everying ( and map window ) */
    clutter_actor_show (stage);

    g_signal_connect (stage, "key-release-event",
                      G_CALLBACK (input_cb),
                      oh);

    /* and start it */
    clutter_timeline_start (oh->timeline);

    clutter_main ();

    g_object_unref (oh->scaler_1);
    g_object_unref (oh->scaler_2);
    g_object_unref (oh->timeline);
    g_free (oh->paint_guards);
    g_free (oh->hand);
    g_free (oh);

    return 0;
}
Ejemplo n.º 24
0
int
main (int argc, char *argv[])
{
  ClutterActor    *stage;
  ClutterColor     stage_color = { 0x34, 0x39, 0x39, 0xff };
  ClutterColor     white = { 0x72, 0x9f, 0xcf, 0xff };
  gint             i = 0;
  Item            *item;
  App             *app;
  gdouble          ang = 0.0;
  ClutterBehaviour *behave;

  clutter_init (&argc, &argv);

  stage = clutter_stage_get_default ();

  clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
  clutter_actor_set_size (stage, 800, 600);

  app = g_new0(App, 1);
  app->off = 0.0;
  app->timeline = clutter_timeline_new (300);
  app->alpha_sine_inc
    = clutter_alpha_new_full (app->timeline, CLUTTER_EASE_OUT_SINE);

  app->alpha_ramp
    = clutter_alpha_new_with_func (app->timeline, label_opacity_alpha_func,
                                   NULL, NULL);

  for (i=0; i<N_ITEMS; i++)
    {
      item = g_new0 (Item, 1);

      item->actor = clutter_texture_new_from_file (ItemDetails[i].img, NULL);
      if (!item->actor)
	g_error ("Unable to load '%s'", ItemDetails[i].img);

      clutter_group_add (CLUTTER_GROUP(stage), item->actor);

      item->ellipse_behave
	= clutter_behaviour_ellipse_new (app->alpha_sine_inc,
					 CSW()/4,   /* center x */
					 CSH() - (CSH()/3),   /* center y */
					 CSW()/2,   /* width */
					 CSH() - (CSH()/4),   /* height */
					 CLUTTER_ROTATE_CW,
					 ang,
					 ang + STEP);
      item->opacity_behave
	= clutter_behaviour_opacity_new (app->alpha_sine_inc, 0x66, 0x66);

      item->scale_behave
	= clutter_behaviour_scale_new (app->alpha_sine_inc,
				       0.6, 0.6, 0.6, 0.6);

      clutter_behaviour_apply (item->ellipse_behave, item->actor);
      clutter_behaviour_apply (item->opacity_behave, item->actor);
      clutter_behaviour_apply (item->scale_behave, item->actor);

      app->items = g_slist_append (app->items, item);

      ang += STEP;
    }

  app->label = clutter_text_new_full ("Bitstream Vera Sans 60px", "", &white);
  clutter_actor_set_position (app->label, CSW()/2 - 30, CSH()/3 - 40);
  clutter_group_add (CLUTTER_GROUP(stage), app->label);

  behave = clutter_behaviour_opacity_new (app->alpha_ramp, 0xff, 0);
  clutter_behaviour_apply (behave, app->label);

  g_signal_connect (app->timeline,
		    "new-frame",
		    G_CALLBACK(on_timeline_new_frame),
		    app);

  g_signal_connect (stage,
		    "event",
		    G_CALLBACK (on_input),
		    app);

  introduce_items (app);

  clutter_actor_show_all (stage);

  clutter_main();

  return 0;
}
Ejemplo n.º 25
0
void load_chess()
{
#if 1
   chessman_images[0]= clutter_texture_new_from_file(IMGAGE_DIR"red_king.png",NULL);
  clutter_container_add_actor(CLUTTER_CONTAINER(_group),chessman_images[0]);
  clutter_actor_show(chessman_images[0]);
  clutter_actor_set_position(chessman_images[0],235,8);

  chessman_images[1]= clutter_texture_new_from_file(IMGAGE_DIR"black_king.png",NULL);
  clutter_container_add_actor(CLUTTER_CONTAINER(_group),chessman_images[1]);
  clutter_actor_show(chessman_images[1]);
  clutter_actor_set_position(chessman_images[1],235,68);

#else

		chessman_images[BLACK_ADVISOR] = clutter_texture_new_from_file(IMGAGE_DIR"black_advisor.png",NULL);
		chessman_images[BLACK_BISHOP] = clutter_texture_new_from_file(IMGAGE_DIR"black_bishop.png",NULL);
		chessman_images[BLACK_CANNON] = clutter_texture_new_from_file(IMGAGE_DIR"black_cannon.png",NULL);
		chessman_images[BLACK_KING] = clutter_texture_new_from_file(IMGAGE_DIR"black_king.png",NULL);
		chessman_images[BLACK_KING_DIE] = clutter_texture_new_from_file(IMGAGE_DIR"black_king_die.png",NULL);
		chessman_images[BLACK_KNIGHT] = clutter_texture_new_from_file(IMGAGE_DIR"black_knight.png",NULL);
		chessman_images[BLACK_PAWN] = clutter_texture_new_from_file(IMGAGE_DIR"black_pawn.png",NULL);
		chessman_images[BLACK_ROOK] = clutter_texture_new_from_file(IMGAGE_DIR"black_rook.png",NULL);
		chessman_images[RED_ADVISOR] = clutter_texture_new_from_file(IMGAGE_DIR"red_advisor.png",NULL);
		chessman_images[RED_BISHOP] = clutter_texture_new_from_file(IMGAGE_DIR"red_bishop.png",NULL);
		chessman_images[RED_CANNON] = clutter_texture_new_from_file(IMGAGE_DIR"red_cannon.png",NULL);
		chessman_images[RED_KING] = clutter_texture_new_from_file(IMGAGE_DIR"red_king.png",NULL);
		chessman_images[RED_KING_DIE] = clutter_texture_new_from_file(IMGAGE_DIR"red_king_die.png",NULL);
		chessman_images[RED_KNIGHT] = clutter_texture_new_from_file(IMGAGE_DIR"red_knight.png",NULL);
		chessman_images[RED_PAWN] = clutter_texture_new_from_file(IMGAGE_DIR"red_pawn.png",NULL);
		chessman_images[RED_ROOK] = clutter_texture_new_from_file(IMGAGE_DIR"red_rook.png",NULL);
		chessman_images[SELECTED_CHESSMAN] = clutter_texture_new_from_file(IMGAGE_DIR"select.png",NULL);
		chessman_images[NULL_CHESSMAN] = clutter_texture_new_from_file(IMGAGE_DIR"null.png",NULL);


		for(int i=0;i<8;i++)
			for(int j=0;j<9;j++)
			{

				clutter_actor_set_position(chessman_images[i+j],i*10+5,j*10+5);

			}
		for(int i=0;i<18;i++)
		{
			//clutter_actor_set_reactive(chessman_images[i],TRUE);
			clutter_container_add_actor(CLUTTER_CONTAINER(_group), chessman_images[i]);
			clutter_actor_show(chessman_images[i]);


		}
#endif

}
Ejemplo n.º 26
0
static void
penge_welcome_tile_init (PengeWelcomeTile *tile)
{
  ClutterActor *placeholder_image;
  GError *error = NULL;

  placeholder_image = clutter_texture_new_from_file (PLACEHOLDER_IMAGE, &error);
  if (error != NULL)
    {
      g_warning ("Couldn't open the placeholder image %s", PLACEHOLDER_IMAGE);
      g_clear_error (&error);
    }
  else
    {
      ClutterActor *bin;

      bin = mx_frame_new ();

      clutter_container_add_actor (CLUTTER_CONTAINER (bin),
          placeholder_image);

      clutter_actor_set_name (bin,
                              "penge-welcome-placeholder-margin");
      clutter_actor_set_name (placeholder_image,
                              "penge-welcome-placeholder");
      clutter_actor_set_size (placeholder_image, 548, 247);

      mx_table_insert_actor_with_properties (MX_TABLE (tile),
                                             bin,
                                             0, 0,
                                             "x-expand", TRUE,
                                             "y-expand", TRUE,
                                             "x-fill", TRUE,
                                             "y-fill", TRUE,
                                             "x-align", MX_ALIGN_START,
                                             NULL);
      mx_bin_set_fill (MX_BIN (bin), TRUE, TRUE);
    }


  /* It's not to be shown
  if (g_file_test (WELCOME_VIDEO_FILENAME, G_FILE_TEST_EXISTS))
    {
      ClutterActor *launcher;
      ClutterActor *inner_table;
      ClutterActor *icon;

      launcher = mx_button_new ();
      clutter_actor_set_name (launcher, "penge-welcome-launcher");

      inner_table = mx_table_new ();
      mx_bin_set_child (MX_BIN (launcher), inner_table);

      icon = mx_icon_new ();
      clutter_actor_set_name (icon, "penge-welcome-launcher-thumbnail");
      mx_table_insert_actor_with_properties (MX_TABLE (inner_table),
                                          icon,
                                          0, 0,
                                          "x-expand", TRUE,
                                          "x-fill", TRUE,
                                          "y-expand", TRUE,
                                          "y-fill", TRUE,
                                          NULL);

      icon = mx_icon_new ();
      clutter_actor_set_name (icon, "penge-welcome-launcher-play-button");
      mx_table_insert_actor_with_properties (MX_TABLE (inner_table),
                                          icon,
                                          0, 0,
                                          "x-expand", TRUE,
                                          "x-fill", FALSE,
                                          "y-expand", TRUE,
                                          "y-fill", FALSE,
                                          NULL);

      mx_table_insert_actor_with_properties (MX_TABLE (tile),
                                          launcher,
                                          1, 0,
                                          "x-expand", FALSE,
                                          "x-fill", FALSE,
                                          "y-expand", FALSE,
                                          "y-fill", FALSE,
                                          "x-align", MX_ALIGN_START,
                                          NULL);

      g_signal_connect (launcher,
                        "clicked",
                        (GCallback)_welcome_launcher_clicked_cb,
                        NULL);
    }
    */
}
Ejemplo n.º 27
0
G_MODULE_EXPORT gint
test_shader_main (gint argc, gchar *argv[])
{
  ClutterActor  *actor;
  ClutterActor  *stage;
  ClutterColor   stage_color = { 0x61, 0x64, 0x8c, 0xff };
  ClutterShader *shader;
  GError        *error;
  gchar         *file;

  if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
    return 1;

  stage = clutter_stage_new ();
  clutter_stage_set_title (CLUTTER_STAGE (stage), "Shaders");
  clutter_actor_set_size (stage, 512, 384);
  g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);

  g_print ("applying shaders[%i] named '%s'\n",
           shader_no,
           shaders[shader_no].name);

  shader = clutter_shader_new ();

  error = NULL;
  clutter_shader_set_fragment_source (shader, shaders[shader_no].source, -1);
  clutter_shader_compile (shader, &error);
  if (error)
    {
      g_print ("unable to load shaders[%d] named '%s': %s\n",
               shader_no,
               shaders[shader_no].name,
               error->message);
      g_error_free (error);

      return EXIT_FAILURE;
    }

  clutter_stage_set_title (CLUTTER_STAGE (stage), "Shader Test");
  clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);

  file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL);

#ifndef TEST_GROUP
  actor = clutter_texture_new_from_file (file, &error);
  if (!actor)
    g_error("pixbuf load failed: %s", error ? error->message : "Unknown");
#else
  actor = clutter_group_new ();

  {
    ClutterActor *child1, *child2, *child3, *child4;
    ClutterColor  color = { 0xff, 0x22, 0x66, 0x99 };

    child1 = clutter_texture_new_from_file (file, &error);
    if (!child1)
      g_error("pixbuf load failed: %s", error ? error->message : "Unknown");

    child2 = clutter_texture_new_from_file (file, &error);
    if (!child2)
      g_error("pixbuf load failed: %s", error ? error->message : "Unknown");

    child3 = clutter_rectangle_new ();
    child4 = clutter_text_new_with_text ("Sans 20px", "Shady stuff");

    clutter_rectangle_set_color (CLUTTER_RECTANGLE (child3), &color);
    clutter_actor_set_size (child3, 50, 50);

    clutter_actor_set_position (child1, 0, 0);
    clutter_actor_set_position (child2, 50, 100);
    clutter_actor_set_position (child3, 30, -30);
    clutter_actor_set_position (child4, -50, 20);

    clutter_container_add (CLUTTER_CONTAINER (actor),
                           child1,
                           child2,
                           child3,
                           child4,
                           NULL);

    clutter_actor_show_all (actor);
  }
#endif /* !TEST_GROUP */

  g_free (file);

  clutter_actor_set_shader (actor, shader);
  clutter_actor_set_position (actor, 100, 100);

  g_object_unref (shader);

  clutter_container_add_actor (CLUTTER_CONTAINER (stage), actor);

  clutter_actor_set_shader_param_int (actor, "tex", 0);
  clutter_actor_set_shader_param_float (actor, "brightness", 0.4);
  clutter_actor_set_shader_param_float (actor, "contrast", -1.9);

  clutter_actor_set_reactive (actor, TRUE);
  g_signal_connect (actor, "button-release-event",
                    G_CALLBACK (button_release_cb), NULL);

#ifdef COGL_HAS_GLES2
  /* On an embedded platform it is difficult to right click so we will
     cycle through the shaders automatically */
  g_timeout_add_seconds (3, timeout_cb, actor);
#endif

  /* Show everying ( and map window ) */
  clutter_actor_show_all (stage);

  clutter_main ();

  return EXIT_SUCCESS;
}
Ejemplo n.º 28
0
int
main (int argc, char *argv[])
{
  ClutterLayoutManager *layout;
  ClutterActor *box;
  ClutterActor *stage;
  ClutterActor *texture;
  CoglHandle *cogl_texture;
  GError *error = NULL;
  gfloat width;

  const gchar *filename = "redhand.png";

  if (argc > 1)
    filename = argv[1];

  if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
    return 1;

  stage = clutter_stage_new ();
  clutter_actor_set_size (stage, STAGE_SIDE, STAGE_SIDE);
  g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);

  layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
                                   CLUTTER_BIN_ALIGNMENT_CENTER);

  box = clutter_actor_new ();
  clutter_actor_set_layout_manager (box, layout);
  clutter_actor_set_background_color (box, &box_color);

  texture = clutter_texture_new_from_file (filename, &error);

  if (error != NULL)
    g_error ("Error loading file %s; message was:\n%s",
             filename,
             error->message);

  /*
   * get a reference to the underlying Cogl texture
   * for copying onto each Clutter texture placed into the layout
   */
  cogl_texture = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (texture));

  /*
   * add gradually turning and shrinking textures,
   * smallest one last; each actor ends up on top
   * of the one added just before it
   */
  for (width = STAGE_SIDE * 0.75; width >= STAGE_SIDE * 0.0625; width -= STAGE_SIDE * 0.0625)
    {
      ClutterActor *texture_copy = clutter_texture_new ();
      clutter_texture_set_cogl_texture (CLUTTER_TEXTURE (texture_copy),
                                        cogl_texture);
      clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (texture_copy),
                                             TRUE);
      clutter_actor_set_z_rotation_from_gravity (texture_copy,
                                                 (gfloat)(width * 0.5) - (STAGE_SIDE * 0.03125),
                                                 CLUTTER_GRAVITY_CENTER);
      clutter_actor_set_width (texture_copy, width);
      clutter_actor_add_child (box, texture_copy);
    }

  clutter_actor_add_constraint (box, clutter_align_constraint_new (stage, CLUTTER_ALIGN_BOTH, 0.5));
  clutter_actor_add_child (stage, box);

  clutter_actor_show (stage);

  clutter_main ();

  return 0;
}
Ejemplo n.º 29
0
int main(int argc, char *argv[])
{
    ClutterActor *stage;
    WebKitWebView *web_view;
    
    ClutterConstraint *width_binding;
    ClutterConstraint *height_binding;
    ClutterConstraint *web_view_height_binding;
    
    gfloat stageWidth, stageHeight;
    ClutterActorBox stageAllocation;
    
    ClutterLayoutManager  *mainLayout;
    ClutterActor          *mainLayoutContainer;
    ClutterLayoutManager  *toolbarLayout;
    ClutterActor          *toolbarContainer;
    ClutterLayoutManager  *toolbarBinLayout;
    ClutterActor          *toolbarBinContainer;
    ClutterActor          *toolbarBgr;
    ClutterActor          *statusBar;
    ClutterActor *backFwdBtns;
    ClutterActor *backBtn;
    ClutterActor *fwdBtn;
    ClutterActor *uriGroup;
    ClutterActor *uriBgr;
    ClutterActor *uriText;
    ClutterActor *spacer;
    
    GError *error = NULL;
    
    ClutterColor whiteColor = { 255, 255, 255, 255 };
    ClutterColor blackColor = { 0, 0, 0, 255 };
    ClutterColor grayColor =  { 200, 200, 200, 255 };
    ClutterColor transparentColor = { 0, 0, 0, 0 };
    
    gchar *toolbarBgrPath = clutter_launcher_file_path("toolbar_bgr.png");
    gchar *backBtnPath = clutter_launcher_file_path("back_btn.png");
    gchar *fwdBtnPath = clutter_launcher_file_path("fwd_btn.png");
    
    g_thread_init(NULL);
    clutter_threads_init();
    
    clutter_init(&argc, &argv);
    
    stage = clutter_stage_get_default();
    clutter_actor_set_size(stage, 1024, 768);
    clutter_stage_set_color(CLUTTER_STAGE(stage), &stage_color);
    g_signal_connect (stage, "destroy", G_CALLBACK(clutter_main_quit), NULL);
    
    /* make the stage resizable */
    clutter_stage_set_user_resizable(CLUTTER_STAGE(stage), TRUE);
    
    clutter_actor_show(stage);
    
    mainLayout = clutter_box_layout_new();
    clutter_box_layout_set_vertical(CLUTTER_BOX_LAYOUT(mainLayout), TRUE);
    
    
    clutter_actor_get_allocation_box(stage, &stageAllocation);
    stageWidth = stageAllocation.x2 - stageAllocation.x1;
    stageHeight = stageAllocation.y2 - stageAllocation.y1;
    
    web_view = WEBKIT_WEB_VIEW(webkit_web_view_new((guint)stageWidth, (guint)stageHeight - (toolbarHeight + statusBarHeight)));
    g_object_set(web_view, "reactive", TRUE, NULL);
    
    mainLayoutContainer = clutter_box_new(mainLayout);
    clutter_actor_set_size(mainLayoutContainer, stageWidth, stageHeight);
    
    width_binding = clutter_bind_constraint_new(stage, CLUTTER_BIND_WIDTH, 0);
    height_binding = clutter_bind_constraint_new(stage, CLUTTER_BIND_HEIGHT, 0);
/*    web_view_height_binding = clutter_bind_constraint_new(stage, CLUTTER_BIND_HEIGHT, -(toolbarHeight + statusBarHeight));
  */  
    clutter_actor_add_constraint(mainLayoutContainer, width_binding);
    clutter_actor_add_constraint(mainLayoutContainer, height_binding);
/*    clutter_actor_add_constraint(CLUTTER_ACTOR(web_view), web_view_height_binding);
  */  
    toolbarBinLayout = clutter_bin_layout_new(CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_CENTER);
    toolbarBinContainer = clutter_box_new(toolbarBinLayout);
    
    toolbarBgr = clutter_texture_new_from_file(toolbarBgrPath, &error);
    if (toolbarBgr == NULL) {
      fprintf(stderr, "Can't load file: %s. Aborting...\n", toolbarBgrPath);
      exit(1);
    }
    clutter_actor_set_height(toolbarBgr, toolbarHeight);
    clutter_texture_set_repeat(CLUTTER_TEXTURE(toolbarBgr), TRUE, FALSE);
    clutter_box_pack(CLUTTER_BOX(toolbarBinContainer), toolbarBgr, NULL, NULL);
    
    toolbarLayout = clutter_box_layout_new();
    clutter_box_layout_set_vertical(CLUTTER_BOX_LAYOUT(toolbarLayout), FALSE);
    clutter_box_layout_set_spacing(CLUTTER_BOX_LAYOUT(toolbarLayout), 16);
    toolbarContainer = clutter_box_new(toolbarLayout);
    
    spacer = clutter_rectangle_new_with_color(&transparentColor);
    clutter_actor_set_size(spacer, 1, 1);
    clutter_box_pack(CLUTTER_BOX(toolbarContainer), spacer, NULL, NULL);
    
    backFwdBtns = clutter_group_new();
    
    backBtn = clutter_texture_new_from_file(backBtnPath, &error);
    if (backBtn == NULL) {
      fprintf(stderr, "Can't load file: %s. Aborting...\n", backBtnPath);
      exit(1);
    }
    clutter_actor_set_reactive(backBtn, TRUE);
    /* connect the release event */
    g_signal_connect (backBtn,
                      "button-release-event",
                      G_CALLBACK (on_back_release_cb),
                      web_view);
    
    fwdBtn = clutter_texture_new_from_file(fwdBtnPath, &error);
    if (fwdBtn == NULL) {
      fprintf(stderr, "Can't load file: %s. Aborting...\n", fwdBtnPath);
      exit(1);
    }
    clutter_actor_set_reactive(fwdBtn, TRUE);
    /* connect the release event */
    g_signal_connect (fwdBtn,
                      "button-release-event",
                      G_CALLBACK (on_fwd_release_cb),
                      web_view);
    
    clutter_actor_set_position(fwdBtn, 
                               clutter_actor_get_width(backBtn), 0);
    clutter_container_add(CLUTTER_CONTAINER(backFwdBtns), backBtn, fwdBtn, NULL);
    clutter_box_pack(CLUTTER_BOX(toolbarContainer), backFwdBtns, NULL, NULL);
    
    uriGroup = clutter_group_new();
    
    uriBgr = clutter_rectangle_new_with_color(&whiteColor);
    clutter_rectangle_set_border_color(CLUTTER_RECTANGLE(uriBgr), &blackColor);
    clutter_rectangle_set_border_width(CLUTTER_RECTANGLE(uriBgr), 1);
    clutter_actor_set_size(uriBgr, 400, 25);
    
    uriText = clutter_text_new_full("Helvetica 11px", "http://www.google.com", &blackColor);
    clutter_text_set_editable(CLUTTER_TEXT(uriText), TRUE);
    clutter_text_set_single_line_mode(CLUTTER_TEXT(uriText), TRUE);
    clutter_actor_set_position(uriText, 5, 7);
    clutter_actor_set_size(uriText, 390, 17);
    clutter_actor_set_reactive(uriText, TRUE);
    g_signal_connect(uriText, "activate", G_CALLBACK(on_uri_activate_cb), web_view);
    
    clutter_container_add(CLUTTER_CONTAINER(uriGroup), uriBgr, uriText, NULL);
    clutter_box_pack(CLUTTER_BOX(toolbarContainer), uriGroup, NULL, NULL);
    
    clutter_box_pack(CLUTTER_BOX(toolbarBinContainer), toolbarContainer, NULL, NULL);
    
    clutter_box_pack(CLUTTER_BOX(mainLayoutContainer), toolbarBinContainer, 
                     "y-align", CLUTTER_BOX_ALIGNMENT_START, NULL);
    clutter_box_layout_set_expand(CLUTTER_BOX_LAYOUT(mainLayout), toolbarBinContainer, TRUE);
    clutter_box_layout_set_fill(CLUTTER_BOX_LAYOUT(mainLayout), toolbarBinContainer, TRUE, FALSE);
    
    statusBar = clutter_rectangle_new_with_color(&grayColor);
    clutter_actor_set_height(statusBar, statusBarHeight);
    
    clutter_box_pack(CLUTTER_BOX(mainLayoutContainer), statusBar, 
                     "y-align", CLUTTER_BOX_ALIGNMENT_END, NULL);
    clutter_box_layout_set_expand(CLUTTER_BOX_LAYOUT(mainLayout), statusBar, TRUE);
    clutter_box_layout_set_fill(CLUTTER_BOX_LAYOUT(mainLayout), statusBar, TRUE, FALSE);
    
    clutter_box_pack_after(CLUTTER_BOX(mainLayoutContainer), CLUTTER_ACTOR(web_view), toolbarBinContainer, 
                           "y-align", CLUTTER_BOX_ALIGNMENT_START, NULL);
    clutter_box_layout_set_expand(CLUTTER_BOX_LAYOUT(mainLayout), CLUTTER_ACTOR(web_view), TRUE);
    clutter_box_layout_set_fill(CLUTTER_BOX_LAYOUT(mainLayout), CLUTTER_ACTOR(web_view), TRUE, TRUE);

    clutter_container_add(CLUTTER_CONTAINER(stage), mainLayoutContainer, NULL);
    
    g_signal_connect(web_view, "webkit-load-finished", G_CALLBACK(load_finished_cb), web_view);
    g_signal_connect(web_view, "notify::progress", G_CALLBACK (notify_progress_cb), web_view);
    /*    g_signal_connect(stage, "delete-event", G_CALLBACK(delete_cb), web_view);*/
    g_signal_connect(web_view, "notify::uri", G_CALLBACK(notify_uri_cb), uriText);
    
    gchar *uri = (gchar*) (argc > 1 ? argv[1] : "http://www.google.com/");
    gchar *fileURL = filenameToURL(uri);

    webkit_web_view_load_uri(web_view, fileURL ? fileURL : uri);
    printf("%s\n", fileURL ? fileURL : uri);
    g_free(fileURL);
        
    g_timeout_add_full(G_PRIORITY_DEFAULT, 3000, timeout_cb, web_view, 0);
    
    clutter_threads_enter ();
    clutter_main();
    clutter_threads_leave ();
    
    return EXIT_SUCCESS;
}
static void
penge_grid_view_init (PengeGridView *self)
{
  PengeGridViewPrivate *priv = GET_PRIVATE_REAL (self);
  GError *error = NULL;

  self->priv = priv;

  priv->header_label = mx_label_new_with_text ("Myzone");
  clutter_actor_set_name (priv->header_label, "myzone-panel-header-label");
  mx_table_insert_actor_with_properties (MX_TABLE (self),
                                      priv->header_label,
                                      0, 0,
                                      "x-expand", FALSE,
                                      "y-expand", FALSE,
                                      "column-span", 3,
                                      NULL);

  priv->calendar_pane = g_object_new (PENGE_TYPE_CALENDAR_PANE,
                                      NULL);
  clutter_actor_set_width (priv->calendar_pane, 280);


  mx_table_insert_actor (MX_TABLE (self),
                      priv->calendar_pane,
                      1,
                      0);

  priv->email_pane = g_object_new (PENGE_TYPE_EMAIL_PANE,
                                   NULL);

  mx_table_insert_actor (MX_TABLE (self),
                      priv->email_pane,
                      2,
                      0);

  priv->favourite_apps_pane = g_object_new (PENGE_TYPE_APPS_PANE,
                                            NULL);

  mx_table_insert_actor (MX_TABLE (self),
                      priv->favourite_apps_pane,
                      3,
                      0);
  priv->div_tex = clutter_texture_new_from_file (V_DIV_LINE, &error);

  if (!priv->div_tex)
  {
    g_warning (G_STRLOC ": Error loading vertical divider: %s",
               error->message);
    g_clear_error (&error);
  } else {
    mx_table_insert_actor (MX_TABLE (self),
                        priv->div_tex,
                        1,
                        1);
  }

  priv->everything_pane = g_object_new (PENGE_TYPE_EVERYTHING_PANE,
                                        NULL);

  mx_table_insert_actor (MX_TABLE (self), priv->everything_pane, 1, 2);

  mx_table_set_row_spacing (MX_TABLE (self), 6);
  mx_table_set_column_spacing (MX_TABLE (self), 6);

  /* 
   * Create a background and parent it to the grid. We paint and allocate this
   * in the overridden vfuncs
   */
  priv->background = g_object_new (PENGE_TYPE_VIEW_BACKGROUND, NULL);
  clutter_actor_set_parent (priv->background, (ClutterActor *)self);
  clutter_actor_show (priv->background);

  priv->background_fade = clutter_texture_new_from_file (FADE_BG,
                                                         NULL);
  clutter_actor_set_parent (priv->background_fade, (ClutterActor *)self);
  clutter_actor_show (priv->background_fade);

  priv->gconf_client = gconf_client_get_default ();
  priv->show_calendar_notify_id = 
    gconf_client_notify_add (priv->gconf_client,
                             MEEGO_MYZONE_SHOW_CALENDAR,
                             _gconf_show_calendar_notify_cb,
                             self,
                             NULL,
                             &error);
  if (error)
  {
    g_warning (G_STRLOC ": Error setting gconf key notification: %s",
               error->message);
    g_clear_error (&error);
  } else {
    gconf_client_notify (priv->gconf_client, MEEGO_MYZONE_SHOW_CALENDAR);
  }

  priv->show_email_notify_id = 
    gconf_client_notify_add (priv->gconf_client,
                             MEEGO_MYZONE_SHOW_EMAIL,
                             _gconf_show_email_notify_cb,
                             self,
                             NULL,
                             &error);
  if (error)
  {
    g_warning (G_STRLOC ": Error setting gconf key notification: %s",
        error->message);
    g_clear_error (&error);
  } else {
    gconf_client_notify (priv->gconf_client, MEEGO_MYZONE_SHOW_EMAIL);
  }

}