app: npd-tool: add option to pause/unpause deformation process

This commit is contained in:
Marek Dvoroznak 2013-09-02 15:31:25 +02:00 committed by Michael Natterer
parent 8fcf1e0015
commit b6b1d3c27a
4 changed files with 122 additions and 55 deletions

View File

@ -43,7 +43,8 @@ enum
PROP_ASAP_DEFORMATION, PROP_ASAP_DEFORMATION,
PROP_MLS_WEIGHTS, PROP_MLS_WEIGHTS,
PROP_MLS_WEIGHTS_ALPHA, PROP_MLS_WEIGHTS_ALPHA,
PROP_MESH_VISIBLE PROP_MESH_VISIBLE,
PROP_PAUSE_DEFORMATION
}; };
@ -100,6 +101,11 @@ gimp_n_point_deformation_options_class_init (GimpNPointDeformationOptionsClass *
"mesh-visible", _("Mesh Visible"), "mesh-visible", _("Mesh Visible"),
TRUE, TRUE,
GIMP_PARAM_STATIC_STRINGS); GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_PAUSE_DEFORMATION,
"pause-deformation", _("Pause Deformation"),
FALSE,
GIMP_PARAM_STATIC_STRINGS);
} }
static void static void
@ -135,6 +141,9 @@ gimp_n_point_deformation_options_set_property (GObject *object,
case PROP_MESH_VISIBLE: case PROP_MESH_VISIBLE:
options->mesh_visible = g_value_get_boolean (value); options->mesh_visible = g_value_get_boolean (value);
break; break;
case PROP_PAUSE_DEFORMATION:
options->deformation_is_paused = g_value_get_boolean (value);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break; break;
@ -169,6 +178,9 @@ gimp_n_point_deformation_options_get_property (GObject *object,
case PROP_MESH_VISIBLE: case PROP_MESH_VISIBLE:
g_value_set_boolean (value, options->mesh_visible); g_value_set_boolean (value, options->mesh_visible);
break; break;
case PROP_PAUSE_DEFORMATION:
g_value_set_boolean (value, options->deformation_is_paused);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break; break;
@ -209,5 +221,32 @@ gimp_n_point_deformation_options_gui (GimpToolOptions *tool_options)
gtk_box_pack_start (GTK_BOX (vbox), scale, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), scale, FALSE, FALSE, 0);
gtk_widget_show (scale); gtk_widget_show (scale);
check = gimp_prop_check_button_new (config, "pause-deformation", _("Pause Deformation"));
GIMP_N_POINT_DEFORMATION_OPTIONS (tool_options)->check_pause_deformation = check;
gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
gtk_widget_show (check);
return vbox; return vbox;
} }
gboolean
gimp_n_point_deformation_options_is_deformation_paused (GimpNPointDeformationOptions *npd_options)
{
return npd_options->deformation_is_paused;
}
void
gimp_n_point_deformation_options_set_pause_deformation (GimpNPointDeformationOptions *npd_options,
gboolean is_active)
{
GtkToggleButton *check = GTK_TOGGLE_BUTTON (npd_options->check_pause_deformation);
gtk_toggle_button_set_active (check, is_active);
npd_options->deformation_is_paused = is_active;
}
void
gimp_n_point_deformation_options_toggle_pause_deformation (GimpNPointDeformationOptions *npd_options)
{
gimp_n_point_deformation_options_set_pause_deformation (npd_options,
!npd_options->deformation_is_paused);
}

View File

@ -45,6 +45,9 @@ struct _GimpNPointDeformationOptions
gboolean MLS_weights; gboolean MLS_weights;
gdouble MLS_weights_alpha; gdouble MLS_weights_alpha;
gboolean mesh_visible; gboolean mesh_visible;
gboolean deformation_is_paused;
GtkWidget *check_pause_deformation;
}; };
struct _GimpNPointDeformationOptionsClass struct _GimpNPointDeformationOptionsClass
@ -57,5 +60,9 @@ GType gimp_n_point_deformation_options_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_n_point_deformation_options_gui (GimpToolOptions *tool_options); GtkWidget * gimp_n_point_deformation_options_gui (GimpToolOptions *tool_options);
gboolean gimp_n_point_deformation_options_is_deformation_paused (GimpNPointDeformationOptions *npd_options);
void gimp_n_point_deformation_options_set_pause_deformation (GimpNPointDeformationOptions *npd_options,
gboolean is_active);
void gimp_n_point_deformation_options_toggle_pause_deformation (GimpNPointDeformationOptions *npd_options);
#endif /* __GIMP_N_POINT_DEFORMATION_OPTIONS_H__ */ #endif /* __GIMP_N_POINT_DEFORMATION_OPTIONS_H__ */

View File

