2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2000-12-17 05:37:03 +08:00
|
|
|
* 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"
|
|
|
|
|
2002-01-30 22:54:27 +08:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#warning GTK_DISABLE_DEPRECATED
|
|
|
|
#endif
|
|
|
|
#undef GTK_DISABLE_DEPRECATED
|
|
|
|
|
2000-12-17 05:37:03 +08:00
|
|
|
#include <gtk/gtk.h>
|
2001-01-08 07:59:46 +08:00
|
|
|
#include <gdk/gdkkeysyms.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-01-24 02:49:44 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
2001-01-24 07:56:18 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
2001-01-25 06:36:18 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
2001-01-24 02:49:44 +08:00
|
|
|
|
2002-03-17 01:58:19 +08:00
|
|
|
#include "widgets-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2003-03-04 22:35:56 +08:00
|
|
|
#include "core/gimp.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpcontainer.h"
|
2003-03-04 22:35:56 +08:00
|
|
|
#include "core/gimpcontext.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpimage.h"
|
2003-03-18 21:49:02 +08:00
|
|
|
#include "core/gimpimage-colormap.h"
|
2001-11-23 07:46:13 +08:00
|
|
|
#include "core/gimpmarshal.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
|
2002-03-17 01:58:19 +08:00
|
|
|
#include "gimpcolormapeditor.h"
|
|
|
|
#include "gimpdnd.h"
|
2005-07-20 04:42:14 +08:00
|
|
|
#include "gimprender.h"
|
2003-01-11 01:55:53 +08:00
|
|
|
#include "gimpmenufactory.h"
|
2004-10-25 02:32:24 +08:00
|
|
|
#include "gimpuimanager.h"
|
2001-05-09 03:29:15 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2001-01-08 07:59:46 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* Add these features:
|
|
|
|
*
|
|
|
|
* load/save colormaps
|
|
|
|
* requantize
|
|
|
|
* add color--by clicking in the checked region
|
|
|
|
* all changes need to flush colormap lookup cache
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
SELECTED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2006-05-29 03:45:52 +08:00
|
|
|
#define EPSILON 1e-10
|
2001-01-08 07:59:46 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
#define HAVE_COLORMAP(image) \
|
|
|
|
(image != NULL && \
|
|
|
|
gimp_image_base_type (image) == GIMP_INDEXED && \
|
|
|
|
gimp_image_get_colormap (image) != NULL)
|
2004-02-12 20:13:21 +08:00
|
|
|
|
|
|
|
|
2004-05-13 23:50:55 +08:00
|
|
|
static GObject * gimp_colormap_editor_constructor (GType type,
|
|
|
|
guint n_params,
|
|
|
|
GObjectConstructParam *params);
|
|
|
|
|
2002-03-17 21:52:25 +08:00
|
|
|
static void gimp_colormap_editor_destroy (GtkObject *object);
|
|
|
|
static void gimp_colormap_editor_unmap (GtkWidget *widget);
|
|
|
|
|
2003-02-20 23:40:15 +08:00
|
|
|
static void gimp_colormap_editor_set_image (GimpImageEditor *editor,
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image);
|
2003-02-20 23:40:15 +08:00
|
|
|
|
2002-03-17 21:52:25 +08:00
|
|
|
static void gimp_colormap_editor_draw (GimpColormapEditor *editor);
|
|
|
|
static void gimp_colormap_editor_draw_cell (GimpColormapEditor *editor,
|
|
|
|
gint col);
|
|
|
|
static void gimp_colormap_editor_clear (GimpColormapEditor *editor,
|
|
|
|
gint start_row);
|
|
|
|
static void gimp_colormap_editor_update_entries (GimpColormapEditor *editor);
|
|
|
|
|
|
|
|
static void gimp_colormap_preview_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation,
|
|
|
|
GimpColormapEditor *editor);
|
|
|
|
static gboolean
|
|
|
|
gimp_colormap_preview_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *bevent,
|
|
|
|
GimpColormapEditor *editor);
|
|
|
|
static void gimp_colormap_preview_drag_color (GtkWidget *widget,
|
|
|
|
GimpRGB *color,
|
|
|
|
gpointer data);
|
|
|
|
static void gimp_colormap_preview_drop_color (GtkWidget *widget,
|
2004-12-31 22:36:30 +08:00
|
|
|
gint x,
|
|
|
|
gint y,
|
2002-03-17 21:52:25 +08:00
|
|
|
const GimpRGB *color,
|
|
|
|
gpointer data);
|
|
|
|
|
|
|
|
static void gimp_colormap_adjustment_changed (GtkAdjustment *adjustment,
|
|
|
|
GimpColormapEditor *editor);
|
2005-03-24 23:29:48 +08:00
|
|
|
static void gimp_colormap_hex_entry_changed (GimpColorHexEntry *entry,
|
2002-03-17 21:52:25 +08:00
|
|
|
GimpColormapEditor *editor);
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
static void gimp_colormap_image_mode_changed (GimpImage *image,
|
2002-03-17 21:52:25 +08:00
|
|
|
GimpColormapEditor *editor);
|
2006-03-29 01:08:36 +08:00
|
|
|
static void gimp_colormap_image_colormap_changed (GimpImage *image,
|
2002-03-17 21:52:25 +08:00
|
|
|
gint ncol,
|
|
|
|
GimpColormapEditor *editor);
|
|
|
|
|
|
|
|
|
2005-12-20 06:37:49 +08:00
|
|
|
G_DEFINE_TYPE (GimpColormapEditor, gimp_colormap_editor,
|
2006-05-15 17:46:31 +08:00
|
|
|
GIMP_TYPE_IMAGE_EDITOR)
|
2001-01-08 07:59:46 +08:00
|
|
|
|
2005-12-20 06:37:49 +08:00
|
|
|
#define parent_class gimp_colormap_editor_parent_class
|
2001-01-08 07:59:46 +08:00
|
|
|
|
2005-12-20 06:37:49 +08:00
|
|
|
static guint editor_signals[LAST_SIGNAL] = { 0 };
|
2001-01-08 07:59:46 +08:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
2002-03-17 01:58:19 +08:00
|
|
|
gimp_colormap_editor_class_init (GimpColormapEditorClass* klass)
|
2001-01-08 07:59:46 +08:00
|
|
|
{
|
2004-05-13 23:50:55 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
GimpImageEditorClass *image_editor_class = GIMP_IMAGE_EDITOR_CLASS (klass);
|
2002-03-17 21:52:25 +08:00
|
|
|
|
|
|
|
editor_signals[SELECTED] =
|
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
|
|
|
g_signal_new ("selected",
|
2004-09-25 19:25:49 +08:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpColormapEditorClass, selected),
|
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__FLAGS,
|
|
|
|
G_TYPE_NONE, 1,
|
2003-09-26 21:33:54 +08:00
|
|
|
GDK_TYPE_MODIFIER_TYPE);
|
2001-01-08 07:59:46 +08:00
|
|
|
|
2004-05-13 23:50:55 +08:00
|
|
|
object_class->constructor = gimp_colormap_editor_constructor;
|
|
|
|
|
|
|
|
gtk_object_class->destroy = gimp_colormap_editor_destroy;
|
2003-02-20 23:40:15 +08:00
|
|
|
|
|
|
|
widget_class->unmap = gimp_colormap_editor_unmap;
|
2002-03-17 21:52:25 +08:00
|
|
|
|
2003-02-20 23:40:15 +08:00
|
|
|
image_editor_class->set_image = gimp_colormap_editor_set_image;
|
2002-03-17 21:52:25 +08:00
|
|
|
|
2003-09-26 21:33:54 +08:00
|
|
|
klass->selected = NULL;
|
2001-01-08 07:59:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-09-19 19:40:12 +08:00
|
|
|
gimp_colormap_editor_init (GimpColormapEditor *editor)
|
2001-01-08 07:59:46 +08:00
|
|
|
{
|
2004-09-25 19:25:49 +08:00
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *table;
|
2007-04-12 22:48:04 +08:00
|
|
|
GtkObject *adj;
|
2004-09-25 19:25:49 +08:00
|
|
|
|
|
|
|
editor->col_index = 0;
|
|
|
|
editor->dnd_col_index = 0;
|
|
|
|
editor->xn = 0;
|
|
|
|
editor->yn = 0;
|
|
|
|
editor->cellsize = 0;
|
|
|
|
|
|
|
|
/* The palette frame */
|
|
|
|
frame = gtk_frame_new (NULL);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
|
|
|
|
gtk_box_pack_start (GTK_BOX (editor), frame, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2005-07-20 03:37:07 +08:00
|
|
|
editor->preview = gtk_preview_new (GTK_PREVIEW_COLOR);
|
|
|
|
gtk_widget_set_size_request (editor->preview, -1, 60);
|
|
|
|
gtk_preview_set_expand (GTK_PREVIEW (editor->preview), TRUE);
|
|
|
|
gtk_widget_add_events (editor->preview, GDK_BUTTON_PRESS_MASK);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), editor->preview);
|
|
|
|
gtk_widget_show (editor->preview);
|
|
|
|
|
|
|
|
g_signal_connect_after (editor->preview, "size-allocate",
|
2004-09-25 19:25:49 +08:00
|
|
|
G_CALLBACK (gimp_colormap_preview_size_allocate),
|
|
|
|
editor);
|
|
|
|
|
2005-07-20 03:37:07 +08:00
|
|
|
g_signal_connect (editor->preview, "button-press-event",
|
2004-09-25 19:25:49 +08:00
|
|
|
G_CALLBACK (gimp_colormap_preview_button_press),
|
|
|
|
editor);
|
|
|
|
|
2005-07-20 03:37:07 +08:00
|
|
|
gimp_dnd_color_source_add (editor->preview, gimp_colormap_preview_drag_color,
|
2004-09-25 19:25:49 +08:00
|
|
|
editor);
|
2005-07-20 03:37:07 +08:00
|
|
|
gimp_dnd_color_dest_add (editor->preview, gimp_colormap_preview_drop_color,
|
2004-09-25 19:25:49 +08:00
|
|
|
editor);
|
|
|
|
|
|
|
|
/* Some helpful hints */
|
|
|
|
table = gtk_table_new (2, 2, FALSE);
|
|
|
|
gtk_table_set_col_spacing (GTK_TABLE (table), 0, 4);
|
|
|
|
gtk_table_set_row_spacing (GTK_TABLE (table), 0, 2);
|
|
|
|
gtk_box_pack_end (GTK_BOX (editor), table, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (table);
|
|
|
|
|
2007-04-12 22:48:04 +08:00
|
|
|
editor->index_spinbutton = gimp_spin_button_new (&adj,
|
|
|
|
0, 0, 0, 1, 10, 10, 1.0, 0);
|
|
|
|
editor->index_adjustment = GTK_ADJUSTMENT (adj);
|
2004-09-25 19:25:49 +08:00
|
|
|
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
|
|
|
|
_("Color index:"), 0.0, 0.5,
|
|
|
|
editor->index_spinbutton, 1, TRUE);
|
|
|
|
|
2005-05-28 00:51:39 +08:00
|
|
|
g_signal_connect (editor->index_adjustment, "value-changed",
|
2004-09-25 19:25:49 +08:00
|
|
|
G_CALLBACK (gimp_colormap_adjustment_changed),
|
|
|
|
editor);
|
|
|
|
|
2005-03-24 23:29:48 +08:00
|
|
|
editor->color_entry = gimp_color_hex_entry_new ();
|
|
|
|
gtk_entry_set_width_chars (GTK_ENTRY (editor->color_entry), 12);
|
2004-09-25 19:25:49 +08:00
|
|
|
gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
|
2004-10-22 23:41:03 +08:00
|
|
|
_("HTML notation:"), 0.0, 0.5,
|
2004-09-25 19:25:49 +08:00
|
|
|
editor->color_entry, 1, TRUE);
|
|
|
|
|
2005-05-28 00:51:39 +08:00
|
|
|
g_signal_connect (editor->color_entry, "color-changed",
|
2005-03-24 23:29:48 +08:00
|
|
|
G_CALLBACK (gimp_colormap_hex_entry_changed),
|
2004-09-25 19:25:49 +08:00
|
|
|
editor);
|
2004-05-13 23:50:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static GObject *
|
|
|
|
gimp_colormap_editor_constructor (GType type,
|
|
|
|
guint n_params,
|
|
|
|
GObjectConstructParam *params)
|
|
|
|
{
|
|
|
|
GObject *object;
|
|
|
|
GimpColormapEditor *editor;
|
|
|
|
|
|
|
|
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
|
|
|
|
|
|
|
|
editor = GIMP_COLORMAP_EDITOR (object);
|
2003-09-19 19:40:12 +08:00
|
|
|
|
|
|
|
editor->edit_button =
|
2006-11-18 06:07:07 +08:00
|
|
|
gimp_editor_add_action_button (GIMP_EDITOR (editor), "colormap",
|
|
|
|
"colormap-edit-color",
|
2004-10-25 02:32:24 +08:00
|
|
|
NULL);
|
2003-09-19 19:40:12 +08:00
|
|
|
|
|
|
|
editor->add_button =
|
2006-11-18 06:07:07 +08:00
|
|
|
gimp_editor_add_action_button (GIMP_EDITOR (editor), "colormap",
|
|
|
|
"colormap-add-color-from-fg",
|
|
|
|
"colormap-add-color-from-bg",
|
2004-05-13 23:50:55 +08:00
|
|
|
GDK_CONTROL_MASK,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
return object;
|
2001-01-08 07:59:46 +08:00
|
|
|
}
|
|
|
|
|
2002-03-17 21:52:25 +08:00
|
|
|
static void
|
|
|
|
gimp_colormap_editor_destroy (GtkObject *object)
|
|
|
|
{
|
2003-12-01 20:58:03 +08:00
|
|
|
GimpColormapEditor *editor = GIMP_COLORMAP_EDITOR (object);
|
2002-03-17 21:52:25 +08:00
|
|
|
|
2004-09-13 23:15:23 +08:00
|
|
|
if (editor->color_dialog)
|
2002-03-17 21:52:25 +08:00
|
|
|
{
|
2004-09-24 04:41:40 +08:00
|
|
|
gtk_widget_destroy (editor->color_dialog);
|
2004-09-13 23:15:23 +08:00
|
|
|
editor->color_dialog = NULL;
|
2002-03-17 21:52:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GTK_OBJECT_CLASS (parent_class)->destroy (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_colormap_editor_unmap (GtkWidget *widget)
|
|
|
|
{
|
2003-12-01 20:58:03 +08:00
|
|
|
GimpColormapEditor *editor = GIMP_COLORMAP_EDITOR (widget);
|
2002-03-17 21:52:25 +08:00
|
|
|
|
2004-09-13 23:15:23 +08:00
|
|
|
if (editor->color_dialog)
|
2004-09-24 04:41:40 +08:00
|
|
|
gtk_widget_hide (editor->color_dialog);
|
2002-03-17 21:52:25 +08:00
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (parent_class)->unmap (widget);
|
|
|
|
}
|
|
|
|
|
2003-02-20 23:40:15 +08:00
|
|
|
static void
|
|
|
|
gimp_colormap_editor_set_image (GimpImageEditor *image_editor,
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image)
|
2003-02-20 23:40:15 +08:00
|
|
|
{
|
2003-12-01 20:58:03 +08:00
|
|
|
GimpColormapEditor *editor = GIMP_COLORMAP_EDITOR (image_editor);
|
2003-02-20 23:40:15 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
if (image_editor->image)
|
2003-02-20 23:40:15 +08:00
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
g_signal_handlers_disconnect_by_func (image_editor->image,
|
2004-09-25 19:25:49 +08:00
|
|
|
gimp_colormap_image_mode_changed,
|
|
|
|
editor);
|
2006-03-29 01:08:36 +08:00
|
|
|
g_signal_handlers_disconnect_by_func (image_editor->image,
|
2004-09-25 19:25:49 +08:00
|
|
|
gimp_colormap_image_colormap_changed,
|
|
|
|
editor);
|
2003-02-20 23:40:15 +08:00
|
|
|
|
2004-09-13 23:15:23 +08:00
|
|
|
if (editor->color_dialog)
|
2004-09-24 04:41:40 +08:00
|
|
|
gtk_widget_hide (editor->color_dialog);
|
2003-02-20 23:40:15 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
if (! HAVE_COLORMAP (image))
|
2004-09-25 19:25:49 +08:00
|
|
|
{
|
|
|
|
editor->index_adjustment->upper = 0;
|
|
|
|
gtk_adjustment_changed (editor->index_adjustment);
|
2003-02-20 23:40:15 +08:00
|
|
|
|
2004-09-25 19:25:49 +08:00
|
|
|
if (GTK_WIDGET_MAPPED (GTK_WIDGET (editor)))
|
|
|
|
gimp_colormap_editor_clear (editor, -1);
|
|
|
|
}
|
2003-02-20 23:40:15 +08:00
|
|
|
}
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
GIMP_IMAGE_EDITOR_CLASS (parent_class)->set_image (image_editor, image);
|
2003-02-20 23:40:15 +08:00
|
|
|
|
|
|
|
editor->col_index = 0;
|
|
|
|
editor->dnd_col_index = 0;
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
if (image)
|
2003-02-20 23:40:15 +08:00
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
g_signal_connect (image, "mode-changed",
|
2004-09-25 19:25:49 +08:00
|
|
|
G_CALLBACK (gimp_colormap_image_mode_changed),
|
|
|
|
editor);
|
2006-03-29 01:08:36 +08:00
|
|
|
g_signal_connect (image, "colormap-changed",
|
2004-09-25 19:25:49 +08:00
|
|
|
G_CALLBACK (gimp_colormap_image_colormap_changed),
|
|
|
|
editor);
|
2003-02-20 23:40:15 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
if (HAVE_COLORMAP (image))
|
2004-09-25 19:25:49 +08:00
|
|
|
{
|
|
|
|
gimp_colormap_editor_draw (editor);
|
2003-02-20 23:40:15 +08:00
|
|
|
|
2004-09-25 19:25:49 +08:00
|
|
|
editor->index_adjustment->upper =
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_get_colormap_size (image) - 1;
|
2003-03-18 21:49:02 +08:00
|
|
|
|
2004-09-25 19:25:49 +08:00
|
|
|
gtk_adjustment_changed (editor->index_adjustment);
|
|
|
|
}
|
2003-02-20 23:40:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gimp_colormap_editor_update_entries (editor);
|
|
|
|
}
|
|
|
|
|
2002-03-17 21:52:25 +08:00
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2001-07-15 22:32:44 +08:00
|
|
|
GtkWidget *
|
2004-09-25 20:48:41 +08:00
|
|
|
gimp_colormap_editor_new (GimpMenuFactory *menu_factory)
|
2001-01-08 07:59:46 +08:00
|
|
|
{
|
2003-01-11 01:55:53 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_MENU_FACTORY (menu_factory), NULL);
|
2001-01-08 07:59:46 +08:00
|
|
|
|
2004-09-25 20:48:41 +08:00
|
|
|
return g_object_new (GIMP_TYPE_COLORMAP_EDITOR,
|
|
|
|
"menu-factory", menu_factory,
|
2006-11-18 06:07:07 +08:00
|
|
|
"menu-identifier", "<Colormap>",
|
|
|
|
"ui-path", "/colormap-popup",
|
2004-09-25 20:48:41 +08:00
|
|
|
NULL);
|
2001-01-08 07:59:46 +08:00
|
|
|
}
|
|
|
|
|
2006-05-29 03:45:52 +08:00
|
|
|
gint
|
|
|
|
gimp_colormap_editor_get_index (GimpColormapEditor *editor,
|
|
|
|
const GimpRGB *search)
|
2001-01-08 07:59:46 +08:00
|
|
|
{
|
2006-05-29 03:45:52 +08:00
|
|
|
GimpImage *image;
|
|
|
|
gint index;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_COLORMAP_EDITOR (editor), 01);
|
|
|
|
|
|
|
|
image = GIMP_IMAGE_EDITOR (editor)->image;
|
|
|
|
|
|
|
|
if (! HAVE_COLORMAP (image))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
index = editor->col_index;
|
|
|
|
|
|
|
|
if (search)
|
|
|
|
{
|
|
|
|
GimpRGB temp;
|
|
|
|
|
|
|
|
gimp_image_get_colormap_entry (image, index, &temp);
|
|
|
|
|
|
|
|
if (gimp_rgb_distance (&temp, search) > EPSILON)
|
|
|
|
{
|
|
|
|
gint n_colors = gimp_image_get_colormap_size (image);
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < n_colors; i++)
|
|
|
|
{
|
|
|
|
gimp_image_get_colormap_entry (image, i, &temp);
|
|
|
|
|
|
|
|
if (gimp_rgb_distance (&temp, search) < EPSILON)
|
|
|
|
{
|
|
|
|
index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gimp_colormap_editor_set_index (GimpColormapEditor *editor,
|
|
|
|
gint index,
|
|
|
|
GimpRGB *color)
|
|
|
|
{
|
|
|
|
GimpImage *image;
|
2007-07-18 00:32:18 +08:00
|
|
|
gint size;
|
2006-05-29 03:45:52 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_COLORMAP_EDITOR (editor), FALSE);
|
|
|
|
|
|
|
|
image = GIMP_IMAGE_EDITOR (editor)->image;
|
|
|
|
|
|
|
|
if (! HAVE_COLORMAP (image))
|
|
|
|
return FALSE;
|
|
|
|
|
2007-07-18 00:32:18 +08:00
|
|
|
size = gimp_image_get_colormap_size (image);
|
|
|
|
|
|
|
|
if (size < 1)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
index = CLAMP (index, 0, size - 1);
|
2006-05-29 03:45:52 +08:00
|
|
|
|
|
|
|
if (index != editor->col_index)
|
|
|
|
{
|
|
|
|
gint old = editor->col_index;
|
|
|
|
|
|
|
|
editor->col_index = index;
|
|
|
|
editor->dnd_col_index = index;
|
|
|
|
|
|
|
|
gimp_colormap_editor_draw_cell (editor, old);
|
|
|
|
gimp_colormap_editor_draw_cell (editor, index);
|
|
|
|
|
|
|
|
gimp_colormap_editor_update_entries (editor);
|
|
|
|
}
|
2001-01-08 07:59:46 +08:00
|
|
|
|
2006-05-29 03:45:52 +08:00
|
|
|
if (color)
|
|
|
|
gimp_image_get_colormap_entry (GIMP_IMAGE_EDITOR (editor)->image,
|
|
|
|
index, color);
|
|
|
|
|
|
|
|
return TRUE;
|
2001-01-08 07:59:46 +08:00
|
|
|
}
|
|
|
|
|
2001-07-15 22:32:44 +08:00
|
|
|
gint
|
2006-05-29 03:45:52 +08:00
|
|
|
gimp_colormap_editor_max_index (GimpColormapEditor *editor)
|
2001-07-15 22:32:44 +08:00
|
|
|
{
|
2006-05-29 03:45:52 +08:00
|
|
|
GimpImage *image;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_COLORMAP_EDITOR (editor), -1);
|
|
|
|
|
|
|
|
image = GIMP_IMAGE_EDITOR (editor)->image;
|
2001-01-15 09:48:53 +08:00
|
|
|
|
2006-05-29 03:45:52 +08:00
|
|
|
if (! HAVE_COLORMAP (image))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return MAX (0, gimp_image_get_colormap_size (image) - 1);
|
2001-01-08 07:59:46 +08:00
|
|
|
}
|
|
|
|
|
2001-07-15 22:32:44 +08:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
2001-01-08 07:59:46 +08:00
|
|
|
#define MIN_CELL_SIZE 4
|
|
|
|
|
|
|
|
static void
|
2002-03-17 21:52:25 +08:00
|
|
|
gimp_colormap_editor_draw (GimpColormapEditor *editor)
|
2001-01-08 07:59:46 +08:00
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image = GIMP_IMAGE_EDITOR (editor)->image;
|
2001-07-15 22:32:44 +08:00
|
|
|
gint i, j, k, l, b;
|
|
|
|
gint col;
|
|
|
|
guchar *row;
|
|
|
|
gint cellsize, ncol, xn, yn, width, height;
|
2001-01-08 07:59:46 +08:00
|
|
|
|
2005-07-20 03:37:07 +08:00
|
|
|
width = editor->preview->allocation.width;
|
|
|
|
height = editor->preview->allocation.height;
|
2006-03-29 01:08:36 +08:00
|
|
|
ncol = gimp_image_get_colormap_size (image);
|
2001-01-08 07:59:46 +08:00
|
|
|
|
2001-07-15 22:32:44 +08:00
|
|
|
if (! ncol)
|
2001-01-08 07:59:46 +08:00
|
|
|
{
|
2002-03-17 21:52:25 +08:00
|
|
|
gimp_colormap_editor_clear (editor, -1);
|
2001-01-08 07:59:46 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-07-15 22:32:44 +08:00
|
|
|
cellsize = sqrt (width * height / ncol);
|
2001-01-08 07:59:46 +08:00
|
|
|
while (cellsize >= MIN_CELL_SIZE
|
2004-09-25 19:25:49 +08:00
|
|
|
&& (xn = width / cellsize) * (yn = height / cellsize) < ncol)
|
2001-01-08 07:59:46 +08:00
|
|
|
cellsize--;
|
|
|
|
|
|
|
|
if (cellsize < MIN_CELL_SIZE)
|
|
|
|
{
|
|
|
|
cellsize = MIN_CELL_SIZE;
|
|
|
|
xn = yn = ceil (sqrt (ncol));
|
|
|
|
}
|
|
|
|
|
2007-07-18 00:32:18 +08:00
|
|
|
yn = ((ncol + xn - 1) / xn);
|
2001-07-15 22:32:44 +08:00
|
|
|
|
2002-05-11 21:25:45 +08:00
|
|
|
/* We used to render just multiples of "cellsize" here, but the
|
|
|
|
* colormap as dockable looks better if it always fills the
|
|
|
|
* available allocation->width (which should always be larger than
|
2007-07-18 00:32:18 +08:00
|
|
|
* "xn * cellsize"). Defensively, we use MAX (width, xn * cellsize)
|
2002-05-11 21:25:45 +08:00
|
|
|
* below --Mitch
|
2007-07-18 00:32:18 +08:00
|
|
|
*/
|
2001-07-15 22:32:44 +08:00
|
|
|
|
2002-03-17 01:58:19 +08:00
|
|
|
editor->xn = xn;
|
|
|
|
editor->yn = yn;
|
|
|
|
editor->cellsize = cellsize;
|
2001-01-08 07:59:46 +08:00
|
|
|
|
2002-05-11 21:25:45 +08:00
|
|
|
row = g_new (guchar, MAX (width, xn * cellsize) * 3);
|
2001-01-08 07:59:46 +08:00
|
|
|
col = 0;
|
|
|
|
for (i = 0; i < yn; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < xn && col < ncol; j++, col++)
|
2004-09-25 19:25:49 +08:00
|
|
|
{
|
|
|
|
for (k = 0; k < cellsize; k++)
|
|
|
|
for (b = 0; b < 3; b++)
|
2006-03-29 01:08:36 +08:00
|
|
|
row[(j * cellsize + k) * 3 + b] = image->cmap[col * 3 + b];
|
2004-09-25 19:25:49 +08:00
|
|
|
}
|
2001-01-08 07:59:46 +08:00
|
|
|
|
|
|
|
for (k = 0; k < cellsize; k++)
|
2004-09-25 19:25:49 +08:00
|
|
|
{
|
|
|
|
for (l = j * cellsize; l < width; l++)
|
|
|
|
for (b = 0; b < 3; b++)
|
|
|
|
row[l * 3 + b] = (((((i * cellsize + k) & 0x4) ?
|
|
|
|
(l) :
|
|
|
|
(l + 0x4)) & 0x4) ?
|
2007-12-13 22:54:23 +08:00
|
|
|
gimp_render_light_check : gimp_render_dark_check);
|
2004-09-25 19:25:49 +08:00
|
|
|
|
2005-07-20 03:37:07 +08:00
|
|
|
gtk_preview_draw_row (GTK_PREVIEW (editor->preview), row, 0,
|
2004-09-25 19:25:49 +08:00
|
|
|
i * cellsize + k,
|
|
|
|
width);
|
|
|
|
}
|
2001-01-08 07:59:46 +08:00
|
|
|
}
|
2001-07-15 22:32:44 +08:00
|
|
|
|
2002-03-17 21:52:25 +08:00
|
|
|
gimp_colormap_editor_clear (editor, yn * cellsize);
|
2001-07-15 22:32:44 +08:00
|
|
|
|
2002-03-17 21:52:25 +08:00
|
|
|
gimp_colormap_editor_draw_cell (editor, editor->col_index);
|
2001-01-08 07:59:46 +08:00
|
|
|
|
|
|
|
g_free (row);
|
2005-07-20 03:37:07 +08:00
|
|
|
gtk_widget_queue_draw (editor->preview);
|
2001-01-08 07:59:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-03-17 21:52:25 +08:00
|
|
|
gimp_colormap_editor_draw_cell (GimpColormapEditor *editor,
|
|
|
|
gint col)
|
2001-01-08 07:59:46 +08:00
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image = GIMP_IMAGE_EDITOR (editor)->image;
|
2005-12-29 08:11:09 +08:00
|
|
|
gint cellsize = editor->cellsize;
|
|
|
|
guchar *row = g_alloca (cellsize * 3);
|
|
|
|
gint x, y, k;
|
2001-07-15 22:32:44 +08:00
|
|
|
|
2007-07-18 00:32:18 +08:00
|
|
|
if (! editor->xn)
|
|
|
|
return;
|
|
|
|
|
2002-03-17 01:58:19 +08:00
|
|
|
x = (col % editor->xn) * cellsize;
|
|
|
|
y = (col / editor->xn) * cellsize;
|
2001-01-08 07:59:46 +08:00
|
|
|
|
2002-03-17 01:58:19 +08:00
|
|
|
if (col == editor->col_index)
|
2001-01-08 07:59:46 +08:00
|
|
|
{
|
2007-07-18 00:32:18 +08:00
|
|
|
for (k = 0; k < cellsize; k++)
|
2004-09-25 19:25:49 +08:00
|
|
|
row[k*3] = row[k*3+1] = row[k*3+2] = (k & 1) * 255;
|
2007-07-18 00:32:18 +08:00
|
|
|
|
2005-07-20 03:37:07 +08:00
|
|
|
gtk_preview_draw_row (GTK_PREVIEW (editor->preview), row, x, y, cellsize);
|
2001-01-08 07:59:46 +08:00
|
|
|
|
|
|
|
if (!(cellsize & 1))
|
2004-09-25 19:25:49 +08:00
|
|
|
for (k = 0; k < cellsize; k++)
|
|
|
|
row[k*3] = row[k*3+1] = row[k*3+2] = ((x+y+1) & 1) * 255;
|
2007-07-18 00:32:18 +08:00
|
|
|
|
2005-07-20 03:37:07 +08:00
|
|
|
gtk_preview_draw_row (GTK_PREVIEW (editor->preview), row,
|
2004-09-25 19:25:49 +08:00
|
|
|
x, y+cellsize-1, cellsize);
|
2001-01-08 07:59:46 +08:00
|
|
|
|
2007-07-18 00:32:18 +08:00
|
|
|
row[0] = row[1] = row[2] = 255;
|
|
|
|
row[cellsize*3-3] = row[cellsize*3-2] = row[cellsize*3-1] = 255 * (cellsize & 1);
|
|
|
|
|
2001-01-08 07:59:46 +08:00
|
|
|
for (k = 1; k < cellsize - 1; k++)
|
2004-09-25 19:25:49 +08:00
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
row[k*3] = image->cmap[col * 3];
|
|
|
|
row[k*3+1] = image->cmap[col * 3 + 1];
|
|
|
|
row[k*3+2] = image->cmap[col * 3 + 2];
|
2004-09-25 19:25:49 +08:00
|
|
|
}
|
2001-01-08 07:59:46 +08:00
|
|
|
for (k = 1; k < cellsize - 1; k+=2)
|
2005-07-20 03:37:07 +08:00
|
|
|
gtk_preview_draw_row (GTK_PREVIEW (editor->preview), row,
|
2004-09-25 19:25:49 +08:00
|
|
|
x, y+k, cellsize);
|
2001-01-08 07:59:46 +08:00
|
|
|
|
|
|
|
row[0] = row[1] = row[2] = 0;
|
|
|
|
row[cellsize*3-3] = row[cellsize*3-2] = row[cellsize*3-1]
|
2004-09-25 19:25:49 +08:00
|
|
|
= 255 * ((cellsize+1) & 1);
|
2001-01-08 07:59:46 +08:00
|
|
|
for (k = 2; k < cellsize - 1; k += 2)
|
2005-07-20 03:37:07 +08:00
|
|
|
gtk_preview_draw_row (GTK_PREVIEW (editor->preview), row,
|
2004-09-25 19:25:49 +08:00
|
|
|
x, y+k, cellsize);
|
2001-01-08 07:59:46 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (k = 0; k < cellsize; k++)
|
2004-09-25 19:25:49 +08:00
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
row[k*3] = image->cmap[col * 3];
|
|
|
|
row[k*3+1] = image->cmap[col * 3 + 1];
|
|
|
|
row[k*3+2] = image->cmap[col * 3 + 2];
|
2004-09-25 19:25:49 +08:00
|
|
|
}
|
2001-01-08 07:59:46 +08:00
|
|
|
for (k = 0; k < cellsize; k++)
|
2005-07-20 03:37:07 +08:00
|
|
|
gtk_preview_draw_row (GTK_PREVIEW (editor->preview), row,
|
2004-09-25 19:25:49 +08:00
|
|
|
x, y+k, cellsize);
|
2001-01-08 07:59:46 +08:00
|
|
|
}
|
2001-12-29 21:26:29 +08:00
|
|
|
|
2005-07-20 03:37:07 +08:00
|
|
|
gtk_widget_queue_draw_area (editor->preview,
|
2001-12-29 21:26:29 +08:00
|
|
|
x, y,
|
|
|
|
cellsize, cellsize);
|
2001-01-08 07:59:46 +08:00
|
|
|
}
|
2002-03-17 21:52:25 +08:00
|
|
|
|
2001-01-08 07:59:46 +08:00
|
|
|
static void
|
2002-03-17 21:52:25 +08:00
|
|
|
gimp_colormap_editor_clear (GimpColormapEditor *editor,
|
|
|
|
gint start_row)
|
2001-01-08 07:59:46 +08:00
|
|
|
{
|
2005-07-20 03:37:07 +08:00
|
|
|
gint i, j;
|
|
|
|
gint offset;
|
|
|
|
gint width, height;
|
2005-12-29 08:11:09 +08:00
|
|
|
guchar *row;
|
2001-01-08 07:59:46 +08:00
|
|
|
|
2005-07-20 03:37:07 +08:00
|
|
|
width = editor->preview->allocation.width;
|
|
|
|
height = editor->preview->allocation.height;
|
2001-07-15 22:32:44 +08:00
|
|
|
|
|
|
|
if (start_row < 0)
|
|
|
|
start_row = 0;
|
|
|
|
|
|
|
|
if (start_row >= height)
|
|
|
|
return;
|
|
|
|
|
2005-12-29 08:11:09 +08:00
|
|
|
row = g_alloca (width * 3);
|
2001-01-08 07:59:46 +08:00
|
|
|
|
2001-07-15 22:32:44 +08:00
|
|
|
if (start_row & 0x3)
|
|
|
|
{
|
|
|
|
offset = (start_row & 0x4) ? 0x4 : 0x0;
|
2001-01-08 07:59:46 +08:00
|
|
|
|
2001-07-15 22:32:44 +08:00
|
|
|
for (j = 0; j < width; j++)
|
2004-09-25 19:25:49 +08:00
|
|
|
{
|
|
|
|
row[j * 3 + 0] = row[j * 3 + 1] = row[j * 3 + 2] =
|
|
|
|
((j + offset) & 0x4) ?
|
2007-12-13 22:54:23 +08:00
|
|
|
gimp_render_dark_check : gimp_render_light_check;
|
2004-09-25 19:25:49 +08:00
|
|
|
}
|
2001-07-15 22:32:44 +08:00
|
|
|
|
|
|
|
for (j = 0; j < (4 - (start_row & 0x3)) && start_row + j < height; j++)
|
2005-07-20 03:37:07 +08:00
|
|
|
gtk_preview_draw_row (GTK_PREVIEW (editor->preview), row,
|
2004-09-25 19:25:49 +08:00
|
|
|
0, start_row + j, width);
|
2001-07-15 22:32:44 +08:00
|
|
|
|
|
|
|
start_row += (4 - (start_row & 0x3));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = start_row; i < height; i += 4)
|
2001-01-08 07:59:46 +08:00
|
|
|
{
|
|
|
|
offset = (i & 0x4) ? 0x4 : 0x0;
|
|
|
|
|
|
|
|
for (j = 0; j < width; j++)
|
2004-09-25 19:25:49 +08:00
|
|
|
{
|
|
|
|
row[j * 3 + 0] = row[j * 3 + 1] = row[j * 3 + 2] =
|
|
|
|
((j + offset) & 0x4) ?
|
2005-07-20 04:42:14 +08:00
|
|
|
gimp_render_blend_dark_check[0] : gimp_render_blend_light_check[0];
|
2004-09-25 19:25:49 +08:00
|
|
|
}
|
2001-01-08 07:59:46 +08:00
|
|
|
|
2001-07-15 22:32:44 +08:00
|
|
|
for (j = 0; j < 4 && i + j < height; j++)
|
2005-07-20 03:37:07 +08:00
|
|
|
gtk_preview_draw_row (GTK_PREVIEW (editor->preview), row,
|
2004-09-25 19:25:49 +08:00
|
|
|
0, i + j, width);
|
2001-01-08 07:59:46 +08:00
|
|
|
}
|
2001-07-15 22:32:44 +08:00
|
|
|
|
2005-07-20 03:37:07 +08:00
|
|
|
gtk_widget_queue_draw (editor->preview);
|
2001-01-08 07:59:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-03-17 21:52:25 +08:00
|
|
|
gimp_colormap_editor_update_entries (GimpColormapEditor *editor)
|
2001-01-08 07:59:46 +08:00
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image = GIMP_IMAGE_EDITOR (editor)->image;
|
2003-02-20 23:40:15 +08:00
|
|
|
|
2007-07-18 00:32:18 +08:00
|
|
|
if (! HAVE_COLORMAP (image) ||
|
|
|
|
! gimp_image_get_colormap_size (image))
|
2001-01-08 07:59:46 +08:00
|
|
|
{
|
2002-03-17 01:58:19 +08:00
|
|
|
gtk_widget_set_sensitive (editor->index_spinbutton, FALSE);
|
|
|
|
gtk_widget_set_sensitive (editor->color_entry, FALSE);
|
2001-07-15 22:32:44 +08:00
|
|
|
|
2002-03-17 01:58:19 +08:00
|
|
|
gtk_adjustment_set_value (editor->index_adjustment, 0);
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (editor->color_entry), "");
|
2001-01-08 07:59:46 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-07-15 22:32:44 +08:00
|
|
|
gchar *string;
|
2001-01-08 07:59:46 +08:00
|
|
|
guchar *col;
|
|
|
|
|
2002-03-17 01:58:19 +08:00
|
|
|
gtk_adjustment_set_value (editor->index_adjustment, editor->col_index);
|
2001-01-08 07:59:46 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
col = image->cmap + editor->col_index * 3;
|
2001-07-15 22:32:44 +08:00
|
|
|
|
2003-09-19 20:05:28 +08:00
|
|
|
string = g_strdup_printf ("%02x%02x%02x", col[0], col[1], col[2]);
|
2002-03-17 01:58:19 +08:00
|
|
|
gtk_entry_set_text (GTK_ENTRY (editor->color_entry), string);
|
2001-01-08 07:59:46 +08:00
|
|
|
g_free (string);
|
2001-07-15 22:32:44 +08:00
|
|
|
|
2002-03-17 01:58:19 +08:00
|
|
|
gtk_widget_set_sensitive (editor->index_spinbutton, TRUE);
|
|
|
|
gtk_widget_set_sensitive (editor->color_entry, TRUE);
|
2001-01-08 07:59:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-03-17 21:52:25 +08:00
|
|
|
gimp_colormap_preview_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *alloc,
|
|
|
|
GimpColormapEditor *editor)
|
2001-01-08 07:59:46 +08:00
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image = GIMP_IMAGE_EDITOR (editor)->image;
|
2003-02-20 23:40:15 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
if (HAVE_COLORMAP (image))
|
2002-03-17 21:52:25 +08:00
|
|
|
gimp_colormap_editor_draw (editor);
|
|
|
|
else
|
|
|
|
gimp_colormap_editor_clear (editor, -1);
|
2001-01-08 07:59:46 +08:00
|
|
|
}
|
|
|
|
|
2002-03-17 21:52:25 +08:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_colormap_preview_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *bevent,
|
|
|
|
GimpColormapEditor *editor)
|
2001-01-08 07:59:46 +08:00
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image = GIMP_IMAGE_EDITOR (editor)->image;
|
2002-03-17 21:52:25 +08:00
|
|
|
guint col;
|
2001-01-08 07:59:46 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
if (! HAVE_COLORMAP (image))
|
2002-03-17 21:52:25 +08:00
|
|
|
return TRUE;
|
2001-01-08 07:59:46 +08:00
|
|
|
|
2002-03-17 21:52:25 +08:00
|
|
|
if (!(bevent->y < editor->cellsize * editor->yn
|
2004-09-25 19:25:49 +08:00
|
|
|
&& bevent->x < editor->cellsize * editor->xn))
|
2002-03-17 21:52:25 +08:00
|
|
|
return TRUE;
|
2001-01-08 07:59:46 +08:00
|
|
|
|
2002-03-17 21:52:25 +08:00
|
|
|
col = (editor->xn * ((gint) bevent->y / editor->cellsize) +
|
|
|
|
((gint) bevent->x / editor->cellsize));
|
2001-01-08 07:59:46 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
if (col >= gimp_image_get_colormap_size (image))
|
2002-03-17 21:52:25 +08:00
|
|
|
return TRUE;
|
2001-01-08 07:59:46 +08:00
|
|
|
|
2002-03-17 21:52:25 +08:00
|
|
|
switch (bevent->button)
|
2001-01-08 07:59:46 +08:00
|
|
|
{
|
2002-03-17 21:52:25 +08:00
|
|
|
case 1:
|
2006-05-29 03:45:52 +08:00
|
|
|
gimp_colormap_editor_set_index (editor, col, NULL);
|
|
|
|
g_signal_emit (editor, editor_signals[SELECTED], 0, bevent->state);
|
2003-09-19 19:40:12 +08:00
|
|
|
|
|
|
|
if (bevent->type == GDK_2BUTTON_PRESS)
|
2006-12-15 20:03:47 +08:00
|
|
|
gimp_ui_manager_activate_action (GIMP_EDITOR (editor)->ui_manager,
|
|
|
|
"colormap",
|
|
|
|
"colormap-edit-color");
|
2003-09-19 19:40:12 +08:00
|
|
|
return TRUE;
|
2001-01-08 07:59:46 +08:00
|
|
|
|
2002-03-17 21:52:25 +08:00
|
|
|
case 2:
|
|
|
|
editor->dnd_col_index = col;
|
|
|
|
break;
|
2001-01-08 07:59:46 +08:00
|
|
|
|
2002-03-17 21:52:25 +08:00
|
|
|
case 3:
|
2006-05-29 03:45:52 +08:00
|
|
|
gimp_colormap_editor_set_index (editor, col, NULL);
|
2004-05-17 21:38:03 +08:00
|
|
|
gimp_editor_popup_menu (GIMP_EDITOR (editor), NULL, NULL);
|
2002-06-01 05:50:52 +08:00
|
|
|
return TRUE;
|
2001-01-08 07:59:46 +08:00
|
|
|
|
2002-03-17 21:52:25 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2001-01-08 07:59:46 +08:00
|
|
|
|
2002-06-01 05:50:52 +08:00
|
|
|
return FALSE;
|
2002-03-17 21:52:25 +08:00
|
|
|
}
|
2002-03-19 03:34:06 +08:00
|
|
|
|
2001-01-08 07:59:46 +08:00
|
|
|
static void
|
2002-03-17 21:52:25 +08:00
|
|
|
gimp_colormap_preview_drag_color (GtkWidget *widget,
|
|
|
|
GimpRGB *color,
|
|
|
|
gpointer data)
|
2001-01-08 07:59:46 +08:00
|
|
|
{
|
2005-12-29 08:11:09 +08:00
|
|
|
GimpColormapEditor *editor = GIMP_COLORMAP_EDITOR (data);
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image = GIMP_IMAGE_EDITOR (editor)->image;
|
2001-01-08 07:59:46 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
if (HAVE_COLORMAP (image))
|
|
|
|
gimp_image_get_colormap_entry (image, editor->dnd_col_index, color);
|
2001-01-08 07:59:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-03-17 21:52:25 +08:00
|
|
|
gimp_colormap_preview_drop_color (GtkWidget *widget,
|
2004-12-31 22:36:30 +08:00
|
|
|
gint x,
|
|
|
|
gint y,
|
2002-03-17 21:52:25 +08:00
|
|
|
const GimpRGB *color,
|
|
|
|
gpointer data)
|
2001-01-08 07:59:46 +08:00
|
|
|
{
|
2005-12-29 08:11:09 +08:00
|
|
|
GimpColormapEditor *editor = GIMP_COLORMAP_EDITOR (data);
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image = GIMP_IMAGE_EDITOR (editor)->image;
|
2001-01-08 07:59:46 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
if (HAVE_COLORMAP (image) && gimp_image_get_colormap_size (image) < 256)
|
2001-01-08 07:59:46 +08:00
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_add_colormap_entry (image, color);
|
2001-01-08 07:59:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-17 21:52:25 +08:00
|
|
|
static void
|
|
|
|
gimp_colormap_adjustment_changed (GtkAdjustment *adjustment,
|
|
|
|
GimpColormapEditor *editor)
|
2001-01-08 07:59:46 +08:00
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image = GIMP_IMAGE_EDITOR (editor)->image;
|
2003-12-01 20:58:03 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
if (HAVE_COLORMAP (image))
|
2002-03-19 03:34:06 +08:00
|
|
|
{
|
2006-05-29 03:45:52 +08:00
|
|
|
gimp_colormap_editor_set_index (editor, adjustment->value + 0.5, NULL);
|
2001-01-08 07:59:46 +08:00
|
|
|
|
2002-03-19 03:34:06 +08:00
|
|
|
gimp_colormap_editor_update_entries (editor);
|
|
|
|
}
|
2002-03-17 21:52:25 +08:00
|
|
|
}
|
2001-01-08 07:59:46 +08:00
|
|
|
|
2002-03-17 21:52:25 +08:00
|
|
|
static void
|
2005-03-24 23:29:48 +08:00
|
|
|
gimp_colormap_hex_entry_changed (GimpColorHexEntry *entry,
|
|
|
|
GimpColormapEditor *editor)
|
2002-03-17 21:52:25 +08:00
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image = GIMP_IMAGE_EDITOR (editor)->image;
|
2003-02-20 23:40:15 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
if (image)
|
2002-03-19 03:34:06 +08:00
|
|
|
{
|
2005-03-24 23:29:48 +08:00
|
|
|
GimpRGB color;
|
2003-02-20 23:40:15 +08:00
|
|
|
|
2005-03-24 23:29:48 +08:00
|
|
|
gimp_color_hex_entry_get_color (entry, &color);
|
2001-01-08 07:59:46 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_set_colormap_entry (image, editor->col_index, &color, TRUE);
|
|
|
|
gimp_image_flush (image);
|
2002-03-19 03:34:06 +08:00
|
|
|
}
|
2002-03-17 21:52:25 +08:00
|
|
|
}
|
2001-01-08 07:59:46 +08:00
|
|
|
|
2002-03-17 21:52:25 +08:00
|
|
|
static void
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_colormap_image_mode_changed (GimpImage *image,
|
2002-03-17 21:52:25 +08:00
|
|
|
GimpColormapEditor *editor)
|
|
|
|
{
|
2004-10-25 02:32:24 +08:00
|
|
|
if (editor->color_dialog)
|
|
|
|
gtk_widget_hide (editor->color_dialog);
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_colormap_image_colormap_changed (image, -1, editor);
|
2002-03-17 21:52:25 +08:00
|
|
|
}
|
2001-01-08 07:59:46 +08:00
|
|
|
|
2002-03-17 21:52:25 +08:00
|
|
|
static void
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_colormap_image_colormap_changed (GimpImage *image,
|
2002-03-17 21:52:25 +08:00
|
|
|
gint ncol,
|
|
|
|
GimpColormapEditor *editor)
|
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
if (HAVE_COLORMAP (image))
|
2002-03-17 21:52:25 +08:00
|
|
|
{
|
|
|
|
if (ncol < 0)
|
2004-09-25 19:25:49 +08:00
|
|
|
{
|
|
|
|
gimp_colormap_editor_draw (editor);
|
|
|
|
}
|
2002-03-17 21:52:25 +08:00
|
|
|
else
|
2004-09-25 19:25:49 +08:00
|
|
|
{
|
|
|
|
gimp_colormap_editor_draw_cell (editor, ncol);
|
|
|
|
}
|
2001-01-08 07:59:46 +08:00
|
|
|
|
2003-03-18 21:49:02 +08:00
|
|
|
if (editor->index_adjustment->upper !=
|
2006-03-29 01:08:36 +08:00
|
|
|
(gimp_image_get_colormap_size (image) - 1))
|
2004-09-25 19:25:49 +08:00
|
|
|
{
|
|
|
|
editor->index_adjustment->upper =
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_get_colormap_size (image) - 1;
|
2003-03-18 21:49:02 +08:00
|
|
|
|
2004-09-25 19:25:49 +08:00
|
|
|
gtk_adjustment_changed (editor->index_adjustment);
|
|
|
|
}
|
2002-03-17 21:52:25 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_colormap_editor_clear (editor, -1);
|
2001-01-08 07:59:46 +08:00
|
|
|
}
|
|
|
|
|
2002-03-17 21:52:25 +08:00
|
|
|
if (ncol == editor->col_index || ncol == -1)
|
|
|
|
gimp_colormap_editor_update_entries (editor);
|
2001-01-08 07:59:46 +08:00
|
|
|
}
|