mirror of https://github.com/GNOME/gimp.git
Applied patch from David Gowers which adds actions to select palette and
2006-05-28 Michael Natterer <mitch@gimp.org> Applied patch from David Gowers which adds actions to select palette and colormap colors with actions. Modified the patch quite a bit. Fixes bug #130123. * app/widgets/gimpcolormapeditor.[ch] * app/widgets/gimppaletteeditor.[ch]: add functions get_index() which gets the currently selected color's index (optionally the index of a passed color), set_index() which sets the selected color by index, and max_index() which returns the maximum possible color index. * app/dialogs/dialogs-constructors.c: changed accordingly. * app/actions/context-actions.c * app/actions/context-commands.[ch]: actions and callbacks which use the new functions.
This commit is contained in:
parent
fa71c34b22
commit
17475c5fec
19
ChangeLog
19
ChangeLog
|
@ -1,3 +1,22 @@
|
|||
2006-05-28 Michael Natterer <mitch@gimp.org>
|
||||
|
||||
Applied patch from David Gowers which adds actions to select
|
||||
palette and colormap colors with actions. Modified the patch quite
|
||||
a bit. Fixes bug #130123.
|
||||
|
||||
* app/widgets/gimpcolormapeditor.[ch]
|
||||
* app/widgets/gimppaletteeditor.[ch]: add functions get_index()
|
||||
which gets the currently selected color's index (optionally the
|
||||
index of a passed color), set_index() which sets the selected
|
||||
color by index, and max_index() which returns the maximum possible
|
||||
color index.
|
||||
|
||||
* app/dialogs/dialogs-constructors.c: changed accordingly.
|
||||
|
||||
* app/actions/context-actions.c
|
||||
* app/actions/context-commands.[ch]: actions and callbacks which
|
||||
use the new functions.
|
||||
|
||||
2006-05-28 Akkana Peck <akkana@cvs.gnome.org>
|
||||
|
||||
* plug-ins/script-fu/scripts/reverse-layers.scm: revert
|
||||
|
|
|
@ -74,6 +74,198 @@ static const GimpActionEntry context_actions[] =
|
|||
GIMP_HELP_TOOLBOX_SWAP_COLORS }
|
||||
};
|
||||
|
||||
static GimpEnumActionEntry context_palette_foreground_actions[] =
|
||||
{
|
||||
{ "context-palette-foreground-set", GIMP_STOCK_PALETTE,
|
||||
"Foreground Palette color Set", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_SET, FALSE,
|
||||
NULL },
|
||||
{ "context-palette-foreground-first", GIMP_STOCK_PALETTE,
|
||||
"Foreground Palette color First", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_FIRST, FALSE,
|
||||
NULL },
|
||||
{ "context-palette-foreground-last", GIMP_STOCK_PALETTE,
|
||||
"Foreground Palette color Last", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_LAST, FALSE,
|
||||
NULL },
|
||||
{ "context-palette-foreground-previous", GIMP_STOCK_PALETTE,
|
||||
"Foreground Palette color Previous", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_PREVIOUS, FALSE,
|
||||
NULL },
|
||||
{ "context-palette-foreground-next", GIMP_STOCK_PALETTE,
|
||||
"Foreground Palette color Next", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_NEXT, FALSE,
|
||||
NULL },
|
||||
{ "context-palette-foreground-previous-skip", GIMP_STOCK_PALETTE,
|
||||
"Foreground Palette color Skip Back", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_SKIP_PREVIOUS, FALSE,
|
||||
NULL },
|
||||
{ "context-palette-foreground-next-skip", GIMP_STOCK_PALETTE,
|
||||
"Foreground Palette color Skip Forward", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_SKIP_NEXT, FALSE,
|
||||
NULL }
|
||||
};
|
||||
|
||||
static GimpEnumActionEntry context_palette_background_actions[] =
|
||||
{
|
||||
{ "context-palette-background-set", GIMP_STOCK_PALETTE,
|
||||
"Background Palette color Set", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_SET, FALSE,
|
||||
NULL },
|
||||
{ "context-palette-background-first", GIMP_STOCK_PALETTE,
|
||||
"Background Palette color First", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_FIRST, FALSE,
|
||||
NULL },
|
||||
{ "context-palette-background-last", GIMP_STOCK_PALETTE,
|
||||
"Background Palette color Last", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_LAST, FALSE,
|
||||
NULL },
|
||||
{ "context-palette-background-previous", GIMP_STOCK_PALETTE,
|
||||
"Background Palette color Previous", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_PREVIOUS, FALSE,
|
||||
NULL },
|
||||
{ "context-palette-background-next", GIMP_STOCK_PALETTE,
|
||||
"Background Palette color Next", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_NEXT, FALSE,
|
||||
NULL },
|
||||
{ "context-palette-background-previous-skip", GIMP_STOCK_PALETTE,
|
||||
"Background Palette color Skip Back", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_SKIP_PREVIOUS, FALSE,
|
||||
NULL },
|
||||
{ "context-palette-background-next-skip", GIMP_STOCK_PALETTE,
|
||||
"Background Palette color Skip ahead", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_SKIP_NEXT, FALSE,
|
||||
NULL }
|
||||
};
|
||||
|
||||
static GimpEnumActionEntry context_colormap_foreground_actions[] =
|
||||
{
|
||||
{ "context-colormap-foreground-set", GIMP_STOCK_INDEXED_PALETTE,
|
||||
"Foreground Colormap color Set", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_SET, FALSE,
|
||||
NULL },
|
||||
{ "context-colormap-foreground-first", GIMP_STOCK_INDEXED_PALETTE,
|
||||
"Foreground Colormap color First", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_FIRST, FALSE,
|
||||
NULL },
|
||||
{ "context-colormap-foreground-last", GIMP_STOCK_INDEXED_PALETTE,
|
||||
"Foreground Colormap color Last", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_LAST, FALSE,
|
||||
NULL },
|
||||
{ "context-colormap-foreground-previous", GIMP_STOCK_INDEXED_PALETTE,
|
||||
"Foreground Colormap color Previous", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_PREVIOUS, FALSE,
|
||||
NULL },
|
||||
{ "context-colormap-foreground-next", GIMP_STOCK_INDEXED_PALETTE,
|
||||
"Foreground Colormap color Next", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_NEXT, FALSE,
|
||||
NULL },
|
||||
{ "context-colormap-foreground-previous-skip", GIMP_STOCK_INDEXED_PALETTE,
|
||||
"Foreground Colormap color Skip Back", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_SKIP_PREVIOUS, FALSE,
|
||||
NULL },
|
||||
{ "context-colormap-foreground-next-skip", GIMP_STOCK_INDEXED_PALETTE,
|
||||
"Foreground Colormap color Skip Forward", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_SKIP_NEXT, FALSE,
|
||||
NULL }
|
||||
};
|
||||
|
||||
static GimpEnumActionEntry context_colormap_background_actions[] =
|
||||
{
|
||||
{ "context-colormap-background-set", GIMP_STOCK_INDEXED_PALETTE,
|
||||
"Background Colormap color Set", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_SET, FALSE,
|
||||
NULL },
|
||||
{ "context-colormap-background-first", GIMP_STOCK_INDEXED_PALETTE,
|
||||
"Background Colormap color First", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_FIRST, FALSE,
|
||||
NULL },
|
||||
{ "context-colormap-background-last", GIMP_STOCK_INDEXED_PALETTE,
|
||||
"Background Colormap color Last", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_LAST, FALSE,
|
||||
NULL },
|
||||
{ "context-colormap-background-previous", GIMP_STOCK_INDEXED_PALETTE,
|
||||
"Background Colormap color Previous", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_PREVIOUS, FALSE,
|
||||
NULL },
|
||||
{ "context-colormap-background-next", GIMP_STOCK_INDEXED_PALETTE,
|
||||
"Background Colormap color Next", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_NEXT, FALSE,
|
||||
NULL },
|
||||
{ "context-colormap-background-previous-skip", GIMP_STOCK_INDEXED_PALETTE,
|
||||
"Background Colormap color Skip Back", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_SKIP_PREVIOUS, FALSE,
|
||||
NULL },
|
||||
{ "context-colormap-background-next-skip", GIMP_STOCK_INDEXED_PALETTE,
|
||||
"Background Colormap color Skip ahead", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_SKIP_NEXT, FALSE,
|
||||
NULL }
|
||||
};
|
||||
|
||||
static GimpEnumActionEntry context_swatch_foreground_actions[] =
|
||||
{
|
||||
{ "context-swatch-foreground-set", GIMP_STOCK_PALETTE,
|
||||
"Foreground Swatch color Set", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_SET, FALSE,
|
||||
NULL },
|
||||
{ "context-swatch-foreground-first", GIMP_STOCK_PALETTE,
|
||||
"Foreground Swatch color First", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_FIRST, FALSE,
|
||||
NULL },
|
||||
{ "context-swatch-foreground-last", GIMP_STOCK_PALETTE,
|
||||
"Foreground Swatch color Last", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_LAST, FALSE,
|
||||
NULL },
|
||||
{ "context-swatch-foreground-previous", GIMP_STOCK_PALETTE,
|
||||
"Foreground Swatch color Previous", "9", NULL,
|
||||
GIMP_ACTION_SELECT_PREVIOUS, FALSE,
|
||||
NULL },
|
||||
{ "context-swatch-foreground-next", GIMP_STOCK_PALETTE,
|
||||
"Foreground Swatch color Next", "0", NULL,
|
||||
GIMP_ACTION_SELECT_NEXT, FALSE,
|
||||
NULL },
|
||||
{ "context-swatch-foreground-previous-skip", GIMP_STOCK_PALETTE,
|
||||
"Foreground Swatch color Skip Back", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_SKIP_PREVIOUS, FALSE,
|
||||
NULL },
|
||||
{ "context-swatch-foreground-next-skip", GIMP_STOCK_PALETTE,
|
||||
"Foreground Swatch color Skip Forward", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_SKIP_NEXT, FALSE,
|
||||
NULL }
|
||||
};
|
||||
|
||||
static GimpEnumActionEntry context_swatch_background_actions[] =
|
||||
{
|
||||
{ "context-swatch-background-set", GIMP_STOCK_PALETTE,
|
||||
"Background Swatch color Set", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_SET, FALSE,
|
||||
NULL },
|
||||
{ "context-swatch-background-first", GIMP_STOCK_PALETTE,
|
||||
"Background Swatch color First", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_FIRST, FALSE,
|
||||
NULL },
|
||||
{ "context-swatch-background-last", GIMP_STOCK_PALETTE,
|
||||
"Background Swatch color Last", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_LAST, FALSE,
|
||||
NULL },
|
||||
{ "context-swatch-background-previous", GIMP_STOCK_PALETTE,
|
||||
"Background Swatch color Previous", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_PREVIOUS, FALSE,
|
||||
NULL },
|
||||
{ "context-swatch-background-next", GIMP_STOCK_PALETTE,
|
||||
"Background Swatch color Next", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_NEXT, FALSE,
|
||||
NULL },
|
||||
{ "context-swatch-background-previous-skip", GIMP_STOCK_PALETTE,
|
||||
"Background Swatch color Skip Back", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_SKIP_PREVIOUS, FALSE,
|
||||
NULL },
|
||||
{ "context-swatch-background-next-skip", GIMP_STOCK_PALETTE,
|
||||
"Background Swatch color Skip ahead", NULL, NULL,
|
||||
GIMP_ACTION_SELECT_SKIP_NEXT, FALSE,
|
||||
NULL }
|
||||
};
|
||||
|
||||
static const GimpEnumActionEntry context_foreground_red_actions[] =
|
||||
{
|
||||
{ "context-foreground-red-set", GIMP_STOCK_CHANNEL_RED,
|
||||
|
@ -838,6 +1030,34 @@ context_actions_setup (GimpActionGroup *group)
|
|||
context_actions,
|
||||
G_N_ELEMENTS (context_actions));
|
||||
|
||||
gimp_action_group_add_enum_actions (group,
|
||||
context_palette_foreground_actions,
|
||||
G_N_ELEMENTS (context_palette_foreground_actions),
|
||||
G_CALLBACK (context_palette_foreground_cmd_callback));
|
||||
gimp_action_group_add_enum_actions (group,
|
||||
context_palette_background_actions,
|
||||
G_N_ELEMENTS (context_palette_background_actions),
|
||||
G_CALLBACK (context_palette_background_cmd_callback));
|
||||
|
||||
gimp_action_group_add_enum_actions (group,
|
||||
context_colormap_foreground_actions,
|
||||
G_N_ELEMENTS (context_colormap_foreground_actions),
|
||||
G_CALLBACK (context_colormap_foreground_cmd_callback));
|
||||
gimp_action_group_add_enum_actions (group,
|
||||
context_colormap_background_actions,
|
||||
G_N_ELEMENTS (context_colormap_background_actions),
|
||||
G_CALLBACK (context_colormap_background_cmd_callback));
|
||||
|
||||
gimp_action_group_add_enum_actions (group,
|
||||
context_swatch_foreground_actions,
|
||||
G_N_ELEMENTS (context_swatch_foreground_actions),
|
||||
G_CALLBACK (context_swatch_foreground_cmd_callback));
|
||||
gimp_action_group_add_enum_actions (group,
|
||||
context_swatch_background_actions,
|
||||
G_N_ELEMENTS (context_swatch_background_actions),
|
||||
G_CALLBACK (context_swatch_background_cmd_callback));
|
||||
|
||||
|
||||
gimp_action_group_add_enum_actions (group,
|
||||
context_foreground_red_actions,
|
||||
G_N_ELEMENTS (context_foreground_red_actions),
|
||||
|
|
|
@ -33,6 +33,11 @@
|
|||
#include "core/gimpdatafactory.h"
|
||||
#include "core/gimplist.h"
|
||||
|
||||
#include "widgets/gimpdialogfactory.h"
|
||||
#include "widgets/gimpsessioninfo.h"
|
||||
#include "widgets/gimppaletteeditor.h"
|
||||
#include "widgets/gimpcolormapeditor.h"
|
||||
|
||||
#include "actions.h"
|
||||
#include "context-commands.h"
|
||||
|
||||
|
@ -64,12 +69,31 @@ static const GimpLayerModeEffects paint_modes[] =
|
|||
GIMP_VALUE_MODE
|
||||
};
|
||||
|
||||
|
||||
/* local function prototypes */
|
||||
|
||||
static void context_select_object (GimpActionSelectType select_type,
|
||||
GimpContext *context,
|
||||
GimpContainer *container);
|
||||
static gint context_paint_mode_index (GimpLayerModeEffects paint_mode);
|
||||
static void context_select_object (GimpActionSelectType select_type,
|
||||
GimpContext *context,
|
||||
GimpContainer *container);
|
||||
static gint context_paint_mode_index (GimpLayerModeEffects paint_mode);
|
||||
|
||||
static void context_select_color (GimpActionSelectType select_type,
|
||||
GimpRGB *color,
|
||||
gboolean use_colormap,
|
||||
gboolean use_palette);
|
||||
|
||||
static gint context_get_color_index (gboolean use_colormap,
|
||||
gboolean use_palette,
|
||||
const GimpRGB *color);
|
||||
static gint context_max_color_index (gboolean use_colormap,
|
||||
gboolean use_palette);
|
||||
static gboolean context_set_color_index (gint index,
|
||||
gboolean use_colormap,
|
||||
gboolean use_palette,
|
||||
GimpRGB *color);
|
||||
|
||||
static GimpPaletteEditor * context_get_palette_editor (void);
|
||||
static GimpColormapEditor * context_get_colormap_editor (void);
|
||||
|
||||
|
||||
/* public functions */
|
||||
|
@ -94,6 +118,29 @@ context_colors_swap_cmd_callback (GtkAction *action,
|
|||
gimp_context_swap_colors (context);
|
||||
}
|
||||
|
||||
#define SELECT_COLOR_CMD_CALLBACK(name, fgbg, usec, usep) \
|
||||
void \
|
||||
context_##name##_##fgbg##ground_cmd_callback (GtkAction *action, \
|
||||
gint value, \
|
||||
gpointer data) \
|
||||
{ \
|
||||
GimpRGB color; \
|
||||
GimpContext *context; \
|
||||
return_if_no_context (context, data); \
|
||||
\
|
||||
gimp_context_get_##fgbg##ground (context, &color); \
|
||||
context_select_color ((GimpActionSelectType) value, &color, usec, usep); \
|
||||
gimp_context_set_##fgbg##ground (context, &color); \
|
||||
\
|
||||
}
|
||||
|
||||
SELECT_COLOR_CMD_CALLBACK (palette, fore, FALSE, TRUE)
|
||||
SELECT_COLOR_CMD_CALLBACK (palette, back, FALSE, TRUE)
|
||||
SELECT_COLOR_CMD_CALLBACK (colormap, fore, TRUE, FALSE)
|
||||
SELECT_COLOR_CMD_CALLBACK (colormap, back, TRUE, FALSE)
|
||||
SELECT_COLOR_CMD_CALLBACK (swatch, fore, TRUE, TRUE)
|
||||
SELECT_COLOR_CMD_CALLBACK (swatch, back, TRUE, TRUE)
|
||||
|
||||
void
|
||||
context_foreground_red_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
|
@ -608,3 +655,150 @@ context_paint_mode_index (GimpLayerModeEffects paint_mode)
|
|||
|
||||
return i;
|
||||
}
|
||||
|
||||
static void
|
||||
context_select_color (GimpActionSelectType select_type,
|
||||
GimpRGB *color,
|
||||
gboolean use_colormap,
|
||||
gboolean use_palette)
|
||||
{
|
||||
gint index;
|
||||
gint max;
|
||||
|
||||
index = context_get_color_index (use_colormap, use_palette, color);
|
||||
max = context_max_color_index (use_colormap, use_palette);
|
||||
|
||||
index = action_select_value (select_type, index,
|
||||
0, max,
|
||||
1, 4, FALSE);
|
||||
|
||||
context_set_color_index (index, use_colormap, use_palette, color);
|
||||
}
|
||||
|
||||
static gint
|
||||
context_get_color_index (gboolean use_colormap,
|
||||
gboolean use_palette,
|
||||
const GimpRGB *color)
|
||||
{
|
||||
if (use_colormap)
|
||||
{
|
||||
GimpColormapEditor *editor = context_get_colormap_editor ();
|
||||
|
||||
if (editor)
|
||||
{
|
||||
gint index = gimp_colormap_editor_get_index (editor, color);
|
||||
|
||||
if (index != -1)
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
if (use_palette)
|
||||
{
|
||||
GimpPaletteEditor *editor = context_get_palette_editor ();
|
||||
|
||||
if (editor)
|
||||
{
|
||||
gint index = gimp_palette_editor_get_index (editor, color);
|
||||
|
||||
if (index != -1)
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static gint
|
||||
context_max_color_index (gboolean use_colormap,
|
||||
gboolean use_palette)
|
||||
{
|
||||
if (use_colormap)
|
||||
{
|
||||
GimpColormapEditor *editor = context_get_colormap_editor ();
|
||||
|
||||
if (editor)
|
||||
{
|
||||
gint index = gimp_colormap_editor_max_index (editor);
|
||||
|
||||
if (index != -1)
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
if (use_palette)
|
||||
{
|
||||
GimpPaletteEditor *editor = context_get_palette_editor ();
|
||||
|
||||
if (editor)
|
||||
{
|
||||
gint index = gimp_palette_editor_max_index (editor);
|
||||
|
||||
if (index != -1)
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
context_set_color_index (gint index,
|
||||
gboolean use_colormap,
|
||||
gboolean use_palette,
|
||||
GimpRGB *color)
|
||||
{
|
||||
if (use_colormap)
|
||||
{
|
||||
GimpColormapEditor *editor = context_get_colormap_editor ();
|
||||
|
||||
if (editor && gimp_colormap_editor_set_index (editor, index, color))
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (use_palette)
|
||||
{
|
||||
GimpPaletteEditor *editor = context_get_palette_editor ();
|
||||
|
||||
if (editor && gimp_palette_editor_set_index (editor, index, color))
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static GimpPaletteEditor *
|
||||
context_get_palette_editor (void)
|
||||
{
|
||||
GimpDialogFactory *dialog_factory;
|
||||
GimpSessionInfo *info;
|
||||
|
||||
dialog_factory = gimp_dialog_factory_from_name ("dock");
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_DIALOG_FACTORY (dialog_factory), NULL);
|
||||
|
||||
info = gimp_dialog_factory_find_session_info (dialog_factory,
|
||||
"gimp-palette-editor");
|
||||
if (info && info->widget)
|
||||
return GIMP_PALETTE_EDITOR (gtk_bin_get_child (GTK_BIN (info->widget)));
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static GimpColormapEditor *
|
||||
context_get_colormap_editor (void)
|
||||
{
|
||||
GimpDialogFactory *dialog_factory;
|
||||
GimpSessionInfo *info;
|
||||
|
||||
dialog_factory = gimp_dialog_factory_from_name ("dock");
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_DIALOG_FACTORY (dialog_factory), NULL);
|
||||
|
||||
info = gimp_dialog_factory_find_session_info (dialog_factory,
|
||||
"gimp-indexed-palette");
|
||||
if (info && info->widget)
|
||||
return GIMP_COLORMAP_EDITOR (gtk_bin_get_child (GTK_BIN (info->widget)));
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -20,95 +20,117 @@
|
|||
#define __CONTEXT_COMMANDS_H__
|
||||
|
||||
|
||||
void context_colors_default_cmd_callback (GtkAction *action,
|
||||
gpointer data);
|
||||
void context_colors_swap_cmd_callback (GtkAction *action,
|
||||
gpointer data);
|
||||
|
||||
void context_foreground_red_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_foreground_green_cmd_callback(GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_foreground_blue_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_colors_default_cmd_callback (GtkAction *action,
|
||||
gpointer data);
|
||||
void context_colors_swap_cmd_callback (GtkAction *action,
|
||||
gpointer data);
|
||||
|
||||
void context_background_red_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_background_green_cmd_callback(GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_background_blue_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_palette_foreground_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_palette_background_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
|
||||
void context_foreground_hue_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_colormap_foreground_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_colormap_background_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
|
||||
void context_swatch_foreground_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_swatch_background_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
|
||||
void context_foreground_red_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_foreground_green_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_foreground_blue_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
|
||||
void context_background_red_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_background_green_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_background_blue_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
|
||||
void context_foreground_hue_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_foreground_saturation_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_foreground_value_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_foreground_value_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
|
||||
void context_background_hue_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_background_hue_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_background_saturation_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_background_value_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_background_value_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
|
||||
void context_opacity_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_paint_mode_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_opacity_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_paint_mode_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
|
||||
void context_tool_select_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_brush_select_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_pattern_select_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_palette_select_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_gradient_select_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_font_select_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_tool_select_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_brush_select_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_pattern_select_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_palette_select_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_gradient_select_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_font_select_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
|
||||
void context_brush_shape_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_brush_radius_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_brush_spikes_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_brush_hardness_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_brush_aspect_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_brush_angle_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_brush_shape_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_brush_radius_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_brush_spikes_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_brush_hardness_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_brush_aspect_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
void context_brush_angle_cmd_callback (GtkAction *action,
|
||||
gint value,
|
||||
gpointer data);
|
||||
|
||||
|
||||
#endif /* __CONTEXT_COMMANDS_H__ */
|
||||
|
|
|
@ -710,7 +710,7 @@ dialogs_indexed_palette_selected (GimpColormapEditor *editor,
|
|||
GimpRGB color;
|
||||
gint index;
|
||||
|
||||
index = gimp_colormap_editor_col_index (editor);
|
||||
index = gimp_colormap_editor_get_index (editor, NULL);
|
||||
|
||||
gimp_image_get_colormap_entry (image_editor->image, index, &color);
|
||||
|
||||
|
|
|
@ -63,6 +63,7 @@ enum
|
|||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
#define EPSILON 1e-10
|
||||
|
||||
#define HAVE_COLORMAP(image) \
|
||||
(image != NULL && \
|
||||
|
@ -86,8 +87,6 @@ static void gimp_colormap_editor_draw_cell (GimpColormapEditor *editor,
|
|||
static void gimp_colormap_editor_clear (GimpColormapEditor *editor,
|
||||
gint start_row);
|
||||
static void gimp_colormap_editor_update_entries (GimpColormapEditor *editor);
|
||||
static void gimp_colormap_editor_set_index (GimpColormapEditor *editor,
|
||||
gint i);
|
||||
|
||||
static void gimp_colormap_preview_size_allocate (GtkWidget *widget,
|
||||
GtkAllocation *allocation,
|
||||
|
@ -344,21 +343,98 @@ gimp_colormap_editor_new (GimpMenuFactory *menu_factory)
|
|||
NULL);
|
||||
}
|
||||
|
||||
void
|
||||
gimp_colormap_editor_selected (GimpColormapEditor *editor,
|
||||
GdkModifierType state)
|
||||
gint
|
||||
gimp_colormap_editor_get_index (GimpColormapEditor *editor,
|
||||
const GimpRGB *search)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_COLORMAP_EDITOR (editor));
|
||||
GimpImage *image;
|
||||
gint index;
|
||||
|
||||
g_signal_emit (editor, editor_signals[SELECTED], 0, state);
|
||||
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;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_COLORMAP_EDITOR (editor), FALSE);
|
||||
|
||||
image = GIMP_IMAGE_EDITOR (editor)->image;
|
||||
|
||||
if (! HAVE_COLORMAP (image))
|
||||
return FALSE;
|
||||
|
||||
index = CLAMP (index, 0, gimp_image_get_colormap_size (image) - 1);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
if (color)
|
||||
gimp_image_get_colormap_entry (GIMP_IMAGE_EDITOR (editor)->image,
|
||||
index, color);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gint
|
||||
gimp_colormap_editor_col_index (GimpColormapEditor *editor)
|
||||
gimp_colormap_editor_max_index (GimpColormapEditor *editor)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_COLORMAP_EDITOR (editor), 0);
|
||||
GimpImage *image;
|
||||
|
||||
return editor->col_index;
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -597,24 +673,6 @@ gimp_colormap_editor_update_entries (GimpColormapEditor *editor)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_colormap_editor_set_index (GimpColormapEditor *editor,
|
||||
gint i)
|
||||
{
|
||||
if (i != editor->col_index)
|
||||
{
|
||||
gint old = editor->col_index;
|
||||
|
||||
editor->col_index = i;
|
||||
editor->dnd_col_index = i;
|
||||
|
||||
gimp_colormap_editor_draw_cell (editor, old);
|
||||
gimp_colormap_editor_draw_cell (editor, i);
|
||||
|
||||
gimp_colormap_editor_update_entries (editor);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_colormap_preview_size_allocate (GtkWidget *widget,
|
||||
GtkAllocation *alloc,
|
||||
|
@ -653,8 +711,8 @@ gimp_colormap_preview_button_press (GtkWidget *widget,
|
|||
switch (bevent->button)
|
||||
{
|
||||
case 1:
|
||||
gimp_colormap_editor_set_index (editor, col);
|
||||
gimp_colormap_editor_selected (editor, bevent->state);
|
||||
gimp_colormap_editor_set_index (editor, col, NULL);
|
||||
g_signal_emit (editor, editor_signals[SELECTED], 0, bevent->state);
|
||||
|
||||
if (bevent->type == GDK_2BUTTON_PRESS)
|
||||
{
|
||||
|
@ -674,7 +732,7 @@ gimp_colormap_preview_button_press (GtkWidget *widget,
|
|||
break;
|
||||
|
||||
case 3:
|
||||
gimp_colormap_editor_set_index (editor, col);
|
||||
gimp_colormap_editor_set_index (editor, col, NULL);
|
||||
gimp_editor_popup_menu (GIMP_EDITOR (editor), NULL, NULL);
|
||||
return TRUE;
|
||||
|
||||
|
@ -721,7 +779,7 @@ gimp_colormap_adjustment_changed (GtkAdjustment *adjustment,
|
|||
|
||||
if (HAVE_COLORMAP (image))
|
||||
{
|
||||
gimp_colormap_editor_set_index (editor, adjustment->value + 0.5);
|
||||
gimp_colormap_editor_set_index (editor, adjustment->value + 0.5, NULL);
|
||||
|
||||
gimp_colormap_editor_update_entries (editor);
|
||||
}
|
||||
|
|
|
@ -67,9 +67,13 @@ GType gimp_colormap_editor_get_type (void) G_GNUC_CONST;
|
|||
|
||||
GtkWidget * gimp_colormap_editor_new (GimpMenuFactory *menu_factory);
|
||||
|
||||
void gimp_colormap_editor_selected (GimpColormapEditor *editor,
|
||||
GdkModifierType state);
|
||||
gint gimp_colormap_editor_col_index (GimpColormapEditor *editor);
|
||||
gint gimp_colormap_editor_get_index (GimpColormapEditor *editor,
|
||||
const GimpRGB *search);
|
||||
gboolean gimp_colormap_editor_set_index (GimpColormapEditor *editor,
|
||||
gint index,
|
||||
GimpRGB *color);
|
||||
|
||||
gint gimp_colormap_editor_max_index (GimpColormapEditor *editor);
|
||||
|
||||
|
||||
#endif /* __GIMP_COLORMAP_EDITOR_H__ */
|
||||
|
|
|
@ -56,6 +56,7 @@
|
|||
#define PREVIEW_WIDTH ((ENTRY_WIDTH + SPACING) * COLUMNS + 1)
|
||||
#define PREVIEW_HEIGHT ((ENTRY_HEIGHT + SPACING) * ROWS + 1)
|
||||
|
||||
#define EPSILON 1e-10
|
||||
|
||||
/* local function prototypes */
|
||||
|
||||
|
@ -544,6 +545,89 @@ gimp_palette_editor_zoom (GimpPaletteEditor *editor,
|
|||
palette_editor_scroll_top_left (editor);
|
||||
}
|
||||
|
||||
gint
|
||||
gimp_palette_editor_get_index (GimpPaletteEditor *editor,
|
||||
const GimpRGB *search)
|
||||
{
|
||||
GimpPalette *palette;
|
||||
gint index = 0;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_PALETTE_EDITOR (editor), -1);
|
||||
|
||||
palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data);
|
||||
|
||||
if (! palette)
|
||||
return -1;
|
||||
|
||||
if (editor->color)
|
||||
index = editor->color->position;
|
||||
|
||||
if (search)
|
||||
{
|
||||
if (! editor->color ||
|
||||
gimp_rgb_distance (&editor->color->color, search) > EPSILON)
|
||||
{
|
||||
GList *list;
|
||||
|
||||
for (list = palette->colors; list; list = g_list_next (list))
|
||||
{
|
||||
GimpPaletteEntry *entry = list->data;
|
||||
|
||||
if (gimp_rgb_distance (&entry->color, search) < EPSILON)
|
||||
{
|
||||
index = entry->position;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gimp_palette_editor_set_index (GimpPaletteEditor *editor,
|
||||
gint index,
|
||||
GimpRGB *color)
|
||||
{
|
||||
GimpPalette *palette;
|
||||
GList *list;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_PALETTE_EDITOR (editor), FALSE);
|
||||
|
||||
palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data);
|
||||
|
||||
if (! palette)
|
||||
return FALSE;
|
||||
|
||||
index = CLAMP (index, 0, palette->n_colors - 1);
|
||||
|
||||
list = g_list_nth (palette->colors, index);
|
||||
|
||||
gimp_palette_view_select_entry (GIMP_PALETTE_VIEW (editor->view),
|
||||
list->data);
|
||||
|
||||
if (color)
|
||||
*color = editor->color->color;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gint
|
||||
gimp_palette_editor_max_index (GimpPaletteEditor *editor)
|
||||
{
|
||||
GimpPalette *palette;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_PALETTE_EDITOR (editor), -1);
|
||||
|
||||
palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data);
|
||||
|
||||
if (! palette)
|
||||
return -1;
|
||||
|
||||
return MAX (0, palette->n_colors - 1);
|
||||
}
|
||||
|
||||
|
||||
/* private functions */
|
||||
|
||||
|
|
|
@ -70,5 +70,13 @@ void gimp_palette_editor_pick_color (GimpPaletteEditor *editor,
|
|||
void gimp_palette_editor_zoom (GimpPaletteEditor *editor,
|
||||
GimpZoomType zoom_type);
|
||||
|
||||
gint gimp_palette_editor_get_index (GimpPaletteEditor *editor,
|
||||
const GimpRGB *search);
|
||||
gboolean gimp_palette_editor_set_index (GimpPaletteEditor *editor,
|
||||
gint index,
|
||||
GimpRGB *color);
|
||||
|
||||
gint gimp_palette_editor_max_index (GimpPaletteEditor *editor);
|
||||
|
||||
|
||||
#endif /* __GIMP_PALETTE_EDITOR_H__ */
|
||||
|
|
Loading…
Reference in New Issue