@ -265,6 +265,7 @@ gimp_n_point_deformation_tool_start (GimpNPointDeformationTool *npd_tool,
/* initialize some options */ /* initialize some options */
npd_options = GIMP_N_POINT_DEFORMATION_TOOL_GET_OPTIONS (npd_tool); npd_options = GIMP_N_POINT_DEFORMATION_TOOL_GET_OPTIONS (npd_tool);
npd_options->mesh_visible = TRUE; npd_options->mesh_visible = TRUE;
gimp_n_point_deformation_options_set_pause_deformation (npd_options, FALSE);
gimp_n_point_deformation_tool_set_options (node, npd_options); gimp_n_point_deformation_tool_set_options (node, npd_options);
/* compute and get model */ /* compute and get model */
@ -333,8 +334,8 @@ gimp_n_point_deformation_tool_options_notify (GimpTool *tool,
const GParamSpec *pspec) const GParamSpec *pspec)
{ {
GimpNPointDeformationTool *npd_tool = GIMP_N_POINT_DEFORMATION_TOOL (tool); GimpNPointDeformationTool *npd_tool = GIMP_N_POINT_DEFORMATION_TOOL (tool);
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
GimpNPointDeformationOptions *npd_options = GIMP_N_POINT_DEFORMATION_OPTIONS (options); GimpNPointDeformationOptions *npd_options = GIMP_N_POINT_DEFORMATION_OPTIONS (options);
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
GIMP_TOOL_CLASS (parent_class)->options_notify (tool, options, pspec); GIMP_TOOL_CLASS (parent_class)->options_notify (tool, options, pspec);
@ -354,6 +355,7 @@ gimp_n_point_deformation_tool_key_press (GimpTool *tool,
GimpDisplay *display) GimpDisplay *display)
{ {
GimpNPointDeformationTool *npd_tool = GIMP_N_POINT_DEFORMATION_TOOL (tool); GimpNPointDeformationTool *npd_tool = GIMP_N_POINT_DEFORMATION_TOOL (tool);
GimpNPointDeformationOptions *npd_options = GIMP_N_POINT_DEFORMATION_TOOL_GET_OPTIONS (npd_tool);
NPDModel *model = npd_tool->model; NPDModel *model = npd_tool->model;
NPDControlPoint *cp; NPDControlPoint *cp;
GArray *cps = model->control_points; GArray *cps = model->control_points;
@ -385,9 +387,9 @@ gimp_n_point_deformation_tool_key_press (GimpTool *tool,
case GDK_KEY_ISO_Enter: case GDK_KEY_ISO_Enter:
gimp_n_point_deformation_tool_halt_deform_thread (npd_tool); gimp_n_point_deformation_tool_halt_deform_thread (npd_tool);
GIMP_N_POINT_DEFORMATION_TOOL_GET_OPTIONS (npd_tool)->mesh_visible = FALSE; npd_options->mesh_visible = FALSE;
gimp_n_point_deformation_tool_set_options (npd_tool->node, gimp_n_point_deformation_tool_set_options (npd_tool->node,
GIMP_N_POINT_DEFORMATION_TOOL_GET_OPTIONS (npd_tool)); npd_options);
gimp_n_point_deformation_tool_perform_deformation (npd_tool); gimp_n_point_deformation_tool_perform_deformation (npd_tool);
gimp_n_point_deformation_tool_update_image (npd_tool); gimp_n_point_deformation_tool_update_image (npd_tool);
@ -399,6 +401,7 @@ gimp_n_point_deformation_tool_key_press (GimpTool *tool,
case GDK_KEY_KP_Space: case GDK_KEY_KP_Space:
case GDK_KEY_space: case GDK_KEY_space:
gimp_n_point_deformation_options_toggle_pause_deformation (npd_options);
break; break;
default: default:
@ -424,6 +427,7 @@ gimp_n_point_deformation_tool_cursor_update (GimpTool *tool,
GimpDisplay *display) GimpDisplay *display)
{ {
GimpNPointDeformationTool *npd_tool = GIMP_N_POINT_DEFORMATION_TOOL (tool); GimpNPointDeformationTool *npd_tool = GIMP_N_POINT_DEFORMATION_TOOL (tool);
GimpNPointDeformationOptions *npd_options = GIMP_N_POINT_DEFORMATION_TOOL_GET_OPTIONS (npd_tool);
GimpCursorModifier modifier = GIMP_CURSOR_MODIFIER_PLUS; GimpCursorModifier modifier = GIMP_CURSOR_MODIFIER_PLUS;
if (!npd_tool->active) if (!npd_tool->active)
@ -431,6 +435,11 @@ gimp_n_point_deformation_tool_cursor_update (GimpTool *tool,
modifier = GIMP_CURSOR_MODIFIER_NONE; modifier = GIMP_CURSOR_MODIFIER_NONE;
} }
else else
if (gimp_n_point_deformation_options_is_deformation_paused (npd_options))
{
modifier = GIMP_CURSOR_MODIFIER_BAD;
}
else
if (npd_tool->hovering_cp != NULL) if (npd_tool->hovering_cp != NULL)
{ {
modifier = GIMP_CURSOR_MODIFIER_MOVE; modifier = GIMP_CURSOR_MODIFIER_MOVE;
@ -487,6 +496,7 @@ gimp_n_point_deformation_tool_button_press (GimpTool *tool,
GimpDisplay *display) GimpDisplay *display)
{ {
GimpNPointDeformationTool *npd_tool = GIMP_N_POINT_DEFORMATION_TOOL (tool); GimpNPointDeformationTool *npd_tool = GIMP_N_POINT_DEFORMATION_TOOL (tool);
GimpNPointDeformationOptions *npd_options = GIMP_N_POINT_DEFORMATION_TOOL_GET_OPTIONS (npd_tool);
NPDControlPoint *cp; NPDControlPoint *cp;
GList **selected_cps = &npd_tool->selected_cps; GList **selected_cps = &npd_tool->selected_cps;
GList **previous_cps_positions = &npd_tool->previous_cps_positions; GList **previous_cps_positions = &npd_tool->previous_cps_positions;
@ -499,7 +509,10 @@ gimp_n_point_deformation_tool_button_press (GimpTool *tool,
} }
/* this is at least second click on the drawable - do usual work */ /* this is at least second click on the drawable - do usual work */
if (gimp_n_point_deformation_options_is_deformation_paused (npd_options)) return;
gimp_tool_control_activate (tool->control); gimp_tool_control_activate (tool->control);
npd_tool->selected_cp = NULL; npd_tool->selected_cp = NULL;
if (press_type == GIMP_BUTTON_PRESS_NORMAL) if (press_type == GIMP_BUTTON_PRESS_NORMAL)
@ -576,12 +589,15 @@ gimp_n_point_deformation_tool_button_release (GimpTool *tool,
GimpDisplay *display) GimpDisplay *display)
{ {
GimpNPointDeformationTool *npd_tool = GIMP_N_POINT_DEFORMATION_TOOL (tool); GimpNPointDeformationTool *npd_tool = GIMP_N_POINT_DEFORMATION_TOOL (tool);
GimpNPointDeformationOptions *npd_options = GIMP_N_POINT_DEFORMATION_TOOL_GET_OPTIONS (npd_tool);
NPDModel *model = npd_tool->model; NPDModel *model = npd_tool->model;
NPDPoint p; NPDPoint p;
NPDControlPoint *cp; NPDControlPoint *cp;
GArray *cps = model->control_points; GArray *cps = model->control_points;
gint i; gint i;
if (gimp_n_point_deformation_options_is_deformation_paused (npd_options)) return;
gimp_tool_control_halt (tool->control); gimp_tool_control_halt (tool->control);
gimp_draw_tool_pause (GIMP_DRAW_TOOL (npd_tool)); gimp_draw_tool_pause (GIMP_DRAW_TOOL (npd_tool));
@ -808,20 +824,25 @@ gpointer
gimp_n_point_deformation_tool_deform_thread_func (gpointer data) gimp_n_point_deformation_tool_deform_thread_func (gpointer data)
{ {
GimpNPointDeformationTool *npd_tool = data; GimpNPointDeformationTool *npd_tool = data;
GimpNPointDeformationOptions *npd_options = GIMP_N_POINT_DEFORMATION_TOOL_GET_OPTIONS (npd_tool);
GimpTool *tool = GIMP_TOOL (npd_tool); GimpTool *tool = GIMP_TOOL (npd_tool);
Gimp *gimp = tool->display->gimp; Gimp *gimp = tool->display->gimp;
while (npd_tool->active) { while (npd_tool->active) {
/* perform the deformation only if the tool hasn't been paused */
if (!gimp_n_point_deformation_options_is_deformation_paused (npd_options))
{
gimp_n_point_deformation_tool_perform_deformation (npd_tool); gimp_n_point_deformation_tool_perform_deformation (npd_tool);
gimp_npd_debug (("gimp_threads_enter\n")); gimp_npd_debug (("gimp_threads_enter\n"));
gimp_threads_enter (gimp); gimp_threads_enter (gimp);
gimp_n_point_deformation_tool_update_image (npd_tool); gimp_n_point_deformation_tool_update_image (npd_tool);
gimp_npd_debug (("gimp_threads_leave\n"));
gimp_npd_debug (("gimp_threads_leave\n"));
gimp_threads_leave (gimp); gimp_threads_leave (gimp);
} }
}
gimp_npd_debug (("thread exit\n")); gimp_npd_debug (("thread exit\n"));

View File

@ -71,7 +71,7 @@ struct _GimpNPointDeformationTool
GList *previous_cps_positions; /* list of NPDPoints holding previous GList *previous_cps_positions; /* list of NPDPoints holding previous
* positions of control points */ * positions of control points */
gboolean active; volatile gboolean active;
gboolean rubber_band; gboolean rubber_band;
}; };