1997-11-25 06:05:25 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
2001-02-14 12:55:21 +08:00
|
|
|
* Copyright (C) 1995-2001 Spencer Kimball, Peter Mattis, and others
|
1997-11-25 06:05:25 +08:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
1998-04-13 13:44:11 +08:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2000-12-17 05:37:03 +08:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2001-01-24 20:21:50 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
2001-01-25 06:36:18 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "tools-types.h"
|
2001-02-27 13:21:12 +08:00
|
|
|
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpdrawable.h"
|
|
|
|
#include "core/gimpimage.h"
|
|
|
|
|
2001-04-18 05:43:29 +08:00
|
|
|
#include "gui/info-dialog.h"
|
|
|
|
#include "gui/palette-editor.h"
|
2001-03-08 09:07:03 +08:00
|
|
|
|
|
|
|
#include "gimpdrawtool.h"
|
|
|
|
#include "gimpcolorpickertool.h"
|
2001-02-21 20:18:09 +08:00
|
|
|
#include "tool_manager.h"
|
2001-01-25 06:36:18 +08:00
|
|
|
#include "tool_options.h"
|
2001-01-24 20:21:50 +08:00
|
|
|
|
2001-05-26 00:04:54 +08:00
|
|
|
#include "gdisplay.h"
|
2001-04-18 05:43:29 +08:00
|
|
|
#include "gimprc.h"
|
|
|
|
|
Lots of ii8n stuff here and some additions to the de.po. Applied
Wed Oct 14 17:46:15 EDT 1998 Adrian Likins <adrian@gimp.org>
* app/*, po/de.po, de/POTFILES.in, libgimp/gimpintl.h:
Lots of ii8n stuff here and some additions to the de.po.
Applied gimp-egger-981005-1 ,gimp-egger-981006-1,
gimp-egger-981007-1, gimp-egger-981008-1,
gimp-egger-981009-1.patch, gimp-egger-981010-1.patch
* plug-in/guillotine/guillotine.c: added the coordinates
of the split images from the original image to the title.
ie foo.jpg (0,0) for the image in the topleft.
* plug-in/script-fu/scripts/neon-logo.scm,
perspective-shadow.scm, predator.scm,rendermap.scm,
ripply-anim.scm, select_to_image.scm,swirltile.scm,
xach-effect.scm: updated scripts to use new script-fu stuff
wooo boy! a big un!
in testing this, it looks like some of the po files are busted.
but the code stuff seems okay.
-adrian
1998-10-15 07:23:52 +08:00
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
/* maximum information buffer size */
|
1999-04-13 01:55:06 +08:00
|
|
|
#define MAX_INFO_BUF 8
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-05-14 08:04:29 +08:00
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
/* the color picker structures */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
typedef struct _GimpColorPickerToolOptions GimpColorPickerToolOptions;
|
1999-10-27 02:27:27 +08:00
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
struct _GimpColorPickerToolOptions
|
1999-04-09 06:25:54 +08:00
|
|
|
{
|
2001-07-18 04:50:01 +08:00
|
|
|
GimpToolOptions tool_options;
|
1999-04-13 01:55:06 +08:00
|
|
|
|
1999-08-24 10:52:40 +08:00
|
|
|
gboolean sample_merged;
|
|
|
|
gboolean sample_merged_d;
|
1999-04-13 01:55:06 +08:00
|
|
|
GtkWidget *sample_merged_w;
|
2001-02-27 13:21:12 +08:00
|
|
|
|
1999-08-24 10:52:40 +08:00
|
|
|
gboolean sample_average;
|
|
|
|
gboolean sample_average_d;
|
1999-04-13 01:55:06 +08:00
|
|
|
GtkWidget *sample_average_w;
|
2001-02-27 13:21:12 +08:00
|
|
|
|
1999-07-24 23:37:03 +08:00
|
|
|
gdouble average_radius;
|
|
|
|
gdouble average_radius_d;
|
1999-04-13 01:55:06 +08:00
|
|
|
GtkObject *average_radius_w;
|
1999-08-24 10:52:40 +08:00
|
|
|
|
|
|
|
gboolean update_active;
|
|
|
|
gboolean update_active_d;
|
|
|
|
GtkWidget *update_active_w;
|
1999-04-09 06:25:54 +08:00
|
|
|
};
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-02-21 20:18:09 +08:00
|
|
|
|
|
|
|
/* local function prototypes */
|
|
|
|
|
2001-02-28 09:05:22 +08:00
|
|
|
static void gimp_color_picker_tool_class_init (GimpColorPickerToolClass *klass);
|
|
|
|
static void gimp_color_picker_tool_init (GimpColorPickerTool *color_picker_tool);
|
2001-02-27 13:21:12 +08:00
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
static void gimp_color_picker_tool_finalize (GObject *object);
|
2001-02-27 13:21:12 +08:00
|
|
|
|
|
|
|
static void gimp_color_picker_tool_button_press (GimpTool *tool,
|
|
|
|
GdkEventButton *bevent,
|
|
|
|
GDisplay *gdisp);
|
|
|
|
|
|
|
|
static void gimp_color_picker_tool_button_release (GimpTool *tool,
|
|
|
|
GdkEventButton *bevent,
|
|
|
|
GDisplay *gdisp);
|
|
|
|
|
|
|
|
static void gimp_color_picker_tool_motion (GimpTool *tool,
|
|
|
|
GdkEventMotion *mevent,
|
|
|
|
GDisplay *gdisp);
|
|
|
|
|
|
|
|
static void gimp_color_picker_tool_cursor_update (GimpTool *tool,
|
|
|
|
GdkEventMotion *mevent,
|
|
|
|
GDisplay *gdisp);
|
|
|
|
|
|
|
|
static void gimp_color_picker_tool_control (GimpTool *tool,
|
2001-02-28 03:18:01 +08:00
|
|
|
ToolAction action,
|
2001-02-27 13:21:12 +08:00
|
|
|
GDisplay *gdisp);
|
|
|
|
|
2001-02-28 03:18:01 +08:00
|
|
|
static void gimp_color_picker_tool_draw (GimpDrawTool *draw_tool);
|
2001-02-27 13:21:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static GimpColorPickerToolOptions * gimp_color_picker_tool_options_new (void);
|
|
|
|
|
2001-07-18 04:50:01 +08:00
|
|
|
static void gimp_color_picker_tool_options_reset (GimpToolOptions *tool_options);
|
2001-02-27 13:21:12 +08:00
|
|
|
static void gimp_color_picker_tool_info_window_close_callback (GtkWidget *widget,
|
2001-02-28 03:18:01 +08:00
|
|
|
gpointer data);
|
2001-02-27 13:21:12 +08:00
|
|
|
static void gimp_color_picker_tool_info_update (GimpTool *tool,
|
2001-02-28 03:18:01 +08:00
|
|
|
gboolean valid);
|
2001-02-27 13:21:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2001-02-21 20:18:09 +08:00
|
|
|
static gboolean pick_color_do (GimpImage *gimage,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gboolean sample_merged,
|
|
|
|
gboolean sample_average,
|
|
|
|
gdouble average_radius,
|
|
|
|
gboolean update_active,
|
|
|
|
gint final);
|
|
|
|
|
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
/* the color picker tool options */
|
2001-02-27 13:21:12 +08:00
|
|
|
static GimpColorPickerToolOptions * gimp_color_picker_tool_options = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-04-19 05:22:41 +08:00
|
|
|
/* the color value */
|
1999-07-24 23:37:03 +08:00
|
|
|
gint col_value[5] = { 0, 0, 0, 0, 0 };
|
1999-04-19 05:22:41 +08:00
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
/* the color picker dialog */
|
1999-07-24 23:37:03 +08:00
|
|
|
static gint update_type;
|
Actually use the enum types GimpImageType, GimpImageBaseType,
* app/*.[ch]: Actually use the enum types GimpImageType,
GimpImageBaseType, LayerModeEffects, PaintApplicationMode,
BrushApplicationMode, GimpFillType and ConvertPaletteType, instead
of just int or gint. Hopefully I catched most of the places
where these should be used.
Add an enum ConvolutionType, suffix the too general constants
NORMAL, ABSOLUTE and NEGATIVE with _CONVOL. Use NORMAL_MODE
instead of NORMAL in some places (this was what was intended). Fix
some minor gccisms.
* app/apptypes.h: New file. This file contains the above
enumeration types, and some opaque struct typedefs. It was
necessary to collect these in one header that doesn't include
other headers, because when we started using the above mentioned
types in the headers, all hell broke loose because of the
spaghetti-like cross-inclusion mess between headers.
(An example: Header A includes header B, which includes header C
which includes A. B uses a type defined in A. This is not defined,
because A hasn't defined it yet at the point where it includes B,
and A included from B of course is skipped as we already are
reading A.)
1999-08-19 07:41:39 +08:00
|
|
|
static GimpImageType sample_type;
|
2001-02-27 13:21:12 +08:00
|
|
|
static InfoDialog *gimp_color_picker_tool_info = NULL;
|
2001-02-24 10:42:09 +08:00
|
|
|
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];
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-02-28 03:18:01 +08:00
|
|
|
static GimpDrawToolClass *parent_class = NULL;
|
1999-04-09 06:25:54 +08:00
|
|
|
|
|
|
|
|
2001-02-21 20:18:09 +08:00
|
|
|
void
|
2001-07-07 20:17:23 +08:00
|
|
|
gimp_color_picker_tool_register (Gimp *gimp)
|
2001-02-21 20:18:09 +08:00
|
|
|
{
|
2001-07-07 20:17:23 +08:00
|
|
|
tool_manager_register_tool (gimp,
|
|
|
|
GIMP_TYPE_COLOR_PICKER_TOOL,
|
2001-02-28 07:20:51 +08:00
|
|
|
FALSE,
|
2001-02-24 05:32:47 +08:00
|
|
|
"gimp:color_picker_tool",
|
|
|
|
_("Color Picker"),
|
|
|
|
_("Pick colors from the image"),
|
2001-02-24 10:42:09 +08:00
|
|
|
N_("/Tools/Color Picker"), "<shift>O",
|
2001-02-21 20:18:09 +08:00
|
|
|
NULL, "tools/color_picker.html",
|
2001-08-06 00:08:19 +08:00
|
|
|
GIMP_STOCK_TOOL_COLOR_PICKER);
|
2001-02-21 20:18:09 +08:00
|
|
|
}
|
|
|
|
|
2001-02-14 12:55:21 +08:00
|
|
|
GtkType
|
2001-02-27 13:21:12 +08:00
|
|
|
gimp_color_picker_tool_get_type (void)
|
2001-02-14 12:55:21 +08:00
|
|
|
{
|
|
|
|
static GtkType tool_type = 0;
|
|
|
|
|
|
|
|
if (! tool_type)
|
|
|
|
{
|
2001-08-14 22:53:55 +08:00
|
|
|
static const GTypeInfo tool_info =
|
2001-02-14 12:55:21 +08:00
|
|
|
{
|
2001-02-27 13:21:12 +08:00
|
|
|
sizeof (GimpColorPickerToolClass),
|
2001-08-14 22:53:55 +08:00
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_color_picker_tool_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpColorPickerTool),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_color_picker_tool_init,
|
2001-02-14 12:55:21 +08:00
|
|
|
};
|
2001-02-27 13:21:12 +08:00
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
tool_type = g_type_register_static (GIMP_TYPE_DRAW_TOOL,
|
|
|
|
"GimpColorPickerTool",
|
|
|
|
&tool_info, 0);
|
2001-02-14 12:55:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return tool_type;
|
|
|
|
}
|
|
|
|
|
2001-02-21 20:18:09 +08:00
|
|
|
static void
|
2001-02-27 13:21:12 +08:00
|
|
|
gimp_color_picker_tool_class_init (GimpColorPickerToolClass *klass)
|
2001-02-21 20:18:09 +08:00
|
|
|
{
|
2001-08-14 22:53:55 +08:00
|
|
|
GObjectClass *object_class;
|
2001-02-27 13:21:12 +08:00
|
|
|
GimpToolClass *tool_class;
|
|
|
|
GimpDrawToolClass *draw_class;
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
object_class = G_OBJECT_CLASS (klass);
|
|
|
|
tool_class = GIMP_TOOL_CLASS (klass);
|
|
|
|
draw_class = GIMP_DRAW_TOOL_CLASS (klass);
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
object_class->finalize = gimp_color_picker_tool_finalize;
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
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->cursor_update = gimp_color_picker_tool_cursor_update;
|
|
|
|
|
|
|
|
draw_class->draw = gimp_color_picker_tool_draw;
|
2001-02-21 20:18:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-02-27 13:21:12 +08:00
|
|
|
gimp_color_picker_tool_init (GimpColorPickerTool *color_picker_tool)
|
2001-02-21 20:18:09 +08:00
|
|
|
{
|
|
|
|
GimpTool *tool;
|
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
tool = GIMP_TOOL (color_picker_tool);
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
if (! gimp_color_picker_tool_options)
|
2001-02-21 20:18:09 +08:00
|
|
|
{
|
2001-02-27 13:21:12 +08:00
|
|
|
gimp_color_picker_tool_options = gimp_color_picker_tool_options_new ();
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
tool_manager_register_tool_options (GIMP_TYPE_COLOR_PICKER_TOOL,
|
2001-07-18 04:50:01 +08:00
|
|
|
(GimpToolOptions *) gimp_color_picker_tool_options);
|
2001-02-21 20:18:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
tool->preserve = FALSE; /* Don't preserve on drawable change */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-08-14 22:53:55 +08:00
|
|
|
gimp_color_picker_tool_finalize (GObject *object)
|
2001-02-21 20:18:09 +08:00
|
|
|
{
|
2001-02-27 13:21:12 +08:00
|
|
|
if (gimp_color_picker_tool_info)
|
2001-02-21 20:18:09 +08:00
|
|
|
{
|
2001-02-27 13:21:12 +08:00
|
|
|
info_dialog_free (gimp_color_picker_tool_info);
|
|
|
|
gimp_color_picker_tool_info = NULL;
|
2001-02-21 20:18:09 +08:00
|
|
|
|
|
|
|
color_area = NULL;
|
|
|
|
}
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2001-02-21 20:18:09 +08:00
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static void
|
2001-08-14 22:53:55 +08:00
|
|
|
gimp_color_picker_tool_control (GimpTool *tool,
|
|
|
|
ToolAction action,
|
|
|
|
GDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-08-14 22:53:55 +08:00
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case PAUSE :
|
|
|
|
break;
|
1999-04-11 14:35:28 +08:00
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
case RESUME :
|
|
|
|
break;
|
1999-04-11 14:35:28 +08:00
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
case HALT :
|
|
|
|
info_dialog_popdown (gimp_color_picker_tool_info);
|
|
|
|
break;
|
1999-04-11 14:35:28 +08:00
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
1999-08-24 10:52:40 +08:00
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
if (GIMP_TOOL_CLASS (parent_class)->control)
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->control (tool, action, gdisp);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-02-27 13:21:12 +08:00
|
|
|
gimp_color_picker_tool_button_press (GimpTool *tool,
|
|
|
|
GdkEventButton *bevent,
|
|
|
|
GDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-02-27 13:21:12 +08:00
|
|
|
GimpColorPickerTool *cp_tool;
|
|
|
|
gint x, y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
cp_tool = GIMP_COLOR_PICKER_TOOL(tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-07-24 23:37:03 +08:00
|
|
|
/* Make the tool active and set it's gdisplay & drawable */
|
2000-12-31 12:07:42 +08:00
|
|
|
tool->gdisp = gdisp;
|
2000-12-29 23:22:01 +08:00
|
|
|
tool->drawable = gimp_image_active_drawable (gdisp->gimage);
|
2000-12-31 12:07:42 +08:00
|
|
|
tool->state = ACTIVE;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-07-24 23:37:03 +08:00
|
|
|
/* create the info dialog if it doesn't exist */
|
2001-02-27 13:21:12 +08:00
|
|
|
if (! gimp_color_picker_tool_info)
|
1999-07-24 23:37:03 +08:00
|
|
|
{
|
1999-08-24 10:52:40 +08:00
|
|
|
GtkWidget *hbox;
|
2001-01-15 14:24:24 +08:00
|
|
|
GtkWidget *frame;
|
2001-01-15 09:48:53 +08:00
|
|
|
GimpRGB color;
|
1999-08-24 10:52:40 +08:00
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
gimp_color_picker_tool_info = info_dialog_new (_("Color Picker"),
|
2001-02-22 05:56:39 +08:00
|
|
|
tool_manager_help_func, NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* if the gdisplay is for a color image, the dialog must have RGB */
|
2001-01-15 05:11:52 +08:00
|
|
|
switch (gimp_drawable_type (tool->drawable))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
case RGB_GIMAGE: case RGBA_GIMAGE:
|
2001-02-27 13:21:12 +08:00
|
|
|
info_dialog_add_label (gimp_color_picker_tool_info, _("Red:"), red_buf);
|
|
|
|
info_dialog_add_label (gimp_color_picker_tool_info, _("Green:"), green_buf);
|
|
|
|
info_dialog_add_label (gimp_color_picker_tool_info, _("Blue:"), blue_buf);
|
|
|
|
info_dialog_add_label (gimp_color_picker_tool_info, _("Alpha:"), alpha_buf);
|
|
|
|
info_dialog_add_label (gimp_color_picker_tool_info, _("Hex Triplet:"), hex_buf);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case INDEXED_GIMAGE: case INDEXEDA_GIMAGE:
|
2001-02-27 13:21:12 +08:00
|
|
|
info_dialog_add_label (gimp_color_picker_tool_info, _("Index:"), index_buf);
|
|
|
|
info_dialog_add_label (gimp_color_picker_tool_info, _("Red:"), red_buf);
|
|
|
|
info_dialog_add_label (gimp_color_picker_tool_info, _("Green:"), green_buf);
|
|
|
|
info_dialog_add_label (gimp_color_picker_tool_info, _("Blue:"), blue_buf);
|
|
|
|
info_dialog_add_label (gimp_color_picker_tool_info, _("Alpha:"), alpha_buf);
|
|
|
|
info_dialog_add_label (gimp_color_picker_tool_info, _("Hex Triplet"), hex_buf);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GRAY_GIMAGE: case GRAYA_GIMAGE:
|
2001-02-27 13:21:12 +08:00
|
|
|
info_dialog_add_label (gimp_color_picker_tool_info, _("Intensity:"), gray_buf);
|
|
|
|
info_dialog_add_label (gimp_color_picker_tool_info, _("Alpha:"), alpha_buf);
|
|
|
|
info_dialog_add_label (gimp_color_picker_tool_info, _("Hex Triplet:"), hex_buf);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default :
|
|
|
|
break;
|
|
|
|
}
|
1999-04-13 01:55:06 +08:00
|
|
|
|
1999-08-24 10:52:40 +08:00
|
|
|
hbox = gtk_hbox_new (FALSE, 4);
|
2001-02-27 13:21:12 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (gimp_color_picker_tool_info->vbox), hbox,
|
1999-08-24 10:52:40 +08:00
|
|
|
FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
gtk_widget_reparent (gimp_color_picker_tool_info->info_table, hbox);
|
1999-08-24 10:52:40 +08:00
|
|
|
|
2001-01-15 14:24:24 +08:00
|
|
|
frame = gtk_frame_new (NULL);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, FALSE, 0);
|
2001-01-15 09:48:53 +08:00
|
|
|
|
2001-01-15 14:24:24 +08:00
|
|
|
gimp_rgba_set (&color, 0.0, 0.0, 0.0, 0.0);
|
2001-02-27 13:21:12 +08:00
|
|
|
color_area =
|
2001-01-16 03:30:42 +08:00
|
|
|
gimp_color_area_new (&color,
|
2001-02-27 13:21:12 +08:00
|
|
|
gimp_drawable_has_alpha (tool->drawable) ?
|
|
|
|
GIMP_COLOR_AREA_LARGE_CHECKS :
|
|
|
|
GIMP_COLOR_AREA_FLAT,
|
2001-01-16 03:30:42 +08:00
|
|
|
GDK_BUTTON1_MASK | GDK_BUTTON2_MASK);
|
|
|
|
gtk_widget_set_usize (color_area, 48, 64);
|
|
|
|
gtk_drag_dest_unset (color_area);
|
2001-01-15 14:24:24 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (frame), color_area);
|
|
|
|
gtk_widget_show (color_area);
|
|
|
|
gtk_widget_show (frame);
|
1999-08-24 10:52:40 +08:00
|
|
|
|
1999-04-13 01:55:06 +08:00
|
|
|
/* create the action area */
|
1999-10-27 02:27:27 +08:00
|
|
|
gimp_dialog_create_action_area
|
2001-02-27 13:21:12 +08:00
|
|
|
(GTK_DIALOG (gimp_color_picker_tool_info->shell),
|
1999-10-27 02:27:27 +08:00
|
|
|
|
2001-08-04 03:43:19 +08:00
|
|
|
GTK_STOCK_CLOSE, gimp_color_picker_tool_info_window_close_callback,
|
2001-02-27 13:21:12 +08:00
|
|
|
gimp_color_picker_tool_info, NULL, NULL, TRUE, FALSE,
|
1999-10-27 02:27:27 +08:00
|
|
|
|
|
|
|
NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1999-04-16 04:52:36 +08:00
|
|
|
/* Keep the coordinates of the target */
|
|
|
|
gdisplay_untransform_coords (gdisp, bevent->x, bevent->y,
|
|
|
|
&cp_tool->centerx, &cp_tool->centery, FALSE, 1);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
gdk_pointer_grab (gdisp->canvas->window, FALSE,
|
|
|
|
(GDK_POINTER_MOTION_HINT_MASK |
|
|
|
|
GDK_BUTTON1_MOTION_MASK |
|
|
|
|
GDK_BUTTON_RELEASE_MASK),
|
|
|
|
NULL, NULL, bevent->time);
|
|
|
|
|
|
|
|
/* First, transform the coordinates to gimp image space */
|
1999-07-24 23:37:03 +08:00
|
|
|
gdisplay_untransform_coords (gdisp, bevent->x, bevent->y, &x, &y,
|
|
|
|
FALSE, FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* if the shift key is down, create a new color.
|
|
|
|
* otherwise, modify the current color.
|
|
|
|
*/
|
|
|
|
if (bevent->state & GDK_SHIFT_MASK)
|
|
|
|
{
|
2001-02-27 13:21:12 +08:00
|
|
|
gimp_color_picker_tool_info_update
|
1999-08-24 10:52:40 +08:00
|
|
|
(tool, pick_color_do (gdisp->gimage, tool->drawable, x, y,
|
2001-02-27 13:21:12 +08:00
|
|
|
gimp_color_picker_tool_options->sample_merged,
|
|
|
|
gimp_color_picker_tool_options->sample_average,
|
|
|
|
gimp_color_picker_tool_options->average_radius,
|
|
|
|
gimp_color_picker_tool_options->update_active,
|
1999-08-24 10:52:40 +08:00
|
|
|
COLOR_NEW));
|
1997-11-25 06:05:25 +08:00
|
|
|
update_type = COLOR_UPDATE_NEW;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-02-27 13:21:12 +08:00
|
|
|
gimp_color_picker_tool_info_update
|
1999-08-24 10:52:40 +08:00
|
|
|
(tool, pick_color_do (gdisp->gimage, tool->drawable, x, y,
|
2001-02-27 13:21:12 +08:00
|
|
|
gimp_color_picker_tool_options->sample_merged,
|
|
|
|
gimp_color_picker_tool_options->sample_average,
|
|
|
|
gimp_color_picker_tool_options->average_radius,
|
|
|
|
gimp_color_picker_tool_options->update_active,
|
1999-08-24 10:52:40 +08:00
|
|
|
COLOR_UPDATE));
|
1997-11-25 06:05:25 +08:00
|
|
|
update_type = COLOR_UPDATE;
|
|
|
|
}
|
1998-01-29 11:13:44 +08:00
|
|
|
|
1999-07-24 23:37:03 +08:00
|
|
|
/* Start drawing the colorpicker tool */
|
2001-02-27 13:21:12 +08:00
|
|
|
gimp_draw_tool_start (GIMP_DRAW_TOOL(cp_tool), gdisp->canvas->window);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-02-27 13:21:12 +08:00
|
|
|
gimp_color_picker_tool_button_release (GimpTool *tool,
|
|
|
|
GdkEventButton *bevent,
|
|
|
|
GDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-02-27 13:21:12 +08:00
|
|
|
GimpColorPickerTool *cp_tool;
|
2000-12-31 12:07:42 +08:00
|
|
|
gint x, y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
gdk_pointer_ungrab (bevent->time);
|
|
|
|
gdk_flush ();
|
2000-12-31 12:07:42 +08:00
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
cp_tool = GIMP_COLOR_PICKER_TOOL(tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* First, transform the coordinates to gimp image space */
|
1999-07-24 23:37:03 +08:00
|
|
|
gdisplay_untransform_coords (gdisp, bevent->x, bevent->y, &x, &y,
|
|
|
|
FALSE, FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
gimp_color_picker_tool_info_update
|
1999-08-24 10:52:40 +08:00
|
|
|
(tool, pick_color_do (gdisp->gimage, tool->drawable, x, y,
|
2001-02-27 13:21:12 +08:00
|
|
|
gimp_color_picker_tool_options->sample_merged,
|
|
|
|
gimp_color_picker_tool_options->sample_average,
|
|
|
|
gimp_color_picker_tool_options->average_radius,
|
|
|
|
gimp_color_picker_tool_options->update_active,
|
1999-08-24 10:52:40 +08:00
|
|
|
update_type));
|
1999-04-16 04:52:36 +08:00
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
gimp_draw_tool_stop (GIMP_DRAW_TOOL(cp_tool));
|
1999-04-16 04:52:36 +08:00
|
|
|
tool->state = INACTIVE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-02-27 13:21:12 +08:00
|
|
|
gimp_color_picker_tool_motion (GimpTool *tool,
|
|
|
|
GdkEventMotion *mevent,
|
|
|
|
GDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-02-27 13:21:12 +08:00
|
|
|
GimpColorPickerTool *cp_tool;
|
2000-12-31 12:07:42 +08:00
|
|
|
gint x, y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
cp_tool = GIMP_COLOR_PICKER_TOOL(tool);
|
1999-04-16 04:52:36 +08:00
|
|
|
|
|
|
|
/* undraw the current tool */
|
2001-02-27 13:21:12 +08:00
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL(cp_tool));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* First, transform the coordinates to gimp image space */
|
1999-07-24 23:37:03 +08:00
|
|
|
gdisplay_untransform_coords (gdisp, mevent->x, mevent->y, &x, &y,
|
|
|
|
FALSE, FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-07-24 23:37:03 +08:00
|
|
|
gdisplay_untransform_coords (gdisp, mevent->x, mevent->y,
|
|
|
|
&cp_tool->centerx, &cp_tool->centery,
|
|
|
|
FALSE, TRUE);
|
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
gimp_color_picker_tool_info_update
|
1999-08-24 10:52:40 +08:00
|
|
|
(tool, pick_color_do (gdisp->gimage, tool->drawable, x, y,
|
2001-02-27 13:21:12 +08:00
|
|
|
gimp_color_picker_tool_options->sample_merged,
|
|
|
|
gimp_color_picker_tool_options->sample_average,
|
|
|
|
gimp_color_picker_tool_options->average_radius,
|
|
|
|
gimp_color_picker_tool_options->update_active,
|
1999-08-24 10:52:40 +08:00
|
|
|
update_type));
|
1999-04-16 04:52:36 +08:00
|
|
|
|
|
|
|
/* redraw the current tool */
|
2001-02-27 13:21:12 +08:00
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL(cp_tool));
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-02-27 13:21:12 +08:00
|
|
|
gimp_color_picker_tool_cursor_update (GimpTool *tool,
|
|
|
|
GdkEventMotion *mevent,
|
|
|
|
GDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-08-24 10:52:40 +08:00
|
|
|
gint x, y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-07-24 23:37:03 +08:00
|
|
|
gdisplay_untransform_coords (gdisp, mevent->x, mevent->y, &x, &y,
|
|
|
|
FALSE, FALSE);
|
|
|
|
|
2001-01-16 03:30:42 +08:00
|
|
|
/* We used to use the following code here:
|
|
|
|
*
|
|
|
|
* if (gimp_image_pick_correlate_layer (gdisp->gimage, x, y)) { ... }
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (gdisp->gimage &&
|
|
|
|
x > 0 && x < gdisp->gimage->width &&
|
|
|
|
y > 0 && y < gdisp->gimage->height)
|
|
|
|
{
|
2001-02-27 13:21:12 +08:00
|
|
|
gdisplay_install_tool_cursor (gdisp, GIMP_COLOR_PICKER_CURSOR,
|
2001-02-25 03:29:47 +08:00
|
|
|
GIMP_COLOR_PICKER_TOOL_CURSOR,
|
|
|
|
GIMP_CURSOR_MODIFIER_NONE);
|
2001-01-16 03:30:42 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
2001-01-16 03:30:42 +08:00
|
|
|
{
|
2001-02-27 13:21:12 +08:00
|
|
|
gdisplay_install_tool_cursor (gdisp, GIMP_BAD_CURSOR,
|
2001-02-25 03:29:47 +08:00
|
|
|
GIMP_COLOR_PICKER_TOOL_CURSOR,
|
|
|
|
GIMP_CURSOR_MODIFIER_NONE);
|
2001-01-16 03:30:42 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2001-01-20 23:37:26 +08:00
|
|
|
typedef guchar * (*GetColorFunc) (GimpObject *object,
|
|
|
|
gint x,
|
|
|
|
gint y);
|
|
|
|
|
1999-04-11 14:35:28 +08:00
|
|
|
|
1999-08-24 10:52:40 +08:00
|
|
|
static gboolean
|
|
|
|
pick_color_do (GimpImage *gimage,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gboolean sample_merged,
|
|
|
|
gboolean sample_average,
|
|
|
|
gdouble average_radius,
|
|
|
|
gboolean update_active,
|
|
|
|
gint final)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-15 09:48:53 +08:00
|
|
|
guchar *color;
|
|
|
|
gint offx, offy;
|
|
|
|
gint has_alpha;
|
|
|
|
gint is_indexed;
|
|
|
|
GetColorFunc get_color_func;
|
2001-01-20 23:37:26 +08:00
|
|
|
GimpObject *get_color_obj;
|
1999-04-11 14:35:28 +08:00
|
|
|
|
2000-02-28 10:40:44 +08:00
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
if (!drawable && !sample_merged)
|
1998-01-22 15:02:57 +08:00
|
|
|
return FALSE;
|
|
|
|
|
1999-04-11 14:35:28 +08:00
|
|
|
if (!sample_merged)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-15 05:11:52 +08:00
|
|
|
gimp_drawable_offsets (drawable, &offx, &offy);
|
1997-11-25 06:05:25 +08:00
|
|
|
x -= offx;
|
|
|
|
y -= offy;
|
2001-01-08 05:07:14 +08:00
|
|
|
|
1999-04-11 14:35:28 +08:00
|
|
|
sample_type = gimp_drawable_type (drawable);
|
1999-10-17 08:07:55 +08:00
|
|
|
is_indexed = gimp_drawable_is_indexed (drawable);
|
2001-01-08 05:07:14 +08:00
|
|
|
|
1999-04-11 14:35:28 +08:00
|
|
|
get_color_func = (GetColorFunc) gimp_drawable_get_color_at;
|
2001-01-20 23:37:26 +08:00
|
|
|
get_color_obj = GIMP_OBJECT (drawable);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-04-11 14:35:28 +08:00
|
|
|
sample_type = gimp_image_composite_type (gimage);
|
1999-02-16 16:53:54 +08:00
|
|
|
is_indexed = FALSE;
|
1999-04-11 14:35:28 +08:00
|
|
|
|
|
|
|
get_color_func = (GetColorFunc) gimp_image_get_color_at;
|
2001-01-20 23:37:26 +08:00
|
|
|
get_color_obj = GIMP_OBJECT (gimage);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2000-12-14 02:53:35 +08:00
|
|
|
has_alpha = GIMP_IMAGE_TYPE_HAS_ALPHA (sample_type);
|
1999-04-11 14:35:28 +08:00
|
|
|
|
2001-01-08 05:07:14 +08:00
|
|
|
if (!(color = (* get_color_func) (get_color_obj, x, y)))
|
2000-03-09 19:58:03 +08:00
|
|
|
return FALSE;
|
|
|
|
|
1999-04-11 14:35:28 +08:00
|
|
|
if (sample_average)
|
|
|
|
{
|
2001-01-20 23:37:26 +08:00
|
|
|
gint i, j;
|
|
|
|
gint count = 0;
|
|
|
|
gint color_avg[4] = { 0, 0, 0, 0 };
|
1999-04-11 14:35:28 +08:00
|
|
|
guchar *tmp_color;
|
2001-01-20 23:37:26 +08:00
|
|
|
gint radius = (gint) average_radius;
|
1999-04-11 14:35:28 +08:00
|
|
|
|
|
|
|
for (i = x - radius; i <= x + radius; i++)
|
|
|
|
for (j = y - radius; j <= y + radius; j++)
|
2001-01-08 05:07:14 +08:00
|
|
|
if ((tmp_color = (* get_color_func) (get_color_obj, i, j)))
|
1999-04-11 14:35:28 +08:00
|
|
|
{
|
|
|
|
count++;
|
2001-02-27 13:21:12 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
color_avg[RED_PIX] += tmp_color[RED_PIX];
|
1999-04-11 14:35:28 +08:00
|
|
|
color_avg[GREEN_PIX] += tmp_color[GREEN_PIX];
|
1999-10-27 02:27:27 +08:00
|
|
|
color_avg[BLUE_PIX] += tmp_color[BLUE_PIX];
|
1999-04-11 14:35:28 +08:00
|
|
|
if (has_alpha)
|
2001-01-20 23:37:26 +08:00
|
|
|
color_avg[ALPHA_PIX] += tmp_color[ALPHA_PIX];
|
2001-01-08 05:07:14 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
g_free (tmp_color);
|
1999-04-11 14:35:28 +08:00
|
|
|
}
|
2001-01-08 05:07:14 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
color[RED_PIX] = (guchar) (color_avg[RED_PIX] / count);
|
1999-04-11 14:35:28 +08:00
|
|
|
color[GREEN_PIX] = (guchar) (color_avg[GREEN_PIX] / count);
|
1999-10-27 02:27:27 +08:00
|
|
|
color[BLUE_PIX] = (guchar) (color_avg[BLUE_PIX] / count);
|
1999-04-11 14:35:28 +08:00
|
|
|
if (has_alpha)
|
2001-01-20 23:37:26 +08:00
|
|
|
color[ALPHA_PIX] = (guchar) (color_avg[ALPHA_PIX] / count);
|
2001-01-08 05:07:14 +08:00
|
|
|
|
1999-04-11 14:35:28 +08:00
|
|
|
is_indexed = FALSE;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
col_value[RED_PIX] = color[RED_PIX];
|
1999-02-16 16:53:54 +08:00
|
|
|
col_value[GREEN_PIX] = color[GREEN_PIX];
|
1999-10-27 02:27:27 +08:00
|
|
|
col_value[BLUE_PIX] = color[BLUE_PIX];
|
1997-11-25 06:05:25 +08:00
|
|
|
if (has_alpha)
|
2001-01-20 23:37:26 +08:00
|
|
|
col_value[ALPHA_PIX] = color[ALPHA_PIX];
|
1999-02-16 16:53:54 +08:00
|
|
|
if (is_indexed)
|
1999-04-11 14:35:28 +08:00
|
|
|
col_value[4] = color[4];
|
|
|
|
|
1999-08-24 10:52:40 +08:00
|
|
|
if (update_active)
|
1999-10-27 02:27:27 +08:00
|
|
|
palette_set_active_color (col_value [RED_PIX],
|
|
|
|
col_value [GREEN_PIX],
|
|
|
|
col_value [BLUE_PIX],
|
|
|
|
final);
|
|
|
|
|
1999-07-24 23:37:03 +08:00
|
|
|
g_free (color);
|
2001-01-08 05:07:14 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
1999-08-24 10:52:40 +08:00
|
|
|
gboolean
|
|
|
|
pick_color (GimpImage *gimage,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gboolean sample_merged,
|
|
|
|
gboolean sample_average,
|
|
|
|
gdouble average_radius,
|
|
|
|
gint final)
|
|
|
|
{
|
|
|
|
return pick_color_do (gimage, drawable,
|
|
|
|
x, y,
|
|
|
|
sample_merged,
|
|
|
|
sample_average,
|
|
|
|
average_radius,
|
|
|
|
TRUE,
|
|
|
|
final);
|
|
|
|
}
|
|
|
|
|
1999-04-16 04:52:36 +08:00
|
|
|
static void
|
2001-02-28 03:18:01 +08:00
|
|
|
gimp_color_picker_tool_draw (GimpDrawTool *draw_tool)
|
1999-04-16 04:52:36 +08:00
|
|
|
{
|
2001-02-27 13:21:12 +08:00
|
|
|
GimpColorPickerTool *cp_tool;
|
2001-02-28 03:18:01 +08:00
|
|
|
GimpTool *tool;
|
|
|
|
gint tx, ty;
|
|
|
|
gint radiusx, radiusy;
|
|
|
|
gint cx, cy;
|
1999-04-16 04:52:36 +08:00
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
if (! gimp_color_picker_tool_options->sample_average)
|
1999-04-16 04:52:36 +08:00
|
|
|
return;
|
|
|
|
|
2001-02-28 03:18:01 +08:00
|
|
|
cp_tool = GIMP_COLOR_PICKER_TOOL (draw_tool);
|
|
|
|
tool = GIMP_TOOL (draw_tool);
|
1999-04-16 04:52:36 +08:00
|
|
|
|
2000-12-31 12:07:42 +08:00
|
|
|
gdisplay_transform_coords (tool->gdisp, cp_tool->centerx, cp_tool->centery,
|
1999-07-24 23:37:03 +08:00
|
|
|
&tx, &ty, TRUE);
|
1999-04-16 04:52:36 +08:00
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
radiusx = SCALEX (tool->gdisp, gimp_color_picker_tool_options->average_radius);
|
|
|
|
radiusy = SCALEY (tool->gdisp, gimp_color_picker_tool_options->average_radius);
|
2000-12-31 12:07:42 +08:00
|
|
|
cx = SCALEX (tool->gdisp, 1);
|
|
|
|
cy = SCALEY (tool->gdisp, 1);
|
1999-04-16 04:52:36 +08:00
|
|
|
|
|
|
|
/* Draw the circle around the collecting area */
|
2001-02-28 03:18:01 +08:00
|
|
|
gdk_draw_rectangle (draw_tool->win, draw_tool->gc, 0,
|
2001-02-27 13:21:12 +08:00
|
|
|
tx - radiusx,
|
1999-07-24 23:37:03 +08:00
|
|
|
ty - radiusy,
|
|
|
|
2 * radiusx + cx, 2 * radiusy + cy);
|
1999-04-16 04:52:36 +08:00
|
|
|
|
2001-01-08 05:07:14 +08:00
|
|
|
if (radiusx > 1 && radiusy > 1)
|
1999-04-16 04:52:36 +08:00
|
|
|
{
|
2001-02-28 03:18:01 +08:00
|
|
|
gdk_draw_rectangle (draw_tool->win, draw_tool->gc, 0,
|
2001-02-27 13:21:12 +08:00
|
|
|
tx - radiusx + 2,
|
1999-07-24 23:37:03 +08:00
|
|
|
ty - radiusy + 2,
|
|
|
|
2 * radiusx + cx - 4, 2 * radiusy + cy - 4);
|
1999-04-16 04:52:36 +08:00
|
|
|
}
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
static void
|
2001-02-27 13:21:12 +08:00
|
|
|
gimp_color_picker_tool_info_update (GimpTool *tool,
|
2001-02-28 03:18:01 +08:00
|
|
|
gboolean valid)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
if (!valid)
|
|
|
|
{
|
2001-01-15 14:24:24 +08:00
|
|
|
if (GTK_WIDGET_IS_SENSITIVE (color_area))
|
|
|
|
gtk_widget_set_sensitive (color_area, FALSE);
|
1999-08-24 10:52:40 +08:00
|
|
|
|
1999-07-24 23:37:03 +08:00
|
|
|
g_snprintf (red_buf, MAX_INFO_BUF, _("N/A"));
|
1998-12-26 02:22:01 +08:00
|
|
|
g_snprintf (green_buf, MAX_INFO_BUF, _("N/A"));
|
1999-07-24 23:37:03 +08:00
|
|
|
g_snprintf (blue_buf, MAX_INFO_BUF, _("N/A"));
|
1998-12-26 02:22:01 +08:00
|
|
|
g_snprintf (alpha_buf, MAX_INFO_BUF, _("N/A"));
|
|
|
|
g_snprintf (index_buf, MAX_INFO_BUF, _("N/A"));
|
1999-07-24 23:37:03 +08:00
|
|
|
g_snprintf (gray_buf, MAX_INFO_BUF, _("N/A"));
|
|
|
|
g_snprintf (hex_buf, MAX_INFO_BUF, _("N/A"));
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-01-15 09:48:53 +08:00
|
|
|
GimpRGB color;
|
|
|
|
guchar r = 0;
|
|
|
|
guchar g = 0;
|
|
|
|
guchar b = 0;
|
|
|
|
guchar a = 0;
|
1999-08-24 10:52:40 +08:00
|
|
|
|
2001-01-15 14:24:24 +08:00
|
|
|
if (! GTK_WIDGET_IS_SENSITIVE (color_area))
|
|
|
|
gtk_widget_set_sensitive (color_area, TRUE);
|
1999-08-24 10:52:40 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
switch (sample_type)
|
|
|
|
{
|
|
|
|
case RGB_GIMAGE: case RGBA_GIMAGE:
|
2000-03-09 21:02:11 +08:00
|
|
|
g_snprintf (index_buf, MAX_INFO_BUF, _("N/A"));
|
1999-07-24 23:37:03 +08:00
|
|
|
g_snprintf (red_buf, MAX_INFO_BUF, "%d", col_value [RED_PIX]);
|
1998-12-26 02:22:01 +08:00
|
|
|
g_snprintf (green_buf, MAX_INFO_BUF, "%d", col_value [GREEN_PIX]);
|
1999-07-24 23:37:03 +08:00
|
|
|
g_snprintf (blue_buf, MAX_INFO_BUF, "%d", col_value [BLUE_PIX]);
|
1997-11-25 06:05:25 +08:00
|
|
|
if (sample_type == RGBA_GIMAGE)
|
1998-12-26 02:22:01 +08:00
|
|
|
g_snprintf (alpha_buf, MAX_INFO_BUF, "%d", col_value [ALPHA_PIX]);
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
1998-12-26 02:22:01 +08:00
|
|
|
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]);
|
2001-01-08 05:07:14 +08:00
|
|
|
|
|
|
|
r = col_value [RED_PIX];
|
|
|
|
g = col_value [GREEN_PIX];
|
|
|
|
b = col_value [BLUE_PIX];
|
|
|
|
if (sample_type == RGBA_GIMAGE)
|
|
|
|
a = col_value [ALPHA_PIX];
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case INDEXED_GIMAGE: case INDEXEDA_GIMAGE:
|
1998-12-26 02:22:01 +08:00
|
|
|
g_snprintf (index_buf, MAX_INFO_BUF, "%d", col_value [4]);
|
2000-03-09 21:02:11 +08:00
|
|
|
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]);
|
1997-11-25 06:05:25 +08:00
|
|
|
if (sample_type == INDEXEDA_GIMAGE)
|
1998-12-26 02:22:01 +08:00
|
|
|
g_snprintf (alpha_buf, MAX_INFO_BUF, "%d", col_value [ALPHA_PIX]);
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
1998-12-26 02:22:01 +08:00
|
|
|
g_snprintf (alpha_buf, MAX_INFO_BUF, _("N/A"));
|
1999-07-24 23:37:03 +08:00
|
|
|
g_snprintf (hex_buf, MAX_INFO_BUF, "#%.2x%.2x%.2x",
|
1998-12-26 02:22:01 +08:00
|
|
|
col_value [RED_PIX],
|
|
|
|
col_value [GREEN_PIX],
|
|
|
|
col_value [BLUE_PIX]);
|
2001-01-08 05:07:14 +08:00
|
|
|
|
|
|
|
r = col_value [RED_PIX];
|
|
|
|
g = col_value [GREEN_PIX];
|
|
|
|
b = col_value [BLUE_PIX];
|
|
|
|
if (sample_type == INDEXEDA_GIMAGE)
|
|
|
|
a = col_value [ALPHA_PIX];
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GRAY_GIMAGE: case GRAYA_GIMAGE:
|
1998-12-26 02:22:01 +08:00
|
|
|
g_snprintf (gray_buf, MAX_INFO_BUF, "%d", col_value [GRAY_PIX]);
|
1997-11-25 06:05:25 +08:00
|
|
|
if (sample_type == GRAYA_GIMAGE)
|
1998-12-26 02:22:01 +08:00
|
|
|
g_snprintf (alpha_buf, MAX_INFO_BUF, "%d", col_value [ALPHA_PIX]);
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
1998-12-26 02:22:01 +08:00
|
|
|
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]);
|
2001-01-08 05:07:14 +08:00
|
|
|
|
|
|
|
r = col_value [GRAY_PIX];
|
|
|
|
g = col_value [GRAY_PIX];
|
|
|
|
b = col_value [GRAY_PIX];
|
|
|
|
if (sample_type == GRAYA_GIMAGE)
|
|
|
|
a = col_value [ALPHA_PIX];
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
}
|
1999-08-24 10:52:40 +08:00
|
|
|
|
2001-01-15 09:48:53 +08:00
|
|
|
gimp_rgba_set_uchar (&color, r, g, b, a);
|
|
|
|
|
2001-01-15 14:24:24 +08:00
|
|
|
gimp_color_area_set_color (GIMP_COLOR_AREA (color_area), &color);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
info_dialog_update (gimp_color_picker_tool_info);
|
|
|
|
info_dialog_popup (gimp_color_picker_tool_info);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1999-07-24 23:37:03 +08:00
|
|
|
static void
|
2001-02-27 13:21:12 +08:00
|
|
|
gimp_color_picker_tool_info_window_close_callback (GtkWidget *widget,
|
2001-02-28 03:18:01 +08:00
|
|
|
gpointer client_data)
|
1999-07-24 23:37:03 +08:00
|
|
|
{
|
|
|
|
info_dialog_popdown ((InfoDialog *) client_data);
|
|
|
|
}
|
2001-08-14 22:53:55 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* tool options stuff */
|
|
|
|
|
|
|
|
static GimpColorPickerToolOptions *
|
|
|
|
gimp_color_picker_tool_options_new (void)
|
|
|
|
{
|
|
|
|
GimpColorPickerToolOptions *options;
|
|
|
|
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *abox;
|
|
|
|
GtkWidget *table;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *scale;
|
|
|
|
|
|
|
|
options = g_new0 (GimpColorPickerToolOptions, 1);
|
|
|
|
tool_options_init ((GimpToolOptions *) options,
|
|
|
|
gimp_color_picker_tool_options_reset);
|
|
|
|
|
|
|
|
options->sample_merged = options->sample_merged_d = FALSE;
|
|
|
|
options->sample_average = options->sample_average_d = FALSE;
|
|
|
|
options->average_radius = options->average_radius_d = 1.0;
|
|
|
|
options->update_active = options->update_active_d = TRUE;
|
|
|
|
|
|
|
|
/* the main vbox */
|
|
|
|
vbox = options->tool_options.main_vbox;
|
|
|
|
|
|
|
|
/* the sample merged toggle button */
|
|
|
|
options->sample_merged_w =
|
|
|
|
gtk_check_button_new_with_label (_("Sample Merged"));
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->sample_merged_w),
|
|
|
|
options->sample_merged_d);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), options->sample_merged_w, FALSE, FALSE, 0);
|
|
|
|
g_signal_connect (G_OBJECT (options->sample_merged_w), "toggled",
|
|
|
|
G_CALLBACK (gimp_toggle_button_update),
|
|
|
|
&options->sample_merged);
|
|
|
|
gtk_widget_show (options->sample_merged_w);
|
|
|
|
|
|
|
|
/* the sample average options */
|
|
|
|
table = gtk_table_new (2, 2, FALSE);
|
|
|
|
gtk_table_set_col_spacing (GTK_TABLE (table), 0, 4);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
options->sample_average_w =
|
|
|
|
gtk_check_button_new_with_label (_("Sample Average"));
|
|
|
|
gtk_table_attach (GTK_TABLE (table), options->sample_average_w, 0, 1, 0, 1,
|
|
|
|
GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->sample_average_w),
|
|
|
|
options->sample_average_d);
|
|
|
|
g_signal_connect (G_OBJECT (options->sample_average_w), "toggled",
|
|
|
|
G_CALLBACK (gimp_toggle_button_update),
|
|
|
|
&options->sample_average);
|
|
|
|
gtk_widget_show (options->sample_average_w);
|
|
|
|
|
|
|
|
label = gtk_label_new (_("Radius:"));
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 1.0);
|
|
|
|
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2,
|
|
|
|
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
/* the feather radius scale */
|
|
|
|
abox = gtk_alignment_new (0.5, 1.0, 1.0, 0.0);
|
|
|
|
gtk_table_attach (GTK_TABLE (table), abox, 1, 2, 0, 2,
|
|
|
|
GTK_EXPAND | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
|
|
|
|
gtk_widget_show (abox);
|
|
|
|
|
|
|
|
options->average_radius_w =
|
|
|
|
gtk_adjustment_new (options->average_radius_d, 1.0, 15.0, 2.0, 2.0, 0.0);
|
|
|
|
scale = gtk_hscale_new (GTK_ADJUSTMENT (options->average_radius_w));
|
|
|
|
gtk_scale_set_digits (GTK_SCALE (scale), 0);
|
|
|
|
gtk_container_add (GTK_CONTAINER (abox), scale);
|
|
|
|
gtk_widget_set_sensitive (scale, options->sample_average_d);
|
|
|
|
g_object_set_data (G_OBJECT (options->sample_average_w), "set_sensitive",
|
|
|
|
scale);
|
|
|
|
gtk_widget_set_sensitive (label, options->sample_average_d);
|
|
|
|
g_object_set_data (G_OBJECT (scale), "set_sensitive",
|
|
|
|
label);
|
|
|
|
gtk_scale_set_value_pos (GTK_SCALE (scale), GTK_POS_TOP);
|
|
|
|
gtk_range_set_update_policy (GTK_RANGE (scale), GTK_UPDATE_DELAYED);
|
|
|
|
g_signal_connect (G_OBJECT (options->average_radius_w), "value_changed",
|
|
|
|
G_CALLBACK (gimp_double_adjustment_update),
|
|
|
|
&options->average_radius);
|
|
|
|
gtk_widget_show (scale);
|
|
|
|
gtk_widget_show (table);
|
|
|
|
|
|
|
|
/* the update active color toggle button */
|
|
|
|
options->update_active_w =
|
|
|
|
gtk_check_button_new_with_label (_("Update Active Color"));
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->update_active_w),
|
|
|
|
options->update_active_d);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), options->update_active_w, FALSE, FALSE, 0);
|
|
|
|
g_signal_connect (G_OBJECT (options->update_active_w), "toggled",
|
|
|
|
G_CALLBACK (gimp_toggle_button_update),
|
|
|
|
&options->update_active);
|
|
|
|
gtk_widget_show (options->update_active_w);
|
|
|
|
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_color_picker_tool_options_reset (GimpToolOptions *tool_options)
|
|
|
|
{
|
|
|
|
GimpColorPickerToolOptions *options;
|
|
|
|
|
|
|
|
options = (GimpColorPickerToolOptions *) tool_options;
|
|
|
|
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->sample_merged_w),
|
|
|
|
options->sample_merged_d);
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->sample_average_w),
|
|
|
|
options->sample_average_d);
|
|
|
|
gtk_adjustment_set_value (GTK_ADJUSTMENT (options->average_radius_w),
|
|
|
|
options->average_radius_d);
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->update_active_w),
|
|
|
|
options->update_active_d);
|
|
|
|
}
|