示例#1
0
G_MODULE_EXPORT int
test_drag_main (int argc, char *argv[])
{
  ClutterActor *stage, *handle;
  ClutterAction *action;
  GError *error;

  error = NULL;
  clutter_init_with_args (&argc, &argv,
                          "test-drag",
                          entries,
                          NULL,
                          &error);
  if (error != NULL)
    {
      g_print ("Unable to run test-drag: %s\n", error->message);
      g_error_free (error);

      return EXIT_FAILURE;
    }

  stage = clutter_stage_new ();
  clutter_stage_set_title (CLUTTER_STAGE (stage), "Drag Test");
  clutter_actor_set_size (stage, 800, 600);
  g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);

  handle = clutter_rectangle_new ();
  clutter_rectangle_set_color (CLUTTER_RECTANGLE (handle),
                               CLUTTER_COLOR_SkyBlue);
  clutter_actor_set_size (handle, 128, 128);
  clutter_actor_set_position (handle, (800 - 128) / 2, (600 - 128) / 2);
  clutter_actor_set_reactive (handle, TRUE);
  clutter_container_add_actor (CLUTTER_CONTAINER (stage), handle);
  g_signal_connect (handle, "enter-event", G_CALLBACK (on_enter), NULL);
  g_signal_connect (handle, "leave-event", G_CALLBACK (on_leave), NULL);

  action = clutter_drag_action_new ();
  clutter_drag_action_set_drag_threshold (CLUTTER_DRAG_ACTION (action),
                                          x_drag_threshold,
                                          y_drag_threshold);
  clutter_drag_action_set_drag_axis (CLUTTER_DRAG_ACTION (action),
                                     get_drag_axis (drag_axis));

  g_signal_connect (action, "drag-begin", G_CALLBACK (on_drag_begin), NULL);
  g_signal_connect (action, "drag-end", G_CALLBACK (on_drag_end), NULL);

  clutter_actor_add_action (handle, action);

  clutter_actor_add_effect_with_name (handle, "disable", clutter_desaturate_effect_new (0.0));
  clutter_actor_add_effect_with_name (handle, "curl", clutter_page_turn_effect_new (0.0, 45.0, 12.0));

  clutter_actor_show (stage);

  clutter_main ();

  return EXIT_SUCCESS;
}
static void
tile_created_cb (MexProxy *proxy,
                 GObject  *content,
                 GObject  *object,
                 gpointer  controls)
{
    const gchar *mime_type;
    ClutterEffect *effect;
    ClutterColor color = { 0, 0, 0, 60 };

    /* filter out folders */
    mime_type = mex_content_get_metadata (MEX_CONTENT (content),
                                          MEX_CONTENT_METADATA_MIMETYPE);

    if (g_strcmp0 (mime_type, "x-grl/box") == 0)
    {
        g_signal_stop_emission_by_name (proxy, "object-created");
        return;
    }

    mex_tile_set_important (MEX_TILE (object), TRUE);
    clutter_actor_set_reactive (CLUTTER_ACTOR (object), TRUE);

    g_object_set (object, "thumb-height", 140, "thumb-width", 250, NULL);

    g_signal_connect (object, "key-press-event", G_CALLBACK (key_press_event_cb),
                      controls);
    g_signal_connect (object, "button-release-event",
                      G_CALLBACK (button_release_event_cb), controls);

    effect = g_object_new (MEX_TYPE_SHADOW,
                           "radius-x", 15,
                           "radius-y", 15,
                           "color", &color,
                           "enabled", FALSE,
                           NULL);
    clutter_actor_add_effect_with_name (CLUTTER_ACTOR (object), "shadow", effect);

    effect = g_object_new (MEX_TYPE_SHADOW,
                           "radius-x", 15,
                           "radius-y", 15,
                           "color", &color,
                           NULL);
    clutter_actor_add_effect_with_name (mx_bin_get_child (MX_BIN (object)),
                                        "shadow", effect);

    g_signal_connect (object, "focus-in", G_CALLBACK (tile_focus_in_cb), NULL);
    g_signal_connect (object, "focus-out", G_CALLBACK (tile_focus_out_cb), NULL);
    tile_focus_out_cb (MX_BIN (object));
}
示例#3
0
/**
 * st_scroll_view_update_vfade_effect:
 * @self: a #StScrollView
 * @fade_offset: The length of the fade effect, in pixels.
 *
 * Sets the height of the fade area area in pixels. A value of 0
 * disables the effect.
 */
