[gimp/soc-2010-cage-2: 50/50] Some generic method sorting and cleanup in the tool
- From: Alexia Death <alexiade src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/soc-2010-cage-2: 50/50] Some generic method sorting and cleanup in the tool
- Date: Thu, 2 Sep 2010 19:28:47 +0000 (UTC)
commit 55b0c9f08e14bc26451cf94b6a3a223059bff6da
Author: Alexia Death <alexiadeath gmail com>
Date: Thu Sep 2 22:28:06 2010 +0300
Some generic method sorting and cleanup in the tool
app/gegl/gimpoperationcagecoefcalc.c | 7 +-
app/tools/gimpcagetool.c | 444 +++++++++++++++++-----------------
2 files changed, 231 insertions(+), 220 deletions(-)
---
diff --git a/app/gegl/gimpoperationcagecoefcalc.c b/app/gegl/gimpoperationcagecoefcalc.c
index e17cd09..d5b5836 100644
--- a/app/gegl/gimpoperationcagecoefcalc.c
+++ b/app/gegl/gimpoperationcagecoefcalc.c
@@ -58,7 +58,6 @@ gimp_operation_cage_coef_calc_class_init (GimpOperationCageCoefCalcClass *klass)
GeglOperationSourceClass *source_class = GEGL_OPERATION_SOURCE_CLASS (klass);
GeglOperationClass *operation_class = GEGL_OPERATION_CLASS (klass);
- /* FIXME: wrong categories and name, to appears in the gegl tool */
operation_class->name = "gimp:cage_coef_calc";
operation_class->categories = "transform";
operation_class->description = "GIMP cage transform coefficient calc";
@@ -94,7 +93,10 @@ gimp_operation_cage_coef_calc_prepare (GeglOperation *operation)
GimpOperationCageCoefCalc *occc = GIMP_OPERATION_CAGE_COEF_CALC (operation);
GimpCageConfig *config = GIMP_CAGE_CONFIG (occc->config);
- gegl_operation_set_format (operation, "output", babl_format_n (babl_type ("float"), 2 * config->cage_vertice_number));
+ gegl_operation_set_format (operation,
+ "output",
+ babl_format_n (babl_type ("float"),
+ 2 * config->cage_vertice_number));
}
static void
@@ -248,7 +250,6 @@ gimp_operation_cage_coef_calc_process (GeglOperation *operation,
if (isnan(coef[j + config->cage_vertice_number]))
{
coef[j + config->cage_vertice_number] = 0.0;
- printf("NAN SRT: %f\n", SRT);
}
/* vertice coef */
diff --git a/app/tools/gimpcagetool.c b/app/tools/gimpcagetool.c
index d203603..f72b9dc 100644
--- a/app/tools/gimpcagetool.c
+++ b/app/tools/gimpcagetool.c
@@ -194,6 +194,26 @@ gimp_cage_tool_finalize (GObject *object)
static void
+gimp_cage_tool_control (GimpTool *tool,
+ GimpToolAction action,
+ GimpDisplay *display)
+{
+ switch (action)
+ {
+ case GIMP_TOOL_ACTION_PAUSE:
+ case GIMP_TOOL_ACTION_RESUME:
+ break;
+
+ case GIMP_TOOL_ACTION_HALT:
+ gimp_cage_tool_halt (GIMP_CAGE_TOOL (tool));
+ break;
+ }
+
+ GIMP_TOOL_CLASS (parent_class)->control (tool, action, display);
+}
+
+
+static void
gimp_cage_tool_start (GimpCageTool *ct,
GimpDisplay *display)
{
@@ -205,15 +225,15 @@ gimp_cage_tool_start (GimpCageTool *ct,
tool->display = display;
if (ct->config)
- {
- g_object_unref (ct->config);
- }
+ {
+ g_object_unref (ct->config);
+ }
if (ct->image_map)
- {
- gimp_image_map_abort (ct->image_map);
- g_object_unref (ct->image_map);
- }
+ {
+ gimp_image_map_abort (ct->image_map);
+ g_object_unref (ct->image_map);
+ }
ct->config = g_object_new (GIMP_TYPE_CAGE_CONFIG, NULL);
ct->cursor_position.x = -1000;
@@ -224,59 +244,108 @@ gimp_cage_tool_start (GimpCageTool *ct,
gimp_draw_tool_start (draw_tool, display);
}
-static void
-gimp_cage_tool_halt (GimpCageTool *ct)
+
+static gboolean
+gimp_cage_tool_key_press (GimpTool *tool,
+ GdkEventKey *kevent,
+ GimpDisplay *display)
{
- GimpTool *tool = GIMP_TOOL (ct);
- GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (ct);
+ GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
- if (gimp_draw_tool_is_active (draw_tool))
- gimp_draw_tool_stop (draw_tool);
+ switch (kevent->keyval)
+ {
+ case GDK_BackSpace:
+ gimp_cage_tool_remove_last_handle (ct);
+ return TRUE;
- if (gimp_tool_control_is_active (tool->control))
- gimp_tool_control_halt (tool->control);
+ case GDK_Return:
+ case GDK_KP_Enter:
+ case GDK_ISO_Enter:
+ if (ct->cage_complete)
+ {
+ gimp_image_map_abort (ct->image_map);
+ g_object_unref (ct->image_map);
+ ct->image_map = NULL;
+ if (ct->idle_id)
+ {
+ g_source_remove(ct->idle_id);
+ ct->idle_id = 0; /*Stop preview update for now*/
+ }
+ gimp_cage_tool_process (ct, display); /*RUN IT BABY*/
+ }
+ return TRUE;
- if (ct->config)
- {
- g_object_unref (ct->config);
- ct->config = NULL;
- }
+ case GDK_Escape:
+ gimp_cage_tool_halt (ct);
+ return TRUE;
- if (ct->coef)
- {
- gegl_buffer_destroy (ct->coef);
- ct->coef = NULL;
- }
+ default:
+ break;
+ }
- if (ct->image_map)
- {
+ return FALSE;
+}
- if (ct->idle_id > 0)
- {
- g_source_remove(ct->idle_id);
- ct->idle_id = 0;
- }
- gimp_tool_control_set_preserve (tool->control, TRUE);
+static void
+gimp_cage_tool_motion (GimpTool *tool,
+ const GimpCoords *coords,
+ guint32 time,
+ GdkModifierType state,
+ GimpDisplay *display)
+{
+ GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
+ GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
+ GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
+ GimpCageConfig *config = ct->config;
- gimp_image_map_abort (ct->image_map);
- g_object_unref (ct->image_map);
- ct->image_map = NULL;
- gimp_tool_control_set_preserve (tool->control, FALSE);
+ gimp_draw_tool_pause (draw_tool);
- gimp_image_flush (gimp_display_get_image (tool->display));
- }
- if (ct->node_preview)
+ if (ct->handle_moved >= 0)
{
- g_object_unref (ct->node_preview);
- ct->node_preview = NULL;
+ gimp_cage_config_move_cage_point (config,
+ options->cage_mode,
+ ct->handle_moved,
+ coords->x,
+ coords->y);
}
- tool->display = NULL;
+ gimp_draw_tool_resume (draw_tool);
}
static void
+gimp_cage_tool_oper_update (GimpTool *tool,
+ const GimpCoords *coords,
+ GdkModifierType state,
+ gboolean proximity,
+ GimpDisplay *display)
+{
+ GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
+ GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
+ GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
+ GimpCageConfig *config = ct->config;
+ gint active_handle = -1;
+
+ if (config)
+ active_handle = gimp_cage_config_is_on_handle (config,
+ options->cage_mode,
+ coords->x,
+ coords->y,
+ HANDLE_SIZE);
+ if (!ct->cage_complete || (active_handle > -1))
+ {
+ gimp_draw_tool_pause (draw_tool);
+
+ ct->cursor_position.x = coords->x;
+ ct->cursor_position.y = coords->y;
+
+ gimp_draw_tool_resume (draw_tool);
+ }
+}
+
+
+static void
gimp_cage_tool_button_press (GimpTool *tool,
const GimpCoords *coords,
guint32 time,
@@ -323,7 +392,8 @@ gimp_cage_tool_button_press (GimpTool *tool,
gimp_draw_tool_resume (GIMP_DRAW_TOOL (ct));
- // user is clicking on the first handle, we close the cage and switch to deform mode
+ /* user is clicking on the first handle, we close the cage and
+ * switch to deform mode*/
if (ct->handle_moved == 0 && config->cage_vertice_number > 2 && !ct->coef)
{
ct->cage_complete = TRUE;
@@ -333,7 +403,6 @@ gimp_cage_tool_button_press (GimpTool *tool,
gimp_cage_tool_compute_coef (ct, display);
gimp_cage_tool_prepare_preview (ct, display);
- printf("Swiched to deform\n");
}
}
@@ -380,8 +449,6 @@ gimp_cage_tool_button_release (GimpTool *tool,
gimp_draw_tool_pause (GIMP_DRAW_TOOL (ct));
- printf("Start to update preview\n");
-
gimp_image_map_apply (ct->image_map, &visible);
ct->idle_id = g_idle_add ((GSourceFunc) gimp_cage_tool_update_preview, tool);
@@ -392,114 +459,6 @@ gimp_cage_tool_button_release (GimpTool *tool,
}
-static gboolean
-gimp_cage_tool_update_preview (GimpTool *tool)
-{
- GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
- GimpImage *image = gimp_display_get_image (tool->display);
-
- if (!gimp_image_map_is_busy(ct->image_map))
- {
- ct->idle_id = 0;
- printf ("Preview render complete, updating\n");
- gimp_projection_flush_now (gimp_image_get_projection (image));
- gimp_display_flush_now (tool->display);
-
- return FALSE;
- }
-
- return TRUE;
-
-
-}
-static gboolean
-gimp_cage_tool_key_press (GimpTool *tool,
- GdkEventKey *kevent,
- GimpDisplay *display)
-{
- GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
-
- switch (kevent->keyval)
- {
- case GDK_BackSpace:
- gimp_cage_tool_remove_last_handle (ct);
- return TRUE;
-
- case GDK_Return:
- case GDK_KP_Enter:
- case GDK_ISO_Enter:
- if (ct->cage_complete)
- {
- gimp_image_map_abort (ct->image_map);
- g_object_unref (ct->image_map);
- ct->image_map = NULL;
- if (ct->idle_id)
- {
- g_source_remove(ct->idle_id);
- ct->idle_id = 0; /*Stop preview update for now*/
- }
- gimp_cage_tool_process (ct, display); /*RUN IT BABY*/
- }
- return TRUE;
-
- case GDK_Escape:
- gimp_cage_tool_halt (ct);
- return TRUE;
-
- default:
- break;
- }
-
- return FALSE;
-}
-
-static void
-gimp_cage_tool_motion (GimpTool *tool,
- const GimpCoords *coords,
- guint32 time,
- GdkModifierType state,
- GimpDisplay *display)
-{
- GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
- GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
- GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
- GimpCageConfig *config = ct->config;
-
-
- gimp_draw_tool_pause (draw_tool);
-
-
- if (ct->handle_moved >= 0)
- {
- gimp_cage_config_move_cage_point (config,
- options->cage_mode,
- ct->handle_moved,
- coords->x,
- coords->y);
- }
-
- gimp_draw_tool_resume (draw_tool);
-}
-
-static void
-gimp_cage_tool_control (GimpTool *tool,
- GimpToolAction action,
- GimpDisplay *display)
-{
- switch (action)
- {
- case GIMP_TOOL_ACTION_PAUSE:
- case GIMP_TOOL_ACTION_RESUME:
- break;
-
- case GIMP_TOOL_ACTION_HALT:
- gimp_cage_tool_halt (GIMP_CAGE_TOOL (tool));
- break;
- }
-
- GIMP_TOOL_CLASS (parent_class)->control (tool, action, display);
-}
-
static void
gimp_cage_tool_cursor_update (GimpTool *tool,
const GimpCoords *coords,
@@ -536,35 +495,6 @@ gimp_cage_tool_cursor_update (GimpTool *tool,
}
}
-static void
-gimp_cage_tool_oper_update (GimpTool *tool,
- const GimpCoords *coords,
- GdkModifierType state,
- gboolean proximity,
- GimpDisplay *display)
-{
- GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
- GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
- GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
- GimpCageConfig *config = ct->config;
- gint active_handle = -1;
-
- if (config)
- active_handle = gimp_cage_config_is_on_handle (config,
- options->cage_mode,
- coords->x,
- coords->y,
- HANDLE_SIZE);
- if (!ct->cage_complete || (active_handle > -1))
- {
- gimp_draw_tool_pause (draw_tool);
-
- ct->cursor_position.x = coords->x;
- ct->cursor_position.y = coords->y;
-
- gimp_draw_tool_resume (draw_tool);
- }
-}
/**
* gimp_cage_tool_draw:
@@ -649,14 +579,6 @@ gimp_cage_tool_draw (GimpDrawTool *draw_tool)
}
static void
-gimp_cage_tool_switch_to_deform (GimpCageTool *ct)
-{
- GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
-
- g_object_set (options, "cage-mode", GIMP_CAGE_MODE_DEFORM, NULL);
-}
-
-static void
gimp_cage_tool_remove_last_handle (GimpCageTool *ct)
{
GimpCageConfig *config = ct->config;
@@ -667,6 +589,14 @@ gimp_cage_tool_remove_last_handle (GimpCageTool *ct)
}
static void
+gimp_cage_tool_switch_to_deform (GimpCageTool *ct)
+{
+ GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
+
+ g_object_set (options, "cage-mode", GIMP_CAGE_MODE_DEFORM, NULL);
+}
+
+static void
gimp_cage_tool_compute_coef (GimpCageTool *ct,
GimpDisplay *display)
{
@@ -722,6 +652,71 @@ gimp_cage_tool_compute_coef (GimpCageTool *ct,
}
static void
+gimp_cage_tool_prepare_preview (GimpCageTool *ct,
+ GimpDisplay *display)
+{
+ GimpImage *image = gimp_display_get_image (display);
+ GimpDrawable *drawable = gimp_image_get_active_drawable (image);
+
+ GeglNode *coef, *cage;
+
+ if (ct->node_preview)
+ {
+ g_object_unref (ct->node_preview);
+ ct->node_preview = NULL;
+ }
+
+ ct->node_preview = gegl_node_new ();
+
+ coef = gegl_node_new_child (ct->node_preview,
+ "operation", "gegl:buffer-source",
+ "buffer", ct->coef,
+ NULL);
+
+ cage = gegl_node_new_child (ct->node_preview,
+ "operation", "gimp:cage_preview",
+ "config", ct->config,
+ NULL);
+
+ gegl_node_connect_to (coef, "output",
+ cage, "aux");
+
+ ct->image_map = gimp_image_map_new (drawable,
+ _("Cage transform"),
+ cage,
+ NULL,
+ NULL);
+}
+
+static gboolean
+gimp_cage_tool_update_preview (GimpTool *tool)
+{
+ GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
+ GimpImage *image = gimp_display_get_image (tool->display);
+
+ if (!ct->image_map)
+ {
+ /*Destroyed, bailing out*/
+ ct->idle_id = 0;
+ return FALSE;
+ }
+
+ gimp_projection_flush_now (gimp_image_get_projection (image));
+ gimp_display_flush_now (tool->display);
+
+ if (!gimp_image_map_is_busy(ct->image_map))
+ {
+ ct->idle_id = 0;
+
+ return FALSE;
+ }
+
+ return TRUE;
+
+
+}
+
+static void
gimp_cage_tool_process (GimpCageTool *ct,
GimpDisplay *display)
{
@@ -887,38 +882,53 @@ gimp_cage_tool_process (GimpCageTool *ct,
static void
-gimp_cage_tool_prepare_preview (GimpCageTool *ct,
- GimpDisplay *display)
+gimp_cage_tool_halt (GimpCageTool *ct)
{
- GimpImage *image = gimp_display_get_image (display);
- GimpDrawable *drawable = gimp_image_get_active_drawable (image);
+ GimpTool *tool = GIMP_TOOL (ct);
+ GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (ct);
- GeglNode *coef, *cage;
+ if (gimp_draw_tool_is_active (draw_tool))
+ gimp_draw_tool_stop (draw_tool);
- if (ct->node_preview)
+ if (gimp_tool_control_is_active (tool->control))
+ gimp_tool_control_halt (tool->control);
+
+ if (ct->config)
{
- g_object_unref (ct->node_preview);
- ct->node_preview = NULL;
+ g_object_unref (ct->config);
+ ct->config = NULL;
}
- ct->node_preview = gegl_node_new ();
+ if (ct->coef)
+ {
+ gegl_buffer_destroy (ct->coef);
+ ct->coef = NULL;
+ }
- coef = gegl_node_new_child (ct->node_preview,
- "operation", "gegl:buffer-source",
- "buffer", ct->coef,
- NULL);
+ if (ct->image_map)
+ {
- cage = gegl_node_new_child (ct->node_preview,
- "operation", "gimp:cage_preview",
- "config", ct->config,
- NULL);
+ if (ct->idle_id > 0)
+ {
+ g_source_remove(ct->idle_id);
+ ct->idle_id = 0;
+ }
+ gimp_tool_control_set_preserve (tool->control, TRUE);
- gegl_node_connect_to (coef, "output",
- cage, "aux");
+ gimp_image_map_abort (ct->image_map);
+ g_object_unref (ct->image_map);
+ ct->image_map = NULL;
- ct->image_map = gimp_image_map_new (drawable,
- _("Cage transform"),
- cage,
- NULL,
- NULL);
-}
+ gimp_tool_control_set_preserve (tool->control, FALSE);
+
+ gimp_image_flush (gimp_display_get_image (tool->display));
+ }
+
+ if (ct->node_preview)
+ {
+ g_object_unref (ct->node_preview);
+ ct->node_preview = NULL;
+ }
+
+ tool->display = NULL;
+}
\ No newline at end of file
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]