gimp/app/widgets/gimpcolormapeditor.c

682 lines
22 KiB
C
Raw Normal View History

/* GIMP - The GNU 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gegl.h>
#include <gtk/gtk.h>
Makefile.am configure.in added stuff for the new library below. 2001-01-23 Michael Natterer <mitch@gimp.org> * Makefile.am * configure.in * gimptool.in: added stuff for the new library below. * libgimpcolor/.cvsignore * libgimpcolor/Makefile.am * libgimpcolor/gimpcolor.h * libgimpcolor/gimpcolorspace.c * libgimpcolor/gimpcolorspace.h * libgimpcolor/gimpcolortypes.h * libgimpcolor/gimphsv.c * libgimpcolor/gimphsv.h * libgimpcolor/gimprgb.c * libgimpcolor/gimprgb.h: new shared library which both the app and plug-ins link against. The library depends only on glib. * libgimpcolor/gimpcolor.def * libgimpcolor/makefile.mingw.in * libgimpcolor/makefile.msc: added Win32 build files which definitely don't work. * libgimp/Makefile.am * libgimp/gimpcolor.[ch] * libgimp/gimpcolorspace.[ch]: removed. * libgimp/gimp.h * libgimp/gimpadaptivesupersample.c * libgimp/gimpbilinear.c * libgimp/gimppalette.c * libgimp/gimptypes.h: include the stuff from libgimpcolor. Plug-Ins don't need to include <libgimpcolor/gimpcolor.h> explicitely. LibGimp depends on libgimpcolor and thus also includes it's headers. * libgimp/gimp.def * libgimp/makefile.mingw.in: fiddled around with Win32 stuff... * app/Makefile.am: link against libgimpcolor.la * app/apptypes.h: include "libgimpcolor/gimpcolortypes.h" * app/asupsample.c * app/channels_dialog.c * app/colormap_dialog.c * app/commands.c * app/convert.c * app/devices.c * app/disp_callbacks.c * app/drawable.c * app/gimpcontext.c * app/gimpdnd.c * app/gimpimage.c * app/gimppalette.c * app/gimprc.c * app/gradient.c * app/libgimp_glue.c * app/palette.c * app/palette_import.c * app/qmask.c * app/xcf.c * app/tools/paint_core.c * app/tools/paintbrush.c * app/tools/pencil.c: include "libgimpcolor/gimpcolor.h" before all gimp includes because it's a standalone library. * plug-ins/FractalExplorer/Makefile.am * plug-ins/Lighting/Makefile.am * plug-ins/MapObject/Makefile.am * plug-ins/bmp/Makefile.am * plug-ins/common/Makefile.am * plug-ins/common/mkgen.pl * plug-ins/dbbrowser/Makefile.am * plug-ins/faxg3/Makefile.am * plug-ins/fits/Makefile.am * plug-ins/flame/Makefile.am * plug-ins/fp/Makefile.am * plug-ins/gap/Makefile.am * plug-ins/gdyntext/Makefile.am * plug-ins/gfig/Makefile.am * plug-ins/gflare/Makefile.am * plug-ins/gfli/Makefile.am * plug-ins/gimpressionist/Makefile.am * plug-ins/helpbrowser/Makefile.am * plug-ins/ifscompose/Makefile.am * plug-ins/imagemap/Makefile.am * plug-ins/maze/Makefile.am * plug-ins/mosaic/Makefile.am * plug-ins/pagecurl/Makefile.am * plug-ins/print/Makefile.am * plug-ins/rcm/Makefile.am * plug-ins/script-fu/Makefile.am * plug-ins/sel2path/Makefile.am * plug-ins/sgi/Makefile.am * plug-ins/webbrowser/Makefile.am * plug-ins/xjt/Makefile.am: add libgimpcolor.la to LDADD. * INSTALL: don't recommend to --disable-shared for development. * TODO.xml: increased some percentages, added plug-in help stuff.
2001-01-24 02:49:44 +08:00
#include "libgimpcolor/gimpcolor.h"
#include "libgimpmath/gimpmath.h"
Makefile.am configure.in added the new library below. 2001-01-24 Michael Natterer <mitch@gimp.org> * Makefile.am * configure.in * gimptool.in: added the new library below. * libgimpwidgets/Makefile.am * libgimpwidgets/gimpchainbutton.[ch] * libgimpwidgets/gimpcolorarea.[ch] * libgimpwidgets/gimpcolorbutton.[ch] * libgimpwidgets/gimpdialog.[ch] * libgimpwidgets/gimpfileselection.[ch] * libgimpwidgets/gimphelpui.[ch] * libgimpwidgets/gimppatheditor.[ch] * libgimpwidgets/gimppixmap.[ch] * libgimpwidgets/gimpquerybox.[ch] * libgimpwidgets/gimpsizeentry.[ch] * libgimpwidgets/gimpunitmenu.[ch] * libgimpwidgets/gimpwidgets.[ch] * libgimpwidgets/gimpwidgets.def * libgimpwidgets/gimpwidgetstypes.h: new shared library. Currently there are some ugly dependencies into libgimp. These will be removed and go to a "libgimpglue" library which will be a library for functions which share a common interface between plug-ins and the app but have different implementations. Include "libgimp/gimpunit.h" from "libgimpwidgets/gimpwidgetstypes.h" to simulate this upcoming separation. * libgimp/Makefile.am * libgimp/gimpchainbutton.[ch] * libgimp/gimpcolorarea.[ch] * libgimp/gimpcolorbutton.[ch] * libgimp/gimpdialog.[ch] * libgimp/gimpfileselection.[ch] * libgimp/gimphelpui.[ch] * libgimp/gimppatheditor.[ch] * libgimp/gimppixmap.[ch] * libgimp/gimpquerybox.[ch] * libgimp/gimpsizeentry.[ch] * libgimp/gimpunitmenu.[ch] * libgimp/gimpwidgets.[ch]: removed from here. * libgimp/gimpui.h * libgimp/gimpuitypes.h * libgimp/makefile.mingw.in * libgimp/makefile.msc: changed accordingly. * app/[all ui files] * app/pdb/palette_cmds.c * app/pdb/tools_cmds.c * tools/pdbgen/pdb/palette.pdb * tools/pdbgen/pdb/tools.pdb: #include "libgimpwidgets/gimpwidgets.h" and removed useless includes. * app/apptypes.h: #include "libgimpwidgets/gimpwidgetstypes.h" * app/Makefile.am * plug-ins/[all makefiles which link against libgimpui]: link against libgimpwidgets.la * po-libgimp/POTFILES.in: changed file locations.
2001-01-25 06:36:18 +08:00
#include "libgimpwidgets/gimpwidgets.h"
Makefile.am configure.in added stuff for the new library below. 2001-01-23 Michael Natterer <mitch@gimp.org> * Makefile.am * configure.in * gimptool.in: added stuff for the new library below. * libgimpcolor/.cvsignore * libgimpcolor/Makefile.am * libgimpcolor/gimpcolor.h * libgimpcolor/gimpcolorspace.c * libgimpcolor/gimpcolorspace.h * libgimpcolor/gimpcolortypes.h * libgimpcolor/gimphsv.c * libgimpcolor/gimphsv.h * libgimpcolor/gimprgb.c * libgimpcolor/gimprgb.h: new shared library which both the app and plug-ins link against. The library depends only on glib. * libgimpcolor/gimpcolor.def * libgimpcolor/makefile.mingw.in * libgimpcolor/makefile.msc: added Win32 build files which definitely don't work. * libgimp/Makefile.am * libgimp/gimpcolor.[ch] * libgimp/gimpcolorspace.[ch]: removed. * libgimp/gimp.h * libgimp/gimpadaptivesupersample.c * libgimp/gimpbilinear.c * libgimp/gimppalette.c * libgimp/gimptypes.h: include the stuff from libgimpcolor. Plug-Ins don't need to include <libgimpcolor/gimpcolor.h> explicitely. LibGimp depends on libgimpcolor and thus also includes it's headers. * libgimp/gimp.def * libgimp/makefile.mingw.in: fiddled around with Win32 stuff... * app/Makefile.am: link against libgimpcolor.la * app/apptypes.h: include "libgimpcolor/gimpcolortypes.h" * app/asupsample.c * app/channels_dialog.c * app/colormap_dialog.c * app/commands.c * app/convert.c * app/devices.c * app/disp_callbacks.c * app/drawable.c * app/gimpcontext.c * app/gimpdnd.c * app/gimpimage.c * app/gimppalette.c * app/gimprc.c * app/gradient.c * app/libgimp_glue.c * app/palette.c * app/palette_import.c * app/qmask.c * app/xcf.c * app/tools/paint_core.c * app/tools/paintbrush.c * app/tools/pencil.c: include "libgimpcolor/gimpcolor.h" before all gimp includes because it's a standalone library. * plug-ins/FractalExplorer/Makefile.am * plug-ins/Lighting/Makefile.am * plug-ins/MapObject/Makefile.am * plug-ins/bmp/Makefile.am * plug-ins/common/Makefile.am * plug-ins/common/mkgen.pl * plug-ins/dbbrowser/Makefile.am * plug-ins/faxg3/Makefile.am * plug-ins/fits/Makefile.am * plug-ins/flame/Makefile.am * plug-ins/fp/Makefile.am * plug-ins/gap/Makefile.am * plug-ins/gdyntext/Makefile.am * plug-ins/gfig/Makefile.am * plug-ins/gflare/Makefile.am * plug-ins/gfli/Makefile.am * plug-ins/gimpressionist/Makefile.am * plug-ins/helpbrowser/Makefile.am * plug-ins/ifscompose/Makefile.am * plug-ins/imagemap/Makefile.am * plug-ins/maze/Makefile.am * plug-ins/mosaic/Makefile.am * plug-ins/pagecurl/Makefile.am * plug-ins/print/Makefile.am * plug-ins/rcm/Makefile.am * plug-ins/script-fu/Makefile.am * plug-ins/sel2path/Makefile.am * plug-ins/sgi/Makefile.am * plug-ins/webbrowser/Makefile.am * plug-ins/xjt/Makefile.am: add libgimpcolor.la to LDADD. * INSTALL: don't recommend to --disable-shared for development. * TODO.xml: increased some percentages, added plug-in help stuff.
2001-01-24 02:49:44 +08:00
#include "widgets-types.h"
#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimpcontainer.h"
#include "core/gimpimage.h"
#include "core/gimpimage-colormap.h"
bumped version number to 1.3.1. Require Glib/GTK+-1.3.11 and Pango-0.22. 2001-11-23 Sven Neumann <sven@gimp.org> * configure.in: bumped version number to 1.3.1. Require Glib/GTK+-1.3.11 and Pango-0.22. Removed GDK_DISABLE_COMPAT_H and GTK_DISABLE_COMPAT_H from our default CFLAGS since they don't exist any longer. * RELEASE-TO-CVS.patch: removed since the glib/gtk+ API is supposed to be frozen now. * HACKING: removed reference to RELEASE-TO-CVS.patch * app/gui/menus.c * app/tools/gimptexttool.c: applied RELEASE-TO-CVS.patch to conform to the new GTK+/Pango API. * app/core/Makefile.am: generate marshallers with gimp_marshal prefix. * app/core/gimpmarshal.list: added all marshallers we use. * app/core/gimpmarshal.[ch]: regenerated. * app/[lots of .c files]: use gimp_marshal_* for all marshallers. * data/images/ * app/app_procs.c * app/gui/splash.c: * libgimpbase/Makefile.am * libgimpbase/gimpbase.h * libgimpbase/gimputils.[ch]: removed since they are no longer needed. * app/gimprc.c * plug-ins/common/ps.c * plug-ins/gdyntext/gdyntext.c * plug-ins/gdyntext/gdyntextcompat.c * plug-ins/gfig/gfig.c * plug-ins/gflare/gflare.c * plug-ins/script-fu/script-fu-scripts.c: use glib functions instead of gimp_strescape() and gimpstrcompress(). * cleaned up all header files: use G_BEGIN_DECLS/G_END_DECLS, declared all _get_type function as G_GNUC_CONST. * tools/pdbgen/enumcode.pl * tools/pdbgen/lib.pl: make them generate header files using G_BEGIN_DECLS/G_END_DECLS. * pixmaps/Makefile.am * pixmaps/wilber3.xpm: removed ... * data/images/tips_wilber.png: ... and added here as PNG * app/gui/tips-dialog.c: load the Wilber on demand using GdkPixbuf. * data/images/gimp_splash.ppm: removed ... * data/images/gimp_splash.png: ... and added as PNG * app/app_procs.c * app/gui/splash.[ch]: load the splash image using GdkPixbuf. * app/gui/about-dialog.c: sink the GtkPreview.
2001-11-23 07:46:13 +08:00
#include "core/gimpmarshal.h"
#include "core/gimppalette.h"
#include "gimpcolormapeditor.h"
#include "gimpdnd.h"
#include "gimpdocked.h"
Move away from creating all item_factories statically in menus_init() but 2003-01-10 Michael Natterer <mitch@gimp.org> Move away from creating all item_factories statically in menus_init() but create a new one for each place where one is needed: * app/widgets/Makefile.am * app/widgets/widgets-types.h * app/widgets/gimpmenufactory.[ch]: new factory which creates and configures the GimpItemFactories it knows about on-the-fly. * app/widgets/gimpitemfactory.[ch]: added gimp_item_factory_update() which calls the "update_func". Added "gboolean update_on_popup" so item_factories can be configured to require manual updates (used for the <Image> factory). * app/gui/menus.[ch]: create a "global_menu_factory" and register all menus we have with it. Added various setup functions which do stuff like adding the "Open Recent" menu or reorder plug-in menu entries. Removed the debugging stuff... * app/gui/Makefile.am * app/gui/debug-commands.[ch]: ...and added it here. * app/gui/gui.c: create the <Toolbox>, the popup-<Image> and the <Paths> factories here because they are still global. * app/gui/plug-in-menus.[ch]: changed the "image_factory" parameters to "item_factory" and create/update the entries for the passed item_factory only. Makes the whole stuff much more straightforward. * app/plug-in/plug-ins.c: don't call plug_in_make_menu(). * app/display/gimpdisplay.[ch] * app/display/gimpdisplayshell.[ch]: added "menu_factory" and "popup_factory" parameters to gimp_display_new() and gimp_display_shell_new(). Create the menubar_factory and the qmask_factory dynamically. Pass the shell, not a Gimp to the QMask callbacks. Changed gimp_display_shell_set_menu_sensitivity() to gimp_display_shell_menu_update() and don't call it directly (it's a GimpItemFactory update_func now). Call gimp_item_factory_update() on the resp. factories instead. * app/gui/qmask-commands.c * app/display/gimpdisplayshell-callbacks.c * app/tools/gimpimagemaptool.c: changed accordingly. * app/widgets/gimpbrusheditor.c * app/widgets/gimpbrushfactoryview.[ch] * app/widgets/gimpbufferview.[ch] * app/widgets/gimpcolormapeditor.[ch] * app/widgets/gimpcontainereditor.[ch] * app/widgets/gimpdataeditor.[ch] * app/widgets/gimpdatafactoryview.[ch] * app/widgets/gimpdialogfactory.[ch] * app/widgets/gimpdock.c * app/widgets/gimpdockbook.[ch] * app/widgets/gimpdocumentview.[ch] * app/widgets/gimpgradienteditor.[ch] * app/widgets/gimpimageview.[ch] * app/widgets/gimpitemlistview.[ch] * app/widgets/gimppaletteeditor.[ch]: pass around lots of GimpMenuFactory pointers and menu_identifiers so all views can create their item_factories themselves. Unref the factories when they are no longer needed because they belong to the views now. * app/gui/dialogs-commands.c * app/gui/dialogs-constructors.c * app/gui/dialogs.c * app/gui/brush-select.c * app/gui/gradient-select.c * app/gui/palette-select.c * app/gui/pattern-select.c: changed accordingly. * app/gui/file-dialog-utils.[ch] (file_dialog_new): require menu_factory and menu_identifier parameters. * app/gui/file-open-dialog.[ch] * app/gui/file-save-dialog.[ch]: removed file_*_dialog_menu_init() (they went to menus.c as setup_funcs). Added file_*_dialog_set_type() and moved the <Load> and <Save> factory callbacks to file-commands.c * app/gui/file-commands.[ch]: changed accordingly. * app/gui/view-commands.c: changed the statusbar, menubar, rulers and guides callbacks to do their job only if the setting has actually changed. Don't update whole item factories afterwards. Instead, just change the state of the items that actually need update. Unrelated: * app/core/gimpchannel.c (gimp_channel_init): set "bounds_known" and friends to FALSE since we don't know that the new channel will be empty (fixes QMask and probably other stuff). * app/gui/image-commands.c * app/gui/vectors-commands.c: cleanup.
2003-01-11 01:55:53 +08:00
#include "gimpmenufactory.h"
#include "gimppaletteview.h"
#include "gimpuimanager.h"
#include "gimpviewrendererpalette.h"
#include "gimp-intl.h"
#define BORDER 6
#define EPSILON 1e-10
#define HAVE_COLORMAP(image) \
(image != NULL && \
gimp_image_base_type (image) == GIMP_INDEXED && \
gimp_image_get_colormap (image) != NULL)
static void gimp_colormap_editor_docked_iface_init (GimpDockedInterface *face);
static void gimp_colormap_editor_constructed (GObject *object);
static void gimp_colormap_editor_dispose (GObject *object);
static void gimp_colormap_editor_finalize (GObject *object);
static void gimp_colormap_editor_unmap (GtkWidget *widget);
static void gimp_colormap_editor_set_image (GimpImageEditor *editor,
GimpImage *image);
static void gimp_colormap_editor_set_context (GimpDocked *docked,
GimpContext *context);
static PangoLayout *
gimp_colormap_editor_create_layout (GtkWidget *widget);
static void gimp_colormap_editor_update_entries (GimpColormapEditor *editor);
2010-09-01 04:58:27 +08:00
static gboolean gimp_colormap_preview_expose (GtkWidget *widget,
GdkEventExpose *event,
GimpColormapEditor *editor);
static void gimp_colormap_editor_entry_clicked (GimpPaletteView *view,
GimpPaletteEntry *entry,
GdkModifierType state,
GimpColormapEditor *editor);
static void gimp_colormap_editor_entry_selected (GimpPaletteView *view,
GimpPaletteEntry *entry,
GimpColormapEditor *editor);
static void gimp_colormap_editor_entry_activated (GimpPaletteView *view,
GimpPaletteEntry *entry,
GimpColormapEditor *editor);
static void gimp_colormap_editor_entry_context (GimpPaletteView *view,
GimpPaletteEntry *entry,
GimpColormapEditor *editor);
static void gimp_colormap_editor_color_dropped (GimpPaletteView *view,
GimpPaletteEntry *entry,
const GimpRGB *color,
GimpColormapEditor *editor);
static void gimp_colormap_adjustment_changed (GtkAdjustment *adjustment,
GimpColormapEditor *editor);
static void gimp_colormap_hex_entry_changed (GimpColorHexEntry *entry,
GimpColormapEditor *editor);
static void gimp_colormap_image_mode_changed (GimpImage *image,
GimpColormapEditor *editor);
static void gimp_colormap_image_colormap_changed (GimpImage *image,
gint ncol,
GimpColormapEditor *editor);
G_DEFINE_TYPE_WITH_CODE (GimpColormapEditor, gimp_colormap_editor,
GIMP_TYPE_IMAGE_EDITOR,
G_IMPLEMENT_INTERFACE (GIMP_TYPE_DOCKED,
gimp_colormap_editor_docked_iface_init))
#define parent_class gimp_colormap_editor_parent_class
static GimpDockedInterface *parent_docked_iface = NULL;
static void
gimp_colormap_editor_class_init (GimpColormapEditorClass* klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GimpImageEditorClass *image_editor_class = GIMP_IMAGE_EDITOR_CLASS (klass);
object_class->constructed = gimp_colormap_editor_constructed;
object_class->dispose = gimp_colormap_editor_dispose;
object_class->finalize = gimp_colormap_editor_finalize;
widget_class->unmap = gimp_colormap_editor_unmap;
image_editor_class->set_image = gimp_colormap_editor_set_image;
}
static void
gimp_colormap_editor_docked_iface_init (GimpDockedInterface *iface)
{
parent_docked_iface = g_type_interface_peek_parent (iface);
if (! parent_docked_iface)
parent_docked_iface = g_type_default_interface_peek (GIMP_TYPE_DOCKED);
iface->set_context = gimp_colormap_editor_set_context;
}
static void
gimp_colormap_editor_init (GimpColormapEditor *editor)
{
2010-09-01 04:58:27 +08:00
GtkWidget *frame;
GtkWidget *table;
GtkObject *adj;
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);
editor->view = gimp_view_new_full_by_types (NULL,
GIMP_TYPE_PALETTE_VIEW,
GIMP_TYPE_PALETTE,
1, 1, 0,
FALSE, TRUE, FALSE);
gimp_view_set_expand (GIMP_VIEW (editor->view), TRUE);
gtk_container_add (GTK_CONTAINER (frame), editor->view);
gtk_widget_show (editor->view);
g_signal_connect (editor->view, "expose-event",
2010-09-01 04:58:27 +08:00
G_CALLBACK (gimp_colormap_preview_expose),
editor);
g_signal_connect (editor->view, "entry-clicked",
G_CALLBACK (gimp_colormap_editor_entry_clicked),
editor);
g_signal_connect (editor->view, "entry-selected",
G_CALLBACK (gimp_colormap_editor_entry_selected),
editor);
g_signal_connect (editor->view, "entry-activated",
G_CALLBACK (gimp_colormap_editor_entry_activated),
editor);
g_signal_connect (editor->view, "entry-context",
G_CALLBACK (gimp_colormap_editor_entry_context),
editor);
g_signal_connect (editor->view, "color-dropped",
G_CALLBACK (gimp_colormap_editor_color_dropped),
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);
editor->index_spinbutton = gimp_spin_button_new (&adj,
0, 0, 0, 1, 10, 0, 1.0, 0);
editor->index_adjustment = GTK_ADJUSTMENT (adj);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
_("Color index:"), 0.0, 0.5,
editor->index_spinbutton, 1, TRUE);
g_signal_connect (editor->index_adjustment, "value-changed",
G_CALLBACK (gimp_colormap_adjustment_changed),
editor);
editor->color_entry = gimp_color_hex_entry_new ();
gtk_entry_set_width_chars (GTK_ENTRY (editor->color_entry), 12);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
_("HTML notation:"), 0.0, 0.5,
editor->color_entry, 1, TRUE);
g_signal_connect (editor->color_entry, "color-changed",
G_CALLBACK (gimp_colormap_hex_entry_changed),
editor);
}
static void
gimp_colormap_editor_constructed (GObject *object)
{
GimpColormapEditor *editor = GIMP_COLORMAP_EDITOR (object);
if (G_OBJECT_CLASS (parent_class)->constructed)
G_OBJECT_CLASS (parent_class)->constructed (object);
gimp_editor_add_action_button (GIMP_EDITOR (editor), "colormap",
"colormap-edit-color",
NULL);
gimp_editor_add_action_button (GIMP_EDITOR (editor), "colormap",
"colormap-add-color-from-fg",
"colormap-add-color-from-bg",
GDK_CONTROL_MASK,
NULL);
}
static void
gimp_colormap_editor_dispose (GObject *object)
{
GimpColormapEditor *editor = GIMP_COLORMAP_EDITOR (object);
if (editor->color_dialog)
{
gtk_widget_destroy (editor->color_dialog);
editor->color_dialog = NULL;
}
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static void
gimp_colormap_editor_finalize (GObject *object)
{
GimpColormapEditor *editor = GIMP_COLORMAP_EDITOR (object);
if (editor->layout)
{
g_object_unref (editor->layout);
editor->layout = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_colormap_editor_unmap (GtkWidget *widget)
{
GimpColormapEditor *editor = GIMP_COLORMAP_EDITOR (widget);
configure.in added new directory app/dialogs and link libappdialogs.c into 2004-09-13 Michael Natterer <mitch@gimp.org> * configure.in * app/Makefile.am: added new directory app/dialogs and link libappdialogs.c into the gimp binary. * app/gui/Makefile.am * app/gui/gui-types.h * app/gui/gui-vtable.c * app/gui/gui.c * app/gui/about-dialog.[ch] * app/gui/authors.h * app/gui/color-notebook.[ch] * app/gui/convert-dialog.[ch] * app/gui/dialogs-constructors.[ch] * app/gui/dialogs.[ch] * app/gui/file-dialog-utils.[ch] * app/gui/file-new-dialog.[ch] * app/gui/file-open-dialog.[ch] * app/gui/file-open-location-dialog.[ch] * app/gui/file-save-dialog.[ch] * app/gui/grid-dialog.[ch] * app/gui/info-dialog.[ch] * app/gui/info-window.[ch] * app/gui/module-browser.[ch] * app/gui/offset-dialog.[ch] * app/gui/palette-import-dialog.[ch] * app/gui/preferences-dialog.[ch] * app/gui/quit-dialog.[ch] * app/gui/resize-dialog.[ch] * app/gui/resolution-calibrate-dialog.[ch] * app/gui/stroke-dialog.[ch] * app/gui/tips-dialog.[ch] * app/gui/tips-parser.[ch] * app/gui/user-install-dialog.[ch]: removed these files... * app/dialogs/Makefile.am * app/dialogs/dialogs-types.h * app/dialogs/*.[ch]: ...and added them here. Changed some filenames like module-browser -> module-dialog. * app/app_procs.c * app/actions/actions-types.h * app/actions/actions.c * app/actions/dialogs-actions.c * app/actions/dialogs-commands.c * app/actions/dockable-commands.c * app/actions/drawable-commands.c * app/actions/edit-commands.c * app/actions/file-commands.c * app/actions/gradient-editor-commands.c * app/actions/image-commands.c * app/actions/layers-commands.c * app/actions/palettes-commands.c * app/actions/select-commands.c * app/actions/templates-commands.c * app/actions/templates-commands.h * app/actions/vectors-commands.c * app/actions/view-commands.c * app/display/gimpdisplayshell-cursor.c * app/display/gimpdisplayshell-title.c * app/display/gimpdisplayshell.[ch] * app/tools/gimpcroptool.c * app/tools/gimpperspectivetool.c * app/tools/gimprotatetool.c * app/tools/gimpscaletool.c * app/tools/gimpsheartool.c * app/tools/gimptransformtool.[ch] * app/tools/gimpvectortool.c * app/widgets/gimpcolormapeditor.[ch] * app/widgets/gimpcolorpanel.c * app/widgets/gimpgradienteditor.[ch] * app/widgets/gimppaletteeditor.[ch] * app/widgets/gimptoolbox-color-area.c * menus/toolbox-menu.xml.in * tools/authorsgen/authorsgen.pl: changed accordingly.
2004-09-13 23:15:23 +08:00
if (editor->color_dialog)
gtk_widget_hide (editor->color_dialog);
GTK_WIDGET_CLASS (parent_class)->unmap (widget);
}
static void
gimp_colormap_editor_set_image (GimpImageEditor *image_editor,
GimpImage *image)
{
GimpColormapEditor *editor = GIMP_COLORMAP_EDITOR (image_editor);
if (image_editor->image)
{
g_signal_handlers_disconnect_by_func (image_editor->image,
gimp_colormap_image_mode_changed,
editor);
g_signal_handlers_disconnect_by_func (image_editor->image,
gimp_colormap_image_colormap_changed,
editor);
configure.in added new directory app/dialogs and link libappdialogs.c into 2004-09-13 Michael Natterer <mitch@gimp.org> * configure.in * app/Makefile.am: added new directory app/dialogs and link libappdialogs.c into the gimp binary. * app/gui/Makefile.am * app/gui/gui-types.h * app/gui/gui-vtable.c * app/gui/gui.c * app/gui/about-dialog.[ch] * app/gui/authors.h * app/gui/color-notebook.[ch] * app/gui/convert-dialog.[ch] * app/gui/dialogs-constructors.[ch] * app/gui/dialogs.[ch] * app/gui/file-dialog-utils.[ch] * app/gui/file-new-dialog.[ch] * app/gui/file-open-dialog.[ch] * app/gui/file-open-location-dialog.[ch] * app/gui/file-save-dialog.[ch] * app/gui/grid-dialog.[ch] * app/gui/info-dialog.[ch] * app/gui/info-window.[ch] * app/gui/module-browser.[ch] * app/gui/offset-dialog.[ch] * app/gui/palette-import-dialog.[ch] * app/gui/preferences-dialog.[ch] * app/gui/quit-dialog.[ch] * app/gui/resize-dialog.[ch] * app/gui/resolution-calibrate-dialog.[ch] * app/gui/stroke-dialog.[ch] * app/gui/tips-dialog.[ch] * app/gui/tips-parser.[ch] * app/gui/user-install-dialog.[ch]: removed these files... * app/dialogs/Makefile.am * app/dialogs/dialogs-types.h * app/dialogs/*.[ch]: ...and added them here. Changed some filenames like module-browser -> module-dialog. * app/app_procs.c * app/actions/actions-types.h * app/actions/actions.c * app/actions/dialogs-actions.c * app/actions/dialogs-commands.c * app/actions/dockable-commands.c * app/actions/drawable-commands.c * app/actions/edit-commands.c * app/actions/file-commands.c * app/actions/gradient-editor-commands.c * app/actions/image-commands.c * app/actions/layers-commands.c * app/actions/palettes-commands.c * app/actions/select-commands.c * app/actions/templates-commands.c * app/actions/templates-commands.h * app/actions/vectors-commands.c * app/actions/view-commands.c * app/display/gimpdisplayshell-cursor.c * app/display/gimpdisplayshell-title.c * app/display/gimpdisplayshell.[ch] * app/tools/gimpcroptool.c * app/tools/gimpperspectivetool.c * app/tools/gimprotatetool.c * app/tools/gimpscaletool.c * app/tools/gimpsheartool.c * app/tools/gimptransformtool.[ch] * app/tools/gimpvectortool.c * app/widgets/gimpcolormapeditor.[ch] * app/widgets/gimpcolorpanel.c * app/widgets/gimpgradienteditor.[ch] * app/widgets/gimppaletteeditor.[ch] * app/widgets/gimptoolbox-color-area.c * menus/toolbox-menu.xml.in * tools/authorsgen/authorsgen.pl: changed accordingly.
2004-09-13 23:15:23 +08:00
if (editor->color_dialog)
gtk_widget_hide (editor->color_dialog);
if (! HAVE_COLORMAP (image))
{
gtk_adjustment_set_upper (editor->index_adjustment, 0);
if (gtk_widget_get_mapped (GTK_WIDGET (editor)))
gimp_view_set_viewable (GIMP_VIEW (editor->view), NULL);
}
}
GIMP_IMAGE_EDITOR_CLASS (parent_class)->set_image (image_editor, image);
editor->col_index = 0;
if (image)
{
g_signal_connect (image, "mode-changed",
G_CALLBACK (gimp_colormap_image_mode_changed),
editor);
g_signal_connect (image, "colormap-changed",
G_CALLBACK (gimp_colormap_image_colormap_changed),
editor);
if (HAVE_COLORMAP (image))
{
gimp_view_set_viewable (GIMP_VIEW (editor->view),
GIMP_VIEWABLE (gimp_image_get_colormap_palette (image)));
gtk_adjustment_set_upper (editor->index_adjustment,
gimp_image_get_colormap_size (image) - 1);
}
}
gimp_colormap_editor_update_entries (editor);
}
static void
gimp_colormap_editor_set_context (GimpDocked *docked,
GimpContext *context)
{
GimpColormapEditor *editor = GIMP_COLORMAP_EDITOR (docked);
parent_docked_iface->set_context (docked, context);
gimp_view_renderer_set_context (GIMP_VIEW (editor->view)->renderer,
context);
}
/* public functions */
GtkWidget *
gimp_colormap_editor_new (GimpMenuFactory *menu_factory)
{
Move away from creating all item_factories statically in menus_init() but 2003-01-10 Michael Natterer <mitch@gimp.org> Move away from creating all item_factories statically in menus_init() but create a new one for each place where one is needed: * app/widgets/Makefile.am * app/widgets/widgets-types.h * app/widgets/gimpmenufactory.[ch]: new factory which creates and configures the GimpItemFactories it knows about on-the-fly. * app/widgets/gimpitemfactory.[ch]: added gimp_item_factory_update() which calls the "update_func". Added "gboolean update_on_popup" so item_factories can be configured to require manual updates (used for the <Image> factory). * app/gui/menus.[ch]: create a "global_menu_factory" and register all menus we have with it. Added various setup functions which do stuff like adding the "Open Recent" menu or reorder plug-in menu entries. Removed the debugging stuff... * app/gui/Makefile.am * app/gui/debug-commands.[ch]: ...and added it here. * app/gui/gui.c: create the <Toolbox>, the popup-<Image> and the <Paths> factories here because they are still global. * app/gui/plug-in-menus.[ch]: changed the "image_factory" parameters to "item_factory" and create/update the entries for the passed item_factory only. Makes the whole stuff much more straightforward. * app/plug-in/plug-ins.c: don't call plug_in_make_menu(). * app/display/gimpdisplay.[ch] * app/display/gimpdisplayshell.[ch]: added "menu_factory" and "popup_factory" parameters to gimp_display_new() and gimp_display_shell_new(). Create the menubar_factory and the qmask_factory dynamically. Pass the shell, not a Gimp to the QMask callbacks. Changed gimp_display_shell_set_menu_sensitivity() to gimp_display_shell_menu_update() and don't call it directly (it's a GimpItemFactory update_func now). Call gimp_item_factory_update() on the resp. factories instead. * app/gui/qmask-commands.c * app/display/gimpdisplayshell-callbacks.c * app/tools/gimpimagemaptool.c: changed accordingly. * app/widgets/gimpbrusheditor.c * app/widgets/gimpbrushfactoryview.[ch] * app/widgets/gimpbufferview.[ch] * app/widgets/gimpcolormapeditor.[ch] * app/widgets/gimpcontainereditor.[ch] * app/widgets/gimpdataeditor.[ch] * app/widgets/gimpdatafactoryview.[ch] * app/widgets/gimpdialogfactory.[ch] * app/widgets/gimpdock.c * app/widgets/gimpdockbook.[ch] * app/widgets/gimpdocumentview.[ch] * app/widgets/gimpgradienteditor.[ch] * app/widgets/gimpimageview.[ch] * app/widgets/gimpitemlistview.[ch] * app/widgets/gimppaletteeditor.[ch]: pass around lots of GimpMenuFactory pointers and menu_identifiers so all views can create their item_factories themselves. Unref the factories when they are no longer needed because they belong to the views now. * app/gui/dialogs-commands.c * app/gui/dialogs-constructors.c * app/gui/dialogs.c * app/gui/brush-select.c * app/gui/gradient-select.c * app/gui/palette-select.c * app/gui/pattern-select.c: changed accordingly. * app/gui/file-dialog-utils.[ch] (file_dialog_new): require menu_factory and menu_identifier parameters. * app/gui/file-open-dialog.[ch] * app/gui/file-save-dialog.[ch]: removed file_*_dialog_menu_init() (they went to menus.c as setup_funcs). Added file_*_dialog_set_type() and moved the <Load> and <Save> factory callbacks to file-commands.c * app/gui/file-commands.[ch]: changed accordingly. * app/gui/view-commands.c: changed the statusbar, menubar, rulers and guides callbacks to do their job only if the setting has actually changed. Don't update whole item factories afterwards. Instead, just change the state of the items that actually need update. Unrelated: * app/core/gimpchannel.c (gimp_channel_init): set "bounds_known" and friends to FALSE since we don't know that the new channel will be empty (fixes QMask and probably other stuff). * app/gui/image-commands.c * app/gui/vectors-commands.c: cleanup.
2003-01-11 01:55:53 +08:00
g_return_val_if_fail (GIMP_IS_MENU_FACTORY (menu_factory), NULL);
return g_object_new (GIMP_TYPE_COLORMAP_EDITOR,
"menu-factory", menu_factory,
"menu-identifier", "<Colormap>",
"ui-path", "/colormap-popup",
NULL);
}
gint
gimp_colormap_editor_get_index (GimpColormapEditor *editor,
const GimpRGB *search)
{
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;
gint size;
g_return_val_if_fail (GIMP_IS_COLORMAP_EDITOR (editor), FALSE);
image = GIMP_IMAGE_EDITOR (editor)->image;
if (! HAVE_COLORMAP (image))
return FALSE;
size = gimp_image_get_colormap_size (image);
if (size < 1)
return FALSE;
index = CLAMP (index, 0, size - 1);
if (index != editor->col_index)
{
GimpPalette *palette = gimp_image_get_colormap_palette (image);
editor->col_index = index;
gimp_palette_view_select_entry (GIMP_PALETTE_VIEW (editor->view),
gimp_palette_get_entry (palette, index));
gimp_colormap_editor_update_entries (editor);
}
if (color)
gimp_image_get_colormap_entry (GIMP_IMAGE_EDITOR (editor)->image,
index, color);
return TRUE;
}
gint
gimp_colormap_editor_max_index (GimpColormapEditor *editor)
{
GimpImage *image;
g_return_val_if_fail (GIMP_IS_COLORMAP_EDITOR (editor), -1);
image = GIMP_IMAGE_EDITOR (editor)->image;
if (! HAVE_COLORMAP (image))
return -1;
return MAX (0, gimp_image_get_colormap_size (image) - 1);
}
/* private functions */
static PangoLayout *
gimp_colormap_editor_create_layout (GtkWidget *widget)
{
PangoLayout *layout;
PangoAttrList *attrs;
PangoAttribute *attr;
layout = gtk_widget_create_pango_layout (widget,
_("Only indexed images have "
"a colormap."));
2010-09-01 04:58:27 +08:00
pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
attrs = pango_attr_list_new ();
attr = pango_attr_style_new (PANGO_STYLE_ITALIC);
attr->start_index = 0;
attr->end_index = -1;
pango_attr_list_insert (attrs, attr);
pango_layout_set_attributes (layout, attrs);
pango_attr_list_unref (attrs);
return layout;
}
2010-09-01 04:58:27 +08:00
static gboolean
gimp_colormap_preview_expose (GtkWidget *widget,
GdkEventExpose *event,
GimpColormapEditor *editor)
{
GimpImageEditor *image_editor = GIMP_IMAGE_EDITOR (editor);
2010-09-01 04:58:27 +08:00
GtkStyle *style;
cairo_t *cr;
GtkAllocation allocation;
gint width, height;
2010-09-01 04:58:27 +08:00
gint y;
if (image_editor->image == NULL ||
gimp_image_base_type (image_editor->image) == GIMP_INDEXED)
2010-09-01 04:58:27 +08:00
return FALSE;
cr = gdk_cairo_create (event->window);
gdk_cairo_region (cr, event->region);
cairo_clip (cr);
style = gtk_widget_get_style (widget);
gdk_cairo_set_source_color (cr, &style->fg[gtk_widget_get_state (widget)]);
gtk_widget_get_allocation (widget, &allocation);
if (! gtk_widget_get_has_window (widget))
cairo_translate (cr, allocation.x, allocation.y);
if (! editor->layout)
editor->layout = gimp_colormap_editor_create_layout (editor->view);
2010-09-01 04:58:27 +08:00
pango_layout_set_width (editor->layout,
PANGO_SCALE * (allocation.width - 2 * BORDER));
pango_layout_get_pixel_size (editor->layout, &width, &height);
y = (allocation.height - height) / 2;
2010-09-01 04:58:27 +08:00
cairo_move_to (cr, BORDER, MAX (y, 0));
pango_cairo_show_layout (cr, editor->layout);
cairo_destroy (cr);
return TRUE;
}
static void
gimp_colormap_editor_update_entries (GimpColormapEditor *editor)
{
GimpImage *image = GIMP_IMAGE_EDITOR (editor)->image;
if (! HAVE_COLORMAP (image) ||
! gimp_image_get_colormap_size (image))
{
gtk_widget_set_sensitive (editor->index_spinbutton, FALSE);
gtk_widget_set_sensitive (editor->color_entry, FALSE);
gtk_adjustment_set_value (editor->index_adjustment, 0);
gtk_entry_set_text (GTK_ENTRY (editor->color_entry), "");
}
else
{
2010-02-04 03:09:20 +08:00
const guchar *colormap = gimp_image_get_colormap (image);
const guchar *col;
gchar *string;
gtk_adjustment_set_value (editor->index_adjustment, editor->col_index);
2010-02-04 03:09:20 +08:00
col = colormap + editor->col_index * 3;
string = g_strdup_printf ("%02x%02x%02x", col[0], col[1], col[2]);
gtk_entry_set_text (GTK_ENTRY (editor->color_entry), string);
g_free (string);
gtk_widget_set_sensitive (editor->index_spinbutton, TRUE);
gtk_widget_set_sensitive (editor->color_entry, TRUE);
}
}
static void
gimp_colormap_editor_entry_clicked (GimpPaletteView *view,
GimpPaletteEntry *entry,
GdkModifierType state,
GimpColormapEditor *editor)
{
GimpImageEditor *image_editor = GIMP_IMAGE_EDITOR (editor);
gimp_colormap_editor_set_index (editor, entry->position, NULL);
if (state & GDK_CONTROL_MASK)
gimp_context_set_background (image_editor->context, &entry->color);
else
gimp_context_set_foreground (image_editor->context, &entry->color);
}
static void
gimp_colormap_editor_entry_selected (GimpPaletteView *view,
GimpPaletteEntry *entry,
GimpColormapEditor *editor)
{
gint index = entry ? entry->position : 0;
gimp_colormap_editor_set_index (editor, index, NULL);
}
static void
gimp_colormap_editor_entry_activated (GimpPaletteView *view,
GimpPaletteEntry *entry,
GimpColormapEditor *editor)
{
gimp_colormap_editor_set_index (editor, entry->position, NULL);
gimp_ui_manager_activate_action (GIMP_EDITOR (editor)->ui_manager,
"colormap",
"colormap-edit-color");
}
static void
gimp_colormap_editor_entry_context (GimpPaletteView *view,
GimpPaletteEntry *entry,
GimpColormapEditor *editor)
{
gimp_colormap_editor_set_index (editor, entry->position, NULL);
gimp_editor_popup_menu (GIMP_EDITOR (editor), NULL, NULL);
}
static void
gimp_colormap_editor_color_dropped (GimpPaletteView *view,
GimpPaletteEntry *entry,
const GimpRGB *color,
GimpColormapEditor *editor)
{
}
static void
gimp_colormap_adjustment_changed (GtkAdjustment *adjustment,
GimpColormapEditor *editor)
{
GimpImage *image = GIMP_IMAGE_EDITOR (editor)->image;
if (HAVE_COLORMAP (image))
{
gint index = ROUND (gtk_adjustment_get_value (adjustment));
gimp_colormap_editor_set_index (editor, index, NULL);
gimp_colormap_editor_update_entries (editor);
}
}
static void
gimp_colormap_hex_entry_changed (GimpColorHexEntry *entry,
GimpColormapEditor *editor)
{
GimpImage *image = GIMP_IMAGE_EDITOR (editor)->image;
if (image)
{
GimpRGB color;
gimp_color_hex_entry_get_color (entry, &color);
gimp_image_set_colormap_entry (image, editor->col_index, &color, TRUE);
gimp_image_flush (image);
}
}
static void
gimp_colormap_image_mode_changed (GimpImage *image,
GimpColormapEditor *editor)
{
if (editor->color_dialog)
gtk_widget_hide (editor->color_dialog);
gimp_colormap_image_colormap_changed (image, -1, editor);
}
static void
gimp_colormap_image_colormap_changed (GimpImage *image,
gint ncol,
GimpColormapEditor *editor)
{
if (HAVE_COLORMAP (image))
{
gimp_view_set_viewable (GIMP_VIEW (editor->view),
GIMP_VIEWABLE (gimp_image_get_colormap_palette (image)));
gtk_adjustment_set_upper (editor->index_adjustment,
gimp_image_get_colormap_size (image) - 1);
}
else
{
gimp_view_set_viewable (GIMP_VIEW (editor->view), NULL);
}
if (ncol == editor->col_index || ncol == -1)
gimp_colormap_editor_update_entries (editor);
}