app: Add basic infratructure for a vector tool popup menu.

This commit is contained in:
Simon Budig 2020-05-18 02:25:03 +02:00
parent 44a7e92967
commit f6f180c5cb
17 changed files with 336 additions and 1 deletions

View File

@ -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 \

View File

@ -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 },

View File

@ -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',

View File

@ -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);
}

View File

@ -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__ */

View File

@ -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);
}

View File

@ -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__ */

View File

@ -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");
}

View File

@ -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__ */

View File

@ -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;
}

View File

@ -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__ */

View File

@ -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",

View File

@ -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)

View File

@ -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__ */

View File

@ -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 = \

View File

@ -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',
]

View File

@ -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>