1 /* GIMP - The GNU Image Manipulation Program
2  * Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
3  *
4  * gimppropgui-color-balance.c
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #include "config.h"
21 
22 #include <gegl.h>
23 #include <gtk/gtk.h>
24 
25 #include "libgimpwidgets/gimpwidgets.h"
26 
27 #include "propgui-types.h"
28 
29 #include "operations/gimpcolorbalanceconfig.h"
30 
31 #include "core/gimpcontext.h"
32 
33 #include "widgets/gimppropwidgets.h"
34 #include "widgets/gimpspinscale.h"
35 
36 #include "gimppropgui.h"
37 #include "gimppropgui-color-balance.h"
38 
39 #include "gimp-intl.h"
40 
41 
42 static void
create_levels_scale(GObject * config,const gchar * property_name,const gchar * left,const gchar * right,GtkWidget * table,gint col)43 create_levels_scale (GObject     *config,
44                      const gchar *property_name,
45                      const gchar *left,
46                      const gchar *right,
47                      GtkWidget   *table,
48                      gint         col)
49 {
50   GtkWidget *label;
51   GtkWidget *scale;
52 
53   label = gtk_label_new (left);
54   gtk_label_set_xalign (GTK_LABEL (label), 1.0);
55   gtk_table_attach (GTK_TABLE (table), label, 0, 1, col, col + 1,
56                     GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
57   gtk_widget_show (label);
58 
59   scale = gimp_prop_spin_scale_new (config, property_name,
60                                     NULL, 0.01, 0.1, 0);
61   gimp_spin_scale_set_label (GIMP_SPIN_SCALE (scale), NULL);
62   gimp_prop_widget_set_factor (scale, 100.0, 0.0, 0.0, 1);
63   gtk_table_attach_defaults (GTK_TABLE (table), scale, 1, 2, col, col + 1);
64   gtk_widget_show (scale);
65 
66   label = gtk_label_new (right);
67   gtk_label_set_xalign (GTK_LABEL (label), 0.0);
68   gtk_table_attach (GTK_TABLE (table), label, 2, 3, col, col + 1,
69                     GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
70   gtk_widget_show (label);
71 }
72 
73 GtkWidget *
_gimp_prop_gui_new_color_balance(GObject * config,GParamSpec ** param_specs,guint n_param_specs,GeglRectangle * area,GimpContext * context,GimpCreatePickerFunc create_picker_func,GimpCreateControllerFunc create_controller_func,gpointer creator)74 _gimp_prop_gui_new_color_balance (GObject                  *config,
75                                   GParamSpec              **param_specs,
76                                   guint                     n_param_specs,
77                                   GeglRectangle            *area,
78                                   GimpContext              *context,
79                                   GimpCreatePickerFunc      create_picker_func,
80                                   GimpCreateControllerFunc  create_controller_func,
81                                   gpointer                  creator)
82 {
83   GtkWidget *main_vbox;
84   GtkWidget *vbox;
85   GtkWidget *hbox;
86   GtkWidget *table;
87   GtkWidget *button;
88   GtkWidget *frame;
89 
90   g_return_val_if_fail (G_IS_OBJECT (config), NULL);
91   g_return_val_if_fail (param_specs != NULL, NULL);
92   g_return_val_if_fail (n_param_specs > 0, NULL);
93   g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
94 
95   main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 4);
96 
97   frame = gimp_prop_enum_radio_frame_new (config, "range",
98                                           _("Select Range to Adjust"),
99                                           0, 0);
100   gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
101   gtk_widget_show (frame);
102 
103   frame = gimp_frame_new (_("Adjust Color Levels"));
104   gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
105   gtk_widget_show (frame);
106 
107   vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 4);
108   gtk_container_add (GTK_CONTAINER (frame), vbox);
109   gtk_widget_show (vbox);
110 
111   /*  The table containing sliders  */
112   table = gtk_table_new (3, 3, FALSE);
113   gtk_table_set_col_spacings (GTK_TABLE (table), 4);
114   gtk_table_set_row_spacings (GTK_TABLE (table), 2);
115   gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
116   gtk_widget_show (table);
117 
118   create_levels_scale (config, "cyan-red",
119                        _("Cyan"), _("Red"),
120                        table, 0);
121 
122   create_levels_scale (config, "magenta-green",
123                        _("Magenta"), _("Green"),
124                        table, 1);
125 
126   create_levels_scale (config, "yellow-blue",
127                        _("Yellow"), _("Blue"),
128                        table, 2);
129 
130   hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
131   gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
132   gtk_widget_show (hbox);
133 
134   button = gtk_button_new_with_mnemonic (_("R_eset Range"));
135   gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
136   gtk_widget_show (button);
137 
138   g_signal_connect_swapped (button, "clicked",
139                             G_CALLBACK (gimp_color_balance_config_reset_range),
140                             config);
141 
142   button = gimp_prop_check_button_new (config,
143                                        "preserve-luminosity",
144                                        _("Preserve _luminosity"));
145   gtk_box_pack_end (GTK_BOX (main_vbox), button, FALSE, FALSE, 0);
146   gtk_widget_show (button);
147 
148   return main_vbox;
149 }
150