2001-01-22 05:29:31 +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-02-04 12:51:17 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
2001-01-22 05:29:31 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2001-01-25 06:36:18 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
2001-01-24 02:49:44 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
#include "gui-types.h"
|
2001-05-15 19:25:25 +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/gimpdatafactory.h"
|
2002-10-09 22:04:25 +08:00
|
|
|
#include "core/gimpgradient.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpimage.h"
|
|
|
|
#include "core/gimppalette.h"
|
|
|
|
#include "core/gimppalette-import.h"
|
|
|
|
|
2002-04-15 01:28:58 +08:00
|
|
|
#include "file/file-utils.h"
|
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
#include "widgets/gimpcontainermenuimpl.h"
|
2002-10-09 22:04:25 +08:00
|
|
|
#include "widgets/gimpdnd.h"
|
2001-12-18 07:41:01 +08:00
|
|
|
#include "widgets/gimppreview.h"
|
2002-10-09 22:04:25 +08:00
|
|
|
#include "widgets/gimpviewabledialog.h"
|
2001-12-18 07:41:01 +08:00
|
|
|
|
2001-04-18 05:43:29 +08:00
|
|
|
#include "gradient-select.h"
|
|
|
|
#include "palette-import-dialog.h"
|
|
|
|
|
2001-01-22 05:29:31 +08:00
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
#define IMPORT_PREVIEW_SIZE 80
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2001-05-10 06:34:59 +08:00
|
|
|
|
2001-01-22 05:29:31 +08:00
|
|
|
typedef enum
|
|
|
|
{
|
2001-12-18 07:41:01 +08:00
|
|
|
GRADIENT_IMPORT,
|
|
|
|
IMAGE_IMPORT
|
2001-01-22 05:29:31 +08:00
|
|
|
} ImportType;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct _ImportDialog ImportDialog;
|
|
|
|
|
|
|
|
struct _ImportDialog
|
|
|
|
{
|
2002-03-13 05:02:10 +08:00
|
|
|
GtkWidget *dialog;
|
|
|
|
|
2002-10-09 22:04:25 +08:00
|
|
|
ImportType import_type;
|
2002-03-13 05:02:10 +08:00
|
|
|
GimpContext *context;
|
2002-10-09 22:04:25 +08:00
|
|
|
GimpPalette *palette;
|
|
|
|
|
2002-03-13 05:02:10 +08:00
|
|
|
GradientSelect *gradient_select;
|
|
|
|
|
2002-10-09 22:04:25 +08:00
|
|
|
GtkWidget *gradient_menu;
|
2002-03-13 05:02:10 +08:00
|
|
|
GtkWidget *image_menu;
|
|
|
|
|
|
|
|
GtkWidget *entry;
|
2002-10-09 22:04:25 +08:00
|
|
|
GtkWidget *image_radio;
|
|
|
|
GtkWidget *gradient_radio;
|
2002-03-13 05:02:10 +08:00
|
|
|
GtkAdjustment *threshold;
|
2002-10-09 22:04:25 +08:00
|
|
|
GtkAdjustment *num_colors;
|
|
|
|
GtkAdjustment *columns;
|
|
|
|
|
|
|
|
GtkWidget *preview;
|
2001-01-22 05:29:31 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2002-10-09 22:04:25 +08:00
|
|
|
static ImportDialog * palette_import_dialog_new (Gimp *gimp);
|
|
|
|
static void palette_import_close_callback (GtkWidget *widget,
|
|
|
|
ImportDialog *import_dialog);
|
|
|
|
static void palette_import_import_callback (GtkWidget *widget,
|
|
|
|
ImportDialog *import_dialog);
|
|
|
|
static void palette_import_gradient_changed (GimpContext *context,
|
|
|
|
GimpGradient *gradient,
|
|
|
|
ImportDialog *import_dialog);
|
|
|
|
static void palette_import_image_changed (GimpContext *context,
|
|
|
|
GimpImage *gimage,
|
|
|
|
ImportDialog *import_dialog);
|
|
|
|
static void import_dialog_drop_callback (GtkWidget *widget,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer data);
|
|
|
|
static void palette_import_grad_callback (GtkWidget *widget,
|
|
|
|
ImportDialog *import_dialog);
|
|
|
|
static void palette_import_image_callback (GtkWidget *widget,
|
|
|
|
ImportDialog *import_dialog);
|
|
|
|
static void palette_import_columns_changed (GtkAdjustment *adjustment,
|
|
|
|
ImportDialog *import_dialog);
|
|
|
|
static void palette_import_image_add (GimpContainer *container,
|
|
|
|
GimpImage *gimage,
|
|
|
|
ImportDialog *import_dialog);
|
|
|
|
static void palette_import_image_remove (GimpContainer *container,
|
|
|
|
GimpImage *gimage,
|
|
|
|
ImportDialog *import_dialog);
|
|
|
|
static void palette_import_make_palette (ImportDialog *import_dialog);
|
|
|
|
|
|
|
|
|
|
|
|
static ImportDialog *the_import_dialog = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2002-10-09 22:04:25 +08:00
|
|
|
void
|
|
|
|
palette_import_dialog_show (Gimp *gimp)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_GIMP (gimp));
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2002-10-09 22:04:25 +08:00
|
|
|
if (! the_import_dialog)
|
|
|
|
the_import_dialog = palette_import_dialog_new (gimp);
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2002-10-09 22:04:25 +08:00
|
|
|
if (! GTK_WIDGET_VISIBLE (the_import_dialog->dialog))
|
|
|
|
{
|
|
|
|
gtk_widget_show (the_import_dialog->dialog);
|
|
|
|
}
|
|
|
|
else if (the_import_dialog->dialog->window)
|
|
|
|
{
|
|
|
|
gdk_window_raise (the_import_dialog->dialog->window);
|
|
|
|
}
|
|
|
|
}
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2002-10-09 22:04:25 +08:00
|
|
|
void
|
|
|
|
palette_import_dialog_destroy (void)
|
|
|
|
{
|
|
|
|
if (the_import_dialog)
|
|
|
|
palette_import_close_callback (NULL, the_import_dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
/* the palette import dialog constructor ***********************************/
|
|
|
|
|
|
|
|
static ImportDialog *
|
|
|
|
palette_import_dialog_new (Gimp *gimp)
|
2001-01-22 05:29:31 +08:00
|
|
|
{
|
2001-10-29 19:47:11 +08:00
|
|
|
ImportDialog *import_dialog;
|
2002-03-13 05:02:10 +08:00
|
|
|
GimpGradient *gradient;
|
2002-10-09 22:04:25 +08:00
|
|
|
GtkWidget *main_hbox;
|
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *table;
|
|
|
|
GtkWidget *abox;
|
|
|
|
GtkWidget *menu;
|
|
|
|
GSList *group;
|
2001-10-29 19:47:11 +08:00
|
|
|
|
2002-10-09 22:04:25 +08:00
|
|
|
gradient = gimp_context_get_gradient (gimp_get_user_context (gimp));
|
2001-10-29 19:47:11 +08:00
|
|
|
|
2002-10-09 22:04:25 +08:00
|
|
|
import_dialog = g_new0 (ImportDialog, 1);
|
|
|
|
|
|
|
|
import_dialog->import_type = GRADIENT_IMPORT;
|
|
|
|
import_dialog->context = gimp_context_new (gimp, "Palette Import",
|
|
|
|
gimp_get_user_context (gimp));
|
|
|
|
|
|
|
|
import_dialog->dialog =
|
|
|
|
gimp_viewable_dialog_new (NULL, _("Import Palette"), "import_palette",
|
|
|
|
GTK_STOCK_CONVERT,
|
|
|
|
_("Import a New Palette"),
|
|
|
|
gimp_standard_help_func,
|
|
|
|
"dialogs/palette_editor/import_palette.html",
|
|
|
|
|
|
|
|
GTK_STOCK_CANCEL, palette_import_close_callback,
|
|
|
|
import_dialog, NULL, NULL, FALSE, TRUE,
|
|
|
|
|
|
|
|
_("_Import"), palette_import_import_callback,
|
|
|
|
import_dialog, NULL, NULL, TRUE, FALSE,
|
|
|
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gimp_dnd_viewable_dest_add (import_dialog->dialog,
|
|
|
|
GIMP_TYPE_GRADIENT,
|
|
|
|
import_dialog_drop_callback,
|
|
|
|
import_dialog);
|
|
|
|
gimp_dnd_viewable_dest_add (import_dialog->dialog,
|
|
|
|
GIMP_TYPE_IMAGE,
|
|
|
|
import_dialog_drop_callback,
|
|
|
|
import_dialog);
|
|
|
|
|
|
|
|
main_hbox = gtk_hbox_new (FALSE, 4);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (main_hbox), 4);
|
|
|
|
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (import_dialog->dialog)->vbox),
|
|
|
|
main_hbox);
|
|
|
|
gtk_widget_show (main_hbox);
|
|
|
|
|
|
|
|
vbox = gtk_vbox_new (FALSE, 4);
|
|
|
|
gtk_box_pack_start (GTK_BOX (main_hbox), vbox, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (vbox);
|
|
|
|
|
|
|
|
|
|
|
|
/* The "Source" frame */
|
|
|
|
frame = gtk_frame_new (_("Select Source"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
|
|
|
table = gtk_table_new (2, 2, FALSE);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (table), 4);
|
|
|
|
gtk_table_set_col_spacings (GTK_TABLE (table), 4);
|
|
|
|
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), table);
|
|
|
|
gtk_widget_show (table);
|
|
|
|
|
|
|
|
import_dialog->gradient_radio =
|
|
|
|
gtk_radio_button_new_with_mnemonic (NULL, _("_Gradient"));
|
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), import_dialog->gradient_radio,
|
|
|
|
0, 1, 0, 1);
|
|
|
|
gtk_widget_show (import_dialog->gradient_radio);
|
|
|
|
|
|
|
|
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (import_dialog->gradient_radio));
|
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (import_dialog->gradient_radio), "toggled",
|
|
|
|
G_CALLBACK (palette_import_grad_callback),
|
|
|
|
import_dialog);
|
|
|
|
|
|
|
|
import_dialog->image_radio =
|
|
|
|
gtk_radio_button_new_with_mnemonic (group, _("I_mage"));
|
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), import_dialog->image_radio,
|
|
|
|
0, 1, 1, 2);
|
|
|
|
gtk_widget_show (import_dialog->image_radio);
|
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (import_dialog->image_radio), "toggled",
|
|
|
|
G_CALLBACK (palette_import_image_callback),
|
|
|
|
import_dialog);
|
|
|
|
|
|
|
|
gtk_widget_set_sensitive (import_dialog->image_radio,
|
|
|
|
gimp_container_num_children (gimp->images) > 0);
|
|
|
|
|
|
|
|
/* The gradient menu */
|
|
|
|
import_dialog->gradient_menu = gtk_option_menu_new ();
|
|
|
|
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
|
|
|
|
NULL, 1.0, 0.5,
|
|
|
|
import_dialog->gradient_menu, 1, FALSE);
|
|
|
|
|
|
|
|
menu = gimp_container_menu_new (gimp->gradient_factory->container,
|
|
|
|
import_dialog->context, 24);
|
|
|
|
gtk_option_menu_set_menu (GTK_OPTION_MENU (import_dialog->gradient_menu),
|
|
|
|
menu);
|
|
|
|
gtk_widget_show (menu);
|
|
|
|
|
|
|
|
/* The image menu */
|
|
|
|
import_dialog->image_menu = gtk_option_menu_new ();
|
|
|
|
gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
|
|
|
|
NULL, 1.0, 0.5,
|
|
|
|
import_dialog->image_menu, 1, FALSE);
|
|
|
|
|
|
|
|
menu = gimp_container_menu_new (gimp->images, import_dialog->context, 24);
|
|
|
|
gtk_option_menu_set_menu (GTK_OPTION_MENU (import_dialog->image_menu), menu);
|
|
|
|
gtk_widget_show (menu);
|
|
|
|
|
|
|
|
{
|
|
|
|
gint focus_line_width;
|
|
|
|
gint focus_padding;
|
|
|
|
gint ythickness;
|
|
|
|
gint ysize;
|
|
|
|
|
|
|
|
gtk_widget_style_get (import_dialog->gradient_menu,
|
|
|
|
"focus_line_width", &focus_line_width,
|
|
|
|
"focus_padding", &focus_padding,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
ythickness = import_dialog->gradient_menu->style->ythickness;
|
|
|
|
|
|
|
|
ysize = 24 + (2 * (1 /* CHILD_SPACING */ +
|
|
|
|
ythickness +
|
|
|
|
focus_padding +
|
|
|
|
focus_line_width));
|
|
|
|
|
|
|
|
gtk_widget_set_size_request (import_dialog->gradient_menu, -1, ysize);
|
|
|
|
gtk_widget_set_size_request (import_dialog->image_menu, -1, ysize);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* The "Import" frame */
|
|
|
|
frame = gtk_frame_new (_("Import Options"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
|
|
|
table = gtk_table_new (4, 3, FALSE);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (table), 4);
|
|
|
|
gtk_table_set_col_spacings (GTK_TABLE (table), 4);
|
|
|
|
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), table);
|
|
|
|
gtk_widget_show (table);
|
|
|
|
|
|
|
|
/* The source's name */
|
|
|
|
import_dialog->entry = gtk_entry_new ();
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (import_dialog->entry),
|
2002-10-10 22:50:54 +08:00
|
|
|
gradient ? GIMP_OBJECT (gradient)->name : _("New Import"));
|
2002-10-09 22:04:25 +08:00
|
|
|
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
|
|
|
|
_("Palette _Name:"), 1.0, 0.5,
|
|
|
|
import_dialog->entry, 2, FALSE);
|
|
|
|
|
|
|
|
/* The # of colors */
|
|
|
|
import_dialog->num_colors =
|
|
|
|
GTK_ADJUSTMENT (gimp_scale_entry_new (GTK_TABLE (table), 0, 1,
|
|
|
|
_("N_umber of Colors:"), -1, 5,
|
|
|
|
256, 2, 10000, 1, 10, 0,
|
|
|
|
TRUE, 0.0, 0.0,
|
|
|
|
NULL, NULL));
|
|
|
|
|
|
|
|
g_signal_connect_swapped (G_OBJECT (import_dialog->num_colors),
|
|
|
|
"value_changed",
|
|
|
|
G_CALLBACK (palette_import_make_palette),
|
|
|
|
import_dialog);
|
|
|
|
|
|
|
|
/* The columns */
|
|
|
|
import_dialog->columns =
|
|
|
|
GTK_ADJUSTMENT (gimp_scale_entry_new (GTK_TABLE (table), 0, 2,
|
|
|
|
_("C_olumns:"), -1, 5,
|
|
|
|
16, 0, 64, 1, 8, 0,
|
|
|
|
TRUE, 0.0, 0.0,
|
|
|
|
NULL, NULL));
|
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (import_dialog->columns), "value_changed",
|
|
|
|
G_CALLBACK (palette_import_columns_changed),
|
|
|
|
import_dialog);
|
2002-03-13 05:02:10 +08:00
|
|
|
|
2002-10-09 22:04:25 +08:00
|
|
|
/* The interval */
|
|
|
|
import_dialog->threshold =
|
|
|
|
GTK_ADJUSTMENT (gimp_scale_entry_new (GTK_TABLE (table), 0, 3,
|
|
|
|
_("I_nterval:"), -1, 5,
|
|
|
|
1, 1, 128, 1, 8, 0,
|
|
|
|
TRUE, 0.0, 0.0,
|
|
|
|
NULL, NULL));
|
|
|
|
gimp_scale_entry_set_sensitive (GTK_OBJECT (import_dialog->threshold), FALSE);
|
|
|
|
|
|
|
|
g_signal_connect_swapped (G_OBJECT (import_dialog->threshold), "value_changed",
|
|
|
|
G_CALLBACK (palette_import_make_palette),
|
|
|
|
import_dialog);
|
|
|
|
|
|
|
|
|
|
|
|
/* The "Preview" frame */
|
|
|
|
frame = gtk_frame_new (_("Preview"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (main_hbox), frame, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (frame);
|
2002-03-13 05:02:10 +08:00
|
|
|
|
2002-10-09 22:04:25 +08:00
|
|
|
abox = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (abox), 4);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), abox);
|
|
|
|
gtk_widget_show (abox);
|
|
|
|
|
|
|
|
import_dialog->preview = gimp_preview_new_by_type (GIMP_TYPE_PALETTE,
|
|
|
|
64, 1,
|
|
|
|
TRUE);
|
|
|
|
GIMP_PREVIEW (import_dialog->preview)->size = -1;
|
|
|
|
gimp_preview_set_size_full (GIMP_PREVIEW (import_dialog->preview),
|
|
|
|
192, 192, 1);
|
|
|
|
gtk_container_add (GTK_CONTAINER (abox), import_dialog->preview);
|
|
|
|
gtk_widget_show (import_dialog->preview);
|
|
|
|
|
|
|
|
/* keep the dialog up-to-date */
|
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (gimp->images), "add",
|
|
|
|
G_CALLBACK (palette_import_image_add),
|
|
|
|
import_dialog);
|
|
|
|
g_signal_connect (G_OBJECT (gimp->images), "remove",
|
|
|
|
G_CALLBACK (palette_import_image_remove),
|
|
|
|
import_dialog);
|
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (import_dialog->context), "gradient_changed",
|
|
|
|
G_CALLBACK (palette_import_gradient_changed),
|
|
|
|
import_dialog);
|
|
|
|
g_signal_connect (G_OBJECT (import_dialog->context), "image_changed",
|
|
|
|
G_CALLBACK (palette_import_image_changed),
|
|
|
|
import_dialog);
|
|
|
|
|
|
|
|
palette_import_make_palette (import_dialog);
|
|
|
|
|
|
|
|
return import_dialog;
|
2001-01-22 05:29:31 +08:00
|
|
|
}
|
|
|
|
|
2002-10-09 22:04:25 +08:00
|
|
|
|
|
|
|
/* the palette import action area callbacks ********************************/
|
|
|
|
|
2001-01-22 05:29:31 +08:00
|
|
|
static void
|
2002-10-09 22:04:25 +08:00
|
|
|
palette_import_close_callback (GtkWidget *widget,
|
|
|
|
ImportDialog *import_dialog)
|
2001-01-22 05:29:31 +08:00
|
|
|
{
|
2002-10-09 22:04:25 +08:00
|
|
|
Gimp *gimp;
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2002-10-09 22:04:25 +08:00
|
|
|
if (import_dialog->gradient_select)
|
|
|
|
gradient_select_free (import_dialog->gradient_select);
|
|
|
|
|
|
|
|
gimp = import_dialog->context->gimp;
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2002-10-09 22:04:25 +08:00
|
|
|
g_signal_handlers_disconnect_by_func (G_OBJECT (gimp->images),
|
|
|
|
palette_import_image_add,
|
|
|
|
import_dialog);
|
|
|
|
g_signal_handlers_disconnect_by_func (G_OBJECT (gimp->images),
|
|
|
|
palette_import_image_remove,
|
|
|
|
import_dialog);
|
|
|
|
|
|
|
|
g_object_unref (G_OBJECT (import_dialog->context));
|
|
|
|
|
|
|
|
if (import_dialog->palette)
|
|
|
|
g_object_unref (G_OBJECT (import_dialog->palette));
|
|
|
|
|
|
|
|
gtk_widget_destroy (import_dialog->dialog);
|
|
|
|
g_free (import_dialog);
|
|
|
|
|
|
|
|
the_import_dialog = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
palette_import_import_callback (GtkWidget *widget,
|
|
|
|
ImportDialog *import_dialog)
|
|
|
|
{
|
|
|
|
if (import_dialog->palette)
|
|
|
|
gimp_container_add (import_dialog->context->gimp->palette_factory->container,
|
|
|
|
GIMP_OBJECT (import_dialog->palette));
|
|
|
|
|
|
|
|
palette_import_close_callback (NULL, import_dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* functions to create & update the import dialog's gradient selection *****/
|
|
|
|
|
|
|
|
static void
|
|
|
|
palette_import_gradient_changed (GimpContext *context,
|
|
|
|
GimpGradient *gradient,
|
|
|
|
ImportDialog *import_dialog)
|
|
|
|
{
|
2001-12-18 07:41:01 +08:00
|
|
|
if (gradient && import_dialog->import_type == GRADIENT_IMPORT)
|
2001-01-22 05:29:31 +08:00
|
|
|
{
|
2001-02-11 03:35:29 +08:00
|
|
|
gtk_entry_set_text (GTK_ENTRY (import_dialog->entry),
|
|
|
|
GIMP_OBJECT (gradient)->name);
|
2002-10-09 22:04:25 +08:00
|
|
|
|
|
|
|
palette_import_make_palette (import_dialog);
|
2001-01-22 05:29:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-12-18 07:41:01 +08:00
|
|
|
palette_import_image_changed (GimpContext *context,
|
|
|
|
GimpImage *gimage,
|
2002-10-09 22:04:25 +08:00
|
|
|
ImportDialog *import_dialog)
|
2001-01-22 05:29:31 +08:00
|
|
|
{
|
2001-12-18 07:41:01 +08:00
|
|
|
if (gimage && import_dialog->import_type == IMAGE_IMPORT)
|
2001-01-22 05:29:31 +08:00
|
|
|
{
|
2001-12-18 07:41:01 +08:00
|
|
|
gchar *basename;
|
|
|
|
gchar *label;
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2002-04-15 01:28:58 +08:00
|
|
|
basename = file_utils_uri_to_utf8_basename (gimp_image_get_uri (gimage));
|
2001-12-18 07:41:01 +08:00
|
|
|
label = g_strdup_printf ("%s-%d", basename, gimp_image_get_ID (gimage));
|
|
|
|
g_free (basename);
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
gtk_entry_set_text (GTK_ENTRY (import_dialog->entry), label);
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
g_free (label);
|
2002-10-09 22:04:25 +08:00
|
|
|
|
|
|
|
palette_import_make_palette (import_dialog);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
import_dialog_drop_callback (GtkWidget *widget,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
ImportDialog *import_dialog;
|
|
|
|
|
|
|
|
import_dialog = (ImportDialog *) data;
|
|
|
|
|
|
|
|
gimp_context_set_by_type (import_dialog->context,
|
|
|
|
G_TYPE_FROM_INSTANCE (viewable),
|
|
|
|
GIMP_OBJECT (viewable));
|
|
|
|
|
|
|
|
if (GIMP_IS_GRADIENT (viewable) &&
|
|
|
|
import_dialog->import_type != GRADIENT_IMPORT)
|
|
|
|
{
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (import_dialog->gradient_radio),
|
|
|
|
TRUE);
|
|
|
|
}
|
|
|
|
else if (GIMP_IS_IMAGE (viewable) &&
|
|
|
|
import_dialog->import_type != IMAGE_IMPORT)
|
|
|
|
{
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (import_dialog->image_radio),
|
|
|
|
TRUE);
|
2001-01-22 05:29:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-09 22:04:25 +08:00
|
|
|
|
2001-01-22 05:29:31 +08:00
|
|
|
/* the import source menu item callbacks ***********************************/
|
|
|
|
|
|
|
|
static void
|
2002-10-09 22:04:25 +08:00
|
|
|
palette_import_grad_callback (GtkWidget *widget,
|
|
|
|
ImportDialog *import_dialog)
|
2001-01-22 05:29:31 +08:00
|
|
|
{
|
2001-12-18 07:41:01 +08:00
|
|
|
GimpGradient *gradient;
|
2001-10-29 19:47:11 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
gradient = gimp_context_get_gradient (import_dialog->context);
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
import_dialog->import_type = GRADIENT_IMPORT;
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2002-10-09 22:04:25 +08:00
|
|
|
gtk_widget_set_sensitive (import_dialog->image_menu, FALSE);
|
|
|
|
gtk_widget_set_sensitive (import_dialog->gradient_menu, TRUE);
|
2001-12-18 07:41:01 +08:00
|
|
|
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (import_dialog->entry),
|
|
|
|
GIMP_OBJECT (gradient)->name);
|
2002-10-09 22:04:25 +08:00
|
|
|
gimp_scale_entry_set_sensitive (GTK_OBJECT (import_dialog->threshold), FALSE);
|
|
|
|
|
|
|
|
palette_import_make_palette (import_dialog);
|
2001-01-22 05:29:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-10-09 22:04:25 +08:00
|
|
|
palette_import_image_callback (GtkWidget *widget,
|
|
|
|
ImportDialog *import_dialog)
|
2001-01-22 05:29:31 +08:00
|
|
|
{
|
2001-12-18 07:41:01 +08:00
|
|
|
GimpImage *gimage;
|
2001-10-29 19:47:11 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
gimage = gimp_context_get_image (import_dialog->context);
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
if (! gimage)
|
|
|
|
{
|
|
|
|
gimage = (GimpImage *)
|
2002-10-09 22:04:25 +08:00
|
|
|
gimp_container_get_child_by_index (import_dialog->context->gimp->images,
|
|
|
|
0);
|
2001-12-18 07:41:01 +08:00
|
|
|
}
|
2001-10-29 19:47:11 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
import_dialog->import_type = IMAGE_IMPORT;
|
2001-10-29 19:47:11 +08:00
|
|
|
|
2002-10-09 22:04:25 +08:00
|
|
|
gtk_widget_set_sensitive (import_dialog->gradient_menu, FALSE);
|
|
|
|
gtk_widget_set_sensitive (import_dialog->image_menu, TRUE);
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2002-10-09 22:04:25 +08:00
|
|
|
palette_import_image_changed (import_dialog->context, gimage, import_dialog);
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2002-10-09 22:04:25 +08:00
|
|
|
gimp_scale_entry_set_sensitive (GTK_OBJECT (import_dialog->threshold), TRUE);
|
2001-12-18 07:41:01 +08:00
|
|
|
}
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2002-10-09 22:04:25 +08:00
|
|
|
static void
|
|
|
|
palette_import_columns_changed (GtkAdjustment *adjustment,
|
|
|
|
ImportDialog *import_dialog)
|
|
|
|
{
|
|
|
|
if (import_dialog->palette)
|
|
|
|
gimp_palette_set_n_columns (import_dialog->palette,
|
|
|
|
ROUND (adjustment->value));
|
|
|
|
}
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
/* functions & callbacks to keep the import dialog uptodate ****************/
|
2001-01-22 05:29:31 +08:00
|
|
|
|
|
|
|
static void
|
2001-12-18 07:41:01 +08:00
|
|
|
palette_import_image_add (GimpContainer *container,
|
2001-02-04 06:05:41 +08:00
|
|
|
GimpImage *gimage,
|
2002-10-09 22:04:25 +08:00
|
|
|
ImportDialog *import_dialog)
|
2001-01-22 05:29:31 +08:00
|
|
|
{
|
2002-10-09 22:04:25 +08:00
|
|
|
if (! GTK_WIDGET_IS_SENSITIVE (import_dialog->image_radio))
|
2001-01-22 05:29:31 +08:00
|
|
|
{
|
2002-10-09 22:04:25 +08:00
|
|
|
gtk_widget_set_sensitive (import_dialog->image_radio, TRUE);
|
|
|
|
gimp_context_set_image (import_dialog->context, gimage);
|
2001-01-22 05:29:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-12-18 07:41:01 +08:00
|
|
|
palette_import_image_remove (GimpContainer *container,
|
|
|
|
GimpImage *gimage,
|
2002-10-09 22:04:25 +08:00
|
|
|
ImportDialog *import_dialog)
|
2001-01-22 05:29:31 +08:00
|
|
|
{
|
2001-12-18 07:41:01 +08:00
|
|
|
if (! gimp_container_num_children (import_dialog->context->gimp->images))
|
2001-01-22 05:29:31 +08:00
|
|
|
{
|
2002-10-09 22:04:25 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (import_dialog->gradient_radio),
|
|
|
|
TRUE);
|
|
|
|
gtk_widget_set_sensitive (import_dialog->image_radio, FALSE);
|
2001-01-22 05:29:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-10-09 22:04:25 +08:00
|
|
|
palette_import_make_palette (ImportDialog *import_dialog)
|
2001-01-22 05:29:31 +08:00
|
|
|
{
|
2001-02-20 02:07:08 +08:00
|
|
|
GimpPalette *palette = NULL;
|
|
|
|
gchar *palette_name;
|
|
|
|
GimpGradient *gradient;
|
2001-12-18 07:41:01 +08:00
|
|
|
GimpImage *gimage;
|
2001-02-20 02:07:08 +08:00
|
|
|
gint n_colors;
|
2002-10-09 22:04:25 +08:00
|
|
|
gint n_columns;
|
2001-02-20 02:07:08 +08:00
|
|
|
gint threshold;
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2001-07-25 08:42:47 +08:00
|
|
|
palette_name = (gchar *) gtk_entry_get_text (GTK_ENTRY (import_dialog->entry));
|
2001-02-20 02:07:08 +08:00
|
|
|
|
2002-10-09 22:04:25 +08:00
|
|
|
if (palette_name && strlen (palette_name))
|
2001-02-20 02:07:08 +08:00
|
|
|
palette_name = g_strdup (palette_name);
|
2002-10-09 22:04:25 +08:00
|
|
|
else
|
|
|
|
palette_name = g_strdup (_("Untitled"));
|
2001-02-20 02:07:08 +08:00
|
|
|
|
2001-12-18 07:41:01 +08:00
|
|
|
gradient = gimp_context_get_gradient (import_dialog->context);
|
|
|
|
gimage = gimp_context_get_image (import_dialog->context);
|
|
|
|
|
2002-10-09 22:04:25 +08:00
|
|
|
n_colors = ROUND (import_dialog->num_colors->value);
|
|
|
|
n_columns = ROUND (import_dialog->columns->value);
|
|
|
|
threshold = ROUND (import_dialog->threshold->value);
|
2001-01-22 05:29:31 +08:00
|
|
|
|
|
|
|
switch (import_dialog->import_type)
|
|
|
|
{
|
2001-12-18 07:41:01 +08:00
|
|
|
case GRADIENT_IMPORT:
|
2001-02-20 02:07:08 +08:00
|
|
|
palette = gimp_palette_import_from_gradient (gradient,
|
|
|
|
palette_name,
|
|
|
|
n_colors);
|
2001-01-22 05:29:31 +08:00
|
|
|
break;
|
2001-02-20 02:07:08 +08:00
|
|
|
|
2001-01-22 05:29:31 +08:00
|
|
|
case IMAGE_IMPORT:
|
2001-12-18 07:41:01 +08:00
|
|
|
if (gimp_image_base_type (gimage) == GIMP_INDEXED)
|
2002-10-09 22:04:25 +08:00
|
|
|
{
|
|
|
|
palette =
|
|
|
|
gimp_palette_import_from_indexed_image (gimage,
|
|
|
|
palette_name);
|
|
|
|
}
|
|
|
|
else
|
2001-12-18 07:41:01 +08:00
|
|
|
{
|
|
|
|
palette = gimp_palette_import_from_image (gimage,
|
|
|
|
palette_name,
|
|
|
|
n_colors,
|
|
|
|
threshold);
|
|
|
|
}
|
2001-01-22 05:29:31 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-02-20 02:07:08 +08:00
|
|
|
g_free (palette_name);
|
|
|
|
|
|
|
|
if (palette)
|
2002-10-09 22:04:25 +08:00
|
|
|
{
|
|
|
|
if (import_dialog->palette)
|
|
|
|
g_object_unref (G_OBJECT (import_dialog->palette));
|
2001-10-29 19:47:11 +08:00
|
|
|
|
2002-10-09 22:04:25 +08:00
|
|
|
palette->n_columns = n_columns;
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2002-10-09 22:04:25 +08:00
|
|
|
gimp_preview_set_viewable (GIMP_PREVIEW (import_dialog->preview),
|
|
|
|
GIMP_VIEWABLE (palette));
|
2001-01-22 05:29:31 +08:00
|
|
|
|
2002-10-09 22:04:25 +08:00
|
|
|
import_dialog->palette = palette;
|
2001-01-22 05:29:31 +08:00
|
|
|
}
|
|
|
|
}
|