2001-02-14 13:19:55 +08:00
|
|
|
/* The GIMP -- an 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 2 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, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2001-02-22 05:56:39 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "tools-types.h"
|
2001-02-14 13:19:55 +08:00
|
|
|
|
2001-07-05 03:31:35 +08:00
|
|
|
#include "core/gimp.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpcontainer.h"
|
|
|
|
#include "core/gimpcontext.h"
|
|
|
|
#include "core/gimpimage.h"
|
|
|
|
#include "core/gimplist.h"
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "core/gimptoolinfo.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
|
2001-07-07 20:17:23 +08:00
|
|
|
#include "gui/brush-select.h"
|
|
|
|
|
2001-03-08 09:07:03 +08:00
|
|
|
#include "gimptool.h"
|
2001-07-08 06:49:01 +08:00
|
|
|
#include "gimprectselecttool.h"
|
2001-07-07 20:17:23 +08:00
|
|
|
#include "paint_options.h"
|
2001-02-24 05:32:47 +08:00
|
|
|
#include "tool_manager.h"
|
2001-02-14 13:19:55 +08:00
|
|
|
#include "tool_options.h"
|
2001-07-07 20:17:23 +08:00
|
|
|
#include "tools.h"
|
2001-02-14 13:19:55 +08:00
|
|
|
|
2001-04-01 07:04:29 +08:00
|
|
|
#include "gimpairbrushtool.h"
|
2001-03-31 23:45:05 +08:00
|
|
|
#include "gimppaintbrushtool.h"
|
2001-04-19 21:01:44 +08:00
|
|
|
#include "gimpclonetool.h"
|
|
|
|
#include "gimpconvolvetool.h"
|
2001-03-31 23:45:05 +08:00
|
|
|
#include "gimpdodgeburntool.h"
|
|
|
|
#include "gimperasertool.h"
|
|
|
|
#include "gimppenciltool.h"
|
2001-04-12 01:20:34 +08:00
|
|
|
#include "gimpsmudgetool.h"
|
2001-03-31 23:45:05 +08:00
|
|
|
|
2001-05-25 09:24:12 +08:00
|
|
|
#include "appenv.h"
|
2001-07-05 03:31:35 +08:00
|
|
|
#include "app_procs.h"
|
2001-05-25 09:24:12 +08:00
|
|
|
#include "gdisplay.h"
|
2001-07-07 20:17:23 +08:00
|
|
|
#include "gimprc.h"
|
2001-05-25 09:24:12 +08:00
|
|
|
|
2001-02-14 13:19:55 +08:00
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
|
|
|
|
2001-07-07 20:17:23 +08:00
|
|
|
#define PAINT_OPTIONS_MASK GIMP_CONTEXT_OPACITY_MASK | \
|
|
|
|
GIMP_CONTEXT_PAINT_MODE_MASK
|
|
|
|
|
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
typedef struct _GimpToolManager GimpToolManager;
|
2001-02-14 13:19:55 +08:00
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
struct _GimpToolManager
|
|
|
|
{
|
|
|
|
GimpTool *active_tool;
|
|
|
|
GSList *tool_stack;
|
2001-02-14 13:19:55 +08:00
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
GimpContext *global_tool_context;
|
2001-07-08 02:16:18 +08:00
|
|
|
|
|
|
|
GQuark image_dirty_handler_id;
|
2001-07-08 01:36:00 +08:00
|
|
|
};
|
2001-02-28 10:29:25 +08:00
|
|
|
|
|
|
|
|
2001-07-07 20:17:23 +08:00
|
|
|
/* local function prototypes */
|
2001-02-14 13:19:55 +08:00
|
|
|
|
2001-07-08 02:16:18 +08:00
|
|
|
static GimpToolManager * tool_manager_get (Gimp *gimp);
|
|
|
|
static void tool_manager_set (Gimp *gimp,
|
|
|
|
GimpToolManager *tool_manager);
|
|
|
|
static void tool_manager_tool_changed (GimpContext *user_context,
|
|
|
|
GimpToolInfo *tool_info,
|
|
|
|
gpointer data);
|
|
|
|
static void tool_manager_image_dirty (GimpImage *gimage,
|
|
|
|
gpointer data);
|
2001-07-07 20:17:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
void
|
|
|
|
tool_manager_init (Gimp *gimp)
|
2001-02-14 13:19:55 +08:00
|
|
|
{
|
2001-07-08 01:36:00 +08:00
|
|
|
GimpToolManager *tool_manager;
|
|
|
|
GimpContext *user_context;
|
|
|
|
GimpContext *tool_context;
|
|
|
|
|
|
|
|
tool_manager = g_new0 (GimpToolManager, 1);
|
|
|
|
|
2001-07-08 02:16:18 +08:00
|
|
|
tool_manager->active_tool = NULL;
|
|
|
|
tool_manager->tool_stack = NULL;
|
|
|
|
tool_manager->global_tool_context = NULL;
|
|
|
|
tool_manager->image_dirty_handler_id = 0;
|
2001-07-08 01:36:00 +08:00
|
|
|
|
|
|
|
tool_manager_set (gimp, tool_manager);
|
2001-07-07 20:17:23 +08:00
|
|
|
|
2001-07-08 02:16:18 +08:00
|
|
|
tool_manager->image_dirty_handler_id =
|
|
|
|
gimp_container_add_handler (gimp->images, "dirty",
|
|
|
|
GTK_SIGNAL_FUNC (tool_manager_image_dirty),
|
|
|
|
tool_manager);
|
|
|
|
|
2001-07-07 20:17:23 +08:00
|
|
|
user_context = gimp_get_user_context (gimp);
|
|
|
|
|
|
|
|
gtk_signal_connect (GTK_OBJECT (user_context), "tool_changed",
|
|
|
|
GTK_SIGNAL_FUNC (tool_manager_tool_changed),
|
2001-07-08 01:36:00 +08:00
|
|
|
tool_manager);
|
2001-07-07 20:17:23 +08:00
|
|
|
|
|
|
|
/* Create a context to store the paint options of the
|
|
|
|
* global paint options mode
|
|
|
|
*/
|
2001-07-08 01:36:00 +08:00
|
|
|
tool_manager->global_tool_context = gimp_create_context (gimp,
|
|
|
|
"Global Tool Context",
|
|
|
|
user_context);
|
2001-07-07 20:17:23 +08:00
|
|
|
|
|
|
|
/* TODO: add foreground, background, brush, pattern, gradient */
|
2001-07-08 01:36:00 +08:00
|
|
|
gimp_context_define_args (tool_manager->global_tool_context,
|
|
|
|
PAINT_OPTIONS_MASK, FALSE);
|
2001-07-07 20:17:23 +08:00
|
|
|
|
|
|
|
/* register internal tools */
|
|
|
|
tools_init (gimp);
|
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
if (! gimprc.global_paint_options && tool_manager->active_tool)
|
2001-07-07 20:17:23 +08:00
|
|
|
{
|
2001-07-08 01:36:00 +08:00
|
|
|
tool_context =
|
|
|
|
tool_manager_get_info_by_tool (gimp,
|
|
|
|
tool_manager->active_tool)->context;
|
|
|
|
|
|
|
|
if (tool_context)
|
|
|
|
{
|
|
|
|
gimp_context_set_parent (tool_context, user_context);
|
|
|
|
}
|
2001-07-07 20:17:23 +08:00
|
|
|
}
|
|
|
|
else if (gimprc.global_paint_options)
|
|
|
|
{
|
2001-07-08 01:36:00 +08:00
|
|
|
gimp_context_set_parent (tool_manager->global_tool_context, user_context);
|
2001-07-07 20:17:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gimp_container_thaw (gimp->tool_info_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tool_manager_exit (Gimp *gimp)
|
|
|
|
{
|
2001-07-08 01:36:00 +08:00
|
|
|
GimpToolManager *tool_manager;
|
|
|
|
|
|
|
|
tool_manager = tool_manager_get (gimp);
|
|
|
|
|
|
|
|
gtk_object_unref (GTK_OBJECT (tool_manager->global_tool_context));
|
|
|
|
|
2001-07-08 02:16:18 +08:00
|
|
|
gimp_container_remove_handler (gimp->images,
|
|
|
|
tool_manager->image_dirty_handler_id);
|
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
g_free (tool_manager);
|
|
|
|
|
|
|
|
tool_manager_set (gimp, NULL);
|
2001-07-07 20:17:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tool_manager_set_global_paint_options (Gimp *gimp,
|
|
|
|
gboolean global)
|
|
|
|
{
|
2001-07-08 01:36:00 +08:00
|
|
|
GimpToolManager *tool_manager;
|
|
|
|
GimpToolInfo *tool_info;
|
2001-07-07 20:17:23 +08:00
|
|
|
|
|
|
|
if (global == gimprc.global_paint_options)
|
2001-02-14 13:19:55 +08:00
|
|
|
return;
|
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
tool_manager = tool_manager_get (gimp);
|
|
|
|
|
2001-07-07 20:17:23 +08:00
|
|
|
paint_options_set_global (global);
|
2001-02-14 13:19:55 +08:00
|
|
|
|
2001-07-07 20:17:23 +08:00
|
|
|
/* NULL is the main brush selection */
|
|
|
|
brush_select_show_paint_options (NULL, global);
|
|
|
|
|
|
|
|
tool_info = gimp_context_get_tool (gimp_get_user_context (gimp));
|
|
|
|
|
|
|
|
if (global)
|
|
|
|
{
|
2001-07-08 01:36:00 +08:00
|
|
|
if (tool_info && tool_info->context)
|
2001-07-07 20:17:23 +08:00
|
|
|
{
|
2001-07-08 01:36:00 +08:00
|
|
|
gimp_context_unset_parent (tool_info->context);
|
2001-07-07 20:17:23 +08:00
|
|
|
}
|
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
gimp_context_copy_args (tool_manager->global_tool_context,
|
2001-07-07 20:17:23 +08:00
|
|
|
gimp_get_user_context (gimp),
|
|
|
|
PAINT_OPTIONS_MASK);
|
2001-07-08 01:36:00 +08:00
|
|
|
gimp_context_set_parent (tool_manager->global_tool_context,
|
2001-07-07 20:17:23 +08:00
|
|
|
gimp_get_user_context (gimp));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-07-08 01:36:00 +08:00
|
|
|
gimp_context_unset_parent (tool_manager->global_tool_context);
|
2001-07-07 20:17:23 +08:00
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
if (tool_info && tool_info->context)
|
2001-07-07 20:17:23 +08:00
|
|
|
{
|
2001-07-08 01:36:00 +08:00
|
|
|
gimp_context_copy_args (tool_info->context,
|
|
|
|
gimp_get_user_context (gimp),
|
2001-07-07 20:17:23 +08:00
|
|
|
GIMP_CONTEXT_PAINT_ARGS_MASK);
|
2001-07-08 01:36:00 +08:00
|
|
|
gimp_context_set_parent (tool_info->context,
|
|
|
|
gimp_get_user_context (gimp));
|
2001-07-07 20:17:23 +08:00
|
|
|
}
|
|
|
|
}
|
2001-02-14 13:19:55 +08:00
|
|
|
}
|
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
GimpTool *
|
|
|
|
tool_manager_get_active (Gimp *gimp)
|
|
|
|
{
|
|
|
|
GimpToolManager *tool_manager;
|
|
|
|
|
|
|
|
tool_manager = tool_manager_get (gimp);
|
|
|
|
|
|
|
|
return tool_manager->active_tool;
|
|
|
|
}
|
|
|
|
|
2001-02-14 13:19:55 +08:00
|
|
|
void
|
2001-07-08 01:36:00 +08:00
|
|
|
tool_manager_select_tool (Gimp *gimp,
|
|
|
|
GimpTool *tool)
|
2001-02-14 13:19:55 +08:00
|
|
|
{
|
2001-07-08 01:36:00 +08:00
|
|
|
GimpToolManager *tool_manager;
|
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
g_return_if_fail (tool != NULL);
|
|
|
|
g_return_if_fail (GIMP_IS_TOOL (tool));
|
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
tool_manager = tool_manager_get (gimp);
|
|
|
|
|
|
|
|
if (tool_manager->active_tool)
|
|
|
|
gtk_object_unref (GTK_OBJECT (tool_manager->active_tool));
|
2001-02-14 13:19:55 +08:00
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
tool_manager->active_tool = tool;
|
2001-02-14 13:19:55 +08:00
|
|
|
}
|
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
void
|
2001-07-08 01:36:00 +08:00
|
|
|
tool_manager_push_tool (Gimp *gimp,
|
|
|
|
GimpTool *tool)
|
2001-02-28 10:29:25 +08:00
|
|
|
{
|
2001-07-08 01:36:00 +08:00
|
|
|
GimpToolManager *tool_manager;
|
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
g_return_if_fail (tool != NULL);
|
|
|
|
g_return_if_fail (GIMP_IS_TOOL (tool));
|
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
tool_manager = tool_manager_get (gimp);
|
|
|
|
|
|
|
|
if (tool_manager->active_tool)
|
2001-02-28 10:29:25 +08:00
|
|
|
{
|
2001-07-08 01:36:00 +08:00
|
|
|
gtk_object_ref (GTK_OBJECT (tool_manager->active_tool));
|
2001-02-28 10:29:25 +08:00
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
tool_manager->tool_stack = g_slist_prepend (tool_manager->tool_stack,
|
|
|
|
tool_manager->active_tool);
|
2001-02-28 10:29:25 +08:00
|
|
|
}
|
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
tool_manager_select_tool (gimp, tool);
|
2001-02-28 10:29:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-07-08 01:36:00 +08:00
|
|
|
tool_manager_pop_tool (Gimp *gimp)
|
2001-02-28 10:29:25 +08:00
|
|
|
{
|
2001-07-08 01:36:00 +08:00
|
|
|
GimpToolManager *tool_manager;
|
|
|
|
|
|
|
|
tool_manager = tool_manager_get (gimp);
|
|
|
|
|
|
|
|
if (tool_manager->tool_stack)
|
2001-02-28 10:29:25 +08:00
|
|
|
{
|
2001-07-08 01:36:00 +08:00
|
|
|
tool_manager_select_tool (gimp,
|
|
|
|
GIMP_TOOL (tool_manager->tool_stack->data));
|
2001-02-28 10:29:25 +08:00
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
tool_manager->tool_stack = g_slist_remove (tool_manager->tool_stack,
|
|
|
|
tool_manager->active_tool);
|
2001-02-28 10:29:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-21 20:18:09 +08:00
|
|
|
void
|
2001-07-07 20:17:23 +08:00
|
|
|
tool_manager_initialize_tool (Gimp *gimp,
|
|
|
|
GimpTool *tool, /* FIXME: remove tool param */
|
2001-02-21 20:18:09 +08:00
|
|
|
GDisplay *gdisp)
|
|
|
|
{
|
2001-07-08 01:36:00 +08:00
|
|
|
GimpToolManager *tool_manager;
|
|
|
|
GimpToolInfo *tool_info;
|
2001-07-08 06:49:01 +08:00
|
|
|
GtkType tool_type;
|
2001-07-08 01:36:00 +08:00
|
|
|
|
|
|
|
tool_manager = tool_manager_get (gimp);
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2001-07-08 06:49:01 +08:00
|
|
|
tool_type = GTK_OBJECT (tool)->klass->type;
|
|
|
|
|
2001-02-21 20:18:09 +08:00
|
|
|
/* Tools which have an init function have dialogs and
|
|
|
|
* cannot be initialized without a display
|
|
|
|
*/
|
|
|
|
if (GIMP_TOOL_CLASS (GTK_OBJECT (tool)->klass)->initialize && ! gdisp)
|
|
|
|
{
|
2001-07-08 06:49:01 +08:00
|
|
|
tool_info = tool_manager_get_info_by_type (gimp,
|
|
|
|
GIMP_TYPE_RECT_SELECT_TOOL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tool_info = gimp_context_get_tool (gimp_get_user_context (gimp));
|
2001-02-21 20:18:09 +08:00
|
|
|
}
|
|
|
|
|
2001-07-08 06:49:01 +08:00
|
|
|
if (tool_type == tool_info->tool_type)
|
2001-02-21 20:18:09 +08:00
|
|
|
{
|
2001-07-07 20:17:23 +08:00
|
|
|
gimp_context_tool_changed (gimp_get_user_context (gimp));
|
2001-02-21 20:18:09 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-07-08 06:49:01 +08:00
|
|
|
tool_info = tool_manager_get_info_by_type (gimp, tool_type);
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2001-07-08 06:49:01 +08:00
|
|
|
gimp_context_set_tool (gimp_get_user_context (gimp), tool_info);
|
2001-02-21 20:18:09 +08:00
|
|
|
}
|
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
gimp_tool_initialize (tool_manager->active_tool, gdisp);
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2001-03-12 09:21:43 +08:00
|
|
|
if (gdisp)
|
2001-07-08 01:36:00 +08:00
|
|
|
tool_manager->active_tool->drawable =
|
|
|
|
gimp_image_active_drawable (gdisp->gimage);
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2001-02-22 05:56:39 +08:00
|
|
|
/* don't set tool->gdisp here! (see commands.c) */
|
2001-02-21 20:18:09 +08:00
|
|
|
}
|
|
|
|
|
2001-02-14 13:19:55 +08:00
|
|
|
void
|
2001-07-08 01:36:00 +08:00
|
|
|
tool_manager_control_active (Gimp *gimp,
|
|
|
|
ToolAction action,
|
2001-02-21 20:18:09 +08:00
|
|
|
GDisplay *gdisp)
|
2001-02-14 13:19:55 +08:00
|
|
|
{
|
2001-07-08 01:36:00 +08:00
|
|
|
GimpToolManager *tool_manager;
|
|
|
|
|
|
|
|
tool_manager = tool_manager_get (gimp);
|
|
|
|
|
|
|
|
if (tool_manager->active_tool)
|
2001-02-21 20:18:09 +08:00
|
|
|
{
|
2001-07-08 01:36:00 +08:00
|
|
|
if (tool_manager->active_tool->gdisp == gdisp)
|
2001-02-21 20:18:09 +08:00
|
|
|
{
|
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case PAUSE:
|
2001-07-08 01:36:00 +08:00
|
|
|
if (tool_manager->active_tool->state == ACTIVE)
|
2001-02-21 20:18:09 +08:00
|
|
|
{
|
2001-07-08 01:36:00 +08:00
|
|
|
if (! tool_manager->active_tool->paused_count)
|
2001-02-21 20:18:09 +08:00
|
|
|
{
|
2001-07-08 01:36:00 +08:00
|
|
|
tool_manager->active_tool->state = PAUSED;
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
gimp_tool_control (tool_manager->active_tool,
|
|
|
|
action, gdisp);
|
2001-02-21 20:18:09 +08:00
|
|
|
}
|
|
|
|
}
|
2001-07-08 01:36:00 +08:00
|
|
|
|
|
|
|
tool_manager->active_tool->paused_count++;
|
2001-02-21 20:18:09 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RESUME:
|
2001-07-08 01:36:00 +08:00
|
|
|
tool_manager->active_tool->paused_count--;
|
|
|
|
|
|
|
|
if (tool_manager->active_tool->state == PAUSED)
|
2001-02-21 20:18:09 +08:00
|
|
|
{
|
2001-07-08 01:36:00 +08:00
|
|
|
if (! tool_manager->active_tool->paused_count)
|
2001-02-21 20:18:09 +08:00
|
|
|
{
|
2001-07-08 01:36:00 +08:00
|
|
|
tool_manager->active_tool->state = ACTIVE;
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
gimp_tool_control (tool_manager->active_tool,
|
|
|
|
action, gdisp);
|
2001-02-21 20:18:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HALT:
|
2001-07-08 01:36:00 +08:00
|
|
|
tool_manager->active_tool->state = INACTIVE;
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
gimp_tool_control (tool_manager->active_tool, action, gdisp);
|
2001-02-21 20:18:09 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DESTROY:
|
2001-07-08 01:36:00 +08:00
|
|
|
gtk_object_unref (GTK_OBJECT (tool_manager->active_tool));
|
|
|
|
tool_manager->active_tool = NULL;
|
2001-02-21 20:18:09 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (action == HALT)
|
|
|
|
{
|
2001-07-08 01:36:00 +08:00
|
|
|
tool_manager->active_tool->state = INACTIVE;
|
2001-02-21 20:18:09 +08:00
|
|
|
}
|
|
|
|
}
|
2001-02-14 13:19:55 +08:00
|
|
|
}
|
|
|
|
|
2001-02-21 20:18:09 +08:00
|
|
|
void
|
2001-07-07 20:17:23 +08:00
|
|
|
tool_manager_register_tool (Gimp *gimp,
|
|
|
|
GtkType tool_type,
|
2001-02-28 07:20:51 +08:00
|
|
|
gboolean tool_context,
|
2001-02-24 05:32:47 +08:00
|
|
|
const gchar *identifier,
|
|
|
|
const gchar *blurb,
|
|
|
|
const gchar *help,
|
2001-02-21 20:18:09 +08:00
|
|
|
const gchar *menu_path,
|
|
|
|
const gchar *menu_accel,
|
|
|
|
const gchar *help_domain,
|
|
|
|
const gchar *help_data,
|
|
|
|
const gchar **icon_data)
|
|
|
|
{
|
2001-07-08 01:36:00 +08:00
|
|
|
GimpToolManager *tool_manager;
|
|
|
|
GimpToolInfo *tool_info;
|
|
|
|
|
|
|
|
tool_manager = tool_manager_get (gimp);
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
tool_info = gimp_tool_info_new (tool_manager->global_tool_context,
|
2001-07-07 20:17:23 +08:00
|
|
|
tool_type,
|
2001-02-28 07:20:51 +08:00
|
|
|
tool_context,
|
2001-02-24 05:32:47 +08:00
|
|
|
identifier,
|
|
|
|
blurb,
|
|
|
|
help,
|
2001-02-21 20:18:09 +08:00
|
|
|
menu_path,
|
|
|
|
menu_accel,
|
|
|
|
help_domain,
|
|
|
|
help_data,
|
|
|
|
icon_data);
|
|
|
|
|
2001-07-07 20:17:23 +08:00
|
|
|
gimp_container_add (gimp->tool_info_list, GIMP_OBJECT (tool_info));
|
2001-02-21 20:18:09 +08:00
|
|
|
}
|
|
|
|
|
2001-02-24 05:32:47 +08:00
|
|
|
void
|
|
|
|
tool_manager_register_tool_options (GtkType tool_type,
|
|
|
|
ToolOptions *tool_options)
|
|
|
|
{
|
|
|
|
GimpToolInfo *tool_info;
|
|
|
|
|
2001-07-07 20:17:23 +08:00
|
|
|
tool_info = tool_manager_get_info_by_type (the_gimp, tool_type);
|
2001-02-24 05:32:47 +08:00
|
|
|
|
|
|
|
if (! tool_info)
|
|
|
|
{
|
|
|
|
g_warning ("%s(): no tool info registered for %s",
|
|
|
|
G_GNUC_FUNCTION, gtk_type_name (tool_type));
|
2001-03-31 22:10:22 +08:00
|
|
|
return;
|
2001-02-24 05:32:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
tool_info->tool_options = tool_options;
|
|
|
|
}
|
|
|
|
|
2001-02-21 20:18:09 +08:00
|
|
|
GimpToolInfo *
|
2001-07-07 20:17:23 +08:00
|
|
|
tool_manager_get_info_by_type (Gimp *gimp,
|
|
|
|
GtkType tool_type)
|
2001-02-21 20:18:09 +08:00
|
|
|
{
|
|
|
|
GimpToolInfo *tool_info;
|
|
|
|
GList *list;
|
|
|
|
|
2001-07-07 20:17:23 +08:00
|
|
|
for (list = GIMP_LIST (gimp->tool_info_list)->list;
|
2001-02-21 20:18:09 +08:00
|
|
|
list;
|
|
|
|
list = g_list_next (list))
|
|
|
|
{
|
|
|
|
tool_info = (GimpToolInfo *) list->data;
|
|
|
|
|
|
|
|
if (tool_info->tool_type == tool_type)
|
|
|
|
return tool_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-02-22 05:56:39 +08:00
|
|
|
|
|
|
|
GimpToolInfo *
|
2001-07-07 20:17:23 +08:00
|
|
|
tool_manager_get_info_by_tool (Gimp *gimp,
|
|
|
|
GimpTool *tool)
|
2001-02-22 05:56:39 +08:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (tool != NULL, NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_TOOL (tool), NULL);
|
|
|
|
|
2001-07-07 20:17:23 +08:00
|
|
|
return tool_manager_get_info_by_type (gimp, GTK_OBJECT (tool)->klass->type);
|
2001-02-22 05:56:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const gchar *
|
2001-07-07 20:17:23 +08:00
|
|
|
tool_manager_active_get_PDB_string (Gimp *gimp)
|
2001-02-22 05:56:39 +08:00
|
|
|
{
|
2001-07-08 01:36:00 +08:00
|
|
|
GimpToolManager *tool_manager;
|
|
|
|
GimpToolInfo *tool_info;
|
|
|
|
const gchar *tool_str = "gimp_paintbrush_default";
|
2001-02-22 05:56:39 +08:00
|
|
|
|
|
|
|
/* Return the correct PDB function for the active tool
|
2001-03-31 23:45:05 +08:00
|
|
|
* The default is paintbrush if the tool is not recognized
|
2001-02-22 05:56:39 +08:00
|
|
|
*/
|
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
tool_manager = tool_manager_get (gimp);
|
|
|
|
|
|
|
|
if (! tool_manager->active_tool)
|
2001-03-31 23:45:05 +08:00
|
|
|
return tool_str;
|
2001-02-22 05:56:39 +08:00
|
|
|
|
2001-07-07 20:17:23 +08:00
|
|
|
tool_info = gimp_context_get_tool (gimp_get_user_context (gimp));
|
2001-03-31 23:45:05 +08:00
|
|
|
|
|
|
|
if (tool_info->tool_type == GIMP_TYPE_PENCIL_TOOL)
|
|
|
|
{
|
|
|
|
tool_str = "gimp_pencil";
|
|
|
|
}
|
|
|
|
else if (tool_info->tool_type == GIMP_TYPE_PAINTBRUSH_TOOL)
|
|
|
|
{
|
|
|
|
tool_str = "gimp_paintbrush_default";
|
|
|
|
}
|
|
|
|
else if (tool_info->tool_type == GIMP_TYPE_ERASER_TOOL)
|
|
|
|
{
|
|
|
|
tool_str = "gimp_eraser_default";
|
|
|
|
}
|
|
|
|
else if (tool_info->tool_type == GIMP_TYPE_AIRBRUSH_TOOL)
|
|
|
|
{
|
|
|
|
tool_str = "gimp_airbrush_default";
|
|
|
|
}
|
|
|
|
else if (tool_info->tool_type == GIMP_TYPE_CLONE_TOOL)
|
|
|
|
{
|
|
|
|
tool_str = "gimp_clone_default";
|
|
|
|
}
|
|
|
|
else if (tool_info->tool_type == GIMP_TYPE_CONVOLVE_TOOL)
|
|
|
|
{
|
|
|
|
tool_str = "gimp_convolve_default";
|
|
|
|
}
|
|
|
|
else if (tool_info->tool_type == GIMP_TYPE_SMUDGE_TOOL)
|
|
|
|
{
|
|
|
|
tool_str = "gimp_smudge_default";
|
|
|
|
}
|
|
|
|
else if (tool_info->tool_type == GIMP_TYPE_DODGEBURN_TOOL)
|
|
|
|
{
|
|
|
|
tool_str = "gimp_dodgeburn_default";
|
|
|
|
}
|
|
|
|
|
|
|
|
return tool_str;
|
2001-02-22 05:56:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const gchar *
|
2001-07-08 01:36:00 +08:00
|
|
|
tool_manager_active_get_help_data (Gimp *gimp)
|
2001-02-22 05:56:39 +08:00
|
|
|
{
|
2001-07-08 01:36:00 +08:00
|
|
|
GimpToolManager *tool_manager;
|
|
|
|
|
|
|
|
tool_manager = tool_manager_get (gimp);
|
2001-02-22 05:56:39 +08:00
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
if (! tool_manager->active_tool)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return tool_manager_get_info_by_tool (gimp,
|
|
|
|
tool_manager->active_tool)->help_data;
|
2001-02-22 05:56:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tool_manager_help_func (const gchar *help_data)
|
|
|
|
{
|
2001-07-08 01:36:00 +08:00
|
|
|
gimp_standard_help_func (tool_manager_active_get_help_data (the_gimp));
|
2001-02-22 05:56:39 +08:00
|
|
|
}
|
2001-07-07 20:17:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
#define TOOL_MANAGER_DATA_KEY "gimp-tool-manager"
|
2001-07-07 20:17:23 +08:00
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
static GimpToolManager *
|
|
|
|
tool_manager_get (Gimp *gimp)
|
|
|
|
{
|
|
|
|
return gtk_object_get_data (GTK_OBJECT (gimp), TOOL_MANAGER_DATA_KEY);
|
|
|
|
}
|
2001-07-07 20:17:23 +08:00
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
static void
|
|
|
|
tool_manager_set (Gimp *gimp,
|
|
|
|
GimpToolManager *tool_manager)
|
|
|
|
{
|
|
|
|
gtk_object_set_data (GTK_OBJECT (gimp), TOOL_MANAGER_DATA_KEY,
|
|
|
|
tool_manager);
|
2001-07-07 20:17:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
tool_manager_tool_changed (GimpContext *user_context,
|
|
|
|
GimpToolInfo *tool_info,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2001-07-08 01:36:00 +08:00
|
|
|
GimpToolManager *tool_manager;
|
|
|
|
GimpTool *new_tool = NULL;
|
|
|
|
GimpContext *tool_context = NULL;
|
2001-07-07 20:17:23 +08:00
|
|
|
|
|
|
|
if (! tool_info)
|
|
|
|
return;
|
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
tool_manager = (GimpToolManager *) data;
|
|
|
|
|
2001-07-07 20:17:23 +08:00
|
|
|
/* FIXME: gimp_busy HACK */
|
|
|
|
if (gimp_busy)
|
|
|
|
{
|
|
|
|
/* there may be contexts waiting for the user_context's "tool_changed"
|
|
|
|
* signal, so stop emitting it.
|
|
|
|
*/
|
|
|
|
gtk_signal_emit_stop_by_name (GTK_OBJECT (user_context), "tool_changed");
|
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
if (GTK_OBJECT (tool_manager->active_tool)->klass->type !=
|
|
|
|
tool_info->tool_type)
|
2001-07-07 20:17:23 +08:00
|
|
|
{
|
|
|
|
gtk_signal_handler_block_by_func (GTK_OBJECT (user_context),
|
|
|
|
tool_manager_tool_changed,
|
2001-07-08 01:36:00 +08:00
|
|
|
data);
|
2001-07-07 20:17:23 +08:00
|
|
|
|
|
|
|
/* explicitly set the current tool */
|
|
|
|
gimp_context_set_tool (user_context,
|
|
|
|
tool_manager_get_info_by_tool (user_context->gimp,
|
2001-07-08 01:36:00 +08:00
|
|
|
tool_manager->active_tool));
|
2001-07-07 20:17:23 +08:00
|
|
|
|
|
|
|
gtk_signal_handler_unblock_by_func (GTK_OBJECT (user_context),
|
|
|
|
tool_manager_tool_changed,
|
2001-07-08 01:36:00 +08:00
|
|
|
data);
|
2001-07-07 20:17:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tool_info->tool_type != GTK_TYPE_NONE)
|
|
|
|
{
|
|
|
|
new_tool = gtk_type_new (tool_info->tool_type);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_warning ("%s(): tool_info contains no valid GtkType",
|
|
|
|
G_GNUC_FUNCTION);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! gimprc.global_paint_options)
|
|
|
|
{
|
2001-07-08 01:36:00 +08:00
|
|
|
if (tool_manager->active_tool &&
|
2001-07-07 20:17:23 +08:00
|
|
|
(tool_context = tool_manager_get_info_by_tool (user_context->gimp,
|
2001-07-08 01:36:00 +08:00
|
|
|
tool_manager->active_tool)->context))
|
2001-07-07 20:17:23 +08:00
|
|
|
{
|
|
|
|
gimp_context_unset_parent (tool_context);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((tool_context = tool_info->context))
|
|
|
|
{
|
|
|
|
gimp_context_copy_args (tool_context, user_context,
|
|
|
|
PAINT_OPTIONS_MASK);
|
|
|
|
gimp_context_set_parent (tool_context, user_context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
tool_manager_select_tool (user_context->gimp, new_tool);
|
2001-07-07 20:17:23 +08:00
|
|
|
}
|
2001-07-08 02:16:18 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
tool_manager_image_dirty (GimpImage *gimage,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GimpToolManager *tool_manager;
|
|
|
|
|
|
|
|
tool_manager = (GimpToolManager *) data;
|
|
|
|
|
|
|
|
if (tool_manager->active_tool && ! tool_manager->active_tool->preserve)
|
|
|
|
{
|
|
|
|
GDisplay *gdisp = tool_manager->active_tool->gdisp;
|
|
|
|
|
|
|
|
if (gdisp)
|
|
|
|
{
|
|
|
|
if (gdisp->gimage == gimage)
|
|
|
|
tool_manager_initialize_tool (gimage->gimp,
|
|
|
|
tool_manager->active_tool,
|
|
|
|
gdisp);
|
|
|
|
else
|
|
|
|
tool_manager_initialize_tool (gimage->gimp,
|
|
|
|
tool_manager->active_tool,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|