[gthumb] added golden sections cropping grid



commit d18d2e4373ed8e183a2933e5b48ca97d88ca9500
Author: Michael J. Chudobiak <mjc avtechpulse com>
Date:   Mon May 10 09:10:44 2010 -0400

    added golden sections cropping grid

 extensions/file_tools/data/ui/crop-options.ui |   28 ++++++---
 extensions/file_tools/gth-file-tool-crop.c    |   17 ++++--
 gthumb/gth-image-selector.c                   |   78 +++++++++++++++----------
 gthumb/gth-image-selector.h                   |   12 +++-
 4 files changed, 88 insertions(+), 47 deletions(-)
---
diff --git a/extensions/file_tools/data/ui/crop-options.ui b/extensions/file_tools/data/ui/crop-options.ui
index 9aef692..e88e2b0 100644
--- a/extensions/file_tools/data/ui/crop-options.ui
+++ b/extensions/file_tools/data/ui/crop-options.ui
@@ -201,27 +201,39 @@
                               <object class="GtkHBox" id="hbox1">
                                 <property name="visible">True</property>
                                 <child>
-                                  <object class="GtkCheckButton" id="show_grid_checkbutton">
-                                    <property name="label" translatable="yes">Show _grid</property>
+                                  <object class="GtkHBox" id="grid_type_combobox_box">
                                     <property name="visible">True</property>
-                                    <property name="can_focus">True</property>
-                                    <property name="receives_default">False</property>
-                                    <property name="use_underline">True</property>
-                                    <property name="draw_indicator">True</property>
+                                    <child>
+                                      <placeholder/>
+                                    </child>
                                   </object>
                                   <packing>
-                                    <property name="expand">False</property>
-                                    <property name="fill">False</property>
                                     <property name="position">0</property>
                                   </packing>
                                 </child>
                               </object>
                               <packing>
+                                <property name="left_attach">1</property>
                                 <property name="right_attach">2</property>
                                 <property name="top_attach">4</property>
                                 <property name="bottom_attach">5</property>
                               </packing>
                             </child>
+                            <child>
+                              <object class="GtkLabel" id="crop_grid_label">
+                                <property name="visible">True</property>
+                                <property name="xalign">0</property>
+                                <property name="label" translatable="yes">_Grid:</property>
+                                <property name="use_underline">True</property>
+                                <property name="mnemonic_widget">crop_x_spinbutton</property>
+                              </object>
+                              <packing>
+                                <property name="top_attach">4</property>
+                                <property name="bottom_attach">5</property>
+                                <property name="x_options">GTK_FILL</property>
+                                <property name="y_options"></property>
+                              </packing>
+                            </child>
                           </object>
                           <packing>
                             <property name="position">0</property>
diff --git a/extensions/file_tools/gth-file-tool-crop.c b/extensions/file_tools/gth-file-tool-crop.c
index f678f05..77ac1ed 100644
--- a/extensions/file_tools/gth-file-tool-crop.c
+++ b/extensions/file_tools/gth-file-tool-crop.c
@@ -62,6 +62,7 @@ struct _GthFileToolCropPrivate {
 	GtkWidget        *crop_y_spinbutton;
 	GtkWidget        *crop_width_spinbutton;
 	GtkWidget        *crop_height_spinbutton;
+	GtkWidget	 *grid_type_combobox;
 };
 
 
@@ -326,10 +327,10 @@ invert_ratio_changed_cb (GtkSpinButton    *spin,
 
 
 static void
-show_grid_changed_cb (GtkCheckButton  *button,
+grid_type_changed_cb (GtkComboBox     *combobox,
 		      GthFileToolCrop *self)
 {
-	gth_image_selector_set_grid_visible (self->priv->selector, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)));
+	gth_image_selector_set_grid_type (self->priv->selector, gtk_combo_box_get_active (combobox));
 }
 
 
@@ -393,6 +394,10 @@ gth_file_tool_crop_get_options (GthFileTool *base)
 	gtk_widget_show (self->priv->ratio_combobox);
 	gtk_box_pack_start (GTK_BOX (GET_WIDGET ("ratio_combobox_box")), self->priv->ratio_combobox, FALSE, FALSE, 0);
 
