[gimp/soc-2012-unified-transformation: 10/12] WIP: menu for ut



commit c3bd83abc9b8b7e2ffd4d9aae2a176a5319d29c0
Author: Mikael Magnusson <mikachu src gnome org>
Date:   Tue Aug 21 15:12:57 2012 +0200

    WIP: menu for ut

 app/actions/Makefile.am                       |    4 +
 app/actions/actions.c                         |    4 +
 app/actions/unified-transform-tool-actions.c  |   99 +++++++++++++++++++++++++
 app/actions/unified-transform-tool-actions.h  |   27 +++++++
 app/actions/unified-transform-tool-commands.c |   61 +++++++++++++++
 app/actions/unified-transform-tool-commands.h |   26 +++++++
 app/menus/menus.c                             |    8 ++
 app/tools/gimpunifiedtransformtool.c          |   66 ++++++++++++++++-
 app/tools/gimpunifiedtransformtool.h          |    7 ++
 menus/Makefile.am                             |    1 +
 menus/unified-transform-tool-menu.xml         |   10 +++
 11 files changed, 312 insertions(+), 1 deletions(-)
---
diff --git a/app/actions/Makefile.am b/app/actions/Makefile.am
index cd6dcf7..68555ca 100644
--- a/app/actions/Makefile.am
+++ b/app/actions/Makefile.am
@@ -169,6 +169,10 @@ libappactions_a_SOURCES = \
 	tools-actions.h			\
 	tools-commands.c		\
 	tools-commands.h		\
+	unified-transform-tool-actions.c		\
+	unified-transform-tool-actions.h		\
+	unified-transform-tool-commands.c		\
+	unified-transform-tool-commands.h		\
 	vectors-actions.c		\
 	vectors-actions.h		\
 	vectors-commands.c		\
diff --git a/app/actions/actions.c b/app/actions/actions.c
index b9b87cb..97cd431 100644
--- a/app/actions/actions.c
+++ b/app/actions/actions.c
@@ -90,6 +90,7 @@
 #include "tool-presets-actions.h"
 #include "tool-preset-editor-actions.h"
 #include "tools-actions.h"
+#include "unified-transform-tool-actions.h"
 #include "vectors-actions.h"
 #include "view-actions.h"
 #include "windows-actions.h"
@@ -226,6 +227,9 @@ static const GimpActionFactoryEntry action_groups[] =
   { "tools", N_("Tools"), GIMP_STOCK_TOOLS,
     tools_actions_setup,
     tools_actions_update },
+  { "unified-transform-tool", N_("Unified Transform Tool"), GTK_STOCK_EDIT,
+    unified_transform_tool_actions_setup,
+    unified_transform_tool_actions_update },
   { "vectors", N_("Paths"), GIMP_STOCK_PATH,
     vectors_actions_setup,
     vectors_actions_update },
