libgimp/Makefile.am libgimp/gimpui.h new file that holds pixbuf accessors

2004-04-21  Sven Neumann  <sven@gimp.org>

	* libgimp/Makefile.am
	* libgimp/gimpui.h
	* libgimp/gimppixbuf.[ch]: new file that holds pixbuf accessors
	to gimp data (drawable and image thumbnails for now).

	* libgimp/gimpdrawablecombobox.[ch]
	* libgimp/gimpimagecombobox.[ch]: new files with GimpIntComboBox
	constructors for image, drawable, channel and layer menus.

	* plug-ins/script-fu/script-fu-scripts.c: use the new functions
	instead of the gimpmenu API that is about to be deprecated.
This commit is contained in:
Sven Neumann 2004-04-20 22:14:49 +00:00 committed by Sven Neumann
parent ff06d05097
commit f4b2b3c146
13 changed files with 1007 additions and 50 deletions

View file

@ -1,3 +1,17 @@
2004-04-21 Sven Neumann <sven@gimp.org>
* libgimp/Makefile.am
* libgimp/gimpui.h
* libgimp/gimppixbuf.[ch]: new file that holds pixbuf accessors
to gimp data (drawable and image thumbnails for now).
* libgimp/gimpdrawablecombobox.[ch]
* libgimp/gimpimagecombobox.[ch]: new files with GimpIntComboBox
constructors for image, drawable, channel and layer menus.
* plug-ins/script-fu/script-fu-scripts.c: use the new functions
instead of the gimpmenu API that is about to be deprecated.
2004-04-20 Sven Neumann <sven@gimp.org>
* tools/pdbgen/pdb/fileops.pdb (file_load_thumbnail): removed

View file

@ -206,6 +206,12 @@ libgimpui_2_0_la_SOURCES = \
gimpgradientmenu.h \
gimppatternmenu.c \
gimppatternmenu.h \
gimpdrawablecombobox.c \
gimpdrawablecombobox.h \
gimpimagecombobox.c \
gimpimagecombobox.h \
gimppixbuf.c \
gimppixbuf.h \
gimpexport.c \
gimpexport.h
@ -230,14 +236,17 @@ gimpinclude_HEADERS = \
gimpselection.h \
gimptile.h \
\
gimpexport.h \
gimpui.h \
gimpuitypes.h \
gimpmenu.h \
gimpbrushmenu.h \
gimpfontmenu.h \
gimpgradientmenu.h \
gimppatternmenu.h
gimppatternmenu.h \
gimppixbuf.h \
gimpdrawablecombobox.h \
gimpimagecombobox.h \
gimpexport.h
libgimp_2_0_la_LDFLAGS = \
-version-info $(LT_VERSION_INFO) \

View file

