[gthumb: 6/129] image viewer: let the viewer tool paint the background



commit 52c55882120c38e0d2cea2b273de854d8c860a40
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Thu Apr 14 16:44:22 2011 +0200

    image viewer: let the viewer tool paint the background
    
    Do not paint the background before calling the expose
    method of the tool, let the tool decide how to draw the background.
    Added the function gth_image_viewer_paint_background() to draw
    the background with the default style.

 gthumb/gth-image-dragger.c  |    4 +-
 gthumb/gth-image-selector.c |    4 +-
 gthumb/gth-image-viewer.c   |  243 ++++++++++++++++++++++---------------------
 gthumb/gth-image-viewer.h   |   10 +-
 4 files changed, 136 insertions(+), 125 deletions(-)
---
diff --git a/gthumb/gth-image-dragger.c b/gthumb/gth-image-dragger.c
index c7e571d..3b96a6e 100644
--- a/gthumb/gth-image-dragger.c
+++ b/gthumb/gth-image-dragger.c
@@ -142,7 +142,9 @@ gth_image_dragger_expose (GthImageViewerTool *self,
 	dragger = (GthImageDragger *) self;
 	viewer = dragger->priv->viewer;
 
-	if (gth_image_viewer_get_current_pixbuf (viewer) == NULL)
+	gth_image_viewer_paint_background (viewer, cr);
+
+	if (gth_image_viewer_get_current_image (viewer) == NULL)
 		return;
 
 	if (gth_image_viewer_get_zoom_quality (viewer) == GTH_ZOOM_QUALITY_LOW)
diff --git a/gthumb/gth-image-selector.c b/gthumb/gth-image-selector.c
index a0f9f23..71c4b22 100644
--- a/gthumb/gth-image-selector.c
+++ b/gthumb/gth-image-selector.c
@@ -738,7 +738,9 @@ gth_image_selector_expose (GthImageViewerTool *base,
 {
 	GthImageSelector *self = GTH_IMAGE_SELECTOR (base);
 
-	if (self->priv->pixbuf == NULL)
+	gth_image_viewer_paint_background (self->priv->viewer, cr);
+
+	if (self->priv->surface == NULL)
 		return;
 
 	if (self->priv->mask_visible) {
diff --git a/gthumb/gth-image-viewer.c b/gthumb/gth-image-viewer.c
index 8300d3e..07c6497 100644
--- a/gthumb/gth-image-viewer.c
+++ b/gthumb/gth-image-viewer.c
@@ -734,137 +734,21 @@ gth_image_viewer_expose (GtkWidget      *widget,
 {
 	GthImageViewer *self;
 	cairo_t        *cr;
-	GtkAllocation   allocation;
-	int             gdk_width;
-	int             gdk_height;
-	GtkStyle       *style;
 
 	self = GTH_IMAGE_VIEWER (widget);
 
 	cr = gdk_cairo_create (gtk_widget_get_window (widget));
-	cairo_set_line_width (cr, 0.5);
-	cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
+	/*cairo_set_line_width (cr, 0.5);
+	cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);*/
 
 	gdk_cairo_region (cr, event->region);
 	cairo_clip (cr);
 
-	/* Draw the background. */
-
-	gtk_widget_get_allocation (widget, &allocation);
-	gdk_width = allocation.width - self->priv->frame_border2;
-	gdk_height = allocation.height - self->priv->frame_border2;
-
-	style = gtk_widget_get_style (widget);
-
-	if ((self->image_area.x > self->priv->frame_border)
-	    || (self->image_area.y > self->priv->frame_border)
-	    || (self->image_area.width < gdk_width)
-	    || (self->image_area.height < gdk_height))
-	{
-		int rx, ry, rw, rh;
-
-		if (self->priv->black_bg)
-			cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
-		else
-			gdk_cairo_set_source_color (cr, &style->bg[GTK_STATE_NORMAL]);
-
-		if (gth_image_viewer_get_current_pixbuf (self) == NULL) {
-			cairo_rectangle (cr,
-					 0,
-					 0,
-					 allocation.width,
-					 allocation.height);
-		}
-		else {
-			/* If an image is present draw in four phases to avoid
-			 * flickering. */
-
-			/* Top rectangle. */
-
-			rx = 0;
-			ry = 0;
-			rw = allocation.width;
-			rh = self->image_area.y;
-			if ((rw > 0) && (rh > 0))
-				cairo_rectangle (cr, rx, ry, rw, rh);
-
-			/* Bottom rectangle. */
-
-			rx = 0;
-			ry = self->image_area.y + self->image_area.height;
-			rw = allocation.width;
-			rh = allocation.height - self->image_area.y - self->image_area.height;
-			if ((rw > 0) && (rh > 0))
-				cairo_rectangle (cr, rx, ry, rw, rh);
-
-			/* Left rectangle. */
-
-			rx = 0;
-			ry = self->image_area.y - 1;
-			rw = self->image_area.x;
-			rh = self->image_area.height + 2;
-			if ((rw > 0) && (rh > 0))
-				cairo_rectangle (cr, rx, ry, rw, rh);
-
-			/* Right rectangle. */
-
-			rx = self->image_area.x + self->image_area.width;
-			ry = self->image_area.y - 1;
-			rw = allocation.width - self->image_area.x - self->image_area.width;
-			rh = self->image_area.height + 2;
-			if ((rw > 0) && (rh > 0))
-				cairo_rectangle (cr, rx, ry, rw, rh);
-		}
-
-		cairo_fill (cr);
-	}
-
-	/* Draw the frame. */
-
-	if ((self->priv->frame_border > 0)
-	    && (gth_image_viewer_get_current_pixbuf (self) != NULL))
-	{
-
-		/* bottom and right side */
-
-		if (self->priv->black_bg)
-			cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
-		else
-			gdk_cairo_set_source_color (cr, &style->light[GTK_STATE_NORMAL]);
-
-		cairo_move_to (cr,
-			       self->image_area.x + self->image_area.width + 0.5,
-			       self->image_area.y - 1 + 0.5);
-		cairo_line_to (cr,
-			       self->image_area.x + self->image_area.width + 0.5,
-			       self->image_area.y + self->image_area.height + 0.5);
-		cairo_line_to (cr,
-			       self->image_area.x - 1 + 0.5,
-			       self->image_area.y + self->image_area.height + 0.5);
-		cairo_stroke (cr);
-
-		/* top and left side */
-
-		if (! self->priv->black_bg)
-			gdk_cairo_set_source_color (cr, &style->dark[GTK_STATE_NORMAL]);
-
-		cairo_move_to (cr,
-			       self->image_area.x - 1 + 0.5,
-			       self->image_area.y + self->image_area.height + 0.5);
-		cairo_line_to (cr,
-			       self->image_area.x - 1 + 0.5,
-			       self->image_area.y - 1 + 0.5);
-		cairo_line_to (cr,
-			       self->image_area.x + self->image_area.width + 0.5,
-			       self->image_area.y - 1 + 0.5);
-		cairo_stroke (cr);
-	}
-
 	gth_image_viewer_tool_expose (self->priv->tool, event, cr);
 
+#if 0
 	/* Draw the focus. */
 
-#if 0
 	if (GTK_WIDGET_HAS_FOCUS (widget)) {
 		GdkRectangle r;
 
@@ -2618,6 +2502,127 @@ gth_image_viewer_paint_region (GthImageViewer  *self,
 
 
 void
+gth_image_viewer_paint_background (GthImageViewer *self,
+				   cairo_t        *cr)
+{
+	GtkAllocation   allocation;
+	int             gdk_width;
+	int             gdk_height;
+	GtkStyle       *style;
+
+	gtk_widget_get_allocation (GTK_WIDGET (self), &allocation);
+	gdk_width = allocation.width - self->priv->frame_border2;
+	gdk_height = allocation.height - self->priv->frame_border2;
+
+	style = gtk_widget_get_style (GTK_WIDGET (self));
+
+	if ((self->image_area.x > self->priv->frame_border)
+	    || (self->image_area.y > self->priv->frame_border)
+	    || (self->image_area.width < gdk_width)
+	    || (self->image_area.height < gdk_height))
+	{
+		int rx, ry, rw, rh;
+
+		if (self->priv->black_bg)
+			cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
+		else
+			gdk_cairo_set_source_color (cr, &style->bg[GTK_STATE_NORMAL]);
+
+		if (gth_image_viewer_get_current_image (self) == NULL) {
+			cairo_rectangle (cr,
+					 0,
+					 0,
+					 allocation.width,
+					 allocation.height);
+		}
+		else {
+			/* If an image is present draw in four phases to avoid
+			 * flickering. */
+
+			/* Top rectangle. */
+
+			rx = 0;
+			ry = 0;
+			rw = allocation.width;
+			rh = self->image_area.y;
+			if ((rw > 0) && (rh > 0))
+				cairo_rectangle (cr, rx, ry, rw, rh);
+
+			/* Bottom rectangle. */
+
+			rx = 0;
+			ry = self->image_area.y + self->image_area.height;
+			rw = allocation.width;
+			rh = allocation.height - self->image_area.y - self->image_area.height;
+			if ((rw > 0) && (rh > 0))
+				cairo_rectangle (cr, rx, ry, rw, rh);
+
+			/* Left rectangle. */
+
+			rx = 0;
+			ry = self->image_area.y - 1;
+			rw = self->image_area.x;
+			rh = self->image_area.height + 2;
+			if ((rw > 0) && (rh > 0))
+				cairo_rectangle (cr, rx, ry, rw, rh);
+
+			/* Right rectangle. */
+
+			rx = self->image_area.x + self->image_area.width;
+			ry = self->image_area.y - 1;
+			rw = allocation.width - self->image_area.x - self->image_area.width;
+			rh = self->image_area.height + 2;
+			if ((rw > 0) && (rh > 0))
+				cairo_rectangle (cr, rx, ry, rw, rh);
+		}
+
+		cairo_fill (cr);
+	}
+
+	/* Draw the frame. */
+
+	if ((self->priv->frame_border > 0)
+	    && (gth_image_viewer_get_current_image (self) != NULL))
+	{
+
+		/* bottom and right side */
+
+		if (self->priv->black_bg)
+			cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
+		else
+			gdk_cairo_set_source_color (cr, &style->light[GTK_STATE_NORMAL]);
+
+		cairo_move_to (cr,
+			       self->image_area.x + self->image_area.width + 0.5,
+			       self->image_area.y - 1 + 0.5);
+		cairo_line_to (cr,
+			       self->image_area.x + self->image_area.width + 0.5,
+			       self->image_area.y + self->image_area.height + 0.5);
+		cairo_line_to (cr,
+			       self->image_area.x - 1 + 0.5,
+			       self->image_area.y + self->image_area.height + 0.5);
+		cairo_stroke (cr);
+
+		/* top and left side */
+
+		if (! self->priv->black_bg)
+			gdk_cairo_set_source_color (cr, &style->dark[GTK_STATE_NORMAL]);
+
+		cairo_move_to (cr,
+			       self->image_area.x - 1 + 0.5,
+			       self->image_area.y + self->image_area.height + 0.5);
+		cairo_line_to (cr,
+			       self->image_area.x - 1 + 0.5,
+			       self->image_area.y - 1 + 0.5);
+		cairo_line_to (cr,
+			       self->image_area.x + self->image_area.width + 0.5,
+			       self->image_area.y - 1 + 0.5);
+		cairo_stroke (cr);
+	}
+}
+
+
+void
 gth_image_viewer_apply_painters (GthImageViewer *self,
 				 GdkEventExpose *event,
 				 cairo_t        *cr)
diff --git a/gthumb/gth-image-viewer.h b/gthumb/gth-image-viewer.h
index a57d641..640905b 100644
--- a/gthumb/gth-image-viewer.h
+++ b/gthumb/gth-image-viewer.h
@@ -285,22 +285,24 @@ gboolean       gth_image_viewer_is_frame_visible         (GthImageViewer     *vi
 
 void           gth_image_viewer_paint                    (GthImageViewer     *viewer,
 							  cairo_t            *cr,
-							  GdkPixbuf          *pixbuf,
+							  cairo_surface_t    *surface,
 							  int                 src_x,
 							  int                 src_y,
 							  int                 dest_x,
 							  int                 dest_y,
 							  int                 width,
 							  int                 height,
-							  int                 interp_type);
+							  cairo_filter_t      filter);
 void           gth_image_viewer_paint_region             (GthImageViewer     *viewer,
 							  cairo_t            *cr,
-							  GdkPixbuf          *pixbuf,
+							  cairo_surface_t    *surface,
 							  int                 src_x,
 							  int                 src_y,
 							  GdkRectangle       *pixbuf_area,
 							  GdkRegion          *region,
-							  int                 interp_type);
+							  cairo_filter_t      filter);
+void           gth_image_viewer_paint_background         (GthImageViewer     *self,
+				   	   	          cairo_t            *cr);
 void           gth_image_viewer_apply_painters           (GthImageViewer     *image_viewer,
 							  GdkEventExpose     *event,
 							  cairo_t            *cr);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]