diff --git a/app/actions/unified-transform-tool-actions.c b/app/actions/unified-transform-tool-actions.c
new file mode 100644
index 0000000..a33bb94
--- /dev/null
+++ b/app/actions/unified-transform-tool-actions.c
@@ -0,0 +1,99 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <gegl.h>
+#include <gtk/gtk.h>
+
+#include "libgimpwidgets/gimpwidgets.h"
+
+#include "actions-types.h"
+
+#include "widgets/gimpactiongroup.h"
+#include "widgets/gimptexteditor.h"
+#include "widgets/gimphelp-ids.h"
+
+#include "display/gimpdisplay.h"
+#include "display/gimpdisplayshell.h"
+
+#include "tools/gimptool.h"
+#include "tools/gimpunifiedtransformtool.h"
+
+#include "text-tool-actions.h"
+#include "text-tool-commands.h"
+
+#include "unified-transform-tool-actions.h"
+#include "unified-transform-tool-commands.h"
+
+#include "gimp-intl.h"
+
+
+static const GimpActionEntry unified_transform_tool_actions[] =
+{
+  { "unified-transform-tool-popup", NULL,
+    NC_("unified-transform-tool-action", "Unified Transform Tool Menu"), NULL, NULL, NULL,
+    NULL },
+
+  { "unified-transform-tool-flip-horiz", GTK_STOCK_CUT,
+    NC_("unified-transform-tool-action", "Flip Horizontally"), NULL, NULL,
+    G_CALLBACK (unified_transform_tool_flip_horiz_callback),
+    NULL },
+
+  { "unified-transform-tool-summon-pivot", GTK_STOCK_COPY,
+    NC_("unified-transform-tool-action", "Put pivot here"), NULL, NULL,
+    G_CALLBACK (unified_transform_tool_summon_pivot_callback),
+    NULL },
+};
+
+#define SET_HIDE_EMPTY(action,condition) \
+        gimp_action_group_set_action_hide_empty (group, action, (condition) != 0)
+
+void
+unified_transform_tool_actions_setup (GimpActionGroup *group)
+{
+  gimp_action_group_add_actions (group, "unified-transform-tool-action",
+                                 unified_transform_tool_actions,
+                                 G_N_ELEMENTS (unified_transform_tool_actions));
+}
+
+void
+unified_transform_tool_actions_update (GimpActionGroup *group,
+                                       gpointer         data)
+{
+  GimpTransformTool *tr_tool  = GIMP_TRANSFORM_TOOL (data);
+  GimpDisplay       *display  = GIMP_TOOL (tr_tool)->display;
+
+#define SET_VISIBLE(action,condition) \
+        gimp_action_group_set_action_visible (group, action, (condition) != 0)
+#define SET_SENSITIVE(action,condition) \
+        gimp_action_group_set_action_sensitive (group, action, (condition) != 0)
+#define SET_ACTIVE(action,condition) \
+        gimp_action_group_set_action_active (group, action, (condition) != 0)
+
+/*  SET_SENSITIVE ("text-tool-cut",             text_sel);
+  SET_SENSITIVE ("text-tool-copy",            text_sel);
+  SET_SENSITIVE ("text-tool-paste",           clip);
+  SET_SENSITIVE ("text-tool-delete",          text_sel);
+  SET_SENSITIVE ("text-tool-clear",           text_layer);
+  SET_SENSITIVE ("text-tool-load",            image);
+  SET_SENSITIVE ("text-tool-text-to-path",    text_layer);
+  SET_SENSITIVE ("text-tool-text-along-path", text_layer && vectors);
+
+  SET_VISIBLE ("text-tool-input-methods-menu", input_method_menu);
+  */
+}
diff --git a/app/actions/unified-transform-tool-actions.h b/app/actions/unified-transform-tool-actions.h
new file mode 100644
index 0000000..5292273
--- /dev/null
+++ b/app/actions/unified-transform-tool-actions.h
@@ -0,0 +1,27 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __UNIFIED_TRANSFORM_TOOL_ACTIONS_H__
+#define __UNIFIED_TRANSFORM_TOOL_ACTIONS_H__
+
+
+void   unified_transform_tool_actions_setup  (GimpActionGroup *group);
+void   unified_transform_tool_actions_update (GimpActionGroup *group,
+                                 gpointer         data);
+
+
+#endif /* __UNIFIED_TRANSFORM_TOOL_ACTIONS_H__ */
diff --git a/app/actions/unified-transform-tool-commands.c b/app/actions/unified-transform-tool-commands.c
new file mode 100644
index 0000000..400e439
--- /dev/null
+++ b/app/actions/unified-transform-tool-commands.c
@@ -0,0 +1,61 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <gtk/gtk.h>
+
+#include "libgimpbase/gimpbase.h"
+#include "libgimpwidgets/gimpwidgets.h"
+
+#include "actions-types.h"
+
+#include "core/gimp.h"
+#include "core/gimptoolinfo.h"
+
+#include "widgets/gimphelp-ids.h"
+#include "widgets/gimpuimanager.h"
+#include "widgets/gimpwidgets-utils.h"
+
+#include "display/gimpdisplay.h"
+
+#include "tools/gimpunifiedtransformtool.h"
+
+#include "unified-transform-tool-commands.h"
+
+#include "gimp-intl.h"
+
+
+/*  public functions  */
+
+void
+unified_transform_tool_flip_horiz_callback (GtkAction *action,
+                                            gpointer   data)
+{
+  GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (data);
+
+  gimp_unified_transform_tool_flip_horiz (tr_tool);
+}
+
+void
+unified_transform_tool_summon_pivot_callback (GtkAction *action,
+                                              gpointer   data)
+{
+  GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (data);
+
+  gimp_unified_transform_tool_summon_pivot (tr_tool);
+}
diff --git a/app/actions/unified-transform-tool-commands.h b/app/actions/unified-transform-tool-commands.h
new file mode 100644
index 0000000..5380795
--- /dev/null
+++ b/app/actions/unified-transform-tool-commands.h
@@ -0,0 +1,26 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __UNIFIED_TRANSFORM_TOOL_COMMANDS_H__
+#define __UNIFIED_TRANSFORM_TOOL_COMMANDS_H__
+
+void unified_transform_tool_flip_horiz_callback   (GtkAction *action,
+                                                   gpointer   data);
+void unified_transform_tool_summon_pivot_callback (GtkAction *action,
+                                                   gpointer   data);
+
+#endif /* __UNIFIED_TRANSFORM_TOOL_COMMANDS_H__ */
diff --git a/app/menus/menus.c b/app/menus/menus.c
index 3d58dac..da6639d 100644
--- a/app/menus/menus.c
+++ b/app/menus/menus.c
@@ -372,6 +372,14 @@ menus_init (Gimp              *gimp,
                                       NULL,
                                       NULL);
 
