mirror of https://github.com/GNOME/gimp.git
app: lots of cleanup in the N-Point Deformation tool
- Formatting and indentation - Handle GIMP_TOOL_ACTION_COMMIT - Fix calls to gimp_tool_control_activate()/halt() - Move variables to local scopes - Remove and reorder includes - Remove redundant members from the tool struct - Set members to NULL after freeing them - And whatnot...
This commit is contained in:
parent
ce29043315
commit
c3b6b3273c
|
@ -35,15 +35,16 @@
|
|||
|
||||
#include "gimp-intl.h"
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_SQUARE_SIZE,
|
||||
PROP_RIGIDITY,
|
||||
PROP_ASAP_DEFORMATION,
|
||||
PROP_MLS_WEIGHTS,
|
||||
PROP_MLS_WEIGHTS_ALPHA,
|
||||
PROP_MESH_VISIBLE
|
||||
PROP_0,
|
||||
PROP_SQUARE_SIZE,
|
||||
PROP_RIGIDITY,
|
||||
PROP_ASAP_DEFORMATION,
|
||||
PROP_MLS_WEIGHTS,
|
||||
PROP_MLS_WEIGHTS_ALPHA,
|
||||
PROP_MESH_VISIBLE
|
||||
};
|
||||
|
||||
|
||||
|
@ -92,7 +93,8 @@ gimp_n_point_deformation_options_class_init (GimpNPointDeformationOptionsClass *
|
|||
GIMP_PARAM_STATIC_STRINGS);
|
||||
|
||||
GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_MLS_WEIGHTS_ALPHA,
|
||||
"MLS-weights-alpha", _("Amount of control points' influence"),
|
||||
"MLS-weights-alpha",
|
||||
_("Amount of control points' influence"),
|
||||
0.1, 2.0, 1.0,
|
||||
GIMP_PARAM_STATIC_STRINGS);
|
||||
|
||||
|
@ -113,39 +115,34 @@ gimp_n_point_deformation_options_set_property (GObject *object,
|
|||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GimpNPointDeformationOptions *options = GIMP_N_POINT_DEFORMATION_OPTIONS (object);
|
||||
GimpNPointDeformationOptions *options;
|
||||
|
||||
options = GIMP_N_POINT_DEFORMATION_OPTIONS (object);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_SQUARE_SIZE:
|
||||
options->square_size = g_value_get_double (value);
|
||||
break;
|
||||
case PROP_RIGIDITY:
|
||||
options->rigidity = g_value_get_double (value);
|
||||
break;
|
||||
case PROP_ASAP_DEFORMATION:
|
||||
options->ASAP_deformation = g_value_get_boolean (value);
|
||||
break;
|
||||
case PROP_MLS_WEIGHTS:
|
||||
options->MLS_weights = g_value_get_boolean (value);
|
||||
case PROP_SQUARE_SIZE:
|
||||
options->square_size = g_value_get_double (value);
|
||||
break;
|
||||
case PROP_RIGIDITY:
|
||||
options->rigidity = g_value_get_double (value);
|
||||
break;
|
||||
case PROP_ASAP_DEFORMATION:
|
||||
options->ASAP_deformation = g_value_get_boolean (value);
|
||||
break;
|
||||
case PROP_MLS_WEIGHTS:
|
||||
options->MLS_weights = g_value_get_boolean (value);
|
||||
break;
|
||||
case PROP_MLS_WEIGHTS_ALPHA:
|
||||
options->MLS_weights_alpha = g_value_get_double (value);
|
||||
break;
|
||||
case PROP_MESH_VISIBLE:
|
||||
options->mesh_visible = g_value_get_boolean (value);
|
||||
break;
|
||||
|
||||
if (options->scale_MLS_weights_alpha)
|
||||
gtk_widget_set_sensitive (options->scale_MLS_weights_alpha,
|
||||
options->MLS_weights);
|
||||
break;
|
||||
case PROP_MLS_WEIGHTS_ALPHA:
|
||||
options->MLS_weights_alpha = g_value_get_double (value);
|
||||
break;
|
||||
case PROP_MESH_VISIBLE:
|
||||
options->mesh_visible = g_value_get_boolean (value);
|
||||
|
||||
if (options->check_mesh_visible)
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->check_mesh_visible),
|
||||
options->mesh_visible);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -155,72 +152,85 @@ gimp_n_point_deformation_options_get_property (GObject *object,
|
|||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GimpNPointDeformationOptions *options = GIMP_N_POINT_DEFORMATION_OPTIONS (object);
|
||||
GimpNPointDeformationOptions *options;
|
||||
|
||||
options = GIMP_N_POINT_DEFORMATION_OPTIONS (object);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_SQUARE_SIZE:
|
||||
g_value_set_double (value, options->square_size);
|
||||
break;
|
||||
case PROP_RIGIDITY:
|
||||
g_value_set_double (value, options->rigidity);
|
||||
break;
|
||||
case PROP_ASAP_DEFORMATION:
|
||||
g_value_set_boolean (value, options->ASAP_deformation);
|
||||
break;
|
||||
case PROP_MLS_WEIGHTS:
|
||||
g_value_set_boolean (value, options->MLS_weights);
|
||||
break;
|
||||
case PROP_MLS_WEIGHTS_ALPHA:
|
||||
g_value_set_double (value, options->MLS_weights_alpha);
|
||||
break;
|
||||
case PROP_MESH_VISIBLE:
|
||||
g_value_set_boolean (value, options->mesh_visible);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
case PROP_SQUARE_SIZE:
|
||||
g_value_set_double (value, options->square_size);
|
||||
break;
|
||||
case PROP_RIGIDITY:
|
||||
g_value_set_double (value, options->rigidity);
|
||||
break;
|
||||
case PROP_ASAP_DEFORMATION:
|
||||
g_value_set_boolean (value, options->ASAP_deformation);
|
||||
break;
|
||||
case PROP_MLS_WEIGHTS:
|
||||
g_value_set_boolean (value, options->MLS_weights);
|
||||
break;
|
||||
case PROP_MLS_WEIGHTS_ALPHA:
|
||||
g_value_set_double (value, options->MLS_weights_alpha);
|
||||
break;
|
||||
case PROP_MESH_VISIBLE:
|
||||
g_value_set_boolean (value, options->mesh_visible);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
gimp_n_point_deformation_options_gui (GimpToolOptions *tool_options)
|
||||
{
|
||||
GimpNPointDeformationOptions *npd_options = GIMP_N_POINT_DEFORMATION_OPTIONS (tool_options);
|
||||
GObject *config = G_OBJECT (tool_options);
|
||||
GtkWidget *vbox = gimp_tool_options_gui (tool_options);
|
||||
GtkWidget *widget;
|
||||
GimpNPointDeformationOptions *npd_options;
|
||||
GObject *config = G_OBJECT (tool_options);
|
||||
GtkWidget *vbox = gimp_tool_options_gui (tool_options);
|
||||
GtkWidget *widget;
|
||||
|
||||
widget = gimp_prop_check_button_new (config, "mesh-visible", _("Show lattice"));
|
||||
npd_options = GIMP_N_POINT_DEFORMATION_OPTIONS (tool_options);
|
||||
|
||||
widget = gimp_prop_check_button_new (config, "mesh-visible",
|
||||
_("Show lattice"));
|
||||
npd_options->check_mesh_visible = widget;
|
||||
gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
|
||||
gtk_widget_set_can_focus (widget, FALSE);
|
||||
gtk_widget_show (widget);
|
||||
|
||||
widget = gimp_prop_spin_scale_new (config, "square-size", _("Density"), 1.0, 10.0, 0);
|
||||
widget = gimp_prop_spin_scale_new (config, "square-size",
|
||||
_("Density"), 1.0, 10.0, 0);
|
||||
npd_options->scale_square_size = widget;
|
||||
gimp_spin_scale_set_scale_limits (GIMP_SPIN_SCALE (widget), 10.0, 100.0);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
|
||||
gtk_widget_set_can_focus (widget, FALSE);
|
||||
gtk_widget_show (widget);
|
||||
|
||||
widget = gimp_prop_spin_scale_new (config, "rigidity", _("Rigidity"), 1.0, 10.0, 0);
|
||||
widget = gimp_prop_spin_scale_new (config, "rigidity",
|
||||
_("Rigidity"), 1.0, 10.0, 0);
|
||||
gimp_spin_scale_set_scale_limits (GIMP_SPIN_SCALE (widget), 1.0, 2000.0);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
|
||||
gtk_widget_set_can_focus (widget, FALSE);
|
||||
gtk_widget_show (widget);
|
||||
|
||||
widget = gimp_prop_boolean_radio_frame_new (config, "ASAP-deformation", _("Deformation mode"), _("scale"), _("rigid (rubber)"));
|
||||
widget = gimp_prop_boolean_radio_frame_new (config, "ASAP-deformation",
|
||||
_("Deformation mode"),
|
||||
_("scale"), _("rigid (rubber)"));
|
||||
gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
|
||||
gtk_widget_set_can_focus (widget, FALSE);
|
||||
gtk_widget_show (widget);
|
||||
|
||||
widget = gimp_prop_check_button_new (config, "MLS-weights", _("Use weights"));
|
||||
widget = gimp_prop_check_button_new (config, "MLS-weights",
|
||||
_("Use weights"));
|
||||
gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
|
||||
gtk_widget_set_can_focus (widget, FALSE);
|
||||
gtk_widget_show (widget);
|
||||
|
||||
widget = gimp_prop_spin_scale_new (config, "MLS-weights-alpha", _("Amount of control points' influence"), 0.1, 0.1, 1);
|
||||
widget = gimp_prop_spin_scale_new (config, "MLS-weights-alpha",
|
||||
_("Amount of control points' influence"),
|
||||
0.1, 0.1, 1);
|
||||
npd_options->scale_MLS_weights_alpha = widget;
|
||||
gimp_spin_scale_set_scale_limits (GIMP_SPIN_SCALE (widget), 0.1, 2.0);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
|
||||
|
@ -228,15 +238,20 @@ gimp_n_point_deformation_options_gui (GimpToolOptions *tool_options)
|
|||
gtk_widget_set_sensitive (widget, npd_options->MLS_weights);
|
||||
gtk_widget_show (widget);
|
||||
|
||||
gimp_n_point_deformation_options_init_some_widgets (npd_options, FALSE);
|
||||
g_object_bind_property (config, "MLS-weights",
|
||||
widget, "sensitive",
|
||||
G_BINDING_DEFAULT |
|
||||
G_BINDING_SYNC_CREATE);
|
||||
|
||||
gimp_n_point_deformation_options_set_sensitivity (npd_options, FALSE);
|
||||
|
||||
return vbox;
|
||||
}
|
||||
|
||||
void
|
||||
gimp_n_point_deformation_options_init_some_widgets (GimpNPointDeformationOptions *npd_options,
|
||||
gboolean is_tool_active)
|
||||
gimp_n_point_deformation_options_set_sensitivity (GimpNPointDeformationOptions *npd_options,
|
||||
gboolean tool_active)
|
||||
{
|
||||
gtk_widget_set_sensitive (npd_options->scale_square_size, !is_tool_active);
|
||||
gtk_widget_set_sensitive (npd_options->check_mesh_visible, is_tool_active);
|
||||
gtk_widget_set_sensitive (npd_options->scale_square_size, ! tool_active);
|
||||
gtk_widget_set_sensitive (npd_options->check_mesh_visible, tool_active);
|
||||
}
|
||||
|
|
|
@ -61,7 +61,8 @@ GType gimp_n_point_deformation_options_get_type (void) G_GNUC_CONST;
|
|||
|
||||
GtkWidget * gimp_n_point_deformation_options_gui (GimpToolOptions *tool_options);
|
||||
|
||||
void gimp_n_point_deformation_options_init_some_widgets (GimpNPointDeformationOptions *npd_options,
|
||||
gboolean is_tool_active);
|
||||
void gimp_n_point_deformation_options_set_sensitivity (GimpNPointDeformationOptions *npd_options,
|
||||
gboolean tool_active);
|
||||
|
||||
|
||||
#endif /* __GIMP_N_POINT_DEFORMATION_OPTIONS_H__ */
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -43,7 +43,6 @@ struct _GimpNPointDeformationTool
|
|||
{
|
||||
GimpDrawTool parent_instance;
|
||||
|
||||
GimpDisplay *display;
|
||||
guint draw_timeout_id;
|
||||
GThread *deform_thread;
|
||||
|
||||
|
@ -53,12 +52,9 @@ struct _GimpNPointDeformationTool
|
|||
GeglNode *sink;
|
||||
|
||||
GeglBuffer *preview_buffer;
|
||||
GeglBuffer *source_buffer;
|
||||
|
||||
GimpDrawable *drawable;
|
||||
|
||||
NPDModel *model;
|
||||
NPDControlPoint *selected_cp; /* last selected control point */
|
||||
NPDControlPoint *selected_cp; /* last selected control point */
|
||||
GList *selected_cps; /* list of selected control points */
|
||||
NPDControlPoint *hovering_cp;
|
||||
|
||||
|
@ -67,31 +63,28 @@ struct _GimpNPointDeformationTool
|
|||
gdouble cursor_x;
|
||||
gdouble cursor_y;
|
||||
|
||||
gdouble offset_x;
|
||||
gdouble offset_y;
|
||||
gint offset_x;
|
||||
gint offset_y;
|
||||
|
||||
gdouble movement_start_x;
|
||||
gdouble movement_start_y;
|
||||
|
||||
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
|
||||
* positions of control points */
|
||||
* positions of control points
|
||||
*/
|
||||
|
||||
gboolean active;
|
||||
volatile gboolean deformation_active;
|
||||
gboolean rubber_band;
|
||||
gboolean apply_deformation;
|
||||
};
|
||||
|
||||
struct _GimpNPointDeformationToolClass
|
||||
{
|
||||
GimpDrawToolClass parent_class;
|
||||
|
||||
/* virtual function */
|
||||
|
||||
void (* perform_deformation) (GimpNPointDeformationTool *npd_tool);
|
||||
};
|
||||
|
||||
void gimp_n_point_deformation_tool_register (GimpToolRegisterCallback callback,
|
||||
|
@ -99,4 +92,5 @@ void gimp_n_point_deformation_tool_register (GimpToolRegisterCallback callba
|
|||
|
||||
GType gimp_n_point_deformation_tool_get_type (void) G_GNUC_CONST;
|
||||
|
||||
|
||||
#endif /* __GIMP_N_POINT_DEFORMATION_TOOL_H__ */
|
||||
|
|
Loading…
Reference in New Issue