static void
clutter_behaviour_ellipse_alpha_notify (ClutterBehaviour *behave,
                                        gdouble           alpha)
{
    ClutterBehaviourEllipse *self = CLUTTER_BEHAVIOUR_ELLIPSE (behave);
    ClutterBehaviourEllipsePrivate *priv = self->priv;
    gfloat start, end;
    gfloat angle = 0;
    knot3d knot;

    /* we do everything in single precision because it's easier, even
     * though all the parameters are stored in double precision for
     * consistency with the equivalent ClutterActor API
     */
    start = priv->angle_start;
    end   = priv->angle_end;

    if (priv->direction == CLUTTER_ROTATE_CW && start >= end)
        end += 360;
    else if (priv->direction == CLUTTER_ROTATE_CCW && start <= end)
        end -= 360;

    angle = (end - start) * alpha + start;

    clutter_behaviour_ellipse_advance (self, angle, &knot);

    knot.x += priv->center.x;
    knot.y += priv->center.y;

    clutter_behaviour_actors_foreach (behave, actor_apply_knot_foreach, &knot);
}
static void
clutter_behaviour_ellipse_set_property (GObject      *gobject,
                                        guint         prop_id,
                                        const GValue *value,
                                        GParamSpec   *pspec)
{
    ClutterBehaviourEllipse *el = CLUTTER_BEHAVIOUR_ELLIPSE (gobject);
    ClutterBehaviourEllipsePrivate *priv = el->priv;

    switch (prop_id)
    {
    case PROP_ANGLE_START:
        priv->angle_start = g_value_get_double (value);
        break;

    case PROP_ANGLE_END:
        priv->angle_end = g_value_get_double (value);
        break;

    case PROP_ANGLE_TILT_X:
        priv->angle_tilt_x = g_value_get_double (value);
        break;

    case PROP_ANGLE_TILT_Y:
        priv->angle_tilt_y = g_value_get_double (value);
        break;

    case PROP_ANGLE_TILT_Z:
        priv->angle_tilt_z = g_value_get_double (value);
        break;

    case PROP_WIDTH:
        clutter_behaviour_ellipse_set_width (el, g_value_get_int (value));
        break;

    case PROP_HEIGHT:
        clutter_behaviour_ellipse_set_height (el, g_value_get_int (value));
        break;

    case PROP_CENTER:
    {
        ClutterKnot *knot = g_value_get_boxed (value);
        if (knot)
            clutter_behaviour_ellipse_set_center (el, knot->x, knot->y);
    }
    break;

    case PROP_DIRECTION:
        priv->direction = g_value_get_enum (value);
        break;

    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
        break;
    }
}
static void
clutter_behaviour_ellipse_get_property (GObject    *gobject,
                                        guint       prop_id,
                                        GValue     *value,
                                        GParamSpec *pspec)
{
    ClutterBehaviourEllipsePrivate *priv;

    priv = CLUTTER_BEHAVIOUR_ELLIPSE (gobject)->priv;

    switch (prop_id)
    {
    case PROP_ANGLE_START:
        g_value_set_double (value, priv->angle_start);
        break;

    case PROP_ANGLE_END:
        g_value_set_double (value, priv->angle_end);
        break;

    case PROP_ANGLE_TILT_X:
        g_value_set_double (value, priv->angle_tilt_x);
        break;

    case PROP_ANGLE_TILT_Y:
        g_value_set_double (value, priv->angle_tilt_y);
        break;

    case PROP_ANGLE_TILT_Z:
        g_value_set_double (value, priv->angle_tilt_z);
        break;

    case PROP_WIDTH:
        g_value_set_int (value, (priv->a * 2));
        break;

    case PROP_HEIGHT:
        g_value_set_int (value, (priv->b * 2));
        break;

    case PROP_CENTER:
        g_value_set_boxed (value, &priv->center);
        break;

    case PROP_DIRECTION:
        g_value_set_enum (value, priv->direction);
        break;

    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
        break;
    }
}
示例#4
0
文件: courasel.c 项目: UIKit0/toys
void
introduce_items (App *app)
{
  gint     i;
  GSList  *node;
  gdouble  ang_start, ang_end;

  node = app->items;

  for (i=0; i<N_ITEMS; i++)
    {
      Item *item = node->data;

      ang_start = -90.0;
      ang_end   = (STEP * i);

      clutter_behaviour_ellipse_set_angle_start
	(CLUTTER_BEHAVIOUR_ELLIPSE(item->ellipse_behave), ang_start);

      clutter_behaviour_ellipse_set_angle_end
	(CLUTTER_BEHAVIOUR_ELLIPSE(item->ellipse_behave), ang_end);

      if (i == app->selected_index)
	{
	  g_object_set (item->opacity_behave,
			"opacity-start", 0x66,
			"opacity-end", 0xff,
			NULL);
	  g_object_set (item->scale_behave,
			"x-scale-start", 0.6,
			"y-scale-start", 0.6,
			"x-scale-end", 1.0,
			"y-scale-end", 1.0,
			NULL);
	}
      node = node->next;
    }

  clutter_timeline_start (app->timeline);
}
static void
clutter_behaviour_ellipse_applied (ClutterBehaviour *behave,
                                   ClutterActor     *actor)
{
    ClutterBehaviourEllipse *e = CLUTTER_BEHAVIOUR_ELLIPSE (behave);
    ClutterBehaviourEllipsePrivate *priv = e->priv;
    knot3d knot = { 0, };

    clutter_behaviour_ellipse_advance (e, priv->angle_start, &knot);

    clutter_actor_set_position (actor, knot.x, knot.y);

    /* the depth should be changed only if there is a tilt on
     * any of the X or the Y axis
     */
    if (priv->angle_tilt_x != 0 || priv->angle_tilt_y != 0)
        clutter_actor_set_depth (actor, knot.z);
}
示例#6
0
文件: courasel.c 项目: UIKit0/toys
void
rotate_items (App *app, int step)
{
  gint     i, from_index;
  GSList  *node;
  gdouble  ang = 0.0, ang_start, ang_end;

  from_index = app->selected_index;

  app->selected_index += (-1 * step);
  if (app->selected_index < 0) app->selected_index = 7;
  if (app->selected_index > 7) app->selected_index = 0;

  ang = app->off;

  node = app->items;

  for (i=0; i<N_ITEMS; i++)
    {
      Item *item = node->data;

      ang_start = ang;
      ang_end   = ang + (STEP * step);

      clutter_behaviour_ellipse_set_direction
	(CLUTTER_BEHAVIOUR_ELLIPSE(item->ellipse_behave),
	 step > 0 ? CLUTTER_ROTATE_CW : CLUTTER_ROTATE_CCW);

      clutter_behaviour_ellipse_set_angle_start
	(CLUTTER_BEHAVIOUR_ELLIPSE(item->ellipse_behave), ang_start);

      clutter_behaviour_ellipse_set_angle_end
	(CLUTTER_BEHAVIOUR_ELLIPSE(item->ellipse_behave), ang_end);

      if (i == from_index)
	{
	  g_object_set (item->opacity_behave,
			"opacity-start", 0xff,
			"opacity-end", 0x66,
			NULL);

	  g_object_set (item->scale_behave,
			"x-scale-start", 1.0,
			"y-scale-start", 1.0,
			"x-scale-end", 0.6,
			"y-scale-end", 0.6,
			NULL);
	}
      else if (i == app->selected_index)
	{
	  g_object_set (item->opacity_behave,
			"opacity-start", 0x66,
			"opacity-end", 0xff,
			NULL);
	  g_object_set (item->scale_behave,
			"x-scale-start", 0.6,
			"y-scale-start", 0.6,
			"x-scale-end", 1.0,
			"y-scale-end", 1.0,
			NULL);
	}
      else
	{
	  g_object_set (item->opacity_behave,
			"opacity-start", 0x66,
			"opacity-end", 0x66,
			NULL);
	  g_object_set (item->scale_behave,
			"x-scale-start", 0.6,
			"y-scale-start", 0.6,
			"x-scale-end", 0.6,
			"y-scale-end", 0.6,
			NULL);
	}

      ang += STEP;
      node = node->next;
    }

  clutter_timeline_start (app->timeline);

  app->off += (STEP * step);
  app->off = CLAMP_ANG(app->off);
}
示例#7
0
G_MODULE_EXPORT int
test_behave_main (int argc, char *argv[])
{
  ClutterTimeline  *timeline;
  ClutterAlpha     *alpha;
  ClutterBehaviour *o_behave, *p_behave;
  ClutterActor     *stage;
  ClutterActor     *group, *rect, *hand;
  ClutterColor      stage_color = { 0xcc, 0xcc, 0xcc, 0xff };
  ClutterColor      rect_bg_color = { 0x33, 0x22, 0x22, 0xff };
  ClutterColor      rect_border_color = { 0, 0, 0, 0 };
  int               i;
  path_t            path_type = PATH_POLY;

  const char       *knots_poly = ("M 0, 0   L 0, 300 L 300, 300 "
                                  "L 300, 0 L 0, 0");

  /* A spiral created with inkscake */
  const char       *knots_bspline =
    "M 34.285713,35.219326 "
    "C 44.026891,43.384723 28.084874,52.378758 20.714286,51.409804 "
    "C 0.7404474,48.783999 -4.6171866,23.967448 1.904757,8.0764719 "
    "C 13.570984,-20.348756 49.798303,-26.746504 74.999994,-13.352108 "
    "C 111.98449,6.3047056 119.56591,55.259271 99.047626,89.505034 "
    "C 71.699974,135.14925 9.6251774,143.91924 -33.571422,116.17172 "
    "C -87.929934,81.254291 -97.88804,5.8941057 -62.857155,-46.209236 "
    "C -20.430061,-109.31336 68.300385,-120.45954 129.2857,-78.114021 "
    "C 201.15479,-28.21129 213.48932,73.938876 163.80954,143.79074 "
    "C 106.45226,224.43749 -9.1490153,237.96076 -87.85713,180.93363 "
    "C -177.29029,116.13577 -192.00272,-12.937817 -127.61907,-100.49494 "
    "C -55.390344,-198.72081 87.170553,-214.62275 183.57141,-142.87593 "
    "C 290.59464,-63.223369 307.68641,92.835839 228.57145,198.07645";

  for (i = 0; i < argc; ++i)
    {
      if (!strncmp (argv[i], "--path", 6))
	{
	  if (!strncmp (argv[i] + 7, "poly", 4))
	    path_type  = PATH_POLY;
	  else if (!strncmp (argv[i] + 7, "bspline", 7))
	    path_type  = PATH_BSPLINE;
	  else if (!strncmp (argv[i] + 7, "ellipse", 7))
	    path_type  = PATH_ELLIPSE;
	}
      else if (!strncmp (argv[i], "--help", 6))
	{
	  printf ("behave [--path=poly|ellipse|bspline]\n");
	  exit (0);
	}
    }
  
  clutter_init (&argc, &argv);

  stage = clutter_stage_get_default ();
  clutter_stage_hide_cursor (CLUTTER_STAGE (stage));

  g_signal_connect (stage, "button-press-event",
                    G_CALLBACK (button_press_cb),
                    NULL);
  g_signal_connect (stage, "scroll-event",
                    G_CALLBACK (scroll_event_cb),
                    NULL);
  g_signal_connect (stage, "key-press-event",
                    G_CALLBACK (clutter_main_quit),
                    NULL);

  clutter_stage_set_color (CLUTTER_STAGE (stage),
		           &stage_color);

  /* Make a hand */
  group = clutter_group_new ();
  clutter_container_add_actor (CLUTTER_CONTAINER (stage), group);
  clutter_actor_show (group);
  
  hand = clutter_texture_new_from_file ("redhand.png", NULL);
  if (hand == NULL)
    {
      g_error("pixbuf load failed");
      return 1;
    }
  clutter_actor_set_position (hand, 0, 0);
  clutter_actor_show (hand);

  rect = clutter_rectangle_new ();
  clutter_actor_set_position (rect, 0, 0);
  clutter_actor_set_size (rect,
                          clutter_actor_get_width (hand),
			  clutter_actor_get_height (hand));
  clutter_rectangle_set_color (CLUTTER_RECTANGLE (rect),
                               &rect_bg_color);
  clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rect), 10);
  clutter_color_from_string (&rect_border_color, "DarkSlateGray");
  clutter_rectangle_set_border_color (CLUTTER_RECTANGLE (rect),
                                      &rect_border_color);
  clutter_actor_show (rect);
  
  clutter_container_add (CLUTTER_CONTAINER (group), rect, hand, NULL);
  
  /* Make a timeline */
  timeline = clutter_timeline_new (4000); /* num frames, fps */
  clutter_timeline_set_loop (timeline, TRUE);
  g_signal_connect (timeline,
                    "completed", G_CALLBACK (timeline_completed),
                    NULL);

  /* Set an alpha func to power behaviour - ramp is constant rise */
  alpha = clutter_alpha_new_full (timeline, CLUTTER_LINEAR);

  /* Create a behaviour for that alpha */
  o_behave = clutter_behaviour_opacity_new (alpha, 0X33, 0xff); 

  /* Apply it to our actor */
  clutter_behaviour_apply (o_behave, group);

  /* Make a path behaviour and apply that too */
  switch (path_type)
    {
    case PATH_POLY:
      {
        ClutterPath *path = clutter_path_new ();
        clutter_path_set_description (path, knots_poly);
        p_behave = clutter_behaviour_path_new (alpha, path);
      }
      break;
    case PATH_ELLIPSE:
      p_behave =
	clutter_behaviour_ellipse_new (alpha, 200, 200, 400, 300,
				       CLUTTER_ROTATE_CW,
				       0.0, 360.0);

      clutter_behaviour_ellipse_set_angle_tilt (CLUTTER_BEHAVIOUR_ELLIPSE (p_behave),
 						CLUTTER_X_AXIS,
 						45.0);
      clutter_behaviour_ellipse_set_angle_tilt (CLUTTER_BEHAVIOUR_ELLIPSE (p_behave),
 						CLUTTER_Z_AXIS,
 						45.0);
      break;

    case PATH_BSPLINE:
      {
        ClutterPath *path = clutter_path_new ();
        clutter_path_set_description (path, knots_bspline);
        p_behave = clutter_behaviour_path_new (alpha, path);
      }
      break;
    }

  clutter_behaviour_apply (p_behave, group);

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

  clutter_actor_show_all (stage);

  clutter_main();

  g_object_unref (o_behave);
  g_object_unref (p_behave);

  return 0;
}