Ejemplo n.º 1
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.º 2
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.º 3
0
static void ease_pdf_actor_draw_page (EasePdfActor* self) {
#line 415 "ease-pdf-actor.c"
	PopplerPage* page;
	double width;
	double height;
	cairo_t* cr;
	GError * _inner_error_ = NULL;
#line 58 "ease-pdf-actor.vala"
	g_return_if_fail (self != NULL);
#line 61 "ease-pdf-actor.vala"
	page = _g_object_ref0 (poppler_document_get_page (self->priv->doc, self->priv->current_page));
#line 62 "ease-pdf-actor.vala"
	width = (double) 0;
#line 62 "ease-pdf-actor.vala"
	height = (double) 0;
#line 63 "ease-pdf-actor.vala"
	poppler_page_get_size (page, &width, &height);
#line 66 "ease-pdf-actor.vala"
	if (self->priv->texture == NULL) {
#line 433 "ease-pdf-actor.c"
		ClutterCairoTexture* _tmp0_;
		ClutterActor* _tmp1_;
#line 68 "ease-pdf-actor.vala"
		self->priv->texture = (_tmp0_ = g_object_ref_sink ((ClutterCairoTexture*) clutter_cairo_texture_new ((guint) ((gint) width), (guint) ((gint) height))), _g_object_unref0 (self->priv->texture), _tmp0_);
#line 69 "ease-pdf-actor.vala"
		clutter_container_add_actor ((ClutterContainer*) (_tmp1_ = ((EaseActor*) self)->contents, CLUTTER_IS_GROUP (_tmp1_) ? ((ClutterGroup*) _tmp1_) : NULL), (ClutterActor*) self->priv->texture);
#line 71 "ease-pdf-actor.vala"
		clutter_actor_set_width ((ClutterActor*) self->priv->texture, clutter_actor_get_width (((EaseActor*) self)->contents));
#line 72 "ease-pdf-actor.vala"
		clutter_actor_set_height ((ClutterActor*) self->priv->texture, clutter_actor_get_height (((EaseActor*) self)->contents));
#line 74 "ease-pdf-actor.vala"
		g_signal_connect_object ((GObject*) ((EaseActor*) self)->contents, "notify::width", (GCallback) __lambda53__g_object_notify, self, 0);
#line 78 "ease-pdf-actor.vala"
		g_signal_connect_object ((GObject*) ((EaseActor*) self)->contents, "notify::height", (GCallback) __lambda54__g_object_notify, self, 0);
#line 448 "ease-pdf-actor.c"
	} else {
#line 86 "ease-pdf-actor.vala"
		clutter_cairo_texture_set_surface_size (self->priv->texture, (guint) ((gint) width), (guint) ((gint) height));
#line 452 "ease-pdf-actor.c"
	}
#line 90 "ease-pdf-actor.vala"
	clutter_cairo_texture_clear (self->priv->texture);
#line 91 "ease-pdf-actor.vala"
	cr = clutter_cairo_texture_create (self->priv->texture);
#line 92 "ease-pdf-actor.vala"
	ease_background_cairo_render (self->priv->pdf_element->background, cr, (gint) width, (gint) height, ease_document_get_path (ease_slide_get_parent (ease_element_get_parent (((EaseActor*) self)->element))), &_inner_error_);
#line 460 "ease-pdf-actor.c"
	if (_inner_error_ != NULL) {
		_cairo_destroy0 (cr);
		_g_object_unref0 (page);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return;
	}
#line 94 "ease-pdf-actor.vala"
	poppler_page_render (page, cr);
#line 470 "ease-pdf-actor.c"
	_cairo_destroy0 (cr);
	_g_object_unref0 (page);
}
Ejemplo n.º 4
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.º 5
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);
}
Ejemplo n.º 6
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.º 7
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);
}
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.º 9
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.º 10
0
void
shell_global_clutter_cairo_texture_draw_clock (ClutterCairoTexture *texture,
                                               int                  hour,
                                               int                  minute)
{
  cairo_t *cr;
  guint width, height;
  double xc, yc, radius, hour_radius, minute_radius;
  double angle;

  clutter_cairo_texture_get_surface_size (texture, &width, &height);
  xc = (double)width / 2;
  yc = (double)height / 2;
  radius = (double)(MIN(width, height)) / 2 - 2;
  minute_radius = radius - 3;
  hour_radius = radius / 2;

  clutter_cairo_texture_clear (texture);
  cr = clutter_cairo_texture_create (texture);
  cairo_set_line_width (cr, 1.0);

  /* Outline */
  cairo_arc (cr, xc, yc, radius, 0.0, 2.0 * M_PI);
  cairo_stroke (cr);

  /* Hour hand. (We add a fraction to @hour for the minutes, then
   * convert to radians, and then subtract pi/2 because cairo's origin
   * is at 3:00, not 12:00.)
   */
  angle = ((hour + minute / 60.0) / 12.0) * 2.0 * M_PI - M_PI / 2.0;
  cairo_move_to (cr, xc, yc);
  cairo_line_to (cr,
                 xc + hour_radius * cos (angle),
                 yc + hour_radius * sin (angle));
  cairo_stroke (cr);

  /* Minute hand */
  angle = (minute / 60.0) * 2.0 * M_PI - M_PI / 2.0;
  cairo_move_to (cr, xc, yc);
  cairo_line_to (cr,
                 xc + minute_radius * cos (angle),
                 yc + minute_radius * sin (angle));
  cairo_stroke (cr);

  cairo_destroy (cr);
}
Ejemplo n.º 11
0
void ease_welcome_actor_set_slide_size (EaseWelcomeActor* self, gint w, gint h) {
#line 240 "ease-welcome-actor.c"
	GError * _inner_error_ = NULL;
#line 150 "ease-welcome-actor.vala"
	g_return_if_fail (self != NULL);
#line 153 "ease-welcome-actor.vala"
	clutter_cairo_texture_set_surface_size (self->priv->slide_actor, (guint) w, (guint) h);
#line 246 "ease-welcome-actor.c"
	{
		EaseSlide* slide;
		cairo_t* _tmp0_;
#line 158 "ease-welcome-actor.vala"
		slide = ease_welcome_actor_create_slide (self, w, h);
#line 159 "ease-welcome-actor.vala"
		ease_slide_cairo_render_sized (slide, _tmp0_ = clutter_cairo_texture_create (self->priv->slide_actor), w, h, &_inner_error_);
#line 254 "ease-welcome-actor.c"
		_cairo_destroy0 (_tmp0_);
		if (_inner_error_ != NULL) {
			_g_object_unref0 (slide);
			goto __catch20_g_error;
		}
		_g_object_unref0 (slide);
	}
	goto __finally20;
	__catch20_g_error:
	{
		GError * e;
		e = _inner_error_;
		_inner_error_ = NULL;
		{
#line 163 "ease-welcome-actor.vala"
			g_critical (_ ("Error rendering preview: %s"), e->message);
#line 271 "ease-welcome-actor.c"
			_g_error_free0 (e);
		}
	}
	__finally20:
	if (_inner_error_ != NULL) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return;
	}
}
Ejemplo n.º 12
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.º 13
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.º 14
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.º 15
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.º 16
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.º 17
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;
}
Ejemplo n.º 18
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);
	}