Commit 03884665 authored by Paolo Bacchilega's avatar Paolo Bacchilega

image viewer: use a checked pattern as background for transparent images

parent fa8ae216
......@@ -1170,3 +1170,37 @@ _cairo_paint_grid (cairo_t *cr,
cairo_restore (cr);
}
cairo_pattern_t *
_cairo_create_checked_pattern (int size)
{
int h_size;
cairo_surface_t *surface;
cairo_t *ctx;
cairo_pattern_t *pattern;
h_size = size / 2;
surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, size, size);
ctx = cairo_create (surface);
cairo_set_source_rgba (ctx, 0.4, 0.4, 0.4, 1.0);
cairo_rectangle (ctx, 0, 0, h_size, h_size);
cairo_fill (ctx);
cairo_rectangle (ctx, h_size, h_size, h_size, h_size);
cairo_fill (ctx);
cairo_set_source_rgba (ctx, 0.5, 0.5, 0.5, 1.0);
cairo_rectangle (ctx, h_size, 0, h_size, h_size);
cairo_fill (ctx);
cairo_rectangle (ctx, 0, h_size, h_size, h_size);
cairo_fill (ctx);
pattern = cairo_pattern_create_for_surface (surface);
cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
cairo_surface_destroy (surface);
cairo_destroy (ctx);
return pattern;
}
......@@ -265,5 +265,6 @@ void _cairo_draw_slide (cairo_t
void _cairo_paint_grid (cairo_t *cr,
cairo_rectangle_int_t *rectangle,
GthGridType grid_type);
cairo_pattern_t * _cairo_create_checked_pattern (int size);
#endif /* CAIRO_UTILS_H */
......@@ -41,6 +41,7 @@
* delay use this delay instead. */
#define STEP_INCREMENT 20.0 /* Scroll increment. */
#define BLACK_VALUE 0.2
#define CHECKED_PATTERN_SIZE 20
enum {
......@@ -72,6 +73,7 @@ struct _GthImageViewerPrivate {
GthImage *image;
cairo_surface_t *surface;
cairo_pattern_t *background_pattern;
GdkPixbufAnimation *animation;
int original_width;
int original_height;
......@@ -175,6 +177,7 @@ gth_image_viewer_finalize (GObject *object)
_g_clear_object (&self->priv->iter);
_cairo_clear_surface (&self->priv->iter_surface);
_cairo_clear_surface (&self->priv->surface);
cairo_pattern_destroy (self->priv->background_pattern);
G_OBJECT_CLASS (gth_image_viewer_parent_class)->finalize (object);
}
......@@ -1518,6 +1521,7 @@ gth_image_viewer_init (GthImageViewer *self)
self->priv = gth_image_viewer_get_instance_private (self);
self->priv->background_pattern = _cairo_create_checked_pattern (CHECKED_PATTERN_SIZE);
self->priv->is_animation = FALSE;
self->priv->play_animation = TRUE;
self->priv->cursor_visible = TRUE;
......@@ -2660,7 +2664,7 @@ gth_image_viewer_paint_frame (GthImageViewer *self,
/* background */
cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 1.0);
cairo_set_source (cr, self->priv->background_pattern);
cairo_rectangle (cr,
self->image_area.x,
self->image_area.y,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment