Ejemplo n.º 1
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_pattern_t *pattern;

    cairo_translate (cr, PAD, PAD);

    /* mask */
    cairo_push_group (cr);
    cairo_set_source_rgba (cr, 0.8, 0.8, 0.8, 0.4);
    cairo_paint (cr);
    cairo_arc (cr, SIZE / 2, SIZE / 2, SIZE / 6, 0., 2. * M_PI);
    cairo_set_source_rgba (cr, 0.4, 0.4, 0.4, 0.8);
    cairo_fill (cr);
    pattern = cairo_pop_group (cr);

    /* source */
    cairo_push_group (cr);
    cairo_rectangle (cr, 0.3 * SIZE, 0.2 * SIZE, 0.5 * SIZE, 0.5 * SIZE);
    cairo_set_source_rgb (cr, 0, 0, 1);
    cairo_fill (cr);
    cairo_move_to     (cr,   0.0,          0.8 * SIZE);
    cairo_rel_line_to (cr,   0.7 * SIZE,   0.0);
    cairo_rel_line_to (cr, -0.375 * SIZE, -0.6 * SIZE);
    cairo_close_path (cr);
    cairo_set_source_rgb (cr, 0, 1, 0);
    cairo_fill (cr);
    cairo_pop_group_to_source (cr);

    cairo_mask (cr, pattern);
    cairo_pattern_destroy (pattern);

    return CAIRO_TEST_SUCCESS;
}
Ejemplo n.º 2
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    /* Neutral gray background */
    cairo_set_source_rgb (cr, 0.51613, 0.55555, 0.51613);
    cairo_paint (cr);

    /* the rest uses CAIRO_OPERATOR_SOURCE so we see better when something goes wrong */
    cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);

    /* add a rectangle */
    cairo_rectangle (cr, CLIP_OFFSET, CLIP_OFFSET, CLIP_SIZE, CLIP_SIZE);

    /* clip to the rectangle */
    cairo_clip_preserve (cr);

    /* push a group. We now have a device offset. */
    cairo_push_group (cr);

    /* push a group again. This is where the bug used to happen. */
    cairo_push_group (cr);

    /* draw something */
    cairo_set_source_rgb (cr, 1, 0, 0);
    cairo_fill_preserve (cr);

    /* make sure the stuff we drew ends up on the output */
    cairo_pop_group_to_source (cr);
    cairo_fill_preserve (cr);

    cairo_pop_group_to_source (cr);
    cairo_fill_preserve (cr);

    return CAIRO_TEST_SUCCESS;
}
Ejemplo n.º 3
0
static void
gtk_css_image_cross_fade_draw (GtkCssImage        *image,
                               cairo_t            *cr,
                               double              width,
                               double              height)
{
  GtkCssImageCrossFade *cross_fade = GTK_CSS_IMAGE_CROSS_FADE (image);

  if (cross_fade->progress <= 0.0)
    {
      if (cross_fade->start)
        _gtk_css_image_draw (cross_fade->start, cr, width, height);
    }
  else if (cross_fade->progress >= 1.0)
    {
      if (cross_fade->end)
        _gtk_css_image_draw (cross_fade->end, cr, width, height);
    }
  else
    {
      if (cross_fade->start && cross_fade->end)
        {
          /* to reduce the group size */
          cairo_rectangle (cr, 0, 0, ceil (width), ceil (height));
          cairo_clip (cr);

          cairo_push_group (cr);

          /* performance trick */
          cairo_reset_clip (cr);

          _gtk_css_image_draw (cross_fade->start, cr, width, height);

          cairo_push_group (cr);
          _gtk_css_image_draw (cross_fade->end, cr, width, height);
          cairo_pop_group_to_source (cr);

          cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
          cairo_paint_with_alpha (cr, cross_fade->progress);

          cairo_pop_group_to_source (cr);
          cairo_paint (cr);
        }
      else if (cross_fade->start || cross_fade->end)
        {
          cairo_push_group (cr);
          _gtk_css_image_draw (cross_fade->start ? cross_fade->start : cross_fade->end, cr, width, height);
          cairo_pop_group_to_source (cr);

          cairo_paint_with_alpha (cr, cross_fade->start ? 1.0 - cross_fade->progress : cross_fade->progress);
        }
    }
}
Ejemplo n.º 4
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    /* fill with black so we don't need an rgb test case */
    cairo_set_source_rgb (cr, 0, 0, 0);
    cairo_paint (cr);

    /* setting a scale will ensure that the device offset is transformed */
    cairo_scale (cr, 2.1, 2.8);
    cairo_set_source_rgb (cr, 1, .5,.4);

    /* all rectangles should look the same */

    /* plain rectangle */
    cairo_rectangle (cr, 4, 4, 8, 8);
    cairo_fill (cr);

    cairo_translate (cr, 10, 0);

    /* clipped rectangle */
    cairo_save (cr);
    cairo_rectangle (cr, 3, 3, 9, 9);
    cairo_clip (cr);
    cairo_rectangle (cr, 4, 4, 8, 8);
    cairo_fill (cr);
    cairo_restore (cr);

    cairo_translate (cr, 0, 10);

    /* clipped and grouped rectangle */
    cairo_save (cr);
    cairo_rectangle (cr, 3, 3, 9, 9);
    cairo_clip (cr);
    cairo_push_group (cr);
    cairo_rectangle (cr, 4, 4, 8, 8);
    cairo_fill (cr);
    cairo_pop_group_to_source (cr);
    cairo_paint (cr);
    cairo_restore (cr);

    cairo_translate (cr, -10, 0);

    /* grouped rectangle */
    cairo_push_group (cr);
    cairo_rectangle (cr, 4, 4, 8, 8);
    cairo_fill (cr);
    cairo_pop_group_to_source (cr);
    cairo_paint (cr);

    return CAIRO_TEST_SUCCESS;
}
Ejemplo n.º 5
0
/* Given a path-generating function and two possibly translucent
 * patterns, fill and stroke the path with the patterns (to an
 * offscreen group), then blend the result into the destination.
 */