static void
st_scroll_view_update_vfade_effect (StScrollView *self,
                                    float fade_offset)
{
  StScrollViewPrivate *priv = ST_SCROLL_VIEW (self)->priv;

  /* A fade amount of more than 0 enables the effect. */
  if (fade_offset > 0.)
    {
      if (priv->vfade_effect == NULL) {
        priv->vfade_effect = g_object_new (ST_TYPE_SCROLL_VIEW_FADE, NULL);

        clutter_actor_add_effect_with_name (CLUTTER_ACTOR (self), "vfade",
                                            CLUTTER_EFFECT (priv->vfade_effect));
      }

      g_object_set (priv->vfade_effect,
                    "fade-offset", fade_offset,
                    NULL);
    }
   else
    {
      if (priv->vfade_effect != NULL) {
        clutter_actor_remove_effect (CLUTTER_ACTOR (self), CLUTTER_EFFECT (priv->vfade_effect));
        priv->vfade_effect = NULL;
      }
    }

  clutter_actor_queue_redraw (CLUTTER_ACTOR (self));
}
示例#4
0
static void
mex_tile_init (MexTile *self)
{
  MexTilePrivate *priv = self->priv = TILE_PRIVATE (self);
  const ClutterColor opaque = { 0x00, 0x00, 0x00, 0x00 };
  ClutterEffect *fade;

  /* create a template material for the header background from which cheap
   * copies can be made for each instance */
  if (G_UNLIKELY (!template_material))
    template_material = cogl_material_new ();

  priv->material = cogl_material_copy (template_material);


  /* layout for primary and secondary labels */
  priv->box_layout = mx_box_layout_new ();
  mx_box_layout_set_spacing (MX_BOX_LAYOUT (priv->box_layout), 12);

  /* add fade effect to the box layout */
  fade = (ClutterEffect*) mx_fade_effect_new ();
  mx_fade_effect_set_border (MX_FADE_EFFECT (fade), 0, 50, 0, 0);
  mx_fade_effect_set_color (MX_FADE_EFFECT (fade), &opaque);
  clutter_actor_add_effect_with_name (priv->box_layout, "fade", fade);
  clutter_actor_meta_set_enabled (CLUTTER_ACTOR_META (fade), TRUE);

  clutter_actor_push_internal (CLUTTER_ACTOR (self));
  clutter_actor_set_parent (priv->box_layout, CLUTTER_ACTOR (self));
  clutter_actor_pop_internal (CLUTTER_ACTOR (self));


  priv->label = clutter_text_new ();
  priv->secondary_label = clutter_text_new ();
  clutter_actor_set_opacity (priv->secondary_label, 128);

  clutter_container_add (CLUTTER_CONTAINER (priv->box_layout), priv->label,
                         priv->secondary_label, NULL);

  priv->header_visible = TRUE;

  priv->timeline = clutter_timeline_new (DURATION);
  priv->important_alpha =
    clutter_alpha_new_full (priv->timeline, CLUTTER_EASE_OUT_QUAD);
  g_signal_connect_object (priv->timeline, "new-frame",
                           G_CALLBACK (mex_tile_important_new_frame_cb), self,
                           0);
  g_signal_connect_object (priv->timeline, "completed",
                           G_CALLBACK (mex_tile_timeline_completed_cb), self,
                           0);

  g_signal_connect (self, "style-changed",
                    G_CALLBACK (mex_tile_style_changed_cb), NULL);

  g_signal_connect (self, "actor-added",
                    G_CALLBACK (mex_tile_actor_added), NULL);
  g_signal_connect (self, "actor-removed",
                    G_CALLBACK (mex_tile_actor_removed), NULL);
}
示例#5
0
static void prepare_workspace_content(MosesOverview *self, MetaWorkspace *ws)
{
    MosesOverviewPrivate* priv = self->priv;
    GList* l = meta_workspace_list_windows(ws);
    if (!priv->clones) { priv->clones = g_ptr_array_new(); }

    while (l) {
        MetaWindow* win = l->data;
        MetaWindowActor* win_actor = META_WINDOW_ACTOR(meta_window_get_compositor_private(win));

        if (meta_window_get_window_type(win) == META_WINDOW_DESKTOP) {
            g_debug("%s: got desktop actor", __func__);
            priv->background_actor = clutter_clone_new(CLUTTER_ACTOR(win_actor));

        } else if (meta_window_get_window_type(win) == META_WINDOW_NORMAL &&
                !meta_window_is_hidden(win)) {
            ClutterActor* clone = clutter_clone_new(CLUTTER_ACTOR(win_actor));
            clutter_actor_set_reactive(clone, TRUE);

            float x = 0.0, y = 0.0;
            clutter_actor_get_position(CLUTTER_ACTOR(win_actor), &x, &y);
            clutter_actor_set_position(clone, x, y);

            clutter_actor_hide(CLUTTER_ACTOR(win_actor));

            g_ptr_array_add(priv->clones, clone);
            clutter_actor_add_child(CLUTTER_ACTOR(self), clone);

            g_object_connect(clone,
                    "signal::transitions-completed", G_CALLBACK(on_effect_complete), self,
                    "signal::button-press-event", on_thumb_button_press, self,
                    "signal::enter-event", on_thumb_enter, self,
                    "signal::leave-event", on_thumb_leave, self,
                    NULL);
        }

        l = l->next;
    }

    ClutterColor clr = CLUTTER_COLOR_INIT(0xff, 0xff, 0xff, 0xff);
    clutter_actor_set_background_color(CLUTTER_ACTOR(self), &clr);

    if (priv->background_actor) {
#if 0
        ClutterEffect* blur = moses_blur_effect_new();
        clutter_actor_add_effect_with_name(priv->background_actor, "blur", blur);
        clutter_actor_insert_child_below(CLUTTER_ACTOR(self), priv->background_actor, NULL);
        clutter_actor_hide(clutter_clone_get_source(CLUTTER_CLONE(priv->background_actor)));
        clutter_actor_set_reactive(priv->background_actor, TRUE);
#endif
    }

    g_object_connect(priv->background_actor ? priv->background_actor: CLUTTER_ACTOR(self),
            "signal::button-press-event", on_bg_button_press, self,
            NULL);
}
示例#6
0
static gboolean on_thumb_enter(ClutterActor *actor, ClutterEvent *event, MosesOverview* self)
{
    MosesOverviewPrivate* priv = self->priv;
    g_debug("%s", __func__);

    ClutterColor clr = {0x20, 0x20, 0x20, 0xe0};
    ClutterEffect* turn = clutter_brightness_contrast_effect_new();
    clutter_brightness_contrast_effect_set_brightness(CLUTTER_BRIGHTNESS_CONTRAST_EFFECT(turn), 0.3);
    clutter_actor_add_effect_with_name(actor, "turn", turn);
    return FALSE;
}
示例#7
0
/**
 * mex_column_add_content:
 *
 * Add an item to the column for the specified content at the specified
 * position.
 */