@ -0,0 +1,243 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpdrawablecombobox.c
* Copyright (C) 2004 Sven Neumann <sven@gimp.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; 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>
#include "libgimpwidgets/gimpwidgets.h"
#include "gimp.h"
#include "gimpdrawablecombobox.h"
#include "gimppixbuf.h"
#include "libgimp-intl.h"
#define MENU_THUMBNAIL_SIZE 24
static gint gimp_drawable_combo_box_model_add (GtkListStore *store,
gint32 image,
gint num_drawables,
gint32 *drawables,
GimpDrawableConstraintFunc constraint,
gpointer data);
static void gimp_drawable_combo_box_model_add_none (GtkListStore *store);
GtkWidget *
gimp_drawable_combo_box_new (GimpDrawableConstraintFunc constraint,
gpointer data)
{
GtkWidget *combo_box;
GtkTreeModel *model;
GtkTreeIter iter;
gint32 *images;
gint num_images;
gint added = 0;
gint i;
combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL);
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
images = gimp_image_list (&num_images);
for (i = 0; i < num_images; i++)
{
gint32 *drawables;
gint num_drawables;
drawables = gimp_image_get_layers (images[i], &num_drawables);
added += gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
images[i],
num_drawables, drawables,
constraint, data);
g_free (drawables);
drawables = gimp_image_get_channels (images[i], &num_drawables);
added += gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
images[i],
num_drawables, drawables,
constraint, data);
g_free (drawables);
}
g_free (images);
if (! added)
gimp_drawable_combo_box_model_add_none (GTK_LIST_STORE (model));
if (gtk_tree_model_get_iter_first (model, &iter))
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
return combo_box;
}
GtkWidget *
gimp_channel_combo_box_new (GimpDrawableConstraintFunc constraint,
gpointer data)
{
GtkWidget *combo_box;
GtkTreeModel *model;
GtkTreeIter iter;
gint32 *images;
gint num_images;
gint added = 0;
gint i;
combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL);
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
images = gimp_image_list (&num_images);
for (i = 0; i < num_images; i++)
{
gint32 *drawables;
gint num_drawables;
drawables = gimp_image_get_channels (images[i], &num_drawables);
added += gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
images[i],
num_drawables, drawables,
constraint, data);
g_free (drawables);
}
g_free (images);
if (! added)
gimp_drawable_combo_box_model_add_none (GTK_LIST_STORE (model));
if (gtk_tree_model_get_iter_first (model, &iter))
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
return combo_box;
}
GtkWidget *
gimp_layer_combo_box_new (GimpDrawableConstraintFunc constraint,
gpointer data)
{
GtkWidget *combo_box;
GtkTreeModel *model;
GtkTreeIter iter;
gint32 *images;
gint num_images;
gint added = 0;
gint i;
combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL);
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
images = gimp_image_list (&num_images);
for (i = 0; i < num_images; i++)
{
gint32 *drawables;
gint num_drawables;
drawables = gimp_image_get_layers (images[i], &num_drawables);
added += gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
images[i],
num_drawables, drawables,
constraint, data);
g_free (drawables);
}
g_free (images);
if (! added)
gimp_drawable_combo_box_model_add_none (GTK_LIST_STORE (model));
if (gtk_tree_model_get_iter_first (model, &iter))
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
return combo_box;
}
static gint
gimp_drawable_combo_box_model_add (GtkListStore *store,
gint32 image,
gint num_drawables,
gint32 *drawables,
GimpDrawableConstraintFunc constraint,
gpointer data)
{
GtkTreeIter iter;
gint added = 0;
gint i;
for (i = 0; i < num_drawables; i++)
{
if (! constraint || (* constraint) (image, drawables[i], data))
{
gchar *image_name = gimp_image_get_name (image);
gchar *drawable_name = gimp_drawable_get_name (drawables[i]);
gchar *label;
GdkPixbuf *thumb;
label = g_strdup_printf ("%s-%d/%s-%d",
image_name, image,
drawable_name, drawables[i]);
g_free (drawable_name);
g_free (image_name);
thumb = gimp_drawable_get_thumbnail (drawables[i],
MENU_THUMBNAIL_SIZE,
MENU_THUMBNAIL_SIZE,
GIMP_PIXBUF_SMALL_CHECKS);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
GIMP_INT_STORE_VALUE, drawables[i],
GIMP_INT_STORE_LABEL, label,
GIMP_INT_STORE_PIXBUF, thumb,
-1);
added++;
if (thumb)
g_object_unref (thumb);
g_free (label);
}
}
return added;
}
static void
gimp_drawable_combo_box_model_add_none (GtkListStore *store)
{
GtkTreeIter iter;
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
GIMP_INT_STORE_VALUE, -1,
GIMP_INT_STORE_LABEL, _("(None)"),
-1);
}

View file

