1
/* The GIMP -- an image manipulation program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
* ParamSpecs for config objects
5
* Copyright (C) 2001-2003 Sven Neumann <sven@gimp.org>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
#include <glib-object.h>
26
#include "libgimpbase/gimpbase.h"
27
#include "libgimpcolor/gimpcolor.h"
28
#include "libgimpmath/gimpmath.h"
30
#include "config-types.h"
32
#include "gimpconfig-params.h"
33
#include "gimpconfig-types.h"
40
#define GIMP_PARAM_SPEC_RGB(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_RGB, GimpParamSpecRGB))
42
static void gimp_param_rgb_class_init (GParamSpecClass *class);
43
static void gimp_param_rgb_init (GParamSpec *pspec);
44
static void gimp_param_rgb_set_default (GParamSpec *pspec,
46
static gboolean gimp_param_rgb_validate (GParamSpec *pspec,
48
static gint gimp_param_rgb_values_cmp (GParamSpec *pspec,
50
const GValue *value2);
52
typedef struct _GimpParamSpecRGB GimpParamSpecRGB;
54
struct _GimpParamSpecRGB
56
GParamSpecBoxed parent_instance;
58
GimpRGB default_value;
62
gimp_param_rgb_get_type (void)
64
static GType spec_type = 0;
68
static const GTypeInfo type_info =
70
sizeof (GParamSpecClass),
72
(GClassInitFunc) gimp_param_rgb_class_init,
74
sizeof (GimpParamSpecRGB),
76
(GInstanceInitFunc) gimp_param_rgb_init
79
spec_type = g_type_register_static (G_TYPE_PARAM_BOXED,
88
gimp_param_rgb_class_init (GParamSpecClass *class)
90
class->value_type = GIMP_TYPE_RGB;
91
class->value_set_default = gimp_param_rgb_set_default;
92
class->value_validate = gimp_param_rgb_validate;
93
class->values_cmp = gimp_param_rgb_values_cmp;
97
gimp_param_rgb_init (GParamSpec *pspec)
99
GimpParamSpecRGB *cspec = GIMP_PARAM_SPEC_RGB (pspec);
101
gimp_rgba_set (&cspec->default_value, 0.0, 0.0, 0.0, 0.0);
105
gimp_param_rgb_set_default (GParamSpec *pspec,
108
GimpParamSpecRGB *cspec = GIMP_PARAM_SPEC_RGB (pspec);
110
g_value_set_static_boxed (value, &cspec->default_value);
114
gimp_param_rgb_validate (GParamSpec *pspec,
119
rgb = value->data[0].v_pointer;
127
gimp_rgb_clamp (rgb);
129
return (oval.r != rgb->r ||
139
gimp_param_rgb_values_cmp (GParamSpec *pspec,
140
const GValue *value1,
141
const GValue *value2)
146
rgb1 = value1->data[0].v_pointer;
147
rgb2 = value2->data[0].v_pointer;
149
/* try to return at least *something*, it's useless anyway... */
152
return rgb2 != NULL ? -1 : 0;
159
gimp_rgba_get_uchar (rgb1,
160
((guchar *) &int1) + 0,
161
((guchar *) &int1) + 1,
162
((guchar *) &int1) + 2,
163
((guchar *) &int1) + 3);
164
gimp_rgba_get_uchar (rgb2,
165
((guchar *) &int2) + 0,
166
((guchar *) &int2) + 1,
167
((guchar *) &int2) + 2,
168
((guchar *) &int2) + 3);
175
gimp_param_spec_rgb (const gchar *name,
178
const GimpRGB *default_value,
181
GimpParamSpecRGB *cspec;
183
g_return_val_if_fail (default_value != NULL, NULL);
185
cspec = g_param_spec_internal (GIMP_TYPE_PARAM_RGB,
186
name, nick, blurb, flags);
188
cspec->default_value = *default_value;
190
return G_PARAM_SPEC (cspec);
195
* GIMP_TYPE_PARAM_MATRIX2
198
#define GIMP_PARAM_SPEC_MATRIX2(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_MATRIX2, GimpParamSpecMatrix2))
200
static void gimp_param_matrix2_class_init (GParamSpecClass *class);
201
static void gimp_param_matrix2_init (GParamSpec *pspec);
202
static void gimp_param_matrix2_set_default (GParamSpec *pspec,
204
static gint gimp_param_matrix2_values_cmp (GParamSpec *pspec,
205
const GValue *value1,
206
const GValue *value2);
208
typedef struct _GimpParamSpecMatrix2 GimpParamSpecMatrix2;
210
struct _GimpParamSpecMatrix2
212
GParamSpecBoxed parent_instance;
214
GimpMatrix2 default_value;
218
gimp_param_matrix2_get_type (void)
220
static GType spec_type = 0;
224
static const GTypeInfo type_info =
226
sizeof (GParamSpecClass),
228
(GClassInitFunc) gimp_param_matrix2_class_init,
230
sizeof (GimpParamSpecMatrix2),
232
(GInstanceInitFunc) gimp_param_matrix2_init
235
spec_type = g_type_register_static (G_TYPE_PARAM_BOXED,
244
gimp_param_matrix2_class_init (GParamSpecClass *class)
246
class->value_type = GIMP_TYPE_MATRIX2;
247
class->value_set_default = gimp_param_matrix2_set_default;
248
class->values_cmp = gimp_param_matrix2_values_cmp;
252
gimp_param_matrix2_init (GParamSpec *pspec)
254
GimpParamSpecMatrix2 *cspec = GIMP_PARAM_SPEC_MATRIX2 (pspec);
256
gimp_matrix2_identity (&cspec->default_value);
260
gimp_param_matrix2_set_default (GParamSpec *pspec,
263
GimpParamSpecMatrix2 *cspec = GIMP_PARAM_SPEC_MATRIX2 (pspec);
265
g_value_set_static_boxed (value, &cspec->default_value);
269
gimp_param_matrix2_values_cmp (GParamSpec *pspec,
270
const GValue *value1,
271
const GValue *value2)
273
GimpMatrix2 *matrix1;
274
GimpMatrix2 *matrix2;
277
matrix1 = value1->data[0].v_pointer;
278
matrix2 = value2->data[0].v_pointer;
280
/* try to return at least *something*, it's useless anyway... */
283
return matrix2 != NULL ? -1 : 0;
285
return matrix1 != NULL;
287
for (i = 0; i < 2; i++)
288
for (j = 0; j < 2; j++)
289
if (matrix1->coeff[i][j] != matrix2->coeff[i][j])
296
gimp_param_spec_matrix2 (const gchar *name,
299
const GimpMatrix2 *default_value,
302
GimpParamSpecMatrix2 *cspec;
304
g_return_val_if_fail (default_value != NULL, NULL);
306
cspec = g_param_spec_internal (GIMP_TYPE_PARAM_MATRIX2,
307
name, nick, blurb, flags);
309
cspec->default_value = *default_value;
311
return G_PARAM_SPEC (cspec);
316
* GIMP_TYPE_PARAM_MEMSIZE
319
static void gimp_param_memsize_class_init (GParamSpecClass *class);
322
gimp_param_memsize_get_type (void)
324
static GType spec_type = 0;
328
static const GTypeInfo type_info =
330
sizeof (GParamSpecClass),
332
(GClassInitFunc) gimp_param_memsize_class_init,
334
sizeof (GParamSpecUInt64),
338
spec_type = g_type_register_static (G_TYPE_PARAM_UINT64,
347
gimp_param_memsize_class_init (GParamSpecClass *class)
349
class->value_type = GIMP_TYPE_MEMSIZE;
353
gimp_param_spec_memsize (const gchar *name,
358
guint64 default_value,
361
GParamSpecUInt64 *pspec;
363
pspec = g_param_spec_internal (GIMP_TYPE_PARAM_MEMSIZE,
364
name, nick, blurb, flags);
366
pspec->minimum = minimum;
367
pspec->maximum = maximum;
368
pspec->default_value = default_value;
370
return G_PARAM_SPEC (pspec);
375
* GIMP_TYPE_PARAM_PATH
378
#define GIMP_PARAM_SPEC_PATH(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_PATH, GimpParamSpecPath))
380
typedef struct _GimpParamSpecPath GimpParamSpecPath;
382
struct _GimpParamSpecPath
384
GParamSpecString parent_instance;
386
GimpParamPathType type;
389
static void gimp_param_path_class_init (GParamSpecClass *class);
392
gimp_param_path_get_type (void)
394
static GType spec_type = 0;
398
static const GTypeInfo type_info =
400
sizeof (GParamSpecClass),
402
(GClassInitFunc) gimp_param_path_class_init,
404
sizeof (GimpParamSpecPath),
408
spec_type = g_type_register_static (G_TYPE_PARAM_STRING,
417
gimp_param_path_class_init (GParamSpecClass *class)
419
class->value_type = GIMP_TYPE_PATH;
423
gimp_param_spec_path (const gchar *name,
426
GimpParamPathType type,
427
gchar *default_value,
430
GParamSpecString *pspec;
432
pspec = g_param_spec_internal (GIMP_TYPE_PARAM_PATH,
433
name, nick, blurb, flags);
436
pspec->default_value = default_value;
438
GIMP_PARAM_SPEC_PATH (pspec)->type = type;
440
return G_PARAM_SPEC (pspec);
444
gimp_param_spec_path_type (GParamSpec *pspec)
446
g_return_val_if_fail (GIMP_IS_PARAM_SPEC_PATH (pspec), 0);
448
return GIMP_PARAM_SPEC_PATH (pspec)->type;
453
* GIMP_TYPE_PARAM_UNIT
456
#define GIMP_PARAM_SPEC_UNIT(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_UNIT, GimpParamSpecUnit))
458
typedef struct _GimpParamSpecUnit GimpParamSpecUnit;
460
struct _GimpParamSpecUnit
462
GParamSpecInt parent_instance;
464
gboolean allow_percent;
467
static void gimp_param_unit_class_init (GParamSpecClass *class);
468
static gboolean gimp_param_unit_value_validate (GParamSpec *pspec,
472
gimp_param_unit_get_type (void)
474
static GType spec_type = 0;
478
static const GTypeInfo type_info =
480
sizeof (GParamSpecClass),
482
(GClassInitFunc) gimp_param_unit_class_init,
484
sizeof (GimpParamSpecUnit),
488
spec_type = g_type_register_static (G_TYPE_PARAM_INT,
497
gimp_param_unit_class_init (GParamSpecClass *class)
499
class->value_type = GIMP_TYPE_UNIT;
500
class->value_validate = gimp_param_unit_value_validate;
504
gimp_param_unit_value_validate (GParamSpec *pspec,
507
GParamSpecInt *ispec = G_PARAM_SPEC_INT (pspec);
508
GimpParamSpecUnit *uspec = GIMP_PARAM_SPEC_UNIT (pspec);
509
gint oval = value->data[0].v_int;
511
if (uspec->allow_percent && value->data[0].v_int == GIMP_UNIT_PERCENT)
513
value->data[0].v_int = value->data[0].v_int;
517
value->data[0].v_int = CLAMP (value->data[0].v_int,
519
gimp_unit_get_number_of_units () - 1);
522
return value->data[0].v_int != oval;
526
gimp_param_spec_unit (const gchar *name,
529
gboolean allow_pixels,
530
gboolean allow_percent,
531
GimpUnit default_value,
534
GimpParamSpecUnit *pspec;
535
GParamSpecInt *ispec;
537
pspec = g_param_spec_internal (GIMP_TYPE_PARAM_UNIT,
538
name, nick, blurb, flags);
540
ispec = G_PARAM_SPEC_INT (pspec);
542
ispec->default_value = default_value;
543
ispec->minimum = allow_pixels ? GIMP_UNIT_PIXEL : GIMP_UNIT_INCH;
544
ispec->maximum = GIMP_UNIT_PERCENT - 1;
546
pspec->allow_percent = allow_percent;
548
return G_PARAM_SPEC (pspec);