[gthumb] image viewer: use a checked pattern as background for transparent images
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] image viewer: use a checked pattern as background for transparent images
- Date: Mon, 8 Apr 2019 18:47:22 +0000 (UTC)
commit 038846658b0ca654a6d79f531b425d0687728448
Author: Paolo Bacchilega <paobac src gnome org>
Date: Mon Apr 8 20:44:29 2019 +0200
image viewer: use a checked pattern as background for transparent images
gthumb/cairo-utils.c | 34 ++++++++++++++++++++++++++++++++++
gthumb/cairo-utils.h | 1 +
gthumb/gth-image-viewer.c | 6 +++++-
3 files changed, 40 insertions(+), 1 deletion(-)
---
diff --git a/gthumb/cairo-utils.c b/gthumb/cairo-utils.c
index 6af4de1c..530ffbb0 100644
--- a/gthumb/cairo-utils.c
+++ b/gthumb/cairo-utils.c
@@ -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;
+}
diff --git a/gthumb/cairo-utils.h b/gthumb/cairo-utils.h
index c83d3b2e..83888114 100644
--- a/gthumb/cairo-utils.h
+++ b/gthumb/cairo-utils.h
@@ -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 */
diff --git a/gthumb/gth-image-viewer.c b/gthumb/gth-image-viewer.c
index 97214a63..923c3fc9 100644
--- a/gthumb/gth-image-viewer.c
+++ b/gthumb/gth-image-viewer.c
@@ -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,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]