added VOID: ENUM, BOXED, INT.
2003-06-04 Sven Neumann <sven@gimp.org> * app/core/gimpmarshal.list: added VOID: ENUM, BOXED, INT. * app/tools/gimpcolortool.[ch]: added a default implementation for GimpColorTool::pick. Emit a "picked" signal when a color was successfully picked. * app/tools/gimpcolorpickertool.c: simplified a lot since GimpColorTool does most of the work for us now.
This commit is contained in:
parent
a014c9d0d3
commit
b108d7028b
5 changed files with 279 additions and 357 deletions
11
ChangeLog
11
ChangeLog
|
|
@ -1,3 +1,14 @@
|
|||
2003-06-04 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* app/core/gimpmarshal.list: added VOID: ENUM, BOXED, INT.
|
||||
|
||||
* app/tools/gimpcolortool.[ch]: added a default implementation for
|
||||
GimpColorTool::pick. Emit a "picked" signal when a color was
|
||||
successfully picked.
|
||||
|
||||
* app/tools/gimpcolorpickertool.c: simplified a lot since
|
||||
GimpColorTool does most of the work for us now.
|
||||
|
||||
2003-06-04 Michael Natterer <mitch@gimp.org>
|
||||
|
||||
* app/display/gimpdisplayshell-callbacks.c
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ VOID: BOXED
|
|||
VOID: DOUBLE
|
||||
VOID: DOUBLE, DOUBLE
|
||||
VOID: ENUM
|
||||
VOID: ENUM, BOXED, INT
|
||||
VOID: ENUM, OBJECT
|
||||
VOID: ENUM, POINTER
|
||||
VOID: FLAGS
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@
|
|||
#include "core/gimp.h"
|
||||
#include "core/gimpdrawable.h"
|
||||
#include "core/gimpimage.h"
|
||||
#include "core/gimpimage-pick-color.h"
|
||||
#include "core/gimptoolinfo.h"
|
||||
|
||||
#include "widgets/gimpdialogfactory.h"
|
||||
|
|
@ -57,57 +56,37 @@
|
|||
|
||||
/* local function prototypes */
|
||||
|
||||
static void gimp_color_picker_tool_class_init (GimpColorPickerToolClass *klass);
|
||||
static void gimp_color_picker_tool_init (GimpColorPickerTool *color_picker_tool);
|
||||
static void gimp_color_picker_tool_class_init (GimpColorPickerToolClass *klass);
|
||||
static void gimp_color_picker_tool_init (GimpColorPickerTool *tool);
|
||||
|
||||
static void gimp_color_picker_tool_finalize (GObject *object);
|
||||
static void gimp_color_picker_tool_finalize (GObject *object);
|
||||
|
||||
static void gimp_color_picker_tool_control (GimpTool *tool,
|
||||
GimpToolAction action,
|
||||
GimpDisplay *gdisp);
|
||||
static void gimp_color_picker_tool_button_press (GimpTool *tool,
|
||||
GimpCoords *coords,
|
||||
guint32 time,
|
||||
GdkModifierType state,
|
||||
GimpDisplay *gdisp);
|
||||
static void gimp_color_picker_tool_button_release (GimpTool *tool,
|
||||
GimpCoords *coords,
|
||||
guint32 time,
|
||||
GdkModifierType state,
|
||||
GimpDisplay *gdisp);
|
||||
static void gimp_color_picker_tool_motion (GimpTool *tool,
|
||||
GimpCoords *coords,
|
||||
guint32 time,
|
||||
GdkModifierType state,
|
||||
GimpDisplay *gdisp);
|
||||
static gboolean gimp_color_picker_tool_pick (GimpColorTool *tool,
|
||||
GimpColorOptions *options,
|
||||
GimpDisplay *display,
|
||||
gint x,
|
||||
gint y);
|
||||
static void gimp_color_picker_tool_control (GimpTool *tool,
|
||||
GimpToolAction action,
|
||||
GimpDisplay *gdisp);
|
||||
static void gimp_color_picker_tool_picked (GimpColorTool *color_tool,
|
||||
GimpImageType sample_type,
|
||||
GimpRGB *color,
|
||||
gint color_index);
|
||||
|
||||
static InfoDialog * gimp_color_picker_tool_info_create (GimpToolInfo *tool_info,
|
||||
GimpDrawable *drawable);
|
||||
static void gimp_color_picker_tool_info_close (GtkWidget *widget,
|
||||
gpointer data);
|
||||
static void gimp_color_picker_tool_info_update (GimpTool *tool,
|
||||
gboolean valid);
|
||||
static InfoDialog * gimp_color_picker_tool_info_create (GimpTool *tool);
|
||||
static void gimp_color_picker_tool_info_close (GtkWidget *widget,
|
||||
gpointer data);
|
||||
static void gimp_color_picker_tool_info_update (GimpImageType sample_type,
|
||||
GimpRGB *color,
|
||||
gint color_index);
|
||||
|
||||
|
||||
static gint col_value[5] = { 0, 0, 0, 0, 0 };
|
||||
static GimpUpdateColorState update_type;
|
||||
static GimpImageType sample_type;
|
||||
static InfoDialog *gimp_color_picker_tool_info = NULL;
|
||||
static GtkWidget *color_area = NULL;
|
||||
static gchar red_buf [MAX_INFO_BUF];
|
||||
static gchar green_buf[MAX_INFO_BUF];
|
||||
static gchar blue_buf [MAX_INFO_BUF];
|
||||
static gchar alpha_buf[MAX_INFO_BUF];
|
||||
static gchar index_buf[MAX_INFO_BUF];
|
||||
static gchar gray_buf [MAX_INFO_BUF];
|
||||
static gchar hex_buf [MAX_INFO_BUF];
|
||||
static InfoDialog *gimp_color_picker_tool_info = NULL;
|
||||
static GtkWidget *color_area = NULL;
|
||||
static gchar red_buf [MAX_INFO_BUF];
|
||||
static gchar green_buf[MAX_INFO_BUF];
|
||||
static gchar blue_buf [MAX_INFO_BUF];
|
||||
static gchar alpha_buf[MAX_INFO_BUF];
|
||||
static gchar index_buf[MAX_INFO_BUF];
|
||||
static gchar hex_buf [MAX_INFO_BUF];
|
||||
|
||||
static GimpColorToolClass *parent_class = NULL;
|
||||
static GimpColorToolClass *parent_class = NULL;
|
||||
|
||||
|
||||
void
|
||||
|
|
@ -168,22 +147,20 @@ gimp_color_picker_tool_class_init (GimpColorPickerToolClass *klass)
|
|||
|
||||
parent_class = g_type_class_peek_parent (klass);
|
||||
|
||||
object_class->finalize = gimp_color_picker_tool_finalize;
|
||||
object_class->finalize = gimp_color_picker_tool_finalize;
|
||||
|
||||
tool_class->control = gimp_color_picker_tool_control;
|
||||
tool_class->button_press = gimp_color_picker_tool_button_press;
|
||||
tool_class->button_release = gimp_color_picker_tool_button_release;
|
||||
tool_class->motion = gimp_color_picker_tool_motion;
|
||||
tool_class->control = gimp_color_picker_tool_control;
|
||||
|
||||
color_tool_class->pick = gimp_color_picker_tool_pick;
|
||||
color_tool_class->picked = gimp_color_picker_tool_picked;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_color_picker_tool_init (GimpColorPickerTool *color_picker_tool)
|
||||
gimp_color_picker_tool_init (GimpColorPickerTool *tool)
|
||||
{
|
||||
GimpTool *tool = GIMP_TOOL (color_picker_tool);
|
||||
gimp_tool_control_set_preserve (GIMP_TOOL (tool)->control, FALSE);
|
||||
|
||||
gimp_tool_control_set_preserve (tool->control, FALSE);
|
||||
/* always pick colors */
|
||||
gimp_color_tool_enable (GIMP_COLOR_TOOL (tool), TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -209,7 +186,10 @@ gimp_color_picker_tool_control (GimpTool *tool,
|
|||
{
|
||||
case HALT:
|
||||
if (gimp_color_picker_tool_info)
|
||||
info_dialog_popdown (gimp_color_picker_tool_info);
|
||||
{
|
||||
info_dialog_free (gimp_color_picker_tool_info);
|
||||
gimp_color_picker_tool_info = NULL;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
@ -220,165 +200,56 @@ gimp_color_picker_tool_control (GimpTool *tool,
|
|||
}
|
||||
|
||||
static void
|
||||
gimp_color_picker_tool_button_press (GimpTool *tool,
|
||||
GimpCoords *coords,
|
||||
guint32 time,
|
||||
GdkModifierType state,
|
||||
GimpDisplay *gdisp)
|
||||
gimp_color_picker_tool_picked (GimpColorTool *color_tool,
|
||||
GimpImageType sample_type,
|
||||
GimpRGB *color,
|
||||
gint color_index)
|
||||
{
|
||||
GimpColorPickerTool *cp_tool;
|
||||
GimpColorOptions *options;
|
||||
GimpTool *tool;
|
||||
GimpColorPickerOptions *options;
|
||||
|
||||
GIMP_TOOL_CLASS (parent_class)->button_press (tool,
|
||||
coords, time, state, gdisp);
|
||||
|
||||
cp_tool = GIMP_COLOR_PICKER_TOOL (tool);
|
||||
options = GIMP_COLOR_OPTIONS (tool->tool_info->tool_options);
|
||||
tool = GIMP_TOOL (color_tool);
|
||||
|
||||
if (! gimp_color_picker_tool_info)
|
||||
gimp_color_picker_tool_info =
|
||||
gimp_color_picker_tool_info_create (tool->tool_info,
|
||||
tool->drawable);
|
||||
gimp_color_picker_tool_info = gimp_color_picker_tool_info_create (tool);
|
||||
|
||||
gimp_viewable_dialog_set_viewable (GIMP_VIEWABLE_DIALOG (gimp_color_picker_tool_info->shell),
|
||||
GIMP_VIEWABLE (tool->drawable));
|
||||
gimp_color_picker_tool_info_update (sample_type, color, color_index);
|
||||
|
||||
gimp_color_picker_tool_info_update (tool,
|
||||
gimp_color_tool_pick (GIMP_COLOR_TOOL (tool),
|
||||
options,
|
||||
gdisp,
|
||||
coords->x,
|
||||
coords->y));
|
||||
|
||||
/* if the shift key is down, create a new color.
|
||||
* otherwise, modify the current color.
|
||||
*/
|
||||
if (state & GDK_SHIFT_MASK)
|
||||
options = GIMP_COLOR_PICKER_OPTIONS (tool->tool_info->tool_options);
|
||||
|
||||
if (options->update_active)
|
||||
{
|
||||
update_type = GIMP_UPDATE_COLOR_STATE_UPDATE_NEW;
|
||||
}
|
||||
else
|
||||
{
|
||||
update_type = GIMP_UPDATE_COLOR_STATE_UPDATE;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_color_picker_tool_button_release (GimpTool *tool,
|
||||
GimpCoords *coords,
|
||||
guint32 time,
|
||||
GdkModifierType state,
|
||||
GimpDisplay *gdisp)
|
||||
{
|
||||
GimpColorPickerTool *cp_tool;
|
||||
GimpColorOptions *options;
|
||||
|
||||
cp_tool = GIMP_COLOR_PICKER_TOOL(tool);
|
||||
options = GIMP_COLOR_OPTIONS (tool->tool_info->tool_options);
|
||||
|
||||
gimp_color_picker_tool_info_update (tool,
|
||||
gimp_color_tool_pick (GIMP_COLOR_TOOL (tool),
|
||||
options,
|
||||
gdisp,
|
||||
coords->x,
|
||||
coords->y));
|
||||
|
||||
GIMP_TOOL_CLASS (parent_class)->button_release (tool,
|
||||
coords, time, state, gdisp);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_color_picker_tool_motion (GimpTool *tool,
|
||||
GimpCoords *coords,
|
||||
guint32 time,
|
||||
GdkModifierType state,
|
||||
GimpDisplay *gdisp)
|
||||
{
|
||||
GimpColorPickerTool *cp_tool;
|
||||
GimpColorOptions *options;
|
||||
|
||||
GIMP_TOOL_CLASS (parent_class)->motion (tool, coords, time, state, gdisp);
|
||||
|
||||
cp_tool = GIMP_COLOR_PICKER_TOOL (tool);
|
||||
options = GIMP_COLOR_OPTIONS (tool->tool_info->tool_options);
|
||||
|
||||
gimp_color_picker_tool_info_update (tool,
|
||||
gimp_color_tool_pick (GIMP_COLOR_TOOL (tool),
|
||||
options,
|
||||
gdisp,
|
||||
coords->x,
|
||||
coords->y));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gimp_color_picker_tool_pick (GimpColorTool *tool,
|
||||
GimpColorOptions *options,
|
||||
GimpDisplay *gdisp,
|
||||
gint x,
|
||||
gint y)
|
||||
{
|
||||
GimpRGB color;
|
||||
gint color_index;
|
||||
gboolean success;
|
||||
|
||||
success = gimp_image_pick_color (gdisp->gimage,
|
||||
GIMP_TOOL (tool)->drawable,
|
||||
options->sample_merged,
|
||||
x, y,
|
||||
options->sample_average,
|
||||
options->average_radius,
|
||||
&sample_type,
|
||||
&color,
|
||||
&color_index);
|
||||
|
||||
if (success)
|
||||
{
|
||||
guchar r, g, b, a;
|
||||
|
||||
gimp_rgba_get_uchar (&color, &r, &g, &b, &a);
|
||||
|
||||
col_value[RED_PIX] = r;
|
||||
col_value[GREEN_PIX] = g;
|
||||
col_value[BLUE_PIX] = b;
|
||||
col_value[ALPHA_PIX] = a;
|
||||
col_value[4] = color_index;
|
||||
|
||||
if (GIMP_COLOR_PICKER_OPTIONS (options)->update_active)
|
||||
{
|
||||
GimpContext *user_context;
|
||||
|
||||
user_context = gimp_get_user_context (gdisp->gimage->gimp);
|
||||
|
||||
GimpContext *user_context;
|
||||
|
||||
user_context = gimp_get_user_context (tool->gdisp->gimage->gimp);
|
||||
|
||||
#if 0
|
||||
gimp_palette_editor_update_color (user_context,
|
||||
&color, update_state);
|
||||
gimp_palette_editor_update_color (user_context, color, update_state);
|
||||
#endif
|
||||
|
||||
if (active_color == FOREGROUND)
|
||||
gimp_context_set_foreground (user_context, &color);
|
||||
else if (active_color == BACKGROUND)
|
||||
gimp_context_set_background (user_context, &color);
|
||||
}
|
||||
if (active_color == FOREGROUND)
|
||||
gimp_context_set_foreground (user_context, color);
|
||||
else if (active_color == BACKGROUND)
|
||||
gimp_context_set_background (user_context, color);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
static InfoDialog *
|
||||
gimp_color_picker_tool_info_create (GimpToolInfo *tool_info,
|
||||
GimpDrawable *drawable)
|
||||
gimp_color_picker_tool_info_create (GimpTool *tool)
|
||||
{
|
||||
InfoDialog *info_dialog;
|
||||
GtkWidget *hbox;
|
||||
GtkWidget *frame;
|
||||
GimpRGB color;
|
||||
|
||||
g_return_val_if_fail (tool->drawable != NULL, NULL);
|
||||
|
||||
info_dialog = info_dialog_new (NULL,
|
||||
_("Color Picker"), "color_picker",
|
||||
GIMP_STOCK_TOOL_COLOR_PICKER,
|
||||
_("Color Picker Information"),
|
||||
gimp_standard_help_func,
|
||||
tool_info->help_data);
|
||||
tool->tool_info->help_data);
|
||||
|
||||
gimp_dialog_create_action_area (GIMP_DIALOG (info_dialog->shell),
|
||||
|
||||
|
|
@ -389,7 +260,7 @@ gimp_color_picker_tool_info_create (GimpToolInfo *tool_info,
|
|||
NULL);
|
||||
|
||||
/* if the gdisplay is for a color image, the dialog must have RGB */
|
||||
switch (GIMP_IMAGE_TYPE_BASE_TYPE (gimp_drawable_type (drawable)))
|
||||
switch (GIMP_IMAGE_TYPE_BASE_TYPE (gimp_drawable_type (tool->drawable)))
|
||||
{
|
||||
case GIMP_RGB:
|
||||
info_dialog_add_label (info_dialog, _("Red:"), red_buf);
|
||||
|
|
@ -400,7 +271,7 @@ gimp_color_picker_tool_info_create (GimpToolInfo *tool_info,
|
|||
break;
|
||||
|
||||
case GIMP_GRAY:
|
||||
info_dialog_add_label (info_dialog, _("Intensity:"), gray_buf);
|
||||
info_dialog_add_label (info_dialog, _("Intensity:"), red_buf);
|
||||
info_dialog_add_label (info_dialog, _("Alpha:"), alpha_buf);
|
||||
info_dialog_add_label (info_dialog, _("Hex Triplet:"), hex_buf);
|
||||
break;
|
||||
|
|
@ -431,7 +302,7 @@ gimp_color_picker_tool_info_create (GimpToolInfo *tool_info,
|
|||
|
||||
gimp_rgba_set (&color, 0.0, 0.0, 0.0, 0.0);
|
||||
color_area = gimp_color_area_new (&color,
|
||||
gimp_drawable_has_alpha (drawable) ?
|
||||
gimp_drawable_has_alpha (tool->drawable) ?
|
||||
GIMP_COLOR_AREA_LARGE_CHECKS :
|
||||
GIMP_COLOR_AREA_FLAT,
|
||||
GDK_BUTTON1_MASK | GDK_BUTTON2_MASK);
|
||||
|
|
@ -445,6 +316,9 @@ gimp_color_picker_tool_info_create (GimpToolInfo *tool_info,
|
|||
"gimp-color-picker-tool-dialog",
|
||||
info_dialog->shell);
|
||||
|
||||
gimp_viewable_dialog_set_viewable (GIMP_VIEWABLE_DIALOG (info_dialog->shell),
|
||||
GIMP_VIEWABLE (tool->drawable));
|
||||
|
||||
return info_dialog;
|
||||
}
|
||||
|
||||
|
|
@ -452,105 +326,44 @@ static void
|
|||
gimp_color_picker_tool_info_close (GtkWidget *widget,
|
||||
gpointer client_data)
|
||||
{
|
||||
info_dialog_popdown ((InfoDialog *) client_data);
|
||||
info_dialog_free (gimp_color_picker_tool_info);
|
||||
gimp_color_picker_tool_info = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_color_picker_tool_info_update (GimpTool *tool,
|
||||
gboolean valid)
|
||||
gimp_color_picker_tool_info_update (GimpImageType sample_type,
|
||||
GimpRGB *color,
|
||||
gint color_index)
|
||||
{
|
||||
if (!valid)
|
||||
{
|
||||
if (GTK_WIDGET_IS_SENSITIVE (color_area))
|
||||
gtk_widget_set_sensitive (color_area, FALSE);
|
||||
guchar r, g, b, a;
|
||||
|
||||
g_snprintf (red_buf, MAX_INFO_BUF, _("N/A"));
|
||||
g_snprintf (green_buf, MAX_INFO_BUF, _("N/A"));
|
||||
g_snprintf (blue_buf, MAX_INFO_BUF, _("N/A"));
|
||||
g_snprintf (alpha_buf, MAX_INFO_BUF, _("N/A"));
|
||||
g_snprintf (index_buf, MAX_INFO_BUF, _("N/A"));
|
||||
g_snprintf (gray_buf, MAX_INFO_BUF, _("N/A"));
|
||||
g_snprintf (hex_buf, MAX_INFO_BUF, _("N/A"));
|
||||
}
|
||||
gimp_rgba_get_uchar (color, &r, &g, &b, &a);
|
||||
|
||||
g_snprintf (red_buf, MAX_INFO_BUF, "%d", r);
|
||||
g_snprintf (green_buf, MAX_INFO_BUF, "%d", g);
|
||||
g_snprintf (blue_buf, MAX_INFO_BUF, "%d", b);
|
||||
|
||||
if (GIMP_IMAGE_TYPE_HAS_ALPHA (sample_type))
|
||||
g_snprintf (alpha_buf, MAX_INFO_BUF, "%d", a);
|
||||
else
|
||||
g_snprintf (alpha_buf, MAX_INFO_BUF, _("N/A"));
|
||||
|
||||
switch (GIMP_IMAGE_TYPE_BASE_TYPE (sample_type))
|
||||
{
|
||||
GimpRGB color;
|
||||
guchar r = 0;
|
||||
guchar g = 0;
|
||||
guchar b = 0;
|
||||
guchar a = 0;
|
||||
case GIMP_RGB:
|
||||
case GIMP_GRAY:
|
||||
g_snprintf (index_buf, MAX_INFO_BUF, _("N/A"));
|
||||
break;
|
||||
|
||||
if (! GTK_WIDGET_IS_SENSITIVE (color_area))
|
||||
gtk_widget_set_sensitive (color_area, TRUE);
|
||||
|
||||
switch (GIMP_IMAGE_TYPE_BASE_TYPE (sample_type))
|
||||
{
|
||||
case GIMP_RGB:
|
||||
g_snprintf (index_buf, MAX_INFO_BUF, _("N/A"));
|
||||
g_snprintf (red_buf, MAX_INFO_BUF, "%d", col_value [RED_PIX]);
|
||||
g_snprintf (green_buf, MAX_INFO_BUF, "%d", col_value [GREEN_PIX]);
|
||||
g_snprintf (blue_buf, MAX_INFO_BUF, "%d", col_value [BLUE_PIX]);
|
||||
if (sample_type == GIMP_RGBA_IMAGE)
|
||||
g_snprintf (alpha_buf, MAX_INFO_BUF, "%d", col_value [ALPHA_PIX]);
|
||||
else
|
||||
g_snprintf (alpha_buf, MAX_INFO_BUF, _("N/A"));
|
||||
g_snprintf (hex_buf, MAX_INFO_BUF, "#%.2x%.2x%.2x",
|
||||
col_value [RED_PIX],
|
||||
col_value [GREEN_PIX],
|
||||
col_value [BLUE_PIX]);
|
||||
|
||||
r = col_value [RED_PIX];
|
||||
g = col_value [GREEN_PIX];
|
||||
b = col_value [BLUE_PIX];
|
||||
if (sample_type == GIMP_RGBA_IMAGE)
|
||||
a = col_value [ALPHA_PIX];
|
||||
break;
|
||||
|
||||
case GIMP_GRAY:
|
||||
g_snprintf (gray_buf, MAX_INFO_BUF, "%d", col_value [GRAY_PIX]);
|
||||
if (sample_type == GIMP_GRAYA_IMAGE)
|
||||
g_snprintf (alpha_buf, MAX_INFO_BUF, "%d", col_value [ALPHA_PIX]);
|
||||
else
|
||||
g_snprintf (alpha_buf, MAX_INFO_BUF, _("N/A"));
|
||||
g_snprintf (hex_buf, MAX_INFO_BUF, "#%.2x%.2x%.2x",
|
||||
col_value [GRAY_PIX],
|
||||
col_value [GRAY_PIX],
|
||||
col_value [GRAY_PIX]);
|
||||
|
||||
r = col_value [GRAY_PIX];
|
||||
g = col_value [GRAY_PIX];
|
||||
b = col_value [GRAY_PIX];
|
||||
if (sample_type == GIMP_GRAYA_IMAGE)
|
||||
a = col_value [ALPHA_PIX];
|
||||
break;
|
||||
|
||||
case GIMP_INDEXED:
|
||||
g_snprintf (index_buf, MAX_INFO_BUF, "%d", col_value [4]);
|
||||
g_snprintf (red_buf, MAX_INFO_BUF, "%d", col_value [RED_PIX]);
|
||||
g_snprintf (green_buf, MAX_INFO_BUF, "%d", col_value [GREEN_PIX]);
|
||||
g_snprintf (blue_buf, MAX_INFO_BUF, "%d", col_value [BLUE_PIX]);
|
||||
if (sample_type == GIMP_INDEXEDA_IMAGE)
|
||||
g_snprintf (alpha_buf, MAX_INFO_BUF, "%d", col_value [ALPHA_PIX]);
|
||||
else
|
||||
g_snprintf (alpha_buf, MAX_INFO_BUF, _("N/A"));
|
||||
g_snprintf (hex_buf, MAX_INFO_BUF, "#%.2x%.2x%.2x",
|
||||
col_value [RED_PIX],
|
||||
col_value [GREEN_PIX],
|
||||
col_value [BLUE_PIX]);
|
||||
|
||||
r = col_value [RED_PIX];
|
||||
g = col_value [GREEN_PIX];
|
||||
b = col_value [BLUE_PIX];
|
||||
if (sample_type == GIMP_INDEXEDA_IMAGE)
|
||||
a = col_value [ALPHA_PIX];
|
||||
break;
|
||||
}
|
||||
|
||||
gimp_rgba_set_uchar (&color, r, g, b, a);
|
||||
|
||||
gimp_color_area_set_color (GIMP_COLOR_AREA (color_area), &color);
|
||||
case GIMP_INDEXED:
|
||||
g_snprintf (index_buf, MAX_INFO_BUF, "%d", color_index);
|
||||
break;
|
||||
}
|
||||
|
||||
g_snprintf (hex_buf, MAX_INFO_BUF, "#%.2x%.2x%.2x", r, g, b);
|
||||
|
||||
gimp_color_area_set_color (GIMP_COLOR_AREA (color_area), color);
|
||||
|
||||
info_dialog_update (gimp_color_picker_tool_info);
|
||||
info_dialog_popup (gimp_color_picker_tool_info);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,8 +24,12 @@
|
|||
|
||||
#include "tools-types.h"
|
||||
|
||||
#include "config/gimpconfig-types.h"
|
||||
|
||||
#include "core/gimpimage.h"
|
||||
#include "core/gimpimage-pick-color.h"
|
||||
#include "core/gimpitem.h"
|
||||
#include "core/gimpmarshal.h"
|
||||
#include "core/gimptoolinfo.h"
|
||||
|
||||
#include "display/gimpdisplay.h"
|
||||
|
|
@ -37,6 +41,13 @@
|
|||
#include "gimp-intl.h"
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
PICKED,
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
|
||||
/* local function prototypes */
|
||||
|
||||
static void gimp_color_tool_class_init (GimpColorToolClass *klass);
|
||||
|
|
@ -64,8 +75,19 @@ static void gimp_color_tool_cursor_update (GimpTool *tool,
|
|||
|
||||
static void gimp_color_tool_draw (GimpDrawTool *draw_tool);
|
||||
|
||||
static gboolean gimp_color_tool_real_pick (GimpColorTool *color_tool,
|
||||
gint x,
|
||||
gint y,
|
||||
GimpImageType *sample_type,
|
||||
GimpRGB *color,
|
||||
gint *color_index);
|
||||
static void gimp_color_tool_pick (GimpColorTool *tool,
|
||||
gint x,
|
||||
gint y);
|
||||
|
||||
|
||||
static guint gimp_color_tool_signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
static GimpDrawToolClass *parent_class = NULL;
|
||||
|
||||
|
||||
|
|
@ -108,6 +130,18 @@ gimp_color_tool_class_init (GimpColorToolClass *klass)
|
|||
|
||||
parent_class = g_type_class_peek_parent (klass);
|
||||
|
||||
gimp_color_tool_signals[PICKED] =
|
||||
g_signal_new ("picked",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET (GimpColorToolClass, picked),
|
||||
NULL, NULL,
|
||||
gimp_marshal_VOID__ENUM_BOXED_INT,
|
||||
G_TYPE_NONE, 3,
|
||||
GIMP_TYPE_IMAGE_TYPE,
|
||||
GIMP_TYPE_COLOR | G_SIGNAL_TYPE_STATIC_SCOPE,
|
||||
G_TYPE_INT);
|
||||
|
||||
tool_class->button_press = gimp_color_tool_button_press;
|
||||
tool_class->button_release = gimp_color_tool_button_release;
|
||||
tool_class->motion = gimp_color_tool_motion;
|
||||
|
|
@ -115,7 +149,8 @@ gimp_color_tool_class_init (GimpColorToolClass *klass)
|
|||
|
||||
draw_class->draw = gimp_color_tool_draw;
|
||||
|
||||
klass->pick = NULL;
|
||||
klass->pick = gimp_color_tool_real_pick;
|
||||
klass->picked = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -123,6 +158,10 @@ gimp_color_tool_init (GimpColorTool *color_tool)
|
|||
{
|
||||
GimpTool *tool = GIMP_TOOL (color_tool);
|
||||
|
||||
color_tool->enabled = FALSE;
|
||||
color_tool->center_x = 0;
|
||||
color_tool->center_y = 0;
|
||||
|
||||
gimp_tool_control_set_tool_cursor (tool->control,
|
||||
GIMP_COLOR_PICKER_TOOL_CURSOR);
|
||||
}
|
||||
|
|
@ -134,27 +173,28 @@ gimp_color_tool_button_press (GimpTool *tool,
|
|||
GdkModifierType state,
|
||||
GimpDisplay *gdisp)
|
||||
{
|
||||
GimpColorTool *cp_tool;
|
||||
GimpColorOptions *options;
|
||||
gint off_x, off_y;
|
||||
|
||||
cp_tool = GIMP_COLOR_TOOL (tool);
|
||||
options = GIMP_COLOR_OPTIONS (tool->tool_info->tool_options);
|
||||
GimpColorTool *color_tool;
|
||||
|
||||
/* Make the tool active and set it's gdisplay & drawable */
|
||||
tool->gdisp = gdisp;
|
||||
tool->drawable = gimp_image_active_drawable (gdisp->gimage);
|
||||
gimp_tool_control_activate (tool->control);
|
||||
|
||||
if (GIMP_COLOR_TOOL_GET_CLASS (tool)->pick)
|
||||
color_tool = GIMP_COLOR_TOOL (tool);
|
||||
|
||||
if (color_tool->enabled)
|
||||
{
|
||||
gint off_x, off_y;
|
||||
|
||||
/* Keep the coordinates of the target */
|
||||
gimp_item_offsets (GIMP_ITEM (tool->drawable), &off_x, &off_y);
|
||||
|
||||
cp_tool->centerx = coords->x - off_x;
|
||||
cp_tool->centery = coords->y - off_y;
|
||||
color_tool->center_x = coords->x - off_x;
|
||||
color_tool->center_y = coords->y - off_y;
|
||||
|
||||
gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), gdisp);
|
||||
|
||||
gimp_color_tool_pick (color_tool, coords->x, coords->y);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -165,7 +205,7 @@ gimp_color_tool_button_release (GimpTool *tool,
|
|||
GdkModifierType state,
|
||||
GimpDisplay *gdisp)
|
||||
{
|
||||
if (GIMP_COLOR_TOOL_GET_CLASS (tool)->pick)
|
||||
if (GIMP_COLOR_TOOL (tool)->enabled)
|
||||
gimp_draw_tool_stop (GIMP_DRAW_TOOL (tool));
|
||||
|
||||
gimp_tool_control_halt (tool->control);
|
||||
|
|
@ -173,29 +213,29 @@ gimp_color_tool_button_release (GimpTool *tool,
|
|||
|
||||
static void
|
||||
gimp_color_tool_motion (GimpTool *tool,
|
||||
GimpCoords *coords,
|
||||
guint32 time,
|
||||
GdkModifierType state,
|
||||
GimpDisplay *gdisp)
|
||||
GimpCoords *coords,
|
||||
guint32 time,
|
||||
GdkModifierType state,
|
||||
GimpDisplay *gdisp)
|
||||
{
|
||||
GimpColorTool *cp_tool;
|
||||
GimpColorOptions *options;
|
||||
gint off_x, off_y;
|
||||
GimpColorTool *color_tool;
|
||||
gint off_x, off_y;
|
||||
|
||||
if (! GIMP_COLOR_TOOL_GET_CLASS (tool)->pick)
|
||||
color_tool = GIMP_COLOR_TOOL (tool);
|
||||
|
||||
if (! color_tool->enabled)
|
||||
return;
|
||||
|
||||
cp_tool = GIMP_COLOR_TOOL (tool);
|
||||
options = GIMP_COLOR_OPTIONS (tool->tool_info->tool_options);
|
||||
|
||||
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
|
||||
|
||||
gimp_item_offsets (GIMP_ITEM (tool->drawable), &off_x, &off_y);
|
||||
|
||||
cp_tool->centerx = coords->x - off_x;
|
||||
cp_tool->centery = coords->y - off_y;
|
||||
color_tool->center_x = coords->x - off_x;
|
||||
color_tool->center_y = coords->y - off_y;
|
||||
|
||||
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
|
||||
|
||||
gimp_color_tool_pick (color_tool, coords->x, coords->y);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -204,20 +244,21 @@ gimp_color_tool_cursor_update (GimpTool *tool,
|
|||
GdkModifierType state,
|
||||
GimpDisplay *gdisp)
|
||||
{
|
||||
if (! GIMP_COLOR_TOOL_GET_CLASS (tool)->pick)
|
||||
return;
|
||||
|
||||
if (gdisp->gimage &&
|
||||
coords->x > 0 &&
|
||||
coords->x < gdisp->gimage->width &&
|
||||
coords->y > 0 &&
|
||||
coords->y < gdisp->gimage->height)
|
||||
if (GIMP_COLOR_TOOL (tool)->enabled)
|
||||
{
|
||||
gimp_tool_control_set_cursor (tool->control, GIMP_COLOR_PICKER_CURSOR);
|
||||
}
|
||||
else
|
||||
{
|
||||
gimp_tool_control_set_cursor (tool->control, GIMP_BAD_CURSOR);
|
||||
if (gdisp->gimage &&
|
||||
coords->x > 0 &&
|
||||
coords->x < gdisp->gimage->width &&
|
||||
coords->y > 0 &&
|
||||
coords->y < gdisp->gimage->height)
|
||||
{
|
||||
gimp_tool_control_set_cursor (tool->control,
|
||||
GIMP_COLOR_PICKER_CURSOR);
|
||||
}
|
||||
else
|
||||
{
|
||||
gimp_tool_control_set_cursor (tool->control, GIMP_BAD_CURSOR);
|
||||
}
|
||||
}
|
||||
|
||||
GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, gdisp);
|
||||
|
|
@ -226,44 +267,97 @@ gimp_color_tool_cursor_update (GimpTool *tool,
|
|||
static void
|
||||
gimp_color_tool_draw (GimpDrawTool *draw_tool)
|
||||
{
|
||||
GimpColorTool *cp_tool;
|
||||
GimpColorOptions *options;
|
||||
GimpTool *tool;
|
||||
GimpColorOptions *options;
|
||||
|
||||
if (! GIMP_COLOR_TOOL_GET_CLASS (draw_tool)->pick)
|
||||
if (! GIMP_COLOR_TOOL (draw_tool)->enabled)
|
||||
return;
|
||||
|
||||
cp_tool = GIMP_COLOR_TOOL (draw_tool);
|
||||
tool = GIMP_TOOL (draw_tool);
|
||||
options = GIMP_COLOR_OPTIONS (tool->tool_info->tool_options);
|
||||
|
||||
if (options->sample_average)
|
||||
gimp_draw_tool_draw_rectangle (draw_tool,
|
||||
FALSE,
|
||||
cp_tool->centerx - options->average_radius,
|
||||
cp_tool->centery - options->average_radius,
|
||||
2 * options->average_radius + 1,
|
||||
2 * options->average_radius + 1,
|
||||
TRUE);
|
||||
{
|
||||
GimpColorTool *color_tool = GIMP_COLOR_TOOL (tool);
|
||||
|
||||
gimp_draw_tool_draw_rectangle (draw_tool,
|
||||
FALSE,
|
||||
(color_tool->center_x -
|
||||
options->average_radius),
|
||||
(color_tool->center_y -
|
||||
options->average_radius),
|
||||
2 * options->average_radius + 1,
|
||||
2 * options->average_radius + 1,
|
||||
TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
gimp_color_tool_pick (GimpColorTool *tool,
|
||||
GimpColorOptions *options,
|
||||
GimpDisplay *gdisp,
|
||||
gint x,
|
||||
gint y)
|
||||
static gboolean
|
||||
gimp_color_tool_real_pick (GimpColorTool *color_tool,
|
||||
gint x,
|
||||
gint y,
|
||||
GimpImageType *sample_type,
|
||||
GimpRGB *color,
|
||||
gint *color_index)
|
||||
{
|
||||
GimpTool *tool;
|
||||
GimpColorOptions *options;
|
||||
|
||||
tool = GIMP_TOOL (color_tool);
|
||||
options = GIMP_COLOR_OPTIONS (tool->tool_info->tool_options);
|
||||
|
||||
g_return_val_if_fail (tool->gdisp != NULL, FALSE);
|
||||
g_return_val_if_fail (tool->drawable != NULL, FALSE);
|
||||
|
||||
return gimp_image_pick_color (tool->gdisp->gimage,
|
||||
tool->drawable,
|
||||
options->sample_merged,
|
||||
x, y,
|
||||
options->sample_average,
|
||||
options->average_radius,
|
||||
sample_type,
|
||||
color,
|
||||
color_index);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_color_tool_pick (GimpColorTool *tool,
|
||||
gint x,
|
||||
gint y)
|
||||
{
|
||||
GimpColorToolClass *klass;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_COLOR_TOOL (tool), FALSE);
|
||||
g_return_val_if_fail (GIMP_IS_COLOR_OPTIONS (options), FALSE);
|
||||
g_return_val_if_fail (GIMP_IS_DISPLAY (gdisp), FALSE);
|
||||
GimpImageType sample_type;
|
||||
GimpRGB color;
|
||||
gint color_index;
|
||||
|
||||
klass = GIMP_COLOR_TOOL_GET_CLASS (tool);
|
||||
|
||||
if (! klass->pick)
|
||||
return FALSE;
|
||||
|
||||
return klass->pick (tool, options, gdisp, x, y);
|
||||
if (klass->pick &&
|
||||
klass->pick (tool, x, y, &sample_type, &color, &color_index))
|
||||
{
|
||||
g_signal_emit (tool,
|
||||
gimp_color_tool_signals[PICKED], 0,
|
||||
sample_type,
|
||||
&color,
|
||||
color_index);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
gimp_color_tool_enable (GimpColorTool *color_tool,
|
||||
gboolean enable)
|
||||
{
|
||||
GimpTool *tool;
|
||||
|
||||
g_return_if_fail (GIMP_IS_COLOR_TOOL (color_tool));
|
||||
|
||||
tool = GIMP_TOOL (color_tool);
|
||||
if (gimp_tool_control_is_active (tool->control))
|
||||
{
|
||||
g_warning ("Trying to enable/disable GimpColorTool while it is active.");
|
||||
return;
|
||||
}
|
||||
|
||||
color_tool->enabled = enable ? TRUE : FALSE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,8 +37,9 @@ struct _GimpColorTool
|
|||
{
|
||||
GimpDrawTool parent_instance;
|
||||
|
||||
gint centerx; /* starting x coord */
|
||||
gint centery; /* starting y coord */
|
||||
gboolean enabled;
|
||||
gint center_x;
|
||||
gint center_y;
|
||||
};
|
||||
|
||||
struct _GimpColorToolClass
|
||||
|
|
@ -46,22 +47,24 @@ struct _GimpColorToolClass
|
|||
GimpDrawToolClass parent_class;
|
||||
|
||||
/* virtual functions */
|
||||
gboolean (* pick) (GimpColorTool *tool,
|
||||
gint x,
|
||||
gint y,
|
||||
GimpImageType *sample_type,
|
||||
GimpRGB *color,
|
||||
gint *color_index);
|
||||
|
||||
gboolean (* pick) (GimpColorTool *tool,
|
||||
GimpColorOptions *options,
|
||||
GimpDisplay *gdisp,
|
||||
gint x,
|
||||
gint y);
|
||||
/* signals */
|
||||
void (* picked) (GimpColorTool *tool,
|
||||
GimpImageType sample_type,
|
||||
GimpRGB *color,
|
||||
gint color_index);
|
||||
};
|
||||
|
||||
|
||||
GType gimp_color_tool_get_type (void) G_GNUC_CONST;
|
||||
|
||||
gboolean gimp_color_tool_pick (GimpColorTool *tool,
|
||||
GimpColorOptions *options,
|
||||
GimpDisplay *gdisp,
|
||||
gint x,
|
||||
gint y);
|
||||
|
||||
void gimp_color_tool_enable (GimpColorTool *color_tool,
|
||||
gboolean enable);
|
||||
|
||||
#endif /* __GIMP_COLOR_TOOL_H__ */
|
||||
|
|
|
|||
Loading…
Reference in a new issue