static void
mex_column_add_content (MexColumn  *column,
                        MexContent *content,
                        guint       position)
{
  MexColumnPrivate *priv = column->priv;
  ClutterActor *box;
  MexShadow *shadow;
  ClutterColor shadow_color = { 0, 0, 0, 128 };
  GList *sibling;

  box = mex_content_box_new ();
  mex_content_view_set_content (MEX_CONTENT_VIEW (box), content);
  mex_content_view_set_context (MEX_CONTENT_VIEW (box), priv->model);

  sibling = g_list_nth (priv->children, position);
  priv->children = g_list_insert_before (priv->children, sibling, box);
  priv->n_items ++;

  /* add shadow */
  shadow = mex_shadow_new ();
  mex_shadow_set_paint_flags (shadow,
                              MEX_TEXTURE_FRAME_TOP
                              | MEX_TEXTURE_FRAME_BOTTOM);
  mex_shadow_set_radius_y (shadow, 25);
  mex_shadow_set_color (shadow, &shadow_color);
  clutter_actor_add_effect_with_name (CLUTTER_ACTOR (box), "shadow",
                                      CLUTTER_EFFECT (shadow));
  clutter_actor_meta_set_enabled (CLUTTER_ACTOR_META (shadow), FALSE);

  g_signal_connect (box, "notify::open",
                    G_CALLBACK (content_box_open_notify), column);

  /* set important if the column has focus */
  mex_content_box_set_important (MEX_CONTENT_BOX (box), priv->has_focus);

  clutter_actor_set_parent (box, CLUTTER_ACTOR (column));
}
示例#8
0
文件: widget.c 项目: ifzz/exlibs-c
static void clutter_widget_init ( ClutterWidget *_self ) {
    ClutterWidgetPrivate *priv;
    ClutterAction *action;
    ClutterState *state;

    _self->priv = priv = CLUTTER_WIDGET_GET_PRIVATE (_self);

    priv->borderColor = *CLUTTER_COLOR_LightGray;
    clutter_actor_set_reactive ( CLUTTER_ACTOR(_self), TRUE );

    // TODO: only in drag-bar { 
    action = clutter_drag_action_new ();
    clutter_drag_action_set_drag_threshold (CLUTTER_DRAG_ACTION (action),
                                            0,
                                            0);
    clutter_drag_action_set_drag_axis ( CLUTTER_DRAG_ACTION (action), CLUTTER_DRAG_X_AXIS&CLUTTER_DRAG_Y_AXIS );
    g_signal_connect (action, "drag-begin", G_CALLBACK (on_drag_begin), NULL);
    g_signal_connect (action, "drag-end", G_CALLBACK (on_drag_end), NULL);
    clutter_actor_add_action (CLUTTER_ACTOR(_self), action);
    clutter_actor_add_effect_with_name (CLUTTER_ACTOR(_self), "disable", clutter_desaturate_effect_new (0.0));
    // } TODO end 

    // init state machine
    state = clutter_state_new ();
    g_object_set_data_full ( G_OBJECT (_self), "hover-state-machine", state, g_object_unref );
    g_signal_connect ( _self, "enter-event", G_CALLBACK (on_enter), state );
    g_signal_connect ( _self, "leave-event", G_CALLBACK (on_leave), state );
    clutter_state_set ( state, NULL, "normal",
                        _self, "border-color", CLUTTER_LINEAR, CLUTTER_COLOR_DarkGray,
                        NULL );
    clutter_state_set ( state, NULL, "hover",
                        _self, "border-color", CLUTTER_LINEAR, CLUTTER_COLOR_LightSkyBlue,
                        NULL );
    clutter_state_set_duration ( state, NULL, NULL, 200 );

    // set init state
    clutter_state_set_state (state, "normal");
}
示例#9
0
static gboolean
on_timeout (State *state)
{
  int test_num = 0;
  int y, x;
  ClutterActor *over_actor = NULL;

  /* This will cause an unclipped pick redraw that will get buffered.
     We'll check below that this buffer is discarded because we also need
     to pick non-reactive actors */
  clutter_stage_get_actor_at_pos (CLUTTER_STAGE (state->stage),
                                  CLUTTER_PICK_REACTIVE, 10, 10);

  clutter_stage_get_actor_at_pos (CLUTTER_STAGE (state->stage),
                                  CLUTTER_PICK_REACTIVE, 10, 10);

  for (test_num = 0; test_num < 5; test_num++)
    {
      if (test_num == 0)
        {
          if (g_test_verbose ())
            g_print ("No covering actor:\n");
        }
      if (test_num == 1)
        {
          static const ClutterColor red = { 0xff, 0x00, 0x00, 0xff };
          /* Create an actor that covers the whole stage but that
             isn't visible so it shouldn't affect the picking */
          over_actor = clutter_rectangle_new_with_color (&red);
          clutter_actor_set_size (over_actor, STAGE_WIDTH, STAGE_HEIGHT);
          clutter_container_add (CLUTTER_CONTAINER (state->stage),
                                 over_actor, NULL);
          clutter_actor_hide (over_actor);

          if (g_test_verbose ())
            g_print ("Invisible covering actor:\n");
        }
      else if (test_num == 2)
        {
          /* Make the actor visible but set a clip so that only some
             of the actors are accessible */
          clutter_actor_show (over_actor);
          clutter_actor_set_clip (over_actor,
                                  state->actor_width * 2,
                                  state->actor_height * 2,
                                  state->actor_width * (ACTORS_X - 4),
                                  state->actor_height * (ACTORS_Y - 4));

          if (g_test_verbose ())
            g_print ("Clipped covering actor:\n");
        }
      else if (test_num == 3)
        {
          clutter_actor_hide (over_actor);

          clutter_actor_add_effect_with_name (CLUTTER_ACTOR (state->stage),
                                              "blur",
                                              clutter_blur_effect_new ());

          if (g_test_verbose ())
            g_print ("With blur effect:\n");
        }
      else if (test_num == 4)
        {
          clutter_actor_hide (over_actor);
          clutter_actor_remove_effect_by_name (CLUTTER_ACTOR (state->stage),
                                               "blur");

          clutter_actor_add_effect_with_name (CLUTTER_ACTOR (state->stage),
            "shift",
            g_object_new (TYPE_SHIFT_EFFECT, NULL));

          if (g_test_verbose ())
            g_print ("With shift effect:\n");
        }

      for (y = 0; y < ACTORS_Y; y++)
        {
          if (test_num == 4)
            x = 1;
          else
            x = 0;

          for (; x < ACTORS_X; x++)
            {
              gboolean pass = FALSE;
              gfloat pick_x;
              ClutterActor *actor;

              pick_x = x * state->actor_width + state->actor_width / 2;

              if (test_num == 4)
                pick_x -= SHIFT_STEP;

              actor
                = clutter_stage_get_actor_at_pos (CLUTTER_STAGE (state->stage),
                                                  CLUTTER_PICK_ALL,
                                                  pick_x,
                                                  y * state->actor_height
                                                  + state->actor_height / 2);

              if (g_test_verbose ())
                g_print ("% 3i,% 3i / %p -> ",
                         x, y, state->actors[y * ACTORS_X + x]);

              if (actor == NULL)
                {
                  if (g_test_verbose ())
                    g_print ("NULL:       FAIL\n");
                }
              else if (actor == over_actor)
                {
                  if (test_num == 2
                      && x >= 2 && x < ACTORS_X - 2
                      && y >= 2 && y < ACTORS_Y - 2)
                    pass = TRUE;

                  if (g_test_verbose ())
                    g_print ("over_actor: %s\n", pass ? "pass" : "FAIL");
                }
              else
                {
                  if (actor == state->actors[y * ACTORS_X + x]
                      && (test_num != 2
                          || x < 2 || x >= ACTORS_X - 2
                          || y < 2 || y >= ACTORS_Y - 2))
                    pass = TRUE;

                  if (g_test_verbose ())
                    g_print ("%p: %s\n", actor, pass ? "pass" : "FAIL");
                }

              if (!pass)
                state->pass = FALSE;
            }
        }
    }

  clutter_main_quit ();

  return FALSE;
}
示例#10
0
G_MODULE_EXPORT int
test_shader_effects_main (int argc, char *argv[])
{
  ClutterTimeline *timeline;
  ClutterActor *stage, *hand, *label, *rect;
  gchar *file;

  clutter_init (&argc, &argv);

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

  stage = clutter_stage_new ();
  clutter_stage_set_title (CLUTTER_STAGE (stage), "Rotations");
  clutter_stage_set_color (CLUTTER_STAGE (stage), CLUTTER_COLOR_Aluminium3);
  g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);

  /* 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 '%s'", file);

  g_free (file);

  clutter_actor_set_position (hand, 326, 265);
  clutter_actor_add_effect_with_name (hand, "desaturate", clutter_desaturate_effect_new (0.75));
  clutter_actor_add_effect_with_name (hand, "blur", clutter_blur_effect_new ());
  clutter_actor_animate_with_timeline (hand, CLUTTER_LINEAR, timeline,
                                       "@effects.desaturate.factor", 1.0,
                                       "rotation-angle-z", 360.0,
                                       "fixed::anchor-x", 86.0,
                                       "fixed::anchor-y", 125.0,
                                       "opacity", 128,
                                       NULL);

  rect = clutter_rectangle_new_with_color (CLUTTER_COLOR_DarkOrange);
  clutter_actor_add_effect_with_name (rect, "blur", clutter_blur_effect_new ());
  clutter_actor_set_position (rect, 415, 215);
  clutter_actor_set_size (rect, 150, 150);
  clutter_actor_animate_with_timeline (rect, CLUTTER_LINEAR, timeline,
                                       "rotation-angle-z", 360.0,
                                       "fixed::anchor-x", 75.0,
                                       "fixed::anchor-y", 75.0,
                                       NULL);

  label = clutter_text_new_with_text ("Mono 16",
                                      "The Wonder\n"
                                      "of the\n"
                                      "Spinning Hand");
  clutter_text_set_line_alignment (CLUTTER_TEXT (label), PANGO_ALIGN_CENTER);
  clutter_actor_set_position (label, 336, 275);
  clutter_actor_set_size (label, 500, 100);
  clutter_actor_animate_with_timeline (label, CLUTTER_LINEAR, timeline,
                                       "rotation-angle-z", 360.0,
                                       "fixed::anchor-x", 86.0,
                                       "fixed::anchor-y", 125.0,
                                       NULL);

  clutter_container_add (CLUTTER_CONTAINER (stage), rect, hand, label, NULL);
  
  /* start the timeline and thus the animations */
  clutter_timeline_start (timeline);

  clutter_actor_show_all (stage);

  clutter_main();

  g_object_unref (timeline);

  return 0;
}