app: more GimpGradientEditor cleanup

Let the split and replicate segments dialogs keep their own data and
don't use GimpGradientEditor struct members. Remove redundant members
and indent the struct.

(cherry picked from commit b8e75a0201)
This commit is contained in:
Michael Natterer
2018-06-24 16:24:16 +02:00
parent a9d851070a
commit 5feabfd1e0
3 changed files with 73 additions and 94 deletions

View File

@ -20,6 +20,7 @@
#include <gegl.h> #include <gegl.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include "libgimpmath/gimpmath.h"
#include "libgimpwidgets/gimpwidgets.h" #include "libgimpwidgets/gimpwidgets.h"
#include "actions-types.h" #include "actions-types.h"
@ -364,6 +365,7 @@ gradient_editor_replicate_cmd_callback (GtkAction *action,
{ {
GimpGradientEditor *editor = GIMP_GRADIENT_EDITOR (data); GimpGradientEditor *editor = GIMP_GRADIENT_EDITOR (data);
GimpDataEditor *data_editor = GIMP_DATA_EDITOR (data); GimpDataEditor *data_editor = GIMP_DATA_EDITOR (data);
GimpGradient *gradient;
GimpGradientSegment *left; GimpGradientSegment *left;
GimpGradientSegment *right; GimpGradientSegment *right;
GtkWidget *dialog; GtkWidget *dialog;
@ -374,7 +376,7 @@ gradient_editor_replicate_cmd_callback (GtkAction *action,
const gchar *title; const gchar *title;
const gchar *desc; const gchar *desc;
gimp_gradient_editor_get_selection (editor, NULL, &left, &right); gimp_gradient_editor_get_selection (editor, &gradient, &left, &right);
if (left == right) if (left == right)
{ {
@ -387,10 +389,10 @@ gradient_editor_replicate_cmd_callback (GtkAction *action,
desc = _("Replicate Gradient Selection"); desc = _("Replicate Gradient Selection");
} }
dialog = dialog = gimp_viewable_dialog_new (GIMP_VIEWABLE (gradient),
gimp_viewable_dialog_new (GIMP_VIEWABLE (data_editor->data),
data_editor->context, data_editor->context,
title, "gimp-gradient-segment-replicate", title,
"gimp-gradient-segment-replicate",
GIMP_ICON_GRADIENT, desc, GIMP_ICON_GRADIENT, desc,
GTK_WIDGET (editor), GTK_WIDGET (editor),
gimp_standard_help_func, gimp_standard_help_func,
@ -428,7 +430,6 @@ gradient_editor_replicate_cmd_callback (GtkAction *action,
gtk_widget_show (label); gtk_widget_show (label);
/* Scale */ /* Scale */
editor->replicate_times = 2;
scale_data = GTK_ADJUSTMENT (gtk_adjustment_new (2.0, 2.0, 21.0, 1.0, 1.0, 1.0)); scale_data = GTK_ADJUSTMENT (gtk_adjustment_new (2.0, 2.0, 21.0, 1.0, 1.0, 1.0));
scale = gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, scale_data); scale = gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, scale_data);
@ -437,9 +438,7 @@ gradient_editor_replicate_cmd_callback (GtkAction *action,
gtk_box_pack_start (GTK_BOX (vbox), scale, FALSE, TRUE, 4); gtk_box_pack_start (GTK_BOX (vbox), scale, FALSE, TRUE, 4);
gtk_widget_show (scale); gtk_widget_show (scale);
g_signal_connect (scale_data, "value-changed", g_object_set_data (G_OBJECT (dialog), "adjustment", scale_data);
G_CALLBACK (gimp_int_adjustment_update),
&editor->replicate_times);
gtk_widget_set_sensitive (GTK_WIDGET (editor), FALSE); gtk_widget_set_sensitive (GTK_WIDGET (editor), FALSE);
gimp_ui_manager_update (gimp_editor_get_ui_manager (GIMP_EDITOR (editor)), gimp_ui_manager_update (gimp_editor_get_ui_manager (GIMP_EDITOR (editor)),
@ -475,6 +474,7 @@ gradient_editor_split_uniformly_cmd_callback (GtkAction *action,
{ {
GimpGradientEditor *editor = GIMP_GRADIENT_EDITOR (data); GimpGradientEditor *editor = GIMP_GRADIENT_EDITOR (data);
GimpDataEditor *data_editor = GIMP_DATA_EDITOR (data); GimpDataEditor *data_editor = GIMP_DATA_EDITOR (data);
GimpGradient *gradient;
GimpGradientSegment *left; GimpGradientSegment *left;
GimpGradientSegment *right; GimpGradientSegment *right;
GtkWidget *dialog; GtkWidget *dialog;
@ -485,7 +485,7 @@ gradient_editor_split_uniformly_cmd_callback (GtkAction *action,
const gchar *title; const gchar *title;
const gchar *desc; const gchar *desc;
gimp_gradient_editor_get_selection (editor, NULL, &left, &right); gimp_gradient_editor_get_selection (editor, &gradient, &left, &right);
if (left == right) if (left == right)
{ {
@ -498,10 +498,10 @@ gradient_editor_split_uniformly_cmd_callback (GtkAction *action,
desc = _("Split Gradient Segments Uniformly"); desc = _("Split Gradient Segments Uniformly");
} }
dialog = dialog = gimp_viewable_dialog_new (GIMP_VIEWABLE (gradient),
gimp_viewable_dialog_new (GIMP_VIEWABLE (data_editor->data),
data_editor->context, data_editor->context,
title, "gimp-gradient-segment-split-uniformly", title,
"gimp-gradient-segment-split-uniformly",
GIMP_ICON_GRADIENT, desc, GIMP_ICON_GRADIENT, desc,
GTK_WIDGET (editor), GTK_WIDGET (editor),
gimp_standard_help_func, gimp_standard_help_func,
@ -540,7 +540,6 @@ gradient_editor_split_uniformly_cmd_callback (GtkAction *action,
gtk_widget_show (label); gtk_widget_show (label);
/* Scale */ /* Scale */
editor->split_parts = 2;
scale_data = GTK_ADJUSTMENT (gtk_adjustment_new (2.0, 2.0, 21.0, 1.0, 1.0, 1.0)); scale_data = GTK_ADJUSTMENT (gtk_adjustment_new (2.0, 2.0, 21.0, 1.0, 1.0, 1.0));
scale = gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, scale_data); scale = gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, scale_data);
@ -549,9 +548,7 @@ gradient_editor_split_uniformly_cmd_callback (GtkAction *action,
gtk_box_pack_start (GTK_BOX (vbox), scale, FALSE, FALSE, 4); gtk_box_pack_start (GTK_BOX (vbox), scale, FALSE, FALSE, 4);
gtk_widget_show (scale); gtk_widget_show (scale);
g_signal_connect (scale_data, "value-changed", g_object_set_data (G_OBJECT (dialog), "adjustment", scale_data);
G_CALLBACK (gimp_int_adjustment_update),
&editor->split_parts);
gtk_widget_set_sensitive (GTK_WIDGET (editor), FALSE); gtk_widget_set_sensitive (GTK_WIDGET (editor), FALSE);
gimp_ui_manager_update (gimp_editor_get_ui_manager (GIMP_EDITOR (editor)), gimp_ui_manager_update (gimp_editor_get_ui_manager (GIMP_EDITOR (editor)),
@ -658,6 +655,13 @@ gradient_editor_split_uniform_response (GtkWidget *widget,
gint response_id, gint response_id,
GimpGradientEditor *editor) GimpGradientEditor *editor)
{ {
GtkAdjustment *adjustment;
gint split_parts;
adjustment = g_object_get_data (G_OBJECT (widget), "adjustment");
split_parts = RINT (gtk_adjustment_get_value (adjustment));
gtk_widget_destroy (widget); gtk_widget_destroy (widget);
gtk_widget_set_sensitive (GTK_WIDGET (editor), TRUE); gtk_widget_set_sensitive (GTK_WIDGET (editor), TRUE);
gimp_ui_manager_update (gimp_editor_get_ui_manager (GIMP_EDITOR (editor)), gimp_ui_manager_update (gimp_editor_get_ui_manager (GIMP_EDITOR (editor)),
@ -675,7 +679,7 @@ gradient_editor_split_uniform_response (GtkWidget *widget,
gimp_gradient_segment_range_split_uniform (gradient, gimp_gradient_segment_range_split_uniform (gradient,
data_editor->context, data_editor->context,
left, right, left, right,
editor->split_parts, split_parts,
editor->blend_color_space, editor->blend_color_space,
&left, &right); &left, &right);
@ -688,6 +692,13 @@ gradient_editor_replicate_response (GtkWidget *widget,
gint response_id, gint response_id,
GimpGradientEditor *editor) GimpGradientEditor *editor)
{ {
GtkAdjustment *adjustment;
gint replicate_times;
adjustment = g_object_get_data (G_OBJECT (widget), "adjustment");
replicate_times = RINT (gtk_adjustment_get_value (adjustment));
gtk_widget_destroy (widget); gtk_widget_destroy (widget);
gtk_widget_set_sensitive (GTK_WIDGET (editor), TRUE); gtk_widget_set_sensitive (GTK_WIDGET (editor), TRUE);
gimp_ui_manager_update (gimp_editor_get_ui_manager (GIMP_EDITOR (editor)), gimp_ui_manager_update (gimp_editor_get_ui_manager (GIMP_EDITOR (editor)),
@ -703,7 +714,7 @@ gradient_editor_replicate_response (GtkWidget *widget,
gimp_gradient_segment_range_replicate (gradient, gimp_gradient_segment_range_replicate (gradient,
left, right, left, right,
editor->replicate_times, replicate_times,
&left, &right); &left, &right);
gimp_gradient_editor_set_selection (editor, left, right); gimp_gradient_editor_set_selection (editor, left, right);

View File

@ -322,10 +322,6 @@ gimp_gradient_editor_init (GimpGradientEditor *editor)
gtk_container_add (GTK_CONTAINER (frame), vbox); gtk_container_add (GTK_CONTAINER (frame), vbox);
gtk_widget_show (vbox); gtk_widget_show (vbox);
/* Gradient view */
editor->view_last_x = 0;
editor->view_button_down = FALSE;
data_editor->view = gimp_view_new_full_by_types (NULL, data_editor->view = gimp_view_new_full_by_types (NULL,
GIMP_TYPE_VIEW, GIMP_TYPE_VIEW,
GIMP_TYPE_GRADIENT, GIMP_TYPE_GRADIENT,
@ -352,16 +348,6 @@ gimp_gradient_editor_init (GimpGradientEditor *editor)
editor); editor);
/* Gradient control */ /* Gradient control */
editor->control_drag_segment = NULL;
editor->control_sel_l = NULL;
editor->control_sel_r = NULL;
editor->control_drag_mode = GRAD_DRAG_NONE;
editor->control_click_time = 0;
editor->control_compress = FALSE;
editor->control_last_x = 0;
editor->control_last_gx = 0.0;
editor->control_orig_pos = 0.0;
editor->control = gtk_drawing_area_new (); editor->control = gtk_drawing_area_new ();
gtk_widget_set_size_request (editor->control, -1, GRAD_CONTROL_HEIGHT); gtk_widget_set_size_request (editor->control, -1, GRAD_CONTROL_HEIGHT);
gtk_widget_set_events (editor->control, GRAD_CONTROL_EVENT_MASK); gtk_widget_set_events (editor->control, GRAD_CONTROL_EVENT_MASK);
@ -430,13 +416,6 @@ gimp_gradient_editor_init (GimpGradientEditor *editor)
editor->hint_label3 = gradient_hint_label_add (GTK_BOX (hint_vbox)); editor->hint_label3 = gradient_hint_label_add (GTK_BOX (hint_vbox));
editor->hint_label4 = gradient_hint_label_add (GTK_BOX (hint_vbox)); editor->hint_label4 = gradient_hint_label_add (GTK_BOX (hint_vbox));
/* Initialize other data */
editor->left_saved_segments = NULL;
editor->left_saved_dirty = FALSE;
editor->right_saved_segments = NULL;
editor->right_saved_dirty = FALSE;
/* Black, 50% Gray, White, Clear */ /* Black, 50% Gray, White, Clear */
gimp_rgba_set (&editor->saved_colors[0], 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE); gimp_rgba_set (&editor->saved_colors[0], 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE);
gimp_rgba_set (&editor->saved_colors[1], 0.5, 0.5, 0.5, GIMP_OPACITY_OPAQUE); gimp_rgba_set (&editor->saved_colors[1], 0.5, 0.5, 0.5, GIMP_OPACITY_OPAQUE);
@ -600,8 +579,8 @@ gimp_gradient_editor_edit_left_color (GimpGradientEditor *editor)
editor->control_sel_l->left_color_type != GIMP_GRADIENT_COLOR_FIXED) editor->control_sel_l->left_color_type != GIMP_GRADIENT_COLOR_FIXED)
return; return;
editor->left_saved_dirty = gimp_data_is_dirty (GIMP_DATA (gradient)); editor->saved_dirty = gimp_data_is_dirty (GIMP_DATA (gradient));
editor->left_saved_segments = gradient_editor_save_selection (editor); editor->saved_segments = gradient_editor_save_selection (editor);
editor->color_dialog = editor->color_dialog =
gimp_color_dialog_new (GIMP_VIEWABLE (gradient), gimp_color_dialog_new (GIMP_VIEWABLE (gradient),
@ -644,8 +623,8 @@ gimp_gradient_editor_edit_right_color (GimpGradientEditor *editor)
editor->control_sel_r->right_color_type != GIMP_GRADIENT_COLOR_FIXED) editor->control_sel_r->right_color_type != GIMP_GRADIENT_COLOR_FIXED)
return; return;
editor->right_saved_dirty = gimp_data_is_dirty (GIMP_DATA (gradient)); editor->saved_dirty = gimp_data_is_dirty (GIMP_DATA (gradient));
editor->right_saved_segments = gradient_editor_save_selection (editor); editor->saved_segments = gradient_editor_save_selection (editor);
editor->color_dialog = editor->color_dialog =
gimp_color_dialog_new (GIMP_VIEWABLE (gradient), gimp_color_dialog_new (GIMP_VIEWABLE (gradient),
@ -1022,7 +1001,7 @@ gradient_editor_left_color_update (GimpColorDialog *dialog,
color, color,
&editor->control_sel_r->right_color, &editor->control_sel_r->right_color,
TRUE, TRUE); TRUE, TRUE);
gimp_gradient_segments_free (editor->left_saved_segments); gimp_gradient_segments_free (editor->saved_segments);
gtk_widget_destroy (editor->color_dialog); gtk_widget_destroy (editor->color_dialog);
editor->color_dialog = NULL; editor->color_dialog = NULL;
gtk_widget_set_sensitive (GTK_WIDGET (editor), TRUE); gtk_widget_set_sensitive (GTK_WIDGET (editor), TRUE);
@ -1031,8 +1010,8 @@ gradient_editor_left_color_update (GimpColorDialog *dialog,
break; break;
case GIMP_COLOR_DIALOG_CANCEL: case GIMP_COLOR_DIALOG_CANCEL:
gradient_editor_replace_selection (editor, editor->left_saved_segments); gradient_editor_replace_selection (editor, editor->saved_segments);
if (! editor->left_saved_dirty) if (! editor->saved_dirty)
gimp_data_clean (GIMP_DATA (gradient)); gimp_data_clean (GIMP_DATA (gradient));
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (gradient)); gimp_viewable_invalidate_preview (GIMP_VIEWABLE (gradient));
gtk_widget_destroy (editor->color_dialog); gtk_widget_destroy (editor->color_dialog);
@ -1070,7 +1049,7 @@ gradient_editor_right_color_update (GimpColorDialog *dialog,
&editor->control_sel_l->left_color, &editor->control_sel_l->left_color,
color, color,
TRUE, TRUE); TRUE, TRUE);
gimp_gradient_segments_free (editor->right_saved_segments); gimp_gradient_segments_free (editor->saved_segments);
gtk_widget_destroy (editor->color_dialog); gtk_widget_destroy (editor->color_dialog);
editor->color_dialog = NULL; editor->color_dialog = NULL;
gtk_widget_set_sensitive (GTK_WIDGET (editor), TRUE); gtk_widget_set_sensitive (GTK_WIDGET (editor), TRUE);
@ -1079,8 +1058,8 @@ gradient_editor_right_color_update (GimpColorDialog *dialog,
break; break;
case GIMP_COLOR_DIALOG_CANCEL: case GIMP_COLOR_DIALOG_CANCEL:
gradient_editor_replace_selection (editor, editor->right_saved_segments); gradient_editor_replace_selection (editor, editor->saved_segments);
if (! editor->right_saved_dirty) if (! editor->saved_dirty)
gimp_data_clean (GIMP_DATA (gradient)); gimp_data_clean (GIMP_DATA (gradient));
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (gradient)); gimp_viewable_invalidate_preview (GIMP_VIEWABLE (gradient));
gtk_widget_destroy (editor->color_dialog); gtk_widget_destroy (editor->color_dialog);

View File

@ -63,9 +63,6 @@ struct _GimpGradientEditor
guint zoom_factor; guint zoom_factor;
GtkAdjustment *scroll_data; GtkAdjustment *scroll_data;
/* Color dialog */
GtkWidget *color_dialog;
/* Gradient view */ /* Gradient view */
gint view_last_x; gint view_last_x;
gboolean view_button_down; gboolean view_button_down;
@ -83,21 +80,13 @@ struct _GimpGradientEditor
GimpGradientBlendColorSpace blend_color_space; GimpGradientBlendColorSpace blend_color_space;
/* Split uniformly dialog */
gint split_parts;
/* Replicate dialog */
gint replicate_times;
/* Saved colors */ /* Saved colors */
GimpRGB saved_colors[GRAD_NUM_COLORS]; GimpRGB saved_colors[GRAD_NUM_COLORS];
/* Color dialogs */ /* Color dialog */
GimpGradientSegment *left_saved_segments; GtkWidget *color_dialog;
gboolean left_saved_dirty; GimpGradientSegment *saved_segments;
gboolean saved_dirty;
GimpGradientSegment *right_saved_segments;
gboolean right_saved_dirty;
}; };
struct _GimpGradientEditorClass struct _GimpGradientEditorClass