1 /*
2     This file is part of darktable,
3     Copyright (C) 2010-2020 darktable developers.
4 
5     darktable is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9 
10     darktable is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License
16     along with darktable.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #pragma once
20 
21 #define GRADIENT_SLIDER_MAX_POSITIONS 10
22 
23 #include "paint.h"
24 #include <gtk/gtk.h>
25 G_BEGIN_DECLS
26 #define DTGTK_GRADIENT_SLIDER(obj)                                                                           \
27   G_TYPE_CHECK_INSTANCE_CAST(obj, dtgtk_gradient_slider_get_type(), GtkDarktableGradientSlider)
28 #define DTGTK_GRADIENT_SLIDER_CLASS(klass)                                                                   \
29   G_TYPE_CHECK_CLASS_CAST(klass, dtgtk_gradient_slider_get_type(), GtkDarktableGradientSliderClass)
30 #define DTGTK_IS_GRADIENT_SLIDER(obj)                                                                        \
31   G_TYPE_CHECK_INSTANCE_TYPE(obj, dtgtk_gradient_slider_get_type())
32 #define DTGTK_IS_GRADIENT_SLIDER_CLASS(klass)                                                                \
33   G_TYPE_CHECK_CLASS_TYPE(obj, dtgtk_gradient_slider_get_type())
34 
35 #define DTGTK_GRADIENT_SLIDER_MULTIVALUE(obj)                                                                \
36   G_TYPE_CHECK_INSTANCE_CAST(obj, dtgtk_gradient_slider_multivalue_get_type(), GtkDarktableGradientSlider)
37 #define DTGTK_GRADIENT_SLIDER_MULTIVALUE_CLASS(klass)                                                        \
38   G_TYPE_CHECK_CLASS_CAST(klass, dtgtk_gradient_slider_multivalue_get_type(), GtkDarktableGradientSliderClass)
39 #define DTGTK_IS_GRADIENT_SLIDER_MULTIVALUE(obj)                                                             \
40   G_TYPE_CHECK_INSTANCE_TYPE(obj, dtgtk_gradient_slider_multivalue_get_type())
41 #define DTGTK_IS_GRADIENT_SLIDER_MULTIVALUE_CLASS(klass)                                                     \
42   G_TYPE_CHECK_CLASS_TYPE(obj, dtgtk_gradient_slider_multivalue_get_type())
43 
44 enum
45 {
46   GRADIENT_SLIDER_VALUE_CHANGED,
47   GRADIENT_SLIDER_LAST_SIGNAL
48 };
49 
50 enum _gradient_slider_direction
51 {
52   MOVE_LEFT = 0,
53   MOVE_RIGHT = 1
54 };
55 
56 
57 /** bitfields for marker: bit-0 open/filled, bit-1 lower off/on, bit-2 upper off/on, bit-3 size small/big */
58 enum
59 {
60   GRADIENT_SLIDER_MARKER_DOUBLE_OPEN = 0x06,
61   GRADIENT_SLIDER_MARKER_DOUBLE_FILLED = 0x07,
62   GRADIENT_SLIDER_MARKER_UPPER_OPEN = 0x04,
63   GRADIENT_SLIDER_MARKER_UPPER_FILLED = 0x05,
64   GRADIENT_SLIDER_MARKER_LOWER_OPEN = 0x02,
65   GRADIENT_SLIDER_MARKER_LOWER_FILLED = 0x03,
66 
67   GRADIENT_SLIDER_MARKER_DOUBLE_OPEN_BIG = 0x0e,
68   GRADIENT_SLIDER_MARKER_DOUBLE_FILLED_BIG = 0x0f,
69   GRADIENT_SLIDER_MARKER_UPPER_OPEN_BIG = 0x0c,
70   GRADIENT_SLIDER_MARKER_UPPER_FILLED_BIG = 0x0d,
71   GRADIENT_SLIDER_MARKER_LOWER_OPEN_BIG = 0x0a,
72   GRADIENT_SLIDER_MARKER_LOWER_FILLED_BIG = 0x0b
73 };
74 
75 enum
76 {
77   GRADIENT_SLIDER_MARGINS_DEFAULT = 6,
78   GRADIENT_SLIDER_MARGINS_ZERO = 0,
79   GRADIENT_SLIDER_MARGINS_SMALL = 2,
80   GRADIENT_SLIDER_MARGINS_BIG = 6
81 };
82 
83 enum
84 {
85   GRADIENT_SLIDER_SET = 1,
86   GRADIENT_SLIDER_GET = 2
87 };
88 
89 enum
90 {
91   FREE_MARKERS = 1,
92   PROPORTIONAL_MARKERS = 2
93 };
94 
95 typedef struct _GtkDarktableGradientSlider
96 {
97   GtkDrawingArea widget;
98   GList *colors;
99   gint selected;
100   gint active;
101   gint positions;
102   gdouble position[GRADIENT_SLIDER_MAX_POSITIONS];
103   gdouble resetvalue[GRADIENT_SLIDER_MAX_POSITIONS];
104   gint marker[GRADIENT_SLIDER_MAX_POSITIONS];
105   gdouble increment;
106   gdouble min_spacing;
107   gdouble picker[3];
108   gint margin_left;
109   gint margin_right;
110   gboolean is_dragging;
111   gboolean is_changed;
112   gboolean is_resettable;
113   gboolean do_reset;
114   gboolean is_entered;
115   gint markers_type;
116   guint timeout_handle;
117   float (*scale_callback)(GtkWidget*, float, int); // scale callback function
118 } GtkDarktableGradientSlider;
119 
120 typedef struct _GtkDarktableGradientSliderClass
121 {
122   GtkDrawingAreaClass parent_class;
123 } GtkDarktableGradientSliderClass;
124 
125 typedef struct _gradient_slider_stop_t
126 {
127   gdouble position;
128   GdkRGBA color;
129 } _gradient_slider_stop_t;
130 
131 
132 GType dtgtk_gradient_slider_get_type(void);
133 GType dtgtk_gradient_slider_multivalue_get_type(void);
134 
135 /** instantiate a new darktable gradient slider control */
136 GtkWidget *dtgtk_gradient_slider_new();
137 GtkWidget *dtgtk_gradient_slider_new_with_name(gchar *name);
138 GtkWidget *dtgtk_gradient_slider_new_with_color(GdkRGBA start, GdkRGBA end);
139 GtkWidget *dtgtk_gradient_slider_new_with_color_and_name(GdkRGBA start, GdkRGBA end, gchar *name);
140 
141 /** Set a color at specified stop */
142 void dtgtk_gradient_slider_set_stop(GtkDarktableGradientSlider *gslider, gfloat position, GdkRGBA color);
143 
144 /** Clear all stops */
145 void dtgtk_gradient_slider_multivalue_clear_stops(GtkDarktableGradientSlider *gslider);
146 
147 /** Get the slider value 0 - 1.0*/
148 gdouble dtgtk_gradient_slider_get_value(GtkDarktableGradientSlider *gslider);
149 void dtgtk_gradient_slider_set_value(GtkDarktableGradientSlider *gslider, gdouble value);
150 gboolean dtgtk_gradient_slider_is_dragging(GtkDarktableGradientSlider *gslider);
151 
152 /** Set the slider marker */
153 void dtgtk_gradient_slider_set_marker(GtkDarktableGradientSlider *gslider, gint mark);
154 
155 /** Set the slider reset value */
156 void dtgtk_gradient_slider_set_resetvalue(GtkDarktableGradientSlider *gslider, gdouble value);
157 
158 /** Set a picker */
159 void dtgtk_gradient_slider_set_picker(GtkDarktableGradientSlider *gslider, gdouble value);
160 void dtgtk_gradient_slider_set_picker_meanminmax(GtkDarktableGradientSlider *gslider, gdouble mean, gdouble min, gdouble max);
161 
162 /** set increment for scroll action */
163 void dtgtk_gradient_slider_set_increment(GtkDarktableGradientSlider *gslider, gdouble value);
164 
165 
166 /** instantiate a new darktable gradient slider multivalue control */
167 GtkWidget *dtgtk_gradient_slider_multivalue_new(gint positions);
168 GtkWidget *dtgtk_gradient_slider_multivalue_new_with_name(gint positions, gchar *name);
169 GtkWidget *dtgtk_gradient_slider_multivalue_new_with_color(GdkRGBA start, GdkRGBA end, gint positions);
170 GtkWidget *dtgtk_gradient_slider_multivalue_new_with_color_and_name(GdkRGBA start, GdkRGBA end, gint positions, gchar *name);
171 
172 
173 /** Set a color at specified stop for multivalue control */
174 void dtgtk_gradient_slider_multivalue_set_stop(GtkDarktableGradientSlider *gslider, gfloat position, GdkRGBA color);
175 
176 /** Get the slider value 0 - 1.0 for multivalue control */
177 gdouble dtgtk_gradient_slider_multivalue_get_value(GtkDarktableGradientSlider *gslider, gint position);
178 void dtgtk_gradient_slider_multivalue_get_values(GtkDarktableGradientSlider *gslider, gdouble *values);
179 void dtgtk_gradient_slider_multivalue_set_value(GtkDarktableGradientSlider *gslider, gdouble value, gint position);
180 void dtgtk_gradient_slider_multivalue_set_values(GtkDarktableGradientSlider *gslider, gdouble *values);
181 gboolean dtgtk_gradient_slider_multivalue_is_dragging(GtkDarktableGradientSlider *gslider);
182 
183 /** Set the slider markers for multivalue control */
184 void dtgtk_gradient_slider_multivalue_set_marker(GtkDarktableGradientSlider *gslider, gint mark, gint pos);
185 void dtgtk_gradient_slider_multivalue_set_markers(GtkDarktableGradientSlider *gslider, gint *markers);
186 
187 /** Set/get the slider reset values for multivalue control */
188 void dtgtk_gradient_slider_multivalue_set_resetvalue(GtkDarktableGradientSlider *gslider, gdouble value, gint pos);
189 void dtgtk_gradient_slider_multivalue_set_resetvalues(GtkDarktableGradientSlider *gslider, gdouble *values);
190 gdouble dtgtk_gradient_slider_multivalue_get_resetvalue(GtkDarktableGradientSlider *gslider, gint pos);
191 gdouble dtgtk_gradient_slider_multivalue_get_resetvalues(GtkDarktableGradientSlider *gslider);
192 
193 
194 /** Set a picker for multivalue control */
195 void dtgtk_gradient_slider_multivalue_set_picker(GtkDarktableGradientSlider *gslider, gdouble value);
196 void dtgtk_gradient_slider_multivalue_set_picker_meanminmax(GtkDarktableGradientSlider *gslider, gdouble mean, gdouble min, gdouble max);
197 
198 /** set increment for scroll action */
199 void dtgtk_gradient_slider_multivalue_set_increment(GtkDarktableGradientSlider *gslider, gdouble value);
200 
201 /** set scaling function callback */
202 void dtgtk_gradient_slider_multivalue_set_scale_callback(GtkDarktableGradientSlider *gslider, float (*callback)(GtkWidget *self, float value, int dir));
203 
204 G_END_DECLS
205 
206 // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh
207 // vim: shiftwidth=2 expandtab tabstop=2 cindent
208 // kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
209