[gthumb: 116/129] image selector: new grid type, performance and cosmetic improvements



commit d5eb5b253b4bca8293df4f606a490edb33e842b0
Author: Stefano Pettini <spettini users sourceforge net>
Date:   Mon Apr 25 14:09:07 2011 +0100

    image selector: new grid type, performance and cosmetic improvements

 extensions/file_tools/gth-file-tool-crop.c   |    1 +
 extensions/file_tools/gth-file-tool-rotate.c |    3 +
 gthumb/gth-image-selector.c                  |  165 +++++++++++++++++++++++---
 gthumb/gth-image-selector.h                  |    3 +-
 4 files changed, 152 insertions(+), 20 deletions(-)
---
diff --git a/extensions/file_tools/gth-file-tool-crop.c b/extensions/file_tools/gth-file-tool-crop.c
index 5bdbe53..8653f09 100644
--- a/extensions/file_tools/gth-file-tool-crop.c
+++ b/extensions/file_tools/gth-file-tool-crop.c
@@ -449,6 +449,7 @@ gth_file_tool_crop_get_options (GthFileTool *base)
 									_("Rule of Thirds"),
 									_("Golden Sections"),
 									_("Center Lines"),
+									_("Uniform"),
 									NULL);
 	gtk_combo_box_set_active (GTK_COMBO_BOX (self->priv->grid_type_combobox), eel_gconf_get_enum (PREF_CROP_GRID_TYPE, GTH_TYPE_GRID_TYPE, GTH_GRID_THIRDS));
 	gtk_widget_show (self->priv->grid_type_combobox);
diff --git a/extensions/file_tools/gth-file-tool-rotate.c b/extensions/file_tools/gth-file-tool-rotate.c
index b75bddd..3818789 100644
--- a/extensions/file_tools/gth-file-tool-rotate.c
+++ b/extensions/file_tools/gth-file-tool-rotate.c
@@ -409,7 +409,10 @@ gth_file_tool_rotate_get_options (GthFileTool *base)
 	self->priv->selector_align = (GthImageSelector *) gth_image_selector_new (GTH_IMAGE_VIEWER (viewer), GTH_SELECTOR_TYPE_POINT);
 
 	gth_image_selector_set_mask_visible (self->priv->selector_crop, TRUE);
+	gth_image_selector_set_grid_type (self->priv->selector_crop, GTH_GRID_UNIFORM);
+	
 	gth_image_selector_set_mask_visible (self->priv->selector_align, TRUE);
+
 	self->priv->selector_align_point = 0;
 	
 	g_signal_connect (GET_WIDGET ("apply_button"),
diff --git a/gthumb/gth-image-selector.c b/gthumb/gth-image-selector.c
index c113476..1700ded 100644
--- a/gthumb/gth-image-selector.c
+++ b/gthumb/gth-image-selector.c
@@ -34,6 +34,9 @@
 #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 {
@@ -642,17 +645,51 @@ paint_selection (GthImageSelector *self,
 					       GDK_INTERP_TILES);
 
 	cairo_save (cr);
-#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 9, 2)
-	cairo_set_operator (cr, CAIRO_OPERATOR_DIFFERENCE);
-	cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
-#else
-	cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
-#endif
+
+// #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_NONE) {
+	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;
@@ -663,18 +700,8 @@ paint_selection (GthImageSelector *self,
                 grid_y0 = selection_area.y;
                 grid_y3 = selection_area.y + selection_area.height;
 
-		if (self->priv->grid_type == GTH_GRID_THIRDS) {
-			x_delta = selection_area.width / 3;
-			y_delta = selection_area.height / 3;
-		}
-		else if (self->priv->grid_type == GTH_GRID_GOLDEN) {
-			x_delta = selection_area.width * GOLDER_RATIO_FACTOR;
-			y_delta = selection_area.height * GOLDER_RATIO_FACTOR;
-		}
-		else if (self->priv->grid_type == GTH_GRID_CENTER) {
-			x_delta = selection_area.width / 2;
-			y_delta = selection_area.height / 2;
-		}
+		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;
@@ -696,7 +723,106 @@ paint_selection (GthImageSelector *self,
 			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);
+	}
+
+	cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 1.0);
 
 	cairo_rectangle (cr,
 			 selection_area.x + 0.5,
@@ -709,6 +835,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 ffa5254..5926008 100644
--- a/gthumb/gth-image-selector.h
+++ b/gthumb/gth-image-selector.h
@@ -49,7 +49,8 @@ typedef enum {
 	GTH_GRID_NONE = 0,
 	GTH_GRID_THIRDS,
 	GTH_GRID_GOLDEN,
-	GTH_GRID_CENTER
+	GTH_GRID_CENTER,
+	GTH_GRID_UNIFORM
 } GthGridType;
 
 struct _GthImageSelector



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