/* 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 Spencer Kimball and Peter Mattis
 *
 * 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 <string.h>

#include <gegl.h>
#include <gtk/gtk.h>

#include "libpikabase/pikabase.h"
#include "libpikacolor/pikacolor.h"

#include "widgets-types.h"

#include "core/pika.h"

#include "pikarender.h"


static void   pika_render_setup_notify (gpointer    config,
                                        GParamSpec *param_spec,
                                        Pika       *pika);


static PikaRGB color1;
static PikaRGB color2;


void
pika_render_init (Pika *pika)
{
  g_return_if_fail (PIKA_IS_PIKA (pika));

  g_signal_connect (pika->config, "notify::transparency-type",
                    G_CALLBACK (pika_render_setup_notify),
                    pika);

  g_signal_connect (pika->config, "notify::transparency-custom-color1",
                    G_CALLBACK (pika_render_setup_notify),
                    pika);

  g_signal_connect (pika->config, "notify::transparency-custom-color2",
                    G_CALLBACK (pika_render_setup_notify),
                    pika);

  pika_render_setup_notify (pika->config, NULL, pika);
}

void
pika_render_exit (Pika *pika)
{
  g_return_if_fail (PIKA_IS_PIKA (pika));

  g_signal_handlers_disconnect_by_func (pika->config,
                                        pika_render_setup_notify,
                                        pika);
}

const PikaRGB *
pika_render_check_color1 (void)
{
  return &color1;
}

const PikaRGB *
pika_render_check_color2 (void)
{
  return &color2;
}

static void
pika_render_setup_notify (gpointer    config,
                          GParamSpec *param_spec,
                          Pika       *pika)
{
  PikaRGB       *color1_custom;
  PikaRGB       *color2_custom;
  PikaCheckType  check_type;

  g_object_get (config,
                "transparency-type",          &check_type,
                "transparency-custom-color1", &color1_custom,
                "transparency-custom-color2", &color2_custom,
                NULL);

  color1 = *color1_custom;
  color2 = *color2_custom;
  pika_checks_get_colors (check_type, &color1, &color2);
  g_free (color1_custom);
  g_free (color2_custom);
}
