2001-02-21 20:18:09 +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"
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
#include <glib-object.h>
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2001-05-26 05:17:07 +08:00
|
|
|
#include "core-types.h"
|
2001-05-15 19:25:25 +08:00
|
|
|
|
|
|
|
#include "base/temp-buf.h"
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2001-07-07 20:17:23 +08:00
|
|
|
#include "gimp.h"
|
2002-02-27 21:57:49 +08:00
|
|
|
#include "gimpcontainer.h"
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "gimpcontext.h"
|
2002-02-27 21:57:49 +08:00
|
|
|
#include "gimppaintinfo.h"
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "gimptoolinfo.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
|
2001-02-21 20:18:09 +08:00
|
|
|
|
|
|
|
static void gimp_tool_info_class_init (GimpToolInfoClass *klass);
|
|
|
|
static void gimp_tool_info_init (GimpToolInfo *tool_info);
|
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
static void gimp_tool_info_finalize (GObject *object);
|
|
|
|
|
2001-02-21 20:18:09 +08:00
|
|
|
static TempBuf * gimp_tool_info_get_new_preview (GimpViewable *viewable,
|
|
|
|
gint width,
|
|
|
|
gint height);
|
|
|
|
|
|
|
|
|
|
|
|
static GimpDataClass *parent_class = NULL;
|
|
|
|
|
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
GType
|
2001-02-21 20:18:09 +08:00
|
|
|
gimp_tool_info_get_type (void)
|
|
|
|
{
|
2001-08-11 22:39:19 +08:00
|
|
|
static GType tool_info_type = 0;
|
2001-02-21 20:18:09 +08:00
|
|
|
|
|
|
|
if (! tool_info_type)
|
|
|
|
{
|
2001-08-11 22:39:19 +08:00
|
|
|
static const GTypeInfo tool_info_info =
|
2001-02-21 20:18:09 +08:00
|
|
|
{
|
|
|
|
sizeof (GimpToolInfoClass),
|
2001-08-11 22:39:19 +08:00
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_tool_info_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpToolInfo),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_tool_info_init,
|
2001-02-21 20:18:09 +08:00
|
|
|
};
|
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
tool_info_type = g_type_register_static (GIMP_TYPE_DATA,
|
|
|
|
"GimpToolInfo",
|
|
|
|
&tool_info_info, 0);
|
2001-02-21 20:18:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return tool_info_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_tool_info_class_init (GimpToolInfoClass *klass)
|
|
|
|
{
|
2001-08-11 22:39:19 +08:00
|
|
|
GObjectClass *object_class;
|
2001-02-21 20:18:09 +08:00
|
|
|
GimpViewableClass *viewable_class;
|
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
object_class = G_OBJECT_CLASS (klass);
|
|
|
|
viewable_class = GIMP_VIEWABLE_CLASS (klass);
|
2001-02-21 20:18:09 +08:00
|
|
|
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-25 05:27:11 +08:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
object_class->finalize = gimp_tool_info_finalize;
|
2001-02-21 20:18:09 +08:00
|
|
|
|
|
|
|
viewable_class->get_new_preview = gimp_tool_info_get_new_preview;
|
|
|
|
}
|
|
|
|
|
2001-10-29 02:45:45 +08:00
|
|
|
static void
|
2001-02-21 20:18:09 +08:00
|
|
|
gimp_tool_info_init (GimpToolInfo *tool_info)
|
|
|
|
{
|
2002-02-26 10:00:02 +08:00
|
|
|
tool_info->tool_type = G_TYPE_NONE;
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2002-02-26 10:00:02 +08:00
|
|
|
tool_info->blurb = NULL;
|
|
|
|
tool_info->help = NULL;
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2002-02-26 10:00:02 +08:00
|
|
|
tool_info->menu_path = NULL;
|
|
|
|
tool_info->menu_accel = NULL;
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2002-02-26 10:00:02 +08:00
|
|
|
tool_info->help_domain = NULL;
|
|
|
|
tool_info->help_data = NULL;
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2002-02-26 10:00:02 +08:00
|
|
|
tool_info->stock_id = NULL;
|
|
|
|
tool_info->stock_pixbuf = NULL;
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2002-02-26 10:00:02 +08:00
|
|
|
tool_info->context = NULL;
|
|
|
|
tool_info->tool_options = NULL;
|
2002-02-27 21:57:49 +08:00
|
|
|
tool_info->paint_info = NULL;
|
2001-02-21 20:18:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-08-11 22:39:19 +08:00
|
|
|
gimp_tool_info_finalize (GObject *object)
|
2001-02-21 20:18:09 +08:00
|
|
|
{
|
|
|
|
GimpToolInfo *tool_info;
|
|
|
|
|
2001-12-08 01:39:51 +08:00
|
|
|
tool_info = GIMP_TOOL_INFO (object);
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
if (tool_info->blurb)
|
|
|
|
{
|
|
|
|
g_free (tool_info->blurb);
|
|
|
|
tool_info->blurb = NULL;
|
|
|
|
}
|
|
|
|
if (tool_info->help)
|
|
|
|
{
|
|
|
|
g_free (tool_info->help);
|
|
|
|
tool_info->blurb = NULL;
|
|
|
|
}
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
if (tool_info->menu_path)
|
|
|
|
{
|
|
|
|
g_free (tool_info->menu_path);
|
|
|
|
tool_info->menu_path = NULL;
|
|
|
|
}
|
|
|
|
if (tool_info->menu_accel)
|
|
|
|
{
|
|
|
|
g_free (tool_info->menu_accel);
|
|
|
|
tool_info->menu_accel = NULL;
|
|
|
|
}
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
if (tool_info->help_domain)
|
|
|
|
{
|
|
|
|
g_free (tool_info->help_domain);
|
|
|
|
tool_info->help_domain = NULL;
|
|
|
|
}
|
|
|
|
if (tool_info->help_data)
|
|
|
|
{
|
|
|
|
g_free (tool_info->help_data);
|
|
|
|
tool_info->help_data = NULL;
|
|
|
|
}
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2002-03-15 01:07:02 +08:00
|
|
|
if (tool_info->stock_id)
|
|
|
|
{
|
|
|
|
g_object_unref (G_OBJECT (tool_info->stock_id));
|
|
|
|
tool_info->stock_id = NULL;
|
|
|
|
}
|
2001-08-06 00:07:02 +08:00
|
|
|
if (tool_info->stock_pixbuf)
|
|
|
|
{
|
|
|
|
g_object_unref (G_OBJECT (tool_info->stock_pixbuf));
|
|
|
|
tool_info->stock_pixbuf = NULL;
|
|
|
|
}
|
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2001-02-21 20:18:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static TempBuf *
|
2001-08-06 00:07:02 +08:00
|
|
|
temp_buf_new_from_pixbuf (GdkPixbuf *pixbuf,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
2001-02-21 20:18:09 +08:00
|
|
|
{
|
2001-08-06 00:07:02 +08:00
|
|
|
TempBuf *temp_buf;
|
|
|
|
gint pixbuf_width;
|
|
|
|
gint pixbuf_height;
|
2002-03-02 19:20:21 +08:00
|
|
|
gint bytes;
|
2001-08-06 00:07:02 +08:00
|
|
|
guchar transparent[4] = { 0, 0, 0, 0 };
|
|
|
|
guchar *p_data;
|
|
|
|
guchar *t_data;
|
2002-03-02 19:20:21 +08:00
|
|
|
gint y;
|
2001-08-06 00:07:02 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
|
|
|
|
|
|
|
|
pixbuf_width = gdk_pixbuf_get_width (pixbuf);
|
|
|
|
pixbuf_height = gdk_pixbuf_get_height (pixbuf);
|
|
|
|
|
|
|
|
if (pixbuf_width != width || pixbuf_height != height)
|
|
|
|
{
|
|
|
|
GdkPixbuf *scaled_pixbuf;
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2001-08-06 00:07:02 +08:00
|
|
|
scaled_pixbuf = gdk_pixbuf_scale_simple (pixbuf,
|
|
|
|
width, height,
|
|
|
|
GDK_INTERP_BILINEAR);
|
2001-02-23 11:29:53 +08:00
|
|
|
|
2001-08-06 00:07:02 +08:00
|
|
|
pixbuf = scaled_pixbuf;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_object_ref (G_OBJECT (pixbuf));
|
|
|
|
}
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2002-03-02 19:20:21 +08:00
|
|
|
bytes = gdk_pixbuf_get_n_channels (pixbuf);
|
|
|
|
|
|
|
|
temp_buf = temp_buf_new (width, height, bytes, 0, 0, transparent);
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2001-08-06 00:07:02 +08:00
|
|
|
p_data = gdk_pixbuf_get_pixels (pixbuf);
|
|
|
|
t_data = temp_buf_data (temp_buf);
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2001-08-06 00:07:02 +08:00
|
|
|
for (y = 0; y < height; y++)
|
2001-02-21 20:18:09 +08:00
|
|
|
{
|
2002-03-02 19:20:21 +08:00
|
|
|
memcpy (t_data, p_data, width * bytes);
|
2001-08-06 00:07:02 +08:00
|
|
|
|
|
|
|
p_data += gdk_pixbuf_get_rowstride (pixbuf);
|
2002-03-02 19:20:21 +08:00
|
|
|
t_data += width * bytes;
|
2001-02-21 20:18:09 +08:00
|
|
|
}
|
|
|
|
|
2001-08-06 00:07:02 +08:00
|
|
|
g_object_unref (G_OBJECT (pixbuf));
|
2001-02-24 10:42:09 +08:00
|
|
|
|
2001-08-06 00:07:02 +08:00
|
|
|
return temp_buf;
|
|
|
|
}
|
2001-02-24 10:42:09 +08:00
|
|
|
|
2001-08-06 00:07:02 +08:00
|
|
|
static TempBuf *
|
|
|
|
gimp_tool_info_get_new_preview (GimpViewable *viewable,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
|
|
|
{
|
|
|
|
GimpToolInfo *tool_info;
|
2001-02-24 10:42:09 +08:00
|
|
|
|
2001-08-06 00:07:02 +08:00
|
|
|
tool_info = GIMP_TOOL_INFO (viewable);
|
2001-02-24 10:42:09 +08:00
|
|
|
|
2001-08-06 00:07:02 +08:00
|
|
|
return temp_buf_new_from_pixbuf (tool_info->stock_pixbuf, width, height);
|
2001-02-21 20:18:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GimpToolInfo *
|
2001-10-29 19:47:11 +08:00
|
|
|
gimp_tool_info_new (Gimp *gimp,
|
|
|
|
GimpContext *context,
|
2001-08-06 00:07:02 +08:00
|
|
|
GType 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,
|
2002-02-26 10:00:02 +08:00
|
|
|
const gchar *paint_core_name,
|
2001-08-06 00:07:02 +08:00
|
|
|
const gchar *stock_id,
|
|
|
|
GdkPixbuf *stock_pixbuf)
|
2001-02-21 20:18:09 +08:00
|
|
|
{
|
2002-02-27 21:57:49 +08:00
|
|
|
GimpPaintInfo *paint_info;
|
|
|
|
GimpToolInfo *tool_info;
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2001-10-29 19:47:11 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
2001-12-08 01:39:51 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
|
2001-08-06 00:07:02 +08:00
|
|
|
g_return_val_if_fail (identifier != NULL, NULL);
|
|
|
|
g_return_val_if_fail (blurb != NULL, NULL);
|
|
|
|
g_return_val_if_fail (help != NULL, NULL);
|
|
|
|
g_return_val_if_fail (menu_path != NULL, NULL);
|
2002-02-26 10:00:02 +08:00
|
|
|
g_return_val_if_fail (paint_core_name != NULL, NULL);
|
2001-08-06 00:07:02 +08:00
|
|
|
g_return_val_if_fail (stock_id != NULL, NULL);
|
2001-11-18 00:32:34 +08:00
|
|
|
g_return_val_if_fail (! stock_pixbuf || GDK_IS_PIXBUF (stock_pixbuf), NULL);
|
2001-08-06 00:07:02 +08:00
|
|
|
|
2002-02-27 21:57:49 +08:00
|
|
|
paint_info = (GimpPaintInfo *)
|
|
|
|
gimp_container_get_child_by_name (gimp->paint_info_list, paint_core_name);
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_PAINT_INFO (paint_info), NULL);
|
|
|
|
|
2001-10-29 19:47:11 +08:00
|
|
|
tool_info = g_object_new (GIMP_TYPE_TOOL_INFO,
|
|
|
|
"name", identifier,
|
|
|
|
NULL);
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2002-02-27 21:57:49 +08:00
|
|
|
tool_info->paint_info = paint_info;
|
|
|
|
|
2001-10-29 19:47:11 +08:00
|
|
|
if (tool_context)
|
|
|
|
{
|
2001-12-08 01:39:51 +08:00
|
|
|
tool_info->context = gimp_context_new (gimp,
|
|
|
|
identifier,
|
|
|
|
context);
|
2001-10-29 19:47:11 +08:00
|
|
|
}
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2002-02-26 10:00:02 +08:00
|
|
|
tool_info->gimp = gimp;
|
|
|
|
tool_info->tool_type = tool_type;
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2002-02-26 10:00:02 +08:00
|
|
|
tool_info->blurb = g_strdup (blurb);
|
|
|
|
tool_info->help = g_strdup (help);
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2002-02-26 10:00:02 +08:00
|
|
|
tool_info->menu_path = g_strdup (menu_path);
|
|
|
|
tool_info->menu_accel = g_strdup (menu_accel);
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2002-02-26 10:00:02 +08:00
|
|
|
tool_info->help_domain = g_strdup (help_domain);
|
|
|
|
tool_info->help_data = g_strdup (help_data);
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2002-03-15 01:07:02 +08:00
|
|
|
tool_info->stock_id = g_strdup (stock_id);
|
2002-02-26 10:00:02 +08:00
|
|
|
tool_info->stock_pixbuf = stock_pixbuf;
|
2001-08-06 00:07:02 +08:00
|
|
|
|
2001-11-18 00:32:34 +08:00
|
|
|
if (stock_pixbuf)
|
|
|
|
g_object_ref (G_OBJECT (stock_pixbuf));
|
2001-02-21 20:18:09 +08:00
|
|
|
|
|
|
|
return tool_info;
|
|
|
|
}
|
2001-02-24 05:32:47 +08:00
|
|
|
|
2001-08-17 22:27:31 +08:00
|
|
|
void
|
|
|
|
gimp_tool_info_set_standard (Gimp *gimp,
|
|
|
|
GimpToolInfo *tool_info)
|
2001-02-24 05:32:47 +08:00
|
|
|
{
|
2001-08-17 22:27:31 +08:00
|
|
|
g_return_if_fail (GIMP_IS_GIMP (gimp));
|
|
|
|
g_return_if_fail (! tool_info || GIMP_IS_TOOL_INFO (tool_info));
|
|
|
|
|
|
|
|
if (gimp->standard_tool_info)
|
|
|
|
{
|
|
|
|
g_object_unref (G_OBJECT (gimp->standard_tool_info));
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp->standard_tool_info = tool_info;
|
2001-02-24 05:32:47 +08:00
|
|
|
|
2001-08-17 22:27:31 +08:00
|
|
|
if (gimp->standard_tool_info)
|
2001-02-24 05:32:47 +08:00
|
|
|
{
|
2001-08-17 22:27:31 +08:00
|
|
|
g_object_ref (G_OBJECT (gimp->standard_tool_info));
|
2001-02-24 05:32:47 +08:00
|
|
|
}
|
2001-08-17 22:27:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GimpToolInfo *
|
|
|
|
gimp_tool_info_get_standard (Gimp *gimp)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
2001-02-24 05:32:47 +08:00
|
|
|
|
2001-08-17 22:27:31 +08:00
|
|
|
return gimp->standard_tool_info;
|
2001-02-24 05:32:47 +08:00
|
|
|
}
|