Ejemplo n.º 1
0
static void
glide_theme_preview_actor_update_texture (GlideThemePreviewActor *preview)
{
    guint width, height;
    cairo_t *cr;

    clutter_cairo_texture_get_surface_size (CLUTTER_CAIRO_TEXTURE (preview->priv->preview_texture), &width, &height);
    cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (preview->priv->preview_texture));
    glide_theme_preview (preview->priv->theme, cr, width, height);
    cairo_destroy (cr);
}
static void
empathy_rounded_rectangle_paint (EmpathyRoundedRectangle *self)
{
  guint width, height;
  guint tmp_alpha;
  cairo_t *cr;

#define RADIUS (height / 8.)

  clutter_cairo_texture_get_surface_size (CLUTTER_CAIRO_TEXTURE (self),
      &width, &height);

  /* compute the composited opacity of the actor taking into
   * account the opacity of the color set by the user */
  tmp_alpha = clutter_actor_get_paint_opacity (CLUTTER_ACTOR (self))
            * self->priv->border_color.alpha
            / 255;

  cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (self));

  cairo_set_source_rgba (cr,
      self->priv->border_color.red,
      self->priv->border_color.green,
      self->priv->border_color.blue,
      tmp_alpha);

  cairo_set_line_width (cr, self->priv->border_width);

  cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
  cairo_paint (cr);
  cairo_set_operator (cr, CAIRO_OPERATOR_OVER);

  cairo_new_sub_path (cr);
  cairo_arc (cr, width - RADIUS, RADIUS, RADIUS,
      -M_PI/2.0, 0);
  cairo_arc (cr, width - RADIUS, height - RADIUS, RADIUS,
      0, M_PI/2.0);
  cairo_arc (cr, RADIUS, height - RADIUS, RADIUS,
      M_PI/2.0, M_PI);
  cairo_arc (cr, RADIUS, RADIUS, RADIUS,
      M_PI, -M_PI/2.0);
  cairo_close_path (cr);

  cairo_stroke (cr);
  cairo_destroy (cr);

#undef RADIUS
}
Ejemplo n.º 3
0
static void
empathy_rounded_rectangle_update_surface_size (EmpathyRoundedRectangle *self)
{
    clutter_cairo_texture_set_surface_size (CLUTTER_CAIRO_TEXTURE (self),
                                            self->priv->width + self->priv->border_width,
                                            self->priv->height + self->priv->border_width);
}
Ejemplo n.º 4
0
static void
pkg_graph_2d_allocation_changed (PkgGraph2d             *graph,
                                 const ClutterActorBox  *box,
                                 ClutterAllocationFlags  flags)
{
	PkgGraph2dPrivate *priv = graph->priv;
	gdouble x0, x1, x2;
	gdouble y0, y1, y2;

	clutter_actor_set_size(priv->texture,
	                       clutter_actor_box_get_width(box),
	                       clutter_actor_box_get_height(box));
	clutter_cairo_texture_set_surface_size(CLUTTER_CAIRO_TEXTURE(priv->texture),
	                                       clutter_actor_box_get_width(box),
	                                       clutter_actor_box_get_height(box));

	if (priv->renderer) {
		pkg_graph_2d_place_child(graph, PKG_RENDERER(priv->renderer));
		pkg_renderer_clear(PKG_RENDERER(priv->renderer));
	}

	pkg_graph_2d_get_primary_extents(graph, &x0, &x1, &x2, &y0, &y1, &y2);
	pkg_scale_set_pixel_range(priv->x_scale, x1, x2);
	pkg_scale_set_pixel_range(priv->y_scale, y2, y1);
	pkg_graph_2d_paint(graph);
}
Ejemplo n.º 5
0
static void
update_background (ClutterActor       *tex,
                   const ClutterColor *color,
                   gfloat              width,
                   gfloat              height)
{
  cairo_t *cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (tex));
  cairo_pattern_t *pat;
  gfloat x, y;

#define BG_ROUND_RADIUS         12

  x = y = 0;

  cairo_move_to (cr, BG_ROUND_RADIUS, y);
  cairo_line_to (cr, width - BG_ROUND_RADIUS, y);
  cairo_curve_to (cr, width, y, width, y, width, BG_ROUND_RADIUS);
  cairo_line_to (cr, width, height - BG_ROUND_RADIUS);
  cairo_curve_to (cr, width, height, width, height, width - BG_ROUND_RADIUS, height);
  cairo_line_to (cr, BG_ROUND_RADIUS, height);
  cairo_curve_to (cr, x, height, x, height, x, height - BG_ROUND_RADIUS);
  cairo_line_to (cr, x, BG_ROUND_RADIUS);
  cairo_curve_to (cr, x, y, x, y, BG_ROUND_RADIUS, y);

  cairo_close_path (cr);

  clutter_cairo_set_source_color (cr, color);
  cairo_stroke (cr);

  x += 4;
  y += 4;
  width -= 4;
  height -= 4;

  cairo_move_to (cr, BG_ROUND_RADIUS, y);
  cairo_line_to (cr, width - BG_ROUND_RADIUS, y);
  cairo_curve_to (cr, width, y, width, y, width, BG_ROUND_RADIUS);
  cairo_line_to (cr, width, height - BG_ROUND_RADIUS);
  cairo_curve_to (cr, width, height, width, height, width - BG_ROUND_RADIUS, height);
  cairo_line_to (cr, BG_ROUND_RADIUS, height);
  cairo_curve_to (cr, x, height, x, height, x, height - BG_ROUND_RADIUS);
  cairo_line_to (cr, x, BG_ROUND_RADIUS);
  cairo_curve_to (cr, x, y, x, y, BG_ROUND_RADIUS, y);

  cairo_close_path (cr);

  pat = cairo_pattern_create_linear (0, 0, 0, height);
  cairo_pattern_add_color_stop_rgba (pat, 1, .85, .85, .85, 1);
  cairo_pattern_add_color_stop_rgba (pat, .95, 1, 1, 1, 1);
  cairo_pattern_add_color_stop_rgba (pat, .05, 1, 1, 1, 1);
  cairo_pattern_add_color_stop_rgba (pat, 0, .85, .85, .85, 1);

  cairo_set_source (cr, pat);
  cairo_fill (cr);

  cairo_pattern_destroy (pat);
  cairo_destroy (cr);

