Debian Codegraph @

clutter/deprecated/clutter-fixed.c

raw
1 /*
2 * Clutter.
3 *
4 * An OpenGL based 'interactive canvas' library.
5 *
6 * Authored By Tomas Frydrych <[email protected]>
7 *
8 * Copyright (C) 2006, 2007 OpenedHand
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
22 *
23 *
24 */
25
26 #define G_IMPLEMENT_INLINES
27
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31
32 #define CLUTTER_DISABLE_DEPRECATION_WARNINGS
33
34 /* This file depends on the cogl-fixed api which isn't exposed when
35 * COGL_ENABLE_EXPERIMENTAL_2_0_API is defined...
36 */
37 #undef COGL_ENABLE_EXPERIMENTAL_2_0_API
38 #include <cogl/cogl.h>
39
40 #include <glib-object.h>
41
42 #include "clutter-fixed.h"
43 #include "clutter-private.h"
44
45 /**
46 * clutter_value_set_fixed: (skip)
47 * @value: a #GValue initialized to %COGL_TYPE_FIXED
48 * @fixed_: the fixed point value to set
49 *
50 * Sets @value to @fixed_.
51 *
52 * Since: 0.8
53 *
54 * Deprecated: 1.10: Use g_value_set_int() instead.
55 */
56 void
57 clutter_value_set_fixed (GValue *value,
58 CoglFixed fixed_)
59 {
60 g_return_if_fail (CLUTTER_VALUE_HOLDS_FIXED (value));
61
62 value->data[0].v_int = fixed_;
63 }
64
65 /**
66 * clutter_value_get_fixed: (skip)
67 * @value: a #GValue initialized to %COGL_TYPE_FIXED
68 *
69 * Gets the fixed point value stored inside @value.
70 *
71 * Return value: the value inside the passed #GValue
72 *
73 * Since: 0.8
74 *
75 * Deprecated: 1.10: Use g_value_get_int() instead.
76 */
77 CoglFixed
78 clutter_value_get_fixed (const GValue *value)
79 {
80 g_return_val_if_fail (CLUTTER_VALUE_HOLDS_FIXED (value), 0);
81
82 return value->data[0].v_int;
83 }
84
85 static void
86 param_fixed_init (GParamSpec *pspec)
87 {
88 ClutterParamSpecFixed *fspec = CLUTTER_PARAM_SPEC_FIXED (pspec);
89
90 fspec->minimum = COGL_FIXED_MIN;
91 fspec->maximum = COGL_FIXED_MAX;
92 fspec->default_value = 0;
93 }
94
95 static void
96 param_fixed_set_default (GParamSpec *pspec,
97 GValue *value)
98 {
99 value->data[0].v_int = CLUTTER_PARAM_SPEC_FIXED (pspec)->default_value;
100 }
101
102 static gboolean
103 param_fixed_validate (GParamSpec *pspec,
104 GValue *value)
105 {
106 ClutterParamSpecFixed *fspec = CLUTTER_PARAM_SPEC_FIXED (pspec);
107 gint oval = value->data[0].v_int;
108 gint min, max, val;
109
110 g_assert (CLUTTER_IS_PARAM_SPEC_FIXED (pspec));
111
112 /* we compare the integer part of the value because the minimum
113 * and maximum values cover just that part of the representation
114 */
115 min = fspec->minimum;
116 max = fspec->maximum;
117 val = (value->data[0].v_int);
118
119 val = CLAMP (val, min, max);
120 if (val != oval)
121 {
122 value->data[0].v_int = val;
123 return TRUE;
124 }
125
126 return FALSE;
127 }
128
129 static gint
130 param_fixed_values_cmp (GParamSpec *pspec,
131 const GValue *value1,
132 const GValue *value2)
133 {
134 if (value1->data[0].v_int < value2->data[0].v_int)
135 return -1;
136 else
137 return value1->data[0].v_int > value2->data[0].v_int;
138 }
139
140 GType
141 clutter_param_fixed_get_type (void)
142 {
143 static GType pspec_type = 0;
144
145 if (G_UNLIKELY (pspec_type == 0))
146 {
147 const GParamSpecTypeInfo pspec_info = {
148 sizeof (ClutterParamSpecFixed),
149 16,
150 param_fixed_init,
151 COGL_TYPE_FIXED,
152 NULL,
153 param_fixed_set_default,
154 param_fixed_validate,
155 param_fixed_values_cmp,
156 };
157
158 pspec_type = g_param_type_register_static (I_("ClutterParamSpecFixed"),
159 &pspec_info);
160 }
161
162 return pspec_type;
163 }
164
165 /**
166 * clutter_param_spec_fixed: (skip)
167 * @name: name of the property
168 * @nick: short name
169 * @blurb: description (can be translatable)
170 * @minimum: lower boundary
171 * @maximum: higher boundary
172 * @default_value: default value
173 * @flags: flags for the param spec
174 *
175 * Creates a #GParamSpec for properties using #CoglFixed values
176 *
177 * Return value: (transfer full): the newly created #GParamSpec
178 *
179 * Since: 0.8
180 *
181 * Deprecated: 1.10: Use #GParamSpecInt instead.
182 */
183 GParamSpec *
184 clutter_param_spec_fixed (const gchar *name,
185 const gchar *nick,
186 const gchar *blurb,
187 CoglFixed minimum,
188 CoglFixed maximum,
189 CoglFixed default_value,
190 GParamFlags flags)
191 {
192 ClutterParamSpecFixed *fspec;
193
194 g_return_val_if_fail (default_value >= minimum && default_value <= maximum,
195 NULL);
196
197 fspec = g_param_spec_internal (CLUTTER_TYPE_PARAM_FIXED,
198 name, nick, blurb,
199 flags);
200 fspec->minimum = minimum;
201 fspec->maximum = maximum;
202 fspec->default_value = default_value;
203
204 return G_PARAM_SPEC (fspec);
205 }