[gimp] app: Add basic infratructure for a vector tool popup menu.
- From: Simon Budig <simon src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: Add basic infratructure for a vector tool popup menu.
- Date: Mon, 25 May 2020 20:21:24 +0000 (UTC)
commit f6f180c5cb640d3dccbe56877c276d027e6b65c9
Author: Simon Budig <simon budig de>
Date: Mon May 18 02:25:03 2020 +0200
app: Add basic infratructure for a vector tool popup menu.
app/actions/Makefile.am | 4 ++
app/actions/actions.c | 4 ++
app/actions/meson.build | 2 +
app/actions/vector-toolpath-actions.c | 86 ++++++++++++++++++++++++++++++++++
app/actions/vector-toolpath-actions.h | 27 +++++++++++
app/actions/vector-toolpath-commands.c | 56 ++++++++++++++++++++++
app/actions/vector-toolpath-commands.h | 26 ++++++++++
app/display/gimptoolpath.c | 49 +++++++++++++++++++
app/display/gimptoolpath.h | 1 +
app/display/gimptoolwidget.c | 21 +++++++++
app/display/gimptoolwidget.h | 13 +++++
app/menus/menus.c | 8 ++++
app/tools/gimpvectortool.c | 28 +++++++++++
app/tools/gimpvectortool.h | 1 -
menus/Makefile.am | 1 +
menus/meson.build | 1 +
menus/vector-toolpath-menu.xml | 9 ++++
17 files changed, 336 insertions(+), 1 deletion(-)
---
diff --git a/app/actions/Makefile.am b/app/actions/Makefile.am
index fd80ce28ef..648ef9b07b 100644
--- a/app/actions/Makefile.am
+++ b/app/actions/Makefile.am
@@ -184,6 +184,10 @@ libappactions_a_SOURCES = \
tools-actions.h \
tools-commands.c \
tools-commands.h \
+ vector-toolpath-actions.c \
+ vector-toolpath-actions.h \
+ vector-toolpath-commands.c \
+ vector-toolpath-commands.h \
vectors-actions.c \
vectors-actions.h \
vectors-commands.c \
diff --git a/app/actions/actions.c b/app/actions/actions.c
index 2779de135c..47f6dcf3d1 100644
--- a/app/actions/actions.c
+++ b/app/actions/actions.c
@@ -92,6 +92,7 @@
#include "tool-presets-actions.h"
#include "tool-preset-editor-actions.h"
#include "tools-actions.h"
+#include "vector-toolpath-actions.h"
#include "vectors-actions.h"
#include "view-actions.h"
#include "windows-actions.h"
@@ -234,6 +235,9 @@ static const GimpActionFactoryEntry action_groups[] =
{ "tools", N_("Tools"), GIMP_ICON_DIALOG_TOOLS,
tools_actions_setup,
tools_actions_update },
+ { "vector-toolpath", N_("Path Toolpath"), GIMP_ICON_PATH,
+ vector_toolpath_actions_setup,
+ vector_toolpath_actions_update },
{ "vectors", N_("Paths"), GIMP_ICON_PATH,
vectors_actions_setup,
vectors_actions_update },
diff --git a/app/actions/meson.build b/app/actions/meson.build
index 0bc17c3df1..b6ad40219d 100644
--- a/app/actions/meson.build
+++ b/app/actions/meson.build
@@ -83,6 +83,8 @@ libappactions_sources = [
'tool-presets-commands.c',
'tools-actions.c',
'tools-commands.c',
+ 'vector-toolpath-actions.c',
+ 'vector-toolpath-commands.c',
'vectors-actions.c',
'vectors-commands.c',
'view-actions.c',
diff --git a/app/actions/vector-toolpath-actions.c b/app/actions/vector-toolpath-actions.c
new file mode 100644
index 0000000000..7c59b43a3e
--- /dev/null
+++ b/app/actions/vector-toolpath-actions.c
@@ -0,0 +1,86 @@
+/* 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 <https://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <gegl.h>
+#include <gtk/gtk.h>
+
+#include "libgimpwidgets/gimpwidgets.h"
+
+#include "actions-types.h"
+
+#include "core/gimpimage.h"
+
+#include "widgets/gimpactiongroup.h"
+#include "widgets/gimphelp-ids.h"
+
+#include "display/gimpdisplay.h"
+#include "display/gimpdisplayshell.h"
+#include "display/gimptoolpath.h"
+
+#include "vector-toolpath-actions.h"
+#include "vector-toolpath-commands.h"
+
+#include "gimp-intl.h"
+
+
+static const GimpActionEntry vector_toolpath_actions[] =
+{
+ { "vector-tool-popup", NULL,
+ NC_("vector-toolpath-action", "Vector Toolpath Menu"), NULL, NULL, NULL,
+ NULL },
+
+ { "vector-toolpath-reverse-stroke", GIMP_ICON_PATH,
+ NC_("vector-toolpath-action", "_Reverse Stroke"), NULL, NULL,
+ vector_toolpath_reverse_stroke_cmd_callback,
+ NULL }
+};
+
+
+#define SET_HIDE_EMPTY(action,condition) \
+ gimp_action_group_set_action_hide_empty (group, action, (condition) != 0)
+
+void
+vector_toolpath_actions_setup (GimpActionGroup *group)
+{
+ gimp_action_group_add_actions (group, "vector-toolpath-action",
+ vector_toolpath_actions,
+ G_N_ELEMENTS (vector_toolpath_actions));
+}
+
+/* The following code is written on the assumption that this is for a
+ * context menu, activated by right-clicking in a text layer.
+ * Therefore, the tool must have a display. If for any reason the
+ * code is adapted to a different situation, some existence testing
+ * will need to be added.
+ */
+void
+vector_toolpath_actions_update (GimpActionGroup *group,
+ gpointer data)
+{
+ GimpToolPath *toolpath = GIMP_TOOL_PATH (data);
+
+#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 ("vector-toolpath-reverse-stroke", TRUE);
+}
diff --git a/app/actions/vector-toolpath-actions.h b/app/actions/vector-toolpath-actions.h
new file mode 100644
index 0000000000..e936c26667
--- /dev/null
+++ b/app/actions/vector-toolpath-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 <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef __VECTOR_TOOLPATH_ACTIONS_H__
+#define __VECTOR_TOOLPATH_ACTIONS_H__
+
+
+void vector_toolpath_actions_setup (GimpActionGroup *group);
+void vector_toolpath_actions_update (GimpActionGroup *group,
+ gpointer data);
+
+
+#endif /* __VECTOR_TOOLPATH_ACTIONS_H__ */
diff --git a/app/actions/vector-toolpath-commands.c b/app/actions/vector-toolpath-commands.c
new file mode 100644
index 0000000000..220e35ab38
--- /dev/null
+++ b/app/actions/vector-toolpath-commands.c
@@ -0,0 +1,56 @@
+/* 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 <https://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <gegl.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 "display/gimptoolpath.h"
+
+#include "dialogs/dialogs.h"
+
+#include "vector-toolpath-commands.h"
+
+#include "gimp-intl.h"
+
+
+/* public functions */
+
+void
+vector_toolpath_reverse_stroke_cmd_callback (GimpAction *action,
+ GVariant *value,
+ gpointer data)
+{
+ GimpToolPath *tool_path = GIMP_TOOL_PATH (data);
+
+ gimp_tool_path_reverse_stroke (tool_path);
+}
+
diff --git a/app/actions/vector-toolpath-commands.h b/app/actions/vector-toolpath-commands.h
new file mode 100644
index 0000000000..9a14b34170
--- /dev/null
+++ b/app/actions/vector-toolpath-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 <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef __VECTOR_TOOLPATH_COMMANDS_H__
+#define __VECTOR_TOOLPATH_COMMANDS_H__
+
+
+void vector_toolpath_reverse_stroke_cmd_callback (GimpAction *action,
+ GVariant *value,
+ gpointer data);
+
+#endif /* __VECTOR_TOOLPATH_COMMANDS_H__ */
diff --git a/app/display/gimptoolpath.c b/app/display/gimptoolpath.c
index 8691dcc686..a28f82f6d9 100644
--- a/app/display/gimptoolpath.c
+++ b/app/display/gimptoolpath.c
@@ -36,6 +36,10 @@
#include "vectors/gimpbezierstroke.h"
#include "vectors/gimpvectors.h"
+#include "widgets/gimpdialogfactory.h"
+#include "widgets/gimpdockcontainer.h"
+#include "widgets/gimpmenufactory.h"
+#include "widgets/gimpuimanager.h"
#include "widgets/gimpwidgets-utils.h"
#include "tools/gimptools-utils.h"
@@ -123,6 +127,8 @@ struct _GimpToolPathPrivate
GimpCanvasItem *path;
GList *items;
+
+ GimpUIManager *ui_manager;
};
@@ -170,6 +176,11 @@ static gboolean gimp_tool_path_get_cursor (GimpToolWidget *widget,
GimpCursorType *cursor,
GimpToolCursorType *tool_cursor,
GimpCursorModifier *modifier);
+static GimpUIManager * gimp_tool_path_get_popup (GimpToolWidget *widget,
+ const GimpCoords *coords,
+ GdkModifierType state,
+ GimpDisplay *display,
+ const gchar **ui_path);
static GimpVectorFunction
gimp_tool_path_get_function (GimpToolPath *path,
@@ -228,6 +239,7 @@ gimp_tool_path_class_init (GimpToolPathClass *klass)
widget_class->hover = gimp_tool_path_hover;
widget_class->key_press = gimp_tool_path_key_press;
widget_class->get_cursor = gimp_tool_path_get_cursor;
+ widget_class->get_popup = gimp_tool_path_get_popup;
path_signals[BEGIN_CHANGE] =
g_signal_new ("begin-change",
@@ -1273,6 +1285,37 @@ gimp_tool_path_get_cursor (GimpToolWidget *widget,
return TRUE;
}
+static GimpUIManager *
+gimp_tool_path_get_popup (GimpToolWidget *widget,
+ const GimpCoords *coords,
+ GdkModifierType state,
+ GimpDisplay *display,
+ const gchar **ui_path)
+{
+ GimpToolPath *path = GIMP_TOOL_PATH (widget);
+ GimpToolPathPrivate *private = path->private;
+
+ if (!private->ui_manager)
+ {
+ GimpDisplayShell *shell = gimp_tool_widget_get_shell (widget);
+ GimpImageWindow *image_window;
+ GimpDialogFactory *dialog_factory;
+
+ image_window = gimp_display_shell_get_window (shell);
+ dialog_factory = gimp_dock_container_get_dialog_factory (GIMP_DOCK_CONTAINER (image_window));
+
+ private->ui_manager =
+ gimp_menu_factory_manager_new (gimp_dialog_factory_get_menu_factory (dialog_factory),
+ "<VectorToolPath>",
+ widget);
+ }
+
+ gimp_ui_manager_update (private->ui_manager, widget);
+ *ui_path = "/vector-toolpath-popup";
+ return private->ui_manager;
+}
+
+
static GimpVectorFunction
gimp_tool_path_get_function (GimpToolPath *path,
const GimpCoords *coords,
@@ -1933,3 +1976,9 @@ gimp_tool_path_set_vectors (GimpToolPath *path,
g_object_notify (G_OBJECT (path), "vectors");
}
+
+void
+gimp_tool_path_reverse_stroke (GimpToolPath *path)
+{
+ g_printerr ("REVERSE_STROKE\n");
+}
diff --git a/app/display/gimptoolpath.h b/app/display/gimptoolpath.h
index 861d5e8a86..b51f00d67a 100644
--- a/app/display/gimptoolpath.h
+++ b/app/display/gimptoolpath.h
@@ -64,5 +64,6 @@ GimpToolWidget * gimp_tool_path_new (GimpDisplayShell *shell);
void gimp_tool_path_set_vectors (GimpToolPath *path,
GimpVectors *vectors);
+void gimp_tool_path_reverse_stroke (GimpToolPath *path);
#endif /* __GIMP_TOOL_PATH_H__ */
diff --git a/app/display/gimptoolwidget.c b/app/display/gimptoolwidget.c
index ecab04b555..952240a9a8 100644
--- a/app/display/gimptoolwidget.c
+++ b/app/display/gimptoolwidget.c
@@ -1084,3 +1084,24 @@ gimp_tool_widget_get_cursor (GimpToolWidget *widget,
return FALSE;
}
+
+GimpUIManager *
+gimp_tool_widget_get_popup (GimpToolWidget *widget,
+ const GimpCoords *coords,
+ GdkModifierType state,
+ GimpDisplay *display,
+ const gchar **ui_path)
+{
+ g_return_val_if_fail (GIMP_IS_TOOL_WIDGET (widget), FALSE);
+ g_return_val_if_fail (coords != NULL, FALSE);
+
+ if (widget->private->visible &&
+ GIMP_TOOL_WIDGET_GET_CLASS (widget)->get_popup)
+ {
+ return GIMP_TOOL_WIDGET_GET_CLASS (widget)->get_popup (widget, coords,
+ state, display,
+ ui_path);
+ }
+
+ return NULL;
+}
diff --git a/app/display/gimptoolwidget.h b/app/display/gimptoolwidget.h
index f1010ea9b8..241488095c 100644
--- a/app/display/gimptoolwidget.h
+++ b/app/display/gimptoolwidget.h
@@ -119,6 +119,13 @@ struct _GimpToolWidgetClass
GimpCursorType *cursor,
GimpToolCursorType *tool_cursor,
GimpCursorModifier *modifier);
+
+ GimpUIManager *
+ (* get_popup) (GimpToolWidget *widget,
+ const GimpCoords *coords,
+ GdkModifierType state,
+ GimpDisplay *display,
+ const gchar **ui_path);
};
@@ -310,5 +317,11 @@ gboolean gimp_tool_widget_get_cursor (GimpToolWidget *widget,
GimpToolCursorType *tool_cursor,
GimpCursorModifier *modifier);
+GimpUIManager *
+ gimp_tool_widget_get_popup (GimpToolWidget *widget,
+ const GimpCoords *coords,
+ GdkModifierType state,
+ GimpDisplay *display,
+ const gchar **ui_path);
#endif /* __GIMP_TOOL_WIDGET_H__ */
diff --git a/app/menus/menus.c b/app/menus/menus.c
index 4ca8b4b843..2bff858c0c 100644
--- a/app/menus/menus.c
+++ b/app/menus/menus.c
@@ -177,6 +177,14 @@ menus_init (Gimp *gimp,
"vectors-menu.xml", plug_in_menus_setup,
NULL);
+ gimp_menu_factory_manager_register (global_menu_factory, "<VectorToolPath>",
+ "vector-toolpath",
+ NULL,
+ "/vector-toolpath-popup",
+ "vector-toolpath-menu.xml",
+ NULL,
+ NULL);
+
gimp_menu_factory_manager_register (global_menu_factory, "<Colormap>",
"colormap",
"plug-in",
diff --git a/app/tools/gimpvectortool.c b/app/tools/gimpvectortool.c
index 76789cfd45..60ddde8b8c 100644
--- a/app/tools/gimpvectortool.c
+++ b/app/tools/gimpvectortool.c
@@ -42,7 +42,11 @@
#include "vectors/gimpvectors.h"
+#include "widgets/gimpdialogfactory.h"
+#include "widgets/gimpdockcontainer.h"
#include "widgets/gimphelp-ids.h"
+#include "widgets/gimpmenufactory.h"
+#include "widgets/gimpuimanager.h"
#include "widgets/gimpwidgets-utils.h"
#include "display/gimpdisplay.h"
@@ -97,6 +101,11 @@ static void gimp_vector_tool_cursor_update (GimpTool *tool,
const GimpCoords *coords,
GdkModifierType state,
GimpDisplay *display);
+static GimpUIManager * gimp_vector_tool_get_popup (GimpTool *tool,
+ const GimpCoords *coords,
+ GdkModifierType state,
+ GimpDisplay *display,
+ const gchar **ui_path);
static void gimp_vector_tool_start (GimpVectorTool *vector_tool,
GimpDisplay *display);
@@ -182,6 +191,7 @@ gimp_vector_tool_class_init (GimpVectorToolClass *klass)
tool_class->motion = gimp_vector_tool_motion;
tool_class->modifier_key = gimp_vector_tool_modifier_key;
tool_class->cursor_update = gimp_vector_tool_cursor_update;
+ tool_class->get_popup = gimp_vector_tool_get_popup;
}
static void
@@ -378,6 +388,24 @@ gimp_vector_tool_cursor_update (GimpTool *tool,
GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, display);
}
+static GimpUIManager *
+gimp_vector_tool_get_popup (GimpTool *tool,
+ const GimpCoords *coords,
+ GdkModifierType state,
+ GimpDisplay *display,
+ const gchar **ui_path)
+{
+ GimpVectorTool *vector_tool = GIMP_VECTOR_TOOL (tool);
+
+ if (display != tool->display || ! vector_tool->widget)
+ {
+ return NULL;
+ }
+
+ return gimp_tool_widget_get_popup (GIMP_TOOL_WIDGET (vector_tool->widget),
+ coords, state, display, ui_path);
+}
+
static void
gimp_vector_tool_start (GimpVectorTool *vector_tool,
GimpDisplay *display)
diff --git a/app/tools/gimpvectortool.h b/app/tools/gimpvectortool.h
index 686ad88e8b..d0622ca375 100644
--- a/app/tools/gimpvectortool.h
+++ b/app/tools/gimpvectortool.h
@@ -63,5 +63,4 @@ GType gimp_vector_tool_get_type (void) G_GNUC_CONST;
void gimp_vector_tool_set_vectors (GimpVectorTool *vector_tool,
GimpVectors *vectors);
-
#endif /* __GIMP_VECTOR_TOOL_H__ */
diff --git a/menus/Makefile.am b/menus/Makefile.am
index 6389e9fc65..b4df3fb23c 100644
--- a/menus/Makefile.am
+++ b/menus/Makefile.am
@@ -40,6 +40,7 @@ menudata_DATA = \
text-tool-menu.xml \
tool-options-menu.xml \
undo-menu.xml \
+ vector-toolpath-menu.xml \
vectors-menu.xml
EXTRA_DIST = \
diff --git a/menus/meson.build b/menus/meson.build
index 865a747714..02b039ed9c 100644
--- a/menus/meson.build
+++ b/menus/meson.build
@@ -31,6 +31,7 @@ menus_files = [
'tool-preset-editor-menu.xml',
'tool-presets-menu.xml',
'undo-menu.xml',
+ 'vector-toolpath-menu.xml',
'vectors-menu.xml',
]
diff --git a/menus/vector-toolpath-menu.xml b/menus/vector-toolpath-menu.xml
new file mode 100644
index 0000000000..1a7605bc7e
--- /dev/null
+++ b/menus/vector-toolpath-menu.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE ui SYSTEM "gtkuimanager.dtd">
+
+<ui>
+ <popup action="vector-toolpath-popup">
+ <menuitem action="vector-toolpath-reverse-stroke" />
+ <separator />
+ </popup>
+</ui>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]