[gthumb] moved the grid painting function in cairo-utils.c



commit 0cf97cc85a081ab4e02bc2a63b31e2454d0a8ccc
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sun May 15 16:09:20 2011 +0200

    moved the grid painting function in cairo-utils.c

 gthumb/cairo-utils.c        |  160 ++++++++++++++++++++++++++++++++++++
 gthumb/cairo-utils.h        |    3 +
 gthumb/gth-image-selector.c |  187 ++-----------------------------------------
 gthumb/gth-image-selector.h |    8 --
 gthumb/typedefs.h           |    8 ++
 5 files changed, 177 insertions(+), 189 deletions(-)
---
diff --git a/gthumb/cairo-utils.c b/gthumb/cairo-utils.c
index 0f4360c..c72c4c9 100644
--- a/gthumb/cairo-utils.c
+++ b/gthumb/cairo-utils.c
@@ -758,3 +758,163 @@ _cairo_draw_slide (cairo_t  *cr,
 
 	cairo_restore (cr);
 }
+
+
+#define GOLDEN_RATIO        1.6180339887
+#define GOLDER_RATIO_FACTOR (GOLDEN_RATIO / (1.0 + 2.0 * GOLDEN_RATIO))
+#define GRID_STEP_1         10
+#define GRID_STEP_2         (GRID_STEP_1 * 5)
+#define GRID_STEP_3         (GRID_STEP_2 * 2)
+
+
+void
+_cairo_paint_grid (cairo_t      *cr,
+		   GdkRectangle *rectangle,
+		   GthGridType   grid_type)
+{
+	cairo_rectangle (cr, rectangle->x, rectangle->y, rectangle->width, rectangle->height);
+	cairo_clip (cr);
+
+	cairo_rectangle (cr, rectangle->x + 0.5, rectangle->y + 0.5, rectangle->width - 1, rectangle->height - 1);
+	cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
+	cairo_stroke (cr);
+
+	if (grid_type == GTH_GRID_NONE)
+		return;
+
+	if (grid_type == GTH_GRID_THIRDS) {
+		int i;
+
+		cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.60);
+		for (i = 1; i < 3; i++) {
+			cairo_move_to (cr, rectangle->x + rectangle->width * i / 3 + 0.5, rectangle->y + 1.5);
+			cairo_line_to (cr, rectangle->x + rectangle->width * i / 3 + 0.5, rectangle->y + rectangle->height - 0.5);
+
+			cairo_move_to (cr, rectangle->x + 1.5, rectangle->y + rectangle->height * i / 3 + 0.5);
+			cairo_line_to (cr, rectangle->x + rectangle->width - 0.5, rectangle->y + rectangle->height * i / 3 + 0.5);
+		}
+		cairo_stroke (cr);
+
+		cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.10);
+		for (i = 1; i < 9; i++) {
+
+			if (i % 3 == 0)
+				continue;
+
+			cairo_move_to (cr, rectangle->x + rectangle->width * i / 9 + 0.5, rectangle->y + 1.5);
+			cairo_line_to (cr, rectangle->x + rectangle->width * i / 9 + 0.5, rectangle->y + rectangle->height - 0.5);
+
+			cairo_move_to (cr, rectangle->x + 1.5, rectangle->y + rectangle->height * i / 9 + 0.5);
+			cairo_line_to (cr, rectangle->x + rectangle->width - 0.5, rectangle->y + rectangle->height * i / 9 + 0.5);
+		}
+		cairo_stroke (cr);
+	}
+	else if (grid_type == GTH_GRID_GOLDEN) {
+		cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.60);
+
+		int grid_x0, grid_x1, grid_x2, grid_x3;
+	        int grid_y0, grid_y1, grid_y2, grid_y3;
+		int x_delta, y_delta;
+
+		grid_x0 = rectangle->x;
+		grid_x3 = rectangle->x + rectangle->width;
+
+                grid_y0 = rectangle->y;
+                grid_y3 = rectangle->y + rectangle->height;
+
+		x_delta = rectangle->width * GOLDER_RATIO_FACTOR;
+		y_delta = rectangle->height * GOLDER_RATIO_FACTOR;
+
+		grid_x1 = grid_x0 + x_delta;
+		grid_x2 = grid_x3 - x_delta;
+                grid_y1 = grid_y0 + y_delta;
+                grid_y2 = grid_y3 - y_delta;
+
+		cairo_move_to (cr, grid_x1 + 0.5, grid_y0 + 0.5);
+		cairo_line_to (cr, grid_x1 + 0.5, grid_y3 + 0.5);
+
+		if (x_delta < rectangle->width / 2) {
+			cairo_move_to (cr, grid_x2 + 0.5, grid_y0 + 0.5);
+			cairo_line_to (cr, grid_x2 + 0.5, grid_y3 + 0.5);
+		}
+
+		cairo_move_to (cr, grid_x0 + 0.5, grid_y1 + 0.5);
+		cairo_line_to (cr, grid_x3 + 0.5, grid_y1 + 0.5);
+
+		if (y_delta < rectangle->height / 2) {
+			cairo_move_to (cr, grid_x0 + 0.5, grid_y2 + 0.5);
+			cairo_line_to (cr, grid_x3 + 0.5, grid_y2 + 0.5);
+		}
+
+		cairo_stroke (cr);
+	}
+	else if (grid_type == GTH_GRID_CENTER) {
+		int i;
+
+		cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.60);
+		cairo_move_to (cr, rectangle->x + rectangle->width / 2 + 0.5, rectangle->y + 1.5);
+		cairo_line_to (cr, rectangle->x + rectangle->width / 2 + 0.5, rectangle->y + rectangle->height - 0.5);
+		cairo_move_to (cr, rectangle->x + 1.5, rectangle->y + rectangle->height / 2 + 0.5);
+		cairo_line_to (cr, rectangle->x + rectangle->width - 0.5, rectangle->y + rectangle->height / 2 + 0.5);
+		cairo_stroke (cr);
+
+		cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.10);
+		for (i = 1; i < 4; i++) {
+
+			if (i == 2)
+				continue;
+
+			cairo_move_to (cr, rectangle->x + rectangle->width * i / 4 + 0.5, rectangle->y + 1.5);
+			cairo_line_to (cr, rectangle->x + rectangle->width * i / 4 + 0.5, rectangle->y + rectangle->height - 0.5);
+			cairo_move_to (cr, rectangle->x + 1.5, rectangle->y + rectangle->height * i / 4 + 0.5);
+			cairo_line_to (cr, rectangle->x + rectangle->width - 0.5, rectangle->y + rectangle->height * i / 4 + 0.5);
+		}
+		cairo_stroke (cr);
+	}
+	else if (grid_type == GTH_GRID_UNIFORM) {
+
+		int x;
+		int y;
+
+		cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.40);
+		for (x = GRID_STEP_3; x < rectangle->width; x += GRID_STEP_3) {
+			cairo_move_to (cr, rectangle->x + x + 0.5, rectangle->y + 1.5);
+			cairo_line_to (cr, rectangle->x + x + 0.5, rectangle->y + rectangle->height - 0.5);
+		}
+		for (y = GRID_STEP_3; y < rectangle->height; y += GRID_STEP_3) {
+			cairo_move_to (cr, rectangle->x + 1.5, rectangle->y + y + 0.5);
+			cairo_line_to (cr, rectangle->x + rectangle->width - 0.5, rectangle->y + y + 0.5);
+		}
+		cairo_stroke (cr);
+
+		cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.20);
+		for (x = GRID_STEP_2; x < rectangle->width; x += GRID_STEP_2) {
+			if (x % GRID_STEP_3 == 0)
+				continue;
+			cairo_move_to (cr, rectangle->x + x + 0.5, rectangle->y + 1.5);
+			cairo_line_to (cr, rectangle->x + x + 0.5, rectangle->y + rectangle->height - 0.5);
+		}
+		for (y = GRID_STEP_2; y < rectangle->height; y += GRID_STEP_2) {
+			if (y % GRID_STEP_3 == 0)
+				continue;
+			cairo_move_to (cr, rectangle->x + 1.5, rectangle->y + y + 0.5);
+			cairo_line_to (cr, rectangle->x + rectangle->width - 0.5, rectangle->y + y + 0.5);
+		}
+		cairo_stroke (cr);
+
+		cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.10);
+		for (x = GRID_STEP_1; x < rectangle->width; x += GRID_STEP_1) {
+			if (x % GRID_STEP_2 == 0)
+				continue;
+			cairo_move_to (cr, rectangle->x + x + 0.5, rectangle->y + 1.5);
+			cairo_line_to (cr, rectangle->x + x + 0.5, rectangle->y + rectangle->height - 0.5);
+		}
+		for (y = GRID_STEP_1; y < rectangle->height; y += GRID_STEP_1) {
+			if (y % GRID_STEP_2 == 0)
+				continue;
+			cairo_move_to (cr, rectangle->x + 1.5, rectangle->y + y + 0.5);
+			cairo_line_to (cr, rectangle->x + rectangle->width - 0.5, rectangle->y + y + 0.5);
+		}
+		cairo_stroke (cr);
+	}
+}
diff --git a/gthumb/cairo-utils.h b/gthumb/cairo-utils.h
index 3921f70..79d4699 100644
--- a/gthumb/cairo-utils.h
+++ b/gthumb/cairo-utils.h
@@ -207,5 +207,8 @@ void              _cairo_draw_slide                         (cairo_t           *
 		   	   	   	   	 	     double             image_height,
 		   	   	   	   	 	     GdkColor          *frame_color,
 		   	   	   	   	 	     gboolean           draw_inner_border);
