1 /* GIMP - The GNU Image Manipulation Program
2 * Copyright (C) 1995-2002 Spencer Kimball, Peter Mattis, and others
3 *
4 * gimp-gradients.c
5 * Copyright (C) 2002 Michael Natterer <mitch@gimp.org>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21 #include "config.h"
22
23 #include <gdk-pixbuf/gdk-pixbuf.h>
24 #include <gegl.h>
25
26 #include "core-types.h"
27
28 #include "gimp.h"
29 #include "gimp-gradients.h"
30 #include "gimpcontext.h"
31 #include "gimpcontainer.h"
32 #include "gimpdatafactory.h"
33 #include "gimpgradient.h"
34
35 #include "gimp-intl.h"
36
37
38 #define CUSTOM_KEY "gimp-gradient-custom"
39 #define FG_BG_RGB_KEY "gimp-gradient-fg-bg-rgb"
40 #define FG_BG_HARDEDGE_KEY "gimp-gradient-fg-bg-rgb-hardedge"
41 #define FG_BG_HSV_CCW_KEY "gimp-gradient-fg-bg-hsv-ccw"
42 #define FG_BG_HSV_CW_KEY "gimp-gradient-fg-bg-hsv-cw"
43 #define FG_TRANSPARENT_KEY "gimp-gradient-fg-transparent"
44
45
46 /* local function prototypes */
47
48 static GimpGradient * gimp_gradients_add_gradient (Gimp *gimp,
49 const gchar *name,
50 const gchar *id);
51
52
53 /* public functions */
54
55 void
gimp_gradients_init(Gimp * gimp)56 gimp_gradients_init (Gimp *gimp)
57 {
58 GimpGradient *gradient;
59
60 g_return_if_fail (GIMP_IS_GIMP (gimp));
61
62 /* Custom */
63 gradient = gimp_gradients_add_gradient (gimp,
64 _("Custom"),
65 CUSTOM_KEY);
66 g_object_set (gradient,
67 "writable", TRUE,
68 NULL);
69 gradient->segments->left_color_type = GIMP_GRADIENT_COLOR_FOREGROUND;
70 gradient->segments->right_color_type = GIMP_GRADIENT_COLOR_BACKGROUND;
71
72 /* FG to BG (RGB) */
73 gradient = gimp_gradients_add_gradient (gimp,
74 _("FG to BG (RGB)"),
75 FG_BG_RGB_KEY);
76 gradient->segments->left_color_type = GIMP_GRADIENT_COLOR_FOREGROUND;
77 gradient->segments->right_color_type = GIMP_GRADIENT_COLOR_BACKGROUND;
78 gimp_context_set_gradient (gimp->user_context, gradient);
79
80 /* FG to BG (Hardedge) */
81 gradient = gimp_gradients_add_gradient (gimp,
82 _("FG to BG (Hardedge)"),
83 FG_BG_HARDEDGE_KEY);
84 gradient->segments->left_color_type = GIMP_GRADIENT_COLOR_FOREGROUND;
85 gradient->segments->right_color_type = GIMP_GRADIENT_COLOR_BACKGROUND;
86 gradient->segments->type = GIMP_GRADIENT_SEGMENT_STEP;
87
88 /* FG to BG (HSV counter-clockwise) */
89 gradient = gimp_gradients_add_gradient (gimp,
90 _("FG to BG (HSV counter-clockwise)"),
91 FG_BG_HSV_CCW_KEY);
92 gradient->segments->left_color_type = GIMP_GRADIENT_COLOR_FOREGROUND;
93 gradient->segments->right_color_type = GIMP_GRADIENT_COLOR_BACKGROUND;
94 gradient->segments->color = GIMP_GRADIENT_SEGMENT_HSV_CCW;
95
96 /* FG to BG (HSV clockwise hue) */
97 gradient = gimp_gradients_add_gradient (gimp,
98 _("FG to BG (HSV clockwise hue)"),
99 FG_BG_HSV_CW_KEY);
100 gradient->segments->left_color_type = GIMP_GRADIENT_COLOR_FOREGROUND;
101 gradient->segments->right_color_type = GIMP_GRADIENT_COLOR_BACKGROUND;
102 gradient->segments->color = GIMP_GRADIENT_SEGMENT_HSV_CW;
103
104 /* FG to Transparent */
105 gradient = gimp_gradients_add_gradient (gimp,
106 _("FG to Transparent"),
107 FG_TRANSPARENT_KEY);
108 gradient->segments->left_color_type = GIMP_GRADIENT_COLOR_FOREGROUND;
109 gradient->segments->right_color_type = GIMP_GRADIENT_COLOR_FOREGROUND_TRANSPARENT;
110 }
111
112 GimpGradient *
gimp_gradients_get_custom(Gimp * gimp)113 gimp_gradients_get_custom (Gimp *gimp)
114 {
115 g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
116
117 return g_object_get_data (G_OBJECT (gimp), CUSTOM_KEY);
118 }
119
120 GimpGradient *
gimp_gradients_get_fg_bg_rgb(Gimp * gimp)121 gimp_gradients_get_fg_bg_rgb (Gimp *gimp)
122 {
123 g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
124
125 return g_object_get_data (G_OBJECT (gimp), FG_BG_RGB_KEY);
126 }
127
128 GimpGradient *
gimp_gradients_get_fg_bg_hsv_ccw(Gimp * gimp)129 gimp_gradients_get_fg_bg_hsv_ccw (Gimp *gimp)
130 {
131 g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
132
133 return g_object_get_data (G_OBJECT (gimp), FG_BG_HSV_CCW_KEY);
134 }
135
136 GimpGradient *
gimp_gradients_get_fg_bg_hsv_cw(Gimp * gimp)137 gimp_gradients_get_fg_bg_hsv_cw (Gimp *gimp)
138 {
139 g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
140
141 return g_object_get_data (G_OBJECT (gimp), FG_BG_HSV_CW_KEY);
142 }
143
144 GimpGradient *
gimp_gradients_get_fg_transparent(Gimp * gimp)145 gimp_gradients_get_fg_transparent (Gimp *gimp)
146 {
147 g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
148
149 return g_object_get_data (G_OBJECT (gimp), FG_TRANSPARENT_KEY);
150 }
151
152
153 /* private functions */
154
155 static GimpGradient *
gimp_gradients_add_gradient(Gimp * gimp,const gchar * name,const gchar * id)156 gimp_gradients_add_gradient (Gimp *gimp,
157 const gchar *name,
158 const gchar *id)
159 {
160 GimpGradient *gradient;
161
162 gradient = GIMP_GRADIENT (gimp_gradient_new (gimp_get_user_context (gimp),
163 name));
164
165 gimp_data_make_internal (GIMP_DATA (gradient), id);
166
167 gimp_container_add (gimp_data_factory_get_container (gimp->gradient_factory),
168 GIMP_OBJECT (gradient));
169 g_object_unref (gradient);
170
171 g_object_set_data (G_OBJECT (gimp), id, gradient);
172
173 return gradient;
174 }
175