[gthumb] added an optional rule-of-thirds grid to the crop tool, bug 618026



commit 093455720c3c5d23d6beebe0b6ba21847c5691c5
Author: Michael J. Chudobiak <mjc avtechpulse com>
Date:   Fri May 7 14:28:13 2010 -0400

    added an optional rule-of-thirds grid to the crop tool, bug 618026

 extensions/file_tools/data/ui/crop-options.ui |   27 +++++++++++-
 extensions/file_tools/gth-file-tool-crop.c    |   13 +++++
 gthumb/gth-image-selector.c                   |   59 +++++++++++++++++++++++++
 gthumb/gth-image-selector.h                   |    4 ++
 4 files changed, 102 insertions(+), 1 deletions(-)
---
diff --git a/extensions/file_tools/data/ui/crop-options.ui b/extensions/file_tools/data/ui/crop-options.ui
index 6c52f64..9aef692 100644
--- a/extensions/file_tools/data/ui/crop-options.ui
+++ b/extensions/file_tools/data/ui/crop-options.ui
@@ -31,7 +31,7 @@
                         <child>
                           <object class="GtkTable" id="table2">
                             <property name="visible">True</property>
-                            <property name="n_rows">4</property>
+                            <property name="n_rows">5</property>
                             <property name="n_columns">2</property>
                             <property name="column_spacing">6</property>
                             <property name="row_spacing">6</property>
@@ -197,6 +197,31 @@
                                 <property name="y_options">GTK_FILL</property>
                               </packing>
                             </child>
+                            <child>
+                              <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>
+                                    <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>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">False</property>
+                                    <property name="position">0</property>
+                                  </packing>
+                                </child>
+                              </object>
+                              <packing>
+                                <property name="right_attach">2</property>
+                                <property name="top_attach">4</property>
+                                <property name="bottom_attach">5</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 d00fd83..f678f05 100644
--- a/extensions/file_tools/gth-file-tool-crop.c
+++ b/extensions/file_tools/gth-file-tool-crop.c
@@ -325,6 +325,14 @@ invert_ratio_changed_cb (GtkSpinButton    *spin,
 }
 
 
+static void
+show_grid_changed_cb (GtkCheckButton  *button,
+		      GthFileToolCrop *self)
+{
+	gth_image_selector_set_grid_visible (self->priv->selector, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)));
+}
+
+
 static GtkWidget *
 gth_file_tool_crop_get_options (GthFileTool *base)
 {
@@ -425,6 +433,10 @@ 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),
+                          self);
 
 	self->priv->selector = (GthImageSelector *) gth_image_selector_new (GTH_IMAGE_VIEWER (viewer), GTH_SELECTOR_TYPE_REGION);
 	g_signal_connect (self->priv->selector,
@@ -438,6 +450,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);
 
 	return options;
 }
diff --git a/gthumb/gth-image-selector.c b/gthumb/gth-image-selector.c
index 6246d01..f8bb6c2 100644
--- a/gthumb/gth-image-selector.c
+++ b/gthumb/gth-image-selector.c
@@ -181,6 +181,7 @@ enum {
 	SELECTED,
 	MOTION_NOTIFY,
 	MASK_VISIBILITY_CHANGED,
+	GRID_VISIBILITY_CHANGED,
 	LAST_SIGNAL
 };
 
@@ -200,6 +201,7 @@ struct _GthImageSelectorPrivate {
 	gboolean         use_ratio;
 	double           ratio;
 	gboolean         mask_visible;
+	gboolean         grid_visible;
 	gboolean         active;
 
 	GdkRectangle     drag_start_selection_area;
@@ -635,6 +637,33 @@ paint_selection (GthImageSelector *self,
 				paint_area.width,
 				paint_area.height,
 				GDK_INTERP_TILES);
+
+	if (self->priv->grid_visible) {
+		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);
+	        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);
+	        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);
+	}
 }
 
 
@@ -1281,6 +1310,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;
 }
 
 
@@ -1349,6 +1379,14 @@ gth_image_selector_class_init (GthImageSelectorClass *class)
 							 g_cclosure_marshal_VOID__VOID,
 							 G_TYPE_NONE,
 							 0);
+        signals[GRID_VISIBILITY_CHANGED] = g_signal_new ("grid_visibility_changed",
+                                                         G_TYPE_FROM_CLASS (class),
+                                                         G_SIGNAL_RUN_LAST,
+                                                         G_STRUCT_OFFSET (GthImageSelectorClass, grid_visibility_changed),
+                                                         NULL, NULL,
+                                                         g_cclosure_marshal_VOID__VOID,
+                                                         G_TYPE_NONE,
+                                                         0);
 }
 
 
@@ -1553,9 +1591,30 @@ gth_image_selector_set_mask_visible (GthImageSelector *self,
 }
 
 
+void
+gth_image_selector_set_grid_visible (GthImageSelector *self,
+                                     gboolean          visible)
+{
+        if (visible == self->priv->grid_visible)
+                return;
+
+        self->priv->grid_visible = visible;
+        gtk_widget_queue_draw (GTK_WIDGET (self->priv->viewer));
+        g_signal_emit (G_OBJECT (self),
+                       signals[GRID_VISIBILITY_CHANGED],
+                       0);
+}
+
+
 gboolean
 gth_image_selector_get_mask_visible (GthImageSelector *self)
 {
 	return self->priv->mask_visible;
 }
 
+
+gboolean
+gth_image_selector_get_grid_visible (GthImageSelector *self)
+{
+        return self->priv->grid_visible;
+}
diff --git a/gthumb/gth-image-selector.h b/gthumb/gth-image-selector.h
index 0a548d5..b164443 100644
--- a/gthumb/gth-image-selector.h
+++ b/gthumb/gth-image-selector.h
@@ -66,6 +66,7 @@ struct _GthImageSelectorClass
 					  int               x,
 					  int               y);
 	void (* mask_visibility_changed) (GthImageSelector *selector);
+        void (* grid_visibility_changed) (GthImageSelector *selector);
 };
 
 GType                 gth_image_selector_get_type             (void);
@@ -92,6 +93,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);
 
 G_END_DECLS
 



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