+void              _cairo_paint_grid                          (cairo_t           *cr,
+							     GdkRectangle      *rectangle,
+							     GthGridType        grid_type);
 
 #endif /* CAIRO_UTILS_H */
diff --git a/gthumb/gth-image-selector.c b/gthumb/gth-image-selector.c
index ac64d1c..7bf3432 100644
--- a/gthumb/gth-image-selector.c
+++ b/gthumb/gth-image-selector.c
@@ -22,6 +22,7 @@
 #include <config.h>
 #include <stdlib.h>
 #include <math.h>
+#include "cairo-utils.h"
 #include "glib-utils.h"
 #include "gth-image-selector.h"
 #include "gth-marshal.h"
@@ -32,11 +33,6 @@
 #define DRAG_THRESHOLD 1
 #define STEP_INCREMENT 20.0  /* scroll increment. */
 #define SCROLL_TIMEOUT 30    /* autoscroll timeout in milliseconds */
-#define GOLDEN_RATIO   1.6180339887
-#define GOLDER_RATIO_FACTOR (GOLDEN_RATIO / (1.0 + 2.0 * GOLDEN_RATIO))
-#define GRID_STEP_1    10
-#define GRID_STEP_2    (GRID_STEP_1 * 5)
-#define GRID_STEP_3    (GRID_STEP_2 * 2)
 
 
 typedef struct {
@@ -643,181 +639,10 @@ paint_selection (GthImageSelector *self,
 
 	cairo_save (cr);
 
-// #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 9, 2)
-//	cairo_set_operator (cr, CAIRO_OPERATOR_DIFFERENCE);
-// #endif
-
-	gdk_cairo_rectangle (cr, &selection_area);
-	cairo_clip (cr);
-
-	if (self->priv->grid_type == GTH_GRID_THIRDS) {
-
-		int i;
-		
-		cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.60);
-
-		for (i = 1; i < 3; i++) {
-		
-			cairo_move_to (cr, selection_area.x + selection_area.width * i / 3 + 0.5, selection_area.y + 1.5);
-			cairo_line_to (cr, selection_area.x + selection_area.width * i / 3 + 0.5, selection_area.y + selection_area.height - 0.5);
-
-			cairo_move_to (cr, selection_area.x + 1.5, selection_area.y + selection_area.height * i / 3 + 0.5);
-			cairo_line_to (cr, selection_area.x + selection_area.width - 0.5, selection_area.y + selection_area.height * i / 3 + 0.5);
-		}
-
-		cairo_stroke (cr);
-
-		cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.10);
-
-		for (i = 1; i < 9; i++) {
-		
-			if (i % 3 == 0)
-				continue;
-
-			cairo_move_to (cr, selection_area.x + selection_area.width * i / 9 + 0.5, selection_area.y + 1.5);
-			cairo_line_to (cr, selection_area.x + selection_area.width * i / 9 + 0.5, selection_area.y + selection_area.height - 0.5);
-
-			cairo_move_to (cr, selection_area.x + 1.5, selection_area.y + selection_area.height * i / 9 + 0.5);
-			cairo_line_to (cr, selection_area.x + selection_area.width - 0.5, selection_area.y + selection_area.height * i / 9 + 0.5);
-		}
-
-		cairo_stroke (cr);
-	}
-	else if (self->priv->grid_type == GTH_GRID_GOLDEN) {
-
-		cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.60);
-
-		int grid_x0, grid_x1, grid_x2, grid_x3;
-	        int grid_y0, grid_y1, grid_y2, grid_y3;
-		int x_delta, y_delta;
-
-		grid_x0 = selection_area.x;
-		grid_x3 = selection_area.x + selection_area.width;
-
-                grid_y0 = selection_area.y;
-                grid_y3 = selection_area.y + selection_area.height;
-
-		x_delta = selection_area.width * GOLDER_RATIO_FACTOR;
-		y_delta = selection_area.height * GOLDER_RATIO_FACTOR;
-
-		grid_x1 = grid_x0 + x_delta;
-		grid_x2 = grid_x3 - x_delta;
-                grid_y1 = grid_y0 + y_delta;
-                grid_y2 = grid_y3 - y_delta;
-
-		cairo_move_to (cr, grid_x1 + 0.5, grid_y0 + 0.5);
-		cairo_line_to (cr, grid_x1 + 0.5, grid_y3 + 0.5);
-
-		if (x_delta < selection_area.width / 2) {
-			cairo_move_to (cr, grid_x2 + 0.5, grid_y0 + 0.5);
-			cairo_line_to (cr, grid_x2 + 0.5, grid_y3 + 0.5);
-		}
-
-		cairo_move_to (cr, grid_x0 + 0.5, grid_y1 + 0.5);
-		cairo_line_to (cr, grid_x3 + 0.5, grid_y1 + 0.5);
-
-		if (y_delta < selection_area.height / 2) {
-			cairo_move_to (cr, grid_x0 + 0.5, grid_y2 + 0.5);
-			cairo_line_to (cr, grid_x3 + 0.5, grid_y2 + 0.5);
-		}
-
-		cairo_stroke (cr);
-	}
-	else if (self->priv->grid_type == GTH_GRID_CENTER) {
-
-		int i;
-		
-		cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.60);
-
-		cairo_move_to (cr, selection_area.x + selection_area.width / 2 + 0.5, selection_area.y + 1.5);
-		cairo_line_to (cr, selection_area.x + selection_area.width / 2 + 0.5, selection_area.y + selection_area.height - 0.5);
-
-		cairo_move_to (cr, selection_area.x + 1.5, selection_area.y + selection_area.height / 2 + 0.5);
-		cairo_line_to (cr, selection_area.x + selection_area.width - 0.5, selection_area.y + selection_area.height / 2 + 0.5);
-
-		cairo_stroke (cr);
-
-		cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.10);
-
-		for (i = 1; i < 4; i++) {
-		
-			if (i == 2)
-				continue;
-				
-			cairo_move_to (cr, selection_area.x + selection_area.width * i / 4 + 0.5, selection_area.y + 1.5);
-			cairo_line_to (cr, selection_area.x + selection_area.width * i / 4 + 0.5, selection_area.y + selection_area.height - 0.5);
-
-			cairo_move_to (cr, selection_area.x + 1.5, selection_area.y + selection_area.height * i / 4 + 0.5);
-			cairo_line_to (cr, selection_area.x + selection_area.width - 0.5, selection_area.y + selection_area.height * i / 4 + 0.5);
-		}
-
-		cairo_stroke (cr);
-	}
-	else if (self->priv->grid_type == GTH_GRID_UNIFORM) {
-
-		int x;
-		int y;
-		
-		cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.40);
-
-		for (x = GRID_STEP_3; x < selection_area.width; x += GRID_STEP_3) {
-		
-			cairo_move_to (cr, selection_area.x + x + 0.5, selection_area.y + 1.5);
-			cairo_line_to (cr, selection_area.x + x + 0.5, selection_area.y + selection_area.height - 0.5);
-		}
-
-		for (y = GRID_STEP_3; y < selection_area.height; y += GRID_STEP_3) {
-		
-			cairo_move_to (cr, selection_area.x + 1.5, selection_area.y + y + 0.5);
-			cairo_line_to (cr, selection_area.x + selection_area.width - 0.5, selection_area.y + y + 0.5);
-		}
-
-		cairo_stroke (cr);
-
-		cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.20);
-
-		for (x = GRID_STEP_2; x < selection_area.width; x += GRID_STEP_2) {
-		
-			if (x % GRID_STEP_3 == 0)
-				continue;
-
-			cairo_move_to (cr, selection_area.x + x + 0.5, selection_area.y + 1.5);
-			cairo_line_to (cr, selection_area.x + x + 0.5, selection_area.y + selection_area.height - 0.5);
-		}
-
-		for (y = GRID_STEP_2; y < selection_area.height; y += GRID_STEP_2) {
-		
-			if (y % GRID_STEP_3 == 0)
-				continue;
-
-			cairo_move_to (cr, selection_area.x + 1.5, selection_area.y + y + 0.5);
-			cairo_line_to (cr, selection_area.x + selection_area.width - 0.5, selection_area.y + y + 0.5);
-		}
-
-		cairo_stroke (cr);
-
-		cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.10);
-
-		for (x = GRID_STEP_1; x < selection_area.width; x += GRID_STEP_1) {
-		
-			if (x % GRID_STEP_2 == 0)
-				continue;
-				
-			cairo_move_to (cr, selection_area.x + x + 0.5, selection_area.y + 1.5);
-			cairo_line_to (cr, selection_area.x + x + 0.5, selection_area.y + selection_area.height - 0.5);
-		}
-
-		for (y = GRID_STEP_1; y < selection_area.height; y += GRID_STEP_1) {
-		
-			if (y % GRID_STEP_2 == 0)
-				continue;
-				
-			cairo_move_to (cr, selection_area.x + 1.5, selection_area.y + y + 0.5);
-			cairo_line_to (cr, selection_area.x + selection_area.width - 0.5, selection_area.y + y + 0.5);
-		}
-
-		cairo_stroke (cr);
-	}
+#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 9, 2)
+	/*cairo_set_operator (cr, CAIRO_OPERATOR_DIFFERENCE);*/
+#endif
+	_cairo_paint_grid (cr, &selection_area, self->priv->grid_type);
 
 	cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 1.0);
 