#undef BG_ROUND_RADIUS
}
Ejemplo n.º 6
0
static void
draw_shadow (BixiMarker *marker,
   gint radius)
{
  BixiMarkerPrivate *priv = marker->priv;
  ClutterActor *shadow = NULL;
  cairo_t *cr;

  shadow = clutter_cairo_texture_new (radius * 2, radius * 2);
  cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (shadow));

  draw_box (cr, radius);

  cairo_set_source_rgba (cr, 0, 0, 0, 0.25);
  cairo_fill (cr);

  cairo_destroy (cr);

  clutter_actor_set_position (shadow, 3, 3);

  clutter_container_add_actor (CLUTTER_CONTAINER (marker), shadow);

  if (priv->shadow != NULL)
    {
      clutter_container_remove_actor (CLUTTER_CONTAINER (marker),
          priv->shadow);
      g_object_unref (priv->shadow);
    }

  priv->shadow = g_object_ref (shadow);
}
Ejemplo n.º 7
0
static void
clutter_cairo_texture_get_property (GObject    *object,
                                    guint       prop_id,
                                    GValue     *value,
                                    GParamSpec *pspec)
{
  ClutterCairoTexturePrivate *priv;

  priv = CLUTTER_CAIRO_TEXTURE (object)->priv;

  switch (prop_id)
    {
    case PROP_SURFACE_WIDTH:
      g_value_set_uint (value, priv->width);
      break;

    case PROP_SURFACE_HEIGHT:
      g_value_set_uint (value, priv->height);
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}
Ejemplo n.º 8
0
static void
draw_background (BixiMarker *marker,
    gint radius)
{
  BixiMarkerPrivate *priv = marker->priv;
  ClutterActor *bg = NULL;
  ClutterColor color;
  ClutterColor darker_color;
  gboolean highlighted = FALSE;
  guint line_width = 1;
  cairo_t *cr;

  bg = clutter_cairo_texture_new (radius * 2, radius * 2);
  cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (bg));
  color = *champlain_marker_get_color (CHAMPLAIN_MARKER (marker));

  if (priv->value == 0)
    color.alpha = 128;

  g_object_get (marker, "highlighted", &highlighted, NULL);
  if (highlighted)
    {
#if CHAMPLAIN_CHECK_VERSION(0, 4, 1)
      color = *champlain_marker_get_highlight_color ();
#else
      line_width *= 3;
#endif
    }

  clutter_color_darken (&color, &darker_color);
  draw_box (cr, radius);

  cairo_set_source_rgba (cr,
      color.red / 255.0,
      color.green / 255.0,
      color.blue / 255.0,
      color.alpha / 255.0);
  cairo_fill_preserve (cr);

  cairo_set_line_width (cr, line_width);
  cairo_set_source_rgba (cr,
      darker_color.red / 255.0,
      darker_color.green / 255.0,
      darker_color.blue / 255.0,
      darker_color.alpha / 255.0);
  cairo_stroke (cr);
  cairo_destroy (cr);

  clutter_container_add_actor (CLUTTER_CONTAINER (marker), bg);

  if (priv->background != NULL)
    {
      clutter_container_remove_actor (CLUTTER_CONTAINER (marker),
          priv->background);
      g_object_unref (priv->background);
    }

  priv->background = g_object_ref (bg);
}
Ejemplo n.º 9
0
static void
shell_drawing_area_init (ShellDrawingArea *area)
{
  area->priv = G_TYPE_INSTANCE_GET_PRIVATE (area, SHELL_TYPE_DRAWING_AREA,
                                            ShellDrawingAreaPrivate);
  area->priv->texture = CLUTTER_CAIRO_TEXTURE (clutter_cairo_texture_new (1, 1));
  clutter_container_add_actor (CLUTTER_CONTAINER (area), CLUTTER_ACTOR (area->priv->texture));
}
Ejemplo n.º 10
0
void
empathy_rounded_rectangle_set_border_color (EmpathyRoundedRectangle *self,
        const ClutterColor *color)
{
    self->priv->border_color = *color;

    clutter_cairo_texture_invalidate (CLUTTER_CAIRO_TEXTURE (self));
}
Ejemplo n.º 11
0
void
empathy_rounded_rectangle_set_border_width (EmpathyRoundedRectangle *self,
        guint border_width)
{
    self->priv->border_width = border_width;

    empathy_rounded_rectangle_update_surface_size (self);
    clutter_cairo_texture_invalidate (CLUTTER_CAIRO_TEXTURE (self));
}
Ejemplo n.º 12
0
/**
 * nemo_preview_create_rounded_background:
 *
 * Returns: (transfer none): a #ClutterActor
 */
