update to 1.10.4
[profile/ivi/clutter.git] / clutter / clutter-units.h
1 /* -*- mode:C; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Clutter.
4  *
5  * An OpenGL based 'interactive canvas' library.
6  *
7  * Authored By: Tomas Frydrych  <tf@openedhand.com>
8  *              Emmanuele Bassu  <ebassi@linux.intel.com>
9  *
10  * Copyright (C) 2007, 2008 OpenedHand
11  * Copyright (C) 2009 Intel Corp.
12  *
13  * This library is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU Lesser General Public
15  * License as published by the Free Software Foundation; either
16  * version 2 of the License, or (at your option) any later version.
17  *
18  * This library is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21  * Lesser General Public License for more details.
22  *
23  * You should have received a copy of the GNU Lesser General Public
24  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
25  */
26
27 #if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
28 #error "Only <clutter/clutter.h> can be included directly."
29 #endif
30
31 #ifndef __CLUTTER_UNITS_H__
32 #define __CLUTTER_UNITS_H__
33
34 #include <glib-object.h>
35
36 #include <cogl/cogl.h>
37
38 G_BEGIN_DECLS
39
40 /**
41  * ClutterUnits:
42  *
43  * An opaque structure, to be used to store sizing and positioning
44  * values along with their unit.
45  *
46  * Since: 1.0
47  */
48 typedef struct _ClutterUnits    ClutterUnits;
49
50 struct _ClutterUnits
51 {
52   /*< private >*/
53   ClutterUnitType unit_type;
54
55   gfloat value;
56
57   /* pre-filled by the provided constructors */
58
59   /* cached pixel value */
60   gfloat pixels;
61
62   /* whether the :pixels field is set */
63   guint pixels_set;
64
65   /* the serial coming from the backend, used to evict the cache */
66   gint32 serial;
67
68   /* padding for eventual expansion */
69   gint32 __padding_1;
70   gint64 __padding_2;
71 };
72
73 GType           clutter_units_get_type         (void) G_GNUC_CONST;
74 ClutterUnitType clutter_units_get_unit_type    (const ClutterUnits *units);
75 gfloat          clutter_units_get_unit_value   (const ClutterUnits *units);
76
77 ClutterUnits *  clutter_units_copy             (const ClutterUnits *units);
78 void            clutter_units_free             (ClutterUnits       *units);
79
80 void            clutter_units_from_pixels      (ClutterUnits       *units,
81                                                 gint                px);
82 void            clutter_units_from_em          (ClutterUnits       *units,
83                                                 gfloat              em);
84 void            clutter_units_from_em_for_font (ClutterUnits       *units,
85                                                 const gchar        *font_name,
86                                                 gfloat              em);
87 void            clutter_units_from_mm          (ClutterUnits       *units,
88                                                 gfloat              mm);
89 void            clutter_units_from_cm          (ClutterUnits       *units,
90                                                 gfloat              cm);
91 void            clutter_units_from_pt          (ClutterUnits       *units,
92                                                 gfloat              pt);
93
94 gfloat          clutter_units_to_pixels        (ClutterUnits       *units);
95
96 gboolean        clutter_units_from_string      (ClutterUnits       *units,
97                                                 const gchar        *str);
98 gchar *         clutter_units_to_string        (const ClutterUnits *units);
99
100 /* shorthands for the constructors */
101 #define clutter_units_pixels            clutter_units_from_pixels
102 #define clutter_units_em                clutter_units_from_em
103 #define clutter_units_em_for_font       clutter_units_from_em_for_font
104 #define clutter_units_mm                clutter_units_from_mm
105 #define clutter_units_cm                clutter_units_from_cm
106 #define clutter_units_pt                clutter_units_from_pt
107
108 #define CLUTTER_TYPE_UNITS                 (clutter_units_get_type ())
109 #define CLUTTER_TYPE_PARAM_UNITS           (clutter_param_units_get_type ())
110 #define CLUTTER_PARAM_SPEC_UNITS(pspec)    (G_TYPE_CHECK_INSTANCE_CAST ((pspec), CLUTTER_TYPE_PARAM_UNITS, ClutterParamSpecUnits))
111 #define CLUTTER_IS_PARAM_SPEC_UNITS(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), CLUTTER_TYPE_PARAM_UNITS))
112
113 /**
114  * CLUTTER_VALUE_HOLDS_UNITS:
115  * @x: a #GValue
116  *
117  * Evaluates to %TRUE if @x holds a #ClutterUnits value
118  *
119  * Since: 0.8
120  */
121 #define CLUTTER_VALUE_HOLDS_UNITS(x)    (G_VALUE_HOLDS ((x), CLUTTER_TYPE_UNITS))
122
123 typedef struct _ClutterParamSpecUnits   ClutterParamSpecUnits;
124
125 /**
126  * ClutterParamSpecUnits: (skip)
127  * @default_type: default type
128  * @default_value: default value
129  * @minimum: lower boundary
130  * @maximum: higher boundary
131  *
132  * #GParamSpec subclass for unit based properties.
133  *
134  * Since: 1.0
135  */
136 struct _ClutterParamSpecUnits
137 {
138   /*< private >*/
139   GParamSpec parent_instance;
140
141   /*< public >*/
142   ClutterUnitType default_type;
143
144   gfloat default_value;
145   gfloat minimum;
146   gfloat maximum;
147 };
148
149 GType clutter_param_units_get_type (void) G_GNUC_CONST;
150
151 GParamSpec *            clutter_param_spec_units (const gchar        *name,
152                                                   const gchar        *nick,
153                                                   const gchar        *blurb,
154                                                   ClutterUnitType     default_type,
155                                                   gfloat              minimum,
156                                                   gfloat              maximum,
157                                                   gfloat              default_value,
158                                                   GParamFlags         flags);
159
160 void                    clutter_value_set_units  (GValue             *value,
161                                                   const ClutterUnits *units);
162 const ClutterUnits *    clutter_value_get_units  (const GValue       *value);
163
164 G_END_DECLS
165
166 #endif /* __CLUTTER_UNITS_H__ */