[gthumb] crop: added ability to maximize and center the selection



commit 1fa5cf2ee51696284db6910aaf6cd5900b10f795
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Wed Apr 6 14:30:12 2011 +0200

    crop: added ability to maximize and center the selection
    
    [new feature, bug #644345]

 extensions/file_tools/data/ui/crop-options.ui |   58 +++++++++++++++++++++++--
 extensions/file_tools/gth-file-tool-crop.c    |   31 +++++++++++++
 gthumb/gth-image-selector.c                   |   54 ++++++++++++++++++-----
 gthumb/gth-image-selector.h                   |   12 +++--
 4 files changed, 135 insertions(+), 20 deletions(-)
---
diff --git a/extensions/file_tools/data/ui/crop-options.ui b/extensions/file_tools/data/ui/crop-options.ui
index 7735609..c1b5390 100644
--- a/extensions/file_tools/data/ui/crop-options.ui
+++ b/extensions/file_tools/data/ui/crop-options.ui
@@ -8,11 +8,9 @@
     <child>
       <object class="GtkVBox" id="vbox2">
         <property name="visible">True</property>
-        <property name="orientation">vertical</property>
         <child>
           <object class="GtkVBox" id="vbox1">
             <property name="visible">True</property>
-            <property name="orientation">vertical</property>
             <property name="spacing">12</property>
             <child>
               <object class="GtkFrame" id="frame4">
@@ -27,7 +25,7 @@
                     <child>
                       <object class="GtkVBox" id="vbox10">
                         <property name="visible">True</property>
-                        <property name="orientation">vertical</property>
+                        <property name="spacing">6</property>
                         <child>
                           <object class="GtkTable" id="table2">
                             <property name="visible">True</property>
@@ -191,6 +189,7 @@
                               <packing>
                                 <property name="top_attach">2</property>
                                 <property name="bottom_attach">3</property>
+                                <property name="x_options">GTK_FILL</property>
                               </packing>
                             </child>
                           </object>
@@ -198,6 +197,58 @@
                             <property name="position">0</property>
                           </packing>
                         </child>
+                        <child>
+                          <object class="GtkHButtonBox" id="hbuttonbox2">
+                            <property name="visible">True</property>
+                            <property name="border_width">6</property>
+                            <property name="layout_style">spread</property>
+                            <child>
+                              <object class="GtkButton" id="maximize_button">
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="receives_default">True</property>
+                                <child>
+                                  <object class="GtkLabel" id="label4">
+                                    <property name="visible">True</property>
+                                    <property name="label" translatable="yes">Maximize</property>
+                                    <attributes>
+                                      <attribute name="size" value="8000"/>
+                                    </attributes>
+                                  </object>
+                                </child>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">False</property>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkButton" id="center_button">
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="receives_default">True</property>
+                                <child>
+                                  <object class="GtkLabel" id="label5">
+                                    <property name="visible">True</property>
+                                    <property name="label" translatable="yes">Center</property>
+                                    <attributes>
+                                      <attribute name="size" value="8000"/>
+                                    </attributes>
+                                  </object>
+                                </child>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">False</property>
+                                <property name="position">1</property>
+                              </packing>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
                       </object>
                     </child>
                   </object>
@@ -231,7 +282,6 @@
                     <child>
                       <object class="GtkVBox" id="vbox8">
                         <property name="visible">True</property>
-                        <property name="orientation">vertical</property>
                         <property name="spacing">6</property>
                         <child>
                           <object class="GtkHBox" id="ratio_combobox_box">
diff --git a/extensions/file_tools/gth-file-tool-crop.c b/extensions/file_tools/gth-file-tool-crop.c
index 3b18f94..75b54b8 100644
--- a/extensions/file_tools/gth-file-tool-crop.c
+++ b/extensions/file_tools/gth-file-tool-crop.c
@@ -357,6 +357,29 @@ bind_factor_spinbutton_value_changed_cb (GtkSpinButton *spinbutton,
 }
 
 
+static void
+maximize_button_clicked_cb (GtkButton *button,
+			    gpointer   user_data)
+{
+	GthFileToolCrop *self = user_data;
+
+	gth_image_selector_set_selection_pos (self->priv->selector, 0, 0);
+	if (! gth_image_selector_set_selection_width (self->priv->selector, self->priv->pixbuf_width) || ! gth_image_selector_get_use_ratio (self->priv->selector))
+		gth_image_selector_set_selection_height (self->priv->selector, self->priv->pixbuf_height);
+	gth_image_selector_center (self->priv->selector);
+}
+
+
+static void
+center_button_clicked_cb (GtkButton *button,
+			  gpointer   user_data)
+{
+	GthFileToolCrop *self = user_data;
+
+	gth_image_selector_center (self->priv->selector);
+}
+
+
 static GtkWidget *
 gth_file_tool_crop_get_options (GthFileTool *base)
 {
@@ -486,6 +509,14 @@ gth_file_tool_crop_get_options (GthFileTool *base)
 			  "value-changed",
 			  G_CALLBACK (bind_factor_spinbutton_value_changed_cb),
 			  self);
+	g_signal_connect (GET_WIDGET ("maximize_button"),
+			  "clicked",
+			  G_CALLBACK (maximize_button_clicked_cb),
+			  self);
+	g_signal_connect (GET_WIDGET ("center_button"),
+			  "clicked",
+			  G_CALLBACK (center_button_clicked_cb),
+			  self);
 
 	self->priv->selector = (GthImageSelector *) gth_image_selector_new (GTH_IMAGE_VIEWER (viewer), GTH_SELECTOR_TYPE_REGION);
 	gth_image_selector_set_grid_type (self->priv->selector, gtk_combo_box_get_active (GTK_COMBO_BOX (self->priv->grid_type_combobox)));
diff --git a/gthumb/gth-image-selector.c b/gthumb/gth-image-selector.c
index 8e694c9..c113476 100644
--- a/gthumb/gth-image-selector.c
+++ b/gthumb/gth-image-selector.c
@@ -908,7 +908,7 @@ bind_dimension (int dimension,
 }
 
 
-static void
+static gboolean
 check_and_set_new_selection (GthImageSelector *self,
 			     GdkRectangle      new_selection)
 {
@@ -924,9 +924,11 @@ check_and_set_new_selection (GthImageSelector *self,
 	     || (self->priv->current_area->id != C_SELECTION_AREA))
 	    && self->priv->use_ratio)
 	{
-		if (rectangle_in_rectangle (new_selection, self->priv->pixbuf_area))
-			set_selection (self, new_selection, FALSE);
-		return;
+		if (! rectangle_in_rectangle (new_selection, self->priv->pixbuf_area))
+			return FALSE;
+
+		set_selection (self, new_selection, FALSE);
+		return TRUE;
 	}
 
 	/* self->priv->current_area->id == C_SELECTION_AREA */
@@ -946,6 +948,8 @@ check_and_set_new_selection (GthImageSelector *self,
 		new_selection.y = self->priv->pixbuf_area.height - new_selection.height;
 
 	set_selection (self, new_selection, FALSE);
+
+	return TRUE;
 }
 
 
@@ -1678,7 +1682,7 @@ gth_image_selector_new (GthImageViewer  *viewer,
 }
 
 
-void
+gboolean
 gth_image_selector_set_selection_x (GthImageSelector *self,
 				    int               x)
 {
@@ -1686,11 +1690,11 @@ gth_image_selector_set_selection_x (GthImageSelector *self,
 
 	new_selection = self->priv->selection;
 	new_selection.x = x;
-	check_and_set_new_selection (self, new_selection);
+	return check_and_set_new_selection (self, new_selection);
 }
 
 
-void
+gboolean
 gth_image_selector_set_selection_y (GthImageSelector *self,
 				    int               y)
 {
@@ -1698,11 +1702,25 @@ gth_image_selector_set_selection_y (GthImageSelector *self,
 
 	new_selection = self->priv->selection;
 	new_selection.y = y;
-	check_and_set_new_selection (self, new_selection);
+	return check_and_set_new_selection (self, new_selection);
 }
 
 
-void
+gboolean
+gth_image_selector_set_selection_pos (GthImageSelector *self,
+				      int               x,
+				      int               y)
+{
+	GdkRectangle new_selection;
+
+	new_selection = self->priv->selection;
+	new_selection.x = x;
+	new_selection.y = y;
+	return check_and_set_new_selection (self, new_selection);
+}
+
+
+gboolean
 gth_image_selector_set_selection_width (GthImageSelector *self,
 					int               width)
 {
@@ -1712,11 +1730,11 @@ gth_image_selector_set_selection_width (GthImageSelector *self,
 	new_selection.width = width;
 	if (self->priv->use_ratio)
 		new_selection.height = IROUND (width / self->priv->ratio);
-	check_and_set_new_selection (self, new_selection);
+	return check_and_set_new_selection (self, new_selection);
 }
 
 
-void
+gboolean
 gth_image_selector_set_selection_height (GthImageSelector *self,
 					 int               height)
 {
@@ -1726,7 +1744,7 @@ gth_image_selector_set_selection_height (GthImageSelector *self,
 	new_selection.height = height;
 	if (self->priv->use_ratio)
 		new_selection.width = IROUND (height * self->priv->ratio);
-	check_and_set_new_selection (self, new_selection);
+	return check_and_set_new_selection (self, new_selection);
 }
 
 
@@ -1851,3 +1869,15 @@ gth_image_selector_bind_dimensions (GthImageSelector *self,
 	self->priv->bind_dimensions = bind;
 	self->priv->bind_factor = factor;
 }
+
+
+void
+gth_image_selector_center (GthImageSelector *self)
+{
+	GdkRectangle new_selection;
+
+	new_selection = self->priv->selection;
+	new_selection.x = (self->priv->pixbuf_area.width - new_selection.width) / 2;
+	new_selection.y = (self->priv->pixbuf_area.height - new_selection.height) / 2;
+	check_and_set_new_selection (self, new_selection);
+}
diff --git a/gthumb/gth-image-selector.h b/gthumb/gth-image-selector.h
index 2d794f4..ffa5254 100644
--- a/gthumb/gth-image-selector.h
+++ b/gthumb/gth-image-selector.h
@@ -78,13 +78,16 @@ struct _GthImageSelectorClass
 GType                 gth_image_selector_get_type             (void);
 GthImageViewerTool *  gth_image_selector_new                  (GthImageViewer   *viewer,
 							       GthSelectorType   type);
-void                  gth_image_selector_set_selection_x      (GthImageSelector *selector,
+gboolean              gth_image_selector_set_selection_x      (GthImageSelector *selector,
 							       int               x);
-void                  gth_image_selector_set_selection_y      (GthImageSelector *selector,
+gboolean              gth_image_selector_set_selection_y      (GthImageSelector *selector,
 							       int               y);
-void                  gth_image_selector_set_selection_width  (GthImageSelector *selector,
+gboolean              gth_image_selector_set_selection_pos    (GthImageSelector *selector,
+							       int               x,
+							       int               y);
+gboolean              gth_image_selector_set_selection_width  (GthImageSelector *selector,
 							       int               width);
-void                  gth_image_selector_set_selection_height (GthImageSelector *selector,
+gboolean              gth_image_selector_set_selection_height (GthImageSelector *selector,
 							       int               height);
 void                  gth_image_selector_set_selection        (GthImageSelector *selector,
 							       GdkRectangle      selection);
@@ -105,6 +108,7 @@ GthGridType           gth_image_selector_get_grid_type        (GthImageSelector
 void                  gth_image_selector_bind_dimensions      (GthImageSelector *selector,
 							       gboolean          bind,
 							       int               factor);
+void                  gth_image_selector_center               (GthImageSelector *selector);
 
 G_END_DECLS
 



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