@ -0,0 +1,47 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpdrawablecombobox.h
* Copyright (C) 2004 Sven Neumann <sven@gimp.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_DRAWABLE_COMBO_BOX_H__
#define __GIMP_DRAWABLE_COMBO_BOX_H__
G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
typedef gboolean (* GimpDrawableConstraintFunc) (gint32 image_id,
gint32 drawable_id,
gpointer data);
GtkWidget * gimp_drawable_combo_box_new (GimpDrawableConstraintFunc constraint,
gpointer data);
GtkWidget * gimp_channel_combo_box_new (GimpDrawableConstraintFunc constraint,
gpointer data);
GtkWidget * gimp_layer_combo_box_new (GimpDrawableConstraintFunc constraint,
gpointer data);
G_END_DECLS
#endif /* __GIMP_DRAWABLE_COMBO_BOX_H__ */

131
libgimp/gimpimagecombobox.c Normal file
View file

@ -0,0 +1,131 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpimagecombobox.c
* Copyright (C) 2004 Sven Neumann <sven@gimp.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; 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>
#include "libgimpwidgets/gimpwidgets.h"
#include "gimp.h"
#include "gimpimagecombobox.h"
#include "gimppixbuf.h"
#include "libgimp-intl.h"
#define MENU_THUMBNAIL_SIZE 24
static void gimp_image_combo_box_model_add (GtkListStore *store,
gint num_images,
gint32 *images,
GimpImageConstraintFunc constraint,
gpointer data);
static void gimp_image_combo_box_model_add_none (GtkListStore *store);
GtkWidget *
gimp_image_combo_box_new (GimpImageConstraintFunc constraint,
gpointer data)
{
GtkWidget *combo_box;
GtkTreeModel *model;
GtkTreeIter iter;
gint32 *images;
gint num_images;
combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL);
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
images = gimp_image_list (&num_images);
if (num_images > 0)
gimp_image_combo_box_model_add (GTK_LIST_STORE (model),
num_images, images,
constraint, data);
else
gimp_image_combo_box_model_add_none (GTK_LIST_STORE (model));
g_free (images);
if (gtk_tree_model_get_iter_first (model, &iter))
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
return combo_box;
}
static void
gimp_image_combo_box_model_add (GtkListStore *store,
gint num_images,
gint32 *images,
GimpImageConstraintFunc constraint,
gpointer data)
{
GtkTreeIter iter;
gint i;
for (i = 0; i < num_images; i++)
{
if (! constraint || (* constraint) (images[i], data))
{
gchar *image_name = gimp_image_get_name (images[i]);
gchar *label;
GdkPixbuf *thumb;
label = g_strdup_printf ("%s-%d", image_name, images[i]);
g_free (image_name);
thumb = gimp_image_get_thumbnail (images[i],
MENU_THUMBNAIL_SIZE,
MENU_THUMBNAIL_SIZE,
GIMP_PIXBUF_SMALL_CHECKS);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
GIMP_INT_STORE_VALUE, images[i],
GIMP_INT_STORE_LABEL, label,
GIMP_INT_STORE_PIXBUF, thumb,
-1);
if (thumb)
g_object_unref (thumb);
g_free (label);
}
}
}
static void
gimp_image_combo_box_model_add_none (GtkListStore *store)
{
GtkTreeIter iter;
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
GIMP_INT_STORE_VALUE, -1,
GIMP_INT_STORE_LABEL, _("(None)"),
-1);
}

View file

@ -0,0 +1,42 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpimagecombobox.h
* Copyright (C) 2004 Sven Neumann <sven@gimp.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_IMAGE_COMBO_BOX_H__
#define __GIMP_IMAGE_COMBO_BOX_H__
G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
typedef gboolean (* GimpImageConstraintFunc) (gint32 image_id,
gpointer data);
GtkWidget * gimp_image_combo_box_new (GimpImageConstraintFunc constraint,
gpointer data);
G_END_DECLS
#endif /* __GIMP_DRAWABLE_COMBO_BOX_H__ */

243
libgimp/gimpitemcombobox.c Normal file
View file

