/* MonochromeEffect.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from MonochromeEffect.vala, do not modify */

/*
 * Copyright 2023 elementary, Inc. <https://elementary.io>
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

#include <clutter/clutter.h>
#include <glib-object.h>
#include <glib.h>
#include <float.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>

#define GALA_MONOCHROME_EFFECT_EFFECT_NAME "monochrome-filter"
#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define GALA_TYPE_MONOCHROME_EFFECT (gala_monochrome_effect_get_type ())
#define GALA_MONOCHROME_EFFECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GALA_TYPE_MONOCHROME_EFFECT, GalaMonochromeEffect))
#define GALA_MONOCHROME_EFFECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GALA_TYPE_MONOCHROME_EFFECT, GalaMonochromeEffectClass))
#define GALA_IS_MONOCHROME_EFFECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GALA_TYPE_MONOCHROME_EFFECT))
#define GALA_IS_MONOCHROME_EFFECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GALA_TYPE_MONOCHROME_EFFECT))
#define GALA_MONOCHROME_EFFECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GALA_TYPE_MONOCHROME_EFFECT, GalaMonochromeEffectClass))

typedef struct _GalaMonochromeEffect GalaMonochromeEffect;
typedef struct _GalaMonochromeEffectClass GalaMonochromeEffectClass;
typedef struct _GalaMonochromeEffectPrivate GalaMonochromeEffectPrivate;
enum  {
	GALA_MONOCHROME_EFFECT_0_PROPERTY,
	GALA_MONOCHROME_EFFECT_STRENGTH_PROPERTY,
	GALA_MONOCHROME_EFFECT_PAUSE_FOR_SCREENSHOT_PROPERTY,
	GALA_MONOCHROME_EFFECT_TRANSITION_ACTOR_PROPERTY,
	GALA_MONOCHROME_EFFECT_NUM_PROPERTIES
};
static GParamSpec* gala_monochrome_effect_properties[GALA_MONOCHROME_EFFECT_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_bytes_unref0(var) ((var == NULL) ? NULL : (var = (g_bytes_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _GalaMonochromeEffect {
	ClutterShaderEffect parent_instance;
	GalaMonochromeEffectPrivate * priv;
};

struct _GalaMonochromeEffectClass {
	ClutterShaderEffectClass parent_class;
};

struct _GalaMonochromeEffectPrivate {
	gdouble _strength;
	ClutterActor* _transition_actor;
};

static gint GalaMonochromeEffect_private_offset;
static gpointer gala_monochrome_effect_parent_class = NULL;

VALA_EXTERN GType gala_monochrome_effect_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GalaMonochromeEffect, g_object_unref)
VALA_EXTERN GalaMonochromeEffect* gala_monochrome_effect_new (gdouble strength);
VALA_EXTERN GalaMonochromeEffect* gala_monochrome_effect_construct (GType object_type,
                                                        gdouble strength);
VALA_EXTERN void gala_monochrome_effect_set_pause_for_screenshot (GalaMonochromeEffect* self,
                                                      gboolean value);
VALA_EXTERN gdouble gala_monochrome_effect_get_strength (GalaMonochromeEffect* self);
VALA_EXTERN void gala_monochrome_effect_set_strength (GalaMonochromeEffect* self,
                                          gdouble value);
VALA_EXTERN ClutterActor* gala_monochrome_effect_get_transition_actor (GalaMonochromeEffect* self);
VALA_EXTERN void gala_monochrome_effect_set_transition_actor (GalaMonochromeEffect* self,
                                                  ClutterActor* value);
static void gala_monochrome_effect_finalize (GObject * obj);
static GType gala_monochrome_effect_get_type_once (void);
static void _vala_gala_monochrome_effect_get_property (GObject * object,
                                                guint property_id,
                                                GValue * value,
                                                GParamSpec * pspec);
static void _vala_gala_monochrome_effect_set_property (GObject * object,
                                                guint property_id,
                                                const GValue * value,
                                                GParamSpec * pspec);

static inline gpointer
gala_monochrome_effect_get_instance_private (GalaMonochromeEffect* self)
{
	return G_STRUCT_MEMBER_P (self, GalaMonochromeEffect_private_offset);
}

GalaMonochromeEffect*
gala_monochrome_effect_construct (GType object_type,
                                  gdouble strength)
{
	GalaMonochromeEffect * self = NULL;
	GError* _inner_error0_ = NULL;
	self = (GalaMonochromeEffect*) g_object_new (object_type, "shader-type", CLUTTER_FRAGMENT_SHADER, "strength", strength, NULL);
	{
		GBytes* bytes = NULL;
		GBytes* _tmp0_;
		gsize _tmp1_ = 0;
		guint8* _tmp2_;
		_tmp0_ = g_resources_lookup_data ("/io/elementary/desktop/gala/shaders/monochrome.frag", G_RESOURCE_LOOKUP_FLAGS_NONE, &_inner_error0_);
		bytes = _tmp0_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp2_ = g_bytes_get_data (bytes, &_tmp1_);
		clutter_shader_effect_set_shader_source ((ClutterShaderEffect*) self, (const gchar*) _tmp2_);
		_g_bytes_unref0 (bytes);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp3_;
		const gchar* _tmp4_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp3_ = e;
		_tmp4_ = _tmp3_->message;
		g_critical ("MonochromeEffect.vala:44: Unable to load monochrome.frag: %s", _tmp4_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return NULL;
	}
	gala_monochrome_effect_set_pause_for_screenshot (self, FALSE);
	return self;
}

GalaMonochromeEffect*
gala_monochrome_effect_new (gdouble strength)
{
	return gala_monochrome_effect_construct (GALA_TYPE_MONOCHROME_EFFECT, strength);
}

gdouble
gala_monochrome_effect_get_strength (GalaMonochromeEffect* self)
{
	gdouble result;
	g_return_val_if_fail (self != NULL, 0.0);
	result = self->priv->_strength;
	return result;
}

void
gala_monochrome_effect_set_strength (GalaMonochromeEffect* self,
                                     gdouble value)
{
	GValue _tmp0_ = {0};
	g_return_if_fail (self != NULL);
	self->priv->_strength = value;
	g_value_init (&_tmp0_, G_TYPE_DOUBLE);
	g_value_set_double (&_tmp0_, value);
	clutter_shader_effect_set_uniform_value ((ClutterShaderEffect*) self, "STRENGTH", &_tmp0_);
	G_IS_VALUE (&_tmp0_) ? (g_value_unset (&_tmp0_), NULL) : NULL;
	clutter_effect_queue_repaint ((ClutterEffect*) self);
	g_object_notify_by_pspec ((GObject *) self, gala_monochrome_effect_properties[GALA_MONOCHROME_EFFECT_STRENGTH_PROPERTY]);
}

void
gala_monochrome_effect_set_pause_for_screenshot (GalaMonochromeEffect* self,
                                                 gboolean value)
{
	GValue _tmp0_ = {0};
	g_return_if_fail (self != NULL);
	g_value_init (&_tmp0_, G_TYPE_INT);
	g_value_set_int (&_tmp0_, (gint) value);
	clutter_shader_effect_set_uniform_value ((ClutterShaderEffect*) self, "PAUSE_FOR_SCREENSHOT", &_tmp0_);
	G_IS_VALUE (&_tmp0_) ? (g_value_unset (&_tmp0_), NULL) : NULL;
	clutter_effect_queue_repaint ((ClutterEffect*) self);
	g_object_notify_by_pspec ((GObject *) self, gala_monochrome_effect_properties[GALA_MONOCHROME_EFFECT_PAUSE_FOR_SCREENSHOT_PROPERTY]);
}

ClutterActor*
gala_monochrome_effect_get_transition_actor (GalaMonochromeEffect* self)
{
	ClutterActor* result;
	ClutterActor* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_transition_actor;
	result = _tmp0_;
	return result;
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

void
gala_monochrome_effect_set_transition_actor (GalaMonochromeEffect* self,
                                             ClutterActor* value)
{
	ClutterActor* old_value;
	g_return_if_fail (self != NULL);
	old_value = gala_monochrome_effect_get_transition_actor (self);
	if (old_value != value) {
		ClutterActor* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_transition_actor);
		self->priv->_transition_actor = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, gala_monochrome_effect_properties[GALA_MONOCHROME_EFFECT_TRANSITION_ACTOR_PROPERTY]);
	}
}

static void
gala_monochrome_effect_class_init (GalaMonochromeEffectClass * klass,
                                   gpointer klass_data)
{
	gala_monochrome_effect_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GalaMonochromeEffect_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_gala_monochrome_effect_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_gala_monochrome_effect_set_property;
	G_OBJECT_CLASS (klass)->finalize = gala_monochrome_effect_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GALA_MONOCHROME_EFFECT_STRENGTH_PROPERTY, gala_monochrome_effect_properties[GALA_MONOCHROME_EFFECT_STRENGTH_PROPERTY] = g_param_spec_double ("strength", "strength", "strength", -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GALA_MONOCHROME_EFFECT_PAUSE_FOR_SCREENSHOT_PROPERTY, gala_monochrome_effect_properties[GALA_MONOCHROME_EFFECT_PAUSE_FOR_SCREENSHOT_PROPERTY] = g_param_spec_boolean ("pause-for-screenshot", "pause-for-screenshot", "pause-for-screenshot", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GALA_MONOCHROME_EFFECT_TRANSITION_ACTOR_PROPERTY, gala_monochrome_effect_properties[GALA_MONOCHROME_EFFECT_TRANSITION_ACTOR_PROPERTY] = g_param_spec_object ("transition-actor", "transition-actor", "transition-actor", clutter_actor_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
gala_monochrome_effect_instance_init (GalaMonochromeEffect * self,
                                      gpointer klass)
{
	self->priv = gala_monochrome_effect_get_instance_private (self);
	self->priv->_transition_actor = NULL;
}

static void
gala_monochrome_effect_finalize (GObject * obj)
{
	GalaMonochromeEffect * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GALA_TYPE_MONOCHROME_EFFECT, GalaMonochromeEffect);
	_g_object_unref0 (self->priv->_transition_actor);
	G_OBJECT_CLASS (gala_monochrome_effect_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
gala_monochrome_effect_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GalaMonochromeEffectClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gala_monochrome_effect_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GalaMonochromeEffect), 0, (GInstanceInitFunc) gala_monochrome_effect_instance_init, NULL };
	GType gala_monochrome_effect_type_id;
	gala_monochrome_effect_type_id = g_type_register_static (clutter_shader_effect_get_type (), "GalaMonochromeEffect", &g_define_type_info, 0);
	GalaMonochromeEffect_private_offset = g_type_add_instance_private (gala_monochrome_effect_type_id, sizeof (GalaMonochromeEffectPrivate));
	return gala_monochrome_effect_type_id;
}

GType
gala_monochrome_effect_get_type (void)
{
	static gsize gala_monochrome_effect_type_id__once = 0;
	if (g_once_init_enter (&gala_monochrome_effect_type_id__once)) {
		GType gala_monochrome_effect_type_id;
		gala_monochrome_effect_type_id = gala_monochrome_effect_get_type_once ();
		g_once_init_leave (&gala_monochrome_effect_type_id__once, gala_monochrome_effect_type_id);
	}
	return gala_monochrome_effect_type_id__once;
}

static void
_vala_gala_monochrome_effect_get_property (GObject * object,
                                           guint property_id,
                                           GValue * value,
                                           GParamSpec * pspec)
{
	GalaMonochromeEffect * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GALA_TYPE_MONOCHROME_EFFECT, GalaMonochromeEffect);
	switch (property_id) {
		case GALA_MONOCHROME_EFFECT_STRENGTH_PROPERTY:
		g_value_set_double (value, gala_monochrome_effect_get_strength (self));
		break;
		case GALA_MONOCHROME_EFFECT_TRANSITION_ACTOR_PROPERTY:
		g_value_set_object (value, gala_monochrome_effect_get_transition_actor (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_gala_monochrome_effect_set_property (GObject * object,
                                           guint property_id,
                                           const GValue * value,
                                           GParamSpec * pspec)
{
	GalaMonochromeEffect * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GALA_TYPE_MONOCHROME_EFFECT, GalaMonochromeEffect);
	switch (property_id) {
		case GALA_MONOCHROME_EFFECT_STRENGTH_PROPERTY:
		gala_monochrome_effect_set_strength (self, g_value_get_double (value));
		break;
		case GALA_MONOCHROME_EFFECT_PAUSE_FOR_SCREENSHOT_PROPERTY:
		gala_monochrome_effect_set_pause_for_screenshot (self, g_value_get_boolean (value));
		break;
		case GALA_MONOCHROME_EFFECT_TRANSITION_ACTOR_PROPERTY:
		gala_monochrome_effect_set_transition_actor (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

