1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007-2008, Nicola Fontana <ntd at entidi.it>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
24 * @short_description: The base class of all styling objects.
27 #include "adg-style.h"
28 #include "adg-style-private.h"
29 #include "adg-line-style.h"
30 #include "adg-font-style.h"
31 #include "adg-arrow-style.h"
32 #include "adg-enums.h"
38 #define PARENT_CLASS ((GObjectClass *) adg_style_parent_class)
48 static void get_property (GObject
*object
,
52 static void set_property (GObject
*object
,
57 static AdgStyle
*from_id (gint id
);
58 static void apply (AdgStyle
*style
,
60 static void set_pattern (AdgStyle
*style
,
64 G_DEFINE_ABSTRACT_TYPE (AdgStyle
, adg_style
, G_TYPE_OBJECT
)
68 adg_style_class_init (AdgStyleClass
*klass
)
70 GObjectClass
*gobject_class
;
73 gobject_class
= (GObjectClass
*) klass
;
75 g_type_class_add_private (klass
, sizeof (AdgStylePrivate
));
77 gobject_class
->get_property
= get_property
;
78 gobject_class
->set_property
= set_property
;
80 klass
->from_id
= from_id
;
83 param
= g_param_spec_boxed ("pattern",
85 P_("The pattern associated to this style"),
88 g_object_class_install_property (gobject_class
, PROP_PATTERN
, param
);
92 adg_style_init (AdgStyle
*style
)
94 AdgStylePrivate
*priv
= G_TYPE_INSTANCE_GET_PRIVATE (style
, ADG_TYPE_STYLE
,
103 get_property (GObject
*object
,
108 AdgStyle
*style
= (AdgStyle
*) object
;
113 g_value_set_boxed (value
, style
->priv
->pattern
);
116 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
122 set_property (GObject
*object
,
127 AdgStyle
*style
= (AdgStyle
*) object
;
132 set_pattern (style
, g_value_get_boxed (value
));
135 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
143 * @style_type: the type id from which obtain the style
146 * Gets the preregistered style identified by @id of @style_type family.
148 * Return value: the requested style or %NULL on errors
151 adg_style_from_id (GType style_type
,
154 AdgStyleClass
*klass
= g_type_class_ref (style_type
);
156 g_return_val_if_fail (ADG_IS_STYLE_CLASS (klass
), NULL
);
158 return klass
->from_id (id
);
163 * @style: an #AdgStyle derived object
164 * @cr: the cairo context
166 * Applies @style to @cr so the next rendering will be done accordling to
167 * this style directives.
170 adg_style_apply (AdgStyle
*style
,
173 g_return_if_fail (ADG_IS_STYLE (style
));
174 g_return_if_fail (cr
!= NULL
);
176 return ADG_STYLE_GET_CLASS (style
)->apply (style
, cr
);
180 * adg_style_get_pattern:
181 * @style: an #AdgStyle object
183 * Gets the pattern binded to this style. The returned pattern refers to
184 * an internally managed struct that must not be modified or freed.
186 * Return value: the requested pattern or %NULL on no pattern or errors
189 adg_style_get_pattern (AdgStyle
*style
)
191 g_return_val_if_fail (ADG_IS_STYLE (style
), NULL
);
193 return style
->priv
->pattern
;
197 * adg_style_set_pattern:
198 * @style: an #AdgStyle object
199 * @pattern: the new pattern
201 * Sets a new pattern for this style. This operation will release one
202 * reference on the old pattern (if any) and will add a new reference
205 * A %NULL pattern is allowed: it means the previous pattern is kept
206 * during the rendering process.
209 adg_style_set_pattern (AdgStyle
*style
,
212 g_return_if_fail (ADG_IS_STYLE (style
));
213 g_return_if_fail (pattern
!= NULL
);
215 set_pattern (style
, pattern
);
216 g_object_notify ((GObject
*) style
, "pattern");
223 g_warning ("Uninmplemented from_id()");
228 apply (AdgStyle
*style
,
231 if (style
->priv
->pattern
!= NULL
)
232 cairo_set_source (cr
, style
->priv
->pattern
);
236 set_pattern (AdgStyle
*style
,
239 if (style
->priv
->pattern
!= NULL
)
240 cairo_pattern_destroy (style
->priv
->pattern
);
243 cairo_pattern_reference (pattern
);
245 style
->priv
->pattern
= pattern
;