diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2018-05-01 14:43:08 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2018-05-01 14:43:08 +0200 |
commit | 2b3f22361da0c1d8e6ce70d71352821758186db7 (patch) | |
tree | 5d10633b47369b3aa52a05bf889ede0dbe5ee108 /src/util/image.vala | |
parent | 211da5fc3048ca2b6ccee2166b0aaaade55cb84f (diff) | |
parent | dc6c76eb04dfe3d4262a1806808f0bc0bf523238 (diff) |
Merge branch 'feature/upstream' into develop
Diffstat (limited to 'src/util/image.vala')
-rw-r--r-- | src/util/image.vala | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/util/image.vala b/src/util/image.vala index 4adafae..f8646e2 100644 --- a/src/util/image.vala +++ b/src/util/image.vala @@ -446,6 +446,59 @@ Gdk.Point derotate_point_arb(Gdk.Point source_point, int img_w, int img_h, doubl return rotate_point_arb(source_point, img_w, img_h, angle, true); } +private static Cairo.Surface background_surface = null; + +private Cairo.Surface get_background_surface() { + if (background_surface == null) { + string color_a; + string color_b; + var config = Config.Facade.get_instance(); + + var type = config.get_transparent_background_type(); + switch (type) { + case "checkered": + color_a = "#808080"; + color_b = "#ccc"; + break; + case "solid": + color_a = color_b = config.get_transparent_background_color(); + break; + default: + color_a = color_b = "#000"; + break; + } + + background_surface = new Cairo.ImageSurface(Cairo.Format.RGB24, 16, 16); + var ctx = new Cairo.Context(background_surface); + ctx.set_operator(Cairo.Operator.SOURCE); + set_source_color_from_string(ctx, color_a); + ctx.rectangle(0,0,8,8); + ctx.rectangle(8,8,8,8); + ctx.fill(); + set_source_color_from_string(ctx, color_b); + ctx.rectangle(0,8,8,8); + ctx.rectangle(8,0,8,8); + ctx.fill(); + } + + return background_surface; +} + +public void invalidate_transparent_background() { + background_surface = null; +} + +public void paint_pixmap_with_background (Cairo.Context ctx, Gdk.Pixbuf pixbuf, int x, int y) { + if (pixbuf.get_has_alpha()) { + ctx.set_source_surface(get_background_surface(), 0, 0); + ctx.get_source().set_extend(Cairo.Extend.REPEAT); + ctx.rectangle(x, y, pixbuf.width, pixbuf.height); + ctx.fill(); + } + + Gdk.cairo_set_source_pixbuf(ctx, pixbuf, x, y); + ctx.paint(); +} // Force an axially-aligned box to be inside a rotated rectangle. Box clamp_inside_rotated_image(Box src, int img_w, int img_h, double angle_deg, |