[shotwell/wip/transparent-background: 2/2] WIP
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [shotwell/wip/transparent-background: 2/2] WIP
- Date: Thu, 20 Apr 2017 20:34:01 +0000 (UTC)
commit 7b9a68e61a12588a9e56163901eedd0a96392024
Author: Jens Georg <mail jensge org>
Date: Thu Apr 20 22:00:25 2017 +0200
WIP
src/Page.vala | 87 ++++++++++++++++----------------------------------------
1 files changed, 25 insertions(+), 62 deletions(-)
---
diff --git a/src/Page.vala b/src/Page.vala
index b5eb953..17efb7c 100644
--- a/src/Page.vala
+++ b/src/Page.vala
@@ -2061,24 +2061,7 @@ public abstract class SinglePhotoPage : Page {
int draw_y = (pixmap_dim.height - view_rect.height) / 2;
draw_y = draw_y.clamp(0, int.MAX);
if (zoomed.get_has_alpha()) {
- if (background_surface == null) {
- background_surface = get_window().create_similar_surface(Cairo.Content.COLOR_ALPHA,
- 16, 16);
- var ctx2 = new Cairo.Context(background_surface);
- ctx2.set_operator(Cairo.Operator.SOURCE);
- set_source_color_from_string(ctx2, "#808080");
- ctx2.rectangle(0,0,8,8);
- ctx2.rectangle(8,8,8,8);
- ctx2.fill();
- set_source_color_from_string(ctx2, "#cccccc");
- ctx2.rectangle(0,8,8,8);
- ctx2.rectangle(8,0,8,8);
- ctx2.fill();
- }
-
- warning ("\n=====================> dkdkjdkjdkjdkj\n");
-
- pixmap_ctx.set_source_surface(background_surface, 0, 0);
+ pixmap_ctx.set_source_surface(get_background_surface(), 0, 0);
pixmap_ctx.get_source().set_extend(Cairo.Extend.REPEAT);
pixmap_ctx.rectangle(draw_x, draw_y,
zoomed.width,
@@ -2275,34 +2258,12 @@ public abstract class SinglePhotoPage : Page {
repaint();
}
- private Cairo.Surface? background_surface = null;
-
private bool on_canvas_exposed(Cairo.Context exposed_ctx) {
// draw pixmap onto canvas unless it's not been instantiated, in which case draw black
// (so either old image or contents of another page is not left on screen)
- if (pixmap != null) {
- /*if (pixmap.has_alpha)*/ {
- if (background_surface == null) {
- background_surface = get_window().create_similar_surface(Cairo.Content.COLOR_ALPHA,
- 16, 16);
- var ctx = new Cairo.Context(background_surface);
- ctx.set_operator(Cairo.Operator.SOURCE);
- set_source_color_from_string(ctx, "#808080");
- ctx.rectangle(0,0,8,8);
- ctx.rectangle(8,8,8,8);
- ctx.fill();
- set_source_color_from_string(ctx, "#cccccc");
- ctx.rectangle(0,8,8,8);
- ctx.rectangle(8,0,8,8);
- ctx.fill();
- }
- exposed_ctx.set_source_surface(background_surface, 0, 0);
- exposed_ctx.get_source().set_extend(Cairo.Extend.REPEAT);
- exposed_ctx.rectangle(0, 0, get_allocated_width(), get_allocated_height());
- exposed_ctx.paint();
- }
+ if (pixmap != null)
exposed_ctx.set_source_surface(pixmap, 0, 0);
- } else
+ else
set_source_color_from_string(exposed_ctx, "#000");
exposed_ctx.rectangle(0, 0, get_allocated_width(), get_allocated_height());
@@ -2316,6 +2277,27 @@ public abstract class SinglePhotoPage : Page {
protected virtual void updated_pixbuf(Gdk.Pixbuf pixbuf, UpdateReason reason, Dimensions old_dim) {
}
+
+ private Cairo.Surface background_surface = null;
+
+ protected Cairo.Surface get_background_surface() {
+ if (background_surface == null) {
+ var window = get_window();
+ background_surface = window.create_similar_surface(Cairo.Content.COLOR_ALPHA, 16, 16);
+ var ctx = new Cairo.Context(background_surface);
+ ctx.set_operator(Cairo.Operator.SOURCE);
+ set_source_color_from_string(ctx, "#808080");
+ ctx.rectangle(0,0,8,8);
+ ctx.rectangle(8,8,8,8);
+ ctx.fill();
+ set_source_color_from_string(ctx, "#cccccc");
+ ctx.rectangle(0,8,8,8);
+ ctx.rectangle(8,0,8,8);
+ ctx.fill();
+ }
+
+ return background_surface;
+ }
protected virtual void paint(Cairo.Context ctx, Dimensions ctx_dim) {
if (is_zoom_supported() && (!static_zoom_state.is_default())) {
@@ -2331,27 +2313,8 @@ public abstract class SinglePhotoPage : Page {
ctx.rectangle(0, 0, pixmap_dim.width, pixmap_dim.height);
ctx.fill();
- warning ("\n====> scaled %d %d %d %d\n", scaled_pos.x,
- scaled_pos.y,
- scaled.width, scaled.height);
-
if (scaled.has_alpha) {
- if (background_surface == null) {
- background_surface = get_window().create_similar_surface(Cairo.Content.COLOR_ALPHA,
- 16, 16);
- var ctx2 = new Cairo.Context(background_surface);
- ctx2.set_operator(Cairo.Operator.SOURCE);
- set_source_color_from_string(ctx2, "#808080");
- ctx2.rectangle(0,0,8,8);
- ctx2.rectangle(8,8,8,8);
- ctx2.fill();
- set_source_color_from_string(ctx2, "#cccccc");
- ctx2.rectangle(0,8,8,8);
- ctx2.rectangle(8,0,8,8);
- ctx2.fill();
- }
-
- ctx.set_source_surface(background_surface, 0, 0);
+ ctx.set_source_surface(get_background_surface(), 0, 0);
ctx.get_source().set_extend(Cairo.Extend.REPEAT);
ctx.rectangle(scaled_pos.x, scaled_pos.y,
scaled.width,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]