188 lines
6.6 KiB
C
188 lines
6.6 KiB
C
|
/* PIKA - Photo and Image Kooker Application
|
||
|
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
|
||
|
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
|
||
|
*
|
||
|
* Original copyright, applying to most contents (license remains unchanged):
|
||
|
* Copyright (C) 1995-2002 Spencer Kimball, Peter Mattis, and others
|
||
|
*
|
||
|
* pika-gradients.c
|
||
|
* Copyright (C) 2002 Michael Natterer <mitch@gimp.org>
|
||
|
*
|
||
|
* This program is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU General Public License as published by
|
||
|
* the Free Software Foundation; either version 3 of the License, or
|
||
|
* (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
|
||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||
|
*/
|
||
|
|
||
|
#include "config.h"
|
||
|
|
||
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||
|
#include <gegl.h>
|
||
|
|
||
|
#include "core-types.h"
|
||
|
|
||
|
#include "pika.h"
|
||
|
#include "pika-gradients.h"
|
||
|
#include "pikacontext.h"
|
||
|
#include "pikacontainer.h"
|
||
|
#include "pikadatafactory.h"
|
||
|
#include "pikagradient.h"
|
||
|
|
||
|
#include "pika-intl.h"
|
||
|
|
||
|
|
||
|
#define CUSTOM_KEY "pika-gradient-custom"
|
||
|
#define FG_BG_RGB_KEY "pika-gradient-fg-bg-rgb"
|
||
|
#define FG_BG_HARDEDGE_KEY "pika-gradient-fg-bg-rgb-hardedge"
|
||
|
#define FG_BG_HSV_CCW_KEY "pika-gradient-fg-bg-hsv-ccw"
|
||
|
#define FG_BG_HSV_CW_KEY "pika-gradient-fg-bg-hsv-cw"
|
||
|
#define FG_TRANSPARENT_KEY "pika-gradient-fg-transparent"
|
||
|
#define FG_TRANSPARENT_HARDEDGE_KEY "pika-gradient-fg-transparent-hardedge"
|
||
|
|
||
|
|
||
|
/* local function prototypes */
|
||
|
|
||
|
static PikaGradient * pika_gradients_add_gradient (Pika *pika,
|
||
|
const gchar *name,
|
||
|
const gchar *id);
|
||
|
|
||
|
|
||
|
/* public functions */
|
||
|
|
||
|
void
|
||
|
pika_gradients_init (Pika *pika)
|
||
|
{
|
||
|
PikaGradient *gradient;
|
||
|
|
||
|
g_return_if_fail (PIKA_IS_PIKA (pika));
|
||
|
|
||
|
/* Custom */
|
||
|
gradient = pika_gradients_add_gradient (pika,
|
||
|
_("Custom"),
|
||
|
CUSTOM_KEY);
|
||
|
g_object_set (gradient,
|
||
|
"writable", TRUE,
|
||
|
NULL);
|
||
|
gradient->segments->left_color_type = PIKA_GRADIENT_COLOR_FOREGROUND;
|
||
|
gradient->segments->right_color_type = PIKA_GRADIENT_COLOR_BACKGROUND;
|
||
|
|
||
|
/* FG to BG (RGB) */
|
||
|
gradient = pika_gradients_add_gradient (pika,
|
||
|
_("FG to BG (RGB)"),
|
||
|
FG_BG_RGB_KEY);
|
||
|
gradient->segments->left_color_type = PIKA_GRADIENT_COLOR_FOREGROUND;
|
||
|
gradient->segments->right_color_type = PIKA_GRADIENT_COLOR_BACKGROUND;
|
||
|
pika_context_set_gradient (pika->user_context, gradient);
|
||
|
|
||
|
/* FG to BG (Hardedge) */
|
||
|
gradient = pika_gradients_add_gradient (pika,
|
||
|
_("FG to BG (Hardedge)"),
|
||
|
FG_BG_HARDEDGE_KEY);
|
||
|
gradient->segments->left_color_type = PIKA_GRADIENT_COLOR_FOREGROUND;
|
||
|
gradient->segments->right_color_type = PIKA_GRADIENT_COLOR_BACKGROUND;
|
||
|
gradient->segments->type = PIKA_GRADIENT_SEGMENT_STEP;
|
||
|
|
||
|
/* FG to BG (HSV counter-clockwise) */
|
||
|
gradient = pika_gradients_add_gradient (pika,
|
||
|
_("FG to BG (HSV counter-clockwise)"),
|
||
|
FG_BG_HSV_CCW_KEY);
|
||
|
gradient->segments->left_color_type = PIKA_GRADIENT_COLOR_FOREGROUND;
|
||
|
gradient->segments->right_color_type = PIKA_GRADIENT_COLOR_BACKGROUND;
|
||
|
gradient->segments->color = PIKA_GRADIENT_SEGMENT_HSV_CCW;
|
||
|
|
||
|
/* FG to BG (HSV clockwise hue) */
|
||
|
gradient = pika_gradients_add_gradient (pika,
|
||
|
_("FG to BG (HSV clockwise hue)"),
|
||
|
FG_BG_HSV_CW_KEY);
|
||
|
gradient->segments->left_color_type = PIKA_GRADIENT_COLOR_FOREGROUND;
|
||
|
gradient->segments->right_color_type = PIKA_GRADIENT_COLOR_BACKGROUND;
|
||
|
gradient->segments->color = PIKA_GRADIENT_SEGMENT_HSV_CW;
|
||
|
|
||
|
/* FG to Transparent */
|
||
|
gradient = pika_gradients_add_gradient (pika,
|
||
|
_("FG to Transparent"),
|
||
|
FG_TRANSPARENT_KEY);
|
||
|
gradient->segments->left_color_type = PIKA_GRADIENT_COLOR_FOREGROUND;
|
||
|
gradient->segments->right_color_type = PIKA_GRADIENT_COLOR_FOREGROUND_TRANSPARENT;
|
||
|
|
||
|
/* FG to Transparent (Hardedge) */
|
||
|
gradient = pika_gradients_add_gradient (pika,
|
||
|
_("FG to Transparent (Hardedge)"),
|
||
|
FG_TRANSPARENT_HARDEDGE_KEY);
|
||
|
gradient->segments->left_color_type = PIKA_GRADIENT_COLOR_FOREGROUND;
|
||
|
gradient->segments->right_color_type = PIKA_GRADIENT_COLOR_FOREGROUND_TRANSPARENT;
|
||
|
gradient->segments->type = PIKA_GRADIENT_SEGMENT_STEP;
|
||
|
}
|
||
|
|
||
|
PikaGradient *
|
||
|
pika_gradients_get_custom (Pika *pika)
|
||
|
{
|
||
|
g_return_val_if_fail (PIKA_IS_PIKA (pika), NULL);
|
||
|
|
||
|
return g_object_get_data (G_OBJECT (pika), CUSTOM_KEY);
|
||
|
}
|
||
|
|
||
|
PikaGradient *
|
||
|
pika_gradients_get_fg_bg_rgb (Pika *pika)
|
||
|
{
|
||
|
g_return_val_if_fail (PIKA_IS_PIKA (pika), NULL);
|
||
|
|
||
|
return g_object_get_data (G_OBJECT (pika), FG_BG_RGB_KEY);
|
||
|
}
|
||
|
|
||
|
PikaGradient *
|
||
|
pika_gradients_get_fg_bg_hsv_ccw (Pika *pika)
|
||
|
{
|
||
|
g_return_val_if_fail (PIKA_IS_PIKA (pika), NULL);
|
||
|
|
||
|
return g_object_get_data (G_OBJECT (pika), FG_BG_HSV_CCW_KEY);
|
||
|
}
|
||
|
|
||
|
PikaGradient *
|
||
|
pika_gradients_get_fg_bg_hsv_cw (Pika *pika)
|
||
|
{
|
||
|
g_return_val_if_fail (PIKA_IS_PIKA (pika), NULL);
|
||
|
|
||
|
return g_object_get_data (G_OBJECT (pika), FG_BG_HSV_CW_KEY);
|
||
|
}
|
||
|
|
||
|
PikaGradient *
|
||
|
pika_gradients_get_fg_transparent (Pika *pika)
|
||
|
{
|
||
|
g_return_val_if_fail (PIKA_IS_PIKA (pika), NULL);
|
||
|
|
||
|
return g_object_get_data (G_OBJECT (pika), FG_TRANSPARENT_KEY);
|
||
|
}
|
||
|
|
||
|
|
||
|
/* private functions */
|
||
|
|
||
|
static PikaGradient *
|
||
|
pika_gradients_add_gradient (Pika *pika,
|
||
|
const gchar *name,
|
||
|
const gchar *id)
|
||
|
{
|
||
|
PikaGradient *gradient;
|
||
|
|
||
|
gradient = PIKA_GRADIENT (pika_gradient_new (pika_get_user_context (pika),
|
||
|
name));
|
||
|
|
||
|
pika_data_make_internal (PIKA_DATA (gradient), id);
|
||
|
|
||
|
pika_container_add (pika_data_factory_get_container (pika->gradient_factory),
|
||
|
PIKA_OBJECT (gradient));
|
||
|
g_object_unref (gradient);
|
||
|
|
||
|
g_object_set_data (G_OBJECT (pika), id, gradient);
|
||
|
|
||
|
return gradient;
|
||
|
}
|