[gimp] app: change GimpColorTool to not touch tool->display and tool->drawable
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: change GimpColorTool to not touch tool->display and tool->drawable
- Date: Fri, 30 Jun 2017 19:26:40 +0000 (UTC)
commit bcb6b77bde8eb640b1551c2dfcea6e6cf00346e3
Author: Michael Natterer <mitch gimp org>
Date: Fri Jun 30 21:23:29 2017 +0200
app: change GimpColorTool to not touch tool->display and tool->drawable
Instead, pass a GimpDisplay around in all virtual functions and use
that instead. Some preparation for more fancy subclasses using
GimpToolWidgets.
app/core/gimpmarshal.list | 2 +-
app/tools/gimpcolorpickertool.c | 59 +++++++------
app/tools/gimpcolortool.c | 179 +++++++++++++++++++++------------------
app/tools/gimpcolortool.h | 8 +-
app/tools/gimpfiltertool.c | 42 +++++-----
5 files changed, 154 insertions(+), 136 deletions(-)
---
diff --git a/app/core/gimpmarshal.list b/app/core/gimpmarshal.list
index d7c5fc8..d9e0641 100644
--- a/app/core/gimpmarshal.list
+++ b/app/core/gimpmarshal.list
@@ -38,7 +38,6 @@ VOID: DOUBLE
VOID: DOUBLE, DOUBLE
VOID: DOUBLE, DOUBLE, DOUBLE, DOUBLE
VOID: ENUM
-VOID: ENUM, DOUBLE, DOUBLE, POINTER, POINTER, BOXED
VOID: ENUM, INT
VOID: ENUM, INT, BOOLEAN
VOID: ENUM, OBJECT
@@ -58,6 +57,7 @@ VOID: POINTER
VOID: POINTER, BOXED
VOID: POINTER, ENUM
VOID: POINTER, FLAGS, BOOLEAN
+VOID: POINTER, OBJECT, ENUM, POINTER, POINTER, BOXED
VOID: POINTER, UINT, FLAGS
VOID: STRING
VOID: STRING, BOOLEAN, UINT, FLAGS
diff --git a/app/tools/gimpcolorpickertool.c b/app/tools/gimpcolorpickertool.c
index 56cb718..d7790ff 100644
--- a/app/tools/gimpcolorpickertool.c
+++ b/app/tools/gimpcolorpickertool.c
@@ -30,6 +30,7 @@
#include "core/gimp.h"
#include "core/gimpdrawable.h"
+#include "core/gimpimage.h"
#include "core/gimptoolinfo.h"
#include "widgets/gimpcolorframe.h"
@@ -66,18 +67,20 @@ static void gimp_color_picker_tool_oper_update (GimpTool *tool,
GimpDisplay *display);
static void gimp_color_picker_tool_picked (GimpColorTool *color_tool,
+ const GimpCoords *coords,
+ GimpDisplay *display,
GimpColorPickState pick_state,
- gdouble x,
- gdouble y,
const Babl *sample_format,
gpointer pixel,
const GimpRGB *color);
-static void gimp_color_picker_tool_info_create (GimpColorPickerTool *picker_tool);
+static void gimp_color_picker_tool_info_create (GimpColorPickerTool *picker_tool,
+ GimpDisplay *display);
static void gimp_color_picker_tool_info_response (GimpToolGui *gui,
gint response_id,
GimpColorPickerTool *picker_tool);
static void gimp_color_picker_tool_info_update (GimpColorPickerTool *picker_tool,
+ GimpDisplay *display,
gboolean sample_average,
const Babl *sample_format,
gpointer pixel,
@@ -295,9 +298,9 @@ gimp_color_picker_tool_oper_update (GimpTool *tool,
static void
gimp_color_picker_tool_picked (GimpColorTool *color_tool,
+ const GimpCoords *coords,
+ GimpDisplay *display,
GimpColorPickState pick_state,
- gdouble x,
- gdouble y,
const Babl *sample_format,
gpointer pixel,
const GimpRGB *color)
@@ -308,40 +311,37 @@ gimp_color_picker_tool_picked (GimpColorTool *color_tool,
options = GIMP_COLOR_PICKER_TOOL_GET_OPTIONS (color_tool);
if (options->use_info_window && ! picker_tool->gui)
- gimp_color_picker_tool_info_create (picker_tool);
+ gimp_color_picker_tool_info_create (picker_tool, display);
if (picker_tool->gui &&
(options->use_info_window ||
gimp_tool_gui_get_visible (picker_tool->gui)))
{
- gimp_color_picker_tool_info_update (picker_tool,
+ gimp_color_picker_tool_info_update (picker_tool, display,
GIMP_COLOR_OPTIONS (options)->sample_average,
sample_format, pixel, color,
- (gint) floor (x),
- (gint) floor (y));
+ (gint) floor (coords->x),
+ (gint) floor (coords->y));
}
- GIMP_COLOR_TOOL_CLASS (parent_class)->picked (color_tool, pick_state,
- x, y,
- sample_format,
- pixel, color);
+ GIMP_COLOR_TOOL_CLASS (parent_class)->picked (color_tool,
+ coords, display, pick_state,
+ sample_format, pixel, color);
}
static void
-gimp_color_picker_tool_info_create (GimpColorPickerTool *picker_tool)
+gimp_color_picker_tool_info_create (GimpColorPickerTool *picker_tool,
+ GimpDisplay *display)
{
- GimpTool *tool = GIMP_TOOL (picker_tool);
- GimpContext *context = GIMP_CONTEXT (tool->tool_info->tool_options);
- GimpDisplayShell *shell;
+ GimpTool *tool = GIMP_TOOL (picker_tool);
+ GimpContext *context = GIMP_CONTEXT (tool->tool_info->tool_options);
+ GimpDisplayShell *shell = gimp_display_get_shell (display);
+ GimpImage *image = gimp_display_get_image (display);
+ GimpDrawable *drawable = gimp_image_get_active_drawable (image);
GtkWidget *hbox;
GtkWidget *frame;
GimpRGB color;
- g_return_if_fail (tool->display != NULL);
- g_return_if_fail (tool->drawable != NULL);
-
- shell = gimp_display_get_shell (tool->display);
-
picker_tool->gui = gimp_tool_gui_new (tool->tool_info,
NULL,
_("Color Picker Information"),
@@ -356,8 +356,7 @@ gimp_color_picker_tool_info_create (GimpColorPickerTool *picker_tool)
gimp_tool_gui_set_auto_overlay (picker_tool->gui, TRUE);
gimp_tool_gui_set_focus_on_map (picker_tool->gui, FALSE);
- gimp_tool_gui_set_viewable (picker_tool->gui,
- GIMP_VIEWABLE (tool->drawable));
+ gimp_tool_gui_set_viewable (picker_tool->gui, GIMP_VIEWABLE (drawable));
g_signal_connect (picker_tool->gui, "response",
G_CALLBACK (gimp_color_picker_tool_info_response),
@@ -397,7 +396,7 @@ gimp_color_picker_tool_info_create (GimpColorPickerTool *picker_tool)
gimp_rgba_set (&color, 0.0, 0.0, 0.0, 0.0);
picker_tool->color_area =
gimp_color_area_new (&color,
- gimp_drawable_has_alpha (tool->drawable) ?
+ gimp_drawable_has_alpha (drawable) ?
GIMP_COLOR_AREA_LARGE_CHECKS :
GIMP_COLOR_AREA_FLAT,
GDK_BUTTON1_MASK | GDK_BUTTON2_MASK);
@@ -416,11 +415,12 @@ gimp_color_picker_tool_info_response (GimpToolGui *gui,
{
GimpTool *tool = GIMP_TOOL (picker_tool);
- gimp_tool_control (tool, GIMP_TOOL_ACTION_HALT, tool->display);
+ gimp_tool_control (tool, GIMP_TOOL_ACTION_HALT, NULL);
}
static void
gimp_color_picker_tool_info_update (GimpColorPickerTool *picker_tool,
+ GimpDisplay *display,
gboolean sample_average,
const Babl *sample_format,
gpointer pixel,
@@ -428,12 +428,13 @@ gimp_color_picker_tool_info_update (GimpColorPickerTool *picker_tool,
gint x,
gint y)
{
- GimpTool *tool = GIMP_TOOL (picker_tool);
+ GimpImage *image = gimp_display_get_image (display);
+ GimpDrawable *drawable = gimp_image_get_active_drawable (image);
gimp_tool_gui_set_shell (picker_tool->gui,
- gimp_display_get_shell (tool->display));
+ gimp_display_get_shell (display));
gimp_tool_gui_set_viewable (picker_tool->gui,
- GIMP_VIEWABLE (tool->drawable));
+ GIMP_VIEWABLE (drawable));
gimp_color_area_set_color (GIMP_COLOR_AREA (picker_tool->color_area),
color);
diff --git a/app/tools/gimpcolortool.c b/app/tools/gimpcolortool.c
index 96a01d1..8a10312 100644
--- a/app/tools/gimpcolortool.c
+++ b/app/tools/gimpcolortool.c
@@ -97,19 +97,19 @@ static void gimp_color_tool_cursor_update (GimpTool *tool,
static void gimp_color_tool_draw (GimpDrawTool *draw_tool);
static gboolean
- gimp_color_tool_real_can_pick (GimpColorTool *color_tool,
+ gimp_color_tool_real_can_pick (GimpColorTool *color_tool,
const GimpCoords *coords,
GimpDisplay *display);
static gboolean gimp_color_tool_real_pick (GimpColorTool *color_tool,
- gint x,
- gint y,
+ const GimpCoords *coords,
+ GimpDisplay *display,
const Babl **sample_format,
gpointer pixel,
GimpRGB *color);
static void gimp_color_tool_real_picked (GimpColorTool *color_tool,
+ const GimpCoords *coords,
+ GimpDisplay *display,
GimpColorPickState pick_state,
- gdouble x,
- gdouble y,
const Babl *sample_format,
gpointer pixel,
const GimpRGB *color);
@@ -118,12 +118,12 @@ static gboolean gimp_color_tool_can_pick (GimpColorTool *tool,
const GimpCoords *coords,
GimpDisplay *display);
static void gimp_color_tool_pick (GimpColorTool *tool,
- GimpColorPickState pick_state,
- gint x,
- gint y);
+ const GimpCoords *coords,
+ GimpDisplay *display,
+ GimpColorPickState pick_state);
-G_DEFINE_TYPE (GimpColorTool, gimp_color_tool, GIMP_TYPE_DRAW_TOOL);
+G_DEFINE_TYPE (GimpColorTool, gimp_color_tool, GIMP_TYPE_DRAW_TOOL)
#define parent_class gimp_color_tool_parent_class
@@ -143,11 +143,11 @@ gimp_color_tool_class_init (GimpColorToolClass *klass)
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpColorToolClass, picked),
NULL, NULL,
- gimp_marshal_VOID__ENUM_DOUBLE_DOUBLE_POINTER_POINTER_BOXED,
+ gimp_marshal_VOID__POINTER_OBJECT_ENUM_POINTER_POINTER_BOXED,
G_TYPE_NONE, 6,
+ G_TYPE_POINTER,
+ GIMP_TYPE_DISPLAY,
GIMP_TYPE_COLOR_PICK_STATE,
- G_TYPE_DOUBLE,
- G_TYPE_DOUBLE,
G_TYPE_POINTER,
G_TYPE_POINTER,
GIMP_TYPE_RGB | G_SIGNAL_TYPE_STATIC_SCOPE);
@@ -202,24 +202,25 @@ gimp_color_tool_button_press (GimpTool *tool,
{
GimpColorTool *color_tool = GIMP_COLOR_TOOL (tool);
- /* Chain up to activate the tool */
- GIMP_TOOL_CLASS (parent_class)->button_press (tool, coords, time, state,
- press_type, display);
-
- if (! color_tool->enabled)
- return;
-
- if (color_tool->sample_point)
+ if (color_tool->enabled)
{
- gimp_tool_control_halt (tool->control);
+ 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);
- gimp_sample_point_tool_start_edit (tool, display,
- color_tool->sample_point);
+ gimp_tool_control_activate (tool->control);
+ }
}
- else if (gimp_color_tool_can_pick (color_tool, coords, display))
+ else
{
- gimp_color_tool_pick (color_tool, GIMP_COLOR_PICK_STATE_START,
- coords->x, coords->y);
+ GIMP_TOOL_CLASS (parent_class)->button_press (tool, coords, time, state,
+ press_type, display);
}
}
@@ -233,18 +234,21 @@ gimp_color_tool_button_release (GimpTool *tool,
{
GimpColorTool *color_tool = GIMP_COLOR_TOOL (tool);
- /* Chain up to halt the tool */
- GIMP_TOOL_CLASS (parent_class)->button_release (tool, coords, time, state,
- release_type, display);
-
- if (! color_tool->enabled)
- return;
+ if (color_tool->enabled)
+ {
+ gimp_tool_control_halt (tool->control);
- if (! color_tool->sample_point &&
- gimp_color_tool_can_pick (color_tool, coords, display))
+ 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
{
- gimp_color_tool_pick (color_tool, GIMP_COLOR_PICK_STATE_END,
- coords->x, coords->y);
+ GIMP_TOOL_CLASS (parent_class)->button_release (tool, coords, time, state,
+ release_type, display);
}
}
@@ -257,25 +261,30 @@ gimp_color_tool_motion (GimpTool *tool,
{
GimpColorTool *color_tool = GIMP_COLOR_TOOL (tool);
- if (! color_tool->enabled)
- return;
-
- if (! color_tool->sample_point)
+ if (color_tool->enabled)
{
- gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
+ if (! color_tool->sample_point)
+ {
+ gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
- 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;
+ 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;
- if (color_tool->can_pick)
- {
- gimp_color_tool_pick (color_tool, GIMP_COLOR_PICK_STATE_UPDATE,
- coords->x, coords->y);
- }
+ if (color_tool->can_pick)
+ {
+ gimp_color_tool_pick (color_tool, coords, display,
+ GIMP_COLOR_PICK_STATE_UPDATE);
+ }
- gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
+ gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
+ }
+ }
+ else
+ {
+ GIMP_TOOL_CLASS (parent_class)->motion (tool, coords, time, state,
+ display);
}
}
@@ -331,6 +340,11 @@ gimp_color_tool_oper_update (GimpTool *tool,
gimp_draw_tool_resume (draw_tool);
}
+ else
+ {
+ GIMP_TOOL_CLASS (parent_class)->oper_update (tool, coords, state,
+ proximity, display);
+ }
}
static void
@@ -378,11 +392,12 @@ gimp_color_tool_cursor_update (GimpTool *tool,
GIMP_TOOL_CURSOR_COLOR_PICKER,
modifier);
}
-
- return; /* don't chain up */
}
-
- GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, display);
+ else
+ {
+ GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state,
+ display);
+ }
}
static void
@@ -420,6 +435,10 @@ gimp_color_tool_draw (GimpDrawTool *draw_tool)
2 * radius + 1);
}
}
+ else
+ {
+ GIMP_DRAW_TOOL_CLASS (parent_class)->draw (draw_tool);
+ }
}
static gboolean
@@ -429,27 +448,26 @@ gimp_color_tool_real_can_pick (GimpColorTool *color_tool,
{
GimpImage *image = gimp_display_get_image (display);
- return
- gimp_image_coords_in_active_pickable (image, coords,
- color_tool->options->sample_merged,
- FALSE);
+ return gimp_image_coords_in_active_pickable (image, coords,
+ color_tool->options->sample_merged,
+ FALSE);
}
static gboolean
-gimp_color_tool_real_pick (GimpColorTool *color_tool,
- gint x,
- gint y,
- const Babl **sample_format,
- gpointer pixel,
- GimpRGB *color)
+gimp_color_tool_real_pick (GimpColorTool *color_tool,
+ const GimpCoords *coords,
+ GimpDisplay *display,
+ const Babl **sample_format,
+ gpointer pixel,
+ GimpRGB *color)
{
- GimpTool *tool = GIMP_TOOL (color_tool);
- GimpImage *image = gimp_display_get_image (tool->display);
+ GimpImage *image = gimp_display_get_image (display);
+ GimpDrawable *drawable = gimp_image_get_active_drawable (image);
- g_return_val_if_fail (tool->display != NULL, FALSE);
- g_return_val_if_fail (tool->drawable != NULL, FALSE);
+ g_return_val_if_fail (drawable != NULL, FALSE);
- return gimp_image_pick_color (image, tool->drawable, x, y,
+ return gimp_image_pick_color (image, drawable,
+ coords->x, coords->y,
color_tool->options->sample_merged,
color_tool->options->sample_average,
color_tool->options->average_radius,
@@ -460,15 +478,15 @@ gimp_color_tool_real_pick (GimpColorTool *color_tool,
static void
gimp_color_tool_real_picked (GimpColorTool *color_tool,
+ const GimpCoords *coords,
+ GimpDisplay *display,
GimpColorPickState pick_state,
- gdouble x,
- gdouble y,
const Babl *sample_format,
gpointer pixel,
const GimpRGB *color)
{
GimpTool *tool = GIMP_TOOL (color_tool);
- GimpDisplayShell *shell = gimp_display_get_shell (tool->display);
+ GimpDisplayShell *shell = gimp_display_get_shell (display);
GimpImageWindow *image_window;
GimpDialogFactory *dialog_factory;
GimpContext *context;
@@ -533,8 +551,8 @@ gimp_color_tool_real_picked (GimpColorTool *color_tool,
GtkWidget *dockable;
dockable =
- gimp_window_strategy_show_dockable_dialog (GIMP_WINDOW_STRATEGY (gimp_get_window_strategy
(tool->display->gimp)),
- tool->display->gimp,
+ gimp_window_strategy_show_dockable_dialog (GIMP_WINDOW_STRATEGY (gimp_get_window_strategy
(display->gimp)),
+ display->gimp,
dialog_factory,
screen,
monitor,
@@ -583,9 +601,9 @@ gimp_color_tool_can_pick (GimpColorTool *tool,
static void
gimp_color_tool_pick (GimpColorTool *tool,
- GimpColorPickState pick_state,
- gint x,
- gint y)
+ const GimpCoords *coords,
+ GimpDisplay *display,
+ GimpColorPickState pick_state)
{
GimpColorToolClass *klass;
const Babl *sample_format;
@@ -595,11 +613,10 @@ gimp_color_tool_pick (GimpColorTool *tool,
klass = GIMP_COLOR_TOOL_GET_CLASS (tool);
if (klass->pick &&
- klass->pick (tool, x, y, &sample_format, pixel, &color))
+ klass->pick (tool, coords, display, &sample_format, pixel, &color))
{
g_signal_emit (tool, gimp_color_tool_signals[PICKED], 0,
- pick_state,
- (gdouble) x, (gdouble) y,
+ coords, display, pick_state,
sample_format, pixel, &color);
}
}
diff --git a/app/tools/gimpcolortool.h b/app/tools/gimpcolortool.h
index 618d4a1..fceec94 100644
--- a/app/tools/gimpcolortool.h
+++ b/app/tools/gimpcolortool.h
@@ -59,17 +59,17 @@ struct _GimpColorToolClass
const GimpCoords *coords,
GimpDisplay *display);
gboolean (* pick) (GimpColorTool *tool,
- gint x,
- gint y,
+ const GimpCoords *coords,
+ GimpDisplay *display,
const Babl **sample_format,
gpointer pixel,
GimpRGB *color);
/* signals */
void (* picked) (GimpColorTool *tool,
+ const GimpCoords *coords,
+ GimpDisplay *display,
GimpColorPickState pick_state,
- gdouble x,
- gdouble y,
const Babl *sample_format,
gpointer pixel,
const GimpRGB *color);
diff --git a/app/tools/gimpfiltertool.c b/app/tools/gimpfiltertool.c
index 6d9a415..3e0c32f 100644
--- a/app/tools/gimpfiltertool.c
+++ b/app/tools/gimpfiltertool.c
@@ -112,15 +112,15 @@ static gboolean gimp_filter_tool_can_pick_color (GimpColorTool *color_too
const GimpCoords *coords,
GimpDisplay *display);
static gboolean gimp_filter_tool_pick_color (GimpColorTool *color_tool,
- gint x,
- gint y,
+ const GimpCoords *coords,
+ GimpDisplay *display,
const Babl **sample_format,
gpointer pixel,
GimpRGB *color);
static void gimp_filter_tool_color_picked (GimpColorTool *color_tool,
+ const GimpCoords *coords,
+ GimpDisplay *display,
GimpColorPickState pick_state,
- gdouble x,
- gdouble y,
const Babl *sample_format,
gpointer pixel,
const GimpRGB *color);
@@ -804,12 +804,12 @@ gimp_filter_tool_can_pick_color (GimpColorTool *color_tool,
}
static gboolean
-gimp_filter_tool_pick_color (GimpColorTool *color_tool,
- gint x,
- gint y,
- const Babl **sample_format,
- gpointer pixel,
- GimpRGB *color)
+gimp_filter_tool_pick_color (GimpColorTool *color_tool,
+ const GimpCoords *coords,
+ GimpDisplay *display,
+ const Babl **sample_format,
+ gpointer pixel,
+ GimpRGB *color)
{
GimpFilterTool *filter_tool = GIMP_FILTER_TOOL (color_tool);
gint off_x, off_y;
@@ -820,8 +820,8 @@ gimp_filter_tool_pick_color (GimpColorTool *color_tool,
*sample_format = gimp_drawable_get_format (filter_tool->drawable);
picked = gimp_pickable_pick_color (GIMP_PICKABLE (filter_tool->drawable),
- x - off_x,
- y - off_y,
+ coords->x - off_x,
+ coords->y - off_y,
color_tool->options->sample_average,
color_tool->options->average_radius,
pixel, color);
@@ -841,20 +841,20 @@ gimp_filter_tool_pick_color (GimpColorTool *color_tool,
static void
gimp_filter_tool_color_picked (GimpColorTool *color_tool,
+ const GimpCoords *coords,
+ GimpDisplay *display,
GimpColorPickState pick_state,
- gdouble x,
- gdouble y,
const Babl *sample_format,
gpointer pixel,
const GimpRGB *color)
{
GimpFilterTool *filter_tool = GIMP_FILTER_TOOL (color_tool);
- GIMP_FILTER_TOOL_GET_CLASS (filter_tool)->color_picked (
- filter_tool,
- filter_tool->pick_identifier,
- x, y,
- sample_format, color);
+ GIMP_FILTER_TOOL_GET_CLASS (filter_tool)->color_picked (filter_tool,
+ filter_tool->pick_identifier,
+ coords->x,
+ coords->y,
+ sample_format, color);
}
static void
@@ -1544,8 +1544,8 @@ gimp_filter_tool_enable_color_picking (GimpFilterTool *filter_tool,
gimp_filter_tool_disable_color_picking (filter_tool);
- /* note that ownership over `identifier` is not transferred, and its lifetime
- * should be managed by the caller.
+ /* note that ownership over 'identifier' is not transferred, and its
+ * lifetime should be managed by the caller.
*/
filter_tool->pick_identifier = identifier;
filter_tool->pick_abyss = pick_abyss;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]