static void drawing_area_snapshot (GtkWidget *widget, GtkSnapshot *snapshot) { DrawingArea *area = (DrawingArea *) widget; GtkAllocation allocation; cairo_t *cr; gtk_widget_get_allocation (widget, &allocation); cr = gtk_snapshot_append_cairo (snapshot, &GRAPHENE_RECT_INIT ( 0, 0, allocation.width, allocation.height )); cairo_set_source_rgb (cr, 1, 1, 1); cairo_paint (cr); cairo_set_source_surface (cr, area->surface, 0, 0); cairo_paint (cr); cairo_set_source_rgb (cr, 0.6, 0.6, 0.6); cairo_rectangle (cr, 0, 0, allocation.width, allocation.height); cairo_stroke (cr); cairo_destroy (cr); }
static void gdk_texture_paintable_snapshot (GdkPaintable *paintable, GdkSnapshot *snapshot, double width, double height) { GdkTexture *self = GDK_TEXTURE (paintable); gtk_snapshot_append_texture (snapshot, self, &GRAPHENE_RECT_INIT (0, 0, width, height)); }
static void snapshot_background (GtkWidget *widget, GtkSnapshot *snapshot) { GdkRectangle visible_rect; gtk_text_view_get_visible_rect (GTK_TEXT_VIEW (widget), &visible_rect); gtk_snapshot_append_color (snapshot, &(GdkRGBA) { CHECK_DARK, CHECK_DARK, CHECK_DARK, 1.0 }, &GRAPHENE_RECT_INIT(visible_rect.x, visible_rect.y, visible_rect.width, visible_rect.height)); gtk_snapshot_push_repeat (snapshot, &GRAPHENE_RECT_INIT(visible_rect.x, visible_rect.y, visible_rect.width, visible_rect.height), &GRAPHENE_RECT_INIT(visible_rect.x, visible_rect.y, CHECK_SIZE * 2, CHECK_SIZE * 2)); gtk_snapshot_append_color (snapshot, &(GdkRGBA) { CHECK_LIGHT, CHECK_LIGHT, CHECK_LIGHT, 1.0 }, &GRAPHENE_RECT_INIT(visible_rect.x, visible_rect.y, CHECK_SIZE, CHECK_SIZE)); gtk_snapshot_append_color (snapshot, &(GdkRGBA) { CHECK_LIGHT, CHECK_LIGHT, CHECK_LIGHT, 1.0 }, &GRAPHENE_RECT_INIT(visible_rect.x + CHECK_SIZE, visible_rect.y + CHECK_SIZE, CHECK_SIZE, CHECK_SIZE)); gtk_snapshot_pop (snapshot); }
static void cb_compose_images_snapshot (GtkWidget *widget, GtkSnapshot *snapshot) { const int width = gtk_widget_get_width (widget); const int height = gtk_widget_get_height (widget); /* This is only relevant when an image gets transitioned to being deleted, * but we just always push a clip node here, for simplicity. */ gtk_snapshot_push_clip (snapshot, &GRAPHENE_RECT_INIT (0, 0, width, height), "ComposeImagesClip"); GTK_WIDGET_CLASS (cb_compose_images_parent_class)->snapshot (widget, snapshot); gtk_snapshot_pop (snapshot); }
static void gtk_css_image_win32_snapshot (GtkCssImage *image, GtkSnapshot *snapshot, double width, double height) { GtkCssImageWin32 *wimage = GTK_CSS_IMAGE_WIN32 (image); cairo_surface_t *surface; int dx, dy; cairo_t *cr; cr = gtk_snapshot_append_cairo (snapshot, &GRAPHENE_RECT_INIT (0, 0, width, height)); surface = gtk_win32_theme_create_surface (wimage->theme, wimage->part, wimage->state, wimage->margins, width, height, &dx, &dy); if (wimage->state2 >= 0) { cairo_surface_t *surface2; cairo_t *cr2; int dx2, dy2; surface2 = gtk_win32_theme_create_surface (wimage->theme, wimage->part2, wimage->state2, wimage->margins, width, height, &dx2, &dy2); cr2 = cairo_create (surface); cairo_set_source_surface (cr2, surface2, dx2 - dx, dy2-dy); cairo_paint_with_alpha (cr2, wimage->over_alpha); cairo_destroy (cr2); cairo_surface_destroy (surface2); } cairo_set_source_surface (cr, surface, dx, dy); cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_NONE); cairo_rectangle (cr, 0, 0, width, height); cairo_fill (cr); cairo_surface_destroy (surface); cairo_destroy (cr); }
/* This is the function that draws the puzzle piece. * It just draws a rectangular cutout of the puzzle by clipping * away the rest. */ static void gtk_puzzle_piece_snapshot (GdkPaintable *paintable, GdkSnapshot *snapshot, double width, double height) { GtkPuzzlePiece *self = GTK_PUZZLE_PIECE (paintable); gtk_snapshot_push_clip (snapshot, &GRAPHENE_RECT_INIT (0, 0, width, height)); gtk_snapshot_offset (snapshot, - width * self->x, - height * self->y); gdk_paintable_snapshot (self->puzzle, snapshot, width * self->width, height * self->height); gtk_snapshot_pop (snapshot); }
void ops_finish (RenderOpBuilder *builder) { if (builder->mv_stack) g_array_free (builder->mv_stack, TRUE); builder->mv_stack = NULL; if (builder->clip_stack) g_array_free (builder->clip_stack, TRUE); builder->clip_stack = NULL; builder->buffer_size = 0; builder->dx = 0; builder->dy = 0; builder->current_modelview = NULL; builder->current_clip = NULL; builder->current_render_target = 0; builder->current_texture = 0; builder->current_program = NULL; builder->current_program_state = NULL; graphene_matrix_init_identity (&builder->current_projection); builder->current_viewport = GRAPHENE_RECT_INIT (0, 0, 0, 0); }
static void gtk_css_image_fallback_snapshot (GtkCssImage *image, GtkSnapshot *snapshot, double width, double height) { GtkCssImageFallback *fallback = GTK_CSS_IMAGE_FALLBACK (image); if (fallback->used < 0) { GdkRGBA red = { 1, 0, 0, 1 }; const GdkRGBA *color; if (fallback->color) color = _gtk_css_rgba_value_get_rgba (fallback->color); else color = &red; gtk_snapshot_append_color (snapshot, color, &GRAPHENE_RECT_INIT (0, 0, width, height)); } else gtk_css_image_snapshot (fallback->images[fallback->used], snapshot, width, height); }
{ graphene_rect_t ra, rb; ra = *a; graphene_rect_normalize_in_place (&ra); rb = *b; graphene_rect_normalize_in_place (&rb); res->origin.x = graphene_lerp (ra.origin.x, rb.origin.x, factor); res->origin.y = graphene_lerp (ra.origin.y, rb.origin.y, factor); res->size.width = graphene_lerp (ra.size.width, rb.size.width, factor); res->size.height = graphene_lerp (ra.size.height, rb.size.height, factor); } static const graphene_rect_t _graphene_rect_zero = GRAPHENE_RECT_INIT (0, 0, 0, 0); /** * graphene_rect_zero: * * Returns a degenerate rectangle with origin fixed at (0, 0) and * a size of 0, 0. * * Returns: (transfer none): a fixed rectangle * * Since: 1.4 */ const graphene_rect_t * graphene_rect_zero (void) { return &_graphene_rect_zero;
static void gtk_css_image_linear_snapshot (GtkCssImage *image, GtkSnapshot *snapshot, double width, double height) { GtkCssImageLinear *linear = GTK_CSS_IMAGE_LINEAR (image); GskColorStop *stops; GskRenderNode *node; double off_x, off_y; /* snapshot offset */ double angle; /* actual angle of the gradiant line in degrees */ double x, y; /* coordinates of start point */ double length; /* distance in pixels for 100% */ double start, end; /* position of first/last point on gradient line - with gradient line being [0, 1] */ double offset; int i, last; char *name; if (linear->side) { /* special casing the regular cases here so we don't get rounding errors */ switch (linear->side) { case 1 << GTK_CSS_RIGHT: angle = 90; break; case 1 << GTK_CSS_LEFT: angle = 270; break; case 1 << GTK_CSS_TOP: angle = 0; break; case 1 << GTK_CSS_BOTTOM: angle = 180; break; default: angle = atan2 (linear->side & 1 << GTK_CSS_TOP ? -width : width, linear->side & 1 << GTK_CSS_LEFT ? -height : height); angle = 180 * angle / G_PI + 90; break; } } else { angle = _gtk_css_number_value_get (linear->angle, 100); } gtk_css_image_linear_compute_start_point (angle, width, height, &x, &y); length = sqrt (x * x + y * y); gtk_css_image_linear_get_start_end (linear, length, &start, &end); if (start == end) { /* repeating gradients with all color stops sharing the same offset * get the color of the last color stop */ GtkCssImageLinearColorStop *stop = &g_array_index (linear->stops, GtkCssImageLinearColorStop, linear->stops->len - 1); gtk_snapshot_append_color_node (snapshot, _gtk_css_rgba_value_get_rgba (stop->color), &GRAPHENE_RECT_INIT (0, 0, width, height), "RepeatingLinearGradient<degenerate>"); return; } offset = start; last = -1; stops = g_newa (GskColorStop, linear->stops->len); for (i = 0; i < linear->stops->len; i++) { GtkCssImageLinearColorStop *stop; double pos, step; stop = &g_array_index (linear->stops, GtkCssImageLinearColorStop, i); if (stop->offset == NULL) { if (i == 0) pos = 0.0; else if (i + 1 == linear->stops->len) pos = 1.0; else continue; } else pos = _gtk_css_number_value_get (stop->offset, length) / length; pos = MAX (pos, offset); step = (pos - offset) / (i - last); for (last = last + 1; last <= i; last++) { stop = &g_array_index (linear->stops, GtkCssImageLinearColorStop, last); offset += step; stops[last].offset = (offset - start) / (end - start); stops[last].color = *_gtk_css_rgba_value_get_rgba (stop->color); } offset = pos; last = i; } gtk_snapshot_get_offset (snapshot, &off_x, &off_y); if (linear->repeating) { node = gsk_repeating_linear_gradient_node_new ( &GRAPHENE_RECT_INIT (off_x, off_y, width, height), &GRAPHENE_POINT_INIT (off_x + width / 2 + x * (start - 0.5), off_y + height / 2 + y * (start - 0.5)), &GRAPHENE_POINT_INIT (off_x + width / 2 + x * (end - 0.5), off_y + height / 2 + y * (end - 0.5)), stops, linear->stops->len); } else { node = gsk_linear_gradient_node_new ( &GRAPHENE_RECT_INIT (off_x, off_y, width, height), &GRAPHENE_POINT_INIT (off_x + width / 2 + x * (start - 0.5), off_y + height / 2 + y * (start - 0.5)), &GRAPHENE_POINT_INIT (off_x + width / 2 + x * (end - 0.5), off_y + height / 2 + y * (end - 0.5)), stops, linear->stops->len); } name = g_strdup_printf ("%sLinearGradient<%ustops>", linear->repeating ? "Repeating" : "", linear->stops->len); gsk_render_node_set_name (node, name); g_free (name); gtk_snapshot_append_node (snapshot, node); gsk_render_node_unref (node); }
static void gtk_css_image_icon_theme_snapshot (GtkCssImage *image, GtkSnapshot *snapshot, double width, double height) { GtkCssImageIconTheme *icon_theme = GTK_CSS_IMAGE_ICON_THEME (image); GError *error = NULL; GtkIconInfo *icon_info; GskTexture *texture; GdkPixbuf *pixbuf; double texture_width, texture_height; gint size; size = floor (MIN (width, height)); if (size <= 0) return; icon_info = gtk_icon_theme_lookup_icon_for_scale (icon_theme->icon_theme, icon_theme->name, size, icon_theme->scale, GTK_ICON_LOOKUP_USE_BUILTIN); if (icon_info == NULL) { /* XXX: render missing icon image here? */ return; } pixbuf = gtk_icon_info_load_symbolic (icon_info, &icon_theme->color, &icon_theme->success, &icon_theme->warning, &icon_theme->error, NULL, &error); if (pixbuf == NULL) { /* XXX: render missing icon image here? */ g_error_free (error); return; } texture = gsk_texture_new_for_pixbuf (pixbuf); texture_width = (double) gdk_pixbuf_get_width (pixbuf) / icon_theme->scale; texture_height = (double) gdk_pixbuf_get_height (pixbuf) / icon_theme->scale; gtk_snapshot_append_texture_node (snapshot, texture, &GRAPHENE_RECT_INIT( (width - texture_width) / 2.0, (height - texture_height) / 2.0, texture_width, texture_height ), "CssImageIconTheme<%s@%d>", icon_theme->name, icon_theme->scale); g_object_unref (texture); g_object_unref (pixbuf); g_object_unref (icon_info); }