@ -0,0 +1,243 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpdrawablecombobox.c
* Copyright (C) 2004 Sven Neumann <sven@gimp.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; 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>
#include "libgimpwidgets/gimpwidgets.h"
#include "gimp.h"
#include "gimpdrawablecombobox.h"
#include "gimppixbuf.h"
#include "libgimp-intl.h"
#define MENU_THUMBNAIL_SIZE 24
static gint gimp_drawable_combo_box_model_add (GtkListStore *store,
gint32 image,
gint num_drawables,
gint32 *drawables,
GimpDrawableConstraintFunc constraint,
gpointer data);
static void gimp_drawable_combo_box_model_add_none (GtkListStore *store);
GtkWidget *
gimp_drawable_combo_box_new (GimpDrawableConstraintFunc constraint,
gpointer data)
{
GtkWidget *combo_box;
GtkTreeModel *model;
GtkTreeIter iter;
gint32 *images;
gint num_images;
gint added = 0;
gint i;
combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL);
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
images = gimp_image_list (&num_images);
for (i = 0; i < num_images; i++)
{
gint32 *drawables;
gint num_drawables;
drawables = gimp_image_get_layers (images[i], &num_drawables);
added += gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
images[i],
num_drawables, drawables,
constraint, data);
g_free (drawables);
drawables = gimp_image_get_channels (images[i], &num_drawables);
added += gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
images[i],
num_drawables, drawables,
constraint, data);
g_free (drawables);
}
g_free (images);
if (! added)
gimp_drawable_combo_box_model_add_none (GTK_LIST_STORE (model));
if (gtk_tree_model_get_iter_first (model, &iter))
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
return combo_box;
}
GtkWidget *
gimp_channel_combo_box_new (GimpDrawableConstraintFunc constraint,
gpointer data)
{
GtkWidget *combo_box;
GtkTreeModel *model;
GtkTreeIter iter;
gint32 *images;
gint num_images;
gint added = 0;
gint i;
combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL);
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
images = gimp_image_list (&num_images);
for (i = 0; i < num_images; i++)
{
gint32 *drawables;
gint num_drawables;
drawables = gimp_image_get_channels (images[i], &num_drawables);
added += gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
images[i],
num_drawables, drawables,
constraint, data);
g_free (drawables);
}
g_free (images);
if (! added)
gimp_drawable_combo_box_model_add_none (GTK_LIST_STORE (model));
if (gtk_tree_model_get_iter_first (model, &iter))
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
return combo_box;
}
GtkWidget *
gimp_layer_combo_box_new (GimpDrawableConstraintFunc constraint,
gpointer data)
{
GtkWidget *combo_box;
GtkTreeModel *model;
GtkTreeIter iter;
gint32 *images;
gint num_images;
gint added = 0;
gint i;
combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL);
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
images = gimp_image_list (&num_images);
for (i = 0; i < num_images; i++)
{
gint32 *drawables;
gint num_drawables;
drawables = gimp_image_get_layers (images[i], &num_drawables);
added += gimp_drawable_combo_box_model_add (GTK_LIST_STORE (model),
images[i],
num_drawables, drawables,
constraint, data);
g_free (drawables);
}
g_free (images);
if (! added)
gimp_drawable_combo_box_model_add_none (GTK_LIST_STORE (model));
if (gtk_tree_model_get_iter_first (model, &iter))
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
return combo_box;
}
static gint
gimp_drawable_combo_box_model_add (GtkListStore *store,
gint32 image,
gint num_drawables,
gint32 *drawables,
GimpDrawableConstraintFunc constraint,
gpointer data)
{
GtkTreeIter iter;
gint added = 0;
gint i;
for (i = 0; i < num_drawables; i++)
{
if (! constraint || (* constraint) (image, drawables[i], data))
{
gchar *image_name = gimp_image_get_name (image);
gchar *drawable_name = gimp_drawable_get_name (drawables[i]);
gchar *label;
GdkPixbuf *thumb;
label = g_strdup_printf ("%s-%d/%s-%d",
image_name, image,
drawable_name, drawables[i]);
g_free (drawable_name);
g_free (image_name);
thumb = gimp_drawable_get_thumbnail (drawables[i],
MENU_THUMBNAIL_SIZE,
MENU_THUMBNAIL_SIZE,
GIMP_PIXBUF_SMALL_CHECKS);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
GIMP_INT_STORE_VALUE, drawables[i],
GIMP_INT_STORE_LABEL, label,
GIMP_INT_STORE_PIXBUF, thumb,
-1);
added++;
if (thumb)
g_object_unref (thumb);
g_free (label);
}
}
return added;
}
static void
gimp_drawable_combo_box_model_add_none (GtkListStore *store)
{
GtkTreeIter iter;
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
GIMP_INT_STORE_VALUE, -1,
GIMP_INT_STORE_LABEL, _("(None)"),
-1);
}

