2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2002-06-12 21:48:47 +08:00
|
|
|
* Copyright (C) 1995-2002 Spencer Kimball, Peter Mattis, and others
|
|
|
|
*
|
|
|
|
* gimp-gradients.c
|
|
|
|
* Copyright (C) 2002 Michael Natterer <mitch@gimp.org>
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2002-06-12 21:48:47 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2002-06-12 21:48:47 +08:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2002-06-12 21:48:47 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2013-10-15 07:58:39 +08:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2012-03-30 01:19:01 +08:00
|
|
|
#include <gegl.h>
|
2002-06-12 21:48:47 +08:00
|
|
|
|
|
|
|
#include "core-types.h"
|
|
|
|
|
|
|
|
#include "gimp.h"
|
2006-10-30 18:13:06 +08:00
|
|
|
#include "gimp-gradients.h"
|
2006-09-03 20:39:24 +08:00
|
|
|
#include "gimpcontext.h"
|
2002-06-12 21:48:47 +08:00
|
|
|
#include "gimpcontainer.h"
|
|
|
|
#include "gimpdatafactory.h"
|
|
|
|
#include "gimpgradient.h"
|
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2002-06-12 21:48:47 +08:00
|
|
|
|
|
|
|
|
2017-07-27 02:45:24 +08:00
|
|
|
#define CUSTOM_KEY "gimp-gradient-custom"
|
2005-06-15 04:40:05 +08:00
|
|
|
#define FG_BG_RGB_KEY "gimp-gradient-fg-bg-rgb"
|
2014-04-30 08:02:24 +08:00
|
|
|
#define FG_BG_HARDEDGE_KEY "gimp-gradient-fg-bg-rgb-hardedge"
|
2005-06-15 04:40:05 +08:00
|
|
|
#define FG_BG_HSV_CCW_KEY "gimp-gradient-fg-bg-hsv-ccw"
|
|
|
|
#define FG_BG_HSV_CW_KEY "gimp-gradient-fg-bg-hsv-cw"
|
|
|
|
#define FG_TRANSPARENT_KEY "gimp-gradient-fg-transparent"
|
2002-06-12 21:48:47 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* local function prototypes */
|
|
|
|
|
2006-09-01 02:47:13 +08:00
|
|
|
static GimpGradient * gimp_gradients_add_gradient (Gimp *gimp,
|
|
|
|
const gchar *name,
|
|
|
|
const gchar *id);
|
2002-06-12 21:48:47 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_gradients_init (Gimp *gimp)
|
|
|
|
{
|
|
|
|
GimpGradient *gradient;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_GIMP (gimp));
|
|
|
|
|
2017-07-27 02:45:24 +08:00
|
|
|
/* Custom */
|
|
|
|
gradient = gimp_gradients_add_gradient (gimp,
|
|
|
|
_("Custom"),
|
|
|
|
CUSTOM_KEY);
|
|
|
|
g_object_set (gradient,
|
|
|
|
"writable", TRUE,
|
|
|
|
NULL);
|
|
|
|
gradient->segments->left_color_type = GIMP_GRADIENT_COLOR_FOREGROUND;
|
|
|
|
gradient->segments->right_color_type = GIMP_GRADIENT_COLOR_BACKGROUND;
|
|
|
|
|
2009-08-15 17:48:36 +08:00
|
|
|
/* FG to BG (RGB) */
|
2002-06-12 21:48:47 +08:00
|
|
|
gradient = gimp_gradients_add_gradient (gimp,
|
|
|
|
_("FG to BG (RGB)"),
|
|
|
|
FG_BG_RGB_KEY);
|
2009-08-15 17:48:36 +08:00
|
|
|
gradient->segments->left_color_type = GIMP_GRADIENT_COLOR_FOREGROUND;
|
|
|
|
gradient->segments->right_color_type = GIMP_GRADIENT_COLOR_BACKGROUND;
|
2002-06-12 21:48:47 +08:00
|
|
|
gimp_context_set_gradient (gimp->user_context, gradient);
|
|
|
|
|
2009-08-15 17:58:08 +08:00
|
|
|
/* FG to BG (Hardedge) */
|
|
|
|
gradient = gimp_gradients_add_gradient (gimp,
|
|
|
|
_("FG to BG (Hardedge)"),
|
|
|
|
FG_BG_HARDEDGE_KEY);
|
2018-10-03 09:23:34 +08:00
|
|
|
gradient->segments->left_color_type = GIMP_GRADIENT_COLOR_FOREGROUND;
|
|
|
|
gradient->segments->right_color_type = GIMP_GRADIENT_COLOR_BACKGROUND;
|
|
|
|
gradient->segments->type = GIMP_GRADIENT_SEGMENT_STEP;
|
2009-08-15 17:58:08 +08:00
|
|
|
|
2009-08-15 17:48:36 +08:00
|
|
|
/* FG to BG (HSV counter-clockwise) */
|
2002-06-12 21:48:47 +08:00
|
|
|
gradient = gimp_gradients_add_gradient (gimp,
|
|
|
|
_("FG to BG (HSV counter-clockwise)"),
|
|
|
|
FG_BG_HSV_CCW_KEY);
|
2009-08-15 17:48:36 +08:00
|
|
|
gradient->segments->left_color_type = GIMP_GRADIENT_COLOR_FOREGROUND;
|
|
|
|
gradient->segments->right_color_type = GIMP_GRADIENT_COLOR_BACKGROUND;
|
|
|
|
gradient->segments->color = GIMP_GRADIENT_SEGMENT_HSV_CCW;
|
2002-06-12 21:48:47 +08:00
|
|
|
|
2009-08-15 17:48:36 +08:00
|
|
|
/* FG to BG (HSV clockwise hue) */
|
2002-06-12 21:48:47 +08:00
|
|
|
gradient = gimp_gradients_add_gradient (gimp,
|
|
|
|
_("FG to BG (HSV clockwise hue)"),
|
|
|
|
FG_BG_HSV_CW_KEY);
|
2009-08-15 17:48:36 +08:00
|
|
|
gradient->segments->left_color_type = GIMP_GRADIENT_COLOR_FOREGROUND;
|
|
|
|
gradient->segments->right_color_type = GIMP_GRADIENT_COLOR_BACKGROUND;
|
|
|
|
gradient->segments->color = GIMP_GRADIENT_SEGMENT_HSV_CW;
|
2002-06-12 21:48:47 +08:00
|
|
|
|
2009-08-15 17:48:36 +08:00
|
|
|
/* FG to Transparent */
|
2002-06-12 21:48:47 +08:00
|
|
|
gradient = gimp_gradients_add_gradient (gimp,
|
|
|
|
_("FG to Transparent"),
|
|
|
|
FG_TRANSPARENT_KEY);
|
2009-08-15 17:48:36 +08:00
|
|
|
gradient->segments->left_color_type = GIMP_GRADIENT_COLOR_FOREGROUND;
|
2006-08-30 05:44:51 +08:00
|
|
|
gradient->segments->right_color_type = GIMP_GRADIENT_COLOR_FOREGROUND_TRANSPARENT;
|
2002-06-12 21:48:47 +08:00
|
|
|
}
|
|
|
|
|
2017-07-27 02:45:24 +08:00
|
|
|
GimpGradient *
|
|
|
|
gimp_gradients_get_custom (Gimp *gimp)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
|
|
|
|
return g_object_get_data (G_OBJECT (gimp), CUSTOM_KEY);
|
|
|
|
}
|
|
|
|
|
2014-04-30 15:15:42 +08:00
|
|
|
GimpGradient *
|
|
|
|
gimp_gradients_get_fg_bg_rgb (Gimp *gimp)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
|
|
|
|
return g_object_get_data (G_OBJECT (gimp), FG_BG_RGB_KEY);
|
|
|
|
}
|
|
|
|
|
|
|
|
GimpGradient *
|
|
|
|
gimp_gradients_get_fg_bg_hsv_ccw (Gimp *gimp)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
|
|
|
|
return g_object_get_data (G_OBJECT (gimp), FG_BG_HSV_CCW_KEY);
|
|
|
|
}
|
|
|
|
|
|
|
|
GimpGradient *
|
|
|
|
gimp_gradients_get_fg_bg_hsv_cw (Gimp *gimp)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
|
|
|
|
return g_object_get_data (G_OBJECT (gimp), FG_BG_HSV_CW_KEY);
|
|
|
|
}
|
|
|
|
|
|
|
|
GimpGradient *
|
|
|
|
gimp_gradients_get_fg_transparent (Gimp *gimp)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
|
|
|
|
return g_object_get_data (G_OBJECT (gimp), FG_TRANSPARENT_KEY);
|
|
|
|
}
|
|
|
|
|
2002-06-12 21:48:47 +08:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static GimpGradient *
|
|
|
|
gimp_gradients_add_gradient (Gimp *gimp,
|
|
|
|
const gchar *name,
|
|
|
|
const gchar *id)
|
|
|
|
{
|
2010-04-05 19:24:54 +08:00
|
|
|
GimpGradient *gradient;
|
|
|
|
|
2010-04-11 01:55:42 +08:00
|
|
|
gradient = GIMP_GRADIENT (gimp_gradient_new (gimp_get_user_context (gimp),
|
|
|
|
name));
|
2002-06-12 21:48:47 +08:00
|
|
|
|
2008-12-12 15:03:42 +08:00
|
|
|
gimp_data_make_internal (GIMP_DATA (gradient), id);
|
2002-06-12 21:48:47 +08:00
|
|
|
|
2008-12-20 05:58:17 +08:00
|
|
|
gimp_container_add (gimp_data_factory_get_container (gimp->gradient_factory),
|
2002-06-12 21:48:47 +08:00
|
|
|
GIMP_OBJECT (gradient));
|
2003-01-06 06:07:10 +08:00
|
|
|
g_object_unref (gradient);
|
2002-06-12 21:48:47 +08:00
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (gimp), id, gradient);
|
|
|
|
|
|
|
|
return gradient;
|
|
|
|
}
|