Example #1
0
static void
mex_tile_style_changed_cb (MexTile *self, MxStyleChangedFlags flags)
{
  MexTilePrivate *priv = self->priv;
  MxBorderImage *image;

  if (priv->header_padding)
    {
      g_boxed_free (MX_TYPE_PADDING, priv->header_padding);
      priv->header_padding = NULL;
    }

  if (priv->header_background_color)
    {
      g_boxed_free (CLUTTER_TYPE_COLOR, priv->header_background_color);
      priv->header_background_color = NULL;
    }

  mx_stylable_get (MX_STYLABLE (self),
                   "x-mex-header-background", &image,
                   "x-mex-header-background-color", &priv->header_background_color,
                   "x-mex-header-padding", &priv->header_padding,
                   NULL);

  mx_stylable_apply_clutter_text_attributes (MX_STYLABLE (self),
                                             CLUTTER_TEXT (priv->label));

  mx_stylable_apply_clutter_text_attributes (MX_STYLABLE (self),
                                             CLUTTER_TEXT (priv->secondary_label));

  if (image && image->uri)
    {
      CoglObject *background;

      background =
        mx_texture_cache_get_cogl_texture (mx_texture_cache_get_default (),
                                           image->uri);
      cogl_material_set_layer (priv->material, 0, background);
    }
  else
    {
      if (cogl_material_get_n_layers (priv->material))
        cogl_material_remove_layer (priv->material, 0);
    }

  if (image)
    g_boxed_free (MX_TYPE_BORDER_IMAGE, image);

  if (priv->icon1)
    mx_stylable_style_changed (MX_STYLABLE (priv->icon1), flags);

  if (priv->icon2)
    mx_stylable_style_changed (MX_STYLABLE (priv->icon2), flags);

  clutter_actor_queue_redraw (CLUTTER_ACTOR (self));
}
Example #2
0
static void
mx_scroll_view_style_changed (MxWidget *widget, MxStyleChangedFlags flags)
{
  MxScrollViewPrivate *priv = MX_SCROLL_VIEW (widget)->priv;

  mx_stylable_style_changed (MX_STYLABLE (priv->hscroll), flags);
  mx_stylable_style_changed (MX_STYLABLE (priv->vscroll), flags);

  mx_stylable_get (MX_STYLABLE (widget),
                   "x-mx-scrollbar-width", &priv->scrollbar_width,
                   "x-mx-scrollbar-height", &priv->scrollbar_height,
                   NULL);
}
static void
mx_scroll_bar_style_changed (MxWidget *widget, MxStyleChangedFlags flags)
{
  MxScrollBarPrivate *priv = MX_SCROLL_BAR (widget)->priv;

  mx_stylable_get (MX_STYLABLE (widget),
                   "mx-min-size", &priv->handle_min_size,
                   NULL);

  mx_stylable_style_changed ((MxStylable *) priv->bw_stepper, flags);
  mx_stylable_style_changed ((MxStylable *) priv->fw_stepper, flags);
  mx_stylable_style_changed ((MxStylable *) priv->trough, flags);
  mx_stylable_style_changed ((MxStylable *) priv->handle, flags);

}
Example #4
0
File: mx-menu.c Project: jku/mx
static void
mx_menu_style_changed (MxMenu              *menu,
                       MxStyleChangedFlags  flags)
{
  MxMenuPrivate *priv = menu->priv;
  gint i;

  for (i = 0; i < priv->children->len; i++)
    {
      MxMenuChild *child;

      child = &g_array_index (priv->children, MxMenuChild, i);

      mx_stylable_style_changed (MX_STYLABLE (child->box), flags);
    }
}
Example #5
0
static void
mx_combo_box_style_changed (MxComboBox *combo, MxStyleChangedFlags flags)
{
  MxBorderImage *marker_filename;
  gint spacing;

  MxComboBoxPrivate *priv = combo->priv;

  mx_stylable_get (MX_STYLABLE (combo),
                   "x-mx-spacing", &spacing,
                   "x-mx-marker-image", &marker_filename,
                   NULL);

  if (spacing != priv->spacing)
    priv->spacing = spacing;

  if (priv->marker)
    {
      clutter_actor_destroy (priv->marker);
      priv->marker = NULL;
    }

  if (marker_filename)
    {
      MxTextureCache *cache = mx_texture_cache_get_default ();
      priv->marker = (ClutterActor *)
        mx_texture_cache_get_texture (cache, marker_filename->uri);
      if (priv->marker)
        clutter_actor_add_child (CLUTTER_ACTOR (combo), priv->marker);

      g_boxed_free (MX_TYPE_BORDER_IMAGE, marker_filename);
    }

  mx_stylable_apply_clutter_text_attributes (MX_STYLABLE (combo),
                                             CLUTTER_TEXT (combo->priv->label));

  /* make sure the popup is also up-to-date */
  mx_stylable_style_changed (MX_STYLABLE (mx_widget_get_menu (MX_WIDGET (combo))),
                             flags | MX_STYLE_CHANGED_FORCE);

  clutter_actor_queue_relayout (CLUTTER_ACTOR (combo));
}
Example #6
0
/**
 * mx_toolbar_set_has_close_button:
 * @toolbar: A #MxToolbar
 * @has_close_button: #TRUE if a close button should be displayed
 *
 * Set the #MxToolbar:has-close-button property
 *
 */