View file

@ -0,0 +1,47 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpdrawablecombobox.h
* Copyright (C) 2004 Sven Neumann <sven@gimp.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_DRAWABLE_COMBO_BOX_H__
#define __GIMP_DRAWABLE_COMBO_BOX_H__
G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
typedef gboolean (* GimpDrawableConstraintFunc) (gint32 image_id,
gint32 drawable_id,
gpointer data);
GtkWidget * gimp_drawable_combo_box_new (GimpDrawableConstraintFunc constraint,
gpointer data);
GtkWidget * gimp_channel_combo_box_new (GimpDrawableConstraintFunc constraint,
gpointer data);
GtkWidget * gimp_layer_combo_box_new (GimpDrawableConstraintFunc constraint,
gpointer data);
G_END_DECLS
#endif /* __GIMP_DRAWABLE_COMBO_BOX_H__ */

143
libgimp/gimppixbuf.c Normal file
View file

@ -0,0 +1,143 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimppixbuf.c
* Copyright (C) 2004 Sven Neumann <sven@gimp.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "gimp.h"
#include "gimppixbuf.h"
static GdkPixbuf * gimp_pixbuf_from_data (guchar *data,
gint width,
gint height,
gint bpp,
GimpPixbufTransparency alpha);
GdkPixbuf *
gimp_image_get_thumbnail (gint32 image_ID,
gint width,
gint height,
GimpPixbufTransparency alpha)
{
gint thumb_width;
gint thumb_height;
gint thumb_bpp;
gint data_size;
guchar *data;
g_return_val_if_fail (width > 0 && width <= 256, NULL);
g_return_val_if_fail (height > 0 && height <= 256, NULL);
if (! _gimp_image_thumbnail (image_ID,
width, height,
&thumb_width, &thumb_height, &thumb_bpp,
&data_size, &data))
return NULL;
g_return_val_if_fail (data_size == (thumb_width * thumb_height * thumb_bpp),
NULL);
return gimp_pixbuf_from_data (data,
thumb_width, thumb_height, thumb_bpp,
alpha);
}
GdkPixbuf *
gimp_drawable_get_thumbnail (gint32 drawable_ID,
gint width,
gint height,
GimpPixbufTransparency alpha)
{
gint thumb_width;
gint thumb_height;
gint thumb_bpp;
gint data_size;
guchar *data;
g_return_val_if_fail (width > 0 && width <= 256, NULL);
g_return_val_if_fail (height > 0 && height <= 256, NULL);
if (! _gimp_drawable_thumbnail (drawable_ID,
width, height,
&thumb_width, &thumb_height, &thumb_bpp,
&data_size, &data))
return NULL;
g_return_val_if_fail (data_size == (thumb_width * thumb_height * thumb_bpp),
NULL);
return gimp_pixbuf_from_data (data,
thumb_width, thumb_height, thumb_bpp, alpha);
}
static GdkPixbuf *
gimp_pixbuf_from_data (guchar *data,
gint width,
gint height,
gint bpp,
GimpPixbufTransparency alpha)
{
GdkPixbuf *pixbuf;
g_return_val_if_fail (bpp == 3 || bpp == 4, NULL);
pixbuf = gdk_pixbuf_new_from_data (data,
GDK_COLORSPACE_RGB, (bpp == 4), 8,
width, height, width * bpp,
(GdkPixbufDestroyNotify) g_free, NULL);
if (bpp == 4)
{
GdkPixbuf *tmp;
gint check_size = 0;
switch (alpha)
{
case GIMP_PIXBUF_KEEP_ALPHA:
return pixbuf;
case GIMP_PIXBUF_SMALL_CHECKS:
check_size = GIMP_CHECK_SIZE_SM;
break;
case GIMP_PIXBUF_LARGE_CHECKS:
check_size = GIMP_CHECK_SIZE;
break;
}
tmp = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, width, height);
gdk_pixbuf_composite_color (pixbuf, tmp,
0, 0, width, height, 0, 0, 1.0, 1.0,
GDK_INTERP_NEAREST, 255,
0, 0, check_size, 0x66666666, 0x99999999);
g_object_unref (pixbuf);
pixbuf = tmp;
}
return pixbuf;
}

