app/tools/Makefile.am app/tools/gimpcoloroptions.[ch] new files that

2003-06-04  Sven Neumann  <sven@gimp.org>

        * app/tools/Makefile.am
        * app/tools/gimpcoloroptions.[ch]
        * app/tools/gimpcolortool.[ch]: new files that implement base
        classes moved out of GimpColorPickerOptions and GimpColorPickerTool.

        * app/tools/gimpcolorpickeroptions.[ch]
        * app/tools/gimpcolorpickertool.[ch]: derive from the new obejcts.

        * app/tools/gimpimagemaptool.h
        * app/tools/gimppainttool.c
        * app/tools/tools-types.h: moved typedefs into the types file.
This commit is contained in:
Sven Neumann 2003-06-04 15:48:17 +00:00 committed by Sven Neumann
parent 909325ee67
commit 737bf44e28
14 changed files with 753 additions and 315 deletions

View File

@ -1,3 +1,17 @@
2003-06-04 Sven Neumann <sven@gimp.org>
* app/tools/Makefile.am
* app/tools/gimpcoloroptions.[ch]
* app/tools/gimpcolortool.[ch]: new files that implement base
classes moved out of GimpColorPickerOptions and GimpColorPickerTool.
* app/tools/gimpcolorpickeroptions.[ch]
* app/tools/gimpcolorpickertool.[ch]: derive from the new obejcts.
* app/tools/gimpimagemaptool.h
* app/tools/gimppainttool.c
* app/tools/tools-types.h: moved typedefs into the types file.
2003-06-04 Michael Natterer <mitch@gimp.org>
* app/display/gimpdisplayshell.c (gimp_display_shell_reconnect):

View File

@ -23,6 +23,10 @@ libapptools_a_sources = \
gimpbycolorselecttool.h \
gimpclonetool.c \
gimpclonetool.h \
gimpcoloroptions.c \
gimpcoloroptions.h \
gimpcolortool.c \
gimpcolortool.h \
gimpcolorbalancetool.c \
gimpcolorbalancetool.h \
gimpcolorizetool.c \

View File