void
mx_toolbar_set_has_close_button (MxToolbar *toolbar,
                                 gboolean   has_close_button)
{
  MxToolbarPrivate *priv;

  g_return_if_fail (MX_IS_TOOLBAR (toolbar));

  priv = toolbar->priv;

  if (priv->has_close_button != has_close_button)
    {
      priv->has_close_button = has_close_button;

      if (!has_close_button)
        {
          if (priv->close_button)
            {
              clutter_actor_destroy (priv->close_button);
              priv->close_button = NULL;
            }
        }
      else
        {
          priv->close_button = mx_button_new ();
          clutter_actor_set_name (priv->close_button, "close-button");
          clutter_actor_add_child (CLUTTER_ACTOR (toolbar),
                                   priv->close_button);
          g_signal_connect (priv->close_button, "clicked",
                            G_CALLBACK (close_button_click_cb), toolbar);
          mx_stylable_style_changed (MX_STYLABLE (priv->close_button),
                                     MX_STYLE_CHANGED_FORCE);
        }

      clutter_actor_queue_relayout (CLUTTER_ACTOR (toolbar));

      g_object_notify (G_OBJECT (toolbar), "has-close-button");
    }
}
Example #7
0
static void
mnb_spinner_constructed (GObject *self)
{
  MnbSpinnerPrivate *priv = MNB_SPINNER (self)->priv;
  MxWidget          *widget = MX_WIDGET (self);
  ClutterTexture    *background;
  ClutterTimeline   *timeline;

  /*
   * Mx does not seem to load the style info until the first show, but we want
   * to get hold of the background asset here to work out the frame count, so
   * we need to force the style loading.
   *
   * NB: mx_widget_ensure_style() does not work here, because the MxWidget
   *     is_style_dirty flag is cleared at this point.
   */
  mx_stylable_style_changed (MX_STYLABLE (widget), MX_STYLE_CHANGED_FORCE);

  if ((background = (ClutterTexture *) mx_widget_get_background_image (widget)))
    {
      gint  tx_w, tx_h;
      guint duration;

      if (!CLUTTER_IS_TEXTURE (background))
        {
          g_critical ("Expected ClutterTexture, but got %s",
                      G_OBJECT_TYPE_NAME (background));
          return;
        }

      /*
       * The background texture is a strip of squares making up the individual
       * frames in the animation, so the width matches the height of the
       * texture.
       */
      clutter_texture_get_base_size (background, &tx_w, &tx_h);

      priv->n_frames = tx_w / tx_h;

      if (tx_w % tx_h)
        g_warning (G_STRLOC ": Expected texture size %d x %d, got %d x %d",
                   tx_h * priv->n_frames, tx_h, tx_w, tx_h);

      /*
       * Setup a looped timeline with a marker that fires everytime we should
       * advance to a new frame.
       *
       * Assume the whole animation is to last 1s.
       */
      duration = 1000/ priv->n_frames;

      timeline = priv->timeline = clutter_timeline_new (duration);

      clutter_timeline_set_loop (timeline, TRUE);
      clutter_timeline_add_marker_at_time (timeline, "next", duration);
      clutter_timeline_stop (timeline);

      g_signal_connect (timeline, "marker-reached",
                        G_CALLBACK (mnb_spinner_marker_reached_cb),
                        self);
    }
  else
    g_warning ("%s did not have background-image set in style !!!",
               G_OBJECT_TYPE_NAME (self));
}
Example #8
0
File: mx-toggle.c Project: jlec/mx
static void
mx_toggle_style_changed (MxToggle *toggle)
{
  mx_stylable_style_changed (MX_STYLABLE (toggle->priv->handle), 0);
}
Example #9
0
static void
mx_tooltip_update_position (MxTooltip *tooltip)
{
  MxTooltipPrivate *priv = tooltip->priv;
  ClutterGeometry tip_area = *tooltip->priv->tip_area;
  gfloat tooltip_w, tooltip_h, tooltip_x, tooltip_y, abs_x, abs_y;
  ClutterActor *stage, *parent;
  gfloat stage_w, stage_h, parent_w, parent_h;
  MxWindow *window;

  /* If there's no stage, bail out - there's nothing we can do */
  stage = clutter_actor_get_stage ((ClutterActor *) tooltip);
  if (!stage)
    return;

  /* find out the stage's size to keep the tooltip on-screen */
  clutter_actor_get_size (stage, &stage_w, &stage_h);


  parent = clutter_actor_get_parent ((ClutterActor *) tooltip);
  clutter_actor_get_transformed_position (parent, &abs_x, &abs_y);
  clutter_actor_get_size (parent, &parent_w, &parent_h);

  /* ensure the tooltip with is not fixed size */
  clutter_actor_set_size ((ClutterActor*) tooltip, -1, -1);

  /* if no area set, just position ourselves top left */
  if (!priv->tip_area)
    {
      clutter_actor_set_position ((ClutterActor*) tooltip, abs_x, abs_y);
      return;
    }

  /* check if we're in a window and if there's rotation */
  window = mx_window_get_for_stage (CLUTTER_STAGE (stage));
  if (window)
    {
      MxWindowRotation rotation;
      gfloat old_x;

      g_object_get (G_OBJECT (window),
                    "window-rotation", &rotation,
                    NULL);

      if (rotation == MX_WINDOW_ROTATION_90
          || rotation == MX_WINDOW_ROTATION_270)
        {
          /* swap stage width and height */
          old_x = stage_w;
          stage_w = stage_h;
          stage_h = old_x;

          /* swap tip area width and height */
          old_x = tip_area.width;
          tip_area.width = tip_area.height;
          tip_area.height = old_x;
        }

      switch (rotation)
        {
        case MX_WINDOW_ROTATION_90:
          /* absolute position */
          old_x = abs_x;
          abs_x = abs_y;
          abs_y = stage_h - old_x;

          /* tip area */
          old_x = tip_area.x;
          tip_area.x = tip_area.y;
          tip_area.y = stage_h - old_x - tip_area.height;
          break;

        case MX_WINDOW_ROTATION_180:
          tip_area.x = stage_w - tip_area.x - tip_area.width;
          tip_area.y = stage_h - tip_area.y - tip_area.height;

          abs_x = stage_w - abs_x;
          abs_y = stage_h - abs_y;
          break;

        case MX_WINDOW_ROTATION_270:
          /* absolute position */
          old_x = abs_x;
          abs_x = stage_w - abs_y;
          abs_y = old_x;

          /* tip area */
          old_x = tip_area.x;
          tip_area.x = stage_w - tip_area.y - tip_area.width;
          tip_area.y = old_x;
          break;

        default:
          break;
        }
    }

  /* we need to have a style in case there are padding values to take into
   * account when calculating width/height */
  mx_stylable_style_changed (MX_STYLABLE (tooltip), MX_STYLE_CHANGED_FORCE);

  /* find out the tooltip's size */
  clutter_actor_get_size ((ClutterActor*) tooltip, &tooltip_w, &tooltip_h);

  /* attempt to place the tooltip */
  /* This special-cases the 4 window rotations, as doing this with
   * arbitrary rotations would massively complicate the code for
   * little benefit.
   */
  priv->actor_below = FALSE;

  tooltip_x = (int)(tip_area.x + (tip_area.width / 2) -
                    (tooltip_w / 2));
  tooltip_y = (int)(tip_area.y + tip_area.height);

  /* Keep on the screen vertically */
  if (tooltip_y + tooltip_h > stage_h)
    {
      priv->actor_below = TRUE;

      /* re-query size as may have changed */
      clutter_actor_get_preferred_height ((ClutterActor*) tooltip,
                                          -1, NULL, &tooltip_h);
      tooltip_y = MAX (0, tip_area.y - tooltip_h);
    }


  /* Keep on the screen horizontally */
  if (tooltip_w > stage_w)
    {
      tooltip_x = 0;
      clutter_actor_set_width ((ClutterActor*) tooltip, stage_w);
    }
  else if (tooltip_x < 0)
    tooltip_x = 0;
  else if (tooltip_x + tooltip_w > stage_w)
    tooltip_x = (int)(stage_w) - tooltip_w;

  gfloat pos_x, pos_y;

  pos_x = tooltip_x - abs_x;
  pos_y = tooltip_y - abs_y;

  /* calculate the arrow offset */
  priv->arrow_offset = tip_area.x + tip_area.width / 2 - tooltip_x;
  clutter_actor_set_position ((ClutterActor*) tooltip, pos_x, pos_y);
}