52
libgimp/gimppixbuf.h Normal file
View file

@ -0,0 +1,52 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimppixbuf.h
* Copyright (C) 2004 Sven Neumann <sven@gimp.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_PIXBUF_H__
#define __GIMP_PIXBUF_H__
G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
typedef enum
{
GIMP_PIXBUF_KEEP_ALPHA,
GIMP_PIXBUF_SMALL_CHECKS,
GIMP_PIXBUF_LARGE_CHECKS
} GimpPixbufTransparency;
GdkPixbuf * gimp_image_get_thumbnail (gint32 image_ID,
gint width,
gint height,
GimpPixbufTransparency alpha);
GdkPixbuf * gimp_drawable_get_thumbnail (gint32 drawable_ID,
gint width,
gint height,
GimpPixbufTransparency alpha);
G_END_DECLS
#endif /* __GIMP_PIXBUF_H__ */

View file

@ -32,6 +32,10 @@
#include <libgimp/gimpfontmenu.h>
#include <libgimp/gimpgradientmenu.h>
#include <libgimp/gimppatternmenu.h>
#include <libgimp/gimppixbuf.h>
#include <libgimp/gimpdrawablecombobox.h>
#include <libgimp/gimpimagecombobox.h>
G_BEGIN_DECLS

View file

@ -172,8 +172,6 @@ static void script_fu_ok (SFScript *script);
static void script_fu_reset (SFScript *script);
static void script_fu_about_callback (GtkWidget *widget,
SFScript *script);
static void script_fu_menu_callback (gint32 id,
gpointer data);
static void script_fu_file_entry_callback (GtkWidget *widget,
SFFilename *fil);
@ -1194,6 +1192,7 @@ script_fu_interface (SFScript *script)
gchar *label_text;
gfloat label_yalign = 0.5;
gboolean widget_leftalign = TRUE;
gint *ID_ptr = NULL;
/* we add a colon after the label;
some languages want an extra space here */
@ -1206,38 +1205,37 @@ script_fu_interface (SFScript *script)
case SF_DRAWABLE:
case SF_LAYER:
case SF_CHANNEL:
widget = gtk_option_menu_new ();
switch (script->arg_types[i])
{
case SF_IMAGE:
menu = gimp_image_menu_new (NULL, script_fu_menu_callback,
&script->arg_values[i].sfa_image,
script->arg_values[i].sfa_image);
widget = gimp_image_combo_box_new (NULL, NULL);
ID_ptr = &script->arg_values[i].sfa_image;
break;
case SF_DRAWABLE:
menu = gimp_drawable_menu_new (NULL, script_fu_menu_callback,
&script->arg_values[i].sfa_drawable,
script->arg_values[i].sfa_drawable);
break;
widget = gimp_drawable_combo_box_new (NULL, NULL);
ID_ptr = &script->arg_values[i].sfa_drawable;
break;
case SF_LAYER:
menu = gimp_layer_menu_new (NULL, script_fu_menu_callback,
&script->arg_values[i].sfa_layer,
script->arg_values[i].sfa_layer);
widget = gimp_layer_combo_box_new (NULL, NULL);
ID_ptr = &script->arg_values[i].sfa_layer;
break;
case SF_CHANNEL:
menu = gimp_channel_menu_new (NULL, script_fu_menu_callback,
&script->arg_values[i].sfa_channel,
script->arg_values[i].sfa_channel);
widget = gimp_channel_combo_box_new (NULL, NULL);
ID_ptr = &script->arg_values[i].sfa_channel;
break;
default:
menu = NULL;
break;
}
gtk_option_menu_set_menu (GTK_OPTION_MENU (widget), menu);
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (widget), *ID_ptr);
g_signal_connect (widget, "changed",
G_CALLBACK (gimp_int_combo_box_get_active),
ID_ptr);
break;
case SF_COLOR:
@ -1958,13 +1956,6 @@ script_fu_about_callback (GtkWidget *widget,
gtk_widget_show (sf_interface->about_dialog);
}
static void
script_fu_menu_callback (gint32 id,
gpointer data)
{
*((gint32 *) data) = id;
}
static void
script_fu_file_entry_callback (GtkWidget *widget,
SFFilename *file)