+	self->priv->grid_type_combobox = _gtk_combo_box_new_with_texts (_("None"), _("Rule of Thirds"), _("Golden Sections"), NULL);
+	gtk_widget_show (self->priv->grid_type_combobox);
+	gtk_box_pack_start (GTK_BOX (GET_WIDGET ("grid_type_combobox_box")), self->priv->grid_type_combobox, FALSE, FALSE, 0);
+
 	g_signal_connect (GET_WIDGET ("crop_button"),
 			  "clicked",
 			  G_CALLBACK (crop_button_clicked_cb),
@@ -433,9 +438,9 @@ gth_file_tool_crop_get_options (GthFileTool *base)
 			  "toggled",
 			  G_CALLBACK (invert_ratio_changed_cb),
 			  self);
-        g_signal_connect (GET_WIDGET ("show_grid_checkbutton"),
-                          "toggled",
-                          G_CALLBACK (show_grid_changed_cb),
+        g_signal_connect (self->priv->grid_type_combobox,
+                          "changed",
+                          G_CALLBACK (grid_type_changed_cb),
                           self);
 
 	self->priv->selector = (GthImageSelector *) gth_image_selector_new (GTH_IMAGE_VIEWER (viewer), GTH_SELECTOR_TYPE_REGION);
@@ -450,7 +455,7 @@ gth_file_tool_crop_get_options (GthFileTool *base)
 
 	gtk_combo_box_set_active (GTK_COMBO_BOX (self->priv->ratio_combobox), 0);
 	gth_image_viewer_set_tool (GTH_IMAGE_VIEWER (viewer), (GthImageViewerTool *) self->priv->selector);
-	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (_gtk_builder_get_widget (self->priv->builder, "show_grid_checkbutton")), TRUE);
+	gtk_combo_box_set_active (GTK_COMBO_BOX (self->priv->grid_type_combobox), GTH_GRID_THIRDS);
 
 	return options;
 }
diff --git a/gthumb/gth-image-selector.c b/gthumb/gth-image-selector.c
index f8bb6c2..a8d62fc 100644
--- a/gthumb/gth-image-selector.c
+++ b/gthumb/gth-image-selector.c
@@ -34,6 +34,7 @@
 #define DRAG_THRESHOLD 1
 #define STEP_INCREMENT 20.0  /* scroll increment. */
 #define SCROLL_TIMEOUT 30    /* autoscroll timeout in milliseconds */
+#define GOLDEN_RATIO   1.6180339887
 
 
 typedef struct {
@@ -201,7 +202,7 @@ struct _GthImageSelectorPrivate {
 	gboolean         use_ratio;
 	double           ratio;
 	gboolean         mask_visible;
-	gboolean         grid_visible;
+	GthGridType      grid_type;
 	gboolean         active;
 
 	GdkRectangle     drag_start_selection_area;
@@ -621,6 +622,10 @@ paint_selection (GthImageSelector *self,
 {
 	GdkRectangle selection_area, paint_area;
 
+	int grid_x0, grid_x1, grid_x2, grid_x3;
+        int grid_y0, grid_y1, grid_y2, grid_y3;
+	int x_delta, y_delta;
+
 	selection_area = self->priv->selection_area;
 	selection_area.x += self->priv->viewer->image_area.x - self->priv->viewer->x_offset;
 	selection_area.y += self->priv->viewer->image_area.y - self->priv->viewer->y_offset;
@@ -638,31 +643,44 @@ paint_selection (GthImageSelector *self,
 				paint_area.height,
 				GDK_INTERP_TILES);
 
-	if (self->priv->grid_visible) {
+	if (self->priv->grid_type != GTH_GRID_NONE) {
+
+		grid_x0 = paint_area.x;
+		grid_x3 = paint_area.x+paint_area.width;
+
+                grid_y0 = paint_area.y;
+                grid_y3 = paint_area.y+paint_area.height;
+
+		if (self->priv->grid_type == GTH_GRID_THIRDS) {
+			x_delta = paint_area.width / 3;
+			y_delta = paint_area.height /3;
+		} else if (self->priv->grid_type == GTH_GRID_GOLDEN) {
+			x_delta = paint_area.width * (GOLDEN_RATIO / (1.0 + 2.0 * GOLDEN_RATIO));
+			y_delta = paint_area.height * (GOLDEN_RATIO / (1.0 + 2.0 * GOLDEN_RATIO));
+		}
+
+		grid_x1 = grid_x0 + x_delta;
+		grid_x2 = grid_x3 - x_delta;
+                grid_y1 = grid_y0 + y_delta;
+                grid_y2 = grid_y3 - y_delta;
+
 		gdk_draw_line (GTK_WIDGET (self->priv->viewer)->window,
 			       self->priv->selection_gc,
-			       paint_area.x+paint_area.width/3,
-			       paint_area.y,
-			       paint_area.x+paint_area.width/3,
-			       paint_area.y+paint_area.height);
-	        gdk_draw_line (GTK_WIDGET (self->priv->viewer)->window,
-        	               self->priv->selection_gc,
-                	       paint_area.x+2*paint_area.width/3,
-	                       paint_area.y,
-        	               paint_area.x+2*paint_area.width/3,
-                	       paint_area.y+paint_area.height);
+			       grid_x1, grid_y0,
+			       grid_x1, grid_y3);
 	        gdk_draw_line (GTK_WIDGET (self->priv->viewer)->window,
-        	               self->priv->selection_gc,
-                	       paint_area.x,
-	                       paint_area.y+paint_area.height/3,
-        	               paint_area.x+paint_area.width,
-                	       paint_area.y+paint_area.height/3);
+       		               self->priv->selection_gc,
+ 			       grid_x2, grid_y0,
+			       grid_x2, grid_y3);
+        	gdk_draw_line (GTK_WIDGET (self->priv->viewer)->window,
+       	        	       self->priv->selection_gc,
+                               grid_x0, grid_y1,
+                               grid_x3, grid_y1);
 	        gdk_draw_line (GTK_WIDGET (self->priv->viewer)->window,
-        	               self->priv->selection_gc,
-                	       paint_area.x,
-	                       paint_area.y+2*paint_area.height/3,
-        	               paint_area.x+paint_area.width,
-                	       paint_area.y+2*paint_area.height/3);
+       		               self->priv->selection_gc,
+                               grid_x0, grid_y2,
+                               grid_x3, grid_y2);
+
 	}
 }
 
@@ -1310,7 +1328,7 @@ gth_image_selector_instance_init (GthImageSelector *self)
 	self->priv->type = GTH_SELECTOR_TYPE_REGION;
 	self->priv->ratio = 1.0;
 	self->priv->mask_visible = TRUE;
-	self->priv->grid_visible = FALSE;
+	self->priv->grid_type = GTH_GRID_NONE;
 }
 
 
