[gimp] app: add "clipping" option to the flip tool



commit 19f5f671d80dfe25e9a802c0e82338d8ab6040ff
Author: Ell <ell_se yahoo com>
Date:   Sun Jun 11 14:49:23 2017 -0400

    app: add "clipping" option to the flip tool
    
    This option behaves similarly to the other transform tool, however
    it's limited to "adjust" and "clip" only.  Now that the flip tool
    can reflect across guides, this option is meaningful.

 app/tools/gimpflipoptions.c |   36 +++++++++++++++++++++++++--------
 app/tools/gimpfliptool.c    |   46 ++++++++++++++++++++++++++++++++++--------
 2 files changed, 64 insertions(+), 18 deletions(-)
---
diff --git a/app/tools/gimpflipoptions.c b/app/tools/gimpflipoptions.c
index 5f68a93..8a80f5b 100644
--- a/app/tools/gimpflipoptions.c
+++ b/app/tools/gimpflipoptions.c
@@ -117,15 +117,18 @@ gimp_flip_options_get_property (GObject    *object,
 GtkWidget *
 gimp_flip_options_gui (GimpToolOptions *tool_options)
 {
-  GObject         *config  = G_OBJECT (tool_options);
-  GimpFlipOptions *options = GIMP_FLIP_OPTIONS (tool_options);
-  GtkWidget       *vbox    = gimp_tool_options_gui (tool_options);
-  GtkWidget       *hbox;
-  GtkWidget       *box;
-  GtkWidget       *label;
-  GtkWidget       *frame;
-  gchar           *str;
-  GdkModifierType  toggle_mask;
+  GObject              *config     = G_OBJECT (tool_options);
+  GimpFlipOptions      *options    = GIMP_FLIP_OPTIONS (tool_options);
+  GimpTransformOptions *tr_options = GIMP_TRANSFORM_OPTIONS (tool_options);
+  GtkWidget            *vbox       = gimp_tool_options_gui (tool_options);
+  GtkWidget            *hbox;
+  GtkWidget            *box;
+  GtkWidget            *label;
+  GtkWidget            *frame;
+  GtkWidget            *combo;
+  gchar                *str;
+  GtkListStore         *clip_model;
+  GdkModifierType       toggle_mask;
 
   toggle_mask = gimp_get_toggle_behavior_mask ();
 
@@ -156,5 +159,20 @@ gimp_flip_options_gui (GimpToolOptions *tool_options)
 
   options->direction_frame = frame;
 
+  /*  the clipping menu  */
+  clip_model = gimp_enum_store_new_with_range (GIMP_TYPE_TRANSFORM_RESIZE,
+                                               GIMP_TRANSFORM_RESIZE_ADJUST,
+                                               GIMP_TRANSFORM_RESIZE_CLIP);
+
+  combo = gimp_prop_enum_combo_box_new (config, "clip", 0, 0);
+  gtk_combo_box_set_model (GTK_COMBO_BOX (combo), GTK_TREE_MODEL (clip_model));
+  gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (combo), tr_options->clip);
+  gimp_int_combo_box_set_label (GIMP_INT_COMBO_BOX (combo), _("Clipping"));
+  g_object_set (combo, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
+  gtk_box_pack_start (GTK_BOX (vbox), combo, FALSE, FALSE, 0);
+  gtk_widget_show (combo);
+
+  g_object_unref (clip_model);
+
   return vbox;
 }
diff --git a/app/tools/gimpfliptool.c b/app/tools/gimpfliptool.c
index 3d9b6dd..6459734 100644
--- a/app/tools/gimpfliptool.c
+++ b/app/tools/gimpfliptool.c
@@ -300,12 +300,14 @@ gimp_flip_tool_transform (GimpTransformTool *trans_tool,
                           gint              *new_offset_x,
                           gint              *new_offset_y)
 {
-  GimpFlipTool         *flip      = GIMP_FLIP_TOOL (trans_tool);
-  GimpFlipOptions      *options   = GIMP_FLIP_TOOL_GET_OPTIONS (trans_tool);
-  GimpContext          *context   = GIMP_CONTEXT (options);
-  GimpOrientationType   flip_type = GIMP_ORIENTATION_UNKNOWN;
-  gdouble               axis      = 0.0;
-  GeglBuffer           *ret       = NULL;
+  GimpFlipTool         *flip        = GIMP_FLIP_TOOL (trans_tool);
+  GimpFlipOptions      *options     = GIMP_FLIP_TOOL_GET_OPTIONS (trans_tool);
+  GimpTransformOptions *tr_options  = GIMP_TRANSFORM_TOOL_GET_OPTIONS (trans_tool);
+  GimpContext          *context     = GIMP_CONTEXT (options);
+  GimpOrientationType   flip_type   = GIMP_ORIENTATION_UNKNOWN;
+  gdouble               axis        = 0.0;
+  gboolean              clip_result = FALSE;
+  GeglBuffer           *ret         = NULL;
 
   flip_type = gimp_flip_tool_get_flip_type (flip);
 
@@ -332,19 +334,40 @@ gimp_flip_tool_transform (GimpTransformTool *trans_tool,
         }
     }
 
+  switch (tr_options->clip)
+    {
+    case GIMP_TRANSFORM_RESIZE_ADJUST:
+      clip_result = FALSE;
+      break;
+
+    case GIMP_TRANSFORM_RESIZE_CLIP:
+      clip_result = TRUE;
+      break;
+
+    default:
+      g_return_val_if_reached (NULL);
+    }
+
   if (orig_buffer)
     {
       /*  this happens when transforming a selection cut out of a
        *  normal drawable, or the selection
        */
 
+      /*  always clip the selction and unfloated channels
+       *  so they keep their size
+       */
+      if (GIMP_IS_CHANNEL (active_item) &&
+          ! babl_format_has_alpha (gegl_buffer_get_format (orig_buffer)))
+        clip_result = TRUE;
+
       ret = gimp_drawable_transform_buffer_flip (GIMP_DRAWABLE (active_item),
                                                  context,
                                                  orig_buffer,
                                                  orig_offset_x,
                                                  orig_offset_y,
                                                  flip_type, axis,
-                                                 FALSE,
+                                                 clip_result,
                                                  buffer_profile,
                                                  new_offset_x,
                                                  new_offset_y);
@@ -353,15 +376,20 @@ gimp_flip_tool_transform (GimpTransformTool *trans_tool,
     {
       /*  this happens for entire drawables, paths and layer groups  */
 
+      /*  always clip layer masks so they keep their size
+       */
+      if (GIMP_IS_CHANNEL (active_item))
+        clip_result = TRUE;
+
       if (gimp_item_get_linked (active_item))
         {
           gimp_item_linked_flip (active_item, context,
-                                 flip_type, axis, FALSE);
+                                 flip_type, axis, clip_result);
         }
       else
         {
           gimp_item_flip (active_item, context,
-                          flip_type, axis, FALSE);
+                          flip_type, axis, clip_result);
         }
     }
 


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