2007-01-17 13:03:52 +00:00
|
|
|
/*
|
|
|
|
* Clutter.
|
|
|
|
*
|
|
|
|
* An OpenGL based 'interactive canvas' library.
|
|
|
|
*
|
2007-04-12 12:42:07 +00:00
|
|
|
* Authored By Tomas Frydrych <tf@openedhand.com>
|
2007-01-17 13:03:52 +00:00
|
|
|
*
|
2007-04-12 12:42:07 +00:00
|
|
|
* Copyright (C) 2006, 2007 OpenedHand
|
2007-01-17 13:03:52 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2010-03-01 12:56:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*
|
2007-01-17 13:03:52 +00:00
|
|
|
*/
|
|
|
|
|
2008-07-11 10:36:07 +00:00
|
|
|
#define G_IMPLEMENT_INLINES
|
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2007-06-07 15:28:59 +00:00
|
|
|
#include "config.h"
|
2007-10-12 08:17:00 +00:00
|
|
|
#endif
|
2007-06-07 15:28:59 +00:00
|
|
|
|
2009-03-09 17:36:22 +00:00
|
|
|
#include <cogl/cogl.h>
|
|
|
|
|
2008-04-17 10:08:17 +00:00
|
|
|
#include <glib-object.h>
|
|
|
|
|
2007-10-12 09:39:41 +00:00
|
|
|
#include "clutter-fixed.h"
|
|
|
|
#include "clutter-private.h"
|
2007-01-15 18:37:12 +00:00
|
|
|
|
2008-04-17 10:08:17 +00:00
|
|
|
/**
|
|
|
|
* clutter_value_set_fixed:
|
2009-03-09 17:36:22 +00:00
|
|
|
* @value: a #GValue initialized to %COGL_TYPE_FIXED
|
2008-04-17 10:08:17 +00:00
|
|
|
* @fixed_: the fixed point value to set
|
|
|
|
*
|
|
|
|
* Sets @value to @fixed_.
|
|
|
|
*
|
|
|
|
* Since: 0.8
|
|
|
|
*/
|
|
|
|
void
|
2009-03-09 17:36:22 +00:00
|
|
|
clutter_value_set_fixed (GValue *value,
|
|
|
|
CoglFixed fixed_)
|
2008-04-17 10:08:17 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (CLUTTER_VALUE_HOLDS_FIXED (value));
|
|
|
|
|
|
|
|
value->data[0].v_int = fixed_;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_value_get_fixed:
|
2009-03-09 17:36:22 +00:00
|
|
|
* @value: a #GValue initialized to %COGL_TYPE_FIXED
|
2008-04-17 10:08:17 +00:00
|
|
|
*
|
|
|
|
* Gets the fixed point value stored inside @value.
|
|
|
|
*
|
|
|
|
* Return value: the value inside the passed #GValue
|
|
|
|
*
|
|
|
|
* Since: 0.8
|
|
|
|
*/
|
2009-03-09 17:36:22 +00:00
|
|
|
CoglFixed
|
2008-04-17 11:42:08 +00:00
|
|
|
clutter_value_get_fixed (const GValue *value)
|
2008-04-17 10:08:17 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (CLUTTER_VALUE_HOLDS_FIXED (value), 0);
|
|
|
|
|
|
|
|
return value->data[0].v_int;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
param_fixed_init (GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
ClutterParamSpecFixed *fspec = CLUTTER_PARAM_SPEC_FIXED (pspec);
|
|
|
|
|
2009-03-09 17:36:22 +00:00
|
|
|
fspec->minimum = COGL_FIXED_MIN;
|
|
|
|
fspec->maximum = COGL_FIXED_MAX;
|
2008-04-17 10:08:17 +00:00
|
|
|
fspec->default_value = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
param_fixed_set_default (GParamSpec *pspec,
|
|
|
|
GValue *value)
|
|
|
|
{
|
|
|
|
value->data[0].v_int = CLUTTER_PARAM_SPEC_FIXED (pspec)->default_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
param_fixed_validate (GParamSpec *pspec,
|
|
|
|
GValue *value)
|
|
|
|
{
|
|
|
|
ClutterParamSpecFixed *fspec = CLUTTER_PARAM_SPEC_FIXED (pspec);
|
2009-03-09 17:36:22 +00:00
|
|
|
gint oval = value->data[0].v_int;
|
2008-05-09 10:58:26 +00:00
|
|
|
gint min, max, val;
|
|
|
|
|
|
|
|
g_assert (CLUTTER_IS_PARAM_SPEC_FIXED (pspec));
|
2008-04-17 10:08:17 +00:00
|
|
|
|
2008-05-09 10:58:26 +00:00
|
|
|
/* we compare the integer part of the value because the minimum
|
|
|
|
* and maximum values cover just that part of the representation
|
|
|
|
*/
|
|
|
|
min = fspec->minimum;
|
|
|
|
max = fspec->maximum;
|
2009-01-20 16:20:54 +00:00
|
|
|
val = (value->data[0].v_int);
|
2008-05-09 10:58:26 +00:00
|
|
|
|
|
|
|
val = CLAMP (val, min, max);
|
|
|
|
if (val != oval)
|
|
|
|
{
|
|
|
|
value->data[0].v_int = val;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2008-04-17 10:08:17 +00:00
|
|
|
|
2008-05-09 10:58:26 +00:00
|
|
|
return FALSE;
|
2008-04-17 10:08:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
param_fixed_values_cmp (GParamSpec *pspec,
|
|
|
|
const GValue *value1,
|
|
|
|
const GValue *value2)
|
|
|
|
{
|
|
|
|
if (value1->data[0].v_int < value2->data[0].v_int)
|
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
return value1->data[0].v_int > value2->data[0].v_int;
|
|
|
|
}
|
|
|
|
|
|
|
|
GType
|
|
|
|
clutter_param_fixed_get_type (void)
|
|
|
|
{
|
|
|
|
static GType pspec_type = 0;
|
|
|
|
|
|
|
|
if (G_UNLIKELY (pspec_type == 0))
|
|
|
|
{
|
|
|
|
const GParamSpecTypeInfo pspec_info = {
|
|
|
|
sizeof (ClutterParamSpecFixed),
|
|
|
|
16,
|
|
|
|
param_fixed_init,
|
2009-03-09 17:36:22 +00:00
|
|
|
COGL_TYPE_FIXED,
|
2008-04-17 10:08:17 +00:00
|
|
|
NULL,
|
|
|
|
param_fixed_set_default,
|
|
|
|
param_fixed_validate,
|
|
|
|
param_fixed_values_cmp,
|
|
|
|
};
|
|
|
|
|
|
|
|
pspec_type = g_param_type_register_static (I_("ClutterParamSpecFixed"),
|
|
|
|
&pspec_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pspec_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_param_spec_fixed:
|
|
|
|
* @name: name of the property
|
|
|
|
* @nick: short name
|
|
|
|
* @blurb: description (can be translatable)
|
|
|
|
* @minimum: lower boundary
|
|
|
|
* @maximum: higher boundary
|
|
|
|
* @default_value: default value
|
|
|
|
* @flags: flags for the param spec
|
|
|
|
*
|
2009-03-09 17:56:48 +00:00
|
|
|
* Creates a #GParamSpec for properties using #CoglFixed values
|
2008-04-17 10:08:17 +00:00
|
|
|
*
|
|
|
|
* Return value: the newly created #GParamSpec
|
|
|
|
*
|
|
|
|
* Since: 0.8
|
|
|
|
*/
|
|
|
|
GParamSpec *
|
2009-03-09 17:36:22 +00:00
|
|
|
clutter_param_spec_fixed (const gchar *name,
|
|
|
|
const gchar *nick,
|
|
|
|
const gchar *blurb,
|
|
|
|
CoglFixed minimum,
|
|
|
|
CoglFixed maximum,
|
|
|
|
CoglFixed default_value,
|
2008-04-17 10:08:17 +00:00
|
|
|
GParamFlags flags)
|
|
|
|
{
|
|
|
|
ClutterParamSpecFixed *fspec;
|
|
|
|
|
|
|
|
g_return_val_if_fail (default_value >= minimum && default_value <= maximum,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
fspec = g_param_spec_internal (CLUTTER_TYPE_PARAM_FIXED,
|
|
|
|
name, nick, blurb,
|
|
|
|
flags);
|
|
|
|
fspec->minimum = minimum;
|
|
|
|
fspec->maximum = maximum;
|
|
|
|
fspec->default_value = default_value;
|
|
|
|
|
|
|
|
return G_PARAM_SPEC (fspec);
|
|
|
|
}
|