+  gimp_menu_factory_manager_register (global_menu_factory, "<UnifiedTransformTool>",
+                                      "unified-transform-tool",
+                                      NULL,
+                                      "/unified-transform-tool-popup",
+                                      "/unified-transform-tool-menu.xml",
+                                      NULL,
+                                      NULL);
+
   gimp_menu_factory_manager_register (global_menu_factory, "<CursorInfo>",
                                       "cursor-info",
                                       NULL,
diff --git a/app/tools/gimpunifiedtransformtool.c b/app/tools/gimpunifiedtransformtool.c
index ab39a1b..acb5e37 100644
--- a/app/tools/gimpunifiedtransformtool.c
+++ b/app/tools/gimpunifiedtransformtool.c
@@ -36,7 +36,10 @@
 #include "vectors/gimpvectors.h"
 #include "vectors/gimpstroke.h"
 
+#include "widgets/gimpdialogfactory.h"
 #include "widgets/gimphelp-ids.h"
+#include "widgets/gimpmenufactory.h"
+#include "widgets/gimpuimanager.h"
 
 #include "display/gimpcanvasgroup.h"
 #include "display/gimpcanvashandle.h"
@@ -69,6 +72,7 @@ enum
 
 /*  local function prototypes  */
 
+/* transform tool methods */
 static void            gimp_unified_transform_tool_dialog        (GimpTransformTool *tr_tool);
 static void            gimp_unified_transform_tool_dialog_update (GimpTransformTool *tr_tool);
 static void            gimp_unified_transform_tool_prepare       (GimpTransformTool *tr_tool);
@@ -86,6 +90,12 @@ static void            gimp_unified_transform_tool_draw_gui      (GimpTransformT
                                                                   gint               handle_w,
                                                                   gint               handle_h);
 
+/* tool methods */
+static GimpUIManager * gimp_unified_transform_tool_get_popup     (GimpTool         *tool,
+                                                                  const GimpCoords *coords,
+                                                                  GdkModifierType   state,
+                                                                  GimpDisplay      *display,
+                                                                  const gchar     **ui_path);
 
 G_DEFINE_TYPE (GimpUnifiedTransformTool, gimp_unified_transform_tool,
                GIMP_TYPE_TRANSFORM_TOOL)
@@ -113,6 +123,7 @@ static void
 gimp_unified_transform_tool_class_init (GimpUnifiedTransformToolClass *klass)
 {
   GimpTransformToolClass *trans_class = GIMP_TRANSFORM_TOOL_CLASS (klass);
+  GimpToolClass          *tool_class  = GIMP_TOOL_CLASS (klass);
 
   trans_class->dialog        = gimp_unified_transform_tool_dialog;
   trans_class->dialog_update = gimp_unified_transform_tool_dialog_update;
@@ -123,18 +134,21 @@ gimp_unified_transform_tool_class_init (GimpUnifiedTransformToolClass *klass)
   trans_class->pick_function = gimp_unified_transform_tool_pick_function;
   trans_class->cursor_update = gimp_unified_transform_tool_cursor_update;
   trans_class->draw_gui      = gimp_unified_transform_tool_draw_gui;
+
+  tool_class->get_popup = gimp_unified_transform_tool_get_popup;
 }
 
 static void
 gimp_unified_transform_tool_init (GimpUnifiedTransformTool *unified_tool)
 {
-  GimpTool          *tool    = GIMP_TOOL (unified_tool);
   GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (unified_tool);
 
   tr_tool->progress_text = _("Unified transform");
 
   tr_tool->use_grid    = TRUE;
   tr_tool->use_handles = TRUE;
+
+  unified_tool->ui_manager = NULL;
 }
 
 static gboolean
@@ -1137,3 +1151,53 @@ gimp_unified_transform_tool_get_undo_desc (GimpTransformTool *tr_tool)
 {
   return g_strdup (C_("undo-type", "Unified Transform"));
 }
+
+static GimpUIManager *
+gimp_unified_transform_tool_get_popup (GimpTool         *tool,
+                                       const GimpCoords *coords,
+                                       GdkModifierType   state,
+                                       GimpDisplay      *display,
+                                       const gchar     **ui_path)
+{
+  GimpUnifiedTransformTool *ut_tool = GIMP_UNIFIED_TRANSFORM_TOOL (tool);
+
+  if (! ut_tool->ui_manager)
+    {
+      GimpDialogFactory *dialog_factory;
+
+      dialog_factory = gimp_dialog_factory_get_singleton ();
+
+      ut_tool->ui_manager =
+        gimp_menu_factory_manager_new (gimp_dialog_factory_get_menu_factory (dialog_factory),
+                                       "<UnifiedTransformTool>",
+                                       ut_tool, FALSE);
+    }
+
+  gimp_ui_manager_update (ut_tool->ui_manager, ut_tool);
+
+  *ui_path = "/unified-transform-tool-popup";
+
+  ut_tool->menu_coords = *coords;
+
+  return ut_tool->ui_manager;
+}
+
+void gimp_unified_transform_tool_flip_horiz (GimpTransformTool *tr_tool)
+{
+  GimpUnifiedTransformTool *ut_tool = GIMP_UNIFIED_TRANSFORM_TOOL (tr_tool);
+}
+
+void gimp_unified_transform_tool_summon_pivot (GimpTransformTool *tr_tool)
+{
+  GimpUnifiedTransformTool *ut_tool = GIMP_UNIFIED_TRANSFORM_TOOL (tr_tool);
+
+  gimp_draw_tool_pause (GIMP_DRAW_TOOL (tr_tool));
+
+  tr_tool->trans_info[PIVOT_X] = ut_tool->menu_coords.x;
+  tr_tool->trans_info[PIVOT_Y] = ut_tool->menu_coords.y;
+
+  gimp_transform_tool_recalc_matrix (tr_tool);
+  gimp_transform_tool_push_internal_undo (tr_tool);
+
+  gimp_draw_tool_resume (GIMP_DRAW_TOOL (tr_tool));
+}
diff --git a/app/tools/gimpunifiedtransformtool.h b/app/tools/gimpunifiedtransformtool.h
index 56182c4..6c7c180 100644
--- a/app/tools/gimpunifiedtransformtool.h
+++ b/app/tools/gimpunifiedtransformtool.h
@@ -37,6 +37,9 @@ struct _GimpUnifiedTransformTool
 {
   GimpTransformTool  parent_instance;
 
+  GimpUIManager     *ui_manager;
+  GimpCoords         menu_coords;
+
   GtkWidget         *label[3][3];
 };
 
@@ -51,5 +54,9 @@ void    gimp_unified_transform_tool_register (GimpToolRegisterCallback  callback
 
 GType   gimp_unified_transform_tool_get_type (void) G_GNUC_CONST;
 
+void gimp_unified_transform_tool_flip_horiz   (GimpTransformTool *tr_tool);
+void gimp_unified_transform_tool_summon_pivot (GimpTransformTool *tr_tool);
+
+
 
 #endif  /*  __GIMP_UNIFIED_TRANSFORM_TOOL_H__  */
diff --git a/menus/Makefile.am b/menus/Makefile.am
index 01548f6..2bc3638 100644
--- a/menus/Makefile.am
+++ b/menus/Makefile.am
@@ -38,6 +38,7 @@ menudata_DATA = \
 	text-tool-menu.xml		\
 	tool-options-menu.xml		\
 	undo-menu.xml			\
+	unified-transform-tool-menu.xml		\
 	vectors-menu.xml
 
 EXTRA_DIST = \
diff --git a/menus/unified-transform-tool-menu.xml b/menus/unified-transform-tool-menu.xml
new file mode 100644
index 0000000..7d57fbf
--- /dev/null
+++ b/menus/unified-transform-tool-menu.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE ui SYSTEM "gtkuimanager.dtd">
+
+<ui>
+  <popup action="unified-transform-tool-popup">
+    <menuitem action="unified-transform-tool-flip-horiz" />
+    <separator />
+    <menuitem action="unified-transform-tool-summon-pivot" />
+  </popup>
+</ui>



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