@@ -1592,13 +1610,13 @@ gth_image_selector_set_mask_visible (GthImageSelector *self,
 
 
 void
-gth_image_selector_set_grid_visible (GthImageSelector *self,
-                                     gboolean          visible)
+gth_image_selector_set_grid_type (GthImageSelector *self,
+                                  GthGridType       grid_type)
 {
-        if (visible == self->priv->grid_visible)
+        if (grid_type == self->priv->grid_type)
                 return;
 
-        self->priv->grid_visible = visible;
+        self->priv->grid_type = grid_type;
         gtk_widget_queue_draw (GTK_WIDGET (self->priv->viewer));
         g_signal_emit (G_OBJECT (self),
                        signals[GRID_VISIBILITY_CHANGED],
@@ -1613,8 +1631,8 @@ gth_image_selector_get_mask_visible (GthImageSelector *self)
 }
 
 
-gboolean
-gth_image_selector_get_grid_visible (GthImageSelector *self)
+GthGridType
+gth_image_selector_get_grid_type (GthImageSelector *self)
 {
-        return self->priv->grid_visible;
+        return self->priv->grid_type;
 }
diff --git a/gthumb/gth-image-selector.h b/gthumb/gth-image-selector.h
index b164443..968c23d 100644
--- a/gthumb/gth-image-selector.h
+++ b/gthumb/gth-image-selector.h
@@ -46,6 +46,12 @@ typedef enum {
 	GTH_SELECTOR_TYPE_POINT
 } GthSelectorType;
 
+typedef enum {
+	GTH_GRID_NONE = 0,
+	GTH_GRID_THIRDS,
+	GTH_GRID_GOLDEN
+} GthGridType;
+
 struct _GthImageSelector
 {
 	GObject __parent;
@@ -93,9 +99,9 @@ gboolean              gth_image_selector_get_use_ratio        (GthImageSelector
 void                  gth_image_selector_set_mask_visible     (GthImageSelector *selector,
 							       gboolean          visible);
 gboolean              gth_image_selector_get_mask_visible     (GthImageSelector *selector);
-void                  gth_image_selector_set_grid_visible     (GthImageSelector *selector,
-                                                               gboolean          visible);
-gboolean              gth_image_selector_get_grid_visible     (GthImageSelector *selector);
+void                  gth_image_selector_set_grid_type        (GthImageSelector *selector,
+                                                               GthGridType       grid_type);
+GthGridType           gth_image_selector_get_grid_type        (GthImageSelector *selector);
 
 G_END_DECLS
 



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