@@ -832,7 +657,7 @@ paint_selection (GthImageSelector *self,
 				 self->priv->current_area->area.y + self->priv->viewer->image_area.y + 0.5,
 				 self->priv->current_area->area.width - 1,
 				 self->priv->current_area->area.height - 1);
-	
+
 	cairo_stroke (cr);
 
 	cairo_restore (cr);
diff --git a/gthumb/gth-image-selector.h b/gthumb/gth-image-selector.h
index 5926008..610615b 100644
--- a/gthumb/gth-image-selector.h
+++ b/gthumb/gth-image-selector.h
@@ -45,14 +45,6 @@ typedef enum {
 	GTH_SELECTOR_TYPE_POINT
 } GthSelectorType;
 
-typedef enum {
-	GTH_GRID_NONE = 0,
-	GTH_GRID_THIRDS,
-	GTH_GRID_GOLDEN,
-	GTH_GRID_CENTER,
-	GTH_GRID_UNIFORM
-} GthGridType;
-
 struct _GthImageSelector
 {
 	GObject __parent;
diff --git a/gthumb/typedefs.h b/gthumb/typedefs.h
index c19ae4c..2d423df 100644
--- a/gthumb/typedefs.h
+++ b/gthumb/typedefs.h
@@ -124,6 +124,14 @@ typedef enum {
 } GthOverwriteMode;
 
 
+typedef enum {
+	GTH_GRID_NONE = 0,
+	GTH_GRID_THIRDS,
+	GTH_GRID_GOLDEN,
+	GTH_GRID_CENTER,
+	GTH_GRID_UNIFORM
+} GthGridType;
+
 typedef void (*DataFunc)         (gpointer    user_data);
 typedef void (*ReadyFunc)        (GError     *error,
 			 	  gpointer    user_data);



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