2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2003-06-04 23:48:17 +08:00
|
|
|
* Copyright (C) 1995-2001 Spencer Kimball, Peter Mattis, and others
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2003-06-04 23:48:17 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2003-06-04 23:48:17 +08:00
|
|
|
* (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
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2003-06-04 23:48:17 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2003-06-04 23:48:17 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2004-07-27 03:56:47 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
2003-06-04 23:48:17 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "tools-types.h"
|
|
|
|
|
2006-05-28 22:13:44 +08:00
|
|
|
#include "config/gimpdisplayconfig.h"
|
|
|
|
|
2005-03-09 08:23:19 +08:00
|
|
|
#include "core/gimp.h"
|
2006-05-28 22:13:44 +08:00
|
|
|
#include "core/gimpdata.h"
|
2003-06-04 23:48:17 +08:00
|
|
|
#include "core/gimpimage.h"
|
2003-06-05 04:23:36 +08:00
|
|
|
#include "core/gimpimage-pick-color.h"
|
2017-06-22 15:43:50 +08:00
|
|
|
#include "core/gimpimage-pick-item.h"
|
2005-03-09 08:23:19 +08:00
|
|
|
#include "core/gimpimage-sample-points.h"
|
2003-06-05 04:23:36 +08:00
|
|
|
#include "core/gimpmarshal.h"
|
2007-01-30 18:34:59 +08:00
|
|
|
#include "core/gimpsamplepoint.h"
|
2003-06-04 23:48:17 +08:00
|
|
|
|
2006-05-28 22:13:44 +08:00
|
|
|
#include "widgets/gimpcolormapeditor.h"
|
|
|
|
#include "widgets/gimpdialogfactory.h"
|
|
|
|
#include "widgets/gimpdockable.h"
|
2016-11-25 20:26:08 +08:00
|
|
|
#include "widgets/gimpdockcontainer.h"
|
2006-05-28 22:13:44 +08:00
|
|
|
#include "widgets/gimppaletteeditor.h"
|
2017-10-28 20:42:54 +08:00
|
|
|
#include "widgets/gimpwidgets-utils.h"
|
2012-01-31 06:33:21 +08:00
|
|
|
#include "widgets/gimpwindowstrategy.h"
|
2005-03-09 08:23:19 +08:00
|
|
|
|
2010-09-30 08:03:16 +08:00
|
|
|
#include "display/gimpcanvasitem.h"
|
2003-06-04 23:48:17 +08:00
|
|
|
#include "display/gimpdisplay.h"
|
2005-03-09 08:23:19 +08:00
|
|
|
#include "display/gimpdisplayshell.h"
|
|
|
|
#include "display/gimpdisplayshell-appearance.h"
|
2003-06-04 23:48:17 +08:00
|
|
|
|
|
|
|
#include "gimpcoloroptions.h"
|
|
|
|
#include "gimpcolortool.h"
|
2016-04-03 22:27:41 +08:00
|
|
|
#include "gimpsamplepointtool.h"
|
2003-06-04 23:48:17 +08:00
|
|
|
#include "gimptoolcontrol.h"
|
|
|
|
|
2005-03-09 08:23:19 +08:00
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
2003-06-04 23:48:17 +08:00
|
|
|
|
2003-06-05 04:23:36 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PICKED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-06-04 23:48:17 +08:00
|
|
|
/* local function prototypes */
|
|
|
|
|
2007-02-28 02:55:12 +08:00
|
|
|
static void gimp_color_tool_finalize (GObject *object);
|
|
|
|
|
|
|
|
static void gimp_color_tool_button_press (GimpTool *tool,
|
2008-11-01 23:17:36 +08:00
|
|
|
const GimpCoords *coords,
|
2007-02-28 02:55:12 +08:00
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
2009-06-20 23:37:31 +08:00
|
|
|
GimpButtonPressType press_type,
|
2007-02-28 02:55:12 +08:00
|
|
|
GimpDisplay *display);
|
|
|
|
static void gimp_color_tool_button_release (GimpTool *tool,
|
2008-11-01 23:17:36 +08:00
|
|
|
const GimpCoords *coords,
|
2007-02-28 02:55:12 +08:00
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpButtonReleaseType release_type,
|
|
|
|
GimpDisplay *display);
|
|
|
|
static void gimp_color_tool_motion (GimpTool *tool,
|
2008-11-01 23:17:36 +08:00
|
|
|
const GimpCoords *coords,
|
2007-02-28 02:55:12 +08:00
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display);
|
|
|
|
static void gimp_color_tool_oper_update (GimpTool *tool,
|
2008-11-01 23:17:36 +08:00
|
|
|
const GimpCoords *coords,
|
2007-02-28 02:55:12 +08:00
|
|
|
GdkModifierType state,
|
|
|
|
gboolean proximity,
|
|
|
|
GimpDisplay *display);
|
|
|
|
static void gimp_color_tool_cursor_update (GimpTool *tool,
|
2008-11-01 23:17:36 +08:00
|
|
|
const GimpCoords *coords,
|
2007-02-28 02:55:12 +08:00
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display);
|
|
|
|
|
|
|
|
static void gimp_color_tool_draw (GimpDrawTool *draw_tool);
|
|
|
|
|
2017-05-04 01:24:39 +08:00
|
|
|
static gboolean
|
2017-07-01 03:23:29 +08:00
|
|
|
gimp_color_tool_real_can_pick (GimpColorTool *color_tool,
|
2017-05-04 01:24:39 +08:00
|
|
|
const GimpCoords *coords,
|
|
|
|
GimpDisplay *display);
|
2007-02-28 02:55:12 +08:00
|
|
|
static gboolean gimp_color_tool_real_pick (GimpColorTool *color_tool,
|
2017-07-01 03:23:29 +08:00
|
|
|
const GimpCoords *coords,
|
|
|
|
GimpDisplay *display,
|
2012-03-29 03:37:59 +08:00
|
|
|
const Babl **sample_format,
|
2015-08-25 06:05:59 +08:00
|
|
|
gpointer pixel,
|
|
|
|
GimpRGB *color);
|
2007-02-28 02:55:12 +08:00
|
|
|
static void gimp_color_tool_real_picked (GimpColorTool *color_tool,
|
2017-07-01 03:23:29 +08:00
|
|
|
const GimpCoords *coords,
|
|
|
|
GimpDisplay *display,
|
2007-02-28 02:55:12 +08:00
|
|
|
GimpColorPickState pick_state,
|
2012-03-29 03:37:59 +08:00
|
|
|
const Babl *sample_format,
|
2015-08-25 06:05:59 +08:00
|
|
|
gpointer pixel,
|
|
|
|
const GimpRGB *color);
|
2003-06-05 04:23:36 +08:00
|
|
|
|
2017-05-04 01:24:39 +08:00
|
|
|
static gboolean gimp_color_tool_can_pick (GimpColorTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
GimpDisplay *display);
|
2014-12-01 20:49:40 +08:00
|
|
|
static void gimp_color_tool_pick (GimpColorTool *tool,
|
2017-07-01 03:23:29 +08:00
|
|
|
const GimpCoords *coords,
|
|
|
|
GimpDisplay *display,
|
|
|
|
GimpColorPickState pick_state);
|
2014-12-01 20:49:40 +08:00
|
|
|
|
2003-06-04 23:48:17 +08:00
|
|
|
|
2017-07-01 03:23:29 +08:00
|
|
|
G_DEFINE_TYPE (GimpColorTool, gimp_color_tool, GIMP_TYPE_DRAW_TOOL)
|
2003-06-04 23:48:17 +08:00
|
|
|
|
2005-12-13 17:13:50 +08:00
|
|
|
#define parent_class gimp_color_tool_parent_class
|
2003-06-04 23:48:17 +08:00
|
|
|
|
2005-12-13 17:13:50 +08:00
|
|
|
static guint gimp_color_tool_signals[LAST_SIGNAL] = { 0 };
|
2003-06-04 23:48:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_color_tool_class_init (GimpColorToolClass *klass)
|
|
|
|
{
|
2004-06-30 20:10:08 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
|
|
|
|
GimpDrawToolClass *draw_class = GIMP_DRAW_TOOL_CLASS (klass);
|
2003-06-04 23:48:17 +08:00
|
|
|
|
2003-06-05 04:23:36 +08:00
|
|
|
gimp_color_tool_signals[PICKED] =
|
|
|
|
g_signal_new ("picked",
|
2005-03-07 19:37:03 +08:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpColorToolClass, picked),
|
|
|
|
NULL, NULL,
|
2017-07-01 03:23:29 +08:00
|
|
|
gimp_marshal_VOID__POINTER_OBJECT_ENUM_POINTER_POINTER_BOXED,
|
2013-05-31 01:29:36 +08:00
|
|
|
G_TYPE_NONE, 6,
|
2017-07-01 03:23:29 +08:00
|
|
|
G_TYPE_POINTER,
|
|
|
|
GIMP_TYPE_DISPLAY,
|
2004-06-30 20:10:08 +08:00
|
|
|
GIMP_TYPE_COLOR_PICK_STATE,
|
2013-05-31 04:34:55 +08:00
|
|
|
G_TYPE_POINTER,
|
2015-08-25 06:05:59 +08:00
|
|
|
G_TYPE_POINTER,
|
|
|
|
GIMP_TYPE_RGB | G_SIGNAL_TYPE_STATIC_SCOPE);
|
2003-06-05 04:23:36 +08:00
|
|
|
|
2003-06-05 23:43:49 +08:00
|
|
|
object_class->finalize = gimp_color_tool_finalize;
|
|
|
|
|
2003-06-04 23:48:17 +08:00
|
|
|
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;
|
2005-03-09 08:23:19 +08:00
|
|
|
tool_class->oper_update = gimp_color_tool_oper_update;
|
2003-06-04 23:48:17 +08:00
|
|
|
tool_class->cursor_update = gimp_color_tool_cursor_update;
|
|
|
|
|
2005-03-07 19:37:03 +08:00
|
|
|
draw_class->draw = gimp_color_tool_draw;
|
2003-06-04 23:48:17 +08:00
|
|
|
|
2017-05-04 01:24:39 +08:00
|
|
|
klass->can_pick = gimp_color_tool_real_can_pick;
|
2003-06-05 04:23:36 +08:00
|
|
|
klass->pick = gimp_color_tool_real_pick;
|
2006-05-28 22:13:44 +08:00
|
|
|
klass->picked = gimp_color_tool_real_picked;
|
2003-06-04 23:48:17 +08:00
|
|
|
}
|
|
|
|
|
2005-03-09 08:23:19 +08:00
|
|
|
static void
|
|
|
|
gimp_color_tool_init (GimpColorTool *color_tool)
|
|
|
|
{
|
|
|
|
GimpTool *tool = GIMP_TOOL (color_tool);
|
|
|
|
|
2014-04-20 02:09:39 +08:00
|
|
|
gimp_tool_control_set_action_size (tool->control,
|
|
|
|
"tools/tools-color-average-radius-set");
|
2005-03-09 08:23:19 +08:00
|
|
|
}
|
|
|
|
|
2003-06-04 23:48:17 +08:00
|
|
|
static void
|
2003-06-05 23:43:49 +08:00
|
|
|
gimp_color_tool_finalize (GObject *object)
|
2003-06-04 23:48:17 +08:00
|
|
|
{
|
2003-06-05 23:43:49 +08:00
|
|
|
GimpColorTool *color_tool = GIMP_COLOR_TOOL (object);
|
|
|
|
|
2018-06-01 18:59:52 +08:00
|
|
|
g_clear_object (&color_tool->options);
|
2003-06-05 23:43:49 +08:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
2003-06-04 23:48:17 +08:00
|
|
|
|
|
|
|
static void
|
2009-06-20 23:37:31 +08:00
|
|
|
gimp_color_tool_button_press (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpButtonPressType press_type,
|
|
|
|
GimpDisplay *display)
|
2003-06-04 23:48:17 +08:00
|
|
|
{
|
2016-04-03 22:27:41 +08:00
|
|
|
GimpColorTool *color_tool = GIMP_COLOR_TOOL (tool);
|
2003-06-04 23:48:17 +08:00
|
|
|
|
2017-07-01 03:23:29 +08:00
|
|
|
if (color_tool->enabled)
|
2005-03-09 08:23:19 +08:00
|
|
|
{
|
2017-07-01 03:23:29 +08:00
|
|
|
if (color_tool->sample_point)
|
|
|
|
{
|
|
|
|
gimp_sample_point_tool_start_edit (tool, display,
|
|
|
|
color_tool->sample_point);
|
|
|
|
}
|
|
|
|
else if (gimp_color_tool_can_pick (color_tool, coords, display))
|
|
|
|
{
|
|
|
|
gimp_color_tool_pick (color_tool, coords, display,
|
|
|
|
GIMP_COLOR_PICK_STATE_START);
|
2008-07-22 22:43:52 +08:00
|
|
|
|
2017-07-01 03:23:29 +08:00
|
|
|
gimp_tool_control_activate (tool->control);
|
|
|
|
}
|
2005-03-09 08:23:19 +08:00
|
|
|
}
|
2017-07-01 03:23:29 +08:00
|
|
|
else
|
2003-06-04 23:48:17 +08:00
|
|
|
{
|
2017-07-01 03:23:29 +08:00
|
|
|
GIMP_TOOL_CLASS (parent_class)->button_press (tool, coords, time, state,
|
|
|
|
press_type, display);
|
2003-06-04 23:48:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-02-28 02:55:12 +08:00
|
|
|
gimp_color_tool_button_release (GimpTool *tool,
|
2008-11-01 23:17:36 +08:00
|
|
|
const GimpCoords *coords,
|
2007-02-28 02:55:12 +08:00
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpButtonReleaseType release_type,
|
|
|
|
GimpDisplay *display)
|
2003-06-04 23:48:17 +08:00
|
|
|
{
|
2016-04-03 22:27:41 +08:00
|
|
|
GimpColorTool *color_tool = GIMP_COLOR_TOOL (tool);
|
2003-06-04 23:48:17 +08:00
|
|
|
|
2017-07-01 03:23:29 +08:00
|
|
|
if (color_tool->enabled)
|
|
|
|
{
|
|
|
|
gimp_tool_control_halt (tool->control);
|
2005-03-09 08:23:19 +08:00
|
|
|
|
2017-07-01 03:23:29 +08:00
|
|
|
if (! color_tool->sample_point &&
|
|
|
|
gimp_color_tool_can_pick (color_tool, coords, display))
|
|
|
|
{
|
|
|
|
gimp_color_tool_pick (color_tool, coords, display,
|
|
|
|
GIMP_COLOR_PICK_STATE_END);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2005-03-09 08:23:19 +08:00
|
|
|
{
|
2017-07-01 03:23:29 +08:00
|
|
|
GIMP_TOOL_CLASS (parent_class)->button_release (tool, coords, time, state,
|
|
|
|
release_type, display);
|
2005-03-09 08:23:19 +08:00
|
|
|
}
|
2003-06-04 23:48:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-11-01 23:17:36 +08:00
|
|
|
gimp_color_tool_motion (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display)
|
2003-06-04 23:48:17 +08:00
|
|
|
{
|
2016-04-03 22:27:41 +08:00
|
|
|
GimpColorTool *color_tool = GIMP_COLOR_TOOL (tool);
|
2003-06-04 23:48:17 +08:00
|
|
|
|
2017-07-01 03:23:29 +08:00
|
|
|
if (color_tool->enabled)
|
2005-03-09 08:23:19 +08:00
|
|
|
{
|
2017-07-01 03:23:29 +08:00
|
|
|
if (! color_tool->sample_point)
|
|
|
|
{
|
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
|
2005-03-09 08:23:19 +08:00
|
|
|
|
2017-07-01 03:23:29 +08:00
|
|
|
color_tool->can_pick = gimp_color_tool_can_pick (color_tool,
|
|
|
|
coords, display);
|
|
|
|
color_tool->center_x = coords->x;
|
|
|
|
color_tool->center_y = coords->y;
|
2005-03-09 08:23:19 +08:00
|
|
|
|
2017-07-01 03:23:29 +08:00
|
|
|
if (color_tool->can_pick)
|
|
|
|
{
|
|
|
|
gimp_color_tool_pick (color_tool, coords, display,
|
|
|
|
GIMP_COLOR_PICK_STATE_UPDATE);
|
|
|
|
}
|
2005-03-09 08:23:19 +08:00
|
|
|
|
2017-07-01 03:23:29 +08:00
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->motion (tool, coords, time, state,
|
|
|
|
display);
|
2005-03-09 08:23:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-11-01 23:17:36 +08:00
|
|
|
gimp_color_tool_oper_update (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
GdkModifierType state,
|
|
|
|
gboolean proximity,
|
|
|
|
GimpDisplay *display)
|
2005-03-09 08:23:19 +08:00
|
|
|
{
|
2017-01-02 00:35:57 +08:00
|
|
|
GimpColorTool *color_tool = GIMP_COLOR_TOOL (tool);
|
2005-03-09 08:23:19 +08:00
|
|
|
|
2017-01-02 00:35:57 +08:00
|
|
|
if (color_tool->enabled)
|
2010-09-30 07:32:34 +08:00
|
|
|
{
|
2017-01-02 00:35:57 +08:00
|
|
|
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
|
|
|
|
GimpDisplayShell *shell = gimp_display_get_shell (display);
|
|
|
|
GimpSamplePoint *sample_point = NULL;
|
2005-03-09 08:23:19 +08:00
|
|
|
|
2010-09-30 07:32:34 +08:00
|
|
|
gimp_draw_tool_pause (draw_tool);
|
2005-03-09 08:23:19 +08:00
|
|
|
|
2017-07-01 22:26:34 +08:00
|
|
|
if (! draw_tool->widget &&
|
|
|
|
|
|
|
|
gimp_draw_tool_is_active (draw_tool) &&
|
2017-01-02 00:35:57 +08:00
|
|
|
(draw_tool->display != display ||
|
|
|
|
! proximity))
|
|
|
|
{
|
|
|
|
gimp_draw_tool_stop (draw_tool);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gimp_display_shell_get_show_sample_points (shell) &&
|
|
|
|
proximity)
|
|
|
|
{
|
|
|
|
GimpImage *image = gimp_display_get_image (display);
|
|
|
|
gint snap_distance = display->config->snap_distance;
|
|
|
|
|
|
|
|
sample_point =
|
2017-06-22 15:43:50 +08:00
|
|
|
gimp_image_pick_sample_point (image,
|
2017-01-02 00:35:57 +08:00
|
|
|
coords->x, coords->y,
|
|
|
|
FUNSCALEX (shell, snap_distance),
|
|
|
|
FUNSCALEY (shell, snap_distance));
|
|
|
|
}
|
2010-09-30 07:32:34 +08:00
|
|
|
|
|
|
|
color_tool->sample_point = sample_point;
|
|
|
|
|
2017-05-04 01:24:39 +08:00
|
|
|
color_tool->can_pick = gimp_color_tool_can_pick (color_tool,
|
|
|
|
coords, display);
|
2017-01-02 00:35:57 +08:00
|
|
|
color_tool->center_x = coords->x;
|
|
|
|
color_tool->center_y = coords->y;
|
|
|
|
|
2017-07-01 22:26:34 +08:00
|
|
|
if (! draw_tool->widget &&
|
|
|
|
|
|
|
|
! gimp_draw_tool_is_active (draw_tool) &&
|
2017-01-02 00:35:57 +08:00
|
|
|
proximity)
|
|
|
|
{
|
|
|
|
gimp_draw_tool_start (draw_tool, display);
|
|
|
|
}
|
2010-09-30 07:32:34 +08:00
|
|
|
|
|
|
|
gimp_draw_tool_resume (draw_tool);
|
2010-08-12 19:13:15 +08:00
|
|
|
}
|
2017-07-01 03:23:29 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->oper_update (tool, coords, state,
|
|
|
|
proximity, display);
|
|
|
|
}
|
2003-06-04 23:48:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-11-01 23:17:36 +08:00
|
|
|
gimp_color_tool_cursor_update (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display)
|
2003-06-04 23:48:17 +08:00
|
|
|
{
|
2003-06-06 02:47:23 +08:00
|
|
|
GimpColorTool *color_tool = GIMP_COLOR_TOOL (tool);
|
|
|
|
|
|
|
|
if (color_tool->enabled)
|
2003-06-04 23:48:17 +08:00
|
|
|
{
|
2005-03-09 08:23:19 +08:00
|
|
|
if (color_tool->sample_point)
|
2003-06-05 04:23:36 +08:00
|
|
|
{
|
2006-03-29 01:55:52 +08:00
|
|
|
gimp_tool_set_cursor (tool, display,
|
2005-11-20 06:16:34 +08:00
|
|
|
GIMP_CURSOR_MOUSE,
|
2005-03-09 08:23:19 +08:00
|
|
|
GIMP_TOOL_CURSOR_COLOR_PICKER,
|
|
|
|
GIMP_CURSOR_MODIFIER_MOVE);
|
2003-06-05 04:23:36 +08:00
|
|
|
}
|
2005-03-09 08:23:19 +08:00
|
|
|
else
|
2003-10-26 03:00:49 +08:00
|
|
|
{
|
2006-06-02 04:30:52 +08:00
|
|
|
GimpCursorModifier modifier = GIMP_CURSOR_MODIFIER_BAD;
|
2005-03-09 08:23:19 +08:00
|
|
|
|
2017-05-04 01:24:39 +08:00
|
|
|
if (gimp_color_tool_can_pick (color_tool, coords, display))
|
2005-03-09 08:23:19 +08:00
|
|
|
{
|
2018-07-15 20:32:53 +08:00
|
|
|
switch (color_tool->pick_target)
|
2006-06-02 04:30:52 +08:00
|
|
|
{
|
2018-07-15 20:32:53 +08:00
|
|
|
case GIMP_COLOR_PICK_TARGET_NONE:
|
2006-06-02 04:30:52 +08:00
|
|
|
modifier = GIMP_CURSOR_MODIFIER_NONE;
|
|
|
|
break;
|
2018-07-15 20:32:53 +08:00
|
|
|
case GIMP_COLOR_PICK_TARGET_FOREGROUND:
|
2006-06-02 04:30:52 +08:00
|
|
|
modifier = GIMP_CURSOR_MODIFIER_FOREGROUND;
|
|
|
|
break;
|
2018-07-15 20:32:53 +08:00
|
|
|
case GIMP_COLOR_PICK_TARGET_BACKGROUND:
|
2006-06-02 04:30:52 +08:00
|
|
|
modifier = GIMP_CURSOR_MODIFIER_BACKGROUND;
|
|
|
|
break;
|
2018-07-15 20:32:53 +08:00
|
|
|
case GIMP_COLOR_PICK_TARGET_PALETTE:
|
2006-06-02 04:30:52 +08:00
|
|
|
modifier = GIMP_CURSOR_MODIFIER_PLUS;
|
|
|
|
break;
|
|
|
|
}
|
2005-03-09 08:23:19 +08:00
|
|
|
}
|
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
gimp_tool_set_cursor (tool, display,
|
2006-06-02 04:30:52 +08:00
|
|
|
GIMP_CURSOR_COLOR_PICKER,
|
|
|
|
GIMP_TOOL_CURSOR_COLOR_PICKER,
|
2005-09-27 00:01:13 +08:00
|
|
|
modifier);
|
2003-10-26 03:00:49 +08:00
|
|
|
}
|
2003-06-04 23:48:17 +08:00
|
|
|
}
|
2017-07-01 03:23:29 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state,
|
|
|
|
display);
|
|
|
|
}
|
2003-06-04 23:48:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_color_tool_draw (GimpDrawTool *draw_tool)
|
|
|
|
{
|
2003-07-11 00:01:45 +08:00
|
|
|
GimpColorTool *color_tool = GIMP_COLOR_TOOL (draw_tool);
|
2003-06-04 23:48:17 +08:00
|
|
|
|
2017-07-01 22:26:34 +08:00
|
|
|
GIMP_DRAW_TOOL_CLASS (parent_class)->draw (draw_tool);
|
|
|
|
|
2007-07-19 17:09:26 +08:00
|
|
|
if (color_tool->enabled)
|
2003-06-05 04:23:36 +08:00
|
|
|
{
|
2010-09-30 07:32:34 +08:00
|
|
|
if (color_tool->sample_point)
|
|
|
|
{
|
|
|
|
GimpImage *image = gimp_display_get_image (draw_tool->display);
|
|
|
|
GimpCanvasItem *item;
|
|
|
|
gint index;
|
2016-01-05 05:06:27 +08:00
|
|
|
gint x;
|
|
|
|
gint y;
|
|
|
|
|
|
|
|
gimp_sample_point_get_position (color_tool->sample_point, &x, &y);
|
2010-09-30 07:32:34 +08:00
|
|
|
|
|
|
|
index = g_list_index (gimp_image_get_sample_points (image),
|
|
|
|
color_tool->sample_point) + 1;
|
|
|
|
|
2016-01-05 05:06:27 +08:00
|
|
|
item = gimp_draw_tool_add_sample_point (draw_tool, x, y, index);
|
2010-09-30 07:32:34 +08:00
|
|
|
gimp_canvas_item_set_highlight (item, TRUE);
|
|
|
|
}
|
2017-05-04 01:24:39 +08:00
|
|
|
else if (color_tool->can_pick && color_tool->options->sample_average)
|
2005-03-09 08:23:19 +08:00
|
|
|
{
|
2010-09-30 07:32:34 +08:00
|
|
|
gdouble radius = color_tool->options->average_radius;
|
|
|
|
|
|
|
|
gimp_draw_tool_add_rectangle (draw_tool,
|
|
|
|
FALSE,
|
|
|
|
color_tool->center_x - radius,
|
|
|
|
color_tool->center_y - radius,
|
|
|
|
2 * radius + 1,
|
|
|
|
2 * radius + 1);
|
2005-03-09 08:23:19 +08:00
|
|
|
}
|
2003-06-05 04:23:36 +08:00
|
|
|
}
|
2003-06-04 23:48:17 +08:00
|
|
|
}
|
|
|
|
|
2017-05-04 01:24:39 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_color_tool_real_can_pick (GimpColorTool *color_tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
GimpDisplay *display)
|
|
|
|
{
|
|
|
|
GimpImage *image = gimp_display_get_image (display);
|
|
|
|
|
2017-07-01 03:23:29 +08:00
|
|
|
return gimp_image_coords_in_active_pickable (image, coords,
|
|
|
|
color_tool->options->sample_merged,
|
|
|
|
FALSE);
|
2017-05-04 01:24:39 +08:00
|
|
|
}
|
|
|
|
|
2003-06-05 04:23:36 +08:00
|
|
|
static gboolean
|
2017-07-01 03:23:29 +08:00
|
|
|
gimp_color_tool_real_pick (GimpColorTool *color_tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
GimpDisplay *display,
|
|
|
|
const Babl **sample_format,
|
|
|
|
gpointer pixel,
|
|
|
|
GimpRGB *color)
|
2003-06-04 23:48:17 +08:00
|
|
|
{
|
2017-07-01 03:23:29 +08:00
|
|
|
GimpImage *image = gimp_display_get_image (display);
|
|
|
|
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
|
2003-06-05 04:23:36 +08:00
|
|
|
|
2017-07-01 03:23:29 +08:00
|
|
|
g_return_val_if_fail (drawable != NULL, FALSE);
|
2003-06-05 04:23:36 +08:00
|
|
|
|
2017-07-01 03:23:29 +08:00
|
|
|
return gimp_image_pick_color (image, drawable,
|
|
|
|
coords->x, coords->y,
|
2003-06-05 23:43:49 +08:00
|
|
|
color_tool->options->sample_merged,
|
|
|
|
color_tool->options->sample_average,
|
|
|
|
color_tool->options->average_radius,
|
2012-03-29 03:37:59 +08:00
|
|
|
sample_format,
|
2015-08-25 06:05:59 +08:00
|
|
|
pixel,
|
|
|
|
color);
|
2003-06-05 04:23:36 +08:00
|
|
|
}
|
|
|
|
|
2006-05-28 22:13:44 +08:00
|
|
|
static void
|
|
|
|
gimp_color_tool_real_picked (GimpColorTool *color_tool,
|
2017-07-01 03:23:29 +08:00
|
|
|
const GimpCoords *coords,
|
|
|
|
GimpDisplay *display,
|
2006-05-28 22:13:44 +08:00
|
|
|
GimpColorPickState pick_state,
|
2012-03-29 03:37:59 +08:00
|
|
|
const Babl *sample_format,
|
2015-08-25 06:05:59 +08:00
|
|
|
gpointer pixel,
|
|
|
|
const GimpRGB *color)
|
2006-05-28 22:13:44 +08:00
|
|
|
{
|
2016-11-25 20:26:08 +08:00
|
|
|
GimpTool *tool = GIMP_TOOL (color_tool);
|
2017-07-01 03:23:29 +08:00
|
|
|
GimpDisplayShell *shell = gimp_display_get_shell (display);
|
2016-11-25 20:26:08 +08:00
|
|
|
GimpImageWindow *image_window;
|
|
|
|
GimpDialogFactory *dialog_factory;
|
|
|
|
GimpContext *context;
|
|
|
|
|
|
|
|
image_window = gimp_display_shell_get_window (shell);
|
|
|
|
dialog_factory = gimp_dock_container_get_dialog_factory (GIMP_DOCK_CONTAINER (image_window));
|
2006-05-28 22:13:44 +08:00
|
|
|
|
2006-09-06 02:25:31 +08:00
|
|
|
/* use this tool's own options here (NOT color_tool->options) */
|
|
|
|
context = GIMP_CONTEXT (gimp_tool_get_options (tool));
|
|
|
|
|
2018-07-15 20:32:53 +08:00
|
|
|
if (color_tool->pick_target == GIMP_COLOR_PICK_TARGET_FOREGROUND ||
|
|
|
|
color_tool->pick_target == GIMP_COLOR_PICK_TARGET_BACKGROUND)
|
2006-05-28 22:13:44 +08:00
|
|
|
{
|
2012-01-11 02:33:42 +08:00
|
|
|
GtkWidget *widget;
|
2006-05-28 22:13:44 +08:00
|
|
|
|
2019-03-07 23:55:26 +08:00
|
|
|
widget = gimp_dialog_factory_find_widget (dialog_factory,
|
|
|
|
"gimp-indexed-palette");
|
|
|
|
if (widget)
|
2006-08-27 20:19:25 +08:00
|
|
|
{
|
2019-03-07 23:55:26 +08:00
|
|
|
GtkWidget *editor = gtk_bin_get_child (GTK_BIN (widget));
|
|
|
|
GimpImage *image = gimp_display_get_image (display);
|
|
|
|
|
|
|
|
if (babl_format_is_palette (sample_format))
|
2006-08-27 20:19:25 +08:00
|
|
|
{
|
2019-03-07 23:55:26 +08:00
|
|
|
guchar *index = pixel;
|
2006-08-27 20:19:25 +08:00
|
|
|
|
2014-12-01 20:49:40 +08:00
|
|
|
gimp_colormap_editor_set_index (GIMP_COLORMAP_EDITOR (editor),
|
2015-08-25 06:05:59 +08:00
|
|
|
*index, NULL);
|
2006-08-27 20:19:25 +08:00
|
|
|
}
|
2019-03-07 23:55:26 +08:00
|
|
|
else if (gimp_image_get_base_type (image) == GIMP_INDEXED)
|
|
|
|
{
|
|
|
|
/* When Sample merged is set, we don't have the index
|
|
|
|
* information and it is possible to pick colors out of
|
|
|
|
* the colormap (with compositing). In such a case, the
|
|
|
|
* sample format will not be a palette format even though
|
|
|
|
* the image is indexed. Still search if the color exists
|
|
|
|
* in the colormap.
|
|
|
|
* Note that even if it does, we might still pick the
|
|
|
|
* wrong color, since several indexes may contain the same
|
|
|
|
* color and we can't know for sure which is the right
|
|
|
|
* one.
|
|
|
|
*/
|
|
|
|
gint index = gimp_colormap_editor_get_index (GIMP_COLORMAP_EDITOR (editor),
|
|
|
|
color);
|
|
|
|
if (index > -1)
|
|
|
|
gimp_colormap_editor_set_index (GIMP_COLORMAP_EDITOR (editor),
|
|
|
|
index, NULL);
|
|
|
|
}
|
2006-08-27 20:19:25 +08:00
|
|
|
}
|
|
|
|
|
2016-11-25 20:26:08 +08:00
|
|
|
widget = gimp_dialog_factory_find_widget (dialog_factory,
|
2014-12-01 20:49:40 +08:00
|
|
|
"gimp-palette-editor");
|
|
|
|
if (widget)
|
2006-05-28 22:13:44 +08:00
|
|
|
{
|
2014-12-01 20:49:40 +08:00
|
|
|
GtkWidget *editor = gtk_bin_get_child (GTK_BIN (widget));
|
|
|
|
gint index;
|
|
|
|
|
|
|
|
index = gimp_palette_editor_get_index (GIMP_PALETTE_EDITOR (editor),
|
|
|
|
color);
|
|
|
|
if (index != -1)
|
|
|
|
gimp_palette_editor_set_index (GIMP_PALETTE_EDITOR (editor),
|
|
|
|
index, NULL);
|
2006-05-28 22:13:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-15 20:32:53 +08:00
|
|
|
switch (color_tool->pick_target)
|
2006-05-28 22:13:44 +08:00
|
|
|
{
|
2018-07-15 20:32:53 +08:00
|
|
|
case GIMP_COLOR_PICK_TARGET_NONE:
|
2006-05-28 22:13:44 +08:00
|
|
|
break;
|
|
|
|
|
2018-07-15 20:32:53 +08:00
|
|
|
case GIMP_COLOR_PICK_TARGET_FOREGROUND:
|
2006-09-06 02:25:31 +08:00
|
|
|
gimp_context_set_foreground (context, color);
|
2006-05-28 22:13:44 +08:00
|
|
|
break;
|
|
|
|
|
2018-07-15 20:32:53 +08:00
|
|
|
case GIMP_COLOR_PICK_TARGET_BACKGROUND:
|
2006-09-06 02:25:31 +08:00
|
|
|
gimp_context_set_background (context, color);
|
2006-05-28 22:13:44 +08:00
|
|
|
break;
|
|
|
|
|
2018-07-15 20:32:53 +08:00
|
|
|
case GIMP_COLOR_PICK_TARGET_PALETTE:
|
2006-05-28 22:13:44 +08:00
|
|
|
{
|
2018-04-29 23:27:47 +08:00
|
|
|
GdkMonitor *monitor = gimp_widget_get_monitor (GTK_WIDGET (shell));
|
|
|
|
GtkWidget *dockable;
|
2006-05-28 22:13:44 +08:00
|
|
|
|
2012-01-31 06:24:44 +08:00
|
|
|
dockable =
|
2017-07-01 03:23:29 +08:00
|
|
|
gimp_window_strategy_show_dockable_dialog (GIMP_WINDOW_STRATEGY (gimp_get_window_strategy (display->gimp)),
|
|
|
|
display->gimp,
|
2016-11-25 20:26:08 +08:00
|
|
|
dialog_factory,
|
2014-05-02 09:01:23 +08:00
|
|
|
monitor,
|
2012-01-31 06:24:44 +08:00
|
|
|
"gimp-palette-editor");
|
|
|
|
|
2006-05-28 22:13:44 +08:00
|
|
|
if (dockable)
|
|
|
|
{
|
|
|
|
GtkWidget *palette_editor;
|
|
|
|
GimpData *data;
|
|
|
|
|
|
|
|
/* don't blink like mad when updating */
|
2014-11-28 19:00:53 +08:00
|
|
|
if (pick_state != GIMP_COLOR_PICK_STATE_START)
|
2017-10-28 20:42:54 +08:00
|
|
|
gimp_widget_blink_cancel (dockable);
|
2006-05-28 22:13:44 +08:00
|
|
|
|
|
|
|
palette_editor = gtk_bin_get_child (GTK_BIN (dockable));
|
|
|
|
|
|
|
|
data = gimp_data_editor_get_data (GIMP_DATA_EDITOR (palette_editor));
|
|
|
|
|
|
|
|
if (! data)
|
|
|
|
{
|
2006-09-06 02:25:31 +08:00
|
|
|
data = GIMP_DATA (gimp_context_get_palette (context));
|
2006-05-28 22:13:44 +08:00
|
|
|
|
|
|
|
gimp_data_editor_set_data (GIMP_DATA_EDITOR (palette_editor),
|
|
|
|
data);
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_palette_editor_pick_color (GIMP_PALETTE_EDITOR (palette_editor),
|
|
|
|
color, pick_state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-04 01:24:39 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_color_tool_can_pick (GimpColorTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
GimpDisplay *display)
|
|
|
|
{
|
|
|
|
GimpColorToolClass *klass;
|
|
|
|
|
|
|
|
klass = GIMP_COLOR_TOOL_GET_CLASS (tool);
|
|
|
|
|
|
|
|
return klass->can_pick && klass->can_pick (tool, coords, display);
|
|
|
|
}
|
|
|
|
|
2003-06-05 04:23:36 +08:00
|
|
|
static void
|
2004-06-30 20:10:08 +08:00
|
|
|
gimp_color_tool_pick (GimpColorTool *tool,
|
2017-07-01 03:23:29 +08:00
|
|
|
const GimpCoords *coords,
|
|
|
|
GimpDisplay *display,
|
|
|
|
GimpColorPickState pick_state)
|
2003-06-05 04:23:36 +08:00
|
|
|
{
|
|
|
|
GimpColorToolClass *klass;
|
2012-03-29 03:37:59 +08:00
|
|
|
const Babl *sample_format;
|
2015-08-25 06:05:59 +08:00
|
|
|
guchar pixel[32];
|
2003-06-05 04:23:36 +08:00
|
|
|
GimpRGB color;
|
2003-06-04 23:48:17 +08:00
|
|
|
|
|
|
|
klass = GIMP_COLOR_TOOL_GET_CLASS (tool);
|
|
|
|
|
2003-06-05 04:23:36 +08:00
|
|
|
if (klass->pick &&
|
2017-07-01 03:23:29 +08:00
|
|
|
klass->pick (tool, coords, display, &sample_format, pixel, &color))
|
2003-06-05 04:23:36 +08:00
|
|
|
{
|
2004-06-30 20:10:08 +08:00
|
|
|
g_signal_emit (tool, gimp_color_tool_signals[PICKED], 0,
|
2017-07-01 03:23:29 +08:00
|
|
|
coords, display, pick_state,
|
2015-08-25 06:05:59 +08:00
|
|
|
sample_format, pixel, &color);
|
2003-06-05 04:23:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-01 20:49:40 +08:00
|
|
|
/* public functions */
|
|
|
|
|
2003-06-05 04:23:36 +08:00
|
|
|
void
|
2003-06-05 23:43:49 +08:00
|
|
|
gimp_color_tool_enable (GimpColorTool *color_tool,
|
|
|
|
GimpColorOptions *options)
|
2003-06-05 04:23:36 +08:00
|
|
|
{
|
|
|
|
GimpTool *tool;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_COLOR_TOOL (color_tool));
|
2003-06-05 23:43:49 +08:00
|
|
|
g_return_if_fail (GIMP_IS_COLOR_OPTIONS (options));
|
2003-06-05 04:23:36 +08:00
|
|
|
|
|
|
|
tool = GIMP_TOOL (color_tool);
|
2005-03-07 19:37:03 +08:00
|
|
|
|
2003-06-05 04:23:36 +08:00
|
|
|
if (gimp_tool_control_is_active (tool->control))
|
|
|
|
{
|
2003-06-05 23:43:49 +08:00
|
|
|
g_warning ("Trying to enable GimpColorTool while it is active.");
|
2003-06-05 04:23:36 +08:00
|
|
|
return;
|
|
|
|
}
|
2003-06-04 23:48:17 +08:00
|
|
|
|
2018-06-01 18:59:52 +08:00
|
|
|
g_set_object (&color_tool->options, options);
|
2003-06-05 23:43:49 +08:00
|
|
|
|
2017-01-02 00:59:26 +08:00
|
|
|
/* color picking doesn't snap, see bug #768058 */
|
|
|
|
color_tool->saved_snap_to = gimp_tool_control_get_snap_to (tool->control);
|
|
|
|
gimp_tool_control_set_snap_to (tool->control, FALSE);
|
|
|
|
|
2003-06-05 23:43:49 +08:00
|
|
|
color_tool->enabled = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_color_tool_disable (GimpColorTool *color_tool)
|
|
|
|
{
|
|
|
|
GimpTool *tool;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_COLOR_TOOL (color_tool));
|
|
|
|
|
|
|
|
tool = GIMP_TOOL (color_tool);
|
2005-03-07 19:37:03 +08:00
|
|
|
|
2003-06-05 23:43:49 +08:00
|
|
|
if (gimp_tool_control_is_active (tool->control))
|
|
|
|
{
|
|
|
|
g_warning ("Trying to disable GimpColorTool while it is active.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-01 18:59:52 +08:00
|
|
|
g_clear_object (&color_tool->options);
|
2003-06-05 23:43:49 +08:00
|
|
|
|
2017-01-02 00:59:26 +08:00
|
|
|
gimp_tool_control_set_snap_to (tool->control, color_tool->saved_snap_to);
|
|
|
|
color_tool->saved_snap_to = FALSE;
|
|
|
|
|
2003-06-05 23:43:49 +08:00
|
|
|
color_tool->enabled = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gimp_color_tool_is_enabled (GimpColorTool *color_tool)
|
|
|
|
{
|
|
|
|
return color_tool->enabled;
|
2003-06-04 23:48:17 +08:00
|
|
|
}
|