[gimp] app: implement GimpTool::options_notify()
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: implement GimpTool::options_notify()
- Date: Wed, 10 Nov 2010 13:40:01 +0000 (UTC)
commit 32926c9b6ab1f916623ef84bc225ce5d4b2be34a
Author: Michael Natterer <mitch gimp org>
Date: Wed Nov 10 14:20:33 2010 +0100
app: implement GimpTool::options_notify()
instead of connecting to the tool options manually.
app/tools/gimpbrushtool.c | 55 ++++-----
app/tools/gimptransformtool.c | 271 +++++++++++++++++++----------------------
2 files changed, 154 insertions(+), 172 deletions(-)
---
diff --git a/app/tools/gimpbrushtool.c b/app/tools/gimpbrushtool.c
index d2774bd..c380e4c 100644
--- a/app/tools/gimpbrushtool.c
+++ b/app/tools/gimpbrushtool.c
@@ -17,6 +17,8 @@
#include "config.h"
+#include <string.h>
+
#include <gegl.h>
#include <gtk/gtk.h>
@@ -59,15 +61,15 @@ static void gimp_brush_tool_cursor_update (GimpTool *tool,
const GimpCoords *coords,
GdkModifierType state,
GimpDisplay *display);
+static void gimp_brush_tool_options_notify (GimpTool *tool,
+ GimpToolOptions *options,
+ const GParamSpec *pspec);
static void gimp_brush_tool_draw (GimpDrawTool *draw_tool);
static void gimp_brush_tool_brush_changed (GimpContext *context,
GimpBrush *brush,
GimpBrushTool *brush_tool);
-static void gimp_brush_tool_brush_transformed (GimpPaintOptions *options,
- GParamSpec *pspec,
- GimpBrushTool *brush_tool);
static void gimp_brush_tool_set_brush (GimpBrushCore *brush_core,
GimpBrush *brush,
GimpBrushTool *brush_tool);
@@ -93,9 +95,10 @@ gimp_brush_tool_class_init (GimpBrushToolClass *klass)
object_class->constructor = gimp_brush_tool_constructor;
- tool_class->motion = gimp_brush_tool_motion;
- tool_class->oper_update = gimp_brush_tool_oper_update;
- tool_class->cursor_update = gimp_brush_tool_cursor_update;
+ tool_class->motion = gimp_brush_tool_motion;
+ tool_class->oper_update = gimp_brush_tool_oper_update;
+ tool_class->cursor_update = gimp_brush_tool_cursor_update;
+ tool_class->options_notify = gimp_brush_tool_options_notify;
draw_tool_class->draw = gimp_brush_tool_draw;
}
@@ -154,17 +157,6 @@ gimp_brush_tool_constructor (GType type,
g_signal_connect_object (gimp_tool_get_options (tool), "brush-changed",
G_CALLBACK (gimp_brush_tool_brush_changed),
brush_tool, 0);
- g_signal_connect_object (gimp_tool_get_options (tool), "notify::brush-size",
- G_CALLBACK (gimp_brush_tool_brush_transformed),
- brush_tool, 0);
-
- g_signal_connect_object (gimp_tool_get_options (tool), "notify::brush-angle",
- G_CALLBACK (gimp_brush_tool_brush_transformed),
- brush_tool, 0);
-
- g_signal_connect_object (gimp_tool_get_options (tool), "notify::brush-aspect-ratio",
- G_CALLBACK (gimp_brush_tool_brush_transformed),
- brush_tool, 0);
g_signal_connect (paint_tool->core, "set-brush",
G_CALLBACK (gimp_brush_tool_set_brush),
@@ -273,6 +265,24 @@ gimp_brush_tool_cursor_update (GimpTool *tool,
}
static void
+gimp_brush_tool_options_notify (GimpTool *tool,
+ GimpToolOptions *options,
+ const GParamSpec *pspec)
+{
+ GIMP_TOOL_CLASS (parent_class)->options_notify (tool, options, pspec);
+
+ if (! strcmp (pspec->name, "brush-size") ||
+ ! strcmp (pspec->name, "brush-angle") ||
+ ! strcmp (pspec->name, "brush-aspect-ratio"))
+ {
+ GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool);
+ GimpBrushCore *brush_core = GIMP_BRUSH_CORE (paint_tool->core);
+
+ gimp_brush_core_set_brush (brush_core, brush_core->main_brush);
+ }
+}
+
+static void
gimp_brush_tool_draw (GimpDrawTool *draw_tool)
{
GimpBrushTool *brush_tool = GIMP_BRUSH_TOOL (draw_tool);
@@ -364,17 +374,6 @@ gimp_brush_tool_brush_changed (GimpContext *context,
}
static void
-gimp_brush_tool_brush_transformed (GimpPaintOptions *options,
- GParamSpec *pspec,
- GimpBrushTool *brush_tool)
-{
- GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (brush_tool);
- GimpBrushCore *brush_core = GIMP_BRUSH_CORE (paint_tool->core);
-
- gimp_brush_core_set_brush (brush_core, brush_core->main_brush);
-}
-
-static void
gimp_brush_tool_set_brush (GimpBrushCore *brush_core,
GimpBrush *brush,
GimpBrushTool *brush_tool)
diff --git a/app/tools/gimptransformtool.c b/app/tools/gimptransformtool.c
index b42fb8f..54797c8 100644
--- a/app/tools/gimptransformtool.c
+++ b/app/tools/gimptransformtool.c
@@ -115,6 +115,9 @@ static void gimp_transform_tool_cursor_update (GimpTool
const GimpCoords *coords,
GdkModifierType state,
GimpDisplay *display);
+static void gimp_transform_tool_options_notify (GimpTool *tool,
+ GimpToolOptions *options,
+ const GParamSpec *pspec);
static void gimp_transform_tool_draw (GimpDrawTool *draw_tool);
@@ -145,13 +148,6 @@ static void gimp_transform_tool_response (GtkWidget
gint response_id,
GimpTransformTool *tr_tool);
-static void gimp_transform_tool_notify_type (GimpTransformOptions *options,
- GParamSpec *pspec,
- GimpTransformTool *tr_tool);
-static void gimp_transform_tool_notify_preview (GimpTransformOptions *options,
- GParamSpec *pspec,
- GimpTransformTool *tr_tool);
-
G_DEFINE_TYPE (GimpTransformTool, gimp_transform_tool, GIMP_TYPE_DRAW_TOOL)
@@ -178,6 +174,7 @@ gimp_transform_tool_class_init (GimpTransformToolClass *klass)
tool_class->active_modifier_key = gimp_transform_tool_modifier_key;
tool_class->oper_update = gimp_transform_tool_oper_update;
tool_class->cursor_update = gimp_transform_tool_cursor_update;
+ tool_class->options_notify = gimp_transform_tool_options_notify;
draw_class->draw = gimp_transform_tool_draw;
@@ -260,40 +257,8 @@ gimp_transform_tool_constructor (GType type,
{
tr_tool->type = options->type;
tr_tool->direction = options->direction;
-
- g_signal_connect_object (options, "notify::type",
- G_CALLBACK (gimp_transform_tool_notify_type),
- tr_tool, 0);
- g_signal_connect_object (options, "notify::type",
- G_CALLBACK (gimp_transform_tool_notify_preview),
- tr_tool, 0);
-
- g_signal_connect_object (options, "notify::direction",
- G_CALLBACK (gimp_transform_tool_notify_type),
- tr_tool, 0);
- g_signal_connect_object (options, "notify::direction",
- G_CALLBACK (gimp_transform_tool_notify_preview),
- tr_tool, 0);
-
- g_signal_connect_object (options, "notify::preview-type",
- G_CALLBACK (gimp_transform_tool_notify_preview),
- tr_tool, 0);
- g_signal_connect_object (options, "notify::grid-type",
- G_CALLBACK (gimp_transform_tool_notify_preview),
- tr_tool, 0);
- g_signal_connect_object (options, "notify::grid-size",
- G_CALLBACK (gimp_transform_tool_notify_preview),
- tr_tool, 0);
- g_signal_connect_object (tool->tool_info->tool_options,
- "notify::preview-opacity",
- G_CALLBACK (gimp_transform_tool_notify_preview),
- tr_tool, 0);
}
- g_signal_connect_object (options, "notify::constrain",
- G_CALLBACK (gimp_transform_tool_dialog_update),
- tr_tool, G_CONNECT_SWAPPED);
-
return object;
}
@@ -775,6 +740,129 @@ gimp_transform_tool_cursor_update (GimpTool *tool,
}
static void
+gimp_transform_tool_options_notify (GimpTool *tool,
+ GimpToolOptions *options,
+ const GParamSpec *pspec)
+{
+ GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (tool);
+
+ GIMP_TOOL_CLASS (parent_class)->options_notify (tool, options, pspec);
+
+ if (tr_tool->use_grid)
+ {
+ GimpTransformOptions *tr_options = GIMP_TRANSFORM_OPTIONS (options);
+
+ if (! strcmp (pspec->name, "type") ||
+ ! strcmp (pspec->name, "direction"))
+ {
+ if (tr_tool->function != TRANSFORM_CREATING)
+ gimp_draw_tool_pause (GIMP_DRAW_TOOL (tr_tool));
+
+ tr_tool->type = tr_options->type;
+ tr_tool->direction = tr_options->direction;
+
+ if (tr_tool->function != TRANSFORM_CREATING)
+ {
+ if (tool->display)
+ {
+ /* reget the selection bounds */
+ gimp_transform_tool_bounds (tr_tool, tool->display);
+
+ /* recalculate the tool's transformation matrix */
+ gimp_transform_tool_recalc (tr_tool, tool->display);
+ }
+
+ gimp_draw_tool_resume (GIMP_DRAW_TOOL (tr_tool));
+ }
+ }
+
+ if (! strcmp (pspec->name, "type") ||
+ ! strcmp (pspec->name, "direction") ||
+ ! strcmp (pspec->name, "preview-type") ||
+ ! strcmp (pspec->name, "grid-type") ||
+ ! strcmp (pspec->name, "grid-size") ||
+ ! strcmp (pspec->name, "preview-opacity"))
+ {
+ GimpDisplayShell *shell = NULL;
+
+ if (gimp_draw_tool_is_active (GIMP_DRAW_TOOL (tr_tool)))
+ shell = gimp_display_get_shell (GIMP_DRAW_TOOL (tr_tool)->display);
+
+ switch (tr_options->preview_type)
+ {
+ default:
+ case GIMP_TRANSFORM_PREVIEW_TYPE_OUTLINE:
+ if (shell)
+ {
+ gimp_display_shell_set_show_transform (shell, FALSE);
+ gimp_transform_tool_force_expose_preview (tr_tool);
+ }
+ break;
+
+ case GIMP_TRANSFORM_PREVIEW_TYPE_GRID:
+ if (shell)
+ {
+ gimp_display_shell_set_show_transform (shell, FALSE);
+ gimp_transform_tool_force_expose_preview (tr_tool);
+ }
+
+ if (tr_tool->function != TRANSFORM_CREATING)
+ {
+ gimp_draw_tool_pause (GIMP_DRAW_TOOL (tr_tool));
+
+ gimp_transform_tool_grid_recalc (tr_tool);
+ gimp_transform_tool_transform_bounding_box (tr_tool);
+
+ gimp_draw_tool_resume (GIMP_DRAW_TOOL (tr_tool));
+ }
+ break;
+
+ case GIMP_TRANSFORM_PREVIEW_TYPE_IMAGE:
+ if (shell)
+ {
+ if (tr_options->type == GIMP_TRANSFORM_TYPE_LAYER &&
+ tr_options->direction == GIMP_TRANSFORM_FORWARD)
+ gimp_display_shell_set_show_transform (shell, TRUE);
+ else
+ gimp_display_shell_set_show_transform (shell, FALSE);
+
+ gimp_transform_tool_force_expose_preview (tr_tool);
+ }
+ break;
+
+ case GIMP_TRANSFORM_PREVIEW_TYPE_IMAGE_GRID:
+ if (shell)
+ {
+ if (tr_options->type == GIMP_TRANSFORM_TYPE_LAYER &&
+ tr_options->direction == GIMP_TRANSFORM_FORWARD)
+ gimp_display_shell_set_show_transform (shell, TRUE);
+ else
+ gimp_display_shell_set_show_transform (shell, FALSE);
+
+ gimp_transform_tool_force_expose_preview (tr_tool);
+ }
+
+ if (tr_tool->function != TRANSFORM_CREATING)
+ {
+ gimp_draw_tool_pause (GIMP_DRAW_TOOL (tr_tool));
+
+ gimp_transform_tool_grid_recalc (tr_tool);
+ gimp_transform_tool_transform_bounding_box (tr_tool);
+
+ gimp_draw_tool_resume (GIMP_DRAW_TOOL (tr_tool));
+ }
+ break;
+ }
+ }
+ }
+
+ if (! strcmp (pspec->name, "constrain"))
+ {
+ gimp_transform_tool_dialog_update (tr_tool);
+ }
+}
+
+static void
gimp_transform_tool_draw (GimpDrawTool *draw_tool)
{
GimpTool *tool = GIMP_TOOL (draw_tool);
@@ -1795,108 +1883,3 @@ gimp_transform_tool_response (GtkWidget *widget,
break;
}
}
-
-static void
-gimp_transform_tool_notify_type (GimpTransformOptions *options,
- GParamSpec *pspec,
- GimpTransformTool *tr_tool)
-{
- GimpDisplay *display = GIMP_TOOL (tr_tool)->display;
-
- if (tr_tool->function != TRANSFORM_CREATING)
- gimp_draw_tool_pause (GIMP_DRAW_TOOL (tr_tool));
-
- tr_tool->type = options->type;
- tr_tool->direction = options->direction;
-
- if (tr_tool->function != TRANSFORM_CREATING)
- {
- if (display)
- {
- /* reget the selection bounds */
- gimp_transform_tool_bounds (tr_tool, display);
-
- /* recalculate the tool's transformation matrix */
- gimp_transform_tool_recalc (tr_tool, display);
- }
-
- gimp_draw_tool_resume (GIMP_DRAW_TOOL (tr_tool));
- }
-}
-
-static void
-gimp_transform_tool_notify_preview (GimpTransformOptions *options,
- GParamSpec *pspec,
- GimpTransformTool *tr_tool)
-{
- GimpDisplayShell *shell = NULL;
-
- if (gimp_draw_tool_is_active (GIMP_DRAW_TOOL (tr_tool)))
- shell = gimp_display_get_shell (GIMP_DRAW_TOOL (tr_tool)->display);
-
- switch (options->preview_type)
- {
- default:
- case GIMP_TRANSFORM_PREVIEW_TYPE_OUTLINE:
- if (shell)
- {
- gimp_display_shell_set_show_transform (shell, FALSE);
- gimp_transform_tool_force_expose_preview (tr_tool);
- }
- break;
-
- case GIMP_TRANSFORM_PREVIEW_TYPE_GRID:
- if (shell)
- {
- gimp_display_shell_set_show_transform (shell, FALSE);
- gimp_transform_tool_force_expose_preview (tr_tool);
- }
-
- if (tr_tool->function != TRANSFORM_CREATING)
- {
- gimp_draw_tool_pause (GIMP_DRAW_TOOL (tr_tool));
-
- gimp_transform_tool_grid_recalc (tr_tool);
- gimp_transform_tool_transform_bounding_box (tr_tool);
-
- gimp_draw_tool_resume (GIMP_DRAW_TOOL (tr_tool));
- }
- break;
-
- case GIMP_TRANSFORM_PREVIEW_TYPE_IMAGE:
- if (shell)
- {
- if (options->type == GIMP_TRANSFORM_TYPE_LAYER &&
- options->direction == GIMP_TRANSFORM_FORWARD)
- gimp_display_shell_set_show_transform (shell, TRUE);
- else
- gimp_display_shell_set_show_transform (shell, FALSE);
-
- gimp_transform_tool_force_expose_preview (tr_tool);
- }
- break;
-
- case GIMP_TRANSFORM_PREVIEW_TYPE_IMAGE_GRID:
- if (shell)
- {
- if (options->type == GIMP_TRANSFORM_TYPE_LAYER &&
- options->direction == GIMP_TRANSFORM_FORWARD)
- gimp_display_shell_set_show_transform (shell, TRUE);
- else
- gimp_display_shell_set_show_transform (shell, FALSE);
-
- gimp_transform_tool_force_expose_preview (tr_tool);
- }
-
- if (tr_tool->function != TRANSFORM_CREATING)
- {
- gimp_draw_tool_pause (GIMP_DRAW_TOOL (tr_tool));
-
- gimp_transform_tool_grid_recalc (tr_tool);
- gimp_transform_tool_transform_bounding_box (tr_tool);
-
- gimp_draw_tool_resume (GIMP_DRAW_TOOL (tr_tool));
- }
- break;
- }
-}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]