ClutterActor *
nemo_preview_create_rounded_background (void)
{
  ClutterActor *retval;

  retval = clutter_cairo_texture_new (1, 1);
  clutter_cairo_texture_set_auto_resize (CLUTTER_CAIRO_TEXTURE (retval), TRUE);

  g_signal_connect (retval, "draw",
                    G_CALLBACK (rounded_background_draw_cb), NULL);

  return retval;
}
Ejemplo n.º 13
0
static void
clutter_cairo_texture_get_preferred_height (ClutterActor *actor,
                                            gfloat        for_width,
                                            gfloat       *min_height,
                                            gfloat       *natural_height)
{
  ClutterCairoTexturePrivate *priv = CLUTTER_CAIRO_TEXTURE (actor)->priv;

  if (min_height)
    *min_height = 0;

  if (natural_height)
    *natural_height = (gfloat) priv->height;
}
Ejemplo n.º 14
0
	/*
		Updates the window controls based on whether the stage is fullscreen
	*/
	void WindowPanel::draw_window_controls() {
		clutter_cairo_texture_clear(CLUTTER_CAIRO_TEXTURE(fullscreen_button_));

		if (clutter_stage_get_fullscreen(CLUTTER_STAGE(clutter_stage_get_default()))) {
			// Stage is fullscreen
			cairo_t * context = clutter_cairo_texture_create(CLUTTER_CAIRO_TEXTURE(fullscreen_button_));

			cairo_rectangle(context, 1.0, 1.0, 16.0, 14.0);
			cairo_rectangle(context, 4.0, 6.0, 10.0, 6.0);
			cairo_set_source_rgb(context, 1.0, 1.0, 1.0);
			cairo_set_fill_rule(context, CAIRO_FILL_RULE_EVEN_ODD);
			cairo_fill_preserve(context);
			cairo_set_line_width(context, 1.0);
			cairo_set_source_rgb(context, 0.0, 0.0, 0.0);
			cairo_stroke(context);

			cairo_destroy(context);

			clutter_actor_show(close_button_);
		} else {
			// Stage is windowed
			cairo_t * context = clutter_cairo_texture_create(CLUTTER_CAIRO_TEXTURE(fullscreen_button_));

			cairo_rectangle(context, 1.0, 1.0, 16.0, 14.0);
			cairo_rectangle(context, 4.0, 4.0, 10.0, 8.0);
			cairo_set_source_rgb(context, 1.0, 1.0, 1.0);
			cairo_set_fill_rule(context, CAIRO_FILL_RULE_EVEN_ODD);
			cairo_fill_preserve(context);
			cairo_set_line_width(context, 1.0);
			cairo_set_source_rgb(context, 0.0, 0.0, 0.0);
			cairo_stroke(context);

			cairo_destroy(context);

			clutter_actor_hide(close_button_);
		}
	}
Ejemplo n.º 15
0
static void
shell_arrow_redraw (ShellArrow *self)
{
  cairo_t *cr;
  guint width, height;

  g_object_get (G_OBJECT (self), "surface-width", &width,
                                 "surface-height", &height,
                                 NULL);

  if (width == 0)
    return;

  cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (self));

  cairo_set_source_rgb (cr, 1, 1, 1);

  switch (self->priv->direction)
  {
    case GTK_ARROW_RIGHT:
      cairo_move_to (cr, 0, 0);
      cairo_line_to (cr, width, height*0.5);
      cairo_line_to (cr, 0, height);
      break;
    case GTK_ARROW_LEFT:
      cairo_move_to (cr, width, 0);
      cairo_line_to (cr, 0, height*0.5);
      cairo_line_to (cr, width, height);
      break;
    case GTK_ARROW_UP:
      cairo_move_to (cr, 0, height);
      cairo_line_to (cr, width*0.5, 0);
      cairo_line_to (cr, width, height);
      break;
    case GTK_ARROW_DOWN:
      cairo_move_to (cr, 0, 0);
      cairo_line_to (cr, width*0.5, height);
      cairo_line_to (cr, width, height);
      break;
    case GTK_ARROW_NONE:
    default:
      break;
  }

  cairo_close_path (cr);
  cairo_fill (cr);

  cairo_destroy (cr);
}
Ejemplo n.º 16
0
static void
on_box_allocation_changed (ClutterActor           *box,
                           const ClutterActorBox  *allocation,
                           ClutterAllocationFlags  flags,
                           ClutterActor           *background)
{
  gfloat new_width, new_height;

  clutter_actor_box_get_size (allocation, &new_width, &new_height);
  clutter_cairo_texture_set_surface_size (CLUTTER_CAIRO_TEXTURE (background),
                                          new_width,
                                          new_height);

  update_background (background, &bg_color, new_width, new_height);
}
ClutterActor *
empathy_rounded_rectangle_new (guint width,
    guint height)
{
  ClutterActor *self;

  self = CLUTTER_ACTOR (g_object_new (EMPATHY_TYPE_ROUNDED_RECTANGLE, NULL));

  clutter_cairo_texture_set_surface_size (CLUTTER_CAIRO_TEXTURE (self),
      width, height);

  empathy_rounded_rectangle_paint (EMPATHY_ROUNDED_RECTANGLE (self));

  return self;
}
Ejemplo n.º 18
0
static ClutterActor *
make_bouncer (const ClutterColor *base_color,
              gfloat              width,
              gfloat              height)
{
  ClutterActor *retval;
  cairo_t *cr;
  cairo_pattern_t *pattern;
  gfloat radius = MAX (width, height);

  retval = clutter_cairo_texture_new (width, height);

  cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (retval));

  cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
  cairo_paint (cr);
  cairo_set_operator (cr, CAIRO_OPERATOR_ADD);

  cairo_arc (cr, radius / 2, radius / 2, radius / 2, 0.0, 2.0 * G_PI);

  pattern = cairo_pattern_create_radial (radius / 2, radius / 2, 0,
                                         radius, radius, radius);
  cairo_pattern_add_color_stop_rgba (pattern,
                                     0,
                                     base_color->red / 255.0,
                                     base_color->green / 255.0,
                                     base_color->blue / 255.0,
                                     base_color->alpha / 255.0);
  cairo_pattern_add_color_stop_rgba (pattern,
                                     0.9,
                                     base_color->red / 255.0,
                                     base_color->green / 255.0,
                                     base_color->blue / 255.0,
                                     0.1);

  cairo_set_source (cr, pattern);
  cairo_fill_preserve (cr);

  cairo_pattern_destroy (pattern);
  cairo_destroy (cr);

  clutter_actor_set_name (retval, "bouncer");
  clutter_actor_set_size (retval, width, height);
  clutter_actor_set_anchor_point (retval, width / 2, height / 2);
  clutter_actor_set_reactive (retval, TRUE);

  return retval;
}
Ejemplo n.º 19
0
static void
clutter_cairo_texture_finalize (GObject *object)
{
  ClutterCairoTexturePrivate *priv = CLUTTER_CAIRO_TEXTURE (object)->priv;

  if (priv->cr_surface != NULL)
    {
      cairo_surface_t *surface = priv->cr_surface;

      priv->cr_surface = NULL;

      cairo_surface_finish (surface);
      cairo_surface_destroy (surface);
    }

  G_OBJECT_CLASS (clutter_cairo_texture_parent_class)->finalize (object);
}
Ejemplo n.º 20
0
static void
rounded_background_draw_cb (ClutterCairoTexture *texture,
                            cairo_t *cr)
{
  ClutterActorBox allocation;

  clutter_actor_get_allocation_box (CLUTTER_ACTOR (texture), &allocation);
  clutter_cairo_texture_clear (CLUTTER_CAIRO_TEXTURE (texture));

  _cairo_round_rectangle (cr, allocation.x1, allocation.y1,
                          allocation.x2 - allocation.x1,
                          allocation.y2 - allocation.y1,
                          6.0);
  cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);

  cairo_fill (cr);
}
Ejemplo n.º 21
0
static void
clutter_cairo_texture_notify (GObject    *object,
                              GParamSpec *pspec)
{
  /* When the surface width or height changes then resize the cairo
     surface. This is done here instead of directly in set_property so
     that if both the width and height properties are set using a
     single call to g_object_set then the surface will only be resized
     once because the notifications will be frozen in between */
  if (strcmp ("surface-width", pspec->name) == 0 ||
      strcmp ("surface-height", pspec->name) == 0)
    {
      ClutterCairoTexture *cairo = CLUTTER_CAIRO_TEXTURE (object);

      clutter_cairo_texture_surface_resize_internal (cairo);
    }

  if (G_OBJECT_CLASS (clutter_cairo_texture_parent_class)->notify)
    G_OBJECT_CLASS (clutter_cairo_texture_parent_class)->notify (object, pspec);
}
Ejemplo n.º 22
0
EmpathyRoundedRectangle *
empathy_rounded_rectangle_new (guint width,
                               guint height,
                               guint round_factor)
{
    EmpathyRoundedRectangle *self;

    self = EMPATHY_ROUNDED_RECTANGLE (g_object_new (EMPATHY_TYPE_ROUNDED_RECTANGLE, NULL));

    self->priv->width = width;
    self->priv->height = height;
    self->priv->round_factor = round_factor;

    g_signal_connect (self, "draw", G_CALLBACK (draw_cb), NULL);

    empathy_rounded_rectangle_update_surface_size (self);
    clutter_cairo_texture_invalidate (CLUTTER_CAIRO_TEXTURE (self));

    return self;
}
Ejemplo n.º 23
0
/**
 * shell_global_create_horizontal_gradient:
 * @left: the color on the left
 * @right: the color on the right
 *
 * Creates a horizontal gradient actor.
 *
 * Return value: (transfer none): a #ClutterCairoTexture actor with the
 *               gradient. The texture actor is floating, hence (transfer none).
 */