static void
fill_and_stroke (cairo_t		*cr,
		 path_func_t		 path_func,
		 cairo_pattern_t	*fill_pattern,
		 cairo_pattern_t	*stroke_pattern)
{
    cairo_push_group (cr);
    {
	(path_func) (cr);
	cairo_set_source (cr, fill_pattern);
	cairo_fill_preserve (cr);

	/* Use DEST_OUT to subtract stroke from fill. */
	cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
	cairo_set_operator (cr, CAIRO_OPERATOR_DEST_OUT);
	cairo_stroke_preserve (cr);

	/* Then use ADD to draw the stroke without a seam. */
	cairo_set_source (cr, stroke_pattern);
	cairo_set_operator (cr, CAIRO_OPERATOR_ADD);
	cairo_stroke (cr);
    }
    cairo_pop_group_to_source (cr);
    cairo_paint (cr);
}
Ejemplo n.º 6
0
static void
redraw_handler(struct widget *widget, void *data)
{
	struct editor *editor = data;
	cairo_surface_t *surface;
	struct rectangle allocation;
	cairo_t *cr;

	surface = window_get_surface(editor->window);
	widget_get_allocation(editor->widget, &allocation);

	cr = cairo_create(surface);
	cairo_rectangle(cr, allocation.x, allocation.y, allocation.width, allocation.height);
	cairo_clip(cr);

	cairo_translate(cr, allocation.x, allocation.y);

	/* Draw background */
	cairo_push_group(cr);
	cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
	cairo_set_source_rgba(cr, 1, 1, 1, 1);
	cairo_rectangle(cr, 0, 0, allocation.width, allocation.height);
	cairo_fill(cr);

	cairo_pop_group_to_source(cr);
	cairo_paint(cr);

	cairo_destroy(cr);
	cairo_surface_destroy(surface);
}
Ejemplo n.º 7
0
static cairo_pattern_t *
draw_clb_pattern(drawing_context_t *ctx) {
  cairo_t *cr = ctx->cr;
  const double zoom = ctx->zoom;
  cairo_pattern_t *pat;
  unsigned width = SITE_WIDTH*zoom, height = SITE_HEIGHT*zoom;

  cairo_save (cr);

  cairo_set_source_rgb (cr, 0., 0., 0.);
  cairo_rectangle (cr, 0, 0, width, height);
  cairo_clip (cr);
  cairo_scale (cr, zoom, zoom);

  cairo_push_group (cr);

/*   cairo_rectangle (cr, 0, 0, SITE_WIDTH, SITE_HEIGHT); */
/*   cairo_set_source_rgb (cr, 0., 0., 0.); */
/*   cairo_paint (cr); */

  cairo_set_line_width (cr, 1.0);
  cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);

  _draw_clb_pattern (cr);
  pat = cairo_pop_group (cr);

  cairo_restore (cr);

  return pat;
}
Ejemplo n.º 8
0
static gboolean fadable_box_real_draw (GtkWidget* base, cairo_t* c) {
	FadableBox * self;
	gboolean result = FALSE;
	cairo_t* _tmp0_;
	cairo_t* _tmp1_;
	cairo_t* _tmp2_;
	cairo_t* _tmp3_;
	FadeTracker* _tmp4_;
	FadeTracker* _tmp5_;
	gdouble _tmp6_;
	gdouble _tmp7_;
	self = (FadableBox*) base;
	g_return_val_if_fail (c != NULL, FALSE);
	_tmp0_ = c;
	cairo_push_group (_tmp0_);
	_tmp1_ = c;
	fadable_box_draw_full_alpha (self, _tmp1_);
	_tmp2_ = c;
	cairo_pop_group_to_source (_tmp2_);
	_tmp3_ = c;
	_tmp4_ = fadable_get_fade_tracker ((Fadable*) self);
	_tmp5_ = _tmp4_;
	_tmp6_ = fade_tracker_get_alpha (_tmp5_);
	_tmp7_ = _tmp6_;
	cairo_paint_with_alpha (_tmp3_, _tmp7_);
	result = FALSE;
	return result;
}
void pango_render_text_shadow(cairo_t *context, PangoLayout *layout)
{
	cairo_push_group(context);

	cairo_new_path(context);
	cairo_move_to(context, 15.0+8.0, 10.0+8.0);

	pango_cairo_layout_path(context, layout);

	cairo_set_line_width(context, 6.0);
	cairo_set_miter_limit(context, 2.0);

	cairo_set_source_rgb(context, 0.0, 0.0, 0.0);
	cairo_stroke_preserve(context);

	cairo_fill(context);

	cairo_pop_group_to_source(context);
	cairo_paint_with_alpha(context, 0.6);

	cairo_new_path(context);
	cairo_move_to(context, 15.0, 10.0);

	pango_cairo_layout_path(context, layout);

	cairo_set_line_width(context, 6.0);
	cairo_set_miter_limit(context, 2.0);

	cairo_set_source_rgb(context, 0.0, 0.3, 0.9);
	cairo_stroke_preserve(context);

	cairo_set_source_rgb(context, 0.9, 0.1, 0.8);
	cairo_fill(context);
}
Ejemplo n.º 10
0
static void
redraw_handler(struct widget *widget, void *data)
{
	struct cliptest *cliptest = data;
	struct geometry *g = cliptest->view.geometry;
	struct rectangle allocation;
	cairo_t *cr;
	cairo_surface_t *surface;
	GLfloat ex[8];
	GLfloat ey[8];
	int n;

	n = calculate_edges(&cliptest->view, &g->clip, &g->surf, ex, ey);

	widget_get_allocation(cliptest->widget, &allocation);

	surface = window_get_surface(cliptest->window);
	cr = cairo_create(surface);
	widget_get_allocation(cliptest->widget, &allocation);
	cairo_rectangle(cr, allocation.x, allocation.y,
			allocation.width, allocation.height);
	cairo_clip(cr);

	cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
	cairo_set_source_rgba(cr, 0, 0, 0, 1);
	cairo_paint(cr);

	cairo_translate(cr, allocation.x, allocation.y);
	cairo_set_line_width(cr, 1.0);
	cairo_move_to(cr, allocation.width / 2.0, 0.0);
	cairo_line_to(cr, allocation.width / 2.0, allocation.height);
	cairo_move_to(cr, 0.0, allocation.height / 2.0);
	cairo_line_to(cr, allocation.width, allocation.height / 2.0);
	cairo_set_source_rgba(cr, 0.5, 0.5, 0.5, 1.0);
	cairo_stroke(cr);

	cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
	cairo_push_group(cr);
		cairo_translate(cr, allocation.width / 2.0,
				allocation.height / 2.0);
		cairo_scale(cr, 4.0, 4.0);
		cairo_set_line_width(cr, 0.5);
		cairo_set_line_join(cr, CAIRO_LINE_JOIN_BEVEL);
		cairo_select_font_face(cr, "Sans", CAIRO_FONT_SLANT_NORMAL,
				       CAIRO_FONT_WEIGHT_BOLD);
		cairo_set_font_size(cr, 5.0);
		draw_geometry(cr, &cliptest->view, ex, ey, n);
	cairo_pop_group_to_source(cr);
	cairo_paint(cr);

	cairo_set_source_rgba(cr, 0.0, 1.0, 0.0, 1.0);
	cairo_select_font_face(cr, "monospace", CAIRO_FONT_SLANT_NORMAL,
			       CAIRO_FONT_WEIGHT_NORMAL);
	cairo_set_font_size(cr, 12.0);
	draw_coordinates(cr, 10.0, 10.0, ex, ey, n);

	cairo_destroy(cr);

	cairo_surface_destroy(surface);
}
Ejemplo n.º 11
0
static void paintRepaintRectOverlay(cairo_surface_t* surface, WKArrayRef repaintRects)
{
    cairo_t* context = cairo_create(surface);

    cairo_push_group(context);

    // Paint the gray mask over the original image.
    cairo_set_source_rgba(context, 0, 0, 0, 0.66);
    cairo_paint(context);

    // Paint transparent rectangles over the mask to show the repainted regions.
    cairo_set_source_rgba(context, 0, 0, 0, 0);
    cairo_set_operator(context, CAIRO_OPERATOR_SOURCE);
    size_t count = WKArrayGetSize(repaintRects);
    for (size_t i = 0; i < count; ++i) {
        WKRect rect = WKRectGetValue(static_cast<WKRectRef>(WKArrayGetItemAtIndex(repaintRects, i)));
        cairo_rectangle(context, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
        cairo_fill(context);
    }

    cairo_pop_group_to_source(context);
    cairo_paint(context);

    cairo_destroy(context);
}
Ejemplo n.º 12
0
void
ags_vindicator_draw(AgsVIndicator *indicator)
{
  GtkWidget *widget;
  GtkAdjustment *adjustment;
  cairo_t *cr;
  gdouble value;
  guint width, height;
  guint segment_width, segment_height;
  guint padding;
  guint i;

  widget = GTK_WIDGET(indicator);
  adjustment = AGS_INDICATOR(indicator)->adjustment;

  //  g_message("draw %f\0", adjustment->value);

  cr = gdk_cairo_create(widget->window);

  if(cr == NULL){
    return;
  }

  width = 16;
  height = 100;

  segment_width = 16;
  segment_height = 7;

  padding = 3;

  cairo_push_group(cr);

  for(i = 0; i < height / (segment_height + padding); i++){
    if(adjustment->value > 0.0 &&
       (1 / adjustment->value * i < (height / (segment_height + padding)))){
      /* active */
      cairo_set_source_rgba(cr, 0.9, 0.7, 0.2, 1.0);
    }else{
      /* normal */
      cairo_set_source_rgba(cr, 0.0, 0.0, 0.4, 1.0);
    }

    cairo_rectangle(cr,
		    0, height - i * (segment_height + padding) - segment_height,
		    segment_width, segment_height);
    cairo_fill(cr);

    cairo_set_source_rgba(cr, 0.0, 0.0, 1.0, 0.3);
    cairo_rectangle(cr,
		    0, height - i * (segment_height + padding) - segment_height,
		    segment_width, segment_height);
    cairo_stroke(cr);
  }

  cairo_pop_group_to_source(cr);
  cairo_paint(cr);

  cairo_destroy(cr);
}
gboolean
ags_automation_area_expose_event(GtkWidget *widget, GdkEventExpose *event,
				 AgsAutomationArea *automation_area)
{
  AgsAutomationEditor *automation_editor;
  cairo_t *cr;

  g_message("debug: c");
  
  automation_editor = gtk_widget_get_ancestor(automation_area,
					      AGS_TYPE_AUTOMATION_EDITOR);

  cr = gdk_cairo_create(widget->window);
  cairo_push_group(cr);

  ags_automation_area_draw_strip(automation_area,
				 cr);
  ags_automation_area_draw_scale(automation_area,
				 cr);
  ags_automation_area_draw_automation(automation_area,
				      cr);

  cairo_pop_group_to_source(cr);
  cairo_paint(cr);

  return(TRUE);
}
Ejemplo n.º 14
0
void PlatformContextCairo::pushImageMask(cairo_surface_t* surface, const FloatRect& rect)
{
    // We must call savePlatformState at least once before we can use image masking,
    // since we actually apply the mask in restorePlatformState.
    ASSERT(!m_stateStack.isEmpty());
    m_state->m_imageMaskInformation.update(surface, rect);

    // Cairo doesn't support the notion of an image clip, so we push a group here
    // and then paint it to the surface with an image mask (which is an immediate
    // operation) during restorePlatformState.

    // We want to allow the clipped elements to composite with the surface as it
    // is now, but they are isolated in another group. To make this work, we're
    // going to blit the current surface contents onto the new group once we push it.
    cairo_surface_t* currentTarget = cairo_get_target(m_cr.get());
    cairo_surface_flush(currentTarget);

    // Pushing a new group ensures that only things painted after this point are clipped.
    cairo_push_group(m_cr.get());
    cairo_set_operator(m_cr.get(), CAIRO_OPERATOR_SOURCE);

    cairo_set_source_surface(m_cr.get(), currentTarget, 0, 0);
    cairo_rectangle(m_cr.get(), rect.x(), rect.y(), rect.width(), rect.height());
    cairo_fill(m_cr.get());
}
Ejemplo n.º 15
0
static void
gd_stack_draw_crossfade (GtkWidget *widget,
                         cairo_t *cr)
{
  GdStack *stack = GD_STACK (widget);
  GdStackPrivate *priv = stack->priv;

  if (priv->last_visible_surface)
    {
      cairo_set_source_surface (cr, priv->last_visible_surface,
				priv->last_visible_surface_allocation.x,
				priv->last_visible_surface_allocation.y);
      cairo_set_operator (cr, CAIRO_OPERATOR_ADD);
      cairo_paint_with_alpha (cr, MAX (1.0 - priv->transition_pos, 0));
    }

  cairo_push_group (cr);
  cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
  gtk_container_propagate_draw (GTK_CONTAINER (stack),
                                priv->visible_child->widget,
                                cr);
  cairo_pop_group_to_source (cr);
  cairo_set_operator (cr, CAIRO_OPERATOR_ADD);
  cairo_paint_with_alpha (cr, priv->transition_pos);
}
Ejemplo n.º 16
0
static VALUE
cr_push_group (int argc, VALUE *argv, VALUE self)
{
  VALUE result = Qnil;
  VALUE content, pop_to_source;
  rb_scan_args (argc, argv, "02", &content, &pop_to_source);

  if (NIL_P(content))
    cairo_push_group (_SELF);
  else
    cairo_push_group_with_content (_SELF, RVAL2CRCONTENT(content));
  cr_check_status (_SELF);

  if (rb_block_given_p ())
    {
      int state = 0;

      if (NIL_P (pop_to_source))
        pop_to_source = Qtrue;

      result = rb_protect (rb_yield, self, &state);
      if (cairo_status(_SELF) == CAIRO_STATUS_SUCCESS)
        {
          if (RVAL2CBOOL (pop_to_source))
            cr_pop_group_to_source (self);
          else
            result = cr_pop_group (self);
        }

      if (state)
        rb_jump_tag (state);
    }

  return result;
}
Ejemplo n.º 17
0
static void draw(void)
{
	if(opt_levels < 1) opt_levels = 1;
	if(opt_levels > 10) opt_levels = 10;

	duc_graph_set_size(graph, win_w, win_h);
	duc_graph_set_position(graph, 0, 0);
	duc_graph_set_max_level(graph, opt_levels);
	duc_graph_set_fuzz(graph, fuzz);
	duc_graph_set_palette(graph, palette);
	duc_graph_set_max_name_len(graph, 30);
	duc_graph_set_size_type(graph, opt_apparent ? DUC_SIZE_TYPE_APPARENT : DUC_SIZE_TYPE_ACTUAL);
	duc_graph_set_exact_bytes(graph, opt_bytes);
	duc_graph_set_tooltip(graph, tooltip_x, tooltip_y);
	duc_graph_set_ring_gap(graph, opt_ring_gap);

	cairo_push_group(cr);
	if(opt_dark) {
		cairo_set_source_rgb(cr, 0, 0, 0);
	} else {
		cairo_set_source_rgb(cr, 1, 1, 1);
	}
	cairo_paint(cr);
	duc_graph_draw(graph, dir);
	cairo_pop_group_to_source(cr);
	cairo_paint(cr);
	cairo_surface_flush(cs);
}
Ejemplo n.º 18
0
static int cairo_push_group_l( lua_State* L )
{
  lua_cairo_t* lc = lua_cairo_check( L, 1 );

  cairo_push_group( lc->cairo );

  return( 0 );
}
Ejemplo n.º 19
0
int startLayerVectorCairo(imageObj *img, mapObj *map, layerObj *layer)
{
  if(layer->compositer && layer->compositer->opacity<100) {
    cairo_renderer *r = CAIRO_RENDERER(img);
    cairo_push_group (r->cr);
  }
  return MS_SUCCESS;
}
Ejemplo n.º 20
0
static void
redraw_handler(struct widget *widget, void *data)
{
	struct image *image = data;
	struct rectangle allocation;
	cairo_t *cr;
	cairo_surface_t *surface;
	double width, height, doc_aspect, window_aspect, scale;
	cairo_matrix_t matrix;
	cairo_matrix_t translate;

	surface = window_get_surface(image->window);
	cr = cairo_create(surface);
	widget_get_allocation(image->widget, &allocation);
	cairo_rectangle(cr, allocation.x, allocation.y,
			allocation.width, allocation.height);
	cairo_clip(cr);
	cairo_push_group(cr);
	cairo_translate(cr, allocation.x, allocation.y);

	cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
	cairo_set_source_rgba(cr, 0, 0, 0, 1);
	cairo_paint(cr);

	if (!image->initialized) {
		image->initialized = true;
		width = cairo_image_surface_get_width(image->image);
		height = cairo_image_surface_get_height(image->image);

		doc_aspect = width / height;
		window_aspect = (double) allocation.width / allocation.height;
		if (doc_aspect < window_aspect)
			scale = allocation.height / height;
		else
			scale = allocation.width / width;

		image->width = width;
		image->height = height;
		cairo_matrix_init_scale(&image->matrix, scale, scale);

		clamp_view(image);
	}

	matrix = image->matrix;
	cairo_matrix_init_translate(&translate, allocation.x, allocation.y);
	cairo_matrix_multiply(&matrix, &matrix, &translate);
	cairo_set_matrix(cr, &matrix);

	cairo_set_source_surface(cr, image->image, 0, 0);
	cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
	cairo_paint(cr);

	cairo_pop_group_to_source(cr);
	cairo_paint(cr);
	cairo_destroy(cr);

	cairo_surface_destroy(surface);
}
Ejemplo n.º 21
0
static inline void reduceSourceByAlpha(cairo_t* cr, float alpha)
{
    if (alpha >= 1)
        return;
    cairo_push_group(cr);
    cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
    cairo_paint_with_alpha(cr, alpha);
    cairo_pop_group_to_source(cr);
}
Ejemplo n.º 22
0
void GraphicsContext::beginPlatformTransparencyLayer(float opacity)
{
    if (paintingDisabled())
        return;

    cairo_t* cr = platformContext()->cr();
    cairo_push_group(cr);
    m_data->layers.append(opacity);
}
void GraphicsContext::strokePath()
{
    if (paintingDisabled())
        return;

    cairo_t* cr = m_data->cr;
    cairo_save(cr);
    switch (m_common->state.strokeColorSpace) {
    case SolidColorSpace:
        if (strokeColor().alpha()) {
            setColor(cr, strokeColor());
            if (m_common->state.globalAlpha < 1.0f) {
                cairo_push_group(cr);
                cairo_paint_with_alpha(cr, m_common->state.globalAlpha);
                cairo_pop_group_to_source(cr);
            }
            cairo_stroke(cr);
        }
        break;
    case PatternColorSpace: {
        AffineTransform affine;
        cairo_set_source(cr, m_common->state.strokePattern->createPlatformPattern(affine));
        if (m_common->state.globalAlpha < 1.0f) {
            cairo_push_group(cr);
            cairo_paint_with_alpha(cr, m_common->state.globalAlpha);
            cairo_pop_group_to_source(cr);
        }
        cairo_stroke(cr);
        break;
    }
    case GradientColorSpace:
        cairo_pattern_t* pattern = m_common->state.strokeGradient->platformGradient();
        pattern = applySpreadMethod(pattern, spreadMethod());
        cairo_set_source(cr, pattern);
        if (m_common->state.globalAlpha < 1.0f) {
            cairo_push_group(cr);
            cairo_paint_with_alpha(cr, m_common->state.globalAlpha);
            cairo_pop_group_to_source(cr);
        }
        cairo_stroke(cr);
        break;
    }
    cairo_restore(cr);
}
Ejemplo n.º 24
0
int 
main(int argc, char** argv) {
   
   cairo_surface_t *sfc;
   cairo_t *ctx;
   
   int x, y;
   struct timespec ts = {0, 500000000};
   
   int running;

   x = y = 0;
   sfc = cairo_create_x11_surface(&x, &y);
   ctx = cairo_create(sfc);
   cairo_set_antialias(ctx, CAIRO_ANTIALIAS_NONE);

   mesh_t* m = mesh_create(x, y);

   for (running = 1; running;) {

      cairo_push_group(ctx);
      
         cairo_set_source_rgb(ctx, 0.1, 0.1, 0.1);
         cairo_paint(ctx);
         
         mesh_draw(ctx, m);

      cairo_pop_group_to_source(ctx);
      cairo_paint(ctx);

      cairo_surface_flush(sfc);

      int event=0;
      switch (event=cairo_check_event(sfc, 0)) {
         case 0xff53:   // right cursor
            break;

         case 0xff51:   // left cursor
            break;

         case 0xff1b:   // Esc
         case -1:       // left mouse button
            running = 0;
            break;
      }

      nanosleep(&ts, NULL);
   }

   mesh_free(m);

   cairo_destroy(ctx);
   cairo_close_x11_surface(sfc);

   return 0;
}
Ejemplo n.º 25
0
__attribute__((unused)) static cairo_pattern_t *
draw_full_clb_pattern(drawing_context_t *ctx,
		      chip_descr_t *chip) {
  cairo_t *cr = ctx->cr;

  cairo_push_group (cr);
  /* draw the thing only using vector operations */
  iterate_over_sites(chip, draw_site_vector, ctx);
  return cairo_pop_group (cr);
}
Ejemplo n.º 26
0
static void
text_entry_redraw_handler(struct widget *widget, void *data)
{
	struct text_entry *entry = data;
	cairo_surface_t *surface;
	struct rectangle allocation;
	cairo_t *cr;

	surface = window_get_surface(entry->window);
	widget_get_allocation(entry->widget, &allocation);

	cr = cairo_create(surface);
	cairo_rectangle(cr, allocation.x, allocation.y, allocation.width, allocation.height);
	cairo_clip(cr);

	cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);

	cairo_push_group(cr);
	cairo_translate(cr, allocation.x, allocation.y);

	cairo_set_source_rgba(cr, 1, 1, 1, 1);
	cairo_rectangle(cr, 0, 0, allocation.width, allocation.height);
	cairo_fill(cr);

	cairo_set_operator(cr, CAIRO_OPERATOR_OVER);

	if (entry->active) {
		cairo_rectangle(cr, 0, 0, allocation.width, allocation.height);
		cairo_set_line_width (cr, 3);
		cairo_set_source_rgba(cr, 0, 0, 1, 1.0);
		cairo_stroke(cr);
	}

	cairo_set_source_rgba(cr, 0, 0, 0, 1);

	cairo_translate(cr, text_offset_left, allocation.height / 2);

	if (!entry->layout)
		entry->layout = pango_cairo_create_layout(cr);
	else
		pango_cairo_update_layout(cr, entry->layout);

	text_entry_update_layout(entry);

	pango_cairo_show_layout(cr, entry->layout);

	text_entry_draw_cursor(entry, cr);

	cairo_pop_group_to_source(cr);
	cairo_paint(cr);

	cairo_destroy(cr);
	cairo_surface_destroy(surface);
}
void GraphicsContext::strokePath()
{
    if (paintingDisabled())
        return;

    cairo_t* cr = m_data->cr;
    cairo_save(cr);
    switch (m_common->state.strokeColorSpace) {
    case SolidColorSpace:
        float red, green, blue, alpha;
        strokeColor().getRGBA(red, green, blue, alpha);
        if (m_common->state.globalAlpha < 1.0f)
            alpha *= m_common->state.globalAlpha;
        cairo_set_source_rgba(cr, red, green, blue, alpha);
        cairo_stroke(cr);
        break;
    case PatternColorSpace: {
        TransformationMatrix affine;
        cairo_set_source(cr, m_common->state.strokePattern->createPlatformPattern(affine));
        if (m_common->state.globalAlpha < 1.0f) {
            cairo_push_group(cr);
            cairo_paint_with_alpha(cr, m_common->state.globalAlpha);
            cairo_pop_group_to_source(cr);
        }
        cairo_stroke(cr);
        break;
    }
    case GradientColorSpace:
        cairo_pattern_t* pattern = m_common->state.strokeGradient->platformGradient();
        pattern = applySpreadMethod(pattern, spreadMethod());
        cairo_set_source(cr, pattern);
        if (m_common->state.globalAlpha < 1.0f) {
            cairo_push_group(cr);
            cairo_paint_with_alpha(cr, m_common->state.globalAlpha);
            cairo_pop_group_to_source(cr);
        }
        cairo_stroke(cr);
        break;
    }
    cairo_restore(cr);
}
Ejemplo n.º 28
0
void
gtk_css_style_render_icon (GtkCssStyle            *style,
                           cairo_t                *cr,
                           double                  x,
                           double                  y,
                           double                  width,
                           double                  height,
                           GtkCssImageBuiltinType  builtin_type)
{
  const GtkCssValue *shadows;
  cairo_matrix_t matrix, transform_matrix, saved_matrix;
  GtkCssImage *image;

  g_return_if_fail (GTK_IS_CSS_STYLE (style));
  g_return_if_fail (cr != NULL);

  image = _gtk_css_image_value_get_image (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_SOURCE));
  if (image == NULL)
    return;

  cairo_get_matrix (cr, &saved_matrix);

  shadows = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_SHADOW);

  cairo_translate (cr, x, y);

  if (_gtk_css_transform_value_get_matrix (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_TRANSFORM), &transform_matrix))
    {
      /* XXX: Implement -gtk-icon-transform-origin instead of hardcoding "50% 50%" here */
      cairo_matrix_init_translate (&matrix, width / 2, height / 2);
      cairo_matrix_multiply (&matrix, &transform_matrix, &matrix);
      cairo_matrix_translate (&matrix, - width / 2, - height / 2);

      if (_gtk_css_shadows_value_is_none (shadows))
        {
          cairo_transform (cr, &matrix);
          gtk_css_image_builtin_draw (image, cr, width, height, builtin_type);
        }
      else
        {
          cairo_push_group (cr);
          cairo_transform (cr, &matrix);
          gtk_css_image_builtin_draw (image, cr, width, height, builtin_type);
          cairo_pop_group_to_source (cr);
          _gtk_css_shadows_value_paint_icon (shadows, cr);
          cairo_paint (cr);
        }
    }

  cairo_set_matrix (cr, &saved_matrix);
}
Ejemplo n.º 29
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_push_group (cr);

    cairo_set_source_rgb (cr, 0, 0, 1);
    cairo_paint (cr);

    cairo_pop_group_to_source (cr);
    cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
    cairo_paint (cr);

    return CAIRO_TEST_SUCCESS;
}
Ejemplo n.º 30
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_surface_set_fallback_resolution (cairo_get_target (cr), FALLBACK_RES_X, FALLBACK_RES_Y);

    rectangles (cr);
    cairo_translate (cr, 3*SIZE, 0);
    cairo_push_group (cr);
    rectangles (cr);
    cairo_pop_group_to_source (cr);
    cairo_paint (cr);

    return CAIRO_TEST_SUCCESS;
}