mirror of https://github.com/GNOME/gimp.git
app: npd-tool: add option to pause/unpause deformation process
This commit is contained in:
parent
8fcf1e0015
commit
b6b1d3c27a
|
@ -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);
|
||||||
|
}
|
||||||
|
|
|
@ -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__ */
|
||||||
|
|
|
@ -261,10 +261,11 @@ gimp_n_point_deformation_tool_start (GimpNPointDeformationTool *npd_tool,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
gegl_node_link_many (source, node, sink, NULL);
|
gegl_node_link_many (source, node, sink, NULL);
|
||||||
|
|
||||||
/* 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);
|
||||||
|
|
||||||
|
@ -353,10 +354,11 @@ gimp_n_point_deformation_tool_key_press (GimpTool *tool,
|
||||||
GdkEventKey *kevent,
|
GdkEventKey *kevent,
|
||||||
GimpDisplay *display)
|
GimpDisplay *display)
|
||||||
{
|
{
|
||||||
GimpNPointDeformationTool *npd_tool = GIMP_N_POINT_DEFORMATION_TOOL (tool);
|
GimpNPointDeformationTool *npd_tool = GIMP_N_POINT_DEFORMATION_TOOL (tool);
|
||||||
NPDModel *model = npd_tool->model;
|
GimpNPointDeformationOptions *npd_options = GIMP_N_POINT_DEFORMATION_TOOL_GET_OPTIONS (npd_tool);
|
||||||
NPDControlPoint *cp;
|
NPDModel *model = npd_tool->model;
|
||||||
GArray *cps = model->control_points;
|
NPDControlPoint *cp;
|
||||||
|
GArray *cps = model->control_points;
|
||||||
|
|
||||||
switch (kevent->keyval)
|
switch (kevent->keyval)
|
||||||
{
|
{
|
||||||
|
@ -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:
|
||||||
|
@ -423,14 +426,20 @@ gimp_n_point_deformation_tool_cursor_update (GimpTool *tool,
|
||||||
GdkModifierType state,
|
GdkModifierType state,
|
||||||
GimpDisplay *display)
|
GimpDisplay *display)
|
||||||
{
|
{
|
||||||
GimpNPointDeformationTool *npd_tool = GIMP_N_POINT_DEFORMATION_TOOL (tool);
|
GimpNPointDeformationTool *npd_tool = GIMP_N_POINT_DEFORMATION_TOOL (tool);
|
||||||
GimpCursorModifier modifier = GIMP_CURSOR_MODIFIER_PLUS;
|
GimpNPointDeformationOptions *npd_options = GIMP_N_POINT_DEFORMATION_TOOL_GET_OPTIONS (npd_tool);
|
||||||
|
GimpCursorModifier modifier = GIMP_CURSOR_MODIFIER_PLUS;
|
||||||
|
|
||||||
if (!npd_tool->active)
|
if (!npd_tool->active)
|
||||||
{
|
{
|
||||||
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;
|
||||||
|
@ -486,10 +495,11 @@ gimp_n_point_deformation_tool_button_press (GimpTool *tool,
|
||||||
GimpButtonPressType press_type,
|
GimpButtonPressType press_type,
|
||||||
GimpDisplay *display)
|
GimpDisplay *display)
|
||||||
{
|
{
|
||||||
GimpNPointDeformationTool *npd_tool = GIMP_N_POINT_DEFORMATION_TOOL (tool);
|
GimpNPointDeformationTool *npd_tool = GIMP_N_POINT_DEFORMATION_TOOL (tool);
|
||||||
NPDControlPoint *cp;
|
GimpNPointDeformationOptions *npd_options = GIMP_N_POINT_DEFORMATION_TOOL_GET_OPTIONS (npd_tool);
|
||||||
GList **selected_cps = &npd_tool->selected_cps;
|
NPDControlPoint *cp;
|
||||||
GList **previous_cps_positions = &npd_tool->previous_cps_positions;
|
GList **selected_cps = &npd_tool->selected_cps;
|
||||||
|
GList **previous_cps_positions = &npd_tool->previous_cps_positions;
|
||||||
|
|
||||||
if (display != tool->display)
|
if (display != tool->display)
|
||||||
{
|
{
|
||||||
|
@ -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)
|
||||||
|
@ -575,13 +588,16 @@ gimp_n_point_deformation_tool_button_release (GimpTool *tool,
|
||||||
GimpButtonReleaseType release_type,
|
GimpButtonReleaseType release_type,
|
||||||
GimpDisplay *display)
|
GimpDisplay *display)
|
||||||
{
|
{
|
||||||
GimpNPointDeformationTool *npd_tool = GIMP_N_POINT_DEFORMATION_TOOL (tool);
|
GimpNPointDeformationTool *npd_tool = GIMP_N_POINT_DEFORMATION_TOOL (tool);
|
||||||
NPDModel *model = npd_tool->model;
|
GimpNPointDeformationOptions *npd_options = GIMP_N_POINT_DEFORMATION_TOOL_GET_OPTIONS (npd_tool);
|
||||||
NPDPoint p;
|
NPDModel *model = npd_tool->model;
|
||||||
NPDControlPoint *cp;
|
NPDPoint p;
|
||||||
GArray *cps = model->control_points;
|
NPDControlPoint *cp;
|
||||||
gint i;
|
GArray *cps = model->control_points;
|
||||||
|
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));
|
||||||
|
@ -807,20 +823,25 @@ gimp_n_point_deformation_tool_motion (GimpTool *tool,
|
||||||
gpointer
|
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;
|
||||||
GimpTool *tool = GIMP_TOOL (npd_tool);
|
GimpNPointDeformationOptions *npd_options = GIMP_N_POINT_DEFORMATION_TOOL_GET_OPTIONS (npd_tool);
|
||||||
Gimp *gimp = tool->display->gimp;
|
GimpTool *tool = GIMP_TOOL (npd_tool);
|
||||||
|
Gimp *gimp = tool->display->gimp;
|
||||||
|
|
||||||
while (npd_tool->active) {
|
while (npd_tool->active) {
|
||||||
gimp_n_point_deformation_tool_perform_deformation (npd_tool);
|
/* 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_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_threads_leave (gimp);
|
gimp_npd_debug (("gimp_threads_leave\n"));
|
||||||
|
gimp_threads_leave (gimp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gimp_npd_debug (("thread exit\n"));
|
gimp_npd_debug (("thread exit\n"));
|
||||||
|
@ -871,4 +892,4 @@ gimp_n_point_deformation_tool_halt_deform_thread (GimpNPointDeformationTool *npd
|
||||||
/* wait for deformation thread to finish its work */
|
/* wait for deformation thread to finish its work */
|
||||||
g_thread_join (npd_tool->deform_thread);
|
g_thread_join (npd_tool->deform_thread);
|
||||||
gimp_npd_debug (("finished\n"));
|
gimp_npd_debug (("finished\n"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,39 +40,39 @@ typedef struct _GimpNPointDeformationToolClass GimpNPointDeformationToolClass;
|
||||||
|
|
||||||
struct _GimpNPointDeformationTool
|
struct _GimpNPointDeformationTool
|
||||||
{
|
{
|
||||||
GimpDrawTool parent_instance;
|
GimpDrawTool parent_instance;
|
||||||
|
|
||||||
GimpDisplay *display;
|
GimpDisplay *display;
|
||||||
GThread *deform_thread;
|
GThread *deform_thread;
|
||||||
|
|
||||||
GeglNode *graph;
|
GeglNode *graph;
|
||||||
GeglNode *source;
|
GeglNode *source;
|
||||||
GeglNode *node;
|
GeglNode *node;
|
||||||
GeglNode *sink;
|
GeglNode *sink;
|
||||||
|
|
||||||
GeglBuffer *shadow, *buf;
|
GeglBuffer *shadow, *buf;
|
||||||
|
|
||||||
GimpDrawable *drawable;
|
GimpDrawable *drawable;
|
||||||
|
|
||||||
NPDModel *model;
|
NPDModel *model;
|
||||||
NPDControlPoint *selected_cp; /* last selected control point */
|
NPDControlPoint *selected_cp; /* last selected control point */
|
||||||
GList *selected_cps; /* list of selected control points */
|
GList *selected_cps; /* list of selected control points */
|
||||||
NPDControlPoint *hovering_cp;
|
NPDControlPoint *hovering_cp;
|
||||||
|
|
||||||
gdouble cursor_x;
|
gdouble cursor_x;
|
||||||
gdouble cursor_y;
|
gdouble cursor_y;
|
||||||
|
|
||||||
gdouble movement_start_x;
|
gdouble movement_start_x;
|
||||||
gdouble movement_start_y;
|
gdouble movement_start_y;
|
||||||
|
|
||||||
gfloat cp_scaled_radius; /* radius of a control point scaled
|
gfloat cp_scaled_radius; /* radius of a control point scaled
|
||||||
* according to display shell's scale */
|
* according to display shell's scale */
|
||||||
|
|
||||||
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GimpNPointDeformationToolClass
|
struct _GimpNPointDeformationToolClass
|
||||||
|
|
Loading…
Reference in New Issue