ClutterCairoTexture *
shell_global_create_horizontal_gradient (ClutterColor *left,
                                         ClutterColor *right)
{
  ClutterCairoTexture *texture;
  cairo_t *cr;
  cairo_pattern_t *pattern;

  /* Draw the gradient on an 8x1 pixel texture. Because the gradient is drawn
   * from the left to the right column, after stretching 1/16 of the
   * texture width has the left side color and 1/16 has the right side color. 
   * There is no reason to use the 8 pixel height that would be similar to the
   * reason we are using the 8 pixel width for the vertical gradient, so we
   * are just using the 1 pixel height instead.
   */
  texture = CLUTTER_CAIRO_TEXTURE (clutter_cairo_texture_new (8, 1));
  cr = clutter_cairo_texture_create (texture);

  pattern = cairo_pattern_create_linear (0, 0, 8, 0);
  cairo_pattern_add_color_stop_rgba (pattern, 0,
                                     left->red / 255.,
                                     left->green / 255.,
                                     left->blue / 255.,
                                     left->alpha / 255.);
  cairo_pattern_add_color_stop_rgba (pattern, 1,
                                     right->red / 255.,
                                     right->green / 255.,
                                     right->blue / 255.,
                                     right->alpha / 255.);

  cairo_set_source (cr, pattern);
  cairo_paint (cr);

  cairo_pattern_destroy (pattern);
  cairo_destroy (cr);

  return texture;
}
Ejemplo n.º 24
0
static void
on_track_joints (GObject      *obj,
                 GAsyncResult *res,
                 gpointer      user_data)
{
  guint i;
  BufferInfo *buffer_info;
  guint16 *reduced;
  gint width, height, reduced_width, reduced_height;

  buffer_info = (BufferInfo *) user_data;
  reduced = (guint16 *) buffer_info->reduced_buffer;
  width = buffer_info->width;
  height = buffer_info->height;
  reduced_width = buffer_info->reduced_width;
  reduced_height = buffer_info->reduced_height;

  GError *error = NULL;

  list = skeltrack_skeleton_track_joints_finish (skeleton,
                                                 res,
                                                 &error);

  if (error == NULL)
    {
      if (SHOW_SKELETON)
        clutter_cairo_texture_invalidate (CLUTTER_CAIRO_TEXTURE (depth_tex));
    }
  else
    {
      g_error_free (error);
    }

  g_slice_free1 (width * height * sizeof (guint16), reduced);

  g_slice_free (BufferInfo, buffer_info);
}
Ejemplo n.º 25
0
/**
 * shell_global_create_vertical_gradient:
 * @top: the color at the top
 * @bottom: the color at the bottom
 *
 * Creates a vertical gradient actor.
 *
 * Return value: (transfer none): a #ClutterCairoTexture actor with the
 *               gradient. The texture actor is floating, hence (transfer none).
 */