View file

@ -172,8 +172,6 @@ static void script_fu_ok (SFScript *script);
static void script_fu_reset (SFScript *script);
static void script_fu_about_callback (GtkWidget *widget,
SFScript *script);
static void script_fu_menu_callback (gint32 id,
gpointer data);
static void script_fu_file_entry_callback (GtkWidget *widget,
SFFilename *fil);
@ -1194,6 +1192,7 @@ script_fu_interface (SFScript *script)
gchar *label_text;
gfloat label_yalign = 0.5;
gboolean widget_leftalign = TRUE;
gint *ID_ptr = NULL;
/* we add a colon after the label;
some languages want an extra space here */
@ -1206,38 +1205,37 @@ script_fu_interface (SFScript *script)
case SF_DRAWABLE:
case SF_LAYER:
case SF_CHANNEL:
widget = gtk_option_menu_new ();
switch (script->arg_types[i])
{
case SF_IMAGE:
menu = gimp_image_menu_new (NULL, script_fu_menu_callback,
&script->arg_values[i].sfa_image,
script->arg_values[i].sfa_image);
widget = gimp_image_combo_box_new (NULL, NULL);
ID_ptr = &script->arg_values[i].sfa_image;
break;
case SF_DRAWABLE:
menu = gimp_drawable_menu_new (NULL, script_fu_menu_callback,
&script->arg_values[i].sfa_drawable,
script->arg_values[i].sfa_drawable);
break;
widget = gimp_drawable_combo_box_new (NULL, NULL);
ID_ptr = &script->arg_values[i].sfa_drawable;
break;
case SF_LAYER:
menu = gimp_layer_menu_new (NULL, script_fu_menu_callback,
&script->arg_values[i].sfa_layer,
script->arg_values[i].sfa_layer);
widget = gimp_layer_combo_box_new (NULL, NULL);
ID_ptr = &script->arg_values[i].sfa_layer;
break;
case SF_CHANNEL:
menu = gimp_channel_menu_new (NULL, script_fu_menu_callback,
&script->arg_values[i].sfa_channel,
script->arg_values[i].sfa_channel);
widget = gimp_channel_combo_box_new (NULL, NULL);
ID_ptr = &script->arg_values[i].sfa_channel;
break;
default:
menu = NULL;
break;
}
gtk_option_menu_set_menu (GTK_OPTION_MENU (widget), menu);
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (widget), *ID_ptr);
g_signal_connect (widget, "changed",
G_CALLBACK (gimp_int_combo_box_get_active),
ID_ptr);
break;
case SF_COLOR:
@ -1958,13 +1956,6 @@ script_fu_about_callback (GtkWidget *widget,
gtk_widget_show (sf_interface->about_dialog);
}
static void
script_fu_menu_callback (gint32 id,
gpointer data)
{
*((gint32 *) data) = id;
}
static void
script_fu_file_entry_callback (GtkWidget *widget,
SFFilename *file)