Example #1
0
/**
 * _st_set_text_from_style:
 * @text: Target #ClutterText
 * @theme_node: Source #StThemeNode
 *
 * Set various GObject properties of the @text object using
 * CSS information from @theme_node.
 */
void
_st_set_text_from_style (ClutterText *text,
                         StThemeNode *theme_node)
{

    ClutterColor color;
    StTextDecoration decoration;
    PangoAttrList *attribs = NULL;
    const PangoFontDescription *font;
    StTextAlign align;

    st_theme_node_get_foreground_color (theme_node, &color);
    clutter_text_set_color (text, &color);

    font = st_theme_node_get_font (theme_node);
    clutter_text_set_font_description (text, (PangoFontDescription *) font);

    decoration = st_theme_node_get_text_decoration (theme_node);
    if (decoration)
    {
        attribs = pango_attr_list_new ();

        if (decoration & ST_TEXT_DECORATION_UNDERLINE)
        {
            PangoAttribute *underline = pango_attr_underline_new (PANGO_UNDERLINE_SINGLE);
            pango_attr_list_insert (attribs, underline);
        }
        if (decoration & ST_TEXT_DECORATION_LINE_THROUGH)
        {
            PangoAttribute *strikethrough = pango_attr_strikethrough_new (TRUE);
            pango_attr_list_insert (attribs, strikethrough);
        }
        /* Pango doesn't have an equivalent attribute for _OVERLINE, and we deliberately
         * skip BLINK (for now...)
         */
    }

    clutter_text_set_attributes (text, attribs);

    if (attribs)
        pango_attr_list_unref (attribs);

    align = st_theme_node_get_text_align (theme_node);
    if (align == ST_TEXT_ALIGN_JUSTIFY)
    {
        clutter_text_set_justify (text, TRUE);
        clutter_text_set_line_alignment (text, PANGO_ALIGN_LEFT);
    }
    else
    {
        clutter_text_set_justify (text, FALSE);
        clutter_text_set_line_alignment (text, (PangoAlignment) align);
    }
}
Example #2
0
static VALUE
rbclt_text_set_line_alignment (VALUE self, VALUE alignment)
{
  ClutterText *text = CLUTTER_TEXT (RVAL2GOBJ (self));
  clutter_text_set_line_alignment (text, RVAL2GENUM (alignment, PANGO_TYPE_ALIGNMENT));
  return Qnil;
}
static void
mnb_launcher_button_init (MnbLauncherButton *self)
{
  ClutterActor *label;

  self->priv = MNB_LAUNCHER_BUTTON_GET_PRIVATE (self);

  g_signal_connect (self, "leave-event",
                    G_CALLBACK (_leave_event_cb), NULL);
  g_signal_connect (self, "key-focus-out",
                    G_CALLBACK (_leave_event_cb), NULL);
  g_signal_connect (self, "enter-event",
                    G_CALLBACK (_enter_event_cb), NULL);

  self->priv->icon = NULL;

  mx_stylable_set_style_class (MX_STYLABLE (self), "contentTile");

  /* "app" label */
  self->priv->title = (MxLabel *) mx_label_new ();
  mx_label_set_x_align (MX_LABEL (self->priv->title), MX_ALIGN_MIDDLE);

  clutter_actor_set_reactive (CLUTTER_ACTOR (self->priv->title), FALSE);
  mx_table_insert_actor_with_properties (MX_TABLE (self),
                                         CLUTTER_ACTOR (self->priv->title),
                                         1, 0,
                                         "x-align", MX_ALIGN_MIDDLE,
                                         "x-expand", TRUE,
                                         "x-fill", TRUE,
                                         "y-align", MX_ALIGN_MIDDLE,
                                         "y-expand", TRUE,
                                         "y-fill", TRUE,
                                         NULL);

  label = mx_label_get_clutter_text (self->priv->title);
  clutter_text_set_ellipsize (CLUTTER_TEXT (label), PANGO_ELLIPSIZE_END);
  clutter_text_set_line_alignment (CLUTTER_TEXT (label), PANGO_ALIGN_CENTER);
  clutter_text_set_line_wrap (CLUTTER_TEXT (label), TRUE);
  clutter_text_set_line_wrap_mode (CLUTTER_TEXT (label), PANGO_WRAP_WORD_CHAR);

  /* "fav app" toggle */
  self->priv->fav_toggle = g_object_ref_sink (CLUTTER_ACTOR (mx_button_new ()));
  mx_button_set_is_toggle (MX_BUTTON (self->priv->fav_toggle), TRUE);
  clutter_actor_set_name (CLUTTER_ACTOR (self->priv->fav_toggle),
                          "mnb-launcher-button-fav-toggle");
  clutter_actor_set_size (self->priv->fav_toggle, FAV_TOGGLE_SIZE, FAV_TOGGLE_SIZE);
  mx_table_insert_actor (MX_TABLE (self),
                         CLUTTER_ACTOR (self->priv->fav_toggle),
                         0, 0);


  g_signal_connect (self->priv->fav_toggle, "notify::toggled",
                    G_CALLBACK (fav_button_notify_toggled_cb), self);

  clutter_actor_set_reactive ((ClutterActor *) self, TRUE);
}
static void
penge_interesting_tile_init (PengeInterestingTile *self)
{
    PengeInterestingTilePrivate *priv = GET_PRIVATE_REAL (self);
    ClutterActor *tmp_text;
    ClutterActor *icon;

    self->priv = priv;

    priv->inner_table = mx_table_new ();
    mx_bin_set_child (MX_BIN (self),
                      priv->inner_table);
    mx_bin_set_fill (MX_BIN (self), TRUE, TRUE);

    priv->primary_text = mx_label_new ();
    mx_stylable_set_style_class (MX_STYLABLE (priv->primary_text),
                                 "PengeInterestingTilePrimaryLabel");
    tmp_text = mx_label_get_clutter_text (MX_LABEL (priv->primary_text));
    clutter_text_set_line_alignment (CLUTTER_TEXT (tmp_text),
                                     PANGO_ALIGN_LEFT);
    clutter_text_set_ellipsize (CLUTTER_TEXT (tmp_text),
                                PANGO_ELLIPSIZE_END);
    g_signal_connect (priv->primary_text,
                      "notify::allocation",
                      (GCallback)_label_notify_allocation_cb,
                      self);

    priv->secondary_text = mx_label_new ();
    mx_stylable_set_style_class (MX_STYLABLE (priv->secondary_text),
                                 "PengeInterestingTileSecondaryLabel");
    tmp_text = mx_label_get_clutter_text (MX_LABEL (priv->secondary_text));
    clutter_text_set_line_alignment (CLUTTER_TEXT (tmp_text),
                                     PANGO_ALIGN_LEFT);
    clutter_text_set_ellipsize (CLUTTER_TEXT (tmp_text),
                                PANGO_ELLIPSIZE_END);
    g_signal_connect (priv->secondary_text,
                      "notify::allocation",
                      (GCallback)_label_notify_allocation_cb,
                      self);

    priv->icon = clutter_texture_new ();
    clutter_actor_set_size (priv->icon, 28, 28);
    clutter_actor_hide (priv->icon);

    /* This gets added to ourself table after our body because of ordering */
    priv->details_overlay = mx_table_new ();
    mx_stylable_set_style_class (MX_STYLABLE (priv->details_overlay),
                                 "PengeInterestingTileDetails");

    mx_table_add_actor (MX_TABLE (priv->inner_table),
                        priv->details_overlay,
                        1,
                        0);

    clutter_container_child_set (CLUTTER_CONTAINER (priv->inner_table),
                                 (ClutterActor *)priv->details_overlay,
                                 "x-expand", TRUE,
                                 "y-expand", FALSE,
                                 "y-fill", FALSE,
                                 "y-align", MX_ALIGN_END,
                                 NULL);

    mx_table_add_actor (MX_TABLE (priv->details_overlay),
                        priv->primary_text,
                        0,
                        1);

    clutter_container_child_set (CLUTTER_CONTAINER (priv->details_overlay),
                                 (ClutterActor *)priv->primary_text,
                                 "x-expand",
                                 TRUE,
                                 "y-expand",
                                 FALSE,
                                 NULL);

    mx_table_add_actor (MX_TABLE (priv->details_overlay),
                        priv->secondary_text,
                        1,
                        1);
    clutter_container_child_set (CLUTTER_CONTAINER (priv->details_overlay),
                                 (ClutterActor *)priv->secondary_text,
                                 "x-expand",
                                 TRUE,
                                 "y-expand",
                                 FALSE,
                                 NULL);

    mx_table_add_actor (MX_TABLE (priv->details_overlay),
                        priv->icon,
                        0,
                        0);
    clutter_container_child_set (CLUTTER_CONTAINER (priv->details_overlay),
                                 priv->icon,
                                 "row-span", 2,
                                 "y-expand", FALSE,
                                 "x-expand", FALSE,
                                 "y-fill", FALSE,
                                 "x-fill", FALSE,
                                 NULL);

    priv->remove_button = mx_button_new ();
    mx_stylable_set_style_class (MX_STYLABLE (priv->remove_button),
                                 "PengeInterestingTileRemoveButton");
    icon = (ClutterActor *)mx_icon_new ();
    mx_stylable_set_style_class (MX_STYLABLE (icon),
                                 "PengeInterestingTileIcon");
    mx_bin_set_child (MX_BIN (priv->remove_button),
                      (ClutterActor *)icon);
    mx_table_add_actor_with_properties (MX_TABLE (priv->details_overlay),
                                        priv->remove_button,
                                        0, 2,
                                        "row-span", 2,
                                        "x-expand", TRUE,
                                        "y-expand", TRUE,
                                        "x-fill", FALSE,
                                        "y-fill", FALSE,
                                        "x-align", MX_ALIGN_END,
                                        "y-align", MX_ALIGN_MIDDLE,
                                        NULL);

    g_signal_connect (priv->remove_button,
                      "clicked",
                      (GCallback)_remove_button_clicked,
                      self);

    mx_table_set_column_spacing (MX_TABLE (priv->details_overlay), 4);

    clutter_actor_set_reactive ((ClutterActor *) self, TRUE);

    clutter_actor_hide (priv->icon);
    clutter_container_child_set (CLUTTER_CONTAINER (priv->details_overlay),
                                 priv->primary_text,
                                 "column", 0,
                                 NULL);
    clutter_container_child_set (CLUTTER_CONTAINER (priv->details_overlay),
                                 priv->secondary_text,
                                 "column", 0,
                                 NULL);
}
Example #5
0
EaseWelcomeActor* ease_welcome_actor_construct (GType object_type, EaseTheme* t) {
#line 152 "ease-welcome-actor.c"
	EaseWelcomeActor * self;
	ClutterRectangle* _tmp0_;
	ClutterColor _tmp1_;
	ClutterColor _tmp2_;
	ClutterRectangle* _tmp3_;
	ClutterColor _tmp4_ = {0};
	ClutterColor _tmp5_;
	ClutterColor _tmp6_;
	ClutterText* _tmp7_;
	ClutterCairoTexture* _tmp8_;
#line 94 "ease-welcome-actor.vala"
	g_return_val_if_fail (t != NULL, NULL);
#line 165 "ease-welcome-actor.c"
	self = g_object_newv (object_type, 0, NULL);
#line 96 "ease-welcome-actor.vala"
	ease_welcome_actor_set_theme (self, t);
#line 97 "ease-welcome-actor.vala"
	clutter_actor_set_reactive ((ClutterActor*) self, TRUE);
#line 100 "ease-welcome-actor.vala"
	self->priv->rect = (_tmp0_ = g_object_ref_sink ((ClutterRectangle*) clutter_rectangle_new ()), _g_object_unref0 (self->priv->rect), _tmp0_);
#line 101 "ease-welcome-actor.vala"
	clutter_rectangle_set_color (self->priv->rect, (_tmp1_ = EASE_WELCOME_ACTOR_RECT_BG, &_tmp1_));
#line 102 "ease-welcome-actor.vala"
	clutter_rectangle_set_border_color (self->priv->rect, (_tmp2_ = EASE_WELCOME_ACTOR_RECT_B_C, &_tmp2_));
#line 103 "ease-welcome-actor.vala"
	clutter_rectangle_set_border_width (self->priv->rect, (guint) EASE_WELCOME_ACTOR_RECT_B_W);
#line 104 "ease-welcome-actor.vala"
	clutter_actor_set_x ((ClutterActor*) self->priv->rect, (float) (-EASE_WELCOME_ACTOR_RECT_B_W));
#line 105 "ease-welcome-actor.vala"
	clutter_actor_set_y ((ClutterActor*) self->priv->rect, (float) (-EASE_WELCOME_ACTOR_RECT_B_W));
#line 106 "ease-welcome-actor.vala"
	clutter_container_add_actor ((ClutterContainer*) self, (ClutterActor*) self->priv->rect);
#line 109 "ease-welcome-actor.vala"
	self->priv->hilight_rect = (_tmp3_ = g_object_ref_sink ((ClutterRectangle*) clutter_rectangle_new ()), _g_object_unref0 (self->priv->hilight_rect), _tmp3_);
#line 110 "ease-welcome-actor.vala"
	clutter_rectangle_set_color (self->priv->hilight_rect, (_tmp5_ = (_tmp4_.red = (guchar) 0, _tmp4_.green = (guchar) 0, _tmp4_.blue = (guchar) 0, _tmp4_.alpha = (guchar) 255, _tmp4_), &_tmp5_));
#line 111 "ease-welcome-actor.vala"
	clutter_actor_set_opacity ((ClutterActor*) self->priv->hilight_rect, (guint) 0);
#line 112 "ease-welcome-actor.vala"
	clutter_rectangle_set_border_color (self->priv->hilight_rect, (_tmp6_ = EASE_WELCOME_ACTOR_HLRECT_C, &_tmp6_));
#line 113 "ease-welcome-actor.vala"
	clutter_rectangle_set_border_width (self->priv->hilight_rect, (guint) EASE_WELCOME_ACTOR_HLRECT_W);
#line 114 "ease-welcome-actor.vala"
	clutter_actor_set_x ((ClutterActor*) self->priv->hilight_rect, (float) (-EASE_WELCOME_ACTOR_HLRECT_W));
#line 115 "ease-welcome-actor.vala"
	clutter_actor_set_y ((ClutterActor*) self->priv->hilight_rect, (float) (-EASE_WELCOME_ACTOR_HLRECT_W));
#line 116 "ease-welcome-actor.vala"
	clutter_container_add_actor ((ClutterContainer*) self, (ClutterActor*) self->priv->hilight_rect);
#line 119 "ease-welcome-actor.vala"
	self->priv->text = (_tmp7_ = g_object_ref_sink ((ClutterText*) clutter_text_new_full (EASE_WELCOME_ACTOR_FONT_NAME, self->priv->_theme->title, &EASE_WELCOME_ACTOR_TEXT_COLOR)), _g_object_unref0 (self->priv->text), _tmp7_);
#line 120 "ease-welcome-actor.vala"
	clutter_actor_set_height ((ClutterActor*) self->priv->text, EASE_WELCOME_ACTOR_TEXT_HEIGHT);
#line 121 "ease-welcome-actor.vala"
	clutter_text_set_line_alignment (self->priv->text, PANGO_ALIGN_RIGHT);
#line 122 "ease-welcome-actor.vala"
	clutter_container_add_actor ((ClutterContainer*) self, (ClutterActor*) self->priv->text);
#line 125 "ease-welcome-actor.vala"
	self->priv->slide_actor = (_tmp8_ = g_object_ref_sink ((ClutterCairoTexture*) clutter_cairo_texture_new ((guint) 1024, (guint) 768)), _g_object_unref0 (self->priv->slide_actor), _tmp8_);
#line 126 "ease-welcome-actor.vala"
	clutter_container_add_actor ((ClutterContainer*) self, (ClutterActor*) self->priv->slide_actor);
#line 129 "ease-welcome-actor.vala"
	clutter_actor_set_opacity ((ClutterActor*) self, (guint) 0);
#line 130 "ease-welcome-actor.vala"
	clutter_actor_animate ((ClutterActor*) self, (gulong) EASE_WELCOME_ACTOR_FADE_EASE, (guint) EASE_WELCOME_ACTOR_FADE_INIT_TIME, "opacity", 255, NULL);
#line 133 "ease-welcome-actor.vala"
	g_signal_connect_object ((ClutterActor*) self, "button-press-event", (GCallback) __lambda55__clutter_actor_button_press_event, self, 0);
#line 219 "ease-welcome-actor.c"
	return self;
}
static void
set_up_stage (CalibArea *calib_area, ClutterActor *stage)
{
  ClutterPoint anchor;
  ClutterColor color;
  ClutterContent *success_content;
  gfloat height;
  gchar *markup;

  calib_area->stage = stage;
  calib_area->action_layer = clutter_actor_new ();
  calib_area->clock = cc_clock_actor_new ();
  calib_area->target = cc_target_actor_new ();
  calib_area->text_title_holder = clutter_actor_new ();
  calib_area->helper_text_title = clutter_text_new ();
  calib_area->text_body_holder = clutter_actor_new ();
  calib_area->helper_text_body = clutter_text_new ();
  calib_area->error_text = clutter_text_new ();
  calib_area->success_image = clutter_actor_new ();

  clutter_stage_set_use_alpha (CLUTTER_STAGE (stage), TRUE);

  clutter_actor_hide (calib_area->target);

  /* bind the action layer's geometry to the stage's */
  clutter_actor_add_constraint (calib_area->action_layer,
                                clutter_bind_constraint_new (stage,
                                                             CLUTTER_BIND_SIZE,
                                                             0));
  clutter_actor_add_child (stage, calib_area->action_layer);

  g_signal_connect (stage,
                    "allocation-changed",
                    G_CALLBACK (on_allocation_changed),
                    calib_area);

  clutter_color_from_string (&color, "#000");
  color.alpha = WINDOW_OPACITY * 255;
  clutter_actor_set_background_color (stage, &color);

  clutter_actor_add_child (calib_area->action_layer, calib_area->clock);
  clutter_actor_add_constraint (calib_area->clock,
                                clutter_align_constraint_new (stage,
                                                              CLUTTER_ALIGN_BOTH,
                                                              0.5));

  clutter_actor_add_child (calib_area->action_layer, calib_area->target);

  /* set the helper text */
  anchor.x =  0;
  g_object_set (calib_area->text_title_holder, "pivot-point", &anchor, NULL);

  clutter_actor_add_child (calib_area->action_layer,
                           calib_area->text_title_holder);
  clutter_actor_add_child (calib_area->text_title_holder,
                           calib_area->helper_text_title);
  height = clutter_actor_get_height (calib_area->clock);
  clutter_actor_add_constraint (calib_area->text_title_holder,
                                clutter_bind_constraint_new (calib_area->clock,
                                                             CLUTTER_BIND_Y,
                                                             height * 1.5));
  clutter_actor_add_constraint (calib_area->text_title_holder,
                                clutter_align_constraint_new (stage,
                                                              CLUTTER_ALIGN_X_AXIS,
                                                              .5));

  clutter_text_set_line_alignment (CLUTTER_TEXT (calib_area->helper_text_title),
                                   PANGO_ALIGN_CENTER);

  color.red = COLOR_GRAY;
  color.green = COLOR_GRAY;
  color.blue = COLOR_GRAY;
  color.alpha = 255;

  markup = g_strdup_printf ("<big><b>%s</b></big>",
                            _(HELP_TEXT_TITLE));
  clutter_text_set_markup (CLUTTER_TEXT (calib_area->helper_text_title), markup);
  clutter_text_set_color (CLUTTER_TEXT (calib_area->helper_text_title), &color);
  g_free (markup);

  g_object_set (calib_area->text_body_holder, "pivot-point", &anchor, NULL);

  clutter_actor_add_child (calib_area->action_layer,
                           calib_area->text_body_holder);
  clutter_actor_add_child (calib_area->text_body_holder,
                           calib_area->helper_text_body);
  height = clutter_actor_get_height (calib_area->helper_text_title);
  clutter_actor_add_constraint (calib_area->text_body_holder,
                                clutter_bind_constraint_new (calib_area->text_title_holder,
                                                             CLUTTER_BIND_Y,
                                                             height * 1.2));
  clutter_actor_add_constraint (calib_area->text_body_holder,
                                clutter_align_constraint_new (stage,
                                                              CLUTTER_ALIGN_X_AXIS,
                                                              .5));

  clutter_text_set_line_alignment (CLUTTER_TEXT (calib_area->helper_text_body),
                                   PANGO_ALIGN_CENTER);
  markup = g_strdup_printf ("<span foreground=\"white\"><big>%s</big></span>",
                            _(HELP_TEXT_MAIN));
  clutter_text_set_markup (CLUTTER_TEXT (calib_area->helper_text_body), markup);
  g_free (markup);

  /* set the error text */
  g_object_set (calib_area->error_text, "pivot-point", &anchor, NULL);

  clutter_actor_add_child (calib_area->action_layer, calib_area->error_text);
  height = clutter_actor_get_height (calib_area->helper_text_body);
  clutter_actor_add_constraint (calib_area->error_text,
                                clutter_bind_constraint_new (calib_area->text_title_holder,
                                                             CLUTTER_BIND_Y,
                                                             height * 3));
  clutter_actor_add_constraint (calib_area->error_text,
                                clutter_align_constraint_new (stage,
                                                              CLUTTER_ALIGN_X_AXIS,
                                                              .5));

  clutter_text_set_line_alignment (CLUTTER_TEXT (calib_area->error_text),
                                   PANGO_ALIGN_CENTER);
  markup = g_strdup_printf ("<span foreground=\"white\"><big>"
                            "<b>%s</b></big></span>",
                            ERROR_MESSAGE);
  clutter_text_set_markup (CLUTTER_TEXT (calib_area->error_text), markup);
  g_free (markup);

  clutter_actor_hide (calib_area->error_text);

  /* configure success image */
  success_content = clutter_image_new ();
  clutter_actor_set_content (calib_area->success_image,
                             success_content);
  g_object_unref (success_content);
  clutter_actor_add_child (stage, calib_area->success_image);
  clutter_actor_add_constraint (calib_area->success_image,
                                clutter_align_constraint_new (stage,
                                                              CLUTTER_ALIGN_BOTH,
                                                              .5));

  /* animate clock */
  calib_area->clock_timeline = clutter_property_transition_new ("angle");
  clutter_timeline_set_progress_mode (CLUTTER_TIMELINE (calib_area->clock_timeline),
                                      CLUTTER_LINEAR);
  clutter_timeline_set_duration (CLUTTER_TIMELINE (calib_area->clock_timeline),
                                 MAX_TIME);
  clutter_transition_set_animatable (calib_area->clock_timeline,
                                     CLUTTER_ANIMATABLE (calib_area->clock));
  clutter_transition_set_from (calib_area->clock_timeline, G_TYPE_FLOAT, .0);
  clutter_transition_set_to (calib_area->clock_timeline, G_TYPE_FLOAT, 360.0);
  clutter_timeline_set_repeat_count (CLUTTER_TIMELINE (calib_area->clock_timeline),
                                     -1);
  clutter_timeline_start (CLUTTER_TIMELINE (calib_area->clock_timeline));
  g_signal_connect (CLUTTER_TIMELINE (calib_area->clock_timeline),
                    "completed",
                    G_CALLBACK (on_timeout),
                    calib_area);

  g_signal_connect (stage,
                    "button-press-event",
                    G_CALLBACK (on_button_press_event),
                    calib_area);
  g_signal_connect (stage,
                    "key-release-event",
                    G_CALLBACK (on_key_release_event),
                    calib_area);
}
Example #7
0
static void
add_actor (ClutterActor *box,
           gint          left,
           gint          top,
           gint          width,
           gint          height)
{
  ClutterLayoutManager *layout;
  ClutterActor *rect, *text;
  ClutterColor color;

  clutter_color_from_hls (&color,
                          g_random_double_range (0.0, 360.0),
                          0.5,
                          0.5);
  color.alpha = 255;

  rect = clutter_actor_new ();
  clutter_actor_set_layout_manager (rect, clutter_bin_layout_new ());
  clutter_actor_set_background_color (rect, &color);
  clutter_actor_set_reactive (rect, TRUE);

  if (random_size)
    clutter_actor_set_size (rect,
                            g_random_int_range (40, 80),
                            g_random_int_range (40, 80));
  else
    clutter_actor_set_size (rect, 60, 60);

  clutter_actor_set_x_expand (rect, default_expand);
  clutter_actor_set_y_expand (rect, default_expand);

  if (!default_expand)
    {
      clutter_actor_set_x_align (rect, CLUTTER_ACTOR_ALIGN_CENTER);
      clutter_actor_set_y_align (rect, CLUTTER_ACTOR_ALIGN_CENTER);
    }

  if (random_align)
    {
      clutter_actor_set_x_align (rect, g_random_int_range (0, 3));
      clutter_actor_set_y_align (rect, g_random_int_range (0, 3));
    }

  text = clutter_text_new_with_text ("Sans 8px", NULL);
  clutter_text_set_line_alignment (CLUTTER_TEXT (text),
                                   PANGO_ALIGN_CENTER);
  clutter_actor_add_child (rect, text);

  g_signal_connect (rect, "button-release-event",
                    G_CALLBACK (button_release_cb), NULL);
  g_signal_connect (rect, "notify::x-expand",
                    G_CALLBACK (changed_cb), text);
  g_signal_connect (rect, "notify::y-expand",
                    G_CALLBACK (changed_cb), text);
  g_signal_connect (rect, "notify::x-align",
                    G_CALLBACK (changed_cb), text);
  g_signal_connect (rect, "notify::y-align",
                    G_CALLBACK (changed_cb), text);

  layout = clutter_actor_get_layout_manager (box);
  if (use_box)
    clutter_actor_add_child (box, rect);
  else
    clutter_grid_layout_attach (CLUTTER_GRID_LAYOUT (layout), rect,
                                left, top, width, height);
  changed_cb (rect, NULL, text);
}
Example #8
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;
}
int
main (int argc, char *argv[])
{
  ClutterActor *stage;
  ClutterLayoutManager *layout;
  ClutterActor *box;
  ClutterActor *rect;
  ClutterActor *text;
  ClutterState *transitions;

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

  stage = clutter_stage_get_default ();
  clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
  clutter_stage_set_title (CLUTTER_STAGE (stage), "btn");

  layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_FILL,
                                   CLUTTER_BIN_ALIGNMENT_FILL);

  box = clutter_box_new (layout);
  clutter_actor_set_position (box, 25, 25);
  clutter_actor_set_reactive (box, TRUE);
  clutter_actor_set_size (box, 100, 30);

  /* background for the button */
  rect = clutter_rectangle_new_with_color (&yellow);
  clutter_container_add_actor (CLUTTER_CONTAINER (box), rect);

  /* text for the button */
  text = clutter_text_new_full ("Sans 10pt", "Hover me", &white);
  clutter_text_set_line_alignment (CLUTTER_TEXT (text), PANGO_ALIGN_CENTER);

  /*
   * NB don't set the height, so the actor assumes the height of the text;
   * then when added to the bin layout, it gets centred on it;
   * also if you don't set the width, the layout goes gets really wide;
   * the 10pt text fits inside the 30px height of the rectangle
   */
  clutter_actor_set_width (text, 100);
  clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout),
                          text,
                          CLUTTER_BIN_ALIGNMENT_CENTER,
                          CLUTTER_BIN_ALIGNMENT_CENTER);

  /* animations */
  transitions = clutter_state_new ();
  clutter_state_set (transitions, NULL, "fade-out",
                     box, "opacity", CLUTTER_LINEAR, 180,
                     NULL);

 /*
  * NB you can't use an easing mode where alpha > 1.0 if you're
  * animating to a value of 255, as the value you're animating
  * to will possibly go > 255
  */
  clutter_state_set (transitions, NULL, "fade-in",
                     box, "opacity", CLUTTER_LINEAR, 255,
                     NULL);

  clutter_state_set_duration (transitions, NULL, NULL, 50);

  clutter_state_warp_to_state (transitions, "fade-out");

  g_signal_connect (box,
                    "enter-event",
                    G_CALLBACK (_pointer_enter_cb),
                    transitions);

  g_signal_connect (box,
                    "leave-event",
                    G_CALLBACK (_pointer_leave_cb),
                    transitions);

  /* bind the stage size to the box size + 50px in each axis */
  clutter_actor_add_constraint (stage, clutter_bind_constraint_new (box, CLUTTER_BIND_HEIGHT, 50.0));
  clutter_actor_add_constraint (stage, clutter_bind_constraint_new (box, CLUTTER_BIND_WIDTH, 50.0));

  clutter_container_add_actor (CLUTTER_CONTAINER (stage), box);

  clutter_actor_show (stage);

  clutter_main ();

  g_object_unref (transitions);

  return 0;
}
Example #10
0
static gboolean
do_tests (CallbackData *data)
{
  PangoFontDescription *fd;
  static const ClutterColor red = { 0xff, 0x00, 0x00, 0xff };
  PangoAttrList *attr_list, *attr_list_copy;
  PangoAttribute *attr;

  /* TEST 1: change the text */
  clutter_text_set_text (CLUTTER_TEXT (data->label), "Counter 0");
  pango_layout_set_text (data->test_layout, "Counter 0", -1);
  g_assert (check_result (data, "Change text", TRUE) == FALSE);

  /* TEST 2: change a single character */
  clutter_text_set_text (CLUTTER_TEXT (data->label), "Counter 1");
  pango_layout_set_text (data->test_layout, "Counter 1", -1);
  g_assert (check_result (data, "Change a single character", TRUE) == FALSE);

  /* TEST 3: move the label */
  clutter_actor_set_position (data->label, 10, 0);
  g_assert (check_result (data, "Move the label", FALSE) == FALSE);

  /* TEST 4: change the font */
  clutter_text_set_font_name (CLUTTER_TEXT (data->label), "Serif 15");
  fd = pango_font_description_from_string ("Serif 15");
  pango_layout_set_font_description (data->test_layout, fd);
  pango_font_description_free (fd);
  g_assert (check_result (data, "Change the font", TRUE) == FALSE);

  /* TEST 5: change the color */
  clutter_text_set_color (CLUTTER_TEXT (data->label), &red);
  g_assert (check_result (data, "Change the color", FALSE) == FALSE);

  /* TEST 6: change the attributes */
  attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
  attr->start_index = 0;
  attr->end_index = 2;
  attr_list = pango_attr_list_new ();
  pango_attr_list_insert (attr_list, attr);
  attr_list_copy = pango_attr_list_copy (attr_list);
  clutter_text_set_attributes (CLUTTER_TEXT (data->label), attr_list);
  pango_layout_set_attributes (data->test_layout, attr_list_copy);
  pango_attr_list_unref (attr_list_copy);
  pango_attr_list_unref (attr_list);
  g_assert (check_result (data, "Change the attributes", TRUE) == FALSE);

  /* TEST 7: change the text again */
  clutter_text_set_attributes (CLUTTER_TEXT (data->label), NULL);
  clutter_text_set_text (CLUTTER_TEXT (data->label), long_text);
  pango_layout_set_attributes (data->test_layout, NULL);
  pango_layout_set_text (data->test_layout, long_text, -1);
  g_assert (check_result (data, "Change the text again", TRUE) == FALSE);

  /* TEST 8: enable markup */
  clutter_text_set_use_markup (CLUTTER_TEXT (data->label), TRUE);
  pango_layout_set_markup (data->test_layout, long_text, -1);
  g_assert (check_result (data, "Enable markup", TRUE) == FALSE);

  /* This part can't be a test because Clutter won't restrict the
     width if wrapping and ellipsizing is disabled so the extents will
     be different, but we still want to do it for the later tests */
  clutter_actor_set_width (data->label, 200);
  pango_layout_set_width (data->test_layout, 200 * PANGO_SCALE);
  /* Force a redraw so that changing the width won't affect the
     results */
  force_redraw (data);

  /* TEST 9: enable ellipsize */
  clutter_text_set_ellipsize (CLUTTER_TEXT (data->label),
			       PANGO_ELLIPSIZE_END);
  pango_layout_set_ellipsize (data->test_layout, PANGO_ELLIPSIZE_END);
  g_assert (check_result (data, "Enable ellipsize", TRUE) == FALSE);
  clutter_text_set_ellipsize (CLUTTER_TEXT (data->label),
			       PANGO_ELLIPSIZE_NONE);
  pango_layout_set_ellipsize (data->test_layout, PANGO_ELLIPSIZE_NONE);
  force_redraw (data);

  /* TEST 10: enable line wrap */
  clutter_text_set_line_wrap (CLUTTER_TEXT (data->label), TRUE);
  pango_layout_set_wrap (data->test_layout, PANGO_WRAP_WORD);
  g_assert (check_result (data, "Enable line wrap", TRUE) == FALSE);

  /* TEST 11: change wrap mode
   * FIXME - broken
   */
  clutter_text_set_line_wrap_mode (CLUTTER_TEXT (data->label),
				    PANGO_WRAP_CHAR);
  pango_layout_set_wrap (data->test_layout, PANGO_WRAP_CHAR);
  g_assert (check_result (data, "Change wrap mode", TRUE) == FALSE);

  /* TEST 12: enable justify */
  clutter_text_set_justify (CLUTTER_TEXT (data->label), TRUE);
  pango_layout_set_justify (data->test_layout, TRUE);
  /* Pango appears to have a bug which means that you can't change the
     justification after setting the text but this fixes it.
     See http://bugzilla.gnome.org/show_bug.cgi?id=551865 */
  pango_layout_context_changed (data->test_layout);
  g_assert (check_result (data, "Enable justify", TRUE) == FALSE);

  /* TEST 13: change alignment */
  clutter_text_set_line_alignment (CLUTTER_TEXT (data->label),
                                   PANGO_ALIGN_RIGHT);
  pango_layout_set_alignment (data->test_layout, PANGO_ALIGN_RIGHT);
  g_assert (check_result (data, "Change alignment", TRUE) == FALSE);

  clutter_main_quit ();

  return FALSE;
}