@ -616,13 +616,13 @@ gimp_paint_tool_draw (GimpDrawTool *draw_tool)
if (paint_tool->pick_state)
{
GimpToolInfo *info;
GimpColorPickerOptions *options;
GimpToolInfo *info;
GimpColorOptions *options;
info = tool_manager_get_info_by_type (GIMP_TOOL (draw_tool)->tool_info->gimp,
GIMP_TYPE_COLOR_PICKER_TOOL);
options = GIMP_COLOR_PICKER_OPTIONS (info->tool_options);
options = GIMP_COLOR_OPTIONS (info->tool_options);
if (options->sample_average)
{
@ -675,24 +675,24 @@ gimp_paint_tool_sample_color (GimpDrawable *drawable,
gint y,
gint state)
{
GimpToolInfo *picker_info;
GimpColorPickerOptions *picker_options;
GimpImage *gimage;
GimpRGB color;
GimpToolInfo *picker_info;
GimpColorOptions *options;
GimpImage *gimage;
GimpRGB color;
gimage = gimp_item_get_image (GIMP_ITEM (drawable));
picker_info = tool_manager_get_info_by_type (gimage->gimp,
GIMP_TYPE_COLOR_PICKER_TOOL);
picker_options = GIMP_COLOR_PICKER_OPTIONS (picker_info->tool_options);
options = GIMP_COLOR_OPTIONS (picker_info->tool_options);
if (gimp_image_pick_color (gimage,
drawable,
picker_options->sample_merged,
options->sample_merged,
x, y,
picker_options->sample_average,
picker_options->average_radius,
options->sample_average,
options->average_radius,
&color,
NULL,
NULL))

View File

@ -0,0 +1,221 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995-2001 Spencer Kimball, Peter Mattis, and others
*
* 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
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "tools-types.h"
#include "config/gimpconfig-params.h"
#include "widgets/gimppropwidgets.h"
#include "gimpcoloroptions.h"
#include "gimp-intl.h"
enum
{
PROP_0,
PROP_SAMPLE_MERGED,
PROP_SAMPLE_AVERAGE,
PROP_AVERAGE_RADIUS
};
static void gimp_color_options_init (GimpColorOptions *options);
static void gimp_color_options_class_init (GimpColorOptionsClass *options_class);
static void gimp_color_options_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_color_options_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static GimpToolOptionsClass *parent_class = NULL;
GType
gimp_color_options_get_type (void)
{
static GType type = 0;
if (! type)
{
static const GTypeInfo info =
{
sizeof (GimpColorOptionsClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_color_options_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpColorOptions),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_color_options_init,
};
type = g_type_register_static (GIMP_TYPE_TOOL_OPTIONS,
"GimpColorOptions",
&info, 0);
}
return type;
}
static void
gimp_color_options_class_init (GimpColorOptionsClass *klass)
{
GObjectClass *object_class;
object_class = G_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->set_property = gimp_color_options_set_property;
object_class->get_property = gimp_color_options_get_property;
GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_SAMPLE_MERGED,
"sample-merged", NULL,
FALSE,
0);
GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_SAMPLE_AVERAGE,
"sample-average", NULL,
FALSE,
0);
GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_AVERAGE_RADIUS,
"average-radius", NULL,
1.0, 15.0, 1.0,
0);
}
static void
gimp_color_options_init (GimpColorOptions *options)
{
}
static void
gimp_color_options_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpColorOptions *options;
options = GIMP_COLOR_OPTIONS (object);
switch (property_id)
{
case PROP_SAMPLE_MERGED:
options->sample_merged = g_value_get_boolean (value);
break;
case PROP_SAMPLE_AVERAGE:
options->sample_average = g_value_get_boolean (value);
break;
case PROP_AVERAGE_RADIUS:
options->average_radius = g_value_get_double (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_color_options_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpColorOptions *options;
options = GIMP_COLOR_OPTIONS (object);
switch (property_id)
{
case PROP_SAMPLE_MERGED:
g_value_set_boolean (value, options->sample_merged);
break;
case PROP_SAMPLE_AVERAGE:
g_value_set_boolean (value, options->sample_average);
break;
case PROP_AVERAGE_RADIUS:
g_value_set_double (value, options->average_radius);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
GtkWidget *
gimp_color_options_gui (GimpToolOptions *tool_options)
{
GObject *config;
GtkWidget *vbox;
GtkWidget *frame;
GtkWidget *table;
GtkWidget *button;
config = G_OBJECT (tool_options);
vbox = gimp_tool_options_gui (tool_options);
/* the sample merged toggle button */
button = gimp_prop_check_button_new (config, "sample-merged",
_("Sample Merged"));
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
/* the sample average options */
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);
gtk_widget_show (frame);
table = gtk_table_new (1, 3, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 2);
gtk_container_set_border_width (GTK_CONTAINER (table), 2);
gtk_container_add (GTK_CONTAINER (frame), table);
gtk_widget_show (table);
button = gimp_prop_check_button_new (config, "sample-average",
_("Sample Average"));
gtk_frame_set_label_widget (GTK_FRAME (frame), button);
gtk_widget_show (button);
gtk_widget_set_sensitive (table,
GIMP_COLOR_OPTIONS (config)->sample_average);
g_object_set_data (G_OBJECT (button), "set_sensitive", table);
gimp_prop_scale_entry_new (config, "average-radius",
GTK_TABLE (table), 0, 0,
_("Radius:"),
1.0, 3.0, 0,
FALSE, 0.0, 0.0);
return vbox;
}

View File

@ -0,0 +1,51 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 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
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_COLOR_OPTIONS_H__
#define __GIMP_COLOR_OPTIONS_H__
#include "tool_options.h"
#define GIMP_TYPE_COLOR_OPTIONS (gimp_color_options_get_type ())
#define GIMP_COLOR_OPTIONS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_COLOR_OPTIONS, GimpColorOptions))
#define GIMP_COLOR_OPTIONS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_COLOR_OPTIONS, GimpColorOptionsClass))
#define GIMP_IS_COLOR_OPTIONS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_COLOR_OPTIONS))
#define GIMP_IS_COLOR_OPTIONS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_COLOR_OPTIONS))
#define GIMP_COLOR_OPTIONS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_COLOR_OPTIONS, GimpColorOptionsClass))
typedef struct _GimpToolOptionsClass GimpColorOptionsClass;
struct _GimpColorOptions
{
GimpToolOptions parent_instance;
gboolean sample_merged;
gboolean sample_average;
gdouble average_radius;
};
GType gimp_color_options_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_color_options_gui (GimpToolOptions *tool_options);
#endif /* __GIMP_COLOR_OPTIONS_H__ */

View File

@ -79,7 +79,7 @@ gimp_color_picker_options_get_type (void)
(GInstanceInitFunc) gimp_color_picker_options_init,
};
type = g_type_register_static (GIMP_TYPE_TOOL_OPTIONS,
type = g_type_register_static (GIMP_TYPE_COLOR_OPTIONS,
"GimpColorPickerOptions",
&info, 0);
}
@ -99,18 +99,6 @@ gimp_color_picker_options_class_init (GimpColorPickerOptionsClass *klass)
object_class->set_property = gimp_color_picker_options_set_property;
object_class->get_property = gimp_color_picker_options_get_property;
GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_SAMPLE_MERGED,
"sample-merged", NULL,
FALSE,
0);
GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_SAMPLE_AVERAGE,
"sample-average", NULL,
FALSE,
0);
GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_AVERAGE_RADIUS,
"average-radius", NULL,
1.0, 15.0, 1.0,
0);
GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_UPDATE_ACTIVE,
"update-active", NULL,
TRUE,
@ -134,15 +122,6 @@ gimp_color_picker_options_set_property (GObject *object,
switch (property_id)
{
case PROP_SAMPLE_MERGED:
options->sample_merged = g_value_get_boolean (value);
break;
case PROP_SAMPLE_AVERAGE:
options->sample_average = g_value_get_boolean (value);
break;
case PROP_AVERAGE_RADIUS:
options->average_radius = g_value_get_double (value);
break;
case PROP_UPDATE_ACTIVE:
options->update_active = g_value_get_boolean (value);
break;
@ -164,15 +143,6 @@ gimp_color_picker_options_get_property (GObject *object,
switch (property_id)
{
case PROP_SAMPLE_MERGED:
g_value_set_boolean (value, options->sample_merged);
break;
case PROP_SAMPLE_AVERAGE:
g_value_set_boolean (value, options->sample_average);
break;
case PROP_AVERAGE_RADIUS:
g_value_set_double (value, options->average_radius);
break;
case PROP_UPDATE_ACTIVE:
g_value_set_boolean (value, options->update_active);
break;
@ -187,46 +157,11 @@ gimp_color_picker_options_gui (GimpToolOptions *tool_options)
{
GObject *config;
GtkWidget *vbox;
GtkWidget *frame;
GtkWidget *table;
GtkWidget *button;
config = G_OBJECT (tool_options);
vbox = gimp_tool_options_gui (tool_options);
/* the sample merged toggle button */
button = gimp_prop_check_button_new (config, "sample-merged",
_("Sample Merged"));
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
/* the sample average options */
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);
gtk_widget_show (frame);
table = gtk_table_new (1, 3, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 2);
gtk_container_set_border_width (GTK_CONTAINER (table), 2);
gtk_container_add (GTK_CONTAINER (frame), table);
gtk_widget_show (table);
button = gimp_prop_check_button_new (config, "sample-average",
_("Sample Average"));
gtk_frame_set_label_widget (GTK_FRAME (frame), button);
gtk_widget_show (button);
gtk_widget_set_sensitive (table,
GIMP_COLOR_PICKER_OPTIONS (config)->sample_average);
g_object_set_data (G_OBJECT (button), "set_sensitive", table);
gimp_prop_scale_entry_new (config, "average-radius",
GTK_TABLE (table), 0, 0,
_("Radius:"),
1.0, 3.0, 0,
FALSE, 0.0, 0.0);
vbox = gimp_color_options_gui (tool_options);
/* the update active color toggle button */
button = gimp_prop_check_button_new (config, "update-active",

View File

@ -20,7 +20,7 @@
#define __GIMP_COLOR_PICKER_OPTIONS_H__
#include "tool_options.h"
#include "gimpcoloroptions.h"
#define GIMP_TYPE_COLOR_PICKER_OPTIONS (gimp_color_picker_options_get_type ())
@ -36,12 +36,9 @@ typedef struct _GimpToolOptionsClass GimpColorPickerOptionsClass;
struct _GimpColorPickerOptions
{
GimpToolOptions parent_instance;
GimpColorOptions parent_instance;
gboolean sample_merged;
gboolean sample_average;
gdouble average_radius;
gboolean update_active;
gboolean update_active;
};

View File

@ -60,42 +60,31 @@
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_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 void gimp_color_picker_tool_cursor_update (GimpTool *tool,
GimpCoords *coords,
GdkModifierType state,
GimpDisplay *gdisp);
static void gimp_color_picker_tool_draw (GimpDrawTool *draw_tool);
static gboolean gimp_color_picker_tool_pick_color (GimpImage *gimage,
GimpDrawable *drawable,
gint x,
gint y,
gboolean sample_merged,
gboolean sample_average,
gdouble average_radius,
gboolean update_active,
GimpUpdateColorState update_state);
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 InfoDialog * gimp_color_picker_tool_info_create (GimpToolInfo *tool_info,
GimpDrawable *drawable);
@ -118,7 +107,7 @@ static gchar index_buf[MAX_INFO_BUF];
static gchar gray_buf [MAX_INFO_BUF];
static gchar hex_buf [MAX_INFO_BUF];
static GimpDrawToolClass *parent_class = NULL;
static GimpColorToolClass *parent_class = NULL;
void
@ -158,7 +147,7 @@ gimp_color_picker_tool_get_type (void)
(GInstanceInitFunc) gimp_color_picker_tool_init,
};
tool_type = g_type_register_static (GIMP_TYPE_DRAW_TOOL,
tool_type = g_type_register_static (GIMP_TYPE_COLOR_TOOL,
"GimpColorPickerTool",
&tool_info, 0);
}
@ -169,13 +158,13 @@ gimp_color_picker_tool_get_type (void)
static void
gimp_color_picker_tool_class_init (GimpColorPickerToolClass *klass)
{
GObjectClass *object_class;
GimpToolClass *tool_class;
GimpDrawToolClass *draw_class;
GObjectClass *object_class;
GimpToolClass *tool_class;
GimpColorToolClass *color_tool_class;
object_class = G_OBJECT_CLASS (klass);
tool_class = GIMP_TOOL_CLASS (klass);
draw_class = GIMP_DRAW_TOOL_CLASS (klass);
object_class = G_OBJECT_CLASS (klass);
tool_class = GIMP_TOOL_CLASS (klass);
color_tool_class = GIMP_COLOR_TOOL_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
@ -185,20 +174,16 @@ gimp_color_picker_tool_class_init (GimpColorPickerToolClass *klass)
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;
color_tool_class->pick = gimp_color_picker_tool_pick;
}
static void
gimp_color_picker_tool_init (GimpColorPickerTool *color_picker_tool)
{
GimpTool *tool;
GimpTool *tool = GIMP_TOOL (color_picker_tool);
tool = GIMP_TOOL (color_picker_tool);
gimp_tool_control_set_preserve (tool->control, FALSE);
gimp_tool_control_set_tool_cursor (tool->control, GIMP_COLOR_PICKER_TOOL_CURSOR);
gimp_tool_control_set_preserve (tool->control, FALSE);
}
static void
@ -222,14 +207,9 @@ gimp_color_picker_tool_control (GimpTool *tool,
{
switch (action)
{
case PAUSE :
break;
case RESUME :
break;
case HALT :
info_dialog_popdown (gimp_color_picker_tool_info);
case HALT:
if (gimp_color_picker_tool_info)
info_dialog_popdown (gimp_color_picker_tool_info);
break;
default:
@ -246,17 +226,14 @@ gimp_color_picker_tool_button_press (GimpTool *tool,
GdkModifierType state,
GimpDisplay *gdisp)
{
GimpColorPickerTool *cp_tool;
GimpColorPickerOptions *options;
gint off_x, off_y;
GimpColorPickerTool *cp_tool;
GimpColorOptions *options;
GIMP_TOOL_CLASS (parent_class)->button_press (tool,
coords, time, state, gdisp);
cp_tool = GIMP_COLOR_PICKER_TOOL (tool);
options = GIMP_COLOR_PICKER_OPTIONS (tool->tool_info->tool_options);
/* 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);
options = GIMP_COLOR_OPTIONS (tool->tool_info->tool_options);
if (! gimp_color_picker_tool_info)
gimp_color_picker_tool_info =
@ -266,49 +243,24 @@ gimp_color_picker_tool_button_press (GimpTool *tool,
gimp_viewable_dialog_set_viewable (GIMP_VIEWABLE_DIALOG (gimp_color_picker_tool_info->shell),
GIMP_VIEWABLE (tool->drawable));
/* 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;
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)
{
gimp_color_picker_tool_info_update
(tool,
gimp_color_picker_tool_pick_color (gdisp->gimage,
tool->drawable,
coords->x,
coords->y,
options->sample_merged,
options->sample_average,
options->average_radius,
options->update_active,
GIMP_UPDATE_COLOR_STATE_NEW));
update_type = GIMP_UPDATE_COLOR_STATE_UPDATE_NEW;
}
else
{
gimp_color_picker_tool_info_update
(tool,
gimp_color_picker_tool_pick_color (gdisp->gimage,
tool->drawable,
coords->x,
coords->y,
options->sample_merged,
options->sample_average,
options->average_radius,
options->update_active,
GIMP_UPDATE_COLOR_STATE_UPDATE));
update_type = GIMP_UPDATE_COLOR_STATE_UPDATE;
}
gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), gdisp);
}
static void
@ -318,27 +270,21 @@ gimp_color_picker_tool_button_release (GimpTool *tool,
GdkModifierType state,
GimpDisplay *gdisp)
{
GimpColorPickerTool *cp_tool;
GimpColorPickerOptions *options;
GimpColorPickerTool *cp_tool;
GimpColorOptions *options;
cp_tool = GIMP_COLOR_PICKER_TOOL(tool);
options = GIMP_COLOR_PICKER_OPTIONS (tool->tool_info->tool_options);
options = GIMP_COLOR_OPTIONS (tool->tool_info->tool_options);
gimp_color_picker_tool_info_update
(tool,
gimp_color_picker_tool_pick_color (gdisp->gimage,
tool->drawable,
coords->x,
coords->y,
options->sample_merged,
options->sample_average,
options->average_radius,
options->update_active,
update_type));
gimp_color_picker_tool_info_update (tool,
gimp_color_tool_pick (GIMP_COLOR_TOOL (tool),
options,
gdisp,
coords->x,
coords->y));
gimp_draw_tool_stop (GIMP_DRAW_TOOL (cp_tool));
gimp_tool_control_halt (tool->control);
GIMP_TOOL_CLASS (parent_class)->button_release (tool,
coords, time, state, gdisp);
}
static void
@ -348,110 +294,43 @@ gimp_color_picker_tool_motion (GimpTool *tool,
GdkModifierType state,
GimpDisplay *gdisp)
{
GimpColorPickerTool *cp_tool;
GimpColorPickerOptions *options;
gint off_x, off_y;
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_PICKER_OPTIONS (tool->tool_info->tool_options);
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;
gimp_color_picker_tool_info_update
(tool,
gimp_color_picker_tool_pick_color (gdisp->gimage,
tool->drawable,
coords->x,
coords->y,
options->sample_merged,
options->sample_average,
options->average_radius,
options->update_active,
update_type));
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
}
static void
gimp_color_picker_tool_cursor_update (GimpTool *tool,
GimpCoords *coords,
GdkModifierType state,
GimpDisplay *gdisp)
{
/* We used to use the following code here:
*
* if (gimp_image_pick_correlate_layer (gdisp->gimage, x, y)) { ... }
*/
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);
}
static void
gimp_color_picker_tool_draw (GimpDrawTool *draw_tool)
{
GimpColorPickerTool *cp_tool;
GimpColorPickerOptions *options;
GimpTool *tool;
cp_tool = GIMP_COLOR_PICKER_TOOL (draw_tool);
tool = GIMP_TOOL (draw_tool);
options = GIMP_COLOR_PICKER_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);
}
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_color (GimpImage *gimage,
GimpDrawable *drawable,
gint x,
gint y,
gboolean sample_merged,
gboolean sample_average,
gdouble average_radius,
gboolean update_active,
GimpUpdateColorState update_state)
gimp_color_picker_tool_pick (GimpColorTool *tool,
GimpColorOptions *options,
GimpDisplay *gdisp,
gint x,
gint y)
{
GimpRGB color;
gint color_index;
gboolean success;
GimpRGB color;
gint color_index;
gboolean success;
success = gimp_image_pick_color (gimage,
drawable,
sample_merged,
success = gimp_image_pick_color (gdisp->gimage,
GIMP_TOOL (tool)->drawable,
options->sample_merged,
x, y,
sample_average,
average_radius,
options->sample_average,
options->average_radius,
&color,
&sample_type,
&color_index);
if (success)
{
guchar r, g, b, a;
@ -464,14 +343,15 @@ gimp_color_picker_tool_pick_color (GimpImage *gimage,
col_value[ALPHA_PIX] = a;
col_value[4] = color_index;
if (update_active)
if (GIMP_COLOR_PICKER_OPTIONS (options)->update_active)
{
GimpContext *user_context;
user_context = gimp_get_user_context (gimage->gimp);
user_context = gimp_get_user_context (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)

View File

@ -20,7 +20,7 @@
#define __GIMP_COLOR_PICKER_TOOL_H__
#include "gimpdrawtool.h"
#include "gimpcolortool.h"
#define GIMP_TYPE_COLOR_PICKER_TOOL (gimp_color_picker_tool_get_type ())
@ -36,15 +36,15 @@ typedef struct _GimpColorPickerToolClass GimpColorPickerToolClass;
struct _GimpColorPickerTool
{
GimpDrawTool parent_instance;
GimpColorTool parent_instance;
gint centerx; /* starting x coord */
gint centery; /* starting y coord */
gint centerx; /* starting x coord */
gint centery; /* starting y coord */
};
struct _GimpColorPickerToolClass
{
GimpDrawToolClass parent_class;
GimpColorToolClass parent_class;
};

269
app/tools/gimpcolortool.c Normal file
View File

@ -0,0 +1,269 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995-2001 Spencer Kimball, Peter Mattis, and others
*
* 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
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "tools-types.h"
#include "core/gimpimage.h"
#include "core/gimpitem.h"
#include "core/gimptoolinfo.h"
#include "display/gimpdisplay.h"
#include "gimpcoloroptions.h"
#include "gimpcolortool.h"
#include "gimptoolcontrol.h"
#include "gimp-intl.h"
/* local function prototypes */
static void gimp_color_tool_class_init (GimpColorToolClass *klass);
static void gimp_color_tool_init (GimpColorTool *color_tool);
static void gimp_color_tool_button_press (GimpTool *tool,
GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpDisplay *gdisp);
static void gimp_color_tool_button_release (GimpTool *tool,
GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpDisplay *gdisp);
static void gimp_color_tool_motion (GimpTool *tool,
GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpDisplay *gdisp);
static void gimp_color_tool_cursor_update (GimpTool *tool,
GimpCoords *coords,
GdkModifierType state,
GimpDisplay *gdisp);
static void gimp_color_tool_draw (GimpDrawTool *draw_tool);
static GimpDrawToolClass *parent_class = NULL;
GtkType
gimp_color_tool_get_type (void)
{
static GtkType tool_type = 0;
if (! tool_type)
{
static const GTypeInfo tool_info =
{
sizeof (GimpColorToolClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_color_tool_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpColorTool),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_color_tool_init,
};
tool_type = g_type_register_static (GIMP_TYPE_DRAW_TOOL,
"GimpColorTool",
&tool_info, 0);
}
return tool_type;
}
static void
gimp_color_tool_class_init (GimpColorToolClass *klass)
{
GimpToolClass *tool_class;
GimpDrawToolClass *draw_class;
tool_class = GIMP_TOOL_CLASS (klass);
draw_class = GIMP_DRAW_TOOL_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
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;
tool_class->cursor_update = gimp_color_tool_cursor_update;
draw_class->draw = gimp_color_tool_draw;
klass->pick = NULL;
}
static void
gimp_color_tool_init (GimpColorTool *color_tool)
{
GimpTool *tool = GIMP_TOOL (color_tool);
gimp_tool_control_set_tool_cursor (tool->control,
GIMP_COLOR_PICKER_TOOL_CURSOR);
}
static void
gimp_color_tool_button_press (GimpTool *tool,
GimpCoords *coords,
guint32 time,
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);
/* 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)
{
/* 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;
gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), gdisp);
}
}
static void
gimp_color_tool_button_release (GimpTool *tool,
GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpDisplay *gdisp)
{
if (GIMP_COLOR_TOOL_GET_CLASS (tool)->pick)
gimp_draw_tool_stop (GIMP_DRAW_TOOL (tool));
gimp_tool_control_halt (tool->control);
}
static void
gimp_color_tool_motion (GimpTool *tool,
GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpDisplay *gdisp)
{
GimpColorTool *cp_tool;
GimpColorOptions *options;
gint off_x, off_y;
if (! GIMP_COLOR_TOOL_GET_CLASS (tool)->pick)
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;
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
}
static void
gimp_color_tool_cursor_update (GimpTool *tool,
GimpCoords *coords,
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)
{
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);
}
static void
gimp_color_tool_draw (GimpDrawTool *draw_tool)
{
GimpColorTool *cp_tool;
GimpColorOptions *options;
GimpTool *tool;
if (! GIMP_COLOR_TOOL_GET_CLASS (draw_tool)->pick)
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);
}
gboolean
gimp_color_tool_pick (GimpColorTool *tool,
GimpColorOptions *options,
GimpDisplay *gdisp,
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);
klass = GIMP_COLOR_TOOL_GET_CLASS (tool);
if (! klass->pick)
return FALSE;
return klass->pick (tool, options, gdisp, x, y);
}

67
app/tools/gimpcolortool.h Normal file
View File

@ -0,0 +1,67 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 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
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_COLOR_TOOL_H__
#define __GIMP_COLOR_TOOL_H__
#include "gimpdrawtool.h"
#define GIMP_TYPE_COLOR_TOOL (gimp_color_tool_get_type ())
#define GIMP_COLOR_TOOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_COLOR_TOOL, GimpColorTool))
#define GIMP_COLOR_TOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_COLOR_TOOL, GimpColorToolClass))
#define GIMP_IS_COLOR_TOOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_COLOR_TOOL))
#define GIMP_IS_COLOR_TOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_COLOR_TOOL))
#define GIMP_COLOR_TOOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_COLOR_TOOL, GimpColorToolClass))
typedef struct _GimpColorToolClass GimpColorToolClass;
struct _GimpColorTool
{
GimpDrawTool parent_instance;
gint centerx; /* starting x coord */
gint centery; /* starting y coord */
};
struct _GimpColorToolClass
{
GimpDrawToolClass parent_class;
/* virtual functions */
gboolean (* pick) (GimpColorTool *tool,
GimpColorOptions *options,
GimpDisplay *gdisp,
gint x,
gint y);
};
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);
#endif /* __GIMP_COLOR_TOOL_H__ */

View File

@ -31,7 +31,6 @@
#define GIMP_IMAGE_MAP_TOOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_IMAGE_MAP_TOOL, GimpImageMapToolClass))
typedef struct _GimpImageMapTool GimpImageMapTool;
typedef struct _GimpImageMapToolClass GimpImageMapToolClass;
struct _GimpImageMapTool

View File

@ -616,13 +616,13 @@ gimp_paint_tool_draw (GimpDrawTool *draw_tool)
if (paint_tool->pick_state)
{
GimpToolInfo *info;
GimpColorPickerOptions *options;
GimpToolInfo *info;
GimpColorOptions *options;
info = tool_manager_get_info_by_type (GIMP_TOOL (draw_tool)->tool_info->gimp,
GIMP_TYPE_COLOR_PICKER_TOOL);
options = GIMP_COLOR_PICKER_OPTIONS (info->tool_options);
options = GIMP_COLOR_OPTIONS (info->tool_options);
if (options->sample_average)
{
@ -675,24 +675,24 @@ gimp_paint_tool_sample_color (GimpDrawable *drawable,
gint y,
gint state)
{
GimpToolInfo *picker_info;
GimpColorPickerOptions *picker_options;
GimpImage *gimage;
GimpRGB color;
GimpToolInfo *picker_info;
GimpColorOptions *options;
GimpImage *gimage;
GimpRGB color;
gimage = gimp_item_get_image (GIMP_ITEM (drawable));
picker_info = tool_manager_get_info_by_type (gimage->gimp,
GIMP_TYPE_COLOR_PICKER_TOOL);
picker_options = GIMP_COLOR_PICKER_OPTIONS (picker_info->tool_options);
options = GIMP_COLOR_OPTIONS (picker_info->tool_options);
if (gimp_image_pick_color (gimage,
drawable,
picker_options->sample_merged,
options->sample_merged,
x, y,
picker_options->sample_average,
picker_options->average_radius,
options->sample_average,
options->average_radius,
&color,
NULL,
NULL))

View File

@ -32,13 +32,14 @@ typedef struct _GimpTool GimpTool;
typedef struct _GimpToolModule GimpToolModule;
typedef struct _GimpToolControl GimpToolControl;
typedef struct _GimpPaintTool GimpPaintTool;
typedef struct _GimpColorTool GimpColorTool;
typedef struct _GimpDrawTool GimpDrawTool;
typedef struct _GimpImageMapTool GimpImageMapTool;
typedef struct _GimpPaintTool GimpPaintTool;
typedef struct _GimpPathTool GimpPathTool;
typedef struct _GimpTransformTool GimpTransformTool;
typedef struct _GimpBezierSelectPoint GimpBezierSelectPoint;
typedef struct _GimpBezierSelectTool GimpBezierSelectTool;
typedef struct _GimpColorOptions GimpColorOptions;
/* functions */