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 void apply (AdgStyle
*style
,
59 static void set_pattern (AdgStyle
*style
,
63 G_DEFINE_ABSTRACT_TYPE (AdgStyle
, adg_style
, G_TYPE_OBJECT
)
67 adg_style_class_init (AdgStyleClass
*klass
)
69 GObjectClass
*gobject_class
;
72 gobject_class
= (GObjectClass
*) klass
;
74 g_type_class_add_private (klass
, sizeof (AdgStylePrivate
));
76 gobject_class
->get_property
= get_property
;
77 gobject_class
->set_property
= set_property
;
81 param
= g_param_spec_boxed ("pattern",
83 P_("The pattern associated to this style"),
86 g_object_class_install_property (gobject_class
, PROP_PATTERN
, param
);
90 adg_style_init (AdgStyle
*style
)
92 AdgStylePrivate
*priv
= G_TYPE_INSTANCE_GET_PRIVATE (style
, ADG_TYPE_STYLE
,
101 get_property (GObject
*object
,
106 AdgStyle
*style
= (AdgStyle
*) object
;
111 g_value_set_boxed (value
, style
->priv
->pattern
);
114 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
120 set_property (GObject
*object
,
125 AdgStyle
*style
= (AdgStyle
*) object
;
130 set_pattern (style
, g_value_get_boxed (value
));
133 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
141 * @style: an #AdgStyle derived object
142 * @cr: the cairo context
144 * Applies @style to @cr so the next rendering will be done accordling to
145 * this style directives.
148 adg_style_apply (AdgStyle
*style
,
151 g_return_if_fail (ADG_IS_STYLE (style
));
152 g_return_if_fail (cr
!= NULL
);
154 return ADG_STYLE_GET_CLASS (style
)->apply (style
, cr
);
158 * adg_style_get_pattern:
159 * @style: an #AdgStyle object
161 * Gets the pattern binded to this style. The returned pattern refers to
162 * an internally managed struct that must not be modified or freed.
164 * Return value: the requested pattern or %NULL on no pattern or errors
167 adg_style_get_pattern (AdgStyle
*style
)
169 g_return_val_if_fail (ADG_IS_STYLE (style
), NULL
);
171 return style
->priv
->pattern
;
175 * adg_style_set_pattern:
176 * @style: an #AdgStyle object
177 * @pattern: the new pattern
179 * Sets a new pattern for this style. This operation will release one
180 * reference on the old pattern (if any) and will add a new reference
183 * A %NULL pattern is allowed: it means the previous pattern is kept
184 * during the rendering process.
187 adg_style_set_pattern (AdgStyle
*style
,
190 g_return_if_fail (ADG_IS_STYLE (style
));
191 g_return_if_fail (pattern
!= NULL
);
193 set_pattern (style
, pattern
);
194 g_object_notify ((GObject
*) style
, "pattern");
199 apply (AdgStyle
*style
,
202 if (style
->priv
->pattern
!= NULL
)
203 cairo_set_source (cr
, style
->priv
->pattern
);
207 set_pattern (AdgStyle
*style
,
210 if (style
->priv
->pattern
!= NULL
)
211 cairo_pattern_destroy (style
->priv
->pattern
);
214 cairo_pattern_reference (pattern
);
216 style
->priv
->pattern
= pattern
;