ClutterCairoTexture *
shell_global_create_vertical_gradient (ClutterColor *top,
                                       ClutterColor *bottom)
{
  ClutterCairoTexture *texture;
  cairo_t *cr;
  cairo_pattern_t *pattern;

  /* Draw the gradient on an 8x8 pixel texture. Because the gradient is drawn
   * from the uppermost to the lowermost row, after stretching 1/16 of the
   * texture height has the top color and 1/16 has the bottom color. The 8
   * pixel width is chosen for reasons related to graphics hardware internals.
   */
  texture = CLUTTER_CAIRO_TEXTURE (clutter_cairo_texture_new (8, 8));
  cr = clutter_cairo_texture_create (texture);

  pattern = cairo_pattern_create_linear (0, 0, 0, 8);
  cairo_pattern_add_color_stop_rgba (pattern, 0,
                                     top->red / 255.,
                                     top->green / 255.,
                                     top->blue / 255.,
                                     top->alpha / 255.);
  cairo_pattern_add_color_stop_rgba (pattern, 1,
                                     bottom->red / 255.,
                                     bottom->green / 255.,
                                     bottom->blue / 255.,
                                     bottom->alpha / 255.);

  cairo_set_source (cr, pattern);
  cairo_paint (cr);

  cairo_pattern_destroy (pattern);
  cairo_destroy (cr);

  return texture;
}
Ejemplo n.º 26
0
static void
ppg_line_visualizer_draw (PpgVisualizer *visualizer)
{
	PpgLineVisualizerPrivate *priv;
	PpgModelIter iter;
	Line *line;
	PpgColorIter color;
	cairo_t *cr;
	GValue value = { 0 };
	gfloat height;
	gfloat width;
	gdouble x;
	gdouble y;
	gdouble begin;
	gdouble end;
	gdouble lower;
	gdouble upper;
	gdouble val = 0;
	gint i;

	g_return_if_fail(PPG_IS_LINE_VISUALIZER(visualizer));

	priv = PPG_LINE_VISUALIZER(visualizer)->priv;

	clutter_cairo_texture_clear(CLUTTER_CAIRO_TEXTURE(priv->actor));
	cr = clutter_cairo_texture_create(CLUTTER_CAIRO_TEXTURE(priv->actor));

	g_object_get(visualizer,
	             "begin", &begin,
	             "end", &end,
	             NULL);

	g_object_get(priv->actor,
	             "width", &width,
	             "height", &height,
	             NULL);

	/* FIXME: */
	lower = 0;
	upper = 200;

	ppg_color_iter_init(&color);

	cairo_set_line_width(cr, 1.0);

	for (i = 0; i < priv->lines->len; i++) {
		line = &g_array_index(priv->lines, Line, i);
		cairo_move_to(cr, 0, height);
		gdk_cairo_set_source_color(cr, &color.color);

		if (!ppg_model_get_iter_first(line->model, &iter)) {
			goto next;
		}

		do {
			ppg_model_get_value(line->model, &iter, line->key, &value);
			if (G_VALUE_HOLDS(&value, G_TYPE_DOUBLE)) {
				val = g_value_get_double(&value);
			} else if (G_VALUE_HOLDS(&value, G_TYPE_INT)) {
				val = g_value_get_int(&value);
			} else if (G_VALUE_HOLDS(&value, G_TYPE_UINT)) {
				val = g_value_get_uint(&value);
			} else {
				g_critical("HOLDS %s", g_type_name(value.g_type));
				g_assert_not_reached();
			}
			x = get_x_offset(begin, end, width, iter.time);
			y = get_y_offset(lower, upper, height, val);
			cairo_line_to(cr, x, y);
			g_value_unset(&value);
		} while (ppg_model_iter_next(line->model, &iter));

		cairo_stroke(cr);

	  next:
		ppg_color_iter_next(&color);
	}

	cairo_destroy(cr);
}
Ejemplo n.º 27
0
/* The marker is drawn with cairo.  It is composed of 1 static filled circle
 * and 1 stroked circle animated as an echo.
 */
