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.
This commit is contained in:
Michael Natterer 2018-06-24 16:24:16 +02:00
parent 025a13b519
commit b8e75a0201
3 changed files with 73 additions and 94 deletions

View File

@ -20,6 +20,7 @@
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpmath/gimpmath.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "actions-types.h"
@ -364,6 +365,7 @@ gradient_editor_replicate_cmd_callback (GtkAction *action,
{
GimpGradientEditor *editor = GIMP_GRADIENT_EDITOR (data);
GimpDataEditor *data_editor = GIMP_DATA_EDITOR (data);
GimpGradient *gradient;
GimpGradientSegment *left;
GimpGradientSegment *right;
GtkWidget *dialog;
@ -374,7 +376,7 @@ gradient_editor_replicate_cmd_callback (GtkAction *action,
const gchar *title;
const gchar *desc;
gimp_gradient_editor_get_selection (editor, NULL, &left, &right);
gimp_gradient_editor_get_selection (editor, &gradient, &left, &right);
if (left == right)
{
@ -387,19 +389,19 @@ gradient_editor_replicate_cmd_callback (GtkAction *action,
desc = _("Replicate Gradient Selection");
}
dialog =
gimp_viewable_dialog_new (GIMP_VIEWABLE (data_editor->data),
data_editor->context,
title, "gimp-gradient-segment-replicate",
GIMP_ICON_GRADIENT, desc,
GTK_WIDGET (editor),
gimp_standard_help_func,
GIMP_HELP_GRADIENT_EDITOR_REPLICATE,
dialog = gimp_viewable_dialog_new (GIMP_VIEWABLE (gradient),
data_editor->context,
title,
"gimp-gradient-segment-replicate",
GIMP_ICON_GRADIENT, desc,
GTK_WIDGET (editor),
gimp_standard_help_func,
GIMP_HELP_GRADIENT_EDITOR_REPLICATE,
_("_Cancel"), GTK_RESPONSE_CANCEL,
_("_Replicate"), GTK_RESPONSE_OK,
_("_Cancel"), GTK_RESPONSE_CANCEL,
_("_Replicate"), GTK_RESPONSE_OK,
NULL);
NULL);
gimp_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
GTK_RESPONSE_OK,
@ -428,8 +430,7 @@ gradient_editor_replicate_cmd_callback (GtkAction *action,
gtk_widget_show (label);
/* 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);
gtk_scale_set_digits (GTK_SCALE (scale), 0);
@ -437,9 +438,7 @@ gradient_editor_replicate_cmd_callback (GtkAction *action,
gtk_box_pack_start (GTK_BOX (vbox), scale, FALSE, TRUE, 4);
gtk_widget_show (scale);
g_signal_connect (scale_data, "value-changed",
G_CALLBACK (gimp_int_adjustment_update),
&editor->replicate_times);
g_object_set_data (G_OBJECT (dialog), "adjustment", scale_data);
gtk_widget_set_sensitive (GTK_WIDGET (editor), FALSE);
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);
GimpDataEditor *data_editor = GIMP_DATA_EDITOR (data);
GimpGradient *gradient;
GimpGradientSegment *left;
GimpGradientSegment *right;
GtkWidget *dialog;
@ -485,7 +485,7 @@ gradient_editor_split_uniformly_cmd_callback (GtkAction *action,
const gchar *title;
const gchar *desc;
gimp_gradient_editor_get_selection (editor, NULL, &left, &right);
gimp_gradient_editor_get_selection (editor, &gradient, &left, &right);
if (left == right)
{
@ -498,19 +498,19 @@ gradient_editor_split_uniformly_cmd_callback (GtkAction *action,
desc = _("Split Gradient Segments Uniformly");
}
dialog =
gimp_viewable_dialog_new (GIMP_VIEWABLE (data_editor->data),
data_editor->context,
title, "gimp-gradient-segment-split-uniformly",
GIMP_ICON_GRADIENT, desc,
GTK_WIDGET (editor),
gimp_standard_help_func,
GIMP_HELP_GRADIENT_EDITOR_SPLIT_UNIFORM,
dialog = gimp_viewable_dialog_new (GIMP_VIEWABLE (gradient),
data_editor->context,
title,
"gimp-gradient-segment-split-uniformly",
GIMP_ICON_GRADIENT, desc,
GTK_WIDGET (editor),
gimp_standard_help_func,
GIMP_HELP_GRADIENT_EDITOR_SPLIT_UNIFORM,
_("_Cancel"), GTK_RESPONSE_CANCEL,
_("_Split"), GTK_RESPONSE_OK,
_("_Cancel"), GTK_RESPONSE_CANCEL,
_("_Split"), GTK_RESPONSE_OK,
NULL);
NULL);
gimp_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
GTK_RESPONSE_OK,
@ -540,7 +540,6 @@ gradient_editor_split_uniformly_cmd_callback (GtkAction *action,
gtk_widget_show (label);
/* 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 = 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_widget_show (scale);
g_signal_connect (scale_data, "value-changed",
G_CALLBACK (gimp_int_adjustment_update),
&editor->split_parts);
g_object_set_data (G_OBJECT (dialog), "adjustment", scale_data);
gtk_widget_set_sensitive (GTK_WIDGET (editor), FALSE);
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,
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_set_sensitive (GTK_WIDGET (editor), TRUE);
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,
data_editor->context,
left, right,
editor->split_parts,
split_parts,
editor->blend_color_space,
&left, &right);
@ -688,6 +692,13 @@ gradient_editor_replicate_response (GtkWidget *widget,
gint response_id,
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_set_sensitive (GTK_WIDGET (editor), TRUE);
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,
left, right,
editor->replicate_times,
replicate_times,
&left, &right);
gimp_gradient_editor_set_selection (editor, left, right);

View File

@ -318,10 +318,6 @@ gimp_gradient_editor_init (GimpGradientEditor *editor)
gtk_container_add (GTK_CONTAINER (frame), 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,
GIMP_TYPE_VIEW,
GIMP_TYPE_GRADIENT,
@ -348,16 +344,6 @@ gimp_gradient_editor_init (GimpGradientEditor *editor)
editor);
/* 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 ();
gtk_widget_set_size_request (editor->control, -1, GRAD_CONTROL_HEIGHT);
gtk_widget_set_events (editor->control, GRAD_CONTROL_EVENT_MASK);
@ -426,13 +412,6 @@ gimp_gradient_editor_init (GimpGradientEditor *editor)
editor->hint_label3 = 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 */
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);
@ -596,8 +575,8 @@ gimp_gradient_editor_edit_left_color (GimpGradientEditor *editor)
editor->control_sel_l->left_color_type != GIMP_GRADIENT_COLOR_FIXED)
return;
editor->left_saved_dirty = gimp_data_is_dirty (GIMP_DATA (gradient));
editor->left_saved_segments = gradient_editor_save_selection (editor);
editor->saved_dirty = gimp_data_is_dirty (GIMP_DATA (gradient));
editor->saved_segments = gradient_editor_save_selection (editor);
editor->color_dialog =
gimp_color_dialog_new (GIMP_VIEWABLE (gradient),
@ -640,8 +619,8 @@ gimp_gradient_editor_edit_right_color (GimpGradientEditor *editor)
editor->control_sel_r->right_color_type != GIMP_GRADIENT_COLOR_FIXED)
return;
editor->right_saved_dirty = gimp_data_is_dirty (GIMP_DATA (gradient));
editor->right_saved_segments = gradient_editor_save_selection (editor);
editor->saved_dirty = gimp_data_is_dirty (GIMP_DATA (gradient));
editor->saved_segments = gradient_editor_save_selection (editor);
editor->color_dialog =
gimp_color_dialog_new (GIMP_VIEWABLE (gradient),
@ -1038,7 +1017,7 @@ gradient_editor_left_color_update (GimpColorDialog *dialog,
color,
&editor->control_sel_r->right_color,
TRUE, TRUE);
gimp_gradient_segments_free (editor->left_saved_segments);
gimp_gradient_segments_free (editor->saved_segments);
gtk_widget_destroy (editor->color_dialog);
editor->color_dialog = NULL;
gtk_widget_set_sensitive (GTK_WIDGET (editor), TRUE);
@ -1047,8 +1026,8 @@ gradient_editor_left_color_update (GimpColorDialog *dialog,
break;
case GIMP_COLOR_DIALOG_CANCEL:
gradient_editor_replace_selection (editor, editor->left_saved_segments);
if (! editor->left_saved_dirty)
gradient_editor_replace_selection (editor, editor->saved_segments);
if (! editor->saved_dirty)
gimp_data_clean (GIMP_DATA (gradient));
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (gradient));
gtk_widget_destroy (editor->color_dialog);
@ -1086,7 +1065,7 @@ gradient_editor_right_color_update (GimpColorDialog *dialog,
&editor->control_sel_l->left_color,
color,
TRUE, TRUE);
gimp_gradient_segments_free (editor->right_saved_segments);
gimp_gradient_segments_free (editor->saved_segments);
gtk_widget_destroy (editor->color_dialog);
editor->color_dialog = NULL;
gtk_widget_set_sensitive (GTK_WIDGET (editor), TRUE);
@ -1095,8 +1074,8 @@ gradient_editor_right_color_update (GimpColorDialog *dialog,
break;
case GIMP_COLOR_DIALOG_CANCEL:
gradient_editor_replace_selection (editor, editor->right_saved_segments);
if (! editor->right_saved_dirty)
gradient_editor_replace_selection (editor, editor->saved_segments);
if (! editor->saved_dirty)
gimp_data_clean (GIMP_DATA (gradient));
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (gradient));
gtk_widget_destroy (editor->color_dialog);

View File

@ -49,26 +49,23 @@ typedef struct _GimpGradientEditorClass GimpGradientEditorClass;
struct _GimpGradientEditor
{
GimpDataEditor parent_instance;
GimpDataEditor parent_instance;
GtkWidget *current_color;
GtkWidget *hint_label1;
GtkWidget *hint_label2;
GtkWidget *hint_label3;
GtkWidget *hint_label4;
GtkWidget *scrollbar;
GtkWidget *control;
GtkWidget *current_color;
GtkWidget *hint_label1;
GtkWidget *hint_label2;
GtkWidget *hint_label3;
GtkWidget *hint_label4;
GtkWidget *scrollbar;
GtkWidget *control;
/* Zoom and scrollbar */
guint zoom_factor;
GtkAdjustment *scroll_data;
/* Color dialog */
GtkWidget *color_dialog;
guint zoom_factor;
GtkAdjustment *scroll_data;
/* Gradient view */
gint view_last_x;
gboolean view_button_down;
gint view_last_x;
gboolean view_button_down;
/* Gradient control */
GimpGradientSegment *control_drag_segment; /* Segment which is being dragged */
@ -83,21 +80,13 @@ struct _GimpGradientEditor
GimpGradientBlendColorSpace blend_color_space;
/* Split uniformly dialog */
gint split_parts;
/* Replicate dialog */
gint replicate_times;
/* Saved colors */
GimpRGB saved_colors[GRAD_NUM_COLORS];
GimpRGB saved_colors[GRAD_NUM_COLORS];
/* Color dialogs */
GimpGradientSegment *left_saved_segments;
gboolean left_saved_dirty;
GimpGradientSegment *right_saved_segments;
gboolean right_saved_dirty;
/* Color dialog */
GtkWidget *color_dialog;
GimpGradientSegment *saved_segments;
gboolean saved_dirty;
};
struct _GimpGradientEditorClass