static ClutterActor *
create_marker ()
{
  ClutterActor *marker;
  ClutterActor *bg;
  ClutterTimeline *timeline;
  cairo_t *cr;

  /* Create the marker */
  marker = champlain_custom_marker_new ();

  /* Static filled circle ----------------------------------------------- */
  bg = clutter_cairo_texture_new (MARKER_SIZE, MARKER_SIZE);
  cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (bg));

  cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
  cairo_paint(cr);
  cairo_set_operator (cr, CAIRO_OPERATOR_OVER);

  /* Draw the circle */
  cairo_set_source_rgb (cr, 0, 0, 0);
  cairo_arc (cr, MARKER_SIZE / 2.0, MARKER_SIZE / 2.0, MARKER_SIZE / 2.0, 0, 2 * M_PI);
  cairo_close_path (cr);

  /* Fill the circle */
  cairo_set_source_rgba (cr, 0.1, 0.1, 0.9, 1.0);
  cairo_fill (cr);

  cairo_destroy (cr);

  /* Add the circle to the marker */
  clutter_container_add_actor (CLUTTER_CONTAINER (marker), bg);
  clutter_actor_set_anchor_point_from_gravity (bg, CLUTTER_GRAVITY_CENTER);
  clutter_actor_set_position (bg, 0, 0);

  /* Echo circle -------------------------------------------------------- */
  bg = clutter_cairo_texture_new (2 * MARKER_SIZE, 2 * MARKER_SIZE);
  cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (bg));

  /* Draw the circle */
  cairo_set_source_rgb (cr, 0, 0, 0);
  cairo_arc (cr, MARKER_SIZE, MARKER_SIZE, 0.9 * MARKER_SIZE, 0, 2 * M_PI);
  cairo_close_path (cr);

  /* Stroke the circle */
  cairo_set_line_width (cr, 2.0);
  cairo_set_source_rgba (cr, 0.1, 0.1, 0.7, 1.0);
  cairo_stroke (cr);

  cairo_destroy (cr);

  /* Add the circle to the marker */
  clutter_container_add_actor (CLUTTER_CONTAINER (marker), bg);
  clutter_actor_lower_bottom (bg); /* Ensure it is under the previous circle */
  clutter_actor_set_position (bg, 0, 0);
  clutter_actor_set_anchor_point_from_gravity (bg, CLUTTER_GRAVITY_CENTER);

  /* Animate the echo circle */
  timeline = clutter_timeline_new (1000);
  clutter_timeline_set_loop (timeline, TRUE);
  clutter_actor_set_opacity (CLUTTER_ACTOR (bg), 255);
  clutter_actor_set_scale (CLUTTER_ACTOR (bg), 0.5, 0.5);
  clutter_actor_animate_with_timeline (CLUTTER_ACTOR (bg),
      CLUTTER_EASE_OUT_SINE, 
      timeline, 
      "opacity", 0, 
      "scale-x", 2.0, 
      "scale-y", 2.0, 
      NULL);

  clutter_timeline_start (timeline);

  return marker;
}
Ejemplo n.º 28
0
static void
pkg_graph_2d_paint (PkgGraph2d *graph)
{
	PkgGraph2dPrivate *priv = graph->priv;
	cairo_t *cr;
	gfloat w, h;
	gdouble x0, x1, x2;
	gdouble y0, y1, y2;
	gdouble dashes[] = {1., 2.};
	gdouble *epochs = NULL;
	gdouble tmp;
	gsize n_epochs = 0;
	gint i;

	clutter_cairo_texture_clear(CLUTTER_CAIRO_TEXTURE(priv->texture));
	clutter_actor_get_size(CLUTTER_ACTOR(graph), &w, &h);

	/*
	 * Create cairo context and set defaults.
	 */
	cr = clutter_cairo_texture_create(CLUTTER_CAIRO_TEXTURE(priv->texture));
	cairo_set_line_width(cr, 1.);
	cairo_set_dash(cr, dashes, 2, 0.);

	/*
	 * Get coordinates for drawing primary extends.
	 */
	pkg_graph_2d_get_primary_extents(graph, &x0, &x1, &x2, &y0, &y1, &y2);

	/*
	 * Draw the background color.
	 */
	cairo_set_source_rgb(cr, 1., 1., 1.);
	cairo_rectangle(cr, x1, y2, x2 - x1, y1);
	cairo_fill(cr);

	/*
	 * Draw the bounding box.
	 */
	cairo_set_source_rgb(cr, 0., 0., 0.);
	cairo_move_to(cr, x0, y2);
	cairo_line_to(cr, x2, y2);
	cairo_line_to(cr, x2, y0);
	cairo_move_to(cr, x0, y1);
	cairo_line_to(cr, x2, y1);
	cairo_move_to(cr, x1, y0 - .5);
	cairo_line_to(cr, x1, y2);
	cairo_stroke(cr);

	/*
	 * Draw the x-scale epochs.
	 */
	if (pkg_scale_get_epochs(priv->x_scale, &epochs, &n_epochs)) {
		if (n_epochs > 0) {
			for (i = 0; i < n_epochs; i++) {
				if (pkg_scale_translate(priv->x_scale, epochs[i], &tmp)) {
					PangoFontDescription *font_desc;
					PangoLayout *layout;
					gchar *format, *markup;
					gint pw, ph;

					/*
					 * Only draw the line if it isn't right near the end of
					 * the visiable region of the graph.
					 */
					if (tmp + 5. < floor(w)) {
						cairo_move_to(cr, tmp, y0 - .5);
						cairo_line_to(cr, tmp, y2);
					}

					/*
					 * Draw the y-scale grid-line value.
					 */
					format = pkg_scale_format_string(priv->x_scale, epochs[i]);
					if (format != NULL) {
						font_desc = pango_font_description_from_string("Bold Sans 8");
						layout = pango_cairo_create_layout(cr);
						pango_layout_set_font_description(layout, font_desc);
						markup = g_strdup_printf("<span size=\"smaller\">%s</span>", format);
						pango_layout_set_markup(layout, markup, -1);
						pango_layout_get_pixel_size(layout, &pw, &ph);
						if (i == 0) {
							cairo_move_to(cr, tmp + 2., y1 + 2.);
						} else {
							cairo_move_to(cr, tmp - pw - 2., y1 + 2.);
						}
						pango_cairo_show_layout(cr, layout);
						g_object_unref(layout);
						pango_font_description_free(font_desc);
						g_free(format);
						g_free(markup);
					}
				}
			}
			cairo_stroke(cr);
		}
	}

	/*
	 * Draw the y-scale epochs.
	 */
	if (pkg_scale_get_epochs(priv->y_scale, &epochs, &n_epochs)) {
		if (n_epochs > 0) {
			for (i = 0; i < n_epochs; i++) {
				if (pkg_scale_translate(priv->y_scale, epochs[i], &tmp)) {
					PangoFontDescription *font_desc;
					PangoLayout *layout;
					gchar *format, *markup;
					gint pw, ph;

					cairo_move_to(cr, x0, floor(y1 - tmp) + .5);
					cairo_line_to(cr, x2, floor(y1 - tmp) + .5);

					/*
					 * Draw the y-scale grid-line value.
					 */
					format = pkg_scale_format_string(priv->y_scale, epochs[i]);
					if (format != NULL) {
						font_desc = pango_font_description_from_string("Bold Sans 8");
						layout = pango_cairo_create_layout(cr);
						pango_layout_set_font_description(layout, font_desc);
						markup = g_strdup_printf("<span size=\"smaller\">%s</span>", format);
						pango_layout_set_markup(layout, markup, -1);
						pango_layout_get_pixel_size(layout, &pw, &ph);
						if (i == 0) {
							cairo_move_to(cr, x1 - pw - 2., y1 - tmp - ph - 2.);
						} else {
							cairo_move_to(cr, x1 - pw - 2., y1 - tmp + 2.);
						}
						pango_cairo_show_layout(cr, layout);
						g_object_unref(layout);
						pango_font_description_free(font_desc);
						g_free(markup);
						g_free(format);
					}
				}
			}
			cairo_stroke(cr);
		}
	}

	priv->x_label = "X Label Here";
	priv->y_label = "Y Label Here";

	/*
	 * Draw the X scale label.
	 */
	if (priv->x_label) {
		PangoFontDescription *font_desc;
		PangoLayout *layout;
		gchar *markup;
		gint pw, ph;

		font_desc = pango_font_description_from_string("Bold Sans 10");
		layout = pango_cairo_create_layout(cr);
		pango_layout_set_font_description(layout, font_desc);
		markup = g_strdup_printf("<span size=\"smaller\">%s</span>",
		                         priv->x_label);
		pango_layout_set_markup(layout, markup, -1);
		pango_layout_get_pixel_size(layout, &pw, &ph);
		cairo_move_to(cr, ((w - pw) / 2.), h - ph);
		pango_cairo_show_layout(cr, layout);
		g_object_unref(layout);
		pango_font_description_free(font_desc);
		g_free(markup);
	}

	/*
	 * Draw the Y scale label.
	 */
	if (priv->x_label) {
		PangoFontDescription *font_desc;
		PangoLayout *layout;
		gchar *markup;
		gint pw, ph;

		font_desc = pango_font_description_from_string("Bold Sans 10");
		layout = pango_cairo_create_layout(cr);
		pango_layout_set_font_description(layout, font_desc);
		markup = g_strdup_printf("<span size=\"smaller\">%s</span>",
		                         priv->y_label);
		pango_layout_set_markup(layout, markup, -1);
		pango_layout_get_pixel_size(layout, &pw, &ph);
		cairo_move_to(cr, 0., h - ((h - pw) / 2.));
		cairo_rotate(cr, M_PI / -2.);
		pango_cairo_show_layout(cr, layout);
		g_object_unref(layout);
		pango_font_description_free(font_desc);
		g_free(markup);
	}

	/*
	 * Free cairo context and resources.
	 */
	cairo_destroy(cr);

	/*
	 * Render the children data points.
	 */
	pkg_graph_2d_paint_children(graph);
}
Ejemplo n.º 29
0
	WindowPanel::WindowPanel()
		: auto_hide_(false) {
		ClutterLayoutManager * main_layout = clutter_bin_layout_new(CLUTTER_BIN_ALIGNMENT_FIXED,
		                                                            CLUTTER_BIN_ALIGNMENT_FIXED);
		actor_ = clutter_box_new(main_layout);

		ClutterActor * menu = clutter_cairo_texture_new(110, 22);
		clutter_actor_set_position(menu, 10.0f, 0.0f);

		cairo_t * context = clutter_cairo_texture_create(CLUTTER_CAIRO_TEXTURE(menu));

		cairo_move_to(context, 0.0, 0.0);
		cairo_line_to(context, 0.0, 19.0);
		cairo_curve_to(context, 1.0, 21.0, 2.0, 22.0, 3.0, 22.0);
		cairo_line_to(context, 107.0, 22.0);
		cairo_curve_to(context, 108.0, 22.0, 109.0, 21.0, 110.0, 19.0);
		cairo_line_to(context, 110.0, 0.0);
		cairo_close_path(context);
		cairo_set_source_rgb(context, 0.8, 0.8, 0.8);
		cairo_fill_preserve(context);
		cairo_set_line_width(context, 1.0);
		cairo_set_source_rgb(context, 0.0, 0.0, 0.0);
		cairo_stroke(context);

		cairo_select_font_face(context, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
		cairo_set_font_size(context, 12.0);

		cairo_text_extents_t extents;
		cairo_text_extents(context, DISPLAY_NAME, &extents);
		cairo_move_to(context, 55.0 - ((extents.width / 2.0) + extents.x_bearing),
		              11.0 - ((extents.height / 2.0) + extents.y_bearing));

		cairo_text_path(context, DISPLAY_NAME);
		cairo_set_source_rgb(context, 0.0, 0.0, 0.0);
		cairo_fill(context);

		cairo_destroy(context);

		clutter_box_pack(CLUTTER_BOX(actor_), menu, NULL, NULL);

		ClutterLayoutManager * controls_layout = clutter_box_layout_new();
		clutter_box_layout_set_spacing(CLUTTER_BOX_LAYOUT(controls_layout), 10u);
		ClutterActor * controls = clutter_box_new(controls_layout);
		clutter_actor_add_constraint(controls, clutter_align_constraint_new(clutter_stage_get_default(),
		                             CLUTTER_ALIGN_X_AXIS, 0.95f));
		clutter_actor_add_constraint(controls, clutter_bind_constraint_new(clutter_stage_get_default(),
		                             CLUTTER_BIND_Y, 5.0f));

		fullscreen_button_ = clutter_cairo_texture_new(18, 16);
		clutter_actor_set_reactive(fullscreen_button_, TRUE);
		g_signal_connect(fullscreen_button_, "button-press-event", G_CALLBACK(fullscreen_clicked_cb), this);
		g_signal_connect(fullscreen_button_, "enter-event", G_CALLBACK(actor_highlight_on_cb), fullscreen_button_);
		g_signal_connect(fullscreen_button_, "leave-event", G_CALLBACK(actor_highlight_off_cb), fullscreen_button_);
		clutter_box_pack(CLUTTER_BOX(controls), fullscreen_button_, NULL, NULL);

		close_button_ = clutter_cairo_texture_new(15, 15);

		context = clutter_cairo_texture_create(CLUTTER_CAIRO_TEXTURE(close_button_));

		cairo_move_to(context, 1.0, 3.0);
		cairo_line_to(context, 3.0, 1.0);
		cairo_line_to(context, 8.0, 6.0);
		cairo_line_to(context, 13.0, 1.0);
		cairo_line_to(context, 15.0, 3.0);
		cairo_line_to(context, 10.0, 8.0);
		cairo_line_to(context, 15.0, 13.0);
		cairo_line_to(context, 13.0, 15.0);
		cairo_line_to(context, 8.0, 10.0);
		cairo_line_to(context, 3.0, 15.0);
		cairo_line_to(context, 1.0, 13.0);
		cairo_line_to(context, 6.0, 8.0);
		cairo_close_path(context);
		cairo_set_source_rgb(context, 1.0, 1.0, 1.0);
		cairo_fill_preserve(context);
		cairo_set_line_width(context, 1.0);
		cairo_set_source_rgb(context, 0.0, 0.0, 0.0);
		cairo_stroke(context);

		cairo_destroy(context);

		clutter_actor_set_reactive(close_button_, TRUE);
		g_signal_connect(close_button_, "button-press-event", G_CALLBACK(close_clicked_cb), NULL);
		g_signal_connect(close_button_, "enter-event", G_CALLBACK(actor_highlight_on_cb), close_button_);
		g_signal_connect(close_button_, "leave-event", G_CALLBACK(actor_highlight_off_cb), close_button_);
		clutter_box_pack(CLUTTER_BOX(controls), close_button_, NULL, NULL);

		draw_window_controls();

		clutter_box_pack(CLUTTER_BOX(actor_), controls, NULL, NULL);

		g_signal_connect(clutter_stage_get_default(), "fullscreen", G_CALLBACK(fullscreen_status_changed_cb), this);
		g_signal_connect(clutter_stage_get_default(), "unfullscreen", G_CALLBACK(fullscreen_status_changed_cb), this);
		g_signal_connect(clutter_stage_get_default(), "motion-event", G_CALLBACK(show_panel_cb), this);
	}
Ejemplo n.º 30
0
ClutterActor*
make_flower_actor (void)
{
  /* No science here, just a hack from toying */
  gint i, j;

  double colors[] = {
    0.71, 0.81, 0.83,
    1.0,  0.78, 0.57,
    0.64, 0.30, 0.35,
    0.73, 0.40, 0.39,
    0.91, 0.56, 0.64,
    0.70, 0.47, 0.45,
    0.92, 0.75, 0.60,
    0.82, 0.86, 0.85,
    0.51, 0.56, 0.67,
    1.0, 0.79, 0.58,

  };

  gint size;
  gint petal_size;
  gint n_groups;    /* Num groups of petals 1-3 */
  gint n_petals;    /* num of petals 4 - 8  */
  gint pm1, pm2;

  gint idx, last_idx = -1;

  ClutterActor *ctex;
  cairo_t      *cr;

  petal_size = PETAL_MIN + rand() % PETAL_VAR;
  size = petal_size * 8;

  n_groups = rand() % 3 + 1;

  ctex = clutter_cairo_texture_new (size, size);

  cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (ctex));

  cairo_set_tolerance (cr, 0.1);

  /* Clear */
  cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
  cairo_paint(cr);
  cairo_set_operator (cr, CAIRO_OPERATOR_OVER);

  cairo_translate(cr, size/2, size/2);

  for (i=0; i<n_groups; i++)
    {
      n_petals = rand() % 5 + 4;
      cairo_save (cr);

      cairo_rotate (cr, rand() % 6);

      do {
	idx = (rand() % (sizeof (colors) / sizeof (double) / 3)) * 3;
      } while (idx == last_idx);

      cairo_set_source_rgba (cr, colors[idx], colors[idx+1],
			     colors[idx+2], 0.5);

      last_idx = idx;

      /* some bezier randomness */
      pm1 = rand() % 20;
      pm2 = rand() % 4;

      for (j=1; j<n_petals+1; j++)
	{
	  cairo_save (cr);
	  cairo_rotate (cr, ((2*M_PI)/n_petals)*j);

	  /* Petals are made up beziers */
	  cairo_new_path (cr);
	  cairo_move_to (cr, 0, 0);
	  cairo_rel_curve_to (cr,
			      petal_size, petal_size,
			      (pm2+2)*petal_size, petal_size,
			      (2*petal_size) + pm1, 0);
	  cairo_rel_curve_to (cr,
			      0 + (pm2*petal_size), -petal_size,
			      -petal_size, -petal_size,
			      -((2*petal_size) + pm1), 0);
	  cairo_close_path (cr);
	  cairo_fill (cr);
	  cairo_restore (cr);
	}

      petal_size -= rand() % (size/8);

      cairo_restore (cr);
    }

  /* Finally draw flower center */
  do {
      idx = (rand() % (sizeof (colors) / sizeof (double) / 3)) * 3;
  } while (idx == last_idx);

  if (petal_size < 0)
    petal_size = rand() % 10;

  cairo_set_source_rgba (cr, colors[idx], colors[idx+1], colors[idx+2], 0.5);

  cairo_arc(cr, 0, 0, petal_size, 0, M_PI * 2);
  cairo_fill(cr);

  cairo_destroy(cr);

  return ctex;
}